189 lines
6.3 KiB
PHP
189 lines
6.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021年9月30日
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\models\common;
|
|
|
|
use app\components\EncryptHelper;
|
|
use app\components\ExportFile;
|
|
use app\models\RechargeOrder;
|
|
use app\models\RechargeRule;
|
|
use app\models\Model;
|
|
use app\models\User;
|
|
use yii\data\Pagination;
|
|
|
|
class CommonRechargeRuleListForm extends Model
|
|
{
|
|
public $keywords;
|
|
public $limit;
|
|
public $page;
|
|
|
|
public $cx_mch_id;
|
|
public $start_end_date;
|
|
public $is_pay;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['keywords'], 'trim'],
|
|
[['keywords','start_end_date'], 'string'],
|
|
[['limit', 'page', 'cx_mch_id','is_pay'], '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
|
|
];
|
|
}
|
|
|
|
public function searchAll()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
$list = RechargeRule::find()
|
|
->where([
|
|
'cx_mch_id' => $this->cx_mch_id,
|
|
'is_delete' => 0
|
|
])
|
|
->select('id,pay_price,created_at')
|
|
->orderBy(['pay_price' => SORT_ASC])->asArray()->all();
|
|
foreach ($list as $index => $item){
|
|
$item['created_at_cn'] = date('Y-m-d H:i:s',$item['created_at']);
|
|
$list[$index] = $item;
|
|
}
|
|
return [
|
|
'code' => 0,
|
|
'msg' => 'ok',
|
|
'data' => $list,
|
|
];
|
|
}
|
|
|
|
public function order_search()
|
|
{
|
|
$query = RechargeOrder::find()->alias('ro')
|
|
->select('ro.*,u.nickname,u.avatar_url,u.mobile_phone,u.level_id')
|
|
->leftJoin(['u' => User::tableName()],'ro.user_id=u.id')
|
|
->where([
|
|
'ro.is_delete' => 0
|
|
])
|
|
->andFilterWhere([
|
|
'ro.is_pay'=> $this->is_pay,
|
|
])
|
|
->andFilterWhere([
|
|
'OR',
|
|
['like', 'u.mobile_phone', $this->keywords],
|
|
['like', 'u.nickname', $this->keywords],
|
|
]);
|
|
|
|
|
|
if(!empty($this->start_end_date)){
|
|
$start_end_date = explode(' - ',$this->start_end_date);
|
|
$start_time = strtotime($start_end_date[0]);
|
|
$end_time = strtotime($start_end_date[1]);
|
|
$query->andWhere(['>=','ro.created_at',$start_time])->andWhere(['<=','ro.created_at',$end_time]);
|
|
}
|
|
|
|
$count = $query->count();
|
|
$pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]);
|
|
$list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['ro.id' => SORT_DESC])->asArray()->all();
|
|
foreach ($list as $index => $item) {
|
|
$item['is_pay_cn'] = '待支付';
|
|
if ($item['is_pay'] == 1) {
|
|
$item['state_cn'] = '已支付';
|
|
}
|
|
$item['created_at_cn'] = date("Y-m-d H:i", $item['created_at']);
|
|
$item['pay_time_cn'] = empty($item['pay_time']) ? '' : date("Y-m-d H:i", $item['pay_time']);
|
|
$item['mobile_phone'] = EncryptHelper::decryptMobilePhone($item['mobile_phone']);
|
|
$list[$index] = $item;
|
|
}
|
|
$data = [];
|
|
$data['code'] = 0;
|
|
$data['msg'] = 'ok';
|
|
$data['data'] = $list;
|
|
$data['count'] = $count;
|
|
return $data;
|
|
|
|
}
|
|
|
|
public function order_search_export()
|
|
{
|
|
$query = RechargeOrder::find()->alias('ro')
|
|
->select('ro.*,u.nickname,u.avatar_url,u.mobile_phone,u.level_id')
|
|
->leftJoin(['u' => User::tableName()],'ro.user_id=u.id')
|
|
->where([
|
|
'ro.is_delete' => 0
|
|
])
|
|
->andFilterWhere([
|
|
'ro.is_pay'=> $this->is_pay,
|
|
])
|
|
->andFilterWhere([
|
|
'OR',
|
|
['like', 'u.mobile_phone', $this->keywords],
|
|
['like', 'u.nickname', $this->keywords],
|
|
]);
|
|
if(!empty($this->start_end_date)){
|
|
$start_end_date = explode(' - ',$this->start_end_date);
|
|
$start_time = strtotime($start_end_date[0]);
|
|
$end_time = strtotime($start_end_date[1]);
|
|
$query->andWhere(['>=','ro.created_at',$start_time])->andWhere(['<=','ro.created_at',$end_time]);
|
|
}
|
|
$list = $query->asArray()->all();
|
|
foreach ($list as $index => $item) {
|
|
$item['is_pay_cn'] = '待支付';
|
|
if ($item['is_pay'] == 1) {
|
|
$item['is_pay_cn'] = '已支付';
|
|
}
|
|
$item['created_at_cn'] = date("Y-m-d H:i", $item['created_at']);
|
|
$item['pay_time_cn'] = empty($item['pay_time']) ? '' : date("Y-m-d H:i", $item['pay_time']);
|
|
$item['mobile_phone'] = EncryptHelper::decryptMobilePhone($item['mobile_phone']);
|
|
$list[$index] = $item;
|
|
}
|
|
|
|
$fileName = '充值订单'.date('Y年m月d日H时i分').'导出';
|
|
ExportFile::order_search_export($list,$fileName,false);
|
|
}
|
|
}
|
|
|
|
|
|
|