Selleraccount.php 9.4 KB

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