songdb 5 gadi atpakaļ
vecāks
revīzija
632af25382
1 mainītis faili ar 125 papildinājumiem un 4 dzēšanām
  1. 125 4
      app/Http/Controllers/Wap/Pay/OrdersController.php

+ 125 - 4
app/Http/Controllers/Wap/Pay/OrdersController.php

@@ -1330,13 +1330,134 @@ class OrdersController extends Controller
         echo "success";
     }
 
+    //平安银行支付回调
     function wcback_originbank(Request $request)
     {
-        Log::info('origin bank:'.json_encode($request->all()));
-        Log::info($request->method());
-        Log::info(file_get_contents('php://input'));
+        Log::info($request->all());
+        Log::info('wcback_palmpay_request');
+        try {
+            $data = $request->except('_url');
 
-        echo 'success';
+            //订单
+            $trade_no = $data['out_no'];
+            $order = OrderService::getByTradeNo($trade_no);
+            if (!$order) die('failed');
+
+            // 防止重复推送
+            if (isset($order->status) && $order->status == 'PAID') {
+                Log::info('has_pay:' . $trade_no);
+                echo 'success';
+                exit();
+            }
+
+            $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')->where('id', $order->pay_merchant_id)->first();
+
+            //校验签名
+//            $sign = _sign($data, json_decode($pay_merchant->config_info, 1)['appKey']);
+//            if ($sign != $data['sign']) die('failed');
+
+            $trade_result = json_decode($data['trade_result'],true);
+            $transaction_id = $trade_result['transaction_id'];
+
+            if ($data['status'] == 'success') {
+                Log::info('wcback_palmpay_notify_sign_success');
+                // 修改表比较多,开启事务
+                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);
+
+            }else {
+
+                Log::info('wcback_palmpay_notify_sign_fail');
+            }
+        } catch (\Exception $e) {
+            var_dump($e->getMessage());
+            DB::rollBack();
+            Log::info('receive_wcback_palmpay_ept:' . $e->getMessage());
+            echo 'fail';
+            Log::info('pay_callback_end error');
+            return;
+        }
+        Log::info('pay_callback_end');
+
+        echo "success";
     }
 
     /**