Selleraccount.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 = $member_name;
  61. $group_id = intval(input('post.group_id'));
  62. $seller_info = array(
  63. 'seller_name' => $seller_name,
  64. 'member_id' => $member_info['member_id'],
  65. 'sellergroup_id' => $group_id,
  66. 'store_id' => session('store_id'),
  67. 'is_admin' => 0
  68. );
  69. $seller_model = model('seller');
  70. $result = $seller_model->addSeller($seller_info);
  71. if ($result) {
  72. $this->recordSellerlog(lang('add_account_successfully') . $result);
  73. ds_json_encode(10000,lang('ds_common_op_succ'));
  74. } else {
  75. $this->recordSellerlog(lang('failed_add_account'));
  76. ds_json_encode(10001,lang('ds_common_save_fail'));
  77. }
  78. }
  79. }
  80. public function account_edit() {
  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. $seller_id = intval(input('post.seller_id'));
  121. if($seller_id > 0) {
  122. $condition = array();
  123. $condition[] = array('seller_id','=',$seller_id);
  124. $condition[] = array('store_id','=',session('store_id'));
  125. $seller_model = model('seller');
  126. $result = $seller_model->delSeller($condition);
  127. if($result) {
  128. $this->recordSellerlog(lang('delete_account_successfully').$seller_id);
  129. ds_json_encode(10000,lang('ds_common_op_succ'));
  130. } else {
  131. $this->recordSellerlog(lang('deletion_account_failed').$seller_id);
  132. ds_json_encode(10001,lang('ds_common_save_fail'));
  133. }
  134. } else {
  135. ds_json_encode(10001,lang('param_error'));
  136. }
  137. }
  138. public function check_seller_name_exist() {
  139. $seller_name = input('get.seller_name');
  140. $result = $this->_is_seller_name_exist($seller_name);
  141. if($result) {
  142. echo 'true';
  143. } else {
  144. echo 'false';
  145. }
  146. }
  147. private function _is_seller_name_exist($seller_name) {
  148. $condition = array();
  149. $condition[] = array('seller_name','=',$seller_name);
  150. $seller_model = model('seller');
  151. return $seller_model->isSellerExist($condition);
  152. }
  153. public function check_seller_member() {
  154. $member_name = input('get.member_name');
  155. $password = input('get.password');
  156. $result = $this->_check_seller_member($member_name, $password);
  157. if($result) {
  158. echo 'true';
  159. } else {
  160. echo 'false';
  161. }
  162. }
  163. private function _check_seller_member($member_name, $password) {
  164. $member_info = $this->_check_member_password($member_name, $password);
  165. if($member_info && !$this->_is_seller_member_exist($member_info['member_id'])) {
  166. return $member_info;
  167. } else {
  168. return false;
  169. }
  170. }
  171. private function _check_member_password($member_name, $password) {
  172. $condition = array();
  173. $condition[] = array('member_name', '=', $member_name);
  174. $condition[] = array('member_password', '=', md5($password));
  175. $member_model = model('member');
  176. $member_info = $member_model->getMemberInfo($condition);
  177. return $member_info;
  178. }
  179. private function _is_seller_member_exist($member_id) {
  180. $condition = array();
  181. $condition[] = array('member_id', '=', $member_id);
  182. $seller_model = model('seller');
  183. return $seller_model->isSellerExist($condition);
  184. }
  185. /**
  186. * 栏目菜单
  187. */
  188. function getSellerItemList() {
  189. $menu_array[] = array(
  190. 'name' => 'account_list',
  191. 'text' => lang('account_list'),
  192. 'url' => (string)url('Selleraccount/account_list'),
  193. );
  194. if (request()->action() === 'account_add') {
  195. $menu_array[] = array(
  196. 'name' => 'account_add',
  197. 'text' => lang('add_account'),
  198. 'url' => (string)url('Selleraccount/account_add'),
  199. );
  200. }
  201. if (request()->action() === 'group_edit') {
  202. $menu_array[] = array(
  203. 'name' => 'account_edit',
  204. 'text' => lang('edit_account'),
  205. 'url' => 'javascript:void(0)',
  206. );
  207. }
  208. return $menu_array;
  209. }
  210. }