ShopAdminController.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. $respond = ShopAdminService::generateAdmin($post);
  53. util::success($respond);
  54. }
  55. //收款通知 ssh 2020.1.4
  56. public function actionUpdateRemind()
  57. {
  58. $get = Yii::$app->request->get();
  59. $id = isset($get['id']) ? $get['id'] : 0;
  60. $remind = isset($get['remind']) && is_numeric($get['remind']) ? $get['remind'] : 0;
  61. $shopAdmin = ShopAdminService::getById($id);
  62. ShopAdminService::valid($shopAdmin, $this->shopId);
  63. ShopAdminService::updateById($id, ['remind' => $remind]);
  64. util::complete();
  65. }
  66. //启用与停用 ssh 2020.1.4
  67. public function actionUpdateStatus()
  68. {
  69. $get = Yii::$app->request->get();
  70. $id = isset($get['id']) && is_numeric($get['id']) ? $get['id'] : 0;
  71. if ($id == $this->shopAdminId) {
  72. util::fail('不能禁用自己');
  73. }
  74. $status = isset($get['status']) ? $get['status'] : 0;
  75. $shopAdmin = ShopAdminService::getById($id);
  76. ShopAdminService::valid($shopAdmin, $this->shopId);
  77. ShopAdminService::updateById($id, ['status' => $status]);
  78. util::complete();
  79. }
  80. //员工列表 ssh 2019.12.8
  81. public function actionList()
  82. {
  83. $where = [];
  84. $where['shopId'] = $this->shopId;
  85. $where['delStatus'] = 0;
  86. $list = ShopAdminService::getAdminList($where);
  87. util::success($list);
  88. }
  89. //获取员工信息 ssh 2021.1.13
  90. public function actionDetail()
  91. {
  92. $get = Yii::$app->request->get();
  93. $id = isset($get['id']) ? $get['id'] : 0;
  94. $respond = ShopAdminClass::getAdminInfo($id);
  95. ShopAdminClass::valid($respond, $this->shopId);
  96. util::success($respond);
  97. }
  98. //修改员工信息
  99. public function actionUpdate()
  100. {
  101. $post = Yii::$app->request->post();
  102. $id = $post['id'] ?? 0;
  103. $shopAdmin = $this->shopAdmin;
  104. if ($shopAdmin['super'] != 1) {
  105. util::fail('超管才能操作');
  106. }
  107. if (empty($id)) {
  108. util::fail('请选择员工');
  109. }
  110. $relation = ShopAdminClass::getById($id, true);
  111. if (empty($relation)) {
  112. util::fail('没有找到员工');
  113. }
  114. ShopAdminClass::valid($relation, $this->shopId);
  115. unset($post['id']);
  116. $roleId = $post['roleId'] ?? 0;
  117. $remind = $post['remind'] ?? 0;
  118. $status = $post['status'] ?? 1;
  119. $relation->roleId = $roleId;
  120. $relation->remind = $remind;
  121. $relation->status = $status;
  122. if (isset($post['name']) && !empty($post['name'])) {
  123. $relation->name = $post['name'];
  124. }
  125. $relation->save();
  126. //若有传密码,则修改密码
  127. $password = $post['password'] ?? '';
  128. if (!empty($password)) {
  129. $adminId = $relation->adminId;
  130. $password = password_hash($password, PASSWORD_BCRYPT);
  131. AdminClass::updateById($adminId, ['password' => $password]);
  132. }
  133. util::complete('修改成功');
  134. }
  135. //删除员工关系 ssh 2021.1.14
  136. public function actionDelete()
  137. {
  138. $id = Yii::$app->request->get('id');
  139. $shopAdmin = $this->shopAdmin;
  140. if ($shopAdmin['super'] != 1) {
  141. util::fail('超管才能操作');
  142. }
  143. $relation = ShopAdminClass::getById($id, true);
  144. \biz\shop\classes\ShopAdminClass::deleteShopAdmin($relation, $this->shopAdminId, $this->shopId);
  145. util::complete();
  146. }
  147. }