Index.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. $getAddId = model('Message')->addMessage($data);
  138. if (empty($getAddId) === false) {
  139. $result = [
  140. 'code' => 200,
  141. 'msg' => '操作成功',
  142. 'success' => true,
  143. 'data' => [],
  144. ];
  145. return json_encode($result);
  146. } else {
  147. $result = [
  148. 'code' => 601,
  149. 'msg' => '操作失败',
  150. 'success' => false,
  151. 'data' => [],
  152. ];
  153. return json_encode($result);
  154. }
  155. }//end if
  156. }//end userNeeds()
  157. /**
  158. * 修改密码
  159. */
  160. public function modifypw()
  161. {
  162. if (request()->isPost()) {
  163. $new_pw = trim(input('post.new_pw'));
  164. $new_pw2 = trim(input('post.new_pw2'));
  165. $old_pw = trim(input('post.old_pw'));
  166. if ($new_pw !== $new_pw2) {
  167. $this->error(lang('index_modifypw_repeat_error'));
  168. }
  169. $admininfo = $this->getAdminInfo();
  170. //查询管理员信息
  171. $service_model = model('service');
  172. $admininfo = $service_model->getserviceInfo(array('service_id' => $admininfo['service_id']));
  173. if (!is_array($admininfo) || count($admininfo) <= 0) {
  174. $this->error(lang('index_modifypw_admin_error'));
  175. }
  176. //旧密码是否正确
  177. if ($admininfo['service_password'] != md5($old_pw)) {
  178. $this->error(lang('index_modifypw_oldpw_error'));
  179. }
  180. $new_pw = md5($new_pw);
  181. $result = $service_model->editService(array('service_id' => $admininfo['service_id']), array('service_password' => $new_pw));
  182. if ($result) {
  183. session(null);
  184. dsLayerOpenSuccess(lang('index_modifypw_succ'));
  185. } else {
  186. $this->error(lang('index_modifypw_fail'));
  187. }
  188. } else {
  189. $this->setAdminCurItem('modifypw');
  190. return $this->fetch();
  191. }
  192. }
  193. /**
  194. * 首页
  195. * @return mixed
  196. */
  197. // public function welCome()
  198. // {
  199. // $setup_date = config('setup_date');
  200. // $statistics['os'] = PHP_OS;
  201. // $statistics['web_server'] = $_SERVER['SERVER_SOFTWARE'];
  202. // $statistics['php_version'] = PHP_VERSION;
  203. // $statistics['sql_version'] = $this->_mysql_version();
  204. // $statistics['setup_date'] = substr($setup_date, 0, 10);
  205. // $statistics['domain'] = $_SERVER['HTTP_HOST'];
  206. // $statistics['ip'] = GetHostByName($_SERVER['SERVER_NAME']);
  207. // $statistics['zlib'] = function_exists('gzclose') ? 'YES' : 'NO'; //zlib
  208. // $statistics['safe_mode'] = (boolean)ini_get('safe_mode') ? 'YES' : 'NO'; //safe_mode = Off
  209. // $statistics['timezone'] = function_exists("date_default_timezone_get") ? date_default_timezone_get() : "no_timezone";
  210. // $statistics['curl'] = function_exists('curl_init') ? 'YES' : 'NO';
  211. // $statistics['fileupload'] = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : 'unknown';
  212. // $statistics['max_ex_time'] = @ini_get("max_execution_time") . 's'; //脚本最大执行时间
  213. // $statistics['set_time_limit'] = function_exists("set_time_limit") ? true : false;
  214. // $statistics['memory_limit'] = ini_get('memory_limit');
  215. // $statistics['version'] = file_get_contents(APP_PATH . 'version.php');
  216. // if (function_exists("gd_info")) {
  217. // $gd = gd_info();
  218. // $statistics['gdinfo'] = $gd['GD Version'];
  219. // } else {
  220. // $statistics['gdinfo'] = lang('Unknown');
  221. // }
  222. // $this->assign('statistics', $statistics);
  223. // return $this->fetch('welcome');
  224. // }
  225. private function _mysql_version()
  226. {
  227. $version = db()->query("select version() as ver");
  228. return $version[0]['ver'];
  229. }
  230. /**
  231. * 修改当前语言
  232. */
  233. public function setLanguageCookie()
  234. {
  235. $language = input('param.language');
  236. if ($language == config('default_lang')) {
  237. $this->error(\lang('ds_language_repetition'), url('Index/index'));
  238. exit();
  239. }
  240. setcookie("ds_admin_lang", $language, 0, '/');
  241. $this->success(\lang('ds_language_switching'), url('Index/index'));
  242. exit();
  243. }
  244. /**
  245. * 删除缓存
  246. */
  247. function clear()
  248. {
  249. $this->delCacheFile('temp');
  250. $this->delCacheFile('cache');
  251. Cache::clear();
  252. ds_json_encode(10000, lang('eliminate_succ'));
  253. exit();
  254. }
  255. /**
  256. * 删除缓存目录下的文件或子目录文件
  257. *
  258. * @param string $dir 目录名或文件名
  259. * @return boolean
  260. */
  261. function delCacheFile($dir)
  262. {
  263. //防止删除cache以外的文件
  264. if (strpos($dir, '..') !== false)
  265. return false;
  266. $path = RUNTIME_PATH . '/' . $dir;
  267. if (is_dir($path)) {
  268. $file_list = array();
  269. read_file_list($path, $file_list);
  270. if (!empty($file_list)) {
  271. foreach ($file_list as $v) {
  272. if (basename($v) != 'index.html')
  273. @unlink($v);
  274. }
  275. }
  276. } else {
  277. if (basename($path) != 'index.html')
  278. @unlink($path);
  279. }
  280. return true;
  281. }
  282. }