Guestbook.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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 think\Page;
  15. use think\Db;
  16. use app\common\logic\ArctypeLogic;
  17. class Guestbook extends Base
  18. {
  19. // 模型标识
  20. public $nid = 'guestbook';
  21. // 模型ID
  22. public $channeltype = '';
  23. // 表单类型
  24. public $attrInputTypeArr = array();
  25. public function _initialize()
  26. {
  27. parent::_initialize();
  28. $channeltype_list = config('global.channeltype_list');
  29. $this->channeltype = $channeltype_list[$this->nid];
  30. $this->attrInputTypeArr = config('global.guestbook_attr_input_type');
  31. }
  32. /**
  33. * 留言列表
  34. */
  35. public function index()
  36. {
  37. $assign_data = array();
  38. $condition = array();
  39. // 获取到所有GET参数
  40. $get = input('get.');
  41. $typeid = input('typeid/d');
  42. $begin = strtotime(input('param.add_time_begin/s'));
  43. $end = input('param.add_time_end/s');
  44. !empty($end) && $end .= ' 23:59:59';
  45. $end = strtotime($end);
  46. // 应用搜索条件
  47. foreach (['keywords', 'typeid'] as $key) {
  48. if (isset($get[$key]) && $get[$key] !== '') {
  49. if ($key == 'keywords') {
  50. $attr_row = Db::name('guestbook_attr')->field('aid')->where(array('attr_value' => array('LIKE', "%{$get[$key]}%")))->group('aid')->getAllWithIndex('aid');
  51. $aids = array_keys($attr_row);
  52. $condition['a.aid'] = array('IN', $aids);
  53. } else if ($key == 'typeid') {
  54. $condition['a.typeid'] = array('eq', $get[$key]);
  55. } else {
  56. $condition['a.' . $key] = array('eq', $get[$key]);
  57. }
  58. }
  59. }
  60. // 时间检索
  61. if ($begin > 0 && $end > 0) {
  62. $condition['a.add_time'] = array('between',"$begin,$end");
  63. } else if ($begin > 0) {
  64. $condition['a.add_time'] = array('egt', $begin);
  65. } else if ($end > 0) {
  66. $condition['a.add_time'] = array('elt', $end);
  67. }
  68. // 多语言
  69. $condition['a.lang'] = array('eq', $this->admin_lang);
  70. /**
  71. * 数据查询,搜索出主键ID的值
  72. */
  73. $count = DB::name('guestbook')->alias('a')->where($condition)->count('aid');// 查询满足要求的总记录数
  74. $Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  75. $list = DB::name('guestbook')
  76. ->field("b.*, a.*")
  77. ->alias('a')
  78. ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
  79. ->where($condition)
  80. ->order('a.add_time desc')
  81. ->limit($Page->firstRow . ',' . $Page->listRows)
  82. ->getAllWithIndex('aid');
  83. /**
  84. * 完善数据集信息
  85. * 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
  86. */
  87. if ($list) {
  88. $where = [
  89. 'b.aid' => ['IN', array_keys($list)],
  90. 'a.is_showlist' => 1,
  91. 'a.lang' => $this->admin_lang,
  92. 'a.is_del' => 0,
  93. ];
  94. $row = DB::name('guestbook_attribute')
  95. ->field('a.attr_name, b.attr_value, b.aid, b.attr_id')
  96. ->alias('a')
  97. ->join('__GUESTBOOK_ATTR__ b', 'b.attr_id = a.attr_id', 'LEFT')
  98. ->where($where)
  99. ->order('b.aid desc, a.sort_order asc, a.attr_id asc')
  100. ->getAllWithIndex();
  101. $attr_list = array();
  102. foreach ($row as $key => $val) {
  103. if (preg_match('/(\.(jpg|gif|png|bmp|jpeg|ico|webp))$/i', $val['attr_value'])) {
  104. if (!stristr($val['attr_value'], '|')) {
  105. $val['attr_value'] = handle_subdir_pic($val['attr_value']);
  106. $val['attr_value'] = "<img src='{$val['attr_value']}' width='60' height='60' style='float: unset;cursor: pointer;' onclick=\"Images('{$val['attr_value']}', 650, 350);\" />";
  107. }
  108. } else {
  109. $val['attr_value'] = str_replace(PHP_EOL, ' | ', $val['attr_value']);
  110. }
  111. $attr_list[$val['aid']][] = $val;
  112. }
  113. foreach ($list as $key => $val) {
  114. $list[$key]['attr_list'] = isset($attr_list[$val['aid']]) ? $attr_list[$val['aid']] : array();
  115. }
  116. }
  117. $assign_data['tab_list'] = Db::name('guestbook_attribute')->where([
  118. 'typeid' => $typeid,
  119. 'is_showlist' => 1,
  120. 'lang' => $this->admin_lang,
  121. 'is_del' => 0,
  122. ])->order('sort_order asc, attr_id asc')->select();
  123. $show = $Page->show(); // 分页显示输出
  124. $assign_data['page'] = $show; // 赋值分页输出
  125. $assign_data['list'] = $list; // 赋值数据集
  126. $assign_data['pager'] = $Page; // 赋值分页对象
  127. // 栏目ID
  128. $assign_data['typeid'] = $typeid; // 栏目ID
  129. /*当前栏目信息*/
  130. $arctype_info = array();
  131. if ($typeid > 0) {
  132. $arctype_info = Db::name('arctype')->field('typename')->find($typeid);
  133. }
  134. $assign_data['arctype_info'] = $arctype_info;
  135. /*--end*/
  136. /*选项卡*/
  137. $tab = input('param.tab/d', 3);
  138. $assign_data['tab'] = $tab;
  139. /*--end*/
  140. $this->assign($assign_data);
  141. return $this->fetch();
  142. }
  143. /**
  144. * 删除
  145. */
  146. public function del()
  147. {
  148. $id_arr = input('del_id/a');
  149. $id_arr = eyIntval($id_arr);
  150. if (!empty($id_arr)) {
  151. $r = Db::name('guestbook')->where([
  152. 'aid' => ['IN', $id_arr],
  153. 'lang' => $this->admin_lang,
  154. ])->delete();
  155. if ($r) {
  156. // ---------后置操作
  157. model('Guestbook')->afterDel($id_arr);
  158. // ---------end
  159. adminLog('删除留言-id:' . implode(',', $id_arr));
  160. $this->success('删除成功');
  161. } else {
  162. $this->error('删除失败');
  163. }
  164. } else {
  165. $this->error('参数有误');
  166. }
  167. }
  168. /**
  169. * 留言表单表单列表
  170. */
  171. public function attribute_index()
  172. {
  173. $assign_data = array();
  174. $condition = array();
  175. // 获取到所有GET参数
  176. $get = input('get.');
  177. $typeid = input('typeid/d');
  178. // 应用搜索条件
  179. foreach (['keywords','typeid'] as $key) {
  180. if (isset($get[$key]) && $get[$key] !== '') {
  181. if ($key == 'keywords') {
  182. $condition['a.attr_name'] = array('LIKE', "%{$get[$key]}%");
  183. } else if ($key == 'typeid') {
  184. $typeids = model('Arctype')->getHasChildren($get[$key]);
  185. $condition['a.typeid'] = array('IN', array_keys($typeids));
  186. } else {
  187. $condition['a.'.$key] = array('eq', $get[$key]);
  188. }
  189. }
  190. }
  191. $condition['b.id'] = ['gt', 0];
  192. $condition['a.is_del'] = 0;
  193. // 多语言
  194. $condition['a.lang'] = $this->admin_lang;
  195. /**
  196. * 数据查询,搜索出主键ID的值
  197. */
  198. $count = DB::name('guestbook_attribute')->alias('a')
  199. ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
  200. ->where($condition)
  201. ->count();// 查询满足要求的总记录数
  202. $Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  203. $list = DB::name('guestbook_attribute')
  204. ->field("a.attr_id")
  205. ->alias('a')
  206. ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
  207. ->where($condition)
  208. ->order('a.typeid desc, a.sort_order asc, a.attr_id asc')
  209. ->limit($Page->firstRow.','.$Page->listRows)
  210. ->getAllWithIndex('attr_id');
  211. /**
  212. * 完善数据集信息
  213. * 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
  214. */
  215. if ($list) {
  216. $attr_ida = array_keys($list);
  217. $fields = "b.*, a.*";
  218. $row = DB::name('guestbook_attribute')
  219. ->field($fields)
  220. ->alias('a')
  221. ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
  222. ->where('a.attr_id', 'in', $attr_ida)
  223. ->getAllWithIndex('attr_id');
  224. /*获取多语言关联绑定的值*/
  225. $row = model('LanguageAttr')->getBindValue($row, 'guestbook_attribute', $this->main_lang); // 多语言
  226. /*--end*/
  227. foreach ($row as $key => $val) {
  228. $val['fieldname'] = 'attr_'.$val['attr_id'];
  229. $row[$key] = $val;
  230. }
  231. foreach ($list as $key => $val) {
  232. $list[$key] = $row[$val['attr_id']];
  233. }
  234. }
  235. $show = $Page->show(); // 分页显示输出
  236. $assign_data['page'] = $show; // 赋值分页输出
  237. $assign_data['list'] = $list; // 赋值数据集
  238. $assign_data['pager'] = $Page; // 赋值分页对象
  239. /*获取当前模型栏目*/
  240. $select_html = allow_release_arctype($typeid, array($this->channeltype));
  241. $typeidNum = substr_count($select_html, '</option>');
  242. $this->assign('select_html',$select_html);
  243. $this->assign('typeidNum',$typeidNum);
  244. /*--end*/
  245. // 栏目ID
  246. $assign_data['typeid'] = $typeid; // 栏目ID
  247. /*当前栏目信息*/
  248. $arctype_info = array();
  249. if ($typeid > 0) {
  250. $arctype_info = Db::name('arctype')->field('typename')->find($typeid);
  251. }
  252. $assign_data['arctype_info'] = $arctype_info;
  253. /*--end*/
  254. /*选项卡*/
  255. $tab = input('param.tab/d', 3);
  256. $assign_data['tab'] = $tab;
  257. /*--end*/
  258. $assign_data['attrInputTypeArr'] = $this->attrInputTypeArr; // 表单类型
  259. $this->assign($assign_data);
  260. return $this->fetch();
  261. }
  262. /**
  263. * 新增留言表单
  264. */
  265. public function attribute_add()
  266. {
  267. //防止php超时
  268. function_exists('set_time_limit') && set_time_limit(0);
  269. $this->language_access(); // 多语言功能操作权限
  270. if(IS_AJAX && IS_POST)//ajax提交验证
  271. {
  272. $model = model('GuestbookAttribute');
  273. $attr_values = str_replace('_', '', input('attr_values')); // 替换特殊字符
  274. $attr_values = str_replace('@', '', $attr_values); // 替换特殊字符
  275. $attr_values = trim($attr_values);
  276. /*过滤重复值*/
  277. $attr_values_arr = explode(PHP_EOL, $attr_values);
  278. foreach ($attr_values_arr as $key => $val) {
  279. $tmp_val = trim($val);
  280. if (empty($tmp_val)) {
  281. unset($attr_values_arr[$key]);
  282. continue;
  283. }
  284. $attr_values_arr[$key] = $tmp_val;
  285. }
  286. $attr_values_arr = array_unique($attr_values_arr);
  287. $attr_values = implode(PHP_EOL, $attr_values_arr);
  288. /*end*/
  289. $post_data = input('post.');
  290. $post_data['attr_values'] = $attr_values;
  291. $attr_input_type = isset($post_data['attr_input_type']) ? $post_data['attr_input_type'] : 0;
  292. /*前台输入是否JS验证*/
  293. $validate_type = 0;
  294. $validate_type_list = config("global.validate_type_list"); // 前台输入验证类型
  295. if (!empty($validate_type_list[$attr_input_type])) {
  296. $validate_type = $attr_input_type;
  297. }
  298. /*end*/
  299. $savedata = array(
  300. 'attr_name' => $post_data['attr_name'],
  301. 'typeid' => $post_data['typeid'],
  302. 'attr_input_type' => $attr_input_type,
  303. 'attr_values' => isset($post_data['attr_values']) ? $post_data['attr_values'] : '',
  304. 'is_showlist' => $post_data['is_showlist'],
  305. 'required' => $post_data['required'],
  306. 'validate_type' => $validate_type,
  307. 'sort_order' => 100,
  308. 'lang' => $this->admin_lang,
  309. 'add_time' => getTime(),
  310. 'update_time' => getTime(),
  311. );
  312. // 数据验证
  313. $validate = \think\Loader::validate('GuestbookAttribute');
  314. if(!$validate->batch()->check($savedata))
  315. {
  316. $error = $validate->getError();
  317. $error_msg = array_values($error);
  318. $return_arr = array(
  319. 'status' => -1,
  320. 'msg' => $error_msg[0],
  321. 'data' => $error,
  322. );
  323. respose($return_arr);
  324. } else {
  325. $model->data($savedata,true); // 收集数据
  326. $model->save(); // 写入数据到数据库
  327. $insertId = $model->getLastInsID();
  328. /*同步留言属性ID到多语言的模板变量里*/
  329. model('GuestbookAttribute')->syn_add_language_attribute($insertId);
  330. /*--end*/
  331. $return_arr = array(
  332. 'status' => 1,
  333. 'msg' => '操作成功',
  334. 'data' => array('url'=>url('Guestbook/attribute_index', array('typeid'=>$post_data['typeid']))),
  335. );
  336. adminLog('新增留言表单:'.$savedata['attr_name']);
  337. respose($return_arr);
  338. }
  339. }
  340. $typeid = input('param.typeid/d', 0);
  341. if ($typeid > 0) {
  342. $select_html = Db::name('arctype')->where('id', $typeid)->getField('typename');
  343. $select_html = !empty($select_html) ? $select_html : '该栏目不存在';
  344. } else {
  345. $arctypeLogic = new ArctypeLogic();
  346. $map = array(
  347. 'channeltype' => $this->channeltype,
  348. );
  349. $arctype_max_level = intval(config('global.arctype_max_level'));
  350. $select_html = $arctypeLogic->arctype_list(0, $typeid, true, $arctype_max_level, $map);
  351. }
  352. $assign_data['select_html'] = $select_html; //
  353. $assign_data['typeid'] = $typeid; // 栏目ID
  354. $assign_data['attrInputTypeArr'] = $this->attrInputTypeArr; // 表单类型
  355. $this->assign($assign_data);
  356. return $this->fetch();
  357. }
  358. /**
  359. * 编辑留言表单
  360. */
  361. public function attribute_edit()
  362. {
  363. if(IS_AJAX && IS_POST)//ajax提交验证
  364. {
  365. $model = model('GuestbookAttribute');
  366. $attr_values = str_replace('_', '', input('attr_values')); // 替换特殊字符
  367. $attr_values = str_replace('@', '', $attr_values); // 替换特殊字符
  368. $attr_values = trim($attr_values);
  369. /*过滤重复值*/
  370. $attr_values_arr = explode(PHP_EOL, $attr_values);
  371. foreach ($attr_values_arr as $key => $val) {
  372. $tmp_val = trim($val);
  373. if (empty($tmp_val)) {
  374. unset($attr_values_arr[$key]);
  375. continue;
  376. }
  377. $attr_values_arr[$key] = $tmp_val;
  378. }
  379. $attr_values_arr = array_unique($attr_values_arr);
  380. $attr_values = implode(PHP_EOL, $attr_values_arr);
  381. /*end*/
  382. $post_data = input('post.');
  383. $post_data['attr_values'] = $attr_values;
  384. $attr_input_type = isset($post_data['attr_input_type']) ? $post_data['attr_input_type'] : 0;
  385. /*前台输入是否JS验证*/
  386. $validate_type = 0;
  387. $validate_type_list = config("global.validate_type_list"); // 前台输入验证类型
  388. if (!empty($validate_type_list[$attr_input_type])) {
  389. $validate_type = $attr_input_type;
  390. }
  391. /*end*/
  392. $savedata = array(
  393. 'attr_id' => $post_data['attr_id'],
  394. 'attr_name' => $post_data['attr_name'],
  395. 'typeid' => $post_data['typeid'],
  396. 'attr_input_type' => $attr_input_type,
  397. 'attr_values' => isset($post_data['attr_values']) ? $post_data['attr_values'] : '',
  398. 'is_showlist' => $post_data['is_showlist'],
  399. 'required' => $post_data['required'],
  400. 'validate_type' => $validate_type,
  401. 'sort_order' => 100,
  402. 'update_time' => getTime(),
  403. );
  404. // 数据验证
  405. $validate = \think\Loader::validate('GuestbookAttribute');
  406. if(!$validate->batch()->check($savedata))
  407. {
  408. $error = $validate->getError();
  409. $error_msg = array_values($error);
  410. $return_arr = array(
  411. 'status' => -1,
  412. 'msg' => $error_msg[0],
  413. 'data' => $error,
  414. );
  415. respose($return_arr);
  416. } else {
  417. $model->data($savedata, true); // 收集数据
  418. $model->isUpdate(true, [
  419. 'attr_id' => $post_data['attr_id'],
  420. 'lang' => $this->admin_lang,
  421. ])->save(); // 写入数据到数据库
  422. $return_arr = array(
  423. 'status' => 1,
  424. 'msg' => '操作成功',
  425. 'data' => array('url' => url('Guestbook/attribute_index', array('typeid' => $post_data['typeid']))),
  426. );
  427. adminLog('编辑留言表单:' . $savedata['attr_name']);
  428. respose($return_arr);
  429. }
  430. }
  431. $assign_data = array();
  432. $id = input('id/d');
  433. /*获取多语言关联绑定的值*/
  434. $new_id = model('LanguageAttr')->getBindValue($id, 'guestbook_attribute'); // 多语言
  435. !empty($new_id) && $id = $new_id;
  436. /*--end*/
  437. $info = Db::name('GuestbookAttribute')->where([
  438. 'attr_id' => $id,
  439. 'lang' => $this->admin_lang,
  440. ])->find();
  441. if (empty($info)) {
  442. $this->error('数据不存在,请联系管理员!');
  443. exit;
  444. }
  445. $assign_data['field'] = $info;
  446. // 所在栏目
  447. $select_html = Db::name('arctype')->where('id', $info['typeid'])->getField('typename');
  448. $select_html = !empty($select_html) ? $select_html : '该栏目不存在';
  449. $assign_data['select_html'] = $select_html;
  450. $assign_data['attrInputTypeArr'] = $this->attrInputTypeArr; // 表单类型
  451. $this->assign($assign_data);
  452. return $this->fetch();
  453. }
  454. /**
  455. * 删除留言表单
  456. */
  457. public function attribute_del()
  458. {
  459. $this->language_access(); // 多语言功能操作权限
  460. $id_arr = input('del_id/a');
  461. $id_arr = eyIntval($id_arr);
  462. if (!empty($id_arr)) {
  463. /*多语言*/
  464. if (is_language()) {
  465. $attr_name_arr = [];
  466. foreach ($id_arr as $key => $val) {
  467. $attr_name_arr[] = 'attr_' . $val;
  468. }
  469. $new_id_arr = Db::name('language_attr')->where([
  470. 'attr_name' => ['IN', $attr_name_arr],
  471. 'attr_group' => 'guestbook_attribute',
  472. ])->column('attr_value');
  473. !empty($new_id_arr) && $id_arr = $new_id_arr;
  474. }
  475. /*--end*/
  476. $r = Db::name('GuestbookAttribute')->where([
  477. 'attr_id' => ['IN', $id_arr],
  478. ])->update([
  479. 'is_del' => 1,
  480. 'update_time' => getTime(),
  481. ]);
  482. if($r){
  483. adminLog('删除留言表单-id:'.implode(',', $id_arr));
  484. $this->success('删除成功');
  485. }else{
  486. $this->error('删除失败');
  487. }
  488. }else{
  489. $this->error('参数有误');
  490. }
  491. }
  492. /**
  493. * 查看详情
  494. */
  495. public function details()
  496. {
  497. $aid = input('param.aid/d');
  498. // 标记为已读和IP地区
  499. $row = Db::name('guestbook')->find($aid);
  500. $city = "";
  501. $city_arr = getCityLocation($row['ip']);
  502. if (!empty($city_arr)) {
  503. !empty($city_arr['location']) && $city .= $city_arr['location'];
  504. }
  505. $row['city'] = $city;
  506. $this->assign('row', $row);
  507. // 留言属性
  508. $condition['a.aid'] = $aid;
  509. $condition['a.lang'] = $this->admin_lang;
  510. $attr_list = Db::name('guestbook_attr')
  511. ->field("b.*, a.*")
  512. ->alias('a')
  513. ->join('__GUESTBOOK_ATTRIBUTE__ b', 'a.attr_id = b.attr_id', 'LEFT')
  514. ->where($condition)
  515. ->order('a.attr_id asc')
  516. ->select();
  517. foreach ($attr_list as $key => &$val) {
  518. if (preg_match('/(\.(jpg|gif|png|bmp|jpeg|ico|webp))$/i', $val['attr_value'])) {
  519. if (!stristr($val['attr_value'], '|')) {
  520. $val['attr_value'] = handle_subdir_pic($val['attr_value']);
  521. $val['attr_value'] = "<a href='{$val['attr_value']}' target='_blank'><img src='{$val['attr_value']}' width='60' height='60' style='float: unset;cursor: pointer;' /></a>";
  522. }
  523. }elseif (preg_match('/(\.('.tpCache('basic.file_type').'))$/i', $val['attr_value'])){
  524. if (!stristr($val['attr_value'], '|')) {
  525. $val['attr_value'] = handle_subdir_pic($val['attr_value']);
  526. $val['attr_value'] = "<a href='{$val['attr_value']}' download='".time()."'><img src=\"".ROOT_DIR."/public/static/common/images/file.png\" alt=\"\" style=\"width: 16px;height: 16px;\">点击下载</a>";
  527. }
  528. }
  529. }
  530. $this->assign('attr_list', $attr_list);
  531. return $this->fetch();
  532. }
  533. /**
  534. * excel导出
  535. */
  536. public function excel_export()
  537. {
  538. $id_arr = input('aid/s');
  539. if (!empty($id_arr)) {
  540. $id_arr = explode(',', $id_arr);
  541. $id_arr = eyIntval($id_arr);
  542. }
  543. $typeid = input('typeid/d');
  544. $start_time = input('start_time/s');
  545. $end_time = input('end_time/s');
  546. $strTable = '<table width="500" border="1">';
  547. $where = [];
  548. $where['typeid'] = $typeid;
  549. $where['lang'] = $this->admin_lang;
  550. $order = 'add_time asc';
  551. //没有指定ID就导出全部
  552. if (!empty($id_arr)) {
  553. $where['aid'] = ['IN', $id_arr];
  554. }
  555. //根据日期导出
  556. if (!empty($start_time) && !empty($end_time)) {
  557. $start_time = strtotime($start_time);
  558. $end_time = strtotime("+1 day", strtotime($end_time)) - 1;
  559. $where['add_time'] = ['between', [$start_time, $end_time]];
  560. } elseif (!empty($start_time) && empty($end_time)) {
  561. $start_time = strtotime($start_time);
  562. $where['add_time'] = ['>=', $start_time];
  563. } elseif (empty($start_time) && !empty($end_time)) {
  564. $end_time = strtotime("+1 day", strtotime($end_time)) - 1;
  565. $where['add_time'] = ['<=', $end_time];
  566. }
  567. $row = Db::name('guestbook')->where($where)->order($order)->select();
  568. $title = Db::name('guestbook_attribute')->where([
  569. 'typeid' => $typeid,
  570. 'lang' => $this->admin_lang,
  571. 'is_del' => 0,
  572. ])->order('sort_order asc, attr_id asc')->select();
  573. if ($row && $title) {
  574. $strTable .= '<tr>';
  575. $strTable .= '<td style="text-align:center;font-size:12px;" width="*">ID</td>';
  576. foreach ($title as &$key) {
  577. $strTable .= '<td style="text-align:center;font-size:12px;" width="*">' . $key['attr_name'] . '</td>';
  578. }
  579. $strTable .= '<td style="text-align:center;font-size:12px;" width="*">新增时间</td>';
  580. $strTable .= '<td style="text-align:center;font-size:12px;" width="*">更新时间</td>';
  581. $strTable .= '</tr>';
  582. foreach ($row as &$val) {
  583. $attr_value = Db::name('guestbook_attr')
  584. ->where(['aid' => $val['aid'], 'lang' => $this->admin_lang])
  585. ->getAllWithIndex('attr_id');
  586. $strTable .= '<tr>';
  587. $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['aid'] . '</td>';
  588. foreach ($title as &$key) {
  589. $strTable .= '<td style="text-align:center;font-size:12px;" style=\'vnd.ms-excel.numberformat:@\' width="*">' . $attr_value[$key['attr_id']]['attr_value'] . '</td>';
  590. }
  591. $strTable .= '<td style="text-align:left;font-size:12px;">' . date('Y-m-d H:i:s', $val['add_time']) . '</td>';
  592. $strTable .= '<td style="text-align:left;font-size:12px;">' . date('Y-m-d H:i:s', $val['update_time']) . '</td>';
  593. $strTable .= '</tr>';
  594. }
  595. }
  596. $strTable .= '</table>';
  597. downloadExcel($strTable, 'guestbook');
  598. exit();
  599. }
  600. }