批量修改在售库存
This commit is contained in:
parent
44163c5c5c
commit
ae5cc03c17
@ -4,6 +4,7 @@ namespace App\Exports;
|
||||
|
||||
use App\Http\Enum\TargetTypeEnum;
|
||||
use App\Models\DailyStockRecord;
|
||||
use App\Models\Goods;
|
||||
use App\Models\Log;
|
||||
use App\Models\PurchaseRecords;
|
||||
use App\Utils\ArrayUtils;
|
||||
@ -37,8 +38,8 @@ class GoodsSkusExport implements FromCollection, ShouldAutoSize
|
||||
$headTitle = [
|
||||
'商品编码',
|
||||
'商品名称',
|
||||
'商品品种',
|
||||
'规格名称',
|
||||
'在售库存',
|
||||
'创建时间',
|
||||
];
|
||||
$map = [
|
||||
'cost' => ['当前成本', '更新前成本', "更新后成本"],
|
||||
@ -51,6 +52,22 @@ class GoodsSkusExport implements FromCollection, ShouldAutoSize
|
||||
if ('inventory' === $this->type) {
|
||||
$update = $this->getInventoryRecord();
|
||||
}
|
||||
if ($this->type === "goods_sku" || $this->type === "goods_combination") {
|
||||
$builder = GoodsSku::query();
|
||||
if (request()->get('type_id')) {
|
||||
$goodsIds = Goods::query()->filter()->pluck('id')->toArray();
|
||||
$builder->whereIn('goods_id', $goodsIds);
|
||||
}
|
||||
if (request()->get('goods_title')) {
|
||||
$builder->where('name', 'like', '%' . request()->get('goods_title') . '%');
|
||||
}
|
||||
if ($this->type === "goods_combination") {
|
||||
$builder->where('is_combination', 1);
|
||||
}else{
|
||||
$builder->where('is_combination', 0);
|
||||
}
|
||||
$data = $builder->filter()->orderByDesc('id')->get()->toArray();
|
||||
} else {
|
||||
$ids = array_keys($update);
|
||||
if (empty($ids)) {
|
||||
return [$headTitle];
|
||||
@ -68,12 +85,14 @@ class GoodsSkusExport implements FromCollection, ShouldAutoSize
|
||||
if (empty($data)) {
|
||||
return [$headTitle];
|
||||
}
|
||||
}
|
||||
|
||||
$bodyData = [];
|
||||
foreach ($data as $item) {
|
||||
$arr[0] = $item['external_sku_id'];
|
||||
$arr[1] = $item['name'];
|
||||
$arr[2] = !empty($item['goods']['type']['name']) ? $item['goods']['type']['name'] : '';
|
||||
$arr[3] = $item['title'];
|
||||
$arr[2] = $item['sale_stock'] ?? 0;
|
||||
$arr[3] = $item['created_at'];
|
||||
if ('cost' === $this->type) {
|
||||
$arr[4] = (string)$item['cost'];
|
||||
$arr[5] = (string)$update[$item['id']]['before_update'];
|
||||
|
||||
@ -28,4 +28,15 @@ class GoodsSkuFilter extends Filters
|
||||
{
|
||||
return $this->builder->where('is_combination', $value);
|
||||
}
|
||||
|
||||
protected function createTimeStart($value)
|
||||
{
|
||||
|
||||
return $this->builder->where('created_at',">=", $value);
|
||||
}
|
||||
|
||||
protected function createTimeEnd($value)
|
||||
{
|
||||
return $this->builder->where('created_at',"<=", $value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -616,6 +616,7 @@ class GoodsSkusController extends Controller
|
||||
$endDate = Carbon::now()->subWeek()->endOfWeek()->toDateString();
|
||||
return Excel::download(new WeekDataExport($startDate, $endDate), $startDate . '~' . $endDate . '.xlsx');
|
||||
}
|
||||
|
||||
return Excel::download(new GoodsSkusExport($type), $type . '.xlsx');
|
||||
}
|
||||
|
||||
|
||||
@ -15,6 +15,8 @@ class GoodsSku extends Model
|
||||
'exclude_ids',
|
||||
'external_sku_id',
|
||||
'is_combination',
|
||||
"create_time_start",
|
||||
"create_time_end"
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
@ -37,8 +39,6 @@ class GoodsSku extends Model
|
||||
'attribute'
|
||||
];
|
||||
|
||||
protected $hidden = ['created_at'];
|
||||
|
||||
public static $STATUS_ON_SALE = 1;
|
||||
public static $STATUS_DOWN = 0;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user