20220715130719_update_data_to_company_strength.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\Permission;
  5. use app\model\CompanyStrengthCate;
  6. use app\model\Company;
  7. class UpdateDataToCompanyStrength 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. CompanyStrengthCate::where('1=1')->delete();
  34. $root_ids = Company::where('1=1')->column('root_id');
  35. $saves = [];
  36. $arr = ['公司产品介绍','材料品类介绍','材料实验室','实景案例','设计师包装' ,'工艺标准','团队服务','客户口碑','企业宣传','老板个人包装','销售培训端','客户使用端'];
  37. foreach ($root_ids as $v) {
  38. foreach ($arr as $v2) {
  39. $saves[] = [
  40. 'root_id' => $v,
  41. 'name' => $v2
  42. ];
  43. }
  44. }
  45. (new CompanyStrengthCate())->saveAll($saves);
  46. }
  47. }