1.新增马来语ms,修改有商品管理和所有接口返回
This commit is contained in:
@@ -620,7 +620,12 @@ class Playx extends Api
|
||||
}
|
||||
$list = $query->order('sort', 'asc')->select();
|
||||
|
||||
return $this->success('', ['list' => $list->toArray()]);
|
||||
$out = [];
|
||||
foreach ($list->toArray() as $row) {
|
||||
$out[] = $this->applyMallItemLocaleForApi($row);
|
||||
}
|
||||
|
||||
return $this->success('', ['list' => $out]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -676,7 +681,15 @@ class Playx extends Api
|
||||
->limit(100)
|
||||
->select();
|
||||
|
||||
return $this->success('', ['list' => $list->toArray()]);
|
||||
$arr = $list->toArray();
|
||||
foreach ($arr as &$orderRow) {
|
||||
if (isset($orderRow['mallItem']) && is_array($orderRow['mallItem'])) {
|
||||
$orderRow['mallItem'] = $this->applyMallItemLocaleForApi($orderRow['mallItem']);
|
||||
}
|
||||
}
|
||||
unset($orderRow);
|
||||
|
||||
return $this->success('', ['list' => $arr]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -877,6 +890,18 @@ SQL;
|
||||
}
|
||||
}
|
||||
|
||||
$itemsMap = $this->buildMallItemLocaleMapForPointsLog($list);
|
||||
foreach ($list as &$row) {
|
||||
$id = (int)($row['item_id'] ?? 0);
|
||||
if ($id > 0 && isset($itemsMap[$id])) {
|
||||
$row['item_title'] = $itemsMap[$id]['title'];
|
||||
if (isset($row['mallItem']) && is_array($row['mallItem'])) {
|
||||
$row['mallItem']['title'] = $itemsMap[$id]['title'];
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($row);
|
||||
|
||||
return $this->success('', [
|
||||
'list' => $list,
|
||||
'next_cursor' => $nextCursor,
|
||||
@@ -1306,6 +1331,75 @@ SQL;
|
||||
]);
|
||||
}
|
||||
|
||||
private function getApiLocale(): string
|
||||
{
|
||||
if (function_exists('locale')) {
|
||||
$l = locale();
|
||||
if (is_string($l) && $l !== '') {
|
||||
return $l;
|
||||
}
|
||||
}
|
||||
|
||||
return 'zh-cn';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $item MallItem 行(可含 title_en/title_ms 与 description_en/description_ms)
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function applyMallItemLocaleForApi(array $item): array
|
||||
{
|
||||
$lang = $this->getApiLocale();
|
||||
if ($lang === 'en') {
|
||||
$te = trim((string)($item['title_en'] ?? ''));
|
||||
$de = trim((string)($item['description_en'] ?? ''));
|
||||
if ($te !== '') {
|
||||
$item['title'] = $te;
|
||||
}
|
||||
if ($de !== '') {
|
||||
$item['description'] = $de;
|
||||
}
|
||||
} elseif ($lang === 'ms') {
|
||||
$tm = trim((string)($item['title_ms'] ?? ''));
|
||||
$dm = trim((string)($item['description_ms'] ?? ''));
|
||||
if ($tm !== '') {
|
||||
$item['title'] = $tm;
|
||||
}
|
||||
if ($dm !== '') {
|
||||
$item['description'] = $dm;
|
||||
}
|
||||
}
|
||||
unset($item['title_en'], $item['description_en'], $item['title_ms'], $item['description_ms']);
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string,mixed>> $list pointsLogs 已组装的列表
|
||||
* @return array<int,array<string,mixed>> id => item 行(已本地化并去掉 *_ms)
|
||||
*/
|
||||
private function buildMallItemLocaleMapForPointsLog(array $list): array
|
||||
{
|
||||
$ids = [];
|
||||
foreach ($list as $row) {
|
||||
$id = (int)($row['item_id'] ?? 0);
|
||||
if ($id > 0) {
|
||||
$ids[$id] = true;
|
||||
}
|
||||
}
|
||||
if ($ids === []) {
|
||||
return [];
|
||||
}
|
||||
$idList = array_keys($ids);
|
||||
$map = [];
|
||||
$models = MallItem::whereIn('id', $idList)->select();
|
||||
foreach ($models as $model) {
|
||||
$map[intval($model->id)] = $this->applyMallItemLocaleForApi($model->toArray());
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
private function callPlayxBonusGrant(MallOrder $order, MallItem $item, string $userId): void
|
||||
{
|
||||
$baseUrl = rtrim(config('playx.api.base_url', ''), '/');
|
||||
|
||||
Reference in New Issue
Block a user