mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-11-30 22:20:45 +00:00
feat: #10000 修改
This commit is contained in:
parent
ffe64ed58b
commit
a2867b0ea8
@ -19,7 +19,6 @@ class BusinessOrdersUpdate
|
|||||||
public $num;
|
public $num;
|
||||||
public $businessGoods;
|
public $businessGoods;
|
||||||
public $goodsSku;
|
public $goodsSku;
|
||||||
public $goodsSkus;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new event instance.
|
* Create a new event instance.
|
||||||
|
|||||||
@ -18,6 +18,7 @@ class StockUpdateEvent
|
|||||||
public $goodsSku;
|
public $goodsSku;
|
||||||
public $goodsSkus;
|
public $goodsSkus;
|
||||||
public $isBatch;
|
public $isBatch;
|
||||||
|
public $combinationGoodsUpdate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new event instance.
|
* Create a new event instance.
|
||||||
@ -26,9 +27,10 @@ class StockUpdateEvent
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($data, $isBatch = 0)
|
public function __construct($data, $isBatch = 0, $combinationGoodsUpdate = false)
|
||||||
{
|
{
|
||||||
$this->isBatch = $isBatch;
|
$this->isBatch = $isBatch;
|
||||||
|
$this->combinationGoodsUpdate = $combinationGoodsUpdate;
|
||||||
if (is_array($data)) {
|
if (is_array($data)) {
|
||||||
// ids集合
|
// ids集合
|
||||||
$this->goodsSkus = GoodsSku::query()->whereIn('id', $data)->get();
|
$this->goodsSkus = GoodsSku::query()->whereIn('id', $data)->get();
|
||||||
|
|||||||
@ -134,7 +134,6 @@ class BusinessGoodsSkusController extends Controller
|
|||||||
$todayGoodsPrice = [];
|
$todayGoodsPrice = [];
|
||||||
foreach ($todayPrice as $item) {
|
foreach ($todayPrice as $item) {
|
||||||
$todayGoodsPrice[$item['external_sku_id']] = [
|
$todayGoodsPrice[$item['external_sku_id']] = [
|
||||||
'today_price' => $item['price'],
|
|
||||||
'goods_name' => $item['goodsSku']['goods']['title'] . $item['goodsSku']['title'],
|
'goods_name' => $item['goodsSku']['goods']['title'] . $item['goodsSku']['title'],
|
||||||
'external_sku_id' => $item['external_sku_id'],
|
'external_sku_id' => $item['external_sku_id'],
|
||||||
'shop_price' => json_decode($item['shop_price'], true),
|
'shop_price' => json_decode($item['shop_price'], true),
|
||||||
|
|||||||
@ -20,14 +20,13 @@ class TodayPriceImport implements ToArray, SkipsEmptyRows
|
|||||||
}, $row);
|
}, $row);
|
||||||
$shopPrice = [];
|
$shopPrice = [];
|
||||||
foreach ($row as $i => $v) {
|
foreach ($row as $i => $v) {
|
||||||
if ($i > 2) {
|
if ($i > 1) {
|
||||||
$shopPrice[$header[$i]] = $v;
|
$shopPrice[$header[$i]] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$data[] = [
|
$data[] = [
|
||||||
'day' => $day,
|
'day' => $day,
|
||||||
'external_sku_id' => $row[1],
|
'external_sku_id' => $row[1],
|
||||||
'price' => $row[2],
|
|
||||||
'shop_price' => json_encode($shopPrice, 256)
|
'shop_price' => json_encode($shopPrice, 256)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
95
app/Listeners/CombinationGoodsStockUpdateListener.php
Normal file
95
app/Listeners/CombinationGoodsStockUpdateListener.php
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\Models\CombinationGood;
|
||||||
|
use App\Models\GoodsSku;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use App\Events\StockUpdateEvent;
|
||||||
|
|
||||||
|
class CombinationGoodsStockUpdateListener
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create the event listener.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle($event)
|
||||||
|
{
|
||||||
|
if ($event->combinationGoodsUpdate) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$updateIds = $combinationGoodsIds = $combinationGoodsItemIds = [];
|
||||||
|
if ($event->goodsSku) {
|
||||||
|
if ($event->goodsSku->is_combination) {
|
||||||
|
$combinationGoodsIds[] = $event->goodsSku->id;
|
||||||
|
} else {
|
||||||
|
$combinationGoodsItemIds[$event->goodsSku->id] = $event->goodsSku->stock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($event->goodsSkus) {
|
||||||
|
foreach ($event->goodsSkus as $sku) {
|
||||||
|
if ($sku->is_combination) {
|
||||||
|
$combinationGoodsIds[] = $sku->id;
|
||||||
|
} else {
|
||||||
|
$combinationGoodsItemIds[$sku->id] = $sku->stock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 减子商品库存
|
||||||
|
if ($combinationGoodsIds) {
|
||||||
|
$combinationGoods = CombinationGood::query()
|
||||||
|
->with('goodsSku:id,stock')
|
||||||
|
->whereIn('goods_sku_id', $combinationGoodsIds)
|
||||||
|
->get();
|
||||||
|
foreach ($combinationGoods as $item) {
|
||||||
|
$sku = GoodsSku::query()->find($item['item_id']);
|
||||||
|
$sku->stock -= $item['item_num'];
|
||||||
|
$sku->save();
|
||||||
|
$updateIds[] = $sku->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 计算主商品库存
|
||||||
|
if ($combinationGoodsItemIds) {
|
||||||
|
$itemIds = array_keys($combinationGoodsItemIds);
|
||||||
|
$goodsSkuIds = CombinationGood::query()
|
||||||
|
->whereIn('item_id', $itemIds)
|
||||||
|
->pluck('goods_sku_id')
|
||||||
|
->toArray();
|
||||||
|
if (empty($goodsSkuIds)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$goodsSkus = GoodsSku::query()
|
||||||
|
->whereIn('id', $goodsSkuIds)
|
||||||
|
->pluck('stock', 'id')
|
||||||
|
->toArray();
|
||||||
|
foreach ($combinationGoodsItemIds as $itemId => $stock) {
|
||||||
|
$combinationGoods = CombinationGood::query()
|
||||||
|
->where('item_id', $itemId)
|
||||||
|
->get();
|
||||||
|
foreach ($combinationGoods as $goods) {
|
||||||
|
$stock = $combinationGoodsItemIds[$goods['item_id']] / $goods['item_num'];
|
||||||
|
if ($stock < $goodsSkus[$goods['goods_sku_id']]) {
|
||||||
|
GoodsSku::query()->where('id', $goods['goods_sku_id'])->update(['stock' => $stock]);
|
||||||
|
$updateIds[] = $goods['goods_sku_id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($updateIds) {
|
||||||
|
event(new StockUpdateEvent($updateIds, 1, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -12,4 +12,9 @@ class CombinationGood extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(GoodsSku::class, 'item_id', 'id');
|
return $this->belongsTo(GoodsSku::class, 'item_id', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function goodsSku()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(GoodsSku::class, 'goods_sku_id', 'id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use App\Events\StockUpdateEvent;
|
|||||||
use App\Listeners\GroupQueryListener;
|
use App\Listeners\GroupQueryListener;
|
||||||
use App\Listeners\StockUpdateListener;
|
use App\Listeners\StockUpdateListener;
|
||||||
use App\Listeners\StockWarning;
|
use App\Listeners\StockWarning;
|
||||||
|
use App\Listeners\CombinationGoodsStockUpdateListener;
|
||||||
use App\Listeners\UpdateBusinessGoodsStock;
|
use App\Listeners\UpdateBusinessGoodsStock;
|
||||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||||
|
|
||||||
@ -22,10 +23,12 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
BusinessOrdersUpdate::class => [
|
BusinessOrdersUpdate::class => [
|
||||||
UpdateBusinessGoodsStock::class,
|
UpdateBusinessGoodsStock::class,
|
||||||
StockWarning::class,
|
StockWarning::class,
|
||||||
|
CombinationGoodsStockUpdateListener::class,
|
||||||
],
|
],
|
||||||
StockUpdateEvent::class => [
|
StockUpdateEvent::class => [
|
||||||
StockUpdateListener::class,
|
StockUpdateListener::class,
|
||||||
StockWarning::class,
|
StockWarning::class,
|
||||||
|
CombinationGoodsStockUpdateListener::class,
|
||||||
],
|
],
|
||||||
GroupSetEvent::class => [
|
GroupSetEvent::class => [
|
||||||
GroupQueryListener::class,
|
GroupQueryListener::class,
|
||||||
|
|||||||
@ -21,7 +21,6 @@ class CreateTodayPricesTable extends Migration
|
|||||||
$table->bigIncrements('id');
|
$table->bigIncrements('id');
|
||||||
$table->date('day');
|
$table->date('day');
|
||||||
$table->string('external_sku_id');
|
$table->string('external_sku_id');
|
||||||
$table->float('price');
|
|
||||||
$table->text('shop_price');
|
$table->text('shop_price');
|
||||||
$table->index(['external_sku_id', 'day']);
|
$table->index(['external_sku_id', 'day']);
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
|||||||
@ -12,6 +12,11 @@
|
|||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary" @click="handleChoose(1)">筛选</el-button>
|
<el-button type="primary" @click="handleChoose(1)">筛选</el-button>
|
||||||
<el-button plain @click="handleReChoose()">重置筛选</el-button>
|
<el-button plain @click="handleReChoose()">重置筛选</el-button>
|
||||||
|
<el-upload ref="myUpload" action="/api/combination/goods" :multiple="false" name="combinationGoods"
|
||||||
|
:show-file-list="false" :on-success="uploadSuccess" :before-upload="beforeUpload"
|
||||||
|
:on-error="uploadError" style="display:inline-block;margin: 0 10px 0 10px;">
|
||||||
|
<el-button type="primary" plain>商品货架导入</el-button>
|
||||||
|
</el-upload>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</div>
|
</div>
|
||||||
@ -227,6 +232,28 @@ export default {
|
|||||||
item_num: 1,
|
item_num: 1,
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
beforeUpload() {
|
||||||
|
this.loadingModule = this.$loading({
|
||||||
|
lock: true,
|
||||||
|
text: '表格导入中...',
|
||||||
|
spinner: 'el-icon-loading',
|
||||||
|
background: 'rgba(0, 0, 0, 0.7)'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
uploadSuccess(response) {
|
||||||
|
this.$message({
|
||||||
|
message: response.message,
|
||||||
|
type: "success",
|
||||||
|
});
|
||||||
|
this.loadingModule.close();
|
||||||
|
},
|
||||||
|
uploadError(err) {
|
||||||
|
this.$message({
|
||||||
|
message: err.errorMessage,
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
this.loadingModule.close();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user