| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- namespace business\controllers;
- use biz\admin\classes\AdminClass;
- use biz\admin\services\AdminService;
- use common\components\jwt;
- use common\components\util;
- use Yii;
- use yii\web\Controller;
- class AdminController extends BaseController
- {
-
- public $withoutLogin = [];
-
- //获取登陆员工的权限 shish 2019.11.24
- public function actionLoginAuth()
- {
- $auth = AdminService::getAuth($this->adminId, $this->merchantId);
- util::success($auth);
- }
-
- //员工列表 shish 2019.12.8
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $where['merchantId'] = $this->merchantId;
- $list = AdminService::getAdminList($where);
- util::success($list);
- }
-
- //添加员工 shish 2019.12.8
- public function actionAdd()
- {
- $post = Yii::$app->request->post();
- $post['merchantId'] = $this->merchantId;
- $admin = AdminService::addAdmin($post);
- $id = $admin['id'];
- $info = AdminService::getDetail($id);
- util::success($info);
- }
-
- //删除员工 shish 2019.12.9
- public function actionDelete()
- {
- $id = Yii::$app->request->get('id');
- $admin = AdminClass::getById($id);
- AdminService::valid($admin, $this->merchantId);
- AdminService::deleteAdmin($admin, $this->adminId);
- util::ok();
- }
-
- //修改员工 shish 2019.12.9
- public function actionUpdate()
- {
- $post = Yii::$app->request->post();
- $id = isset($post['id']) && is_numeric($post['id']) ? $post['id'] : 0;
- unset($post['id']);
- $originalAdmin = AdminService::getById($id);
- AdminService::updateAdmin($originalAdmin, $post);
- util::ok('修改成功');
- }
-
- //查看员工详情 shish 2019.12.9
- public function actionDetail()
- {
- $id = Yii::$app->request->get('id');
- $admin = AdminService::getDetail($id);
- AdminService::valid($admin, $this->merchantId);
- util::success($admin);
- }
-
- //密码修改
- public function actionPassword()
- {
- $post = Yii::$app->request->post();
- $old = isset($post['old']) ? $post['old'] : '';
- $new = isset($post['new']) ? $post['new'] : '';
- $confirm = isset($post['confirm']) ? $post['confirm'] : '';
- if (empty($new)) {
- util::fail('请输入新密码');
- }
- if ($new != $confirm) {
- util::fail('二次密码不一致');
- }
- $admin = $this->admin;
- $adminId = $this->adminId;
- if (!empty($admin['password'])) {
- if (empty($old)) {
- util::fail('请填写旧密码');
- }
- if (password_verify($old, $admin['password']) == false) {
- util::fail('旧密码错误');
- }
- }
- AdminService::updateById($adminId, ['password' => password_hash($new, PASSWORD_BCRYPT)]);
- util::ok('修改成功');
- }
-
- //确认密码修改
- public function actionConfirmPassword()
- {
- $post = Yii::$app->request->post();
- $old = isset($post['old']) ? $post['old'] : '';
- $new = isset($post['new']) ? $post['new'] : '';
- $confirm = isset($post['confirm']) ? $post['confirm'] : '';
- if (empty($new)) {
- util::fail('请输入新密码');
- }
- if ($new != $confirm) {
- util::fail('二次密码不一致');
- }
- $admin = $this->admin;
- $adminId = $this->adminId;
- if (!empty($admin['confirmPassword'])) {
- if (empty($old)) {
- util::fail('请填写旧密码');
- }
- if (password_verify($old, $admin['confirmPassword']) == false) {
- util::fail('旧密码错误');
- }
- }
- AdminService::updateById($adminId, ['confirmPassword' => password_hash($new, PASSWORD_BCRYPT)]);
- util::ok('修改成功');
- }
-
- //登陆员工的详情 shish 2019.12.26
- public function actionLoginDetail()
- {
- $detail = AdminService::getDetail($this->adminId);
- util::success($detail);
- }
-
- //收款通知 shish 2020.1.4
- public function actionUpdateRemind()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $remind = isset($get['remind']) && is_numeric($get['remind']) ? $get['remind'] : 0;
- $admin = AdminService::getAdminById($id);
- AdminService::valid($admin, $this->merchantId);
- AdminService::updateById($id, ['remind' => $remind]);
- util::ok();
- }
- //启用与停用 shish 2020.1.4
- public function actionUpdateStatus()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) && is_numeric($get['id']) ? $get['id'] : 0;
- $status = isset($get['status']) ? $get['status'] : 0;
- $admin = AdminService::getAdminById($id);
- AdminService::valid($admin, $this->merchantId);
- AdminService::updateById($id, ['status' => $status]);
- util::ok();
- }
- }
|