Selleraccountgroup.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 Selleraccountgroup extends BaseSeller
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/selleraccount.lang.php');
  21. }
  22. public function group_list()
  23. {
  24. $sellergroup_model = model('sellergroup');
  25. $seller_group_list = $sellergroup_model->getSellergroupList(array('store_id' => session('store_id')));
  26. View::assign('seller_group_list', $seller_group_list);
  27. /* 设置卖家当前菜单 */
  28. $this->setSellerCurMenu('selleraccountgroup');
  29. /* 设置卖家当前栏目 */
  30. $this->setSellerCurItem('group_list');
  31. return View::fetch($this->template_dir . 'group_list');
  32. }
  33. public function group_add()
  34. {
  35. $seller_group_info = array(
  36. 'sellergroup_id' => 0,
  37. 'sellergroup_name' => '',
  38. 'sellergroup_limits' => '',
  39. 'smt_limits' => ''
  40. );
  41. View::assign('group_info', $seller_group_info);
  42. View::assign('group_limits', explode(',', $seller_group_info['sellergroup_limits']));
  43. View::assign('smt_limits', explode(',', $seller_group_info['smt_limits']));
  44. // 店铺消息模板列表
  45. $smt_list = model('storemsgtpl')->getStoremsgtplList(array(), 'storemt_code,storemt_name');
  46. View::assign('smt_list', $smt_list);
  47. /* 设置卖家当前菜单 */
  48. $this->setSellerCurMenu('selleraccountgroup');
  49. /* 设置卖家当前栏目 */
  50. $this->setSellerCurItem('group_add');
  51. return View::fetch($this->template_dir . 'group_add');
  52. }
  53. public function group_edit()
  54. {
  55. $group_id = intval(input('param.group_id'));
  56. if ($group_id <= 0) {
  57. $this->error(lang('param_error'));
  58. }
  59. $sellergroup_model = model('sellergroup');
  60. $seller_group_info = $sellergroup_model->getSellergroupInfo(array('sellergroup_id' => $group_id, 'store_id' => session('store_id')));
  61. if (empty($seller_group_info)) {
  62. $this->error(lang('there_no_group'));
  63. }
  64. View::assign('group_info', $seller_group_info);
  65. View::assign('group_limits', explode('|', $seller_group_info['sellergroup_limits']));
  66. View::assign('smt_limits', explode(',', $seller_group_info['smt_limits']));
  67. // 店铺消息模板列表
  68. $smt_list = model('storemsgtpl')->getStoremsgtplList(array(), 'storemt_code,storemt_name');
  69. View::assign('smt_list', $smt_list);
  70. /* 设置卖家当前菜单 */
  71. $this->setSellerCurMenu('selleraccountgroup');
  72. /* 设置卖家当前栏目 */
  73. $this->setSellerCurItem('group_edit');
  74. return View::fetch($this->template_dir . 'group_add');
  75. }
  76. public function group_save()
  77. {
  78. $seller_info = array();
  79. $group_id = intval(input('param.group_id'));
  80. $seller_info['sellergroup_name'] = input('post.seller_group_name');
  81. $seller_info['sellergroup_limits'] = implode('|', input('post.limits/a'));
  82. $seller_info['smt_limits'] = empty(input('post.smt_limits/a')) ? '' : implode(',', input('post.smt_limits/a'));
  83. $seller_info['store_id'] = session('store_id');
  84. $sellergroup_model = model('sellergroup');
  85. if (empty($group_id)) {
  86. $result = $sellergroup_model->addSellergroup($seller_info);
  87. $this->recordSellerlog(lang('add_group_successfully') . $result);
  88. if ($result) {
  89. ds_json_encode(10001, lang('add_success'));
  90. } else {
  91. ds_json_encode(10001, lang('add_failure'));
  92. }
  93. } else {
  94. $condition = array();
  95. $condition[] = array('sellergroup_id', '=', $group_id);
  96. $condition[] = array('store_id', '=', session('store_id'));
  97. $result = $sellergroup_model->editSellergroup($seller_info, $condition);
  98. $this->recordSellerlog(lang('editorial_team_succeeds') . $group_id);
  99. if ($result) {
  100. ds_json_encode(10000, lang('edit_success'));
  101. } else {
  102. ds_json_encode(10001, lang('edit_failure'));
  103. }
  104. }
  105. }
  106. public function group_del()
  107. {
  108. $group_id = intval(input('param.group_id'));
  109. if ($group_id > 0) {
  110. //判断当前用户组下是否有用户
  111. $condition = array();
  112. $condition[] = array('seller.store_id', '=', session('store_id'));
  113. $condition[] = array('seller.sellergroup_id', '=', $group_id);
  114. $seller_list = model('seller')->getSellerList($condition);
  115. if (!empty($seller_list)) {
  116. ds_json_encode(10001, lang('please_change_account_group'));
  117. }
  118. $condition = array();
  119. $condition[] = array('sellergroup_id', '=', $group_id);
  120. $condition[] = array('store_id', '=', session('store_id'));
  121. $sellergroup_model = model('sellergroup');
  122. $result = $sellergroup_model->delSellergroup($condition);
  123. if ($result) {
  124. $this->recordSellerlog(lang('group_deleted_successfully') . $group_id);
  125. ds_json_encode(10000, lang('ds_common_op_succ'));
  126. } else {
  127. $this->recordSellerlog(lang('deletion_group_failed') . $group_id);
  128. ds_json_encode(10001, lang('ds_common_save_fail'));
  129. }
  130. } else {
  131. ds_json_encode(10001, lang('param_error'));
  132. }
  133. }
  134. /**
  135. * 栏目菜单
  136. */
  137. function getSellerItemList()
  138. {
  139. $menu_array[] = array(
  140. 'name' => 'group_list',
  141. 'text' => lang('group_list'),
  142. 'url' => (string)url('Selleraccountgroup/group_list'),
  143. );
  144. if (request()->action() === 'group_add') {
  145. $menu_array[] = array(
  146. 'name' => 'group_add',
  147. 'text' => lang('add_group'),
  148. 'url' => (string)url('Selleraccountgroup/group_add'),
  149. );
  150. }
  151. if (request()->action() === 'group_edit') {
  152. $menu_array[] = array(
  153. 'name' => 'group_edit',
  154. 'text' => lang('editorial_team'),
  155. 'url' => 'javascript:void(0)',
  156. );
  157. }
  158. return $menu_array;
  159. }
  160. }