Sellerplate.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Sellerplate extends BaseSeller {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerplate.lang.php');
  20. }
  21. public function index() {
  22. $this->plate_list();
  23. }
  24. /**
  25. * 关联版式列表
  26. */
  27. public function plate_list() {
  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. if (!request()->isPost()) {
  56. $plate_info = array(
  57. 'storeplate_name' => '',
  58. 'storeplate_position' => '',
  59. 'storeplate_content' => '',
  60. );
  61. View::assign('plate_info', $plate_info);
  62. /* 设置卖家当前菜单 */
  63. $this->setSellerCurMenu('sellerplate');
  64. /* 设置卖家当前栏目 */
  65. $this->setSellerCurItem('plate_add');
  66. return View::fetch($this->template_dir . 'plate_add');
  67. } else {
  68. $insert = array();
  69. $insert['storeplate_name'] = input('post.p_name');
  70. $insert['storeplate_position'] = input('post.p_position');
  71. $insert['storeplate_content'] = input('post.p_content');
  72. $insert['store_id'] = session('store_id');
  73. $sellerplate_validate = ds_validate('sellerplate');
  74. if (!$sellerplate_validate->scene('plate_add')->check($insert)) {
  75. ds_json_encode(10001, lang('error') . $sellerplate_validate->getError());
  76. }
  77. $result = model('storeplate')->addStoreplate($insert);
  78. if ($result) {
  79. ds_json_encode(10000, lang('ds_common_op_succ'));
  80. } else {
  81. ds_json_encode(10001, lang('ds_common_op_fail'));
  82. }
  83. }
  84. }
  85. /**
  86. * 关联版式编辑
  87. */
  88. public function plate_edit() {
  89. $storeplate_id = intval(input('param.p_id'));
  90. if ($storeplate_id <= 0) {
  91. $this->error(lang('param_error'));
  92. }
  93. if (!request()->isPost()) {
  94. $plate_info = model('storeplate')->getStoreplateInfo(array('storeplate_id' => $storeplate_id, 'store_id' => session('store_id')));
  95. View::assign('plate_info', $plate_info);
  96. /* 设置卖家当前菜单 */
  97. $this->setSellerCurMenu('sellerplate');
  98. /* 设置卖家当前栏目 */
  99. $this->setSellerCurItem('plate_edit');
  100. return View::fetch($this->template_dir . 'plate_add');
  101. } else {
  102. $update = array();
  103. $update['storeplate_name'] = input('post.p_name');
  104. $update['storeplate_position'] = input('post.p_position');
  105. $update['storeplate_content'] = input('post.p_content');
  106. //验证数据 BEGIN
  107. $sellerplate_validate = ds_validate('sellerplate');
  108. if (!$sellerplate_validate->scene('plate_edit')->check($update)) {
  109. ds_json_encode(10001, lang('error') . $sellerplate_validate->getError());
  110. }
  111. //验证数据 END
  112. $condition = array();
  113. $condition[] = array('storeplate_id','=',$storeplate_id);
  114. $condition[] = array('store_id','=',session('store_id'));
  115. $result = model('storeplate')->editStoreplate($update, $condition);
  116. if ($result) {
  117. ds_json_encode(10000, lang('ds_common_op_succ'));
  118. } else {
  119. ds_json_encode(10001, lang('ds_common_op_fail'));
  120. }
  121. }
  122. }
  123. /**
  124. * 删除关联版式
  125. */
  126. public function drop_plate() {
  127. $storeplate_id = input('param.p_id');
  128. if (!preg_match('/^[\d,]+$/i', $storeplate_id)) {
  129. ds_json_encode(10001, lang('param_error'));
  130. }
  131. $plateid_array = explode(',', $storeplate_id);
  132. $return = model('storeplate')->delStoreplate(array(array('storeplate_id', 'in', $plateid_array), array('store_id' ,'=', session('store_id'))));
  133. if ($return) {
  134. ds_json_encode(10000, lang('ds_common_del_succ'));
  135. } else {
  136. ds_json_encode(10001, lang('ds_common_del_fail'));
  137. }
  138. }
  139. /**
  140. * 用户中心右边,小导航
  141. *
  142. * @param string $menu_type 导航类型
  143. * @param string $menu_key 当前导航的menu_key
  144. * @return
  145. */
  146. function getSellerItemList() {
  147. $item_list = array(
  148. array(
  149. 'name' => 'plate_list',
  150. 'text' => lang('associated_format'),
  151. 'url' => (string) url('Sellerplate/plate_list'),
  152. ),
  153. );
  154. if (request()->action() == 'plate_add') {
  155. $item_list[] = array(
  156. 'name' => 'plate_add',
  157. 'text' => lang('ds_new'),
  158. 'url' => (string) url('Sellerplate/plate_add'),
  159. );
  160. }
  161. if (request()->action() == 'plate_edit') {
  162. $item_list[] = array(
  163. 'name' => 'plate_add',
  164. 'text' => lang('ds_new'),
  165. 'url' => (string) url('Sellerplate/plate_add'),
  166. );
  167. $item_list[] = array(
  168. 'name' => 'plate_edit',
  169. 'text' => lang('ds_edit'),
  170. 'url' => (string) url('Sellerplate/plate_edit'),
  171. );
  172. }
  173. return $item_list;
  174. }
  175. }
  176. ?>