From 66cccf78c310729c857f9bcbdf2aa0c4f91ad2d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Thu, 1 Jun 2023 20:09:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20#10000=20=E5=A2=9E=E5=8A=A0=E4=B8=8A?= =?UTF-8?q?=E6=96=B0=E5=AF=BC=E5=85=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/DeleteKttQuery.php | 5 ++ app/Console/Kernel.php | 2 +- .../Controllers/Goods/GoodsSkusController.php | 24 ++++++- app/Imports/NewSetImport.php | 62 +++++++++++++++++++ resources/frontend/src/views/goods/goods.vue | 7 ++- resources/lang/zh-CN/permission.php | 5 ++ routes/api.php | 2 + 7 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 app/Imports/NewSetImport.php diff --git a/app/Console/Commands/DeleteKttQuery.php b/app/Console/Commands/DeleteKttQuery.php index 3043ec1..830114c 100644 --- a/app/Console/Commands/DeleteKttQuery.php +++ b/app/Console/Commands/DeleteKttQuery.php @@ -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); } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 30feaf5..4700d82 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -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(); diff --git a/app/Http/Controllers/Goods/GoodsSkusController.php b/app/Http/Controllers/Goods/GoodsSkusController.php index fa495cf..09c0b0d 100644 --- a/app/Http/Controllers/Goods/GoodsSkusController.php +++ b/app/Http/Controllers/Goods/GoodsSkusController.php @@ -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')) { diff --git a/app/Imports/NewSetImport.php b/app/Imports/NewSetImport.php new file mode 100644 index 0000000..4409468 --- /dev/null +++ b/app/Imports/NewSetImport.php @@ -0,0 +1,62 @@ +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)); + } +} diff --git a/resources/frontend/src/views/goods/goods.vue b/resources/frontend/src/views/goods/goods.vue index 6f14dec..302c81b 100644 --- a/resources/frontend/src/views/goods/goods.vue +++ b/resources/frontend/src/views/goods/goods.vue @@ -58,6 +58,11 @@ 其它合计: {{ other_num }}