first commit
This commit is contained in:
43
app/common/command/ItemProgress.php
Normal file
43
app/common/command/ItemProgress.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user