ShopAdminController.php 4.9 KB

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