Archives.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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\Db;
  15. use think\Page;
  16. use app\common\logic\ArctypeLogic;
  17. class Archives extends Base
  18. {
  19. // 允许发布文档的模型ID
  20. public $allowReleaseChannel = array();
  21. public function _initialize() {
  22. parent::_initialize();
  23. $this->allowReleaseChannel = config('global.allow_release_channel');
  24. }
  25. /**
  26. * 内容管理
  27. */
  28. public function index()
  29. {
  30. $arctype_list = array();
  31. // 目录列表
  32. $arctypeLogic = new ArctypeLogic();
  33. $where['is_del'] = '0'; // 回收站功能
  34. $arctype_list = $arctypeLogic->arctype_list(0, 0, false, 0, $where, false);
  35. $zNodes = "[";
  36. foreach ($arctype_list as $key => $val) {
  37. $current_channel = $val['current_channel'];
  38. if (!empty($val['weapp_code'])) {
  39. // 插件栏目
  40. $typeurl = weapp_url($val['weapp_code'].'/'.$val['weapp_code'].'/index');
  41. } else {
  42. if (6 == $current_channel) {
  43. $gourl = url('Arctype/single_edit', array('typeid'=>$val['id']));
  44. $typeurl = url("Arctype/single_edit", array('typeid'=>$val['id'],'gourl'=>$gourl));
  45. } else if (8 == $current_channel) {
  46. $typeurl = url("Guestbook/index", array('typeid'=>$val['id'], 'archives'=>1));
  47. } else {
  48. $typeurl = url('Archives/index_archives', array('typeid'=>$val['id']));
  49. }
  50. }
  51. $typename = $val['typename'];
  52. $zNodes .= "{"."id:{$val['id']}, pId:{$val['parent_id']}, name:\"{$typename}\", url:'{$typeurl}',target:'content_body'";
  53. /*默认展开一级栏目*/
  54. if (empty($val['parent_id'])) {
  55. $zNodes .= ",open:true";
  56. }
  57. /*--end*/
  58. /*栏目有下级栏目时,显示图标*/
  59. if (1 == $val['has_children']) {
  60. $zNodes .= ",isParent:true";
  61. } else {
  62. $zNodes .= ",isParent:false";
  63. }
  64. /*--end*/
  65. $zNodes .= "},";
  66. }
  67. $zNodes .= "]";
  68. $this->assign('zNodes', $zNodes);
  69. return $this->fetch();
  70. }
  71. /**
  72. * 内容管理 - 所有文档列表风格(只针对ey_archives表,排除单页记录)
  73. */
  74. public function index_archives()
  75. {
  76. $assign_data = array();
  77. $condition = array();
  78. // 获取到所有URL参数
  79. $param = input('param.');
  80. $flag = input('flag/s');
  81. $typeid = input('typeid/d', 0);
  82. /*跳转到指定栏目的文档列表*/
  83. if (0 < intval($typeid)) {
  84. $row = Db::name('arctype')
  85. ->alias('a')
  86. ->field('b.ctl_name,b.id')
  87. ->join('__CHANNELTYPE__ b', 'a.current_channel = b.id', 'LEFT')
  88. ->where('a.id', 'eq', $typeid)
  89. ->find();
  90. $ctl_name = $row['ctl_name'];
  91. $current_channel = $row['id'];
  92. if (6 == $current_channel) {
  93. $gourl = url('Arctype/single_edit', array('typeid'=>$typeid));
  94. $gourl = url("Arctype/single_edit", array('typeid'=>$typeid,'gourl'=>$gourl));
  95. $this->redirect($gourl);
  96. } else if (8 == $current_channel) {
  97. $gourl = url("Guestbook/index", array('typeid'=>$typeid));
  98. $this->redirect($gourl);
  99. }
  100. }
  101. /*--end*/
  102. // 应用搜索条件
  103. foreach (['keywords','typeid','flag','is_release'] as $key) {
  104. if (isset($param[$key]) && $param[$key] !== '') {
  105. if ($key == 'keywords') {
  106. $condition['a.title'] = array('LIKE', "%{$param[$key]}%");
  107. } else if ($key == 'typeid') {
  108. $typeid = $param[$key];
  109. $hasRow = model('Arctype')->getHasChildren($typeid);
  110. $typeids = get_arr_column($hasRow, 'id');
  111. /*权限控制 by 小虎哥*/
  112. $admin_info = session('admin_info');
  113. if (0 < intval($admin_info['role_id'])) {
  114. $auth_role_info = $admin_info['auth_role_info'];
  115. if(! empty($auth_role_info)){
  116. if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
  117. $condition['a.admin_id'] = $admin_info['admin_id'];
  118. }
  119. if(! empty($auth_role_info['permission']['arctype'])){
  120. if (!empty($typeid)) {
  121. $typeids = array_intersect($typeids, $auth_role_info['permission']['arctype']);
  122. }
  123. }
  124. }
  125. }
  126. /*--end*/
  127. $condition['a.typeid'] = array('IN', $typeids);
  128. } else if ($key == 'flag') {
  129. if ('is_release' == $param[$key]) {
  130. $condition['a.users_id'] = array('gt', 0);
  131. } else {
  132. $condition['a.'.$param[$key]] = array('eq', 1);
  133. }
  134. // } else if ($key == 'is_release') {
  135. // if (0 < intval($param[$key])) {
  136. // $condition['a.users_id'] = array('gt', intval($param[$key]));
  137. // }
  138. } else {
  139. $condition['a.'.$key] = array('eq', $param[$key]);
  140. }
  141. }
  142. }
  143. /*权限控制 by 小虎哥*/
  144. if (empty($typeid)) {
  145. $typeids = [];
  146. $admin_info = session('admin_info');
  147. if (0 < intval($admin_info['role_id'])) {
  148. $auth_role_info = $admin_info['auth_role_info'];
  149. if(! empty($auth_role_info)){
  150. if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
  151. $condition['a.admin_id'] = $admin_info['admin_id'];
  152. }
  153. if(! empty($auth_role_info['permission']['arctype'])){
  154. $typeids = $auth_role_info['permission']['arctype'];
  155. }
  156. }
  157. }
  158. if (!empty($typeids)) {
  159. $condition['a.typeid'] = array('IN', $typeids);
  160. }
  161. }
  162. /*--end*/
  163. if (empty($typeid)) {
  164. // 只显示允许发布文档的模型,且是开启状态
  165. $channelIds = Db::name('channeltype')->where('status',0)
  166. ->whereOr('id','IN',[6,8])->column('id');
  167. $condition['a.channel'] = array('NOT IN', $channelIds);
  168. } else {
  169. // 只显示当前栏目对应模型下的文档
  170. $current_channel = Db::name('arctype')->where('id',$typeid)->getField('current_channel');
  171. $condition['a.channel'] = array('eq', $current_channel);
  172. }
  173. /*多语言*/
  174. $condition['a.lang'] = array('eq', $this->admin_lang);
  175. /*--end*/
  176. /*回收站数据不显示*/
  177. $condition['a.is_del'] = array('eq', 0);
  178. /*--end*/
  179. /*自定义排序*/
  180. $orderby = input('param.orderby/s');
  181. $orderway = input('param.orderway/s');
  182. if (!empty($orderby)) {
  183. $orderby = "a.{$orderby} {$orderway}";
  184. $orderby .= ", a.aid desc";
  185. } else {
  186. $orderby = "a.aid desc";
  187. }
  188. /*end*/
  189. /**
  190. * 数据查询,搜索出主键ID的值
  191. */
  192. $count = DB::name('archives')->alias('a')->where($condition)->count('aid');// 查询满足要求的总记录数
  193. $Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  194. $list = DB::name('archives')
  195. ->field("a.aid,a.channel")
  196. ->alias('a')
  197. ->where($condition)
  198. ->order($orderby)
  199. ->limit($Page->firstRow.','.$Page->listRows)
  200. ->getAllWithIndex('aid');
  201. /**
  202. * 完善数据集信息
  203. * 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
  204. */
  205. if ($list) {
  206. $aids = array_keys($list);
  207. $fields = "b.*, a.*, a.aid as aid";
  208. $row = DB::name('archives')
  209. ->field($fields)
  210. ->alias('a')
  211. ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
  212. ->where('a.aid', 'in', $aids)
  213. ->getAllWithIndex('aid');
  214. /*获取当页文档的所有模型*/
  215. $channelIds = get_arr_column($list, 'channel');
  216. $channelRow = Db::name('channeltype')->field('id, ctl_name, ifsystem')
  217. ->where('id','IN',$channelIds)
  218. ->getAllWithIndex('id');
  219. $assign_data['channelRow'] = $channelRow;
  220. /*--end*/
  221. foreach ($list as $key => $val) {
  222. $row[$val['aid']]['arcurl'] = get_arcurl($row[$val['aid']]);
  223. $row[$val['aid']]['litpic'] = handle_subdir_pic($row[$val['aid']]['litpic']); // 支持子目录
  224. $list[$key] = $row[$val['aid']];
  225. }
  226. }
  227. $show = $Page->show(); // 分页显示输出
  228. $assign_data['page'] = $show; // 赋值分页输出
  229. $assign_data['list'] = $list; // 赋值数据集
  230. $assign_data['pager'] = $Page; // 赋值分页对象
  231. // 栏目ID
  232. $assign_data['typeid'] = $typeid; // 栏目ID
  233. /*当前栏目信息*/
  234. $arctype_info = array();
  235. if ($typeid > 0) {
  236. $arctype_info = M('arctype')->field('typename,current_channel')->find($typeid);
  237. }
  238. $assign_data['arctype_info'] = $arctype_info;
  239. /*--end*/
  240. /*允许发布文档列表的栏目*/
  241. $assign_data['arctype_html'] = allow_release_arctype($typeid, array());
  242. /*--end*/
  243. /*前台URL模式*/
  244. $assign_data['seo_pseudo'] = tpCache('seo.seo_pseudo');
  245. $this->assign($assign_data);
  246. return $this->fetch('index_archives');
  247. }
  248. /**
  249. * 内容管理 - 栏目展开风格
  250. */
  251. private function index_arctype() {
  252. $arctype_list = array();
  253. // 目录列表
  254. $arctypeLogic = new ArctypeLogic();
  255. $arctype_list = $arctypeLogic->arctype_list(0, 0, false, 0, array(), false);
  256. $this->assign('arctype_list', $arctype_list);
  257. // 模型列表
  258. $channeltype_list = getChanneltypeList();
  259. $this->assign('channeltype_list', $channeltype_list);
  260. // 栏目最多级别
  261. $arctype_max_level = intval(config('global.arctype_max_level'));
  262. $this->assign('arctype_max_level', $arctype_max_level);
  263. // 允许发布文档的模型
  264. $this->assign('allow_release_channel', $this->allowReleaseChannel);
  265. return $this->fetch('index_arctype');
  266. }
  267. /**
  268. * 发布文档
  269. */
  270. public function add()
  271. {
  272. $typeid = input('param.typeid/d', 0);
  273. if (!empty($typeid)) {
  274. $row = Db::name('arctype')
  275. ->alias('a')
  276. ->field('b.ctl_name,b.id,b.ifsystem')
  277. ->join('__CHANNELTYPE__ b', 'a.current_channel = b.id', 'LEFT')
  278. ->where('a.id', 'eq', $typeid)
  279. ->find();
  280. $data = [
  281. 'typeid' => $typeid,
  282. ];
  283. if (empty($row['ifsystem'])) {
  284. $ctl_name = 'Custom';
  285. $data['channel'] = $row['id'];
  286. } else {
  287. $ctl_name = $row['ctl_name'];
  288. }
  289. $gourl = url('Archives/index_archives', array('typeid'=>$typeid));
  290. $data['gourl'] = $gourl;
  291. $jumpUrl = url("{$ctl_name}/add", $data);
  292. } else {
  293. $jumpUrl = url("Archives/release");
  294. }
  295. $this->redirect($jumpUrl);
  296. }
  297. /**
  298. * 编辑文档
  299. */
  300. public function edit()
  301. {
  302. $id = input('param.id/d', 0);
  303. $typeid = input('param.typeid/d', 0);
  304. $row = Db::name('archives')
  305. ->alias('a')
  306. ->field('a.channel,b.ctl_name,b.id,b.ifsystem')
  307. ->join('__CHANNELTYPE__ b', 'a.channel = b.id', 'LEFT')
  308. ->where('a.aid', 'eq', $id)
  309. ->find();
  310. if (empty($row['channel'])) {
  311. $channelRow = Db::name('channeltype')->field('id as channel, ctl_name')
  312. ->where('nid','article')
  313. ->find();
  314. $row = array_merge($row, $channelRow);
  315. }
  316. $data = [
  317. 'id' => $id,
  318. ];
  319. if (empty($row['ifsystem'])) {
  320. $ctl_name = 'Custom';
  321. $data['channel'] = $row['id'];
  322. } else {
  323. $ctl_name = $row['ctl_name'];
  324. }
  325. $arcurl = input('param.arcurl/s');
  326. $data['arcurl'] = $arcurl;
  327. $jumpUrl = url("{$ctl_name}/edit", $data);
  328. $this->redirect($jumpUrl);
  329. }
  330. /**
  331. * 删除文档
  332. */
  333. public function del()
  334. {
  335. if (IS_POST) {
  336. $del_id = input('del_id/a');
  337. $thorough = input('thorough/d', 0);
  338. $archivesLogic = new \app\admin\logic\ArchivesLogic;
  339. $archivesLogic->del($del_id, $thorough);
  340. }
  341. }
  342. /**
  343. * 移动
  344. */
  345. public function move()
  346. {
  347. if (IS_POST) {
  348. $post = input('post.');
  349. $typeid = !empty($post['typeid']) ? eyIntval($post['typeid']) : '';
  350. $aids = !empty($post['aids']) ? eyIntval($post['aids']) : '';
  351. if (empty($typeid) || empty($aids)) {
  352. $this->error('参数有误,请联系技术支持');
  353. }
  354. // 获取移动栏目的模型ID
  355. $current_channel = Db::name('arctype')->where([
  356. 'id' => $typeid,
  357. 'lang' => $this->admin_lang,
  358. ])->getField('current_channel');
  359. // 抽取相符合模型ID的文档aid
  360. $aids = Db::name('archives')->where([
  361. 'aid' => ['IN', $aids],
  362. 'channel' => $current_channel,
  363. 'lang' => $this->admin_lang,
  364. ])->column('aid');
  365. // 移动文档处理
  366. $update_data = array(
  367. 'typeid' => $typeid,
  368. 'update_time' => getTime(),
  369. );
  370. $r = M('archives')->where([
  371. 'aid' => ['IN', $aids],
  372. ])->update($update_data);
  373. if($r){
  374. adminLog('移动文档-id:'.$aids);
  375. $this->success('操作成功');
  376. }else{
  377. $this->error('操作失败');
  378. }
  379. }
  380. $typeid = input('param.typeid/d', 0);
  381. /*允许发布文档列表的栏目*/
  382. $allowReleaseChannel = [];
  383. if (!empty($typeid)) {
  384. $channelId = Db::name('arctype')->where('id',$typeid)->getField('current_channel');
  385. $allowReleaseChannel[] = $channelId;
  386. }
  387. $arctype_html = allow_release_arctype($typeid, $allowReleaseChannel);
  388. $this->assign('arctype_html', $arctype_html);
  389. /*--end*/
  390. /*不允许发布文档的模型ID,用于JS判断*/
  391. // $js_allow_channel_arr = '[]';
  392. // if (!empty($allowReleaseChannel)) {
  393. // $js_allow_channel_arr = '[';
  394. // foreach ($allowReleaseChannel as $key => $val) {
  395. // if ($key > 0) {
  396. // $js_allow_channel_arr .= ',';
  397. // }
  398. // $js_allow_channel_arr .= $val;
  399. // }
  400. // $js_allow_channel_arr = $js_allow_channel_arr.']';
  401. // }
  402. // $this->assign('js_allow_channel_arr', $js_allow_channel_arr);
  403. /*--end*/
  404. /*表单提交URL*/
  405. $form_action = url('Archives/move');
  406. $this->assign('form_action', $form_action);
  407. /*--end*/
  408. return $this->fetch();
  409. }
  410. /**
  411. * 发布内容
  412. */
  413. public function release()
  414. {
  415. $typeid = input('param.typeid/d', 0);
  416. if (0 < $typeid) {
  417. $param = input('param.');
  418. $row = Db::name('arctype')
  419. ->field('b.ctl_name,b.id,b.ifsystem')
  420. ->alias('a')
  421. ->join('__CHANNELTYPE__ b', 'a.current_channel = b.id', 'LEFT')
  422. ->where('a.id', 'eq', $typeid)
  423. ->find();
  424. /*针对不支持发布文档的模型*/
  425. if (!in_array($row['id'], $this->allowReleaseChannel)) {
  426. $this->error('该栏目不支持发布文档!', url('Archives/release'));
  427. exit;
  428. }
  429. /*-----end*/
  430. $data = [
  431. 'typeid' => $typeid,
  432. ];
  433. if (empty($row['ifsystem'])) {
  434. $ctl_name = 'Custom';
  435. $data['channel'] = $row['id'];
  436. } else {
  437. $ctl_name = $row['ctl_name'];
  438. }
  439. $gourl = url('Archives/index_archives', array('typeid'=>$typeid), true, true);
  440. $data['gourl'] = $gourl;
  441. $jumpUrl = url("{$ctl_name}/add", $data, true, true);
  442. header('Location: '.$jumpUrl);
  443. exit;
  444. }
  445. $iframe = input('param.iframe/d',0);
  446. /*允许发布文档列表的栏目*/
  447. $select_html = allow_release_arctype();
  448. $this->assign('select_html',$select_html);
  449. /*--end*/
  450. /*不允许发布文档的模型ID,用于JS判断*/
  451. $js_allow_channel_arr = '[';
  452. foreach ($this->allowReleaseChannel as $key => $val) {
  453. if ($key > 0) {
  454. $js_allow_channel_arr .= ',';
  455. }
  456. $js_allow_channel_arr .= $val;
  457. }
  458. $js_allow_channel_arr = $js_allow_channel_arr.']';
  459. $this->assign('js_allow_channel_arr', $js_allow_channel_arr);
  460. /*--end*/
  461. $this->assign('iframe', $iframe);
  462. $template = !empty($iframe) ? 'release_iframe' : 'release';
  463. return $this->fetch($template);
  464. }
  465. public function ajax_get_arctype()
  466. {
  467. $pid = input('pid/d');
  468. $html = '';
  469. $status = 0;
  470. if (0 < $pid) {
  471. $map = array(
  472. 'current_channel' => array('IN', $this->allowReleaseChannel),
  473. 'parent_id' => $pid,
  474. );
  475. $row = model('Arctype')->getAll('id,typename', $map, 'id');
  476. if (!empty($row)) {
  477. $status = 1;
  478. $html = '<option value="0">请选择栏目…</option>';
  479. foreach ($row as $key => $val) {
  480. $html .= '<option value="'.$val['id'].'">'.$val['typename'].'</option>';
  481. }
  482. }
  483. }
  484. respose(array(
  485. 'status' => $status,
  486. 'msg' => $html,
  487. ));
  488. }
  489. /**
  490. * 复制
  491. */
  492. public function batch_copy()
  493. {
  494. if (IS_AJAX_POST) {
  495. $typeid = input('post.typeid/d');
  496. $aids = input('post.aids/s');
  497. $num = input('post.num/d');
  498. if (empty($typeid) || empty($aids)) {
  499. $this->error('复制失败!');
  500. } else if (empty($num)) {
  501. $this->error('复制数量至少一篇!');
  502. }
  503. // 获取复制栏目的模型ID
  504. $current_channel = Db::name('arctype')->where([
  505. 'id' => $typeid,
  506. ])->getField('current_channel');
  507. // 抽取相符合模型ID的文档aid
  508. $aids = Db::name('archives')->where([
  509. 'aid' => ['IN', $aids],
  510. 'channel' => $current_channel,
  511. ])->column('aid');
  512. // 复制文档处理
  513. $archivesLogic = new \app\admin\logic\ArchivesLogic;
  514. $r = $archivesLogic->batch_copy($aids, $typeid, $current_channel, $num);
  515. if($r){
  516. adminLog('复制文档-id:'.$aids);
  517. $this->success('操作成功');
  518. }else{
  519. $this->error('操作失败');
  520. }
  521. }
  522. $typeid = input('param.typeid/d', 0);
  523. /*允许发布文档列表的栏目*/
  524. $allowReleaseChannel = [];
  525. if (!empty($typeid)) {
  526. $channelId = Db::name('arctype')->where('id',$typeid)->getField('current_channel');
  527. $allowReleaseChannel[] = $channelId;
  528. }
  529. $arctype_html = allow_release_arctype($typeid, $allowReleaseChannel);
  530. $this->assign('arctype_html', $arctype_html);
  531. /*--end*/
  532. /*表单提交URL*/
  533. $form_action = url('Archives/batch_copy');
  534. $this->assign('form_action', $form_action);
  535. /*--end*/
  536. return $this->fetch();
  537. }
  538. /**
  539. * 远程图片本地化
  540. *
  541. * @access public
  542. * @return string
  543. */
  544. public function ajax_remote_to_local()
  545. {
  546. if (IS_AJAX_POST) {
  547. $body = input('post.body/s', '', null);
  548. $body = remote_to_local($body);
  549. $this->success('本地化成功!', null, ['body'=>$body]);
  550. }
  551. $this->error('本地化失败!');
  552. }
  553. /**
  554. * 清除非站内链接
  555. *
  556. * @access public
  557. * @return string
  558. */
  559. public function ajax_replace_links()
  560. {
  561. if (IS_AJAX_POST) {
  562. $body = input('post.body/s', '', null);
  563. $body = replace_links($body);
  564. $this->success('清除成功!', null, ['body'=>$body]);
  565. }
  566. $this->error('清除失败!');
  567. }
  568. }