feat: #10000 库存同步使用优化
This commit is contained in:
parent
94a4862240
commit
f16224e2ab
@ -40,7 +40,7 @@ class Test extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$shop = Shop::query()->find(1);
|
$shop = Shop::query()->find(2);
|
||||||
$business = BusinessFactory::init()->make($shop->plat_id);
|
$business = BusinessFactory::init()->make($shop->plat_id);
|
||||||
$business->setShop($shop);
|
$business->setShop($shop);
|
||||||
// 下载商品列表
|
// 下载商品列表
|
||||||
@ -53,9 +53,9 @@ class Test extends Command
|
|||||||
// $business->incrQuantity(1);
|
// $business->incrQuantity(1);
|
||||||
|
|
||||||
// 订单下载
|
// 订单下载
|
||||||
// $beginTime = DateTimeUtils::getMicroTime('2022-08-08');
|
$beginTime = DateTimeUtils::getMicroTime('2022-08-22 18:16:18');
|
||||||
// $endTime = DateTimeUtils::getMicroTime('2022-08-09');
|
$endTime = DateTimeUtils::getMicroTime('2022-08-22 18:16:20');
|
||||||
// $business->downloadOrdersAndSave($beginTime, $endTime);
|
$business->downloadOrdersAndSave($beginTime, $endTime);
|
||||||
|
|
||||||
$this->info('执行测试成功');
|
$this->info('执行测试成功');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,10 +45,8 @@ class BusinessOrdersUpdate
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($this->goodsSku) {
|
if ($this->goodsSku) {
|
||||||
$stock = $this->goodsSku->stock + $this->num;
|
|
||||||
if ($stock >= 0) {
|
|
||||||
$this->goodsSku->stock += $this->num;
|
$this->goodsSku->stock += $this->num;
|
||||||
} else {
|
if ($this->goodsSku->stock <= 0) {
|
||||||
$this->goodsSku->status = 0;
|
$this->goodsSku->status = 0;
|
||||||
}
|
}
|
||||||
$this->goodsSku->save();
|
$this->goodsSku->save();
|
||||||
|
|||||||
@ -261,8 +261,9 @@ class GoodsSkusController extends Controller
|
|||||||
]);
|
]);
|
||||||
$sku->two_days_ago_num = $update['two_days_ago_num'];
|
$sku->two_days_ago_num = $update['two_days_ago_num'];
|
||||||
$sku->yesterday_num = $update['yesterday_num'];
|
$sku->yesterday_num = $update['yesterday_num'];
|
||||||
$sku->num = $update['two_days_ago_num'] + $update['yesterday_num'] + $update['arrived_today_num'];
|
$num = $update['two_days_ago_num'] + $update['yesterday_num'] + $update['arrived_today_num'];
|
||||||
$sku->stock += ($update['two_days_ago_num'] + $update['yesterday_num'] + $update['arrived_today_num'] - $record->arrived_today_num - $sku->two_days_ago_num - $sku->yesterday_num);
|
$sku->num = $num;
|
||||||
|
$sku->stock += ($num - $record->arrived_today_num - $sku->two_days_ago_num - $sku->yesterday_num);
|
||||||
$sku->save();
|
$sku->save();
|
||||||
$record->arrived_today_num = $update['arrived_today_num'];
|
$record->arrived_today_num = $update['arrived_today_num'];
|
||||||
$record->save();
|
$record->save();
|
||||||
|
|||||||
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Listeners;
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\Models\BusinessGoodsSku;
|
||||||
use App\Models\Log;
|
use App\Models\Log;
|
||||||
use App\Models\Shop;
|
use App\Models\Shop;
|
||||||
use App\Services\Business\BusinessFactory;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use App\Events\BusinessOrdersUpdate;
|
use App\Events\BusinessOrdersUpdate;
|
||||||
@ -60,7 +60,10 @@ class UpdateBusinessGoodsStock implements ShouldQueue
|
|||||||
$num = $event->goodsSku->stock;
|
$num = $event->goodsSku->stock;
|
||||||
$isIncremental = false;
|
$isIncremental = false;
|
||||||
}
|
}
|
||||||
BusinessGoodsSkuIncrQuantity::dispatch($shop, $event->businessOrderItem, $num, $isIncremental);
|
$businessGoodsSkus = BusinessGoodsSku::query()->where('shop_id', $shop->id)->where('external_sku_id', $event->businessOrderItem['external_sku_id'])->get();
|
||||||
|
foreach ($businessGoodsSkus as $businessGoodsSku) {
|
||||||
|
BusinessGoodsSkuIncrQuantity::dispatch($shop, $businessGoodsSku->toArray(), $num, $isIncremental);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@ class CreateGoodsSkusTable extends Migration
|
|||||||
$table->string('sku_code', 32)->comment('规格编码');
|
$table->string('sku_code', 32)->comment('规格编码');
|
||||||
$table->unsignedTinyInteger('status')->default(0)->comment('规格状态(0-下架,1在售,2预警)');
|
$table->unsignedTinyInteger('status')->default(0)->comment('规格状态(0-下架,1在售,2预警)');
|
||||||
$table->unsignedInteger('num')->default(0)->comment('总量');
|
$table->unsignedInteger('num')->default(0)->comment('总量');
|
||||||
$table->unsignedInteger('stock')->default(0)->comment('库存');
|
$table->integer('stock')->default(0)->comment('库存');
|
||||||
$table->unsignedDecimal('cost')->default(0)->comment('成本');
|
$table->unsignedDecimal('cost')->default(0)->comment('成本');
|
||||||
$table->unsignedInteger('two_days_ago_num')->default(0)->comment('2天前库存');
|
$table->unsignedInteger('two_days_ago_num')->default(0)->comment('2天前库存');
|
||||||
$table->unsignedInteger('yesterday_num')->default(0)->comment('1天前库存');
|
$table->unsignedInteger('yesterday_num')->default(0)->comment('1天前库存');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user