ctms/ctms-api/controllers/GmController.php
2025-04-10 23:19:13 +08:00

128 lines
4.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
# @Author: 嗨噜客(三亚) <fm453>
# @Date: 2022-04-15 20:22:03
# @Email: fm453@lukegzs.com
# @Last modified by: fm453
# @Last modified time: 2024-07-06T09:26:30+08:00
# @Copyright: www.hiluker.cn
//管理员用户入口
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use common\models\Member as User;
use addons\models\AcUserExt;
use addons\models\AcStore;
use addons\models\AcEmployee;
use backend\controllers\Common;
class GmController extends Common
{
public function beforeAction($action)
{
if (!$this->pid) {
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
}
return parent::beforeAction($action);
}
public function actionIndex()
{
$this->result('您正使用CMTS系统本接口为内部系统接口禁止非法链接使用', ['total'=>0,'data'=>[],'page'=>1], 200);
}
public function actionLogin()
{
$pid = $this->pid;
$post = $this->postdata;
$search = isset($post['search']) ? $post['search'] : null;
$username = isset($search['username']) ? $search['username'] : null;
$username = isset($post['username']) ? $post['username'] : $username;
$passwd = isset($search['passwd']) ? $search['passwd'] : null;
$passwd = isset($post['passwd']) ? $post['passwd'] : $passwd;
$return = [];
if (!$username && !passwd) {
$this->result('登陆参数错误!', null, 400);
}
if (!$username) {
$this->result('请输入您的账号!', null, 400);
}
if (!$passwd) {
$this->result('请输入您的密码!', null, 400);
}
$username = trim(htmlspecialchars_decode($username));
$passwd = trim(htmlspecialchars_decode($passwd));
if (!$username) {
$this->result('输入错误,请检查您的账号!', null, 400);
}
if (!$passwd) {
$this->result('输入有误,请检查您的密码!', null, 400);
}
$model = new User();
$user = $model->findOne(['mobile' => $username]);
if (!$user) {
$this->result('查无此人!', null, 404);
}
if ($user->status != User::STATUS_ACTIVE) {
$this->result('账户异常,禁止登陆!', null, 403);
}
//安全校验,登陆密码
$isPwdRight = $user->validatePassword($passwd);
if (!$isPwdRight) {
$this->result('密码错误,禁止登陆!', null, 400);
}
//校验结束
// 使用指定用户名获取用户身份实例
$identity = $user;
// 登录用户有效期30d
$duration = 3600 * 24 * 30;
$_login = Yii::$app->user->login($identity, $duration);
if (!$_login) {
$this->result('登陆失败!', null, 400);
}
//登陆成功,返回用户信息
$_user = ['id'=>$user->id,'username'=>$user->username,'mobile'=>$user->mobile,'email'=>$user->email,'avatar'=>Url::to($user->avatar)];
//查询关联网点信息(以登陆手机号为依据)
$AcEmployeeModel = new AcEmployee();
$employee = $AcEmployeeModel->findOne(['mobile'=>$user->mobile]);
if (!$employee) {
$this->result('未找到对应工号,请联系管理员!', null, 404);
}
if ($employee->deleted) {
$this->result('工号已清除,禁止登陆!', null, 403);
}
if (!$employee->status) {
$this->result('工号禁用,禁止登陆!', null, 403);
}
$_user['employee_id'] = $employee->id;
$AcStoreModel = new AcStore();
$store = $AcStoreModel->findOne($employee->store_id);
$_store = [];
$citys = Yii::$app->params['citys'];
if ($store && !$store->deleted) {
$_store= [
'id' => $store->id,
'title' => $store->title,
'city' => isset($citys[$store->city]) ? $citys[$store->city]['name'] : '',
'addr' => $store->addr,
'longt' => $store->longt,
'lat' => $store->lat,
'status' => $store->status_code
];
}
$_user['store'] = $_store;
$this->result('登陆成功!', ['user'=>$_user], 200);
}
}