xiaogang il y a 4 ans
Parent
commit
285fd86e47

+ 1 - 1
app/Helper/function.php

xqd
@@ -23,7 +23,7 @@ function create_invite_code() {
 
 function create_order_number()
 {
-    return date('Ymd') . str_pad(mt_rand(1, 999999), 6, '0', STR_PAD_LEFT);
+    return date('YmdHis') . str_pad(mt_rand(1, 999999), 6, '0', STR_PAD_LEFT);
 }
 
 /**

+ 29 - 7
app/Http/Controllers/Api/PayNotifyController.php

xqd xqd xqd
@@ -4,8 +4,10 @@
 namespace App\Http\Controllers\Api;
 
 
+use App\Models\PaymentLogModel;
 use App\Services\PayService;
 use Illuminate\Support\Facades\Log;
+use PHPUnit\Util\Exception;
 use Yansongda\Pay\Pay;
 
 class PayNotifyController extends Controller
@@ -15,10 +17,16 @@ class PayNotifyController extends Controller
      */
     public function wx_notify(){
         $wxpay = Pay::wechat(PayService::wx_config());
-        $data = $wxpay->verify();
-        Log::info($data);
-
-       return $wxpay->success();
+        try{
+            $data = $wxpay->verify();
+            Log::info($data);
+            $order_no = $data->out_trade_no;
+            $this->order_do_sth($order_no);
+            Log::debug('Wechat notify', $data->all());
+        } catch (\Exception $e) {
+            Log::info($e->getMessage());
+        }
+        return $wxpay->success();
     }
 
     /**
@@ -26,15 +34,29 @@ class PayNotifyController extends Controller
      */
     public function ali_notify(){
         $alipay = Pay::alipay(PayService::ali_config());
-        $data = $alipay->verify();
-        Log::info($data);
+        try{
+            $data = $alipay->verify();
+            Log::info($data);
+            $order_no = $data->out_trade_no;
+            $this->order_do_sth($order_no);
+            Log::debug('Wechat notify', $data->all());
+        } catch (\Exception $e) {
+            Log::info($e->getMessage());
+        }
         return $alipay->success();
     }
 
     /**
      * 支付回调业务处理
      */
-    public function order_do_sth($order){
+    public function order_do_sth($order_no){
+        $order = PaymentLogModel::query()->where(['order_no'=>$order_no])->first();
+        if(!$order){
+            throw new Exception("订单不存在");
+        }
+        if($order['status']==1){
+            return true;
+        }
 
     }
 }

+ 3 - 0
app/Models/PaymentLogModel.php

xqd
@@ -4,8 +4,11 @@
 namespace App\Models;
 
 
+use Dcat\Admin\Traits\HasDateTimeFormatter;
+
 class PaymentLogModel extends BaseModel
 {
+    use HasDateTimeFormatter;
     protected $table = 'payment_log';
     protected $fillable = ['user_id', 'order_no','price','status','content','type','payment'];
 

+ 1 - 1
app/Services/UserService.php

xqd
@@ -60,7 +60,7 @@ class UserService
         $ins['content'] = json_encode($vip_info);
         $ins['type'] = 1;
         $ins['payment'] = $param['payment'];
-        if(!PaymentLogModel::query()->insertGetId($ins)){
+        if(!PaymentLogModel::query()->create($ins)){
             throw new Exception("插入订单失败");
         }