20220811952588_add_daily_wechat_label_default.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\Company;
  5. use app\model\DailyWechatLabel;
  6. class AddDailyWechatLabelDefault extends Migrator
  7. {
  8. /**
  9. * Change Method.
  10. *
  11. * Write your reversible migrations using this method.
  12. *
  13. * More information on writing migrations is available here:
  14. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  15. *
  16. * The following commands can be used in this method and Phinx will
  17. * automatically reverse them when rolling back:
  18. *
  19. * createTable
  20. * renameTable
  21. * addColumn
  22. * renameColumn
  23. * addIndex
  24. * addForeignKey
  25. *
  26. * Remember to call "create()" or "update()" and NOT "save()" when working
  27. * with the Table class.
  28. */
  29. public function change()
  30. {
  31. $root_ids = Company::where([['company_group', '>', 0]])->column('root_id');
  32. foreach ($root_ids as $v) {
  33. $haveLabel = DailyWechatLabel::where(['root_id'=>$v , 'show'=>1])->count();
  34. if(empty($haveLabel)) DailyWechatLabel::create(['root_id'=>$v , 'label_name'=>'其它' , 'show'=>1]);
  35. }
  36. }
  37. }