cxfoot/models/common/CommonRechargeRuleListForm.php
2023-10-24 14:54:18 +08:00

76 lines
2.0 KiB
PHP

<?php
/**
* @author Any
* @description KISS
* @date 2021年9月30日
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\models\common;
use app\models\RechargeRule;
use app\models\Model;
use yii\data\Pagination;
class CommonRechargeRuleListForm extends Model
{
public $keywords;
public $limit;
public $page;
public $cx_mch_id;
public function rules()
{
return [
[['keywords'], 'trim'],
[['keywords'], 'string'],
[['limit', 'page', 'cx_mch_id'], 'integer'],
[['page'], 'default', 'value' => 1],
[['limit'], 'default', 'value' => 20],
[['cx_mch_id'], 'required']
];
}
public function search()
{
if(!$this->validate()){
return $this->getModelError();
}
$query = RechargeRule::find()
->where([
'cx_mch_id' => $this->cx_mch_id,
'is_delete' => 0
])
->andFilterWhere(['LIKE', 'name', $this->keywords])
->select('id,name,pay_price,send_price,created_at');
$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(['created_at' => SORT_DESC])->asArray()->all();
foreach ($list as $index => $item){
$item['created_at_cn'] = date('Y-m-d H:i:s',$item['created_at']);
$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
];
}
}