fix bug
This commit is contained in:
parent
074b630679
commit
535c2bee95
@ -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)
|
||||
|
@ -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();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user