Login.php 4.2 KB
<?php
/**
 * Created by PhpStorm.
 * User: yrf
 * Date: 2022/4/3
 * Time: 9:24
 * ResvRaninDate
 * 水库安全运行监测大屏接口
 *
 */

namespace app\api\controller\safeoperation;

use app\admin\model\inspection\Depart;
use app\common\controller\Api;
use fast\Tree;
use think\Db;
use think\Request;

/**
 * 渗压
 */
class Login extends Api
{
    protected $id;
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 雨水情登录
     * @return void
     */
    public function rainwatersituation_login(){
        $account = $this->request->param('account');
        $password = $this->request->param('password');

        if (!$account || !$password) {
            $this->error(__('Invalid parameters'));
        }
        $staffModel = new \app\admin\model\inspection\Staff();
        $staffInfo = $staffModel->where(['is_screen_mng' => '1', "is_regulatory_mng" => '0'])
            ->where("staff_code = '$account' or mobile = '$account'")
            ->find();
        if ($staffInfo) {
            $userModel = new \app\admin\model\User();
            $userInfo = $userModel->where(['id' => $staffInfo['user_id']])->find();
            $departModel = new Depart();
            $departInfo = $departModel->where(['id' => $staffInfo->depart_id])->find();
            if (empty($userInfo)) {
                $this->error('大屏管理员登录信息异常');
            }
            if ($userInfo->password != $this->auth->getEncryptPassword($password, $userInfo->salt)) {
                $this->error('登录密码不正确');
                return false;
            }

            $this->auth->direct($userInfo->id);
            $userInfo->openid = $openid;
            $userInfo->save();

            $user = $this->auth->getUserinfo();
            if ('data' != substr($this->auth->getUserinfo()['avatar'], 0, 4)) {
                $user['avatar'] = 'https://qiniu.ynzhsk.cn' . $this->auth->getUserinfo()['avatar'];
            }
            $data = ['userinfo' => $user, 'depart_name' => $departInfo->depart_name, 'duty' => $staffInfo->duty, 'staff' => $staffInfo];
            $this->success(__('登录成功'), $data);
        } else {
            $this->error('大屏管理员账号不存在');
        }
        $this->success("登陆成功");
    }
    /**
     * 雨水情登录
     * @return void
     */
    public function security_login(){
        $account = $this->request->param('account');
        $password = $this->request->param('password');

        if (!$account || !$password) {
            $this->error(__('Invalid parameters'));
        }
        $staffModel = new \app\admin\model\inspection\Staff();
        $staffInfo = $staffModel->where(['is_screen_mng' => '1', "is_regulatory_mng" => '0'])
            ->where("staff_code = '$account' or mobile = '$account'")
            ->find();
        if ($staffInfo) {
            $userModel = new \app\admin\model\User();
            $userInfo = $userModel->where(['id' => $staffInfo['user_id']])->find();
            $departModel = new Depart();
            $departInfo = $departModel->where(['id' => $staffInfo->depart_id])->find();
            if (empty($userInfo)) {
                $this->error('大屏管理员登录信息异常');
            }
            if ($userInfo->password != $this->auth->getEncryptPassword($password, $userInfo->salt)) {
                $this->error('登录密码不正确');
                return false;
            }

            $this->auth->direct($userInfo->id);
            //$userInfo->openid = $openid;
            $userInfo->save();

            $user = $this->auth->getUserinfo();
            if ('data' != substr($this->auth->getUserinfo()['avatar'], 0, 4)) {
                $user['avatar'] = 'https://qiniu.ynzhsk.cn' . $this->auth->getUserinfo()['avatar'];
            }
            $data = ['userinfo' => $user, 'depart_name' => $departInfo->depart_name, 'duty' => $staffInfo->duty, 'staff' => $staffInfo];
            $this->success(__('登录成功'), $data);
        } else {
            $this->error('大屏管理员账号不存在');
        }
        $this->success("登陆成功");
    }
}