<?php
|
|
namespace app\api\model\plus\vip;
|
|
use app\common\model\plus\vip\User as VipUserModel;
|
|
use app\common\model\plus\vip\Capital as VipCapitalModel;
|
use app\common\model\plus\vip\Order as VipOrderModel;
|
|
/**
|
* VIP专区用户API模型
|
*/
|
class User extends VipUserModel
|
{
|
/**
|
* 隐藏属性
|
* @var array
|
*/
|
protected $hidden = [
|
'app_id',
|
'update_time'
|
];
|
|
/**
|
* 获取VIP专区用户信息
|
* @param $user_id
|
* @return array|null|static
|
* @throws \think\db\exception\DataNotFoundException
|
* @throws \think\db\exception\ModelNotFoundException
|
* @throws \think\exception\DbException
|
*/
|
public static function getDetail($user_id)
|
{
|
return self::detail($user_id, ['user', 'referee', 'grade']);
|
}
|
|
/**
|
* 获取VIP专区统计数据
|
* @param $user_id
|
* @return array
|
*/
|
public static function getStatistics($user_id)
|
{
|
// VIP专区用户信息
|
$vipUser = self::detail($user_id);
|
if (!$vipUser) {
|
return [];
|
}
|
|
// 获取推荐人数
|
$inviteCount = self::where('referee_id', '=', $user_id)->count();
|
|
// 获取未结算订单数
|
$unsettledCount = VipOrderModel::where('vip_area_user_id', '=', $user_id)
|
->where('is_settled', '=', 0)
|
->count();
|
|
// 获取已结算佣金
|
$settledMoney = VipCapitalModel::where('user_id', '=', $user_id)
|
->where('flow_type', '=', 10)
|
->sum('money');
|
|
return [
|
'user' => $vipUser,
|
'invite_count' => $inviteCount,
|
'unsettled_count' => $unsettledCount,
|
'settled_money' => $settledMoney,
|
];
|
}
|
}
|