123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743 |
- <?php
- namespace app\api\controller;
- use AlibabaCloud\Client\AlibabaCloud;
- use AlibabaCloud\Client\Exception\ClientException;
- use AlibabaCloud\Client\Exception\ServerException;
- use app\common\library\AliPay;
- use EasyWeChat\Factory;
- 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:邀请地址
- */
- 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'] = $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;
- $this->success('获取成功',$user_info);
- }
- /**
- * @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
- * @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 (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');
- 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位纯数字');
- $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: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 myCollection(){
- $list = Db::name('store_order_info')
- ->where('mid',$this->uid)
- ->whereIn('status','1,3')
- ->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(){
- $id = input('id');
- if (!$id) $this->error('参数错误');
- $info = Db::name('store_order_info')->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');
- $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(){
- $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)->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('转赠用户不存在');
- $examples_number = Db::name('store_member')->where('id',$this->uid)->value('examples_number');
- $date = date('Y-m');
- $number = Db::name('store_collect_examples_log')
- ->where('mid',$this->uid)
- ->where('date',$date)
- ->count();
- //if ($number>=$examples_number) $this->error('转赠次数不足,无法转赠');
- if (!$info['collectors_hash']) $this->error('发放中,无法转赠');
- $mem = getMemberInfoHash($this->uid);
- if ($mem['second_password']!=md5($second_password)) $this->error('密码错误');
- if ($mem['id']==$member['id']) $this->error('无法转给自己');
- //$pro_info = json_decode($info['pro_info'],true);
- $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('持有时间限制,无法转赠');
- }
- }
- if ($info['is_business']==0 || $info['is_gas']==0){
- $recharge_address = $mem['wallet_address'];
- $data = [];
- if ($info['is_business']==0){
- //授权平台
- $rand = get_order_sn();
- $money = '30';
- $url = "http://192.144.219.204:8083/ddc/rechargeBusiness?money=$money&address=$recharge_address&transSn=".$rand;
- $res=curlRequest($url);
- $result = json_decode($res,true);
- if (isset($result['code']) && $result['code']==0){
- $data['is_business'] = 1;
- $data['business'] = $money;
- }else{
- $this->error('充值失败,请稍后再试');
- }
- }
- if ($info['is_gas']==0){
- $rand2 = get_order_sn();
- $money2 = '40';
- $url2 = "http://192.144.219.204:8083/ddc/rechargeGas?money=$money2&address=$recharge_address&transSn=".$rand2;
- $res2=curlRequest($url2);
- $result2 = json_decode($res2,true);
- if (isset($result2['code']) && $result2['code']==0){
- $data['is_gas'] = 1;
- $data['gas'] = $money2;
- }else{
- $this->error('充值失败,请稍后再试');
- }
- }
- if ($data){
- Db::name('store_order_info')->where('id',$id)->update($data);
- }
- //$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'],
- 'pro_info'=>$info['pro_info'],
- 'status'=>3,
- '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'),
- 'type'=>$info['type']
- ];
- Db::name('store_order_info')->insert($to_date);
- $log_date = [
- 'order_info_id'=>$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){
- $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
- *
- */
- 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(){
- $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(){
- $count = Db::name('store_member')->where('pid',$this->uid)->count();
- $list = Db::name('store_member')
- ->field('id,headimg,name,create_at')
- ->where('pid',$this->uid)
- ->order('id 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(){
- $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 M
- * @method POST
- * @url /api/User_center/wallet
- * @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:money type:int require:0 default:0 desc:余额
- * @return name:list@change type:string require:0 default:0 desc:变动金额
- * @return name:list@reason type:string require:0 default:0 desc:变动说明
- * @return name:list@time type:string require:0 default:0 desc:变动时间
- */
- public function wallet(){
- $uid = $this->uid;
- $user_info = Db::name('store_member')
- ->field('money')
- ->where('id',$uid)
- ->find();
- if(empty($user_info)) $this->error('用户信息不正确');
- $list = Db::name('system_money_record')
- ->field('id,pm,change,reason,time')
- ->where('mem_id',$uid)
- ->order('time 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'];
- }
- $v['time'] = date('Y-m-d H:i:s',$v['time']);
- }
- $user_info['list'] = $list;
- $this->success('获取成功',$user_info);
- }
- /**
- * @title 充值页面
- * @desc 充值页面
- * @author M
- * @method POST
- * @url /api/User_center/recharge
- * @header name:Authorization require:1 desc:Token
- *
- * @return name:money type:int require:0 default:0 desc:余额
- * @return name:pay_way@img type:string require:0 default:0 desc:支付方式logo
- * @return name:pay_way@name type:string require:0 default:0 desc:支付方式
- * @return name:pay_way@code type:string require:0 default:0 desc:支付方式code
- */
- public function recharge(){
- $uid = $this->uid;
- $user_info = Db::name('store_member')
- ->field('money')
- ->where('id',$uid)
- ->find();
- if(empty($user_info)) $this->error('用户信息不正确');
- $detail['money'] = $user_info['money'];
- $list = Db::name('SystemPayWay')->where('status = 1 and code != "yue"')->field('img,name,code')->select();
- $detail['pay_way'] = $list;
- $this->success('获取成功',$detail);
- }
- /**
- * @title 提交充值
- * @desc 提交充值
- * @author M
- * @method POST
- * @url /api/User_center/toRecharge
- * @header name:Authorization require:1 desc:Token
- *
- * @param name:money type:int require:1 default:0.01 desc:充值金额
- * @param name:pay_way type:string require:1 default:-- desc:支付方式
- *
- * @return name:order_no type:int require:0 default:0 desc:订单号
- * @return name:pay type:string require:0 default:0 desc:支付信息
- */
- public function toRecharge(){
- $this->error('系统升级中...');
- $data = $this->request->post();
- $param_arr = [
- 'money'=>'请输入充值金额',
- 'pay_way'=>'请选择支付方式',
- ];
- foreach ($param_arr as $key=>$v){
- if(!isset($data[$key]) || $data[$key] == ''){
- $this->error($v);
- }
- }
- $uid = $this->uid;
- if($data['money'] <= 0) $this->error('充值数量不能小于0');
- $order['number'] = get_order_sn();
- $order['money'] = $data['money'];
- $order['need_pay'] = $data['money'];
- $order['mem_id'] = $uid;
- $order['time'] = time();
- $re_id = Db::name('SystemRecharge')->insertGetId($order);
- if($re_id){
- $body = '象寻在线充值';
- $order_no = $order['number'];
- $total_fee = $data['money'];
- switch ($data['pay_way']) {
- case 'wx':
- $config = retrunWxConfig();
- $total_fee = $total_fee * 100;
- $config['notify_url'] = $this->request->root(true).'/api/Pay/WxRechargeNotify';
- $app = Factory::payment($config);
- $result = $app->order->unify([
- 'body' => $body,
- 'out_trade_no' => $order_no,
- 'total_fee' => $total_fee,
- 'trade_type' => 'APP', // 请对应换成你的支付方式对应的值类型
- ]);
- if ($result['return_code']=='SUCCESS'){
- $jssdk = $app->jssdk;
- $order1 = $jssdk->appConfig($result['prepay_id']);
- $retrun_data['order_no'] = $order_no;
- $retrun_data['pay'] = $order1;
- }else{
- $this->error('调用微信支付失败');
- }
- break;
- case 'zfb':
- $zfb = new AliPay();
- $notify_url = $this->request->root(true).'/api/Pay/alipayRechargeNotify';//回调地址
- $order = $zfb->aliPay($body, $total_fee, $order_no, $notify_url);//调用支付宝支付的方法
- $retrun_data['order_no'] = $order_no;
- $retrun_data['pay'] = $order;
- break;
- case 'apple':
- $retrun_data['order_no'] = $order_no;
- $retrun_data['pay'] = ['order_no'=>$order_no];
- break;
- default:
- $this->error('支付方式错误');
- }
- $this->success('成功',$retrun_data);
- }else{
- $this->error('充值失败');
- }
- }
- }
|