Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Archives.php 74KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908
  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. $shopOpen = isset($this->usersConfig['shop_open']) ? intval($this->usersConfig['shop_open']) : 0;
  26. $this->assign('shopOpen', $shopOpen);
  27. // 产品模型的所有栏目字段
  28. $goodsTypeIds = Db::name('arctype')->where(['current_channel' => 2, 'lang' => $this->admin_lang])->column('id');
  29. $goodsTypeIds = !empty($goodsTypeIds) ? implode(',', $goodsTypeIds) : '';
  30. $this->assign('goodsTypeIds', $goodsTypeIds);
  31. // 返回页面
  32. $paramTypeid = input('param.typeid/d', 0);
  33. $this->callback_url = url('Archives/index_archives', ['lang' => $this->admin_lang, 'typeid' => $paramTypeid]);
  34. $this->assign('callback_url', $this->callback_url);
  35. }
  36. /**
  37. * 内容管理
  38. */
  39. public function index()
  40. {
  41. //加入栏目筛选条件
  42. $catid = $_GET['catid']?$_GET['catid']:1;
  43. $catid = (int)$catid;
  44. $this->assign('catid', $catid);
  45. //var_dump($catid);
  46. if($catid > 1){
  47. $where1 = [
  48. 'is_del' => 0,
  49. 'area_id' => $catid, //其他
  50. ];
  51. }else{
  52. $where1 = [
  53. 'is_del' => 0,
  54. 'area_id' => 1, //默认广东省
  55. ];
  56. }
  57. $arctype_list = array();
  58. // 目录列表
  59. $arctypeLogic = new ArctypeLogic();
  60. $where['is_del'] = '0'; // 回收站功能
  61. $where['current_channel'] = ['neq',51]; // 问答模型
  62. $where['weapp_code'] = '';
  63. //之前已加入筛选功能
  64. $arctype_list = $arctypeLogic->arctype_list(0, 0, false, 0, $where, false,'',$catid);
  65. /*获取所有有子栏目的栏目id*/
  66. $parent_ids = Db::name('arctype')->where([
  67. 'parent_id' => ['gt', 0],
  68. 'is_del' => 0,
  69. ])
  70. //加多条件 加错了
  71. /*->where('topid','<>',38)
  72. ->whereOr(function($query) use ($where1){
  73. $query->where($where1);
  74. })*/
  75. ->group('parent_id')
  76. ->cache(true, EYOUCMS_CACHE_TIME, 'arctype') //whereOr必须取消 cache
  77. ->column('parent_id');
  78. //var_dump($parent_ids);
  79. $cookied_treeclicked = json_decode(cookie('admin-arctreeClicked-Arr'));
  80. empty($cookied_treeclicked) && $cookied_treeclicked = [];
  81. $all_treeclicked = cookie('admin-arctreeClicked_All');
  82. empty($all_treeclicked) && $all_treeclicked = [];
  83. $last_id = [];
  84. foreach ($arctype_list as $k => $v){
  85. if (!in_array($v['id'],$cookied_treeclicked) && 0 < $v['has_children']){
  86. $last_id[] = $v['id'];
  87. continue;
  88. }elseif (0 == $v['parent_id'] ){
  89. continue;
  90. }
  91. if (in_array($v['parent_id'],$last_id) && in_array($v['id'],$cookied_treeclicked)){
  92. $key = array_search($v['id'],$cookied_treeclicked);
  93. array_splice($cookied_treeclicked,$key,1);
  94. }
  95. }
  96. $tree = [
  97. 'parent_ids'=>json_encode($parent_ids),
  98. 'all_treeclicked'=>$all_treeclicked,
  99. 'cookied_treeclicked'=>$cookied_treeclicked,
  100. 'cookied_treeclicked_arr'=>json_encode($cookied_treeclicked),
  101. ];
  102. $this->assign('tree', $tree);
  103. /* end */
  104. $zNodes = "[";
  105. foreach ($arctype_list as $key => $val) {
  106. if ($val['current_channel'] == 5 && 1.5 > $this->php_servicemeal) {
  107. continue;
  108. }
  109. $current_channel = $val['current_channel'];
  110. if (!empty($val['weapp_code'])) {
  111. // 插件栏目
  112. $typeurl = weapp_url($val['weapp_code'].'/'.$val['weapp_code'].'/index');
  113. } else {
  114. if (6 == $current_channel) {
  115. $gourl = url('Arctype/single_edit', array('typeid'=>$val['id']));
  116. $typeurl = url("Arctype/single_edit", array('typeid'=>$val['id'],'archives'=>1,'gourl'=>$gourl));
  117. } else if (8 == $current_channel) {
  118. $typeurl = url("Guestbook/index", array('typeid'=>$val['id'], 'archives'=>1));
  119. } else {
  120. $typeurl = url('Archives/index_archives', array('typeid'=>$val['id'],'catid'=>$catid));
  121. }
  122. }
  123. $typename = htmlspecialchars_decode(addslashes($val['typename']));
  124. $zNodes .= "{id:{$val['id']}, pId:{$val['parent_id']}, name:'{$typename}', url:'{$typeurl}',target:'content_body'";
  125. /*默认展开一级栏目*/
  126. // if (empty($val['parent_id'])) {
  127. // $zNodes .= ",open:true";
  128. // }
  129. /*--end*/
  130. if (!empty($tree['cookied_treeclicked'])) {
  131. if (in_array($val['id'], $tree['cookied_treeclicked'])) {
  132. $zNodes .= ",open:true";
  133. }
  134. }
  135. /*栏目有下级栏目时,显示图标*/
  136. if (1 == $val['has_children']) {
  137. $zNodes .= ",isParent:true";
  138. } else {
  139. $zNodes .= ",isParent:false";
  140. }
  141. /*--end*/
  142. $zNodes .= "},";
  143. }
  144. $zNodes .= "]";
  145. $this->assign('zNodes', $zNodes);
  146. // 中间那块内容栏目的展示/收缩记忆
  147. $treeClicked_1649642233 = cookie('admin-treeClicked-1649642233');
  148. $this->assign('treeClicked_1649642233', $treeClicked_1649642233);
  149. //调用区域
  150. /*
  151. * 调用省份数据
  152. */
  153. $pro_list = Db::table('ey_citysite')->where([
  154. "level" => 1,
  155. "parent_id" => 0,
  156. "topid" => 0,
  157. "status" => 1,
  158. ])->select();
  159. $this->assign('pro_list',$pro_list);
  160. return $this->fetch();
  161. }
  162. /**
  163. * 内容管理 - 所有文档列表风格(只针对ey_archives表,排除单页记录)
  164. */
  165. public function index_archives()
  166. {
  167. $assign_data = array();
  168. $condition = [];
  169. if (is_dir('./weapp/MultiMerchant/')) {
  170. $condition['a.merchant_id'] = 0;
  171. }
  172. // 获取到所有URL参数
  173. $param = input('param.');
  174. $flag = input('flag/s');
  175. $typeid = input('typeid/d', 0);
  176. $product_id = input('proid/d', 0);
  177. $catid = input('catid/d',1); //默认是1 广东省
  178. if((int)$product_id === 0){
  179. $product_id = input('product_id/d', 0);
  180. }
  181. //var_dump($typeid);
  182. //查询产品表 列出产品
  183. //点击产品 筛选出文档
  184. $list = Db::name('arctype_cat')
  185. ->where('parent_id','=',$typeid)
  186. ->where('type','=','产品')
  187. ->where('is_del','=',0)
  188. ->order('id asc')
  189. ->select();
  190. //var_dump($list);
  191. $this->assign('pro_list',$list);
  192. //当前产品id 默认显示就是0
  193. if($product_id === 0){
  194. //$product_id = $list[0]['id'];
  195. }
  196. $this->assign('product_id',$product_id);
  197. $this->assign('typeid',$typeid);
  198. $this->assign('catid',$catid);
  199. //查询topid
  200. $topid = Db::name('arctype')->where('id','=',$typeid)->value('topid');
  201. $this->assign('topid',$topid);
  202. //var_dump($topid);
  203. //跳转到指定栏目的文档列表
  204. if (0 < intval($typeid)) {
  205. $row = Db::name('arctype')
  206. ->alias('a')
  207. ->field('b.ctl_name,b.id')
  208. ->join('__CHANNELTYPE__ b', 'a.current_channel = b.id', 'LEFT')
  209. ->where('a.id', 'eq', $typeid)
  210. ->find();
  211. $ctl_name = $row['ctl_name'];
  212. $current_channel = $row['id'];
  213. if (6 == $current_channel) {
  214. $gourl = url('Arctype/single_edit', array('typeid'=>$typeid));
  215. $gourl = url("Arctype/single_edit", array('typeid'=>$typeid,'gourl'=>$gourl));
  216. $this->redirect($gourl);
  217. } else if (8 == $current_channel) {
  218. $gourl = url("Guestbook/index", array('typeid'=>$typeid));
  219. $this->redirect($gourl);
  220. }
  221. }
  222. foreach (['keywords','typeid','flag','is_release','province_id','city_id','area_id'] as $key) {
  223. $param[$key] = !empty($param[$key]) ? addslashes(trim($param[$key])):"";
  224. if (isset($param[$key]) && $param[$key] !== '') {
  225. if ($key == 'keywords') {
  226. $condition['a.title|a.aid'] = array('LIKE', "%{$param[$key]}%");
  227. } else if ($key == 'typeid') {
  228. $typeid = $param[$key];
  229. $hasRow = model('Arctype')->getHasChildren($typeid);
  230. $typeids = get_arr_column($hasRow, 'id');
  231. //权限控制 by 小虎哥
  232. $admin_info = session('admin_info');
  233. if (0 < intval($admin_info['role_id'])) {
  234. $auth_role_info = $admin_info['auth_role_info'];
  235. if(! empty($auth_role_info)){
  236. if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
  237. $condition['a.admin_id'] = $admin_info['admin_id'];
  238. }
  239. if(! empty($auth_role_info['permission']['arctype'])){
  240. if (!empty($typeid)) {
  241. $typeids = array_intersect($typeids, $auth_role_info['permission']['arctype']);
  242. }
  243. }
  244. }
  245. }
  246. $condition['a.typeid'] = array('IN', $typeids);
  247. } else if ($key == 'flag') {
  248. if ('is_release' == $param[$key]) {
  249. $condition['a.users_id'] = array('gt', 0);
  250. } else {
  251. $FlagNew = $param[$key];
  252. $condition['a.'.$param[$key]] = array('eq', 1);
  253. }
  254. // } else if ($key == 'is_release') {
  255. // if (0 < intval($param[$key])) {
  256. // $condition['a.users_id'] = array('gt', intval($param[$key]));
  257. // }
  258. } else if (in_array($key, ['province_id','city_id','area_id'])) {
  259. $citysiteNew = '';
  260. if (!empty($param['province_id'])) {
  261. $condition['a.province_id'] = $param['province_id'];
  262. $citysiteNew .= $param['province_id'];
  263. }
  264. if (!empty($param['city_id'])) {
  265. $condition['a.city_id'] = $param['city_id'];
  266. $citysiteNew .= !empty($citysiteNew) ? '_' . $param['city_id'] : $param['city_id'];
  267. }
  268. if (!empty($param['area_id'])) {
  269. $condition['a.area_id'] = $param['area_id'];
  270. $citysiteNew .= !empty($citysiteNew) ? '_' . $param['area_id'] : $param['area_id'];
  271. }
  272. } else {
  273. $condition['a.'.$key] = array('eq', $param[$key]);
  274. }
  275. }
  276. }
  277. //权限控制 by 小虎哥
  278. if (empty($typeid)) {
  279. $typeids = [];
  280. $admin_info = session('admin_info');
  281. if (0 < intval($admin_info['role_id'])) {
  282. $auth_role_info = $admin_info['auth_role_info'];
  283. if(! empty($auth_role_info)){
  284. if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
  285. $condition['a.admin_id'] = $admin_info['admin_id'];
  286. }
  287. if(! empty($auth_role_info['permission']['arctype'])){
  288. $typeids = $auth_role_info['permission']['arctype'];
  289. }
  290. }
  291. }
  292. if (!empty($typeids)) {
  293. $condition['a.typeid'] = array('IN', $typeids);
  294. }
  295. }
  296. $channelIds = [];
  297. if (empty($typeid)) {
  298. $id_tmp = [6,8];
  299. // 只显示允许发布文档的模型,且是开启状态
  300. $channelIds = Db::name('channeltype')->where('status',0)->whereOr('id','IN',$id_tmp)->column('id');
  301. $condition['a.channel'] = array('NOT IN', $channelIds);
  302. } else {
  303. // 只显示当前栏目对应模型下的文档
  304. $current_channel = Db::name('arctype')->where('id', $typeid)->getField('current_channel');
  305. $condition['a.channel'] = array('eq', $current_channel);
  306. }
  307. $condition['a.lang'] = array('eq', $this->admin_lang);
  308. $condition['a.is_del'] = array('eq', 0);
  309. $condition['a.arcrank'] = array('egt', -1);
  310. $continueNew = "(a.users_id = 0 OR (a.users_id > 0 AND a.arcrank >= 0))";
  311. $orderby = input('param.orderby/s');
  312. $orderway = input('param.orderway/s');
  313. if (!empty($orderby)) {
  314. $orderby = "a.{$orderby} {$orderway}, a.aid desc";
  315. } else {
  316. $orderby = "a.aid desc";
  317. }
  318. // 手机端后台管理插件特定使用参数
  319. $isMobile = input('param.isMobile/d', 0);
  320. if (!empty($isMobile)) $condition['a.channel'] = 1;
  321. // 数据查询,搜索出主键ID的值
  322. $SqlQuery = Db::name('archives')->alias('a')->where($condition)->where($continueNew)->fetchSql()->count('aid');
  323. $count = Db::name('sql_cache_table')->where(['sql_md5'=>md5($SqlQuery)])->getField('sql_result');
  324. if (!isset($count) && empty($count)) {
  325. $count = (intval($count) < 0) ? 0 : intval($count);
  326. $count = Db::name('archives')->alias('a')->where($condition)->where($continueNew)->count('aid');
  327. /*添加查询执行语句到mysql缓存表*/
  328. $SqlCacheTable = [
  329. 'sql_name' => '|archives|!=' . implode(',', $channelIds) . '|',
  330. 'sql_result' => $count,
  331. 'sql_md5' => md5($SqlQuery),
  332. 'sql_query' => $SqlQuery,
  333. 'add_time' => getTime(),
  334. 'update_time' => getTime(),
  335. ];
  336. if (!empty($FlagNew)) $SqlCacheTable['sql_name'] = $SqlCacheTable['sql_name'] . $FlagNew . '|';
  337. if (!empty($citysiteNew)) $SqlCacheTable['sql_name'] = $SqlCacheTable['sql_name'] . 'citysite_' . $citysiteNew . '|';
  338. if (!empty($typeid)) {
  339. $channeltype_list = config('global.channeltype_list');
  340. foreach ($channeltype_list as $key => $value) {
  341. if ($value == $current_channel) {
  342. $ModelMark = $key;
  343. break;
  344. }
  345. }
  346. $SqlCacheTable['sql_name'] = '|' . $ModelMark . '|' . $current_channel . '|' . $typeid . '|';
  347. }
  348. Db::name('sql_cache_table')->insertGetId($SqlCacheTable);
  349. /*END*/
  350. }
  351. $Page = new Page($count, config('paginate.list_rows'));
  352. $list = [];
  353. if (0 < $count) {
  354. $limit = $count > config('paginate.list_rows') ? $Page->firstRow.','.$Page->listRows : $count;
  355. if((int)$topid === 38){
  356. $list = Db::name('archives')
  357. ->field("a.aid, a.channel")
  358. ->alias('a')
  359. ->where($condition)
  360. ->where('a.product_id','=',$product_id) //筛选出文档 默认是0
  361. ->where($continueNew)
  362. ->order($orderby)
  363. ->limit($limit)
  364. ->getAllWithIndex('aid');
  365. }else{
  366. $list = Db::name('archives')
  367. ->field("a.aid, a.channel")
  368. ->alias('a')
  369. ->where($condition)
  370. ->where($continueNew)
  371. ->order($orderby)
  372. ->limit($limit)
  373. ->getAllWithIndex('aid');
  374. }
  375. // 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
  376. if ($list) {
  377. $aids = array_keys($list);
  378. $fields = "b.*, a.*, a.aid as aid";
  379. if((int)$topid === 38){
  380. //查询出文档
  381. $row = Db::name('archives')
  382. ->field($fields)
  383. ->alias('a')
  384. ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
  385. ->where('a.aid', 'in', $aids)
  386. ->where('a.product_id','=',$product_id) //筛选出文档 默认是0
  387. ->getAllWithIndex('aid');
  388. }else{
  389. //查询出文档
  390. $row = Db::name('archives')
  391. ->field($fields)
  392. ->alias('a')
  393. ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
  394. ->where('a.aid', 'in', $aids)
  395. ->getAllWithIndex('aid');
  396. }
  397. //var_dump(count($row));
  398. /*获取当页文档的所有模型*/
  399. $channelIds = get_arr_column($list, 'channel');
  400. $channelRow = Db::name('channeltype')->field('id, ctl_name, ifsystem')
  401. ->where('id','IN',$channelIds)
  402. ->getAllWithIndex('id');
  403. $assign_data['channelRow'] = $channelRow;
  404. foreach ($list as $key => $val) {
  405. $row[$val['aid']]['arcurl'] = get_arcurl($row[$val['aid']]);
  406. $row[$val['aid']]['litpic'] = handle_subdir_pic($row[$val['aid']]['litpic']); // 支持子目录
  407. $list[$key] = $row[$val['aid']];
  408. }
  409. //var_dump(count($list));
  410. }
  411. }
  412. $show = $Page->show();
  413. $assign_data['page'] = $show;
  414. $assign_data['list'] = $list;
  415. $assign_data['pager'] = $Page;
  416. $assign_data['typeid'] = $typeid; // 栏目ID
  417. //当前栏目信息
  418. $arctype_info = array();
  419. if ($typeid > 0) {
  420. $arctype_info = Db::name('arctype')->field('topid,typename,current_channel')->find($typeid);
  421. }
  422. $assign_data['arctype_info'] = $arctype_info;
  423. // $assign_data['arctype_html'] = allow_release_arctype($typeid, array());//允许发布文档列表的栏目,可以废弃
  424. $assign_data['seo_pseudo'] = tpCache('global.seo_pseudo');//前台URL模式
  425. $assign_data['archives_flags'] = model('ArchivesFlag')->getList();//文档属性
  426. $assign_data['shop_open'] = getUsersConfigData('shop.shop_open');//商城开关
  427. //是否存在栏目
  428. $assign_data['is_arctype'] = Db::name('arctype')->where([
  429. 'is_del' => 0,
  430. 'lang' => get_current_lang(),
  431. ])->count();
  432. $this->assign($assign_data);
  433. // 如果安装手机端后台管理插件并且在手机端访问时执行
  434. if (is_dir('./weapp/Mbackend/') && !empty($isMobile)) {
  435. $mbPage = input('param.p/d', 1);
  436. $nullShow = intval($pageObj->totalPages) === intval($mbPage) ? 1 : 0;
  437. $this->assign('nullShow', $nullShow);
  438. if ($mbPage >= 2) {
  439. return $this->display('archives/archives_list');
  440. } else {
  441. return $this->display('archives/index_archives');
  442. }
  443. } else {
  444. return $this->fetch('index_archives');
  445. }
  446. }
  447. /**
  448. * 内容管理 - 栏目展开风格
  449. */
  450. private function index_arctype() {
  451. $arctype_list = array();
  452. // 目录列表
  453. $arctypeLogic = new ArctypeLogic();
  454. $arctype_list = $arctypeLogic->arctype_list(0, 0, false, 0, array(), false);
  455. $this->assign('arctype_list', $arctype_list);
  456. // 模型列表
  457. $channeltype_list = getChanneltypeList();
  458. $this->assign('channeltype_list', $channeltype_list);
  459. // 栏目最多级别
  460. $arctype_max_level = intval(config('global.arctype_max_level'));
  461. $this->assign('arctype_max_level', $arctype_max_level);
  462. // 允许发布文档的模型
  463. $this->assign('allow_release_channel', $this->allowReleaseChannel);
  464. return $this->fetch('index_arctype');
  465. }
  466. /**
  467. * 发布文档
  468. */
  469. public function add()
  470. {
  471. $typeid = input('param.typeid/d', 0);
  472. $product_id = input('param.product_id/d', 0);
  473. $catid = input('param.catid/d', 0);
  474. $callback_url = $_GET['callback_url']?$_GET['callback_url']:'';
  475. //var_dump($_GET);return;
  476. if (!empty($typeid)) {
  477. $row = Db::name('arctype')
  478. ->alias('a')
  479. ->field('b.ctl_name,b.id,b.ifsystem')
  480. ->join('__CHANNELTYPE__ b', 'a.current_channel = b.id', 'LEFT')
  481. ->where('a.id', 'eq', $typeid)
  482. ->find();
  483. $data = [
  484. 'typeid' => $typeid,
  485. ];
  486. if (empty($row['ifsystem'])) {
  487. $ctl_name = 'Custom';
  488. $data['channel'] = $row['id'];
  489. } else {
  490. $ctl_name = $row['ctl_name'];
  491. }
  492. $gourl = url('Archives/index_archives', array('typeid'=>$typeid,'product_id'=>$product_id,'catid' => $catid), true, true);
  493. $data['gourl'] = $gourl;
  494. $data['product_id'] = $product_id;
  495. $data['catid'] = $catid;
  496. $jumpUrl = url("{$ctl_name}/add", $data, true, true);
  497. } else {
  498. $jumpUrl = url("Archives/release", [], true, true);
  499. }
  500. $this->redirect($jumpUrl);
  501. }
  502. /**
  503. * 编辑文档
  504. */
  505. public function edit()
  506. {
  507. $id = input('param.id/d', 0);
  508. $typeid = input('param.typeid/d', 0);
  509. $row = Db::name('archives')
  510. ->alias('a')
  511. ->field('a.channel,b.ctl_name,b.id,b.ifsystem')
  512. ->join('__CHANNELTYPE__ b', 'a.channel = b.id', 'LEFT')
  513. ->where('a.aid', 'eq', $id)
  514. ->find();
  515. if (empty($row['channel'])) {
  516. $channelRow = Db::name('channeltype')->field('id as channel, ctl_name')
  517. ->where('nid','article')
  518. ->find();
  519. $row = array_merge($row, $channelRow);
  520. }
  521. $data = [
  522. 'id' => $id,
  523. ];
  524. if (empty($row['ifsystem'])) {
  525. $ctl_name = 'Custom';
  526. $data['channel'] = $row['id'];
  527. } else {
  528. $ctl_name = $row['ctl_name'];
  529. }
  530. $arcurl = input('param.arcurl/s');
  531. $data['arcurl'] = $arcurl;
  532. $jumpUrl = url("{$ctl_name}/edit", $data, true, true);
  533. $this->redirect($jumpUrl);
  534. }
  535. /*
  536. * 增加小类
  537. */
  538. public function add_pro(){
  539. //proid
  540. //typeid
  541. $input = request()->get();
  542. $this->assign('typeid',$input['typeid']);
  543. $this->assign('proid',$input['proid']);
  544. return $this->fetch();
  545. }
  546. public function add_pro_post(){
  547. $post = request()->post();
  548. //var_dump($post);
  549. $data = [
  550. 'parent_id' => (int)$post['typeid'],
  551. 'topid' => 38,
  552. 'typename' => $post['name'],
  553. 'is_hot' => $post['is_hot'],
  554. 'type' => '产品',
  555. 'add_time' => time()
  556. ];
  557. $res = Db::name('arctype_cat')->insertGetId($data);
  558. //新增序列号 (三级大类)
  559. //获取num 不排除已删除
  560. $last = Db::name('seo_number')->where([
  561. "type" => 1,
  562. "tid" => (int)$post['typeid'],
  563. 'topid' => 38,
  564. 'parentid' => (int)$post['typeid'],
  565. 'area_id' => 0,
  566. ])->order('number desc')->find();
  567. if(empty($last['number'])){
  568. $num = 1;
  569. }else{
  570. $num = (int)$last['number'] + 1;
  571. }
  572. $in_data = [
  573. "type" => 1, //产品类型
  574. "aid" => $res, //实际的ID
  575. "tid" => (int)$post['typeid'], //属于哪个栏目的
  576. 'is_del' => 0,
  577. 'is_kan' => 0, // 0正常 1审核
  578. 'status' => 1,
  579. 'area_id' => 0,
  580. 'topid' => 38,
  581. 'parentid' => (int)$post['typeid'],
  582. 'number' => $num
  583. ];
  584. Db::name('seo_number')->insert($in_data);
  585. if($res > 0){
  586. return ['code'=>0,msg=>'succerss',data=>[]];
  587. }else{
  588. return ['code'=>1,msg=>'fail',data=>[]];
  589. }
  590. }
  591. public function getTag(){
  592. $pid = request()->post('pid');
  593. $catid = request()->post('catid');
  594. $aid = request()->post('aid');
  595. //var_dump($pid);
  596. if((int)$catid === 825 || (int)$catid === 126 || (int)$catid === 125){
  597. return json([
  598. 'code' => 1,
  599. 'data' => ''
  600. ]);
  601. }else{
  602. $product_tag_id = Db::name('archives')->where(['aid'=>$aid])->value('product_tag_id');
  603. $cat = Db::name('arctype')->where(['parent_id'=>369,'article_id'=>$catid])->find();
  604. if(empty($cat)){
  605. $cat_id = 371;
  606. }else{
  607. $cat_id = $cat['id'];
  608. }
  609. $product_tag = Db::name('archives')
  610. ->field('aid,typeid,title')
  611. ->where('typeid','=',$cat_id)
  612. ->where('province_id','=',$pid)
  613. ->where('is_del','=',0)
  614. ->order('sort_order asc,aid asc')
  615. ->select();
  616. $html = '<option value="0">默认标签</option>';
  617. foreach ($product_tag as $index => $row){
  618. if((int)$product_tag_id === (int)$row['aid']){
  619. $html .= '<option value="'.$row['aid'].'" selected>'.$row['title'].'</option>';
  620. }else{
  621. $html .= '<option value="'.$row['aid'].'">'.$row['title'].'</option>';
  622. }
  623. }
  624. return json([
  625. 'code' => 0,
  626. 'data' => $html
  627. ]);
  628. }
  629. }
  630. public function edit_pro(){
  631. //proid
  632. //typeid
  633. $input = request()->get();
  634. $this->assign('typeid',$input['typeid']);
  635. $this->assign('proid',$input['proid']);
  636. $detail = Db::name('arctype_cat')->find((int)$input['proid']);
  637. $this->assign('detail',$detail);
  638. return $this->fetch();
  639. }
  640. public function edit_pro_post(){
  641. $post = request()->post();
  642. //var_dump($post);
  643. $data = [
  644. 'parent_id' => (int)$post['typeid'],
  645. 'topid' => 38,
  646. 'typename' => $post['name'],
  647. 'is_hot' => $post['is_hot'],
  648. 'type' => '产品',
  649. 'update_time' => time()
  650. ];
  651. $res = Db::name('arctype_cat')->where('id','=',(int)$post['id'])->update($data);
  652. if($res > 0){
  653. return ['code'=>0,msg=>'succerss',data=>[]];
  654. }else{
  655. return ['code'=>1,msg=>'fail',data=>[]];
  656. }
  657. }
  658. public function del_pro_post(){
  659. $post = request()->post();
  660. $data = [
  661. 'is_del' => 1,
  662. 'update_time' => time()
  663. ];
  664. $res = Db::name('arctype_cat')->where('id','=',(int)$post['id'])->update($data);
  665. if($res > 0){
  666. $numinfo = [
  667. 'is_del' => 1,
  668. ];
  669. //文档aid 对应 序列号aid
  670. Db::name('seo_number')->where('type','=',1)->where('tid','<>',38)->where('aid','=',(int)$post['id'])->update($numinfo);
  671. return ['code'=>0,msg=>'succerss',data=>[]];
  672. }else{
  673. return ['code'=>1,msg=>'fail',data=>[]];
  674. }
  675. }
  676. public function get_level_list()
  677. {
  678. $typeid = request()->post('typeid');
  679. //
  680. $level_group_name = Db::name('archives')
  681. ->field('aid,typeid,title')
  682. ->where('typeid','=',(int)$typeid)
  683. ->where('is_del','=',0)
  684. ->order('sort_order asc,aid asc')
  685. ->select();
  686. return ['code'=>0,msg=>'success',data=>$level_group_name];
  687. }
  688. /**
  689. * 删除文档
  690. */
  691. public function del()
  692. {
  693. if (IS_POST) {
  694. $del_id = input('del_id/a');
  695. $thorough = input('thorough/d', 0);
  696. $archivesLogic = new \app\admin\logic\ArchivesLogic;
  697. $archivesLogic->del($del_id, $thorough);
  698. }
  699. }
  700. /**
  701. * 审核文档
  702. */
  703. public function check()
  704. {
  705. if (IS_POST) {
  706. $aids = input('ids/a');
  707. $aids = !empty($aids) ? eyIntval($aids) : '';
  708. if (!empty($aids)){
  709. $info = [
  710. 'arcrank' => 0,
  711. 'update_time'=>getTime(),
  712. ];
  713. $r = Db::name('archives')->where('aid','IN',$aids)->cache(true,null,'archives')->save($info);
  714. if ($r !== false) {
  715. adminLog('审核文档-id:'.implode(',', $aids));
  716. /*清空sql_cache_table数据缓存表 并 添加查询执行语句到mysql缓存表*/
  717. Db::name('sql_cache_table')->execute('TRUNCATE TABLE '.config('database.prefix').'sql_cache_table');
  718. model('SqlCacheTable')->InsertSqlCacheTable(true);
  719. /* END */
  720. $this->success('操作成功!');
  721. } else {
  722. $this->error('操作失败!');
  723. }
  724. }
  725. }
  726. }
  727. /**
  728. * 取消审核文档
  729. */
  730. public function uncheck()
  731. {
  732. if (IS_POST) {
  733. $aids = input('ids/a');
  734. $aids = !empty($aids) ? eyIntval($aids) : '';
  735. if (!empty($aids)){
  736. $info = [
  737. 'arcrank' => -1,
  738. 'update_time'=>getTime(),
  739. ];
  740. $r = Db::name('archives')->where('aid','IN',$aids)->cache(true,null,'archives')->save($info);
  741. if ($r !== false) {
  742. adminLog('取消审核-id:'.implode(',', $aids));
  743. /*清空sql_cache_table数据缓存表 并 添加查询执行语句到mysql缓存表*/
  744. Db::name('sql_cache_table')->execute('TRUNCATE TABLE '.config('database.prefix').'sql_cache_table');
  745. model('SqlCacheTable')->InsertSqlCacheTable(true);
  746. /* END */
  747. $this->success('操作成功!');
  748. } else {
  749. $this->error('操作失败!');
  750. }
  751. }
  752. }
  753. }
  754. /**
  755. * 移动
  756. */
  757. public function move()
  758. {
  759. if (IS_POST) {
  760. $post = input('post.');
  761. $typeid = !empty($post['typeid']) ? eyIntval($post['typeid']) : '';
  762. $aids = !empty($post['aids']) ? eyIntval($post['aids']) : '';
  763. $all_move = !empty($post['all_move']) ? intval($post['all_move']) : 0;
  764. if (empty($typeid) || empty($aids)) {
  765. $this->error('参数有误');
  766. }
  767. $r = true;
  768. // 获取移动栏目的模型ID
  769. $current_channel = Db::name('arctype')->where([
  770. 'id' => $typeid,
  771. 'lang' => $this->admin_lang,
  772. ])->getField('current_channel');
  773. if (empty($all_move)) {
  774. // 抽取相符合模型ID的文档aid
  775. $aids = Db::name('archives')->where([
  776. 'aid' => ['IN', $aids],
  777. 'channel' => $current_channel,
  778. 'lang' => $this->admin_lang,
  779. ])->column('aid');
  780. // 移动文档处理
  781. if (!empty($aids)) {
  782. $r = Db::name('archives')->where([
  783. 'aid' => ['IN', $aids],
  784. ])->update([
  785. 'typeid' => $typeid,
  786. 'update_time' => getTime(),
  787. ]);
  788. }
  789. } else {
  790. // 抽取相符合模型ID的文档栏目
  791. $dest_typeids = Db::name('archives')->where([
  792. 'aid' => ['IN', $aids],
  793. 'channel' => $current_channel,
  794. 'lang' => $this->admin_lang,
  795. ])->column('typeid');
  796. // 移动栏目下的全部文档处理
  797. if (!empty($dest_typeids)) {
  798. $r = Db::name('archives')->where([
  799. 'typeid' => ['IN', $dest_typeids],
  800. ])->update([
  801. 'typeid' => $typeid,
  802. 'update_time' => getTime(),
  803. ]);
  804. }
  805. }
  806. if ($r !== false) {
  807. if (empty($all_move)) {
  808. // 移动tag标签
  809. Db::name('taglist')->where(['aid'=>['IN', $aids]])->update([
  810. 'typeid' => $typeid,
  811. 'update_time' => getTime(),
  812. ]);
  813. adminLog('移动文档-aid:'.$aids);
  814. } else {
  815. // 移动tag标签
  816. Db::name('taglist')->where(['typeid'=>['IN', $dest_typeids]])->update([
  817. 'typeid' => $typeid,
  818. 'update_time' => getTime(),
  819. ]);
  820. Db::name('tagindex')->where(['typeid'=>['IN', $dest_typeids]])->update([
  821. 'typeid' => $typeid,
  822. 'update_time' => getTime(),
  823. ]);
  824. $dest_typeid_str = implode(',', $dest_typeids);
  825. adminLog("移动栏目 {$dest_typeid_str} 全部文档");
  826. }
  827. \think\Cache::clear('taglist');
  828. \think\Cache::clear('archives');
  829. /*清空sql_cache_table数据缓存表 并 添加查询执行语句到mysql缓存表*/
  830. Db::name('sql_cache_table')->execute('TRUNCATE TABLE '.config('database.prefix').'sql_cache_table');
  831. model('SqlCacheTable')->InsertSqlCacheTable(true);
  832. /* END */
  833. $this->success('操作成功');
  834. }
  835. $this->error('操作失败');
  836. }
  837. $typeid = input('param.typeid/d', 0);
  838. /*允许发布文档列表的栏目*/
  839. $allowReleaseChannel = [];
  840. if (!empty($typeid)) {
  841. $channelId = Db::name('arctype')->where('id',$typeid)->getField('current_channel');
  842. $allowReleaseChannel[] = $channelId;
  843. }
  844. $arctype_html = allow_release_arctype($typeid, $allowReleaseChannel);
  845. $this->assign('arctype_html', $arctype_html);
  846. /*--end*/
  847. /*不允许发布文档的模型ID,用于JS判断*/
  848. // $js_allow_channel_arr = '[]';
  849. // if (!empty($allowReleaseChannel)) {
  850. // $js_allow_channel_arr = '[';
  851. // foreach ($allowReleaseChannel as $key => $val) {
  852. // if ($key > 0) {
  853. // $js_allow_channel_arr .= ',';
  854. // }
  855. // $js_allow_channel_arr .= $val;
  856. // }
  857. // $js_allow_channel_arr = $js_allow_channel_arr.']';
  858. // }
  859. // $this->assign('js_allow_channel_arr', $js_allow_channel_arr);
  860. /*--end*/
  861. /*表单提交URL*/
  862. $form_action = url('Archives/move');
  863. $this->assign('form_action', $form_action);
  864. /*--end*/
  865. return $this->fetch();
  866. }
  867. /**
  868. * 发布内容
  869. */
  870. public function release()
  871. {
  872. $typeid = input('param.typeid/d', 0);
  873. if (0 < $typeid) {
  874. $param = input('param.');
  875. $row = Db::name('arctype')
  876. ->field('b.ctl_name,b.id,b.ifsystem')
  877. ->alias('a')
  878. ->join('__CHANNELTYPE__ b', 'a.current_channel = b.id', 'LEFT')
  879. ->where('a.id', 'eq', $typeid)
  880. ->find();
  881. /*针对不支持发布文档的模型*/
  882. if (!in_array($row['id'], $this->allowReleaseChannel)) {
  883. $this->error('该栏目不支持发布文档!', url('Archives/release'));
  884. exit;
  885. }
  886. /*-----end*/
  887. $data = [
  888. 'typeid' => $typeid,
  889. ];
  890. if (empty($row['ifsystem'])) {
  891. $ctl_name = 'Custom';
  892. $data['channel'] = $row['id'];
  893. } else {
  894. $ctl_name = $row['ctl_name'];
  895. }
  896. $gourl = url('Archives/index_archives', array('typeid'=>$typeid), true, true);
  897. $data['gourl'] = $gourl;
  898. $jumpUrl = url("{$ctl_name}/add", $data, true, true);
  899. header('Location: '.$jumpUrl);
  900. exit;
  901. }
  902. $iframe = input('param.iframe/d',0);
  903. /*允许发布文档列表的栏目*/
  904. $select_html = allow_release_arctype();
  905. $this->assign('select_html',$select_html);
  906. /*--end*/
  907. /*不允许发布文档的模型ID,用于JS判断*/
  908. $js_allow_channel_arr = '[';
  909. foreach ($this->allowReleaseChannel as $key => $val) {
  910. if ($key > 0) {
  911. $js_allow_channel_arr .= ',';
  912. }
  913. $js_allow_channel_arr .= $val;
  914. }
  915. $js_allow_channel_arr = $js_allow_channel_arr.']';
  916. $this->assign('js_allow_channel_arr', $js_allow_channel_arr);
  917. /*--end*/
  918. if (!empty($iframe)) {
  919. $template = 'release_iframe';
  920. $attribute_row = Db::name('product_attribute')->field('typeid, count(attr_id) as num')
  921. ->where([
  922. 'is_del' => 0,
  923. 'lang' => $this->admin_lang,
  924. ])
  925. ->group('typeid')
  926. ->getAllWithIndex('typeid');
  927. $this->assign('attribute_row', $attribute_row);
  928. } else {
  929. $template = 'release';
  930. }
  931. $this->assign('iframe', $iframe);
  932. return $this->fetch($template);
  933. }
  934. public function ajax_get_arctype()
  935. {
  936. $pid = input('pid/d');
  937. $html = '';
  938. $status = 0;
  939. if (0 < $pid) {
  940. $map = array(
  941. 'current_channel' => array('IN', $this->allowReleaseChannel),
  942. 'parent_id' => $pid,
  943. );
  944. $row = model('Arctype')->getAll('id,typename', $map, 'id');
  945. if (!empty($row)) {
  946. $status = 1;
  947. $html = '<option value="0">请选择栏目…</option>';
  948. foreach ($row as $key => $val) {
  949. $html .= '<option value="'.$val['id'].'">'.$val['typename'].'</option>';
  950. }
  951. }
  952. }
  953. respose(array(
  954. 'status' => $status,
  955. 'msg' => $html,
  956. ));
  957. }
  958. /**
  959. * 复制
  960. */
  961. public function batch_copy()
  962. {
  963. if (IS_AJAX_POST) {
  964. $typeid = input('post.typeid/d');
  965. $aids = input('post.aids/s');
  966. $num = input('post.num/d');
  967. if (empty($typeid) || empty($aids)) {
  968. $this->error('复制失败!');
  969. } else if (empty($num)) {
  970. $this->error('复制数量至少一篇!');
  971. }
  972. // 获取复制栏目的模型ID
  973. $current_channel = Db::name('arctype')->where([
  974. 'id' => $typeid,
  975. ])->getField('current_channel');
  976. // 抽取相符合模型ID的文档aid
  977. $aids = Db::name('archives')->where([
  978. 'aid' => ['IN', $aids],
  979. 'channel' => $current_channel,
  980. ])->column('aid');
  981. // 复制文档处理
  982. $archivesLogic = new \app\admin\logic\ArchivesLogic;
  983. $r = $archivesLogic->batch_copy($aids, $typeid, $current_channel, $num);
  984. if($r){
  985. adminLog('复制文档-id:'.$aids);
  986. $this->success('操作成功');
  987. }else{
  988. $this->error('操作失败');
  989. }
  990. }
  991. $typeid = input('param.typeid/d', 0);
  992. /*允许发布文档列表的栏目*/
  993. $allowReleaseChannel = [];
  994. if (!empty($typeid)) {
  995. $channelId = Db::name('arctype')->where('id',$typeid)->getField('current_channel');
  996. $allowReleaseChannel[] = $channelId;
  997. }
  998. $arctype_html = allow_release_arctype($typeid, $allowReleaseChannel);
  999. $this->assign('arctype_html', $arctype_html);
  1000. /*--end*/
  1001. /*表单提交URL*/
  1002. $form_action = url('Archives/batch_copy');
  1003. $this->assign('form_action', $form_action);
  1004. /*--end*/
  1005. return $this->fetch();
  1006. }
  1007. /**
  1008. * 批量属性操作
  1009. */
  1010. public function batch_attr()
  1011. {
  1012. if (IS_AJAX_POST) {
  1013. $opt = input('post.opt/s');
  1014. $aids = input('post.aids/s');
  1015. $attrType = input('post.attrType/s');
  1016. if (empty($opt)) {
  1017. $this->error('操作失败!');
  1018. } else if (empty($attrType)) {
  1019. $this->error('请勾选属性!');
  1020. } else if (empty($aids)) {
  1021. $this->error('文档ID不能为空!');
  1022. }
  1023. $value = ($opt == 'add') ? 1 : 0;
  1024. $aids = str_replace(',', ',', $aids);
  1025. $r = Db::name('archives')->where([
  1026. 'aid' => ['IN', explode(',', $aids)],
  1027. 'lang' => $this->admin_lang,
  1028. ])->update([
  1029. $attrType => $value,
  1030. 'update_time' => getTime(),
  1031. ]);
  1032. if($r !== false){
  1033. adminLog('批量处理属性-id:'.$aids);
  1034. $this->success('操作成功');
  1035. }else{
  1036. $this->error('操作失败');
  1037. }
  1038. }
  1039. /*文档属性*/
  1040. $assign_data['archives_flags'] = model('ArchivesFlag')->getList();
  1041. $this->assign($assign_data);
  1042. return $this->fetch();
  1043. }
  1044. /**
  1045. * 远程图片本地化
  1046. *
  1047. * @access public
  1048. * @return string
  1049. */
  1050. public function ajax_remote_to_local()
  1051. {
  1052. if (IS_AJAX_POST) {
  1053. $body = input('post.body/s', '', null);
  1054. $body = remote_to_local($body);
  1055. $this->success('本地化成功!', null, ['body'=>$body]);
  1056. }
  1057. $this->error('本地化失败!');
  1058. }
  1059. /**
  1060. * 清除非站内链接
  1061. *
  1062. * @access public
  1063. * @return string
  1064. */
  1065. public function ajax_replace_links()
  1066. {
  1067. if (IS_AJAX_POST) {
  1068. $body = input('post.body/s', '', null);
  1069. $body = replace_links($body);
  1070. $this->success('清除成功!', null, ['body'=>$body]);
  1071. }
  1072. $this->error('清除失败!');
  1073. }
  1074. /**
  1075. * 自动远程图片本地化/自动清除非站内链接
  1076. *
  1077. * @access public
  1078. * @return string
  1079. */
  1080. public function ajax_auto_editor()
  1081. {
  1082. $this->error('因安全问题,已作废禁用');
  1083. if (IS_AJAX_POST) {
  1084. $body = input('post.body/s', '', null);
  1085. $local = input('post.local/d', '', 0);
  1086. $link = input('post.link/d', '', 0);
  1087. if (1 == $local){
  1088. $body = remote_to_local($body);
  1089. }
  1090. if (1 == $link){
  1091. $body = replace_links($body);
  1092. }
  1093. $this->success('操作成功!', null, ['body'=>$body]);
  1094. }
  1095. $this->error('操作失败!');
  1096. }
  1097. /**
  1098. * 自定义字段
  1099. */
  1100. public function ajax_get_addonextitem()
  1101. {
  1102. \think\Session::pause(); // 暂停session,防止session阻塞机制
  1103. $aid = input('param.aid/d', 0);
  1104. $typeid = input('param.typeid/d', 0);
  1105. $channeltype = input('param.channeltype/d', 0);
  1106. $assign_data = [];
  1107. $controller_name = input('param.controller_name/s');
  1108. $assign_data['controller_name'] = $controller_name;
  1109. $action_name = input('param.action_name/s');
  1110. $assign_data['action_name'] = $action_name;
  1111. $editor = tpSetting('editor');
  1112. if (!empty($typeid) && !empty($channeltype)) {
  1113. // 存在aid则执行,查询文档数据
  1114. $info = [];
  1115. if (!empty($aid)) {
  1116. $info = Db::name('archives')->where('aid', $aid)->find();
  1117. }
  1118. if (!empty($info)) {
  1119. $editor['editor_remote_img_local'] = $info['editor_remote_img_local'];
  1120. $editor['editor_img_clear_link'] = $info['editor_img_clear_link'];
  1121. }
  1122. // 查询对应的自定义字段
  1123. $addonFieldExtList = model('Field')->getChannelFieldList($channeltype, 0, $aid, $info);
  1124. $field_ids = get_arr_column($addonFieldExtList, 'id');
  1125. $typeids = [0, $typeid];
  1126. $channelfieldBindList = Db::name('channelfield_bind')->field('field_id,typeid')->where([
  1127. 'typeid' => ['IN', $typeids],
  1128. ])->whereOr([
  1129. 'field_id' => ['IN', $field_ids],
  1130. ])->select();
  1131. $field_id_row = $channelfieldBindRow = [];
  1132. foreach ($channelfieldBindList as $key => $val) {
  1133. // 查询对应的自定义字段
  1134. if (in_array($val['field_id'], $field_ids)) {
  1135. $field_id_row[] = $val['field_id'];
  1136. }
  1137. // 查询绑定的自定义字段
  1138. if (in_array($val['typeid'], $typeids)) {
  1139. $channelfieldBindRow[] = $val['field_id'];
  1140. }
  1141. }
  1142. // 匹配显示的自定义字段
  1143. $htmltextField = []; // 富文本的字段名
  1144. $content_ey_m_dfvalue = ""; //手机端详情内容
  1145. $have_content_ey_m = 0; //是否显示手机端
  1146. $name_arr = get_arr_column($addonFieldExtList,'name');
  1147. if (!empty($field_id_row)) {
  1148. $first_html = '';
  1149. foreach ($addonFieldExtList as $key => $val) {
  1150. if (in_array($val['id'], $field_id_row) && !in_array($val['id'], $channelfieldBindRow)) {
  1151. unset($addonFieldExtList[$key]);
  1152. continue;
  1153. }
  1154. if ($val['dtype'] == 'htmltext') {
  1155. if ($val['name'] == 'content_ey_m'){
  1156. $content_ey_m_dfvalue = $val['dfvalue'];
  1157. if ($val['ifeditable']){
  1158. $have_content_ey_m = 1;
  1159. }
  1160. }
  1161. if (empty($first_html) && $val['name'] != 'content_ey_m'){
  1162. $addonFieldExtList[$key]['editor'] = $editor;
  1163. if ('content' == $val['name'] || 'Custom' == $controller_name) {
  1164. $addonFieldExtList[$key]['first'] = 1;
  1165. $first_html = 1;
  1166. }
  1167. }
  1168. array_push($htmltextField, $val['name']);
  1169. }
  1170. if($val['name'] == 'content_ey_m' && in_array('content',$name_arr)){
  1171. unset($addonFieldExtList[$key]);
  1172. continue;
  1173. }
  1174. }
  1175. } else {
  1176. $first_html = '';
  1177. foreach ($addonFieldExtList as $key => $val) {
  1178. if ($val['dtype'] == 'htmltext') {
  1179. if ($val['name'] == 'content_ey_m'){
  1180. $content_ey_m_dfvalue = $val['dfvalue'];
  1181. if ($val['ifeditable']){
  1182. $have_content_ey_m = 1;
  1183. }
  1184. }
  1185. if (empty($first_html) && $val['name'] != 'content_ey_m'){
  1186. $addonFieldExtList[$key]['editor'] = $editor;
  1187. if ('content' == $val['name'] || 'Custom' == $controller_name) {
  1188. $addonFieldExtList[$key]['first'] = 1;
  1189. $first_html = 1;
  1190. }
  1191. }
  1192. array_push($htmltextField, $val['name']);
  1193. }else if ($val['dtype'] == 'region' && !empty($val['set_type']) && $val['set_type'] == 1) {
  1194. if (!empty($val['trueValue'][1])){
  1195. $addonFieldExtList[$key]['city_list'] = Db::name('region')->where(['level'=>2,'parent_id'=>$val['trueValue'][0]])->select();
  1196. }
  1197. if (!empty($val['trueValue'][2])){
  1198. $addonFieldExtList[$key]['area_list'] = Db::name('region')->where(['level'=>3,'parent_id'=>$val['trueValue'][1]])->select();
  1199. }
  1200. }
  1201. if($val['name'] == 'content_ey_m' && in_array('content',$name_arr)){
  1202. unset($addonFieldExtList[$key]);
  1203. continue;
  1204. }
  1205. }
  1206. }
  1207. $assign_data['content_ey_m_dfvalue'] = $content_ey_m_dfvalue;
  1208. $assign_data['have_content_ey_m'] = $have_content_ey_m;
  1209. // 加载模板
  1210. $assign_data['params'] = input('param.');
  1211. $assign_data['field'] = $info;
  1212. //var_dump($assign_data);
  1213. /*
  1214. dtype text
  1215. define
  1216. title
  1217. name
  1218. dfvalue
  1219. remark
  1220. */
  1221. $assign_data['typeid'] = $typeid;
  1222. //$topid = Db::name('arctype')->where('id','=',$typeid)->value('topid');
  1223. $cat = Db::name('arctype')->where(['id'=>$typeid])->find();
  1224. $vb = ['qkmc','zbdw','yxyz','zgdw','jb','gnkh','slzt','jytg'];
  1225. $vbs = ['content_5','down','imgs','pagenum','content_4','zylm','wplj','tqm']; //保留两者
  1226. if((int)$cat['topid'] === 38){
  1227. //删除期刊
  1228. foreach ($addonFieldExtList as $key=>$item){
  1229. //echo $item['name'];
  1230. if(in_array($item['name'],$vb) && !in_array($item['name'],$vbs)){
  1231. unset($addonFieldExtList[$key]);
  1232. }
  1233. }
  1234. }else if((int)$cat['parent_id'] === 116 || (int)$typeid === 116){
  1235. //论文期刊
  1236. foreach ($addonFieldExtList as $key=>$item){
  1237. //echo $item['name'];
  1238. if(!in_array($item['name'],$vb) && !in_array($item['name'],$vbs)){
  1239. unset($addonFieldExtList[$key]);
  1240. }
  1241. if($item['name'] === 'content_5'){
  1242. $item['first'] = 1;
  1243. $addonFieldExtList[$key] = $item;
  1244. }
  1245. }
  1246. //first 属性
  1247. }else{
  1248. if((int)$cat['topid'] !== 36) {
  1249. //隐藏产品和期刊
  1250. foreach ($addonFieldExtList as $key => $item) {
  1251. //echo $item['name'];
  1252. if (!in_array($item['name'], $vbs)) {
  1253. unset($addonFieldExtList[$key]);
  1254. }
  1255. if($item['name'] === 'content_5'){
  1256. $item['first'] = 1;
  1257. $addonFieldExtList[$key] = $item;
  1258. }
  1259. }
  1260. //first 属性
  1261. }
  1262. }
  1263. //var_dump($addonFieldExtList);
  1264. $assign_data['addonFieldExtList'] = $addonFieldExtList;
  1265. $this->assign($assign_data);
  1266. // 渲染模板
  1267. $html = $this->fetch('field/addonextitem');
  1268. $this->success('请求成功', null, ['html'=>$html, 'htmltextField'=>$htmltextField]);
  1269. }
  1270. }
  1271. /**
  1272. * 新建模板文件
  1273. */
  1274. public function ajax_newtpl()
  1275. {
  1276. $this->error('已废弃');
  1277. if (IS_POST) {
  1278. $post = input('post.', '', null);
  1279. $content = input('post.content', '', null);
  1280. $view_suffix = config('template.view_suffix');
  1281. if (!empty($post['filename'])) {
  1282. if (!preg_match("/^[\w\-\_]{1,}$/u", $post['filename'])) {
  1283. $this->error('文件名称只允许字母、数字、下划线、连接符的任意组合!');
  1284. }
  1285. $filename = "{$post['type']}_{$post['nid']}_{$post['filename']}.{$view_suffix}";
  1286. } else {
  1287. $filename = "{$post['type']}_{$post['nid']}.{$view_suffix}";
  1288. }
  1289. $content = !empty($content) ? $content : '';
  1290. $tpldirpath = !empty($post['tpldir']) ? '/template/'.TPL_THEME.trim($post['tpldir']) : '/template/'.TPL_THEME.'pc';
  1291. if (file_exists(ROOT_PATH.ltrim($tpldirpath, '/').'/'.$filename)) {
  1292. $this->error('文件名称已经存在,请重新命名!', null, ['focus'=>'filename']);
  1293. }
  1294. $nosubmit = input('param.nosubmit/d');
  1295. if (1 == $nosubmit) {
  1296. $this->success('检测通过');
  1297. }
  1298. $filemanagerLogic = new \app\admin\logic\FilemanagerLogic;
  1299. $r = $filemanagerLogic->editFile($filename, $tpldirpath, $content);
  1300. if ($r === true) {
  1301. $this->success('操作成功', null, ['filename'=>$filename,'type'=>$post['type']]);
  1302. } else {
  1303. $this->error($r);
  1304. }
  1305. }
  1306. $type = input('param.type/s');
  1307. $nid = input('param.nid/s');
  1308. $tpldirList = glob('template/'.TPL_THEME.'*');
  1309. $tpl_theme = str_replace('/', '\\/', TPL_THEME);
  1310. foreach ($tpldirList as $key => $val) {
  1311. if (!preg_match('/template\/'.$tpl_theme.'(pc|mobile)$/i', $val)) {
  1312. unset($tpldirList[$key]);
  1313. } else {
  1314. $tpldirList[$key] = preg_replace('/^(.*)template\/'.$tpl_theme.'(pc|mobile)$/i', '$2', $val);
  1315. }
  1316. }
  1317. !empty($tpldirList) && arsort($tpldirList);
  1318. $this->assign('tpldirList', $tpldirList);
  1319. $content = '';
  1320. if ('special' == $nid) {
  1321. $fileContent = @file_get_contents('./data/model/template/pc/view_custommodel.htm');
  1322. if (!empty($fileContent)) {
  1323. $content = $fileContent;
  1324. $replace = <<<EOF
  1325. <section class="article-list">
  1326. {eyou:specnode code="default1" id="field"}
  1327. <article>
  1328. {eyou:notempty name="\$field.is_litpic"}
  1329. <a href="{\$field.arcurl}" target="_blank" title="{\$field.title}" style="float: left; margin-right: 10px"> <img src="{\$field.litpic}" alt="{\$field.title}" height="100" /> </a>
  1330. {/eyou:notempty}
  1331. <h2><a href="{\$field.arcurl}" target="_blank">{\$field.title}</a><span>{\$field.click}°C</span></h2>
  1332. <div class="excerpt">
  1333. <p>{\$field.seo_description}</p>
  1334. </div>
  1335. <div class="meta">
  1336. <span class="item"><time>{\$field.add_time|MyDate='Y-m-d',###}</time></span>
  1337. <span class="item"><a href="{\$field.typeurl}" target="_blank">{\$field.typename}</a></span>
  1338. </div>
  1339. </article>
  1340. {/eyou:specnode}
  1341. </section>
  1342. EOF;
  1343. $content = str_replace("<!-- #special# -->", $replace, $content);
  1344. }
  1345. }
  1346. $this->assign('content', $content);
  1347. $this->assign('type', $type);
  1348. $this->assign('nid', $nid);
  1349. $this->assign('tpl_theme', TPL_THEME);
  1350. return $this->fetch();
  1351. }
  1352. /**
  1353. * 检测自定义文件名是否存在
  1354. */
  1355. public function ajax_check_htmlfilename()
  1356. {
  1357. $htmlfilename = input('post.htmlfilename/s');
  1358. $htmlfilename = trim($htmlfilename);
  1359. if (!empty($htmlfilename)) {
  1360. $aid = input('post.aid/d');
  1361. $typeid = input('post.typeid/d');
  1362. $htmlfilename = preg_replace("/[^\x{4e00}-\x{9fa5}\w\-]+/u", "-", $htmlfilename);
  1363. // $htmlfilename = strtolower($htmlfilename);
  1364. $map = array(
  1365. 'htmlfilename' => $htmlfilename,
  1366. 'lang' => $this->admin_lang,
  1367. );
  1368. if ($aid > 0) {
  1369. $map['aid'] = array('neq', $aid);
  1370. }
  1371. if ($typeid > 0) {
  1372. $map['typeid'] = array('eq', $typeid);
  1373. }
  1374. $result = Db::name('archives')->where($map)->find();
  1375. if (!empty($result)) {
  1376. $this->error('同栏目下,自定义文件名已存在!');
  1377. }
  1378. }
  1379. $this->success('自定义文件名可用!');
  1380. }
  1381. //投稿列表
  1382. public function index_draft()
  1383. {
  1384. $assign_data = array();
  1385. $condition = [];
  1386. if (is_dir('./weapp/MultiMerchant/')) {
  1387. $condition['a.merchant_id'] = 0;
  1388. }
  1389. $param = input('param.');
  1390. $typeid = input('typeid/d', 0);
  1391. $draft_type = input('param.draft_type/s');
  1392. foreach (['keywords','typeid','draft_type'] as $key) {
  1393. $param[$key] = addslashes(trim($param[$key]));
  1394. if (isset($param[$key]) && $param[$key] !== '') {
  1395. if ($key == 'keywords') {
  1396. $condition['a.title'] = array('LIKE', "%{$param[$key]}%");
  1397. } else if ($key == 'typeid') {
  1398. $typeid = $param[$key];
  1399. $hasRow = model('Arctype')->getHasChildren($typeid);
  1400. $typeids = get_arr_column($hasRow, 'id');
  1401. //权限控制 by 小虎哥
  1402. $admin_info = session('admin_info');
  1403. if (0 < intval($admin_info['role_id'])) {
  1404. $auth_role_info = $admin_info['auth_role_info'];
  1405. if(! empty($auth_role_info)){
  1406. if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
  1407. $condition['a.admin_id'] = $admin_info['admin_id'];
  1408. }
  1409. if(! empty($auth_role_info['permission']['arctype'])){
  1410. if (!empty($typeid)) {
  1411. $typeids = array_intersect($typeids, $auth_role_info['permission']['arctype']);
  1412. }
  1413. }
  1414. }
  1415. }
  1416. $condition['a.typeid'] = array('IN', $typeids);
  1417. } else if ($key == 'draft_type') {
  1418. if ('user' == $param[$key]) {
  1419. $condition['a.users_id'] = array('gt', 0);
  1420. } else if ('admin' == $param[$key]) {
  1421. $condition['a.users_id'] = array('eq', 0);
  1422. }
  1423. } else {
  1424. $condition['a.'.$key] = array('eq', $param[$key]);
  1425. }
  1426. }
  1427. }
  1428. //权限控制 by 小虎哥
  1429. if (empty($typeid)) {
  1430. $typeids = [];
  1431. $admin_info = session('admin_info');
  1432. if (0 < intval($admin_info['role_id'])) {
  1433. $auth_role_info = $admin_info['auth_role_info'];
  1434. if(! empty($auth_role_info)){
  1435. if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
  1436. $condition['a.admin_id'] = $admin_info['admin_id'];
  1437. }
  1438. if (!empty($auth_role_info['permission']['arctype'])) $typeids = $auth_role_info['permission']['arctype'];
  1439. }
  1440. }
  1441. if (!empty($typeids)) $condition['a.typeid'] = array('IN', $typeids);
  1442. }
  1443. if (empty($typeid)) {
  1444. $id_tmp = [6,8];
  1445. // 只显示允许发布文档的模型,且是开启状态
  1446. $channelIds = Db::name('channeltype')->where('status',0)
  1447. ->whereOr('id','IN',$id_tmp)->column('id');
  1448. $condition['a.channel'] = array('NOT IN', $channelIds);
  1449. } else {
  1450. // 只显示当前栏目对应模型下的文档
  1451. $current_channel = Db::name('arctype')->where('id',$typeid)->getField('current_channel');
  1452. $condition['a.channel'] = array('eq', $current_channel);
  1453. }
  1454. $condition['a.arcrank'] = -1;
  1455. $condition['a.lang'] = array('eq', $this->admin_lang);
  1456. $condition['a.is_del'] = array('eq', 0);
  1457. // 自定义排序
  1458. $orderby = input('param.orderby/s');
  1459. $orderway = input('param.orderway/s');
  1460. $orderby = !empty($orderby) ? "a.{$orderby} {$orderway}, a.aid desc" : "a.aid desc";
  1461. // 总投稿数
  1462. $condition1 = $condition2 = $condition;
  1463. if (!empty($condition1['a.users_id'])) {
  1464. unset($condition1['a.users_id']);
  1465. }
  1466. $allCount = Db::name('archives')->alias('a')->where($condition1)->count('aid');
  1467. $assign_data['allCount'] = $allCount;
  1468. if (empty($draft_type)) {
  1469. $condition2['a.users_id'] = ['gt', 0];
  1470. $userCount = Db::name('archives')->alias('a')->where($condition2)->count('aid');
  1471. }
  1472. $currentCount = Db::name('archives')->alias('a')->where($condition)->count('aid');
  1473. // 查询并处理缓存表
  1474. $SqlQuery = Db::name('archives')->alias('a')->where($condition)->fetchSql()->count('aid');
  1475. $count = Db::name('sql_cache_table')->where(['sql_md5'=>md5($SqlQuery)])->getField('sql_result');
  1476. $count = ($count < 0) ? 0 : $count;
  1477. if (empty($count)) {
  1478. $count = Db::name('archives')->alias('a')->where($condition)->count('aid');
  1479. // 添加查询执行语句到mysql缓存表
  1480. $SqlCacheTable = [
  1481. 'sql_name' => '|archives|draft|',
  1482. 'sql_result' => $count,
  1483. 'sql_md5' => md5($SqlQuery),
  1484. 'sql_query' => $SqlQuery,
  1485. 'add_time' => getTime(),
  1486. 'update_time' => getTime()
  1487. ];
  1488. if (!empty($typeid)) $SqlCacheTable['sql_name'] = $SqlCacheTable['sql_name'] . $typeid . '|';
  1489. Db::name('sql_cache_table')->insertGetId($SqlCacheTable);
  1490. }
  1491. if ('user' == $draft_type) { // 前台投稿总数
  1492. $userCount = $currentCount;
  1493. $adminCount = $allCount - $userCount;
  1494. } else if ('admin' == $draft_type) { // 后台发布待审核总数
  1495. $adminCount = $currentCount;
  1496. $userCount = $allCount - $adminCount;
  1497. } else {
  1498. $adminCount = $allCount - $userCount;
  1499. }
  1500. $assign_data['userCount'] = $userCount;
  1501. $assign_data['adminCount'] = $adminCount;
  1502. // 分页
  1503. $Page = new Page($count, config('paginate.list_rows'));
  1504. $list = [];
  1505. if (0 < $count) {
  1506. // 数据查询,搜索出主键ID的值
  1507. $limit = $count > config('paginate.list_rows') ? $Page->firstRow.','.$Page->listRows : $count;
  1508. $list = Db::name('archives')
  1509. ->field("a.aid,a.channel,a.admin_id,a.users_id")
  1510. ->alias('a')
  1511. ->where($condition)
  1512. ->orderRaw($orderby)
  1513. ->limit($limit)
  1514. ->getAllWithIndex('aid');
  1515. $aids = [];
  1516. $admin_ids = [];
  1517. $users_ids = [];
  1518. $channelIds = [];
  1519. // 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
  1520. if ($list) {
  1521. foreach ($list as $key => $val) {
  1522. array_push($aids, $val['aid']);
  1523. !empty($val['admin_id']) && array_push($admin_ids, $val['admin_id']);
  1524. !empty($val['users_id']) && array_push($users_ids, $val['users_id']);
  1525. array_push($channelIds, $val['channel']);
  1526. }
  1527. $fields = "b.*, a.*, a.aid as aid";
  1528. $row = Db::name('archives')
  1529. ->field($fields)
  1530. ->alias('a')
  1531. ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
  1532. ->where('a.aid', 'in', $aids)
  1533. ->getAllWithIndex('aid');
  1534. // 获取当页文档的所有模型
  1535. $assign_data['channelRow'] = Db::name('channeltype')->field('id, ctl_name, ifsystem')
  1536. ->where('id', 'IN', $channelIds)
  1537. ->getAllWithIndex('id');
  1538. $userlist = Db::name('users')->field('users_id,username,nickname')->where('users_id', 'in', $users_ids)->getAllWithIndex('users_id');
  1539. $adminlist = Db::name('admin')->field('admin_id,user_name,pen_name')->where('admin_id', 'in', $admin_ids)->getAllWithIndex('admin_id');
  1540. foreach ($list as $key => $val) {
  1541. $row[$val['aid']]['arcurl'] = get_arcurl($row[$val['aid']]);
  1542. $row[$val['aid']]['litpic'] = handle_subdir_pic($row[$val['aid']]['litpic']);
  1543. if (!empty($userlist[$val['users_id']])) {
  1544. $row[$val['aid']]['username'] = !empty($userlist[$val['users_id']]['nickname']) ? $userlist[$val['users_id']]['nickname'] : $userlist[$val['users_id']]['username'];
  1545. } else if (!empty($adminlist[$val['admin_id']])) {
  1546. $row[$val['aid']]['username'] = !empty($adminlist[$val['admin_id']]['pen_name']) ? $adminlist[$val['admin_id']]['pen_name'] : $adminlist[$val['admin_id']]['user_name'];
  1547. } else {
  1548. $row[$val['aid']]['username'] = '匿名';
  1549. }
  1550. $list[$key] = $row[$val['aid']];
  1551. }
  1552. }
  1553. }
  1554. // 加载信息
  1555. $assign_data['page'] = $Page->show();
  1556. $assign_data['list'] = $list;
  1557. $assign_data['pager'] = $Page;
  1558. $assign_data['typeid'] = $typeid;
  1559. $arctype_info = array(); // 当前栏目信息
  1560. if ($typeid > 0) $arctype_info = Db::name('arctype')->field('typename,current_channel')->find($typeid);
  1561. $assign_data['arctype_info'] = $arctype_info;
  1562. // $assign_data['arctype_html'] = allow_release_arctype($typeid, array()); // 允许发布文档列表的栏目
  1563. $assign_data['seo_pseudo'] = tpCache('global.seo_pseudo'); // 前台URL模式
  1564. $assign_data['archives_flags'] = model('ArchivesFlag')->getList(); // 文档属性
  1565. $assign_data['shop_open'] = getUsersConfigData('shop.shop_open'); // 商城开关
  1566. $assign_data['is_arctype'] = Db::name('arctype')->where(['is_del'=>0,'lang'=>get_current_lang()])->count(); // 是否存在栏目
  1567. $assign_data['draft_type'] = $draft_type;
  1568. // 页面url
  1569. $assign_data['pageurl'] = request()->url(true);
  1570. $assign_data['menu'] = input('param.menu/d', 0);
  1571. $this->assign($assign_data);
  1572. return $this->fetch('index_draft');
  1573. }
  1574. //文档标题重复检测
  1575. public function check_title_repeat($title='',$aid=0)
  1576. {
  1577. $map['title'] = $title;
  1578. if (!empty($aid)){
  1579. $map['aid'] = ['NEQ', $aid];
  1580. }
  1581. $count = Db::name('archives')->where($map)->count('aid');
  1582. if (!empty($count)){
  1583. $this->error("<font color='black'>系统已存在标题为'<font color='red'>".$title."'</font>的文档! </font><a href='javascript:void(0);' onclick='layer.closeAll();'>[<font color='red'>关闭</font>]</a>");
  1584. }
  1585. $this->success("没有重复!");
  1586. }
  1587. //ajax改变富文本编辑器远程图片本地化/清除非本站链接
  1588. public function ajax_editor_set()
  1589. {
  1590. if (IS_AJAX){
  1591. $post = input('post.');
  1592. if (0 == $post['value']){
  1593. $post['value'] = 1;
  1594. }elseif (1 == $post['value']){
  1595. $post['value'] = 0;
  1596. }
  1597. $editor_arr[$post['name']] = $post['value'];
  1598. $res = tpSetting('editor', $editor_arr);
  1599. if (!empty($res)){
  1600. $this->success("保存成功!");
  1601. }else{
  1602. $this->error('保存失败!');
  1603. }
  1604. }
  1605. }
  1606. /**
  1607. * 设置来源列表
  1608. * @return [type] [description]
  1609. */
  1610. public function ajax_set_originlist()
  1611. {
  1612. if (IS_POST) {
  1613. $originlist = [];
  1614. $origin = input('param.origin/s');
  1615. $origin = str_replace(["\r\n", "\r", "\n", PHP_EOL], "~|~", $origin);
  1616. $originArr = explode("~|~", $origin);
  1617. foreach ($originArr as $key => $val) {
  1618. $val = trim($val);
  1619. if (!empty($val)) {
  1620. array_push($originlist, $val);
  1621. }
  1622. }
  1623. tpSetting('system', ['system_originlist'=>json_encode($originlist)]);
  1624. $originlist_str = implode(PHP_EOL, $originlist);
  1625. $this->success('操作成功', null, ['originlist_str'=>$originlist_str]);
  1626. }
  1627. $this->error('操作失败');
  1628. }
  1629. /**
  1630. * 查找显示来源列表
  1631. * @return [type] [description]
  1632. */
  1633. public function search_origin()
  1634. {
  1635. if (IS_AJAX_POST) {
  1636. $post = input('param.');
  1637. $keyword = trim($post['keyword']);
  1638. $originlist = tpSetting('system.system_originlist');
  1639. $originlist = json_decode($originlist, true);
  1640. $search_data = $originlist;
  1641. if (!empty($keyword)) {
  1642. $search_data = [];
  1643. if ($originlist) {
  1644. foreach ($originlist as $k => $v) {
  1645. if (preg_match("/$keyword/s", $v)) $search_data[] = $v;
  1646. }
  1647. }
  1648. }
  1649. $this->success("获取成功",null,$search_data);
  1650. }
  1651. }
  1652. /**
  1653. * 发布/编辑文档时选择副栏目
  1654. * @return [type] [description]
  1655. */
  1656. public function ajax_get_stypeid_list()
  1657. {
  1658. $assign_data = [];
  1659. $channel = input('param.channel/d');
  1660. $catid = input('param.catid/d',1);
  1661. if (empty($channel)) {
  1662. $this->error('URL缺少channel参数!');
  1663. }
  1664. $assign_data['channel'] = $channel;
  1665. // 目录列表
  1666. $where = [];
  1667. $where['current_channel'] = $channel;
  1668. $where['is_del'] = 0; // 回收站功能
  1669. $arctypeLogic = new ArctypeLogic;
  1670. /*获取所有有子栏目的栏目id*/
  1671. $parent_ids = Db::name('arctype')->where([
  1672. 'parent_id' => ['gt', 0],
  1673. 'is_del' => 0,
  1674. ])->group('parent_id')->cache(true, EYOUCMS_CACHE_TIME, 'arctype')->column('parent_id');
  1675. $cookied_treeclicked = json_decode(cookie('stypeid-treeClicked-Arr'));
  1676. empty($cookied_treeclicked) && $cookied_treeclicked = [];
  1677. $all_treeclicked = cookie('stypeid-treeClicked_All');
  1678. empty($all_treeclicked) && $all_treeclicked = [];
  1679. $tree = [
  1680. 'has_children'=>!empty($parent_ids) ? 1 : 0,
  1681. 'parent_ids'=>json_encode($parent_ids),
  1682. 'all_treeclicked'=>$all_treeclicked,
  1683. 'cookied_treeclicked'=>$cookied_treeclicked,
  1684. 'cookied_treeclicked_arr'=>json_encode($cookied_treeclicked),
  1685. ];
  1686. $assign_data['tree'] = $tree;
  1687. /* end */
  1688. // 副栏目
  1689. $stypeid = input('param.stypeid/s');
  1690. $stypeid = trim($stypeid, ',');
  1691. $stypeid_arr = explode(',', $stypeid);
  1692. $typename_arr = [];
  1693. $row = Db::name('arctype')->field('id,typename')->where(['id'=>['IN', $stypeid_arr]])->select();
  1694. foreach ($row as $key => $val) {
  1695. $typename_arr[] = "{$val['typename']}";
  1696. }
  1697. $stypename = implode('&nbsp;&nbsp;|&nbsp;&nbsp;', $typename_arr);
  1698. // 主栏目
  1699. $typeid = input('param.typeid/d');
  1700. // !empty($typeid) && array_push($stypeid_arr, $typeid);
  1701. $assign_data['typeid'] = $typeid;
  1702. //加入区域条件
  1703. $proid = 1; //默认广东省
  1704. $typeid = $_GET['typeid']?$_GET['typeid']:0;
  1705. $typeid = (int)$typeid;
  1706. $arctypeInfo = Db::name('arctype')->find($typeid);
  1707. if((int)$arctypeInfo['area_id'] > 1){
  1708. $proid = (int)$arctypeInfo['area_id'];
  1709. }else{
  1710. if((int)$catid === 0) {
  1711. $catid = 1;
  1712. //默认广东省
  1713. }
  1714. $proid = $catid;
  1715. }
  1716. //再次计算
  1717. //$stypeid 存在 查询默认的
  1718. //不然没结果
  1719. $arctype = Db::name('arctype')->where('id','=',$stypeid)->find();
  1720. if((int)$stypeid > 0){
  1721. $proid = $arctype['area_id'];
  1722. }
  1723. $this->assign('catid',$proid);
  1724. //var_dump($catid);
  1725. $arctype_list = $arctypeLogic->arctype_list(0, 0, false, 0, $where, false,'',$proid);
  1726. $assign_data['arctype_list'] = $arctype_list;
  1727. $assign_data['stypeid'] = $stypeid;
  1728. $assign_data['stypename'] = $stypename;
  1729. $assign_data['stypeid_arr'] = $stypeid_arr;
  1730. //区域数据
  1731. /*
  1732. * 调用省份数据
  1733. */
  1734. $pro_list = Db::table('ey_citysite')->where([
  1735. "level" => 1,
  1736. "parent_id" => 0,
  1737. "topid" => 0,
  1738. "status" => 1,
  1739. ])->select();
  1740. $this->assign('pro_list',$pro_list);
  1741. $this->assign($assign_data);
  1742. return $this->fetch();
  1743. }
  1744. }