field($field)->where('id',$this->user_id)->find()->toArray(); if(empty($user_info)) $this->error('用户信息不正确'); $user_info['level_name'] = UserLevel::where('id',$user_info['level_id'])->value('name'); $this->success('获取成功',['detail'=>$user_info,]); } /** * @title 获取个人信息 * @desc 个人信息 * @author qc * @url /api/User_center/getUserInfo * @method GET * @tag 个人信息 * @header name:Authorization require:1 desc:Token * @return name:phone type:int default:-- desc:手机号 * @return name:name type:string default:-- desc:昵称 * @return name:encryption_password type:string default:-- desc:加密密码 * @return name:headimg type:string default:-- desc:头像地址 * @return name:sex type:int default:1 desc:性别(1男2女) * @return name:true_name type:string default:-- desc:真实姓名 * @return name:invite_code type:string default:-- desc:邀请码 * @return name:birthday type:string default:-- desc:出生日期 * @return name:province_name type:string default:-- desc:省 * @return name:city_name type:string default:-- desc:市 * @return name:counties_name type:string default:-- desc:县区 * @return name:bind_wechat type:string default:-- desc:绑定微信号 * @return name:true_name type:string default:-- desc:真实姓名 * @return name:id_card type:string default:-- desc:身份证号 * @return name:is_auth type:int default:-- desc:是否认证(0否1是) * @return name:auth_at type:string default:-- desc:认证时间 * @return name:card_front type:string default:-- desc:身份证正面 * @return name:card_back type:string default:-- desc:身份证背面 * @return name:level_name type:string default:-- desc:等级名称 * @return name:partner_lev type:int default:-- desc:分销商等级id(0不是分销商) * @return name:is_agency type:int default:-- desc:是否是区域代理(0不是) * @return name:fans type:int default:-- desc:粉丝数量 * @return name:collect type:int default:-- desc:收藏量 * @return name:coupon_num type:int default:-- desc:券数量 * @return name:track_num type:int default:-- desc:足迹条数 * @return name:wallet type:array default:-- desc:钱包 * @return name:wallet.integral type:int default:-- desc:积分 * @return name:wallet.growth type:int default:-- desc:经验值(成长值) * @return name:wallet.money type:float default:-- desc:佣金 * @return name:order_stat type:array default:-- desc:订单统计 * @return name:order_stat.no_pay type:int default:-- desc:未支付订单 * @return name:order_stat.no_deliver type:int default:-- desc:未发货 * @return name:order_stat.no_receive type:int default:-- desc:未收货 * @return name:order_stat.no_comment type:int default:-- desc:未评论 * */ public function getUserInfo() { $field = 'id,phone,encryption_password,name,level_id,pay_password,headimg,openid,true_name,sex,invite_code,birthday,province_name,city_name,counties_name,bind_wechat,id_card,card_front,card_back,auth_at,is_agency,partner_lev'; $user_info = User::with('wallet')->field($field)->where('id',$this->user_id)->find()->toArray(); $user_info['level_name'] = UserLevel::where('id',$user_info['level_id'])->value('name'); $user_info['fans'] = User::where('pid',$user_info['id'])->count(); $user_info['collect'] = UserCollect::where('user_id',$user_info['id'])->count(); $user_info['coupon_num'] = UserCouponList::where(['user_id'=>$user_info['id'],'status'=>0])->count(); $user_info['track_num'] = UserTrack::where(['user_id'=>$user_info['id']])->count(); $order_stat = []; $order_stat['no_pay'] = GoodsOrder::where(['user_id'=>$this->user_id,'status'=>0])->count(); $order_stat['no_deliver'] = GoodsOrder::where(['user_id'=>$this->user_id,'status'=>1])->count(); $order_stat['no_receive'] = GoodsOrder::where(['user_id'=>$this->user_id,'status'=>2])->count(); $order_stat['no_comment '] = GoodsOrder::where(['user_id'=>$this->user_id,'status'=>3])->count(); if(empty($user_info)) $this->error('用户信息不正确'); $this->success('获取成功',['detail'=>$user_info,'order_stat'=>$order_stat]); } /** * @title 编辑个人信息 * @desc 编辑个人信息 * @author qc * @url /api/User_center/updateUserInfo * @method POST * @tag 编辑信息 * @header name:Authorization require:1 desc:Token * @param name:name type:string default:-- desc:昵称 * @param name:headimg type:string default:-- desc:头像地址 * @param name:sex type:int default:1 desc:性别(1男2女) * @param name:birthday type:string default:1 desc:出生日期 * @param name:address type:string default:1 desc:地址(山东省-临沂市-兰山区) */ public function updateUserInfo() { $headimg = input('post.headimg'); $name = trim(input('post.name','')); $sex = trim(input('post.sex',1)); $birthday = input('post.birthday'); $address = input('post.address'); $update_data= []; $update_data['name'] = $name; $update_data['headimg'] = $headimg; $update_data['sex'] = $sex; $update_data['birthday'] = $birthday; if($address){ $add_arr = explode('-',$address); $update_data['province_name'] = $add_arr[0]; $update_data['city_name'] = $add_arr[1]; $update_data['counties_name'] = $add_arr[2]; } if($name){ $check_member = Db::name('store_member')->where('name',$name)->where('id','<>',$this->user_id)->count(); if($check_member) $this->error('该用户名已被占用'); } Db::name('store_member')->where('id',$this->user_id)->update($update_data); $field = 'phone,name,headimg'; $user_info = Db::name('store_member')->field($field)->where('id',$this->user_id)->find(); $this->success('编辑成功',$user_info); } /** * @title 绑定手机号 * @desc 绑定手机号 * @author qc * @url /api/User_center/modifyPhone * @method POST * @header name:Authorization require:1 desc:Token * @param name:phone type:int require:1 default:-- desc:手机号 * @param name:code type:int require:1 default:-- desc:手机号验证码 * @return name:phone type:int default:-- desc:手机号 * @return name:name type:string default:-- desc:昵称 * @return name:headimg type:string default:-- desc:头像地址 * @return name:true_name type:string default:-- desc:真实姓名 * @return name:id_card type:string default:-- desc:身份证号 * @return name:is_auth type:int default:-- desc:是否认证(0否1是) */ public function modifyPhone() { $uid = $this->user_id; $phone = input('post.phone'); $code = input('post.code'); if(empty($phone) || empty($code) ) $this->error('参数错误'); $field = 'id,phone,name,headimg,status,openid,true_name,id_card,is_auth'; $user_info = Db::name('store_member')->field($field)->where('id',$this->user_id)->find(); if($user_info['phone'] == $phone)$this->error('更换手机号与绑定手机号一致!'); $check_code = $this->checkPhoneCode($phone,$code); if(!$check_code) $this->error('验证码错误'); //判断手机号是否已注册 $member_id = Db::name('store_member') ->where('phone','=',$phone)->where('is_deleted','=',0)->where('id','<>',$this->user_id)->value('id'); if($member_id) $this->error('手机号已注册过'); Db::name('store_member')->where('id',$uid)->update(['phone'=>$phone]); $user_info['phone'] = $phone; $this->updatePhoneCode($check_code); $this->success('绑定成功',$user_info); } /** * @title 验证已绑定手机号是否正确 * @desc 验证已绑定手机号是否正确 * @author qc * @url /api/User_center/checkBindPhone * @method POST * @header name:Authorization require:1 desc:Token * @param name:phone type:int require:1 default:-- desc:手机号 * @param name:code type:int require:1 default:-- desc:手机号验证码 */ public function checkBindPhone() { $phone = input('post.phone'); $code = input('post.code'); if(empty($phone) || empty($code) ) $this->error('参数错误'); $field = 'id,phone,name,headimg,status,openid,true_name,id_card,is_auth'; $user_info = Db::name('store_member')->field($field)->where('id',$this->user_id)->find(); if($user_info['phone'] != $phone) $this->error('该手机号与当前账户不一致!'); $check_code = $this->checkPhoneCode($phone,$code); if(!$check_code) $this->error('验证码错误'); $this->updatePhoneCode($check_code); $this->success('验证通过'); } /** * @title 更换或设置登录密码 * @desc 更换或设置登录密码 * @author qc * @url /api/User_center/modifyPassword * @method POST * @header name:Authorization require:1 desc:Token * @param name:phone type:int require:1 default:-- desc:手机号 * @param name:code type:int require:1 default:-- desc:手机号验证码 * @param name:password type:string default:-- desc:密码 */ public function modifyPassword() { $uid = $this->user_id; $phone = input('post.phone'); $code = input('post.code'); $password = input('post.password'); if(empty($phone) || empty($code) || empty($password) ) $this->error('参数错误'); $field = 'id,phone'; $user_info = User::field($field)->where('id',$this->user_id)->find()->toArray(); if(!$user_info['phone']) $this->error('请先绑定手机号'); if($user_info['phone'] != $phone) $this->error('与绑定手机号不一致'); $check_code = $this->checkPhoneCode($phone,$code); if(!$check_code) $this->error('验证码错误'); $validate = new UserVali(); if (!$validate->scene('reset_password')->check(['phone'=>$phone,'password'=>$password])) { $this->error($validate->getError()); } $encryption_password = encrypt_password($password); User::where('id',$uid)->update(['password'=>$password,'encryption_password'=>$encryption_password]); $this->updatePhoneCode($check_code); $this->success('更换成功'); } /** * @title 更换或设置提现密码 * @desc 更换或设置提现密码 * @author qc * @url /api/User_center/setPayPassword * @method POST * @header name:Authorization require:1 desc:Token * @param name:phone type:int require:1 default:-- desc:手机号 * @param name:code type:int require:1 default:-- desc:手机号验证码 * @param name:pay_password type:string default:-- desc:密码 */ public function setPayPassword() { $uid = $this->user_id; $phone = input('post.phone'); $code = input('post.code'); $pay_password = input('post.pay_password'); if(empty($phone) || empty($code) || empty($pay_password)) $this->error('参数错误'); $field = 'id,phone'; $user_info = User::field($field)->where('id',$this->user_id)->find()->toArray(); if(!$user_info['phone']) $this->error('请先绑定手机号'); if($user_info['phone'] != $phone) $this->error('与绑定手机号不一致'); $check_code = $this->checkPhoneCode($phone,$code); if(!$check_code) $this->error('验证码错误');; User::where('id',$uid)->update(['pay_password'=>encrypt_password($pay_password)]); $this->updatePhoneCode($check_code); $this->success('更换成功'); } /** * @title 实名认证 * @desc 实名认证 * @author qc * @method POST * @tag 实名认证 * @url /api/User_center/userCertification * @header name:Authorization require:1 desc:Token * @param name:true_name type:string require:1 default:-- desc:真实姓名 * @param name:id_card type:string require:1 default:-- desc:身份证号 * @param name:card_front type:string require:1 default:-- desc:身份证正面 * @param name:card_back type:string require:1 default:-- desc:身份证反面 */ public function userCertification() { $true_name = input('post.true_name'); $id_card = input('post.id_card'); $card_front = input('post.card_front'); $card_back = input('post.card_back'); $is_auth =User::where('id',$this->user_id)->value('is_auth'); if($is_auth) $this->error('已认证'); $get_age = get_age($id_card); if($get_age < 18)$this->error('未满18周岁!'); $res = user_certification($id_card,$true_name); if(!$res) $this->error('认证失败'); User::where('id',$this->user_id)->update(['is_auth'=>1,'true_name'=>$true_name,'card_front'=>$card_front,'card_back'=>$card_back,'id_card'=>$id_card,'auth_at'=>date('Y-m-d H:i:s')]); $this->success('认证成功'); } /** * @title 注销会员 * @desc 注销会员 * @author qc * @method POST * @url /api/User_center/cancelUserInfo * @header name:Authorization require:1 desc:Token */ public function cancelUserInfo() { Db::name('store_member')->where('id',$this->user_id)->update(['is_deleted'=>1]); $this->success('注销成功'); } /** * @title 获取我绑定的支付宝账户 * @desc 获取我绑定的支付宝账户 * @author qc * @method GET * @url /api/User_center/getMyAliAccount * @return name:birthday type:string default:-- desc:出生日期 * @return name:real_name type:string default:-- desc:姓名 * @return name:card_no type:string default:-- desc:账号 */ public function getMyAliAccount() { $ali_account = UserBank::field('id,real_name,card_no')->where(['user_id'=>$this->user_id,'type'=>1,'is_deleted'=>0])->find(); $ali_account ? $this->success('ok',['account'=>$ali_account->toArray()]) : $this->error('还没有绑定支付宝账户'); } /** * @title 更改或绑定支付宝账户 * @desc 更改或绑定支付宝账户 * @author qc * @method POST * @url /api/User_center/bindAliAccount * @param name:phone type:string require:1 default:-- desc:手机号 * @param name:code type:string require:1 default:-- desc:验证码 * @param name:real_name type:string require:1 default:-- desc:真实姓名 * @param name:card_no type:string require:1 default:-- desc:账号 */ public function bindAliAccount() { $phone = input('post.phone'); $code = input('post.code'); $real_name = input('post.real_name'); $card_no = input('post.card_no'); $check_code = $this->checkPhoneCode($phone,$code); if(!$check_code) $this->error('验证码错误'); $ali_account = UserBank::where(['user_id'=>$this->user_id,'type'=>1,'is_deleted'=>0])->find(); if(!$ali_account){ $account_data =[ 'user_id' => $this->user_id, 'real_name' => $real_name, 'bank_name' => '支付宝账号', 'card_no' => $card_no, 'create_time' => date('Y-m-d H:i:s'), ]; UserBank::create($account_data); }else{ $account_data =[ 'user_id' => $this->user_id, 'real_name' => $real_name, 'bank_name' => '支付宝账号', 'card_no' => $card_no, 'update_time' => date('Y-m-d H:i:s'), ]; UserBank::update($account_data,['id'=>$ali_account->id]); } $this->success('绑定成功'); } /** * @title 更改或绑定银行卡 * @desc 更改或绑定银行卡 * @author qc * @method POST * @url /api/User_center/bindBankAccount * @param name:account_id type:string require:1 default:-- desc:记录id(修改时必传) * @param name:phone type:string require:1 default:-- desc:手机号 * @param name:code type:string require:1 default:-- desc:验证码 * @param name:real_name type:string require:1 default:-- desc:真实姓名 * @param name:card_no type:string require:1 default:-- desc:账号 * @param name:bank_name type:string require:1 default:-- desc:所属银行 */ public function bindBankAccount() { $phone = input('post.phone'); $code = input('post.code'); $real_name = input('post.real_name'); $card_no = input('post.card_no'); $bank_name = input('post.bank_name'); $account_id = input('post.account_id'); $check_code = $this->checkPhoneCode($phone,$code); if(!$check_code) $this->error('验证码错误'); if(!$account_id){ $account_data =[ 'user_id' => $this->user_id, 'type' => 2, 'real_name' => $real_name, 'bank_name' => $bank_name, 'card_no' => $card_no, 'create_time' => date('Y-m-d H:i:s'), ]; UserBank::create($account_data); }else{ $account_data =[ 'user_id' => $this->user_id, 'real_name' => $real_name, 'bank_name' => $bank_name, 'card_no' => $card_no, 'update_time' => date('Y-m-d H:i:s'), ]; UserBank::update($account_data,['id'=>$account_id]); } $this->success('绑定成功'); } /** * @title 获取绑定银行卡详情 * @desc 获取绑定银行卡详情 * @author qc * @method GET * @url /api/User_center/getBandAccountDetail * @param name:account_id type:string require:1 default:-- desc:id * @return name:real_name type:string require:1 default:-- desc:真实姓名 * @return name:card_no type:string require:1 default:-- desc:账号 * @return name:bank_name type:string require:1 default:-- desc:所属银行 */ public function getBandAccountDetail() { $account_id = input('get.account_id'); $account_info = UserBank::field('id,real_name,card_no,bank_name')->where(['user_id'=>$this->user_id,'id'=>$account_id,'is_deleted'=>0])->find(); $account_info ? $this->success('ok',['account'=>$account_info->toArray()]) : $this->error('没找到记录'); } /** * @title 获取绑定银行卡列表 * @desc 获取绑定银行卡列表 * @author qc * @method GET * @url /api/User_center/getBankAccountList * @return name:real_name type:string require:1 default:-- desc:真实姓名 * @return name:card_no type:string require:1 default:-- desc:账号 * @return name:bank_name type:string require:1 default:-- desc:所属银行 */ public function getBankAccountList() { $list = UserBank::field('id,real_name,card_no,bank_name')->where(['user_id'=>$this->user_id,'type'=>2,'is_deleted'=>0])->order('id desc')->select(); $this->success('ok',['list'=>$list ? $list->toArray() : []]); } }