ShopAdminController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace hd\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\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\jwt;
  10. use common\components\util;
  11. use Yii;
  12. use yii\web\Controller;
  13. class ShopAdminController extends BaseController
  14. {
  15. public $guestAccess = ['generate-admin'];
  16. //创建管理员数据准备 ssh 2020.4.17
  17. public function actionPrepareBind()
  18. {
  19. $post = Yii::$app->request->post();
  20. $roleId = isset($post['roleId']) ? $post['roleId'] : 0;
  21. $role = AdminRoleService::getById($roleId);
  22. if (empty($role) || isset($role['merchantId']) != $this->sjId) {
  23. util::fail('请选择角色!');
  24. }
  25. unset($post['userId']);
  26. unset($post['status']);
  27. $post['shopId'] = $this->shopId;
  28. $post['adminId'] = $this->adminId;
  29. $merchant = WxOpenService::getWxInfo();
  30. $post['merchant'] = $merchant;
  31. $respond = ShopAdminService::prepareBindAdmin($post);
  32. $miniCode = isset($respond['miniCode']) ? imgUtil::getPrefix() . $respond['miniCode'] : '';
  33. util::success(['miniCode' => $miniCode]);
  34. }
  35. //创建管理员 ssh 2020.4.20
  36. public function actionGenerateAdmin()
  37. {
  38. $post = Yii::$app->request->post();
  39. $respond = ShopAdminService::generateAdmin($post);
  40. util::success($respond);
  41. }
  42. //收款通知 ssh 2020.1.4
  43. public function actionUpdateRemind()
  44. {
  45. $get = Yii::$app->request->get();
  46. $id = isset($get['id']) ? $get['id'] : 0;
  47. $remind = isset($get['remind']) && is_numeric($get['remind']) ? $get['remind'] : 0;
  48. $shopAdmin = ShopAdminService::getById($id);
  49. ShopAdminService::valid($shopAdmin, $this->shopId);
  50. ShopAdminService::updateById($id, ['remind' => $remind]);
  51. util::complete();
  52. }
  53. //启用与停用 ssh 2020.1.4
  54. public function actionUpdateStatus()
  55. {
  56. $get = Yii::$app->request->get();
  57. $id = isset($get['id']) && is_numeric($get['id']) ? $get['id'] : 0;
  58. $status = isset($get['status']) ? $get['status'] : 0;
  59. $shopAdmin = ShopAdminService::getById($id);
  60. ShopAdminService::valid($shopAdmin, $this->shopId);
  61. ShopAdminService::updateById($id, ['status' => $status]);
  62. util::complete();
  63. }
  64. //员工列表 ssh 2019.12.8
  65. public function actionList()
  66. {
  67. $where = [];
  68. $where['shopId'] = $this->shopId;
  69. $where['delStatus'] = 0;
  70. $list = ShopAdminService::getAdminList($where);
  71. util::success($list);
  72. }
  73. //获取员工信息 ssh 2021.1.13
  74. public function actionDetail()
  75. {
  76. $get = Yii::$app->request->get();
  77. $id = isset($get['id']) ? $get['id'] : 0;
  78. $respond = ShopAdminClass::getAdminInfo($id);
  79. ShopAdminClass::valid($respond, $this->shopId);
  80. util::success($respond);
  81. }
  82. //修改员工信息
  83. public function actionUpdate()
  84. {
  85. $post = Yii::$app->request->post();
  86. $id = $post['id'] ?? 0;
  87. if (empty($id)) {
  88. util::fail('请选择员工');
  89. }
  90. $relation = ShopAdminClass::getById($id, true);
  91. if (empty($relation)) {
  92. util::fail('没有找到员工');
  93. }
  94. ShopAdminClass::valid($relation, $this->shopId);
  95. unset($post['id']);
  96. $roleId = $post['roleId'] ?? 0;
  97. $remind = $post['remind'] ?? 0;
  98. $status = $post['status'] ?? 1;
  99. $relation->roleId = $roleId;
  100. $relation->remind = $remind;
  101. $relation->status = $status;
  102. if (isset($post['name']) && !empty($post['name'])) {
  103. $relation->name = $post['name'];
  104. }
  105. $relation->save();
  106. //若有传密码,则修改密码
  107. $password = $post['password'] ?? '';
  108. if (!empty($password)) {
  109. $adminId = $relation->adminId;
  110. $password = password_hash($password, PASSWORD_BCRYPT);
  111. AdminClass::updateById($adminId, ['password' => $password]);
  112. }
  113. util::complete('修改成功');
  114. }
  115. }