20221228090924_update_smart_screen_default_data3.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\SmartScreen;
  5. use app\model\SmartScreenCate;
  6. use app\model\Company;
  7. class UpdateSmartScreenDefaultData3 extends Migrator
  8. {
  9. /**
  10. * Change Method.
  11. *
  12. * Write your reversible migrations using this method.
  13. *
  14. * More information on writing migrations is available here:
  15. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  16. *
  17. * The following commands can be used in this method and Phinx will
  18. * automatically reverse them when rolling back:
  19. *
  20. * createTable
  21. * renameTable
  22. * addColumn
  23. * renameColumn
  24. * addIndex
  25. * addForeignKey
  26. *
  27. * Remember to call "create()" or "update()" and NOT "save()" when working
  28. * with the Table class.
  29. */
  30. public function change()
  31. {
  32. //默认数据
  33. $arr = ['introduce'=>'公司简介#0','pattern'=>'模式优势#0','boutique'=>'精品设计#1','science'=>'材料#0','major'=>'大牌软装#0','customized'=>'定制家具#0','realistic'=>'实景样板房#0','praise'=>'口碑及服务#0','platinum'=>'铂金工程#0'];
  34. $root_ids = Company::where('1=1')->column('root_id');
  35. //
  36. foreach ($root_ids as $v) {
  37. foreach ($arr as $k2 => $v2) {
  38. //一级
  39. $s = explode('#',$v2);
  40. $pid = SmartScreenCate::insertGetId([
  41. 'root_id'=>$v,
  42. 'title'=>$s[0],
  43. 'code'=>$k2,
  44. 'pid'=>0,
  45. 'is_case'=>$s[1],
  46. 'level'=>1
  47. ]);
  48. }
  49. }
  50. }
  51. }