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