error('参数错误'); } if (!Validate::regex($phone, "^1\d{10}$")) { $this->error('手机号格式错误'); } //验证短信验证码 $time = time()-60; $sms = Db::name('store_sms')->where(['mobile' => $phone, 'event' => 'register']) ->where('createtime','>',$time) ->order('id', 'DESC') ->find(); if (!$sms || $sms['code'] != $ver_code) $this->error('短信验证码不正确!'); $user = Db::name('store_member') ->where('is_deleted',0) ->where('phone',$phone) ->find(); if ($user) $this->error('手机号已注册'); if (!preg_match('/^[0-9a-z]{6,12}$/i',$password)) $this->error('密码格式错误,请输入6-12位数字+字母'); if ($password!=$confirm_password) $this->error('密码与确认密码不一致'); if (!preg_match('/^[0-9]{6}$/i',$second_password)) $this->error('支付密码格式错误,请输入6位纯数字'); if ($second_password!=$confirm_second_password) $this->error('支付密码与确认密码不一致'); if ($invite_code){ $isset = Db::name('store_member')->where('is_deleted',0)->where('invite_code',$invite_code)->find(); if (!$isset) $this->error('邀请码不存在'); $invitecode = $isset['id']; }else{ $invitecode = 0; } $accountName = $phone; $data = [ 'phone'=>$phone, 'pid'=>$invitecode, 'password'=>md5($password), 'second_password'=>md5($second_password), 'wallet_address'=>'', 'accountName'=>$accountName, 'money'=> '0.00', 'name'=> '象链'.substr($phone,7) ]; $member_id = Db::name('store_member')->insertGetId($data); if ($member_id){ $code = get32Str(8); $invite_img = setintivecode($code); $invite_address = getintiveaddress($code); Db::name('store_member')->where('id',$member_id)->update(['invite_img'=>$invite_img,'invite_address'=>$invite_address,'invite_code'=>$code]); //邀请好友送积分 if ($invite_code>0){ $invite_friends_integral = getConfigValue('invite_friends_integral'); //memberMoneyChange($invite_friends_integral,1,$invite_code,'邀请好友',1,$member_id); } $this->success('注册成功'); } $this->error('注册失败'); } /** * @title 登录 * @desc 登录 * @url /api/Login/passwordLogin * @method POST * @tag 基础 * @header * @param name:phone type:int require:1 default:-- desc:手机号 * @param name:password type:string require:1 default:-- desc:密码 * @return name:token type:string default:-- desc:用户登录成功后的token值 */ public function passwordLogin() { $phone = input('phone'); $password = input('password'); if (empty($password) || empty($phone)) { $this->error('参数错误'); } $member = Db::name('store_member') ->where('phone', $phone) ->where('is_deleted',0) ->find(); if (!$member) $this->error('手机号未注册'); if ($member['password']!=md5($password)) $this->error('密码错误'); $token = self::create_jwt($member['id']); setMemberInfoHash($member['id']); $this->success('登录成功', $token); } //token加密 public function create_jwt($uid) { $key = md5(config('app.jwt')); //jwt的签发密钥,验证token的时候需要用到 $time = time(); //签发时间 $expire = $time + config('app.jwt_time'); //过期时间 $token = array( "uid" => $uid, "iss" => "https://zain.com",//签发组织 "aud" => "https://zain.com", //签发作者 "iat" => $time, "nbf" => $time, "exp" => $expire ); $jwt = JWT::encode($token, $key); return $jwt; } /** * @title 找回密码 * @desc 找回密码 * @url /api/Login/ForgetPassword * @method POST * @tag 基础 * @header * @param name:phone type:int require:1 default:-- desc:手机号 * @param name:ver_code type:string require:1 desc:验证码 * @param name:password type:string require:1 default:-- desc:密码 * @param name:confirm_password type:string require:1 desc:确认密码 */ public function ForgetPassword(){ $phone = input('phone'); $ver_code = input('ver_code'); $password = input('password'); $confirm_password = input('confirm_password'); if (!$phone || !$ver_code || !$password || !$confirm_password) $this->error('参数错误'); $member = Db::name('store_member') ->where('phone', $phone) ->where('is_deleted',0) ->find(); if (!$member) $this->error('手机号未注册'); //验证短信验证码 $time = time()-60; $sms = Db::name('store_sms')->where(['mobile' => $phone, 'event' => 'forgetpwd']) ->where('createtime','>',$time) ->order('id', 'DESC') ->find(); if (!$sms || $sms['code'] != $ver_code) $this->error('短信验证码不正确!'); if (!preg_match('/^[0-9a-z]{6,12}$/i',$password)) $this->error('密码格式错误,请输入6-12位数字+字母'); if ($password!=$confirm_password) $this->error('密码与确认密码不一致'); $data = [ 'password'=>md5($password), 'update_at'=>date('Y-m-d H:i:s') ]; if (Db::name('store_member')->where('id',$member['id'])->update($data)) $this->success('修改成功'); $this->error('修改失败'); } public function test(){ $list = Db::name('store_collection')->select(); foreach ($list as &$v){ $cover = str_replace('https://fanyi.fanyiys.com/','https://fanyisc.oss-cn-hangzhou.aliyuncs.com/',$v['auth_img']); echo $cover."
"; Db::name('store_collection')->where('id',$v['id'])->update(['auth_img'=>$cover]); } // $list = Db::name('store_order_info')->select(); // foreach ($list as &$v){ // $data = []; // $info = Db::name('store_collection')->where('id',$v['c_id'])->find(); // $data['cover'] = $info['cover']; // $data['pro_info'] = json_encode($info,true); // Db::name('store_order_info')->where('id',$v['id'])->update($data); // echo $v['id']."
"; // // } // $ids = Db::name('store_order_info')->group('c_id')->column('c_id'); // $redis = new Redis(); // foreach ($ids as &$v){ // $max = Db::name('store_order_info')->where('c_id',$v)->order('id desc')->field('id,tag,c_id')->limit(1)->find(); // $tag = explode('#',$max['tag']); // $num = explode('/',$tag[1]); // $number = (int)$num[0]; // $redis->set('ranking'.$v,$number); // dump($max)."
"; // } // $redis = new Redis(); // $list = Db::name('hash')->where('status',0)->select(); // foreach ($list as &$v){ // //存入reids list // $redis_data = ['hash'=>$v['hash'],'tokenid'=>$v['tokenid'],'create_at'=>$v['create_at']]; // $redis->rPush('collectionHash_'.$v['goods_id'],json_encode($redis_data)); // echo $v['hash']."
"; // } $redis = new Redis(); $list = Db::name('store_collection')->select(); foreach ($list as &$v){ $buy_count = Db::name('store_order_info') ->whereIn('status','1,3') ->where('c_id',$v['id']) ->count(); $now = $v['inventory']-$buy_count; $redis->set('collection_count_'.$v['id'],$now); echo $v['id']."
"; } } }