TaskSystem/app/adminapi/lists/finance/WithdrawLists.php
2023-09-11 19:03:54 +08:00

92 lines
2.7 KiB
PHP

<?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)
->with('user')
->where($this->queryWhere())
->order('id', 'desc')
->limit($this->limitOffset, $this->limitLength)
->select()
->toArray();
// 组装审核时直接跳转到余额明细列表的 开始和结束时间
foreach ($lists as &$item) {
$withdrawedCount = Withdraw::where(['user_id'=>$item['user_id'], 'status'=>3])->count();
$company = Company::where(['admin_id'=>$item['admin_id']])->find();
$item['company_name'] = $company['company_name'];
// 开始时间 如果用户第一次提现申请,则以该公司内用户 周期内第一条数据的生成时间为开始时间
if ($withdrawedCount == 0) {
$firstUserLog = UserAccountLog::where(['company_id'=>$company['id']])->order('id', 'asc')->find();
$item['s_date'] = $firstUserLog['create_time'];
} else {
// 如果用户已成功申请过提现,则以上次提现的截止日期为开始时间
$withdrawedCount = Withdraw::where(['user_id'=>$item['user_id'], 'status'=>3])->order('id', 'desc')->find();
$item['s_date'] = $withdrawedCount['transfer_end_cycel'];
}
// 结束时间
$item['e_date'] = date('Y-m-d H:i:s', $item['transfer_end_cycel']);
}
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();
}
}