85 lines
3.0 KiB
PHP
85 lines
3.0 KiB
PHP
<?php
|
||
|
||
namespace app\admin\model;
|
||
|
||
use app\common\library\DatabaseRoute;
|
||
use think\facade\Cache;
|
||
use think\facade\Db;
|
||
use think\Model;
|
||
use think\model\relation\BelongsTo;
|
||
|
||
|
||
class SysUserMoneyDetails extends Model
|
||
{
|
||
|
||
public static function queryUserMoneyDetails($page, $limit, $sysUserId, $userId, $classify, $type, $moneyType, $viewType)
|
||
{
|
||
if ($sysUserId !== null) {
|
||
$sysUserId = intval($sysUserId);
|
||
$db = DatabaseRoute::getDb('sys_user_money_details', $sysUserId);
|
||
$total = $db->name('sys_user_money_details')->where('user_id', $sysUserId)->count();
|
||
// 系统用户模式:查询系统用户资金明细
|
||
$list = $db->name('sys_user_money_details')->where('user_id', $sysUserId)
|
||
->order('create_time', 'desc')
|
||
->limit(page($page, $limit), $limit)
|
||
->select()
|
||
->toArray();
|
||
return [
|
||
'list' => $list,
|
||
'totalCount' => $total,
|
||
'totalPage' => (int)ceil($total / $limit),
|
||
'currPage' => $page,
|
||
'pageSize' => $limit,
|
||
];
|
||
}
|
||
if($userId !== null) {
|
||
$db = DatabaseRoute::getDb('user_money_details', $userId)->name('user_money_details');
|
||
$query = $db->where('user_id', $userId);
|
||
if ($classify !== null) {
|
||
$query = $query->where('classify', $classify);
|
||
}
|
||
|
||
if ($type !== null) {
|
||
$query = $query->where('type', $type);
|
||
}
|
||
|
||
if ($moneyType !== null) {
|
||
$query = $query->where('money_type', $moneyType);
|
||
}
|
||
if ($viewType == 1) {
|
||
// 视图类型1:特殊分类(1和6)
|
||
$query = $query->whereIn('classify', [1, 6]);
|
||
}
|
||
$total = $query->count();
|
||
$query = $query->limit(page($page, $limit), $limit)
|
||
->order('create_time', 'desc')
|
||
->select()
|
||
->toArray();
|
||
return [
|
||
'list' => $query,
|
||
'totalCount' => $total,
|
||
'totalPage' => (int)ceil($total / $limit),
|
||
'currPage' => $page,
|
||
'pageSize' => $limit,
|
||
];
|
||
}else {
|
||
return DatabaseRoute::paginateAllDb('user_money_details', function ($query)use($page, $limit, $sysUserId, $userId, $classify, $type, $moneyType, $viewType) {
|
||
if ($classify !== null) {
|
||
$query->where('classify', $classify);
|
||
}
|
||
if ($type !== null) {
|
||
$query->where('type', $type);
|
||
}
|
||
if ($moneyType !== null) {
|
||
$query->where('money_type', $moneyType);
|
||
}
|
||
if ($viewType == 1) {
|
||
// 视图类型1:特殊分类(1和6)
|
||
$query->whereIn('classify', [1, 6]);
|
||
}
|
||
return $query;
|
||
}, $page, $limit);
|
||
}
|
||
}
|
||
|
||
} |