ShopAdminController.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. namespace hd\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\shop\classes\ShopClass;
  5. use bizGhs\admin\services\AdminService;
  6. use bizGhs\shop\classes\ShopAdminClass;
  7. use bizHd\admin\services\AdminRoleService;
  8. use bizHd\admin\services\ShopAdminService;
  9. use bizHd\wx\services\WxOpenService;
  10. use common\components\dict;
  11. use common\components\imgUtil;
  12. use common\components\sms;
  13. use common\components\stringUtil;
  14. use common\components\util;
  15. use Yii;
  16. class ShopAdminController extends BaseController
  17. {
  18. public $guestAccess = ['generate-admin'];
  19. //获取添加员工的验证码 shish 20210117
  20. public function actionGetStaffAuthCode()
  21. {
  22. $get = Yii::$app->request->get();
  23. $mobile = $get['mobile'] ?? '';
  24. if (stringUtil::isMobile($mobile) == false) {
  25. util::fail('请输入正确手机号');
  26. }
  27. $rand = rand(11111, 99999);
  28. $minute = 10;
  29. sms::send($mobile . ',' . $rand . ',' . $minute, '您的员工验证码:{$var},{$var}分钟内有效');
  30. $ptStyle = Yii::$app->params['ptStyle'];
  31. $cacheKey = 'add_staff_auth_code_' . $ptStyle . '_' . $mobile;
  32. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 600, $rand]);
  33. util::complete();
  34. }
  35. //添加员工
  36. public function actionAddStaff()
  37. {
  38. $shopAdmin = $this->shopAdmin;
  39. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  40. util::fail('没有权限');
  41. }
  42. $post = Yii::$app->request->post();
  43. $authCode = $post['authCode'] ?? '';
  44. $mobile = $post['mobile'] ?? '';
  45. $name = $post['name'] ?? '';
  46. //避免重复提交
  47. util::checkRepeatCommit($mobile, 10);
  48. $ptStyle = Yii::$app->params['ptStyle'];
  49. $cacheKey = 'add_staff_auth_code_' . $ptStyle . '_' . $mobile;
  50. $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  51. if (empty($saveAuthCode)) {
  52. util::fail('请填写验证码哦');
  53. }
  54. if (empty($authCode)) {
  55. util::fail('请填写验证码');
  56. }
  57. if ($saveAuthCode != $authCode) {
  58. util::fail('验证码错误');
  59. }
  60. $adminInfo = ['name' => $name, 'mobile' => $mobile, 'style' => $ptStyle,];
  61. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  62. $admin = AdminService::replaceAdmin($adminInfo, $fromApp);
  63. $post['shopId'] = $this->shopId;
  64. $respond = \bizGhs\shop\services\ShopAdminService::appGenerateStaff($post, $admin);
  65. util::success($respond);
  66. }
  67. //创建管理员数据准备 ssh 2020.4.17
  68. public function actionPrepareBind()
  69. {
  70. $post = Yii::$app->request->post();
  71. $roleId = isset($post['roleId']) ? $post['roleId'] : 0;
  72. $shopAdmin = $this->shopAdmin->attributes;
  73. if ($shopAdmin['super'] != 1) {
  74. util::fail('超管才能操作');
  75. }
  76. $role = AdminRoleService::getById($roleId);
  77. if (empty($role) || isset($role['sjId']) != $this->sjId) {
  78. util::fail('请选择角色!');
  79. }
  80. unset($post['userId']);
  81. unset($post['status']);
  82. $post['shopId'] = $this->shopId;
  83. $post['adminId'] = $this->adminId;
  84. $merchant = WxOpenService::getWxInfo();
  85. $post['merchant'] = $merchant;
  86. $respond = ShopAdminService::prepareBindAdmin($post);
  87. $miniCode = isset($respond['miniCode']) ? imgUtil::getPrefix() . $respond['miniCode'] : '';
  88. util::success(['miniCode' => $miniCode]);
  89. }
  90. //创建管理员 ssh 2020.4.20
  91. public function actionGenerateAdmin()
  92. {
  93. $post = Yii::$app->request->post();
  94. $post['adminId'] = $this->adminId;
  95. $admin = $this->admin->attributes;
  96. $currentShopId = $admin['currentShopId'] ?? 0;
  97. if (!empty($currentShopId)) {
  98. $shop = ShopClass::getShopInfo($currentShopId);
  99. //一个人不能同时在二个商家门店下工作
  100. if (isset($shop['sjId']) && $shop['sjId'] != $this->sjId) {
  101. util::fail('您已经是别的商家员工');
  102. }
  103. }
  104. $openShop = $admin['openShop'] ?? AdminClass::OPEN_SHOP_NO;
  105. if ($openShop != AdminClass::OPEN_SHOP_NO) {
  106. util::fail('您已申请开过店,不能成为别人的员工');
  107. }
  108. $respond = ShopAdminService::generateAdmin($post, $admin);
  109. util::success($respond);
  110. }
  111. //收款通知 ssh 2020.1.4
  112. public function actionUpdateRemind()
  113. {
  114. $get = Yii::$app->request->get();
  115. $id = isset($get['id']) ? $get['id'] : 0;
  116. $remind = isset($get['remind']) && is_numeric($get['remind']) ? $get['remind'] : 0;
  117. $shopAdmin = ShopAdminService::getById($id);
  118. ShopAdminService::valid($shopAdmin, $this->shopId);
  119. ShopAdminService::updateById($id, ['remind' => $remind]);
  120. util::complete();
  121. }
  122. //启用与停用 ssh 2020.1.4
  123. public function actionUpdateStatus()
  124. {
  125. $get = Yii::$app->request->get();
  126. $id = isset($get['id']) && is_numeric($get['id']) ? $get['id'] : 0;
  127. if ($id == $this->shopAdminId) {
  128. util::fail('不能禁用自己');
  129. }
  130. $status = isset($get['status']) ? $get['status'] : 0;
  131. $shopAdmin = ShopAdminService::getById($id);
  132. ShopAdminService::valid($shopAdmin, $this->shopId);
  133. ShopAdminService::updateById($id, ['status' => $status]);
  134. util::complete();
  135. }
  136. //员工列表 ssh 2019.12.8
  137. public function actionList()
  138. {
  139. $where = [];
  140. $where['shopId'] = $this->shopId;
  141. $where['delStatus'] = 0;
  142. $list = ShopAdminService::getAdminList($where);
  143. util::success($list);
  144. }
  145. //获取员工信息 ssh 2021.1.13
  146. public function actionDetail()
  147. {
  148. $get = Yii::$app->request->get();
  149. $id = isset($get['id']) ? $get['id'] : 0;
  150. $respond = ShopAdminClass::getAdminInfo($id);
  151. ShopAdminClass::valid($respond, $this->shopId);
  152. util::success($respond);
  153. }
  154. //修改员工信息
  155. public function actionUpdate()
  156. {
  157. $post = Yii::$app->request->post();
  158. $id = $post['id'] ?? 0;
  159. $shopAdmin = $this->shopAdmin->attributes;
  160. if ($shopAdmin['super'] != 1) {
  161. util::fail('超管才能操作');
  162. }
  163. if (empty($id)) {
  164. util::fail('请选择员工');
  165. }
  166. $relation = ShopAdminClass::getById($id, true);
  167. if (empty($relation)) {
  168. util::fail('没有找到员工');
  169. }
  170. ShopAdminClass::valid($relation, $this->shopId);
  171. unset($post['id']);
  172. $roleId = $post['roleId'] ?? 0;
  173. $remind = $post['remind'] ?? 0;
  174. $status = $post['status'] ?? 1;
  175. $super = $post['super'] ?? 0;
  176. $relation->roleId = $roleId;
  177. $relation->remind = $remind;
  178. $relation->status = $status;
  179. $relation->super = $super;
  180. if (isset($post['name']) && !empty($post['name'])) {
  181. $relation->name = $post['name'];
  182. }
  183. $relation->save();
  184. //若有传密码,则修改密码
  185. $password = $post['password'] ?? '';
  186. if (!empty($password)) {
  187. $adminId = $relation->adminId;
  188. $password = password_hash($password, PASSWORD_BCRYPT);
  189. AdminClass::updateById($adminId, ['password' => $password]);
  190. }
  191. util::complete('修改成功');
  192. }
  193. //删除员工关系 ssh 2021.1.14
  194. public function actionDelete()
  195. {
  196. $id = Yii::$app->request->get('id');
  197. $shopAdmin = $this->shopAdmin->attributes;
  198. if ($shopAdmin['super'] != 1) {
  199. util::fail('超管才能操作');
  200. }
  201. $relation = ShopAdminClass::getById($id, true);
  202. \biz\shop\classes\ShopAdminClass::deleteShopAdmin($relation, $this->shopAdminId, $this->shopId);
  203. util::complete();
  204. }
  205. }