2023-01-19 02:36:01 +00:00

801 lines
34 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\api\controller;
use app\api\BaseController;
use app\api\middleware\Auth;
use think\facade\Db;
/**
* 综合文章
*/
class Article extends BaseController
{
/**
* 控制器中间件 [不需要鉴权]
* @var array
*/
protected $middleware = [
Auth::class => ['except' => ['index','hot_list','getArticleList','details','indexs'] ]
];
public function index($search = '', $category_id = 1, $page = 1, $is_time = 0, $category_type = 0)
{
$param = get_params();
$screen = $param['screen']??1;
$solve = $param['solve']??1;
$order = $param['order']??1;
$model = Db::table('fa_article');
$where = [
['status', '=', 1],
['category_id', '=', $category_id]
];
//查询升降序
if($order==1){
$orders='desc';
}else{
$orders='asc';
}
if (!$category_id) {
unset($where[1]);
}
//根据个人村id进行查询
if (JWT_UID) {
$find = Db::table('fa_szxc_information_useraddress')->where('user_id', JWT_UID)->find();
if ($find) {
if ($find['auth_range']==1){
$where[] = ['village', '=', $find['village_id']];
}elseif ($find['auth_range']==2){
$where[] = ['township', '=', $find['street_id']];
}elseif ($find['auth_range']==3){
$where[] = ['county', '=', $find['area_id']];
}
}
}
//总条数
$count = $model->where($where)->count();
//当月条数
$month_count = $model->where($where)->whereMonth('view_time')->count();
if ($search != '') {
$where[] = ['title', 'like', '%' . $search . '%'];
}
if ($category_type != 0) {
$where[] = ['category_type', '=', $category_type];
}
//判断筛选查询
if ($screen==2){
foreach ($where as $key =>$value){
$where[$key][0] = 'a.'.$value[0];
}
//查询
$select = Db::table('fa_article')->where($where)->page($page)->limit(20)
->alias('a')
->join('article_vote_side_tables avst',"a.id = avst.article_id and avst.end_time >=".date('Y-m-d'))
->field('a.id,a.title,a.describe,a.user_id,a.view,a.view_time,a.image,a.end_time,a.is_solve,a.is_vote,a.is_nickname,a.video,a.category_type,avst.end_time as die_time')
->order('a.id DESC')
->select()->toArray();
}else if ($screen==3){
foreach ($where as $key =>$value){
$where[$key][0] = 'a.'.$value[0];
}
//查询
$select = Db::table('fa_article')->where($where)->page($page)->limit(20)
->alias('a')
->join('article_vote_side_tables avst',"a.id = avst.article_id and avst.end_time <=".date('Y-m-d'))
->field('a.id,a.title,a.describe,a.user_id,a.view,a.view_time,a.image,a.end_time,a.is_solve,a.is_vote,a.is_nickname,a.video,a.category_type,avst.end_time as die_time')
->order('a.id DESC')->select()->toArray();
}else{
//查询是否解决
if($solve==2){
$where[] = ['is_solve', '=', 0];
}else if($solve==3){
$where[] = ['is_solve', '=', 1];
}
$select = $model->with('user')->where($where)->page($page)->limit(20)
->field('id,title,user_id,view,view_time,image,end_time,is_solve,is_vote,is_nickname,video,category_type,describe')
->order('id',$orders)->select()->toArray();
}
foreach ($select as $key => $value) {
if ($value['is_nickname'] == 1) {
$select[$key]['nickname'] = "匿名人员";
$select[$key]['avatar'] = "";
$select[$key]['user_id'] = 0;
} else {
$select[$key]['nickname'] = Db::table('fa_szxc_information_usermsg')->where('user_id', $value['user_id'])->value('name');
}
//投票处理
if ($value['is_vote'] == 1) {
$article_vote = Db::table('fa_article_vote_side_tables')->where('article_id', $value['id'])->find();
if ($article_vote) {
$data = $article_vote;
$data['agree_percentage'] = 0;
$data['opposition_percentage'] = 0;
$count_vote = $data['agree'] + $data['opposition'] + $data['other'];
if ($count_vote != 0) {
if ($data['agree'] != 0) {
$data['agree_percentage'] = round(($data['agree'] / $count_vote) * 100);
}
if ($data['opposition'] != 0) {
$data['opposition_percentage'] = round(($data['opposition'] / $count_vote) * 100);
}
}
$select[$key]['extend']['vote'] = $data;
}
} else {
$select[$key]['extend'] = [];
}
if ($is_time == 1) {
if ($value['end_time'] < date('Y-m-d H:i:s')) {
if ($value['end_time'] == '0000-00-00 00:00:00') {
$select[$key]['overdue_time'] = '显示错误';
} else {
if($value['is_solve']==1){
$select[$key]['overdue_time'] = 0;
}else{
$cle = time() - strtotime($value['end_time']);
$select[$key]['overdue_time'] = ceil($cle / 3600 / 24);
}
}
} else {
$select[$key]['overdue_time'] = 0;
}
}
if ($category_id == 165) {
if ($value['category_type'] != 0) {
$find = Db::table('fa_category')->where('id', $value['category_type'])->find();
$select[$key]['extend']['category_type_name'] = $find ? $find['name'] . '' : '';
} else {
$select[$key]['extend']['category_type_name'] = '';
}
}
}
$this->apiSuccess('ok', ['list' => $select, 'count' => ['count' => $count, 'month_count' => $month_count]]);
}
/**首页推荐
* @param $category_id
* @param $page
*/
public function hot_list($category_id = 0, $page = 1, $county = 0, $township = 0, $village = 0)
{
$where = [
['status', '=', 1],
];
if (!$category_id) {
unset($where[1]);
}
// 如果登录
if (JWT_UID) {
$find = Db::table('fa_szxc_information_useraddress')->where('user_id', JWT_UID)->find();
if ($find) {
if ($find['auth_range']==1){
$where[] = ['village', '=', $find['village_id']];
}elseif ($find['auth_range']==2){
$where[] = ['township', '=', $find['street_id']];
}elseif ($find['auth_range']==3){
$where[] = ['county', '=', $find['area_id']];
}
}
}
// if ($county != 0) {
// $where[] = ['county', '=', $county];
// }
// if ($township != 0) {
// $where[] = ['township', '=', $township];
// }
// if ($village != 0) {
// $where[] = ['village', '=', $village];
// }
if ($category_id == 0) {
$where[] = ['category_id', 'in', [176, 162, 161, 160, 152]];
$sos = Db::table('fa_article')->where('category_id', 150)->where('status', 1)
->whereTime('view_time','between', [date("H:i:s",strtotime("-5 minute")), date("H:i:s",strtotime("+5 minute"))])
->page($page)->limit(3)
->withAttr('user_info', function ($value, $data) {
$user = Db::table('fa_user')->where('id', $data['user_id'])->field('nickname,avatar')->find();
$user['name'] = Db::table('fa_szxc_information_usermsg')->where('user_id', $data['user_id'])->value('name');
return $user;
})
->withAttr('article_comment', function ($value, $data) {
return Db::table('fa_article_comment')->where([['vote_id','=',$data['id']],['status','=',1]])->count();
})
->withAttr('article_type', function ($value, $data) {
return '一键求救';
})
->field('id,title,user_id,view,view_time,image,end_time,is_solve,is_vote,is_nickname,video,category_id,source')->order('id DESC')
->withAttr('image', function ($value, $data) {
if ($data['image'] != '') {
return explode(',', $data['image']);
}
})
->select()->toArray();
} else {
$where[] = ['category_id', '=', $category_id];
$sos = [];
}
//查询
$mapo[] = [['category_id','=','1'],['status','=','1']];
$select = Db::table('fa_article')->where($where)->whereOr($mapo)->page($page)->limit(20)
->withAttr('user_info', function ($value, $data) {
$user = Db::table('fa_user')->where('id', $data['user_id'])->field('nickname,avatar')->find();
$user['name'] = Db::table('fa_szxc_information_usermsg')->where('user_id', $data['user_id'])->value('name');
return $user;
})
->field('id,title,describe,user_id,view,view_time,image,end_time,is_solve,is_vote,is_nickname,video,category_id')->order('id DESC')
->withAttr('image', function ($value, $data) {
if ($data['image'] != '') {
return explode(',', $data['image']);
}
})
->withAttr('article_comment', function ($value, $data) {
return Db::table('fa_article_comment')->where([['vote_id','=',$data['id']],['status','=',1]])->count();
})
->withAttr('article_type', function ($value, $data) {
if($data['category_id'] == 1){
return '实时信息';
}elseif($data['category_id'] == 176){
return '党务公开';
}elseif($data['category_id'] == 162){
return '议事大厅';
}elseif($data['category_id'] == 161){
return '财务公开';
}elseif($data['category_id'] == 160){
return '村务公开';
}elseif($data['category_id'] == 152){
return '好人好事';
}else{
return '';
}
})
->select()->toArray();
$personal=Db::table('fa_szxc_personal_news')
->withAttr('user_info', function ($value, $data) {
$user = Db::table('fa_user')->where('id', $data['user_id'])->field('nickname,avatar')->find();
$user['name'] = Db::table('fa_szxc_information_usermsg')->where('user_id', $data['user_id'])->value('name');
return $user;
})
->withAttr('image', function ($value, $data) {
if ($data['image'] != '') {
return json_decode($data['image'],true);
}
})
->withAttr('article_comment', function ($value, $data) {
return Db::table('fa_szxc_personal_news_comment')->where([['personal_news_id','=',$data['id']],['status','=',1]])->count();
})
->withAttr('article_type', function ($value, $data) {
return Db::table('fa_category')->where('id', $data['category_id'])->value('name');
})
->withAttr('view_time', function ($value, $data) {
return date('Y-m-d H:i:s', $value);
})
->field('id,id as personal_news_id,content as title,user_id,view,createtime as view_time,images as image,video,category_id')
->limit(5)->order('id desc')->page($page)->select()->toArray();
$i=0;
$personal_count=count($personal);
if ($select && $personal){
foreach($select as $key=>$value){
if ($key!=0 &&$key%2==0 &&$i<$personal_count){
array_splice($select,$key+$i,0,[$personal[$i]]);
++$i;
}
}
}
$this->apiSuccess('ok', ['list' => array_merge($sos, $select)]);
}
/**首页分类列表
* @param $category_id
* @param $page
*/
public function getArticleList($category_id = 0, $page = 1, $type = 1)
{
$model = Db::table('fa_article');
$where = [
['status', '=', 1],
];
//根据个人村id进行查询
if (JWT_UID) {
$find = Db::table('fa_szxc_information_useraddress')->where('user_id', JWT_UID)->find();
if ($find) {
if ($find['auth_range']==1){
$where[] = ['village', '=', $find['village_id']];
}elseif ($find['auth_range']==2){
$where[] = ['township', '=', $find['street_id']];
}elseif ($find['auth_range']==3){
$where[] = ['county', '=', $find['area_id']];
}
}
}
if ($type == 1) {
$where[] = ['category_id', 'in', [162, 161, 160, 152]];
} else {
$where[] = ['category_id', '=', $category_id];
}
//查询
$select = Db::table('fa_article')->where($where)->page($page)->limit(20)
->field('id,title,user_id,view,view_time,image,end_time,is_solve,is_vote,is_nickname,video,category_id')->order('id DESC')
->withAttr('image', function ($value, $data) {
if ($data['image'] != '') {
return explode(',', $data['image']);
}
})
->withAttr('user_info', function ($value, $data) {
$user = Db::table('fa_user')->where('id', $data['user_id'])->field('nickname,avatar')->find();
$user['name'] = Db::table('fa_szxc_information_usermsg')->where('user_id', $data['user_id'])->value('name');
return $user;
})
->withAttr('article_comment', function ($value, $data) {
return Db::table('fa_article_comment')->where([['vote_id','=',$data['id']],['status','=',1]])->count();
})
->withAttr('article_type', function ($value, $data) {
if($data['category_id'] == 176){
return '党务公开';
}elseif($data['category_id'] == 162){
return '议事大厅';
}elseif($data['category_id'] == 161){
return '财务公开';
}elseif($data['category_id'] == 160){
return '村务公开';
}elseif($data['category_id'] == 152){
return '好人好事';
}else{
return '';
}
})
->select()->toArray();
return $this->apiSuccess('ok', ['list' => $select]);
}
/**详情
* @param $id
* @return null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function details($id)
{
// 增加阅读数
// $ip = 'article-details-'.$this->request->ip().'-'.$id;
// $ip_cache = Cache::get($ip);
// if(empty($ip_cache)){
// Cache::set($ip,$id,3600*24);
$map[] =['id','=', $id];
Db::table('fa_article')->where($map)->inc('view','1')->update();
// }
$where = [
['status', '=', 1],
['id', '=', $id]
];
$find = Db::table('fa_article')->where($where)
->withAttr('user_info', function ($data, $value) {
$find['nickname'] = "匿名人员";
$find['mobile'] = "匿名状态无法显示";
$find['gender'] = "匿名状态无法显示";
$find['avatar'] = "";
$find['user_id'] = 0;
$find['count'] = 0;
$find['end_count'] = 0;
$find['overdue_count'] = 0;
if ($value['is_nickname'] == 0) {
$user = Db::table('fa_user')->where('id', $value['user_id'])->field('nickname,avatar,mobile')->find();
if ($user) {
$find = $user;
}
$find['nickname'] = Db::table('fa_szxc_information_usermsg')->where('user_id', $value['user_id'])->value('name');
}
$config_find = Db::table('fa_config')->where('id', 20)->find();
//是否查询提案数
if (in_array($value['category_id'], explode(',', $config_find['value']))) {
//提案总数
$where = [
['category_id', '=', $value['category_id']],
['user_id', '=', $value['user_id']]
];
//处理总数
$whereTwo = [
['category_id', '=', $value['category_id']],
['user_id', '=', $value['user_id']],
['is_solve', '=', 1]
];
$find['count'] = Db::table('fa_article')->where($where)->count();
$find['end_count'] = Db::table('fa_article')->where($whereTwo)->count();
//逾期总数
$where[] = ['is_solve', '=', 0];
$find['overdue_count'] = Db::table('fa_article')->where($where)->whereTime('end_time', '<=', date('Y-m-d H:i:s'))
->count();
$usermsg = Db::table('fa_szxc_information_usermsg')->where('user_id', $value['user_id'])->field('age,address_name,gender,name')->find();
if ($value['is_nickname']==1){
$find['age'] ='匿名状态无法显示';
$find['address'] = '匿名状态无法显示';
$find['gender'] = '匿名状态无法显示';
}else{
$find['age'] = $usermsg?$usermsg['age']:'';
$find['address'] = $usermsg?$usermsg['address_name']:'';
if ($usermsg){
$find['gender'] =$usermsg['gender']==1?'男':'女';
}
$find['nickname'] = $usermsg['name'];
}
$insurance = Db::table('fa_szxc_information_insurance')->where('user_id', $value['user_id'])->field('insurance_type')->find();
if ($insurance) {
$find['insurance_type'] = $insurance['insurance_type'];
} else {
$find['insurance_type'] = "";
}
}
return $find;
})->withAttr('category_type_title', function ($data, $value) {
if ($value['category_type'] != 0) {
$find = Db::table('fa_category')->where('id', $value['category_type'])->find();
return $find['name'];
}
})
->find();
//投票处理
if ($find['is_vote'] == 1) {
$article_vote = Db::table('fa_article_vote_side_tables')->where('article_id', $find['id'])->find();
if ($article_vote) {
$data = $article_vote;
$data['agree_percentage'] = 0;
$data['opposition_percentage'] = 0;
$count_vote = $data['agree'] + $data['opposition'] + $data['other'];
if ($count_vote != 0) {
if ($data['agree'] != 0) {
$data['agree_percentage'] = round(($data['agree'] / $count_vote) * 100);
}
if ($data['opposition'] != 0) {
$data['opposition_percentage'] = round(($data['opposition'] / $count_vote) * 100);
}
}
$find['extend']['vote'] = $data;
}
} else {
$find['extend'] = [];
}
return $this->apiSuccess('ok', $find);
}
public function add()
{
}
/**提交内容
* @return null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function post()
{
$input = get_params();
// $valdate = new ArticleValdate();
// $res = $valdate->check($input);
// if (!$res) {
// return $this->apiError($valdate->getError());
// }
$useraddress = Db::table('fa_szxc_information_useraddress')->where('user_id', JWT_UID)->where('status', 1)->find();
$data = [];
if ($useraddress) {
$data['county'] = $useraddress['area_id'];
$data['township'] = $useraddress['street_id'];
$data['village'] = $useraddress['village_id'];
}
$data['end_time'] = date('Y-m-d H:i:s', strtotime('+1 day'));
$data['view_time'] = date('Y-m-d H:i:s');
$data['user_id'] = JWT_UID;//添加用户的id
$data['category_id'] = $input['category_id'];//大分类id
$data['category_type'] = $input['category_type'];//小分类id
$data['title'] = $input['title'];//标题
$data['is_nickname'] =empty($input['is_nickname'])?0:$input['is_nickname'];//是否匿名
$data['content'] = $input['content'];//内容
$data['describe'] = empty($input['describe'])?'':$input['describe'];//简介
$data['image'] = $input['image'];//封面
$data['is_vote'] =empty($input['is_vote'])?0:$input['is_vote'];//是否投票
if ($input['category_id']==150){
$name=Db::table('fa_szxc_information_usermsg')->where('user_id',JWT_UID)->value('name');
$data['title'] = '来自于'.$name.'的一键求救';
}
$res = Db::table('fa_article')->insertGetId($data);
if ($input['is_vote'] == 1) {
$vote_data = [
'article_id' => $res,
'start_time' => $input['start_time'],
'end_time' => $input['end_time'],
];
Db::table('fa_article_vote_side_tables')->insert($vote_data);
}
if ($res) {
return $this->apiSuccess('添加成功');
} else {
return $this->apiError('添加失败');
}
}
/**获取要编辑的内容
* @param $id
* @return null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function edit($id)
{
$model =Db::table('fa_article');
$find = $model->where('id', $id)->find()->toArray();
if ($find && $find['is_vote'] == 1) {
$data = Db::table('fa_article_vote_side_tables')->where('article_id', $find['id'])->find();
$find['extend']['vote'] = $data;
}
return $this->apiSuccess('ok', $find);
}
/**提交要编辑的内容
* @param $id
* @return null
*/
public function put($id)
{
$input = get_params();
$data = [];
$data['end_time'] = date('Y-m-d H:i:s');
$data['view_time'] = $input['view_time'];
$data['category_type'] = $input['category_type'];//小分类id
$data['title'] = $input['title'];//标题
$data['content'] = $input['content'];//内容
$data['describe'] = empty($input['describe'])?'':$input['describe'];//简介
$data['image'] = $input['image'];//封面
$data['is_vote'] = $input['is_vote'];//是否投票
$input['update_user_id'] = JWT_UID;//更新用户的id
$res = Db::table('fa_article')->where('id', $id)->update($data);
if ($input['is_vote'] == 1) {
$vote_data = [
'start_time' => $input['start_time'],
'end_time' => $input['end_time'],
];
Db::table('fa_article_vote_side_tables')->where('article_id', $id)->update($vote_data);
}
if ($res) {
return $this->apiSuccess('修改成功');
} else {
return $this->apiError('修改失败');
}
}
public function getWorkArticleCount()
{
$model = Db::table('fa_article');
//根据个人村id进行查询
if (JWT_UID) {
$find = Db::table('fa_szxc_information_useraddress')->where('user_id', JWT_UID)->find();
if ($find) {
if ($find['auth_range']==1){
$where[] = ['village', '=', $find['village_id']];
}elseif ($find['auth_range']==2){
$where[] = ['township', '=', $find['street_id']];
}elseif ($find['auth_range']==3){
$where[] = ['county', '=', $find['area_id']];
}
}
}
$is_solve = $model->where('is_solve', 1)->where($where)->count();
$shuqiu = $model->where('is_solve', 0)->where($where)->where('category_id', 'in',[165,150,149,148,147])->whereTime('end_time','>', date('Y-m-d h:i:s'))->count();
$time = $model->where('is_solve', 0)->where($where)->where('category_id', 'in',[165,150,149,148,147])->whereTime('end_time','<=', date('Y-m-d h:i:s'))->count();
$maodun = $model->where('is_solve', 0)->where($where)->where('category_id',147)->count();
$xiejiao = $model->where('is_solve', 0)->where($where)->where('category_id', 148)->count();
$saohei = $model->where('is_solve', 0)->where($where)->where('category_id', 149)->count();
$sos = $model->where('is_solve', 0)->where($where)->where('category_id', 150)->count();
$one_shuqiu = $model->where('is_solve', 0)->where($where)->where('category_id', 165)->count();
$select = [
'solve_count' => $is_solve,
'shuqiu' => $shuqiu,
'time' =>$time,
'one'=>[
'maodun' => $maodun,
'xiejiao' => $xiejiao,
'saohei' => $saohei,
'sos' => $sos,
'shuqiu' => $one_shuqiu,
]
];
return $this->apiSuccess('ok', $select);
}
public function delete($id)
{
$model = Db::table('fa_article');
$res = $model->where('id', $id)->update(['status' => 0]);
if ($res) {
return $this->apiSuccess('删除成功');
} else {
return $this->apiError('删除失败');
}
}
// 服务大厅小红点
public function getMyArticleCount()
{
$model = Db::table('fa_article');
//根据个人id进行查询
$where[] = ['a.user_id','=',JWT_UID];
$where[] = ['b.is_read','=','0'];
//根据个人村id进行查询
if (JWT_UID) {
$find = Db::table('fa_szxc_information_useraddress')->where('user_id', JWT_UID)->find();
if ($find) {
if ($find['auth_range']==1){
$www[] = ['a.village', '=', $find['village_id']];
}elseif ($find['auth_range']==2){
$www[] = ['a.township', '=', $find['street_id']];
}elseif ($find['auth_range']==3){
$www[] = ['a.county', '=', $find['area_id']];
}
}
}
$yishi = $model->alias('a')->join('fa_article_vote_side_tables b','a.id=b.article_id')->where($www)->where('a.category_id',162)->whereTime('b.end_time', '>', date('Y-m-d H:i:s'))->count();
$maodun = $model->alias('a')->join('article_comment b','a.id=b.vote_id')->where('a.is_solve', 1)->where($where)->where('a.category_id',147)->count();
$xiejiao = $model->alias('a')->join('article_comment b','a.id=b.vote_id')->where('a.is_solve', 1)->where($where)->where('a.category_id', 148)->count();
$saohei = $model->alias('a')->join('article_comment b','a.id=b.vote_id')->where('a.is_solve', 1)->where($where)->where('a.category_id', 149)->count();
$sos = $model->alias('a')->join('article_comment b','a.id=b.vote_id')->where('a.is_solve', 1)->where($where)->where('a.category_id', 150)->count();
$one_shuqiu = $model->alias('a')->join('article_comment b','a.id=b.vote_id')->where('a.is_solve', 1)->where($where)->where('a.category_id', 165)->count();
$select = [
'yishi' => $yishi,
'maodun' => $maodun,
'xiejiao' => $xiejiao,
'saohei' => $saohei,
'sos' => $sos,
'shuqiu' => $one_shuqiu,
];
return $this->apiSuccess('ok', $select);
}
public function indexs($search = '', $category_id = 1, $page = 1, $is_time = 0, $category_type = 0)
{
$param = get_params();
$screen = $param['screen']??1;
$solve = $param['solve']??1;
$order = $param['order']??1;
$model = Db::table('fa_article');
$where = [
['status', '=', 1],
['category_id', '=', $category_id]
];
//查询升降序
if($order==1){
$orders='desc';
}else{
$orders='asc';
}
if (!$category_id) {
unset($where[1]);
}
$village_id = get_params('village_id');
if ($village_id) {
$where[] = ['village', '=', $village_id];
}
//总条数
$count = $model->where($where)->count();
//当月条数
$month_count = $model->where($where)->whereMonth('view_time')->count();
if ($search != '') {
$where[] = ['title', 'like', '%' . $search . '%'];
}
if ($category_type != 0) {
$where[] = ['category_type', '=', $category_type];
}
//判断筛选查询
if ($screen==2){
foreach ($where as $key =>$value){
$where[$key][0] = 'a.'.$value[0];
}
//查询
$select = Db::table('fa_article')->where($where)->page($page)->limit(20)
->alias('a')
->join('article_vote_side_tables avst',"a.id = avst.article_id and avst.end_time >=".date('Y-m-d'))
->field('a.id,a.title,a.describe,a.user_id,a.view,a.view_time,a.image,a.end_time,a.is_solve,a.is_vote,a.is_nickname,a.video,a.category_type,avst.end_time as die_time')
->order('a.id DESC')
->select()->toArray();
}else if ($screen==3){
foreach ($where as $key =>$value){
$where[$key][0] = 'a.'.$value[0];
}
//查询
$select = Db::table('fa_article')->where($where)->page($page)->limit(20)
->alias('a')
->join('article_vote_side_tables avst',"a.id = avst.article_id and avst.end_time <=".date('Y-m-d'))
->field('a.id,a.title,a.describe,a.user_id,a.view,a.view_time,a.image,a.end_time,a.is_solve,a.is_vote,a.is_nickname,a.video,a.category_type,avst.end_time as die_time')
->order('a.id DESC')->select()->toArray();
}else{
//查询是否解决
if($solve==2){
$where[] = ['is_solve', '=', 0];
}else if($solve==3){
$where[] = ['is_solve', '=', 1];
}
$select = $model->with('user')->where($where)->page($page)->limit(20)
->field('id,title,user_id,view,view_time,image,end_time,is_solve,is_vote,is_nickname,video,category_type,describe')
->order('id',$orders)->select()->toArray();
}
foreach ($select as $key => $value) {
if ($value['is_nickname'] == 1) {
$select[$key]['nickname'] = "匿名人员";
$select[$key]['avatar'] = "";
$select[$key]['user_id'] = 0;
} else {
$select[$key]['nickname'] = Db::table('fa_szxc_information_usermsg')->where('user_id', $value['user_id'])->value('name');
}
//投票处理
if ($value['is_vote'] == 1) {
$article_vote = Db::table('fa_article_vote_side_tables')->where('article_id', $value['id'])->find();
if ($article_vote) {
$data = $article_vote;
$data['agree_percentage'] = 0;
$data['opposition_percentage'] = 0;
$count_vote = $data['agree'] + $data['opposition'] + $data['other'];
if ($count_vote != 0) {
if ($data['agree'] != 0) {
$data['agree_percentage'] = round(($data['agree'] / $count_vote) * 100);
}
if ($data['opposition'] != 0) {
$data['opposition_percentage'] = round(($data['opposition'] / $count_vote) * 100);
}
}
$select[$key]['extend']['vote'] = $data;
}
} else {
$select[$key]['extend'] = [];
}
if ($is_time == 1) {
if ($value['end_time'] < date('Y-m-d H:i:s')) {
if ($value['end_time'] == '0000-00-00 00:00:00') {
$select[$key]['overdue_time'] = '显示错误';
} else {
if($value['is_solve']==1){
$select[$key]['overdue_time'] = 0;
}else{
$cle = time() - strtotime($value['end_time']);
$select[$key]['overdue_time'] = ceil($cle / 3600 / 24);
}
}
} else {
$select[$key]['overdue_time'] = 0;
}
}
if ($category_id == 165) {
if ($value['category_type'] != 0) {
$find = Db::table('fa_category')->where('id', $value['category_type'])->find();
$select[$key]['extend']['category_type_name'] = $find ? $find['name'] . '' : '';
} else {
$select[$key]['extend']['category_type_name'] = '';
}
}
}
$this->apiSuccess('ok', ['list' => $select, 'count' => ['count' => $count, 'month_count' => $month_count]]);
}
}