20220813114646_update_data_to_train_class_orders2.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\TrainClassCate;
  5. class UpdateDataToTrainClassOrders2 extends Migrator
  6. {
  7. /**
  8. * Change Method.
  9. *
  10. * Write your reversible migrations using this method.
  11. *
  12. * More information on writing migrations is available here:
  13. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  14. *
  15. * The following commands can be used in this method and Phinx will
  16. * automatically reverse them when rolling back:
  17. *
  18. * createTable
  19. * renameTable
  20. * addColumn
  21. * renameColumn
  22. * addIndex
  23. * addForeignKey
  24. *
  25. * Remember to call "create()" or "update()" and NOT "save()" when working
  26. * with the Table class.
  27. */
  28. public function change()
  29. {
  30. //要修改的店面,装企数字化系统
  31. $root_id = 996;
  32. //,
  33. $arr = ['销冠分享','网销培训','社群培训','市场培训','营销工具'];
  34. $where[] = ['root_id','=',$root_id];
  35. $where[] = ['pid','=',0];
  36. $cate = TrainClassCate::where($where)->select()->toArray();
  37. foreach ($cate as $key => $val) {
  38. $order = array_search($val['name'],$arr);
  39. $order = $order===false ? 50 : $order;
  40. TrainClassCate::where('id',$val['id'])->update(['order'=>$order]);
  41. }
  42. }
  43. }