123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\Info;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Http\Request;
- class InfoController extends Controller
- {
- //获取公告信息列表
- public function getInfoList(Request $request){
- $input=$request->all();
- $page_size=$input['page_size'];
- $page_index=$input['page_index'];
- $num = ($page_index - 1) * $page_size;
- $search_name=$input['search_name'];
- $where=[];
- $count=Info::where($where)
- ->count();
- if($count==0){
- $this->error('400001','没有数据');
- }
- $list=Info::where($where)
- ->orderBy('is_top','desc')
- ->orderBy('top_at','desc')
- ->orderBy('created_at', 'desc')
- ->skip($num)->take($page_size)
- ->get();
- if(empty($list)){
- return $this->error('400002','没有获取到数据');
- }
- return $this->success_list($list,'success',$count);
- }
- //添加公告信息
- public function uploadInfo(Request $request){
- $input=$request->all();
- // $data['title']=$input['title'];
- $data['adminid']=Auth::user()->id;
- $data['author']=$input['author'];
- $data['status']=1;
- $data['is_top']=0;// 1表示置顶,0表示不置顶
- $data['contents']=$input['contents'];
- $row=Info::create($data);
- if($row){
- Log::info('管理员:'.Auth::user()->name.'(id='.Auth::user()->id.')添加公告成功,公告id:'.$row->id);
- return $this->success([]);
- }
- return $this->error();
- }
- //截取简介
- function make_excerpt($value, $length = 200)
- {
- $excerpt = trim(preg_replace('/\r\n|\r|\n+/', ' ', strip_tags($value)));
- return str_limit($excerpt, $length);
- }
- //修改公告信息
- public function updateInfo(Request $request){
- $input=$request->all();
- // $data['title']=$input['title'];
- $data['adminid']=Auth::user()->id;
- $data['author']=$input['author'];
- $data['contents']=$input['contents'];
- $row=Info::where('id',$input['id'])->update($data);
- if($row){
- Log::info('管理员:'.Auth::user()->name.'(id='.Auth::user()->id.')修改公告成功,公告id:'.$input['id']);
- return $this->success([]);
- }
- return $this->error();
- }
- /* 公告置顶 */
- public function setInfoTop(Request $request){
- $input=$request->all();
- $info=Info::find($input['id']);
- $info->is_top=($info->is_top=='0')?'1':'0';
- $info->top_at=date("Y-m-d H:i:s");
- $row=$info->save();
- if($row){
- Log::info('管理员:'.Auth::user()->name.'(id='.Auth::user()->id.')置顶公告成功,公告id:'.$input['id']);
- return $this->success([]);
- } else {
- return $this->error();
- }
- }
- /* 公告禁用 */
- public function disableInfo(Request $request){
- $input=$request->all();
- $info=Info::find($input['id']);
- $info->disabled=($info->disabled==0)?1:0;
- $row=$info->save();
- if($row){
- Log::info('管理员:'.Auth::user()->name.'(id='.Auth::user()->id.')禁用公告成功,公告id:'.$input['id']);
- return $this->success([]);
- } else {
- return $this->error();
- }
- }
- //删除社区信息
- public function destoryInfo(Request $request){
- $input=$request->all();
- $info=Info::find($input['id']);
- $row=$info->delete();
- if($row){
- Log::info('管理员:'.Auth::user()->name.'(id='.Auth::user()->id.')删除公告成功,公告id:'.$input['id']);
- return $this->success([]);
- }
- return $this->error();
- }
- }
|