AdminController.php 4.4 KB

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