20230608155403_add_old_visit_due_time_to_article.php 715 B

123456789101112131415161718192021222324
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\Permission;
  5. use app\model\Article;
  6. use app\model\Footprints;
  7. class AddOldVisitDueTimeToArticle extends Migrator
  8. {
  9. public function change()
  10. {
  11. $list = Article::column('id,visit_due_time');
  12. foreach($list as $key=>$val){
  13. $foot_where = [];
  14. $foot_where[] = ['pipe_type', '=', 'article'];
  15. $foot_where[] = ['pipe_id', '=', $val['id']];
  16. $alltime = Footprints::where($foot_where)->sum('visit_due_time');
  17. if(!empty($alltime)) $all[] = ['id'=>$val['id'],'visit_due_time'=>$alltime];
  18. }
  19. $mod = new Article;
  20. $mod->saveAll($all);
  21. }
  22. }
  23. ?>