first commit
This commit is contained in:
137
app/api/logic/TeamLogic.php
Normal file
137
app/api/logic/TeamLogic.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\{UtilsService,ConfigService,FileService};
|
||||
use app\common\model\finance\{UserFinance};
|
||||
use app\common\model\user\{User,UserRelation,UserNotice};
|
||||
use app\common\model\item\{ItemRecord};
|
||||
use think\facade\{Db};
|
||||
|
||||
|
||||
/**
|
||||
* 团队逻辑
|
||||
* Class TeamLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class TeamLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 首页数据
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function getIndexData(array $params)
|
||||
{
|
||||
$todayStart = strtotime("today midnight");
|
||||
|
||||
$distributes = ConfigService::get('website', 'distribute');
|
||||
|
||||
$distributeLevel = UtilsService::get_distribute_level();
|
||||
|
||||
//用户----------------------------------------------------------
|
||||
$user = User::where(['id' => $params['user_id']])
|
||||
->field('id,sn,avatar,total_income')
|
||||
->findOrEmpty();
|
||||
|
||||
$user['teamNum'] = UserRelation::where(['parent_id' => $params['user_id']])->where("level <= $distributeLevel")->count();
|
||||
|
||||
$user['teamNewNum'] = UserRelation::where(['parent_id' => $params['user_id']])->where("level <= $distributeLevel")->where("create_time > $todayStart")->count();
|
||||
|
||||
$user['teamCom'] = UserFinance::where(['user_id' => $params['user_id']])
|
||||
->where(" change_type IN (11) ")
|
||||
->sum('change_amount');
|
||||
|
||||
//分销----------------------------------------------------------
|
||||
foreach ($distributes as &$distribute) {
|
||||
$level = $distribute['level'];
|
||||
$distribute['num'] = UserRelation::where(['parent_id' => $params['user_id'],'level' => $level])->count();
|
||||
}
|
||||
|
||||
return [
|
||||
'user' => $user,
|
||||
'dis_list' => $distributes,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 首页数据2
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function getIndexReport(array $params)
|
||||
{
|
||||
|
||||
$distributeLevel = UtilsService::get_distribute_level();
|
||||
//报表----------------------------------------------------------
|
||||
|
||||
$where = " 1 = 1 ";
|
||||
$where2 = " 1 = 1 ";
|
||||
//0全部1今天2近7天3近30天4近60天
|
||||
switch ($params['time_type']) {
|
||||
case 1:
|
||||
$time = strtotime(date('Y-m-d 00:00:00'));
|
||||
$where = " create_time > $time ";
|
||||
$where2 = " uf.create_time > $time ";
|
||||
break;
|
||||
case 2:
|
||||
$time = strtotime("-7 days midnight");
|
||||
$where = " create_time > $time ";
|
||||
$where2 = " uf.create_time > $time ";
|
||||
break;
|
||||
case 3:
|
||||
$time = strtotime("-30 days midnight");
|
||||
$where = " create_time > $time ";
|
||||
$where2 = " uf.create_time > $time ";
|
||||
break;
|
||||
case 4:
|
||||
$time = strtotime("-60 days midnight");
|
||||
$where = " create_time > $time ";
|
||||
$where2 = " uf.create_time > $time ";
|
||||
break;
|
||||
}
|
||||
|
||||
//我
|
||||
|
||||
// //下级
|
||||
// $report_time['income'] = UserRelation::alias('ur')
|
||||
// ->join('user_finance uf', 'uf.user_id = ur.user_id')
|
||||
// ->where(['ur.parent_id' => $params['user_id']])
|
||||
// ->where(" ur.level <= $distributeLevel AND change_type IN (13) ")
|
||||
// ->where($where2)
|
||||
// ->sum('uf.change_amount');
|
||||
|
||||
// $report_time['income'] = $report_time['income'] + $income_my;
|
||||
|
||||
$report_time['teamNum'] = UserRelation::where(['parent_id' => $params['user_id']])->where("level <= $distributeLevel")->where($where)->count();
|
||||
$report_time['tasks'] = UserFinance::where($where)
|
||||
->where(['user_id' => $params['user_id']])
|
||||
->where(" change_type IN (15) ")
|
||||
->sum('change_amount');
|
||||
$report_time['invest'] = UserFinance::where($where)
|
||||
->where(['user_id' => $params['user_id']])
|
||||
->where(" change_type IN (17) ")
|
||||
->sum('change_amount');
|
||||
$report_time['recom'] = UserFinance::where($where)
|
||||
->where(['user_id' => $params['user_id']])
|
||||
->where(" change_type IN (11) ")
|
||||
->sum('change_amount');
|
||||
|
||||
$report_time['income'] = $report_time['invest'] +$report_time['tasks'] +$report_time['recom'];
|
||||
|
||||
|
||||
return $report_time;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user