85 lines
2.9 KiB
PHP
85 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace app\api\model;
|
|
use think\Model;
|
|
use think\Db;
|
|
use think\Session;
|
|
|
|
class UserMode extends Model
|
|
{
|
|
// 开启自动写入时间戳字段
|
|
protected $autoWriteTimestamp = true;
|
|
// 定义时间戳字段名
|
|
protected $createTime = 'createtime';
|
|
protected $updateTime = 'updatetime';
|
|
public function __construct($data = [])
|
|
{
|
|
parent::__construct($data);
|
|
// $this->table = config('database.prefix').'user_mode';
|
|
}
|
|
|
|
//开启、修改青少年模式
|
|
public function open_teen_mode($uid, $type, $password, $again_password){
|
|
$user_info = model('User')->get_user_info($uid);
|
|
if(!$user_info){
|
|
return ['code' => 0, 'msg' => '参数错误', 'data' => null];
|
|
}
|
|
|
|
if($password != $again_password){
|
|
return ['code' => 0, 'msg' => '两次密码不一致', 'data' => null];
|
|
}
|
|
if($user_info['is_real']!=1){
|
|
return ['code' => 0, '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' => 0, 'msg' => '青少年模式尚未开启', 'data' => null];
|
|
}
|
|
$msg = '修改';
|
|
$data['teenager_password'] = md5($password);
|
|
$data['updatetime'] = time();
|
|
}
|
|
$reslut = $this->where('user_id', $uid)->update($data);
|
|
if($reslut){
|
|
return ['code' => 1, 'msg' => $msg.'成功', 'data' => null];
|
|
}else{
|
|
return ['code' => 0, 'msg' => $msg.'失败', 'data' => null];
|
|
}
|
|
}
|
|
|
|
//关闭、修改青少年模式
|
|
public function close_teen_mode($uid, $type, $password){
|
|
$user_info = model('User')->get_user_info($uid);
|
|
if(!$user_info){
|
|
return ['code' => 0, 'msg' => '参数错误', 'data' => null];
|
|
}
|
|
|
|
if($user_info['is_teenager'] == 2){
|
|
return ['code' => 0, 'msg' => '青少年模式尚未开启', 'data' => null];
|
|
}
|
|
|
|
if(md5($password) != $user_info['teenager_password']){
|
|
return ['code' => 0, 'msg' => '密码不正确', 'data' => null];
|
|
}
|
|
|
|
$data = [];
|
|
if($type == 1){//关闭
|
|
$msg = '关闭';
|
|
$data['is_teenager'] = 2;
|
|
$reslut = $this->where('user_id', $uid)->update($data);
|
|
if($reslut){
|
|
return ['code' => 1, 'msg' => $msg.'成功', 'data' => null];
|
|
}else{
|
|
return ['code' => 0, 'msg' => $msg.'失败', 'data' => null];
|
|
}
|
|
}else if($type == 2){//确认密码
|
|
return ['code' => 1, 'msg' => '密码正确', 'data' => null];
|
|
}
|
|
}
|
|
}
|