mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-11-30 22:20:45 +00:00
commit
78560249f4
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\BusinessOrderItem;
|
||||
use App\Models\GoodsSku;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
@ -18,7 +17,7 @@ class BusinessOrdersUpdate
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $num;
|
||||
public $businessOrderItem;
|
||||
public $businessGoods;
|
||||
public $goodsSku;
|
||||
|
||||
/**
|
||||
@ -26,9 +25,9 @@ class BusinessOrdersUpdate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(BusinessOrderItem $item, $num)
|
||||
public function __construct($item, $num)
|
||||
{
|
||||
$this->businessOrderItem = $item->toArray();
|
||||
$this->businessGoods = $item->toArray();
|
||||
$this->num = $num;
|
||||
$this->updateStock();
|
||||
}
|
||||
@ -36,7 +35,7 @@ class BusinessOrdersUpdate
|
||||
private function updateStock()
|
||||
{
|
||||
try {
|
||||
[$goodsCode, $skuCode] = explode('_', $this->businessOrderItem['external_sku_id']);
|
||||
[$goodsCode, $skuCode] = explode('_', $this->businessGoods['external_sku_id']);
|
||||
$this->goodsSku = GoodsSku::query()->where('sku_code', $skuCode)
|
||||
->whereHas('goods', function ($query) use ($goodsCode) {
|
||||
$query->where('goods_code', $goodsCode);
|
||||
|
||||
@ -22,13 +22,17 @@ class StockUpdateEvent
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $data array|object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
// ids集合
|
||||
$this->goodsSkus = GoodsSku::query()->whereIn('id', $data)->with(['goods:id,goods_code'])->get();
|
||||
} else {
|
||||
// GoodsSku Elo模型对象
|
||||
$this->goodsSku = $data;
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ class BusinessGoodsSkuIncrQuantity implements ShouldQueue
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $shop;
|
||||
public $businessOrderItem;
|
||||
public $businessGoods;
|
||||
public $num;
|
||||
public $isIncremental = true;
|
||||
|
||||
@ -23,10 +23,10 @@ class BusinessGoodsSkuIncrQuantity implements ShouldQueue
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($shop, $businessOrderItem, $num, $isIncremental)
|
||||
public function __construct($shop, $businessGoods, $num, $isIncremental)
|
||||
{
|
||||
$this->shop = $shop;
|
||||
$this->businessOrderItem = $businessOrderItem;
|
||||
$this->businessGoods = $businessGoods;
|
||||
$this->num = $num;
|
||||
$this->isIncremental = $isIncremental;
|
||||
}
|
||||
@ -38,8 +38,8 @@ class BusinessGoodsSkuIncrQuantity implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($this->businessOrderItem) {
|
||||
BusinessFactory::init()->make($this->shop['plat_id'])->setShopWithId($this->shop['id'])->incrQuantity($this->businessOrderItem, $this->num, $this->isIncremental);
|
||||
if ($this->businessGoods) {
|
||||
BusinessFactory::init()->make($this->shop['plat_id'])->setShopWithId($this->shop['id'])->incrQuantity($this->businessGoods, $this->num, $this->isIncremental);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ class UpdateBusinessGoodsStock implements ShouldQueue
|
||||
$log->target_id = $event->goodsSku->id ?? 0;
|
||||
$log->target_field = 'stock';
|
||||
$log->user_id = 999;
|
||||
$log->message = '未找到' . json_encode($event->businessOrderItem, 256);
|
||||
$log->message = '未找到' . json_encode($event->businessGoods, 256);
|
||||
$log->save();
|
||||
|
||||
return;
|
||||
@ -57,7 +57,7 @@ class UpdateBusinessGoodsStock implements ShouldQueue
|
||||
|
||||
foreach ($shops as $shop) {
|
||||
$num = $event->goodsSku->stock;
|
||||
$businessGoodsSkus = BusinessGoodsSku::query()->where('shop_id', $shop->id)->where('external_sku_id', $event->businessOrderItem['external_sku_id'])->get();
|
||||
$businessGoodsSkus = BusinessGoodsSku::query()->where('shop_id', $shop->id)->where('external_sku_id', $event->businessGoods['external_sku_id'])->get();
|
||||
foreach ($businessGoodsSkus as $businessGoodsSku) {
|
||||
BusinessGoodsSkuIncrQuantity::dispatch($shop, $businessGoodsSku->toArray(), $num, false);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user