ShopAdminController.php 4.1 KB

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