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("
共提交".$cuarray['success']."条。今日自动提交剩余".$cuarray['remain'].'条
','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("
共提交".$cuarray['success']."条。今日自动提交剩余".$cuarray['remain'].'条
','jiameng/index?page='.$page);
}else{
$this->error("今天提交已经到上线,明天再来吧!",'jiameng/index?page='.$page);
}
}else{
$this->success("没有新熊掌天级连接提交",'jiameng/index?page='.$page);
}
}
}
?>