111
liyaozhi
2025-11-09 c13b8914228e6a404bd60ee36bf2479383da8f23
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
 
namespace app\api\service\branch;
 
use app\api\model\branch\Branch as BranchModel;
use app\api\model\branch\Activity as ActivityModel;
use app\api\model\branch\ActivityUser as ActivityUserModel;
use app\api\model\branch\Member as MemberModel;
// use app\api\model\user\Favorite as FavoriteModel;
 
/**
 * 分会模型
 */
class BranchService
{
    // 活动模型
    private $ActivityModel;
    // 分会模型
    private $BranchModel;
    // 会员模型
    private $MemberModel;
    // 活动报名模型
    private $ActivityUserModel;
    // 收藏模型
    // private $FavoriteModel;
    // 分会id
    private $branch_id;
 
    /**
     * 构造方法
     */
    public function __construct($branch_id)
    {
        /* 初始化模型 */
        // $this->FavoriteModel = new FavoriteModel();
        $this->ActivityModel = new ActivityModel();
        $this->BranchModel = new BranchModel();
        $this->MemberModel = new MemberModel();
        $this->ActivityUserModel = new ActivityUserModel();
        $this->branch_id = $branch_id;
    }
 
    /**
     * 后台首页数据
     */
    public function getHomeData()
    {
        $today = date('Y-m-d');
        $yesterday = date('Y-m-d', strtotime('-1 day'));
        $branch = BranchModel::detail($this->branch_id);
        $data = [
            'top_data' => [
                // 活动总量
                'total_activity' => $this->getActivityTotal(null),
                // 会员总量
                'total_member' => $branch['member_num'],
                // 连盟币总数
                'total_points' => $branch['points'],
                // 关注人数
                'total_money' => $branch['total_money'],
                // 分会总数
                'total_branch' => $this->getBranchTotal(),
            ],
            'branch_data' => [
                // 报名费(元)
                'total_price' => [
                    'tday' => $this->getActivityTotalPrice($today),
                    'ytd' => $this->getActivityTotalPrice($yesterday)
                ],
                // 活动报名人数
                'total_activity_user' => [
                    'tday' => $this->getActivityUserTotal($today),
                    'ytd' => $this->getActivityUserTotal($yesterday)
                ],
                // 新会员数
                'total_new_member' => [
                    'tday' => $this->getMemberTotal($today),
                    'ytd' => $this->getMemberTotal($yesterday)
                ],
                // 新活动数
                'total_new_activity' => [
                    'tday' => $this->getActivityTotal($today),
                    'ytd' => $this->getActivityTotal($yesterday)
                ],
                // // 分会关注人数
                // 'fav_user_total' => [
                //     'tday' => $this->getFavUserTotal($today),
                //     'ytd' => $this->getFavUserTotal($yesterday)
                // ]
            ],
            // 待办事项
            'wait_data' => [
                
            ]
        ];
        return $data;
    }
 
    /**
     * 获取活动总量
     */
    private function getActivityTotal($day)
    {
        return number_format($this->ActivityModel->getActivityData($day, null, 'activity_total', $this->branch_id));
    }
 
    /**
     * 获取某天的总报名费
     */
    private function getActivityTotalPrice($day)
    {
        return sprintf('%.2f', $this->ActivityUserModel->getTotalPrice($day, null, $this->branch_id));
    }
 
    /**
     * 获取会员总量
     */
    private function getMemberTotal($day = null)
    {
        return number_format($this->MemberModel->getMemberTotal($day, null, $this->branch_id));
    }
 
    /**
     * 获取报名人数
     */
    private function getActivityUserTotal($day)
    {
        return number_format($this->ActivityUserModel->getUserData($day, null, 'user_total',$this->branch_id));
    }
 
    /**
     * 获取某天的关注用户数
     */
    // private function getFavUserTotal($day)
    // {
    //     return number_format($this->FavoriteModel->getUserTotal($day, $this->branch_id));
    // }
 
    /**
     * 获取分会总数
     */
    private function getBranchTotal() {
        return number_format($this->BranchModel->getBranchTotal($this->branch_id));
    }
}