60 lines
2.1 KiB
PHP
Executable File
60 lines
2.1 KiB
PHP
Executable File
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\command;
|
|
|
|
use think\console\Command;
|
|
use think\console\Input;
|
|
use think\console\Output;
|
|
use think\facade\Db;
|
|
|
|
class CreateOffshelfLogTable extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
// 指令配置
|
|
$this->setName('create:offshelf:log:table')
|
|
->setDescription('创建盒子自动下架日志表');
|
|
}
|
|
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
$output->writeln('开始创建盒子下架日志表...');
|
|
|
|
// 检查表是否已存在
|
|
$tableExists = false;
|
|
try {
|
|
$result = Db::query("SHOW TABLES LIKE 'goods_offshelf_log'");
|
|
$tableExists = !empty($result);
|
|
} catch (\Exception $e) {
|
|
$output->writeln('检查表是否存在时出错:' . $e->getMessage());
|
|
}
|
|
|
|
if ($tableExists) {
|
|
$output->writeln('盒子下架日志表已存在,无需创建。');
|
|
return;
|
|
}
|
|
|
|
// 创建日志表
|
|
try {
|
|
Db::execute("
|
|
CREATE TABLE `goods_offshelf_log` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`goods_id` int(11) NOT NULL COMMENT '盒子ID',
|
|
`profit_rate` decimal(10,2) NOT NULL COMMENT '当前利润率',
|
|
`xiajia_lirun` decimal(10,2) NOT NULL COMMENT '配置的下架利润阈值',
|
|
`order_total` decimal(10,2) NOT NULL COMMENT '订单总价值',
|
|
`goods_total` decimal(10,2) NOT NULL COMMENT '出货总价值',
|
|
`create_time` int(11) NOT NULL COMMENT '下架时间',
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_goods_id` (`goods_id`),
|
|
KEY `idx_create_time` (`create_time`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='盒子自动下架日志表';
|
|
");
|
|
|
|
$output->writeln('盒子下架日志表创建成功!');
|
|
} catch (\Exception $e) {
|
|
$output->writeln('创建表时出错:' . $e->getMessage());
|
|
}
|
|
}
|
|
}
|