SettingController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <?php
  2. // +—————————————————————————————————————————————————————————————————————
  3. // | Created by Yunbao
  4. // +—————————————————————————————————————————————————————————————————————
  5. // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
  6. // +—————————————————————————————————————————————————————————————————————
  7. // | Author: https://gitee.com/yunbaokeji
  8. // +—————————————————————————————————————————————————————————————————————
  9. // | Date: 2022-02-17
  10. // +—————————————————————————————————————————————————————————————————————
  11. namespace app\admin\controller;
  12. use app\admin\model\RouteModel;
  13. use cmf\controller\AdminBaseController;
  14. use think\Db;
  15. /**
  16. * Class SettingController
  17. * @package app\admin\controller
  18. * @adminMenuRoot(
  19. * 'name' =>'设置',
  20. * 'action' =>'default',
  21. * 'parent' =>'',
  22. * 'display'=> true,
  23. * 'order' => 0,
  24. * 'icon' =>'cogs',
  25. * 'remark' =>'系统设置入口'
  26. * )
  27. */
  28. class SettingController extends AdminBaseController
  29. {
  30. /**
  31. * 网站信息
  32. * @adminMenu(
  33. * 'name' => '网站信息',
  34. * 'parent' => 'default',
  35. * 'display'=> true,
  36. * 'hasView'=> true,
  37. * 'order' => 0,
  38. * 'icon' => '',
  39. * 'remark' => '网站信息',
  40. * 'param' => ''
  41. * )
  42. */
  43. public function site()
  44. {
  45. $content = hook_one('admin_setting_site_view');
  46. if (!empty($content)) {
  47. return $content;
  48. }
  49. $noNeedDirs = [".", "..", ".svn", 'fonts'];
  50. $adminThemesDir = WEB_ROOT . config('template.cmf_admin_theme_path') . config('template.cmf_admin_default_theme') . '/public/assets/themes/';
  51. $adminStyles = cmf_scan_dir($adminThemesDir . '*', GLOB_ONLYDIR);
  52. $adminStyles = array_diff($adminStyles, $noNeedDirs);
  53. $cdnSettings = cmf_get_option('cdn_settings');
  54. $cmfSettings = cmf_get_option('cmf_settings');
  55. $adminSettings = cmf_get_option('admin_settings');
  56. $adminThemes = [];
  57. $themes = cmf_scan_dir(WEB_ROOT . config('template.cmf_admin_theme_path') . '/*', GLOB_ONLYDIR);
  58. foreach ($themes as $theme) {
  59. if (strpos($theme, 'admin_') === 0) {
  60. array_push($adminThemes, $theme);
  61. }
  62. }
  63. if (APP_DEBUG && false) { // TODO 没确定要不要可以设置默认应用
  64. $apps = cmf_scan_dir(APP_PATH . '*', GLOB_ONLYDIR);
  65. $apps = array_diff($apps, $noNeedDirs);
  66. $this->assign('apps', $apps);
  67. }
  68. $this->assign('site_info', cmf_get_option('site_info'));
  69. $this->assign("admin_styles", $adminStyles);
  70. $this->assign("templates", []);
  71. $this->assign("admin_themes", $adminThemes);
  72. $this->assign("cdn_settings", $cdnSettings);
  73. $this->assign("admin_settings", $adminSettings);
  74. $this->assign("cmf_settings", $cmfSettings);
  75. return $this->fetch();
  76. }
  77. /**
  78. * 网站信息设置提交
  79. * @adminMenu(
  80. * 'name' => '网站信息设置提交',
  81. * 'parent' => 'site',
  82. * 'display'=> false,
  83. * 'hasView'=> false,
  84. * 'order' => 10000,
  85. * 'icon' => '',
  86. * 'remark' => '网站信息设置提交',
  87. * 'param' => ''
  88. * )
  89. */
  90. public function sitePost()
  91. {
  92. if ($this->request->isPost()) {
  93. $result = $this->validate($this->request->param(), 'SettingSite');
  94. if ($result !== true) {
  95. $this->error($result);
  96. }
  97. $oldconfig=cmf_get_option('site_info');
  98. $options = $this->request->param('options/a');
  99. $login_type=isset($_POST['login_type'])?$_POST['login_type']:'';
  100. $live_type=isset($_POST['live_type'])?$_POST['live_type']:'';
  101. $options['login_type']='';
  102. $options['live_type']='';
  103. if($login_type){
  104. $options['login_type']=implode(',',$login_type);
  105. }
  106. if($live_type){
  107. $options['live_type']=implode(',',$live_type);
  108. }
  109. if($options['qr_url']!=$options['qr_url_old']){
  110. $options['qr_url']=set_upload_path($options['qr_url']);
  111. }
  112. unset($options['qr_url_old']);
  113. cmf_set_option('site_info', $options,true);
  114. $this->resetcache('getConfigPub',$options);
  115. $cmfSettings = $this->request->param('cmf_settings/a');
  116. $bannedUsernames = preg_replace("/[^0-9A-Za-z_\\x{4e00}-\\x{9fa5}-]/u", ",", $cmfSettings['banned_usernames']);
  117. $cmfSettings['banned_usernames'] = $bannedUsernames;
  118. cmf_set_option('cmf_settings', $cmfSettings,true);
  119. $cdnSettings = $this->request->param('cdn_settings/a');
  120. cmf_set_option('cdn_settings', $cdnSettings,true);
  121. $adminSettings = $this->request->param('admin_settings/a');
  122. $routeModel = new RouteModel();
  123. if (!empty($adminSettings['admin_password'])) {
  124. $routeModel->setRoute($adminSettings['admin_password'] . '$', 'admin/Index/index', [], 2, 5000);
  125. } else {
  126. $routeModel->deleteRoute('admin/Index/index', []);
  127. }
  128. $routeModel->getRoutes(true);
  129. if (!empty($adminSettings['admin_theme'])) {
  130. $result = cmf_set_dynamic_config([
  131. 'template' => [
  132. 'cmf_admin_default_theme' => $adminSettings['admin_theme']
  133. ]
  134. ]);
  135. if ($result === false) {
  136. $this->error('配置写入失败!');
  137. }
  138. }
  139. cmf_set_option('admin_settings', $adminSettings,true);
  140. $this->success("保存成功!", '');
  141. }
  142. }
  143. /**
  144. * 密码修改
  145. * @adminMenu(
  146. * 'name' => '密码修改',
  147. * 'parent' => 'default',
  148. * 'display'=> false,
  149. * 'hasView'=> true,
  150. * 'order' => 10000,
  151. * 'icon' => '',
  152. * 'remark' => '密码修改',
  153. * 'param' => ''
  154. * )
  155. */
  156. public function password()
  157. {
  158. return $this->fetch();
  159. }
  160. /**
  161. * 密码修改提交
  162. * @adminMenu(
  163. * 'name' => '密码修改提交',
  164. * 'parent' => 'password',
  165. * 'display'=> false,
  166. * 'hasView'=> false,
  167. * 'order' => 10000,
  168. * 'icon' => '',
  169. * 'remark' => '密码修改提交',
  170. * 'param' => ''
  171. * )
  172. */
  173. public function passwordPost()
  174. {
  175. if ($this->request->isPost()) {
  176. $data = $this->request->param();
  177. if (empty($data['old_password'])) {
  178. $this->error("原始密码不能为空!");
  179. }
  180. if (empty($data['password'])) {
  181. $this->error("新密码不能为空!");
  182. }
  183. $userId = cmf_get_current_admin_id();
  184. $admin = Db::name('user')->where("id", $userId)->find();
  185. $oldPassword = $data['old_password'];
  186. $password = $data['password'];
  187. $rePassword = $data['re_password'];
  188. if (cmf_compare_password($oldPassword, $admin['user_pass'])) {
  189. if ($password == $rePassword) {
  190. if (cmf_compare_password($password, $admin['user_pass'])) {
  191. $this->error("新密码不能和原始密码相同!");
  192. } else {
  193. Db::name('user')->where('id', $userId)->update(['user_pass' => cmf_password($password)]);
  194. $this->success("密码修改成功!");
  195. }
  196. } else {
  197. $this->error("密码输入不一致!");
  198. }
  199. } else {
  200. $this->error("原始密码不正确!");
  201. }
  202. }
  203. }
  204. /**
  205. * 上传限制设置界面
  206. * @adminMenu(
  207. * 'name' => '上传设置',
  208. * 'parent' => 'default',
  209. * 'display'=> true,
  210. * 'hasView'=> true,
  211. * 'order' => 10000,
  212. * 'icon' => '',
  213. * 'remark' => '上传设置',
  214. * 'param' => ''
  215. * )
  216. */
  217. public function upload()
  218. {
  219. $uploadSetting = cmf_get_upload_setting();
  220. $this->assign('upload_setting', $uploadSetting);
  221. return $this->fetch();
  222. }
  223. /**
  224. * 上传限制设置界面提交
  225. * @adminMenu(
  226. * 'name' => '上传设置提交',
  227. * 'parent' => 'upload',
  228. * 'display'=> false,
  229. * 'hasView'=> false,
  230. * 'order' => 10000,
  231. * 'icon' => '',
  232. * 'remark' => '上传设置提交',
  233. * 'param' => ''
  234. * )
  235. */
  236. public function uploadPost()
  237. {
  238. if ($this->request->isPost()) {
  239. //TODO 非空验证
  240. $uploadSetting = $this->request->post();
  241. $olduploadSetting = cmf_get_upload_setting();
  242. cmf_set_option('upload_setting', $uploadSetting,true);
  243. $this->success('保存成功!');
  244. }
  245. }
  246. /**
  247. * 清除缓存
  248. * @adminMenu(
  249. * 'name' => '清除缓存',
  250. * 'parent' => 'default',
  251. * 'display'=> false,
  252. * 'hasView'=> true,
  253. * 'order' => 10000,
  254. * 'icon' => '',
  255. * 'remark' => '清除缓存',
  256. * 'param' => ''
  257. * )
  258. */
  259. public function clearCache()
  260. {
  261. $content = hook_one('admin_setting_clear_cache_view');
  262. if (!empty($content)) {
  263. return $content;
  264. }
  265. cmf_clear_cache();
  266. return $this->fetch();
  267. }
  268. /**
  269. * 私密设置
  270. */
  271. public function configpri(){
  272. $siteinfo=cmf_get_option('site_info');
  273. $name_coin=$siteinfo['name_coin'];
  274. $this->assign('name_coin',$name_coin);
  275. $this->assign('config', cmf_get_option('configpri'));
  276. return $this->fetch();
  277. }
  278. /**
  279. * 私密设置提交
  280. */
  281. public function configpriPost(){
  282. if ($this->request->isPost()) {
  283. $oldconfigpri=cmf_get_option('configpri');
  284. $options = $this->request->param('options/a');
  285. if($options['reg_reward']==''){
  286. $this->error("登录配置请填写注册奖励");
  287. }
  288. if(!is_numeric($options['reg_reward'])){
  289. $this->error("注册奖励必须为数字");
  290. }
  291. if(floor($options['reg_reward']) !=$options['reg_reward']){
  292. $this->error("注册奖励必须为整数");
  293. }
  294. if($options['iplimit_times']==''){
  295. $this->error("登录配置请填写短信验证码IP限制次数");
  296. }
  297. if(!is_numeric($options['iplimit_times'])){
  298. $this->error("短信验证码IP限制次数必须为数字");
  299. }
  300. if(floor($options['iplimit_times']) !=$options['iplimit_times']){
  301. $this->error("短信验证码IP限制次数必须为整数");
  302. }
  303. if($options['level_limit']==''){
  304. $this->error("直播配置请填写直播限制等级");
  305. }
  306. if(!is_numeric($options['level_limit'])){
  307. $this->error("直播限制等级必须为数字");
  308. }
  309. if(floor($options['level_limit']) !=$options['level_limit']){
  310. $this->error("直播限制等级必须为整数");
  311. }
  312. if($options['speak_limit']==''){
  313. $this->error("直播配置请填写发言等级限制");
  314. }
  315. if(!is_numeric($options['speak_limit'])){
  316. $this->error("发言等级限制必须为数字");
  317. }
  318. if(floor($options['speak_limit']) !=$options['speak_limit']){
  319. $this->error("发言等级限制必须为整数");
  320. }
  321. if($options['barrage_limit']==''){
  322. $this->error("直播配置请填写弹幕等级限制");
  323. }
  324. if(!is_numeric($options['barrage_limit'])){
  325. $this->error("弹幕等级限制必须为数字");
  326. }
  327. if(floor($options['barrage_limit']) !=$options['barrage_limit']){
  328. $this->error("弹幕等级限制必须为整数");
  329. }
  330. if($options['barrage_fee']==''){
  331. $this->error("直播配置请填写弹幕费用");
  332. }
  333. if(!is_numeric($options['barrage_fee'])){
  334. $this->error("弹幕费用必须为数字");
  335. }
  336. if(floor($options['barrage_fee']) !=$options['barrage_fee']){
  337. $this->error("弹幕费用必须为整数");
  338. }
  339. if($options['userlist_time']==''){
  340. $this->error("直播配置请填写用户列表请求间隔");
  341. }
  342. if(!is_numeric($options['userlist_time'])){
  343. $this->error("用户列表请求间隔必须为数字");
  344. }
  345. if(floor($options['userlist_time']) !=$options['userlist_time']){
  346. $this->error("用户列表请求间隔必须为整数");
  347. }
  348. if($options['userlist_time']<5){
  349. $this->error("用户列表请求间隔不能小于5秒");
  350. }
  351. unset($options['video_watermark_old']);
  352. cmf_set_option('configpri', $options,true);
  353. $this->resetcache('getConfigPri',$options);
  354. $this->success("保存成功!", '');
  355. }
  356. }
  357. protected function resetcache($key='',$info=[]){
  358. if($key!='' && $info){
  359. delcache($key);
  360. setcaches($key,$info);
  361. }
  362. }
  363. }