123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908 |
- <?php
- /**
- * 易优CMS
- * ============================================================================
- * 版权所有 2016-2028 海口快推科技有限公司,并保留所有权利。
- * 网站地址: http://www.eyoucms.com
- * ----------------------------------------------------------------------------
- * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
- * ============================================================================
- * Author: 小虎哥 <1105415366@qq.com>
- * Date: 2018-4-3
- */
-
- namespace app\admin\controller;
-
- use think\Db;
- use think\Page;
- use app\common\logic\ArctypeLogic;
-
- class Archives extends Base
- {
- // 允许发布文档的模型ID
- public $allowReleaseChannel = array();
-
- public function _initialize() {
- parent::_initialize();
- $this->allowReleaseChannel = config('global.allow_release_channel');
- // 商城中心开关
- $shopOpen = isset($this->usersConfig['shop_open']) ? intval($this->usersConfig['shop_open']) : 0;
- $this->assign('shopOpen', $shopOpen);
- // 产品模型的所有栏目字段
- $goodsTypeIds = Db::name('arctype')->where(['current_channel' => 2, 'lang' => $this->admin_lang])->column('id');
- $goodsTypeIds = !empty($goodsTypeIds) ? implode(',', $goodsTypeIds) : '';
- $this->assign('goodsTypeIds', $goodsTypeIds);
- // 返回页面
- $paramTypeid = input('param.typeid/d', 0);
- $this->callback_url = url('Archives/index_archives', ['lang' => $this->admin_lang, 'typeid' => $paramTypeid]);
- $this->assign('callback_url', $this->callback_url);
- }
-
- /**
- * 内容管理
- */
- public function index()
- {
- //加入栏目筛选条件
- $catid = $_GET['catid']?$_GET['catid']:1;
- $catid = (int)$catid;
- $this->assign('catid', $catid);
- //var_dump($catid);
- if($catid > 1){
- $where1 = [
- 'is_del' => 0,
- 'area_id' => $catid, //其他
- ];
- }else{
- $where1 = [
- 'is_del' => 0,
- 'area_id' => 1, //默认广东省
- ];
- }
-
- $arctype_list = array();
- // 目录列表
- $arctypeLogic = new ArctypeLogic();
- $where['is_del'] = '0'; // 回收站功能
- $where['current_channel'] = ['neq',51]; // 问答模型
- $where['weapp_code'] = '';
-
- //之前已加入筛选功能
- $arctype_list = $arctypeLogic->arctype_list(0, 0, false, 0, $where, false,'',$catid);
-
- /*获取所有有子栏目的栏目id*/
- $parent_ids = Db::name('arctype')->where([
- 'parent_id' => ['gt', 0],
- 'is_del' => 0,
- ])
- //加多条件 加错了
- /*->where('topid','<>',38)
- ->whereOr(function($query) use ($where1){
- $query->where($where1);
- })*/
- ->group('parent_id')
- ->cache(true, EYOUCMS_CACHE_TIME, 'arctype') //whereOr必须取消 cache
- ->column('parent_id');
- //var_dump($parent_ids);
-
- $cookied_treeclicked = json_decode(cookie('admin-arctreeClicked-Arr'));
- empty($cookied_treeclicked) && $cookied_treeclicked = [];
- $all_treeclicked = cookie('admin-arctreeClicked_All');
- empty($all_treeclicked) && $all_treeclicked = [];
- $last_id = [];
-
- foreach ($arctype_list as $k => $v){
- if (!in_array($v['id'],$cookied_treeclicked) && 0 < $v['has_children']){
- $last_id[] = $v['id'];
- continue;
- }elseif (0 == $v['parent_id'] ){
- continue;
- }
- if (in_array($v['parent_id'],$last_id) && in_array($v['id'],$cookied_treeclicked)){
- $key = array_search($v['id'],$cookied_treeclicked);
- array_splice($cookied_treeclicked,$key,1);
- }
- }
- $tree = [
- 'parent_ids'=>json_encode($parent_ids),
- 'all_treeclicked'=>$all_treeclicked,
- 'cookied_treeclicked'=>$cookied_treeclicked,
- 'cookied_treeclicked_arr'=>json_encode($cookied_treeclicked),
- ];
- $this->assign('tree', $tree);
- /* end */
-
- $zNodes = "[";
- foreach ($arctype_list as $key => $val) {
- if ($val['current_channel'] == 5 && 1.5 > $this->php_servicemeal) {
- continue;
- }
- $current_channel = $val['current_channel'];
- if (!empty($val['weapp_code'])) {
- // 插件栏目
- $typeurl = weapp_url($val['weapp_code'].'/'.$val['weapp_code'].'/index');
- } else {
- if (6 == $current_channel) {
- $gourl = url('Arctype/single_edit', array('typeid'=>$val['id']));
- $typeurl = url("Arctype/single_edit", array('typeid'=>$val['id'],'archives'=>1,'gourl'=>$gourl));
- } else if (8 == $current_channel) {
- $typeurl = url("Guestbook/index", array('typeid'=>$val['id'], 'archives'=>1));
- } else {
- $typeurl = url('Archives/index_archives', array('typeid'=>$val['id'],'catid'=>$catid));
- }
- }
- $typename = htmlspecialchars_decode(addslashes($val['typename']));
- $zNodes .= "{id:{$val['id']}, pId:{$val['parent_id']}, name:'{$typename}', url:'{$typeurl}',target:'content_body'";
- /*默认展开一级栏目*/
- // if (empty($val['parent_id'])) {
- // $zNodes .= ",open:true";
- // }
- /*--end*/
-
- if (!empty($tree['cookied_treeclicked'])) {
- if (in_array($val['id'], $tree['cookied_treeclicked'])) {
- $zNodes .= ",open:true";
- }
- }
-
- /*栏目有下级栏目时,显示图标*/
- if (1 == $val['has_children']) {
- $zNodes .= ",isParent:true";
- } else {
- $zNodes .= ",isParent:false";
- }
- /*--end*/
- $zNodes .= "},";
- }
- $zNodes .= "]";
- $this->assign('zNodes', $zNodes);
-
- // 中间那块内容栏目的展示/收缩记忆
- $treeClicked_1649642233 = cookie('admin-treeClicked-1649642233');
- $this->assign('treeClicked_1649642233', $treeClicked_1649642233);
-
- //调用区域
- /*
- * 调用省份数据
- */
- $pro_list = Db::table('ey_citysite')->where([
- "level" => 1,
- "parent_id" => 0,
- "topid" => 0,
- "status" => 1,
- ])->select();
- $this->assign('pro_list',$pro_list);
-
- return $this->fetch();
- }
-
- /**
- * 内容管理 - 所有文档列表风格(只针对ey_archives表,排除单页记录)
- */
- public function index_archives()
- {
- $assign_data = array();
- $condition = [];
- if (is_dir('./weapp/MultiMerchant/')) {
- $condition['a.merchant_id'] = 0;
- }
- // 获取到所有URL参数
- $param = input('param.');
- $flag = input('flag/s');
- $typeid = input('typeid/d', 0);
-
- $product_id = input('proid/d', 0);
- $catid = input('catid/d',1); //默认是1 广东省
-
- if((int)$product_id === 0){
- $product_id = input('product_id/d', 0);
- }
-
- //var_dump($typeid);
- //查询产品表 列出产品
- //点击产品 筛选出文档
- $list = Db::name('arctype_cat')
- ->where('parent_id','=',$typeid)
- ->where('type','=','产品')
- ->where('is_del','=',0)
- ->order('id asc')
- ->select();
-
- //var_dump($list);
- $this->assign('pro_list',$list);
-
- //当前产品id 默认显示就是0
- if($product_id === 0){
- //$product_id = $list[0]['id'];
- }
- $this->assign('product_id',$product_id);
- $this->assign('typeid',$typeid);
- $this->assign('catid',$catid);
- //查询topid
- $topid = Db::name('arctype')->where('id','=',$typeid)->value('topid');
- $this->assign('topid',$topid);
- //var_dump($topid);
-
- //跳转到指定栏目的文档列表
- if (0 < intval($typeid)) {
- $row = Db::name('arctype')
- ->alias('a')
- ->field('b.ctl_name,b.id')
- ->join('__CHANNELTYPE__ b', 'a.current_channel = b.id', 'LEFT')
- ->where('a.id', 'eq', $typeid)
- ->find();
- $ctl_name = $row['ctl_name'];
- $current_channel = $row['id'];
- if (6 == $current_channel) {
- $gourl = url('Arctype/single_edit', array('typeid'=>$typeid));
- $gourl = url("Arctype/single_edit", array('typeid'=>$typeid,'gourl'=>$gourl));
- $this->redirect($gourl);
- } else if (8 == $current_channel) {
- $gourl = url("Guestbook/index", array('typeid'=>$typeid));
- $this->redirect($gourl);
- }
- }
-
- foreach (['keywords','typeid','flag','is_release','province_id','city_id','area_id'] as $key) {
- $param[$key] = !empty($param[$key]) ? addslashes(trim($param[$key])):"";
- if (isset($param[$key]) && $param[$key] !== '') {
- if ($key == 'keywords') {
- $condition['a.title|a.aid'] = array('LIKE', "%{$param[$key]}%");
- } else if ($key == 'typeid') {
- $typeid = $param[$key];
- $hasRow = model('Arctype')->getHasChildren($typeid);
- $typeids = get_arr_column($hasRow, 'id');
- //权限控制 by 小虎哥
- $admin_info = session('admin_info');
- if (0 < intval($admin_info['role_id'])) {
- $auth_role_info = $admin_info['auth_role_info'];
- if(! empty($auth_role_info)){
- if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
- $condition['a.admin_id'] = $admin_info['admin_id'];
- }
- if(! empty($auth_role_info['permission']['arctype'])){
- if (!empty($typeid)) {
- $typeids = array_intersect($typeids, $auth_role_info['permission']['arctype']);
- }
- }
- }
- }
- $condition['a.typeid'] = array('IN', $typeids);
- } else if ($key == 'flag') {
- if ('is_release' == $param[$key]) {
- $condition['a.users_id'] = array('gt', 0);
- } else {
- $FlagNew = $param[$key];
- $condition['a.'.$param[$key]] = array('eq', 1);
- }
- // } else if ($key == 'is_release') {
- // if (0 < intval($param[$key])) {
- // $condition['a.users_id'] = array('gt', intval($param[$key]));
- // }
- } else if (in_array($key, ['province_id','city_id','area_id'])) {
- $citysiteNew = '';
- if (!empty($param['province_id'])) {
- $condition['a.province_id'] = $param['province_id'];
- $citysiteNew .= $param['province_id'];
- }
- if (!empty($param['city_id'])) {
- $condition['a.city_id'] = $param['city_id'];
- $citysiteNew .= !empty($citysiteNew) ? '_' . $param['city_id'] : $param['city_id'];
- }
- if (!empty($param['area_id'])) {
- $condition['a.area_id'] = $param['area_id'];
- $citysiteNew .= !empty($citysiteNew) ? '_' . $param['area_id'] : $param['area_id'];
- }
- } else {
- $condition['a.'.$key] = array('eq', $param[$key]);
- }
- }
- }
-
- //权限控制 by 小虎哥
- if (empty($typeid)) {
- $typeids = [];
- $admin_info = session('admin_info');
- if (0 < intval($admin_info['role_id'])) {
- $auth_role_info = $admin_info['auth_role_info'];
- if(! empty($auth_role_info)){
- if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
- $condition['a.admin_id'] = $admin_info['admin_id'];
- }
- if(! empty($auth_role_info['permission']['arctype'])){
- $typeids = $auth_role_info['permission']['arctype'];
- }
- }
- }
- if (!empty($typeids)) {
- $condition['a.typeid'] = array('IN', $typeids);
- }
- }
-
- $channelIds = [];
- if (empty($typeid)) {
- $id_tmp = [6,8];
- // 只显示允许发布文档的模型,且是开启状态
- $channelIds = Db::name('channeltype')->where('status',0)->whereOr('id','IN',$id_tmp)->column('id');
- $condition['a.channel'] = array('NOT IN', $channelIds);
- } else {
- // 只显示当前栏目对应模型下的文档
- $current_channel = Db::name('arctype')->where('id', $typeid)->getField('current_channel');
- $condition['a.channel'] = array('eq', $current_channel);
- }
-
- $condition['a.lang'] = array('eq', $this->admin_lang);
- $condition['a.is_del'] = array('eq', 0);
- $condition['a.arcrank'] = array('egt', -1);
-
- $continueNew = "(a.users_id = 0 OR (a.users_id > 0 AND a.arcrank >= 0))";
-
- $orderby = input('param.orderby/s');
- $orderway = input('param.orderway/s');
- if (!empty($orderby)) {
- $orderby = "a.{$orderby} {$orderway}, a.aid desc";
- } else {
- $orderby = "a.aid desc";
- }
-
- // 手机端后台管理插件特定使用参数
- $isMobile = input('param.isMobile/d', 0);
- if (!empty($isMobile)) $condition['a.channel'] = 1;
-
- // 数据查询,搜索出主键ID的值
- $SqlQuery = Db::name('archives')->alias('a')->where($condition)->where($continueNew)->fetchSql()->count('aid');
- $count = Db::name('sql_cache_table')->where(['sql_md5'=>md5($SqlQuery)])->getField('sql_result');
- if (!isset($count) && empty($count)) {
- $count = (intval($count) < 0) ? 0 : intval($count);
- $count = Db::name('archives')->alias('a')->where($condition)->where($continueNew)->count('aid');
- /*添加查询执行语句到mysql缓存表*/
- $SqlCacheTable = [
- 'sql_name' => '|archives|!=' . implode(',', $channelIds) . '|',
- 'sql_result' => $count,
- 'sql_md5' => md5($SqlQuery),
- 'sql_query' => $SqlQuery,
- 'add_time' => getTime(),
- 'update_time' => getTime(),
- ];
- if (!empty($FlagNew)) $SqlCacheTable['sql_name'] = $SqlCacheTable['sql_name'] . $FlagNew . '|';
- if (!empty($citysiteNew)) $SqlCacheTable['sql_name'] = $SqlCacheTable['sql_name'] . 'citysite_' . $citysiteNew . '|';
- if (!empty($typeid)) {
- $channeltype_list = config('global.channeltype_list');
- foreach ($channeltype_list as $key => $value) {
- if ($value == $current_channel) {
- $ModelMark = $key;
- break;
- }
- }
- $SqlCacheTable['sql_name'] = '|' . $ModelMark . '|' . $current_channel . '|' . $typeid . '|';
- }
- Db::name('sql_cache_table')->insertGetId($SqlCacheTable);
- /*END*/
- }
-
- $Page = new Page($count, config('paginate.list_rows'));
- $list = [];
- if (0 < $count) {
- $limit = $count > config('paginate.list_rows') ? $Page->firstRow.','.$Page->listRows : $count;
- if((int)$topid === 38){
- $list = Db::name('archives')
- ->field("a.aid, a.channel")
- ->alias('a')
- ->where($condition)
- ->where('a.product_id','=',$product_id) //筛选出文档 默认是0
- ->where($continueNew)
- ->order($orderby)
- ->limit($limit)
- ->getAllWithIndex('aid');
- }else{
- $list = Db::name('archives')
- ->field("a.aid, a.channel")
- ->alias('a')
- ->where($condition)
- ->where($continueNew)
- ->order($orderby)
- ->limit($limit)
- ->getAllWithIndex('aid');
- }
-
- // 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
- if ($list) {
- $aids = array_keys($list);
- $fields = "b.*, a.*, a.aid as aid";
-
- if((int)$topid === 38){
- //查询出文档
- $row = Db::name('archives')
- ->field($fields)
- ->alias('a')
- ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
- ->where('a.aid', 'in', $aids)
- ->where('a.product_id','=',$product_id) //筛选出文档 默认是0
- ->getAllWithIndex('aid');
- }else{
- //查询出文档
- $row = Db::name('archives')
- ->field($fields)
- ->alias('a')
- ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
- ->where('a.aid', 'in', $aids)
- ->getAllWithIndex('aid');
- }
-
- //var_dump(count($row));
-
- /*获取当页文档的所有模型*/
- $channelIds = get_arr_column($list, 'channel');
- $channelRow = Db::name('channeltype')->field('id, ctl_name, ifsystem')
- ->where('id','IN',$channelIds)
- ->getAllWithIndex('id');
- $assign_data['channelRow'] = $channelRow;
-
- foreach ($list as $key => $val) {
- $row[$val['aid']]['arcurl'] = get_arcurl($row[$val['aid']]);
- $row[$val['aid']]['litpic'] = handle_subdir_pic($row[$val['aid']]['litpic']); // 支持子目录
- $list[$key] = $row[$val['aid']];
- }
-
- //var_dump(count($list));
- }
- }
-
- $show = $Page->show();
- $assign_data['page'] = $show;
- $assign_data['list'] = $list;
- $assign_data['pager'] = $Page;
-
- $assign_data['typeid'] = $typeid; // 栏目ID
- //当前栏目信息
- $arctype_info = array();
- if ($typeid > 0) {
- $arctype_info = Db::name('arctype')->field('topid,typename,current_channel')->find($typeid);
- }
- $assign_data['arctype_info'] = $arctype_info;
-
- // $assign_data['arctype_html'] = allow_release_arctype($typeid, array());//允许发布文档列表的栏目,可以废弃
- $assign_data['seo_pseudo'] = tpCache('global.seo_pseudo');//前台URL模式
- $assign_data['archives_flags'] = model('ArchivesFlag')->getList();//文档属性
- $assign_data['shop_open'] = getUsersConfigData('shop.shop_open');//商城开关
- //是否存在栏目
- $assign_data['is_arctype'] = Db::name('arctype')->where([
- 'is_del' => 0,
- 'lang' => get_current_lang(),
- ])->count();
- $this->assign($assign_data);
-
- // 如果安装手机端后台管理插件并且在手机端访问时执行
- if (is_dir('./weapp/Mbackend/') && !empty($isMobile)) {
- $mbPage = input('param.p/d', 1);
- $nullShow = intval($pageObj->totalPages) === intval($mbPage) ? 1 : 0;
- $this->assign('nullShow', $nullShow);
- if ($mbPage >= 2) {
- return $this->display('archives/archives_list');
- } else {
- return $this->display('archives/index_archives');
- }
- } else {
- return $this->fetch('index_archives');
- }
- }
-
- /**
- * 内容管理 - 栏目展开风格
- */
- private function index_arctype() {
- $arctype_list = array();
- // 目录列表
- $arctypeLogic = new ArctypeLogic();
- $arctype_list = $arctypeLogic->arctype_list(0, 0, false, 0, array(), false);
- $this->assign('arctype_list', $arctype_list);
-
- // 模型列表
- $channeltype_list = getChanneltypeList();
- $this->assign('channeltype_list', $channeltype_list);
-
- // 栏目最多级别
- $arctype_max_level = intval(config('global.arctype_max_level'));
- $this->assign('arctype_max_level', $arctype_max_level);
-
- // 允许发布文档的模型
- $this->assign('allow_release_channel', $this->allowReleaseChannel);
-
- return $this->fetch('index_arctype');
- }
-
- /**
- * 发布文档
- */
- public function add()
- {
- $typeid = input('param.typeid/d', 0);
- $product_id = input('param.product_id/d', 0);
- $catid = input('param.catid/d', 0);
- $callback_url = $_GET['callback_url']?$_GET['callback_url']:'';
-
- //var_dump($_GET);return;
-
- if (!empty($typeid)) {
-
- $row = Db::name('arctype')
- ->alias('a')
- ->field('b.ctl_name,b.id,b.ifsystem')
- ->join('__CHANNELTYPE__ b', 'a.current_channel = b.id', 'LEFT')
- ->where('a.id', 'eq', $typeid)
- ->find();
-
- $data = [
- 'typeid' => $typeid,
- ];
- if (empty($row['ifsystem'])) {
- $ctl_name = 'Custom';
- $data['channel'] = $row['id'];
- } else {
- $ctl_name = $row['ctl_name'];
- }
-
- $gourl = url('Archives/index_archives', array('typeid'=>$typeid,'product_id'=>$product_id,'catid' => $catid), true, true);
-
- $data['gourl'] = $gourl;
- $data['product_id'] = $product_id;
- $data['catid'] = $catid;
-
- $jumpUrl = url("{$ctl_name}/add", $data, true, true);
- } else {
- $jumpUrl = url("Archives/release", [], true, true);
- }
- $this->redirect($jumpUrl);
- }
-
- /**
- * 编辑文档
- */
- public function edit()
- {
- $id = input('param.id/d', 0);
- $typeid = input('param.typeid/d', 0);
- $row = Db::name('archives')
- ->alias('a')
- ->field('a.channel,b.ctl_name,b.id,b.ifsystem')
- ->join('__CHANNELTYPE__ b', 'a.channel = b.id', 'LEFT')
- ->where('a.aid', 'eq', $id)
- ->find();
- if (empty($row['channel'])) {
- $channelRow = Db::name('channeltype')->field('id as channel, ctl_name')
- ->where('nid','article')
- ->find();
- $row = array_merge($row, $channelRow);
- }
- $data = [
- 'id' => $id,
- ];
- if (empty($row['ifsystem'])) {
- $ctl_name = 'Custom';
- $data['channel'] = $row['id'];
- } else {
- $ctl_name = $row['ctl_name'];
- }
- $arcurl = input('param.arcurl/s');
- $data['arcurl'] = $arcurl;
- $jumpUrl = url("{$ctl_name}/edit", $data, true, true);
- $this->redirect($jumpUrl);
- }
-
- /*
- * 增加小类
- */
- public function add_pro(){
- //proid
- //typeid
- $input = request()->get();
- $this->assign('typeid',$input['typeid']);
- $this->assign('proid',$input['proid']);
- return $this->fetch();
- }
-
- public function add_pro_post(){
- $post = request()->post();
- //var_dump($post);
- $data = [
- 'parent_id' => (int)$post['typeid'],
- 'topid' => 38,
- 'typename' => $post['name'],
- 'is_hot' => $post['is_hot'],
- 'type' => '产品',
- 'add_time' => time()
- ];
- $res = Db::name('arctype_cat')->insertGetId($data);
-
- //新增序列号 (三级大类)
- //获取num 不排除已删除
- $last = Db::name('seo_number')->where([
- "type" => 1,
- "tid" => (int)$post['typeid'],
- 'topid' => 38,
- 'parentid' => (int)$post['typeid'],
- 'area_id' => 0,
- ])->order('number desc')->find();
- if(empty($last['number'])){
- $num = 1;
- }else{
- $num = (int)$last['number'] + 1;
- }
- $in_data = [
- "type" => 1, //产品类型
- "aid" => $res, //实际的ID
- "tid" => (int)$post['typeid'], //属于哪个栏目的
- 'is_del' => 0,
- 'is_kan' => 0, // 0正常 1审核
- 'status' => 1,
- 'area_id' => 0,
- 'topid' => 38,
- 'parentid' => (int)$post['typeid'],
- 'number' => $num
- ];
- Db::name('seo_number')->insert($in_data);
-
-
- if($res > 0){
- return ['code'=>0,msg=>'succerss',data=>[]];
- }else{
- return ['code'=>1,msg=>'fail',data=>[]];
- }
- }
-
- public function getTag(){
-
- $pid = request()->post('pid');
- $catid = request()->post('catid');
- $aid = request()->post('aid');
- //var_dump($pid);
-
- if((int)$catid === 825 || (int)$catid === 126 || (int)$catid === 125){
- return json([
- 'code' => 1,
- 'data' => ''
- ]);
- }else{
- $product_tag_id = Db::name('archives')->where(['aid'=>$aid])->value('product_tag_id');
- $cat = Db::name('arctype')->where(['parent_id'=>369,'article_id'=>$catid])->find();
- if(empty($cat)){
- $cat_id = 371;
- }else{
- $cat_id = $cat['id'];
- }
-
- $product_tag = Db::name('archives')
- ->field('aid,typeid,title')
- ->where('typeid','=',$cat_id)
- ->where('province_id','=',$pid)
- ->where('is_del','=',0)
- ->order('sort_order asc,aid asc')
- ->select();
-
- $html = '<option value="0">默认标签</option>';
- foreach ($product_tag as $index => $row){
- if((int)$product_tag_id === (int)$row['aid']){
- $html .= '<option value="'.$row['aid'].'" selected>'.$row['title'].'</option>';
- }else{
- $html .= '<option value="'.$row['aid'].'">'.$row['title'].'</option>';
- }
-
- }
-
- return json([
- 'code' => 0,
- 'data' => $html
- ]);
- }
-
-
- }
- public function edit_pro(){
- //proid
- //typeid
- $input = request()->get();
- $this->assign('typeid',$input['typeid']);
- $this->assign('proid',$input['proid']);
- $detail = Db::name('arctype_cat')->find((int)$input['proid']);
- $this->assign('detail',$detail);
- return $this->fetch();
- }
- public function edit_pro_post(){
- $post = request()->post();
- //var_dump($post);
- $data = [
- 'parent_id' => (int)$post['typeid'],
- 'topid' => 38,
- 'typename' => $post['name'],
- 'is_hot' => $post['is_hot'],
- 'type' => '产品',
- 'update_time' => time()
- ];
- $res = Db::name('arctype_cat')->where('id','=',(int)$post['id'])->update($data);
- if($res > 0){
- return ['code'=>0,msg=>'succerss',data=>[]];
- }else{
- return ['code'=>1,msg=>'fail',data=>[]];
- }
- }
- public function del_pro_post(){
- $post = request()->post();
- $data = [
- 'is_del' => 1,
- 'update_time' => time()
- ];
- $res = Db::name('arctype_cat')->where('id','=',(int)$post['id'])->update($data);
- if($res > 0){
-
-
- $numinfo = [
- 'is_del' => 1,
- ];
-
- //文档aid 对应 序列号aid
- Db::name('seo_number')->where('type','=',1)->where('tid','<>',38)->where('aid','=',(int)$post['id'])->update($numinfo);
-
-
- return ['code'=>0,msg=>'succerss',data=>[]];
- }else{
- return ['code'=>1,msg=>'fail',data=>[]];
- }
- }
-
- public function get_level_list()
- {
- $typeid = request()->post('typeid');
- //
- $level_group_name = Db::name('archives')
- ->field('aid,typeid,title')
- ->where('typeid','=',(int)$typeid)
- ->where('is_del','=',0)
- ->order('sort_order asc,aid asc')
- ->select();
- return ['code'=>0,msg=>'success',data=>$level_group_name];
- }
- /**
- * 删除文档
- */
- public function del()
- {
- if (IS_POST) {
- $del_id = input('del_id/a');
- $thorough = input('thorough/d', 0);
- $archivesLogic = new \app\admin\logic\ArchivesLogic;
- $archivesLogic->del($del_id, $thorough);
- }
- }
-
- /**
- * 审核文档
- */
- public function check()
- {
- if (IS_POST) {
- $aids = input('ids/a');
- $aids = !empty($aids) ? eyIntval($aids) : '';
- if (!empty($aids)){
- $info = [
- 'arcrank' => 0,
- 'update_time'=>getTime(),
- ];
- $r = Db::name('archives')->where('aid','IN',$aids)->cache(true,null,'archives')->save($info);
- if ($r !== false) {
- adminLog('审核文档-id:'.implode(',', $aids));
- /*清空sql_cache_table数据缓存表 并 添加查询执行语句到mysql缓存表*/
- Db::name('sql_cache_table')->execute('TRUNCATE TABLE '.config('database.prefix').'sql_cache_table');
- model('SqlCacheTable')->InsertSqlCacheTable(true);
- /* END */
- $this->success('操作成功!');
- } else {
- $this->error('操作失败!');
- }
- }
- }
- }
-
- /**
- * 取消审核文档
- */
- public function uncheck()
- {
- if (IS_POST) {
- $aids = input('ids/a');
- $aids = !empty($aids) ? eyIntval($aids) : '';
- if (!empty($aids)){
- $info = [
- 'arcrank' => -1,
- 'update_time'=>getTime(),
- ];
- $r = Db::name('archives')->where('aid','IN',$aids)->cache(true,null,'archives')->save($info);
- if ($r !== false) {
- adminLog('取消审核-id:'.implode(',', $aids));
- /*清空sql_cache_table数据缓存表 并 添加查询执行语句到mysql缓存表*/
- Db::name('sql_cache_table')->execute('TRUNCATE TABLE '.config('database.prefix').'sql_cache_table');
- model('SqlCacheTable')->InsertSqlCacheTable(true);
- /* END */
- $this->success('操作成功!');
- } else {
- $this->error('操作失败!');
- }
- }
- }
- }
-
- /**
- * 移动
- */
- public function move()
- {
- if (IS_POST) {
- $post = input('post.');
- $typeid = !empty($post['typeid']) ? eyIntval($post['typeid']) : '';
- $aids = !empty($post['aids']) ? eyIntval($post['aids']) : '';
- $all_move = !empty($post['all_move']) ? intval($post['all_move']) : 0;
-
- if (empty($typeid) || empty($aids)) {
- $this->error('参数有误');
- }
-
- $r = true;
- // 获取移动栏目的模型ID
- $current_channel = Db::name('arctype')->where([
- 'id' => $typeid,
- 'lang' => $this->admin_lang,
- ])->getField('current_channel');
- if (empty($all_move)) {
- // 抽取相符合模型ID的文档aid
- $aids = Db::name('archives')->where([
- 'aid' => ['IN', $aids],
- 'channel' => $current_channel,
- 'lang' => $this->admin_lang,
- ])->column('aid');
- // 移动文档处理
- if (!empty($aids)) {
- $r = Db::name('archives')->where([
- 'aid' => ['IN', $aids],
- ])->update([
- 'typeid' => $typeid,
- 'update_time' => getTime(),
- ]);
- }
- } else {
- // 抽取相符合模型ID的文档栏目
- $dest_typeids = Db::name('archives')->where([
- 'aid' => ['IN', $aids],
- 'channel' => $current_channel,
- 'lang' => $this->admin_lang,
- ])->column('typeid');
- // 移动栏目下的全部文档处理
- if (!empty($dest_typeids)) {
- $r = Db::name('archives')->where([
- 'typeid' => ['IN', $dest_typeids],
- ])->update([
- 'typeid' => $typeid,
- 'update_time' => getTime(),
- ]);
- }
- }
- if ($r !== false) {
- if (empty($all_move)) {
- // 移动tag标签
- Db::name('taglist')->where(['aid'=>['IN', $aids]])->update([
- 'typeid' => $typeid,
- 'update_time' => getTime(),
- ]);
- adminLog('移动文档-aid:'.$aids);
- } else {
- // 移动tag标签
- Db::name('taglist')->where(['typeid'=>['IN', $dest_typeids]])->update([
- 'typeid' => $typeid,
- 'update_time' => getTime(),
- ]);
- Db::name('tagindex')->where(['typeid'=>['IN', $dest_typeids]])->update([
- 'typeid' => $typeid,
- 'update_time' => getTime(),
- ]);
- $dest_typeid_str = implode(',', $dest_typeids);
- adminLog("移动栏目 {$dest_typeid_str} 全部文档");
- }
- \think\Cache::clear('taglist');
- \think\Cache::clear('archives');
- /*清空sql_cache_table数据缓存表 并 添加查询执行语句到mysql缓存表*/
- Db::name('sql_cache_table')->execute('TRUNCATE TABLE '.config('database.prefix').'sql_cache_table');
- model('SqlCacheTable')->InsertSqlCacheTable(true);
- /* END */
- $this->success('操作成功');
- }
- $this->error('操作失败');
- }
-
- $typeid = input('param.typeid/d', 0);
-
- /*允许发布文档列表的栏目*/
- $allowReleaseChannel = [];
- if (!empty($typeid)) {
- $channelId = Db::name('arctype')->where('id',$typeid)->getField('current_channel');
- $allowReleaseChannel[] = $channelId;
- }
- $arctype_html = allow_release_arctype($typeid, $allowReleaseChannel);
- $this->assign('arctype_html', $arctype_html);
- /*--end*/
-
- /*不允许发布文档的模型ID,用于JS判断*/
- // $js_allow_channel_arr = '[]';
- // if (!empty($allowReleaseChannel)) {
- // $js_allow_channel_arr = '[';
- // foreach ($allowReleaseChannel as $key => $val) {
- // if ($key > 0) {
- // $js_allow_channel_arr .= ',';
- // }
- // $js_allow_channel_arr .= $val;
- // }
- // $js_allow_channel_arr = $js_allow_channel_arr.']';
- // }
- // $this->assign('js_allow_channel_arr', $js_allow_channel_arr);
- /*--end*/
-
- /*表单提交URL*/
- $form_action = url('Archives/move');
- $this->assign('form_action', $form_action);
- /*--end*/
-
- return $this->fetch();
- }
-
- /**
- * 发布内容
- */
- public function release()
- {
- $typeid = input('param.typeid/d', 0);
- if (0 < $typeid) {
- $param = input('param.');
- $row = Db::name('arctype')
- ->field('b.ctl_name,b.id,b.ifsystem')
- ->alias('a')
- ->join('__CHANNELTYPE__ b', 'a.current_channel = b.id', 'LEFT')
- ->where('a.id', 'eq', $typeid)
- ->find();
- /*针对不支持发布文档的模型*/
- if (!in_array($row['id'], $this->allowReleaseChannel)) {
- $this->error('该栏目不支持发布文档!', url('Archives/release'));
- exit;
- }
- /*-----end*/
-
- $data = [
- 'typeid' => $typeid,
- ];
- if (empty($row['ifsystem'])) {
- $ctl_name = 'Custom';
- $data['channel'] = $row['id'];
- } else {
- $ctl_name = $row['ctl_name'];
- }
- $gourl = url('Archives/index_archives', array('typeid'=>$typeid), true, true);
- $data['gourl'] = $gourl;
- $jumpUrl = url("{$ctl_name}/add", $data, true, true);
- header('Location: '.$jumpUrl);
- exit;
- }
-
- $iframe = input('param.iframe/d',0);
-
- /*允许发布文档列表的栏目*/
- $select_html = allow_release_arctype();
- $this->assign('select_html',$select_html);
- /*--end*/
-
- /*不允许发布文档的模型ID,用于JS判断*/
- $js_allow_channel_arr = '[';
- foreach ($this->allowReleaseChannel as $key => $val) {
- if ($key > 0) {
- $js_allow_channel_arr .= ',';
- }
- $js_allow_channel_arr .= $val;
- }
- $js_allow_channel_arr = $js_allow_channel_arr.']';
- $this->assign('js_allow_channel_arr', $js_allow_channel_arr);
- /*--end*/
-
- if (!empty($iframe)) {
- $template = 'release_iframe';
- $attribute_row = Db::name('product_attribute')->field('typeid, count(attr_id) as num')
- ->where([
- 'is_del' => 0,
- 'lang' => $this->admin_lang,
- ])
- ->group('typeid')
- ->getAllWithIndex('typeid');
- $this->assign('attribute_row', $attribute_row);
- } else {
- $template = 'release';
- }
- $this->assign('iframe', $iframe);
-
- return $this->fetch($template);
- }
-
- public function ajax_get_arctype()
- {
- $pid = input('pid/d');
- $html = '';
- $status = 0;
- if (0 < $pid) {
- $map = array(
- 'current_channel' => array('IN', $this->allowReleaseChannel),
- 'parent_id' => $pid,
- );
- $row = model('Arctype')->getAll('id,typename', $map, 'id');
- if (!empty($row)) {
- $status = 1;
- $html = '<option value="0">请选择栏目…</option>';
- foreach ($row as $key => $val) {
- $html .= '<option value="'.$val['id'].'">'.$val['typename'].'</option>';
- }
- }
- }
-
- respose(array(
- 'status' => $status,
- 'msg' => $html,
- ));
- }
-
- /**
- * 复制
- */
- public function batch_copy()
- {
- if (IS_AJAX_POST) {
- $typeid = input('post.typeid/d');
- $aids = input('post.aids/s');
- $num = input('post.num/d');
-
- if (empty($typeid) || empty($aids)) {
- $this->error('复制失败!');
- } else if (empty($num)) {
- $this->error('复制数量至少一篇!');
- }
-
- // 获取复制栏目的模型ID
- $current_channel = Db::name('arctype')->where([
- 'id' => $typeid,
- ])->getField('current_channel');
- // 抽取相符合模型ID的文档aid
- $aids = Db::name('archives')->where([
- 'aid' => ['IN', $aids],
- 'channel' => $current_channel,
- ])->column('aid');
- // 复制文档处理
- $archivesLogic = new \app\admin\logic\ArchivesLogic;
- $r = $archivesLogic->batch_copy($aids, $typeid, $current_channel, $num);
- if($r){
- adminLog('复制文档-id:'.$aids);
- $this->success('操作成功');
- }else{
- $this->error('操作失败');
- }
- }
-
- $typeid = input('param.typeid/d', 0);
-
- /*允许发布文档列表的栏目*/
- $allowReleaseChannel = [];
- if (!empty($typeid)) {
- $channelId = Db::name('arctype')->where('id',$typeid)->getField('current_channel');
- $allowReleaseChannel[] = $channelId;
- }
- $arctype_html = allow_release_arctype($typeid, $allowReleaseChannel);
- $this->assign('arctype_html', $arctype_html);
- /*--end*/
-
- /*表单提交URL*/
- $form_action = url('Archives/batch_copy');
- $this->assign('form_action', $form_action);
- /*--end*/
-
- return $this->fetch();
- }
-
- /**
- * 批量属性操作
- */
- public function batch_attr()
- {
- if (IS_AJAX_POST) {
- $opt = input('post.opt/s');
- $aids = input('post.aids/s');
- $attrType = input('post.attrType/s');
-
- if (empty($opt)) {
- $this->error('操作失败!');
- } else if (empty($attrType)) {
- $this->error('请勾选属性!');
- } else if (empty($aids)) {
- $this->error('文档ID不能为空!');
- }
-
- $value = ($opt == 'add') ? 1 : 0;
- $aids = str_replace(',', ',', $aids);
- $r = Db::name('archives')->where([
- 'aid' => ['IN', explode(',', $aids)],
- 'lang' => $this->admin_lang,
- ])->update([
- $attrType => $value,
- 'update_time' => getTime(),
- ]);
- if($r !== false){
- adminLog('批量处理属性-id:'.$aids);
- $this->success('操作成功');
- }else{
- $this->error('操作失败');
- }
- }
-
- /*文档属性*/
- $assign_data['archives_flags'] = model('ArchivesFlag')->getList();
-
- $this->assign($assign_data);
- return $this->fetch();
- }
-
- /**
- * 远程图片本地化
- *
- * @access public
- * @return string
- */
- public function ajax_remote_to_local()
- {
- if (IS_AJAX_POST) {
- $body = input('post.body/s', '', null);
- $body = remote_to_local($body);
- $this->success('本地化成功!', null, ['body'=>$body]);
- }
- $this->error('本地化失败!');
- }
-
- /**
- * 清除非站内链接
- *
- * @access public
- * @return string
- */
- public function ajax_replace_links()
- {
- if (IS_AJAX_POST) {
- $body = input('post.body/s', '', null);
- $body = replace_links($body);
- $this->success('清除成功!', null, ['body'=>$body]);
- }
- $this->error('清除失败!');
- }
-
- /**
- * 自动远程图片本地化/自动清除非站内链接
- *
- * @access public
- * @return string
- */
- public function ajax_auto_editor()
- {
- $this->error('因安全问题,已作废禁用');
- if (IS_AJAX_POST) {
- $body = input('post.body/s', '', null);
- $local = input('post.local/d', '', 0);
- $link = input('post.link/d', '', 0);
- if (1 == $local){
- $body = remote_to_local($body);
- }
- if (1 == $link){
- $body = replace_links($body);
- }
- $this->success('操作成功!', null, ['body'=>$body]);
- }
- $this->error('操作失败!');
- }
-
- /**
- * 自定义字段
- */
- public function ajax_get_addonextitem()
- {
- \think\Session::pause(); // 暂停session,防止session阻塞机制
- $aid = input('param.aid/d', 0);
- $typeid = input('param.typeid/d', 0);
- $channeltype = input('param.channeltype/d', 0);
-
- $assign_data = [];
- $controller_name = input('param.controller_name/s');
- $assign_data['controller_name'] = $controller_name;
- $action_name = input('param.action_name/s');
- $assign_data['action_name'] = $action_name;
-
- $editor = tpSetting('editor');
- if (!empty($typeid) && !empty($channeltype)) {
- // 存在aid则执行,查询文档数据
- $info = [];
- if (!empty($aid)) {
- $info = Db::name('archives')->where('aid', $aid)->find();
- }
- if (!empty($info)) {
- $editor['editor_remote_img_local'] = $info['editor_remote_img_local'];
- $editor['editor_img_clear_link'] = $info['editor_img_clear_link'];
- }
- // 查询对应的自定义字段
- $addonFieldExtList = model('Field')->getChannelFieldList($channeltype, 0, $aid, $info);
- $field_ids = get_arr_column($addonFieldExtList, 'id');
- $typeids = [0, $typeid];
- $channelfieldBindList = Db::name('channelfield_bind')->field('field_id,typeid')->where([
- 'typeid' => ['IN', $typeids],
- ])->whereOr([
- 'field_id' => ['IN', $field_ids],
- ])->select();
- $field_id_row = $channelfieldBindRow = [];
- foreach ($channelfieldBindList as $key => $val) {
- // 查询对应的自定义字段
- if (in_array($val['field_id'], $field_ids)) {
- $field_id_row[] = $val['field_id'];
- }
- // 查询绑定的自定义字段
- if (in_array($val['typeid'], $typeids)) {
- $channelfieldBindRow[] = $val['field_id'];
- }
- }
- // 匹配显示的自定义字段
- $htmltextField = []; // 富文本的字段名
- $content_ey_m_dfvalue = ""; //手机端详情内容
- $have_content_ey_m = 0; //是否显示手机端
- $name_arr = get_arr_column($addonFieldExtList,'name');
- if (!empty($field_id_row)) {
- $first_html = '';
- foreach ($addonFieldExtList as $key => $val) {
- if (in_array($val['id'], $field_id_row) && !in_array($val['id'], $channelfieldBindRow)) {
- unset($addonFieldExtList[$key]);
- continue;
- }
- if ($val['dtype'] == 'htmltext') {
- if ($val['name'] == 'content_ey_m'){
- $content_ey_m_dfvalue = $val['dfvalue'];
- if ($val['ifeditable']){
- $have_content_ey_m = 1;
- }
- }
- if (empty($first_html) && $val['name'] != 'content_ey_m'){
- $addonFieldExtList[$key]['editor'] = $editor;
- if ('content' == $val['name'] || 'Custom' == $controller_name) {
- $addonFieldExtList[$key]['first'] = 1;
- $first_html = 1;
- }
- }
- array_push($htmltextField, $val['name']);
- }
- if($val['name'] == 'content_ey_m' && in_array('content',$name_arr)){
- unset($addonFieldExtList[$key]);
- continue;
- }
- }
- } else {
- $first_html = '';
- foreach ($addonFieldExtList as $key => $val) {
- if ($val['dtype'] == 'htmltext') {
- if ($val['name'] == 'content_ey_m'){
- $content_ey_m_dfvalue = $val['dfvalue'];
- if ($val['ifeditable']){
- $have_content_ey_m = 1;
- }
- }
- if (empty($first_html) && $val['name'] != 'content_ey_m'){
- $addonFieldExtList[$key]['editor'] = $editor;
- if ('content' == $val['name'] || 'Custom' == $controller_name) {
- $addonFieldExtList[$key]['first'] = 1;
- $first_html = 1;
- }
- }
- array_push($htmltextField, $val['name']);
- }else if ($val['dtype'] == 'region' && !empty($val['set_type']) && $val['set_type'] == 1) {
- if (!empty($val['trueValue'][1])){
- $addonFieldExtList[$key]['city_list'] = Db::name('region')->where(['level'=>2,'parent_id'=>$val['trueValue'][0]])->select();
- }
- if (!empty($val['trueValue'][2])){
- $addonFieldExtList[$key]['area_list'] = Db::name('region')->where(['level'=>3,'parent_id'=>$val['trueValue'][1]])->select();
- }
- }
- if($val['name'] == 'content_ey_m' && in_array('content',$name_arr)){
- unset($addonFieldExtList[$key]);
- continue;
- }
- }
- }
- $assign_data['content_ey_m_dfvalue'] = $content_ey_m_dfvalue;
- $assign_data['have_content_ey_m'] = $have_content_ey_m;
-
- // 加载模板
- $assign_data['params'] = input('param.');
- $assign_data['field'] = $info;
-
- //var_dump($assign_data);
- /*
- dtype text
- define
- title
- name
- dfvalue
- remark
- */
- $assign_data['typeid'] = $typeid;
-
- //$topid = Db::name('arctype')->where('id','=',$typeid)->value('topid');
- $cat = Db::name('arctype')->where(['id'=>$typeid])->find();
- $vb = ['qkmc','zbdw','yxyz','zgdw','jb','gnkh','slzt','jytg'];
- $vbs = ['content_5','down','imgs','pagenum','content_4','zylm','wplj','tqm']; //保留两者
- if((int)$cat['topid'] === 38){
- //删除期刊
- foreach ($addonFieldExtList as $key=>$item){
- //echo $item['name'];
- if(in_array($item['name'],$vb) && !in_array($item['name'],$vbs)){
- unset($addonFieldExtList[$key]);
- }
- }
- }else if((int)$cat['parent_id'] === 116 || (int)$typeid === 116){
- //论文期刊
- foreach ($addonFieldExtList as $key=>$item){
- //echo $item['name'];
- if(!in_array($item['name'],$vb) && !in_array($item['name'],$vbs)){
- unset($addonFieldExtList[$key]);
- }
-
- if($item['name'] === 'content_5'){
- $item['first'] = 1;
- $addonFieldExtList[$key] = $item;
- }
- }
- //first 属性
- }else{
-
- if((int)$cat['topid'] !== 36) {
- //隐藏产品和期刊
- foreach ($addonFieldExtList as $key => $item) {
- //echo $item['name'];
- if (!in_array($item['name'], $vbs)) {
- unset($addonFieldExtList[$key]);
- }
-
- if($item['name'] === 'content_5'){
- $item['first'] = 1;
- $addonFieldExtList[$key] = $item;
- }
- }
-
- //first 属性
- }
- }
-
- //var_dump($addonFieldExtList);
- $assign_data['addonFieldExtList'] = $addonFieldExtList;
- $this->assign($assign_data);
- // 渲染模板
- $html = $this->fetch('field/addonextitem');
- $this->success('请求成功', null, ['html'=>$html, 'htmltextField'=>$htmltextField]);
- }
- }
-
- /**
- * 新建模板文件
- */
- public function ajax_newtpl()
- {
- $this->error('已废弃');
- if (IS_POST) {
- $post = input('post.', '', null);
- $content = input('post.content', '', null);
- $view_suffix = config('template.view_suffix');
- if (!empty($post['filename'])) {
- if (!preg_match("/^[\w\-\_]{1,}$/u", $post['filename'])) {
- $this->error('文件名称只允许字母、数字、下划线、连接符的任意组合!');
- }
- $filename = "{$post['type']}_{$post['nid']}_{$post['filename']}.{$view_suffix}";
- } else {
- $filename = "{$post['type']}_{$post['nid']}.{$view_suffix}";
- }
-
- $content = !empty($content) ? $content : '';
- $tpldirpath = !empty($post['tpldir']) ? '/template/'.TPL_THEME.trim($post['tpldir']) : '/template/'.TPL_THEME.'pc';
- if (file_exists(ROOT_PATH.ltrim($tpldirpath, '/').'/'.$filename)) {
- $this->error('文件名称已经存在,请重新命名!', null, ['focus'=>'filename']);
- }
-
- $nosubmit = input('param.nosubmit/d');
- if (1 == $nosubmit) {
- $this->success('检测通过');
- }
-
- $filemanagerLogic = new \app\admin\logic\FilemanagerLogic;
- $r = $filemanagerLogic->editFile($filename, $tpldirpath, $content);
- if ($r === true) {
- $this->success('操作成功', null, ['filename'=>$filename,'type'=>$post['type']]);
- } else {
- $this->error($r);
- }
- }
- $type = input('param.type/s');
- $nid = input('param.nid/s');
- $tpldirList = glob('template/'.TPL_THEME.'*');
- $tpl_theme = str_replace('/', '\\/', TPL_THEME);
- foreach ($tpldirList as $key => $val) {
- if (!preg_match('/template\/'.$tpl_theme.'(pc|mobile)$/i', $val)) {
- unset($tpldirList[$key]);
- } else {
- $tpldirList[$key] = preg_replace('/^(.*)template\/'.$tpl_theme.'(pc|mobile)$/i', '$2', $val);
- }
- }
- !empty($tpldirList) && arsort($tpldirList);
- $this->assign('tpldirList', $tpldirList);
-
- $content = '';
- if ('special' == $nid) {
- $fileContent = @file_get_contents('./data/model/template/pc/view_custommodel.htm');
- if (!empty($fileContent)) {
- $content = $fileContent;
- $replace = <<<EOF
- <section class="article-list">
- {eyou:specnode code="default1" id="field"}
- <article>
- {eyou:notempty name="\$field.is_litpic"}
- <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>
- {/eyou:notempty}
- <h2><a href="{\$field.arcurl}" target="_blank">{\$field.title}</a><span>{\$field.click}°C</span></h2>
- <div class="excerpt">
- <p>{\$field.seo_description}</p>
- </div>
- <div class="meta">
- <span class="item"><time>{\$field.add_time|MyDate='Y-m-d',###}</time></span>
- <span class="item"><a href="{\$field.typeurl}" target="_blank">{\$field.typename}</a></span>
- </div>
- </article>
- {/eyou:specnode}
- </section>
- EOF;
- $content = str_replace("<!-- #special# -->", $replace, $content);
- }
- }
- $this->assign('content', $content);
-
- $this->assign('type', $type);
- $this->assign('nid', $nid);
- $this->assign('tpl_theme', TPL_THEME);
- return $this->fetch();
- }
-
- /**
- * 检测自定义文件名是否存在
- */
- public function ajax_check_htmlfilename()
- {
- $htmlfilename = input('post.htmlfilename/s');
- $htmlfilename = trim($htmlfilename);
- if (!empty($htmlfilename)) {
- $aid = input('post.aid/d');
- $typeid = input('post.typeid/d');
- $htmlfilename = preg_replace("/[^\x{4e00}-\x{9fa5}\w\-]+/u", "-", $htmlfilename);
- // $htmlfilename = strtolower($htmlfilename);
- $map = array(
- 'htmlfilename' => $htmlfilename,
- 'lang' => $this->admin_lang,
- );
- if ($aid > 0) {
- $map['aid'] = array('neq', $aid);
- }
- if ($typeid > 0) {
- $map['typeid'] = array('eq', $typeid);
- }
- $result = Db::name('archives')->where($map)->find();
- if (!empty($result)) {
- $this->error('同栏目下,自定义文件名已存在!');
- }
- }
- $this->success('自定义文件名可用!');
- }
-
- //投稿列表
- public function index_draft()
- {
- $assign_data = array();
- $condition = [];
- if (is_dir('./weapp/MultiMerchant/')) {
- $condition['a.merchant_id'] = 0;
- }
- $param = input('param.');
- $typeid = input('typeid/d', 0);
- $draft_type = input('param.draft_type/s');
- foreach (['keywords','typeid','draft_type'] as $key) {
- $param[$key] = addslashes(trim($param[$key]));
- if (isset($param[$key]) && $param[$key] !== '') {
- if ($key == 'keywords') {
- $condition['a.title'] = array('LIKE', "%{$param[$key]}%");
- } else if ($key == 'typeid') {
- $typeid = $param[$key];
- $hasRow = model('Arctype')->getHasChildren($typeid);
- $typeids = get_arr_column($hasRow, 'id');
- //权限控制 by 小虎哥
- $admin_info = session('admin_info');
- if (0 < intval($admin_info['role_id'])) {
- $auth_role_info = $admin_info['auth_role_info'];
- if(! empty($auth_role_info)){
- if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
- $condition['a.admin_id'] = $admin_info['admin_id'];
- }
- if(! empty($auth_role_info['permission']['arctype'])){
- if (!empty($typeid)) {
- $typeids = array_intersect($typeids, $auth_role_info['permission']['arctype']);
- }
- }
- }
- }
- $condition['a.typeid'] = array('IN', $typeids);
- } else if ($key == 'draft_type') {
- if ('user' == $param[$key]) {
- $condition['a.users_id'] = array('gt', 0);
- } else if ('admin' == $param[$key]) {
- $condition['a.users_id'] = array('eq', 0);
- }
- } else {
- $condition['a.'.$key] = array('eq', $param[$key]);
- }
- }
- }
-
- //权限控制 by 小虎哥
- if (empty($typeid)) {
- $typeids = [];
- $admin_info = session('admin_info');
- if (0 < intval($admin_info['role_id'])) {
- $auth_role_info = $admin_info['auth_role_info'];
- if(! empty($auth_role_info)){
- if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
- $condition['a.admin_id'] = $admin_info['admin_id'];
- }
- if (!empty($auth_role_info['permission']['arctype'])) $typeids = $auth_role_info['permission']['arctype'];
- }
- }
- if (!empty($typeids)) $condition['a.typeid'] = array('IN', $typeids);
- }
-
- if (empty($typeid)) {
- $id_tmp = [6,8];
- // 只显示允许发布文档的模型,且是开启状态
- $channelIds = Db::name('channeltype')->where('status',0)
- ->whereOr('id','IN',$id_tmp)->column('id');
- $condition['a.channel'] = array('NOT IN', $channelIds);
- } else {
- // 只显示当前栏目对应模型下的文档
- $current_channel = Db::name('arctype')->where('id',$typeid)->getField('current_channel');
- $condition['a.channel'] = array('eq', $current_channel);
- }
-
- $condition['a.arcrank'] = -1;
- $condition['a.lang'] = array('eq', $this->admin_lang);
- $condition['a.is_del'] = array('eq', 0);
-
- // 自定义排序
- $orderby = input('param.orderby/s');
- $orderway = input('param.orderway/s');
- $orderby = !empty($orderby) ? "a.{$orderby} {$orderway}, a.aid desc" : "a.aid desc";
-
- // 总投稿数
- $condition1 = $condition2 = $condition;
- if (!empty($condition1['a.users_id'])) {
- unset($condition1['a.users_id']);
- }
- $allCount = Db::name('archives')->alias('a')->where($condition1)->count('aid');
- $assign_data['allCount'] = $allCount;
- if (empty($draft_type)) {
- $condition2['a.users_id'] = ['gt', 0];
- $userCount = Db::name('archives')->alias('a')->where($condition2)->count('aid');
- }
- $currentCount = Db::name('archives')->alias('a')->where($condition)->count('aid');
-
- // 查询并处理缓存表
- $SqlQuery = Db::name('archives')->alias('a')->where($condition)->fetchSql()->count('aid');
- $count = Db::name('sql_cache_table')->where(['sql_md5'=>md5($SqlQuery)])->getField('sql_result');
- $count = ($count < 0) ? 0 : $count;
- if (empty($count)) {
- $count = Db::name('archives')->alias('a')->where($condition)->count('aid');
- // 添加查询执行语句到mysql缓存表
- $SqlCacheTable = [
- 'sql_name' => '|archives|draft|',
- 'sql_result' => $count,
- 'sql_md5' => md5($SqlQuery),
- 'sql_query' => $SqlQuery,
- 'add_time' => getTime(),
- 'update_time' => getTime()
- ];
- if (!empty($typeid)) $SqlCacheTable['sql_name'] = $SqlCacheTable['sql_name'] . $typeid . '|';
- Db::name('sql_cache_table')->insertGetId($SqlCacheTable);
- }
-
- if ('user' == $draft_type) { // 前台投稿总数
- $userCount = $currentCount;
- $adminCount = $allCount - $userCount;
- } else if ('admin' == $draft_type) { // 后台发布待审核总数
- $adminCount = $currentCount;
- $userCount = $allCount - $adminCount;
- } else {
- $adminCount = $allCount - $userCount;
- }
- $assign_data['userCount'] = $userCount;
- $assign_data['adminCount'] = $adminCount;
-
- // 分页
- $Page = new Page($count, config('paginate.list_rows'));
- $list = [];
- if (0 < $count) {
- // 数据查询,搜索出主键ID的值
- $limit = $count > config('paginate.list_rows') ? $Page->firstRow.','.$Page->listRows : $count;
- $list = Db::name('archives')
- ->field("a.aid,a.channel,a.admin_id,a.users_id")
- ->alias('a')
- ->where($condition)
- ->orderRaw($orderby)
- ->limit($limit)
- ->getAllWithIndex('aid');
-
- $aids = [];
- $admin_ids = [];
- $users_ids = [];
- $channelIds = [];
- // 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
- if ($list) {
- foreach ($list as $key => $val) {
- array_push($aids, $val['aid']);
- !empty($val['admin_id']) && array_push($admin_ids, $val['admin_id']);
- !empty($val['users_id']) && array_push($users_ids, $val['users_id']);
- array_push($channelIds, $val['channel']);
- }
-
- $fields = "b.*, a.*, a.aid as aid";
- $row = Db::name('archives')
- ->field($fields)
- ->alias('a')
- ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
- ->where('a.aid', 'in', $aids)
- ->getAllWithIndex('aid');
-
- // 获取当页文档的所有模型
- $assign_data['channelRow'] = Db::name('channeltype')->field('id, ctl_name, ifsystem')
- ->where('id', 'IN', $channelIds)
- ->getAllWithIndex('id');
-
- $userlist = Db::name('users')->field('users_id,username,nickname')->where('users_id', 'in', $users_ids)->getAllWithIndex('users_id');
- $adminlist = Db::name('admin')->field('admin_id,user_name,pen_name')->where('admin_id', 'in', $admin_ids)->getAllWithIndex('admin_id');
- foreach ($list as $key => $val) {
- $row[$val['aid']]['arcurl'] = get_arcurl($row[$val['aid']]);
- $row[$val['aid']]['litpic'] = handle_subdir_pic($row[$val['aid']]['litpic']);
- if (!empty($userlist[$val['users_id']])) {
- $row[$val['aid']]['username'] = !empty($userlist[$val['users_id']]['nickname']) ? $userlist[$val['users_id']]['nickname'] : $userlist[$val['users_id']]['username'];
- } else if (!empty($adminlist[$val['admin_id']])) {
- $row[$val['aid']]['username'] = !empty($adminlist[$val['admin_id']]['pen_name']) ? $adminlist[$val['admin_id']]['pen_name'] : $adminlist[$val['admin_id']]['user_name'];
- } else {
- $row[$val['aid']]['username'] = '匿名';
- }
- $list[$key] = $row[$val['aid']];
- }
- }
- }
-
- // 加载信息
- $assign_data['page'] = $Page->show();
- $assign_data['list'] = $list;
- $assign_data['pager'] = $Page;
- $assign_data['typeid'] = $typeid;
- $arctype_info = array(); // 当前栏目信息
- if ($typeid > 0) $arctype_info = Db::name('arctype')->field('typename,current_channel')->find($typeid);
- $assign_data['arctype_info'] = $arctype_info;
- // $assign_data['arctype_html'] = allow_release_arctype($typeid, array()); // 允许发布文档列表的栏目
- $assign_data['seo_pseudo'] = tpCache('global.seo_pseudo'); // 前台URL模式
- $assign_data['archives_flags'] = model('ArchivesFlag')->getList(); // 文档属性
- $assign_data['shop_open'] = getUsersConfigData('shop.shop_open'); // 商城开关
- $assign_data['is_arctype'] = Db::name('arctype')->where(['is_del'=>0,'lang'=>get_current_lang()])->count(); // 是否存在栏目
- $assign_data['draft_type'] = $draft_type;
- // 页面url
- $assign_data['pageurl'] = request()->url(true);
- $assign_data['menu'] = input('param.menu/d', 0);
- $this->assign($assign_data);
- return $this->fetch('index_draft');
- }
-
- //文档标题重复检测
- public function check_title_repeat($title='',$aid=0)
- {
- $map['title'] = $title;
- if (!empty($aid)){
- $map['aid'] = ['NEQ', $aid];
- }
- $count = Db::name('archives')->where($map)->count('aid');
- if (!empty($count)){
- $this->error("<font color='black'>系统已存在标题为'<font color='red'>".$title."'</font>的文档! </font><a href='javascript:void(0);' onclick='layer.closeAll();'>[<font color='red'>关闭</font>]</a>");
- }
- $this->success("没有重复!");
-
- }
-
- //ajax改变富文本编辑器远程图片本地化/清除非本站链接
- public function ajax_editor_set()
- {
- if (IS_AJAX){
- $post = input('post.');
- if (0 == $post['value']){
- $post['value'] = 1;
- }elseif (1 == $post['value']){
- $post['value'] = 0;
- }
- $editor_arr[$post['name']] = $post['value'];
- $res = tpSetting('editor', $editor_arr);
- if (!empty($res)){
- $this->success("保存成功!");
- }else{
- $this->error('保存失败!');
- }
- }
- }
-
- /**
- * 设置来源列表
- * @return [type] [description]
- */
- public function ajax_set_originlist()
- {
- if (IS_POST) {
- $originlist = [];
- $origin = input('param.origin/s');
- $origin = str_replace(["\r\n", "\r", "\n", PHP_EOL], "~|~", $origin);
- $originArr = explode("~|~", $origin);
- foreach ($originArr as $key => $val) {
- $val = trim($val);
- if (!empty($val)) {
- array_push($originlist, $val);
- }
- }
- tpSetting('system', ['system_originlist'=>json_encode($originlist)]);
-
- $originlist_str = implode(PHP_EOL, $originlist);
- $this->success('操作成功', null, ['originlist_str'=>$originlist_str]);
- }
- $this->error('操作失败');
- }
-
- /**
- * 查找显示来源列表
- * @return [type] [description]
- */
- public function search_origin()
- {
- if (IS_AJAX_POST) {
- $post = input('param.');
- $keyword = trim($post['keyword']);
-
- $originlist = tpSetting('system.system_originlist');
- $originlist = json_decode($originlist, true);
-
- $search_data = $originlist;
- if (!empty($keyword)) {
- $search_data = [];
- if ($originlist) {
- foreach ($originlist as $k => $v) {
- if (preg_match("/$keyword/s", $v)) $search_data[] = $v;
- }
- }
- }
-
- $this->success("获取成功",null,$search_data);
- }
- }
-
- /**
- * 发布/编辑文档时选择副栏目
- * @return [type] [description]
- */
- public function ajax_get_stypeid_list()
- {
- $assign_data = [];
-
- $channel = input('param.channel/d');
- $catid = input('param.catid/d',1);
- if (empty($channel)) {
- $this->error('URL缺少channel参数!');
- }
- $assign_data['channel'] = $channel;
-
- // 目录列表
- $where = [];
- $where['current_channel'] = $channel;
- $where['is_del'] = 0; // 回收站功能
- $arctypeLogic = new ArctypeLogic;
-
-
-
- /*获取所有有子栏目的栏目id*/
- $parent_ids = Db::name('arctype')->where([
- 'parent_id' => ['gt', 0],
- 'is_del' => 0,
- ])->group('parent_id')->cache(true, EYOUCMS_CACHE_TIME, 'arctype')->column('parent_id');
- $cookied_treeclicked = json_decode(cookie('stypeid-treeClicked-Arr'));
- empty($cookied_treeclicked) && $cookied_treeclicked = [];
- $all_treeclicked = cookie('stypeid-treeClicked_All');
- empty($all_treeclicked) && $all_treeclicked = [];
- $tree = [
- 'has_children'=>!empty($parent_ids) ? 1 : 0,
- 'parent_ids'=>json_encode($parent_ids),
- 'all_treeclicked'=>$all_treeclicked,
- 'cookied_treeclicked'=>$cookied_treeclicked,
- 'cookied_treeclicked_arr'=>json_encode($cookied_treeclicked),
- ];
- $assign_data['tree'] = $tree;
- /* end */
-
- // 副栏目
- $stypeid = input('param.stypeid/s');
- $stypeid = trim($stypeid, ',');
- $stypeid_arr = explode(',', $stypeid);
- $typename_arr = [];
- $row = Db::name('arctype')->field('id,typename')->where(['id'=>['IN', $stypeid_arr]])->select();
- foreach ($row as $key => $val) {
- $typename_arr[] = "{$val['typename']}";
- }
- $stypename = implode(' | ', $typename_arr);
- // 主栏目
- $typeid = input('param.typeid/d');
- // !empty($typeid) && array_push($stypeid_arr, $typeid);
- $assign_data['typeid'] = $typeid;
-
- //加入区域条件
- $proid = 1; //默认广东省
- $typeid = $_GET['typeid']?$_GET['typeid']:0;
- $typeid = (int)$typeid;
- $arctypeInfo = Db::name('arctype')->find($typeid);
- if((int)$arctypeInfo['area_id'] > 1){
- $proid = (int)$arctypeInfo['area_id'];
- }else{
- if((int)$catid === 0) {
- $catid = 1;
- //默认广东省
- }
- $proid = $catid;
- }
- //再次计算
- //$stypeid 存在 查询默认的
- //不然没结果
- $arctype = Db::name('arctype')->where('id','=',$stypeid)->find();
- if((int)$stypeid > 0){
- $proid = $arctype['area_id'];
- }
-
- $this->assign('catid',$proid);
- //var_dump($catid);
- $arctype_list = $arctypeLogic->arctype_list(0, 0, false, 0, $where, false,'',$proid);
- $assign_data['arctype_list'] = $arctype_list;
-
- $assign_data['stypeid'] = $stypeid;
- $assign_data['stypename'] = $stypename;
- $assign_data['stypeid_arr'] = $stypeid_arr;
-
- //区域数据
- /*
- * 调用省份数据
- */
- $pro_list = Db::table('ey_citysite')->where([
- "level" => 1,
- "parent_id" => 0,
- "topid" => 0,
- "status" => 1,
- ])->select();
- $this->assign('pro_list',$pro_list);
-
- $this->assign($assign_data);
-
- return $this->fetch();
- }
- }
|