mb_special.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  1. <?php
  2. /**
  3. * 手机专题
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. require_once (BASE_ROOT_PATH . '/helper/util_helper.php');
  11. require_once (BASE_ROOT_PATH . '/helper/special/block_filter.php');
  12. require_once (BASE_ROOT_PATH . '/helper/special/upgrade_helper.php');
  13. require_once (BASE_ROOT_PATH . '/helper/search/tcp_client.php');
  14. require_once (BASE_ROOT_PATH . '/helper/search/util.php');
  15. require_once (BASE_ROOT_PATH . '/helper/search_param.php');
  16. require_once (BASE_ROOT_PATH . '/helper/area_helper.php');
  17. require_once (BASE_ROOT_PATH . '/helper/model_helper.php');
  18. require_once (BASE_ROOT_PATH . '/helper/ugc_helper.php');
  19. require_once (BASE_ROOT_PATH . '/helper/activity_helper.php');
  20. class mb_specialControl extends SystemControl
  21. {
  22. const mb_home_tab_id = 123;
  23. const def_item_bg_color = '#F7F7F7';
  24. const def_item_bg_type = 'color';
  25. const def_divider_bg_img = '/mobile/defimg/divider_bg.png';
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. public function area_uplastOp()
  31. {
  32. echo "area_uplast start";
  33. area_helper::uplast_country();
  34. echo "area_uplast end";
  35. }
  36. public function area_fixareaidOp()
  37. {
  38. echo "area_fixareaid start";
  39. area_helper::fix_areaid();
  40. echo "area_fixareaid end";
  41. }
  42. public function area_fixareainfoOp()
  43. {
  44. echo "fix_areainfo start";
  45. area_helper::fix_areainfo();
  46. echo "fix_areainfo end";
  47. }
  48. //升级专题数据
  49. public function upgradeOp()
  50. {
  51. $mod_mb_special = Model('mb_special');
  52. //$items = Model()->table('mb_special_item')->where(array('item_type' => 'home7','special_id' => array('gt',10)))->order('special_id desc')->field('*')->limit(2)->select();
  53. $items = Model()->table('mb_special_item')->field('*')->limit(false)->select();
  54. foreach ($items as $item)
  55. {
  56. $filter = new upgrade_helper($item['item_type'],$item['special_id'],unserialize($item['item_data']));
  57. $item_data = $filter->filter();
  58. if($item_data == false) continue;
  59. $result = $mod_mb_special->editMbSpecialItemByID(array('item_data' => $item_data), $item['item_id'], $item['special_id']);
  60. if($result == false) {
  61. echo "upgrade error special_id={$item['special_id']} item_id={$item['item_id']}</br>";
  62. } else {
  63. echo "upgrade success special_id={$item['special_id']} item_id={$item['item_id']}</br>";
  64. }
  65. }
  66. }
  67. /**
  68. * 专题列表
  69. */
  70. public function special_listOp()
  71. {
  72. $special_id = intval($_REQUEST['search_special_id']);
  73. $special_desc = trim($_REQUEST['special_desc']);
  74. if($special_id > 0) {
  75. $cond = array("special_id" => $special_id);
  76. }
  77. elseif(!empty($special_desc)) {
  78. $cond = array("special_desc" => array('like', "%{$special_desc}%"));
  79. } else {
  80. $cond = [];
  81. }
  82. $cond['from_user'] = 0;
  83. $model_mb_special = Model('mb_special');
  84. $mb_special_list = $model_mb_special->getMbSpecialList($cond, 50);
  85. Tpl::output('list', $mb_special_list);
  86. Tpl::output('page', $model_mb_special->showpage(2));
  87. $this->show_menu('special_list');
  88. Tpl::showpage('mb_special.list');
  89. }
  90. public function discoveryOp()
  91. {
  92. $special_id = intval($_REQUEST['search_special_id']);
  93. $special_desc = trim($_REQUEST['special_desc']);
  94. if($special_id > 0) {
  95. $cond = array("special_id" => $special_id);
  96. }
  97. elseif(!empty($special_desc)) {
  98. $cond = array("special_desc" => array('like', "%{$special_desc}%"));
  99. } else {
  100. $cond = [];
  101. }
  102. $cond['from_user'] = 0;
  103. $model_mb_special = Model('mb_special');
  104. $mb_special_list = $model_mb_special->getMbSpecialList(['from_user' => 1,'special_id' => ['gt', 0],'state' => 0,'reader_type' => 0], 50);
  105. Tpl::output('list', $mb_special_list);
  106. Tpl::output('page', $model_mb_special->showpage(2));
  107. $this->show_menu('special_list');
  108. Tpl::showpage('mb_special.list');
  109. }
  110. public function search_keyword_coverOp()
  111. {
  112. $cover_img = trim($_POST['cover_img']);
  113. $keywords = trim($_POST['keyword']);
  114. $special_id = intval($_POST['special_id']);
  115. if($special_id > 0 && !empty($keywords))
  116. {
  117. $mod_special = Model('mb_special');
  118. $mod_special->editMbSpecial(['keywords' => $keywords,'share_image' =>$cover_img],$special_id);
  119. echo json_encode(200);
  120. } else {
  121. echo json_encode(-1);
  122. }
  123. }
  124. public function tab_listOp()
  125. {
  126. $mod_webcode = Model('web_code');
  127. $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
  128. $this->show_menu('tab_list');
  129. Tpl::output('tabs', $tabs);
  130. Tpl::showpage('mb_special.tab');
  131. }
  132. /**
  133. * 保存专题
  134. */
  135. public function special_saveOp()
  136. {
  137. $model_mb_special = Model('mb_special');
  138. $param = array();
  139. $param['special_desc'] = $_POST['special_desc'];
  140. $result = $model_mb_special->addMbSpecial($param);
  141. if($result) {
  142. $this->log('添加手机专题' . '[ID:' . $result. ']', 1);
  143. showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'special_list'));
  144. } else {
  145. $this->log('添加手机专题' . '[ID:' . $result. ']', 0);
  146. showMessage(L('nc_common_save_fail'), urlAdmin('mb_special', 'special_list'));
  147. }
  148. }
  149. /**
  150. * 编辑专题描述
  151. */
  152. public function update_special_descOp() {
  153. $model_mb_special = Model('mb_special');
  154. $param = array();
  155. $param['special_desc'] = $_GET['value'];
  156. $result = $model_mb_special->editMbSpecial($param, $_GET['id']);
  157. $data = array();
  158. if($result) {
  159. $this->log('保存手机专题' . '[ID:' . $result. ']', 1);
  160. $data['result'] = true;
  161. } else {
  162. $this->log('保存手机专题' . '[ID:' . $result. ']', 0);
  163. $data['result'] = false;
  164. $data['message'] = '保存失败';
  165. }
  166. echo json_encode($data);die;
  167. }
  168. /**
  169. * 删除专题
  170. */
  171. public function special_delOp()
  172. {
  173. $model_mb_special = Model('mb_special');
  174. $result = $model_mb_special->delMbSpecialByID($_POST['special_id']);
  175. if($result) {
  176. $this->log('删除手机专题' . '[ID:' . $_POST['special_id'] . ']', 1);
  177. showMessage(L('nc_common_del_succ'), urlAdmin('mb_special', 'special_list'));
  178. } else {
  179. $this->log('删除手机专题' . '[ID:' . $_POST['special_id'] . ']', 0);
  180. showMessage(L('nc_common_del_fail'), urlAdmin('mb_special', 'special_list'));
  181. }
  182. }
  183. /**
  184. * 编辑首页
  185. */
  186. public function index_editOp()
  187. {
  188. $model_mb_special = Model('mb_special');
  189. $special_item_list = $model_mb_special->getMbSpecialItemListByID($model_mb_special::INDEX_SPECIAL_ID);
  190. Tpl::output('list', $special_item_list);
  191. Tpl::output('page', $model_mb_special->showpage(2));
  192. Tpl::output('module_list', $model_mb_special->getMbSpecialModuleList());
  193. Tpl::output('special_id', $model_mb_special::INDEX_SPECIAL_ID);
  194. $this->show_menu('index_edit');
  195. Tpl::showpage('mb_special_item.list');
  196. }
  197. /**
  198. * 编辑专题
  199. */
  200. public function special_editOp() {
  201. $model_mb_special = Model('mb_special');
  202. $special_item_list = $model_mb_special->getMbSpecialItemListByID($_GET['special_id']);
  203. $spinfo = $model_mb_special->getMbSpecialByID($_GET['special_id']);
  204. $tabs = empty($spinfo['tabs']) ? "" : $spinfo['tabs'];
  205. Tpl::output('list', $special_item_list);
  206. Tpl::output('tabs', $tabs);
  207. Tpl::output('page', $model_mb_special->showpage(2));
  208. Tpl::output('module_list', $model_mb_special->getMbSpecialModuleList());
  209. Tpl::output('special_id', $_GET['special_id']);
  210. $this->show_menu('special_item_list');
  211. Tpl::showpage('mb_special_item.list');
  212. }
  213. /**
  214. * 专题项目添加
  215. */
  216. public function special_item_addOp()
  217. {
  218. $item_info = $this->add_item($_POST['special_id'],$_POST['item_type']);
  219. if($item_info) {
  220. echo json_encode($item_info);die;
  221. } else {
  222. echo json_encode(array('error' => '添加失败'));die;
  223. }
  224. }
  225. private function add_item($special_id,$item_type)
  226. {
  227. $model_mb_special = Model('mb_special');
  228. $param = array();
  229. $param['special_id'] = $special_id;
  230. $param['item_type'] = $item_type;
  231. $param['bg_type'] = self::def_item_bg_type;
  232. $param['bg_data'] = self::def_item_bg_color;
  233. $param['has_margin'] = 0;
  234. $param['bg_image'] = '';
  235. if($item_type == 'divider')
  236. {
  237. $filter = new block_filter($item_type,$special_id,null);
  238. $image = RESOURCE_SITE_URL . self::def_divider_bg_img;
  239. if($filter->to_local($image)) {
  240. $param['bg_image'] = $image;
  241. }
  242. }
  243. $item_info = $model_mb_special->addMbSpecialItem($param);
  244. return $item_info;
  245. }
  246. //专题项目插入分割线
  247. public function add_frontOp()
  248. {
  249. $item_type = $_POST['item_type'];
  250. $special_id = intval($_POST['special_id']);
  251. $item_info = $this->add_item($special_id,$item_type);
  252. if($item_info == false) {
  253. echo json_encode(array('error' => '添加失败'));die;
  254. }
  255. $sel_item_id = intval($_POST['sel_item_id']);
  256. $insert_item_id = intval($item_info['item_id']);
  257. $model_mb_special = Model('mb_special');
  258. $special_item_list = $model_mb_special->getMbSpecialItemListByID($special_id);
  259. $item_ids = [];
  260. foreach ($special_item_list as $item)
  261. {
  262. $item_id = intval($item['item_id']);
  263. if($item_id == $sel_item_id) {
  264. $item_ids[] = $insert_item_id;
  265. $item_ids[] = $item_id;
  266. }
  267. elseif($item_id == $insert_item_id) {
  268. continue;
  269. }
  270. else {
  271. $item_ids[] = $item_id;
  272. }
  273. }
  274. $index = 0;
  275. foreach ($item_ids as $item_id) {
  276. $result = $model_mb_special->editMbSpecialItemByID(array('item_sort' => $index), $item_id, $special_id);
  277. $index++;
  278. }
  279. $data = array();
  280. $data['message'] = '操作成功';
  281. echo json_encode($data);
  282. }
  283. public function move_itemOp()
  284. {
  285. $special_id = intval($_POST['special_id']);
  286. $src_id = intval($_POST['src_id']);
  287. $desc_id = intval($_POST['dest_id']);
  288. $href = urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id']));
  289. if($src_id == $desc_id || $src_id <= 0 || $desc_id <= 0) {
  290. showMessage(L('nc_common_save_fail'), $href);
  291. }
  292. else
  293. {
  294. $model_mb_special = Model('mb_special');
  295. $special_item_list = $model_mb_special->getMbSpecialItemListByID($special_id);
  296. $nfind = 0;
  297. $item_ids = [];
  298. foreach ($special_item_list as $item)
  299. {
  300. $item_id = intval($item['item_id']);
  301. if($item_id == $desc_id) {
  302. $item_ids[] = $src_id;
  303. $item_ids[] = $desc_id;
  304. $nfind += 1;
  305. }
  306. elseif($item_id == $src_id) {
  307. $nfind += 1;
  308. continue;
  309. }
  310. else {
  311. $item_ids[] = $item_id;
  312. }
  313. }
  314. if($nfind == 2)
  315. {
  316. $index = 0;
  317. foreach ($item_ids as $item_id) {
  318. $result = $model_mb_special->editMbSpecialItemByID(array('item_sort' => $index), $item_id, $special_id);
  319. $index++;
  320. }
  321. showMessage(L('nc_common_save_succ'),$href);
  322. }
  323. else {
  324. showMessage(L('nc_common_save_fail'), $href);
  325. }
  326. }
  327. }
  328. public function special_item_edit_tabOp()
  329. {
  330. $href = urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id']));
  331. $special_id = intval($_POST['special_id']);
  332. $tabs = $_POST['tabs'];
  333. if($special_id > 0)
  334. {
  335. if(!empty($tabs))
  336. {
  337. $items = preg_split("/#/",$tabs);
  338. foreach ($items as $item)
  339. {
  340. $values = explode(":",$item);
  341. if(count($values) != 2 || intval($values[0]) <= 0) {
  342. showMessage(L('nc_common_save_fail'), $href);
  343. return;
  344. }
  345. }
  346. }
  347. $mod_special = Model('mb_special');
  348. $mod_special->editMbSpecial(['tabs' => $tabs],$special_id);
  349. showMessage(L('nc_common_save_succ'),$href);
  350. } else {
  351. showMessage(L('nc_common_save_fail'), $href);
  352. }
  353. }
  354. /**
  355. * 专题项目删除
  356. */
  357. public function special_item_delOp() {
  358. $model_mb_special = Model('mb_special');
  359. $condition = array();
  360. $condition['item_id'] = $_POST['item_id'];
  361. $result = $model_mb_special->delMbSpecialItem($condition, $_POST['special_id']);
  362. if($result) {
  363. echo json_encode(array('message' => '删除成功'));die;
  364. } else {
  365. echo json_encode(array('error' => '删除失败'));die;
  366. }
  367. }
  368. /**
  369. * 专题项目编辑
  370. */
  371. public function special_item_editOp()
  372. {
  373. $model_mb_special = Model('mb_special');
  374. $item_info = $model_mb_special->getMbSpecialItemInfoByID($_GET['item_id']);
  375. if($item_info['has_margin'] == 1) {
  376. $item_info['has_margin'] = 'true';
  377. } else {
  378. $item_info['has_margin'] = 'false';
  379. }
  380. Tpl::output('item_info', $item_info);
  381. if($item_info['special_id'] == 0) {
  382. $this->show_menu('index_edit');
  383. } else {
  384. $this->show_menu('special_item_list');
  385. }
  386. Tpl::showpage('mb_special_item.edit');
  387. }
  388. /**
  389. * 专题项目保存
  390. */
  391. public function special_item_saveOp()
  392. {
  393. $model_mb_special = Model('mb_special');
  394. $bg_type = $_POST['bg_type'];
  395. if($bg_type == 'image') {
  396. $bg_data = $_POST['bg_image_name'];
  397. } else {
  398. $bg_data = $_POST['bg_data'];
  399. if(empty($bg_data)) $bg_data = self::def_item_bg_color;
  400. }
  401. if($_POST['has_margin'] == "true") {
  402. $has_margin = 1;
  403. } else {
  404. $has_margin = 0;
  405. }
  406. $filter = new block_filter($_POST['item_type'],$_POST['special_id'],$_POST['item_data']);
  407. $item_data = $filter->filter();
  408. if($item_data == false) $item_data = $_POST['item_data'];
  409. $updata = array('item_data' => $item_data,'bg_type' => $bg_type,'bg_data' => $bg_data,'bg_image' => $_POST['bg_image_name'],'has_margin' => $has_margin);
  410. $result = $model_mb_special->editMbSpecialItemByID($updata, $_POST['item_id'], $_POST['special_id']);
  411. if($result)
  412. {
  413. if($_POST['special_id'] == $model_mb_special::INDEX_SPECIAL_ID) {
  414. showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'index_edit'));
  415. }
  416. else
  417. {
  418. $ret = $this->other_check($_POST['special_id'],$err);
  419. if($ret) {
  420. showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id'])));
  421. } else {
  422. showMessage($err, urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id'])));
  423. }
  424. }
  425. } else {
  426. showMessage(L('nc_common_save_succ'), '');
  427. }
  428. }
  429. private function other_check($special_id,&$err)
  430. {
  431. $special_id = intval($special_id);
  432. global $config;
  433. $opids = $config['optional_goods'];
  434. if(in_array($special_id,$opids))
  435. {
  436. $layerror = \activity\optional_goods::instance()->layout_error();
  437. if($layerror != false) {
  438. $gids = implode(",",$layerror);
  439. $err = "下列商品 {$gids} 布局错误或者重复添加";
  440. return false;
  441. }
  442. $all_goods = activity\optional_goods::instance()->all_goods();
  443. $err_goods = [];
  444. foreach ($all_goods as $gid)
  445. {
  446. $ret = activity_helper::optional_goods_check($gid,$erret);
  447. if($ret == false) {
  448. $err_goods[] = $gid;
  449. }
  450. }
  451. if(!empty($err_goods)) {
  452. $gids = implode(",",$err_goods);
  453. $err = "下列商品 {$gids} 已经参与了其它活动,不能添加,请处理";
  454. return false;
  455. }
  456. return true;
  457. }
  458. else {
  459. return true;
  460. }
  461. }
  462. /**
  463. * 图片上传
  464. */
  465. public function special_image_uploadOp()
  466. {
  467. $data = array();
  468. if(!empty($_FILES['special_image']['name'])) {
  469. $prefix = 's' . $_POST['special_id'];
  470. $upload = new UploadFile();
  471. $upload->set('default_dir', ATTACH_MOBILE . DS . 'special' . DS . $prefix);
  472. $upload->set('fprefix', $prefix);
  473. $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png'));
  474. $result = $upload->upfile('special_image');
  475. if(!$result) {
  476. $data['error'] = $upload->error;
  477. }
  478. $data['image_name'] = $upload->file_name;
  479. $data['image_url'] = getMbSpecialImageUrl($data['image_name']);
  480. }
  481. echo json_encode($data);
  482. }
  483. /**
  484. * 商品列表
  485. */
  486. public function goods_listOp()
  487. {
  488. $p['keyword'] = urlencode($_REQUEST['keyword']);
  489. $param = new search_param($p);
  490. $params = $param->format();
  491. $result = search\search_client::instance()->get_result($params);
  492. $model_goods = Model('goods');
  493. $goods_list = $model_goods->getGoodsListByColorDistinct(array('goods_commonid' => array('in',$result['cids'])),
  494. 'goods_id,goods_name,goods_promotion_price,goods_image,goods_storage', '', 10);
  495. Tpl::output('goods_list', $goods_list);
  496. Tpl::output('keyword', $_REQUEST['keyword']);
  497. Tpl::output('show_page', $model_goods->showpage());
  498. Tpl::showpage('mb_special_widget.goods', 'null_layout');
  499. }
  500. /**
  501. * 更新项目排序
  502. */
  503. public function update_item_sortOp() {
  504. $item_id_string = $_POST['item_id_string'];
  505. $special_id = $_POST['special_id'];
  506. if(!empty($item_id_string)) {
  507. $model_mb_special = Model('mb_special');
  508. $item_id_array = explode(',', $item_id_string);
  509. $index = 0;
  510. foreach ($item_id_array as $item_id) {
  511. $result = $model_mb_special->editMbSpecialItemByID(array('item_sort' => $index), $item_id, $special_id);
  512. $index++;
  513. }
  514. }
  515. $data = array();
  516. $data['message'] = '操作成功';
  517. echo json_encode($data);
  518. }
  519. /**
  520. * 更新项目启用状态
  521. */
  522. public function update_item_usableOp() {
  523. $model_mb_special = Model('mb_special');
  524. $result = $model_mb_special->editMbSpecialItemUsableByID($_POST['usable'], $_POST['item_id'], $_POST['special_id']);
  525. $data = array();
  526. if($result) {
  527. $data['message'] = '操作成功';
  528. } else {
  529. $data['error'] = '操作失败';
  530. }
  531. echo json_encode($data);
  532. }
  533. public function add_tabOp()
  534. {
  535. $tab_name = $_POST['tab_name'];
  536. $special_id = intval($_POST['special_id']);
  537. $sort = intval($_POST['tab_sort']);
  538. $result = true;
  539. if ($special_id >= 0 && !empty($tab_name) && $sort > 0)
  540. {
  541. $mod_webcode = Model('web_code');
  542. $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
  543. foreach ($tabs as $tab)
  544. {
  545. if($tab['special_id'] == $special_id) {
  546. $result = false;
  547. break;
  548. }
  549. }
  550. if($result == true) {
  551. $tabs[] = array('special_id' => $special_id, 'name' => $tab_name, 'sort' => $sort);
  552. $mod_webcode->edit(self::mb_home_tab_id,serialize($tabs));
  553. } else {
  554. $result = false;
  555. }
  556. }
  557. else {
  558. $result = false;
  559. }
  560. if($result) {
  561. $this->log('添加首页标签' . '[ID:' . $result. ']', 1);
  562. showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'tab_list'));
  563. } else {
  564. $this->log('添加首页标签' . '[ID:' . $result. ']', 0);
  565. showMessage(L('nc_common_save_fail'), urlAdmin('mb_special', 'tab_list'));
  566. }
  567. }
  568. public function del_tabOp()
  569. {
  570. $special_id = $_POST['special_id'];
  571. $result = false;
  572. if ($special_id >= 0)
  573. {
  574. $mod_webcode = Model('web_code');
  575. $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
  576. $tabs_new = [];
  577. foreach ($tabs as $key => $val)
  578. {
  579. if($val['special_id'] != $special_id) {
  580. $tabs_new[] = $val;
  581. } else {
  582. $result = true;
  583. }
  584. }
  585. if($result == true) {
  586. $mod_webcode->edit(self::mb_home_tab_id,serialize($tabs_new));
  587. }
  588. }
  589. if($result) {
  590. $this->log('删除首页标签' . '[ID:' . $_POST['special_id'] . ']', 1);
  591. showMessage(L('nc_common_del_succ'), urlAdmin('mb_special', 'tab_list'));
  592. } else {
  593. $this->log('删除首页标签' . '[ID:' . $_POST['special_id'] . ']', 0);
  594. showMessage(L('nc_common_del_fail'), urlAdmin('mb_special', 'tab_list'));
  595. }
  596. }
  597. public function update_tab_nameOp()
  598. {
  599. $tab_name = $_GET['value'];
  600. $special_id = intval($_GET['id']);
  601. $data = array();
  602. $data['result'] = false;
  603. if ($special_id >= 0 && !empty($tab_name))
  604. {
  605. $mod_webcode = Model('web_code');
  606. $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
  607. foreach ($tabs as &$tab)
  608. {
  609. if($tab['special_id'] == $special_id) {
  610. $tab['name'] = $tab_name;
  611. $data['result'] = true;
  612. break;
  613. }
  614. }
  615. if($data['result'] == true) {
  616. $mod_webcode->edit(self::mb_home_tab_id,serialize($tabs));
  617. }
  618. }
  619. if($data['result'] == true) {
  620. $data['message'] = '操作成功';
  621. } else {
  622. $data['error'] = '操作失败';
  623. }
  624. echo json_encode($data);die;
  625. }
  626. public function update_tab_sortOp()
  627. {
  628. $tab_sort = $_GET['value'];
  629. $special_id = intval($_GET['id']);
  630. $data = array();
  631. $data['result'] = false;
  632. if ($special_id >= 0 && $tab_sort > 0)
  633. {
  634. $mod_webcode = Model('web_code');
  635. $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
  636. foreach ($tabs as &$tab)
  637. {
  638. if($tab['special_id'] == $special_id) {
  639. $tab['sort'] = $tab_sort;
  640. $data['result'] = true;
  641. break;
  642. }
  643. }
  644. if($data['result'] == true) {
  645. $mod_webcode->edit(self::mb_home_tab_id,serialize($tabs));
  646. }
  647. }
  648. if($data['result'] == true) {
  649. $data['message'] = '操作成功';
  650. } else {
  651. $data['error'] = '操作失败';
  652. }
  653. echo json_encode($data);die;
  654. }
  655. /**
  656. * 专题审核
  657. */
  658. public function ugc_listOp()
  659. {
  660. $special_id = intval($_REQUEST['search_special_id']);
  661. $special_desc = trim($_REQUEST['special_desc']);
  662. $state_sel = intval($_REQUEST['state_sel']);
  663. if($special_id > 0) {
  664. $cond = ["special_id" => $special_id];
  665. }
  666. elseif(!empty($special_desc)) {
  667. $cond = ["special_desc" => array('like', "%{$special_desc}%")];
  668. } else {
  669. $cond = [];
  670. }
  671. $cond['from_user'] = 1;
  672. if($state_sel == 1) {
  673. $cond['check_time'] = 0;
  674. $cond['state'] = 0;
  675. }
  676. elseif($state_sel == 2) {
  677. $cond['check_time'] = ['gt',0];
  678. $cond['state'] = 1;
  679. }
  680. elseif($state_sel == 3) {
  681. $cond['check_time'] = ['gt',0];
  682. $cond['state'] = 0;
  683. }
  684. else {
  685. }
  686. $model_mb_special = Model('mb_special');
  687. $items = $model_mb_special->getMbSpecialList($cond, 50);
  688. $uids = [];
  689. foreach ($items as $item) {
  690. $sender = intval($item['member_id']);
  691. $uids[] = $sender;
  692. }
  693. $members = $this->users($uids);
  694. foreach ($items as &$item) {
  695. $userid = intval($item['member_id']);
  696. $item['nickname'] = $members[$userid]['nickname'];
  697. }
  698. Tpl::output('list', $items);
  699. Tpl::output('page', $model_mb_special->showpage(2));
  700. $this->show_menu('ugc_list');
  701. tpl::output('item_title', '用户内容审核');
  702. Tpl::showpage('mb_special.review');
  703. }
  704. private function users($user_ids)
  705. {
  706. if(empty($user_ids)) return [];
  707. $mod_member = Model('member');
  708. $members = $mod_member->getMemberList(array('member_id' => ['in',$user_ids]));
  709. if(empty($members)) return [];
  710. $result = [];
  711. foreach ($members as $item)
  712. {
  713. $member = new member_info($item);
  714. $mid = $member->member_id();
  715. $val['avatar'] = $member->avatar();
  716. $val['nickname'] = $member->nickname();
  717. $result[$mid] = $val;
  718. }
  719. return $result;
  720. }
  721. /**
  722. * 页面内导航菜单
  723. * @param string $menu_key 当前导航的menu_key
  724. * @param array $array 附加菜单
  725. * @return
  726. */
  727. private function show_menu($menu_key='') {
  728. $menu_array = array();
  729. if($menu_key == 'index_edit') {
  730. $menu_array[] = array('menu_key'=>'index_edit', 'menu_name'=>'编辑', 'menu_url'=>'javascript:;');
  731. }
  732. elseif($menu_key == 'special_list' || $menu_key == 'tab_list') {
  733. $menu_array[] = array('menu_key'=>'special_list','menu_name'=>'列表', 'menu_url'=>urlAdmin('mb_special', 'special_list'));
  734. $menu_array[] = array('menu_key'=>'tab_list','menu_name'=>'首页标签', 'menu_url'=>urlAdmin('mb_special', 'tab_list'));
  735. }
  736. else {
  737. $menu_array[] = array('menu_key'=>'ugc_list','menu_name'=>'用户内容列表', 'menu_url'=>urlAdmin('mb_special', 'ugc_list'));
  738. }
  739. if($menu_key == 'special_item_list') {
  740. $menu_array[] = array('menu_key'=>'special_item_list', 'menu_name'=>'编辑专题', 'menu_url'=>'javascript:;');
  741. }
  742. if($menu_key == 'index_edit') {
  743. tpl::output('item_title', '首页编辑');
  744. } else {
  745. tpl::output('item_title', '专题设置');
  746. }
  747. Tpl::output('menu', $menu_array);
  748. Tpl::output('menu_key', $menu_key);
  749. }
  750. public function check_ugcOp()
  751. {
  752. $state = $_GET['state'];
  753. $special_id = intval($_GET['special_id']);
  754. if($special_id > 0)
  755. {
  756. $mod_special = Model('mb_special');
  757. $special_info = $mod_special->getMbSpecialByID($special_id,'*');
  758. $special = new ugc\special($special_info);
  759. if($state == 'pass') {
  760. $mod_special->editUserSpecial($special_id,['special_id' => $special_id], ['state' => 0,'check_time' => time()]);
  761. QueueClient::push('onAsyncUgcPublish',['special_id' => $special_id]);
  762. }
  763. elseif($state == 'unpass') {
  764. $mod_special = Model('mb_special');
  765. $mod_special->editUserSpecial($special_id,['special_id' => $special_id], ['state' => 1,'check_time' => time()]);
  766. QueueClient::push('onAsyncUgcDel',['special_id' => $special_id]);
  767. }
  768. else {
  769. }
  770. }
  771. showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'ugc_list'));
  772. }
  773. }