mb_special.php 22 KB

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