12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394 |
- <?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;
- use think\Exception;
- class UserCenter extends Base
- {
- public function initialize()
- {
- parent::initialize();
- parent::check_login();
- }
-
- public function getUserInfo()
- {
- $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'] = '普通会员';
-
- $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);
- }
-
- 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失败');
- }
- }
-
- 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('编辑失败');
- }
-
- 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('绑定失败');
- }
-
- 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();
-
- $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('绑定失败');
- }
-
- 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('认证失败');
- }
-
- 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('修改失败');
- }
-
- 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);
-
- $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('修改失败');
- }
-
- 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']*24*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']*24*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);
- }
-
- 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')
- ->order('jump_id desc')
- ->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]);
- }
-
- 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);
- }
-
- 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);
- }
-
- 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['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']*24*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']*24*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);
- }
-
- public function examples(){
- $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');
-
- $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 (!$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']*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'],
- '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('转赠失败');
- }
-
- 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();
- 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'));
- }
-
- 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]);
- }
-
- public function getFaceSign(){
- $name = input('name');
- $idNo = input('idNo');
- if (!$name || !$idNo) $this->error('参数错误');
- $userId = $this->uid;
-
- $data = getfaceid($name,$idNo,$userId);
- $this->success('成功',$data);
- }
-
- public function invitedRecord(){
- $count = Db::name('store_member')->where('pid',$this->uid)->count();
- $list = Db::name('store_member')
- ->field('id,headimg,name,phone,create_at')
- ->where('pid',$this->uid)
- ->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'));
- }
-
- 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) 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) as count')
- ->group('a.id')
- ->having('count>0')
- ->order('count desc')
- ->limit($this->off_set,$this->page_num)
- ->select();
- $this->success('成功',compact('count','list'));
- }
-
- 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('签到失败');
- }
-
- 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'));
- }
-
- public function moneyLog(){
- $select_type = input('select_type',-1);
- $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,change_type')
- ->where($where)
- ->when($select_type,function ($query)use($select_type){
- switch ($select_type) {
- case 0:case 1:
- $query->where('pm',$select_type);
- break;
- case 2:
- $query->whereIn('change_type','2,3');
- break;
- }
- })
- ->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'));
- }
-
- public function withdraw(){
- 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','wx');
- $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('余额不足');
-
- $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_min_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());
- }
- $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','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');
- $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_min_price.'元');
- if ($withdraw_type=='zfb'){
- if (!$user['zfb_account'] || !$user['zfb_real_name']) $this->error('请先绑定支付宝');
- }
- if($withdraw_type == 'wx' && !$user['openid']) $this->error('请先绑定微信');
- Db::startTrans();
- try {
- $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['account_no'] = $withdraw_type == 'wx'? $user['openid'] : $user['zfb_account'];
- $data['account_name'] = $withdraw_type == 'wx' ? $user['name'] : $user['zfb_real_name'];
- $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();
- DelRedisSetNx('withdraw'.$this->uid);
- $this->error($e->getMessage());
- }
- DelRedisSetNx('withdraw'.$this->uid);
- $this->success('提现申请成功,等待审核!');
- }else{
- $this->error('服务器繁忙,请稍后重试');
- }
- }
-
- public function openBoxCollection(){
-
- 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('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');
-
- $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)+1;
- $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,
-
- '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 : '');
- }else{
- DelRedisSetNx('openBox'.$this->uid);
- $this->error($msg);
- }
- }else{
- $this->error('请求过快');
- }
- }
-
- 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('已绑定手机号错误');
-
- $check_code = Db::name('store_sms')
- ->where(['phone'=>$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('验证成功');
- }
-
- 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(['phone'=>$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(['phone'=>$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('更换成功');
- }
-
- 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);
- }
-
- 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('认证成功');
- }
- }
|