ShopAdminController.php 4.6 KB

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