Bläddra i källkod

地区 报名 支付回调

15954078560 2 år sedan
förälder
incheckning
e8634e17be

+ 65 - 0
application/api/controller/Area.php

@@ -0,0 +1,65 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 地区接口
+ */
+class Area extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+    public function area_list(){
+        $pid = input('pid',0);
+
+        $list = Db::name('area')->field('id,pid,name')->where('pid',$pid)->order('id asc')->select();
+
+        $this->success('success',$list);
+    }
+
+    //给ios用的
+    //一个接口全部数据都给到
+    public function area_json(){
+        $list   = Db::name('area')->field('id,pid,name,level')->order('id asc')->select();
+
+        //按级拆分
+        $list_1 = [];
+        $list_2 = [];
+        $list_3 = [];
+        foreach($list as $key => $value){
+            if($value['level'] == 1){
+                $list_1[] = $value;
+            }
+            if($value['level'] == 2){
+                $list_2[] = $value;
+            }
+            if($value['level'] == 3){
+                $list_3[] = $value;
+            }
+        }
+
+        //三级并到市级
+        foreach($list_2 as $k2 => $v2){
+            foreach($list_3 as $k3 => $v3){
+                if($v2['id'] == $v3['pid']){
+                    $list_2[$k2]['child'][] = $v3;
+                }
+            }
+        }
+
+        //市级并到省级
+        foreach($list_1 as $k1 => $v1){
+            foreach($list_2 as $k2 => $v2){
+                if($v1['id'] == $v2['pid']){
+                    $list_1[$k1]['child'][] = $v2;
+                }
+            }
+        }
+
+        $this->success('success',$list_1);
+
+    }
+}

+ 179 - 1
application/api/controller/Index.php

@@ -14,7 +14,7 @@ use Qcloud\Cos\Exception\ServiceResponseException;
  */
 class Index extends Api
 {
-    protected $noNeedLogin = ['banner', 'activelist', 'personaltype', 'personalactivetype', 'car', 'leader', 'personaldirection', 'activeinfo'];
+    protected $noNeedLogin = ['banner', 'activelist', 'personaltype', 'personalactivetype', 'car', 'leader', 'personaldirection', 'activeinfo', 'position', 'gamelist'];
     protected $noNeedRight = ['*'];
 
     /**
@@ -1196,4 +1196,182 @@ class Index extends Api
 
         $this->success('信息', $info);
     }
+    
+    //擅长位置
+    public function position() {
+        $list = Db::name('position')->field('id, name')->order('weigh, id')->select();
+
+        $this->success('擅长位置', $list);
+    }
+
+    //赛事活动
+    public function gameinfo() {
+        $list = Db::name('game_info')->field('id, name, image, createtime')->page($this->page, $this->pagenum)->order('weigh, id desc')->select();
+        $list = list_domain_image($list, ['image']);
+        if ($list) {
+            foreach ($list as &$v) {
+                $v['createtime'] = date('Y年m月d日');
+            }
+        }
+
+        $this->success('赛事活动', $list);
+    }
+
+    //赛事活动详情
+    public function gameinfodetail() {
+        $id = input('id', 0, 'intval');
+        if (!$id) {
+            $this->error('参数缺失');
+        }
+
+        $info = Db::name('game_info')->field('name, content')->where(['id' => $id])->find();
+        if (!$info) {
+            $this->error('您的网络开小差了');
+        }
+
+        $this->success('详情', $info);
+    }
+
+    //排位赛
+    public function gamelist() {
+        $where['signupendtime'] = ['gt', time()];
+        $where['status'] = 0;
+        $where['showstatus'] = 1;
+
+        $list = Db::name('game')->field('id, name, image')
+            ->where($where)->page($this->page, $this->pagenum)->order('weigh, id desc')->select();
+
+        $list = list_domain_image($list, ['image']);
+
+        $this->success('排位赛', $list);
+    }
+
+    //排位赛详情
+    public function gamedetail() {
+        $id = input('id', 0, 'intval'); //排位赛id
+        if (!$id) {
+            $this->error('参数缺失');
+        }
+
+        $info = Db::name('game')->field('id, name, desc, image, price, signupendtime, activecontent, status, showstatus')->where(['id' => $id])->find();
+        if (!$info) {
+            $this->error('您的网络开小差了');
+        }
+        if ($info['showstatus'] != 1) {
+            $this->error('比赛已经下架');
+        }
+
+        $info['signupendtime'] = date('Y.m.d H:i', $info['signupendtime']);
+        $info['image'] = one_domain_image($info['image']);
+        //查询是否报名
+        $info['sign_up'] = Db::name('game_people')->where(['user_id' => $this->auth->id, 'game_id' => $id, 'status' => 1])->count('id');
+
+        $this->success('详情', $info);
+    }
+
+    //场地列表
+    public function gameplace() {
+        $id = input('id', 0, 'intval'); //排位赛id
+        $area_id = input('area_id', 0, 'intval'); //区id
+        if (!$id || !$area_id) {
+            $this->error('参数缺失');
+        }
+
+        $where['game_id'] = $id;
+        $where['area_id'] = $area_id;
+        $where['status'] = 1;
+
+        $list = Db::name('game_place')->field('id, name, image')
+            ->where($where)->page($this->page, $this->pagenum)->order('id')->select();
+
+        $list = list_domain_image($list, ['image']);
+
+        $this->success('场地列表', $list);
+    }
+    
+    //报名比赛
+    public function signupgame() {
+        $id = input('id', 0, 'intval'); //排位赛id
+        $game_place_id = input('place_id', 0, 'intval'); //场地id
+
+        if (!$id || !$game_place_id) {
+            $this->error('参数缺失');
+        }
+        //比赛信息
+        $game_info = Db::name('game')->find($id);
+        if (!$game_info) {
+            $this->error('您的网络开小差了');
+        }
+        if ($game_info['status'] != 0 || $game_info['showstatus'] != 1) {
+            $this->error('当前比赛已不能报名');
+        }
+        if ($game_info['signupendtime'] < time()) {
+            $this->error('比赛已经截止报名');
+        }
+        //查询是否已报名
+        $game_people = Db::name('game_people')->where(['user_id' => $this->auth->id, 'game_id' => $id])->find();
+        if ($game_people) {
+            if ($game_people['status'] == 1) {
+                $this->error('您已经报名了');
+            }
+            if ($game_people['status'] == 2) {
+                $this->error('您正在申请退款,暂不能报名');
+            }
+        }
+
+        $data['user_id'] = $this->auth->id;
+        $data['game_id'] = $id;
+        $data['game_place_id'] = $game_place_id;
+        $data['price'] = $game_info['price'];
+        $data['starttime'] = $game_info['starttime'];
+        $data['endtime'] = $game_info['endtime'];
+        $data['num'] = $game_info['num'];
+        $data['status'] = 0;
+        $data['createtime'] = time();
+        $data['updatetime'] = time();
+
+        //开启事务
+        Db::startTrans();
+        //添加记录
+        if ($game_people) {
+            $rs = Db::name('game_people')->where(['id' => $game_people['id'], 'status' => $game_people['status']])->setField($data);
+        } else {
+            $rs = Db::name('game_people')->insertGetId($data);
+        }
+        if (!$rs) {
+            Db::rollback();
+            $this->error('您的网络开小差了');
+        }
+
+        //生成支付订单记录
+        $rechar_order['user_id'] = $this->auth->id;
+        $rechar_order['order_no'] = date('YmdHis', time()) . $this->auth->id . rand(10000000, 99999999); //微信订单编号
+        $rechar_order['money'] = $game_info['price'];
+        $rechar_order['purpose'] = 1; //充值用途:1=支付订单,2=充值,3=开通会员
+        $rechar_order['pay_type'] = 'wechat';
+        $rechar_order['relation_id'] = $game_people ? $game_people['id'] : $rs;
+        $rechar_order['createtime'] = time();
+
+        $result = Db::name('rechar_order')->insertGetId($rechar_order);
+        if (!$result) {
+            Db::rollback();
+            $this->error('网络延迟,请稍后再试');
+        }
+
+        Db::commit();
+
+        //构建支付链接数据
+        $wxData['body'] = '报名比赛支付';
+        $wxData['out_trade_no'] = $rechar_order['order_no'];
+        $wxData['total_fee'] = $game_info['price'];
+//            $wxData['total_fee'] = 0.01;
+        $wxData['openid'] = $this->auth->openid;
+
+//            require_once($_SERVER['DOCUMENT_ROOT'] . '/Plugins/Weixin/WxPay/WxPay.php');
+        $wxPay = new wxpay\WxPay(config('wxchatpay'));
+        $doResult = $wxPay->WxPayJs($wxData);
+
+        $this->success('微信支付参数返回成功', $doResult);
+    }
+    
 }

+ 8 - 95
application/api/controller/Notify.php

@@ -54,117 +54,30 @@ class Notify extends Api
                 //支付订单类型
                 if ($order_info['purpose'] == 1) {
                     //查询订单
-                    $active_order = Db::name('active_order')->find($order_info['relation_id']);
+                    $active_order = Db::name('game_people')->find($order_info['relation_id']);
                     //开启事务
                     Db::startTrans();
-                    //修改报名订单状态
-                    $active_order_rs = Db::name('active_order')->where(['id' => $order_info['relation_id'], 'status' => 0])->setField(['status' => 1, 'updatetime' => time(), 'transaction_id' => $_data['transaction_id']]);
-                    //修改报名人员信息状态
-                    $active_people_rs = Db::name('active_people')->where(['order_id' => $order_info['relation_id'], 'status' => 0])->setField(['status' => 1, 'updatetime' => time()]);
-                    //给上级发送优惠券
-                    $user_info = Db::name('user')->find($order_info['user_id']);
-                    //发放优惠券状态
-                    $invite_coupon_rs = true;
-                    if ($user_info['pre_user_id']) {
-                        //查询报名活动优惠券
-                        $invite_coupon = Db::name('coupon')->where(['purpose' => 5, 'status' => 1])->order('weigh desc, id desc')->find();
-                        if ($invite_coupon) {
-                            $invite_coupon_data = [
-                                'user_id' => $user_info['pre_user_id'],
-                                'coupon_id' => $invite_coupon['id'],
-                                'title' => $invite_coupon['title'],
-                                'desc' => $invite_coupon['desc'],
-                                'type' => $invite_coupon['type'],
-                                'money' => $invite_coupon['money'],
-                                'minmoney' => $invite_coupon['minmoney'],
-                                'purpose' => $invite_coupon['purpose'],
-                                'starttime' => time(),
-                                'endtime' => time() + $invite_coupon['effectiveday'] * 86400,
-                                'active_id' => $active_order['active_id'],
-                                'order_id' => $active_order['id'],
-                                'createtime' => time()
-                            ];
-
-                            $invite_coupon_rs = Db::name('user_coupon')->insertGetId($invite_coupon_data);
-                        }
-                    }
+                    //修改报名状态
+                    $active_order_rs = Db::name('game_people')->where(['id' => $order_info['relation_id'], 'status' => 0])->setField(['status' => 1, 'updatetime' => time()]);
+
                     //活动标题
-                    $active_title = Db::name('active')->where(['id' => $active_order['active_id']])->value('title');
+                    $active_title = Db::name('game')->where(['id' => $active_order['game_id']])->value('name');
                     //发送消息
                     $data = [
                         'user_id' => $order_info['user_id'],
                         'type' => 1,
-                        'title' => '活动通知',
-                        'content' => '您已成功报名' . $active_title . '活动',
+                        'title' => '比赛通知',
+                        'content' => '您已成功报名' . $active_title . '比赛',
                         'createtime' => time()
                     ];
                     $sys_rs = Db::name('sys_msg')->insertGetId($data);
-                    //增加成长值
-                    $paygrowth = (int)config('site.paygrowth'); //每消费1元赠送成长值数量, 1元=?成长值
-                    $balance = floor($paygrowth * $order_info['money']);
-                    $paygrowth_rs = 1;
-                    if ($balance > 0) {
-                        $paygrowth_rs = create_growth_log($balance, '微信支付活动订单', $order_info['user_id'], 3);
-                    }
 
-                    if ($active_order_rs && $active_people_rs && $invite_coupon_rs && $sys_rs && $paygrowth_rs == 1) {
+                    if ($active_order_rs && $sys_rs) {
                         Db::commit();
                     } else {
                         Db::rollback();
                         $_data['pay_status'] = 1; //回调状态: 1=支付订单回调失败,2=充值回调失败,3=开通会员回调失败
                     }
-                } elseif ($order_info['purpose'] == 2) {
-                    //充值
-                    //查询充值信息
-                    $recharge = Db::name('recharge')->find($order_info['relation_id']);
-                    //开启事务
-                    Db::startTrans();
-                    //增加用户余额
-                    $rs = create_log($recharge['price'], '充值', $order_info['user_id'], 1, $order_info['id']);
-                    //发放优惠券状态
-                    $invite_coupon_rs = true;
-                    if ($recharge['coupon_id'] && $recharge['couponnum'] > 0) {
-                        //查询报名活动优惠券
-                        $invite_coupon = Db::name('coupon')->where(['id' => $recharge['coupon_id'], 'purpose' => 0, 'status' => 1])->find();
-                        if ($invite_coupon) {
-                            $invite_coupon_data = [
-                                'user_id' => $order_info['user_id'],
-                                'coupon_id' => $invite_coupon['id'],
-                                'title' => $invite_coupon['title'],
-                                'desc' => $invite_coupon['desc'],
-                                'type' => $invite_coupon['type'],
-                                'money' => $invite_coupon['money'],
-                                'minmoney' => $invite_coupon['minmoney'],
-                                'purpose' => $invite_coupon['purpose'],
-                                'starttime' => time(),
-                                'endtime' => time() + $invite_coupon['effectiveday'] * 86400,
-                                'active_id' => 0,
-                                'order_id' => 0,
-                                'createtime' => time()
-                            ];
-
-                            for ($i=1; $i<=$recharge['couponnum']; $i++) {
-                                $invite_coupon_rs = Db::name('user_coupon')->insertGetId($invite_coupon_data);
-                                if (!$invite_coupon_rs) {
-                                    break;
-                                }
-                            }
-                        }
-                    }
-                    //增加成长值
-                    $paygrowth = (int)config('site.paygrowth'); //每消费1元赠送成长值数量, 1元=?成长值
-                    $balance = floor($paygrowth * $order_info['money']);
-                    $paygrowth_rs = 1;
-                    if ($balance > 0) {
-                        $paygrowth_rs = create_growth_log($balance, '充值', $order_info['user_id'], 2);
-                    }
-
-                    if ($rs == 1 && $invite_coupon_rs && $paygrowth_rs == 1) {
-                        Db::commit();
-                    } else {
-                        Db::rollback();
-                        $_data['pay_status'] = 2; //回调状态: 1=支付订单回调失败,2=充值回调失败,3=开通会员回调失败
-                    }
                 }
 
                 $PayResult->where($where)->setField($_data);