ShopAdminController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\wx\classes\WxOpenClass;
  4. use bizGhs\admin\classes\AdminClass;
  5. use bizGhs\admin\classes\ShopAdminClass;
  6. use bizGhs\admin\services\AdminRoleService;
  7. use bizGhs\admin\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['adminId'] = $this->adminId;
  28. $merchant = WxOpenClass::getGhsWxInfo();
  29. $post['merchant'] = $merchant;
  30. $respond = ShopAdminService::prepareBindAdmin($post);
  31. $miniCode = isset($respond['miniCode']) ? Yii::$app->params['imgHost'] . $respond['miniCode'] : '';
  32. util::success(['miniCode' => $miniCode]);
  33. }
  34. //创建管理员 shish 2020.4.20
  35. public function actionGenerateAdmin()
  36. {
  37. $post = Yii::$app->request->post();
  38. $respond = ShopAdminService::generateAdmin($post);
  39. util::success($respond);
  40. }
  41. //收款通知 shish 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->ghsId);
  52. $relation->remind = $remind;
  53. $relation->save();
  54. util::complete();
  55. }
  56. //启用与停用 shish 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->ghsId);
  67. $relation->status = $status;
  68. $relation->save();
  69. util::complete();
  70. }
  71. //员工列表 shish 2019.12.8
  72. public function actionList()
  73. {
  74. $get = Yii::$app->request->get();
  75. $where = [];
  76. $where['shopId'] = $this->shopId;
  77. $where['delStatus'] = 0;
  78. $list = ShopAdminService::getAdminList($where);
  79. util::success($list);
  80. }
  81. //获取员工信息 shish 2021.1.13
  82. public function actionDetail()
  83. {
  84. $get = Yii::$app->request->get();
  85. $id = isset($get['id']) ? $get['id'] : 0;
  86. $respond = ShopAdminService::getAdminInfo($id);
  87. ShopAdminClass::valid($respond, $this->ghsId);
  88. util::success($respond);
  89. }
  90. //修改员工信息
  91. public function actionUpdate()
  92. {
  93. $post = Yii::$app->request->post();
  94. $id = isset($post['id']) && is_numeric($post['id']) ? $post['id'] : 0;
  95. $relation = ShopAdminClass::getById($id, true);
  96. unset($post['id']);
  97. $roleId = isset($post['roleId']) && !empty($post['roleId']) ? $post['roleId'] : 0;
  98. $remind = isset($post['remind']) && !empty($post['remind']) ? $post['remind'] : 0;
  99. $relation->roleId = $roleId;
  100. $relation->remind = $remind;
  101. $relation->save();
  102. $adminId = isset($relation->adminId) ? $relation->adminId : 0;
  103. $originalAdmin = ShopAdminService::getAdminInfo($adminId);
  104. ShopAdminClass::valid($originalAdmin, $this->ghsId);
  105. AdminClass::updateById($adminId, $post);
  106. util::complete('修改成功');
  107. }
  108. //删除员工关系 shish 2021.1.14
  109. public function actionDelete()
  110. {
  111. $id = Yii::$app->request->get('id');
  112. $relation = ShopAdminClass::getById($id);
  113. $adminId = $relation['adminId'] ?? 0;
  114. $admin = ShopAdminService::getAdminInfo($adminId);
  115. ShopAdminClass::valid($admin, $this->ghsId);
  116. ShopAdminClass::deleteById($id);
  117. util::complete();
  118. }
  119. }