WIN-2308041133\Administrator há 1 ano atrás
pai
commit
09fe21c3d2

+ 53 - 20
application/api/controller/Lave.php

@@ -260,6 +260,8 @@ class Lave extends Api
     //    申请扣款
     //    申请扣款
     public function payPap(Request $request)
     public function payPap(Request $request)
     {
     {
+        @file_put_contents("quanju.txt", "测试申请扣款-\r\n", 8);
+        die();
         $list=WechatPlanRecord::where('is_signing',0)->select();
         $list=WechatPlanRecord::where('is_signing',0)->select();
         $cid=$this->cid;
         $cid=$this->cid;
 
 
@@ -269,32 +271,33 @@ class Lave extends Api
 
 
         foreach ($list as $k => $v){
         foreach ($list as $k => $v){
             $cid=$v['cid'];
             $cid=$v['cid'];
-            $arr['mch_id'] =Company::where('id', $cid)->value('mch_id');
-            $arr['out_trade_no']=LaveModel::getNewOrderId();
-            $arr['total_fee'] = $v['price'];
+            if ($this->querySign($cid,$v['uid'],$v['plan_id'],$v['contract_code'])){
+                $arr['mch_id'] =Company::where('id', $cid)->value('mch_id');
+                $arr['out_trade_no']=LaveModel::getNewOrderId();
+                $arr['total_fee'] = $v['price'];
 //            $arr['trade_type'] = 'PAP';
 //            $arr['trade_type'] = 'PAP';
-            $arr['contract_id'] = Company::where('id', $cid)->value('contract_id');
+                $arr['contract_id'] = Company::where('id', $cid)->value('contract_id');
 //            $rs = WechatService::paymentOrder($openid, $orderInfo['order_id'], $orderInfo['amount'], "lave", $orderInfo['order_name'], '', 'JSAPI', [], $cid);
 //            $rs = WechatService::paymentOrder($openid, $orderInfo['order_id'], $orderInfo['amount'], "lave", $orderInfo['order_name'], '', 'JSAPI', [], $cid);
-            $rs = WechatService::papPayApply($arr['out_trade_no'], $arr['total_fee'], "lave", '月捐款', 'PAP', [], $cid,$arr['mch_id'],$arr['contract_id']);
-            $where1['cid']=$cid;
-            $where1['user_id']=$this->auth->getUserinfo()['id'];
-            $where1['order_name']='月捐款';
-            $where1['category_id']=81;
-            $where1['amount']=$arr['total_fee'];
-            $where1['name']=$this->auth->getUserinfo()['username'];
-            $where1['contact']='';
-            $where1['tel']=$this->auth->getUserinfo()['mobile'];
-            $where1['address']='用户未填写联系地址';
-            $where1['is_open']=$v['is_open'];
-            $where1['is_ticket']='0';
-            $where1['type']='0';
-            $where1['help_id']='0';
-            $order = LaveModel::create($where1);
+                $rs = WechatService::papPayApply($arr['out_trade_no'], $arr['total_fee'], "lave", '月捐款', 'PAP', [], $cid,$arr['mch_id'],$arr['contract_id']);
+                $where1['cid']=$cid;
+                $where1['user_id']=$this->auth->getUserinfo()['id'];
+                $where1['order_name']='月捐款';
+                $where1['category_id']=81;
+                $where1['amount']=$arr['total_fee'];
+                $where1['name']=$this->auth->getUserinfo()['username'];
+                $where1['contact']='';
+                $where1['tel']=$this->auth->getUserinfo()['mobile'];
+                $where1['address']='用户未填写联系地址';
+                $where1['is_open']=$v['is_open'];
+                $where1['is_ticket']='0';
+                $where1['type']='0';
+                $where1['help_id']='0';
+                $order = LaveModel::create($where1);
+            }
         }
         }
     }
     }
 //    解除签约
 //    解除签约
     public function deleteSign(Request $request){
     public function deleteSign(Request $request){
-        var_dump(123);die();
         $where = UtilService::postMore(
         $where = UtilService::postMore(
             [
             [
                 ['cid', $this->cid],
                 ['cid', $this->cid],
@@ -310,6 +313,7 @@ class Lave extends Api
         $contract_code=$sign_info['contract_code'];
         $contract_code=$sign_info['contract_code'];
 //        $mch_id,$contract_code,$pan_id,$version='1.0',$options=[],$cid=0)
 //        $mch_id,$contract_code,$pan_id,$version='1.0',$options=[],$cid=0)
         $rs=WechatService::deleteSign($mch_id,$contract_code,$plan_id,'1.0',[],$where['cid']);
         $rs=WechatService::deleteSign($mch_id,$contract_code,$plan_id,'1.0',[],$where['cid']);
+        @file_put_contents("quanju.txt", json_encode($rs)."-解除签约返回结果\r\n", 8);
         if ($rs){
         if ($rs){
             WechatPlanRecord::where('cid', $where['cid'])->where('uid', $where['user_id'])->where('is_signing',0)->update(['is_signing'=>1]);
             WechatPlanRecord::where('cid', $where['cid'])->where('uid', $where['user_id'])->where('is_signing',0)->update(['is_signing'=>1]);
             $this->success('解除签约成功!');
             $this->success('解除签约成功!');
@@ -317,6 +321,35 @@ class Lave extends Api
             $this->error('解除签约失败!');
             $this->error('解除签约失败!');
         }
         }
     }
     }
+//    查询签约状态
+    public function querySign(int $cid,int $uid,int $plan_id,string $contract_code)
+    {
+//        $where = UtilService::postMore(
+//            [
+//                ['cid', $this->cid],
+//                ['user_id', $this->auth->getUserinfo()['id']],
+//            ], $request
+//        );
+        $sign_info = WechatPlanRecord::where('cid', $cid)->where('uid', $uid)->where('is_signing', 1)->find();
+        if (!$sign_info) {
+            $this->error('未找到签约信息!');
+        }
+        $mch_id = Company::where('id', $cid)->value('mch_id');
+//        $plan_id = $sign_info['plan_id'];
+//        $contract_code = $sign_info['contract_code'];
+        $rs = WechatService::querySign($mch_id, $contract_code, $plan_id);
+        @file_put_contents("quanju.txt", json_encode($rs) . "-查询签约状态返回结果\r\n", 8);
+        if ($rs['return_code'] == 'SUCCESS') {
+            if ($rs['contract_state'] == 1) {
+                WechatPlanRecord::where('cid',$cid)->where('uid', $uid)->where('is_signing', 1)->update(['is_signing' => 0]);
+                return false;
+            }else{
+                return true;
+            }
+        } else {
+            $this->error('查询签约状态失败!');
+        }
+    }
 }
 }
 
 
 ?>
 ?>

+ 1 - 1
application/route.php

@@ -85,7 +85,7 @@ Route::group('api', function () {
         Route::get('lst', 'api/lave/lst');
         Route::get('lst', 'api/lave/lst');
         Route::get('mylst', 'api/lave/mylst');
         Route::get('mylst', 'api/lave/mylst');
         Route::get('pay', 'api/lave/pay');
         Route::get('pay', 'api/lave/pay');
-        Route::get('pay_sign', 'api/lave/paySign');
+        Route::get('pay_sign', 'api/lave/paySign');  //申请扣款
     });
     });
     //帮扶
     //帮扶
     Route::group('help', function () {
     Route::group('help', function () {

+ 13 - 9
extend/liuniu/WechatService.php

@@ -557,15 +557,6 @@ class WechatService
     }
     }
     /**
     /**
      * 解除签约
      * 解除签约
-     * @param $openid
-     * @param $out_trade_no
-     * @param $total_fee
-     * @param $attach
-     * @param $body
-     * @param string $detail
-     * @param string $trade_type
-     * @param array $options
-     * @return Order
      */
      */
     public static function deleteSign($mch_id,$contract_code,$pan_id,$version='1.0',$options=[],$cid=0)
     public static function deleteSign($mch_id,$contract_code,$pan_id,$version='1.0',$options=[],$cid=0)
     {
     {
@@ -577,4 +568,17 @@ class WechatService
         );
         );
         return $result;
         return $result;
     }
     }
+    /**
+     * 查询签约
+     */
+    public static function querySign($mch_id,$contract_code,$pan_id,$version='1.0',$options=[],$cid=0)
+    {
+        $order = array_merge(compact('mch_id','contract_code','pan_id','version'), $options);
+        if ($order['detail'] == '') unset($order['detail']);
+//        $order['notify_url']=Request::instance()->domain() . "/api/wechat/notify/" . $cid;
+        $result = self::payment(false, $cid)->contract->query(
+            $order
+        );
+        return $result;
+    }
 }
 }