|
@@ -7,6 +7,10 @@ use App\dao\Pay\PayController;
|
|
|
use App\Facade\TableName;
|
|
use App\Facade\TableName;
|
|
|
use App\Http\helper\CreateOrder;
|
|
use App\Http\helper\CreateOrder;
|
|
|
use App\Http\helper\NumConfig;
|
|
use App\Http\helper\NumConfig;
|
|
|
|
|
+use App\Jobs\Order;
|
|
|
|
|
+use App\Notification\TelegramBot;
|
|
|
|
|
+use App\Services\OrderServices;
|
|
|
|
|
+use App\Services\PayConfig;
|
|
|
use App\Services\WiwiPay;
|
|
use App\Services\WiwiPay;
|
|
|
use App\Services\CreateLog;
|
|
use App\Services\CreateLog;
|
|
|
use App\Util;
|
|
use App\Util;
|
|
@@ -21,7 +25,7 @@ class WiwiPayLogic extends BaseApiLogic
|
|
|
$dao = new AccountPayInfo();
|
|
$dao = new AccountPayInfo();
|
|
|
[$userPhone, $userName, $userEmail] = $dao->payInfo($userId);
|
|
[$userPhone, $userName, $userEmail] = $dao->payInfo($userId);
|
|
|
|
|
|
|
|
- $pay_amount = (int)$pay_amount;
|
|
|
|
|
|
|
+// $pay_amount = (int)$pay_amount;
|
|
|
|
|
|
|
|
// 礼包类型验证
|
|
// 礼包类型验证
|
|
|
$PayVerify = new PayController();
|
|
$PayVerify = new PayController();
|
|
@@ -49,7 +53,7 @@ class WiwiPayLogic extends BaseApiLogic
|
|
|
$params = [
|
|
$params = [
|
|
|
"mchNo" => $service->mchNo,
|
|
"mchNo" => $service->mchNo,
|
|
|
"mchOrderNo" => $order_sn,
|
|
"mchOrderNo" => $order_sn,
|
|
|
- "amount" => 499,
|
|
|
|
|
|
|
+ "amount" => $amount,
|
|
|
"currency" => $config['currency'] ?? "usd",
|
|
"currency" => $config['currency'] ?? "usd",
|
|
|
"wayCode" => !empty($pay_method) ? $pay_method : ($config['wayCode'] ?? "cashapp"),
|
|
"wayCode" => !empty($pay_method) ? $pay_method : ($config['wayCode'] ?? "cashapp"),
|
|
|
"clientIp" => $buyIP,
|
|
"clientIp" => $buyIP,
|
|
@@ -108,13 +112,13 @@ class WiwiPayLogic extends BaseApiLogic
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$body = [
|
|
$body = [
|
|
|
- 'payment_sn' => $post['orderNo'] ?? $post['platformOrderNo'] ?? '',
|
|
|
|
|
|
|
+ 'payment_sn' => $post['orderNo'] ?? $post['channelOrderNo'] ?? '',
|
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
$apply_data = [
|
|
$apply_data = [
|
|
|
'order_id' => $order->id,
|
|
'order_id' => $order->id,
|
|
|
- 'payment_sn' => $post['orderNo'] ?? $post['platformOrderNo'] ?? '',
|
|
|
|
|
|
|
+ 'payment_sn' => $post['orderNo'] ?? $post['channelOrderNo'] ?? '',
|
|
|
'payment_code' => 'WiwiPay',
|
|
'payment_code' => 'WiwiPay',
|
|
|
'return' => \GuzzleHttp\json_encode($post),
|
|
'return' => \GuzzleHttp\json_encode($post),
|
|
|
'is_error' => 0,
|
|
'is_error' => 0,
|
|
@@ -122,31 +126,84 @@ class WiwiPayLogic extends BaseApiLogic
|
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
- $ordStatus = $post['status'] ?? $post['orderStatus'] ?? '';
|
|
|
|
|
|
|
+// 支付订单状态
|
|
|
|
|
+//0-订单生成
|
|
|
|
|
+//1-支付中
|
|
|
|
|
+//2-支付成功
|
|
|
|
|
+//3-支付失败
|
|
|
|
|
+//4-已撤销
|
|
|
|
|
+//5-已退款
|
|
|
|
|
+//6-订单关闭
|
|
|
|
|
+
|
|
|
|
|
+ $ordStatus = $post['state'] ??'';
|
|
|
$GiftsID = $order->GiftsID ?: '';
|
|
$GiftsID = $order->GiftsID ?: '';
|
|
|
$userID = $order->user_id ?: '';
|
|
$userID = $order->user_id ?: '';
|
|
|
$AdId = $order->AdId ?: '';
|
|
$AdId = $order->AdId ?: '';
|
|
|
$eventType = $order->eventType ?: '';
|
|
$eventType = $order->eventType ?: '';
|
|
|
- $payAmt = (int)($post['amount'] ?? $post['orderAmount'] ?? 0);
|
|
|
|
|
-
|
|
|
|
|
- // 订单成功状态判断(根据实际API调整)
|
|
|
|
|
- if ($ordStatus == 'SUCCESS' || $ordStatus == 2 || $ordStatus == 'PAID') {
|
|
|
|
|
- $body['pay_at'] = date('Y-m-d H:i:s');
|
|
|
|
|
- $body['finished_at'] = date('Y-m-d H:i:s');
|
|
|
|
|
- $body['status'] = 2;
|
|
|
|
|
|
|
+ $post['amount'] = $post['realAmount']??$post['amount'];
|
|
|
|
|
+ $payAmt = round(intval($post['amount'])/100,2);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ switch ($ordStatus) {
|
|
|
|
|
+ case 2: // 支付成功
|
|
|
|
|
+
|
|
|
|
|
+ $body['pay_status'] = 1;
|
|
|
|
|
+ $body['pay_at'] = date('Y-m-d H:i:s');
|
|
|
|
|
+ $body['finished_at'] = date('Y-m-d H:i:s');
|
|
|
|
|
+ $body['amount'] = $payAmt * NumConfig::NUM_VALUE;
|
|
|
|
|
+ $config = (new PayConfig())->getConfig('WiwiPay');
|
|
|
|
|
+ $body['payment_fee']=$body['amount']*$config['payin_fee'];
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 获取金额
|
|
|
|
|
+ $service = new OrderServices();
|
|
|
|
|
+
|
|
|
|
|
+ if ($order->amount != $body['amount']) {
|
|
|
|
|
+ $body['GiftsID'] = 0;
|
|
|
|
|
+ $body['amount'] = $payAmt * NumConfig::NUM_VALUE;
|
|
|
|
|
+ $Recharge = $payAmt;
|
|
|
|
|
+ $give = 0;
|
|
|
|
|
+ $favorable_price = $Recharge + $give;
|
|
|
|
|
+ $czReason = 1;
|
|
|
|
|
+ $cjReason = 45;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ [$give, $favorable_price, $Recharge, $czReason, $cjReason] = $service->getPayInfo($GiftsID, $userID, $payAmt);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 增加充值记录
|
|
|
|
|
+ [$Score] = $service->addRecord($userID, $payAmt, $favorable_price, $order_sn, $GiftsID, $Recharge, $czReason, $give, $cjReason, $AdId, $eventType);
|
|
|
|
|
+ // 成功处理回调
|
|
|
|
|
+ Order::dispatch([$userID, $payAmt, $Score, $favorable_price, $GiftsID, $order_sn]);
|
|
|
|
|
+
|
|
|
|
|
+ }catch (\Exception $exception) {
|
|
|
|
|
+ TelegramBot::getDefault()->sendProgramNotify("OrderService Except ",$exception->getMessage() );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 3: // 支付失败
|
|
|
|
|
+ $body['pay_status'] = 2;
|
|
|
|
|
+ $apply_data['is_error'] = 1;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- DB::connection('write')->table('agent.dbo.order')->where('id', $order->id)->update($body);
|
|
|
|
|
- DB::connection('write')->table('agent.dbo.apply_record')->insert($apply_data);
|
|
|
|
|
|
|
+ $order_up = DB::connection('write')->table('agent.dbo.order')
|
|
|
|
|
+ ->where('order_sn', $order_sn)
|
|
|
|
|
+ ->update($body);
|
|
|
|
|
|
|
|
- // 处理订单完成后的业务逻辑
|
|
|
|
|
- $logic = new OrderLogic();
|
|
|
|
|
- $logic->orderFinished($order->id, $order->order_sn, $GiftsID, $userID, $AdId, $eventType, $payAmt);
|
|
|
|
|
|
|
+ $apply = DB::connection('write')->table('agent.dbo.payment_apply')
|
|
|
|
|
+ ->insert($apply_data);
|
|
|
|
|
|
|
|
- return 'SUCCESS';
|
|
|
|
|
- } else {
|
|
|
|
|
- Util::WriteLog('WiwiPay', '订单状态异常:' . $ordStatus);
|
|
|
|
|
- return '{"success":false,"message":"订单状态异常"}';
|
|
|
|
|
|
|
+ if (($order_up && $apply) != true) {
|
|
|
|
|
+ Util::WriteLog('WiwiPay','订单更新失败');
|
|
|
|
|
+ return '{"success":false,"message":"商户自定义出错信息"}';
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ //Util::WriteLog('SitoBank','success');
|
|
|
|
|
+
|
|
|
|
|
+ return 'SUCCESS';
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
} catch (\Exception $exception) {
|
|
} catch (\Exception $exception) {
|
|
|
Util::WriteLog("WiwiPay_error", $exception->getMessage());
|
|
Util::WriteLog("WiwiPay_error", $exception->getMessage());
|
|
|
throw $exception;
|
|
throw $exception;
|