20221025154906_add_subjection_to_portrait_table.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\CustomerPortraitField;
  5. use app\model\CustomerPortraitFieldSelect;
  6. class AddSubjectionToPortraitTable 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. subjection
  28. */
  29. public function change()
  30. {
  31. $fieldmod = new CustomerPortraitField;
  32. $fieldselmod = new CustomerPortraitFieldSelect;
  33. $list= CustomerPortraitField::where('keyname','basic_info')->field('id,root_id,name')->select()->toArray();
  34. foreach($list as $p=>$m){
  35. $root_id=$m['root_id'];
  36. $all[]=['name'=>'隶属计划','pid'=>$m['id'],'type'=>3,'isedit'=>1,'root_id'=>$root_id,'status'=>0,'isdel'=>1,'keyname'=>'subjection_plan','unity'=>'','is_status'=>0,'isedit_type'=>1,'sort'=>28];
  37. }
  38. $childObjs = $fieldmod->saveAll($all);
  39. foreach($childObjs as $key=>$val){
  40. $add[]=['name'=>'年中大促销','pid'=>$val->getAttr('id')];
  41. $add[]=['name'=>'装修报价','pid'=>$val->getAttr('id')];
  42. }
  43. $fieldselmod->saveAll($add);
  44. }
  45. }