Files
zzp-server/app/common/command/ItemProgress.php
2026-01-19 14:19:22 +08:00

43 lines
1.1 KiB
PHP

<?php
namespace app\common\command;
use app\common\model\item\Item;
use think\console\{Command,Output,Input};
use think\facade\{Db,Log};
class ItemProgress extends Command
{
protected function configure()
{
$this->setName('item_progress')
->setDescription('项目进度自增');
}
protected function execute(Input $input, Output $output)
{
Db::startTrans();
try {
$items = Item::where(['is_show' => 1])
->order(['create_time' => 'desc'])
->select()
->toArray();
foreach ($items as &$item) {
if($item['progress'] >= 100) continue;
$item['progress'] = $item['progress'] + $item['progress_auto'];
Item::update([
'id' => $item['id'],
'progress' => $item['progress'],
]);
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
Log::write('失败原因:' . $e->getMessage());
return false;
}
}
}