mb_special.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <?php
  2. /**
  3. * 手机专题
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class mb_specialControl extends SystemControl{
  11. public function __construct(){
  12. parent::__construct();
  13. }
  14. /**
  15. * 专题列表
  16. */
  17. public function special_listOp() {
  18. $model_mb_special = Model('mb_special');
  19. $mb_special_list = $model_mb_special->getMbSpecialList($array, 10);
  20. Tpl::output('list', $mb_special_list);
  21. Tpl::output('page', $model_mb_special->showpage(2));
  22. $this->show_menu('special_list');
  23. Tpl::showpage('mb_special.list');
  24. }
  25. /**
  26. * 保存专题
  27. */
  28. public function special_saveOp() {
  29. $model_mb_special = Model('mb_special');
  30. $param = array();
  31. $param['special_desc'] = $_POST['special_desc'];
  32. $result = $model_mb_special->addMbSpecial($param);
  33. if($result) {
  34. $this->log('添加手机专题' . '[ID:' . $result. ']', 1);
  35. showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'special_list'));
  36. } else {
  37. $this->log('添加手机专题' . '[ID:' . $result. ']', 0);
  38. showMessage(L('nc_common_save_fail'), urlAdmin('mb_special', 'special_list'));
  39. }
  40. }
  41. /**
  42. * 编辑专题描述
  43. */
  44. public function update_special_descOp() {
  45. $model_mb_special = Model('mb_special');
  46. $param = array();
  47. $param['special_desc'] = $_GET['value'];
  48. $result = $model_mb_special->editMbSpecial($param, $_GET['id']);
  49. $data = array();
  50. if($result) {
  51. $this->log('保存手机专题' . '[ID:' . $result. ']', 1);
  52. $data['result'] = true;
  53. } else {
  54. $this->log('保存手机专题' . '[ID:' . $result. ']', 0);
  55. $data['result'] = false;
  56. $data['message'] = '保存失败';
  57. }
  58. echo json_encode($data);die;
  59. }
  60. /**
  61. * 删除专题
  62. */
  63. public function special_delOp() {
  64. $model_mb_special = Model('mb_special');
  65. $result = $model_mb_special->delMbSpecialByID($_POST['special_id']);
  66. if($result) {
  67. $this->log('删除手机专题' . '[ID:' . $_POST['special_id'] . ']', 1);
  68. showMessage(L('nc_common_del_succ'), urlAdmin('mb_special', 'special_list'));
  69. } else {
  70. $this->log('删除手机专题' . '[ID:' . $_POST['special_id'] . ']', 0);
  71. showMessage(L('nc_common_del_fail'), urlAdmin('mb_special', 'special_list'));
  72. }
  73. }
  74. /**
  75. * 编辑首页
  76. */
  77. public function index_editOp() {
  78. $model_mb_special = Model('mb_special');
  79. $special_item_list = $model_mb_special->getMbSpecialItemListByID($model_mb_special::INDEX_SPECIAL_ID);
  80. Tpl::output('list', $special_item_list);
  81. Tpl::output('page', $model_mb_special->showpage(2));
  82. Tpl::output('module_list', $model_mb_special->getMbSpecialModuleList());
  83. Tpl::output('special_id', $model_mb_special::INDEX_SPECIAL_ID);
  84. $this->show_menu('index_edit');
  85. Tpl::showpage('mb_special_item.list');
  86. }
  87. /**
  88. * 编辑专题
  89. */
  90. public function special_editOp() {
  91. $model_mb_special = Model('mb_special');
  92. $special_item_list = $model_mb_special->getMbSpecialItemListByID($_GET['special_id']);
  93. Tpl::output('list', $special_item_list);
  94. Tpl::output('page', $model_mb_special->showpage(2));
  95. Tpl::output('module_list', $model_mb_special->getMbSpecialModuleList());
  96. Tpl::output('special_id', $_GET['special_id']);
  97. $this->show_menu('special_item_list');
  98. Tpl::showpage('mb_special_item.list');
  99. }
  100. /**
  101. * 专题项目添加
  102. */
  103. public function special_item_addOp() {
  104. $model_mb_special = Model('mb_special');
  105. $param = array();
  106. $param['special_id'] = $_POST['special_id'];
  107. $param['item_type'] = $_POST['item_type'];
  108. //广告只能添加一个
  109. // if($param['item_type'] == 'adv_list') {
  110. // $result = $model_mb_special->isMbSpecialItemExist($param);
  111. // if($result) {
  112. // echo json_encode(array('error' => '广告条板块只能添加一个'));die;
  113. // }
  114. // }
  115. $item_info = $model_mb_special->addMbSpecialItem($param);
  116. if($item_info) {
  117. echo json_encode($item_info);die;
  118. } else {
  119. echo json_encode(array('error' => '添加失败'));die;
  120. }
  121. }
  122. /**
  123. * 专题项目删除
  124. */
  125. public function special_item_delOp() {
  126. $model_mb_special = Model('mb_special');
  127. $condition = array();
  128. $condition['item_id'] = $_POST['item_id'];
  129. $result = $model_mb_special->delMbSpecialItem($condition, $_POST['special_id']);
  130. if($result) {
  131. echo json_encode(array('message' => '删除成功'));die;
  132. } else {
  133. echo json_encode(array('error' => '删除失败'));die;
  134. }
  135. }
  136. /**
  137. * 专题项目编辑
  138. */
  139. public function special_item_editOp() {
  140. $model_mb_special = Model('mb_special');
  141. $item_info = $model_mb_special->getMbSpecialItemInfoByID($_GET['item_id']);
  142. Tpl::output('item_info', $item_info);
  143. if($item_info['special_id'] == 0) {
  144. $this->show_menu('index_edit');
  145. } else {
  146. $this->show_menu('special_item_list');
  147. }
  148. Tpl::showpage('mb_special_item.edit');
  149. }
  150. /**
  151. * 专题项目保存
  152. */
  153. public function special_item_saveOp() {
  154. $model_mb_special = Model('mb_special');
  155. $result = $model_mb_special->editMbSpecialItemByID(array('item_data' => $_POST['item_data']), $_POST['item_id'], $_POST['special_id']);
  156. if($result) {
  157. if($_POST['special_id'] == $model_mb_special::INDEX_SPECIAL_ID) {
  158. showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'index_edit'));
  159. } else {
  160. showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id'])));
  161. }
  162. } else {
  163. showMessage(L('nc_common_save_succ'), '');
  164. }
  165. }
  166. /**
  167. * 图片上传
  168. */
  169. public function special_image_uploadOp() {
  170. $data = array();
  171. if(!empty($_FILES['special_image']['name'])) {
  172. $prefix = 's' . $_POST['special_id'];
  173. $upload = new UploadFile();
  174. $upload->set('default_dir', ATTACH_MOBILE . DS . 'special' . DS . $prefix);
  175. $upload->set('fprefix', $prefix);
  176. $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png'));
  177. $result = $upload->upfile('special_image');
  178. if(!$result) {
  179. $data['error'] = $upload->error;
  180. }
  181. $data['image_name'] = $upload->file_name;
  182. $data['image_url'] = getMbSpecialImageUrl($data['image_name']);
  183. }
  184. echo json_encode($data);
  185. }
  186. /**
  187. * 商品列表
  188. */
  189. public function goods_listOp() {
  190. $model_goods = Model('goods');
  191. $condition = array();
  192. $condition['goods_name'] = array('like', '%' . $_REQUEST['keyword'] . '%');
  193. $goods_list = $model_goods->getGoodsOnlineList($condition, 'goods_id,goods_name,goods_promotion_price,goods_image', 10);
  194. Tpl::output('goods_list', $goods_list);
  195. Tpl::output('keyword', $_REQUEST['keyword']);
  196. Tpl::output('show_page', $model_goods->showpage());
  197. Tpl::showpage('mb_special_widget.goods', 'null_layout');
  198. }
  199. /**
  200. * 更新项目排序
  201. */
  202. public function update_item_sortOp() {
  203. $item_id_string = $_POST['item_id_string'];
  204. $special_id = $_POST['special_id'];
  205. if(!empty($item_id_string)) {
  206. $model_mb_special = Model('mb_special');
  207. $item_id_array = explode(',', $item_id_string);
  208. $index = 0;
  209. foreach ($item_id_array as $item_id) {
  210. $result = $model_mb_special->editMbSpecialItemByID(array('item_sort' => $index), $item_id, $special_id);
  211. $index++;
  212. }
  213. }
  214. $data = array();
  215. $data['message'] = '操作成功';
  216. echo json_encode($data);
  217. }
  218. /**
  219. * 更新项目启用状态
  220. */
  221. public function update_item_usableOp() {
  222. $model_mb_special = Model('mb_special');
  223. $result = $model_mb_special->editMbSpecialItemUsableByID($_POST['usable'], $_POST['item_id'], $_POST['special_id']);
  224. $data = array();
  225. if($result) {
  226. $data['message'] = '操作成功';
  227. } else {
  228. $data['error'] = '操作失败';
  229. }
  230. echo json_encode($data);
  231. }
  232. /**
  233. * 页面内导航菜单
  234. * @param string $menu_key 当前导航的menu_key
  235. * @param array $array 附加菜单
  236. * @return
  237. */
  238. private function show_menu($menu_key='') {
  239. $menu_array = array();
  240. if($menu_key == 'index_edit') {
  241. $menu_array[] = array('menu_key'=>'index_edit', 'menu_name'=>'编辑', 'menu_url'=>'javascript:;');
  242. } else {
  243. $menu_array[] = array('menu_key'=>'special_list','menu_name'=>'列表', 'menu_url'=>urlAdmin('mb_special', 'special_list'));
  244. }
  245. if($menu_key == 'special_item_list') {
  246. $menu_array[] = array('menu_key'=>'special_item_list', 'menu_name'=>'编辑专题', 'menu_url'=>'javascript:;');
  247. }
  248. if($menu_key == 'index_edit') {
  249. tpl::output('item_title', '首页编辑');
  250. } else {
  251. tpl::output('item_title', '专题设置');
  252. }
  253. Tpl::output('menu', $menu_array);
  254. Tpl::output('menu_key', $menu_key);
  255. }
  256. }