WokerTask/app/adminapi/lists/finance/WithdrawLists.php

96 lines
2.9 KiB
PHP
Raw Normal View History

2023-12-27 14:06:33 +08:00
<?php
namespace app\adminapi\lists\finance;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\Company;
use app\common\model\user\UserAccountLog;
use app\common\model\user\Withdraw;
class WithdrawLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 搜索条件
* @return array
* @author 段誉
* @date 2023/2/24 15:26
*/
public function setSearch(): array
{
return [
'=' => ['order_sn','user_id', 'amount', 'status'],
];
}
/**
* @notes 搜索条件
* @author 段誉
* @date 2023/2/24 15:26
*/
public function queryWhere()
{
$where = [];
// 用户余额
return $where;
}
/**
* @notes 获取列表
* @return array
* @author 段誉
* @date 2023/2/24 15:31
*/
public function lists(): array
{
$lists = Withdraw::where($this->searchWhere)
->append(['s_date', 'e_date', 'company_name'], true)
->with('user')
->where($this->queryWhere())
->withAttr('company_name', function ($value, $data) {
$company = Company::where(['admin_id'=>$data['admin_id']])->find();
return $company['company_name']??'';
})
->withAttr('s_date', function ($value, $data) {
$withdrawedCount = Withdraw::where(['user_id'=>$data['user_id'], 'status'=>3])->count();
$company = Company::where(['admin_id'=>$data['admin_id']])->find();
// 开始时间 如果用户第一次提现申请,则以该公司内用户 周期内第一条数据的生成时间为开始时间
if ($withdrawedCount == 0) {
$firstUserLog = UserAccountLog::where(['company_id'=>$company['id']])->order('id', 'asc')->find();
return $firstUserLog['create_time'];
} else {
// 如果用户已成功申请过提现,则以上次提现的截止日期为开始时间
$withdrawedCount = Withdraw::where(['user_id'=>$data['user_id'], 'status'=>3])->order('id', 'desc')->find();
return $withdrawedCount['transfer_end_cycel'];
}
})
->withAttr('e_date', function ($value, $data) {
// 结束时间
return date('Y-m-d H:i:s', $data['transfer_end_cycel']);
})
->order('id', 'desc')
->limit($this->limitOffset, $this->limitLength)
->select()
->toArray();
unset($item);
return $lists;
}
/**
* @notes 获取数量
* @return int
* @author 段誉
* @date 2023/2/24 15:36
*/
public function count(): int
{
return Withdraw::where($this->queryWhere())
->where($this->searchWhere)
->count();
}
}