Selleraccount.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Selleraccount extends BaseSeller {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/selleraccount.lang.php');
  20. }
  21. public function account_list() {
  22. $seller_model = model('seller');
  23. $condition = array(
  24. array('seller.store_id' ,'=', session('store_id')),
  25. array('seller.sellergroup_id','>', 0)
  26. );
  27. $seller_list = $seller_model->getSellerList($condition);
  28. View::assign('seller_list', $seller_list);
  29. $sellergroup_model = model('sellergroup');
  30. $seller_group_list = $sellergroup_model->getSellergroupList(array('store_id' => session('store_id')));
  31. $seller_group_array = array_under_reset($seller_group_list, 'sellergroup_id');
  32. View::assign('seller_group_array', $seller_group_array);
  33. /* 设置卖家当前菜单 */
  34. $this->setSellerCurMenu('selleraccount');
  35. /* 设置卖家当前栏目 */
  36. $this->setSellerCurItem('account_list');
  37. return View::fetch($this->template_dir.'account_list');
  38. }
  39. public function account_add() {
  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. if (!request()->isPost()) {
  81. $seller_id = intval(input('param.seller_id'));
  82. if ($seller_id <= 0) {
  83. $this->error(lang('param_error'));
  84. }
  85. $seller_model = model('seller');
  86. $seller_info = $seller_model->getSellerInfo(array('seller_id' => $seller_id));
  87. if (empty($seller_info) || intval($seller_info['store_id']) !== intval(session('store_id'))) {
  88. $this->error(lang('account_not_exist'));
  89. }
  90. View::assign('seller_info', $seller_info);
  91. $sellergroup_model = model('sellergroup');
  92. $seller_group_list = $sellergroup_model->getSellergroupList(array('store_id' => session('store_id')));
  93. if (empty($seller_group_list)) {
  94. $this->error(lang('please_set_account_group_first'), (string)url('Selleraccountgroup/group_add'));
  95. }
  96. View::assign('seller_group_list', $seller_group_list);
  97. /* 设置卖家当前菜单 */
  98. $this->setSellerCurMenu('selleraccount');
  99. /* 设置卖家当前栏目 */
  100. $this->setSellerCurItem('account_edit');
  101. return View::fetch($this->template_dir . 'account_edit');
  102. } else {
  103. $param = array('sellergroup_id' => intval(input('post.group_id')));
  104. $condition = array();
  105. $condition[] = array('seller_id','=',intval(input('post.seller_id')));
  106. $condition[] = array('store_id','=',session('store_id'));
  107. $seller_model = model('seller');
  108. $result = $seller_model->editSeller($param, $condition);
  109. if ($result) {
  110. $this->recordSellerlog(lang('edit_account_successfully') . input('post.seller_id'));
  111. ds_json_encode(10000,lang('ds_common_op_succ'));
  112. } else {
  113. $this->recordSellerlog(lang('edit_account_failed') . input('post.seller_id'), 0);
  114. ds_json_encode(10001,lang('ds_common_save_fail'));
  115. }
  116. }
  117. }
  118. public function account_del() {
  119. $seller_id = intval(input('post.seller_id'));
  120. if($seller_id > 0) {
  121. $condition = array();
  122. $condition[] = array('seller_id','=',$seller_id);
  123. $condition[] = array('store_id','=',session('store_id'));
  124. $seller_model = model('seller');
  125. $result = $seller_model->delSeller($condition);
  126. if($result) {
  127. $this->recordSellerlog(lang('delete_account_successfully').$seller_id);
  128. ds_json_encode(10000,lang('ds_common_op_succ'));
  129. } else {
  130. $this->recordSellerlog(lang('deletion_account_failed').$seller_id);
  131. ds_json_encode(10001,lang('ds_common_save_fail'));
  132. }
  133. } else {
  134. ds_json_encode(10001,lang('param_error'));
  135. }
  136. }
  137. public function check_seller_name_exist() {
  138. $seller_name = input('get.seller_name');
  139. $result = $this->_is_seller_name_exist($seller_name);
  140. if($result) {
  141. echo 'true';
  142. } else {
  143. echo 'false';
  144. }
  145. }
  146. private function _is_seller_name_exist($seller_name) {
  147. $condition = array();
  148. $condition[] = array('seller_name','=',$seller_name);
  149. $seller_model = model('seller');
  150. return $seller_model->isSellerExist($condition);
  151. }
  152. public function check_seller_member() {
  153. $member_name = input('get.member_name');
  154. $password = input('get.password');
  155. $result = $this->_check_seller_member($member_name, $password);
  156. if($result) {
  157. echo 'true';
  158. } else {
  159. echo 'false';
  160. }
  161. }
  162. private function _check_seller_member($member_name, $password) {
  163. $member_info = $this->_check_member_password($member_name, $password);
  164. if($member_info && !$this->_is_seller_member_exist($member_info['member_id'])) {
  165. return $member_info;
  166. } else {
  167. return false;
  168. }
  169. }
  170. private function _check_member_password($member_name, $password) {
  171. $condition = array();
  172. $condition[] = array('member_name', '=', $member_name);
  173. $condition[] = array('member_password', '=', md5($password));
  174. $member_model = model('member');
  175. $member_info = $member_model->getMemberInfo($condition);
  176. return $member_info;
  177. }
  178. private function _is_seller_member_exist($member_id) {
  179. $condition = array();
  180. $condition[] = array('member_id', '=', $member_id);
  181. $seller_model = model('seller');
  182. return $seller_model->isSellerExist($condition);
  183. }
  184. /**
  185. * 栏目菜单
  186. */
  187. function getSellerItemList() {
  188. $menu_array[] = array(
  189. 'name' => 'account_list',
  190. 'text' => lang('account_list'),
  191. 'url' => (string)url('Selleraccount/account_list'),
  192. );
  193. if (request()->action() === 'account_add') {
  194. $menu_array[] = array(
  195. 'name' => 'account_add',
  196. 'text' => lang('add_account'),
  197. 'url' => (string)url('Selleraccount/account_add'),
  198. );
  199. }
  200. if (request()->action() === 'group_edit') {
  201. $menu_array[] = array(
  202. 'name' => 'account_edit',
  203. 'text' => lang('edit_account'),
  204. 'url' => 'javascript:void(0)',
  205. );
  206. }
  207. return $menu_array;
  208. }
  209. }