cxfoot/modules/admin/models/comment/CommentListForm.php
2023-10-24 14:54:18 +08:00

76 lines
2.4 KiB
PHP

<?php
/**
* @author Any
* @description KISS
* @date 2020-11-5
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\modules\admin\models\comment;
use app\components\EncryptHelper;
use app\models\Comment;
use app\models\Model;
use app\models\Store;
use app\models\User;
use app\modules\admin\models\AdminModel;
use yii\data\Pagination;
class CommentListForm extends AdminModel
{
public $page;
public $limit;
public $keywords;
public $store_id;
public function rules()
{
return [
[['keywords',], 'trim'],
[['keywords',], 'string'],
[['page', 'limit','store_id'], 'integer'],
[['page'], 'default', 'value' => 1],
[['limit'], 'default', 'value' => 20],
];
}
public function search()
{
$query = Comment::find()->alias('c')
->select('c.id,c.level,c.content,c.created_at,u.nickname,u.avatar_url,u.mobile_phone,ut.nickname as to_nickname,ut.avatar_url as to_avatar_url,ut.mobile_phone as to_mobile_phone,s.name as store_name')
->leftJoin(['u' => User::tableName()],'c.user_id=u.id')
->leftJoin(['ut' => User::tableName()],'c.to_user_id=ut.id')
->leftJoin(['s' => Store::tableName()],'c.store_id=s.id')
->where(['c.is_delete' => 0])
->andFilterWhere(['c.store_id' => $this->store_id])
->andFilterWhere([
'OR',
['like','u.nickname',$this->keywords],
['like','ut.nickname',$this->keywords],
['like','s.name',$this->keywords],
]);
$count = $query->count();
$pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]);
$list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['c.created_at' => SORT_DESC])->asArray()->all();
foreach ($list as $index => $item){
$item['created_at_cn'] = date("Y-m-d H:i",$item['created_at']);
$item['mobile_phone'] = EncryptHelper::decryptMobilePhone($item['mobile_phone']);
$item['to_mobile_phone'] = EncryptHelper::decryptMobilePhone($item['to_mobile_phone']);
$list[$index] = $item;
}
$data = [];
$data['code'] = 0;
$data['msg'] = 'ok';
$data['data'] = $list;
$data['count'] = $count;
return $data;
}
}