12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- use think\migration\Migrator;
- use think\migration\db\Column;
- use app\model\Company;
- use app\model\TalkskillUsersCate;
- use app\model\Permission;
- class CreateTalkskillCate 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()
- {
- $table = $this->table('talkskill_users_cate')->setComment('话术使用人群');
- $table->addColumn('root_id', 'integer', ['limit' => 10, 'comment' => '店面id', 'null' => true, 'default' => 0])
- ->addColumn('name', 'string', ['limit' => 100, 'comment' => '名称', 'null' => true, 'default' => ''])
- ->addColumn('addtime', 'timestamp', ['comment' => '预约时间', 'default' => 'CURRENT_TIMESTAMP', 'null' => true])
- ->create();
- $this->table('talkskill')
- ->addColumn('user_cate', 'string', ['limit' => 100, 'comment' => '使用人群', 'null' => true, 'default' => ''])
- ->update();
- $this->table('talkskill_comment')
- ->addColumn('user_cate', 'string', ['limit' => 100, 'comment' => '使用人群', 'null' => true, 'default' => ''])
- ->update();
- //权限
- $per = ',talkskill/person,talkskill/person_list,talkskill/person_add,talkskill/person_edit';
- $w[] = ['auth_name', '=', '话术管理'];
- $w[] = ['pid', '>', 0];
- $w[] = ['is_menu', '=', 1];
- $info = Permission::where($w)->find();
- $per = $info->relation . $per;
- $info->relation = $per;
- $info->save();
- //默认数据
- $root_ids = Company::where([['company_group', '>', 0]])->column('root_id');
- $saves = [];
- $arr = ['业务部', '网销部', '设计师', '客户经理'];
- foreach ($root_ids as $v) {
- foreach ($arr as $v2) {
- $saves[] = [
- 'root_id' => $v,
- 'name' => $v2
- ];
- }
- }
-
- (new TalkskillUsersCate())->saveAll($saves);
- }
- }
|