uid; $user_info = Db::name('store_member') ->field('password,second_password',true) ->where('id',$uid) ->find(); if(empty($user_info)) $this->error('用户信息不正确'); $user_info['vip_name'] = '普通会员'; //是否有待支付订单 $order = Db::name('store_order')->where('status',0)->where('is_deleted',0)->where('mid',$uid)->count(); $user_info['is_order_no_paid'] = $order ? true : false; $user_info['is_sign'] = false; //获取每日免费次数 $free_number = getConfigValue('free_lucky_number'); //获取当日免费抽奖记录 $date = date('Y-m-d'); $now_date_count = Db::name('store_blind_box_log')->where('m_id',$this->uid)->where('date',$date)->where('is_free',0)->count(); $lucky_number = $user_info['lottery_number'] + ($free_number-$now_date_count); $user_info['lucky_number'] =$lucky_number<=0 ? 0 : $lucky_number; //生成邀请码 if (!$user_info['invite_img'] || !$user_info['invite_address']){ $code = $user_info['invite_code']; $invite_img = setintivecode($code); $invite_address = getintiveaddress($code); Db::name('store_member')->where('id',$this->uid)->update(['invite_img'=>$invite_img,'invite_address'=>$invite_address]); } $user_info['invite_img'] = str_replace('http:','https:',$user_info['invite_img']); $user_info['share_poster'] = sysconf('share_poster'); $this->success('获取成功',$user_info); } /** * @title 绑定opendid * @desc 绑定opendid * @author Gavin * @url /api/User_center/bindOpenid * @method POST * @tag 编辑信息 * @header name:Authorization require:1 desc:Token * * @param name:code type:string require:0 default:-- desc:code */ public function bindOpenid() { $code = input('code'); if(empty($code)) $this->error('参数错误'); $appid = 'wx8e47a12d0a1c007f'; $secret = 'f19bfac2108af3aee75df0a31a1fee1c'; $res = http_get('https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$secret.'&code='.$code.'&grant_type=authorization_code'); $res = json_decode($res,true); if (isset($res['openid'])){ $update_data['openid'] = $res['openid']; $update_data['update_at'] = date('Y-m-d H:i:s'); if (Db::name('store_member')->where('id',$this->uid)->update($update_data)){ setMemberInfoHash($this->uid); $this->success('绑定成功'); } $this->error('绑定失败'); }else{ $this->error('获取openid失败'); } } /** * @title 编辑个人信息 * @desc 编辑个人信息 * @author Gavin * @url /api/User_center/updateUserInfo * @method POST * @tag 编辑信息 * @header name:Authorization require:1 desc:Token * * @param name:name type:string require:0 default:-- desc:姓名 * @param name:headimg type:string require:0 default:-- desc:头像地址 */ public function updateUserInfo() { $headimg = input('post.headimg'); $name = trim(input('post.name','')); if(!$headimg && !$name) $this->error('参数错误'); $update_data= []; if($name) $update_data['name'] = $name; if ($headimg) $update_data['headimg'] = $headimg; if($name){ $check_member = Db::name('store_member') ->where('name',$name) ->where('id','<>',$this->uid) ->count(); if($check_member) $this->error('该用户名已被占用'); } $update_data['update_at'] = date('Y-m-d H:i:s'); if (Db::name('store_member')->where('id',$this->uid)->update($update_data)){ setMemberInfoHash($this->uid); $this->success('编辑成功'); } $this->error('编辑失败'); } /** * @title 绑定支付宝 * @desc 绑定支付宝 * @author Gavin * @url /api/User_center/bind_zfb * @method POST * @tag 编辑信息 * @header name:Authorization require:1 desc:Token * * @param name:account type:string require:0 default:-- desc:支付宝账号 * @param name:zfb_real_name type:string require:0 default:-- desc:真实姓名 */ public function bind_zfb(){ $account = input('account'); //账号 $real_name = input('real_name'); //真实姓名 if (!$account) $this->error('支付宝账号为空'); if (!$real_name) $this->error('真实姓名为空'); $update_data['zfb_account'] = $account; $update_data['zfb_real_name'] = $real_name; $update_data['update_at'] = date('Y-m-d H:i:s'); if (Db::name('store_member')->where('id',$this->uid)->update($update_data)){ setMemberInfoHash($this->uid); $this->success('绑定成功'); } $this->error('绑定失败'); } /** * @title 绑定【更换绑定】银行卡 * @desc 绑定【更换绑定】银行卡 * @author qc * @url /api/User_center/bind_bank * @method POST * @tag 编辑信息 * @header name:Authorization require:1 desc:Token * * @param name:bank_num type:string require:0 default:-- desc:银行卡号 * @param name:bank_user type:string require:0 default:-- desc:姓名 */ public function bind_bank(){ $bank_num = input('bank_num'); //账号 $bank_user = input('bank_user'); //真实姓名 $pay_password = input('pay_password'); //真实姓名 if (!$bank_num) $this->error('银行卡号不能为空'); if (!$bank_user) $this->error('姓名不能为空'); if(check_bankCard($bank_num) != 1) $this->error('银行卡格式错误'); $user_info = Db::name('store_member')->where('id',$this->uid)->find(); if ($user_info['bank_num'] == $bank_num && $user_info['bank_user'] == $bank_user) $this->error('与原绑定信息一致'); $update_data['bank_num'] = $bank_num; $update_data['bank_user'] = $bank_user; if (Db::name('store_member')->where('id',$this->uid)->update($update_data)){ setMemberInfoHash($this->uid); $this->success('绑定成功'); } $this->error('绑定失败'); } /** * @title 实名认证 * @desc 实名认证 * @author Gavin * @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:身份证号 */ public function userCertification(){ $true_name = input('post.true_name'); $id_card = input('post.id_card'); if (!$true_name || !$id_card) $this->error('参数错误'); $check_id_card = isCreditNo($id_card); if (!$check_id_card) $this->error('身份证号格式错误'); $is_auth = Db::table('store_member')->where('id',$this->uid)->value('is_auth'); if($is_auth) $this->error('已认证'); $check = Db::name('store_member')->where('id_card',$id_card)->count(); if ($check) $this->error('身份证号已经认证过'); if (!identifyCertification($id_card,$true_name)) $this->error('身份证与姓名验证失败'); if (Db::table('store_member')->where('id',$this->uid)->update(['is_auth'=>1,'true_name'=>$true_name,'id_card'=>$id_card,'auth_at'=>date('Y-m-d H:i:s')])){ setMemberInfoHash($this->uid); $this->success('认证成功'); } $this->error('认证失败'); } /** * @title 修改密码 * @desc 修改密码 * @author Gavin * @method POST * @tag 编辑信息 * @url /api/User_center/updatePass * @header name:Authorization require:1 desc:Token * @param name:old_password type:string require:1 default:-- desc:旧密码 * @param name:new_password type:string require:1 default:-- desc:新密码 * @param name:confirm_password type:string require:1 default:-- desc:确认密码 */ public function updatePass() { $old_password = input('post.old_password'); $new_password = input('post.new_password'); $confirm_password = input('post.confirm_password'); if (!$old_password || !$new_password || !$confirm_password) $this->error('参数错误'); if ($new_password!=$confirm_password) $this->error('密码与确认密码不一致'); if (!preg_match('/^[0-9a-z]{6,12}$/i',$new_password)) $this->error('密码格式错误,请输入6-12位数字+字母'); $member = Db::name('store_member')->where('id',$this->uid)->find(); if ($member['password']!=md5($old_password)) $this->error('旧密码错误'); $data['password'] = md5($new_password); $data['update_at'] = date('Y-m-d H:i:s'); if (Db::name('store_member')->where('id',$this->uid)->update($data)){ setMemberInfoHash($this->uid); $this->success('修改成功'); } $this->error('修改失败'); } /** * @title 修改支付密码 * @desc 修改支付密码 * @author Gavin * @method POST * @tag 编辑信息 * @url /api/User_center/updateSecondPass * @header name:Authorization require:1 desc:Token * @param name:second_password type:string require:1 default:-- desc:支付密码 * @param name:confirm_second_password type:string require:1 default:-- desc:确认密码 */ public function updateSecondPass() { $second_password = input('post.second_password'); $confirm_second_password = input('post.confirm_second_password'); $yzm = input('post.yzm'); if (!$second_password || !$confirm_second_password) $this->error('参数错误'); if ($second_password!=$confirm_second_password) $this->error('密码与确认密码不一致'); if (!preg_match('/^[0-9]{6}$/i',$second_password)) $this->error('支付密码格式错误,请输入6位纯数字'); $member = getMemberInfoHash($this->uid); //获取用户信息 //验证短信验证码 // $time = time()-60; // $sms = Db::name('store_sms')->where(['mobile' => $member['phone'], 'event' => 'forgetpwd']) // ->where('createtime','>',$time) // ->order('id', 'DESC') // ->find(); // if (!$sms || $sms['code'] != $yzm) $this->error('短信验证码不正确!'); $data['second_password'] = md5($second_password); $data['update_at'] = date('Y-m-d H:i:s'); if (Db::name('store_member')->where('id',$this->uid)->update($data)){ setMemberInfoHash($this->uid); $this->success('修改成功'); } $this->error('修改失败'); } /** * @title 我的藏品 * @desc 我的藏品 * @author Gavin * @method POST * @tag 编辑信息 * @url /api/User_center/myCollection * @header name:Authorization require:1 desc:Token * @param name:type type:int require:0 default:1 desc:类型(0全部1:藏品,3:盲盒) * @return name:id type:int require:0 default:0 desc:藏品ID * @return name:tag type:string require:0 default:0 desc:唯一标签 * @return name:name type:string require:0 default:0 desc:藏品名称 * @return name:type type:int default:1 desc:类型(1:藏品,3:盲盒) * @return name:cover type:string require:0 default:0 desc:藏品图片 * @return name:resale_price type:string require:0 default:0 desc:二级市场挂售价格 * @return name:auth_img type:string require:0 default:0 desc:作者头像 * @return name:auth_name type:string require:0 default:0 desc:作者名称 * @return name:resale_status type:string require:0 default:0 desc:1:未挂售2挂售中3已出售 * @return name:is_destruction type:int require:0 default:0 desc:1:盲盒状态1未开启0已开启 * @return name:send_btn type:int require:0 default:0 desc:是否可以赠送1是0否 * @return name:send_time type:string require:0 default:-- desc:可以赠时间【send_btn=1时为空】 */ public function myCollection(){ $type = input('type',1); $list = Db::name('store_order_info') ->where('mid',$this->uid) ->where('status','neq','2') ->where('is_destruction',1) ->where('resale_status',1) ->when($type,function ($query)use($type){ if($type) $query->where('type',$type);}) ->field('id,c_id,tag,pro_info,resale_status,resale_price,type,is_destruction,create_at') ->order('id desc') ->select(); foreach ($list as &$v){ $pro_info = json_decode($v['pro_info'],true); $v['name'] = $pro_info['name']; $v['cover'] = $pro_info['cover']; $v['auth_img'] = $pro_info['auth_img']; $v['auth_name'] = $pro_info['auth_name']; $goods_info = Db::name('store_collection')->where('id',$v['c_id'])->find(); $log = Db::name('store_collect_examples_log')->where('order_info_id',$v['id'])->find(); $v['send_btn'] = 1; $v['send_time'] = ''; if (!$log){ if ($goods_info['one_given_day']!=0) { $exam_time = strtotime($v['create_at'])+($goods_info['one_given_day']*60*60); if ($exam_time>time()){ $v['send_btn'] = 0; $v['send_time'] = date('Y-m-d H:i:s',$exam_time); } } }else{ if ($pro_info['other_given_day']!=0){ $exam_time = strtotime($log['create_at'])+($pro_info['other_given_day']*60*60); if ($exam_time>time()) { $v['send_btn'] = 0; $v['send_time'] = date('Y-m-d H:i:s',$exam_time); } } } unset($v['pro_info']); } $this->success('成功',$list); } /** * @title 我的藏品(折叠) * @desc 我的藏品 * @author QC * @method POST * @tag 编辑信息 * @url /api/User_center/myCollectionGroupBy * @header name:Authorization require:1 desc:Token * @return name:num type:int default:0 desc:同组下几个藏品【最小是1】 * @return name:jump_id type:int default:0 desc:同组下最新的收藏记录id[只有一个可以用这个作为跳转详情的id] * @return name:tag type:string default:0 desc:唯一标签 * @return name:name type:string require:0 default:0 desc:藏品名称 * @return name:cover type:string require:0 default:0 desc:藏品图片 * @return name:auth_img type:string require:0 default:0 desc:作者头像 * @return name:auth_name type:string require:0 default:0 desc:作者名称 * @return name:total_num type:int require:0 default:0 desc:总数 */ public function myCollectionGroupBy(){ $type = input('type',1); $group_list = Db::name('store_order_info') ->field('c_id,count(id) num ,max(id) jump_id') ->where('mid',$this->uid) ->where('status','neq','2') ->where('is_destruction',1) ->where('resale_status',1) ->when($type,function ($query)use($type){ if($type) $query->where('type',$type);}) ->group('c_id') ->select(); array_walk($group_list,function (&$val){ $min_info = Db::name('store_order_info')->field('tag,pro_info')->where('id',$val['jump_id'])->find(); $pro_info = json_decode($min_info['pro_info'],true); $val['tag'] = $min_info['tag']; $val['name'] = $pro_info['name']; $val['cover'] = $pro_info['cover']; $val['auth_img'] = $pro_info['auth_img']; $val['auth_name'] = $pro_info['auth_name']; }); $this->success('成功',['list'=>$group_list,'total_num'=>!empty($group_list)?array_sum(array_column($group_list,'num')):0]); } /** * @title 我的藏品(展开) * @desc 我的藏品(展开) * @author QC * @method POST * @tag 编辑信息 * @url /api/User_center/unfoldCollection * @header name:Authorization require:1 desc:Token * @param name:c_id type:int require:0 default:1 desc:myCollectionGroupBy接口的c_id[商品id] * @return name:id type:int require:0 default:0 desc:藏品ID * @return name:tag type:string require:0 default:0 desc:唯一标签 * @return name:name type:string require:0 default:0 desc:藏品名称 * @return name:type type:int default:1 desc:类型(1:藏品,3:盲盒) * @return name:cover type:string require:0 default:0 desc:藏品图片 * @return name:resale_price type:string require:0 default:0 desc:二级市场挂售价格 * @return name:auth_img type:string require:0 default:0 desc:作者头像 * @return name:auth_name type:string require:0 default:0 desc:作者名称 */ public function unfoldCollection() { $c_id = input('c_id'); $list = Db::name('store_order_info') ->field('id,tag,pro_info,resale_status,resale_price,type,is_destruction') ->where('c_id',$c_id) ->where('mid',$this->uid) ->where('status','neq','2') ->where('is_destruction',1) ->where('resale_status',1) ->order('id desc') ->select(); array_walk($list,function (&$val){ $pro_info = json_decode($val['pro_info'],true); $val['name'] = $pro_info['name']; $val['cover'] = $pro_info['cover']; $val['auth_img'] = $pro_info['auth_img']; $val['auth_name'] = $pro_info['auth_name']; unset($val['pro_info']); }); $this->success('ok',$list); } /** * @title 我的盲盒 * @desc 我的盲盒 * @author Gavin * @method POST * @tag 编辑信息 * @url /api/User_center/myBoxCollection * @header name:Authorization require:1 desc:Token * @return name:id type:int require:0 default:0 desc:藏品ID * @return name:tag type:string require:0 default:0 desc:唯一标签 * @return name:name type:string require:0 default:0 desc:藏品名称 * @return name:cover type:string require:0 default:0 desc:藏品图片 * @return name:auth_img type:string require:0 default:0 desc:作者头像 * @return name:auth_name type:string require:0 default:0 desc:作者名称 */ public function myBoxCollection(){ $list = Db::name('store_order_info') ->where('mid',$this->uid) ->where('status','neq','2') ->where('type',3) ->where('is_destruction',1) ->where('resale_status',1) ->field('id,tag,pro_info') ->order('id desc') ->select(); foreach ($list as &$v){ $pro_info = json_decode($v['pro_info'],true); $v['name'] = $pro_info['name']; $v['cover'] = $pro_info['cover']; $v['auth_img'] = $pro_info['auth_img']; $v['auth_name'] = $pro_info['auth_name']; unset($v['pro_info']); } $this->success('成功',$list); } /** * @title 藏品详情 * @desc 藏品详情 * @author Gavin * @method POST * @tag 编辑信息 * @url /api/User_center/myCollectionDetail * @header name:Authorization require:1 desc:Token * @param name:id type:int require:1 default:-- desc:藏品ID * * @return name:id type:int require:0 default:0 desc:藏品ID * @return name:tag type:string require:0 default:0 desc:唯一标签 * @return name:type type:int require:0 default:1 desc:类型1:藏品,3:盲盒 * @return name:collectors_name type:string require:0 default:0 desc:收藏者 * @return name:collectors_hash type:string require:0 default:0 desc:收藏者hash * @return name:create_at type:string require:0 default:0 desc:收藏时间 * @return name:company type:string require:0 default:0 desc:流转公司 * @return name:send_btn type:int require:0 default:0 desc:是否可以赠送1是0否 * @return name:send_time type:string require:0 default:-- desc:可以赠时间【send_btn=1时为空】 * @return name:company_hash type:string require:0 default:0 desc:流转公司hash * @return name:contract_address type:string require:0 default:0 desc:合约地址 * @return name:resale_status type:string require:0 default:0 desc:1:未挂售2挂售中3已出售 * @return name:is_destruction type:int require:0 default:0 desc:1:盲盒状态1未开启0已开启 * @return name:resale_price type:float require:0 default:0 desc:二级市场挂售价格 * @return name:examples_illustrate type:string require:0 default:0 desc:转赠说明 * @return name:sell_illustrate type:string require:0 default:0 desc:寄售须知 * @return name:royalties_rate type:string require:0 default:0 desc:上架版税率【版权税】 * @return name:royalties type:string require:0 default:0 desc:上架版税【版权税】 * @return name:service_fee_rate type:string require:0 default:0 desc:服务费率 * @return name:service_fee type:string require:0 default:0 desc:服务费 * @return name:pro_info@name type:string require:0 default:0 desc:藏品名称 * @return name:pro_info@price type:string require:0 default:0 desc:藏品价格 * @return name:pro_info@label type:string require:0 default:0 desc:藏品标签 * @return name:pro_info@cover type:string require:0 default:0 desc:藏品图片 * @return name:pro_info@auth_img type:string require:0 default:0 desc:作者头像 * @return name:pro_info@auth_name type:string require:0 default:0 desc:作者姓名 * @return name:pro_info@warm_prompt type:string require:0 default:0 desc:温馨提示 * @return name:pro_info@share_img type:string require:0 default:0 desc:分享二维码 */ public function myCollectionDetail(){ $id = input('id'); if (!$id) $this->error('参数错误'); $info = Db::name('store_order_info') ->where('mid',$this->uid) ->where('id',$id) ->find(); if (!$info) $this->error('藏品不存在'); $info['pro_info'] = json_decode($info['pro_info'],true); if (!isset($info['pro_info']['share_img'])){ //$info['pro_info']['share_img'] = Db::name('store_collection')->where('id',$info['pro_info']['id'])->value('share_img'); } $info['collectors_name'] = Db::name('store_member')->where('id',$this->uid)->value('name'); $info['collectors_hash'] = $info['collectors_hash']=='' ? "发放中" : $info['collectors_hash']; $info['collectors_hash_time'] = $info['collectors_hash_time']=='' ? "发放中" : $info['collectors_hash_time']; $info['examples_illustrate'] = Db::table('system_config')->where('name','examples_illustrate')->value('value'); $info['sell_illustrate'] = Db::table('system_config')->where('name','sell_illustrate')->value('value'); $discount = getMemberServiceCharge($this->uid);// 折扣 $service_fee_rate = Db::table('system_config')->where('name','service_fee')->value('value'); $royalties_rate = Db::table('system_config')->where('name','royalties')->value('value'); $info['service_fee_rate'] = bcmul($service_fee_rate,$discount).'%'; $info['royalties_rate'] =bcmul($royalties_rate,$discount).'%'; $info['service_fee'] = sprintf("%.2f", $info['resale_price'] * (bcmul($service_fee_rate,$discount)/100)); $info['royalties'] = sprintf("%.2f", $info['resale_price'] * (bcmul($royalties_rate,$discount)/100)); $info['contract_address'] = '0c214bcd4f1766fdd6d36f127234fc7e7ba883711e19938777f01523c28e74dc'; $goods_info = Db::name('store_collection')->where('id',$info['c_id'])->find(); $log = Db::name('store_collect_examples_log')->where('order_info_id',$info['id'])->find(); $info['send_btn'] = 1; $info['send_time'] = ''; if (!$log){ if ($goods_info['one_given_day']!=0) { $exam_time = strtotime($info['create_at'])+($goods_info['one_given_day']*60*60); if ($exam_time>time()){ $info['send_btn'] = 0; $info['send_time'] = date('Y-m-d H:i:s',$exam_time); } } }else{ if ($goods_info['other_given_day']!=0){ $exam_time = strtotime($log['create_at'])+($goods_info['other_given_day']*60*60); if ($exam_time>time()) { $info['send_btn'] = 0; $info['send_time'] = date('Y-m-d H:i:s',$exam_time); } } } $this->success('成功',$info); } /** * @title 转赠 * @desc 转赠 * @author Gavin * @method POST * @tag 编辑信息 * @url /api/User_center/examples * @header name:Authorization require:1 desc:Token * @param name:id type:int require:1 default:-- desc:藏品ID * @param name:phone type:string require:1 default:-- desc:手机号 * @param name:second_password type:int require:1 default:-- desc:支付密码 * */ public function examples(){ //$this->error('暂时未开放...'); $id = input('id'); $redis = new Redis([ 'select'=> 2]); $redis_value = $redis->get('examples'.$this->uid); if ($redis_value){ $this->error('请求过快,请稍后重试'); }else{ $redis->set('examples'.$this->uid,1,2); } $phone = input('phone'); // $wallet_address = input('wallet_address'); $second_password = input('second_password'); if (!$id || !$phone ) $this->error('参数错误'); $info = Db::name('store_order_info')->where('id',$id)->where('mid',$this->uid)->find(); if (!$info) $this->error('藏品不存在'); if ($info['status']==2) $this->error('藏品已转赠'); $member = Db::name('store_member')->where('phone',$phone)->find(); if (!$member) $this->error('转赠用户不存在'); if($member['id'] == $this->uid){ $this->error('自己无法转赠给自己'); } //防止两两转赠 //if($info['to_mid'] == $member['id']) $this->error('不可相互转赠'); if (!$info['collectors_hash'] && $info['type'] != 3) $this->error('发放中,无法转赠'); $mem = getMemberInfoHash($this->uid); if ($mem['second_password']!=md5($second_password)) $this->error('密码错误'); $pro_info = Db::name('store_collection')->where('id',$info['c_id'])->find(); $log = Db::name('store_collect_examples_log') ->where('order_info_id',$id) ->find(); if (!$log){ if ($pro_info['one_given_day']!=0){ $exam_time = strtotime($info['create_at'])+($pro_info['one_given_day']*60*60); if ($exam_time>time()) $this->error('持有时间限制,无法转赠'); } }else{ if ($pro_info['other_given_day']!=0){ $exam_time = strtotime($log['create_at'])+($pro_info['other_given_day']*60*60); if ($exam_time>time()) $this->error('持有时间限制,无法转赠'); } } $com = true; Db::startTrans(); try { Db::name('store_order_info') ->where('id',$id) ->update(['status'=>2,'over_time'=>date('Y-m-d H:i:s'),'to_mid'=>$member['id']]); $to_date = [ 'order_id'=>$info['order_id'], 'order_no'=>get_order_sn(), 'tag'=>$info['tag'], 'mid'=>$member['id'], 'c_id'=>$info['c_id'], 'name'=>$pro_info['name'], 'cover'=>$pro_info['cover'], 'pro_info'=>$info['pro_info'], 'status'=>3, 'type' => $info['type'], 'to_mid'=>$this->uid, 'over_time'=>date('Y-m-d H:i:s'), 'company'=>'象链数藏', 'company_hash'=>$info['company_hash'], 'company_hash_time'=>$info['company_hash_time'], 'ddcid'=>$info['ddcid'], 'collectors_hash'=>'', 'collectors_hash_time'=>date('Y-m-d H:i:s') ]; $new_id = Db::name('store_order_info')->insertGetId($to_date); $log_date = [ 'order_info_id'=>$new_id, 'mid'=>$this->uid, 'to_mid'=>$member['id'], 'date'=>date('Y-m') ]; Db::name('store_collect_examples_log')->insert($log_date); Db::commit(); }catch (\Exception $e){ $com = false; Db::rollback(); } if ($com){ if($pro_info['vipid'] > 0){ //转赠成功等级掉级 $otherData = [ 'type' => 2, 'status' => 0, 'desc' => '转赠'.$pro_info['name'].'藏品自动掉级', 'order_table' => 'store_order_info', 'order_id' => $id, ]; memberVipChange(0,$this->uid,$otherData); //转赠成功获赠人等级同步 $otherData = [ 'type' => 2, 'status' => 1, 'desc' => '获赠'.$pro_info['name'].'藏品自动同步等级', 'order_table' => 'store_order_info', 'order_id' => $new_id, ]; memberVipChange($pro_info['vipid'],$member['id'],$otherData); } $this->success('转赠成功'); } $this->error('转赠失败'); } /** * @title 消息列表[公告] * @desc 消息列表 * @author Gavin * @method POST * @tag 编辑信息 * @url /api/User_center/messageList * @header name:Authorization require:1 desc:Token * * @param name:page type:int : default:1 desc:页数 * @param name:page_num type:int : default:20 desc:每页数 * * @return name:id type:int require:0 default:0 desc:消息ID * @return name:title type:string require:0 default:0 desc:标题 * @return name:content type:string require:0 default:0 desc:内容【富文本】 * @return name:create_at type:string require:0 default:0 desc:发布时间 * @return name:is_read type:string require:0 default:0 desc:是否查看true:已查看false:未查看 */ public function messageList(){ $count = Db::name('store_message')->where('is_deleted',0)->count(); $list = Db::name('store_message') ->field('is_deleted,update_at',true) ->where('is_deleted',0) ->order('id desc') ->limit($this->off_set,$this->page_num) ->select(); // echo Db::name('store_message')->getLastSql();die; foreach ($list as &$v){ $is_read = Db::name('store_message_read_log')->where('mid',$this->uid)->where('message_id',$v['id'])->count(); $v['is_read'] = $is_read ? true : false; } $this->success('成功',compact('count','list')); } /** * @title 点击消息[公告] * @desc 点击消息,查看消息 * @author Gavin * @method POST * @tag 编辑信息 * @url /api/User_center/readMessage * @header name:Authorization require:1 desc:Token * @param name:id type:int : default:1 desc:消息ID * @return name:id type:int require:0 default:0 desc:消息ID * @return name:title type:string require:0 default:0 desc:标题 * @return name:content type:string require:0 default:0 desc:内容【富文本】 * @return name:create_at type:string require:0 default:0 desc:发布时间 */ public function readMessage(){ $id = input('id'); if (!$id) $this->error('参数错误'); $log = Db::name('store_message_read_log')->where('message_id',$id)->where('mid',$this->uid)->count(); $detail = Db::name('store_message')->field('is_deleted,update_at',true)->where('id',$id)->find(); if (!$log){ $data = [ 'mid'=>$this->uid, 'message_id'=>$id ]; Db::name('store_message_read_log')->insert($data); } $this->success('成功',['detail'=>$detail]); } /** * @title 人脸认证sign * @desc 人脸认证sign * @author Gavin * @method POST * @tag 编辑信息 * @url /api/User_center/getFaceSign * @header name:Authorization require:1 desc:Token * * * @param name:name type:string default:1 desc:姓名 * @param name:idNo type:string default:1 desc:身份证号 * * @return name:sign type:string require: default:-- desc:签名 * */ public function getFaceSign(){ $name = input('name'); $idNo = input('idNo'); if (!$name || !$idNo) $this->error('参数错误'); $userId = $this->uid; //$userId = get32Str(); $data = getfaceid($name,$idNo,$userId); $this->success('成功',$data); } /** * @title 邀请记录 * @desc 邀请记录 * @author Gavin * @method POST * @tag 编辑信息 * @url /api/User_center/invitedRecord * @header name:Authorization require:1 desc:Token * * @param name:page type:int : default:1 desc:页数 * @param name:page_num type:int : default:20 desc:每页数 * * @return name:id type:int require:0 default:0 desc:用户ID * @return name:headimg type:string require:0 default:0 desc:头像 * @return name:name type:string require:0 default:0 desc:名称 * @return name:phone type:string require:0 default:0 desc:手机号 * @return name:create_at type:string require:0 default:0 desc:时间 * @return name:is_auth type:int require:0 default:0 desc:是否认证 */ public function invitedRecord(){ $count = Db::name('store_member')->where('pid',$this->uid)->where('is_auth',1)->count(); $list = Db::name('store_member') ->field('id,headimg,name,phone,create_at,is_auth') ->where('pid',$this->uid) ->where('is_auth',1) ->order('id desc') ->limit($this->off_set,$this->page_num) ->select(); foreach ($list as &$v){ $v['phone'] = substr_replace($v['phone'],'****',3,4); $v['create_at'] = date('Y-m-d',strtotime($v['create_at'])); } $this->success('成功',compact('count','list')); } /** * @title 邀请排行榜 * @desc 邀请排行榜 * @author Gavin * @method POST * @tag 编辑信息 * @url /api/User_center/invitedList * @header name:Authorization require:1 desc:Token * * @param name:page type:int : default:1 desc:页数 * @param name:page_num type:int : default:20 desc:每页数 * * @return name:count type:int require:0 default:0 desc:人数 * @return name:id type:int require:0 default:0 desc:用户ID * @return name:headimg type:string require:0 default:0 desc:头像 * @return name:name type:string require:0 default:0 desc:名称 * @return name:phone type:string require:0 default:0 desc:手机号 * @return name:is_auth type:int require:0 default:0 desc:是否认证 * @return name:create_at type:string require:0 default:0 desc:时间 */ public function invitedList(){ //$this->error('新品发售中,暂时停止访问'); $count = Db::name('store_member')->field('pid,count(*) count')->where('pid','>',0)->where('is_auth',1)->group('pid')->order('count desc')->count(); $list = Db::name('store_member') ->field('pid,count(*) count') ->where('pid','>',0) ->where('is_auth',1) ->group('pid') ->order('count desc') ->limit($this->off_set,$this->page_num) ->select(); foreach ($list as &$value){ $users_info = Db::name('store_member')->field('headimg,name,is_auth')->where('id',$value['pid'])->find(); $value['name'] = $users_info['name']; $value['headimg'] = $users_info['headimg']; $value['is_auth'] = $users_info['is_auth']; unset($value['pid']); } $this->success('成功',compact('count','list')); } /** * @title 签到 * @desc 签到 * @author Gavin * @method POST * @tag 编辑信息 * @url /api/User_center/sign * @header name:Authorization require:1 desc:Token * */ public function sign(){ $date = date('Y-m-d'); $log = Db::name('store_member_sign')->where('mid',$this->uid)->where('date',$date)->count(); if ($log) $this->error('今日已签到'); $data = [ 'mid'=>$this->uid, 'date'=>$date ]; $com = true; Db::startTrans(); try { $id = Db::name('store_member_sign')->insertGetId($data); $sign_integral = getConfigValue('sign_integral'); if ($sign_integral>0){ memberMoneyChange($sign_integral,1,$this->uid,'签到',1,$id); } Db::commit(); }catch (\Exception $e){ $com=false; Db::rollback(); } if ($com){ $this->success('签到成功'); } $this->error('签到失败'); } /** * @title 积分记录 * @desc 积分记录 * @author Gavin * @method POST * @tag 编辑信息 * @url /api/User_center/integralLog * @header name:Authorization require:1 desc:Token * * @param name:page type:int : default:1 desc:页数 * @param name:page_num type:int : default:20 desc:每页数 * * @return name:id type:int require:0 default:0 desc:id * @return name:change type:string require:0 default:0 desc:变动数值 * @return name:title type:string require:0 default:0 desc:标题 * @return name:create_at type:string require:0 default:0 desc:时间 */ public function integralLog(){ $where = [ 'm_id'=>$this->uid, 'type'=>1 ]; $count = Db::name('store_member_log')->where($where)->count(); $list = Db::name('store_member_log') ->field('id,pm,change,title,create_at') ->where($where) ->order('id desc') ->limit($this->off_set,$this->page_num) ->select(); foreach ($list as &$v){ if ($v['pm']==1){ $v['change'] = '+'.$v['change']; }else{ $v['change'] = '-'.$v['change']; } } $this->success('成功',compact('count','list')); } /** * @title 余额记录 * @desc 余额记录 * @author Gavin * @method POST * @tag 编辑信息 * @url /api/User_center/moneyLog * @header name:Authorization require:1 desc:Token * * @param name:page type:int default:1 desc:页数 * @param name:page_num type:int default:20 desc:每页数 * @param name:select_type type:int require:0 default:-1 desc:查询类型[-1全部0减少(支出)1增加(收入),2提现【包含提现申请的减少和拒绝的增加】] * * @return name:id type:int require:0 default:0 desc:id * @return name:change type:string require:0 default:0 desc:变动数值 * @return name:title type:string require:0 default:0 desc:标题 * @return name:create_at type:string require:0 default:0 desc:时间 * @return name:pm type:int require:0 default:0 desc:变更类型[0减少1增加] * @return name:change_type type:int require:0 default:0 desc:来源1出售佣金2提现3提现拒绝 */ public function moneyLog(){ $select_type = input('select_type',-1); $where = ['m_id'=>$this->uid, 'type'=>3]; if(in_array($select_type,[0,1]))$where['pm'] = $select_type; $count = Db::name('store_member_log')->where($where)->when($select_type,function ($query)use($select_type){ if($select_type == 2 ) $query->whereIn('change_type','2,3'); })->count(); $list = Db::name('store_member_log') ->field('id,pm,change,title,create_at,change_type') ->where($where) ->when($select_type,function ($query)use($select_type){ if($select_type == 2 ) $query->whereIn('change_type','2,3'); })->order('id desc') ->limit($this->off_set,$this->page_num) ->select(); foreach ($list as &$v){ if ($v['pm']==1){ $v['change'] = '+'.$v['change']; }else{ $v['change'] = '-'.$v['change']; } } $this->success('成功',compact('count','list')); } /** * @title 提现 * @desc 提现 * @author Gavin * @method POST * @tag 编辑信息 * @url /api/User_center/withdraw * @header name:Authorization require:1 desc:Token * * @param name:money type:int default: desc:提现金额 * @param name:withdraw_type type:string default:bank desc:提现方式:wx[微信],zfb[支付宝],bank[银行卡] * @param name:pay_password type:string default:wx desc:二级密码 * */ public function withdraw(){ // $this->error('维护中,暂时关闭'); if (redisSetNx('withdraw'.$this->uid,3)){ $v = getConfigValue('withdraw_switch'); if (!$v) $this->error('维护中,暂时关闭'); $redis = new Redis(['select'=>2]); $redis_value = $redis->get('withdraw'.$this->uid); if ($redis_value){ $this->error('请求过快,请稍后重试'); }else{ $redis->set('withdraw'.$this->uid,1,3); } $money = input('money'); $withdraw_type = input('withdraw_type','bank'); if($withdraw_type != 'bank') $this->error('提现方式错误'.$withdraw_type); $pay_password = input('pay_password'); if (!$money) $this->error('参数错误'); $user = Db::name('store_member')->where('id',$this->uid)->find(); if ($user['money'] < $money) $this->error('余额不足'); //if ($user['second_password']!=md5($pay_password)) $this->error('密码错误'); $withdraw_min_price = getConfigValue('withdraw_min_price'); //最小提现金额 $withdraw_max_price = getConfigValue('withdraw_max_price'); //最大提现金额 $poundage_proportion = getConfigValue('poundage_proportion'); //手续费百分比 $discount = getMemberServiceCharge($this->uid);// 折扣 $poundage_proportion = bcmul($poundage_proportion,$discount); if ($money < $withdraw_min_price) $this->error('最低提现'.$withdraw_min_price.'元'); if ($money > $withdraw_max_price) $this->error('最大提现'.$withdraw_max_price.'元'); if($withdraw_type=='zfb' && (!$user['zfb_account'] || !$user['zfb_real_name'])) $this->error('请先绑定支付宝'); if($withdraw_type == 'wx' && !$user['openid']) $this->error('请先绑定微信'); if($withdraw_type == 'bank' && !$user['bank_num'])$this->error('请先绑定银行卡'); Db::startTrans(); try { $data['mid'] = $this->uid; $data['withdraw_type'] = $withdraw_type; $order_no = get_order_sn(); $data['order_no'] = $order_no; $data['price'] = $money; $data['poundage_proportion'] = $poundage_proportion; $proportion = sprintf("%.2f", $money*($poundage_proportion/100)); //四舍五入保留两位小数点 $data['proportion'] = $proportion; $real_money = $money-$proportion; $data['real_money'] = $real_money; switch ($withdraw_type){ case 'wx': $data['account_no'] = $user['openid']; $data['account_name']=$user['name']; break; case 'zfb': $data['account_no'] = $user['zfb_account']; $data['account_name']=$user['zfb_real_name']; break; case 'bank': $data['account_no'] = $user['bank_num']; $data['account_name']=$user['bank_user']; break; } $id =Db::name('store_member_withdraw')->insertGetId($data); $res = memberMoneyChange($money,3,$this->uid,'余额提现',0,$id,2); if(!$res) throw new Exception('提现失败'); Db::commit(); }catch (\Exception $e) { Db::rollback(); $this->error($e->getMessage()); } DelRedisSetNx('withdraw'.$this->uid); $this->success('提现申请成功,等待审核!'); }else{ $this->error('服务器繁忙,请稍后重试'); } } /** * @title 打开盲盒 * @desc 返回值是空就没中奖 * @author Gavin * @method POST * @tag 编辑信息 * @url /api/User_center/openBoxCollection * @header name:Authorization require:1 desc:Token * @param name:id type:int : default: desc:详情ID * @return name:name type:string default: desc:名称 * @return name:cover type:string default: desc:图片 * @return name:price type:string default: desc:价格 * @return name:auth_name type:string default: desc:作者 * @return name:auth_img type:string default: desc:作者头像 * */ public function openBoxCollection(){ //redis原子锁 if (redisSetNx('openBox'.$this->uid)){ $id = input('id'); if (!$id) $this->error('参数错误'); $info = Db::name('store_order_info') ->where('id',$id) ->where('mid',$this->uid) ->where('status','neq','2') ->where('is_destruction',1) ->find(); if (!$info) $this->error('盲盒不存在'); if ($info['resale_status']!=1) $this->error('盲盒挂售中或已出售'); $where = 'status = 1 and coll_id = '.$info['c_id'].' and is_del = 1 and residue_num > 0'; $residue_num_all = Db::name('store_blind_box')->where($where)->sum('residue_num'); // if($residue_num_all <= 0 )$this->error('对不起,盲盒已没有奖品'); $com = true; Db::startTrans(); try { //销毁 Db::name('store_order_info')->where('id',$id)->update(['is_destruction'=>0]); $win_num = rand(1,$residue_num_all); $blind_box_info = Db::name('store_blind_box')->field('id,prize_id,residue_num')->where($where)->select(); $residue_num = 0; $win_prize_id = 0; $win_box_id = 0; foreach ($blind_box_info as $val) { $residue_num += $val['residue_num']; if($win_prize_id == 0 && $win_num <= $residue_num){ $win_prize_id = $val['prize_id']; $win_box_id = $val['id']; } } if($win_prize_id){ $coll_info = getCollectionInfoHash($win_prize_id); $json_info = json_encode($coll_info,true); $return['name'] = $coll_info['name']; $return['cover'] = $coll_info['cover']; $return['price'] = $coll_info['price']; $return['auth_name'] = $coll_info['auth_name']; $return['auth_img'] = $coll_info['auth_img']; $data = [ 'm_id'=>$this->uid, 'b_id'=>$win_prize_id, 'is_prize'=>1, 'name'=>$coll_info['name'], 'cover'=>$coll_info['cover'], 'info'=>$json_info, 'date'=>date('Y-m-d'), 'is_free'=>1 ]; Db::name('store_blind_box_log')->insert($data); //获取排名 $rank = getRanking($win_prize_id); $tag = getTag($win_prize_id,$rank,$coll_info['inventory']); saveRanking($win_prize_id); $company = '象链数藏'; $hash = getCompanyHash($win_prize_id); $company_hash = $hash['hash']; $company_hash_time = $hash['create_at']; $tokenid = $hash['tokenid']; Db::name('hash')->where('hash',$hash['hash'])->update(['status'=>1]); $collectors_hash = ''; $date = [ 'order_id'=>0, 'order_no'=>get_order_sn(), 'tag'=>$tag, 'mid'=>$this->uid, 'c_id'=>$win_prize_id, 'name'=>$coll_info['name'], 'cover'=>$coll_info['cover'], 'pro_info'=>$json_info, 'company'=>$company, 'company_hash'=>$company_hash, 'company_hash_time'=>$company_hash_time, 'ddcid'=>$tokenid, 'collectors_hash'=>$collectors_hash, // 'collectors_hash_time'=>'', 'status'=>1 ]; Db::name('store_order_info')->insert($date); } Db::commit(); }catch (\Exception $e) { $com = false; $msg = $e->getMessage(); Db::rollback(); } if ($com){ setMemberInfoHash($this->uid); //扣减库存 Db::name('store_blind_box')->where('id',$win_box_id)->setDec('residue_num',1); DelRedisSetNx('openBox'.$this->uid); $this->success('成功',$win_prize_id ? $return : null); }else{ DelRedisSetNx('openBox'.$this->uid); $this->error($msg); } }else{ $this->error('请求过快'); } } /** * @title 验证被更换手机号【更换手机号第一步】 * @desc 验证已绑定的手机号 * @author QC * @method POST * @tag 编辑信息 * @url /api/User_center/checkPhone * @header name:Authorization require:1 desc:Token * @param name:phone type:int default: desc:手机号 * @param name:code type:string default: desc:验证码 */ public function checkPhone() { $phone = input('post.phone'); $code = input('post.code'); if(!$phone || !$code) $this->error('参数错误'); $user_info = Db::name('store_member')->find($this->uid); if($user_info['phone'] != $phone) $this->error('已绑定手机号错误'); // 5 分钟之内的验证码 $check_code = Db::name('store_sms') ->where(['mobile'=>$phone,'event'=>'change','is_use'=>0,'code'=>$code]) ->where('createtime','>' ,time() - 300) ->value('id'); if(!$check_code) $this->error('验证码错误'); Db::name('store_sms')->where('id',$check_code)->update(['is_use'=>1]); $this->success('验证成功'); } /** * @title 更换新的手机号 * @desc 更换新的手机号 * @author QC * @method POST * @tag 更换新的手机号 * @url /api/User_center/changePhone * @header name:Authorization require:1 desc:Token * @param name:phone type:int default: desc:手机号 * @param name:code type:string default: desc:验证码 */ public function changePhone() { $phone = input('post.phone'); $code = input('post.code'); if(!$phone || !$code) $this->error('参数错误'); $user_info = Db::name('store_member')->find($this->uid); $check_code = Db::name('store_sms') ->where(['mobile'=>$user_info['phone'],'event'=>'change','is_use'=>1]) ->order('id desc') ->find(); if(!$check_code) $this->error('请验证已绑定手机号'); if($check_code['createtime'] < time() - 300) $this->error('验证超时,请在5分钟之内更换手机号'); $check_new = Db::name('store_sms') ->where(['mobile'=>$phone,'event'=>'new','is_use'=>0,'code'=>$code]) ->where('createtime','>' ,time() - 300) ->value('id'); if(!$check_new) $this->error('验证码错误'); Db::name('store_sms')->where('id',$check_new)->update(['is_use'=>1]); Db::name('store_member')->where('id',$this->uid)->update(['phone'=>$phone]); setMemberInfoHash($this->uid); $this->success('更换成功'); } /** * @title 阿里云金融级实名认证初始化 * @desc 阿里云金融级实名认证初始化 * @author QC * @method POST * @tag 编辑信息 * @url /api/User_center/initFaceVerify * @header name:Authorization require:1 desc:Token * @param name:name type:string default:1 desc:姓名 * @param name:id_no type:string default:1 desc:身份证号 * @param name:MetaInfo type:string default:1 desc:MetaInfo * @param name:ReturnUrl type:string default:1 desc:业务页面回跳的目标地址 * @return name:RequestId type:String default:-- desc:请求ID * @return name:Message type:String default:-- desc:返回信息 * @return name:Code type:String default:-- desc:返返回码:200为成功,其他为失败。【具体的参考阿里云文档】 * @return name:ResultObject.CertifyId type:String default:-- desc:实人认证唯一标识 * @return name:ResultObject.CertifyUrl type:String default:-- desc:Web认证URL,认证结束后根据入参ReturnUrl进行进行转赠跳转 */ function initFaceVerify(){ $name = input('name'); $id_no = input('id_no'); $MetaInfo = input('MetaInfo'); $ReturnUrl = input('ReturnUrl'); $res = Certification::main($name,$id_no,$MetaInfo,$ReturnUrl); if(!$res) $this->error('初始化错误'); $result = json_decode(json_encode($res),true)['body']; $result['code'] != 200 ? $this->error($result['message']):$this->success('ok',$result); } /** * @title 保存人脸认证 * @desc 保存人脸认证 * @author QC * @method POST * @tag 编辑信息 * @url /api/User_center/saveVerify * @header name:Authorization require:1 desc:Token * @param name:name type:string default:1 desc:姓名 * @param name:id_no type:string default:1 desc:身份证号 * @param name:CertifyId type:string default:1 desc:实人认证唯一标识 */ function saveVerify() { $name = input('name'); $id_no = input('id_no'); $CertifyId = input('CertifyId'); if (!$name || !$id_no || !$CertifyId) $this->error('参数错误'); $check_id_card = isCreditNo($id_no); if (!$check_id_card) $this->error('身份证号格式错误'); $is_auth = Db::table('store_member')->where('id',$this->uid)->value('is_auth'); if($is_auth) $this->error('已认证'); $check = Db::name('store_member')->where('id_card',$id_no)->count(); if ($check) $this->error('身份证号已经认证过'); // 核验 $res = Certification::check($CertifyId); if(!$res) $this->error('认证失败'); $result = json_decode(json_encode($res),true)['body']; if($result['code'] != 200) $this->error($result['message']); Db::table('store_member')->where('id',$this->uid)->update(['is_auth'=>1,'true_name'=>$name,'id_card'=>$id_no,'auth_at'=>date('Y-m-d H:i:s')]); setMemberInfoHash($this->uid); $this->success('认证成功'); } }