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
368f3f5bea
commit
66cccf78c3
@ -62,5 +62,10 @@ class DeleteKttQuery extends Command
|
||||
->where('created_at', '<', date('Y-m-d H:i:s', strtotime('-3 day')))
|
||||
->delete();
|
||||
$this->info('删除妙选更新库存: ' . $count);
|
||||
|
||||
$count = Log::query()->where('target_field', 'stock')
|
||||
->where('created_at', '<', date('Y-m-d H:i:s', strtotime('-3 day')))
|
||||
->delete();
|
||||
$this->info('删除更新库存: ' . $count);
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ class Kernel extends ConsoleKernel
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// 服务器/etc/crontab添加cron入口
|
||||
// * * * * * cd /mnt/wwwroot/erp.chutang66.com && php artisan schedule:run >> /dev/null 2>&1
|
||||
// * * * * * cd /home/wwwroot/erp.chutang66.com && php artisan schedule:run >> /dev/null 2>&1
|
||||
$schedule->command(Inventory::class)->dailyAt('07:00');
|
||||
$schedule->command(KttOrderQuery::class)->everyMinute();
|
||||
$schedule->command(DeleteKttQuery::class)->daily();
|
||||
|
||||
@ -8,14 +8,13 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\GoodsRequest;
|
||||
use App\Http\Requests\GoodsSkuRequest;
|
||||
use App\Imports\InventoryImport;
|
||||
use App\Imports\NewSetImport;
|
||||
use App\Models\BusinessOrderItem;
|
||||
use App\Models\Goods;
|
||||
use App\Models\GoodsType;
|
||||
use App\Models\Log;
|
||||
use App\Models\Log as LogModel;
|
||||
use App\Utils\ArrayUtils;
|
||||
use App\Utils\DateTimeUtils;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\GoodsSku;
|
||||
use App\Http\Resources\GoodsSkuResource;
|
||||
@ -486,6 +485,27 @@ class GoodsSkusController extends Controller
|
||||
return Excel::download(new GoodsSkusExport($type), $type . '.xlsx');
|
||||
}
|
||||
|
||||
public function newSetImport(Request $request)
|
||||
{
|
||||
if (!$request->hasFile('newSetFile')) {
|
||||
$this->res = [
|
||||
'httpCode' => 404,
|
||||
'errorCode' => 404404,
|
||||
'errorMessage' => 'not found new set file',
|
||||
];
|
||||
}
|
||||
try {
|
||||
$import = new NewSetImport();
|
||||
$path = $request->file('newSetFile');
|
||||
Excel::import($import, $path);
|
||||
$this->addLog(0, 'import', 'newSetFile');
|
||||
} catch (ValidationException $exception) {
|
||||
$this->setValidatorFailResponse($exception->validator->getMessageBag()->getMessages());
|
||||
}
|
||||
|
||||
return response($this->res, $this->res['httpCode']);
|
||||
}
|
||||
|
||||
public function inventoryImport(Request $request)
|
||||
{
|
||||
if (!$request->hasFile('inventoryFile')) {
|
||||
|
||||
62
app/Imports/NewSetImport.php
Normal file
62
app/Imports/NewSetImport.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports;
|
||||
|
||||
use App\Models\DailyStockRecord;
|
||||
use App\Models\GoodsSku;
|
||||
use App\Models\TodayPrice;
|
||||
use App\Utils\DateTimeUtils;
|
||||
use Exception;
|
||||
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
||||
use Maatwebsite\Excel\Concerns\ToArray;
|
||||
use App\Utils\ArrayUtils;
|
||||
use App\Events\StockUpdateEvent;
|
||||
|
||||
class NewSetImport implements ToArray, SkipsEmptyRows
|
||||
{
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function array(array $collection)
|
||||
{
|
||||
unset($collection[0]);
|
||||
$externalSkuId = [];
|
||||
foreach ($collection as &$row) {
|
||||
$row = array_map(static function ($v) {
|
||||
return trim($v);
|
||||
}, $row);
|
||||
$externalSkuId[] = $row[0];
|
||||
}
|
||||
unset($row);
|
||||
$day = DateTimeUtils::getToday();
|
||||
$updateIds = [];
|
||||
$hasGoodsSkus = GoodsSku::query()
|
||||
->whereIn('external_sku_id', $externalSkuId)
|
||||
->get(['id', 'status', 'external_sku_id', 'stock'])
|
||||
->toArray();
|
||||
$hasGoodsSkus = ArrayUtils::index($hasGoodsSkus, 'external_sku_id');
|
||||
foreach ($collection as $row) {
|
||||
if (!isset($hasGoodsSkus[$row[0]])) {
|
||||
continue;
|
||||
}
|
||||
$goodsSku = $hasGoodsSkus[$row[0]];
|
||||
if ('下架' === $goodsSku['status']) {
|
||||
GoodsSku::query()->where('id', $goodsSku['id'])->update([
|
||||
'stock' => $row[2] + $goodsSku['stock'],
|
||||
'status' => 1,
|
||||
]);
|
||||
} else {
|
||||
GoodsSku::query()->where('id', $goodsSku['id'])->update([
|
||||
'stock' => $row[2] + $goodsSku['stock'],
|
||||
]);
|
||||
}
|
||||
$updateIds[] = $goodsSku['id'];
|
||||
// 今日到货
|
||||
$record = DailyStockRecord::query()->where('sku_id', $goodsSku['id'])->where('day', $day)->first(['id', 'arrived_today_num']);
|
||||
$record->arrived_today_num += $row[2];
|
||||
$record->save();
|
||||
}
|
||||
sleep(2);
|
||||
event(new StockUpdateEvent($updateIds, 1));
|
||||
}
|
||||
}
|
||||
@ -58,6 +58,11 @@
|
||||
<span> 其它合计: {{ other_num }}</span>
|
||||
<div class="btn">
|
||||
<el-button type="primary" plain @click="update()">上新</el-button>
|
||||
<el-upload ref="newset" action="/api/new/set/goods_skus" :multiple="false" name="newSetFile"
|
||||
:show-file-list="false" :on-success="inventorySuccess" :before-upload="beforeInventory"
|
||||
:on-error="inventoryError" style="display:inline-block;margin: 0 10px 0 10px;">
|
||||
<el-button type="primary" plain>上新导入</el-button>
|
||||
</el-upload>
|
||||
<el-upload ref="myUpload" action="/api/inventory/goods_skus" :multiple="false" name="inventoryFile"
|
||||
:show-file-list="false" :on-success="inventorySuccess" :before-upload="beforeInventory"
|
||||
:on-error="inventoryError" style="display:inline-block;margin: 0 10px 0 10px;">
|
||||
@ -912,7 +917,7 @@ export default {
|
||||
beforeInventory() {
|
||||
this.loadingModule = this.$loading({
|
||||
lock: true,
|
||||
text: '盘点导入中...',
|
||||
text: '导入中...',
|
||||
spinner: 'el-icon-loading',
|
||||
background: 'rgba(0, 0, 0, 0.7)'
|
||||
});
|
||||
|
||||
@ -64,6 +64,11 @@ return [
|
||||
'name' => '盘点导入',
|
||||
'parent_id' => 2,
|
||||
],
|
||||
'goods_sku.new_set' => [
|
||||
'id' => 200,
|
||||
'name' => '上新导入',
|
||||
'parent_id' => 2,
|
||||
],
|
||||
'GOODS_TYPE' => [
|
||||
'id' => 3,
|
||||
'name' => '商品种类',
|
||||
|
||||
@ -85,6 +85,8 @@ Route::post('business', [ShopsController::class, 'business'])->name('shop.put.bu
|
||||
|
||||
// 盘点导入
|
||||
Route::post('inventory/goods_skus', [GoodsSkusController::class, 'inventoryImport'])->name('goods_sku.inventory');
|
||||
// 上新导入
|
||||
Route::post('new/set/goods_skus', [GoodsSkusController::class, 'newSetImport'])->name('goods_sku.new_set');
|
||||
// 商品货架导入
|
||||
Route::post('goods_sku_location', [GoodsSkuLocationController::class, 'import'])->name('goods_sku_location.import');
|
||||
// 组合商品导入
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user