WIN-2308041133\Administrator há 1 ano atrás
pai
commit
79fdb6cfed

+ 2 - 1
application/api/controller/Lave.php

@@ -333,10 +333,11 @@ class Lave extends Api
                     $where1['record_id']=$v['id'];
                     $where1['contract_code']=$v['contract_code'];
                     $where1['plan_id']=$v['plan_id'];
+                    $where1['nonce_str'] = uniqid();
 //                $where1['help_id']='0';
                     $order = LaveMonthModel::create($where1);
 //            }
-                    $rs = WechatService::papPayApply($mch_id,$where1['order_id'], $where1['amount'], "lave", '月捐款', 'PAP', [], $cid,$v['contract_id'],$where1['order_name']);
+                    $rs = WechatService::papPayApply($mch_id,$where1['order_id'], $where1['amount'], "lave", '月捐款', 'PAP', [], $cid,$v['contract_id'],$where1['order_name'],$where1['nonce_str']);
 
                 }
             }

+ 13 - 1
application/common/model/LaveMonth.php

@@ -161,5 +161,17 @@ class LaveMonth extends BaseModel
         $res = self::where('contract_code', $order_id)->where('cid', $cid)->where('paid',0)->update(['paid' => 1, 'paytime' => time(), "SN" => $SN]);//订单改为支付
         return false !== $res;
     }
-
+    public static function pappayapplySuccess($cid, $order_id)
+    {
+        $max_sn = self::where('cid', $cid)->order('SN DESC')->value('SN');
+        if ($max_sn) {
+            $no = intval(explode("_", $max_sn)[1]) + 1;
+        } else {
+            $no = 1;
+        }
+        $SN = $cid . "_" . str_pad($no, 8, '0', STR_PAD_LEFT);
+        $res = self::where('nonce_str', $order_id)->where('cid', $cid)->where('paid',0)->update(['paid' => 1, 'paytime' => time(), "SN" => $SN]);//订单改为支付
+        @file_put_contents("quanju.txt", $SN."-修改内容\r\n", 8);
+        return false !== $res;
+    }
 }

+ 16 - 3
extend/liuniu/WechatService.php

@@ -4,6 +4,7 @@ namespace liuniu;
 
 use app\admin\model\Company;
 use app\admin\model\WechatPlanRecord;
+use app\common\model\LaveMonth;
 use app\common\model\WechatContext;
 use EasyWeChat\Factory;
 use EasyWeChat\Kernel\Messages\Article;
@@ -378,6 +379,18 @@ class WechatService
                 $wechatContext = WechatContext::create($data, true);
                 return true;
             }
+
+            if (isset($notify['nonce_str'])) {
+                $cz = LaveMonth::Where(['contract_code' => $notify['nonce_str']])->find();
+                @file_put_contents("quanju.txt", json_encode($cz)."-随机字符搜索\r\n", 8);
+                if (!empty($cz)){
+                    $params = [$cid, $notify['nonce_str']];
+                    Hook::exec("\\liuniu\\repositories\\PaymentRepositories", "wechat" . ucfirst('MonthLavePay'), $params);
+                }
+                $data = ['eventkey' => 'notify', 'command' => '', 'refreshtime' => time(), 'openid' => $notify['openid'], 'message' => json_encode($notify)];
+                $wechatContext = WechatContext::create($data, true);
+                return true;
+            }
         });
         $response->send();
     }
@@ -569,12 +582,12 @@ class WechatService
      * @param array $options
      * @return Order
      */
-    public static function papPayApply($mch_id,$out_trade_no, $total_fee, $attach, $detail = '', $trade_type = 'PAP', $options = [], $cid = 0,$contract_id='',$body='月捐款')
+    public static function papPayApply($mch_id,$out_trade_no, $total_fee, $attach, $detail = '', $trade_type = 'PAP', $options = [], $cid = 0,$contract_id='',$body='月捐款',$nonce_str='')
     {
         $total_fee = bcmul($total_fee, 100, 0);
-        $order = array_merge(compact('mch_id','out_trade_no', 'total_fee', 'attach', 'detail', 'trade_type','contract_id','body'), $options);
+        $order = array_merge(compact('mch_id','out_trade_no', 'total_fee', 'attach', 'detail', 'trade_type','contract_id','body','nonce_str'), $options);
         if ($order['detail'] == '') unset($order['detail']);
-//        $order['notify_url']=Request::instance()->domain() . "/api/wechat/notify/" . $cid;
+        $order['notify_url']=Request::instance()->domain() . "/api/wechat/notify/" . $cid;
         $result = self::payment(false, $cid)->contract->apply(
             $order
         );

+ 15 - 0
extend/liuniu/repositories/PaymentRepositories.php

@@ -101,4 +101,19 @@ class PaymentRepositories
             return false;
         }
     }
+    /**
+     * 月捐款申请扣款
+     * @param string|null $order_id 订单id
+     * @return bool
+     */
+    public static function wechatMonthLavePay($event)
+    {
+        list($cid, $order_id) = $event;
+        try {
+            if (LaveMonth::where(['cid' => $cid, 'nonce_str' => $order_id, 'paid' => 1])->find()) return true;
+            return LaveMonth::pappayapplySuccess($cid, $order_id);
+        } catch (\Exception $e) {
+            return false;
+        }
+    }
 }