ShopAdminController.php 4.8 KB

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