mb_special.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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. class mb_specialControl extends SystemControl
  17. {
  18. const mb_home_tab_id = 123;
  19. const def_item_bg_color = '#F2F2F2';
  20. const def_item_bg_type = 'color';
  21. public function __construct()
  22. {
  23. parent::__construct();
  24. }
  25. //升级专题数据
  26. public function upgradeOp()
  27. {
  28. $mod_mb_special = Model('mb_special');
  29. //$items = Model()->table('mb_special_item')->where(array('item_type' => 'home7','special_id' => array('gt',10)))->order('special_id desc')->field('*')->limit(2)->select();
  30. $items = Model()->table('mb_special_item')->field('*')->limit(false)->select();
  31. foreach ($items as $item)
  32. {
  33. $filter = new upgrade_helper($item['item_type'],$item['special_id'],unserialize($item['item_data']));
  34. $item_data = $filter->filter();
  35. if($item_data == false) continue;
  36. $result = $mod_mb_special->editMbSpecialItemByID(array('item_data' => $item_data), $item['item_id'], $item['special_id']);
  37. if($result == false) {
  38. echo "upgrade error special_id={$item['special_id']} item_id={$item['item_id']}</br>";
  39. } else {
  40. echo "upgrade success special_id={$item['special_id']} item_id={$item['item_id']}</br>";
  41. }
  42. }
  43. }
  44. /**
  45. * 专题列表
  46. */
  47. public function special_listOp()
  48. {
  49. $model_mb_special = Model('mb_special');
  50. $mb_special_list = $model_mb_special->getMbSpecialList($array, 10);
  51. Tpl::output('list', $mb_special_list);
  52. Tpl::output('page', $model_mb_special->showpage(2));
  53. $this->show_menu('special_list');
  54. Tpl::showpage('mb_special.list');
  55. }
  56. public function tab_listOp()
  57. {
  58. $mod_webcode = Model('web_code');
  59. $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
  60. $this->show_menu('tab_list');
  61. Tpl::output('tabs', $tabs);
  62. Tpl::showpage('mb_special.tab');
  63. }
  64. /**
  65. * 保存专题
  66. */
  67. public function special_saveOp()
  68. {
  69. $model_mb_special = Model('mb_special');
  70. $param = array();
  71. $param['special_desc'] = $_POST['special_desc'];
  72. $result = $model_mb_special->addMbSpecial($param);
  73. if($result) {
  74. $this->log('添加手机专题' . '[ID:' . $result. ']', 1);
  75. showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'special_list'));
  76. } else {
  77. $this->log('添加手机专题' . '[ID:' . $result. ']', 0);
  78. showMessage(L('nc_common_save_fail'), urlAdmin('mb_special', 'special_list'));
  79. }
  80. }
  81. /**
  82. * 编辑专题描述
  83. */
  84. public function update_special_descOp() {
  85. $model_mb_special = Model('mb_special');
  86. $param = array();
  87. $param['special_desc'] = $_GET['value'];
  88. $result = $model_mb_special->editMbSpecial($param, $_GET['id']);
  89. $data = array();
  90. if($result) {
  91. $this->log('保存手机专题' . '[ID:' . $result. ']', 1);
  92. $data['result'] = true;
  93. } else {
  94. $this->log('保存手机专题' . '[ID:' . $result. ']', 0);
  95. $data['result'] = false;
  96. $data['message'] = '保存失败';
  97. }
  98. echo json_encode($data);die;
  99. }
  100. /**
  101. * 删除专题
  102. */
  103. public function special_delOp()
  104. {
  105. $model_mb_special = Model('mb_special');
  106. $result = $model_mb_special->delMbSpecialByID($_POST['special_id']);
  107. if($result) {
  108. $this->log('删除手机专题' . '[ID:' . $_POST['special_id'] . ']', 1);
  109. showMessage(L('nc_common_del_succ'), urlAdmin('mb_special', 'special_list'));
  110. } else {
  111. $this->log('删除手机专题' . '[ID:' . $_POST['special_id'] . ']', 0);
  112. showMessage(L('nc_common_del_fail'), urlAdmin('mb_special', 'special_list'));
  113. }
  114. }
  115. /**
  116. * 编辑首页
  117. */
  118. public function index_editOp()
  119. {
  120. $model_mb_special = Model('mb_special');
  121. $special_item_list = $model_mb_special->getMbSpecialItemListByID($model_mb_special::INDEX_SPECIAL_ID);
  122. Tpl::output('list', $special_item_list);
  123. Tpl::output('page', $model_mb_special->showpage(2));
  124. Tpl::output('module_list', $model_mb_special->getMbSpecialModuleList());
  125. Tpl::output('special_id', $model_mb_special::INDEX_SPECIAL_ID);
  126. $this->show_menu('index_edit');
  127. Tpl::showpage('mb_special_item.list');
  128. }
  129. /**
  130. * 编辑专题
  131. */
  132. public function special_editOp() {
  133. $model_mb_special = Model('mb_special');
  134. $special_item_list = $model_mb_special->getMbSpecialItemListByID($_GET['special_id']);
  135. Tpl::output('list', $special_item_list);
  136. Tpl::output('page', $model_mb_special->showpage(2));
  137. Tpl::output('module_list', $model_mb_special->getMbSpecialModuleList());
  138. Tpl::output('special_id', $_GET['special_id']);
  139. $this->show_menu('special_item_list');
  140. Tpl::showpage('mb_special_item.list');
  141. }
  142. /**
  143. * 专题项目添加
  144. */
  145. public function special_item_addOp()
  146. {
  147. $item_info = $this->add_item($_POST['special_id'],$_POST['item_type']);
  148. if($item_info) {
  149. echo json_encode($item_info);die;
  150. } else {
  151. echo json_encode(array('error' => '添加失败'));die;
  152. }
  153. }
  154. private function add_item($special_id,$item_type)
  155. {
  156. $model_mb_special = Model('mb_special');
  157. $param = array();
  158. $param['special_id'] = $special_id;
  159. $param['item_type'] = $item_type;
  160. $param['bg_image'] = '';
  161. $param['bg_type'] = self::def_item_bg_type;
  162. $param['bg_data'] = self::def_item_bg_color;
  163. $param['has_margin'] = 0;
  164. $item_info = $model_mb_special->addMbSpecialItem($param);
  165. return $item_info;
  166. }
  167. //专题项目插入分割线
  168. public function add_frontOp()
  169. {
  170. $item_type = $_POST['item_type'];
  171. $special_id = intval($_POST['special_id']);
  172. $item_info = $this->add_item($special_id,$item_type);
  173. if($item_info == false) {
  174. echo json_encode(array('error' => '添加失败'));die;
  175. }
  176. $sel_item_id = intval($_POST['sel_item_id']);
  177. $insert_item_id = intval($item_info['item_id']);
  178. $model_mb_special = Model('mb_special');
  179. $special_item_list = $model_mb_special->getMbSpecialItemListByID($special_id);
  180. $item_ids = [];
  181. foreach ($special_item_list as $item)
  182. {
  183. $item_id = intval($item['item_id']);
  184. if($item_id == $sel_item_id) {
  185. $item_ids[] = $insert_item_id;
  186. $item_ids[] = $item_id;
  187. }
  188. elseif($item_id == $insert_item_id) {
  189. continue;
  190. }
  191. else {
  192. $item_ids[] = $item_id;
  193. }
  194. }
  195. $index = 0;
  196. foreach ($item_ids as $item_id) {
  197. $result = $model_mb_special->editMbSpecialItemByID(array('item_sort' => $index), $item_id, $special_id);
  198. $index++;
  199. }
  200. $data = array();
  201. $data['message'] = '操作成功';
  202. echo json_encode($data);
  203. }
  204. public function move_itemOp()
  205. {
  206. $special_id = intval($_POST['special_id']);
  207. $src_id = intval($_POST['src_id']);
  208. $desc_id = intval($_POST['dest_id']);
  209. $href = urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id']));
  210. if($src_id == $desc_id || $src_id <= 0 || $desc_id <= 0) {
  211. showMessage(L('nc_common_save_fail'), $href);
  212. }
  213. else
  214. {
  215. $model_mb_special = Model('mb_special');
  216. $special_item_list = $model_mb_special->getMbSpecialItemListByID($special_id);
  217. $nfind = 0;
  218. $item_ids = [];
  219. foreach ($special_item_list as $item)
  220. {
  221. $item_id = intval($item['item_id']);
  222. if($item_id == $desc_id) {
  223. $item_ids[] = $src_id;
  224. $item_ids[] = $desc_id;
  225. $nfind += 1;
  226. }
  227. elseif($item_id == $src_id) {
  228. $nfind += 1;
  229. continue;
  230. }
  231. else {
  232. $item_ids[] = $item_id;
  233. }
  234. }
  235. if($nfind == 2)
  236. {
  237. $index = 0;
  238. foreach ($item_ids as $item_id) {
  239. $result = $model_mb_special->editMbSpecialItemByID(array('item_sort' => $index), $item_id, $special_id);
  240. $index++;
  241. }
  242. showMessage(L('nc_common_save_succ'),$href);
  243. }
  244. else {
  245. showMessage(L('nc_common_save_fail'), $href);
  246. }
  247. }
  248. }
  249. /**
  250. * 专题项目删除
  251. */
  252. public function special_item_delOp() {
  253. $model_mb_special = Model('mb_special');
  254. $condition = array();
  255. $condition['item_id'] = $_POST['item_id'];
  256. $result = $model_mb_special->delMbSpecialItem($condition, $_POST['special_id']);
  257. if($result) {
  258. echo json_encode(array('message' => '删除成功'));die;
  259. } else {
  260. echo json_encode(array('error' => '删除失败'));die;
  261. }
  262. }
  263. /**
  264. * 专题项目编辑
  265. */
  266. public function special_item_editOp()
  267. {
  268. $model_mb_special = Model('mb_special');
  269. $item_info = $model_mb_special->getMbSpecialItemInfoByID($_GET['item_id']);
  270. if($item_info['has_margin'] == 1) {
  271. $item_info['has_margin'] = 'true';
  272. } else {
  273. $item_info['has_margin'] = 'false';
  274. }
  275. Tpl::output('item_info', $item_info);
  276. if($item_info['special_id'] == 0) {
  277. $this->show_menu('index_edit');
  278. } else {
  279. $this->show_menu('special_item_list');
  280. }
  281. Tpl::showpage('mb_special_item.edit');
  282. }
  283. /**
  284. * 专题项目保存
  285. */
  286. public function special_item_saveOp()
  287. {
  288. $model_mb_special = Model('mb_special');
  289. $bg_type = $_POST['bg_type'];
  290. if($bg_type == 'image') {
  291. $bg_data = $_POST['bg_image_name'];
  292. } else {
  293. $bg_data = $_POST['bg_data'];
  294. if(empty($bg_data)) $bg_data = self::def_item_bg_color;
  295. }
  296. if($_POST['has_margin'] == "true") {
  297. $has_margin = 1;
  298. } else {
  299. $has_margin = 0;
  300. }
  301. $filter = new block_filter($_POST['item_type'],$_POST['special_id'],$_POST['item_data']);
  302. $item_data = $filter->filter();
  303. if($item_data == false) $item_data = $_POST['item_data'];
  304. $updata = array('item_data' => $item_data,'bg_type' => $bg_type,'bg_data' => $bg_data,'bg_image' => $_POST['bg_image_name'],'has_margin' => $has_margin);
  305. $result = $model_mb_special->editMbSpecialItemByID($updata, $_POST['item_id'], $_POST['special_id']);
  306. if($result) {
  307. if($_POST['special_id'] == $model_mb_special::INDEX_SPECIAL_ID) {
  308. showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'index_edit'));
  309. } else {
  310. showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id'])));
  311. }
  312. } else {
  313. showMessage(L('nc_common_save_succ'), '');
  314. }
  315. }
  316. /**
  317. * 图片上传
  318. */
  319. public function special_image_uploadOp() {
  320. $data = array();
  321. if(!empty($_FILES['special_image']['name'])) {
  322. $prefix = 's' . $_POST['special_id'];
  323. $upload = new UploadFile();
  324. $upload->set('default_dir', ATTACH_MOBILE . DS . 'special' . DS . $prefix);
  325. $upload->set('fprefix', $prefix);
  326. $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png'));
  327. $result = $upload->upfile('special_image');
  328. if(!$result) {
  329. $data['error'] = $upload->error;
  330. }
  331. $data['image_name'] = $upload->file_name;
  332. $data['image_url'] = getMbSpecialImageUrl($data['image_name']);
  333. }
  334. echo json_encode($data);
  335. }
  336. /**
  337. * 商品列表
  338. */
  339. public function goods_listOp()
  340. {
  341. //$model_goods = Model('goods');
  342. // $condition = array();
  343. // $condition['goods_name'] = array('like', '%' . $_REQUEST['keyword'] . '%');
  344. // $goods_list = $model_goods->getGoodsOnlineList($condition, 'goods_id,goods_name,goods_promotion_price,goods_image,goods_storage', 10);
  345. $p['keyword'] = urlencode($_REQUEST['keyword']);
  346. $param = new search_param($p);
  347. $params = $param->format();
  348. $cids = search\tcp_client::instance()->get_result($params);
  349. $model_goods = Model('goods');
  350. $goods_list = $model_goods->getGoodsListByColorDistinct(array('goods_commonid' => array('in',$cids['cids'])),
  351. 'goods_id,goods_name,goods_promotion_price,goods_image,goods_storage', '', 10);
  352. Tpl::output('goods_list', $goods_list);
  353. Tpl::output('keyword', $_REQUEST['keyword']);
  354. Tpl::output('show_page', $model_goods->showpage());
  355. Tpl::showpage('mb_special_widget.goods', 'null_layout');
  356. }
  357. /**
  358. * 更新项目排序
  359. */
  360. public function update_item_sortOp() {
  361. $item_id_string = $_POST['item_id_string'];
  362. $special_id = $_POST['special_id'];
  363. if(!empty($item_id_string)) {
  364. $model_mb_special = Model('mb_special');
  365. $item_id_array = explode(',', $item_id_string);
  366. $index = 0;
  367. foreach ($item_id_array as $item_id) {
  368. $result = $model_mb_special->editMbSpecialItemByID(array('item_sort' => $index), $item_id, $special_id);
  369. $index++;
  370. }
  371. }
  372. $data = array();
  373. $data['message'] = '操作成功';
  374. echo json_encode($data);
  375. }
  376. /**
  377. * 更新项目启用状态
  378. */
  379. public function update_item_usableOp() {
  380. $model_mb_special = Model('mb_special');
  381. $result = $model_mb_special->editMbSpecialItemUsableByID($_POST['usable'], $_POST['item_id'], $_POST['special_id']);
  382. $data = array();
  383. if($result) {
  384. $data['message'] = '操作成功';
  385. } else {
  386. $data['error'] = '操作失败';
  387. }
  388. echo json_encode($data);
  389. }
  390. public function add_tabOp()
  391. {
  392. $tab_name = $_POST['tab_name'];
  393. $special_id = intval($_POST['special_id']);
  394. $sort = intval($_POST['tab_sort']);
  395. $result = true;
  396. if ($special_id >= 0 && !empty($tab_name) && $sort > 0)
  397. {
  398. $mod_webcode = Model('web_code');
  399. $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
  400. foreach ($tabs as $tab)
  401. {
  402. if($tab['special_id'] == $special_id) {
  403. $result = false;
  404. break;
  405. }
  406. }
  407. if($result == true) {
  408. $tabs[] = array('special_id' => $special_id, 'name' => $tab_name, 'sort' => $sort);
  409. $mod_webcode->edit(self::mb_home_tab_id,serialize($tabs));
  410. } else {
  411. $result = false;
  412. }
  413. }
  414. else {
  415. $result = false;
  416. }
  417. if($result) {
  418. $this->log('添加首页标签' . '[ID:' . $result. ']', 1);
  419. showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'tab_list'));
  420. } else {
  421. $this->log('添加首页标签' . '[ID:' . $result. ']', 0);
  422. showMessage(L('nc_common_save_fail'), urlAdmin('mb_special', 'tab_list'));
  423. }
  424. }
  425. public function del_tabOp()
  426. {
  427. $special_id = $_POST['special_id'];
  428. $result = false;
  429. if ($special_id >= 0)
  430. {
  431. $mod_webcode = Model('web_code');
  432. $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
  433. $tabs_new = [];
  434. foreach ($tabs as $key => $val)
  435. {
  436. if($val['special_id'] != $special_id) {
  437. $tabs_new[] = $val;
  438. } else {
  439. $result = true;
  440. }
  441. }
  442. if($result == true) {
  443. $mod_webcode->edit(self::mb_home_tab_id,serialize($tabs_new));
  444. }
  445. }
  446. if($result) {
  447. $this->log('删除首页标签' . '[ID:' . $_POST['special_id'] . ']', 1);
  448. showMessage(L('nc_common_del_succ'), urlAdmin('mb_special', 'tab_list'));
  449. } else {
  450. $this->log('删除首页标签' . '[ID:' . $_POST['special_id'] . ']', 0);
  451. showMessage(L('nc_common_del_fail'), urlAdmin('mb_special', 'tab_list'));
  452. }
  453. }
  454. public function update_tab_nameOp()
  455. {
  456. $tab_name = $_GET['value'];
  457. $special_id = intval($_GET['id']);
  458. $data = array();
  459. $data['result'] = false;
  460. if ($special_id >= 0 && !empty($tab_name))
  461. {
  462. $mod_webcode = Model('web_code');
  463. $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
  464. foreach ($tabs as &$tab)
  465. {
  466. if($tab['special_id'] == $special_id) {
  467. $tab['name'] = $tab_name;
  468. $data['result'] = true;
  469. break;
  470. }
  471. }
  472. if($data['result'] == true) {
  473. $mod_webcode->edit(self::mb_home_tab_id,serialize($tabs));
  474. }
  475. }
  476. if($data['result'] == true) {
  477. $data['message'] = '操作成功';
  478. } else {
  479. $data['error'] = '操作失败';
  480. }
  481. echo json_encode($data);die;
  482. }
  483. public function update_tab_sortOp()
  484. {
  485. $tab_sort = $_GET['value'];
  486. $special_id = intval($_GET['id']);
  487. $data = array();
  488. $data['result'] = false;
  489. if ($special_id >= 0 && $tab_sort > 0)
  490. {
  491. $mod_webcode = Model('web_code');
  492. $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
  493. foreach ($tabs as &$tab)
  494. {
  495. if($tab['special_id'] == $special_id) {
  496. $tab['sort'] = $tab_sort;
  497. $data['result'] = true;
  498. break;
  499. }
  500. }
  501. if($data['result'] == true) {
  502. $mod_webcode->edit(self::mb_home_tab_id,serialize($tabs));
  503. }
  504. }
  505. if($data['result'] == true) {
  506. $data['message'] = '操作成功';
  507. } else {
  508. $data['error'] = '操作失败';
  509. }
  510. echo json_encode($data);die;
  511. }
  512. /**
  513. * 页面内导航菜单
  514. * @param string $menu_key 当前导航的menu_key
  515. * @param array $array 附加菜单
  516. * @return
  517. */
  518. private function show_menu($menu_key='') {
  519. $menu_array = array();
  520. if($menu_key == 'index_edit') {
  521. $menu_array[] = array('menu_key'=>'index_edit', 'menu_name'=>'编辑', 'menu_url'=>'javascript:;');
  522. } else {
  523. $menu_array[] = array('menu_key'=>'special_list','menu_name'=>'列表', 'menu_url'=>urlAdmin('mb_special', 'special_list'));
  524. $menu_array[] = array('menu_key'=>'tab_list','menu_name'=>'首页标签', 'menu_url'=>urlAdmin('mb_special', 'tab_list'));
  525. }
  526. if($menu_key == 'special_item_list') {
  527. $menu_array[] = array('menu_key'=>'special_item_list', 'menu_name'=>'编辑专题', 'menu_url'=>'javascript:;');
  528. }
  529. if($menu_key == 'index_edit') {
  530. tpl::output('item_title', '首页编辑');
  531. } else {
  532. tpl::output('item_title', '专题设置');
  533. }
  534. Tpl::output('menu', $menu_array);
  535. Tpl::output('menu_key', $menu_key);
  536. }
  537. }