Selleraccount.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 Selleraccount extends BaseSeller
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/selleraccount.lang.php');
  18. }
  19. public function account_list()
  20. {
  21. $seller_model = model('seller');
  22. $condition = array(
  23. array('seller.store_id', '=', session('store_id')),
  24. array('seller.sellergroup_id', '>', 0)
  25. );
  26. $seller_list = $seller_model->getSellerList($condition);
  27. View::assign('seller_list', $seller_list);
  28. $sellergroup_model = model('sellergroup');
  29. $seller_group_list = $sellergroup_model->getSellergroupList(array('store_id' => session('store_id')));
  30. $seller_group_array = array_under_reset($seller_group_list, 'sellergroup_id');
  31. View::assign('seller_group_array', $seller_group_array);
  32. /* 设置卖家当前菜单 */
  33. $this->setSellerCurMenu('selleraccount');
  34. /* 设置卖家当前栏目 */
  35. $this->setSellerCurItem('account_list');
  36. return View::fetch($this->template_dir . 'account_list');
  37. }
  38. public function account_add()
  39. {
  40. if (!request()->isPost()) {
  41. $sellergroup_model = model('sellergroup');
  42. $seller_group_list = $sellergroup_model->getSellergroupList(array('store_id' => session('store_id')));
  43. if (empty($seller_group_list)) {
  44. $this->error(lang('please_set_account_group_first'), (string)url('Selleraccountgroup/group_add'));
  45. }
  46. View::assign('seller_group_list', $seller_group_list);
  47. /* 设置卖家当前菜单 */
  48. $this->setSellerCurMenu('selleraccount');
  49. /* 设置卖家当前栏目 */
  50. $this->setSellerCurItem('account_add');
  51. return View::fetch($this->template_dir . 'account_add');
  52. } else {
  53. $member_name = input('post.member_name');
  54. $password = input('post.password');
  55. $member_info = $this->_check_seller_member($member_name, $password);
  56. if (!$member_info) {
  57. ds_json_encode(10001, lang('user_authentication_failed'));
  58. }
  59. $seller_name = $member_name;
  60. $group_id = intval(input('post.group_id'));
  61. $seller_info = array(
  62. 'seller_name' => $seller_name,
  63. 'member_id' => $member_info['member_id'],
  64. 'sellergroup_id' => $group_id,
  65. 'store_id' => session('store_id'),
  66. 'is_admin' => 0
  67. );
  68. $seller_model = model('seller');
  69. $result = $seller_model->addSeller($seller_info);
  70. if ($result) {
  71. $this->recordSellerlog(lang('add_account_successfully') . $result);
  72. ds_json_encode(10000, lang('ds_common_op_succ'));
  73. } else {
  74. $this->recordSellerlog(lang('failed_add_account'));
  75. ds_json_encode(10001, lang('ds_common_save_fail'));
  76. }
  77. }
  78. }
  79. public function account_edit()
  80. {
  81. if (!request()->isPost()) {
  82. $seller_id = intval(input('param.seller_id'));
  83. if ($seller_id <= 0) {
  84. $this->error(lang('param_error'));
  85. }
  86. $seller_model = model('seller');
  87. $seller_info = $seller_model->getSellerInfo(array('seller_id' => $seller_id));
  88. if (empty($seller_info) || intval($seller_info['store_id']) !== intval(session('store_id'))) {
  89. $this->error(lang('account_not_exist'));
  90. }
  91. View::assign('seller_info', $seller_info);
  92. $sellergroup_model = model('sellergroup');
  93. $seller_group_list = $sellergroup_model->getSellergroupList(array('store_id' => session('store_id')));
  94. if (empty($seller_group_list)) {
  95. $this->error(lang('please_set_account_group_first'), (string)url('Selleraccountgroup/group_add'));
  96. }
  97. View::assign('seller_group_list', $seller_group_list);
  98. /* 设置卖家当前菜单 */
  99. $this->setSellerCurMenu('selleraccount');
  100. /* 设置卖家当前栏目 */
  101. $this->setSellerCurItem('account_edit');
  102. return View::fetch($this->template_dir . 'account_edit');
  103. } else {
  104. $param = array('sellergroup_id' => intval(input('post.group_id')));
  105. $condition = array();
  106. $condition[] = array('seller_id', '=', intval(input('post.seller_id')));
  107. $condition[] = array('store_id', '=', session('store_id'));
  108. $seller_model = model('seller');
  109. $result = $seller_model->editSeller($param, $condition);
  110. if ($result) {
  111. $this->recordSellerlog(lang('edit_account_successfully') . input('post.seller_id'));
  112. ds_json_encode(10000, lang('ds_common_op_succ'));
  113. } else {
  114. $this->recordSellerlog(lang('edit_account_failed') . input('post.seller_id'), 0);
  115. ds_json_encode(10001, lang('ds_common_save_fail'));
  116. }
  117. }
  118. }
  119. public function account_del()
  120. {
  121. $seller_id = intval(input('post.seller_id'));
  122. if ($seller_id > 0) {
  123. $condition = array();
  124. $condition[] = array('seller_id', '=', $seller_id);
  125. $condition[] = array('store_id', '=', session('store_id'));
  126. $seller_model = model('seller');
  127. $result = $seller_model->delSeller($condition);
  128. if ($result) {
  129. $this->recordSellerlog(lang('delete_account_successfully') . $seller_id);
  130. ds_json_encode(10000, lang('ds_common_op_succ'));
  131. } else {
  132. $this->recordSellerlog(lang('deletion_account_failed') . $seller_id);
  133. ds_json_encode(10001, lang('ds_common_save_fail'));
  134. }
  135. } else {
  136. ds_json_encode(10001, lang('param_error'));
  137. }
  138. }
  139. public function check_seller_name_exist()
  140. {
  141. $seller_name = input('get.seller_name');
  142. $result = $this->_is_seller_name_exist($seller_name);
  143. if ($result) {
  144. echo 'true';
  145. } else {
  146. echo 'false';
  147. }
  148. }
  149. private function _is_seller_name_exist($seller_name)
  150. {
  151. $condition = array();
  152. $condition[] = array('seller_name', '=', $seller_name);
  153. $seller_model = model('seller');
  154. return $seller_model->isSellerExist($condition);
  155. }
  156. public function check_seller_member()
  157. {
  158. $member_name = input('get.member_name');
  159. $password = input('get.password');
  160. $result = $this->_check_seller_member($member_name, $password);
  161. if ($result) {
  162. echo 'true';
  163. } else {
  164. echo 'false';
  165. }
  166. }
  167. private function _check_seller_member($member_name, $password)
  168. {
  169. $member_info = $this->_check_member_password($member_name, $password);
  170. if ($member_info && !$this->_is_seller_member_exist($member_info['member_id'])) {
  171. return $member_info;
  172. } else {
  173. return false;
  174. }
  175. }
  176. private function _check_member_password($member_name, $password)
  177. {
  178. $condition = array();
  179. $condition[] = array('member_name', '=', $member_name);
  180. $condition[] = array('member_password', '=', md5($password));
  181. $member_model = model('member');
  182. $member_info = $member_model->getMemberInfo($condition);
  183. return $member_info;
  184. }
  185. private function _is_seller_member_exist($member_id)
  186. {
  187. $condition = array();
  188. $condition[] = array('member_id', '=', $member_id);
  189. $seller_model = model('seller');
  190. return $seller_model->isSellerExist($condition);
  191. }
  192. /**
  193. * 栏目菜单
  194. */
  195. function getSellerItemList()
  196. {
  197. $menu_array[] = array(
  198. 'name' => 'account_list',
  199. 'text' => lang('account_list'),
  200. 'url' => (string)url('Selleraccount/account_list'),
  201. );
  202. if (request()->action() === 'account_add') {
  203. $menu_array[] = array(
  204. 'name' => 'account_add',
  205. 'text' => lang('add_account'),
  206. 'url' => (string)url('Selleraccount/account_add'),
  207. );
  208. }
  209. if (request()->action() === 'group_edit') {
  210. $menu_array[] = array(
  211. 'name' => 'account_edit',
  212. 'text' => lang('edit_account'),
  213. 'url' => 'javascript:void(0)',
  214. );
  215. }
  216. return $menu_array;
  217. }
  218. }