123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561 |
- <?php
- namespace App\Console\Commands\Base;
- use App\Repositories\Models\Base\Admin;
- use App\Repositories\Models\Base\Dict;
- use App\Repositories\Models\Base\DictDetail;
- use App\Repositories\Models\Base\Role;
- use App\Repositories\Models\Base\Setting;
- use App\Repositories\Models\School\Student;
- use Illuminate\Console\Command;
- use Illuminate\Support\Arr;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Hash;
- /**
- * Class PresenterCommand
- * @package Prettus\Repository\Generators\Commands
- * @author Anderson Andrade <contato@andersonandra.de>
- */
- class InitSettingCommand extends Command
- {
- /**
- * The name of command.
- *
- * @var string
- */
- protected $signature = 'init:setting';
- /**
- * The description of command.
- *
- * @var string
- */
- protected $description = 'init setting';
- /**
- * The type of class being generated.
- *
- * @var string
- */
- protected $type = 'setting';
- /**
- * Execute the command.
- *
- * @return void
- * @see fire()
- */
- public function handle()
- {
- // $this->clear();
- // $this->initSetting();
- $this->initDict();
- // $this->initRole();
- // $this->initUser();
- $this->line('配置初始化成功');
- }
- /**
- * 初始化字典
- * @return void
- */
- public function initDict()
- {
- // 01中共党员、02中共预备党员、03共青团员、04民革党员、05民盟盟员、06民建会员、07民进会员、08农工党党员、09致公党党员、10九三学社社员、11台盟盟员、12无党派人士、13群众
- $dicts = [];
- $dicts[] = [
- 'name' => '政治面貌',
- 'code' => 'STUDENT_ZHENGZHIMIANMAO',
- 'is_system' => 1,
- 'options' => [
- [
- 'name' => '中共党员',
- 'value' => 1,
- ],
- [
- 'name' => '中共预备党员',
- 'value' => 2,
- ],
- [
- 'name' => '共青团员',
- 'value' => 3,
- ],
- [
- 'name' => '民革党员',
- 'value' => 4,
- ],
- [
- 'name' => '民盟盟员',
- 'value' => 5,
- ],
- [
- 'name' => '民建会员',
- 'value' => 6,
- ],
- [
- 'name' => '民进会员',
- 'value' => 7,
- ],
- [
- 'name' => '农工党党员',
- 'value' => 8,
- ],
- [
- 'name' => '致公党党员',
- 'value' => 9,
- ],
- [
- 'name' => '九三学社社员',
- 'value' => 10,
- ],
- [
- 'name' => '台盟盟员',
- 'value' => 11,
- ],
- [
- 'name' => '无党派人士',
- 'value' => 12,
- ],
- [
- 'name' => '群众',
- 'value' => 13,
- ],
- ]
- ];
- $dicts[] = [
- 'name' => '宗教信仰',
- 'code' => 'STUDENT_ZONGJIAOXINYANG',
- 'is_system' => 1,
- 'options' => [
- [
- 'name' => '无',
- 'value' => 1,
- ],
- [
- 'name' => '基督教',
- 'value' => 2,
- ],
- [
- 'name' => '天主教',
- 'value' => 3,
- ],
- [
- 'name' => '伊斯兰教',
- 'value' => 4,
- ],
- [
- 'name' => '佛教',
- 'value' => 5,
- ], [
- 'name' => '道教',
- 'value' => 6,
- ], [
- 'name' => '其他',
- 'value' => 7,
- ],
- ]
- ];
- $dicts[] = [
- 'name' => '校区',
- 'code' => 'STUDENT_XIAOQU',
- 'is_system' => 1,
- 'options' => [
- [
- 'name' => "龙子湖校区",
- 'value' => 1,
- ],
- [
- 'name' => '老校区',
- 'value' => 2,
- ],
- [
- 'name' => '嵩山校区',
- 'value' => 3,
- ],
- ]
- ];
- $dicts[] = [
- 'name' => '民族',
- 'code' => 'STUDENT_NATION',
- 'is_system' => 1,
- 'options' => Student::map2arr(Student::$nationMaps)
- ];
- //A型血、B型血、O型血、AB型血四种,再加上RH型血
- $dicts[] = [
- 'name' => '血型',
- 'code' => 'STUDENT_XUEXING',
- 'is_system' => 1,
- 'options' => [
- [
- 'name' => "A型血",
- 'value' => 1,
- ],
- [
- 'name' => 'B型血',
- 'value' => 2,
- ],
- [
- 'name' => 'AB型血',
- 'value' => 3,
- ],
- [
- 'name' => 'O型血',
- 'value' => 4,
- ],
- [
- 'name' => 'RH型血',
- 'value' => 5,
- ],
- ]
- ];
- $dicts[] = [
- 'name' => '学年',
- 'code' => 'STUDENT_XUENIAN',
- 'is_system' => 1,
- 'options' => [
- [
- 'name' => "第一学年",
- 'value' => 1,
- ],
- [
- 'name' => '第二学年',
- 'value' => 2,
- ],
- [
- 'name' => '第三学年',
- 'value' => 3,
- ],
- [
- 'name' => '第四学年',
- 'value' => 4,
- ],
- [
- 'name' => '第五学年',
- 'value' => 5,
- ],
- ]
- ];
- //国家奖学金/国家励志奖学金/校内综合奖学金/其他(可填写文本)
- $dicts[] = [
- 'name' => '奖学金类型',
- 'code' => 'STUDENT_JIANGXUEJINLEIXING',
- 'is_system' => 1,
- 'options' => [
- [
- 'name' => "国家奖学金",
- 'value' => 1,
- ],
- [
- 'name' => '国家励志奖学金',
- 'value' => 2,
- ],
- [
- 'name' => '校内综合奖学金',
- 'value' => 3,
- ],
- [
- 'name' => '其他',
- 'value' => 4,
- ],
- ]
- ];
- //生源地贷款/高校助学贷款
- $dicts[] = [
- 'name' => '贷款类型',
- 'code' => 'STUDENT_DAIKUANLEIXING',
- 'is_system' => 1,
- 'options' => [
- [
- 'name' => "生源地贷款",
- 'value' => 1,
- ],
- [
- 'name' => '高校助学贷款',
- 'value' => 2,
- ],
- ]
- ];
- $dicts[] = [
- 'name' => '荣誉类型',
- 'code' => 'STUDENT_RONGYULEIXING',
- 'is_system' => 1,
- 'options' => [
- [
- 'name' => "国家级荣誉",
- 'value' => 1,
- ],
- [
- 'name' => '省部级',
- 'value' => 2,
- ],
- [
- 'name' => '厅局级',
- 'value' => 3,
- ],
- [
- 'name' => '校级',
- 'value' => 4,
- ],
- [
- 'name' => '院系级',
- 'value' => 5,
- ],
- ]
- ];
- DB::transaction(function () use ($dicts) {
- foreach ($dicts as $data) {
- $dict = Dict::query()->updateOrCreate(['code' => $data['code']], Arr::only($data, ['name', 'code', 'is_system']));
- foreach ($data['options'] as $option) {
- DictDetail::query()->updateOrCreate(['dict_id' => $dict['id'], 'name' => $option['name']], ['dict_id' => $dict['id'], 'name' => $option['name'], 'value' => $option['value']]);
- }
- }
- });
- }
- public function clear()
- {
- DB::statement('SET FOREIGN_KEY_CHECKS = 0'); // 禁用外键约束
- DB::table('base_admins')->truncate();
- DB::table('base_auth')->truncate();
- DB::table('base_banners')->truncate();
- DB::table('base_departments')->truncate();
- DB::table('base_dict_detail')->truncate();
- DB::table('base_dicts')->truncate();
- DB::table('base_model_has_roles')->truncate();
- DB::table('base_model_has_permissions')->truncate();
- DB::table('base_permissions')->truncate();
- DB::table('base_resources')->truncate();
- DB::table('base_role_has_permissions')->truncate();
- DB::table('base_roles')->truncate();
- DB::table('base_roles_data')->truncate();
- DB::table('base_roles_menus')->truncate();
- DB::table('base_settings')->truncate();
- DB::table('base_tasks')->truncate();
- DB::table('base_users')->truncate();
- // DB::table('base_category_settings')->truncate();
- DB::statement('SET FOREIGN_KEY_CHECKS = 1'); // 启用外键约束
- }
- public function initUser()
- {
- $admin = Admin::query()->updateOrCreate([
- 'username' => 'superadmin',
- 'mobile' => '15225006562',
- ], [
- 'username' => 'superadmin',
- 'name' => '超级管理员',
- 'mobile' => '15225006562',
- 'type' => '1',
- 'email' => '751066209@qq.com',
- 'password' => Hash::make('Q1w2e3r4!'),
- ]);
- $admin->syncRoles('admin');
- }
- /**
- * 初始化配置
- * @return void
- */
- public function initSetting()
- {
- $settings[] = [
- 'name' => '系统上传图片允许格式',
- 'tag' => '系统',
- 'type' => SettingTypeEnum::STRING,
- 'code' => 'system_upload_img_type',
- 'value' => 'png,jpg,gif,jpeg',
- 'is_system' => 1,
- ];
- $settings[] = [
- 'name' => '系统上传文件允许格式',
- 'tag' => '系统',
- 'type' => SettingTypeEnum::STRING,
- 'code' => 'system_upload_file_type',
- 'value' => arr2str(["doc", 'docx', "xls", "pdf", 'xlsx', 'mp4', 'webvtt', 'vtt', "png", "jpg", "gif", 'jpeg'], ','),
- 'is_system' => 1,
- ];
- $settings[] = [
- 'name' => '锁屏时间',
- 'tag' => '系统',
- 'type' => SettingTypeEnum::NUMBER,
- 'code' => 'system_auto_lock_minutes',
- 'value' => 30,
- 'is_system' => 1,
- ];
- $settings[] = [
- 'name' => '用户及隐私协议',
- 'tag' => '基础配置',
- 'type' => SettingTypeEnum::TEXT,
- 'code' => 'h5_base_user_xieyi',
- 'value' => '用户及隐私协议',
- 'is_system' => 1,
- ];
- $settings[] = [
- 'name' => '用户的第一封信-内容',
- 'tag' => '基础配置',
- 'type' => SettingTypeEnum::TEXT,
- 'code' => 'h5_base_user_diyifengxin',
- 'value' => '用户的第一封信 ',
- 'is_system' => 1,
- ];
- $settings[] = [
- 'name' => '用户的第一封信-标题',
- 'tag' => '基础配置',
- 'type' => SettingTypeEnum::STRING,
- 'code' => 'h5_base_user_diyifengxin_title',
- 'value' => '第一封信标题',
- 'is_system' => 1,
- ];
- $settings[] = [
- 'name' => '用户长时间未卖货-时间(小时)',
- 'tag' => '基础配置',
- 'type' => SettingTypeEnum::NUMBER,
- 'code' => 'h5_base_user_no_order_hour',
- 'value' => 5,
- 'is_system' => 1,
- ];
- $settings[] = [
- 'name' => '用户长时间未卖货-提示',
- 'tag' => '基础配置',
- 'type' => SettingTypeEnum::STRING,
- 'code' => 'h5_base_user_no_order_tip',
- 'value' => '您已经好久没有卖货了',
- 'is_system' => 1,
- ];
- $settings[] = [
- 'name' => '用户当天学分上升-提示',
- 'tag' => '基础配置',
- 'type' => SettingTypeEnum::STRING,
- 'code' => 'h5_base_user_xuefen_up_tip',
- 'value' => '您的学分上升了',
- 'is_system' => 1,
- ];
- $settings[] = [
- 'name' => '学分兑换积分-比率',
- 'tag' => '基础配置',
- 'type' => SettingTypeEnum::NUMBER,
- 'code' => 'h5_base_xuefen_to_jifen',
- 'value' => 1,
- 'is_system' => 1,
- ];
- $settings[] = [
- 'name' => '用户协议',
- 'tag' => '基础配置',
- 'type' => SettingTypeEnum::TEXT,
- 'code' => 'h5_base_user_xieyi',
- 'value' => '',
- 'is_system' => 1,
- ];
- $settings[] = [
- 'name' => '学霸背景图',
- 'tag' => '图片配置',
- 'type' => SettingTypeEnum::IMG,
- 'code' => 'h5_base_img_xueba_beijingtu',
- 'value' => '',
- 'is_system' => 1,
- ];
- $settings[] = [
- 'name' => '名次上升-火箭成就图',
- 'tag' => '图片配置',
- 'type' => SettingTypeEnum::IMG,
- 'code' => 'h5_base_img_huojian',
- 'value' => '',
- 'is_system' => 1,
- ];
- $settings[] = [
- 'name' => '排行榜背景图',
- 'tag' => '排行榜配置',
- 'type' => SettingTypeEnum::IMG,
- 'code' => 'h5_base_img_ranking',
- 'value' => '',
- 'is_system' => 1,
- ];
- $settings[] = [
- 'name' => '排行榜分组背景图-经销商',
- 'tag' => '排行榜配置',
- 'type' => SettingTypeEnum::IMG,
- 'code' => 'h5_base_img_ranking_group_2',
- 'value' => '',
- 'is_system' => 1,
- ];
- $settings[] = [
- 'name' => '排行榜分组背景图-批发商',
- 'tag' => '排行榜配置',
- 'type' => SettingTypeEnum::IMG,
- 'code' => 'h5_base_img_ranking_group_3',
- 'value' => '',
- 'is_system' => 1,
- ];
- $settings[] = [
- 'name' => '是否开启用户组排行榜',
- 'tag' => '排行榜配置',
- 'type' => SettingTypeEnum::BOOL,
- 'code' => 'h5_paihangbang_is_group_user',
- 'value' => 0,
- 'is_system' => 1,
- ];
- DB::transaction(function () use ($settings) {
- foreach ($settings as $setting) {
- unset($setting['value']);
- Setting::query()->updateOrCreate(['code' => $setting['code']], $setting);
- }
- });
- }
- public function initRole()
- {
- $roles[] = [
- 'name' => 'admin',
- 'nickname' => '管理员',
- 'guard_name' => 'admins',
- 'is_system' => 1,
- ];
- $roles[] = [
- 'name' => 'user',
- 'nickname' => '巡检员',
- 'guard_name' => 'admins',
- 'is_system' => 1,
- ];
- DB::statement('SET FOREIGN_KEY_CHECKS = 0'); // 禁用外键约束
- DB::table('base_roles')->truncate();
- DB::statement('SET FOREIGN_KEY_CHECKS = 1'); // 启用外键约束
- DB::transaction(function () use ($roles) {
- foreach ($roles as $role) {
- Role::query()->updateOrCreate(['name' => $role['name']], $role);
- }
- });
- }
- }
|