Archives.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <?php
  2. namespace app\admin\controller\cms;
  3. use addons\cms\library\FulltextSearch;
  4. use app\admin\model\cms\Channel;
  5. use app\admin\model\cms\ChannelAdmin;
  6. use app\admin\model\cms\Modelx;
  7. use app\common\controller\Backend;
  8. use app\common\model\User;
  9. use fast\Tree;
  10. use think\Db;
  11. use think\db\Query;
  12. use think\Hook;
  13. /**
  14. * 内容表
  15. *
  16. * @icon fa fa-file-text-o
  17. */
  18. class Archives extends Backend
  19. {
  20. /**
  21. * Archives模型对象
  22. */
  23. protected $model = null;
  24. protected $noNeedRight = ['get_fields_html', 'check_element_available', 'suggestion', 'copy', 'special', 'tags', 'move', 'flag'];
  25. protected $channelIds = [];
  26. protected $isSuperAdmin = false;
  27. protected $searchFields = 'id,title';
  28. public function _initialize()
  29. {
  30. parent::_initialize();
  31. $this->model = new \app\admin\model\cms\Archives;
  32. $config = get_addon_config('cms');
  33. if ($config['archivesdatalimit'] != 'all') {
  34. $this->dataLimit = $config['archivesdatalimit'];
  35. }
  36. //复制/加入专题/修改标签均检测编辑权限
  37. if (in_array($this->request->action(), ['copy', 'special', 'tags', 'move', 'flag']) && !$this->auth->check('cms/archives/edit')) {
  38. Hook::listen('admin_nopermission', $this);
  39. $this->error(__('You have no permission'), '');
  40. }
  41. //是否超级管理员
  42. $this->isSuperAdmin = $this->auth->isSuperAdmin();
  43. $channelList = [];
  44. $disabledIds = [];
  45. $all = collection(Channel::order("weigh desc,id desc")->select())->toArray();
  46. //允许的栏目
  47. $this->channelIds = $this->isSuperAdmin || !$config['channelallocate'] ? Channel::column('id') : ChannelAdmin::getAdminChanneIds();
  48. $parentChannelIds = Channel::where('id', 'in', $this->channelIds)->column('parent_id');
  49. $parentChannelIds = array_unique($parentChannelIds);
  50. $parentChannelList = \think\Db::name('cms_channel')->where('id', 'in', $parentChannelIds)->where('parent_id', '<>', 0)->field('id,parent_id,name')->select();
  51. $tree = Tree::instance()->init($all, 'parent_id');
  52. foreach ($parentChannelList as $index => $channel) {
  53. $parentChannelIds = array_merge($parentChannelIds, $tree->getParentsIds($channel['parent_id'], true));
  54. }
  55. $this->channelIds = array_merge($parentChannelIds, $this->channelIds);
  56. foreach ($all as $k => $v) {
  57. $state = ['opened' => true];
  58. // if ($v['type'] == 'link') {
  59. // $disabledIds[] = $v['id'];
  60. // }
  61. if ($v['type'] == 'link') {
  62. $state['checkbox_disabled'] = true;
  63. }
  64. if (!$this->isSuperAdmin) {
  65. if (!in_array($v['id'], $parentChannelIds) && !in_array($v['id'], $this->channelIds)) {
  66. unset($all[$k]);
  67. continue;
  68. }
  69. }
  70. $channelList[] = [
  71. 'id' => $v['id'],
  72. 'parent' => $v['parent_id'] ? $v['parent_id'] : '#',
  73. 'text' => __($v['name']),
  74. 'type' => $v['type'],
  75. 'state' => $state
  76. ];
  77. }
  78. $tree = Tree::instance()->init($all, 'parent_id');
  79. $channelOptions = $tree->getTree(0, "<option model='@model_id' value=@id @selected @disabled>@spacer@name</option>", '', $disabledIds);
  80. $secondChannelOptions = $tree->getTree(0, "<option model='@model_id' value=@id disabled>@spacer@name</option>", '', $disabledIds);
  81. $this->view->assign('channelOptions', $channelOptions);
  82. $this->view->assign('secondChannelOptions', $secondChannelOptions);
  83. $this->assignconfig('channelList', $channelList);
  84. $this->assignconfig('spiderRecord', intval($config['spiderrecord'] ?? 0));
  85. $this->assignconfig("flagList", $this->model->getFlagList());
  86. $this->view->assign("flagList", $this->model->getFlagList());
  87. $this->view->assign("statusList", $this->model->getStatusList());
  88. $this->view->assign('IshomeList', $this->model->getIshomeList());
  89. $this->assignconfig('cms', ['archiveseditmode' => $config['archiveseditmode']]);
  90. }
  91. /**
  92. * 查看
  93. */
  94. public function index()
  95. {
  96. //设置过滤方法
  97. $this->request->filter(['strip_tags']);
  98. if ($this->request->isAjax()) {
  99. $this->relationSearch = true;
  100. //如果发送的来源是Selectpage,则转发到Selectpage
  101. if ($this->request->request('keyField')) {
  102. return $this->selectpage();
  103. }
  104. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  105. if (!$this->auth->isSuperAdmin()) {
  106. $this->model->where('channel_id', 'in', $this->channelIds);
  107. }
  108. $total = $this->model
  109. ->with(['Channel', 'user', 'admin', 'model'])
  110. ->where($where)
  111. ->order($sort, $order)
  112. ->count();
  113. if (!$this->auth->isSuperAdmin()) {
  114. $this->model->where('channel_id', 'in', $this->channelIds);
  115. }
  116. $list = $this->model
  117. ->with(['Channel', 'user', 'admin', 'model'])
  118. ->where($where)
  119. ->order($sort, $order)
  120. ->limit($offset, $limit)
  121. ->select();
  122. foreach ($list as $v) {
  123. $v['user_id'] = $v['user']['nickname'] ?? '-';
  124. $v['admin_id'] = $v['admin']['nickname'] ?? '-';
  125. $v['model_id'] = $v['model']['name'];
  126. }
  127. addtion($list, [
  128. [
  129. 'field' => 'channel_ids',
  130. 'display' => 'channel_ids',
  131. 'model' => Channel::class,
  132. ],
  133. ]);
  134. \app\admin\model\cms\SpiderLog::render($list, 'archives');
  135. $result = array("total" => $total, "rows" => $list);
  136. return json($result);
  137. }
  138. $modelList = \app\admin\model\cms\Modelx::all();
  139. $specialList = \app\admin\model\cms\Special::where('status', 'normal')->select();
  140. $this->view->assign('modelList', $modelList);
  141. $this->view->assign('specialList', $specialList);
  142. return $this->view->fetch();
  143. }
  144. /**
  145. * 副表内容
  146. */
  147. public function content($model_id = null)
  148. {
  149. $model = \app\admin\model\cms\Modelx::get($model_id);
  150. if (!$model) {
  151. $this->error('未找到对应模型');
  152. }
  153. $fieldsList = \app\admin\model\cms\Fields::where('source', 'model')->where('source_id', $model['id'])->where('type', '<>', 'text')->select();
  154. //设置过滤方法
  155. $this->request->filter(['strip_tags', 'trim']);
  156. if ($this->request->isAjax()) {
  157. //如果发送的来源是Selectpage,则转发到Selectpage
  158. if ($this->request->request('keyField')) {
  159. return $this->selectpage();
  160. }
  161. $fields = [];
  162. foreach ($fieldsList as $index => $item) {
  163. $fields[] = "addon." . $item['name'];
  164. }
  165. $filter = $this->request->request('filter');
  166. $op = $this->request->request('op');
  167. if ($filter && $op) {
  168. $filterArr = json_decode($filter, true);
  169. $opArr = json_decode($op, true);
  170. foreach ($filterArr as $index => $item) {
  171. if (in_array("addon." . $index, $fields)) {
  172. $filterArr["addon." . $index] = $item;
  173. $opArr["addon." . $index] = $opArr[$index];
  174. unset($filterArr[$index], $opArr[$index]);
  175. }
  176. }
  177. $this->request->get(['filter' => json_encode($filterArr), 'op' => json_encode($opArr)]);
  178. }
  179. $this->searchFields = "archives.id,archives.title";
  180. $this->relationSearch = true;
  181. $table = $this->model->getTable();
  182. list($where, $sort, $order, $offset, $limit, $page, $alias) = $this->buildparams();
  183. $sort = 'archives.id';
  184. $isSuperAdmin = $this->isSuperAdmin;
  185. $channelIds = $this->channelIds;
  186. $customWhere = function ($query) use ($isSuperAdmin, $channelIds, $model_id) {
  187. if (!$isSuperAdmin) {
  188. $query->where('archives.channel_id', 'in', $channelIds);
  189. }
  190. if ($model_id) {
  191. $query->where('archives.model_id', $model_id);
  192. }
  193. };
  194. $list = $this->model
  195. ->alias($alias)
  196. ->alias('archives')
  197. ->join('cms_channel channel', 'channel.id=archives.channel_id', 'LEFT')
  198. ->join($model['table'] . ' addon', 'addon.id=archives.id', 'LEFT')
  199. ->field('archives.*,channel.name as channel_name,addon.id as aid' . ($fields ? ',' . implode(',', $fields) : ''))
  200. ->where($customWhere)
  201. ->whereNull('deletetime')
  202. ->where($where)
  203. ->order($sort, $order)
  204. ->paginate($limit);
  205. $result = array("total" => $list->total(), "rows" => $list->items());
  206. return json($result);
  207. }
  208. $fields = [];
  209. foreach ($fieldsList as $index => $item) {
  210. $fields[] = ['field' => $item['name'], 'title' => $item['title'], 'type' => $item['type'], 'content' => $item['content_list']];
  211. }
  212. $this->assignconfig('fields', $fields);
  213. $this->view->assign('fieldsList', $fieldsList);
  214. $this->view->assign('model', $model);
  215. $this->assignconfig('model_id', $model_id);
  216. $modelList = \app\admin\model\cms\Modelx::all();
  217. $this->view->assign('modelList', $modelList);
  218. return $this->view->fetch();
  219. }
  220. /**
  221. * 编辑
  222. *
  223. * @param mixed $ids
  224. * @return string
  225. */
  226. public function edit($ids = null)
  227. {
  228. $row = $this->model->get($ids);
  229. if (!$row) {
  230. $this->error(__('No Results were found'));
  231. }
  232. $adminIds = $this->getDataLimitAdminIds();
  233. if (is_array($adminIds)) {
  234. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  235. $this->error(__('You have no permission'));
  236. }
  237. }
  238. if (!$this->isSuperAdmin && !in_array($row['channel_id'], $this->channelIds)) {
  239. $this->error(__('You have no permission'));
  240. }
  241. if ($this->request->isPost()) {
  242. return parent::edit($ids);
  243. }
  244. $channel = Channel::get($row['channel_id']);
  245. if (!$channel) {
  246. $this->error(__('No specified channel found'));
  247. }
  248. $model = \app\admin\model\cms\Modelx::get($channel['model_id']);
  249. if (!$model) {
  250. $this->error(__('No specified model found'));
  251. }
  252. $addon = db($model['table'])->where('id', $row['id'])->find();
  253. if ($addon) {
  254. $row->setData($addon);
  255. }
  256. $disabledIds = [];
  257. $all = collection(Channel::order("weigh desc,id desc")->select())->toArray();
  258. // foreach ($all as $k => $v) {
  259. // if ($v['type'] == 'link' || $v['model_id'] != $channel['model_id']) {
  260. // $disabledIds[] = $v['id'];
  261. // }
  262. // }
  263. $disabledIds = array_diff($disabledIds, [$row['channel_id']]);
  264. $tree = Tree::instance()->init($all, 'parent_id');
  265. $pChannelOptions = $tree->getTree(0, "<option model='@model_id' value=@id @selected @disabled>@spacer@name</option>", $row['p_channel_id'], $disabledIds);
  266. $channelOptions = $tree->getTree(0, "<option model='@model_id' value=@id @selected @disabled>@spacer@name</option>", $row['channel_id'], $disabledIds);
  267. $secondChannelOptions = $tree->getTree(0, "<option model='@model_id' value=@id @selected @disabled>@spacer@name</option>", explode(',', $row['channel_ids']), $disabledIds);
  268. $this->view->assign('pChannelOptions', $pChannelOptions);
  269. $this->view->assign('channelOptions', $channelOptions);
  270. $this->view->assign('secondChannelOptions', $secondChannelOptions);
  271. $this->view->assign("row", $row);
  272. return $this->view->fetch();
  273. }
  274. /**
  275. * 删除
  276. * @param mixed $ids
  277. */
  278. public function del($ids = "")
  279. {
  280. parent::del($ids);
  281. }
  282. /**
  283. * 销毁
  284. * @param string $ids
  285. */
  286. public function destroy($ids = "")
  287. {
  288. \app\admin\model\cms\Archives::event('after_delete', function ($row) {
  289. //删除副表
  290. $channel = Channel::get($row->channel_id);
  291. if ($channel) {
  292. $model = Modelx::get($channel['model_id']);
  293. if ($model) {
  294. db($model['table'])->where("id", $row['id'])->delete();
  295. }
  296. }
  297. });
  298. parent::destroy($ids);
  299. }
  300. /**
  301. * 还原
  302. * @param mixed $ids
  303. */
  304. public function restore($ids = "")
  305. {
  306. if (!$this->request->isPost()) {
  307. $this->error(__("Invalid parameters"));
  308. }
  309. $pk = $this->model->getPk();
  310. $adminIds = $this->getDataLimitAdminIds();
  311. if (is_array($adminIds)) {
  312. $this->model->where($this->dataLimitField, 'in', $adminIds);
  313. }
  314. if ($ids) {
  315. $this->model->where($pk, 'in', $ids);
  316. }
  317. $config = get_addon_config('cms');
  318. $list = $this->model->onlyTrashed()->select();
  319. if ($list) {
  320. $ids = [];
  321. $refreshIds = [];
  322. foreach ($list as $index => $item) {
  323. if ($item['status'] == 'normal') {
  324. User::score($config['score']['postarchives'], $item['user_id'], '发布文章');
  325. }
  326. $ids[] = $item['id'];
  327. $refreshIds = array_merge([$item['channel_id']], explode(',', $item['channel_ids']));
  328. $refreshIds = array_filter(array_unique($refreshIds));
  329. }
  330. $this->model->where('id', 'in', $ids);
  331. $this->model->restore('1=1');
  332. Channel::refreshItems($refreshIds);
  333. $this->success();
  334. }
  335. $this->error(__('No rows were updated'));
  336. }
  337. /**
  338. * 移动
  339. * @param string $ids
  340. */
  341. public function move($ids = "")
  342. {
  343. if (!$this->request->isPost()) {
  344. $this->error(__("Invalid parameters"));
  345. }
  346. if ($ids) {
  347. if (!$this->request->isPost()) {
  348. $this->error(__("Invalid parameters"));
  349. }
  350. $channel_id = $this->request->post('channel_id');
  351. $pk = $this->model->getPk();
  352. $adminIds = $this->getDataLimitAdminIds();
  353. if (is_array($adminIds)) {
  354. $this->model->where($this->dataLimitField, 'in', $adminIds);
  355. }
  356. $this->model->where($pk, 'in', $ids);
  357. $channel = Channel::get($channel_id);
  358. if ($channel && $channel['type'] === 'list') {
  359. $channelNums = \app\admin\model\cms\Archives::
  360. with('channel')
  361. ->where('archives.' . $pk, 'in', $ids)
  362. ->where('channel_id', '<>', $channel['id'])
  363. ->field('channel_id,COUNT(*) AS nums')
  364. ->group('channel_id')
  365. ->select();
  366. $result = $this->model
  367. ->where('model_id', '=', $channel['model_id'])
  368. ->where('channel_id', '<>', $channel['id'])
  369. ->update(['channel_id' => $channel_id]);
  370. if ($result) {
  371. $this->success();
  372. } else {
  373. $this->error(__('No rows were updated'));
  374. }
  375. } else {
  376. $this->error(__('No rows were updated'));
  377. }
  378. $this->error(__('Parameter %s can not be empty', 'ids'));
  379. }
  380. }
  381. /**
  382. * 复制选择行
  383. * @param string $ids
  384. */
  385. public function copy($ids = "")
  386. {
  387. if (!$this->request->isPost()) {
  388. $this->error(__("Invalid parameters"));
  389. }
  390. if ($ids) {
  391. $pk = $this->model->getPk();
  392. $adminIds = $this->getDataLimitAdminIds();
  393. if (is_array($adminIds)) {
  394. $this->model->where($this->dataLimitField, 'in', $adminIds);
  395. }
  396. $archivesList = $this->model->where('id', 'in', $ids)->select();
  397. foreach ($archivesList as $index => $item) {
  398. try {
  399. $model = Modelx::get($item['model_id']);
  400. $addon = \think\Db::name($model['table'])->find($item['id']);
  401. $data = $item->toArray();
  402. $data = array_merge($data, $addon ?? []);
  403. $data['title'] = $data['title'] . "_copy";
  404. $data['status'] = 'hidden';
  405. unset($data['id']);
  406. \app\admin\model\cms\Archives::create($data, true);
  407. } catch (\Exception $e) {
  408. //
  409. }
  410. }
  411. $this->success();
  412. $this->error(__('Parameter %s can not be empty', 'ids'));
  413. }
  414. }
  415. /**
  416. * 加入专题
  417. * @param string $ids
  418. */
  419. public function special($ids = "")
  420. {
  421. if (!$this->request->isPost()) {
  422. $this->error(__("Invalid parameters"));
  423. }
  424. if ($ids) {
  425. $special_id = $this->request->post('special_id');
  426. $pk = $this->model->getPk();
  427. $adminIds = $this->getDataLimitAdminIds();
  428. if (is_array($adminIds)) {
  429. $this->model->where($this->dataLimitField, 'in', $adminIds);
  430. }
  431. $special = \app\admin\model\cms\Special::get($special_id);
  432. if ($special) {
  433. $archivesList = $this->model->where($pk, 'in', $ids)->select();
  434. foreach ($archivesList as $index => $item) {
  435. $special_ids = explode(',', $item['special_ids']);
  436. if (!in_array($special['id'], $special_ids)) {
  437. $special_ids[] = $special['id'];
  438. $item->save(['special_ids' => implode(',', array_unique(array_filter($special_ids)))]);
  439. }
  440. }
  441. $this->success();
  442. } else {
  443. $this->error(__('No rows were updated'));
  444. }
  445. }
  446. $this->error(__('Please select at least one row'));
  447. }
  448. /**
  449. * 加入标签
  450. * @param string $ids
  451. */
  452. public function tags($ids = "")
  453. {
  454. if (!$this->request->isPost()) {
  455. $this->error(__("Invalid parameters"));
  456. }
  457. if ($ids) {
  458. $tags = $this->request->post('tags');
  459. $newTagsArr = array_filter(explode(',', $tags));
  460. if ($newTagsArr) {
  461. $pk = $this->model->getPk();
  462. $adminIds = $this->getDataLimitAdminIds();
  463. if (is_array($adminIds)) {
  464. $this->model->where($this->dataLimitField, 'in', $adminIds);
  465. }
  466. $archivesList = $this->model->where($pk, 'in', $ids)->select();
  467. foreach ($archivesList as $index => $item) {
  468. $tagsArr = explode(',', $item['tags']);
  469. $tagsArr = array_merge($tagsArr, $newTagsArr);
  470. $item->save(['tags' => implode(',', array_unique(array_filter($tagsArr)))]);
  471. }
  472. $this->success();
  473. } else {
  474. $this->error(__('标签数据不能为空'));
  475. }
  476. }
  477. $this->error(__('Please select at least one row'));
  478. }
  479. /**
  480. * 修改标志
  481. * @param string $ids
  482. */
  483. public function flag($ids = "")
  484. {
  485. if (!$this->request->isPost()) {
  486. $this->error(__("Invalid parameters"));
  487. }
  488. if ($ids) {
  489. $type = $this->request->post('type');
  490. $flag = $this->request->post('flag');
  491. $changeFlagArr = array_filter(explode(',', $flag));
  492. if ($changeFlagArr) {
  493. $pk = $this->model->getPk();
  494. $adminIds = $this->getDataLimitAdminIds();
  495. if (is_array($adminIds)) {
  496. $this->model->where($this->dataLimitField, 'in', $adminIds);
  497. }
  498. $archivesList = $this->model->where($pk, 'in', $ids)->select();
  499. foreach ($archivesList as $index => $item) {
  500. $flagArr = explode(',', $item['flag']);
  501. if ($type == 'add') {
  502. $flagArr = array_merge($flagArr, $changeFlagArr);
  503. } else {
  504. $flagArr = array_diff($flagArr, $changeFlagArr);
  505. }
  506. $item->save(['flag' => implode(',', array_unique(array_filter($flagArr)))]);
  507. }
  508. $this->success();
  509. } else {
  510. $this->error(__('标志数据不能为空'));
  511. }
  512. }
  513. $this->error(__('Please select at least one row'));
  514. }
  515. /**
  516. * 获取栏目列表
  517. * @internal
  518. */
  519. public function get_fields_html()
  520. {
  521. $this->view->engine->layout(false);
  522. $channel_id = $this->request->post('channel_id');
  523. $archives_id = $this->request->post('archives_id');
  524. $channel = Channel::get($channel_id, 'model');
  525. if ($channel) {
  526. $model_id = $channel['model_id'];
  527. $values = [];
  528. if ($archives_id) {
  529. $values = db($channel['model']['table'])->where('id', $archives_id)->find();
  530. //优先从栏目获取模型ID,再从文档获取
  531. $archives = \app\admin\model\cms\Archives::get($archives_id);
  532. $model_id = $archives ? $archives['model_id'] : $model_id;
  533. }
  534. $fields = \addons\cms\library\Service::getCustomFields('model', $model_id, $values);
  535. $model = Modelx::get($model_id);
  536. $setting = $model['setting'];
  537. $publishfields = isset($setting['publishfields']) ? $setting['publishfields'] : [];
  538. $titlelist = isset($setting['titlelist']) ? $setting['titlelist'] : [];
  539. $this->view->assign('channel', $channel);
  540. $this->view->assign('fields', $fields);
  541. $this->view->assign('values', $values);
  542. $this->success('', null, ['html' => $this->view->fetch('cms/common/fields'), 'publishfields' => $publishfields, 'titlelist' => $titlelist]);
  543. } else {
  544. $this->error(__('Please select channel'));
  545. }
  546. $this->error(__('Parameter %s can not be empty', 'ids'));
  547. }
  548. /**
  549. * 检测元素是否可用
  550. * @internal
  551. */
  552. public function check_element_available()
  553. {
  554. $id = $this->request->request('id');
  555. $name = $this->request->request('name');
  556. $value = $this->request->request('value');
  557. $name = substr($name, 4, -1);
  558. if (!$name) {
  559. $this->error(__('Parameter %s can not be empty', 'name'));
  560. }
  561. if ($id) {
  562. $this->model->where('id', '<>', $id);
  563. }
  564. $exist = $this->model->where($name, $value)->find();
  565. if ($exist) {
  566. $this->error(__('The data already exist'));
  567. } else {
  568. $this->success();
  569. }
  570. }
  571. /**
  572. * 搜索建议
  573. * @internal
  574. */
  575. public function suggestion()
  576. {
  577. $config = get_addon_config('cms');
  578. $q = trim($this->request->request("q"));
  579. $id = trim($this->request->request("id/d"));
  580. $list = [];
  581. if ($config['searchtype'] == 'xunsearch') {
  582. $result = FulltextSearch::search($q, 1, 10);
  583. } else {
  584. $result = $this->model->where("title|keywords|description", "like", "%{$q}%")->where('id', '<>', $id)->limit(10)->order("id", "desc")->select();
  585. foreach ($result as $index => $item) {
  586. $item['image'] = $item['image'] ? $item['image'] : '/assets/addons/cms/img/noimage.png';
  587. $list[] = ['id' => $item['id'], 'url' => $item['fullurl'], 'image' => cdnurl($item['image']), 'title' => $item['title'], 'create_date' => datetime($item['createtime']), 'status' => $item['status'], 'status_text' => $item['status_text'], 'deletetime' => $item['deletetime']];
  588. }
  589. }
  590. return json($list);
  591. }
  592. }