fly %!s(int64=5) %!d(string=hai) anos
pai
achega
bc617cbded
Modificáronse 1 ficheiros con 97 adicións e 93 borrados
  1. 97 93
      app/Http/Controllers/Wap/Pay/OrdersController.php

+ 97 - 93
app/Http/Controllers/Wap/Pay/OrdersController.php

@@ -1118,104 +1118,108 @@ class OrdersController extends Controller
         $data = $request->except('_url');
         $data = $request->except('_url');
         \Log::info('union_pay.notify: ');
         \Log::info('union_pay.notify: ');
         \Log::info($data);
         \Log::info($data);
-        if (isset($data['merOrderId'])) {
-            $trade_no = $data['merOrderId'];
-            if ($trade_no) {
-                $order = OrderService::getByTradeNo($trade_no);
-                $transaction_id = $data['targetOrderId'];
-                if ($order) {
-                    if (isset($order->status) && $order->status == 'PAID') {
-                        Log::info('has_pay:' . $order->trade_no);
-                        return 'SUCCESS';
-                    }
-                    $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')
-                        ->where('id', $order->pay_merchant_id)->where('is_enabled', 1)->first();
-                    $instance =  WechatPay::Union($pay_merchant->source, json_decode($pay_merchant->config_info, true));
-                    if ($instance->notify($data)) {
-                        // 修改表比较多,开启事务
-                        DB::beginTransaction();
-
-                        $uid = $order->uid;
-                        $distribution_channel_id = $order->distribution_channel_id;
-                        $product_id = $order->product_id;
-                        $product = ProductService::getProductSingle($product_id);
-                        $send_order_id = $order->send_order_id;
-                        $price = $product->price;
-                        Log::info('save_order_end');
-
-                        Log::info($product);
-
-                        Log::info('product_type:' . $product->type);
-                        $prize_fee = (int) (($product->price * 100) * 0.1);
-                        $this->substituteOrderPrice($order->id, $prize_fee);
-                        $this->smartPushTestBookPaidUv($order->from_bid, $order->uid, $order->price);
-                        //获取用户充值次数
-                        $order->pay_type = $this->getChargeTimes($order->uid);
-                        // 更新其他定制Order表
-                        if ($product->type == 'YEAR_ORDER') {
-                            Log::info('YEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDER');
-                            $order_type = 'YEAR';
-                            $this->yearOrder($uid, $distribution_channel_id, $price, $send_order_id);
-                            $order->order_type = $order_type;
-                            $order->status = 'PAID';
-                            $order->pay_end_at = date('Y-m-d H:i:s');
-                            $order->transaction_id = $transaction_id;
-                            $order->save();
-                        } elseif ($product->type == 'BOOK_ORDER') {
-                            Log::info('BOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDER');
-                            $order_type = 'BOOK';
-                            $this->bookOrder($product_id, $uid, $send_order_id, $price, $distribution_channel_id);
-                            $order->order_type = $order_type;
-                            $order->status = 'PAID';
-                            $order->pay_end_at = date('Y-m-d H:i:s');
-                            $order->transaction_id = $transaction_id;
-                            $order->save();
-                        } elseif ($product->type == 'TICKET_RECHARGE' || $product->type == 'NEW_USER') {
-                            Log::info('TICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGE');
-                            $order_type = 'RECHARGE';
-                            $this->userCharge($product, $uid);
-                            $order->order_type = $order_type;
-                            $order->status = 'PAID';
-                            $order->pay_end_at = date('Y-m-d H:i:s');
-                            $order->transaction_id = $transaction_id;
-                            $order->save();
-                        } elseif ($product->type == 'FOREVER') {
-                            Log::info('FOREVER------------------------FOREVER');
-                            $order_type = 'FOREVER';
-                            $this->foreverFreeOrder($uid, $distribution_channel_id, $price, $send_order_id);
-                            $order->order_type = $order_type;
-                            $order->status = 'PAID';
-                            $order->pay_end_at = date('Y-m-d H:i:s');
-                            $order->transaction_id = $transaction_id;
-                            $order->save();
+        try {
+            if (isset($data['merOrderId'])) {
+                $trade_no = $data['merOrderId'];
+                if ($trade_no) {
+                    $order = OrderService::getByTradeNo($trade_no);
+                    $transaction_id = $data['targetOrderId'];
+                    if ($order) {
+                        if (isset($order->status) && $order->status == 'PAID') {
+                            Log::info('has_pay:' . $order->trade_no);
+                            return 'SUCCESS';
                         }
                         }
-                        $this->successPayPushMsg($uid, $product, $order->id);
-                        $this->orderStatistical($order);
-                        DB::commit();
-                        //redis 删除未支付的uid
-                        try {
-                            $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
-                            Redis::hdel($key, $uid);
-                        } catch (\Exception $e) {
-                            Log::info('redis remote error-----------------------');
-                            Log::info($e);
+                        $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')
+                            ->where('id', $order->pay_merchant_id)->where('is_enabled', 1)->first();
+                        $instance =  WechatPay::Union($pay_merchant->source, json_decode($pay_merchant->config_info, true));
+                        if ($instance->notify($data)) {
+                            // 修改表比较多,开启事务
+                            DB::beginTransaction();
+
+                            $uid = $order->uid;
+                            $distribution_channel_id = $order->distribution_channel_id;
+                            $product_id = $order->product_id;
+                            $product = ProductService::getProductSingle($product_id);
+                            $send_order_id = $order->send_order_id;
+                            $price = $product->price;
+                            Log::info('save_order_end');
+
+                            Log::info($product);
+
+                            Log::info('product_type:' . $product->type);
+                            $prize_fee = (int) (($product->price * 100) * 0.1);
+                            $this->substituteOrderPrice($order->id, $prize_fee);
+                            $this->smartPushTestBookPaidUv($order->from_bid, $order->uid, $order->price);
+                            //获取用户充值次数
+                            $order->pay_type = $this->getChargeTimes($order->uid);
+                            // 更新其他定制Order表
+                            if ($product->type == 'YEAR_ORDER') {
+                                Log::info('YEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDER');
+                                $order_type = 'YEAR';
+                                $this->yearOrder($uid, $distribution_channel_id, $price, $send_order_id);
+                                $order->order_type = $order_type;
+                                $order->status = 'PAID';
+                                $order->pay_end_at = date('Y-m-d H:i:s');
+                                $order->transaction_id = $transaction_id;
+                                $order->save();
+                            } elseif ($product->type == 'BOOK_ORDER') {
+                                Log::info('BOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDER');
+                                $order_type = 'BOOK';
+                                $this->bookOrder($product_id, $uid, $send_order_id, $price, $distribution_channel_id);
+                                $order->order_type = $order_type;
+                                $order->status = 'PAID';
+                                $order->pay_end_at = date('Y-m-d H:i:s');
+                                $order->transaction_id = $transaction_id;
+                                $order->save();
+                            } elseif ($product->type == 'TICKET_RECHARGE' || $product->type == 'NEW_USER') {
+                                Log::info('TICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGE');
+                                $order_type = 'RECHARGE';
+                                $this->userCharge($product, $uid);
+                                $order->order_type = $order_type;
+                                $order->status = 'PAID';
+                                $order->pay_end_at = date('Y-m-d H:i:s');
+                                $order->transaction_id = $transaction_id;
+                                $order->save();
+                            } elseif ($product->type == 'FOREVER') {
+                                Log::info('FOREVER------------------------FOREVER');
+                                $order_type = 'FOREVER';
+                                $this->foreverFreeOrder($uid, $distribution_channel_id, $price, $send_order_id);
+                                $order->order_type = $order_type;
+                                $order->status = 'PAID';
+                                $order->pay_end_at = date('Y-m-d H:i:s');
+                                $order->transaction_id = $transaction_id;
+                                $order->save();
+                            }
+                            $this->successPayPushMsg($uid, $product, $order->id);
+                            $this->orderStatistical($order);
+                            DB::commit();
+                            //redis 删除未支付的uid
+                            try {
+                                $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
+                                Redis::hdel($key, $uid);
+                            } catch (\Exception $e) {
+                                Log::info('redis remote error-----------------------');
+                                Log::info($e);
+                            }
+
+                            // 注册动作-》回调订单
+                            $action_type = 'CallBackOrder';
+                            $param = [
+                                'order_sn' => isset($trade_no) ? $trade_no : '0',
+                                'openid' => isset($uid) ? $uid : '0', // 没有openid,用uid写log
+                            ];
+                            UserService::PushUserActionToQueue($action_type, $distribution_channel_id, $param);
+
+                            $this->userProperty($uid, $price, $product->type, $order->activity_id);
+                            //$this->huaweiActivity($order->activity_id,$uid,$product_id);
+                            //交换订单时间
+                            $this->exchangeUpdateAndCreated($order->id);
                         }
                         }
-
-                        // 注册动作-》回调订单
-                        $action_type = 'CallBackOrder';
-                        $param = [
-                            'order_sn' => isset($trade_no) ? $trade_no : '0',
-                            'openid' => isset($uid) ? $uid : '0', // 没有openid,用uid写log
-                        ];
-                        UserService::PushUserActionToQueue($action_type, $distribution_channel_id, $param);
-
-                        $this->userProperty($uid, $price, $product->type, $order->activity_id);
-                        //$this->huaweiActivity($order->activity_id,$uid,$product_id);
-                        //交换订单时间
-                        $this->exchangeUpdateAndCreated($order->id);
                     }
                     }
                 }
                 }
             }
             }
+        } catch (\Exception $e) {
+            \Log::error('union: ' . $e->getMessage());
         }
         }
     }
     }