12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- use app\model\ExamEmpResult;
- use app\model\ExamPaper;
- use think\migration\Migrator;
- use think\migration\db\Column;
- class AddEndmaketimeToExamResult extends Migrator
- {
- /**
- * Change Method.
- *
- * Write your reversible migrations using this method.
- *
- * More information on writing migrations is available here:
- * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
- *
- * The following commands can be used in this method and Phinx will
- * automatically reverse them when rolling back:
- *
- * createTable
- * renameTable
- * addColumn
- * renameColumn
- * addIndex
- * addForeignKey
- *
- * Remember to call "create()" or "update()" and NOT "save()" when working
- * with the Table class.
- */
- public function change()
- {
- $this->table('exam_emp_result')
- ->addColumn('endmaketime', 'integer', ['comment' => '考试结束时间', 'default' => 0])
- ->update();
- $paper = ExamPaper::column('duringtime*60 as duringtime, endtime', 'id');
- $result = ExamEmpResult::select();
- // 更新时间
- foreach ($result as $r) {
- $r->startmaketime = date('Y-m-d H:i:s', strtotime($r->addtime) - $r->time_spend * 60);
- $endTime = strtotime($r->startmaketime) + $paper[$r->paper_id]['duringtime'];
- $paperEndtime = strtotime($paper[$r->paper_id]['endtime']);
- if ($endTime > $paperEndtime) $endTime = $paperEndtime;
- $r->endmaketime = $endTime;
- $r->save();
- }
- }
- }
|