Sellerplate.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Sellerplate extends BaseSeller
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerplate.lang.php');
  18. }
  19. public function index()
  20. {
  21. $this->plate_list();
  22. }
  23. /**
  24. * 关联版式列表
  25. */
  26. public function plate_list()
  27. {
  28. // 版式列表
  29. $where = array();
  30. $where[] = array('store_id', '=', session('store_id'));
  31. $p_name = trim(input('get.p_name'));
  32. if ($p_name != '') {
  33. $where[] = array('storeplate_name', 'like', '%' . $p_name . '%');
  34. }
  35. $p_position = trim(input('get.p_position'));
  36. if (in_array($p_position, array('0', '1'))) {
  37. $where[] = array('storeplate_position', '=', $p_position);
  38. }
  39. $store_plate = model('storeplate');
  40. $plate_list = $store_plate->getStoreplateList($where, '*', 10);
  41. View::assign('show_page', $store_plate->page_info->render());
  42. View::assign('plate_list', $plate_list);
  43. View::assign('position', array(0 => lang('bottom'), 1 => lang('top')));
  44. /* 设置卖家当前菜单 */
  45. $this->setSellerCurMenu('sellerplate');
  46. /* 设置卖家当前栏目 */
  47. $this->setSellerCurItem('plate_list');
  48. echo View::fetch($this->template_dir . 'plate_list');
  49. exit;
  50. }
  51. /**
  52. * 关联版式添加
  53. */
  54. public function plate_add()
  55. {
  56. if (!request()->isPost()) {
  57. $plate_info = array(
  58. 'storeplate_name' => '',
  59. 'storeplate_position' => '',
  60. 'storeplate_content' => '',
  61. );
  62. View::assign('plate_info', $plate_info);
  63. /* 设置卖家当前菜单 */
  64. $this->setSellerCurMenu('sellerplate');
  65. /* 设置卖家当前栏目 */
  66. $this->setSellerCurItem('plate_add');
  67. return View::fetch($this->template_dir . 'plate_add');
  68. } else {
  69. $insert = array();
  70. $insert['storeplate_name'] = input('post.p_name');
  71. $insert['storeplate_position'] = input('post.p_position');
  72. $insert['storeplate_content'] = input('post.p_content');
  73. $insert['store_id'] = session('store_id');
  74. $sellerplate_validate = ds_validate('sellerplate');
  75. if (!$sellerplate_validate->scene('plate_add')->check($insert)) {
  76. ds_json_encode(10001, lang('error') . $sellerplate_validate->getError());
  77. }
  78. $result = model('storeplate')->addStoreplate($insert);
  79. if ($result) {
  80. ds_json_encode(10000, lang('ds_common_op_succ'));
  81. } else {
  82. ds_json_encode(10001, lang('ds_common_op_fail'));
  83. }
  84. }
  85. }
  86. /**
  87. * 关联版式编辑
  88. */
  89. public function plate_edit()
  90. {
  91. $storeplate_id = intval(input('param.p_id'));
  92. if ($storeplate_id <= 0) {
  93. $this->error(lang('param_error'));
  94. }
  95. if (!request()->isPost()) {
  96. $plate_info = model('storeplate')->getStoreplateInfo(array('storeplate_id' => $storeplate_id, 'store_id' => session('store_id')));
  97. View::assign('plate_info', $plate_info);
  98. /* 设置卖家当前菜单 */
  99. $this->setSellerCurMenu('sellerplate');
  100. /* 设置卖家当前栏目 */
  101. $this->setSellerCurItem('plate_edit');
  102. return View::fetch($this->template_dir . 'plate_add');
  103. } else {
  104. $update = array();
  105. $update['storeplate_name'] = input('post.p_name');
  106. $update['storeplate_position'] = input('post.p_position');
  107. $update['storeplate_content'] = input('post.p_content');
  108. //验证数据 BEGIN
  109. $sellerplate_validate = ds_validate('sellerplate');
  110. if (!$sellerplate_validate->scene('plate_edit')->check($update)) {
  111. ds_json_encode(10001, lang('error') . $sellerplate_validate->getError());
  112. }
  113. //验证数据 END
  114. $condition = array();
  115. $condition[] = array('storeplate_id', '=', $storeplate_id);
  116. $condition[] = array('store_id', '=', session('store_id'));
  117. $result = model('storeplate')->editStoreplate($update, $condition);
  118. if ($result) {
  119. ds_json_encode(10000, lang('ds_common_op_succ'));
  120. } else {
  121. ds_json_encode(10001, lang('ds_common_op_fail'));
  122. }
  123. }
  124. }
  125. /**
  126. * 删除关联版式
  127. */
  128. public function drop_plate()
  129. {
  130. $storeplate_id = input('param.p_id');
  131. if (!preg_match('/^[\d,]+$/i', $storeplate_id)) {
  132. ds_json_encode(10001, lang('param_error'));
  133. }
  134. $plateid_array = explode(',', $storeplate_id);
  135. $return = model('storeplate')->delStoreplate(array(array('storeplate_id', 'in', $plateid_array), array('store_id', '=', session('store_id'))));
  136. if ($return) {
  137. ds_json_encode(10000, lang('ds_common_del_succ'));
  138. } else {
  139. ds_json_encode(10001, lang('ds_common_del_fail'));
  140. }
  141. }
  142. /**
  143. * 用户中心右边,小导航
  144. *
  145. * @param string $menu_type 导航类型
  146. * @param string $menu_key 当前导航的menu_key
  147. * @return
  148. */
  149. function getSellerItemList()
  150. {
  151. $item_list = array(
  152. array(
  153. 'name' => 'plate_list',
  154. 'text' => lang('associated_format'),
  155. 'url' => (string) url('Sellerplate/plate_list'),
  156. ),
  157. );
  158. if (request()->action() == 'plate_add') {
  159. $item_list[] = array(
  160. 'name' => 'plate_add',
  161. 'text' => lang('ds_new'),
  162. 'url' => (string) url('Sellerplate/plate_add'),
  163. );
  164. }
  165. if (request()->action() == 'plate_edit') {
  166. $item_list[] = array(
  167. 'name' => 'plate_add',
  168. 'text' => lang('ds_new'),
  169. 'url' => (string) url('Sellerplate/plate_add'),
  170. );
  171. $item_list[] = array(
  172. 'name' => 'plate_edit',
  173. 'text' => lang('ds_edit'),
  174. 'url' => (string) url('Sellerplate/plate_edit'),
  175. );
  176. }
  177. return $item_list;
  178. }
  179. }