From 467601a8596685a1f0de7cd9a327855fb29b3e85 Mon Sep 17 00:00:00 2001 From: tsf <460834639@qq.com> Date: Mon, 20 May 2024 13:56:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/app/controller/Base.php | 5 +- application/app/controller/Index.php | 86 +++++++++++++++------------- application/app/controller/Login.php | 69 +++++++++++----------- application/route.php | 4 +- 4 files changed, 88 insertions(+), 76 deletions(-) diff --git a/application/app/controller/Base.php b/application/app/controller/Base.php index 4d3e11b..52295f7 100644 --- a/application/app/controller/Base.php +++ b/application/app/controller/Base.php @@ -25,7 +25,7 @@ class Base extends Controller{ } // 检查变量是否是一个只有数字的一维数组 - function isNumericArray($array = [1,2,3]) { + function is_num_array($array = [1,2,3]) { if (!is_array($array)) { return false; // 变量不是数组 } @@ -35,8 +35,11 @@ class Base extends Controller{ } } + // $result = Db::table('app_card_data')->where(['is_del'=>1])->cache(true,3600)->column('id');//查询结果缓存3600秒 $result = Db::table('app_card_data')->where(['is_del'=>0])->cache(true,3600)->select();//查询结果缓存3600秒 + dump($result); + die; // dump(array_column($result, 'id')); // die; if(empty(array_diff($array, array_column($result, 'id')))){ diff --git a/application/app/controller/Index.php b/application/app/controller/Index.php index 79dec52..2c16e00 100644 --- a/application/app/controller/Index.php +++ b/application/app/controller/Index.php @@ -28,11 +28,11 @@ class Index extends Base{ // $result = Db::table('admin_user')->select(); // dump($result); // } - // 创建用户 - public function create_user_data(){ - $data = input(); - + public function create_user_data($data = ['aan_id'=>66,'nickname'=>'王小二','birthday'=>'2019-01-01','gender'=>1,'grade'=>'二年级']){ + if(count(input()) > 0){ + $data = input(); + } $verify_result = $this->verify_parameters($data,'register'); if(!is_array($verify_result)){ return $this->msg(10002,$verify_result); @@ -47,23 +47,29 @@ class Index extends Base{ // 获取账号下用户列表 // $type 1获取列表,2获取详细信息 - public function user_card_list($aan_id,$type=1){ - $result = Db::table('app_user_data')->where(['aan_id'=>$aan_id])->select(); + public function get_user_card_list($data = ['aan_id'=>66,'type'=>1]){ + if(count(input()) > 0){ + $data = input(); + } + $result = Db::table('app_user_data')->where(['aan_id'=>$data['aan_id']])->select(); // $result = Db::table('app_user_data')->where(['aan_id'=>$aan_id])->field('id,nickname')->select(); - $data = []; - if($type == 1){ + $temporary_data = []; + if($data['type'] == 1){ for ($i=0; $i < count($result); $i++) { - array_push($data,['id'=>$result[$i]['id'],'nickname'=>$result[$i]['nickname']]); + array_push($temporary_data,['id'=>$result[$i]['id'],'nickname'=>$result[$i]['nickname']]); } }else{ - $data = $result; + $temporary_data = $result; } - return $this->msg(0,'success',$data); + return $this->msg(0,'success',$temporary_data); } // 获取指定用户详细信息 - public function user_data_information($id=11){ - $result = Db::table('app_user_data')->where(['id'=>$id])->field('id,aan_id,nickname,birthday,gender,card_order')->find(); + public function get_user_data_information($data = ['aud_id'=>11]){ + if(count(input()) > 0){ + $data = input(); + } + $result = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,aan_id,nickname,birthday,gender,card_order')->find(); unset($result['ROW_NUMBER']); if($result['card_order'] === ''){ $result['age'] = $this->calculate_age($result['birthday']); @@ -77,8 +83,11 @@ class Index extends Base{ } // 获取所有卡片列表信息 - public function get_card_all_list($id = 11){ - $user_card_list = Db::table('app_user_data')->where(['id'=>$id])->field('id,card_order')->find(); + public function get_card_all_list($data = ['aud_id'=>11]){ + if(count(input()) > 0){ + $data = input(); + } + $user_card_list = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,card_order')->find(); unset($user_card_list['ROW_NUMBER']); $user_card_list['card_order'] = explode(',',$user_card_list['card_order']); $all_card_list = Db::table('app_card_data')->field('id,name')->select(); @@ -97,37 +106,32 @@ class Index extends Base{ } // 保存用户的卡片排序 - public function save_user_card_order($data=['id'=>11,'card_order'=>[2,8]]){ - $data = input(); - if(!array_key_exists('order_list', $data) || !array_key_exists('user_token', $data)){ - return $this->msg(10001,'数据格式错误'); + public function save_user_card_order($data=['aud_id'=>11,'card_order'=>'2,8']){ + if(count(input()) > 0){ + $data = input(); } - if(!$this->isNumericArray($data['order_list'])){ + if(!array_key_exists('aud_id', $data) || !array_key_exists('card_order', $data)){ + return $this->msg(10001,'数据参数错误'); + } + // dump($data['card_order']); + // dump(explode(',',$data['card_order'])); + // die; + dump($this->is_num_array(explode(',',$data['card_order']))); + die; + if(!$this->is_num_array(explode(',',$data['card_order']))){ return $this->msg(10002,'数据内参数格式或值错误'); } + $data['card_order'] = json_encode($data['card_order']); - $result = Db::table('app_user_data')->where(['id'=>$data['id']])->update(['card_order'=>implode(',',$data['card_order'])]); - return $this->msg(0,'success'); - } - - // 存储卡片顺序 - // $data = ['id'=>'xxxxxxxxxxxxxxx','card_order'=>[1,2,3,4,5]] - public function save_card_order(){ - $data = input(); - if(!array_key_exists('order_list', $data) || !array_key_exists('user_token', $data)){ - return $this->msg(10001,'数据格式错误'); - } - if(!$this->isNumericArray($data['order_list'])){ - return $this->msg(10002,'数据内参数格式或值错误'); - } - $data['order_list'] = json_encode($data['order_list']); - $result = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->update(['card_order'=>$data['order_list']]); + $result = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->update(['card_order'=>$data['card_order']]); if($result){ return $this->msg(0,'success'); }else{ - return $this->msg(10003,'修改失败'); + return $this->msg(10003,'保存失败或未发生改变'); } + } + ################################获取账号下信息操作################################ // 获取账号下首页卡片的基础数据 @@ -194,14 +198,16 @@ class Index extends Base{ $parameter['create_time'] = date('Y-m-d H:i:s'); $parameter['last_update_time'] = date('Y-m-d H:i:s'); + $result = Db::table('app_user_data')->where(['nickname'=>$parameter['nickname'],'aan_id'=>$parameter['aan_id']])->count(); + if($result>0){ + return '该成员已存在'; + } return $parameter; } - public function msg($code,$msg='',$data=[]){ - return json(['code'=>$code,'msg'=>$msg,'data'=>$data]); - } + } \ No newline at end of file diff --git a/application/app/controller/Login.php b/application/app/controller/Login.php index 9c27b5d..4ee8ebb 100644 --- a/application/app/controller/Login.php +++ b/application/app/controller/Login.php @@ -18,11 +18,11 @@ class Login extends Base{ ################################################################个人资料卡################################################################ // 注册 - public function register_action($data = ['tel'=>18866668889,'password'=>'ceshi','code'=>'123456']){ + public function register_action($data = ['data'=>15588885555,'password'=>'ceshi','code'=>'123456']){ // dump('123'); - phpinfo(); - die; + // phpinfo(); + // die; if(count(input()) > 0){ $data = input(); } @@ -30,7 +30,8 @@ class Login extends Base{ if(!is_array($verify_result)){ return $this->msg(10001,$verify_result); } - // dump('321'); + // dump($verify_result); + // die; // 记录 $result = Db::table('app_account_number')->insert($verify_result); if($result){ @@ -47,7 +48,7 @@ class Login extends Base{ $data = input(); } - if(!array_key_exists('data', $data) || !array_key_exists('validate_data', $data) || !array_key_exists('type', $data) || !array_key_exists('validate_type', $data)){ + if(!array_key_exists('data', $data) || !array_key_exists('validate_data', $data) || !array_key_exists('validate_type', $data)){ return $this->msg(10001,'参数缺失'); } // 检测是否为手机 @@ -60,19 +61,24 @@ class Login extends Base{ } // 检测校验途径 if($data['validate_type'] == 'code'){ - $code_name = $data['data']."_".$road."_".$data['type']; + $code_name = $data['data']; // dump(cache($code_name)); // die; if(cache($code_name) == $data['validate_data']){ - return $this->msg(0,'success',$data); + $result = Db::table('app_account_number')->where(['tel'=>$verify_result['tel']])->find(); + if($result){ + return $this->msg(0,'success',$result['id']); + }else{ + return $this->msg(10002,'登录失败,无效账号'); + } }else{ return $this->msg(10001,'登录失败,验证码错误或失效'); } }else if($data['validate_type'] == 'password'){ $verify_result['password'] = $data['validate_data']; - $result = Db::table('app_account_number')->where($verify_result)->count(); + $result = Db::table('app_account_number')->where($verify_result)->find(); if($result){ - return $this->msg(0,'success'); + return $this->msg(0,'success',$result['id']); }else{ return $this->msg(10001,'登录失败,账号/密码错误'); } @@ -105,7 +111,7 @@ class Login extends Base{ $road = 'email'; } if(is_array($result) && $result['code'] == 0){ - cache($data['data']."_".$road."_".$data['type'], $num, 60); + cache($data['data'], $num, 60); // dump($data['data']."_".$data['road']."_".$data['type']); return $this->msg(0,'success',$num); // return true; @@ -230,17 +236,15 @@ class Login extends Base{ public function verify_parameters($data,$type){ // 设置验证 $rule = [ - 'tel' => 'number|length:11', + 'data' => 'require', 'password' => 'require', - 'email' => 'email', - 'code' => 'number', + 'code' => 'require|number', ]; $msg = [ 'password.require' => '密码必须', - 'tel.number' => '手机必须是数字', + 'data.require' => '手机或邮箱必须', 'code.number' => '验证码必须是数字', - 'tel.length' => '手机必须是11位', - 'email' => '邮箱格式错误', + 'code.number' => '验证码必须', ]; $validate = new Validate($rule,$msg); $result = $validate->check($data); @@ -249,31 +253,30 @@ class Login extends Base{ } // dump('3211'); // 判断参数 - if(array_key_exists('tel', $data)){ - $parameter['tel'] = $data['tel']; - $parameter['password'] = $data['password']; + if(preg_match('/^\d{11}$/', $data['data'])){ + $parameter['tel'] = $data['data']; $montage_data = 'tel'; - }else if(array_key_exists('email', $data)){ - $parameter['email'] = $data['email']; - $parameter['password'] = $data['password']; - $montage_data = 'email'; }else{ - return '手机/邮箱必须'; + $parameter['email'] = $data['data']; + $montage_data = 'email'; } + $parameter['password'] = $data['password']; - dump($montage_data); + // dump($montage_data); + // dump( $parameter); // 检验是否注册过 if($montage_data == 'tel'){ - // $inspect_repeat = Db::table('app_account_number')->where(['tel'=>$parameter['tel'],'password'=>$parameter['password']])->count(); - $inspect_repeat = Db::query("select count(*) from app_account_number where tel='".$parameter['tel']."'and password='".$parameter['password']); + $inspect_repeat = Db::table('app_account_number')->where(['tel'=>$parameter['tel']])->count(); + // $inspect_repeat = Db::query("select count(*) from app_account_number where tel='".$parameter['tel']."'and password='".$parameter['password']); }else{ - $inspect_repeat = Db::table('app_account_number')->where(['email'=>$parameter['email'],'password'=>$parameter['password']])->count(); + $inspect_repeat = Db::table('app_account_number')->where(['email'=>$parameter['email']])->count(); } - - dump($inspect_repeat); + // dump( $inspect_repeat); + // die; + // dump($inspect_repeat); // dump('3212'); - if($inspect_repeat){ + if($inspect_repeat>0){ return '注册失败,账号已存在'; } @@ -281,10 +284,10 @@ class Login extends Base{ if($type == 'register'){ if(array_key_exists('code', $data)){ // dump($parameter[$montage_data]."_".$montage_data."_register".'='.cache($parameter[$montage_data]."_".$montage_data."_register")); - if(cache($parameter[$montage_data]."_".$montage_data."_register") == false){ + if(cache($parameter[$montage_data]) == false){ return '验证码过期'; }else{ - if($data['code'] != cache($parameter[$montage_data]."_".$montage_data."_register")){ + if($data['code'] != cache($parameter[$montage_data])){ return '验证码错误'; } } diff --git a/application/route.php b/application/route.php index b34dd02..ca3483a 100644 --- a/application/route.php +++ b/application/route.php @@ -47,9 +47,9 @@ Route::any('/send_phone_email_code', 'app/login/send_phone_email_code'); // 创建用户 Route::any('/create_user_data', 'app/index/create_user_data'); // 获取账号下用户列表 -Route::any('/user_card_list', 'app/index/user_card_list'); +Route::any('/get_user_card_list', 'app/index/get_user_card_list'); // 获取指定用户详细信息 -Route::any('/user_data_information', 'app/index/user_data_information'); +Route::any('/get_user_data_information', 'app/index/get_user_data_information'); // 获取所有卡片列表信息 Route::any('/get_card_all_list', 'app/index/get_card_all_list'); // 保存用户的卡片排序