AdminController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 ($new != $confirm) {
  71. util::fail('二次密码不一致');
  72. }
  73. $admin = $this->admin;
  74. if (empty($old) && !empty($admin['password'])) {
  75. util::fail('请输入旧密码');
  76. }
  77. }
  78. //确认密码修改
  79. public function actionConfirmPassword()
  80. {
  81. $post = Yii::$app->request->post();
  82. $old = isset($post['old']) ? $post['old'] : '';
  83. $new = isset($post['new']) ? $post['new'] : '';
  84. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  85. if ($new != $confirm) {
  86. util::fail('二次密码不一致');
  87. }
  88. }
  89. }