123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- use think\migration\Migrator;
- use think\migration\db\Column;
- use app\model\TalkskillCates;
- use app\model\Talkskill;
- use app\model\Company;
- use app\model\TalkskillLabel;
- class AddSceneFeldsToTalkskill 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()
- {
- $this->table('talkskill')
- ->addColumn('house_type', 'string',['limit' => 255,'comment'=>'房屋类型','null' => true,'default'=>''])
- ->addColumn('cate1', 'string',['limit' => 255,'comment'=>'一级分类','null' => true,'default'=>''])
- ->addColumn('cate2', 'string',['limit' => 255,'comment'=>'二级分类','null' => true,'default'=>''])
- ->update();
- $this->table('talkskill_users_cate')
- ->addColumn('from_type', 'integer', ['limit' => 10, 'comment' => '来源类型,0自建/1集团/2其它店面', 'null' => true, 'default' => 0])
- ->addColumn('from_root_id', 'integer', ['limit' => 10, 'comment' => '0为自建/其它店面', 'null' => true, 'default' => 0])
- ->addColumn('from_content_id', 'integer', ['limit' => 10, 'comment' => '0为自建/内容id', 'null' => true, 'default' => 0])
- ->update();
- $table = $this->table('talkskill_cates')->setComment('话术分类管理');
- $table->addColumn('root_id', 'integer', ['limit' => 10, 'comment' => '店面id', 'null' => true, 'default' => 0])
- ->addColumn('pid', 'integer', ['limit' => 10, 'comment' => '父级id', 'null' => true, 'default' => 0])
- ->addColumn('type', 'string', ['limit' => 255,'comment'=>'类型','null' => true,'default'=>''])
- ->addColumn('name', 'string', ['limit' => 100, 'comment' => '名称', 'null' => true, 'default' => ''])
- ->addColumn('from_type', 'integer', ['limit' => 10, 'comment' => '来源类型,0自建/1集团/2其它店面', 'null' => true, 'default' => 0])
- ->addColumn('from_root_id', 'integer', ['limit' => 10, 'comment' => '0为自建/其它店面', 'null' => true, 'default' => 0])
- ->addColumn('from_content_id', 'integer', ['limit' => 10, 'comment' => '0为自建/内容id', 'null' => true, 'default' => 0])
- ->addColumn('addtime', 'timestamp', ['comment' => '预约时间', 'default' => 'CURRENT_TIMESTAMP', 'null' => true])
- ->create();
- $cates = [
- '开场邀约' => ['直播活动','样板征集','团购活动','量房设计'],
- '添加微信' => ['加微验证','加微短信','电话加微'],
- '引导挖需' => ['基础信息','谁来做主','过往经验','竞品情况','装修需求'],
- '建立信任' => ['企业文化','产品模式','客户见证','设计实力','材料实力','施工实力','性价比优','售后承诺'],
- '产品介绍' => ['产品内容','产品优势','装修流程'],
- '异议处理' => ['价格问题','考虑问题','对比问题','不急问题'],
- '其他' => []
- ];
- $root_ids = Company::where('1=1')->column('root_id');
- $saves = [];
- foreach ($root_ids as $v) {
- foreach ($cates as $k2 => $v2) {
- $psave = [
- 'pid' => 0,
- 'type' => 'cate',
- 'root_id' => $v,
- 'name' => $k2
- ];
- $pid = TalkskillCates::insertGetId($psave);
- $save = [];
- foreach ($v2 as $k3 => $v3) {
- $save[] = [
- 'pid' => $pid,
- 'type' => 'cate',
- 'root_id' => $v,
- 'name' => $v3
- ];
- }
- if($save) (new TalkskillCates())->saveAll($save);
- unset($save);
- unset($psave);
- }
- }
-
- //旧场景数据添加到其他中
- foreach ($root_ids as $k4 => $v4) {
- //pid
- $w1 = [];
- $w1[] = ['name','=','其他'];
- $w1[] = ['root_id','=',$v4];
- $w1[] = ['pid','=',0];
- $w1[] = ['type','=','cate'];
- $pid = TalkskillCates::where($w1)->value('id');
- //查询原始场景
- $w = [];
- $w[] = ['root_id','=',$v4];
- $labels = TalkskillLabel::where($w)->field('label_name name,root_id,from_type,from_root_id,from_content_id,'.$pid.' as pid,"cate" as type')->select()->toarray();
- if($labels && $pid) (new TalkskillCates())->saveAll($labels);
- unset($w1);
- unset($w);
- }
- //房屋类型
- $arr = ['毛坯期房','毛坯现房','毛坯准现房','老房翻新','精装房期房','精装房准现房','精装房现房'];
- $fsave = [];
- foreach ($root_ids as $k5 => $v5) {
- foreach ($arr as $k6 => $v6) {
- $fsave[] = [
- 'pid' => 0,
- 'root_id' => $v5,
- 'type' => 'house_type',
- 'name' => $v6
- ];
- }
- }
- if ($fsave) (new TalkskillCates())->saveAll($fsave);
- }
- }
|