89 lines
2.5 KiB
PHP
89 lines
2.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-5
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\admin\models\coach;
|
|
use app\components\EncryptHelper;
|
|
use app\models\Coach;
|
|
use app\models\Model;
|
|
use app\models\Store;
|
|
use app\models\User;
|
|
use app\modules\admin\models\AdminModel;
|
|
use yii\data\Pagination;
|
|
|
|
class CoachListForm extends AdminModel
|
|
{
|
|
public $page;
|
|
public $limit;
|
|
|
|
public $keywords;
|
|
public $status;
|
|
public $store_id;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['keywords',], 'trim'],
|
|
[['keywords',], 'string'],
|
|
[['page', 'limit','status','store_id'], 'integer'],
|
|
[['page'], 'default', 'value' => 1],
|
|
[['limit'], 'default', 'value' => 20],
|
|
];
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$query = Coach::find()->alias('c')
|
|
->select('c.*,u.real_name,u.mobile_phone as phone')
|
|
->leftJoin(['u' => User::tableName()],'c.user_id=u.id')
|
|
->where([
|
|
'c.is_delete' => 0
|
|
])
|
|
->andFilterWhere(['c.status' => $this->status])
|
|
->andFilterWhere(['c.store_id' => $this->store_id])
|
|
->andFilterWhere([
|
|
'OR',
|
|
['like','c.mobile_phone',$this->keywords],
|
|
['like','c.title',$this->keywords],
|
|
['like','c.number',$this->keywords],
|
|
['like','u.real_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['store_name'] = '未绑定';
|
|
$store = Store::findOne([
|
|
'id' => $item['store_id'],
|
|
'is_delete' => 0
|
|
]);
|
|
if(!empty($store)){
|
|
$item['store_name'] = $store->name;
|
|
}
|
|
$item['created_at_cn'] = date("Y-m-d H:i",$item['created_at']);
|
|
$item['phone'] = EncryptHelper::decryptMobilePhone($item['phone']);
|
|
$list[$index] = $item;
|
|
}
|
|
$data = [];
|
|
$data['code'] = 0;
|
|
$data['msg'] = 'ok';
|
|
$data['data'] = $list;
|
|
$data['count'] = $count;
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |