mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 06:30:49 +00:00
feat: 目标去化率优化修改
This commit is contained in:
parent
7b9a40651f
commit
10535b560a
@ -61,7 +61,7 @@ class GoodsController extends Controller
|
||||
$item['stock'] = $item['num'];
|
||||
$item['reference_price'] = $item['cost'] * 1.5;
|
||||
$item['external_sku_id'] = $goods->goods_code . '_' . $item['sku_code'];
|
||||
$item['name'] = $goods->goods_code . $item['title'];
|
||||
$item['name'] = $goods->title . $item['title'];
|
||||
$goodsSkus[] = $item;
|
||||
}
|
||||
$collection = $goods->skus()->createMany($goodsSkus)->toArray();
|
||||
|
||||
@ -12,6 +12,7 @@ use App\Http\Requests\GoodsSkuRequest;
|
||||
use App\Imports\InventoryImport;
|
||||
use App\Imports\NewSetImport;
|
||||
use App\Models\BusinessOrderItem;
|
||||
use App\Models\DailySalesReport;
|
||||
use App\Models\DeveloperConfig;
|
||||
use App\Models\Goods;
|
||||
use App\Models\Log;
|
||||
@ -504,6 +505,16 @@ class GoodsSkusController extends Controller
|
||||
if (in_array($updateField, ['reserve', 'loss_num'])) {
|
||||
event(new StockUpdateEvent($sku));
|
||||
}
|
||||
// 更新目标去化率
|
||||
if ('goal_rate' === $updateField) {
|
||||
DailySalesReport::query()
|
||||
->where('date', date('Y-m-d'))
|
||||
->where('goods_sku_id', $sku->id)
|
||||
->update([
|
||||
'goal_rate' => $request->$updateField
|
||||
]);
|
||||
}
|
||||
|
||||
$this->addLog($id, $updateField);
|
||||
end:
|
||||
|
||||
|
||||
@ -45,15 +45,15 @@ class GoodsSkusImport implements ToCollection, SkipsEmptyRows
|
||||
}
|
||||
unset($row);
|
||||
$validator = Validator::make($collection, [
|
||||
'*.0' => ['required', 'string', 'max:191'],
|
||||
'*.1' => ['required', 'string', 'max:191', 'exists:goods_types,name'],
|
||||
'*.2' => ['string', 'max:191', 'exists:goods_brands,name'],
|
||||
'*.3' => ['required', 'alpha_dash', 'max:32'],
|
||||
'*.4' => ['required', 'string', 'max:191'],
|
||||
'*.5' => ['required', 'alpha_dash', 'max:32'],
|
||||
'*.0' => ['required', 'string', 'max:191'], // 商品名称
|
||||
'*.1' => ['required', 'string', 'max:191', 'exists:goods_types,name'], // 分类
|
||||
'*.2' => ['string', 'max:191', 'exists:goods_brands,name'], // 品牌
|
||||
'*.3' => ['required', 'alpha_dash', 'max:32'], // 商品编码
|
||||
'*.4' => ['required', 'string', 'max:191'], // 规格名称
|
||||
'*.5' => ['required', 'alpha_dash', 'max:32'], // 规格编码
|
||||
'*.6' => ['required', 'string', Rule::in(['下架', '在售', '预警'])],
|
||||
'*.7' => ['required', 'max:10'],
|
||||
'*.8' => ['required', 'max:10'],
|
||||
'*.7' => ['required', 'max:10'], // 数量
|
||||
'*.8' => ['required', 'max:10'], // 成本
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
throw new ValidationException($validator);
|
||||
@ -93,10 +93,15 @@ class GoodsSkusImport implements ToCollection, SkipsEmptyRows
|
||||
if ($newGoods) {
|
||||
$goods = new Goods();
|
||||
$goods->batchInsert(array_values($newGoods));
|
||||
$hasGoods = Goods::query()->whereIn('goods_code', array_column($newGoods, 'goods_code'))->pluck('id', 'goods_code')->toArray();
|
||||
$hasGoods = Goods::query()
|
||||
->whereIn('goods_code', array_column($newGoods, 'goods_code'))
|
||||
->get()
|
||||
->toArray();
|
||||
$hasGoods = ArrayUtils::index($hasGoods, 'goods_code');
|
||||
foreach ($skus as &$newGoodsSku) {
|
||||
$newGoodsSku['goods_id'] = $hasGoods[$newGoodsSku['goods_code']];
|
||||
$newGoodsSku['goods_id'] = $hasGoods[$newGoodsSku['goods_code']]['id'];
|
||||
$newGoodsSku['external_sku_id'] = $newGoodsSku['goods_code'] . '_' . $newGoodsSku['sku_code'];
|
||||
$newGoodsSku['name'] = $hasGoods[$newGoodsSku['goods_code']]['title'] . '_' . $newGoodsSku['title'];
|
||||
unset($newGoodsSku['goods_code']);
|
||||
}
|
||||
unset($newGoodsSku);
|
||||
|
||||
@ -32,6 +32,7 @@ class GoodsSku extends Model
|
||||
'thumb_url',
|
||||
'external_sku_id',
|
||||
'is_combination',
|
||||
'name',
|
||||
];
|
||||
|
||||
protected $hidden = ['created_at'];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user