85 lines
2.7 KiB
PHP
85 lines
2.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021年6月1日
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\models\common;
|
|
|
|
use app\models\Address;
|
|
use app\models\District;
|
|
use app\models\Model;
|
|
use yii\data\Pagination;
|
|
|
|
class CommonAddressListForm extends Model
|
|
{
|
|
public $keywords;
|
|
public $limit;
|
|
public $page;
|
|
|
|
public $user_id;
|
|
public $cx_mch_id;
|
|
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['keywords'], 'trim'],
|
|
[['keywords'], 'string'],
|
|
[['limit', 'page', 'user_id', 'cx_mch_id'], 'integer'],
|
|
[['page'], 'default', 'value' => 1],
|
|
[['limit'], 'default', 'value' => 20],
|
|
[['user_id', 'cx_mch_id'], 'required']
|
|
];
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$query = Address::find()
|
|
->where([
|
|
'user_id' => $this->user_id,
|
|
'cx_mch_id' => $this->cx_mch_id,
|
|
'is_delete' => 0
|
|
])
|
|
->andFilterWhere([
|
|
'OR',
|
|
['LIKE', 'name', $this->keywords],
|
|
['LIKE', 'mobile', $this->keywords],
|
|
['LIKE', 'detail', $this->keywords],
|
|
])
|
|
->select('id,user_id,name,mobile,province_id,province,city_id,city,district_id,district,town_id,town,detail,lat,lng,is_default,tag,gender,formatted_addr,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(['is_default' => SORT_DESC, '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['tag_cn'] = Address::getTag($item['tag']);
|
|
$item['gender_cn'] = Address::getGender($item['gender']);
|
|
$item['selected'] = $item['is_default'] == 1 ? true : false;
|
|
$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
|
|
];
|
|
}
|
|
}
|
|
|