新增积分流水接口
This commit is contained in:
@@ -679,6 +679,210 @@ class Playx extends Api
|
|||||||
return $this->success('', ['list' => $list->toArray()]);
|
return $this->success('', ['list' => $list->toArray()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 积分流水(领取/兑换/退回)
|
||||||
|
* GET /api/v1/mall/pointsLogs
|
||||||
|
*
|
||||||
|
* 鉴权:token / session_id / user_id(同 assets/orders)
|
||||||
|
*
|
||||||
|
* 参数:
|
||||||
|
* - limit: 每页条数(默认 20,最大 100)
|
||||||
|
* - cursor: 游标(上一页返回的 next_cursor)
|
||||||
|
* - direction: IN | OUT(可选,不传返回全部)
|
||||||
|
*/
|
||||||
|
public function pointsLogs(Request $request): Response
|
||||||
|
{
|
||||||
|
$response = $this->initializeApi($request);
|
||||||
|
if ($response !== null) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
$assetId = $this->resolvePlayxAssetIdFromRequest($request);
|
||||||
|
if ($assetId === null) {
|
||||||
|
return $this->error(__('Token expiration'), null, 0, ['statusCode' => 401]);
|
||||||
|
}
|
||||||
|
$asset = $this->getAssetById($assetId);
|
||||||
|
if (!$asset || ($asset->playx_user_id ?? '') === '') {
|
||||||
|
return $this->success('', [
|
||||||
|
'list' => [],
|
||||||
|
'next_cursor' => null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$playxUserId = $asset->playx_user_id;
|
||||||
|
|
||||||
|
$limit = $request->get('limit', $request->post('limit', '20'));
|
||||||
|
if (!is_string($limit) || $limit === '' || !ctype_digit($limit) || $limit === '0') {
|
||||||
|
$limit = '20';
|
||||||
|
}
|
||||||
|
if (strlen($limit) > 3 || $limit > '100') {
|
||||||
|
$limit = '100';
|
||||||
|
}
|
||||||
|
|
||||||
|
$cursor = $request->get('cursor', $request->post('cursor', ''));
|
||||||
|
if (!is_string($cursor)) {
|
||||||
|
$cursor = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$direction = $request->get('direction', $request->post('direction', ''));
|
||||||
|
$direction = is_string($direction) ? strtoupper(trim($direction)) : '';
|
||||||
|
if ($direction !== '' && $direction !== 'IN' && $direction !== 'OUT') {
|
||||||
|
$direction = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = <<<SQL
|
||||||
|
SELECT
|
||||||
|
t.biz_type,
|
||||||
|
t.direction,
|
||||||
|
t.points,
|
||||||
|
t.ts,
|
||||||
|
t.ref_id,
|
||||||
|
t.order_no,
|
||||||
|
t.order_status,
|
||||||
|
t.item_id,
|
||||||
|
t.item_title,
|
||||||
|
t.item_type,
|
||||||
|
t.item_score,
|
||||||
|
t.item_amount,
|
||||||
|
t.item_multiplier,
|
||||||
|
t.item_category,
|
||||||
|
t.item_category_title,
|
||||||
|
t.sort_key
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
'CLAIM' AS biz_type,
|
||||||
|
'IN' AS direction,
|
||||||
|
cl.claimed_amount AS points,
|
||||||
|
cl.create_time AS ts,
|
||||||
|
cl.claim_request_id AS ref_id,
|
||||||
|
'' AS order_no,
|
||||||
|
'' AS order_status,
|
||||||
|
0 AS item_id,
|
||||||
|
'' AS item_title,
|
||||||
|
0 AS item_type,
|
||||||
|
0 AS item_score,
|
||||||
|
0 AS item_amount,
|
||||||
|
0 AS item_multiplier,
|
||||||
|
'' AS item_category,
|
||||||
|
'' AS item_category_title,
|
||||||
|
CONCAT(LPAD(cl.create_time, 10, '0'), '_1_', LPAD(cl.id, 10, '0')) AS sort_key
|
||||||
|
FROM mall_claim_log cl
|
||||||
|
WHERE cl.user_id = :user_id_claim
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
CONCAT('REDEEM_', o.type) AS biz_type,
|
||||||
|
'OUT' AS direction,
|
||||||
|
o.points_cost AS points,
|
||||||
|
o.create_time AS ts,
|
||||||
|
o.external_transaction_id AS ref_id,
|
||||||
|
o.external_transaction_id AS order_no,
|
||||||
|
o.status AS order_status,
|
||||||
|
o.mall_item_id AS item_id,
|
||||||
|
COALESCE(i.title, '') AS item_title,
|
||||||
|
COALESCE(i.type, 0) AS item_type,
|
||||||
|
COALESCE(i.score, 0) AS item_score,
|
||||||
|
COALESCE(i.amount, 0) AS item_amount,
|
||||||
|
COALESCE(i.multiplier, 0) AS item_multiplier,
|
||||||
|
COALESCE(i.category, '') AS item_category,
|
||||||
|
COALESCE(i.category_title, '') AS item_category_title,
|
||||||
|
CONCAT(LPAD(o.create_time, 10, '0'), '_2_', LPAD(o.id, 10, '0')) AS sort_key
|
||||||
|
FROM mall_order o
|
||||||
|
LEFT JOIN mall_item i ON i.id = o.mall_item_id
|
||||||
|
WHERE o.user_id = :user_id_redeem AND o.points_cost > 0
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
'REFUND' AS biz_type,
|
||||||
|
'IN' AS direction,
|
||||||
|
o.points_cost AS points,
|
||||||
|
o.update_time AS ts,
|
||||||
|
o.external_transaction_id AS ref_id,
|
||||||
|
o.external_transaction_id AS order_no,
|
||||||
|
o.status AS order_status,
|
||||||
|
o.mall_item_id AS item_id,
|
||||||
|
COALESCE(i.title, '') AS item_title,
|
||||||
|
COALESCE(i.type, 0) AS item_type,
|
||||||
|
COALESCE(i.score, 0) AS item_score,
|
||||||
|
COALESCE(i.amount, 0) AS item_amount,
|
||||||
|
COALESCE(i.multiplier, 0) AS item_multiplier,
|
||||||
|
COALESCE(i.category, '') AS item_category,
|
||||||
|
COALESCE(i.category_title, '') AS item_category_title,
|
||||||
|
CONCAT(LPAD(o.update_time, 10, '0'), '_3_', LPAD(o.id, 10, '0')) AS sort_key
|
||||||
|
FROM mall_order o
|
||||||
|
LEFT JOIN mall_item i ON i.id = o.mall_item_id
|
||||||
|
WHERE o.user_id = :user_id_refund AND o.status = 'REJECTED' AND o.points_cost > 0 AND o.update_time IS NOT NULL
|
||||||
|
) t
|
||||||
|
WHERE 1=1
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
$params = [
|
||||||
|
'user_id_claim' => $playxUserId,
|
||||||
|
'user_id_redeem' => $playxUserId,
|
||||||
|
'user_id_refund' => $playxUserId,
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($cursor !== '') {
|
||||||
|
$sql .= "\n AND t.sort_key < :cursor";
|
||||||
|
$params['cursor'] = $cursor;
|
||||||
|
}
|
||||||
|
if ($direction !== '') {
|
||||||
|
$sql .= "\n AND t.direction = :direction";
|
||||||
|
$params['direction'] = $direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql .= "\nORDER BY t.sort_key DESC";
|
||||||
|
$sql .= "\nLIMIT " . $limit;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$rows = Db::query($sql, $params);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->error($e->getMessage(), null, 0, ['statusCode' => 500]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = [];
|
||||||
|
$nextCursor = null;
|
||||||
|
if (is_array($rows)) {
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
if (!is_array($row)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$list[] = [
|
||||||
|
'biz_type' => $row['biz_type'] ?? '',
|
||||||
|
'direction' => $row['direction'] ?? '',
|
||||||
|
'points' => $row['points'] ?? 0,
|
||||||
|
'ts' => $row['ts'] ?? null,
|
||||||
|
'ref_id' => $row['ref_id'] ?? '',
|
||||||
|
'order_no' => $row['order_no'] ?? '',
|
||||||
|
'order_status' => $row['order_status'] ?? '',
|
||||||
|
'item_id' => $row['item_id'] ?? 0,
|
||||||
|
'item_title' => $row['item_title'] ?? '',
|
||||||
|
'item_type' => $row['item_type'] ?? 0,
|
||||||
|
'item_score' => $row['item_score'] ?? 0,
|
||||||
|
'mallItem' => ($row['item_id'] ?? 0) ? [
|
||||||
|
'id' => $row['item_id'] ?? 0,
|
||||||
|
'title' => $row['item_title'] ?? '',
|
||||||
|
'type' => $row['item_type'] ?? 0,
|
||||||
|
'score' => $row['item_score'] ?? 0,
|
||||||
|
'amount' => $row['item_amount'] ?? 0,
|
||||||
|
'multiplier' => $row['item_multiplier'] ?? 0,
|
||||||
|
'category' => $row['item_category'] ?? '',
|
||||||
|
'category_title' => $row['item_category_title'] ?? '',
|
||||||
|
] : null,
|
||||||
|
'cursor' => $row['sort_key'] ?? '',
|
||||||
|
];
|
||||||
|
$nextCursor = $row['sort_key'] ?? $nextCursor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->success('', [
|
||||||
|
'list' => $list,
|
||||||
|
'next_cursor' => $nextCursor,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 收货地址列表
|
* 收货地址列表
|
||||||
* GET /api/v1/playx/address/list?session_id=xxx
|
* GET /api/v1/playx/address/list?session_id=xxx
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ Route::post('/api/v1/mall/bonusRedeem', [\app\api\controller\v1\Playx::class, 'b
|
|||||||
Route::post('/api/v1/mall/physicalRedeem', [\app\api\controller\v1\Playx::class, 'physicalRedeem']);
|
Route::post('/api/v1/mall/physicalRedeem', [\app\api\controller\v1\Playx::class, 'physicalRedeem']);
|
||||||
Route::post('/api/v1/mall/withdrawApply', [\app\api\controller\v1\Playx::class, 'withdrawApply']);
|
Route::post('/api/v1/mall/withdrawApply', [\app\api\controller\v1\Playx::class, 'withdrawApply']);
|
||||||
Route::get('/api/v1/mall/orders', [\app\api\controller\v1\Playx::class, 'orders']);
|
Route::get('/api/v1/mall/orders', [\app\api\controller\v1\Playx::class, 'orders']);
|
||||||
|
Route::get('/api/v1/mall/pointsLogs', [\app\api\controller\v1\Playx::class, 'pointsLogs']);
|
||||||
Route::get('/api/v1/mall/addressList', [\app\api\controller\v1\Playx::class, 'addressList']);
|
Route::get('/api/v1/mall/addressList', [\app\api\controller\v1\Playx::class, 'addressList']);
|
||||||
Route::post('/api/v1/mall/addressAdd', [\app\api\controller\v1\Playx::class, 'addressAdd']);
|
Route::post('/api/v1/mall/addressAdd', [\app\api\controller\v1\Playx::class, 'addressAdd']);
|
||||||
Route::post('/api/v1/mall/addressEdit', [\app\api\controller\v1\Playx::class, 'addressEdit']);
|
Route::post('/api/v1/mall/addressEdit', [\app\api\controller\v1\Playx::class, 'addressEdit']);
|
||||||
|
|||||||
Reference in New Issue
Block a user