Index.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <?php
  2. namespace app\home\controller;
  3. use think\Lang;
  4. use think\Cache;
  5. use think\Request;
  6. use think\Controller;
  7. use think\Validate;
  8. /**
  9. * 主页管理类
  10. */
  11. class Index extends Controller
  12. {
  13. /**
  14. * 构造函数
  15. *
  16. * @access public
  17. */
  18. public function __construct()
  19. {
  20. parent::__construct();
  21. }// end__construct()
  22. /**
  23. * 主页管理
  24. *
  25. * @access public
  26. * @return array JsonString
  27. */
  28. public function index()
  29. {
  30. // 获取导航.
  31. $navigationField = [
  32. 'navigation_zhName',
  33. 'navigation_enName',
  34. 'navigation_id',
  35. ];
  36. $navigationWhere = ['navigation_type' => 1];
  37. $getNavigation = model('Navigation')->getSelect($navigationField, $navigationWhere);
  38. $this->assign('navigation', $getNavigation);
  39. // 导航Id.
  40. $navigationId = [
  41. 'home',
  42. 'service',
  43. 'count',
  44. 'about-us',
  45. 'contact',
  46. 'pricing',
  47. ];
  48. $this->assign('navigationId', $navigationId);
  49. // 获取未显示在导航的标题.
  50. $navigationWhere = ['navigation_type' => 2];
  51. $getNavigation = model('Navigation')->getSelect($navigationField, $navigationWhere);
  52. $this->assign('navigationTitle', $getNavigation);
  53. // 主获取页主介绍.
  54. $getIndexIntroduceSlt = ['product_ctitle'];
  55. $getIndexIntroduceWhr['product_type'] = 1;
  56. $getIndexIntroduce = model('Product')->getSelect($getIndexIntroduceSlt, $getIndexIntroduceWhr);
  57. $getIndexIntroduceArr = explode("@#", $getIndexIntroduce[0]['product_ctitle']);
  58. $this->assign('indexIntroduceArr', $getIndexIntroduceArr);
  59. // 获取服务.
  60. $getServiceSlt = [
  61. 'product_ctitle',
  62. 'product_title',
  63. ];
  64. $getServiceWhr['product_type'] = 2;
  65. $getService = model('Product')->getSelect($getServiceSlt, $getServiceWhr);
  66. $this->assign('service', $getService);
  67. // 获取解决方案.
  68. $getSolutionSlt = ['product_title'];
  69. $getSolutionWhr['product_type'] = 4;
  70. $getSolution = model('Product')->getSelect($getSolutionSlt, $getSolutionWhr);
  71. $this->assign('solution', $getSolution);
  72. // 获取案例展示.
  73. $getCaseSlt = [
  74. 'product_title',
  75. 'product_ctitle',
  76. ];
  77. $getCaseWhr['product_type'] = 3;
  78. $getCase = model('Product')->getSelect($getCaseSlt, $getCaseWhr);
  79. $this->assign('case', $getCase);
  80. // 合作流程.
  81. $getCooperationProcessSlt = ['product_title'];
  82. $getCooperationProcessWhr['product_type'] = 7;
  83. $getCooperationProcess = model('Product')->getSelect($getCooperationProcessSlt, $getCooperationProcessWhr);
  84. $this->assign('cooperationProcess', $getCooperationProcess);
  85. // 获取foot.
  86. $getFootSlt = [
  87. 'value',
  88. 'remark',
  89. ];
  90. $getFootWhr = [
  91. ['code' => 'site_phone'],
  92. ['code' => 'site_email'],
  93. ['code' => 'fax'],
  94. ];
  95. $getFoot = model('Config')->getSelect($getFootSlt, $getFootWhr);
  96. $this->assign('foot', $getFoot);
  97. return $this->fetch();
  98. }//endindex()
  99. /**
  100. * 用户留言
  101. *
  102. * @access public
  103. * @return array JsonString
  104. */
  105. public function userNeeds()
  106. {
  107. if (request()->isPost() === true) {
  108. $name = input('post.name');
  109. $email = input('post.email');
  110. $phone = input('post.phone');
  111. $content = input('post.content');
  112. $data = array(
  113. 'message_customer' => $name,
  114. 'message_email' => $email,
  115. 'message_phone' => $phone,
  116. 'message_content' => $content,
  117. );
  118. // 验证数据 BEGIN.
  119. $rule = [
  120. ['message_customer', 'require', '称呼不能为空'],
  121. ['message_email', 'email', '邮箱格式不符合要求'],
  122. ['message_phone', 'require', '电话不能为空'],
  123. ['message_content', 'require', '需求不能为空'],
  124. ];
  125. $validate = new Validate($rule);
  126. $validate_result = $validate->check($data);
  127. // 验证失败.
  128. if ($validate_result === false) {
  129. $result = [
  130. 'code' => 601,
  131. 'msg' => $validate->getError(),
  132. 'success' => false,
  133. 'data' => [],
  134. ];
  135. return json_encode($result);
  136. }//end if
  137. $data['message_addtime'] = time();
  138. $getAddId = model('Message')->addMessage($data);
  139. if (empty($getAddId) === false) {
  140. $result = [
  141. 'code' => 200,
  142. 'msg' => '操作成功',
  143. 'success' => true,
  144. 'data' => [],
  145. ];
  146. return json_encode($result);
  147. } else {
  148. $result = [
  149. 'code' => 601,
  150. 'msg' => '操作失败',
  151. 'success' => false,
  152. 'data' => [],
  153. ];
  154. return json_encode($result);
  155. }
  156. }//end if
  157. }//end userNeeds()
  158. /**
  159. * 修改密码
  160. */
  161. public function modifypw()
  162. {
  163. if (request()->isPost()) {
  164. $new_pw = trim(input('post.new_pw'));
  165. $new_pw2 = trim(input('post.new_pw2'));
  166. $old_pw = trim(input('post.old_pw'));
  167. if ($new_pw !== $new_pw2) {
  168. $this->error(lang('index_modifypw_repeat_error'));
  169. }
  170. $admininfo = $this->getAdminInfo();
  171. //查询管理员信息
  172. $service_model = model('service');
  173. $admininfo = $service_model->getserviceInfo(array('service_id' => $admininfo['service_id']));
  174. if (!is_array($admininfo) || count($admininfo) <= 0) {
  175. $this->error(lang('index_modifypw_admin_error'));
  176. }
  177. //旧密码是否正确
  178. if ($admininfo['service_password'] != md5($old_pw)) {
  179. $this->error(lang('index_modifypw_oldpw_error'));
  180. }
  181. $new_pw = md5($new_pw);
  182. $result = $service_model->editService(array('service_id' => $admininfo['service_id']), array('service_password' => $new_pw));
  183. if ($result) {
  184. session(null);
  185. dsLayerOpenSuccess(lang('index_modifypw_succ'));
  186. } else {
  187. $this->error(lang('index_modifypw_fail'));
  188. }
  189. } else {
  190. $this->setAdminCurItem('modifypw');
  191. return $this->fetch();
  192. }
  193. }
  194. /**
  195. * 首页
  196. * @return mixed
  197. */
  198. // public function welCome()
  199. // {
  200. // $setup_date = config('setup_date');
  201. // $statistics['os'] = PHP_OS;
  202. // $statistics['web_server'] = $_SERVER['SERVER_SOFTWARE'];
  203. // $statistics['php_version'] = PHP_VERSION;
  204. // $statistics['sql_version'] = $this->_mysql_version();
  205. // $statistics['setup_date'] = substr($setup_date, 0, 10);
  206. // $statistics['domain'] = $_SERVER['HTTP_HOST'];
  207. // $statistics['ip'] = GetHostByName($_SERVER['SERVER_NAME']);
  208. // $statistics['zlib'] = function_exists('gzclose') ? 'YES' : 'NO'; //zlib
  209. // $statistics['safe_mode'] = (boolean)ini_get('safe_mode') ? 'YES' : 'NO'; //safe_mode = Off
  210. // $statistics['timezone'] = function_exists("date_default_timezone_get") ? date_default_timezone_get() : "no_timezone";
  211. // $statistics['curl'] = function_exists('curl_init') ? 'YES' : 'NO';
  212. // $statistics['fileupload'] = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : 'unknown';
  213. // $statistics['max_ex_time'] = @ini_get("max_execution_time") . 's'; //脚本最大执行时间
  214. // $statistics['set_time_limit'] = function_exists("set_time_limit") ? true : false;
  215. // $statistics['memory_limit'] = ini_get('memory_limit');
  216. // $statistics['version'] = file_get_contents(APP_PATH . 'version.php');
  217. // if (function_exists("gd_info")) {
  218. // $gd = gd_info();
  219. // $statistics['gdinfo'] = $gd['GD Version'];
  220. // } else {
  221. // $statistics['gdinfo'] = lang('Unknown');
  222. // }
  223. // $this->assign('statistics', $statistics);
  224. // return $this->fetch('welcome');
  225. // }
  226. private function _mysql_version()
  227. {
  228. $version = db()->query("select version() as ver");
  229. return $version[0]['ver'];
  230. }
  231. /**
  232. * 修改当前语言
  233. */
  234. public function setLanguageCookie()
  235. {
  236. $language = input('param.language');
  237. if ($language == config('default_lang')) {
  238. $this->error(\lang('ds_language_repetition'), url('Index/index'));
  239. exit();
  240. }
  241. setcookie("ds_admin_lang", $language, 0, '/');
  242. $this->success(\lang('ds_language_switching'), url('Index/index'));
  243. exit();
  244. }
  245. /**
  246. * 删除缓存
  247. */
  248. function clear()
  249. {
  250. $this->delCacheFile('temp');
  251. $this->delCacheFile('cache');
  252. Cache::clear();
  253. ds_json_encode(10000, lang('eliminate_succ'));
  254. exit();
  255. }
  256. /**
  257. * 删除缓存目录下的文件或子目录文件
  258. *
  259. * @param string $dir 目录名或文件名
  260. * @return boolean
  261. */
  262. function delCacheFile($dir)
  263. {
  264. //防止删除cache以外的文件
  265. if (strpos($dir, '..') !== false)
  266. return false;
  267. $path = RUNTIME_PATH . '/' . $dir;
  268. if (is_dir($path)) {
  269. $file_list = array();
  270. read_file_list($path, $file_list);
  271. if (!empty($file_list)) {
  272. foreach ($file_list as $v) {
  273. if (basename($v) != 'index.html')
  274. @unlink($v);
  275. }
  276. }
  277. } else {
  278. if (basename($path) != 'index.html')
  279. @unlink($path);
  280. }
  281. return true;
  282. }
  283. }