ShopAdminController.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\shop\classes\ShopClass;
  5. use bizGhs\admin\services\AdminService;
  6. use bizHd\wx\classes\WxOpenClass;
  7. use bizGhs\shop\classes\ShopAdminClass;
  8. use bizGhs\admin\services\AdminRoleService;
  9. use bizGhs\shop\services\ShopAdminService;
  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. //获取添加员工的验证码 ssh 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. $ptStyle = Yii::$app->params['ptStyle'];
  61. $adminInfo = ['name' => $name, 'mobile' => $mobile, 'style' => $ptStyle,];
  62. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  63. $admin = AdminService::replaceAdmin($adminInfo, $fromApp);
  64. $post['shopId'] = $this->shopId;
  65. $respond = ShopAdminService::appGenerateStaff($post, $admin);
  66. util::success($respond);
  67. }
  68. //创建管理员数据准备 ssh 2020.4.17
  69. public function actionPrepareBind()
  70. {
  71. $post = Yii::$app->request->post();
  72. $shopAdmin = $this->shopAdmin->attributes;
  73. if ($shopAdmin['super'] != 1) {
  74. util::fail('超管才能操作');
  75. }
  76. $roleId = isset($post['roleId']) ? $post['roleId'] : 0;
  77. $role = AdminRoleService::getById($roleId);
  78. if (empty($role) || isset($role['sjId']) != $this->sjId) {
  79. util::fail('请选择角色!');
  80. }
  81. unset($post['userId']);
  82. unset($post['status']);
  83. $post['shopId'] = $this->shopId;
  84. $post['sjId'] = $this->sjId;
  85. $post['adminId'] = $this->adminId;
  86. $post['mainId'] = $this->mainId;
  87. $merchant = WxOpenClass::getGhsWxInfo();
  88. $post['merchant'] = $merchant;
  89. $respond = ShopAdminService::prepareBindAdmin($post);
  90. $miniCode = isset($respond['miniCode']) ? imgUtil::getPrefix() . $respond['miniCode'] : '';
  91. util::success(['miniCode' => $miniCode]);
  92. }
  93. //创建员工 ssh 2020.4.20
  94. public function actionGenerateAdmin()
  95. {
  96. $post = Yii::$app->request->post();
  97. $post['adminId'] = $this->adminId;
  98. $post['mainId'] = $this->mainId;
  99. $admin = $this->admin->attributes;
  100. $currentShopId = $admin['currentGhsShopId'] ?? 0;
  101. if (!empty($currentShopId)) {
  102. $shop = ShopClass::getShopInfo($currentShopId);
  103. //一个人不能同时在二个商家门店下工作
  104. if (isset($shop['sjId']) && $shop['sjId'] != $this->sjId) {
  105. util::fail('您已经是别的商家员工');
  106. }
  107. }
  108. $openShop = $admin['openGhsShop'] ?? AdminClass::OPEN_SHOP_NO;
  109. if ($openShop != AdminClass::OPEN_SHOP_NO) {
  110. util::fail('您已申请开过店,不能成为别人的员工');
  111. }
  112. $respond = ShopAdminService::generateAdmin($post, $admin);
  113. util::success($respond);
  114. }
  115. //收款通知 ssh 2021.1.14
  116. public function actionUpdateRemind()
  117. {
  118. $get = Yii::$app->request->get();
  119. $id = $get['id'] ?? 0;
  120. $remind = $get['remind'] ?? 0;
  121. $relation = ShopAdminClass::getById($id, true);
  122. if (empty($relation)) {
  123. util::fail('没有找到员工');
  124. }
  125. ShopAdminClass::valid($relation->attributes, $this->shopId);
  126. $relation->remind = $remind;
  127. $relation->save();
  128. util::complete();
  129. }
  130. //启用与停用 ssh 2021.1.14
  131. public function actionUpdateStatus()
  132. {
  133. $get = Yii::$app->request->get();
  134. $id = $get['id'] ?? 0;
  135. $status = $get['status'] ?? 0;
  136. $relation = ShopAdminClass::getById($id, true);
  137. if (empty($relation)) {
  138. util::fail('没有找到员工');
  139. }
  140. ShopAdminClass::valid($relation->attributes, $this->shopId);
  141. $relation->status = $status;
  142. $relation->save();
  143. util::complete();
  144. }
  145. //员工列表 ssh 2019.12.8
  146. public function actionList()
  147. {
  148. $where = [];
  149. $where['mainId'] = $this->mainId;
  150. $where['delStatus'] = 0;
  151. $where['isPt'] = 0;
  152. $list = ShopAdminService::getAdminList($where);
  153. util::success($list);
  154. }
  155. //获取员工信息 ssh 2021.1.13
  156. public function actionDetail()
  157. {
  158. $get = Yii::$app->request->get();
  159. $id = isset($get['id']) ? $get['id'] : 0;
  160. $respond = ShopAdminService::getAdminInfo($id);
  161. ShopAdminClass::valid($respond, $this->shopId);
  162. util::success($respond);
  163. }
  164. //修改员工信息
  165. public function actionUpdate()
  166. {
  167. $post = Yii::$app->request->post();
  168. $id = $post['id'] ?? 0;
  169. $shopAdmin = $this->shopAdmin;
  170. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  171. util::fail('没有权限');
  172. }
  173. if (empty($id)) {
  174. util::fail('请选择员工');
  175. }
  176. $relation = ShopAdminClass::getById($id, true);
  177. if (empty($relation)) {
  178. util::fail('没有找到员工');
  179. }
  180. ShopAdminClass::valid($relation, $this->shopId);
  181. unset($post['id']);
  182. $roleId = $post['roleId'] ?? 0;
  183. $remind = $post['remind'] ?? 0;
  184. $status = $post['status'] ?? 1;
  185. $super = $post['super'] ?? 0;
  186. $founder = $relation->founder ?? 1;
  187. if ($founder == 2 && $super == 0) {
  188. util::fail('不能关闭超管权限');
  189. }
  190. $relation->roleId = $roleId;
  191. $relation->remind = $remind;
  192. $relation->status = $status;
  193. $relation->super = $super;
  194. if (isset($post['name']) && !empty($post['name'])) {
  195. $relation->name = $post['name'];
  196. }
  197. $relation->save();
  198. //若有传密码,则修改密码
  199. $password = $post['password'] ?? '';
  200. if (!empty($password)) {
  201. if (ctype_alnum($password)) {
  202. util::fail('密码必须是字母、数字和符号的组合');
  203. }
  204. $adminId = $relation->adminId;
  205. $password = password_hash($password, PASSWORD_BCRYPT);
  206. AdminClass::updateById($adminId, ['password' => $password]);
  207. }
  208. util::complete('修改成功');
  209. }
  210. //删除员工关系 ssh 2021.1.14
  211. public function actionDelete()
  212. {
  213. $id = Yii::$app->request->get('id');
  214. $shopAdmin = $this->shopAdmin;
  215. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  216. util::fail('没有权限');
  217. }
  218. $relation = ShopAdminClass::getById($id, true);
  219. \biz\shop\classes\ShopAdminClass::deleteShopAdmin($relation, $this->shopAdminId, $this->shopId);
  220. util::complete();
  221. }
  222. }