90 lines
3.2 KiB
PHP
90 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace app\api\model;
|
|
|
|
use think\Db;
|
|
use think\Model;
|
|
class UserMode extends Model{
|
|
|
|
//开启、修改青少年模式
|
|
public function open_teen_mode($uid, $type, $password, $again_password){
|
|
$user_info = db::name('user')->where('uid',$uid)->find($uid);
|
|
if(!$user_info){
|
|
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
|
}
|
|
|
|
if($password != $again_password){
|
|
return ['code' => 201, 'msg' => '两次密码不一致', 'data' => null];
|
|
}
|
|
if($user_info['is_real']!=1){
|
|
return ['code' => 201, 'msg' => '未实名认证无法开启青少年模式', 'data' => null];
|
|
}
|
|
$data = [];
|
|
if($type == 1){//开启
|
|
$msg = '开启';
|
|
$data['is_teenager'] = 1;
|
|
$data['teenager_password'] = md5($password);
|
|
}else if($type == 2){//修改密码
|
|
if($user_info['is_teenager'] == 2){
|
|
return ['code' => 201, 'msg' => '青少年模式尚未开启', 'data' => null];
|
|
}
|
|
$msg = '修改';
|
|
$data['teenager_password'] = md5($password);
|
|
$data['update_time'] = time();
|
|
}
|
|
|
|
$reslut = db::name('user')->where('uid', $uid)->update($data);
|
|
if($reslut){
|
|
return ['code' => 200, 'msg' => $msg.'成功', 'data' => null];
|
|
}else{
|
|
return ['code' => 201, 'msg' => $msg.'失败', 'data' => null];
|
|
}
|
|
}
|
|
|
|
|
|
//关闭、修改青少年模式
|
|
public function close_teen_mode($uid, $type, $password){
|
|
$user_info = db::name('user')->find($uid);
|
|
if(!$user_info){
|
|
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
|
}
|
|
|
|
if($user_info['is_teenager'] == 2){
|
|
return ['code' => 201, 'msg' => '青少年模式尚未开启', 'data' => null];
|
|
}
|
|
|
|
if(md5($password) != $user_info['teenager_password']){
|
|
return ['code' => 201, 'msg' => '密码不正确', 'data' => null];
|
|
}
|
|
|
|
$data = [];
|
|
if($type == 1){//关闭
|
|
$msg = '关闭';
|
|
$data['is_teenager'] = 2;
|
|
$reslut = db::name('user')->where('uid', $uid)->update($data);
|
|
if($reslut){
|
|
return ['code' => 200, 'msg' => $msg.'成功', 'data' => null];
|
|
}else{
|
|
return ['code' => 201, 'msg' => $msg.'失败', 'data' => null];
|
|
}
|
|
}else if($type == 2){//确认密码
|
|
return ['code' => 200, 'msg' => '密码正确', 'data' => null];
|
|
}
|
|
}
|
|
/**
|
|
* 申诉身份验证
|
|
* @return void
|
|
*/
|
|
public function edit_teen_mode($uid, $card_id, $real_name)
|
|
{
|
|
if (!$card_id || !$real_name) return ['code' => 201, 'msg' => '缺少必要参数失败', 'data' => null];
|
|
$user_info = Db::name('user')->where('uid', $uid)->find();
|
|
if (!$user_info) return ['code' => 201, 'msg' => '用户已被删除或不存在', 'data' => null];
|
|
if($card_id==$user_info['card_id']&&$real_name==$user_info['real_name']){
|
|
return ['code' => 200, 'msg' => '验证成功', 'data' => $user_info];
|
|
}else{
|
|
return ['code' => 201, 'msg' => '验证失败', 'data' => null];
|
|
}
|
|
}
|
|
}
|