mb_special.php 20 KB

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