quanwei
2 days ago 04102f7237efefa744090ed7c25f7b5d0807b679
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?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,
        ];
    }
}