diff --git a/app/Jobs/notice.php b/app/Jobs/notice.php index c4b1330..2ffe9fe 100644 --- a/app/Jobs/notice.php +++ b/app/Jobs/notice.php @@ -66,6 +66,7 @@ public function addGoods(): void $goods = $goodsItems = $noticeIds = []; $this->client = new Client(); $apiToken = env('API_TOKEN'); + $now = date('Y-m-d H:i:s'); foreach ($this->data as $item) { $product = apiRequest::requests($this->client, $this->goodsUrl, [ 'token' => $apiToken, @@ -79,18 +80,22 @@ public function addGoods(): void $product['itemid'] = $product['itemId']; $good = new Good(); $good->fill($product); - $goods[] = $good->toArray(); + $goodsData = $good->toArray(); + $goodsData['created_at'] = $now; + $goods[] = $goodsData; $goodsItem = new GoodsItem(); $product['item_id'] = $product['itemid']; $product['specifications'] = json_encode($product['specifications']); $goodsItem->fill($product); - $goodsItems[] = $goodsItem->toArray(); + $itemData = $goodsItem->toArray(); + $itemData['created_at'] = $now; + $goodsItems[] = $itemData; } try { DB::transaction(function () use ($goods, $goodsItems, $noticeIds) { if (!Good::insert($goods) || !GoodsItem::insert($goodsItems) || !\App\Models\Notice::query()->whereIn('notice_id', $noticeIds)->update(['state' => 3])) { throw new Exception('insert failed'); - }; + } }); } catch (Throwable $throwable) { \App\Models\Notice::query()->whereIn('notice_id', $noticeIds) diff --git a/database/migrations/2024_05_24_033401_create_notices_table.php b/database/migrations/2024_05_24_033401_create_notices_table.php index 8bb488d..09e2845 100644 --- a/database/migrations/2024_05_24_033401_create_notices_table.php +++ b/database/migrations/2024_05_24_033401_create_notices_table.php @@ -18,7 +18,7 @@ public function up() $table->integer('notice_id')->unique()->comment('通知id'); $table->integer('notice_type')->comment('通知type'); $table->text('raw_content')->comment('原始消息内容'); - $table->string('err_message')->default('')->comment('处理时错误信息'); + $table->text('err_message')->comment('处理时错误信息'); $table->tinyInteger('state')->default(1)->comment('消息状态,1待消费,2消费进行中,3处理完成'); $table->timestamps(); });