[FIX] 修正與標準化 B005 廣告下載 API 以相容既有 Android App
All checks were successful
star-cloud-deploy-demo / deploy-demo (push) Successful in 1m7s

1. 修改 MachineController@getAdvertisements 回傳欄位,將 t070v02 改為播放秒數,t070v03 改為位置代碼 (Flag)。
2. 根據 Android App 原始碼分析結果,調整位置對應:3 為待機廣告 (HomeActivity),1 為販賣頁廣告 (FontendActivity)。
3. 在 AdvertisementController@getMachineAds 增加 sort_order 排序,確保後台管理介面視圖與 API 輸出順序一致。
4. 更新廣告下載 API 的技術文件 (SKILL.md),明確標記欄位用途與位置代碼。
5. 在 routes/api.php 補上 B005 與 B009 的路由定義。
This commit is contained in:
2026-04-07 11:41:24 +08:00
parent bbdc5bad9f
commit b60afc3abe
5 changed files with 166 additions and 11 deletions

View File

@@ -64,24 +64,36 @@ class MachineService
public function syncSlots(Machine $machine, array $slotsData): void
{
DB::transaction(function () use ($machine, $slotsData) {
// 蒐集所有傳入的商品 ID (可能是 SKU 或 實際 ID)
$productCodes = collect($slotsData)->pluck('product_id')->filter()->unique()->toArray();
// 批次查詢商品 (支援以 SKU 查詢,確保對應至資料庫 ID)
$products = \App\Models\Product\Product::whereIn('sku', $productCodes)
->orWhereIn('id', $productCodes)
->get()
->keyBy(fn($p) => $p->sku ?: $p->id);
foreach ($slotsData as $slotData) {
$slotNo = $slotData['slot_no'] ?? null;
if (!$slotNo) continue;
$existingSlot = $machine->slots()->where('slot_no', $slotNo)->first();
// 查找對應的實體 ID
$productCode = $slotData['product_id'] ?? null;
$actualProductId = null;
if ($productCode) {
$actualProductId = $products->get($productCode)?->id;
}
$updateData = [
'product_id' => $slotData['product_id'] ?? null,
'product_id' => $actualProductId,
'stock' => $slotData['stock'] ?? 0,
'capacity' => $slotData['capacity'] ?? ($existingSlot->capacity ?? 10),
'price' => $slotData['price'] ?? ($existingSlot->price ?? 0),
'last_restocked_at' => now(),
'max_stock' => $slotData['capacity'] ?? ($existingSlot->max_stock ?? 10),
'is_active' => true,
];
// 如果商品變了,或者這是一次明確的補貨回報,清空效期等待管理員更新
// 這裡我們暫定只要有 report 進來,就需要重新確認效期
$updateData['expiry_date'] = null;
// 如果這是一次明確的補貨回報,建議更新時間並記錄
if ($existingSlot) {
$existingSlot->update($updateData);
} else {