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