123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278 |
- <?php
- namespace app\api\controller;
- use AlibabaCloud\Client\AlibabaCloud;
- use AlibabaCloud\Client\Exception\ClientException;
- use AlibabaCloud\Client\Exception\ServerException;
- use app\common\library\AliPay2;
- use think\cache\driver\Redis;
- use think\Db;
- /**
- * @title 会员个人中心
- * @controller UserCenter
- * @group base
- */
- class UserCenter extends Base
- {
- public function initialize()
- {
- parent::initialize();
- // parent::check_login();
- }
- /**
- * @title 获取个人信息
- * @desc 个人信息
- * @author Gavin
- * @url /api/User_center/getUserInfo
- * @method POST
- * @tag 个人信息
- * @header name:Authorization require:1 desc:Token
- * @return name:id type:int default:-- desc:ID(邀请ID)
- * @return name:phone type:string default:-- desc:手机号
- * @return name:name type:string default:-- desc:昵称
- * @return name:headimg type:string default:-- desc:头像地址
- * @return name:integral type:int default:-- desc:积分
- * @return name:snap_card type:int default:-- desc:抢购卡
- * @return name:wallet_address type:int 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:vip_name type:int default:-- desc:身份
- * @return name:is_order_no_paid type:string default:-- desc:是否有未支付订单true:有false:没有
- * @return name:is_sign type:string default:-- desc:今日是否已经签到true:已签到false:未签到
- * @return name:invite_img type:string default:-- desc:邀请二维码
- * @return name:invite_address type:string default:-- desc:邀请地址
- * @return name:lucky_number type:int default:-- desc:剩余抽奖次数
- * @return name:money type:string default:-- desc:余额
- */
- public function getUserInfo()
- {
- parent::check_login();
- $uid = $this->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'] = $user_info['vip']==1 ? "藏友" : "创世勋章";
- //是否有待支付订单
- $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;
- //今日是否签到
- $date = date('Y-m-d');
- $sign = Db::name('store_member_sign')->where('mid',$uid)->where('date',$date)->count();
- $user_info['is_sign'] = $sign ? true : 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;
- $user_info['id'] = (string)$user_info['id'];
- //生成邀请码
- 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']);
- if (!$user_info['wallet_address']){
- $name = $user_info['phone'];
- $operationId = $user_info['phone'];
- $operationId .= rand(10000,99999);
- $url = getIpAddress()."customNFT/createAccount?name=".$name."&operationId=".$operationId;
- $offlineaccount = file_get_contents($url);
- $offline_account = json_decode($offlineaccount,true);
- if (isset($offline_account) && isset($offline_account['account'])){
- Db::name('store_member')->where('id',$user_info['id'])
- ->update(['accountName'=>$operationId,'wallet_address'=>$offline_account['account'],'offline_account'=>$offlineaccount]);
- }
- }
- $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()
- {
- parent::check_login();
- $code = input('code');
- if(empty($code)) $this->error('参数错误');
- $appid = getConfigValue('wechat_appid');
- $secret = getConfigValue('wechat_appsecret');
- $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()
- {
- parent::check_login();
- $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(){
- parent::check_login();
- $this->check_login();
- $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 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(){
- parent::check_login();
- //redis原子锁
- if (redisSetNx('userCertification'.$this->uid,2)){
- $true_name = input('post.true_name');
- $id_card = input('post.id_card');
- $bank_card = input('post.bank_card');
- $bank_mobile = input('post.bank_mobile');
- if (!$true_name || !$id_card || !$bank_card) $this->error('参数错误');
- $check_id_card = isCreditNo($id_card);
- //获取年龄
- $age = getAge($id_card);
- if (!$check_id_card) $this->error('身份证号格式错误');
- // if (!checkbank($bank_card)) $this->error('银行卡号格式错误');
- if ($age<18 || $age>65) $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('身份证号已经认证过');
- $bank_check = Db::name('store_member')->where('bank_card',$bank_card)->count();
- if ($bank_check) $this->error('银行卡号已经使用过');
- //四要素
- $res = idcardlingyufour($id_card,$true_name,$bank_card,$bank_mobile);
- if (!$res['success']) $this->error($res['remark']);
- 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);
- $user1 = getMemberInfoHash($this->uid); //获取用户信息
- if ($user1['pid']){
- $data = [
- 'mid'=>$user1['pid'],
- 'to_mid'=>$this->uid,
- 'create_at'=>date('Y-m-d H:i:s')
- ];
- Db::name('store_activities_invite_log')->insert($data);
- }
- //拉新奖励
- //pullNew($this->uid);
- pull_new($this->uid);
- DelRedisSetNx('userCertification'.$this->uid);
- $this->success('认证成功');
- }
- DelRedisSetNx('userCertification'.$this->uid);
- $this->error('认证失败');
- }else{
- $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()
- {
- parent::check_login();
- $old_password = input('post.old_password');
- $new_password = input('post.new_password');
- $confirm_password = input('post.confirm_password');
- // $yzm = input('post.yzm');
- 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();
- //验证短信验证码
- // $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('短信验证码不正确!');
- 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()
- {
- parent::check_login();
- $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
- *
- * @return name:id type:int require:0 default:0 desc:藏品ID
- * @return name:tag type:strin 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 myCollection(){
- parent::check_login();
- $type = input('type');
- $where = [
- 'mid'=>$this->uid,
- 'is_destruction'=>1,
- 'resale_status'=>1
- ];
- $cids = Db::name('store_order_info')->where($where)
- ->where('status','neq','2')
- ->when($type,function ($query) use ($type){
- if ($type==1){
- $query->where('type','neq',3);
- }else{
- $query->where('type',3);
- }
- })
- ->group('c_id')
- ->column('c_id');
- $arr = [];
- foreach ($cids as &$v){
- $array['c_id'] = $v;
- $array['count'] = Db::name('store_order_info')
- ->where($where)
- ->when($type,function ($query) use ($type){
- if ($type==1){
- $query->where('type','neq',3);
- }else{
- $query->where('type',3);
- }
- })
- ->where('c_id',$v)
- ->where('status','neq','2')
- ->count();
- $info = Db::name('store_order_info')
- ->where($where)->where('c_id',$v)
- ->limit(1)
- ->field('id,name,cover,tag,pro_info')
- ->find();
- $array['cover'] = $info['cover'];
- $array['name'] = $info['name'];
- $pro_info = json_decode($info['pro_info'],true);
- $array['auth_img'] = $pro_info['auth_img'];
- $array['auth_name'] = $pro_info['auth_name'];
- $tag = explode('#',$info['tag']);
- $tag2 = explode('/',$tag[1]);
- $array['tag'] = $tag[0].'#???'.'/'.$tag2[1];
- array_push($arr,$array);
- }
- $this->success('成功',$arr);
- $list = Db::name('store_order_info')
- ->where('mid',$this->uid)
- ->when($type,function ($query) use ($type){
- if ($type==1){
- $query->where('type','neq',3);
- }else{
- $query->where('type',3);
- }
- })
- ->where('status','neq','2')
- ->where('is_destruction',1)
- ->where('resale_status',1)
- ->field('id,tag,pro_info,c_id')
- ->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']? $pro_info['auth_img'] : Db::name('store_collection')->where('id',$v['c_id'])->value('auth_img');
- $v['auth_name'] = $pro_info['auth_name'] ? $pro_info['auth_name'] : Db::name('store_collection')->where('id',$v['c_id'])->value('auth_name');
- if ($v['tag']){
- $tag = explode('#',$v['tag']);
- $tag1 = substr($tag[0],0,6);
- $v['tag'] = $tag1.'#'.$tag[1];
- }
- unset($v['pro_info']);
- }
- $this->success('成功',$list);
- }
- /**
- * @title 藏品列表
- * @desc 藏品列表
- * @author Gavin
- * @method POST
- * @tag 编辑信息
- * @url /api/User_center/myCollectionList
- * @header name:Authorization require:1 desc:Token
- *
- * @param name:c_id type:string 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: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 myCollectionList(){
- parent::check_login();
- $c_id = input('c_id');
- if (!$c_id) $this->error('参数错误');
- $list = Db::name('store_order_info')
- ->where('mid',$this->uid)
- ->where('status','neq','2')
- ->where('c_id',$c_id)
- ->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/myCollection
- * @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 myCollection2(){
- parent::check_login();
- $type = input('type');
- $list = Db::name('store_order_info')
- ->where('mid',$this->uid)
- ->when($type,function ($query) use ($type){
- if ($type==1){
- $query->where('type','neq',3);
- }else{
- $query->where('type',3);
- }
- })
- ->where('status','neq','2')
- ->where('is_destruction',1)
- ->where('resale_status',1)
- ->field('id,tag,pro_info,c_id')
- ->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']? $pro_info['auth_img'] : Db::name('store_collection')->where('id',$v['c_id'])->value('auth_img');
- $v['auth_name'] = $pro_info['auth_name'] ? $pro_info['auth_name'] : Db::name('store_collection')->where('id',$v['c_id'])->value('auth_name');
- if ($v['tag']){
- $tag = explode('#',$v['tag']);
- $tag1 = substr($tag[0],0,6);
- $v['tag'] = $tag1.'#'.$tag[1];
- }
- unset($v['pro_info']);
- }
- $this->success('成功',$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(){
- parent::check_login();
- $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: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:company_hash type:string require:0 default:0 desc:流转公司hash
- * @return name:examples_illustrate 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(){
- parent::check_login();
- $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');
- }
- $issuer = Db::name('store_collection')->where('id',$info['c_id'])->value('issuer');
- if (!empty($issuer)){
- $info['company'] = $issuer;
- }
- $info['detail_img'] = $info['pro_info']['detail_img'];
- $info['format'] = $info['pro_info']['format'];
- $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['c_id'] = (string)$info['c_id'];
- if (!empty($info['tag'])){
- $tag = explode('#',$info['tag']);
- $tag1 = substr($tag[0],0,6);
- $info['tag'] = $tag1.'#'.$tag[1];
- }
- $info['pro_info']['auth_name'] = $info['pro_info']['auth_name'] ? $info['pro_info']['auth_name'] : Db::name('store_collection')->where('id',$info['c_id'])->value('auth_name');
- $info['pro_info']['auth_img'] = $info['pro_info']['auth_img'] ? $info['pro_info']['auth_img'] : Db::name('store_collection')->where('id',$info['c_id'])->value('auth_img');
- if ($info['collectors_hash_time']!='0000-00-00 00:00:00'){
- $info['create_at'] = $info['collectors_hash_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:wallet_address type:int require:1 default:-- desc:钱包地址
- * @param name:second_password type:int require:1 default:-- desc:二级密码
- *
- */
- public function examples(){
- parent::check_login();
- //redis原子锁
- if (redisSetNx('examples'.$this->uid,2)){
- $v = getConfigValue('examples_switch');
- if (!$v) $this->error('维护中,暂时关闭');
- $id = input('id');
- $phone = input('phone');
- $wallet_address = input('wallet_address');
- $second_password = input('second_password');
- if (!$id || !$phone || !$wallet_address) $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)->where('wallet_address',$wallet_address)->find();
- if (!$member) $this->error('转赠用户不存在');
- if ($member['id']==$this->uid) $this->error('不能转赠给自己');
- if (!$info['collectors_hash']) $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']*24*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']*24*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'],
- 'type'=>$pro_info['type'],
- 'status'=>3,
- 'to_mid'=>$this->uid,
- 'over_time'=>date('Y-m-d H:i:s'),
- 'tokenid'=>$info['tokenid'],
- 'nfttype'=>$info['nfttype'],
- 'nftid'=>$info['nftid'],
- '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){
- DelRedisSetNx('examples'.$this->uid);
- $this->success('转赠成功');
- }
- DelRedisSetNx('examples'.$this->uid);
- $this->error('转赠失败');
- }else{
- $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
- *
- */
- 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();
- if (!$log){
- $data = [
- 'mid'=>$this->uid,
- 'message_id'=>$id
- ];
- Db::name('store_message_read_log')->insert($data);
- }
- $this->success('成功');
- }
- /**
- * @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(){
- parent::check_login();
- $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:create_at type:string require:0 default:0 desc:时间
- */
- public function invitedRecord(){
- parent::check_login();
- $count = Db::name('store_member')
- ->where('is_auth',1)
- ->where('pid',$this->uid)->count();
- $list = Db::name('store_member')
- ->field('id,headimg,name,create_at,phone,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['name'] = substr($v['name'],0,16);
- $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: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:时间
- */
- public function invitedList(){
- $count = Db::name('store_member as a')
- ->field('a.id,a.name,a.headimg,a.phone,a.pid,(select count(b.id) from store_member as b where b.pid=a.id and b.is_auth=1) as count')
- ->group('a.id')
- ->having('count>0')
- ->count();
- $list = Db::name('store_member as a')
- ->field('a.id,a.name,a.headimg,a.phone,a.pid,(select count(b.id) from store_member as b where b.pid=a.id and b.is_auth=1) as count')
- ->group('a.id')
- ->having('count>0')
- ->order('count desc')
- ->limit($this->off_set,$this->page_num)
- ->select();
- $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(){
- parent::check_login();
- $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(){
- parent::check_login();
- $where = [
- 'm_id'=>$this->uid,
- 'type'=>1
- ];
- $status = input('status');
- $count = Db::name('store_member_log')
- ->where($where)
- ->when($status,function ($query) use ($status){
- $pm = $status==1 ? 1 : 0;
- $query->where('pm',$pm);
- })
- ->count();
- $list = Db::name('store_member_log')
- ->field('id,pm,change,title,create_at')
- ->where($where)
- ->when($status,function ($query) use ($status){
- $pm = $status==1 ? 1 : 0;
- $query->where('pm',$pm);
- })
- ->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:每页数
- *
- * @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 moneyLog(){
- parent::check_login();
- $where = [
- 'm_id'=>$this->uid,
- 'type'=>3
- ];
- $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/withdraw
- * @header name:Authorization require:1 desc:Token
- *
- * @param name:money type:int : default: desc:提现金额
- * @param name:withdraw_type type:int : default: desc:提现方式
- *
- */
- public function withdraw(){
- parent::check_login();
- //redis原子锁
- if (redisSetNx('withdraw'.$this->uid,3)){
- $v = getConfigValue('withdraw_switch');
- if (!$v) $this->error('维护中,暂时关闭');
- $money = input('money');
- $withdraw_type = input('withdraw_type','wx');
- if (!$money) $this->error('参数错误');
- $user = Db::name('store_member')->where('id',$this->uid)->find();
- if ($user['money']<$money) $this->error('余额不足');
- $withdraw_min_price = getConfigValue('withdraw_min_price'); //最小提现金额
- $withdraw_max_price = getConfigValue('withdraw_max_price'); //最大提现金额
- $poundage_proportion = getConfigValue('poundage_proportion'); //手续费百分比
- if ($money < $withdraw_min_price)
- $this->error('最低提现'.$withdraw_min_price.'元');
- if ($money > $withdraw_max_price)
- $this->error('最大提现'.$withdraw_min_price.'元');
- if ($withdraw_type=='zfb'){
- if (!$user['zfb_account'] || !$user['zfb_real_name']) $this->error('请先绑定支付宝');
- }
- $data['mid'] = $this->uid;
- $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;
- $data['withdraw_type'] = $withdraw_type;
- $id =Db::name('store_member_withdraw')->insertGetId($data);
- if ($id){
- Db::startTrans();
- try {
- //减少用户余额
- $res = memberMoneyChange($money,3,$this->uid,'余额提现',0,$id);
- if ($res){
- switch ($withdraw_type){
- case 'zfb':
- $zfb = new AliPay2();//实例化支付宝支付控制器
- $result = $zfb->FundTransToaccount($order_no, $user['zfb_account'], $user['zfb_real_name'], $real_money,'余额提现');//调用支付宝支付的方法
- if (!empty($result) && $result['code'] == 10000){
- Db::name('store_member_withdraw')->where('id',$id)->update(['paid'=>1,'pay_time'=>time(),'return_info'=>json_encode($result['result'],true)]);
- }else{
- Db::name('store_member_withdraw')->where('id',$id)->update(['return_info'=>json_encode($result['result'],true)]);
- Db::rollback();
- $this->error('提现失败,请检查绑定的支付宝信息');
- }
- break;
- }
- Db::commit();
- DelRedisSetNx('withdraw'.$this->uid);
- $this->success('提现成功');
- }else{
- Db::rollback();
- DelRedisSetNx('withdraw'.$this->uid);
- $this->error('提现失败,请稍后重试');
- }
- }catch (Exception $e) {
- Db::rollback();
- DelRedisSetNx('withdraw'.$this->uid);
- $this->error('提现失败,请稍后重试1');
- }
- }else{
- DelRedisSetNx('withdraw'.$this->uid);
- $this->error('提现失败,请稍后重试2');
- }
- }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
- *
- */
- public function openBoxCollection(){
- parent::check_login();
- //redis原子锁
- if (redisSetNx('openBox'.$this->uid,3)){
- $id = input('id');
- if (!$id) $this->error('参数错误');
- $info = Db::name('store_order_info')
- ->where('id',$id)
- ->where('status','neq',2)
- ->where('mid',$this->uid)
- ->where('is_destruction',1)
- ->find();
- if (!$info) $this->error('盲盒不存在');
- if ($info['resale_status']!=1) $this->error('盲盒挂售中或已出售');
- $com = true;
- Db::startTrans();
- try {
- //销毁
- Db::name('store_order_info')->where('id',$id)->update(['is_destruction'=>0]);
- checkBoxCollection($info['c_id']);
- $prize_arr = Db::name('store_box')
- ->where('status',1)
- ->where('coll_id',$info['c_id'])
- ->where('is_del',1)
- ->field('id,rate')
- ->select();
- foreach ($prize_arr as $key => $val) {
- $arr[$val['id']] = $val['rate'];//概率数组
- }
- $rid = get_rand($arr); //根据概率获取奖项id
- // $a=array_rand($prize_arr,1);
- // $rid=$prize_arr[$a]['id'];
- $pr_info = Db::name('store_box')->where('id',$rid)->field('id,title,prize,is_prize')->find();
- $return = [
- 'is_prize'=>$pr_info['is_prize']
- ];
- $coll_info = getCollectionInfoHash($pr_info['prize']);
- if ($pr_info['is_prize']==1){
- $json_info = json_encode($coll_info,true);
- $return['name'] = $pr_info['title'];
- $return['cover'] = $coll_info['cover'];
- }else{
- $json_info = '';
- $return['name'] = '未中奖';
- $return['cover'] = '';
- }
- $data = [
- 'm_id'=>$this->uid,
- 'b_id'=>$rid,
- 'is_prize'=>$pr_info['is_prize'],
- 'name'=>$return['name'],
- 'cover'=>$return['cover'],
- 'info'=>$json_info,
- 'date'=>date('Y-m-d'),
- 'is_free'=>1
- ];
- Db::name('store_blind_box_log')->insert($data);
- if ($pr_info['is_prize']==1){
- //获取排名
- $rank = getRanking($pr_info['prize'])+1;
- $tag = getTag($pr_info['prize'],$rank,$coll_info['inventory']);
- saveRanking($pr_info['prize']);
- $is_nft = Db::name('hash2')->where('goods_id',$pr_info['prize'])->where('success',1)->find();
- $collectors_hash = '';
- $date = [
- 'order_id'=>0,
- 'order_no'=>get_order_sn(),
- 'tag'=>$tag,
- 'mid'=>$this->uid,
- 'c_id'=>$pr_info['prize'],
- 'name'=>$coll_info['name'],
- 'cover'=>$coll_info['cover'],
- 'pro_info'=>$json_info,
- 'tokenid'=>$is_nft['class_id'],
- 'nfttype'=>$is_nft['operationId'],
- 'collectors_hash'=>$collectors_hash,
- // 'collectors_hash_time'=>' ',
- 'status'=>4
- ];
- Db::name('store_order_info')->insert($date);
- }
- Db::commit();
- }catch (Exception $e) {
- $com = false;
- Db::rollback();
- }
- if ($com){
- setMemberInfoHash($this->uid);
- if ($pr_info['is_prize']==1){
- //减掉库存
- loseCollectionInventory($pr_info['prize'],1);
- }
- DelRedisSetNx('openBox'.$this->uid);
- $this->success('成功',$return);
- }else{
- DelRedisSetNx('openBox'.$this->uid);
- $this->error('开启失败,请稍后重试');
- }
- }else{
- $this->error('请求过快');
- }
- }
- }
|