zhangwei #2
|
@ -12,26 +12,26 @@ class SystemLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||||
public function setSearch(): array
|
public function setSearch(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'=' => ['system_status'],
|
'=' => ['status'],
|
||||||
'%like%' => ['system_name'],
|
'%like%' => ['name'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取列表
|
// 获取列表
|
||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
$field = "id,system_name,system_appid,system_appkey,system_url,create_time,system_status";
|
$field = "id,name,app_id,app_key,url,status,create_time";
|
||||||
return System::field($field)->where($this->searchWhere)->where('system_status','<>',2)
|
return System::field($field)->where($this->searchWhere)->where('status','<>',2)
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order('id desc')
|
->order('id desc')
|
||||||
->select()->each(function($item){
|
->select()->each(function($item){
|
||||||
$item['system_status_text'] = $item->system_status_text;
|
$item['status_text'] = $item->status_text;
|
||||||
})->toArray();
|
})->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取数量
|
// 获取数量
|
||||||
public function count(): int
|
public function count(): int
|
||||||
{
|
{
|
||||||
return System::field('id')->where($this->searchWhere)->where('system_status','<>',2)->count();
|
return System::field('id')->where($this->searchWhere)->where('status','<>',2)->count();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,11 +12,11 @@ class SystemLogic extends BaseLogic
|
||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
System::create([
|
System::create([
|
||||||
'system_name' => $params['system_name'],
|
'name' => $params['name'],
|
||||||
'system_url' => $params['system_url'],
|
'url' => $params['url'],
|
||||||
'system_appid' => create_appid(),
|
'app_id' => create_app_id(),
|
||||||
'system_appkey' => create_appkey(),
|
'app_key' => create_app_key(),
|
||||||
'system_status' => 0,
|
'status' => 0,
|
||||||
]);
|
]);
|
||||||
return true;
|
return true;
|
||||||
}catch (\Exception $e) {
|
}catch (\Exception $e) {
|
||||||
|
@ -31,7 +31,7 @@ class SystemLogic extends BaseLogic
|
||||||
try {
|
try {
|
||||||
System::update([
|
System::update([
|
||||||
'id' => $params['id'],
|
'id' => $params['id'],
|
||||||
'system_status' => 2,
|
'status' => 2,
|
||||||
'update_time' => time()
|
'update_time' => time()
|
||||||
]);
|
]);
|
||||||
return true;
|
return true;
|
||||||
|
@ -47,9 +47,9 @@ class SystemLogic extends BaseLogic
|
||||||
try {
|
try {
|
||||||
System::update([
|
System::update([
|
||||||
'id' => $params['id'],
|
'id' => $params['id'],
|
||||||
'system_name' => $params['system_name'],
|
'name' => $params['name'],
|
||||||
'system_url' => $params['system_url'],
|
'url' => $params['url'],
|
||||||
'system_status' => $params['system_status'],
|
'status' => $params['status'],
|
||||||
'update_time' => time()
|
'update_time' => time()
|
||||||
]);
|
]);
|
||||||
return true;
|
return true;
|
||||||
|
@ -62,8 +62,8 @@ class SystemLogic extends BaseLogic
|
||||||
// 查看
|
// 查看
|
||||||
public static function detail($params) : array
|
public static function detail($params) : array
|
||||||
{
|
{
|
||||||
$data = System::field('id,system_name,system_appid,system_appkey,system_url,system_status,system_type,create_time')->findOrEmpty($params['id']);
|
$data = System::field('id,name,app_id,app_key,url,status,create_time')->findOrEmpty($params['id']);
|
||||||
$data['system_status_text'] = $data->system_status_text;
|
$data['status_text'] = $data->status_text;
|
||||||
return $data->toArray();
|
return $data->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,7 +16,7 @@ use think\response\Json;
|
||||||
class LoginController extends BaseApiController
|
class LoginController extends BaseApiController
|
||||||
{
|
{
|
||||||
// 免登录方法
|
// 免登录方法
|
||||||
public array $notNeedLogin = ['register', 'login', 'logout', 'verify'];
|
public array $notNeedLogin = ['register', 'login', 'verify'];
|
||||||
|
|
||||||
// 注册
|
// 注册
|
||||||
public function register(): Json
|
public function register(): Json
|
||||||
|
@ -43,8 +43,12 @@ class LoginController extends BaseApiController
|
||||||
// 退出
|
// 退出
|
||||||
public function logout(): Json
|
public function logout(): Json
|
||||||
{
|
{
|
||||||
LoginLogic::logout($this->userInfo);
|
$result = LoginLogic::logout($this->userInfo);
|
||||||
return $this->success();
|
if($result){
|
||||||
|
return $this->success('成功');
|
||||||
|
}else{
|
||||||
|
return $this->fail('失败');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证token
|
// 验证token
|
||||||
|
|
|
@ -18,7 +18,7 @@ class UserController extends BaseApiController
|
||||||
$params = (new PasswordValidate())->post()->goCheck('resetPassword');
|
$params = (new PasswordValidate())->post()->goCheck('resetPassword');
|
||||||
$result = UserLogic::resetPassword($params);
|
$result = UserLogic::resetPassword($params);
|
||||||
if (true === $result) {
|
if (true === $result) {
|
||||||
return $this->success('操作成功', [], 1, 1);
|
return $this->success('操作成功');
|
||||||
}
|
}
|
||||||
return $this->fail(UserLogic::getError());
|
return $this->fail(UserLogic::getError());
|
||||||
}
|
}
|
||||||
|
@ -29,25 +29,30 @@ class UserController extends BaseApiController
|
||||||
$params = (new PasswordValidate())->post()->goCheck('changePassword');
|
$params = (new PasswordValidate())->post()->goCheck('changePassword');
|
||||||
$result = UserLogic::changePassword($params, $this->userId);
|
$result = UserLogic::changePassword($params, $this->userId);
|
||||||
if (true === $result) {
|
if (true === $result) {
|
||||||
return $this->success('操作成功', [], 1, 1);
|
return $this->success('操作成功');
|
||||||
}
|
}
|
||||||
return $this->fail(UserLogic::getError());
|
return $this->fail(UserLogic::getError());
|
||||||
}
|
}
|
||||||
|
|
||||||
//绑定/变更 手机号
|
//绑定/变更 手机号
|
||||||
public function bindMobile(): Json
|
public function changeMobile(): Json
|
||||||
{
|
{
|
||||||
$params = (new UserValidate())->post()->goCheck('bindMobile');
|
$params = (new UserValidate())->post()->goCheck('changeMobile');
|
||||||
$params['user_id'] = $this->userId;
|
$result = UserLogic::changeMobile($params,$this->userId);
|
||||||
$result = UserLogic::bindMobile($params);
|
|
||||||
if($result) {
|
if($result) {
|
||||||
return $this->success('绑定成功', [], 1, 1);
|
return $this->success('修改成功');
|
||||||
}
|
}
|
||||||
return $this->fail(UserLogic::getError());
|
return $this->fail(UserLogic::getError());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 实名认证
|
// 更新用户信息
|
||||||
public function identifiy() {
|
public function updateUser(): Json
|
||||||
//todo
|
{
|
||||||
|
$params = (new UserValidate())->post()->goCheck('edit');
|
||||||
|
$result = UserLogic::updateUser($params,$this->userId);
|
||||||
|
if($result) {
|
||||||
|
return $this->success('更新成功');
|
||||||
|
}
|
||||||
|
return $this->fail(UserLogic::getError());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -26,7 +26,7 @@ class LoginLogic extends BaseLogic
|
||||||
$adminPassword = create_password($params['phone'], $passwordSalt);
|
$adminPassword = create_password($params['phone'], $passwordSalt);
|
||||||
$userPassword = create_password($params['password'], $passwordSalt);
|
$userPassword = create_password($params['password'], $passwordSalt);
|
||||||
$avatar = env('project.web_domain').'/'.ConfigService::get('default_image', 'user_avatar');
|
$avatar = env('project.web_domain').'/'.ConfigService::get('default_image', 'user_avatar');
|
||||||
(new Db)->startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
//添加到管理员表
|
//添加到管理员表
|
||||||
$admin = Admin::create([
|
$admin = Admin::create([
|
||||||
|
@ -42,28 +42,30 @@ class LoginLogic extends BaseLogic
|
||||||
$user = User::create([
|
$user = User::create([
|
||||||
'admin_id' => $admin['id'],
|
'admin_id' => $admin['id'],
|
||||||
'phone' => $params['phone'],
|
'phone' => $params['phone'],
|
||||||
'nickname' => '用户'.$params['phone'],
|
'nick_name' => '用户'.$params['phone'],
|
||||||
'password' => $userPassword,
|
'password' => $userPassword,
|
||||||
'avatar' => empty($params['avatar']) ? $avatar : $params['avatar'],
|
'avatar' => empty($params['avatar']) ? $avatar : $params['avatar'],
|
||||||
'age' => $params['age'],
|
'age' => empty($params['age']) ? 0 : $params['age'],
|
||||||
'gender' => $params['gender'],
|
'gender' => empty($params['gender']) ? 0 : $params['gender'],
|
||||||
'province' => $params['province'],
|
'real_name' => empty($params['real_name']) ? '' : $params['real_name'],
|
||||||
'city' => $params['city'],
|
'id_card' => empty($params['id_card']) ? '' : $params['id_card'],
|
||||||
'area' => $params['area'],
|
'province' => empty($params['province']) ? 0 : $params['province'],
|
||||||
'street' => $params['street'],
|
'city' => empty($params['city']) ? 0 : $params['city'],
|
||||||
'village' => $params['village'],
|
'area' => empty($params['area']) ? 0 : $params['area'],
|
||||||
'brigade' => $params['brigade'],
|
'street' => empty($params['street']) ? 0 : $params['street'],
|
||||||
'address' => $params['address'],
|
'village' => empty($params['village']) ? 0 : $params['village'],
|
||||||
|
'brigade' => empty($params['brigade']) ? 0 : $params['brigade'],
|
||||||
|
'address' => empty($params['address']) ? '' : $params['address'],
|
||||||
]);
|
]);
|
||||||
if(!empty($admin['id']) && !empty($user['id'])){
|
if(!empty($admin['id']) && !empty($user['id'])){
|
||||||
(new Db)->commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
(new Db)->rollback();
|
Db::rollback();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
(new Db)->rollback();
|
Db::rollback();
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
self::setError($e->getMessage());
|
self::setError($e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
|
@ -83,7 +85,7 @@ class LoginLogic extends BaseLogic
|
||||||
//设置token
|
//设置token
|
||||||
$userInfo = UserTokenService::setToken($user->id,0);
|
$userInfo = UserTokenService::setToken($user->id,0);
|
||||||
return [
|
return [
|
||||||
'user_id' => $userInfo['user_id'],
|
'uid' => $userInfo['user_id'],
|
||||||
'phone' => $userInfo['phone'],
|
'phone' => $userInfo['phone'],
|
||||||
'token' => $userInfo['token'],
|
'token' => $userInfo['token'],
|
||||||
];
|
];
|
||||||
|
@ -111,12 +113,12 @@ class LoginLogic extends BaseLogic
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$userInfo = (new UserTokenCache())->getUserInfo($params['token']);
|
$userInfo = (new UserTokenCache())->getUserInfo($params['token']);
|
||||||
if(empty($userInfo)){
|
if(empty($userInfo) || $userInfo['user_id'] != $params['uid']){
|
||||||
self::setError('token无效');
|
self::setError('token无效');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
'user_id' => $userInfo['user_id'],
|
'uid' => $userInfo['user_id'],
|
||||||
'phone' => $userInfo['phone'],
|
'phone' => $userInfo['phone'],
|
||||||
'token' => $userInfo['token'],
|
'token' => $userInfo['token'],
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace app\api\logic;
|
namespace app\api\logic;
|
||||||
use app\common\{enum\notice\NoticeEnum,
|
use app\common\{enum\notice\NoticeEnum, logic\BaseLogic, model\auth\Admin, model\user\User, service\sms\SmsDriver};
|
||||||
logic\BaseLogic,
|
|
||||||
model\user\User,
|
|
||||||
service\sms\SmsDriver,};
|
|
||||||
use think\facade\Config;
|
use think\facade\Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,7 +24,7 @@ class UserLogic extends BaseLogic
|
||||||
$passwordSalt = Config::get('project.unique_identification');
|
$passwordSalt = Config::get('project.unique_identification');
|
||||||
$password = create_password($params['password'], $passwordSalt);
|
$password = create_password($params['password'], $passwordSalt);
|
||||||
// 更新
|
// 更新
|
||||||
User::where('user_phone', $params['phone'])->update(['user_password' => $password]);
|
User::where('phone', $params['phone'])->update(['password' => $password]);
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
self::setError($e->getMessage());
|
self::setError($e->getMessage());
|
||||||
|
@ -47,12 +44,12 @@ class UserLogic extends BaseLogic
|
||||||
$passwordSalt = Config::get('project.unique_identification');
|
$passwordSalt = Config::get('project.unique_identification');
|
||||||
// 加密原密码
|
// 加密原密码
|
||||||
$oldPassword = create_password($params['old_password'], $passwordSalt);
|
$oldPassword = create_password($params['old_password'], $passwordSalt);
|
||||||
if($oldPassword != $user['user_password']){
|
if($oldPassword != $user['password']){
|
||||||
throw new \Exception('原密码不正确');
|
throw new \Exception('原密码不正确');
|
||||||
}
|
}
|
||||||
// 保存密码
|
// 保存密码
|
||||||
$password = create_password($params['password'], $passwordSalt);
|
$password = create_password($params['password'], $passwordSalt);
|
||||||
$user->user_password = $password;
|
$user->password = $password;
|
||||||
$user->save();
|
$user->save();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -61,35 +58,26 @@ class UserLogic extends BaseLogic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//绑定手机号
|
//修改手机号
|
||||||
public static function bindMobile(array $params): bool
|
public static function changeMobile(array $params,int $uid): bool
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// 变更手机号场景
|
$user = User::field('admin_id')->where('id',$uid)->findOrEmpty();
|
||||||
$sceneId = NoticeEnum::CHANGE_MOBILE_CAPTCHA;
|
if($user->isEmpty()){
|
||||||
$where = [
|
throw new \Exception('数据错误');
|
||||||
['id', '=', $params['user_id']],
|
|
||||||
['user_phone', '=', $params['phone']]
|
|
||||||
];
|
|
||||||
// 绑定手机号场景
|
|
||||||
if ($params['type'] == 'bind') {
|
|
||||||
$sceneId = NoticeEnum::BIND_MOBILE_CAPTCHA;
|
|
||||||
$where = [
|
|
||||||
['user_phone', '=', $params['phone']]
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
// 校验短信
|
// 校验短信
|
||||||
$checkSmsCode = (new SmsDriver())->verify($params['phone'], $params['code'], $sceneId);
|
$checkSmsCode = (new SmsDriver())->verify($params['phone'], $params['code'], NoticeEnum::CHANGE_MOBILE_CAPTCHA);
|
||||||
if (!$checkSmsCode) {
|
if (!$checkSmsCode) {
|
||||||
throw new \Exception('验证码错误');
|
throw new \Exception('验证码错误');
|
||||||
}
|
}
|
||||||
$user = User::where($where)->findOrEmpty();
|
|
||||||
if (!$user->isEmpty()) {
|
|
||||||
throw new \Exception('该手机号已被使用');
|
|
||||||
}
|
|
||||||
User::update([
|
User::update([
|
||||||
'id' => $params['user_id'],
|
'id' => $uid,
|
||||||
'user_phone' => $params['phone'],
|
'phone' => $params['phone'],
|
||||||
|
]);
|
||||||
|
Admin::update([
|
||||||
|
'id' => $user['admin_id'],
|
||||||
|
'account' => $params['phone']
|
||||||
]);
|
]);
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -98,4 +86,26 @@ class UserLogic extends BaseLogic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//更新用户信息
|
||||||
|
public static function updateUser(array $params, int $uid): bool
|
||||||
|
{
|
||||||
|
if(empty($params)){
|
||||||
|
self::setError('参数列表为空');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$user = User::where('id',$uid)->findOrEmpty();
|
||||||
|
if ($user->isEmpty()) {
|
||||||
|
self::setError('数据不存在');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$params['id'] = $uid;
|
||||||
|
try {
|
||||||
|
User::update($params);
|
||||||
|
return true;
|
||||||
|
}catch (\Exception $e){
|
||||||
|
self::setError($e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -31,28 +31,28 @@ function create_token(string $extra = '') : string
|
||||||
return md5($salt . $extra . time() . $encryptSalt);
|
return md5($salt . $extra . time() . $encryptSalt);
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_appid()
|
function create_app_id()
|
||||||
{
|
{
|
||||||
$appid = 'AD'.time();
|
$appid = 'AD'.time();
|
||||||
//判断appid是否存在
|
//判断appid是否存在
|
||||||
$system = \app\common\model\systems\System::field('id')->where('system_appid',$appid)->findOrEmpty();
|
$system = \app\common\model\systems\System::field('id')->where('app_id',$appid)->findOrEmpty();
|
||||||
if($system->isEmpty()){
|
if($system->isEmpty()){
|
||||||
return $appid;
|
return $appid;
|
||||||
}else{
|
}else{
|
||||||
create_appid();
|
create_app_id();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_appkey()
|
function create_app_key()
|
||||||
{
|
{
|
||||||
$salt = md5('dc@lh@app_key'.uniqid().microtime());
|
$salt = md5('dc@lh@app_key'.uniqid().microtime());
|
||||||
$appkey = 'AK'.strtoupper(md5($salt.time().$salt));
|
$appkey = 'AK'.strtoupper(md5($salt.time().$salt));
|
||||||
//判断appkey是否存在
|
//判断appkey是否存在
|
||||||
$system = \app\common\model\systems\System::field('id')->where('system_appkey',$appkey)->findOrEmpty();
|
$system = \app\common\model\systems\System::field('id')->where('app_key',$appkey)->findOrEmpty();
|
||||||
if($system->isEmpty()){
|
if($system->isEmpty()){
|
||||||
return $appkey;
|
return $appkey;
|
||||||
}else{
|
}else{
|
||||||
create_appkey();
|
create_app_key();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,9 @@ class System extends BaseModel
|
||||||
{
|
{
|
||||||
protected $name = 'system';
|
protected $name = 'system';
|
||||||
|
|
||||||
public function getSystemStatusTextAttr($value,$data): string
|
public function getStatusTextAttr($value,$data): string
|
||||||
{
|
{
|
||||||
$system_status = [0=>'正常',1=>'禁用',2=>'删除'];
|
$status = [0=>'正常',1=>'禁用',2=>'删除'];
|
||||||
return $system_status[$data['system_status']];
|
return $status[$data['status']];
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,16 +17,28 @@ use think\facade\Config;
|
||||||
class LoginAccountValidate extends BaseValidate
|
class LoginAccountValidate extends BaseValidate
|
||||||
{
|
{
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
|
'account' => 'require|checkAccount',
|
||||||
'scene' => 'require|in:' . LoginEnum::ACCOUNT_PASSWORD . ',' . LoginEnum::MOBILE_CAPTCHA . '|checkScene',
|
'scene' => 'require|in:' . LoginEnum::ACCOUNT_PASSWORD . ',' . LoginEnum::MOBILE_CAPTCHA . '|checkScene',
|
||||||
'account' => 'require',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $message = [
|
protected $message = [
|
||||||
|
'account.require' => '请输入账号',
|
||||||
'scene.require' => '场景不能为空',
|
'scene.require' => '场景不能为空',
|
||||||
'scene.in' => '场景值错误',
|
'scene.in' => '场景值错误',
|
||||||
'account.require' => '请输入账号',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function checkAccount($account): bool|string
|
||||||
|
{
|
||||||
|
$user = User::field('id,status')->where('phone',$account)->findOrEmpty();
|
||||||
|
if($user->isEmpty()){
|
||||||
|
return '账号错误';
|
||||||
|
}
|
||||||
|
if ($user['status'] != 0) {
|
||||||
|
return '用户已冻结或删除';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public function checkScene($scene, $rule, $data): bool|string
|
public function checkScene($scene, $rule, $data): bool|string
|
||||||
{
|
{
|
||||||
// 判断scene的值
|
// 判断scene的值
|
||||||
|
@ -55,17 +67,7 @@ class LoginAccountValidate extends BaseValidate
|
||||||
if (!$userAccountSafeCache->isSafe()) {
|
if (!$userAccountSafeCache->isSafe()) {
|
||||||
return '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试';
|
return '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试';
|
||||||
}
|
}
|
||||||
$userInfo = User::where('phone',$data['account'])->field('password,status')->findOrEmpty();
|
$userInfo = User::field('password')->where('phone',$data['account'])->findOrEmpty();
|
||||||
if ($userInfo->isEmpty()) {
|
|
||||||
return '用户不存在';
|
|
||||||
}
|
|
||||||
if ($userInfo['status'] != 0) {
|
|
||||||
return '用户已冻结或删除';
|
|
||||||
}
|
|
||||||
if (empty($userInfo['password'])) {
|
|
||||||
$userAccountSafeCache->record();
|
|
||||||
return '密码不存在';
|
|
||||||
}
|
|
||||||
$passwordSalt = Config::get('project.unique_identification');
|
$passwordSalt = Config::get('project.unique_identification');
|
||||||
if ($userInfo['password'] !== create_password($password, $passwordSalt)) {
|
if ($userInfo['password'] !== create_password($password, $passwordSalt)) {
|
||||||
$userAccountSafeCache->record();
|
$userAccountSafeCache->record();
|
||||||
|
@ -77,13 +79,6 @@ class LoginAccountValidate extends BaseValidate
|
||||||
|
|
||||||
public function checkCode($code, $rule, $data): bool|string
|
public function checkCode($code, $rule, $data): bool|string
|
||||||
{
|
{
|
||||||
$userInfo = User::where('phone',$data['account'])->field('id,status')->findOrEmpty();
|
|
||||||
if ($userInfo->isEmpty()) {
|
|
||||||
return '用户不存在';
|
|
||||||
}
|
|
||||||
if ($userInfo['status'] != 0) {
|
|
||||||
return '用户已冻结或删除';
|
|
||||||
}
|
|
||||||
$smsDriver = new SmsDriver();
|
$smsDriver = new SmsDriver();
|
||||||
$result = $smsDriver->verify($data['account'], $code, NoticeEnum::LOGIN_CAPTCHA);
|
$result = $smsDriver->verify($data['account'], $code, NoticeEnum::LOGIN_CAPTCHA);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
|
|
|
@ -17,18 +17,19 @@ class RegisterValidate extends BaseValidate
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'phone' => 'require|mobile|unique:user,user_phone',
|
'phone' => 'require|mobile|unique:user',
|
||||||
'password' => 'require|length:6,20',
|
'password' => 'require|length:6,20',
|
||||||
'password_confirm' => 'require|confirm',
|
'password_confirm' => 'require|confirm',
|
||||||
'age' => 'require|number|gt:0',
|
'age' => 'number|gt:0',
|
||||||
'gender' => 'require|in:0,1,2',
|
'gender' => 'in:0,1,2',
|
||||||
'province' => 'require|number',
|
'real_name' => 'chs|length:2,25',
|
||||||
'city' => 'require|number',
|
'id_card' => 'idCard',
|
||||||
'area' => 'require|number',
|
'province' => 'number',
|
||||||
'street' => 'require|number',
|
'city' => 'number',
|
||||||
'village' => 'require|number',
|
'area' => 'number',
|
||||||
'brigade' => 'require|number',
|
'street' => 'number',
|
||||||
'address' => 'require'
|
'village' => 'number',
|
||||||
|
'brigade' => 'number',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $message = [
|
protected $message = [
|
||||||
|
@ -39,24 +40,18 @@ class RegisterValidate extends BaseValidate
|
||||||
'password.length' => '密码须在6-25位之间',
|
'password.length' => '密码须在6-25位之间',
|
||||||
'password_confirm.require' => '请输入确认密码',
|
'password_confirm.require' => '请输入确认密码',
|
||||||
'password_confirm.confirm' => '两次输入的密码不一致',
|
'password_confirm.confirm' => '两次输入的密码不一致',
|
||||||
'age.require' => '请输入用户年龄',
|
|
||||||
'age.number' => '年龄必须是数字',
|
'age.number' => '年龄必须是数字',
|
||||||
'age.gt' => '年龄必须大于0',
|
'age.gt' => '年龄必须大于0',
|
||||||
'gender.require' => '请输入用户性别',
|
|
||||||
'gender.in' => '用户性别值错误',
|
'gender.in' => '用户性别值错误',
|
||||||
'province.require' => '请输入所在省份编码',
|
'real_name.chs' => '真实姓名必须是汉字',
|
||||||
|
'real_name.length' => '真实姓名长度必须大于2个汉字且不得超过25个汉字',
|
||||||
|
'id_card.idCard' => '身份证号码不正确',
|
||||||
'province.number' => '省份编码值错误',
|
'province.number' => '省份编码值错误',
|
||||||
'city.require' => '请输入所在城市编码',
|
|
||||||
'city.number' => '城市编码值错误',
|
'city.number' => '城市编码值错误',
|
||||||
'area.require' => '请输入所在区县编码',
|
|
||||||
'area.number' => '区县编码值错误',
|
'area.number' => '区县编码值错误',
|
||||||
'street.require' => '请输入所在镇街编码',
|
|
||||||
'street.number' => '镇街编码值错误',
|
'street.number' => '镇街编码值错误',
|
||||||
'village.require' => '请输入所在村社编码',
|
|
||||||
'village.number' => '村社编码值错误',
|
'village.number' => '村社编码值错误',
|
||||||
'brigade.require' => '请输入所在小组编码',
|
|
||||||
'brigade.number' => '小组编码值错误',
|
'brigade.number' => '小组编码值错误',
|
||||||
'address.require' => '请输入详细地址'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,11 @@ class TokenValidate extends BaseValidate
|
||||||
{
|
{
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'token' => 'require',
|
'token' => 'require',
|
||||||
|
'uid' => 'require',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $message = [
|
protected $message = [
|
||||||
'phone.require' => '缺少必要参数',
|
'token.require' => '缺少必要参数token',
|
||||||
|
'uid.require' => '缺少必要参数uid',
|
||||||
];
|
];
|
||||||
}
|
}
|
|
@ -13,30 +13,30 @@ class SystemValidate extends BaseValidate
|
||||||
|
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'id' => 'require',
|
'id' => 'require',
|
||||||
'system_name' => 'require|unique:system',
|
'name' => 'require|unique:system',
|
||||||
'system_url' => 'require|uri|unique:system',
|
'url' => 'require|uri|unique:system',
|
||||||
'system_status' => 'require|in:0,1',
|
'status' => 'require|in:0,1',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $message = [
|
protected $message = [
|
||||||
'id.require' => '请选择系统',
|
'id.require' => '请选择系统',
|
||||||
'system_name.require' => '请填写系统名称',
|
'name.require' => '请填写系统名称',
|
||||||
'system_name' => '系统名称已被使用',
|
'name' => '系统名称已被使用',
|
||||||
'system_url.require' => '请填写系统网址',
|
'url.require' => '请填写系统网址',
|
||||||
'system_url.uri' => '系统网址填写错误',
|
'url.uri' => '系统网址填写错误',
|
||||||
'system_url.unique' => '系统网址已被使用',
|
'url.unique' => '系统网址已被使用',
|
||||||
'system_status.require' => '请选择系统状态',
|
'status.require' => '请选择系统状态',
|
||||||
'system_status.in' => '系统状态值错误',
|
'status.in' => '系统状态值错误',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function sceneAdd(): SystemValidate
|
public function sceneAdd(): SystemValidate
|
||||||
{
|
{
|
||||||
return $this->only(['system_name','system_url']);
|
return $this->only(['name','url']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sceneEdit(): SystemValidate
|
public function sceneEdit(): SystemValidate
|
||||||
{
|
{
|
||||||
return $this->only(['id','system_name','system_url','system_status']);
|
return $this->only(['id','_name','url','status']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sceneDetail(): SystemValidate
|
public function sceneDetail(): SystemValidate
|
||||||
|
|
|
@ -3,20 +3,52 @@
|
||||||
namespace app\common\validate\user;
|
namespace app\common\validate\user;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\enum\notice\NoticeEnum;
|
||||||
use app\common\validate\BaseValidate;
|
use app\common\validate\BaseValidate;
|
||||||
|
|
||||||
class UserValidate extends BaseValidate
|
class UserValidate extends BaseValidate
|
||||||
{
|
{
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'id' => 'require',
|
'phone' => 'require|mobile|unique:user',
|
||||||
|
'code' => 'require',
|
||||||
|
'age' => 'number|gt:0',
|
||||||
|
'gender' => 'in:0,1,2',
|
||||||
|
'real_name' => 'chs|length:2,25',
|
||||||
|
'id_card' => 'idCard',
|
||||||
|
'province' => 'number',
|
||||||
|
'city' => 'number',
|
||||||
|
'area' => 'number',
|
||||||
|
'street' => 'number',
|
||||||
|
'village' => 'number',
|
||||||
|
'brigade' => 'number',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $message = [
|
protected $message = [
|
||||||
'id.require' => '请选择用户',
|
'phone.require' => '请输入手机号码',
|
||||||
|
'phone.mobile' => '请输入正确的手机号码',
|
||||||
|
'phone.unique' => '该手机号码已注册',
|
||||||
|
'code.require' => '请输入验证码',
|
||||||
|
'age.number' => '年龄必须是数字',
|
||||||
|
'age.gt' => '年龄必须大于0',
|
||||||
|
'gender.in' => '用户性别值错误',
|
||||||
|
'real_name.chs' => '真实姓名必须是汉字',
|
||||||
|
'real_name.length' => '真实姓名长度必须大于2个汉字且不得超过25个汉字',
|
||||||
|
'id_card.idCard' => '身份证号码不正确',
|
||||||
|
'province.number' => '省份编码值错误',
|
||||||
|
'city.number' => '城市编码值错误',
|
||||||
|
'area.number' => '区县编码值错误',
|
||||||
|
'street.number' => '镇街编码值错误',
|
||||||
|
'village.number' => '村社编码值错误',
|
||||||
|
'brigade.number' => '小组编码值错误',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function sceneDetail(): UserValidate
|
public function sceneChangeMobile(): UserValidate
|
||||||
{
|
{
|
||||||
return $this->only(['id']);
|
return $this->only(['phone','code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sceneEdit(): UserValidate
|
||||||
|
{
|
||||||
|
return $this->only(['age','gender','real_name','id_card','province','city','area','street','village','brigade','address']);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue