92 lines
2.6 KiB
PHP
92 lines
2.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-5
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\admin\models\coupon;
|
|
|
|
use app\models\Coupon;
|
|
use app\models\Store;
|
|
use app\models\StoreUser;
|
|
use app\models\User;
|
|
use app\modules\admin\models\AdminModel;
|
|
use yii\data\Pagination;
|
|
|
|
class CouponListForm extends AdminModel
|
|
{
|
|
public $page;
|
|
public $limit;
|
|
|
|
public $keywords;
|
|
public $status;
|
|
public $type;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['keywords',], 'trim'],
|
|
[['keywords',], 'string'],
|
|
[['page', 'limit','status','type'], 'integer'],
|
|
[['page'], 'default', 'value' => 1],
|
|
[['limit'], 'default', 'value' => 20],
|
|
];
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
|
|
$query = Coupon::find()
|
|
->where([
|
|
'is_delete' => 0
|
|
])
|
|
->andFilterWhere([
|
|
'OR',
|
|
['like','title',$this->keywords],
|
|
])->andFilterWhere([
|
|
'type' => $this->type
|
|
]);
|
|
|
|
$count = $query->count();
|
|
$pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]);
|
|
$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",$item['created_at']);
|
|
$item['business'] = date('Y-m-d',$item['start_time']).' - '.date('Y-m-d',$item['end_time']);
|
|
$item['get_business'] = date('Y-m-d',$item['get_start_time']).' - '.date('Y-m-d',$item['get_end_time']);
|
|
if($item['num'] < 0){
|
|
$item['num'] = '不限量';
|
|
}
|
|
$item['store_name_list'] = '';
|
|
if(!empty($item['store_ids'])){
|
|
$store_ids = explode(',',$item['store_ids']);
|
|
$store_ids = array_filter($store_ids);
|
|
$store = Store::find()->where(['id' => $store_ids,'is_delete' => 0])->select('name')->column();
|
|
if(!empty($store)){
|
|
$item['store_name_list'] = implode(',',$store);
|
|
}
|
|
}else{
|
|
$item['store_name_list'] = '全部';
|
|
}
|
|
|
|
$list[$index] = $item;
|
|
}
|
|
$data = [];
|
|
$data['code'] = 0;
|
|
$data['msg'] = 'ok';
|
|
$data['data'] = $list;
|
|
$data['count'] = $count;
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
} |