Index.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\admin\controller;
  14. use app\admin\controller\Base;
  15. use think\Controller;
  16. use think\Db;
  17. class Index extends Base
  18. {
  19. public function index()
  20. {
  21. $language_db = Db::name('language');
  22. /*多语言列表*/
  23. $web_language_switch = tpCache('web.web_language_switch');
  24. $languages = [];
  25. if (1 == intval($web_language_switch)) {
  26. $languages = $language_db->field('a.mark, a.title')
  27. ->alias('a')
  28. ->where('a.status',1)
  29. ->getAllWithIndex('mark');
  30. }
  31. $this->assign('languages', $languages);
  32. $this->assign('web_language_switch', $web_language_switch);
  33. /*--end*/
  34. /*小程序开关*/
  35. $web_diyminipro_switch = tpCache('web.web_diyminipro_switch');
  36. if (!is_dir('./weapp/Diyminipro/') || $this->admin_lang != $this->main_lang) {
  37. $web_diyminipro_switch = -1;
  38. }
  39. $this->assign('web_diyminipro_switch', $web_diyminipro_switch);
  40. /*end*/
  41. /*网站首页链接*/
  42. // 去掉入口文件
  43. $inletStr = '/index.php';
  44. $seo_inlet = config('ey_config.seo_inlet');
  45. 1 == intval($seo_inlet) && $inletStr = '';
  46. // --end
  47. $home_default_lang = config('ey_config.system_home_default_lang');
  48. $admin_lang = $this->admin_lang;
  49. $home_url = request()->domain().ROOT_DIR.'/'; // 支持子目录
  50. if ($home_default_lang != $admin_lang) {
  51. $home_url = $language_db->where(['mark'=>$admin_lang])->getField('url');
  52. if (empty($home_url)) {
  53. $seoConfig = tpCache('seo');
  54. $seo_pseudo = !empty($seoConfig['seo_pseudo']) ? $seoConfig['seo_pseudo'] : config('ey_config.seo_pseudo');
  55. if (1 == $seo_pseudo) {
  56. $home_url = request()->domain().ROOT_DIR.$inletStr; // 支持子目录
  57. if (!empty($inletStr)) {
  58. $home_url .= '?';
  59. } else {
  60. $home_url .= '/?';
  61. }
  62. $home_url .= http_build_query(['lang'=>$admin_lang]);
  63. } else {
  64. $home_url = request()->domain().ROOT_DIR.$inletStr.'/'.$admin_lang; // 支持子目录
  65. }
  66. }
  67. }
  68. $this->assign('home_url', $home_url);
  69. /*--end*/
  70. $this->assign('admin_info', getAdminInfo(session('admin_id')));
  71. $this->assign('menu',getMenuList());
  72. /*检测是否存在会员中心模板*/
  73. $globalConfig = tpCache('global');
  74. if ('v1.0.1' > getVersion('version_themeusers') && !empty($globalConfig['web_users_switch'])) {
  75. $is_syn_theme_users = 1;
  76. } else {
  77. $is_syn_theme_users = 0;
  78. }
  79. $this->assign('is_syn_theme_users',$is_syn_theme_users);
  80. /*--end*/
  81. return $this->fetch();
  82. }
  83. public function welcome()
  84. {
  85. $globalConfig = tpCache('global');
  86. /*百度分享*/
  87. /* $share = array(
  88. 'bdText' => $globalConfig['web_title'],
  89. 'bdPic' => is_http_url($globalConfig['web_logo']) ? $globalConfig['web_logo'] : request()->domain().$globalConfig['web_logo'],
  90. 'bdUrl' => $globalConfig['web_basehost'],
  91. );
  92. $this->assign('share',$share);*/
  93. /*--end*/
  94. /*小程序组件更新*/
  95. $is_update_component_access = 1;
  96. if (!is_dir('./weapp/Diyminipro/') || $this->admin_lang != $this->main_lang) {
  97. $is_update_component_access = 0;
  98. }
  99. $this->assign('is_update_component_access', $is_update_component_access);
  100. /*end*/
  101. // 纠正上传附件的大小,始终以空间大小为准
  102. $file_size = $globalConfig['file_size'];
  103. $maxFileupload = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : 0;
  104. $maxFileupload = intval($maxFileupload);
  105. if (empty($file_size) || $file_size > $maxFileupload) {
  106. /*多语言*/
  107. if (is_language()) {
  108. $langRow = Db::name('language')->cache(true, EYOUCMS_CACHE_TIME, 'language')
  109. ->order('id asc')
  110. ->select();
  111. foreach ($langRow as $key => $val) {
  112. tpCache('basic', ['file_size'=>$maxFileupload], $val['mark']);
  113. }
  114. } else { // 单语言
  115. tpCache('basic', ['file_size'=>$maxFileupload]);
  116. }
  117. /*--end*/
  118. }
  119. /*未备份数据库提示*/
  120. $system_explanation_welcome = !empty($globalConfig['system_explanation_welcome']) ? $globalConfig['system_explanation_welcome'] : 0;
  121. $sqlfiles = glob(DATA_PATH.'sqldata/*');
  122. foreach ($sqlfiles as $file) {
  123. if(stristr($file, getCmsVersion())){
  124. $system_explanation_welcome = 1;
  125. }
  126. }
  127. $this->assign('system_explanation_welcome', $system_explanation_welcome);
  128. /*--end*/
  129. /*检查密码复杂度*/
  130. $admin_login_pwdlevel = -1;
  131. $system_explanation_welcome_2 = !empty($globalConfig['system_explanation_welcome_2']) ? $globalConfig['system_explanation_welcome_2'] : 0;
  132. if (empty($system_explanation_welcome_2)) {
  133. $admin_login_pwdlevel = session('admin_login_pwdlevel');
  134. if (!session('?admin_login_pwdlevel') || 3 < intval($admin_login_pwdlevel)) {
  135. $system_explanation_welcome_2 = 1;
  136. }
  137. }
  138. $this->assign('admin_login_pwdlevel', $admin_login_pwdlevel);
  139. $this->assign('system_explanation_welcome_2', $system_explanation_welcome_2);
  140. /*end*/
  141. // 同步导航与内容统计的状态
  142. $this->syn_open_quickmenu();
  143. // 快捷导航
  144. $quickMenu = Db::name('quickentry')->where([
  145. 'type' => 1,
  146. 'checked' => 1,
  147. 'status' => 1,
  148. ])->order('sort_order asc, id asc')->select();
  149. foreach ($quickMenu as $key => $val) {
  150. $quickMenu[$key]['vars'] = !empty($val['vars']) ? $val['vars']."&lang=".$this->admin_lang : "lang=".$this->admin_lang;
  151. }
  152. $this->assign('quickMenu',$quickMenu);
  153. // 内容统计
  154. $contentTotal = $this->contentTotalList();
  155. $this->assign('contentTotal',$contentTotal);
  156. // 服务器信息
  157. $this->assign('sys_info',$this->get_sys_info());
  158. // 升级弹窗
  159. $this->assign('web_show_popup_upgrade', $globalConfig['web_show_popup_upgrade']);
  160. // 升级系统时,同时处理sql语句
  161. $this->synExecuteSql();
  162. $ajaxLogic = new \app\admin\logic\AjaxLogic;
  163. $ajaxLogic->update_template('users'); // 升级前台会员中心的模板文件
  164. $ajaxLogic->syn_guestbook_attribute(); // 只同步一次每个留言栏目的字段列表前4个显示(v1.5.1节点去掉)
  165. $ajaxLogic->syn_wechat_login_config(); // 只同步一次微信登录配置信息(v1.5.1节点去掉)
  166. $ajaxLogic->system_langnum_file(); // 记录当前是多语言还是单语言到文件里
  167. $ajaxLogic->syn_admin_logic_sms_template(); // 同步手机短信模板(v1.5.1节点去掉)
  168. $ajaxLogic->admin_logic_unlink(); // 删除多余Minipro的文件(v1.5.1节点去掉)
  169. $ajaxLogic->admin_logic_update_basic(); // 纠正允许上传文件类型(v1.5.1节点去掉)
  170. $ajaxLogic->admin_logic_update_tag(); // 纠正tag标签的阅读权限(v1.5.1节点去掉)
  171. $ajaxLogic->admin_logic_update_arctype(); // 纠正批量新增栏目的错误层级(v1.5.1节点去掉)
  172. return $this->fetch();
  173. }
  174. /**
  175. * 升级系统时,同时处理sql语句
  176. * @return [type] [description]
  177. */
  178. private function synExecuteSql()
  179. {
  180. // 新增订单提醒的邮箱模板
  181. if (!tpCache('system.system_smtp_tpl_5')){
  182. /*多语言*/
  183. if (is_language()) {
  184. $langRow = Db::name('language')->cache(true, EYOUCMS_CACHE_TIME, 'language')
  185. ->order('id asc')
  186. ->select();
  187. foreach ($langRow as $key => $val) {
  188. $r = Db::name('smtp_tpl')->insert([
  189. 'tpl_name' => '订单提醒',
  190. 'tpl_title' => '您有新的订单消息,请查收!',
  191. 'tpl_content' => '${content}',
  192. 'send_scene' => 5,
  193. 'is_open' => 1,
  194. 'lang' => $val['mark'],
  195. 'add_time' => getTime(),
  196. ]);
  197. false !== $r && tpCache('system', ['system_smtp_tpl_5' => 1], $val['mark']);
  198. }
  199. } else { // 单语言
  200. $r = Db::name('smtp_tpl')->insert([
  201. 'tpl_name' => '订单提醒',
  202. 'tpl_title' => '您有新的订单消息,请查收!',
  203. 'tpl_content' => '${content}',
  204. 'send_scene' => 5,
  205. 'is_open' => 1,
  206. 'lang' => $this->admin_lang,
  207. 'add_time' => getTime(),
  208. ]);
  209. false !== $r && tpCache('system', ['system_smtp_tpl_5' => 1]);
  210. }
  211. /*--end*/
  212. }
  213. }
  214. /**
  215. * 内容统计管理
  216. */
  217. public function ajax_content_total()
  218. {
  219. if (IS_AJAX_POST) {
  220. $checkedids = input('post.checkedids/a', []);
  221. $ids = input('post.ids/a', []);
  222. $saveData = [];
  223. foreach ($ids as $key => $val) {
  224. if (in_array($val, $checkedids)) {
  225. $checked = 1;
  226. } else {
  227. $checked = 0;
  228. }
  229. $saveData[$key] = [
  230. 'id' => $val,
  231. 'checked' => $checked,
  232. 'sort_order' => intval($key) + 1,
  233. 'update_time' => getTime(),
  234. ];
  235. }
  236. if (!empty($saveData)) {
  237. $r = model('Quickentry')->saveAll($saveData);
  238. if ($r) {
  239. $this->success('操作成功', url('Index/welcome'));
  240. }
  241. }
  242. $this->error('操作失败');
  243. }
  244. /*同步v1.3.9以及早期版本的自定义模型*/
  245. $this->syn_custom_quickmenu(2);
  246. /*end*/
  247. $totalList = Db::name('quickentry')->where([
  248. 'type' => ['IN', [2]],
  249. 'status' => 1,
  250. ])->order('sort_order asc, id asc')->select();
  251. $this->assign('totalList',$totalList);
  252. return $this->fetch();
  253. }
  254. /**
  255. * 内容统计 - 数量处理
  256. */
  257. private function contentTotalList()
  258. {
  259. $archivesTotalRow = null;
  260. $quickentryList = Db::name('quickentry')->where([
  261. 'type' => 2,
  262. 'checked' => 1,
  263. 'status' => 1,
  264. ])->order('sort_order asc, id asc')->select();
  265. foreach ($quickentryList as $key => $val) {
  266. $code = $val['controller'].'@'.$val['action'].'@'.$val['vars'];
  267. $quickentryList[$key]['vars'] = !empty($val['vars']) ? $val['vars']."&lang=".$this->admin_lang : "lang=".$this->admin_lang;
  268. if ($code == 'Guestbook@index@channel=8') // 留言列表
  269. {
  270. $map = [
  271. 'lang' => $this->admin_lang,
  272. ];
  273. $quickentryList[$key]['total'] = Db::name('guestbook')->where($map)->count();
  274. }
  275. else if (1 == $val['groups']) // 模型内容统计
  276. {
  277. if (null === $archivesTotalRow) {
  278. $map = [
  279. 'lang' => $this->admin_lang,
  280. 'status' => 1,
  281. 'is_del' => 0,
  282. ];
  283. /*权限控制 by 小虎哥*/
  284. $admin_info = session('admin_info');
  285. if (0 < intval($admin_info['role_id'])) {
  286. $auth_role_info = $admin_info['auth_role_info'];
  287. if(! empty($auth_role_info)){
  288. if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
  289. $map['admin_id'] = $admin_info['admin_id'];
  290. }
  291. }
  292. }
  293. /*--end*/
  294. $archivesTotalRow = Db::name('archives')->field('channel, count(aid) as total')->where($map)->group('channel')
  295. ->getAllWithIndex('channel');
  296. }
  297. parse_str($val['vars'], $vars);
  298. $total = !empty($archivesTotalRow[$vars['channel']]['total']) ? intval($archivesTotalRow[$vars['channel']]['total']) : 0;
  299. $quickentryList[$key]['total'] = $total;
  300. }
  301. else if ($code == 'AdPosition@index@') // 广告
  302. {
  303. $map = [
  304. 'lang' => $this->admin_lang,
  305. 'is_del' => 0,
  306. ];
  307. $quickentryList[$key]['total'] = Db::name('ad_position')->where($map)->count();
  308. }
  309. else if ($code == 'Links@index@') // 友情链接
  310. {
  311. $map = [
  312. 'lang' => $this->admin_lang,
  313. ];
  314. $quickentryList[$key]['total'] = Db::name('links')->where($map)->count();
  315. }
  316. else if ($code == 'Tags@index@') // Tags标签
  317. {
  318. $map = [
  319. 'lang' => $this->admin_lang,
  320. ];
  321. $quickentryList[$key]['total'] = Db::name('tagindex')->where($map)->count();
  322. }
  323. else if ($code == 'Member@users_index@') // 会员
  324. {
  325. $map = [
  326. 'lang' => $this->admin_lang,
  327. 'is_del' => 0,
  328. ];
  329. $quickentryList[$key]['total'] = Db::name('users')->where($map)->count();
  330. }
  331. else if ($code == 'Shop@index@') // 订单
  332. {
  333. $map = [
  334. 'lang' => $this->admin_lang,
  335. ];
  336. $quickentryList[$key]['total'] = Db::name('shop_order')->where($map)->count();
  337. }
  338. }
  339. return $quickentryList;
  340. }
  341. /**
  342. * 快捷导航管理
  343. */
  344. public function ajax_quickmenu()
  345. {
  346. if (IS_AJAX_POST) {
  347. $checkedids = input('post.checkedids/a', []);
  348. $ids = input('post.ids/a', []);
  349. $saveData = [];
  350. foreach ($ids as $key => $val) {
  351. if (in_array($val, $checkedids)) {
  352. $checked = 1;
  353. } else {
  354. $checked = 0;
  355. }
  356. $saveData[$key] = [
  357. 'id' => $val,
  358. 'checked' => $checked,
  359. 'sort_order' => intval($key) + 1,
  360. 'update_time' => getTime(),
  361. ];
  362. }
  363. if (!empty($saveData)) {
  364. $r = model('Quickentry')->saveAll($saveData);
  365. if ($r) {
  366. $this->success('操作成功', url('Index/welcome'));
  367. }
  368. }
  369. $this->error('操作失败');
  370. }
  371. /*同步v1.3.9以及早期版本的自定义模型*/
  372. $this->syn_custom_quickmenu(1);
  373. /*end*/
  374. $menuList = Db::name('quickentry')->where([
  375. 'type' => ['IN', [1]],
  376. 'groups' => 0,
  377. 'status' => 1,
  378. ])->order('sort_order asc, id asc')->select();
  379. $this->assign('menuList',$menuList);
  380. return $this->fetch();
  381. }
  382. /**
  383. * 同步自定义模型的快捷导航
  384. */
  385. private function syn_custom_quickmenu($type = 1)
  386. {
  387. $row = Db::name('quickentry')->where([
  388. 'controller' => 'Custom',
  389. 'type' => $type,
  390. ])->count();
  391. if (empty($row)) {
  392. $customRow = Db::name('channeltype')->field('id,ntitle')
  393. ->where(['ifsystem'=>0])->select();
  394. $saveData = [];
  395. foreach ($customRow as $key => $val) {
  396. $saveData[] = [
  397. 'title' => $val['ntitle'],
  398. 'laytext' => $val['ntitle'].'列表',
  399. 'type' => $type,
  400. 'controller' => 'Custom',
  401. 'action' => 'index',
  402. 'vars' => 'channel='.$val['id'],
  403. 'groups' => 1,
  404. 'sort_order' => 100,
  405. 'add_time' => getTime(),
  406. 'update_time' => getTime(),
  407. ];
  408. }
  409. model('Quickentry')->saveAll($saveData);
  410. }
  411. }
  412. /**
  413. * 同步受开关控制的导航和内容统计
  414. */
  415. private function syn_open_quickmenu()
  416. {
  417. $tpcacheConfig = tpCache('global');
  418. $usersConfig = getUsersConfigData('all');
  419. /*商城中心 - 受本身开关和会员中心开关控制*/
  420. if (!empty($tpcacheConfig['web_users_switch']) && !empty($usersConfig['shop_open'])) {
  421. $shop_open = 1;
  422. } else {
  423. $shop_open = 0;
  424. }
  425. /*end*/
  426. $saveData = [
  427. [
  428. 'id' => 31,
  429. 'status' => !empty($tpcacheConfig['web_users_switch']) ? 1 : 0,
  430. 'update_time' => getTime(),
  431. ],
  432. [
  433. 'id' => 32,
  434. 'status' => (1 == $tpcacheConfig['web_weapp_switch']) ? 1 : 0,
  435. 'update_time' => getTime(),
  436. ],
  437. [
  438. 'id' => 33,
  439. 'status' => !empty($tpcacheConfig['web_users_switch']) ? 1 : 0,
  440. 'update_time' => getTime(),
  441. ],
  442. [
  443. 'id' => 34,
  444. 'status' => $shop_open,
  445. 'update_time' => getTime(),
  446. ],
  447. [
  448. 'id' => 35,
  449. 'status' => $shop_open,
  450. 'update_time' => getTime(),
  451. ],
  452. ];
  453. model('Quickentry')->saveAll($saveData);
  454. /*处理模型导航和统计*/
  455. $channeltypeRow = Db::name('channeltype')->cache(true,EYOUCMS_CACHE_TIME,"channeltype")->select();
  456. foreach ($channeltypeRow as $key => $val) {
  457. $updateData = [
  458. 'groups' => 1,
  459. 'vars' => 'channel='.$val['id'],
  460. 'status' => $val['status'],
  461. 'update_time' => getTime(),
  462. ];
  463. Db::name('quickentry')->where([
  464. 'vars' => 'channel='.$val['id']
  465. ])->update($updateData);
  466. }
  467. /*end*/
  468. }
  469. /**
  470. * 服务器信息
  471. */
  472. private function get_sys_info()
  473. {
  474. $sys_info['os'] = PHP_OS;
  475. $sys_info['zlib'] = function_exists('gzclose') ? 'YES' : '<font color="red">NO(请开启 php.ini 中的php-zlib扩展)</font>';//zlib
  476. $sys_info['safe_mode'] = (boolean) ini_get('safe_mode') ? 'YES' : 'NO';//safe_mode = Off
  477. $sys_info['timezone'] = function_exists("date_default_timezone_get") ? date_default_timezone_get() : "no_timezone";
  478. $sys_info['curl'] = function_exists('curl_init') ? 'YES' : '<font color="red">NO(请开启 php.ini 中的php-curl扩展)</font>';
  479. $sys_info['web_server'] = $_SERVER['SERVER_SOFTWARE'];
  480. $sys_info['phpv'] = phpversion();
  481. $sys_info['ip'] = serverIP();
  482. $sys_info['postsize'] = @ini_get('file_uploads') ? ini_get('post_max_size') :'未知';
  483. $sys_info['fileupload'] = @ini_get('file_uploads') ? ini_get('upload_max_filesize') :'未开启';
  484. $sys_info['max_ex_time'] = @ini_get("max_execution_time").'s'; //脚本最大执行时间
  485. $sys_info['set_time_limit'] = function_exists("set_time_limit") ? true : false;
  486. $sys_info['domain'] = $_SERVER['HTTP_HOST'];
  487. $sys_info['memory_limit'] = ini_get('memory_limit');
  488. $sys_info['version'] = file_get_contents(DATA_PATH.'conf/version.txt');
  489. $mysqlinfo = Db::query("SELECT VERSION() as version");
  490. $sys_info['mysql_version'] = $mysqlinfo[0]['version'];
  491. if(function_exists("gd_info")){
  492. $gd = gd_info();
  493. $sys_info['gdinfo'] = $gd['GD Version'];
  494. }else {
  495. $sys_info['gdinfo'] = "未知";
  496. }
  497. if (extension_loaded('zip')) {
  498. $sys_info['zip'] = "YES";
  499. } else {
  500. $sys_info['zip'] = '<font color="red">NO(请开启 php.ini 中的php-zip扩展)</font>';
  501. }
  502. $upgradeLogic = new \app\admin\logic\UpgradeLogic();
  503. $sys_info['curent_version'] = $upgradeLogic->curent_version; //当前程序版本
  504. $sys_info['web_name'] = tpCache('global.web_name');
  505. return $sys_info;
  506. }
  507. /**
  508. * 录入商业授权
  509. */
  510. public function authortoken()
  511. {
  512. $domain = config('service_ey');
  513. $domain = base64_decode($domain);
  514. $vaules = array(
  515. 'client_domain' => urldecode($this->request->host(true)),
  516. );
  517. $url = $domain.'/index.php?m=api&c=Service&a=check_authortoken&'.http_build_query($vaules);
  518. $context = stream_context_set_default(array('http' => array('timeout' => 3,'method'=>'GET')));
  519. $response = @file_get_contents($url,false,$context);
  520. $params = json_decode($response,true);
  521. if (false === $response || (is_array($params) && 1 == $params['code'])) {
  522. $web_authortoken = $params['msg'];
  523. /*多语言*/
  524. if (is_language()) {
  525. $langRow = Db::name('language')->cache(true, EYOUCMS_CACHE_TIME, 'language')
  526. ->order('id asc')
  527. ->select();
  528. foreach ($langRow as $key => $val) {
  529. tpCache('web', ['web_authortoken'=>$web_authortoken], $val['mark']);
  530. }
  531. } else { // 单语言
  532. tpCache('web', array('web_authortoken'=>$web_authortoken));
  533. }
  534. /*--end*/
  535. $source = realpath('public/static/admin/images/logo_ey.png');
  536. $destination = realpath('public/static/admin/images/logo.png');
  537. @copy($source, $destination);
  538. delFile(RUNTIME_PATH.'html'); // 清空缓存页面
  539. session('isset_author', null);
  540. adminLog('验证商业授权');
  541. $this->success('域名授权成功', request()->baseFile(), '', 1, [], '_parent');
  542. }
  543. $this->error('域名('.$this->request->domain().')未授权', request()->baseFile(), '', 3, [], '_parent');
  544. }
  545. /**
  546. * 更换后台logo
  547. */
  548. public function edit_adminlogo()
  549. {
  550. $filename = input('param.filename/s', '');
  551. if (!empty($filename)) {
  552. $source = realpath(preg_replace('#^'.ROOT_DIR.'/#i', '', $filename)); // 支持子目录
  553. $web_is_authortoken = tpCache('web.web_is_authortoken');
  554. if (empty($web_is_authortoken)) {
  555. $destination = realpath('public/static/admin/images/logo.png');
  556. } else {
  557. $destination = realpath('public/static/admin/images/logo_ey.png');
  558. }
  559. if (@copy($source, $destination)) {
  560. $this->success('操作成功');
  561. }
  562. }
  563. $this->error('操作失败');
  564. }
  565. /**
  566. * 待处理事项
  567. */
  568. public function pending_matters()
  569. {
  570. $html = '<div style="text-align: center; margin: 20px 0px; color:red;">惹妹子生气了,没啥好处理!</div>';
  571. echo $html;
  572. }
  573. /**
  574. * ajax 修改指定表数据字段 一般修改状态 比如 是否推荐 是否开启 等 图标切换的
  575. * table,id_name,id_value,field,value
  576. */
  577. public function changeTableVal()
  578. {
  579. if (IS_AJAX_POST) {
  580. $url = null;
  581. $data = [
  582. 'refresh' => 0,
  583. ];
  584. $param = input('param.');
  585. $table = input('param.table/s'); // 表名
  586. $id_name = input('param.id_name/s'); // 表主键id名
  587. $id_value = input('param.id_value/d'); // 表主键id值
  588. $field = input('param.field/s'); // 修改哪个字段
  589. $value = input('param.value/s', '', null); // 修改字段值
  590. $value = eyPreventShell($value) ? $value : strip_sql($value);
  591. /*插件专用*/
  592. if ('weapp' == $table) {
  593. if (1 == intval($value)) { // 启用
  594. action('Weapp/enable', ['id' => $id_value]);
  595. } else if (-1 == intval($value)) { // 禁用
  596. action('Weapp/disable', ['id' => $id_value]);
  597. }
  598. }
  599. /*end*/
  600. /*处理数据的安全性*/
  601. if (empty($id_value)) {
  602. $this->error('查询条件id不合法!');
  603. }
  604. foreach ($param as $key => $val) {
  605. if ('value' == $key) {
  606. continue;
  607. }
  608. if (!preg_match('/^([A-Za-z0-9_-]*)$/i', $val)) {
  609. $this->error('数据含有非法入侵字符!');
  610. }
  611. }
  612. /*end*/
  613. switch ($table) {
  614. // 会员等级表
  615. case 'users_level':
  616. {
  617. $return = model('UsersLevel')->isRequired($id_name,$id_value,$field,$value);
  618. if (is_array($return)) {
  619. $this->error($return['msg']);
  620. }
  621. }
  622. break;
  623. // 会员属性表
  624. case 'users_parameter':
  625. {
  626. $return = model('UsersParameter')->isRequired($id_name,$id_value,$field,$value);
  627. if (is_array($return)) {
  628. $this->error($return['msg']);
  629. }
  630. }
  631. break;
  632. // 会员中心菜单表
  633. case 'users_menu':
  634. {
  635. if ('is_userpage' == $field) {
  636. Db::name('users_menu')->where('id','gt',0)->update([
  637. 'is_userpage' => 0,
  638. 'update_time' => getTime(),
  639. ]);
  640. }
  641. $data['refresh'] = 1;
  642. }
  643. break;
  644. // 会员投稿功能
  645. case 'archives':
  646. {
  647. if ('arcrank' == $field) {
  648. if (0 == $value) {
  649. $value = -1;
  650. }else{
  651. $value = 0;
  652. }
  653. }
  654. }
  655. break;
  656. // 会员产品类型表
  657. case 'users_type_manage':
  658. {
  659. if (empty($value)) {
  660. $this->error('不可为空');
  661. }
  662. }
  663. break;
  664. // 留言属性表
  665. case 'guestbook_attribute':
  666. {
  667. $return = model('GuestbookAttribute')->isValidate($id_name,$id_value,$field,$value);
  668. if (is_array($return)) {
  669. $time = !empty($return['time']) ? $return['time'] : 3;
  670. $this->error($return['msg'], null, [], $time);
  671. }
  672. }
  673. break;
  674. // 小程序页面表
  675. case 'diyminipro_page':
  676. {
  677. $re = Db::name('diyminipro_page')->where([
  678. 'is_home' => 1,
  679. $id_name => ['EQ', $id_value],
  680. ])->count();
  681. if (!empty($re)) {
  682. $this->error('禁止取消默认项', null, [], 3);
  683. }
  684. }
  685. break;
  686. default:
  687. # code...
  688. break;
  689. }
  690. $savedata = [
  691. $field => $value,
  692. 'update_time' => getTime(),
  693. ];
  694. switch ($table) {
  695. case 'diyminipro_page':
  696. {
  697. if ('is_home' == $field) {
  698. if ($value == 1) {
  699. $savedata['page_type'] = 1;
  700. } else {
  701. $savedata['page_type'] = -1;
  702. }
  703. }
  704. break;
  705. }
  706. }
  707. $r = Db::name($table)->where([$id_name => $id_value])->cache(true,null,$table)->save($savedata); // 根据条件保存修改的数据
  708. if ($r !== false) {
  709. // 以下代码可以考虑去掉,与行为里的清除缓存重复 AppEndBehavior.php / clearHtmlCache
  710. switch ($table) {
  711. case 'auth_modular':
  712. extra_cache('admin_auth_modular_list_logic', null);
  713. extra_cache('admin_all_menu', null);
  714. break;
  715. case 'diyminipro_page':
  716. {
  717. if ('is_home' == $field) {
  718. $data['refresh'] = 1;
  719. Db::name('diyminipro_page')->where([
  720. $id_name => ['NEQ', $id_value],
  721. 'lang' => $this->admin_lang,
  722. ])->update([
  723. 'is_home' => 0,
  724. 'page_type' => -1,
  725. 'update_time' => getTime()
  726. ]);
  727. }
  728. break;
  729. }
  730. // 会员投稿功能
  731. case 'archives':
  732. {
  733. if ('arcrank' == $field) {
  734. Db::name('taglist')->where('aid', $id_value)->update([
  735. 'arcrank'=>$value,
  736. 'update_time' => getTime(),
  737. ]);
  738. }
  739. break;
  740. }
  741. default:
  742. // 清除logic逻辑定义的缓存
  743. extra_cache('admin_'.$table.'_list_logic', null);
  744. // 清除一下缓存
  745. // delFile(RUNTIME_PATH.'html'); // 先清除缓存, 否则不好预览
  746. \think\Cache::clear($table);
  747. break;
  748. }
  749. $this->success('更新成功', $url, $data);
  750. }
  751. $this->error('更新失败', null, []);
  752. }
  753. }
  754. /**
  755. * 功能开关
  756. */
  757. public function switch_map()
  758. {
  759. if (IS_POST) {
  760. $inc_type = input('post.inc_type/s');
  761. $name = input('post.name/s');
  762. $value = input('post.value/s');
  763. $data = [];
  764. switch ($inc_type) {
  765. case 'pay':
  766. case 'shop':
  767. {
  768. getUsersConfigData($inc_type, [$name => $value]);
  769. // 开启商城
  770. if (1 == $value) {
  771. /*多语言 - 同时开启会员中心*/
  772. if (is_language()) {
  773. $langRow = \think\Db::name('language')->order('id asc')
  774. ->cache(true, EYOUCMS_CACHE_TIME, 'language')
  775. ->select();
  776. foreach ($langRow as $key => $val) {
  777. tpCache('web', ['web_users_switch' => 1], $val['mark']);
  778. }
  779. } else { // 单语言
  780. tpCache('web', ['web_users_switch' => 1]);
  781. }
  782. /*--end*/
  783. // 同时显示发布文档时的价格文本框
  784. Db::name('channelfield')->where([
  785. 'name' => 'users_price',
  786. 'channel_id' => 2,
  787. ])->update([
  788. 'ifeditable' => 1,
  789. 'update_time' => getTime(),
  790. ]);
  791. }
  792. if (in_array($name, ['shop_open'])) {
  793. // $data['reload'] = 1;
  794. /*检测是否存在订单中心模板*/
  795. if ('v1.0.1' > getVersion('version_themeshop') && !empty($value)) {
  796. $is_syn = 1;
  797. } else {
  798. $is_syn = 0;
  799. }
  800. $data['is_syn'] = $is_syn;
  801. /*--end*/
  802. // 同步会员中心的左侧菜单
  803. if ('shop_open' == $name) {
  804. Db::name('users_menu')->where([
  805. 'mca' => 'user/Shop/shop_centre',
  806. 'lang' => $this->admin_lang,
  807. ])->update([
  808. 'status' => (1 == $value) ? 1 : 0,
  809. 'update_time' => getTime(),
  810. ]);
  811. }
  812. } else if ('pay_open' == $name) {
  813. // 同步会员中心的左侧菜单
  814. Db::name('users_menu')->where([
  815. 'mca' => 'user/Pay/pay_consumer_details',
  816. 'lang' => $this->admin_lang,
  817. ])->update([
  818. 'status' => (1 == $value) ? 1 : 0,
  819. 'update_time' => getTime(),
  820. ]);
  821. }
  822. break;
  823. }
  824. case 'users':
  825. {
  826. // 会员投稿
  827. $r = Db::name('users_menu')->where([
  828. 'mca' => 'user/UsersRelease/release_centre',
  829. 'lang' => $this->admin_lang,
  830. ])->update([
  831. 'status' => (1 == $value) ? 1 : 0,
  832. 'update_time' => getTime(),
  833. ]);
  834. if ($r) {
  835. getUsersConfigData($inc_type, [$name => $value]);
  836. if (1 == $value) {
  837. /*多语言 - 同时开启会员中心*/
  838. if (is_language()) {
  839. $langRow = \think\Db::name('language')->order('id asc')
  840. ->cache(true, EYOUCMS_CACHE_TIME, 'language')
  841. ->select();
  842. foreach ($langRow as $key => $val) {
  843. tpCache('web', ['web_users_switch' => 1], $val['mark']);
  844. }
  845. } else { // 单语言
  846. tpCache('web', ['web_users_switch' => 1]);
  847. }
  848. /*--end*/
  849. }
  850. }
  851. break;
  852. }
  853. case 'level':
  854. {
  855. // 会员升级
  856. $r = Db::name('users_menu')->where([
  857. 'mca' => 'user/Level/level_centre',
  858. 'lang' => $this->admin_lang,
  859. ])->update([
  860. 'status' => (1 == $value) ? 1 : 0,
  861. 'update_time' => getTime(),
  862. ]);
  863. if ($r) {
  864. getUsersConfigData($inc_type, [$name => $value]);
  865. if (1 == $value) {
  866. /*多语言 - 同时开启会员中心*/
  867. if (is_language()) {
  868. $langRow = \think\Db::name('language')->order('id asc')
  869. ->cache(true, EYOUCMS_CACHE_TIME, 'language')
  870. ->select();
  871. foreach ($langRow as $key => $val) {
  872. tpCache('web', ['web_users_switch' => 1], $val['mark']);
  873. }
  874. } else { // 单语言
  875. tpCache('web', ['web_users_switch' => 1]);
  876. }
  877. /*--end*/
  878. }
  879. }
  880. break;
  881. }
  882. case 'web':
  883. {
  884. /*多语言*/
  885. if (is_language()) {
  886. $langRow = \think\Db::name('language')->order('id asc')
  887. ->cache(true, EYOUCMS_CACHE_TIME, 'language')
  888. ->select();
  889. foreach ($langRow as $key => $val) {
  890. tpCache($inc_type, [$name => $value], $val['mark']);
  891. }
  892. } else { // 单语言
  893. tpCache($inc_type, [$name => $value]);
  894. }
  895. /*--end*/
  896. if (in_array($name, ['web_users_switch'])) {
  897. // $data['reload'] = 1;
  898. /*检测是否存在会员中心模板*/
  899. if ('v1.0.1' > getVersion('version_themeusers') && !empty($value)) {
  900. $is_syn = 1;
  901. } else {
  902. $is_syn = 0;
  903. }
  904. $data['is_syn'] = $is_syn;
  905. /*--end*/
  906. } else if ($name == 'web_language_switch') { // 多语言开关
  907. // 统计多语言数量
  908. model('Language')->setLangNum();
  909. // 重新生成sitemap.xml
  910. sitemap_all();
  911. }
  912. break;
  913. }
  914. }
  915. $this->success('操作成功', null, $data);
  916. }
  917. $globalConfig = tpCache('global');
  918. $this->assign('globalConfig', $globalConfig);
  919. $UsersConfigData = getUsersConfigData('all');
  920. $this->assign('userConfig',$UsersConfigData);
  921. $is_online = 0;
  922. if (is_realdomain()) {
  923. $is_online = 1;
  924. }
  925. $this->assign('is_online',$is_online);
  926. /*检测是否存在会员中心模板*/
  927. if ('v1.0.1' > getVersion('version_themeusers')) {
  928. $is_themeusers_exist = 1;
  929. } else {
  930. $is_themeusers_exist = 0;
  931. }
  932. $this->assign('is_themeusers_exist',$is_themeusers_exist);
  933. /*--end*/
  934. /*检测是否存在商城中心模板*/
  935. if ('v1.0.1' > getVersion('version_themeshop')) {
  936. $is_themeshop_exist = 1;
  937. } else {
  938. $is_themeshop_exist = 0;
  939. }
  940. $this->assign('is_themeshop_exist',$is_themeshop_exist);
  941. /*--end*/
  942. return $this->fetch();
  943. }
  944. }