| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- <?php
- namespace app\admin\controller;
- use cmf\controller\AdminBaseController;
- use think\Db;
- class NewsController extends AdminBaseController{
- public function initialize(){
- parent::initialize();
- $username = $_SESSION['think']['name'];
- $userid = $_SESSION['think']['ADMIN_ID'];
- //判断是否是编辑管理员
- $iseditor = 0;
- $iseditor = Db::name('role_user')->where('role_id',3)->where('user_id',$userid)->count();
- $this->iseditor = $iseditor;
- $this->uname = $username;
- $this->assign('iseditor',$iseditor);
- }
- public function index(){
- $param = $this->request->param();
- $page = isset($param['page'])?intval($param['page']):1;
- $this->assign('page',$page);
- $cates = Db::name('category')->where('parent_id',0)->order('list_order')->select();
- foreach($cates as $k=>$v){
- $son = Db::name('category')->where('parent_id',$v['id'])->order('list_order')->select();
- $v['son'] = $son;
- $cates[$k] = $v;
- }
- $this->assign('cates',$cates);
- $keywords = isset($param['keywords'])?trim($param['keywords']):'';
- $catid = isset($param['catid'])?intval($param['catid']):0;
- $query = array(
- 'catid' => $catid,
- 'keywords' => $keywords
- );
- $map = array();
- if($this->iseditor){
- $map['author'] = $this->uname;
- //加多一个编辑人员下的,如果是审核了,就不显示文章。2020-05-15
- //$map['status'] = 0;
- }
- if($catid){
- $map['catid'] = $catid;
- }
- if($keywords!=''){
- $lists = Db::name('news')->where($map)->where('title','like','%'.$keywords.'%')->order('id desc')->paginate(20,false,['query'=>$query]);
- }else{
- $lists = Db::name('news')->where($map)->order('id desc')->paginate(20,false,['query'=>$query]);
- }
- //文章分类
- $article_list = Db::name('news_category')->order('list_order')->select();
- $article_cates = array();
- foreach($article_list as $k=>$v){
- $article_cates[$v['id']] = $v['catname'];
- }
- // var_dump($this->iseditor);die;
- $this->assign('iseditor',$this->iseditor);
- $this->assign('article_cates',$article_cates);
- $this->assign('keywords',$keywords);
- $this->assign('catid',$catid);
- $this->assign('lists',$lists);
- return $this->fetch();
- }
- public function add(){
-
- //如果是管理员的就是这样。
- $admin_id=$_SESSION['think']['ADMIN_ID'];
- $user = Db::name('role_user')->field('role_id,user_id')->where('user_id',$admin_id)->find();
- // echo Db::name('role_user')->getLastSql();die();
- // echo ($user['role_id']) ;die;
- // echo $admin_id;die();
- if($user['role_id']==3){
- $param = $this->request->param();
- $cates = Db::name('user')->field('category')->where('id',$user['user_id'])->find();
- $category=explode(',',$cates['category']);
-
- $categorys='';
- //遍历数组成字符串,然后再进行循环读取。
-
- foreach($category as $k=>$value){
- if(($k+1)==count($category)){
- $categorys.=$value."";
- }else{
- $categorys.=$value.",";
- }
- }
- // echo $categorys;die();
- //foreach($cates as $k=>$v){
- //sdfsdfs
- $cates = Db::name('category')->where('id','in',$categorys)->order('id')->select();
- // echo Db::name('category')->getLastSql();die();
- //}
- //文章分类
- //文章分类
- $article_list = Db::name('news_category')->order('list_order')->select();
- $article_cates = array();
- foreach($article_list as $k=>$v){
- $article_cates[$v['id']] = $v['catname'];
- }
- }else{
- $param = $this->request->param();
- isset($param['pid']) or $param['pid'] = 0;
- $cates = Db::name('category')->where('parent_id',0)->order('list_order')->select();
- foreach($cates as $k=>$v){
- $son = Db::name('category')->where('parent_id',$v['id'])->order('list_order')->select();
- $v['son'] = $son;
- $cates[$k] = $v;
- }
- //文章分类
- //文章分类
- $article_list = Db::name('news_category')->order('list_order')->select();
- $article_cates = array();
- foreach($article_list as $k=>$v){
- $article_cates[$v['id']] = $v['catname'];
- }
- }
-
- //var_dump($_SESSION['think']['ADMIN_ID']);die;
- //通过admin_id来进行读取用户的角色信息
- //
-
- $this->assign('pid',$param['pid']);
- $this->assign('article_cates',$article_cates);
- $this->assign('cates',$cates);
- return $this->fetch();
- }
- public function addPost(){
- $param = $this->request->param();
- $param['create_time'] = time();
- $data['content'] = $param['content'];
- unset($param['content']);
- if($this->iseditor){
- $param['author'] = $this->uname;
- $param['status'] = 0;
- }
- $res = Db::name('news')->insertGetId($param);
- $data['id'] = $res;
-
-
- Db::name('news_data')->insert($data);
- if($res){
- $this->success('添加成功');
- }else{
- $this->error('添加失败');
- }
- }
- public function delete(){
- $param = $this->request->param();
- isset($param['id'])&&$param['id']!='' or $this->error('需要id');
- $res = Db::name('news')->where('id',$param['id'])->delete();
- if($res){
- $this->success('删除成功');
- }else{
- $this->error('删除失败');
- }
- }
- public function edit(){
- $param = $this->request->param();
- $page = isset($param['page'])?intval($param['page']):1;
- $this->assign('page',$page);
-
- isset($param['id']) or $this->error('需要id');
- $cates = Db::name('category')->where('parent_id',0)->order('list_order')->select();
- foreach($cates as $k=>$v){
- $son = Db::name('category')->where('parent_id',$v['id'])->order('list_order')->select();
- $v['son'] = $son;
- $cates[$k] = $v;
- }
- $this->assign('cates',$cates);
- //文章分类
- //文章分类
- $article_list = Db::name('news_category')->order('list_order')->select();
- $article_cates = array();
- foreach($article_list as $k=>$v){
- $article_cates[$v['id']] = $v['catname'];
- }
- $this->assign('article_cates',$article_cates);
- $info = Db::name('news')->where('id',$param['id'])->find();
- $content = Db::name('news_data')->where('id',$param['id'])->find();
- $info['content'] = $content['content'];
- if(empty($info['id'])){
- $this->error('未找到信息');
- }
- $this->assign('iseditor',$this->iseditor);
- $this->assign('info',$info);
- return $this->fetch();
- }
- public function editPost(){
- $param = $this->request->param();
- $page = $param['page'];
- unset($param['page']);
- isset($param['id']) or $this->error('需要id');
- $param['update_time'] = time();
- $data['content'] = $param['content'];
- unset($param['content']);
- $res = Db::name('news')->update($param);
- $data['id'] = $param['id'];
- Db::name('news_data')->update($data);
- if($res){
- // $this->success('编辑成功','news/index?page='.$page);
- // $this->success('编辑成功','news/index');
- $this->success('编辑成功',$page);
- }else{
- $this->error('编辑失败');
- }
- }
- /**
- * 添加分类页面
- */
- public function cateAdd(){
- return $this->fetch();
- }
- /**
- * 添加分类提交
- */
- public function cateAddPost(){
- $param = $this->request->param();
-
- isset($param['catname'])&&trim($param['catname'])!='' or $this->error('请填写分类名称');
- $data = array(
- 'catname' => $param['catname'],
- 'enname' => $param['enname'],
- 'seo_title' => $param['seo_title'],
- 'seo_keywords' => $param['seo_keywords'],
- 'seo_desc' => $param['seo_desc'],
- 'list_order' => $param['list_order'],
- 'create_time' => time()
- );
-
- $res = Db::name('news_category')->insert($data);
- if($res){
- $this->success('添加成功');
- }else{
- $this->error('添加失败');
- }
- }
- /**
- * 分类编辑
- */
- public function cateEdit(){
- $param = $this->request->param();
- isset($param['id']) or $this->error('没有id');
- $res = Db::name('news_category')->where('id',$param['id'])->find();
- $this->assign('info',$res);
- return $this->fetch();
- }
- public function cateEditPost(){
- $param = $this->request->param();
- isset($param['catname'])&&trim($param['catname'])!='' or $this->error('请填写分类名称');
- isset($param['parent_id']) or $param['parent_id'] = 0;
- $data = array(
- 'id' => $param['id'],
- 'catname' => $param['catname'],
- 'enname' => $param['enname'],
- 'seo_title' => $param['seo_title'],
- 'seo_keywords' => $param['seo_keywords'],
- 'seo_desc' => $param['seo_desc'],
- 'list_order' => $param['list_order'],
- 'update_time' => time()
- );
-
- $res = Db::name('news_category')->update($data);
- if($res){
- $this->success('编辑成功');
- }else{
- $this->error('编辑失败');
- }
- }
- public function cateList(){
- $lists = Db::name('news_category')->order('list_order')->select();
- $this->assign('lists',$lists);
- return $this->fetch();
- }
- public function cateDelete(){
- $param = $this->request->param();
- isset($param['id']) or $this->error('没有id');
- $res = Db::name('news_category')->where('id',$param['id'])->delete();
- if($res){
- $this->success('删除成功');
- }else{
- $this->error('删除失败');
- }
- }
-
- public function chongfu(){
- $param = $this->request->param();
- $title = isset($param['title'])?trim($param['title']):'';
- if($title==''){
- echo 0;
- }
- $res = Db::name('news')->where('title',$title)->count();
- if($res>0){
- echo 1;
- }else{
- echo 0;
- }
- exit;
- }
-
- public function seo(){
- $param = $this->request->param();
- $page = isset($param['page'])?$param['page']:1;
- $msg = $param['msg'];
- if(count($msg)==0){
- $this->error('请选择要提交的信息');
- }
- $str = implode(",",$msg);
- if(isset($param['pc'])){
- $this->baidu($str,$page);
- }
- if(isset($param['mobile'])){
- $this->shouji($str,$page);
- }
- if(isset($param['xiongzhang'])){
- $this->bear($str,$page);
- }
- $this->success('提交成功');
- }
- // 百度链接自动提交
- public function baidu($ids,$page){
- $where = [];
- $where[] = ['id','in', $ids];
- $artRes = Db::name('news')->where($where)->select()->toArray();
-
-
- // print_r($artRes);die;
- $urls = array();
- $dataRes = array();
- $local = $_SERVER['SERVER_NAME'];
- foreach ($artRes as $k => &$v) {
-
- $v['arcurl'] = 'http://'.$local.'/news'.$v['id']."/";
- $urls[] = $v['arcurl'];
- }
- $site_info = cmf_get_option('site_info');
- // print_r($site_info);die;
- if($site_info['site_tj_pc'] == ''){
- $this->error("请设置百度提交参数!",'');
- }
- $site_baidu = $site_info['site_tj_pc'];
- $site_baidu = explode('&', $site_baidu);
- $site_baidu = implode('&', $site_baidu);
- $site_baidu = str_replace(PHP_EOL, '', $site_baidu);
- // dump($dataRes);die;
- // print_r($urls);exit;
- if(count($urls)>0 && trim($site_baidu)!=''){
- $api = $site_baidu;
- $ch = curl_init();
- $options = array(
- CURLOPT_URL => $api,
- CURLOPT_POST => true,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_POSTFIELDS => implode("\n", $urls),
- CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
- );
- curl_setopt_array($ch, $options);
- $curlresult = curl_exec($ch);
- $cuarray = json_decode($curlresult,true);
- // dump($cuarray);die;
- if($cuarray['success']>0){
-
- $this->success("共提交".$cuarray['success']."条。今日自动提交剩余".$cuarray['remain'].'条','jiameng/index?page='.$page);
-
- }else{
- $this->error("今天提交已经到上线,明天再来吧!",'jiameng/index?page='.$page);
- }
- }else{
- $this->success("没有新百度Pc连接提交",'jiameng/index?page='.$page);
- }
- }
-
- // 百度手机链接自动提交
- public function shouji($ids,$page){
- $where = [];
- $where[] = ['id','in', $ids];
- $artRes = Db::name('news')->where($where)->select()->toArray();
- $urls = array();
- $dataRes = array();
- $local = $_SERVER['SERVER_NAME'];
- $host = explode('.', $local);
- if(count($host)==3){
- $host = $host[1].'.'.$host[2];
- }else{
- $host = $host[1].'.'.$host[2].'.'.$host[3];
- }
- $local = 'm.'.$host;
-
- foreach ($artRes as $k => &$v) {
- $v['arcurl'] = 'http://'.$local.'/b'.$v['id']."/";
- $urls[] = $v['arcurl'];
-
-
- }
-
- $site_info = cmf_get_option('site_info');
-
- if($site_info['site_tj_mobile'] == ''){
- $this->error("请设置百度提交参数!",'jiameng/index?page='.$page);
- }
-
- $site_shouji = $site_info['site_tj_mobile'];
- $site_shouji = explode('&', $site_shouji);
- $site_shouji = implode('&', $site_shouji);
- $site_shouji = str_replace(PHP_EOL, '', $site_shouji);
- // print_r($urls);exit;
- if(count($urls)>0 && trim($site_shouji)!=''){
- $api = $site_shouji;
- $ch = curl_init();
- $options = array(
- CURLOPT_URL => $api,
- CURLOPT_POST => true,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_POSTFIELDS => implode("\n", $urls),
- CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
- );
- curl_setopt_array($ch, $options);
- $curlresult = curl_exec($ch);
- $cuarray = json_decode($curlresult,true);
- // dump($cuarray);die;
- if($cuarray['success']>0){
- //如果提交过并且成功的将其状态标记为1
- // foreach ($dataRes as $k => $v) {
- // Db::name('brand_post')->where('id',$k)->update(['shouji' => '1']);
- // }
- $this->success("<br/>共提交".$cuarray['success']."条。今日自动提交剩余".$cuarray['remain'].'条<br/>','jiameng/index?page='.$page);
-
- }else{
- $this->error("今天提交已经到上线,明天再来吧!",'jiameng/index?page='.$page);
- }
- }else{
- $this->success("没有新手机百度连接提交",'jiameng/index?page='.$page);
- }
- }
-
- // 百度链接自动提交
- public function bear($ids,$page){
- $where = [];
- $where[] = ['id','in', $ids];
- $artRes = Db::name('news')->where($where)->select()->toArray();
- //dump($artRes);die;
- $urls = array();
- $dataRes = array();
- $local = $_SERVER['SERVER_NAME'];
- foreach ($artRes as $k => &$v) {
- $v['arcurl'] = 'http://'.$local.'/b'.$v['id']."/";
- $urls[] = $v['arcurl'];
- }
- // dump($urls);exit;
- $site_info = cmf_get_option('site_info');
-
- //dump($site_info);die;
- if($site_info['site_tj_xiongzhang'] == ''){
- $this->error("请设置熊掌号提交参数!",'jiameng/index?page='.$page);
- }
- $site_xiongzhang = $site_info['site_tj_xiongzhang'];
- $site_xiongzhang = explode('&', $site_xiongzhang);
- $site_xiongzhang = implode('&', $site_xiongzhang);
- $site_xiongzhang = str_replace(PHP_EOL, '', $site_xiongzhang);
-
- // dump($dataRes);die;
- if(count($urls)>0 && trim($site_xiongzhang)!=''){
- $api = trim($site_xiongzhang);
- $ch = curl_init();
- $options = array(
- CURLOPT_URL => $api,
- CURLOPT_POST => true,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_POSTFIELDS => implode("\n", $urls),
- CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
- );
- curl_setopt_array($ch, $options);
- $curlresult = curl_exec($ch);
- $cuarray = json_decode($curlresult,true);
- // dump($cuarray);die;
- if($cuarray['success']>0){
- //如果提交过并且成功的将其状态标记为1
- foreach ($dataRes as $k => $v) {
- Db::name('brand_post')->where('id',$k)->update(['xiongzhang' => '1']);
- }
- $this->success("<br/>共提交".$cuarray['success']."条。今日自动提交剩余".$cuarray['remain'].'条<br/>','jiameng/index?page='.$page);
-
- }else{
- $this->error("今天提交已经到上线,明天再来吧!",'jiameng/index?page='.$page);
- }
- }else{
- $this->success("没有新熊掌天级连接提交",'jiameng/index?page='.$page);
- }
- }
- }
- ?>
|