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); } }