192 lines
5.7 KiB
PHP
192 lines
5.7 KiB
PHP
<?php
|
||
|
||
/**
|
||
* @author Any
|
||
* @description KISS
|
||
* @date 2021年6月29日
|
||
* @version 1.0.0
|
||
*
|
||
* _____LOG_____
|
||
*
|
||
*/
|
||
namespace app\models\common;
|
||
|
||
use app\models\Feedback;
|
||
use app\models\User;
|
||
use app\models\Cat;
|
||
use app\models\Model;
|
||
use app\components\SiteHelper;
|
||
use yii\data\Pagination;
|
||
|
||
class CommonFeedbackListForm extends Model
|
||
{
|
||
public $keywords;
|
||
public $limit;
|
||
public $page;
|
||
|
||
public $user_id;
|
||
public $cx_mch_id;
|
||
public $review_status;
|
||
|
||
public $start_time;
|
||
public $end_time;
|
||
public $time_type;//时间类型:1=反馈时间,2=处理时间
|
||
|
||
public $cat_id;
|
||
|
||
|
||
public function rules()
|
||
{
|
||
return [
|
||
[['keywords'], 'trim'],
|
||
[['keywords'], 'string'],
|
||
[['limit', 'page', 'user_id', 'cx_mch_id', 'review_status', 'time_type', 'cat_id'], 'integer'],
|
||
[['page'], 'default', 'value' => 1],
|
||
[['limit'], 'default', 'value' => 20],
|
||
[['cx_mch_id'], 'required'],
|
||
[['time_type'], 'in', 'range' => [1, 2]],
|
||
[['start_time', 'end_time'], 'safe'],
|
||
[['user_id', ], 'required', 'on' => 'user'],
|
||
];
|
||
}
|
||
|
||
public function search()
|
||
{
|
||
if(!$this->validate()){
|
||
return $this->getModelError();
|
||
}
|
||
$query = Feedback::find()->alias('f')
|
||
->leftJoin(['u' => User::tableName()], 'f.user_id=u.id')
|
||
->where([
|
||
'f.cx_mch_id' => $this->cx_mch_id,
|
||
'f.is_delete' => 0,
|
||
])
|
||
->andWhere([
|
||
'OR',
|
||
['LIKE', 'f.contact', $this->keywords],
|
||
['LIKE', 'f.content', $this->keywords],
|
||
])
|
||
->andFilterWhere([
|
||
'f.user_id' => $this->user_id,
|
||
'f.review_status' => $this->review_status,
|
||
'f.cat_id' => $this->cat_id
|
||
]);
|
||
$query = $this->switchTime($query);
|
||
$query = $query->select('u.nickname,u.avatar_url,f.id,f.cat_id,f.contact,f.content,f.pic_list,f.created_at,f.review_user_id,f.review_status,f.review_time,f.review_comment');
|
||
$count_query = clone $query;
|
||
$count = $count_query->count();
|
||
$pagination = new Pagination(['pageSize' => $this->limit, 'totalCount' => $count, 'page' => $this->page - 1]);
|
||
$list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['f.created_at' => SORT_DESC])->asArray()->all();
|
||
foreach ($list as $index => $item){
|
||
$item['avatar_url'] = SiteHelper::getFullUrl($item['avatar_url']);
|
||
$item['created_at_cn'] = date('Y-m-d H:i:s',$item['created_at']);
|
||
$item['review_time_cn'] = date('Y-m-d H:i:s',$item['review_time']);
|
||
$item['review_status_cn'] = Feedback::getReviewStatus($item['review_status']);
|
||
$item['pic_list'] = $this->fixPicList($item['pic_list']);
|
||
$review_user = $this->getUser($item['review_user_id']);
|
||
$item['review_user_nickname'] = $review_user['nickname'];
|
||
$cat = $this->getCat($item['cat_id']);
|
||
$item['cat_name'] = $cat['name'];
|
||
$list[$index] = $item;
|
||
}
|
||
//是否已经全部加载
|
||
$end_flag = $this->page > $pagination->pageCount ? true : false;
|
||
return [
|
||
'code' => 0,
|
||
'msg' => 'ok',
|
||
'data' => $list,
|
||
'count' => $count,
|
||
'page_size' => $this->limit,
|
||
'page_count' => $pagination->pageCount,
|
||
'page_no' => $this->page,
|
||
'end_flag' => $end_flag
|
||
];
|
||
}
|
||
|
||
private function switchTime($query)
|
||
{
|
||
if($this->time_type == 1){
|
||
if(!empty($this->start_time)){
|
||
$query = $query->andWhere([
|
||
'>=',
|
||
'f.created_at',
|
||
strtotime($this->start_time)
|
||
]);
|
||
}
|
||
if(!empty($this->end_time)){
|
||
$query = $query->andWhere([
|
||
'<=',
|
||
'f.created_at',
|
||
strtotime($this->end_time)
|
||
]);
|
||
}
|
||
}
|
||
if($this->time_type == 2){
|
||
if(!empty($this->start_time)){
|
||
$query = $query->andWhere([
|
||
'>=',
|
||
'f.review_time',
|
||
strtotime($this->start_time)
|
||
]);
|
||
}
|
||
if(!empty($this->end_time)){
|
||
$query = $query->andWhere([
|
||
'<=',
|
||
'f.review_time',
|
||
strtotime($this->end_time)
|
||
]);
|
||
}
|
||
}
|
||
return $query;
|
||
}
|
||
|
||
private function fixPicList($pic_list)
|
||
{
|
||
if(empty($pic_list))
|
||
return [];
|
||
$pic_list = json_decode($pic_list,true);
|
||
if(!is_array($pic_list))
|
||
return [];
|
||
foreach ($pic_list as $index => $pic){
|
||
$pic_list[$index] = SiteHelper::getFullUrl($pic);
|
||
}
|
||
return $pic_list;
|
||
}
|
||
|
||
private function getUser($user_id)
|
||
{
|
||
$user = User::findOne([
|
||
'id' => $user_id,
|
||
]);
|
||
if($user == null){
|
||
return [
|
||
'nickname' => '匿名'
|
||
];
|
||
}
|
||
return [
|
||
'nickname' => $user->nickname,
|
||
];
|
||
}
|
||
|
||
private function getCat($cat_id)
|
||
{
|
||
$cat = Cat::findOne([
|
||
'id' => $cat_id,
|
||
'type' => Cat::TYPE_FEEDBACK,
|
||
'is_delete' => 0,
|
||
]);
|
||
if($cat == null){
|
||
return [
|
||
'id' => 0,
|
||
'name' => '默认'
|
||
];
|
||
}
|
||
return [
|
||
'id' => $cat->id,
|
||
'name' => $cat->name,
|
||
];
|
||
}
|
||
|
||
}
|
||
|