AdminController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace business\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\admin\services\AdminService;
  5. use common\components\jwt;
  6. use common\components\util;
  7. use Yii;
  8. use yii\web\Controller;
  9. class AdminController extends BaseController
  10. {
  11. public $withoutLogin = [];
  12. //获取登陆员工的权限 shish 2019.11.24
  13. public function actionLoginAuth()
  14. {
  15. $auth = AdminService::getAuth($this->adminId, $this->merchantId);
  16. util::success($auth);
  17. }
  18. //员工列表 shish 2019.12.8
  19. public function actionList()
  20. {
  21. $get = Yii::$app->request->get();
  22. $where['merchantId'] = $this->merchantId;
  23. $list = AdminService::getAdminList($where);
  24. util::success($list);
  25. }
  26. //添加员工 shish 2019.12.8
  27. public function actionAdd()
  28. {
  29. $post = Yii::$app->request->post();
  30. $post['merchantId'] = $this->merchantId;
  31. $admin = AdminService::addAdmin($post);
  32. $id = $admin['id'];
  33. $info = AdminService::getDetail($id);
  34. util::success($info);
  35. }
  36. //删除员工 shish 2019.12.9
  37. public function actionDelete()
  38. {
  39. $id = Yii::$app->request->get('id');
  40. $admin = AdminClass::getById($id);
  41. AdminService::valid($admin, $this->merchantId);
  42. AdminService::deleteAdmin($admin, $this->adminId);
  43. util::complete();
  44. }
  45. //修改员工 shish 2019.12.9
  46. public function actionUpdate()
  47. {
  48. $post = Yii::$app->request->post();
  49. $id = isset($post['id']) && is_numeric($post['id']) ? $post['id'] : 0;
  50. unset($post['id']);
  51. $originalAdmin = AdminService::getById($id);
  52. $post['merchantId'] = $this->merchantId;
  53. AdminService::updateAdmin($originalAdmin, $post);
  54. util::complete('修改成功');
  55. }
  56. //查看员工详情 shish 2019.12.9
  57. public function actionDetail()
  58. {
  59. $id = Yii::$app->request->get('id');
  60. $admin = AdminService::getDetail($id);
  61. AdminService::valid($admin, $this->merchantId);
  62. util::success($admin);
  63. }
  64. //密码修改
  65. public function actionPassword()
  66. {
  67. $post = Yii::$app->request->post();
  68. $old = isset($post['old']) ? $post['old'] : '';
  69. $new = isset($post['new']) ? $post['new'] : '';
  70. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  71. if (empty($new)) {
  72. util::fail('请输入新密码');
  73. }
  74. if ($new != $confirm) {
  75. util::fail('二次密码不一致');
  76. }
  77. $admin = $this->admin;
  78. $adminId = $this->adminId;
  79. if (!empty($admin['password'])) {
  80. if (empty($old)) {
  81. util::fail('请填写旧密码');
  82. }
  83. if (password_verify($old, $admin['password']) == false) {
  84. util::fail('旧密码错误');
  85. }
  86. }
  87. AdminService::updateById($adminId, ['password' => password_hash($new, PASSWORD_BCRYPT)]);
  88. util::complete('修改成功');
  89. }
  90. //确认密码修改
  91. public function actionConfirmPassword()
  92. {
  93. $post = Yii::$app->request->post();
  94. $old = isset($post['old']) ? $post['old'] : '';
  95. $new = isset($post['new']) ? $post['new'] : '';
  96. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  97. if (empty($new)) {
  98. util::fail('请输入新密码');
  99. }
  100. if ($new != $confirm) {
  101. util::fail('二次密码不一致');
  102. }
  103. $admin = $this->admin;
  104. $adminId = $this->adminId;
  105. if (!empty($admin['confirmPassword'])) {
  106. if (empty($old)) {
  107. util::fail('请填写旧密码');
  108. }
  109. if (password_verify($old, $admin['confirmPassword']) == false) {
  110. util::fail('旧密码错误');
  111. }
  112. }
  113. AdminService::updateById($adminId, ['confirmPassword' => password_hash($new, PASSWORD_BCRYPT)]);
  114. util::complete('修改成功');
  115. }
  116. //登陆员工的详情 shish 2019.12.26
  117. public function actionLoginDetail()
  118. {
  119. $detail = AdminService::getDetail($this->adminId);
  120. util::success($detail);
  121. }
  122. //收款通知 shish 2020.1.4
  123. public function actionUpdateRemind()
  124. {
  125. $get = Yii::$app->request->get();
  126. $id = isset($get['id']) ? $get['id'] : 0;
  127. $remind = isset($get['remind']) && is_numeric($get['remind']) ? $get['remind'] : 0;
  128. $admin = AdminService::getAdminById($id);
  129. AdminService::valid($admin, $this->merchantId);
  130. AdminService::updateById($id, ['remind' => $remind]);
  131. util::complete();
  132. }
  133. //启用与停用 shish 2020.1.4
  134. public function actionUpdateStatus()
  135. {
  136. $get = Yii::$app->request->get();
  137. $id = isset($get['id']) && is_numeric($get['id']) ? $get['id'] : 0;
  138. $status = isset($get['status']) ? $get['status'] : 0;
  139. $admin = AdminService::getAdminById($id);
  140. AdminService::valid($admin, $this->merchantId);
  141. AdminService::updateById($id, ['status' => $status]);
  142. util::complete();
  143. }
  144. }