20220721065532_add_scene_felds_to_talkskill.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\TalkskillCates;
  5. use app\model\Talkskill;
  6. use app\model\Company;
  7. use app\model\TalkskillLabel;
  8. class AddSceneFeldsToTalkskill extends Migrator
  9. {
  10. /**
  11. * Change Method.
  12. *
  13. * Write your reversible migrations using this method.
  14. *
  15. * More information on writing migrations is available here:
  16. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  17. *
  18. * The following commands can be used in this method and Phinx will
  19. * automatically reverse them when rolling back:
  20. *
  21. * createTable
  22. * renameTable
  23. * addColumn
  24. * renameColumn
  25. * addIndex
  26. * addForeignKey
  27. *
  28. * Remember to call "create()" or "update()" and NOT "save()" when working
  29. * with the Table class.
  30. */
  31. public function change()
  32. {
  33. $this->table('talkskill')
  34. ->addColumn('house_type', 'string',['limit' => 255,'comment'=>'房屋类型','null' => true,'default'=>''])
  35. ->addColumn('cate1', 'string',['limit' => 255,'comment'=>'一级分类','null' => true,'default'=>''])
  36. ->addColumn('cate2', 'string',['limit' => 255,'comment'=>'二级分类','null' => true,'default'=>''])
  37. ->update();
  38. $this->table('talkskill_users_cate')
  39. ->addColumn('from_type', 'integer', ['limit' => 10, 'comment' => '来源类型,0自建/1集团/2其它店面', 'null' => true, 'default' => 0])
  40. ->addColumn('from_root_id', 'integer', ['limit' => 10, 'comment' => '0为自建/其它店面', 'null' => true, 'default' => 0])
  41. ->addColumn('from_content_id', 'integer', ['limit' => 10, 'comment' => '0为自建/内容id', 'null' => true, 'default' => 0])
  42. ->update();
  43. $table = $this->table('talkskill_cates')->setComment('话术分类管理');
  44. $table->addColumn('root_id', 'integer', ['limit' => 10, 'comment' => '店面id', 'null' => true, 'default' => 0])
  45. ->addColumn('pid', 'integer', ['limit' => 10, 'comment' => '父级id', 'null' => true, 'default' => 0])
  46. ->addColumn('type', 'string', ['limit' => 255,'comment'=>'类型','null' => true,'default'=>''])
  47. ->addColumn('name', 'string', ['limit' => 100, 'comment' => '名称', 'null' => true, 'default' => ''])
  48. ->addColumn('from_type', 'integer', ['limit' => 10, 'comment' => '来源类型,0自建/1集团/2其它店面', 'null' => true, 'default' => 0])
  49. ->addColumn('from_root_id', 'integer', ['limit' => 10, 'comment' => '0为自建/其它店面', 'null' => true, 'default' => 0])
  50. ->addColumn('from_content_id', 'integer', ['limit' => 10, 'comment' => '0为自建/内容id', 'null' => true, 'default' => 0])
  51. ->addColumn('addtime', 'timestamp', ['comment' => '预约时间', 'default' => 'CURRENT_TIMESTAMP', 'null' => true])
  52. ->create();
  53. $cates = [
  54. '开场邀约' => ['直播活动','样板征集','团购活动','量房设计'],
  55. '添加微信' => ['加微验证','加微短信','电话加微'],
  56. '引导挖需' => ['基础信息','谁来做主','过往经验','竞品情况','装修需求'],
  57. '建立信任' => ['企业文化','产品模式','客户见证','设计实力','材料实力','施工实力','性价比优','售后承诺'],
  58. '产品介绍' => ['产品内容','产品优势','装修流程'],
  59. '异议处理' => ['价格问题','考虑问题','对比问题','不急问题'],
  60. '其他' => []
  61. ];
  62. $root_ids = Company::where('1=1')->column('root_id');
  63. $saves = [];
  64. foreach ($root_ids as $v) {
  65. foreach ($cates as $k2 => $v2) {
  66. $psave = [
  67. 'pid' => 0,
  68. 'type' => 'cate',
  69. 'root_id' => $v,
  70. 'name' => $k2
  71. ];
  72. $pid = TalkskillCates::insertGetId($psave);
  73. $save = [];
  74. foreach ($v2 as $k3 => $v3) {
  75. $save[] = [
  76. 'pid' => $pid,
  77. 'type' => 'cate',
  78. 'root_id' => $v,
  79. 'name' => $v3
  80. ];
  81. }
  82. if($save) (new TalkskillCates())->saveAll($save);
  83. unset($save);
  84. unset($psave);
  85. }
  86. }
  87. //旧场景数据添加到其他中
  88. foreach ($root_ids as $k4 => $v4) {
  89. //pid
  90. $w1 = [];
  91. $w1[] = ['name','=','其他'];
  92. $w1[] = ['root_id','=',$v4];
  93. $w1[] = ['pid','=',0];
  94. $w1[] = ['type','=','cate'];
  95. $pid = TalkskillCates::where($w1)->value('id');
  96. //查询原始场景
  97. $w = [];
  98. $w[] = ['root_id','=',$v4];
  99. $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();
  100. if($labels && $pid) (new TalkskillCates())->saveAll($labels);
  101. unset($w1);
  102. unset($w);
  103. }
  104. //房屋类型
  105. $arr = ['毛坯期房','毛坯现房','毛坯准现房','老房翻新','精装房期房','精装房准现房','精装房现房'];
  106. $fsave = [];
  107. foreach ($root_ids as $k5 => $v5) {
  108. foreach ($arr as $k6 => $v6) {
  109. $fsave[] = [
  110. 'pid' => 0,
  111. 'root_id' => $v5,
  112. 'type' => 'house_type',
  113. 'name' => $v6
  114. ];
  115. }
  116. }
  117. if ($fsave) (new TalkskillCates())->saveAll($fsave);
  118. }
  119. }