modify table
This commit is contained in:
parent
535c2bee95
commit
ebb87f09df
|
@ -76,6 +76,7 @@ public function handle(): int
|
|||
'notice_id' => $id,
|
||||
'notice_type' => $data[$id]['type'],
|
||||
'raw_content' => json_encode($data[$id]),
|
||||
'err_message' => '',
|
||||
'created_at' => $time,
|
||||
];
|
||||
if (isset($typeIds[$data[$id]['type']])) {
|
||||
|
|
|
@ -67,7 +67,17 @@ public function addGoods(): void
|
|||
$this->client = new Client();
|
||||
$apiToken = env('API_TOKEN');
|
||||
$now = date('Y-m-d H:i:s');
|
||||
foreach ($this->data as $item) {
|
||||
$good = new Good();
|
||||
$goodsItem = new GoodsItem();
|
||||
$goodsIds = array_column(array_values($this->data), 'itemId');
|
||||
$existedIds = Good::query()->whereIn('itemid', $goodsIds)->select('itemid')->get()->toArray();
|
||||
$newIds = array_diff($goodsIds, $existedIds);
|
||||
if (!$newIds) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($newIds as $id) {
|
||||
$item = $this->data[$id];
|
||||
$product = apiRequest::requests($this->client, $this->goodsUrl, [
|
||||
'token' => $apiToken,
|
||||
'itemId' => $item['result']['itemId'],
|
||||
|
@ -78,12 +88,12 @@ public function addGoods(): void
|
|||
$noticeIds[] = $item['notice_id'];
|
||||
$product = $product['data']['product'];
|
||||
$product['itemid'] = $product['itemId'];
|
||||
$good = new Good();
|
||||
|
||||
$good->fill($product);
|
||||
$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);
|
||||
|
|
|
@ -15,8 +15,8 @@ public function up()
|
|||
{
|
||||
Schema::create('goods', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('itemid')->comment('商品id');
|
||||
$table->integer('typeid')->comment('');
|
||||
$table->integer('itemid')->comment('商品id')->unique();
|
||||
$table->integer('typeid')->comment('类型');
|
||||
$table->string('product_name')->comment('商品名');
|
||||
$table->string('product_code')->index()->comment('商品code');
|
||||
$table->string('product_group')->comment('商品组');
|
||||
|
|
|
@ -15,7 +15,7 @@ public function up()
|
|||
{
|
||||
Schema::create('goods_items', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('item_id')->index();
|
||||
$table->integer('item_id')->unique();
|
||||
$table->string('brand')->default('')->comment('品牌');
|
||||
$table->string('color_name')->default('')->comment('颜色');
|
||||
$table->text('sell_point')->comment('卖点');
|
||||
|
|
Loading…
Reference in New Issue
Block a user