20220712023003_create_talkskill_cate.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\Company;
  5. use app\model\TalkskillUsersCate;
  6. use app\model\Permission;
  7. class CreateTalkskillCate 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. $table = $this->table('talkskill_users_cate')->setComment('话术使用人群');
  33. $table->addColumn('root_id', 'integer', ['limit' => 10, 'comment' => '店面id', 'null' => true, 'default' => 0])
  34. ->addColumn('name', 'string', ['limit' => 100, 'comment' => '名称', 'null' => true, 'default' => ''])
  35. ->addColumn('addtime', 'timestamp', ['comment' => '预约时间', 'default' => 'CURRENT_TIMESTAMP', 'null' => true])
  36. ->create();
  37. $this->table('talkskill')
  38. ->addColumn('user_cate', 'string', ['limit' => 100, 'comment' => '使用人群', 'null' => true, 'default' => ''])
  39. ->update();
  40. $this->table('talkskill_comment')
  41. ->addColumn('user_cate', 'string', ['limit' => 100, 'comment' => '使用人群', 'null' => true, 'default' => ''])
  42. ->update();
  43. //权限
  44. $per = ',talkskill/person,talkskill/person_list,talkskill/person_add,talkskill/person_edit';
  45. $w[] = ['auth_name', '=', '话术管理'];
  46. $w[] = ['pid', '>', 0];
  47. $w[] = ['is_menu', '=', 1];
  48. $info = Permission::where($w)->find();
  49. $per = $info->relation . $per;
  50. $info->relation = $per;
  51. $info->save();
  52. //默认数据
  53. $root_ids = Company::where([['company_group', '>', 0]])->column('root_id');
  54. $saves = [];
  55. $arr = ['业务部', '网销部', '设计师', '客户经理'];
  56. foreach ($root_ids as $v) {
  57. foreach ($arr as $v2) {
  58. $saves[] = [
  59. 'root_id' => $v,
  60. 'name' => $v2
  61. ];
  62. }
  63. }
  64. (new TalkskillUsersCate())->saveAll($saves);
  65. }
  66. }