ShopAdminController.php 4.4 KB

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