Sellerplate.php 6.9 KB

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