AdminController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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::ok();
  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. AdminService::updateAdmin($originalAdmin, $post);
  53. util::ok('修改成功');
  54. }
  55. //查看员工详情 shish 2019.12.9
  56. public function actionDetail()
  57. {
  58. $id = Yii::$app->request->get('id');
  59. $admin = AdminService::getDetail($id);
  60. AdminService::valid($admin, $this->merchantId);
  61. util::success($admin);
  62. }
  63. //密码修改
  64. public function actionPassword()
  65. {
  66. $post = Yii::$app->request->post();
  67. $old = isset($post['old']) ? $post['old'] : '';
  68. $new = isset($post['new']) ? $post['new'] : '';
  69. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  70. if (empty($new)) {
  71. util::fail('请输入新密码');
  72. }
  73. if ($new != $confirm) {
  74. util::fail('二次密码不一致');
  75. }
  76. $admin = $this->admin;
  77. $adminId = $this->adminId;
  78. if (!empty($admin['password'])) {
  79. if (empty($old)) {
  80. util::fail('请填写旧密码');
  81. }
  82. if (password_verify($old, $admin['password']) == false) {
  83. util::fail('旧密码错误');
  84. }
  85. }
  86. AdminService::updateById($adminId, ['password' => password_hash($new, PASSWORD_BCRYPT)]);
  87. util::ok('修改成功');
  88. }
  89. //确认密码修改
  90. public function actionConfirmPassword()
  91. {
  92. $post = Yii::$app->request->post();
  93. $old = isset($post['old']) ? $post['old'] : '';
  94. $new = isset($post['new']) ? $post['new'] : '';
  95. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  96. if (empty($new)) {
  97. util::fail('请输入新密码');
  98. }
  99. if ($new != $confirm) {
  100. util::fail('二次密码不一致');
  101. }
  102. $admin = $this->admin;
  103. $adminId = $this->adminId;
  104. if (!empty($admin['confirmPassword'])) {
  105. if (empty($old)) {
  106. util::fail('请填写旧密码');
  107. }
  108. if (password_verify($old, $admin['confirmPassword']) == false) {
  109. util::fail('旧密码错误');
  110. }
  111. }
  112. AdminService::updateById($adminId, ['confirmPassword' => password_hash($new, PASSWORD_BCRYPT)]);
  113. util::ok('修改成功');
  114. }
  115. //登陆员工的详情 shish 2019.12.26
  116. public function actionLoginDetail()
  117. {
  118. $detail = AdminService::getDetail($this->adminId);
  119. util::success($detail);
  120. }
  121. //收款通知 shish 2020.1.4
  122. public function actionUpdateRemind()
  123. {
  124. $get = Yii::$app->request->get();
  125. $id = isset($get['id']) ? $get['id'] : 0;
  126. $remind = isset($get['remind']) && is_numeric($get['remind']) ? $get['remind'] : 0;
  127. $admin = AdminService::getAdminById($id);
  128. AdminService::valid($admin, $this->merchantId);
  129. AdminService::updateById($id, ['remind' => $remind]);
  130. util::ok();
  131. }
  132. //启用与停用 shish 2020.1.4
  133. public function actionUpdateStatus()
  134. {
  135. $get = Yii::$app->request->get();
  136. $id = isset($get['id']) && is_numeric($get['id']) ? $get['id'] : 0;
  137. $status = isset($get['status']) ? $get['status'] : 0;
  138. $admin = AdminService::getAdminById($id);
  139. AdminService::valid($admin, $this->merchantId);
  140. AdminService::updateById($id, ['status' => $status]);
  141. util::ok();
  142. }
  143. }