No Description

Custom.php 46KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海口快推科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\admin\controller;
  14. use think\Page;
  15. use think\Db;
  16. class Custom extends Base
  17. {
  18. // 模型标识
  19. public $nid = '';
  20. // 模型ID
  21. public $channeltype = 0;
  22. // 模型附加表
  23. public $table = '';
  24. /*
  25. * 初始化操作
  26. */
  27. public function _initialize()
  28. {
  29. parent::_initialize();
  30. $this->archives_db = Db::name('archives');
  31. $this->channeltype = input('param.channel/d', 0);
  32. $channeltypeRow = Db::name('channeltype')->field('nid,table')->where(['id'=>['eq',$this->channeltype]])->find();
  33. if (empty($this->channeltype) || empty($channeltypeRow)) {
  34. $this->error('自定义模型ID丢失,打开失败!');
  35. }
  36. $this->nid = $channeltypeRow['nid'];
  37. $this->table = $channeltypeRow['table'];
  38. $this->assign('nid', $this->nid);
  39. $this->assign('table', $this->table);
  40. $this->assign('channeltype', $this->channeltype);
  41. // 返回页面
  42. $paramTypeid = input('param.typeid/d', 0);
  43. $this->callback_url = url('Custom/index', ['lang' => $this->admin_lang, 'channel'=>$this->channeltype, 'typeid' => $paramTypeid]);
  44. $this->assign('callback_url', $this->callback_url);
  45. }
  46. //列表
  47. public function index()
  48. {
  49. $assign_data = $condition = [];
  50. // 获取到所有GET参数
  51. $param = input('param.');
  52. $typeid = input('typeid/d', 0);
  53. // 搜索、筛选查询条件处理
  54. foreach (['keywords', 'typeid', 'flag', 'is_release','province_id','city_id','area_id'] as $key) {
  55. if ($key == 'typeid' && empty($param['typeid'])) {
  56. $typeids = Db::name('arctype')->where('current_channel', $this->channeltype)->column('id');
  57. $condition['a.typeid'] = array('IN', $typeids);
  58. }
  59. if (isset($param[$key]) && $param[$key] !== '') {
  60. if ($key == 'keywords') {
  61. $keywords = $param[$key];
  62. $condition['a.title'] = array('LIKE', "%{$param[$key]}%");
  63. } else if ($key == 'typeid') {
  64. $typeid = $param[$key];
  65. $hasRow = model('Arctype')->getHasChildren($typeid);
  66. $typeids = get_arr_column($hasRow, 'id');
  67. // 权限控制 by 小虎哥
  68. $admin_info = session('admin_info');
  69. if (0 < intval($admin_info['role_id'])) {
  70. $auth_role_info = $admin_info['auth_role_info'];
  71. if (!empty($typeid) && !empty($auth_role_info) && !empty($auth_role_info['permission']['arctype'])) {
  72. $typeids = array_intersect($typeids, $auth_role_info['permission']['arctype']);
  73. }
  74. }
  75. $condition['a.typeid'] = array('IN', $typeids);
  76. } else if ($key == 'flag') {
  77. if ('is_release' == $param[$key]) {
  78. $condition['a.users_id'] = array('gt', 0);
  79. } else {
  80. $FlagNew = $param[$key];
  81. $condition['a.'.$param[$key]] = array('eq', 1);
  82. }
  83. } else if (in_array($key, ['province_id','city_id','area_id'])) {
  84. if (!empty($param['area_id'])) {
  85. $condition['a.area_id'] = $param['area_id'];
  86. } else if (!empty($param['city_id'])) {
  87. $condition['a.city_id'] = $param['city_id'];
  88. } else if (!empty($param['province_id'])) {
  89. $condition['a.province_id'] = $param['province_id'];
  90. }
  91. } else {
  92. $condition['a.'.$key] = array('eq', $param[$key]);
  93. }
  94. }
  95. }
  96. // 权限控制 by 小虎哥
  97. $admin_info = session('admin_info');
  98. if (0 < intval($admin_info['role_id'])) {
  99. $auth_role_info = $admin_info['auth_role_info'];
  100. if (!empty($auth_role_info) && isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']) {
  101. $condition['a.admin_id'] = $admin_info['admin_id'];
  102. }
  103. }
  104. // 时间检索条件
  105. $begin = strtotime(input('add_time_begin'));
  106. $end = strtotime(input('add_time_end'));
  107. if ($begin > 0 && $end > 0) {
  108. $condition['a.add_time'] = array('between', "$begin, $end");
  109. } else if ($begin > 0) {
  110. $condition['a.add_time'] = array('egt', $begin);
  111. } else if ($end > 0) {
  112. $condition['a.add_time'] = array('elt', $end);
  113. }
  114. // 必要条件
  115. $condition['a.channel'] = array('eq', $this->channeltype);
  116. $condition['a.lang'] = array('eq', $this->admin_lang);
  117. $condition['a.is_del'] = array('eq', 0);
  118. $conditionNew = "(a.users_id = 0 OR (a.users_id > 0 AND a.arcrank >= 0))";
  119. // 自定义排序
  120. $orderby = input('param.orderby/s');
  121. $orderway = input('param.orderway/s');
  122. if (!empty($orderby) && !empty($orderway)) {
  123. $orderby = "a.{$orderby} {$orderway}, a.aid desc";
  124. } else {
  125. $orderby = "a.aid desc";
  126. }
  127. // 数据查询,搜索出主键ID的值
  128. $SqlQuery = $this->archives_db->alias('a')->where($condition)->where($conditionNew)->fetchSql()->count('aid');
  129. $count = Db::name('sql_cache_table')->where(['sql_md5'=>md5($SqlQuery)])->getField('sql_result');
  130. $count = ($count < 0) ? 0 : $count;
  131. if (empty($count)) {
  132. $count = $this->archives_db->alias('a')->where($condition)->where($conditionNew)->count('aid');
  133. /*添加查询执行语句到mysql缓存表*/
  134. $SqlCacheTable = [
  135. 'sql_name' => '|' . $this->table . '|' . $this->channeltype . '|',
  136. 'sql_result' => $count,
  137. 'sql_md5' => md5($SqlQuery),
  138. 'sql_query' => $SqlQuery,
  139. 'add_time' => getTime(),
  140. 'update_time' => getTime(),
  141. ];
  142. if (!empty($FlagNew)) $SqlCacheTable['sql_name'] = $SqlCacheTable['sql_name'] . $FlagNew . '|';
  143. if (!empty($typeid)) $SqlCacheTable['sql_name'] = $SqlCacheTable['sql_name'] . $typeid . '|';
  144. if (!empty($keywords)) $SqlCacheTable['sql_name'] = '|custom|keywords|';
  145. Db::name('sql_cache_table')->insertGetId($SqlCacheTable);
  146. /*END*/
  147. }
  148. $Page = new Page($count, config('paginate.list_rows'));
  149. $list = [];
  150. if (!empty($count)) {
  151. $limit = $count > config('paginate.list_rows') ? $Page->firstRow.','.$Page->listRows : $count;
  152. $list = $this->archives_db
  153. ->field("a.aid")
  154. ->alias('a')
  155. ->where($condition)
  156. ->where($conditionNew)
  157. ->order($orderby)
  158. ->limit($limit)
  159. ->getAllWithIndex('aid');
  160. if (!empty($list)) {
  161. $aids = array_keys($list);
  162. $fields = "b.*, a.*, a.aid as aid";
  163. $row = $this->archives_db
  164. ->field($fields)
  165. ->alias('a')
  166. ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
  167. ->where('a.aid', 'in', $aids)
  168. ->getAllWithIndex('aid');
  169. foreach ($list as $key => $val) {
  170. $row[$val['aid']]['arcurl'] = get_arcurl($row[$val['aid']]);
  171. $row[$val['aid']]['litpic'] = handle_subdir_pic($row[$val['aid']]['litpic']);
  172. $list[$key] = $row[$val['aid']];
  173. }
  174. }
  175. }
  176. $show = $Page->show();
  177. $assign_data['page'] = $show;
  178. $assign_data['list'] = $list;
  179. $assign_data['pager'] = $Page;
  180. $assign_data['typeid'] = $typeid;
  181. $assign_data['tab'] = input('param.tab/d', 3);// 选项卡
  182. $assign_data['archives_flags'] = model('ArchivesFlag')->getList();// 文档属性
  183. $assign_data['arctype_info'] = $typeid > 0 ? Db::name('arctype')->field('typename')->find($typeid) : [];// 当前栏目信息
  184. $this->assign($assign_data);
  185. return $this->fetch();
  186. }
  187. /**
  188. * 添加
  189. */
  190. public function add()
  191. {
  192. $admin_info = session('admin_info');
  193. $auth_role_info = $admin_info['auth_role_info'];
  194. $this->assign('auth_role_info', $auth_role_info);
  195. $this->assign('admin_info', $admin_info);
  196. if (IS_POST) {
  197. $post = input('post.');
  198. model('Archives')->editor_auto_210607($post);
  199. /* 处理TAG标签 */
  200. if (!empty($post['tags_new'])) {
  201. $post['tags'] = !empty($post['tags']) ? $post['tags'] . ',' . $post['tags_new'] : $post['tags_new'];
  202. unset($post['tags_new']);
  203. }
  204. $post['tags'] = explode(',', $post['tags']);
  205. $post['tags'] = array_unique($post['tags']);
  206. $post['tags'] = implode(',', $post['tags']);
  207. /* END */
  208. /*获取第一个html类型的内容,作为文档的内容来截取SEO描述*/
  209. $contentField = Db::name('channelfield')->where([
  210. 'channel_id' => $this->channeltype,
  211. 'dtype' => 'htmltext',
  212. ])->getField('name');
  213. $content = empty($post['addonFieldExt'][$contentField]) ? '' : htmlspecialchars_decode($post['addonFieldExt'][$contentField]);
  214. /*--end*/
  215. // 根据标题自动提取相关的关键字
  216. $seo_keywords = $post['seo_keywords'];
  217. if (!empty($seo_keywords)) {
  218. $seo_keywords = str_replace(',', ',', $seo_keywords);
  219. } else {
  220. // $seo_keywords = get_split_word($post['title'], $content);
  221. }
  222. // 自动获取内容第一张图片作为封面图
  223. $is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
  224. $litpic = '';
  225. if ($is_remote == 1) {
  226. $litpic = $post['litpic_remote'];
  227. } else {
  228. $litpic = $post['litpic_local'];
  229. }
  230. if (empty($litpic)) {
  231. $litpic = get_html_first_imgurl($content);
  232. }
  233. $post['litpic'] = $litpic;
  234. /*是否有封面图*/
  235. if (empty($post['litpic'])) {
  236. $is_litpic = 0; // 无封面图
  237. } else {
  238. $is_litpic = 1; // 有封面图
  239. }
  240. // SEO描述
  241. $seo_description = '';
  242. if (empty($post['seo_description']) && !empty($content)) {
  243. $seo_description = @msubstr(checkStrHtml($content), 0, config('global.arc_seo_description_length'), false);
  244. } else {
  245. $seo_description = $post['seo_description'];
  246. }
  247. // 外部链接跳转
  248. $jumplinks = '';
  249. $is_jump = isset($post['is_jump']) ? $post['is_jump'] : 0;
  250. if (intval($is_jump) > 0) {
  251. $jumplinks = $post['jumplinks'];
  252. }
  253. // 模板文件,如果文档模板名与栏目指定的一致,默认就为空。让它跟随栏目的指定而变
  254. if ($post['type_tempview'] == $post['tempview']) {
  255. unset($post['type_tempview']);
  256. unset($post['tempview']);
  257. }
  258. //处理自定义文件名,仅由字母数字下划线和短横杆组成,大写强制转换为小写
  259. $htmlfilename = trim($post['htmlfilename']);
  260. if (!empty($htmlfilename)) {
  261. $htmlfilename = preg_replace("/[^\x{4e00}-\x{9fa5}\w\-]+/u", "-", $htmlfilename);
  262. // $htmlfilename = strtolower($htmlfilename);
  263. //判断是否存在相同的自定义文件名
  264. $map = [
  265. 'htmlfilename' => $htmlfilename,
  266. 'lang' => $this->admin_lang,
  267. ];
  268. if (!empty($post['typeid'])) {
  269. $map['typeid'] = array('eq', $post['typeid']);
  270. }
  271. $filenameCount = Db::name('archives')->where($map)->count();
  272. if (!empty($filenameCount)) {
  273. $this->error("同栏目下,自定义文件名已存在!");
  274. } else if (preg_match('/^(\d+)$/i', $htmlfilename)) {
  275. $this->error("自定义文件名不能纯数字,会与文档ID冲突!");
  276. }
  277. } else {
  278. // 处理外贸链接
  279. if (is_dir('./weapp/Waimao/')) {
  280. $waimaoLogic = new \weapp\Waimao\logic\WaimaoLogic;
  281. $waimaoLogic->get_new_htmlfilename($htmlfilename, $post, 'add', $this->globalConfig);
  282. }
  283. }
  284. $post['htmlfilename'] = $htmlfilename;
  285. //做自动通过审核判断
  286. if ($admin_info['role_id'] > 0 && $auth_role_info['check_oneself'] < 1) {
  287. $post['arcrank'] = -1;
  288. }
  289. // 副栏目
  290. if (isset($post['stypeid'])) {
  291. $post['stypeid'] = preg_replace('/([^\d\,\,]+)/i', ',', $post['stypeid']);
  292. $post['stypeid'] = str_replace(',', ',', $post['stypeid']);
  293. $post['stypeid'] = trim($post['stypeid'], ',');
  294. $post['stypeid'] = str_replace(",{$post['typeid']},", ',', ",{$post['stypeid']},");
  295. $post['stypeid'] = trim($post['stypeid'], ',');
  296. }
  297. //查询排序 等级
  298. $sort_order = Db::name('archives')->where('aid','=',(int)$post['level_group_name'])->value('sort_order');
  299. // --存储数据
  300. $newData = array(
  301. 'typeid'=> empty($post['typeid']) ? 0 : $post['typeid'],
  302. 'channel' => $this->channeltype,
  303. 'is_b' => empty($post['is_b']) ? 0 : $post['is_b'],
  304. 'is_head' => empty($post['is_head']) ? 0 : $post['is_head'],
  305. 'is_special' => empty($post['is_special']) ? 0 : $post['is_special'],
  306. 'is_recom' => empty($post['is_recom']) ? 0 : $post['is_recom'],
  307. 'is_roll' => empty($post['is_roll']) ? 0 : $post['is_roll'],
  308. 'is_slide' => empty($post['is_slide']) ? 0 : $post['is_slide'],
  309. 'is_diyattr' => empty($post['is_diyattr']) ? 0 : $post['is_diyattr'],
  310. 'editor_remote_img_local'=> empty($post['editor_remote_img_local']) ? 0 : $post['editor_remote_img_local'],
  311. 'editor_img_clear_link' => empty($post['editor_img_clear_link']) ? 0 : $post['editor_img_clear_link'],
  312. 'is_jump' => $is_jump,
  313. 'is_litpic' => $is_litpic,
  314. 'jumplinks' => $jumplinks,
  315. 'origin' => empty($post['origin']) ? '网络' : $post['origin'],
  316. 'seo_keywords' => $seo_keywords,
  317. 'seo_description' => $seo_description,
  318. 'admin_id' => session('admin_info.admin_id'),
  319. 'lang' => $this->admin_lang,
  320. 'sort_order' => 100,
  321. 'crossed_price' => empty($post['crossed_price']) ? 0 : floatval($post['crossed_price']),
  322. 'add_time' => strtotime($post['add_time']),
  323. 'update_time' => strtotime($post['add_time']),
  324. 'product_id' => (int)$post['product_id'], //增加
  325. 'lunwen_id' => (int)$post['lunwen_id'], //增加
  326. 'level_group_id' => (int)$post['level_group_id'],
  327. 'level_id' => (int)$post['level_group_name'],
  328. 'level' => (int)$sort_order,
  329. 'product_tag_id' => (int)$post['product_tag_id'],
  330. 'area_tag_id' => (int)$post['area_tag_id'],
  331. );
  332. $data = array_merge($post, $newData);
  333. $aid = $this->archives_db->insertGetId($data);
  334. $_POST['aid'] = $aid;
  335. if ($aid) {
  336. // ---------后置操作
  337. model('Custom')->afterSave($aid, $data, 'add', $this->table);
  338. // 添加查询执行语句到mysql缓存表
  339. model('SqlCacheTable')->InsertSqlCacheTable();
  340. // ---------end
  341. adminLog('新增数据:'.$data['title']);
  342. //新增序列号 (论文期刊和论文模板)
  343. //只考虑新增场景 其他的用api修复
  344. if((int)$newData['typeid'] === 116 || (int)$newData['typeid'] === 123 || (int)$newData['typeid'] === 127 || (int)$newData['typeid'] === 128){
  345. $last = Db::name('seo_number')->where([
  346. "type" => 4,
  347. "tid" => (int)$post['typeid'],
  348. 'topid' => 0,
  349. 'parentid' => 0,
  350. 'area_id' => 0,
  351. ])->order('number desc')->find();
  352. if(empty($last['number'])){
  353. $num = 1;
  354. }else{
  355. $num = (int)$last['number'] + 1;
  356. }
  357. $in_data = [
  358. "type" => 4, //产品类型
  359. "aid" => $aid, //实际的ID
  360. "tid" => (int)$post['typeid'], //属于哪个栏目的
  361. 'is_del' => 0,
  362. 'is_kan' => 0, // 0正常 1审核
  363. 'status' => 1,
  364. 'area_id' => 0,
  365. 'topid' => 0,
  366. 'parentid' => 0,
  367. 'number' => $num
  368. ];
  369. Db::name('seo_number')->insert($in_data);
  370. }else if((int)$newData['typeid'] === 126 || (int)$newData['typeid'] === 825 || (int)$newData['typeid'] === 826){
  371. //资料文档
  372. $last = Db::name('seo_number')->where([
  373. "type" => 5,
  374. "tid" => (int)$post['typeid'],
  375. 'topid' => 0,
  376. 'parentid' => 0,
  377. 'area_id' => (int)$post['province_id'], //如果是0的话 后续也不能改
  378. ])->order('number desc')->find();
  379. if(empty($last['number'])){
  380. $num = 1;
  381. }else{
  382. $num = (int)$last['number'] + 1;
  383. }
  384. $in_data = [
  385. "type" => 5, //产品类型
  386. "aid" => $aid, //实际的ID
  387. "tid" => (int)$post['typeid'], //属于哪个栏目的
  388. 'is_del' => 0,
  389. 'is_kan' => 0, // 0正常 1审核
  390. 'status' => 1,
  391. 'area_id' => (int)$post['province_id'],
  392. 'topid' => 0,
  393. 'parentid' => 0,
  394. 'number' => $num
  395. ];
  396. Db::name('seo_number')->insert($in_data);
  397. }else if((int)$newData['typeid'] === 120 || (int)$newData['typeid'] === 118 || (int)$newData['typeid'] === 122 || (int)$newData['typeid'] === 11100000 || (int)$newData['typeid'] === 133 || (int)$newData['typeid'] === 132 || (int)$newData['typeid'] === 131 || (int)$newData['typeid'] === 306){
  398. //案例 申报 职称相关问题 常见问题汇总 历年真题题库 答辩问题汇总 防骗指南 职称补贴
  399. $last = Db::name('seo_number')->where([
  400. "type" => 2,
  401. "tid" => (int)$post['typeid'],
  402. 'topid' => 0,
  403. 'parentid' => 0,
  404. 'area_id' => 0,
  405. ])->order('number desc')->find();
  406. if(empty($last['number'])){
  407. $num = 1;
  408. }else{
  409. $num = (int)$last['number'] + 1;
  410. }
  411. $in_data = [
  412. "type" => 2, //文章类型
  413. "aid" => $aid, //实际的ID
  414. "tid" => (int)$post['typeid'], //属于哪个栏目的
  415. 'is_del' => 0,
  416. 'is_kan' => 0, // 0正常 1审核
  417. 'status' => 1,
  418. 'area_id' => 0,
  419. 'topid' => 0,
  420. 'parentid' => 0,
  421. 'number' => $num
  422. ];
  423. Db::name('seo_number')->insert($in_data);
  424. }else if((int)$newData['typeid'] === 115 || (int)$newData['typeid'] === 117 || (int)$newData['typeid'] === 111){
  425. $where6 = [
  426. "type" => 2,
  427. "tid" => (int)$post['typeid'],
  428. 'topid' => 0,
  429. 'parentid' => 0,
  430. 'area_id' => (int)$post['province_id'], //如果是0的话 后续也不能改
  431. 'city_id' => (int)$post['city_id'], //如果是0的话 后续也不能改
  432. ];
  433. /*if((int)$post['city_id'] > 0){
  434. $where6['city_id'] = (int)$post['city_id'];
  435. }*/
  436. //攻略和政策资讯
  437. $last = Db::name('seo_number')->where($where6)->order('number desc')->find();
  438. if(empty($last['number'])){
  439. $num = 1;
  440. }else{
  441. $num = (int)$last['number'] + 1;
  442. }
  443. $in_data = [
  444. "type" => 2, //产品类型
  445. "aid" => $aid, //实际的ID
  446. "tid" => (int)$post['typeid'], //属于哪个栏目的
  447. 'is_del' => 0,
  448. 'is_kan' => 0, // 0正常 1审核
  449. 'status' => 1,
  450. 'area_id' => (int)$post['province_id'],
  451. 'city_id' => (int)$post['city_id'],
  452. 'topid' => 0,
  453. 'parentid' => 0,
  454. 'number' => $num
  455. ];
  456. Db::name('seo_number')->insert($in_data);
  457. }else{
  458. //其他
  459. }
  460. // 生成静态页面代码
  461. $successData = [
  462. 'aid' => $aid,
  463. 'tid' => $post['typeid'],
  464. ];
  465. $this->success("操作成功!", null, $successData);
  466. }
  467. $this->error("操作失败!");
  468. }
  469. $typeid = input('param.typeid/d', 0);
  470. $assign_data['typeid'] = $typeid; // 栏目ID
  471. //列出产品
  472. $list = Db::name('arctype_cat')
  473. ->where('parent_id','=',$typeid)
  474. ->where('type','=','产品')
  475. ->where('is_del','=',0)
  476. ->order('id asc')
  477. ->select();
  478. //var_dump($list);
  479. $this->assign('pro_list',$list);
  480. //列出职称级别
  481. $level_group_list = Db::name('arctype')
  482. ->field('id,parent_id,typename')
  483. ->where('parent_id','=',53)
  484. ->where('is_del','=',0)
  485. ->order('id asc')
  486. ->select();
  487. //var_dump($list);
  488. $this->assign('level_group_list',$level_group_list);
  489. //列出
  490. $level_group_name = Db::name('archives')
  491. ->field('aid,typeid,title')
  492. ->where('typeid','=',$level_group_list[0]['id'])
  493. ->where('is_del','=',0)
  494. ->order('sort_order asc,aid asc')
  495. ->select();
  496. $this->assign('level_group_name',$level_group_name);
  497. $product_id = input('param.product_id/d', 0);
  498. //var_dump($product_id);
  499. $assign_data['product_id'] = $product_id; //关联产品ID 默认都是0
  500. //var_dump($typeid);
  501. if((int)$typeid === 126 || (int)$typeid === 825 || (int)$typeid === 826){
  502. //列出职称标签
  503. $product_tag = Db::name('archives')
  504. ->field('aid,typeid,title')
  505. ->where('typeid','=',58)
  506. ->where('is_del','=',0)
  507. ->order('sort_order asc,aid asc')
  508. ->select();
  509. }else{
  510. //列出职称标签
  511. $cat = Db::name('arctype')->where(['parent_id'=>369,'article_id'=>$typeid])->find();
  512. if(empty($cat)){
  513. $cat_id = 371;
  514. }else{
  515. $cat_id = $cat['id'];
  516. }
  517. $product_tag = Db::name('archives')
  518. ->field('aid,typeid,title')
  519. ->where('typeid','=',$cat_id)
  520. ->where('is_del','=',0)
  521. ->order('sort_order asc,aid asc')
  522. ->select();
  523. }
  524. $this->assign('product_tag',$product_tag);
  525. // 栏目信息
  526. $arctypeInfo = Db::name('arctype')->find($typeid);
  527. $topid = $arctypeInfo['topid'];
  528. $assign_data['topid'] = $topid;
  529. //查询区域id
  530. $catid = $arctypeInfo['area_id'];
  531. if((int)$catid === 0){
  532. $catid = input('param.catid/d', 0);
  533. }
  534. $assign_data['catid'] = $catid;
  535. //var_dump($catid);
  536. /*允许发布文档列表的栏目*/ //加入区域
  537. $arctype_html = allow_release_arctype($typeid, array($this->channeltype),true,[],false,$catid);
  538. $assign_data['arctype_html'] = $arctype_html;
  539. /*--end*/
  540. // 阅读权限
  541. $arcrank_list = get_arcrank_list();
  542. $assign_data['arcrank_list'] = $arcrank_list;
  543. /*获取可显示的系统字段*/
  544. $condition['ifcontrol'] = 0;
  545. $condition['channel_id'] = $this->channeltype;
  546. $channelfield_row = Db::name('channelfield')->where($condition)->field('name,ifeditable')->getAllWithIndex('name');
  547. $assign_data['channelfield_row'] = $channelfield_row;
  548. /*--end*/
  549. /*模板列表*/
  550. $archivesLogic = new \app\admin\logic\ArchivesLogic;
  551. $templateList = $archivesLogic->getTemplateList($this->nid);
  552. $this->assign('templateList', $templateList);
  553. /*--end*/
  554. /*默认模板文件*/
  555. $tempview = 'view_'.$this->nid.'.'.config('template.view_suffix');
  556. !empty($arctypeInfo['tempview']) && $tempview = $arctypeInfo['tempview'];
  557. $this->assign('tempview', $tempview);
  558. /*--end*/
  559. // 文档默认浏览量
  560. $globalConfig = tpCache('global');
  561. if (isset($globalConfig['other_arcclick']) && 0 <= $globalConfig['other_arcclick']) {
  562. $arcclick_arr = explode("|", $globalConfig['other_arcclick']);
  563. if (count($arcclick_arr) > 1) {
  564. $assign_data['rand_arcclick'] = mt_rand($arcclick_arr[0], $arcclick_arr[1]);
  565. } else {
  566. $assign_data['rand_arcclick'] = intval($arcclick_arr[0]);
  567. }
  568. }else{
  569. $arcclick_config['other_arcclick'] = '500|1000';
  570. tpCache('other', $arcclick_config);
  571. $assign_data['rand_arcclick'] = mt_rand(500, 1000);
  572. }
  573. // URL模式
  574. $tpcache = config('tpcache');
  575. $assign_data['seo_pseudo'] = !empty($tpcache['seo_pseudo']) ? $tpcache['seo_pseudo'] : 1;
  576. /*文档属性*/
  577. $assign_data['archives_flags'] = model('ArchivesFlag')->getList();
  578. $channelRow = Db::name('channeltype')->where('id', $this->channeltype)->find();
  579. $assign_data['channelRow'] = $channelRow;
  580. // 来源列表
  581. $system_originlist = tpSetting('system.system_originlist');
  582. $system_originlist = json_decode($system_originlist, true);
  583. $system_originlist = !empty($system_originlist) ? $system_originlist : [];
  584. $assign_data['system_originlist_0'] = !empty($system_originlist) ? $system_originlist[0] : "";
  585. $assign_data['system_originlist_str'] = implode(PHP_EOL, $system_originlist);
  586. // 多站点,当用站点域名访问后台,发布文档自动选择当前所属区域
  587. model('Citysite')->auto_location_select($assign_data);
  588. $this->assign($assign_data);
  589. return $this->fetch();
  590. }
  591. /**
  592. * 编辑
  593. */
  594. public function edit()
  595. {
  596. $admin_info = session('admin_info');
  597. $auth_role_info = $admin_info['auth_role_info'];
  598. $this->assign('auth_role_info', $auth_role_info);
  599. $this->assign('admin_info', $admin_info);
  600. if (IS_POST) {
  601. $post = input('post.');
  602. model('Archives')->editor_auto_210607($post);
  603. $post['aid'] = intval($post['aid']);
  604. $typeid = input('post.typeid/d', 0);
  605. /* 处理TAG标签 */
  606. if (!empty($post['tags_new'])) {
  607. $post['tags'] = !empty($post['tags']) ? $post['tags'] . ',' . $post['tags_new'] : $post['tags_new'];
  608. unset($post['tags_new']);
  609. }
  610. $post['tags'] = explode(',', $post['tags']);
  611. $post['tags'] = array_unique($post['tags']);
  612. $post['tags'] = implode(',', $post['tags']);
  613. /* END */
  614. /*获取第一个html类型的内容,作为文档的内容来截取SEO描述*/
  615. $contentField = Db::name('channelfield')->where([
  616. 'channel_id' => $this->channeltype,
  617. 'dtype' => 'htmltext',
  618. ])->getField('name');
  619. $content = empty($post['addonFieldExt'][$contentField]) ? '' : htmlspecialchars_decode($post['addonFieldExt'][$contentField]);
  620. /*--end*/
  621. // 根据标题自动提取相关的关键字
  622. $seo_keywords = $post['seo_keywords'];
  623. if (!empty($seo_keywords)) {
  624. $seo_keywords = str_replace(',', ',', $seo_keywords);
  625. } else {
  626. // $seo_keywords = get_split_word($post['title'], $content);
  627. }
  628. // 自动获取内容第一张图片作为封面图
  629. $is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
  630. $litpic = '';
  631. if ($is_remote == 1) {
  632. $litpic = $post['litpic_remote'];
  633. } else {
  634. $litpic = $post['litpic_local'];
  635. }
  636. if (empty($litpic)) {
  637. $litpic = get_html_first_imgurl($content);
  638. }
  639. $post['litpic'] = $litpic;
  640. /*是否有封面图*/
  641. if (empty($post['litpic'])) {
  642. $is_litpic = 0; // 无封面图
  643. } else {
  644. $is_litpic = !empty($post['is_litpic']) ? $post['is_litpic'] : 0; // 有封面图
  645. }
  646. // 勾选后SEO描述将随正文内容更新
  647. $basic_update_seo_description = empty($post['basic_update_seo_description']) ? 0 : 1;
  648. if (is_language()) {
  649. $langRow = \think\Db::name('language')->order('id asc')
  650. ->cache(true, EYOUCMS_CACHE_TIME, 'language')
  651. ->select();
  652. foreach ($langRow as $key => $val) {
  653. tpCache('basic', ['basic_update_seo_description'=>$basic_update_seo_description], $val['mark']);
  654. }
  655. } else {
  656. tpCache('basic', ['basic_update_seo_description'=>$basic_update_seo_description]);
  657. }
  658. /*--end*/
  659. // SEO描述
  660. $seo_description = '';
  661. if (!empty($basic_update_seo_description) || empty($post['seo_description'])) {
  662. $seo_description = @msubstr(checkStrHtml($content), 0, config('global.arc_seo_description_length'), false);
  663. } else {
  664. $seo_description = $post['seo_description'];
  665. }
  666. // --外部链接
  667. $jumplinks = '';
  668. $is_jump = isset($post['is_jump']) ? $post['is_jump'] : 0;
  669. if (intval($is_jump) > 0) {
  670. $jumplinks = $post['jumplinks'];
  671. }
  672. // 模板文件,如果文档模板名与栏目指定的一致,默认就为空。让它跟随栏目的指定而变
  673. if ($post['type_tempview'] == $post['tempview']) {
  674. unset($post['type_tempview']);
  675. unset($post['tempview']);
  676. }
  677. // 同步栏目切换模型之后的文档模型
  678. $channel = Db::name('arctype')->where(['id'=>$typeid])->getField('current_channel');
  679. //处理自定义文件名,仅由字母数字下划线和短横杆组成,大写强制转换为小写
  680. $htmlfilename = trim($post['htmlfilename']);
  681. if (!empty($htmlfilename)) {
  682. $htmlfilename = preg_replace("/[^\x{4e00}-\x{9fa5}\w\-]+/u", "-", $htmlfilename);
  683. // $htmlfilename = strtolower($htmlfilename);
  684. //判断是否存在相同的自定义文件名
  685. $map = [
  686. 'aid' => ['NEQ', $post['aid']],
  687. 'htmlfilename' => $htmlfilename,
  688. 'lang' => $this->admin_lang,
  689. ];
  690. if (!empty($post['typeid'])) {
  691. $map['typeid'] = array('eq', $post['typeid']);
  692. }
  693. $filenameCount = Db::name('archives')->where($map)->count();
  694. if (!empty($filenameCount)) {
  695. $this->error("同栏目下,自定义文件名已存在!");
  696. } else if (preg_match('/^(\d+)$/i', $htmlfilename)) {
  697. $this->error("自定义文件名不能纯数字,会与文档ID冲突!");
  698. }
  699. } else {
  700. // 处理外贸链接
  701. if (is_dir('./weapp/Waimao/')) {
  702. $waimaoLogic = new \weapp\Waimao\logic\WaimaoLogic;
  703. $waimaoLogic->get_new_htmlfilename($htmlfilename, $post, 'edit', $this->globalConfig);
  704. }
  705. }
  706. $post['htmlfilename'] = $htmlfilename;
  707. //做未通过审核文档不允许修改文档状态操作
  708. if ($admin_info['role_id'] > 0 && $auth_role_info['check_oneself'] < 1) {
  709. $old_archives_arcrank = Db::name('archives')->where(['aid' => $post['aid']])->getField("arcrank");
  710. if ($old_archives_arcrank < 0) {
  711. unset($post['arcrank']);
  712. }
  713. }
  714. // 副栏目
  715. if (isset($post['stypeid'])) {
  716. $post['stypeid'] = preg_replace('/([^\d\,\,]+)/i', ',', $post['stypeid']);
  717. $post['stypeid'] = str_replace(',', ',', $post['stypeid']);
  718. $post['stypeid'] = trim($post['stypeid'], ',');
  719. $post['stypeid'] = str_replace(",{$typeid},", ',', ",{$post['stypeid']},");
  720. $post['stypeid'] = trim($post['stypeid'], ',');
  721. }
  722. //查询排序 等级
  723. $sort_order = Db::name('archives')->where('aid','=',(int)$post['level_group_name'])->value('sort_order');
  724. // --存储数据
  725. $newData = array(
  726. 'typeid'=> $typeid,
  727. 'channel' => $channel,
  728. 'is_b' => empty($post['is_b']) ? 0 : $post['is_b'],
  729. 'is_head' => empty($post['is_head']) ? 0 : $post['is_head'],
  730. 'is_special' => empty($post['is_special']) ? 0 : $post['is_special'],
  731. 'is_recom' => empty($post['is_recom']) ? 0 : $post['is_recom'],
  732. 'is_roll' => empty($post['is_roll']) ? 0 : $post['is_roll'],
  733. 'is_slide' => empty($post['is_slide']) ? 0 : $post['is_slide'],
  734. 'is_diyattr' => empty($post['is_diyattr']) ? 0 : $post['is_diyattr'],
  735. 'editor_remote_img_local'=> empty($post['editor_remote_img_local']) ? 0 : $post['editor_remote_img_local'],
  736. 'editor_img_clear_link' => empty($post['editor_img_clear_link']) ? 0 : $post['editor_img_clear_link'],
  737. 'is_jump' => $is_jump,
  738. 'is_litpic' => $is_litpic,
  739. 'jumplinks' => $jumplinks,
  740. 'seo_keywords' => $seo_keywords,
  741. 'seo_description' => $seo_description,
  742. 'crossed_price' => empty($post['crossed_price']) ? 0 : floatval($post['crossed_price']),
  743. 'add_time' => strtotime($post['add_time']),
  744. 'update_time' => getTime(),
  745. 'product_id' => (int)$post['product_id'], //增加
  746. 'lunwen_id' => (int)$post['lunwen_id'], //增加
  747. 'level_group_id' => (int)$post['level_group_id'],
  748. 'level_id' => (int)$post['level_group_name'],
  749. 'level' => (int)$sort_order,
  750. 'product_tag_id' => (int)$post['product_tag_id'],
  751. 'area_tag_id' => (int)$post['area_tag_id'],
  752. );
  753. $data = array_merge($post, $newData);
  754. if((int)$typeid === 126 || (int)$typeid === 825 || (int)$typeid === 826){
  755. //资料文档的时候
  756. //不更新 区域信息
  757. unset($data['province_id']);
  758. unset($data['city_id']);
  759. unset($data['area_id']);
  760. }
  761. if((int)$typeid === 117 || (int)$typeid === 115 || (int)$typeid === 111){
  762. //评审攻略和政策资讯 增加常见问题
  763. //不更新 区域信息
  764. unset($data['province_id']);
  765. unset($data['city_id']);
  766. unset($data['area_id']);
  767. }
  768. $arctype_par = Db::name('arctype')->field('id,parent_id')->where('id','=',$typeid)->find();
  769. if((int)$arctype_par['parent_id'] === 369){
  770. //文章标签
  771. //不更新 区域信息
  772. unset($data['province_id']);
  773. unset($data['city_id']);
  774. unset($data['area_id']);
  775. }
  776. $r = Db::name('archives')->where([
  777. 'aid' => $data['aid'],
  778. 'lang' => $this->admin_lang,
  779. ])->update($data);
  780. if ($r) {
  781. // ---------后置操作
  782. model('Custom')->afterSave($data['aid'], $data, 'edit', $this->table);
  783. // ---------end
  784. adminLog('编辑文章:'.$data['title']);
  785. $numinfo = [
  786. 'is_del' => $data['is_del'],
  787. 'is_kan' => $data['arcrank'],
  788. 'status' => $data['status'],
  789. ];
  790. //文档aid 对应 序列号aid
  791. Db::name('seo_number')->where('aid','=',$data['aid'])->update($numinfo);
  792. // 生成静态页面代码
  793. $successData = [
  794. 'aid' => $data['aid'],
  795. 'tid' => $typeid,
  796. ];
  797. $this->success("操作成功!", null, $successData);
  798. }
  799. $this->error("操作失败!");
  800. }
  801. $assign_data = array();
  802. $id = input('id/d');
  803. $info = model('Custom')->getInfo($id, null, false);
  804. if (empty($info)) {
  805. $this->error('数据不存在,请联系管理员!');
  806. exit;
  807. }
  808. /*兼容采集没有归属栏目的文档*/
  809. if (empty($info['channel'])) {
  810. $channelRow = Db::name('channeltype')->field('id as channel')
  811. ->where('id',$this->channeltype)
  812. ->find();
  813. $info = array_merge($info, $channelRow);
  814. }
  815. /*--end*/
  816. $typeid = $info['typeid'];
  817. $assign_data['typeid'] = $typeid;
  818. //查找产品
  819. $list = Db::name('arctype_cat')
  820. ->where('parent_id','=',$typeid)
  821. ->where('type','=','产品')
  822. ->where('is_del','=',0)
  823. ->order('id asc')
  824. ->select();
  825. //var_dump($list);
  826. $this->assign('pro_list',$list);
  827. //列出职称级别
  828. $level_group_list = Db::name('arctype')
  829. ->field('id,parent_id,typename')
  830. ->where('parent_id','=',53)
  831. ->where('is_del','=',0)
  832. ->order('id asc')
  833. ->select();
  834. //var_dump($list);
  835. $this->assign('level_group_list',$level_group_list);
  836. //列出
  837. if((int)$info['level_group_id'] === 0){
  838. $level_group_id = $level_group_list[0]['id'];
  839. }else{
  840. $level_group_id = (int)$info['level_group_id'];
  841. }
  842. $level_group_name = Db::name('archives')
  843. ->field('aid,typeid,title')
  844. ->where('typeid','=',$level_group_id)
  845. ->where('is_del','=',0)
  846. ->order('sort_order asc,aid asc')
  847. ->select();
  848. $this->assign('level_group_name',$level_group_name);
  849. if((int)$typeid === 126 || (int)$typeid === 825 || (int)$typeid === 826){
  850. //列出职称标签
  851. $product_tag = Db::name('archives')
  852. ->field('aid,typeid,title')
  853. ->where('typeid','=',58)
  854. ->where('is_del','=',0)
  855. ->order('sort_order asc,aid asc')
  856. ->select();
  857. }else{
  858. //列出职称标签
  859. $cat = Db::name('arctype')->where(['parent_id'=>369,'article_id'=>$typeid])->find();
  860. if(empty($cat)){
  861. $cat_id = 371;
  862. }else{
  863. $cat_id = $cat['id'];
  864. }
  865. $product_tag = Db::name('archives')
  866. ->field('aid,typeid,title')
  867. ->where('typeid','=',$cat_id)
  868. ->where('is_del','=',0)
  869. ->order('sort_order asc,aid asc')
  870. ->select();
  871. }
  872. $this->assign('product_tag',$product_tag);
  873. // 副栏目
  874. $stypeid_arr = [];
  875. if (!empty($info['stypeid'])) {
  876. $info['stypeid'] = trim($info['stypeid'], ',');
  877. $stypeid_arr = Db::name('arctype')->field('id,typename')->where(['id'=>['IN', $info['stypeid']],'is_del'=>0])->select();
  878. }
  879. $assign_data['stypeid_arr'] = $stypeid_arr;
  880. // 栏目信息
  881. $arctypeInfo = Db::name('arctype')->find($typeid);
  882. $topid = $arctypeInfo['topid'];
  883. $assign_data['topid'] = $topid;
  884. $info['channel'] = $arctypeInfo['current_channel'];
  885. if (is_http_url($info['litpic'])) {
  886. $info['is_remote'] = 1;
  887. $info['litpic_remote'] = handle_subdir_pic($info['litpic']);
  888. } else {
  889. $info['is_remote'] = 0;
  890. $info['litpic_local'] = handle_subdir_pic($info['litpic']);
  891. }
  892. // SEO描述
  893. // if (!empty($info['seo_description'])) {
  894. // $info['seo_description'] = @msubstr(checkStrHtml($info['seo_description']), 0, config('global.arc_seo_description_length'), false);
  895. // }
  896. $assign_data['field'] = $info;
  897. /*允许发布文档列表的栏目,文档所在模型以栏目所在模型为主,兼容切换模型之后的数据编辑*/
  898. $arctype_html = allow_release_arctype($typeid, array($info['channel']));
  899. $assign_data['arctype_html'] = $arctype_html;
  900. /*--end*/
  901. /*获取可显示的系统字段*/
  902. $condition['ifcontrol'] = 0;
  903. $condition['channel_id'] = $this->channeltype;
  904. $channelfield_row = Db::name('channelfield')->where($condition)->field('name,ifeditable')->getAllWithIndex('name');
  905. $assign_data['channelfield_row'] = $channelfield_row;
  906. /*--end*/
  907. // 阅读权限
  908. $arcrank_list = get_arcrank_list();
  909. $assign_data['arcrank_list'] = $arcrank_list;
  910. /*模板列表*/
  911. $archivesLogic = new \app\admin\logic\ArchivesLogic;
  912. $templateList = $archivesLogic->getTemplateList($this->nid);
  913. $this->assign('templateList', $templateList);
  914. /*--end*/
  915. /*默认模板文件*/
  916. $tempview = $info['tempview'];
  917. empty($tempview) && $tempview = $arctypeInfo['tempview'];
  918. $this->assign('tempview', $tempview);
  919. /*--end*/
  920. // URL模式
  921. $tpcache = config('tpcache');
  922. $assign_data['seo_pseudo'] = !empty($tpcache['seo_pseudo']) ? $tpcache['seo_pseudo'] : 1;
  923. /*文档属性*/
  924. $assign_data['archives_flags'] = model('ArchivesFlag')->getList();
  925. $channelRow = Db::name('channeltype')->where('id', $this->channeltype)->find();
  926. $assign_data['channelRow'] = $channelRow;
  927. // 来源列表
  928. $system_originlist = tpSetting('system.system_originlist');
  929. $system_originlist = json_decode($system_originlist, true);
  930. $system_originlist = !empty($system_originlist) ? $system_originlist : [];
  931. $assign_data['system_originlist_str'] = implode(PHP_EOL, $system_originlist);
  932. $this->assign($assign_data);
  933. return $this->fetch();
  934. }
  935. /**
  936. * 删除
  937. */
  938. public function del()
  939. {
  940. $archivesLogic = new \app\admin\logic\ArchivesLogic;
  941. $archivesLogic->del([], 0, 'custom');
  942. }
  943. //帮助
  944. public function help()
  945. {
  946. $system_originlist = tpSetting('system.system_originlist');
  947. $system_originlist = json_decode($system_originlist, true);
  948. $system_originlist = !empty($system_originlist) ? $system_originlist : [];
  949. $assign_data['system_originlist_str'] = implode(PHP_EOL, $system_originlist);
  950. $this->channeltype = input('param.channel/d', 0);
  951. $assign_data['channel'] = $this->channeltype ;
  952. $this->assign($assign_data);
  953. return $this->fetch();
  954. }
  955. }