cxfoot/models/common/CommonPaymentConfigListForm.php
2023-10-27 14:25:12 +08:00

90 lines
2.7 KiB
PHP

<?php
/**
* @author Any
* @description KISS
* @date 2022年7月12日
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\models\common;
use app\models\PaymentConfig;
use app\models\Model;
use yii\data\Pagination;
use app\models\PaymentTypes;
class CommonPaymentConfigListForm extends Model
{
public $keywords;
public $limit;
public $page;
public $cx_mch_id;
public $status;
public $pay_type;
public function rules()
{
return [
[['keywords', 'pay_type'], 'trim'],
[['keywords', 'pay_type'], 'string'],
[['limit', 'page', 'cx_mch_id', 'status'], 'integer'],
[['page'], 'default', 'value' => 1],
[['limit'], 'default', 'value' => 20],
[['cx_mch_id'], 'required']
];
}
public function search()
{
if(!$this->validate()){
return $this->getModelError();
}
$query = PaymentConfig::find()
->where([
'cx_mch_id' => $this->cx_mch_id,
'is_delete' => 0
])
->andFilterWhere([
'OR',
['LIKE', 'name', $this->keywords],
['LIKE', 'remark', $this->keywords],
])
->andFilterWhere([
'pay_type' => $this->pay_type,
'status' => $this->status
])
->select('id,name,status,remark,pay_type,created_at,updated_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']);
$item['updated_at_cn'] = date('Y-m-d H:i:s',$item['created_at']);
$item['status_cn'] = PaymentConfig::getStatus($item['status']);
$item['pay_type_cn'] = PaymentTypes::getPayType(PaymentTypes::payTypeKeyToId($item['pay_type']));
$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
];
}
}