返回小型企业站新闻......登陆

小型企业站新闻模块

12019-06-16 10:01:46107

<?php 

namespace app\admin\controller;

use app\admin\controller\Commn;

use think\facade\Request;

use think\facade\Session;

use app\admin\model\Newsl;


/**

*/

class News extends Commn

{

//新闻展示

public function index()

{

$res = Newsl::order('news_id','desc')->paginate(4);


$page = $res->render();


    $this->assign('page',$page);


$this->assign('res',$res);


return $this->fetch();

}

//新闻添加页面

public function add()

{

return $this->fetch();

}

//图片上传页面

public function uplode()

{

//获取图片信息

$file = Request::file('img');

if ($info = $file->validate(['ext'=>'jpg,png,jpeg,gif'])->move('upload')){

//返回上次成功信息


return json(['errno'=>0,'data'=>["/upload/" .$info->getSaveName()]]);

}else{

echo $info->getError();

}

}

//新闻添加处理页面

public function add_do()

{

$data = Request::param();

$data['username'] = Session::get('username');

$data['create_time'] = time();

//验证标题的唯一性

if ($res = newsL::where('title',$data['title'])->find()) {

return json(['code'=>0,'msg'=>'文章标题已经存在']);

}

if ($res = newsl::insert($data)) {

    return json(['code'=>1,'msg'=>'添加文章成功']);

}else{

return json(['code'=>2,'msg'=>'添加操作异常,请重新操作']);

}

}

//修改新闻方法

public function upl()

{

$data = Request::param();


$news_id = $data['news_id'];


$res = newsl::where('news_id',$data['news_id'])->find();


$this->assign('res',$res);


return $this->fetch();


}

//修改新闻处理方法

public function upl_do()

{

$data = Request::param();


$data['create_time'] = time();


$news_id = $data['news_id'];


$res = newsl::where('news_id',$data['news_id'])->find();


if ($data['title']==$res['title']) {

$info = newsl::where('news_id',$data['news_id'])->update($data);

if ($info == true) {

return json(['code'=>1,'msg'=>'修改新闻成功']);

}else{

return json(['code'=>2,'msg'=>'修改操作异常,请重新操作']);

}

}else{

$ture = newsl::where('title',$data['title'])->all();

if ($ture == true) {

return json(['code'=>3,'msg'=>'文章标题已经存在,不能重复添加']);

}else{

$upldate = newsl::where('news_id',$data['news_id'])->update($data);

if ($update == true) {

return json(['code'=>1,'msg'=>'修改新闻成功']);

}

}

}

}

public function del()

{

$res = Request::param();


$news_id = $res['id'];


if ($res = Newsl::where('news_id',$news_id)->delete()) {

return json(['code'=>1,'msg'=>'修改新闻成功']);

}else{

return json(['code'=>2,'msg'=>'删除新闻成功']);

}

}

}




















J[5LE]T]T0]BI%YA{CRFUGV.png



 ?>


最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送
  • PHP中文网