InitSettingCommand.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. <?php
  2. namespace App\Console\Commands\Base;
  3. use App\Repositories\Models\Base\Admin;
  4. use App\Repositories\Models\Base\Dict;
  5. use App\Repositories\Models\Base\DictDetail;
  6. use App\Repositories\Models\Base\Role;
  7. use App\Repositories\Models\Base\Setting;
  8. use App\Repositories\Models\School\Student;
  9. use Illuminate\Console\Command;
  10. use Illuminate\Support\Arr;
  11. use Illuminate\Support\Facades\DB;
  12. use Illuminate\Support\Facades\Hash;
  13. /**
  14. * Class PresenterCommand
  15. * @package Prettus\Repository\Generators\Commands
  16. * @author Anderson Andrade <contato@andersonandra.de>
  17. */
  18. class InitSettingCommand extends Command
  19. {
  20. /**
  21. * The name of command.
  22. *
  23. * @var string
  24. */
  25. protected $signature = 'init:setting';
  26. /**
  27. * The description of command.
  28. *
  29. * @var string
  30. */
  31. protected $description = 'init setting';
  32. /**
  33. * The type of class being generated.
  34. *
  35. * @var string
  36. */
  37. protected $type = 'setting';
  38. /**
  39. * Execute the command.
  40. *
  41. * @return void
  42. * @see fire()
  43. */
  44. public function handle()
  45. {
  46. // $this->clear();
  47. // $this->initSetting();
  48. $this->initDict();
  49. // $this->initRole();
  50. // $this->initUser();
  51. $this->line('配置初始化成功');
  52. }
  53. /**
  54. * 初始化字典
  55. * @return void
  56. */
  57. public function initDict()
  58. {
  59. // 01中共党员、02中共预备党员、03共青团员、04民革党员、05民盟盟员、06民建会员、07民进会员、08农工党党员、09致公党党员、10九三学社社员、11台盟盟员、12无党派人士、13群众
  60. $dicts = [];
  61. $dicts[] = [
  62. 'name' => '政治面貌',
  63. 'code' => 'STUDENT_ZHENGZHIMIANMAO',
  64. 'is_system' => 1,
  65. 'options' => [
  66. [
  67. 'name' => '中共党员',
  68. 'value' => 1,
  69. ],
  70. [
  71. 'name' => '中共预备党员',
  72. 'value' => 2,
  73. ],
  74. [
  75. 'name' => '共青团员',
  76. 'value' => 3,
  77. ],
  78. [
  79. 'name' => '民革党员',
  80. 'value' => 4,
  81. ],
  82. [
  83. 'name' => '民盟盟员',
  84. 'value' => 5,
  85. ],
  86. [
  87. 'name' => '民建会员',
  88. 'value' => 6,
  89. ],
  90. [
  91. 'name' => '民进会员',
  92. 'value' => 7,
  93. ],
  94. [
  95. 'name' => '农工党党员',
  96. 'value' => 8,
  97. ],
  98. [
  99. 'name' => '致公党党员',
  100. 'value' => 9,
  101. ],
  102. [
  103. 'name' => '九三学社社员',
  104. 'value' => 10,
  105. ],
  106. [
  107. 'name' => '台盟盟员',
  108. 'value' => 11,
  109. ],
  110. [
  111. 'name' => '无党派人士',
  112. 'value' => 12,
  113. ],
  114. [
  115. 'name' => '群众',
  116. 'value' => 13,
  117. ],
  118. ]
  119. ];
  120. $dicts[] = [
  121. 'name' => '宗教信仰',
  122. 'code' => 'STUDENT_ZONGJIAOXINYANG',
  123. 'is_system' => 1,
  124. 'options' => [
  125. [
  126. 'name' => '无',
  127. 'value' => 1,
  128. ],
  129. [
  130. 'name' => '基督教',
  131. 'value' => 2,
  132. ],
  133. [
  134. 'name' => '天主教',
  135. 'value' => 3,
  136. ],
  137. [
  138. 'name' => '伊斯兰教',
  139. 'value' => 4,
  140. ],
  141. [
  142. 'name' => '佛教',
  143. 'value' => 5,
  144. ], [
  145. 'name' => '道教',
  146. 'value' => 6,
  147. ], [
  148. 'name' => '其他',
  149. 'value' => 7,
  150. ],
  151. ]
  152. ];
  153. $dicts[] = [
  154. 'name' => '校区',
  155. 'code' => 'STUDENT_XIAOQU',
  156. 'is_system' => 1,
  157. 'options' => [
  158. [
  159. 'name' => "龙子湖校区",
  160. 'value' => 1,
  161. ],
  162. [
  163. 'name' => '老校区',
  164. 'value' => 2,
  165. ],
  166. [
  167. 'name' => '嵩山校区',
  168. 'value' => 3,
  169. ],
  170. ]
  171. ];
  172. $dicts[] = [
  173. 'name' => '民族',
  174. 'code' => 'STUDENT_NATION',
  175. 'is_system' => 1,
  176. 'options' => Student::map2arr(Student::$nationMaps)
  177. ];
  178. //A型血、B型血、O型血、AB型血四种,再加上RH型血
  179. $dicts[] = [
  180. 'name' => '血型',
  181. 'code' => 'STUDENT_XUEXING',
  182. 'is_system' => 1,
  183. 'options' => [
  184. [
  185. 'name' => "A型血",
  186. 'value' => 1,
  187. ],
  188. [
  189. 'name' => 'B型血',
  190. 'value' => 2,
  191. ],
  192. [
  193. 'name' => 'AB型血',
  194. 'value' => 3,
  195. ],
  196. [
  197. 'name' => 'O型血',
  198. 'value' => 4,
  199. ],
  200. [
  201. 'name' => 'RH型血',
  202. 'value' => 5,
  203. ],
  204. ]
  205. ];
  206. $dicts[] = [
  207. 'name' => '学年',
  208. 'code' => 'STUDENT_XUENIAN',
  209. 'is_system' => 1,
  210. 'options' => [
  211. [
  212. 'name' => "第一学年",
  213. 'value' => 1,
  214. ],
  215. [
  216. 'name' => '第二学年',
  217. 'value' => 2,
  218. ],
  219. [
  220. 'name' => '第三学年',
  221. 'value' => 3,
  222. ],
  223. [
  224. 'name' => '第四学年',
  225. 'value' => 4,
  226. ],
  227. [
  228. 'name' => '第五学年',
  229. 'value' => 5,
  230. ],
  231. ]
  232. ];
  233. //国家奖学金/国家励志奖学金/校内综合奖学金/其他(可填写文本)
  234. $dicts[] = [
  235. 'name' => '奖学金类型',
  236. 'code' => 'STUDENT_JIANGXUEJINLEIXING',
  237. 'is_system' => 1,
  238. 'options' => [
  239. [
  240. 'name' => "国家奖学金",
  241. 'value' => 1,
  242. ],
  243. [
  244. 'name' => '国家励志奖学金',
  245. 'value' => 2,
  246. ],
  247. [
  248. 'name' => '校内综合奖学金',
  249. 'value' => 3,
  250. ],
  251. [
  252. 'name' => '其他',
  253. 'value' => 4,
  254. ],
  255. ]
  256. ];
  257. //生源地贷款/高校助学贷款
  258. $dicts[] = [
  259. 'name' => '贷款类型',
  260. 'code' => 'STUDENT_DAIKUANLEIXING',
  261. 'is_system' => 1,
  262. 'options' => [
  263. [
  264. 'name' => "生源地贷款",
  265. 'value' => 1,
  266. ],
  267. [
  268. 'name' => '高校助学贷款',
  269. 'value' => 2,
  270. ],
  271. ]
  272. ];
  273. $dicts[] = [
  274. 'name' => '荣誉类型',
  275. 'code' => 'STUDENT_RONGYULEIXING',
  276. 'is_system' => 1,
  277. 'options' => [
  278. [
  279. 'name' => "国家级荣誉",
  280. 'value' => 1,
  281. ],
  282. [
  283. 'name' => '省部级',
  284. 'value' => 2,
  285. ],
  286. [
  287. 'name' => '厅局级',
  288. 'value' => 3,
  289. ],
  290. [
  291. 'name' => '校级',
  292. 'value' => 4,
  293. ],
  294. [
  295. 'name' => '院系级',
  296. 'value' => 5,
  297. ],
  298. ]
  299. ];
  300. DB::transaction(function () use ($dicts) {
  301. foreach ($dicts as $data) {
  302. $dict = Dict::query()->updateOrCreate(['code' => $data['code']], Arr::only($data, ['name', 'code', 'is_system']));
  303. foreach ($data['options'] as $option) {
  304. DictDetail::query()->updateOrCreate(['dict_id' => $dict['id'], 'name' => $option['name']], ['dict_id' => $dict['id'], 'name' => $option['name'], 'value' => $option['value']]);
  305. }
  306. }
  307. });
  308. }
  309. public function clear()
  310. {
  311. DB::statement('SET FOREIGN_KEY_CHECKS = 0'); // 禁用外键约束
  312. DB::table('base_admins')->truncate();
  313. DB::table('base_auth')->truncate();
  314. DB::table('base_banners')->truncate();
  315. DB::table('base_departments')->truncate();
  316. DB::table('base_dict_detail')->truncate();
  317. DB::table('base_dicts')->truncate();
  318. DB::table('base_model_has_roles')->truncate();
  319. DB::table('base_model_has_permissions')->truncate();
  320. DB::table('base_permissions')->truncate();
  321. DB::table('base_resources')->truncate();
  322. DB::table('base_role_has_permissions')->truncate();
  323. DB::table('base_roles')->truncate();
  324. DB::table('base_roles_data')->truncate();
  325. DB::table('base_roles_menus')->truncate();
  326. DB::table('base_settings')->truncate();
  327. DB::table('base_tasks')->truncate();
  328. DB::table('base_users')->truncate();
  329. // DB::table('base_category_settings')->truncate();
  330. DB::statement('SET FOREIGN_KEY_CHECKS = 1'); // 启用外键约束
  331. }
  332. public function initUser()
  333. {
  334. $admin = Admin::query()->updateOrCreate([
  335. 'username' => 'superadmin',
  336. 'mobile' => '15225006562',
  337. ], [
  338. 'username' => 'superadmin',
  339. 'name' => '超级管理员',
  340. 'mobile' => '15225006562',
  341. 'type' => '1',
  342. 'email' => '751066209@qq.com',
  343. 'password' => Hash::make('Q1w2e3r4!'),
  344. ]);
  345. $admin->syncRoles('admin');
  346. }
  347. /**
  348. * 初始化配置
  349. * @return void
  350. */
  351. public function initSetting()
  352. {
  353. $settings[] = [
  354. 'name' => '系统上传图片允许格式',
  355. 'tag' => '系统',
  356. 'type' => SettingTypeEnum::STRING,
  357. 'code' => 'system_upload_img_type',
  358. 'value' => 'png,jpg,gif,jpeg',
  359. 'is_system' => 1,
  360. ];
  361. $settings[] = [
  362. 'name' => '系统上传文件允许格式',
  363. 'tag' => '系统',
  364. 'type' => SettingTypeEnum::STRING,
  365. 'code' => 'system_upload_file_type',
  366. 'value' => arr2str(["doc", 'docx', "xls", "pdf", 'xlsx', 'mp4', 'webvtt', 'vtt', "png", "jpg", "gif", 'jpeg'], ','),
  367. 'is_system' => 1,
  368. ];
  369. $settings[] = [
  370. 'name' => '锁屏时间',
  371. 'tag' => '系统',
  372. 'type' => SettingTypeEnum::NUMBER,
  373. 'code' => 'system_auto_lock_minutes',
  374. 'value' => 30,
  375. 'is_system' => 1,
  376. ];
  377. $settings[] = [
  378. 'name' => '用户及隐私协议',
  379. 'tag' => '基础配置',
  380. 'type' => SettingTypeEnum::TEXT,
  381. 'code' => 'h5_base_user_xieyi',
  382. 'value' => '用户及隐私协议',
  383. 'is_system' => 1,
  384. ];
  385. $settings[] = [
  386. 'name' => '用户的第一封信-内容',
  387. 'tag' => '基础配置',
  388. 'type' => SettingTypeEnum::TEXT,
  389. 'code' => 'h5_base_user_diyifengxin',
  390. 'value' => '用户的第一封信 ',
  391. 'is_system' => 1,
  392. ];
  393. $settings[] = [
  394. 'name' => '用户的第一封信-标题',
  395. 'tag' => '基础配置',
  396. 'type' => SettingTypeEnum::STRING,
  397. 'code' => 'h5_base_user_diyifengxin_title',
  398. 'value' => '第一封信标题',
  399. 'is_system' => 1,
  400. ];
  401. $settings[] = [
  402. 'name' => '用户长时间未卖货-时间(小时)',
  403. 'tag' => '基础配置',
  404. 'type' => SettingTypeEnum::NUMBER,
  405. 'code' => 'h5_base_user_no_order_hour',
  406. 'value' => 5,
  407. 'is_system' => 1,
  408. ];
  409. $settings[] = [
  410. 'name' => '用户长时间未卖货-提示',
  411. 'tag' => '基础配置',
  412. 'type' => SettingTypeEnum::STRING,
  413. 'code' => 'h5_base_user_no_order_tip',
  414. 'value' => '您已经好久没有卖货了',
  415. 'is_system' => 1,
  416. ];
  417. $settings[] = [
  418. 'name' => '用户当天学分上升-提示',
  419. 'tag' => '基础配置',
  420. 'type' => SettingTypeEnum::STRING,
  421. 'code' => 'h5_base_user_xuefen_up_tip',
  422. 'value' => '您的学分上升了',
  423. 'is_system' => 1,
  424. ];
  425. $settings[] = [
  426. 'name' => '学分兑换积分-比率',
  427. 'tag' => '基础配置',
  428. 'type' => SettingTypeEnum::NUMBER,
  429. 'code' => 'h5_base_xuefen_to_jifen',
  430. 'value' => 1,
  431. 'is_system' => 1,
  432. ];
  433. $settings[] = [
  434. 'name' => '用户协议',
  435. 'tag' => '基础配置',
  436. 'type' => SettingTypeEnum::TEXT,
  437. 'code' => 'h5_base_user_xieyi',
  438. 'value' => '',
  439. 'is_system' => 1,
  440. ];
  441. $settings[] = [
  442. 'name' => '学霸背景图',
  443. 'tag' => '图片配置',
  444. 'type' => SettingTypeEnum::IMG,
  445. 'code' => 'h5_base_img_xueba_beijingtu',
  446. 'value' => '',
  447. 'is_system' => 1,
  448. ];
  449. $settings[] = [
  450. 'name' => '名次上升-火箭成就图',
  451. 'tag' => '图片配置',
  452. 'type' => SettingTypeEnum::IMG,
  453. 'code' => 'h5_base_img_huojian',
  454. 'value' => '',
  455. 'is_system' => 1,
  456. ];
  457. $settings[] = [
  458. 'name' => '排行榜背景图',
  459. 'tag' => '排行榜配置',
  460. 'type' => SettingTypeEnum::IMG,
  461. 'code' => 'h5_base_img_ranking',
  462. 'value' => '',
  463. 'is_system' => 1,
  464. ];
  465. $settings[] = [
  466. 'name' => '排行榜分组背景图-经销商',
  467. 'tag' => '排行榜配置',
  468. 'type' => SettingTypeEnum::IMG,
  469. 'code' => 'h5_base_img_ranking_group_2',
  470. 'value' => '',
  471. 'is_system' => 1,
  472. ];
  473. $settings[] = [
  474. 'name' => '排行榜分组背景图-批发商',
  475. 'tag' => '排行榜配置',
  476. 'type' => SettingTypeEnum::IMG,
  477. 'code' => 'h5_base_img_ranking_group_3',
  478. 'value' => '',
  479. 'is_system' => 1,
  480. ];
  481. $settings[] = [
  482. 'name' => '是否开启用户组排行榜',
  483. 'tag' => '排行榜配置',
  484. 'type' => SettingTypeEnum::BOOL,
  485. 'code' => 'h5_paihangbang_is_group_user',
  486. 'value' => 0,
  487. 'is_system' => 1,
  488. ];
  489. DB::transaction(function () use ($settings) {
  490. foreach ($settings as $setting) {
  491. unset($setting['value']);
  492. Setting::query()->updateOrCreate(['code' => $setting['code']], $setting);
  493. }
  494. });
  495. }
  496. public function initRole()
  497. {
  498. $roles[] = [
  499. 'name' => 'admin',
  500. 'nickname' => '管理员',
  501. 'guard_name' => 'admins',
  502. 'is_system' => 1,
  503. ];
  504. $roles[] = [
  505. 'name' => 'user',
  506. 'nickname' => '巡检员',
  507. 'guard_name' => 'admins',
  508. 'is_system' => 1,
  509. ];
  510. DB::statement('SET FOREIGN_KEY_CHECKS = 0'); // 禁用外键约束
  511. DB::table('base_roles')->truncate();
  512. DB::statement('SET FOREIGN_KEY_CHECKS = 1'); // 启用外键约束
  513. DB::transaction(function () use ($roles) {
  514. foreach ($roles as $role) {
  515. Role::query()->updateOrCreate(['name' => $role['name']], $role);
  516. }
  517. });
  518. }
  519. }