170 lines
8.1 KiB
PHP
Raw Permalink 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
// +----------------------------------------------------------------------
// | 作者:修缘 联系QQ278896498 QQ群1054861244
// | 声明:未经作者许可,禁止倒卖等商业运营,违者必究
// | 另接php业务网站制作、代理后台、gm后台、支付对接等
// +----------------------------------------------------------------------
// | 创建时间: 2022/1/10 2:20
// +----------------------------------------------------------------------
namespace app\common\model;
use app\admin\model\AgencyUser;
class Index extends Model
{
public static function index_data($user, $son_agency, $directlySon)
{
$data = [
'agency_count' => [
'total' => AgencyUser::progeny($user)->scope('role')->count(),
'already_money' => CheckOut::DirectlySon($directlySon)->whereIn('status', 1)->sum('money'),
'no_money' => AgencyUser::DirectlySon($user)->scope('role')->sum('money'),
'procedure_fee_money' => CheckOut::DirectlySon($directlySon)->whereIn('status', 1)->sum('tax'),
],
'exchange' => [
'today' => CdkRecord::DirectlySon($directlySon)->whereTime('update_time', 'd')->whereIn('status', 1)->sum('money'),
'yesterday' => CdkRecord::DirectlySon($directlySon)->whereTime('update_time', 'yesterday')->whereIn('status', 1)->sum('money'),
'month' => CdkRecord::DirectlySon($directlySon)->whereTime('update_time', 'month')->whereIn('status', 1)->sum('money'),
'last_month' => CdkRecord::DirectlySon($directlySon)->whereTime('update_time', 'last month')->whereIn('status', 1)->sum('money'),
'year' => CdkRecord::DirectlySon($directlySon)->whereTime('update_time', 'year')->whereIn('status', 1)->sum('money'),
'total' => CdkRecord::DirectlySon($directlySon)->whereIn('status', 1)->sum('money'),
],
'account' => [
'today' => User::whereTime('register_time', 'd')->withJoin([
'agency' => function ($query) use ($son_agency) {
$query->whereIn('username', $son_agency);
}
])->count(),
'yesterday' => User::whereTime('register_time', 'yesterday')->withJoin([
'agency' => function ($query) use ($son_agency) {
$query->whereIn('username', $son_agency);
}
])->count(),
'month' => User::whereTime('register_time', 'm')->withJoin([
'agency' => function ($query) use ($son_agency) {
$query->whereIn('username', $son_agency);
}
])->count(),
'last_month' => User::whereTime('register_time', 'last month')->withJoin([
'agency' => function ($query) use ($son_agency) {
$query->whereIn('username', $son_agency);
}
])->count(),
'year' => User::whereTime('register_time', 'year')->withJoin([
'agency' => function ($query) use ($son_agency) {
$query->whereIn('username', $son_agency);
}
])->count(),
'total' => User::withJoin([
'agency' => function ($query) use ($son_agency) {
$query->whereIn('username', $son_agency);
}
])->count(),
],
'player' => [
'today' => Player::whereTime('create_time', 'd')->count(),
'yesterday' => Player::whereTime('create_time', 'yesterday')->count(),
'month' => Player::whereTime('create_time', 'm')->count(),
'last_month' => Player::whereTime('create_time', 'last month')->count(),
'year' => Player::whereTime('create_time', 'year')->count(),
'total' => Player::count(),
]
];
if (in_array(2, $user->role)) {
$data['agency_receive_money'] = CheckOut::whereIn('agency',$user->username)
->whereIn('status', 1)
->sum('money');
$data['agency_commission'] = [
'today_money' => Revenue::whereTime('revenue.create_time', 'd')
->withJoin([
'agency_id' => function ($query) use ($user) {
$query->where(['parent_id' => $user->id]);
},
])->sum('revenue.money'),
'yesterday_money' => Revenue::whereTime('revenue.create_time', 'yesterday')
->withJoin([
'agency_id' => function ($query) use ($user) {
$query->where(['parent_id' => $user->id]);
},
])->sum('revenue.money'),
'month_money' => Revenue::whereTime('revenue.create_time', 'm')
->withJoin([
'agency_id' => function ($query) use ($user) {
$query->where(['parent_id' => $user->id]);
},
])->sum('revenue.money'),
'last_month_money' => Revenue::whereTime('revenue.create_time', 'last month')
->withJoin([
'agency_id' => function ($query) use ($user) {
$query->where(['parent_id' => $user->id]);
},
])->sum('revenue.money'),
'year_money' => Revenue::whereTime('revenue.create_time', 'year')
->withJoin([
'agency_id' => function ($query) use ($user) {
$query->where(['parent_id' => $user->id]);
},
])->sum('revenue.money'),
'total_money' => Revenue::withJoin([
'agency_id' => function ($query) use ($user) {
$query->where(['parent_id' => $user->id]);
},
])->sum('revenue.money'),
];
} else {
$data['agency_commission'] = [
'today_money' => Revenue::whereTime('revenue.create_time', 'd')
->withJoin([
'agency_id' => function ($query) {
$query->where(['parent_id' => 0, 'grandpa_id' => 0]);
},
])->sum('revenue.money'),
'yesterday_money' => Revenue::whereTime('revenue.create_time', 'yesterday')
->withJoin([
'agency_id' => function ($query) {
$query->where(['parent_id' => 0, 'grandpa_id' => 0]);
},
])->sum('revenue.money'),
'month_money' => Revenue::whereTime('revenue.create_time', 'm')
->withJoin([
'agency_id' => function ($query) {
$query->where(['parent_id' => 0, 'grandpa_id' => 0]);
},
])->sum('revenue.money'),
'last_month_money' => Revenue::whereTime('revenue.create_time', 'last month')
->withJoin([
'agency_id' => function ($query) {
$query->where(['parent_id' => 0, 'grandpa_id' => 0]);
},
])->sum('revenue.money'),
'year_money' => Revenue::whereTime('revenue.create_time', 'year')
->withJoin([
'agency_id' => function ($query) {
$query->where(['parent_id' => 0, 'grandpa_id' => 0]);
},
])->sum('revenue.money'),
'total_money' => Revenue::withJoin([
'agency_id' => function ($query) {
$query->where(['parent_id' => 0, 'grandpa_id' => 0]);
},
])->sum('revenue.money'),
];
}
return $data;
}
}