Sellerplate.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Sellerplate extends BaseSeller {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerplate.lang.php');
  21. }
  22. public function index() {
  23. $this->plate_list();
  24. }
  25. /**
  26. * 关联版式列表
  27. */
  28. public function plate_list() {
  29. // 版式列表
  30. $where = array();
  31. $where[] = array('store_id', '=', session('store_id'));
  32. $p_name = trim(input('get.p_name'));
  33. if ($p_name != '') {
  34. $where[] = array('storeplate_name', 'like', '%' . $p_name . '%');
  35. }
  36. $p_position = trim(input('get.p_position'));
  37. if (in_array($p_position, array('0', '1'))) {
  38. $where[] = array('storeplate_position', '=', $p_position);
  39. }
  40. $store_plate = model('storeplate');
  41. $plate_list = $store_plate->getStoreplateList($where, '*', 10);
  42. View::assign('show_page', $store_plate->page_info->render());
  43. View::assign('plate_list', $plate_list);
  44. View::assign('position', array(0 => lang('bottom'), 1 => lang('top')));
  45. /* 设置卖家当前菜单 */
  46. $this->setSellerCurMenu('sellerplate');
  47. /* 设置卖家当前栏目 */
  48. $this->setSellerCurItem('plate_list');
  49. echo View::fetch($this->template_dir . 'plate_list');
  50. exit;
  51. }
  52. /**
  53. * 关联版式添加
  54. */
  55. public function plate_add() {
  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. $storeplate_id = intval(input('param.p_id'));
  91. if ($storeplate_id <= 0) {
  92. $this->error(lang('param_error'));
  93. }
  94. if (!request()->isPost()) {
  95. $plate_info = model('storeplate')->getStoreplateInfo(array('storeplate_id' => $storeplate_id, 'store_id' => session('store_id')));
  96. View::assign('plate_info', $plate_info);
  97. /* 设置卖家当前菜单 */
  98. $this->setSellerCurMenu('sellerplate');
  99. /* 设置卖家当前栏目 */
  100. $this->setSellerCurItem('plate_edit');
  101. return View::fetch($this->template_dir . 'plate_add');
  102. } else {
  103. $update = array();
  104. $update['storeplate_name'] = input('post.p_name');
  105. $update['storeplate_position'] = input('post.p_position');
  106. $update['storeplate_content'] = input('post.p_content');
  107. //验证数据 BEGIN
  108. $sellerplate_validate = ds_validate('sellerplate');
  109. if (!$sellerplate_validate->scene('plate_edit')->check($update)) {
  110. ds_json_encode(10001, lang('error') . $sellerplate_validate->getError());
  111. }
  112. //验证数据 END
  113. $condition = array();
  114. $condition[] = array('storeplate_id','=',$storeplate_id);
  115. $condition[] = array('store_id','=',session('store_id'));
  116. $result = model('storeplate')->editStoreplate($update, $condition);
  117. if ($result) {
  118. ds_json_encode(10000, lang('ds_common_op_succ'));
  119. } else {
  120. ds_json_encode(10001, lang('ds_common_op_fail'));
  121. }
  122. }
  123. }
  124. /**
  125. * 删除关联版式
  126. */
  127. public function drop_plate() {
  128. $storeplate_id = input('param.p_id');
  129. if (!preg_match('/^[\d,]+$/i', $storeplate_id)) {
  130. ds_json_encode(10001, lang('param_error'));
  131. }
  132. $plateid_array = explode(',', $storeplate_id);
  133. $return = model('storeplate')->delStoreplate(array(array('storeplate_id', 'in', $plateid_array), array('store_id' ,'=', session('store_id'))));
  134. if ($return) {
  135. ds_json_encode(10000, lang('ds_common_del_succ'));
  136. } else {
  137. ds_json_encode(10001, lang('ds_common_del_fail'));
  138. }
  139. }
  140. /**
  141. * 用户中心右边,小导航
  142. *
  143. * @param string $menu_type 导航类型
  144. * @param string $menu_key 当前导航的menu_key
  145. * @return
  146. */
  147. function getSellerItemList() {
  148. $item_list = array(
  149. array(
  150. 'name' => 'plate_list',
  151. 'text' => lang('associated_format'),
  152. 'url' => (string) url('Sellerplate/plate_list'),
  153. ),
  154. );
  155. if (request()->action() == 'plate_add') {
  156. $item_list[] = array(
  157. 'name' => 'plate_add',
  158. 'text' => lang('ds_new'),
  159. 'url' => (string) url('Sellerplate/plate_add'),
  160. );
  161. }
  162. if (request()->action() == 'plate_edit') {
  163. $item_list[] = array(
  164. 'name' => 'plate_add',
  165. 'text' => lang('ds_new'),
  166. 'url' => (string) url('Sellerplate/plate_add'),
  167. );
  168. $item_list[] = array(
  169. 'name' => 'plate_edit',
  170. 'text' => lang('ds_edit'),
  171. 'url' => (string) url('Sellerplate/plate_edit'),
  172. );
  173. }
  174. return $item_list;
  175. }
  176. }
  177. ?>