ShopAdminController.php 4.2 KB

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