ShopAdminController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\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 biz\wx\services\WxOpenService;
  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. //创建管理员数据准备 shish 2020.4.17
  16. public function actionPrepareBind()
  17. {
  18. $post = Yii::$app->request->post();
  19. $roleId = isset($post['roleId']) ? $post['roleId'] : 0;
  20. $role = AdminRoleService::getById($roleId);
  21. if (empty($role) || isset($role['ghsId']) != $this->ghsId) {
  22. util::fail('请选择角色!');
  23. }
  24. unset($post['userId']);
  25. unset($post['status']);
  26. $post['shopId'] = $this->shopId;
  27. $post['ghsId'] = $this->ghsId;
  28. $post['adminId'] = $this->adminId;
  29. $merchant = WxOpenClass::getGhsWxInfo();
  30. $post['merchant'] = $merchant;
  31. $respond = ShopAdminService::prepareBindAdmin($post);
  32. $miniCode = isset($respond['miniCode']) ? Yii::$app->params['imgHost'] . $respond['miniCode'] : '';
  33. util::success(['miniCode' => $miniCode]);
  34. }
  35. //创建管理员 shish 2020.4.20
  36. public function actionGenerateAdmin()
  37. {
  38. $post = Yii::$app->request->post();
  39. $post['adminId'] = $this->adminId;
  40. $post['ghsId'] = $this->ghsId;
  41. $respond = ShopAdminService::generateAdmin($post);
  42. util::success($respond);
  43. }
  44. //收款通知 shish 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->ghsId);
  55. $relation->remind = $remind;
  56. $relation->save();
  57. util::complete();
  58. }
  59. //启用与停用 shish 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->ghsId);
  70. $relation->status = $status;
  71. $relation->save();
  72. util::complete();
  73. }
  74. //员工列表 shish 2019.12.8
  75. public function actionList()
  76. {
  77. $get = Yii::$app->request->get();
  78. $where = [];
  79. $where['shopId'] = $this->shopId;
  80. $where['delStatus'] = 0;
  81. $list = ShopAdminService::getAdminList($where);
  82. util::success($list);
  83. }
  84. //获取员工信息 shish 2021.1.13
  85. public function actionDetail()
  86. {
  87. $get = Yii::$app->request->get();
  88. $id = isset($get['id']) ? $get['id'] : 0;
  89. $respond = ShopAdminService::getAdminInfo($id);
  90. ShopAdminClass::valid($respond, $this->ghsId);
  91. util::success($respond);
  92. }
  93. //修改员工信息
  94. public function actionUpdate()
  95. {
  96. $post = Yii::$app->request->post();
  97. $id = isset($post['id']) && is_numeric($post['id']) ? $post['id'] : 0;
  98. $relation = ShopAdminClass::getById($id, true);
  99. unset($post['id']);
  100. $roleId = isset($post['roleId']) && !empty($post['roleId']) ? $post['roleId'] : 0;
  101. $remind = isset($post['remind']) && !empty($post['remind']) ? $post['remind'] : 0;
  102. $relation->roleId = $roleId;
  103. $relation->remind = $remind;
  104. $relation->save();
  105. $adminId = isset($relation->adminId) ? $relation->adminId : 0;
  106. $originalAdmin = ShopAdminService::getAdminInfo($adminId);
  107. ShopAdminClass::valid($originalAdmin, $this->ghsId);
  108. AdminClass::updateById($adminId, $post);
  109. util::complete('修改成功');
  110. }
  111. //删除员工关系 shish 2021.1.14
  112. public function actionDelete()
  113. {
  114. $id = Yii::$app->request->get('id');
  115. $relation = ShopAdminClass::getById($id);
  116. $adminId = $relation['adminId'] ?? 0;
  117. $admin = ShopAdminService::getAdminInfo($adminId);
  118. ShopAdminClass::valid($admin, $this->ghsId);
  119. ShopAdminClass::deleteById($id);
  120. util::complete();
  121. }
  122. }