Browse Source

支付及回调 业务鉴权 用户信息

15954078560 2 years ago
parent
commit
5fa027f0b0
2 changed files with 122 additions and 187 deletions
  1. 75 7
      application/api/controller/Pay.php
  2. 47 180
      application/api/controller/User.php

+ 75 - 7
application/api/controller/Pay.php

@@ -3,13 +3,8 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
-use app\common\library\Ems;
-use app\common\library\Sms;
-use fast\Random;
 use think\Config;
-use think\Validate;
 use think\Db;
-use wxpay;
 
 /**
  * 会员接口
@@ -89,13 +84,86 @@ class Pay extends Api
             'Content-Type:application/json'
         ];
         $rs = httpRequest($url, 'POST', $data, $header);
-        p($rs);
+        if (!$rs) {
+            $this->error('您的网络开小差了~');
+        }
+        $rs = json_decode($rs, true);
+        if ($rs['resultCode'] != 0) {
+            $this->error('您的网络开小差了~');
+        }
 
+        $this->success('链接', $rs['data']);
     }
     
     //支付回调
     public function notify() {
-        
+        $data = file_get_contents('php://input');
+        if (!$data) {
+            $this->error('参数缺失');
+        }
+
+        $data = json_decode($data, true);
+        if (!$data) {
+            $this->error('参数缺失');
+        }
+
+        if ($data['orderstate'] != 0) {
+            echo json_encode([
+                'transid' => $data['transid'],
+                'orderid' => $data['orderid'],
+                'statuscode' => -1,
+                'statusdesc' => '订单状态失败'
+            ], 320);
+            die;
+        }
+
+        $order_no = $data['orderid'];
+        $where['order_no'] = $order_no;
+        $order_info = Db::name('rechar_order')->where($where)->find();
+        if (!$order_info) {
+            echo json_encode([
+                'transid' => $data['transid'],
+                'orderid' => $data['orderid'],
+                'statuscode' => -1,
+                'statusdesc' => '业务订单不存在'
+            ], 320);
+            die;
+        }
+        if ($order_info['status'] == 1) { //已回调成功
+            echo json_encode([
+                'transid' => $data['transid'],
+                'orderid' => $data['orderid'],
+                'statuscode' => 0,
+                'statusdesc' => ''
+            ], 320);
+            die;
+        }
+
+        //构建支付订单处理结果信息
+        $_data['status'] = 1;
+        $_data['updatetime'] = time();
+        if ($order_info['purpose'] == 3) {
+            //开通会员
+            Db::startTrans();
+            //充值
+            $rs = Db::name('user')->where(['id' => $order_info['user_id']])->setField('is_vip', 1);
+            if ($rs === false) {
+                Db::rollback();
+                $_data['pay_status'] = 3; //回调状态:1=支付订单回调失败,2=充值回调失败,3=开通会员回调失败
+            } else {
+                Db::commit();
+            }
+        }
+
+        //修改订单信息
+        Db::name('rechar_order')->where($where)->setField($_data);
+
+        echo json_encode([
+            'transid' => $data['transid'],
+            'orderid' => $data['orderid'],
+            'statuscode' => 0,
+            'statusdesc' => ''
+        ], 320);
     }
     
 }

+ 47 - 180
application/api/controller/User.php

@@ -2004,186 +2004,6 @@ class User extends Api
         $this->success('申请退款成功,请等待审核');
     }
 
-    //查询用户信息
-    public function getmyinfo() {
-        $user_id = input('user_id', 0, 'intval'); //用户id
-        if (!$user_id) {
-            $user_id = $this->auth->id;
-        }
-
-        $hu_user = Db::name('user');
-        $user_info = $hu_user->field(['id', 'nickname', 'mobile', 'avatar', 'height', 'weight', 'birthday', 'excel_position', 'rank_id', 'total_num', 'win_num', 'lose_num', 'power_value', 'mvp_num', 'foul_num', 'block_num', 'help_num', 'backboard_num', 'score', 'assess'])->where(['id' => $user_id])->find();
-        if (!$user_info) {
-            $this->error('您的网络开小差了');
-        }
-        $user_info['avatar'] = one_domain_image($user_info['avatar']);
-        $user_info['age'] = birthtime_to_age($user_info['birthday']);
-        $user_info['birthday'] = date('Y-m-d', $user_info['birthday']);
-        $rank_info = Db::name('rank')->where(['id' => $user_info['rank_id']])->find();
-        $user_info['rank_name'] = $rank_info ? $rank_info['name'] : '';
-        $user_info['rank_image'] = $rank_info ? one_domain_image($rank_info['image']) : '';
-
-        $user_info['max_total_num'] = $hu_user->order('total_num desc')->value('total_num');
-        $user_info['max_power_value'] = $hu_user->order('power_value desc')->value('power_value');
-        $user_info['max_win_num'] = $hu_user->order('win_num desc')->value('win_num');
-        $user_info['max_mvp_num'] = $hu_user->order('mvp_num desc')->value('mvp_num');
-        $user_info['max_foul_num'] = $hu_user->order('foul_num desc')->value('foul_num');
-        $user_info['winning_rate'] = $user_info['total_num'] == 0 ? 0 : ceil($user_info['win_num'] / $user_info['total_num']);
-        $user_info['max_block_num'] = $hu_user->order('block_num desc')->value('block_num');
-        $user_info['max_help_num'] = $hu_user->order('help_num desc')->value('help_num');
-        $user_info['max_backboard_num'] = $hu_user->order('backboard_num desc')->value('backboard_num');
-        $user_info['max_score'] = $hu_user->order('score desc')->value('score');
-
-        $this->success('信息', $user_info);
-    }
-
-    //修改信息
-    public function editinfo() {
-        $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars'); //头像
-        $nickname = $this->request->post('nickname', '', 'trim'); //昵称
-        $birthday = $this->request->post('birthday', '', 'strtotime'); //生日
-        $height = input('height', 0, 'intval'); //身高
-        $weight = input('weight', 0, 'intval'); //体重
-        $excel_position = input('excel_position', '', 'trim'); //擅长位置
-
-        $data = [];
-        if ($avatar) {
-            if (iconv_strlen($avatar, 'utf-8') > 255) {
-                $this->error('图片超出范围');
-            }
-            $data['avatar'] = $avatar;
-        }
-        if ($nickname) {
-            if (iconv_strlen($nickname, 'utf-8') > 30) {
-                $this->error('昵称最多30字');
-            }
-            $data['nickname'] = $nickname;
-        }
-        if ($height > 0) {
-            $data['height'] = $height;
-        }
-        if ($weight > 0) {
-            $data['weight'] = $weight;
-        }
-        if ($birthday) {
-            $data['birthday'] = $birthday;
-        }
-        if ($excel_position) {
-            if(iconv_strlen($excel_position, 'utf-8') > 30) {
-                $this->error('请选择正确位置');
-            }
-            $data['excel_position'] = $excel_position;
-        }
-
-        if (!$data) {
-            $this->error('暂无修改内容');
-        }
-        //修改用户表
-        $rt = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
-        if ($rt === false) {
-            $this->error('修改失败');
-        }
-
-        $this->success('修改成功');
-    }
-
-    //我的比赛
-    public function mygame() {
-        $list = Db::name('game_people')->field('id, game_id, createtime, status')->where(['user_id' => $this->auth->id, 'status' => ['gt', 0]])->page($this->page, $this->pagenum)->order('id desc')->select();
-
-        if ($list) {
-            $hu_game = Db::name('game');
-            foreach ($list as &$v) {
-                $v['createtime'] = date('Y.m.d', $v['createtime']);
-                $game_info = $hu_game->field('name, image')->where(['id' => $v['game_id']])->find();
-                $v['game_name'] = $game_info['name'];
-                $v['game_image'] = one_domain_image($game_info['image']);
-            }
-        }
-
-        $this->success('我的比赛', $list);
-    }
-    
-    //取消报名
-    public function cancelsignup() {
-        $id = input('id', 0, 'intval'); //报名id
-        if (!$id) {
-            $this->error('参数缺失');
-        }
-
-        $game_people_info = Db::name('game_people')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
-        if (!$game_people_info) {
-            $this->error('数据丢失');
-        }
-        if ($game_people_info['status'] == 0) {
-            $this->error('您尚未报名');
-        }
-        if ($game_people_info['status'] != 1) {
-            $this->error('您已取消报名了');
-        }
-        $time = time();
-        if ($game_people_info['starttime'] < $time) {
-            $this->error('比赛已经开始,不能取消');
-        }
-
-        $data['group'] = 0;
-        $data['is_leader'] = 0;
-        $data['now_num'] = $game_people_info['is_leader'] == 1 ? 0 : ($game_people_info['now_num'] - 1);
-        $data['status'] = 2;
-        $data['updatetime'] = $time;
-
-        //开启事务
-        Db::startTrans();
-        //修改数据
-        $rs = Db::name('game_people')->where(['id' => $id, 'status' => 1])->setField($data);
-        if (!$rs) {
-            Db::rollback();
-            $this->error('您的网络开小差了');
-        }
-        if ($game_people_info['is_leader'] == 1) {
-            //是队长, 取消即解散队伍
-            //开启redis
-            $redis = new \Redis();
-            $redis->connect(config('redis_host'), config('redis_port'));
-            if (config('redis_pwd')) {
-                $redis->auth(config('redis_pwd'));
-            }
-            if(config('redis_selectdb') > 0){
-                $redis->select(config('redis_selectdb'));
-            }
-            //是否可以操作: 1可以  其他 不可以
-            $game_people_status = $redis->lPop('game_people' . $game_people_info['game_id'] . '_' . $game_people_info['group']);
-            if ($game_people_status != 1) {
-                Db::rollback();
-                $this->error('网络繁忙,请稍后再试');
-            }
-
-            //更改队伍其他成员信息
-            $rt = Db::name('game_people')->where(['game_id' => $game_people_info['game_id'], 'group' => $game_people_info['group']])->setField(['group' => 0, 'now_num' => 0, 'updatetime' => $time]);
-            if ($rt === false) {
-                Db::rollback();
-                $redis->rPush('game_people' .  $game_people_info['game_id'] . '_' . $game_people_info['group'], 1);
-                $this->error('您的网络开小差了');
-            }
-
-            $redis->rPush('game_people' .  $game_people_info['game_id'] . '_' . $game_people_info['group'], 1);
-        }
-
-
-        Db::commit();
-        $this->success('取消成功');
-    }
-
-    //联系我们
-    public function contact() {
-        $data['customer_service'] = config('site.customer_service'); //客服电话
-        $data['customer_service_desc'] = config('site.customer_service_desc'); //客服电话描述
-        $data['qq'] = config('site.qq'); //联系QQ
-        $data['qr_code'] = cdnurl(config('site.qr_code')); //微信群二维码
-
-        $this->success('联系我们', $data);
-    }
-
     //手机号登录/注册
     public function mobileloginregister() {
         $mobile = $this->request->post('mobile');
@@ -2211,4 +2031,51 @@ class User extends Api
             $this->error($this->auth->getError());
         }
     }
+
+    //查询我的信息
+    public function getmyinfo()
+    {
+        $user = Db::name('user')->find($this->auth->id);
+
+        $data['nickname'] = $user['nickname']; //姓名
+        $data['username'] = $user['username']; //UID
+        $data['avatar'] = cdnurl($user['avatar']); //头像
+        $data['mobile'] = $user['mobile']; //手机号
+        $data['money'] = $user['money']; //余额
+        $data['realname'] = $user['realname']; //真实姓名
+        $data['gender'] = $user['gender']; //性别:1=男,2=女
+        $data['birthday'] = date('Y-m-d', $user['birthday']); //生日
+        //查询vip是否到期
+        $url = 'http:// 183.207.215.112:8090/HDC/bizauth/phone/auth';
+        $post_data = [
+            'phoneNumber' => $this->auth->mobile,
+            'productCodes' => [config('product_code')],
+            'channel' => '01'
+        ];
+        $post_data = json_encode($post_data, 320);
+        $header = [
+            /*'Host:112.4.10.122:8090',
+            'HDC-Service:2',
+            'HDC-APPID:00001',
+            'HDC-Token:8e2b129d2cd3ebf40ca5a1c6048b083ce92e5fd3f305fd6c11a3ef3e35b5fa08',*/
+            'Content-Type:application/json'
+        ];
+        $rs = httpRequest($url, 'POST', $post_data, $header);
+        if (!$rs) {
+            $data['is_vip'] = 0;
+        } else {
+            $rs = json_decode($rs, true);
+            if ($rs['code'] == '00' && $rs['result'][0]['isOrder'] == true) {
+                $data['is_vip'] = 1;
+            } else {
+                $data['is_vip'] = 0;
+            }
+        }
+
+        if ($this->auth->is_vip != $data['is_vip']) {
+            Db::name('user')->where(['id' => $this->auth->id])->setField('is_vip', $data['is_vip']);
+        }
+
+        $this->success('信息', $data);
+    }
 }