ShopAdminController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\admin\classes\AdminClass;
  4. use bizGhs\admin\classes\ShopAdminClass;
  5. use bizGhs\admin\services\AdminRoleService;
  6. use bizGhs\admin\services\ShopAdminService;
  7. use biz\wx\services\WxOpenService;
  8. use common\components\jwt;
  9. use common\components\util;
  10. use Yii;
  11. use yii\web\Controller;
  12. class ShopAdminController extends BaseController
  13. {
  14. //创建管理员数据准备 shish 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['ghsId']) != $this->ghsId) {
  21. util::fail('请选择角色!');
  22. }
  23. unset($post['userId']);
  24. unset($post['status']);
  25. $post['shopId'] = $this->shopId;
  26. $post['adminId'] = $this->adminId;
  27. $merchant = WxOpenService::getGhsWxInfo();
  28. $post['merchant'] = $merchant;
  29. $respond = ShopAdminService::prepareBindAdmin($post);
  30. $miniCode = isset($respond['miniCode']) ? Yii::$app->params['imgHost'] . $respond['miniCode'] : '';
  31. util::success(['miniCode' => $miniCode]);
  32. }
  33. //创建管理员 shish 2020.4.20
  34. public function actionGenerateAdmin()
  35. {
  36. $post = Yii::$app->request->post();
  37. $respond = ShopAdminService::generateAdmin($post);
  38. util::success($respond);
  39. }
  40. //收款通知 shish 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->ghsId);
  51. $relation->remind = $remind;
  52. $relation->save();
  53. util::complete();
  54. }
  55. //启用与停用 shish 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->ghsId);
  66. $relation->status = $status;
  67. $relation->save();
  68. util::complete();
  69. }
  70. //员工列表 shish 2019.12.8
  71. public function actionList()
  72. {
  73. $get = Yii::$app->request->get();
  74. $where = [];
  75. $where['shopId'] = $this->shopId;
  76. $where['delStatus'] = 0;
  77. $list = ShopAdminService::getAdminList($where);
  78. util::success($list);
  79. }
  80. //获取员工信息 shish 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->ghsId);
  87. util::success($respond);
  88. }
  89. //修改员工信息
  90. public function actionUpdate()
  91. {
  92. $post = Yii::$app->request->post();
  93. $id = isset($post['id']) && is_numeric($post['id']) ? $post['id'] : 0;
  94. $relation = ShopAdminClass::getById($id, true);
  95. unset($post['id']);
  96. $roleId = isset($post['roleId']) && !empty($post['roleId']) ? $post['roleId'] : 0;
  97. $remind = isset($post['remind']) && !empty($post['remind']) ? $post['remind'] : 0;
  98. $relation->roleId = $roleId;
  99. $relation->remind = $remind;
  100. $relation->save();
  101. $adminId = isset($relation->adminId) ? $relation->adminId : 0;
  102. $originalAdmin = ShopAdminService::getAdminInfo($adminId);
  103. ShopAdminClass::valid($originalAdmin, $this->ghsId);
  104. AdminClass::updateById($adminId, $post);
  105. util::complete('修改成功');
  106. }
  107. //删除员工关系 shish 2021.1.14
  108. public function actionDelete()
  109. {
  110. $id = Yii::$app->request->get('id');
  111. $relation = ShopAdminClass::getById($id);
  112. $adminId = $relation['adminId'] ?? 0;
  113. $admin = ShopAdminService::getAdminInfo($adminId);
  114. ShopAdminClass::valid($admin, $this->ghsId);
  115. ShopAdminClass::deleteById($id);
  116. util::complete();
  117. }
  118. }