ShopAdminController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. $respond = ShopAdminService::generateAdmin($post);
  40. util::success($respond);
  41. }
  42. //收款通知 shish 2021.1.14
  43. public function actionUpdateRemind()
  44. {
  45. $get = Yii::$app->request->get();
  46. $id = $get['id'] ?? 0;
  47. $remind = $get['remind'] ?? 0;
  48. $relation = ShopAdminClass::getById($id, true);
  49. if (empty($relation)) {
  50. util::fail('没有找到员工');
  51. }
  52. ShopAdminClass::valid($relation->attributes, $this->ghsId);
  53. $relation->remind = $remind;
  54. $relation->save();
  55. util::complete();
  56. }
  57. //启用与停用 shish 2021.1.14
  58. public function actionUpdateStatus()
  59. {
  60. $get = Yii::$app->request->get();
  61. $id = $get['id'] ?? 0;
  62. $status = $get['status'] ?? 0;
  63. $relation = ShopAdminClass::getById($id, true);
  64. if (empty($relation)) {
  65. util::fail('没有找到员工');
  66. }
  67. ShopAdminClass::valid($relation->attributes, $this->ghsId);
  68. $relation->status = $status;
  69. $relation->save();
  70. util::complete();
  71. }
  72. //员工列表 shish 2019.12.8
  73. public function actionList()
  74. {
  75. $get = Yii::$app->request->get();
  76. $where = [];
  77. $where['shopId'] = $this->shopId;
  78. $where['delStatus'] = 0;
  79. $list = ShopAdminService::getAdminList($where);
  80. util::success($list);
  81. }
  82. //获取员工信息 shish 2021.1.13
  83. public function actionDetail()
  84. {
  85. $get = Yii::$app->request->get();
  86. $id = isset($get['id']) ? $get['id'] : 0;
  87. $respond = ShopAdminService::getAdminInfo($id);
  88. ShopAdminClass::valid($respond, $this->ghsId);
  89. util::success($respond);
  90. }
  91. //修改员工信息
  92. public function actionUpdate()
  93. {
  94. $post = Yii::$app->request->post();
  95. $id = isset($post['id']) && is_numeric($post['id']) ? $post['id'] : 0;
  96. $relation = ShopAdminClass::getById($id, true);
  97. unset($post['id']);
  98. $roleId = isset($post['roleId']) && !empty($post['roleId']) ? $post['roleId'] : 0;
  99. $remind = isset($post['remind']) && !empty($post['remind']) ? $post['remind'] : 0;
  100. $relation->roleId = $roleId;
  101. $relation->remind = $remind;
  102. $relation->save();
  103. $adminId = isset($relation->adminId) ? $relation->adminId : 0;
  104. $originalAdmin = ShopAdminService::getAdminInfo($adminId);
  105. ShopAdminClass::valid($originalAdmin, $this->ghsId);
  106. AdminClass::updateById($adminId, $post);
  107. util::complete('修改成功');
  108. }
  109. //删除员工关系 shish 2021.1.14
  110. public function actionDelete()
  111. {
  112. $id = Yii::$app->request->get('id');
  113. $relation = ShopAdminClass::getById($id);
  114. $adminId = $relation['adminId'] ?? 0;
  115. $admin = ShopAdminService::getAdminInfo($adminId);
  116. ShopAdminClass::valid($admin, $this->ghsId);
  117. ShopAdminClass::deleteById($id);
  118. util::complete();
  119. }
  120. }