瀏覽代碼

改成线上和收款码并行

lizhen_gitee 2 年之前
父節點
當前提交
486fa9b7c3

+ 19 - 1
application/api/controller/Active.php

@@ -101,6 +101,7 @@ class Active extends Api
         Db::startTrans();
 
         //下单
+        $pay_type = $this->get_pay_type();
         $data = [
             'order_no' => createUniqueNo('A',$this->auth->id),
             'active_id' => $active_id,
@@ -110,6 +111,7 @@ class Active extends Api
             'pay_fee' => $info['pay_fee'],
             'status' => 0,
             'remark' => $remark,
+            'pay_type'=> $pay_type,
         ];
 
         $order_id = Db::name('order')->insertGetId($data);
@@ -119,9 +121,25 @@ class Active extends Api
         }
 
         Db::commit();
-        $this->success(1,$order_id);
+        $rs = [
+            'order_id'=>$order_id,
+            'pay_type'=>$pay_type,
+        ];
+        $this->success(1,$rs);
+
+    }
 
+    //1=微信线上,2=线下收款码
+    private function get_pay_type(){
+        $pay_type = rand(1,2);
+
+        //未开启微信支付,强制改
+        $wechat_switch = config('site.wechat_online_switch');
+        if($wechat_switch != 1){
+            $pay_type = 2;
+        }
 
+        return $pay_type;
     }
 
 

+ 31 - 3
application/api/controller/Order.php

@@ -20,9 +20,11 @@ class order extends Api
 
         $where = [
             'order.user_id'=>$this->auth->id,
-            'order.status' =>1,//已支付
+
         ];
 
+        $whereop = '(pay_type = 1 and status = 1) or (pay_type = 2)';
+
         if($active_status == 1){
             $where['active.activestarttime'] = ['gt',time()];
         }
@@ -36,8 +38,8 @@ class order extends Api
 
         $list = Db::name('order')->field('order.*,active.activestarttime,active.activeendtime,active.name,active.images')
             ->join('active','order.active_id = active.id','LEFT')
-            ->where($where)->order('order.id desc')->autopage()->select();
-        $list = list_domain_image($list,['images']);
+            ->where($where)->where($whereop)->order('order.id desc')->autopage()->select();
+        $list = list_domain_image($list,['images','offline_images']);
 
         if(!empty($list)){
             foreach($list as $key => &$item){
@@ -59,6 +61,13 @@ class order extends Api
 
                 $item['status_text'] = $status_text;
                 $item['active_status'] = $status;
+
+                //是否能传图
+                $item['can_upload'] = 0;
+                if($item['pay_type'] == 2 && $item['status'] == 0){
+                    //收款码支付,待支付的
+                    $item['can_upload'] = 1;
+                }
             }
         }
 
@@ -75,6 +84,7 @@ class order extends Api
             ->join('grade','us.grade_id = grade.id','LEFT')
             ->join('classes','us.classes_id = classes.id','LEFT')
             ->where('order.id',$id)->find();
+        $info = info_domain_image($info,['offline_images']);
 
 
         $status_text = '进行中';
@@ -92,9 +102,27 @@ class order extends Api
         $info['status_text'] = $status_text;
         $info['active_status'] = $status;
 
+        //是否能传图
+        $info['can_upload'] = 0;
+        if($info['pay_type'] == 2 && $info['status'] == 0){
+            //收款码支付,待支付的
+            $info['can_upload'] = 1;
+        }
+
         $this->success(1,$info);
     }
 
+    public function order_upload(){
+        $offline_images = input('offline_images','trim');
+        $id = input('id',0);
+
+        $data = ['offline_images' => $offline_images];
+        $info = Db::name('order')->where('id',$id)->upload($data);
+
+        $this->success('上传成功');
+
+    }
+
 
 
 

+ 12 - 2
application/api/controller/Pay.php

@@ -23,13 +23,24 @@ class Pay extends Api
         $orderid = input('orderid','0');
         $uid = $this->auth->id;
 
-        $orderinfo = Db::name('order')->where('id',$orderid)->where('user_id',$uid)->find();
+        $map = [
+            'id'       => $orderid,
+            'user_id'  => $uid,
+            'status'   => 0,
+            'pay_type' => 1,
+
+        ];
+        $orderinfo = Db::name('order')->where($map)->find();
+        if(empty($orderinfo)){
+            $this->error('请刷新重试');
+        }
 
         //创建订单
         $data['user_id'] = $uid;
         $data['out_trade_no'] = createUniqueNo('P',$uid); // 数据库订单号加密
         $data['order_amount'] = $orderinfo['pay_fee'];
         $data['createtime'] = time();
+
         $data['pay_type'] = $pay_type;
         $data['platform'] = $platform;
         $data['order_status'] = 0;
@@ -124,7 +135,6 @@ class Pay extends Api
         $update = [
             'status'=>1,
             'paytime'=>time(),
-            'pay_type'=>$orderInfo['pay_type'],
             'pay_out_trade_no'=>$out_trade_no,
         ];
         $rs_order = Db::name('order')->where('id',$orderInfo['table_id'])->update($update);

+ 1 - 0
application/extra/site.php

@@ -41,4 +41,5 @@ return array (
     'custom' => '自定义',
   ),
   'contactus' => '400123456',
+  'wechat_online_switch' => '1',
 );