Files
zzp-server/app/adminapi/lists/finance/UserFinanceLists.php
2026-01-19 14:19:22 +08:00

161 lines
5.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists\finance;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\finance\UserFinance;
use app\common\model\user\{User,UserRelation,UserRelationAgent};
use app\common\lists\ListsSearchInterface;
/**
* 资金明细列表
* Class UserFinanceLists
* @package app\adminapi\listsfinance
*/
class UserFinanceLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author bd
* @date 2024/01/31 14:07
*/
public function setSearch(): array
{
return [
'=' => [ 'uf.sn', 'uf.frozen', 'uf.change_type'],
];
}
/**
* @notes 搜索条件
* @author 段誉
* @date 2023/2/24 16:08
*/
public function queryWhere()
{
$where = [];
// 用户编号
if (!empty($this->params['user_info'])) {
$where[] = ['u.sn|u.account|u.mobile', '=', $this->params['user_info']];
}
// 下单时间
if (!empty($this->params['start_time']) && !empty($this->params['end_time'])) {
$time = [strtotime($this->params['start_time']), strtotime($this->params['end_time'])];
$where[] = ['uf.create_time', 'between', $time];
}
return $where;
}
/**
* @notes 获取资金明细列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author BD
* @date 2024/03/07 13:10
*/
public function lists(): array
{
$field = 'uf.id,uf.sn,uf.user_id,uf.change_type,uf.action,uf.change_amount,uf.left_amount,uf.source_sn,uf.remark,uf.create_time,uf.thaw_time,uf.frozen';
$field .= ',u.account,u.sn as u_sn,u.mobile,u.country_code';
$where = " 1 = 1 ";
$join_table = "user t";
$join_require = 't.id = uf.user_id';
if(isset($this->params['parent_sn']) && $this->params['parent_sn'] !=""){
$join_table = "user_relation_agent ur";
$join_require = 'uf.user_id = ur.user_id';
$user = User::where(['sn' => $this->params['parent_sn']]) -> findOrEmpty();
$parent_id = 0;
if (!$user->isEmpty()) $parent_id = $user['id'];
$where .= " AND ur.parent_id = $parent_id ";
if(isset($this->params['level']) && $this->params['level'] !=""){
$level = $this->params['level'];
$where .= " AND ur.level = $level ";
}
$field .= ',ur.level';
}
$lists = UserFinance::alias('uf')
->join('user u', 'u.id = uf.user_id')
->join($join_table, $join_require)
->field($field)
->append(['team_top'])
->where($where)
->where($this->queryWhere())
->where($this->searchWhere)
->limit($this->limitOffset, $this->limitLength)
->order(['uf.id' => 'desc'])
->select()
->toArray();
foreach ($lists as &$item) {
if(isset($item['level']) && isset($item['team_top']['level'])){
$item['team_top']['level'] = $item['level'];
}
}
return $lists;
}
/**
* @notes 获取资金明细数量
* @return int
* @author BD
* @date 2024/03/07 13:10
*/
public function count(): int
{
$where = " 1 = 1 ";
$join_table = "user t";
$join_require = 't.id = uf.user_id';
if(isset($this->params['parent_sn']) && $this->params['parent_sn'] !=""){
$join_table = "user_relation_agent ur";
$join_require = 'uf.user_id = ur.user_id';
$user = User::where(['sn' => $this->params['parent_sn']]) -> findOrEmpty();
$parent_id = 0;
if (!$user->isEmpty()) $parent_id = $user['id'];
$where .= " AND ur.parent_id = $parent_id ";
if(isset($this->params['level']) && $this->params['level'] !=""){
$level = $this->params['level'];
$where .= " AND ur.level = $level ";
}
}
return UserFinance::alias('uf')
->join('user u', 'u.id = uf.user_id')
->join($join_table, $join_require)
->where($where)
->where($this->queryWhere())
->where($this->searchWhere)
->count();
}
}