WIN-2308041133\Administrator 1 year ago
parent
commit
77d128fd26
3 changed files with 42 additions and 45 deletions
  1. 19 44
      application/api/controller/Lave.php
  2. 1 0
      application/route.php
  3. 22 1
      extend/liuniu/WechatService.php

+ 19 - 44
application/api/controller/Lave.php

@@ -291,56 +291,31 @@ class Lave extends Api
             $where1['help_id']='0';
             $order = LaveModel::create($where1);
         }
-
-
+    }
+//    解除签约
+    public function deleteSign(Request $request){
+        var_dump(123);die();
         $where = UtilService::postMore(
             [
                 ['cid', $this->cid],
                 ['user_id', $this->auth->getUserinfo()['id']],
-                ['order_name', 'order_name'],
-                ['category_id', 0],
-                ['amount', 0],
-                ['name', ''],
-                ['contact', ''],
-                ['tel', 0],
-                ['address', ''],
-                ['is_open', '0'],
-                ['is_ticket', '0'],
-                ['type', '0'],
-                ['help_id', 0],
             ], $request
         );
-        $where1 = $where;
-        unset($where1['from']);
-        $where1['order_id'] = LaveModel::getNewOrderId();
-        if (cache('lave_' . $where['user_id'])) $this->error('正在处理中');
-        @file_put_contents("lave.txt", json_encode($where1));
-        $order = LaveModel::create($where1);
-        cache('lave_' . $where['user_id'], '1', 10);
-        if (!$order) $this->error(LaveModel::getErrorInfo());
-        $orderId = $order['order_id'];
-        $info = compact('orderId');
-        $order['plan_id'] = WechatPlan::where('price', $where['amount'])->value('plan_id');
-        if ($orderId) {
-            $orderInfo = LaveModel::where('order_id', $orderId)->find();
-            if (!$orderInfo || !isset($orderInfo['paid'])) $this->error('支付订单不存在!');
-            if ($orderInfo['paid']) $this->error('支付已支付!');
-            try {
-                if ($where['from'] == 'routine') {
-                    $jsConfig = LaveRepository::jsPaySign($this->cid, $orderId); //创建订单jspay
-                } else if ($where['from'] == 'weixinh5') {
-                    $jsConfig = LaveRepository::h5PaySign($this->cid, $orderId);
-                } else {
-                    $jsConfig = LaveRepository::wxPaySign($this->cid, $orderId);
-                }
-            } catch (\Exception $e) {
-                return $this->error($e->getMessage());
-            }
-            $info['jsConfig'] = $jsConfig;
-
-            return $this->success('订单创建成功', $info);
-
-        } else $this->error(LaveModel::getErrorInfo());
+        $sign_info=WechatPlanRecord::where('cid', $where['cid'])->where('uid', $where['user_id'])->where('is_signing',1)->find();
+        if (!$sign_info){
+            $this->error('未找到签约信息!');
+        }
+        $mch_id =Company::where('id', $where['cid'])->value('mch_id');
+        $plan_id=$sign_info['plan_id'];
+        $contract_code=$sign_info['contract_code'];
+//        $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']);
+        if ($rs){
+            WechatPlanRecord::where('cid', $where['cid'])->where('uid', $where['user_id'])->where('is_signing',0)->update(['is_signing'=>1]);
+            $this->success('解除签约成功!');
+        }else{
+            $this->error('解除签约失败!');
+        }
     }
 }
 

+ 1 - 0
application/route.php

@@ -80,6 +80,7 @@ Route::group('api', function () {
     Route::group('lave', function () {
         Route::post('create', 'api/lave/create');
         Route::post('create_sign', 'api/lave/createSign');  //支付签约
+        Route::post('delete_sign', 'api/lave/deleteSign');  //解除签约
         Route::get('ify', 'api/lave/ify');
         Route::get('lst', 'api/lave/lst');
         Route::get('mylst', 'api/lave/mylst');

+ 22 - 1
extend/liuniu/WechatService.php

@@ -555,5 +555,26 @@ class WechatService
         );
         return $result;
     }
-
+    /**
+     * 解除签约
+     * @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)
+    {
+        $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->delete(
+            $order
+        );
+        return $result;
+    }
 }