mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 14:40:44 +00:00
feat: #20220804 7点库存盘点
This commit is contained in:
parent
c45c004ad8
commit
9553c73c42
79
app/Console/Commands/Inventory.php
Normal file
79
app/Console/Commands/Inventory.php
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use App\Models\DailyStockRecord;
|
||||||
|
use App\Models\GoodsSku;
|
||||||
|
use App\Models\Log;
|
||||||
|
|
||||||
|
class Inventory extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'timing:inventory';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = '定时盘点';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
DB::beginTransaction();
|
||||||
|
try {
|
||||||
|
// 数据库存储过程,7点定时执行
|
||||||
|
$skus = GoodsSku::query()->get(['id', 'stock', 'two_days_ago_num', 'yesterday_num']);
|
||||||
|
$data = [];
|
||||||
|
$date = date('Y-m-d');
|
||||||
|
foreach ($skus as $sku) {
|
||||||
|
$data[] = [
|
||||||
|
'sku_id' => $sku->id,
|
||||||
|
'day' => $date,
|
||||||
|
];
|
||||||
|
GoodsSku::where('id', $sku->id)->update([
|
||||||
|
'stock' => $sku->stock + $sku->two_days_ago_num + $sku->yesterday_num,
|
||||||
|
'yesterday_num' => $sku->stock,
|
||||||
|
'two_days_ago_num' => $sku->two_days_ago_num + $sku->yesterday_num,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$log = new Log();
|
||||||
|
$log->module = 'goods';
|
||||||
|
$log->action = 'PATCH';
|
||||||
|
$log->target_type = 'goods_sku';
|
||||||
|
$log->target_id = 0;
|
||||||
|
$log->target_field = 'timingInventory';
|
||||||
|
$log->user_id = 1;
|
||||||
|
$record = new DailyStockRecord();
|
||||||
|
$record->batchInsert($data);
|
||||||
|
$log->message = '成功';
|
||||||
|
DB::commit();
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
$log->message = '失败';
|
||||||
|
DB::rollBack();
|
||||||
|
}
|
||||||
|
$log->save();
|
||||||
|
$this->info($log->message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -36,6 +36,7 @@ class GoodsSkusController extends Controller
|
|||||||
$goods = Goods::query()->filter()->get()->toArray();
|
$goods = Goods::query()->filter()->get()->toArray();
|
||||||
$goodsIds = array_column($goods, 'id');
|
$goodsIds = array_column($goods, 'id');
|
||||||
// 状态变更时间查询,日志
|
// 状态变更时间查询,日志
|
||||||
|
|
||||||
$day = FormatUtils::date();
|
$day = FormatUtils::date();
|
||||||
$goodsSkus = GoodsSku::query()
|
$goodsSkus = GoodsSku::query()
|
||||||
->whereIn('goods_id', $goodsIds)
|
->whereIn('goods_id', $goodsIds)
|
||||||
|
|||||||
@ -87,7 +87,7 @@ class Log extends Model
|
|||||||
|
|
||||||
public function setUserIdAttribute($value)
|
public function setUserIdAttribute($value)
|
||||||
{
|
{
|
||||||
$this->attributes['user_id'] = Auth::id();
|
$this->attributes['user_id'] = Auth::id() ?: $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add($targetId = 0, $targetField = '')
|
public function add($targetId = 0, $targetField = '')
|
||||||
|
|||||||
@ -20,6 +20,7 @@ class CreateDailyStockRecordsTable extends Migration
|
|||||||
$table->unsignedInteger('arrived_today_num')->default(0)->comment('今日到货');
|
$table->unsignedInteger('arrived_today_num')->default(0)->comment('今日到货');
|
||||||
$table->unsignedInteger('loss_num')->default(0)->comment('损耗');
|
$table->unsignedInteger('loss_num')->default(0)->comment('损耗');
|
||||||
$table->unsignedInteger('inventory')->default(0)->comment('库存盘点');
|
$table->unsignedInteger('inventory')->default(0)->comment('库存盘点');
|
||||||
|
$table->unique('sku_id', 'day');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@ class CreateLogsTable extends Migration
|
|||||||
$table->text('after_update')->nullable()->comment('更新后数据');
|
$table->text('after_update')->nullable()->comment('更新后数据');
|
||||||
$table->text('message')->nullable()->comment('备注信息');
|
$table->text('message')->nullable()->comment('备注信息');
|
||||||
$table->bigInteger('user_id')->comment('操作人id');
|
$table->bigInteger('user_id')->comment('操作人id');
|
||||||
|
$table->index('target_type', 'target_id', 'target_field');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user