20230531190306_add_deposit_mode_to_portrait_table.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 AddDepositModeToPortraitTable 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. $fieldselmod = new CustomerPortraitFieldSelect;
  32. $list= CustomerPortraitField::with(['select'])->where('keyname','deposit_mode')->field('id,root_id,name')->select()->toArray();
  33. foreach($list as $p=>$m){
  34. if(empty($m['select'])) $pids[] = $m['id'];
  35. }
  36. foreach($pids as $key=>$val){
  37. $add[]=['name'=>'线上定金','pid'=>$val];
  38. $add[]=['name'=>'线下定金','pid'=>$val];
  39. }
  40. $fieldselmod->saveAll($add);
  41. CustomerPortraitField::where('keyname','down_payment')->update(['type'=>2]);
  42. }
  43. }