123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- use think\migration\Migrator;
- use think\migration\db\Column;
- use app\model\CustomerPortrait;
- class UpdateProtraitTableData extends Migrator
- {
- /**
- * Change Method.
- *
- * Write your reversible migrations using this method.
- *
- * More information on writing migrations is available here:
- * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
- *
- * The following commands can be used in this method and Phinx will
- * automatically reverse them when rolling back:
- *
- * createTable
- * renameTable
- * addColumn
- * renameColumn
- * addIndex
- * addForeignKey
- *
- * Remember to call "create()" or "update()" and NOT "save()" when working
- * with the Table class.
- */
- public function change()
- {
- (new CustomerPortrait())->select()->each(function ($item){
- $content = json_decode($item['fields'], true);
- if (isset($content['behavioral_info']['free_time'])){
- $content['family_info']['free_time'] = $content['behavioral_info']['free_time'];
- }
- if (isset($content['other_info']['car_price'])) {
- $content['family_info']['car_price'] = $content['other_info']['car_price'];
- }
- if (isset($content['other_info']['hourse_price'])) {
- $content['family_info']['hourse_price'] = $content['other_info']['hourse_price'];
- }
- if (isset($content['other_info']['buying_community'])) {
- $content['family_info']['buying_community'] = $content['other_info']['buying_community'];
- }
- if (isset($content['other_info']['peripheral_supporting'])) {
- $content['family_info']['peripheral_supporting'] = $content['other_info']['peripheral_supporting'];
- }
- unset($content['behavioral_info']['free_time']);
- unset($content['other_info']['car_price']);
- unset($content['other_info']['hourse_price']);
- unset($content['other_info']['buying_community']);
- unset($content['other_info']['peripheral_supporting']);
- $item->fields = json_encode($content);
- $item->save();
- });
- }
- }
|