dlh_test_server/app/admin/logic/withdraw/WithdrawLogic.php
2024-10-14 11:22:32 +08:00

138 lines
4.1 KiB
PHP

<?php
namespace app\admin\logic\withdraw;
use app\admin\controller\withdraw\Withdraw;
use app\common\basics\Logic;
use app\common\enum\WithdrawEnum;
use app\common\model\WithdrawApply;
use app\common\server\UrlServer;
class WithdrawLogic extends Logic
{
public static function Lists($get)
{
$where = [];
// 会员信息
if (!empty($get['search_key']) && !empty($get['keyword'])) {
$keyword = $get['keyword'];
if ($get['search_key'] == 'user_sn') {
$where[] = ['u.sn', '=', $keyword];
} elseif ($get['search_key'] == 'nickname') {
$where[] = ['u.nickname', 'like', '%' . $keyword . '%'];
}
}
//提现单号
if (isset($get['withdraw_sn']) && $get['withdraw_sn'] != '') {
$where[] = ['w.sn', '=', $get['withdraw_sn']];
}
//提现来源
if (isset($get['type']) && $get['type'] != '') {
$where[] = ['w.type', '=', $get['type']];
}
if (isset($get['source']) && $get['source'] != '') {
$where[] = ['w.withdraw_source', '=', $get['source']];
}
// if (empty($get['start_time']) && empty($get['end_time'])) {
// $where[] = ['w.create_time', '>=', strtotime(date("Y-m-d", time()))];
// $where[] = ['w.create_time', '<=', strtotime(date("Y-m-d", time())) + 86399];
// }
// // 提现时间
if (isset($get['start_time']) && $get['start_time'] && isset($get['end_time']) && $get['end_time']) {
$where[] = ['w.create_time', 'between', [strtotime($get['start_time']), strtotime($get['end_time'])]];
}
$lists = WithdrawApply::alias('w')
->field('w.*, u.nickname,u.avatar, u.sn as user_sn, u.mobile')
->with('user')
->leftJoin('user u', 'u.id = w.user_id')
->where($where)
->where('status',3)
->page($get['page'], $get['limit'])
->order('w.id desc')
->select();
$count = WithdrawApply::alias('w')
->field('w.*, u.nickname,u.avatar, u.sn as user_sn, u.mobile')
->with('user')
->leftJoin('user u', 'u.id = w.user_id')
->where($where)
->where('status',3)
->order('w.id desc')
->count();
foreach ($lists as &$item) {
if (empty($item['user'])) {
// 用户不存在
$user = [
'avatar' => '',
'sn' => '-',
'nickname' => '-',
];
} else {
$user = $item['user'];
}
$item['type_text'] = WithdrawEnum::getTypeDesc($item['type']);
$item['status_text'] = WithdrawEnum::getStatusDesc($item['status']);
$item['avatar'] = UrlServer::getFileUrl($item['avatar']);
$user['avatar'] = UrlServer::getFileUrl($user['avatar']);
// 通过中间变量$user解决Indirect modification of overloaded element报错
$item['user'] = $user;
}
return ['count' => $count, 'lists' => $lists];
}
public static function summary(){
$model = new WithdrawApply();
$total_server = $model
->where([
'status' => WithdrawEnum::STATUS_SUCCESS,
])->sum('poundage');
$sales_server = $model
->where([
'status' => WithdrawEnum::STATUS_SUCCESS,
'withdraw_source'=>1
])->sum('poundage');
$sales_server = $model
->where([
'status' => WithdrawEnum::STATUS_SUCCESS,
'withdraw_source'=>1
])->sum('poundage');
$rebate_server = $model
->where([
'status' => WithdrawEnum::STATUS_SUCCESS,
'withdraw_source'=>2
])->sum('poundage');
return array(
'total_server'=>$total_server,
'sales_server'=>$sales_server,
'rebate_server'=>$rebate_server
);
}
}