ShopAdminController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace ghs\controllers;
  3. use bizHd\wx\classes\WxOpenClass;
  4. use bizGhs\admin\classes\AdminClass;
  5. use bizGhs\shop\classes\ShopAdminClass;
  6. use bizGhs\admin\services\AdminRoleService;
  7. use bizGhs\shop\services\ShopAdminService;
  8. use bizHd\wx\services\WxOpenService;
  9. use common\components\imgUtil;
  10. use common\components\jwt;
  11. use common\components\util;
  12. use Yii;
  13. use yii\web\Controller;
  14. class ShopAdminController extends BaseController
  15. {
  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['merchantId'] = $this->sjId;
  29. $post['adminId'] = $this->adminId;
  30. $merchant = WxOpenClass::getGhsWxInfo();
  31. $post['merchant'] = $merchant;
  32. $respond = ShopAdminService::prepareBindAdmin($post);
  33. $miniCode = isset($respond['miniCode']) ? imgUtil::getPrefix() . $respond['miniCode'] : '';
  34. util::success(['miniCode' => $miniCode]);
  35. }
  36. //创建管理员 ssh 2020.4.20
  37. public function actionGenerateAdmin()
  38. {
  39. $post = Yii::$app->request->post();
  40. $post['adminId'] = $this->adminId;
  41. $respond = ShopAdminService::generateAdmin($post);
  42. util::success($respond);
  43. }
  44. //收款通知 ssh 2021.1.14
  45. public function actionUpdateRemind()
  46. {
  47. $get = Yii::$app->request->get();
  48. $id = $get['id'] ?? 0;
  49. $remind = $get['remind'] ?? 0;
  50. $relation = ShopAdminClass::getById($id, true);
  51. if (empty($relation)) {
  52. util::fail('没有找到员工');
  53. }
  54. ShopAdminClass::valid($relation->attributes, $this->sjId);
  55. $relation->remind = $remind;
  56. $relation->save();
  57. util::complete();
  58. }
  59. //启用与停用 ssh 2021.1.14
  60. public function actionUpdateStatus()
  61. {
  62. $get = Yii::$app->request->get();
  63. $id = $get['id'] ?? 0;
  64. $status = $get['status'] ?? 0;
  65. $relation = ShopAdminClass::getById($id, true);
  66. if (empty($relation)) {
  67. util::fail('没有找到员工');
  68. }
  69. ShopAdminClass::valid($relation->attributes, $this->sjId);
  70. $relation->status = $status;
  71. $relation->save();
  72. util::complete();
  73. }
  74. //员工列表 ssh 2019.12.8
  75. public function actionList()
  76. {
  77. $where = [];
  78. $where['shopId'] = $this->shopId;
  79. $where['delStatus'] = 0;
  80. $list = ShopAdminService::getAdminList($where);
  81. util::success($list);
  82. }
  83. //获取员工信息 ssh 2021.1.13
  84. public function actionDetail()
  85. {
  86. $get = Yii::$app->request->get();
  87. $id = isset($get['id']) ? $get['id'] : 0;
  88. $respond = ShopAdminService::getAdminInfo($id);
  89. ShopAdminClass::valid($respond, $this->shopId);
  90. util::success($respond);
  91. }
  92. //修改员工信息
  93. public function actionUpdate()
  94. {
  95. $post = Yii::$app->request->post();
  96. $id = $post['id'] ?? 0;
  97. if (empty($id)) {
  98. util::fail('请选择员工');
  99. }
  100. $relation = ShopAdminClass::getById($id, true);
  101. if (empty($relation)) {
  102. util::fail('没有找到员工');
  103. }
  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. $relation->save();
  112. ShopAdminClass::valid($relation, $this->shopId);
  113. util::complete('修改成功');
  114. }
  115. //删除员工关系 ssh 2021.1.14
  116. public function actionDelete()
  117. {
  118. $id = Yii::$app->request->get('id');
  119. $relation = ShopAdminClass::getInfo($id);
  120. if ($relation['super'] == 1) {
  121. //util::fail("管理员不能删除");
  122. }
  123. ShopAdminClass::valid($relation, $this->sjId);
  124. ShopAdminClass::delRelation($relation);
  125. util::complete();
  126. }
  127. }