优化页面翻译,优化统一订单页面审核操作
This commit is contained in:
@@ -4,6 +4,7 @@ namespace app\admin\controller\mall;
|
||||
|
||||
use Throwable;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\MallBonusGrantPush;
|
||||
use app\common\model\MallOrder;
|
||||
use app\common\model\MallUserAsset;
|
||||
use support\think\Db;
|
||||
@@ -251,7 +252,7 @@ class Order extends Backend
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动重试(仅红利推送失败可重试)
|
||||
* 手动推送红利(同步调用 PlayX,不限制自动重试次数;成功则 ACCEPTED,失败写入 fail_reason)
|
||||
*/
|
||||
public function retry(Request $request): Response
|
||||
{
|
||||
@@ -276,17 +277,42 @@ class Order extends Backend
|
||||
if ($order->type !== MallOrder::TYPE_BONUS) {
|
||||
return $this->error(__('Only BONUS can retry'));
|
||||
}
|
||||
if ($order->grant_status !== MallOrder::GRANT_FAILED_RETRYABLE) {
|
||||
return $this->error(__('Only FAILED_RETRYABLE can retry'));
|
||||
}
|
||||
if (($order->retry_count ?? 0) >= 3) {
|
||||
return $this->error(__('Retry count exceeded'));
|
||||
if ($order->status !== MallOrder::STATUS_PENDING) {
|
||||
return $this->error(__('Order status must be PENDING'));
|
||||
}
|
||||
|
||||
$order->grant_status = MallOrder::GRANT_NOT_SENT;
|
||||
$allowedStatuses = [
|
||||
MallOrder::GRANT_NOT_SENT,
|
||||
MallOrder::GRANT_SENT_PENDING,
|
||||
MallOrder::GRANT_FAILED_RETRYABLE,
|
||||
MallOrder::GRANT_FAILED_FINAL,
|
||||
];
|
||||
if (!in_array($order->grant_status, $allowedStatuses, true)) {
|
||||
return $this->error(__('Current grant status cannot be manually pushed'));
|
||||
}
|
||||
|
||||
if (strval(config('playx.api.base_url', '')) === '') {
|
||||
return $this->error(__('PlayX API not configured'));
|
||||
}
|
||||
|
||||
$result = MallBonusGrantPush::push($order);
|
||||
if ($result['ok']) {
|
||||
$order->grant_status = MallOrder::GRANT_ACCEPTED;
|
||||
$order->playx_transaction_id = $result['playx_transaction_id'];
|
||||
$order->fail_reason = null;
|
||||
$order->update_time = time();
|
||||
$order->save();
|
||||
|
||||
return $this->success(__('Push succeeded'));
|
||||
}
|
||||
|
||||
$failReason = __('Manual push failed') . ': ' . $result['message'];
|
||||
$order->fail_reason = $failReason;
|
||||
$order->grant_status = MallOrder::GRANT_FAILED_FINAL;
|
||||
$order->update_time = time();
|
||||
$order->save();
|
||||
|
||||
return $this->success(__('Retry queued'));
|
||||
return $this->error($failReason);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,4 +95,9 @@ return [
|
||||
'%d records and files have been deleted' => '%d records and files have been deleted',
|
||||
'Please input correct username' => 'Please enter the correct username',
|
||||
'Group Name Arr' => 'Group Name Arr',
|
||||
'Push succeeded' => 'Push succeeded',
|
||||
'Manual push failed' => 'Manual push failed',
|
||||
'PlayX API not configured' => 'PlayX API not configured',
|
||||
'Current grant status cannot be manually pushed' => 'Current grant status cannot be manually pushed',
|
||||
'Order status must be PENDING' => 'Order status must be PENDING',
|
||||
];
|
||||
@@ -114,4 +114,9 @@ return [
|
||||
'%d records and files have been deleted' => '已删除%d条记录和文件',
|
||||
'Please input correct username' => '请输入正确的用户名',
|
||||
'Group Name Arr' => '分组名称数组',
|
||||
'Push succeeded' => '推送成功',
|
||||
'Manual push failed' => '手动推送失败',
|
||||
'PlayX API not configured' => 'PlayX 接口未配置',
|
||||
'Current grant status cannot be manually pushed' => '当前发放状态不可手动推送',
|
||||
'Order status must be PENDING' => '订单状态须为处理中',
|
||||
];
|
||||
85
app/common/library/MallBonusGrantPush.php
Normal file
85
app/common/library/MallBonusGrantPush.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\library;
|
||||
|
||||
use app\common\model\MallItem;
|
||||
use app\common\model\MallOrder;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
/**
|
||||
* 红利订单调用 PlayX bonus/grant(与定时任务、后台手动推送共用)
|
||||
*/
|
||||
final class MallBonusGrantPush
|
||||
{
|
||||
/**
|
||||
* @return array{ok: bool, message: string, playx_transaction_id: string}
|
||||
*/
|
||||
public static function push(MallOrder $order): array
|
||||
{
|
||||
$baseUrl = rtrim(strval(config('playx.api.base_url', '')), '/');
|
||||
if ($baseUrl === '') {
|
||||
return [
|
||||
'ok' => false,
|
||||
'message' => 'PlayX base_url not configured',
|
||||
'playx_transaction_id' => '',
|
||||
];
|
||||
}
|
||||
|
||||
$path = strval(config('playx.api.bonus_grant_url', '/api/v1/bonus/grant'));
|
||||
$url = $baseUrl . $path;
|
||||
|
||||
$item = MallItem::where('id', $order->mall_item_id)->find();
|
||||
$rewardName = $item ? strval($item->title) : '';
|
||||
$category = $item ? strval($item->category) : 'daily';
|
||||
$categoryTitle = $item ? strval($item->category_title) : '';
|
||||
$multiplier = intval($order->multiplier ?? 0);
|
||||
if ($multiplier <= 0) {
|
||||
$multiplier = 1;
|
||||
}
|
||||
|
||||
$client = new Client([
|
||||
'timeout' => 20,
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
$requestId = 'mall_bonus_' . uniqid();
|
||||
|
||||
try {
|
||||
$res = $client->post($url, [
|
||||
'json' => [
|
||||
'request_id' => $requestId,
|
||||
'externalTransactionId' => $order->external_transaction_id,
|
||||
'user_id' => $order->user_id,
|
||||
'amount' => $order->amount,
|
||||
'rewardName' => $rewardName,
|
||||
'category' => $category,
|
||||
'categoryTitle' => $categoryTitle,
|
||||
'multiplier' => $multiplier,
|
||||
],
|
||||
]);
|
||||
|
||||
$data = json_decode(strval($res->getBody()), true) ?? [];
|
||||
if ($res->getStatusCode() === 200 && ($data['status'] ?? '') === 'accepted') {
|
||||
return [
|
||||
'ok' => true,
|
||||
'message' => '',
|
||||
'playx_transaction_id' => strval($data['playx_transaction_id'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'ok' => false,
|
||||
'message' => strval($data['message'] ?? 'PlayX bonus grant not accepted'),
|
||||
'playx_transaction_id' => '',
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'message' => $e->getMessage(),
|
||||
'playx_transaction_id' => '',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace app\process;
|
||||
|
||||
use app\common\model\MallItem;
|
||||
use app\common\library\MallBonusGrantPush;
|
||||
use app\common\model\MallOrder;
|
||||
use app\common\model\MallUserAsset;
|
||||
use GuzzleHttp\Client;
|
||||
@@ -99,9 +99,6 @@ class PlayxJobs
|
||||
return;
|
||||
}
|
||||
|
||||
$bonusPath = strval(config('playx.api.bonus_grant_url', '/api/v1/bonus/grant'));
|
||||
$bonusUrl = rtrim($baseUrl, '/') . $bonusPath;
|
||||
|
||||
$maxRetry = 3;
|
||||
$list = MallOrder::where('type', MallOrder::TYPE_BONUS)
|
||||
->whereIn('grant_status', [
|
||||
@@ -124,14 +121,12 @@ class PlayxJobs
|
||||
$order->retry_count = intval($order->retry_count ?? 0) + 1;
|
||||
|
||||
try {
|
||||
$this->sendGrantByOrder($order, $bonusUrl, $maxRetry);
|
||||
$this->sendGrantByOrder($order, $maxRetry);
|
||||
} catch (\Throwable $e) {
|
||||
$order->fail_reason = $e->getMessage();
|
||||
if (intval($order->retry_count) >= $maxRetry) {
|
||||
$order->grant_status = MallOrder::GRANT_FAILED_FINAL;
|
||||
$order->status = MallOrder::STATUS_REJECTED;
|
||||
$order->save();
|
||||
$this->refundPoints($order);
|
||||
} else {
|
||||
$order->grant_status = MallOrder::GRANT_FAILED_RETRYABLE;
|
||||
$order->save();
|
||||
@@ -167,61 +162,31 @@ class PlayxJobs
|
||||
return false;
|
||||
}
|
||||
|
||||
private function sendGrantByOrder(MallOrder $order, string $bonusUrl, int $maxRetry): void
|
||||
private function sendGrantByOrder(MallOrder $order, int $maxRetry): void
|
||||
{
|
||||
$item = null;
|
||||
if ($order->mallItem) {
|
||||
$item = $order->mallItem;
|
||||
} else {
|
||||
$item = MallItem::where('id', $order->mall_item_id)->find();
|
||||
}
|
||||
|
||||
if ($order->type === MallOrder::TYPE_BONUS) {
|
||||
$rewardName = $item ? strval($item->title) : '';
|
||||
$category = $item ? strval($item->category) : 'daily';
|
||||
$categoryTitle = $item ? strval($item->category_title) : '';
|
||||
$multiplier = intval($order->multiplier ?? 0);
|
||||
if ($multiplier <= 0) {
|
||||
$multiplier = 1;
|
||||
}
|
||||
|
||||
$requestId = 'mall_retry_bonus_' . uniqid();
|
||||
$res = $this->http->post($bonusUrl, [
|
||||
'json' => [
|
||||
'request_id' => $requestId,
|
||||
'externalTransactionId' => $order->external_transaction_id,
|
||||
'user_id' => $order->user_id,
|
||||
'amount' => $order->amount,
|
||||
'rewardName' => $rewardName,
|
||||
'category' => $category,
|
||||
'categoryTitle' => $categoryTitle,
|
||||
'multiplier' => $multiplier,
|
||||
],
|
||||
]);
|
||||
|
||||
$data = json_decode(strval($res->getBody()), true) ?? [];
|
||||
if ($res->getStatusCode() === 200 && ($data['status'] ?? '') === 'accepted') {
|
||||
$order->grant_status = MallOrder::GRANT_ACCEPTED;
|
||||
$order->playx_transaction_id = strval($data['playx_transaction_id'] ?? '');
|
||||
$order->save();
|
||||
return;
|
||||
}
|
||||
|
||||
$order->fail_reason = strval($data['message'] ?? 'PlayX bonus grant not accepted');
|
||||
if (intval($order->retry_count) >= $maxRetry) {
|
||||
$order->grant_status = MallOrder::GRANT_FAILED_FINAL;
|
||||
$order->status = MallOrder::STATUS_REJECTED;
|
||||
$order->save();
|
||||
$this->refundPoints($order);
|
||||
return;
|
||||
}
|
||||
|
||||
$order->grant_status = MallOrder::GRANT_FAILED_RETRYABLE;
|
||||
$order->save();
|
||||
if ($order->type !== MallOrder::TYPE_BONUS) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 非 BONUS 订单不参与 PlayX 发放重试(提现/实物由后台流程处理)
|
||||
$result = MallBonusGrantPush::push($order);
|
||||
if ($result['ok']) {
|
||||
$order->grant_status = MallOrder::GRANT_ACCEPTED;
|
||||
$order->playx_transaction_id = $result['playx_transaction_id'];
|
||||
$order->save();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$order->fail_reason = $result['message'];
|
||||
if (intval($order->retry_count) >= $maxRetry) {
|
||||
$order->grant_status = MallOrder::GRANT_FAILED_FINAL;
|
||||
$order->save();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$order->grant_status = MallOrder::GRANT_FAILED_RETRYABLE;
|
||||
$order->save();
|
||||
}
|
||||
|
||||
private function refundPoints(MallOrder $order): void
|
||||
|
||||
Reference in New Issue
Block a user