ShopAdminController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. namespace hd\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use bizGhs\shop\classes\ShopAdminClass;
  5. use bizHd\admin\services\AdminRoleService;
  6. use bizHd\admin\services\ShopAdminService;
  7. use bizHd\wx\services\WxOpenService;
  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. $roleId = isset($post['roleId']) ? $post['roleId'] : 0;
  19. $shopAdmin = $this->shopAdmin;
  20. if ($shopAdmin['super'] != 1) {
  21. util::fail('超管才能操作');
  22. }
  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['adminId'] = $this->adminId;
  31. $merchant = WxOpenService::getWxInfo();
  32. $post['merchant'] = $merchant;
  33. $respond = ShopAdminService::prepareBindAdmin($post);
  34. $miniCode = isset($respond['miniCode']) ? imgUtil::getPrefix() . $respond['miniCode'] : '';
  35. util::success(['miniCode' => $miniCode]);
  36. }
  37. //创建管理员 ssh 2020.4.20
  38. public function actionGenerateAdmin()
  39. {
  40. $post = Yii::$app->request->post();
  41. $respond = ShopAdminService::generateAdmin($post);
  42. util::success($respond);
  43. }
  44. //收款通知 ssh 2020.1.4
  45. public function actionUpdateRemind()
  46. {
  47. $get = Yii::$app->request->get();
  48. $id = isset($get['id']) ? $get['id'] : 0;
  49. $remind = isset($get['remind']) && is_numeric($get['remind']) ? $get['remind'] : 0;
  50. $shopAdmin = ShopAdminService::getById($id);
  51. ShopAdminService::valid($shopAdmin, $this->shopId);
  52. ShopAdminService::updateById($id, ['remind' => $remind]);
  53. util::complete();
  54. }
  55. //启用与停用 ssh 2020.1.4
  56. public function actionUpdateStatus()
  57. {
  58. $get = Yii::$app->request->get();
  59. $id = isset($get['id']) && is_numeric($get['id']) ? $get['id'] : 0;
  60. if ($id == $this->shopAdminId) {
  61. util::fail('不能禁用自己');
  62. }
  63. $status = isset($get['status']) ? $get['status'] : 0;
  64. $shopAdmin = ShopAdminService::getById($id);
  65. ShopAdminService::valid($shopAdmin, $this->shopId);
  66. ShopAdminService::updateById($id, ['status' => $status]);
  67. util::complete();
  68. }
  69. //员工列表 ssh 2019.12.8
  70. public function actionList()
  71. {
  72. $where = [];
  73. $where['shopId'] = $this->shopId;
  74. $where['delStatus'] = 0;
  75. $list = ShopAdminService::getAdminList($where);
  76. util::success($list);
  77. }
  78. //获取员工信息 ssh 2021.1.13
  79. public function actionDetail()
  80. {
  81. $get = Yii::$app->request->get();
  82. $id = isset($get['id']) ? $get['id'] : 0;
  83. $respond = ShopAdminClass::getAdminInfo($id);
  84. ShopAdminClass::valid($respond, $this->shopId);
  85. util::success($respond);
  86. }
  87. //修改员工信息
  88. public function actionUpdate()
  89. {
  90. $post = Yii::$app->request->post();
  91. $id = $post['id'] ?? 0;
  92. $shopAdmin = $this->shopAdmin;
  93. if ($shopAdmin['super'] != 1) {
  94. util::fail('超管才能操作');
  95. }
  96. if (empty($id)) {
  97. util::fail('请选择员工');
  98. }
  99. $relation = ShopAdminClass::getById($id, true);
  100. if (empty($relation)) {
  101. util::fail('没有找到员工');
  102. }
  103. ShopAdminClass::valid($relation, $this->shopId);
  104. unset($post['id']);
  105. $roleId = $post['roleId'] ?? 0;
  106. $remind = $post['remind'] ?? 0;
  107. $status = $post['status'] ?? 1;
  108. $relation->roleId = $roleId;
  109. $relation->remind = $remind;
  110. $relation->status = $status;
  111. if (isset($post['name']) && !empty($post['name'])) {
  112. $relation->name = $post['name'];
  113. }
  114. $relation->save();
  115. //若有传密码,则修改密码
  116. $password = $post['password'] ?? '';
  117. if (!empty($password)) {
  118. $adminId = $relation->adminId;
  119. $password = password_hash($password, PASSWORD_BCRYPT);
  120. AdminClass::updateById($adminId, ['password' => $password]);
  121. }
  122. util::complete('修改成功');
  123. }
  124. //删除员工关系 ssh 2021.1.14
  125. public function actionDelete()
  126. {
  127. $id = Yii::$app->request->get('id');
  128. $shopAdmin = $this->shopAdmin;
  129. if ($shopAdmin['super'] != 1) {
  130. util::fail('超管才能操作');
  131. }
  132. $relation = ShopAdminClass::getById($id, true);
  133. \biz\shop\classes\ShopAdminClass::deleteShopAdmin($relation, $this->shopAdminId, $this->shopId);
  134. util::complete();
  135. }
  136. }