WIN-2308041133\Administrator 1 місяць тому
батько
коміт
38602aa947
1 змінених файлів з 76 додано та 68 видалено
  1. 76 68
      application/api/controller/Lave.php

+ 76 - 68
application/api/controller/Lave.php

@@ -177,19 +177,19 @@ class Lave extends Api
 //        if (empty($contract_display_account)){
 //            $this->error('用户不存在!');
 //        }
-        if ($where['amount']>500){
+        if ($where['amount'] > 500) {
             $this->error('捐款金额不能大于500');
         }
-        $sign=WechatPlanRecord::where('uid', $where1['user_id'])->where('plan_id', $where1['plan_id'])->where('is_signing',0)->find();
-        if (!empty($sign)){
+        $sign = WechatPlanRecord::where('uid', $where1['user_id'])->where('plan_id', $where1['plan_id'])->where('is_signing', 0)->find();
+        if (!empty($sign)) {
             $this->error('您已签约,请勿重复签约!');
         }
         if (cache('lave_' . $where['user_id'])) $this->error('正在处理中');
-        $plan_id=$where1['plan_id'];
+        $plan_id = $where1['plan_id'];
 //        unset($where1['plan_id']);
         $where1['contract_code'] = WechatPlanRecord::getNewCode();
         $order = LaveMonthModel::create($where1);
-        $where1['contract_display_account']=$where1['name'];
+        $where1['contract_display_account'] = $where1['name'];
         cache('lave_' . $where['user_id'], '1', 10);
         if (!$order) $this->error(LaveMonthModel::getErrorInfo());
         $orderId = $order['order_id'];
@@ -197,37 +197,37 @@ class Lave extends Api
         $order['plan_id'] = $plan_id;
         if ($orderId) {
             $orderInfo = LaveMonthModel::where('order_id', $orderId)->find();
-            if (!$orderInfo || !isset($orderInfo['paid'])){
+            if (!$orderInfo || !isset($orderInfo['paid'])) {
                 $this->error('支付订单不存在!');
             }
             if ($orderInfo['paid']) $this->error('支付已支付!');
 //          创建签约
-            $plan_record=[
-                'plan_id'=>$plan_id,
-                'cid'=>$where['cid'],
-                'uid'=>$where['user_id'],
-                'price'=>$where['amount'],
-                'is_signing'=>2,
-                'contract_code'=>$where1['contract_code'],
-                'contract_display_account'=>$where1['contract_display_account'],
-                'is_open'=>$where1['is_open'],
-                'tel'=>$where1['tel'],
+            $plan_record = [
+                'plan_id' => $plan_id,
+                'cid' => $where['cid'],
+                'uid' => $where['user_id'],
+                'price' => $where['amount'],
+                'is_signing' => 2,
+                'contract_code' => $where1['contract_code'],
+                'contract_display_account' => $where1['contract_display_account'],
+                'is_open' => $where1['is_open'],
+                'tel' => $where1['tel'],
 //                'category_id'=>$where1['category_id'],
-                'order_name'=>$where1['order_name'],
+                'order_name' => $where1['order_name'],
             ];
-            $count=WechatPlanRecord::where('uid', $where1['user_id'])->where('plan_id',$plan_id)->count();
-            $record=WechatPlanRecord::create($plan_record);
-            @file_put_contents("quanju.txt", json_encode($record)."-签约模版记录\r\n", 8);
+            $count = WechatPlanRecord::where('uid', $where1['user_id'])->where('plan_id', $plan_id)->count();
+            $record = WechatPlanRecord::create($plan_record);
+            @file_put_contents("quanju.txt", json_encode($record) . "-签约模版记录\r\n", 8);
             LaveMonthModel::where('order_id', $orderId)->update(['record_id' => $record['id']]);
-            $plan_record['spbill_create_ip']=User::where('id', $where1['user_id'])->value('loginip');
-            $plan_record['contract_notify_url']=Request::instance()->domain() . "/api/wechat/notify/" . $where['cid'];
+            $plan_record['spbill_create_ip'] = User::where('id', $where1['user_id'])->value('loginip');
+            $plan_record['contract_notify_url'] = Request::instance()->domain() . "/api/wechat/notify/" . $where['cid'];
             try {
                 if ($where['from'] == 'routine') {
-                    $jsConfig = LaveRepository::jsPaySign($this->cid, $orderId,$plan_record); //创建订单jspay
+                    $jsConfig = LaveRepository::jsPaySign($this->cid, $orderId, $plan_record); //创建订单jspay
                 } else if ($where['from'] == 'weixinh5') {
-                    $jsConfig = LaveRepository::h5PaySign($this->cid, $orderId,$plan_record);
+                    $jsConfig = LaveRepository::h5PaySign($this->cid, $orderId, $plan_record);
                 } else {
-                    $jsConfig = LaveRepository::wxPaySign($this->cid, $orderId,$plan_record);
+                    $jsConfig = LaveRepository::wxPaySign($this->cid, $orderId, $plan_record);
                 }
             } catch (\Exception $e) {
                 return $this->error($e->getMessage());
@@ -236,71 +236,73 @@ class Lave extends Api
 //            增加参与人数
 
 //            @file_put_contents("quanju.txt", $count."-参与次数\r\n", 8);
-            if ($count==0){
-                $num=WechatPlan::where('plan_id', $plan_id)->value('num');
+            if ($count == 0) {
+                $num = WechatPlan::where('plan_id', $plan_id)->value('num');
 //                @file_put_contents("quanju.txt", $num."-参与人数\r\n", 8);
-                WechatPlan::where('plan_id', $plan_id)->update(['num' => $num+1]);
+                WechatPlan::where('plan_id', $plan_id)->update(['num' => $num + 1]);
             }
             return $this->success('订单创建成功', $info);
 
         } else $this->error(LaveMonthModel::getErrorInfo());
     }
+
     //    申请扣款
     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;
 //        $arr=[];
 //        $arr['body']='月捐款';
         foreach ($list as $k => $v) {
             $day = intval(date('d', $v['createtime']));
             $date = date('Y-m', $v['createtime']);
-            $last=intval(date("t", time())); //当月最后一天
+            $last = intval(date("t", time())); //当月最后一天
 //            @file_put_contents("quanju.txt", $day."-日期\r\n", 8);
             $today = intval(date('d'));
             $now_date = date('Y-m', time());
-            $tf=false;
-            if($day==1&&$today==$last){ //签约时间是第一天,且今天是这个月的最后一天
-                $tf=true;
+            $tf = false;
+            if ($day == 1 && $today == $last) { //签约时间是第一天,且今天是这个月的最后一天
+                $tf = true;
             }
-            if ($day-1>$last&&$today==$last){  //签约时间的前一天日期依然比这个月的最后一天大,且今天是这个月的最后一天
-                $tf=true;
+            if ($day - 1 > $last && $today == $last) {  //签约时间的前一天日期依然比这个月的最后一天大,且今天是这个月的最后一天
+                $tf = true;
             }
             if ($date != $now_date) {  //先确定月份不同
 
-                if ($today == $day-1||$tf) { //再确定是不是今天是不是签约日期的前一天
+                if ($today == $day - 1 || $tf) { //再确定是不是今天是不是签约日期的前一天
 //                 var_dump(789456132);die();
-                    $cid=$v['cid'];
-                    $mch_id =Company::where('id',$cid)->value('pay_weixin_mchid');
-                    $where1['cid']=$cid;
-                    $where1['user_id']=$v['uid'];
-                    $where1['order_name']=$v['order_name'];
-                    $where1['order_id']=LaveMonthModel::getNewOrderId();;
+                    if ($v['uid'] == 8318) {
+                        $cid = $v['cid'];
+                        $mch_id = Company::where('id', $cid)->value('pay_weixin_mchid');
+                        $where1['cid'] = $cid;
+                        $where1['user_id'] = $v['uid'];
+                        $where1['order_name'] = $v['order_name'];
+                        $where1['order_id'] = LaveMonthModel::getNewOrderId();;
 
 //                $where1['category_id']=$v['category_id'];
-                    $where1['amount']=$v['price'];
-                    $where1['name']=$v['contract_display_account'];
-                    $where1['contact']='';
-                    $where1['tel']=$v['tel'];
-                    $where1['address']='用户未填写联系地址';
-                    $where1['is_open']=$v['is_open'];
-                    $where1['is_ticket']='0';
-                    $where1['type']='0';
-                    $where1['record_id']=$v['id'];
-                    $where1['contract_code']=$v['contract_code'];
-                    $where1['plan_id']=$v['plan_id'];
+                        $where1['amount'] = $v['price'];
+                        $where1['name'] = $v['contract_display_account'];
+                        $where1['contact'] = '';
+                        $where1['tel'] = $v['tel'];
+                        $where1['address'] = '用户未填写联系地址';
+                        $where1['is_open'] = $v['is_open'];
+                        $where1['is_ticket'] = '0';
+                        $where1['type'] = '0';
+                        $where1['record_id'] = $v['id'];
+                        $where1['contract_code'] = $v['contract_code'];
+                        $where1['plan_id'] = $v['plan_id'];
 
-                    $where1['nonce_str'] = uniqid();
+                        $where1['nonce_str'] = uniqid();
 //                $where1['help_id']='0';
 //                    @file_put_contents("quanju.txt", json_encode($where1)."测试申请扣款-\r\n", 8);
-                    $order = LaveMonthModel::create($where1);
+                        $order = LaveMonthModel::create($where1);
 //            }
 //                    var_dump(988745613);die();
-                    $rs = WechatService::papPayApply($mch_id,$where1['order_id'], $where1['amount'], "lave", '月捐款', 'PAP', [], $cid,$v['contract_id'],$where1['order_name'],$where1['nonce_str']);
-
+                        $rs = WechatService::papPayApply($mch_id, $where1['order_id'], $where1['amount'], "lave", '月捐款', 'PAP', [], $cid, $v['contract_id'], $where1['order_name'], $where1['nonce_str']);
+                    }
                 }
             }
         }
@@ -308,29 +310,31 @@ class Lave extends Api
 
 //        }
     }
+
 //    解除签约
-    public function deleteSign(Request $request){
+    public function deleteSign(Request $request)
+    {
         $where = UtilService::postMore(
             [
-                ['id',0],
+                ['id', 0],
                 ['cid', $this->cid],
                 ['user_id', $this->auth->getUserinfo()['id']],
             ], $request
         );
-        if ($where['id']==0){
-            $sign_info=WechatPlanRecord::where('cid', $where['cid'])->where('uid', $where['user_id'])->where('is_signing',0)->find();
-        }else{
-            $sign_info=WechatPlanRecord::where('id', $where['id'])->where('is_signing',0)->find();
+        if ($where['id'] == 0) {
+            $sign_info = WechatPlanRecord::where('cid', $where['cid'])->where('uid', $where['user_id'])->where('is_signing', 0)->find();
+        } else {
+            $sign_info = WechatPlanRecord::where('id', $where['id'])->where('is_signing', 0)->find();
         }
 
-        if (!$sign_info){
+        if (!$sign_info) {
             $this->error('未找到签约信息!');
         }
-        $mch_id =Company::where('id', $where['cid'])->value('pay_weixin_mchid');
-        $plan_id=$sign_info['plan_id'];
-        $contract_code=$sign_info['contract_code'];
+        $mch_id = Company::where('id', $where['cid'])->value('pay_weixin_mchid');
+        $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']);
+        $rs = WechatService::deleteSign($mch_id, $contract_code, $plan_id, '1.0', [], $where['cid']);
 //        @file_put_contents("quanju.txt", json_encode($rs)."-解除签约返回结果\r\n", 8);
         $this->success('解除签约成功!');
 //        if ($rs){
@@ -340,6 +344,7 @@ class Lave extends Api
 //            $this->error('解除签约失败!');
 //        }
     }
+
     public function plan_lst(Request $request)
     {
         $where = UtilService::getMore(
@@ -355,6 +360,7 @@ class Lave extends Api
         );
         $this->success('获取成功', WechatPlan::lst($where));
     }
+
     public function plan_read(Request $request)
     {
         $where = UtilService::getMore(
@@ -365,6 +371,7 @@ class Lave extends Api
         );
         $this->success('获取成功', WechatPlan::read($where));
     }
+
 //    签约列表
     public function user_plan_lst(Request $request)
     {
@@ -380,6 +387,7 @@ class Lave extends Api
         if (!isset($where['cid'])) $this->error('请选择正确的城市的红十字会');
         $this->success('获取成功', WechatPlanRecord::record_lst($where));
     }
+
 //    签约记录详情
     public function user_record_info(Request $request)
     {