ShopAdminController.php 5.6 KB

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