<?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));
|
}
|
}
|