ShopAdminController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. namespace hd\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\shop\classes\ShopClass;
  5. use bizGhs\shop\classes\ShopAdminClass;
  6. use bizHd\admin\services\AdminRoleService;
  7. use bizHd\admin\services\ShopAdminService;
  8. use bizHd\wx\services\WxOpenService;
  9. use common\components\imgUtil;
  10. use common\components\util;
  11. use Yii;
  12. class ShopAdminController extends BaseController
  13. {
  14. public $guestAccess = ['generate-admin'];
  15. //创建管理员数据准备 ssh 2020.4.17
  16. public function actionPrepareBind()
  17. {
  18. $post = Yii::$app->request->post();
  19. $roleId = isset($post['roleId']) ? $post['roleId'] : 0;
  20. $shopAdmin = $this->shopAdmin;
  21. if ($shopAdmin['super'] != 1) {
  22. util::fail('超管才能操作');
  23. }
  24. $role = AdminRoleService::getById($roleId);
  25. if (empty($role) || isset($role['merchantId']) != $this->sjId) {
  26. util::fail('请选择角色!');
  27. }
  28. unset($post['userId']);
  29. unset($post['status']);
  30. $post['shopId'] = $this->shopId;
  31. $post['adminId'] = $this->adminId;
  32. $merchant = WxOpenService::getWxInfo();
  33. $post['merchant'] = $merchant;
  34. $respond = ShopAdminService::prepareBindAdmin($post);
  35. $miniCode = isset($respond['miniCode']) ? imgUtil::getPrefix() . $respond['miniCode'] : '';
  36. util::success(['miniCode' => $miniCode]);
  37. }
  38. //创建管理员 ssh 2020.4.20
  39. public function actionGenerateAdmin()
  40. {
  41. $post = Yii::$app->request->post();
  42. $post['adminId'] = $this->adminId;
  43. $admin = $this->admin;
  44. $currentShopId = $admin['currentShopId'] ?? 0;
  45. if (!empty($currentShopId)) {
  46. $shop = ShopClass::getShopInfo($currentShopId);
  47. //一个人不能同时在二个商家门店下工作
  48. if (isset($shop['merchantId']) && $shop['merchantId'] != $this->sjId) {
  49. util::fail('您已经是别的商家员工');
  50. }
  51. }
  52. $openShop = $admin['openShop'] ?? AdminClass::OPEN_SHOP_NO;
  53. if ($openShop != AdminClass::OPEN_SHOP_NO) {
  54. util::fail('您已申请开过店,不能成为别人的员工');
  55. }
  56. $respond = ShopAdminService::generateAdmin($post);
  57. util::success($respond);
  58. }
  59. //收款通知 ssh 2020.1.4
  60. public function actionUpdateRemind()
  61. {
  62. $get = Yii::$app->request->get();
  63. $id = isset($get['id']) ? $get['id'] : 0;
  64. $remind = isset($get['remind']) && is_numeric($get['remind']) ? $get['remind'] : 0;
  65. $shopAdmin = ShopAdminService::getById($id);
  66. ShopAdminService::valid($shopAdmin, $this->shopId);
  67. ShopAdminService::updateById($id, ['remind' => $remind]);
  68. util::complete();
  69. }
  70. //启用与停用 ssh 2020.1.4
  71. public function actionUpdateStatus()
  72. {
  73. $get = Yii::$app->request->get();
  74. $id = isset($get['id']) && is_numeric($get['id']) ? $get['id'] : 0;
  75. if ($id == $this->shopAdminId) {
  76. util::fail('不能禁用自己');
  77. }
  78. $status = isset($get['status']) ? $get['status'] : 0;
  79. $shopAdmin = ShopAdminService::getById($id);
  80. ShopAdminService::valid($shopAdmin, $this->shopId);
  81. ShopAdminService::updateById($id, ['status' => $status]);
  82. util::complete();
  83. }
  84. //员工列表 ssh 2019.12.8
  85. public function actionList()
  86. {
  87. $where = [];
  88. $where['shopId'] = $this->shopId;
  89. $where['delStatus'] = 0;
  90. $list = ShopAdminService::getAdminList($where);
  91. util::success($list);
  92. }
  93. //获取员工信息 ssh 2021.1.13
  94. public function actionDetail()
  95. {
  96. $get = Yii::$app->request->get();
  97. $id = isset($get['id']) ? $get['id'] : 0;
  98. $respond = ShopAdminClass::getAdminInfo($id);
  99. ShopAdminClass::valid($respond, $this->shopId);
  100. util::success($respond);
  101. }
  102. //修改员工信息
  103. public function actionUpdate()
  104. {
  105. $post = Yii::$app->request->post();
  106. $id = $post['id'] ?? 0;
  107. $shopAdmin = $this->shopAdmin;
  108. if ($shopAdmin['super'] != 1) {
  109. util::fail('超管才能操作');
  110. }
  111. if (empty($id)) {
  112. util::fail('请选择员工');
  113. }
  114. $relation = ShopAdminClass::getById($id, true);
  115. if (empty($relation)) {
  116. util::fail('没有找到员工');
  117. }
  118. ShopAdminClass::valid($relation, $this->shopId);
  119. unset($post['id']);
  120. $roleId = $post['roleId'] ?? 0;
  121. $remind = $post['remind'] ?? 0;
  122. $status = $post['status'] ?? 1;
  123. $relation->roleId = $roleId;
  124. $relation->remind = $remind;
  125. $relation->status = $status;
  126. if (isset($post['name']) && !empty($post['name'])) {
  127. $relation->name = $post['name'];
  128. }
  129. $relation->save();
  130. //若有传密码,则修改密码
  131. $password = $post['password'] ?? '';
  132. if (!empty($password)) {
  133. $adminId = $relation->adminId;
  134. $password = password_hash($password, PASSWORD_BCRYPT);
  135. AdminClass::updateById($adminId, ['password' => $password]);
  136. }
  137. util::complete('修改成功');
  138. }
  139. //删除员工关系 ssh 2021.1.14
  140. public function actionDelete()
  141. {
  142. $id = Yii::$app->request->get('id');
  143. $shopAdmin = $this->shopAdmin;
  144. if ($shopAdmin['super'] != 1) {
  145. util::fail('超管才能操作');
  146. }
  147. $relation = ShopAdminClass::getById($id, true);
  148. \biz\shop\classes\ShopAdminClass::deleteShopAdmin($relation, $this->shopAdminId, $this->shopId);
  149. util::complete();
  150. }
  151. }