parent
3c53f8a4ab
commit
cb1f15ca96
|
|
@ -406,11 +406,14 @@ class ComponentService
|
|||
['name' => '我的拼团', 'mini_url' => '/packageB/member/group/MyGroups/MyGroups', 'url' => 'mygroups', 'plugin_name' => 'fight-groups'],
|
||||
['name' => '帮助中心(旧)', 'mini_url' => '', 'url' => 'member/helpcenter'],
|
||||
['name' => '帮助中心(新)', 'mini_url' => '', 'url' => 'member/new_help/index'],
|
||||
['name' => '典藏室', 'mini_url' => '', 'url' => 'member/collection_room'],
|
||||
['name' => '关于我们', 'mini_url' => '', 'url' => 'member/tool/about_us'],
|
||||
// ['name' => '典藏室', 'mini_url' => '', 'url' => 'member/collection_room'],
|
||||
// ['name' => '关于我们', 'mini_url' => '', 'url' => 'member/tool/about_us'],
|
||||
['name' => '消息中心', 'mini_url' => '', 'url' => 'member/message_center/index'],
|
||||
['name' => '文创豆商城', 'mini_url' => '', 'url' => 'member/legumes/shopping'],
|
||||
['name' => '文创空间管理中心', 'mini_url' => '', 'url' => "member/weight_value_home?i={$uniacid}&content_type=cultural_space&", 'plugin_name' => 'cultural-space','params'=>['type'=>'cultural_space']],
|
||||
// ['name' => '文创豆商城', 'mini_url' => '', 'url' => 'member/legumes/shopping'],
|
||||
// ['name' => '文创空间管理中心', 'mini_url' => '', 'url' => "member/weight_value_home?i={$uniacid}&content_type=cultural_space&", 'plugin_name' => 'cultural-space','params'=>['type'=>'cultural_space']],
|
||||
['name' => '我的收入', 'mini_url' => '', 'url' => 'member/rebate/my_income'],
|
||||
['name' => '返利明细', 'mini_url' => '', 'url' => 'member/rebate/detail'],
|
||||
['name' => '推荐奖励', 'mini_url' => '', 'url' => 'member/rebate/recommend'],
|
||||
];
|
||||
|
||||
$data = static::delNotOpenPlugin($data);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,212 @@
|
|||
<?php
|
||||
|
||||
namespace Yunshop\Rebate\Api;
|
||||
|
||||
use app\common\components\ApiController;
|
||||
use app\common\models\Goods;
|
||||
use app\common\models\Income;
|
||||
use app\common\models\Member;
|
||||
use Yunshop\Rebate\models\Rebate;
|
||||
use Yunshop\TeamDividend\models\TeamDividendAgencyModel;
|
||||
use Yunshop\TeamDividend\models\TeamDividendLevelModel;
|
||||
use Yunshop\TeamDividend\models\TeamDividendModel;
|
||||
|
||||
class IndexController extends ApiController{
|
||||
/**
|
||||
* Common: 我的收入
|
||||
* Author: wu-hui
|
||||
* Time: 2024/03/18 10:58
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function myIncomeStatistics(){
|
||||
$uid = \YunShop::app()->getMemberId();
|
||||
$userInfo = Member::select(['uid','nickname','avatar'])
|
||||
->where('uid',$uid)
|
||||
->with(['hasOneTeamDividend'=>function($query){
|
||||
$query->select(['uid','id','level']);
|
||||
}])
|
||||
->first();
|
||||
if($userInfo) $userInfo = $userInfo->toArray();
|
||||
// 经销商等级
|
||||
$userInfo['level_info'] = TeamDividendLevelModel::select(['id','level_name'])->where('id',$userInfo['has_one_team_dividend']['level'])->first();
|
||||
if($userInfo['level_info']) $userInfo['level_info'] = $userInfo['level_info']->toArray();
|
||||
// 今日收益
|
||||
$startTime = strtotime(date("Y-m-d 00:00:00", time()));
|
||||
$endTime = strtotime(date("Y-m-d 23:59:59",time()));
|
||||
$toDayIncome = TeamDividendModel::where('created_at','>=',$startTime)
|
||||
->where('created_at','<=',$endTime)
|
||||
->where('member_id',$uid)
|
||||
->sum('dividend_amount');
|
||||
// 全部收益
|
||||
$allIncome = TeamDividendModel:: where('member_id',$uid)->sum('dividend_amount');
|
||||
// 可提现
|
||||
$withdrawal = (float)Income::uniacid()
|
||||
->leftjoin('yz_team_dividend','yz_team_dividend.id','=','yz_member_income.incometable_id')
|
||||
->where('yz_member_income.dividend_code', 2)
|
||||
->where('yz_member_income.member_id', $uid)
|
||||
->where('yz_member_income.status', 0)
|
||||
->sum('yz_member_income.amount');
|
||||
// 返利收益
|
||||
$rebate = Rebate::where('uid',$uid)->whereNotIn('status', [3,4])->sum('money');
|
||||
// 推荐奖收益
|
||||
$recommend = TeamDividendModel::uniacid()->where('member_id',$uid)->whereIn('type',[7,8])->sum('dividend_amount');
|
||||
// 平级奖
|
||||
$levelGive = TeamDividendModel::uniacid()->where('member_id',$uid)->where('type',1)->sum('dividend_amount');
|
||||
// 下级总数
|
||||
$subCount = TeamDividendAgencyModel::where('parent_id', $uid)->count();
|
||||
// 复购商品 是否存在消费返利信息 存在继续下一个步骤
|
||||
$goods = [];
|
||||
$rebateGroupMax = Rebate::selectRaw('max(id) as max_id,max(reality_thaw_time) as max_reality_thaw_time,order_id,goods_id,max(status) as status')
|
||||
->where('uid',$uid)
|
||||
->groupBy('order_id','goods_id')
|
||||
->get()
|
||||
->toArray();
|
||||
// 获取最新返利信息
|
||||
if($rebateGroupMax){
|
||||
foreach($rebateGroupMax as $rebateInfo){
|
||||
// 判断:是否失效 未失效则获取最后一次结算时间,已失效则无操作
|
||||
if(!in_array($rebateInfo['status'], [3,4])){
|
||||
// 未失效:最后一次结算时间是否需要复购 需要则判断是否在复购时间内(解冻时间N天内); 在时间内则获取商品信息,不在时间内则失效
|
||||
$lastSettlement = Rebate::where([
|
||||
'order_id' => $rebateInfo['order_id'],
|
||||
'goods_id' => $rebateInfo['goods_id'],
|
||||
'reality_thaw_time' => $rebateInfo['max_reality_thaw_time'],
|
||||
])->first();
|
||||
$isRepurchase = $lastSettlement->is_repurchase ?? 0;
|
||||
if($isRepurchase == 1){
|
||||
$good = Goods::where('id',$rebateInfo['goods_id'])
|
||||
->select(['id','title','thumb'])
|
||||
->first();
|
||||
if($good) {
|
||||
$good->price = $lastSettlement['repurchase_money'];
|
||||
$goods[] = $good->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data = compact('userInfo','toDayIncome','allIncome','withdrawal','rebate','recommend','levelGive','subCount','goods');
|
||||
return $this->successJson('success', $data);
|
||||
}
|
||||
/**
|
||||
* Common: 获取返利明细
|
||||
* Author: wu-hui
|
||||
* Time: 2024/03/18 11:33
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function rebateInfo(){
|
||||
$uid = \YunShop::app()->getMemberId();
|
||||
$statistics = [];
|
||||
$quarterList = [];
|
||||
$realityThawTime = 0;
|
||||
// 获取最新一期内容 存在且未失效
|
||||
$lastRebateMaxId = Rebate::where('uid',$uid)->max('id');
|
||||
$lastRebateInfo = Rebate::where('id',$lastRebateMaxId)->first();
|
||||
if($lastRebateInfo && !in_array($lastRebateInfo->status,[3,4])){
|
||||
$lastRebateInfo = $lastRebateInfo->toArray();
|
||||
// 获取最后结算时间
|
||||
$realityThawTime = Rebate::where([
|
||||
'uid' => $uid,
|
||||
'order_id' => $lastRebateInfo['order_id'],
|
||||
'goods_id' => $lastRebateInfo['goods_id'],
|
||||
])->max('reality_thaw_time');
|
||||
// 统计
|
||||
$statistics['all_balance'] = Rebate::where( 'uid',$uid)->sum('money');// 所有期全部返利金额
|
||||
$statistics['recorded'] = Rebate::where( 'uid',$uid)->where('status', 2)->sum('money');// 所有期 已入账(已结算)金额
|
||||
$statistics['credited'] = Rebate::where( 'uid',$uid)->where('status', 0)->sum('money');// 所有期 待入账(冻结中)金额
|
||||
// 可提现
|
||||
$statistics['withdrawal'] = (float)Income::uniacid()
|
||||
->leftjoin('yz_rebate','yz_rebate.id','=','yz_member_income.incometable_id')
|
||||
->where('yz_member_income.dividend_code', 203)
|
||||
->where('yz_member_income.member_id', $uid)
|
||||
->where('yz_member_income.status', 0)
|
||||
->sum('yz_member_income.amount');
|
||||
// 获取全部返利信息 并且循环处理
|
||||
$monthList = Rebate::select(['id','quarter','month','expect_thaw_time','money','status','is_repurchase','repurchase_money','reality_thaw_time'])
|
||||
->where([
|
||||
'uid' => $uid,
|
||||
'order_id' => $lastRebateInfo['order_id'],
|
||||
'goods_id' => $lastRebateInfo['goods_id'],
|
||||
])
|
||||
->get()
|
||||
->toArray();
|
||||
foreach($monthList as $monthInfo){
|
||||
$quarterList[$monthInfo['quarter']]['quarter'] = (int)$monthInfo['quarter'];
|
||||
$quarterList[$monthInfo['quarter']]['list'][$monthInfo['month']] = $monthInfo;
|
||||
// 复购信息
|
||||
if($quarterList[$monthInfo['quarter']]['is_repurchase'] != 1) {
|
||||
$quarterList[$monthInfo['quarter']]['is_repurchase'] = (int)$monthInfo['is_repurchase'];
|
||||
$quarterList[$monthInfo['quarter']]['repurchase_money'] = (float)$monthInfo['repurchase_money'];
|
||||
}
|
||||
// 返利时间 开始 ~ 结束
|
||||
if($monthInfo['month'] == 1) $quarterList[$monthInfo['quarter']]['start_time'] = date("Y.m", strtotime($monthInfo['expect_thaw_time']));
|
||||
$quarterList[$monthInfo['quarter']]['end_time'] = date("Y.m", strtotime($monthInfo['expect_thaw_time']));
|
||||
// 本季度总金额
|
||||
$quarterList[$monthInfo['quarter']]['total_money'] += (float)$monthInfo['money'];
|
||||
// 本季度是否在结算中 不是结算中 = 最新状态,是结算中 = 状态不变
|
||||
if($quarterList[$monthInfo['quarter']]['status'] != 2) $quarterList[$monthInfo['quarter']]['status'] = (int)$monthInfo['status'];
|
||||
// 当前记录最后一次结算时间
|
||||
$reality_thaw_time = $monthInfo['reality_thaw_time'] ? strtotime($monthInfo['reality_thaw_time']) : 0;
|
||||
if((int)$reality_thaw_time > 0) $quarterList[$monthInfo['quarter']]['last_reality_thaw_time'] = (int)$reality_thaw_time;
|
||||
// 最后一次预计结算时间
|
||||
$quarterList[$monthInfo['quarter']]['last_expect_thaw_time'] = $monthInfo['expect_thaw_time'] ? strtotime($monthInfo['expect_thaw_time']) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->successJson('success',compact('statistics', 'quarterList', 'realityThawTime'));
|
||||
}
|
||||
/**
|
||||
* Common: 推荐奖励 - 统计
|
||||
* Author: wu-hui
|
||||
* Time: 2024/03/16 18:01
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function recommendStatistics(){
|
||||
$uid = \YunShop::app()->getMemberId();
|
||||
// 获取统计信息
|
||||
$data = [
|
||||
'all_income' => TeamDividendModel::uniacid()->where('member_id',$uid)->sum('dividend_amount'),// 全部收益
|
||||
'credited' => TeamDividendModel::uniacid()->where('member_id',$uid)->where('status',2)->sum('dividend_amount'),// 待入账收益
|
||||
'recorded' => TeamDividendModel::uniacid()->where('member_id',$uid)->whereIn('status',[0,1])->sum('dividend_amount'),// 已入账收益
|
||||
// 可提现
|
||||
'withdrawable' => (float)Income::uniacid()
|
||||
->leftjoin('yz_team_dividend','yz_team_dividend.id','=','yz_member_income.incometable_id')
|
||||
->where('yz_member_income.dividend_code', 2)
|
||||
->where('yz_member_income.member_id', $uid)
|
||||
->where('yz_member_income.status', 0)
|
||||
->sum('yz_member_income.amount'),
|
||||
];
|
||||
|
||||
return $this->successJson('success',$data);
|
||||
}
|
||||
/**
|
||||
* Common: 推荐奖励 - 等级统计
|
||||
* Author: wu-hui
|
||||
* Time: 2024/03/18 9:14
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function recommendLvStatistics(){
|
||||
$uid = \YunShop::app()->getMemberId();
|
||||
$levelId = (int)request()->input('level_id');
|
||||
// 获取全部等级
|
||||
$level_list = TeamDividendLevelModel::uniacid()->select(['id','level_name'])->get()->toArray();
|
||||
// 获取登记统计 不存在则使用默认第一个等级
|
||||
$levelId = $levelId <= 0 ? $level_list[0]['id'] : $levelId;
|
||||
$list = TeamDividendModel::where('member_id', $uid)
|
||||
->select(['id','expect_thaw_time','dividend_amount','status','type'])
|
||||
->where('agent_level',$levelId)
|
||||
->get()->each(function($item){
|
||||
$item['expect_thaw_time'] = date("m月d日",$item['expect_thaw_time']);
|
||||
|
||||
return $item;
|
||||
})->toArray();
|
||||
// 统计
|
||||
$all_income = TeamDividendModel::where('member_id', $uid)->where('agent_level',$levelId)->sum('dividend_amount');
|
||||
$credited = TeamDividendModel::where('member_id', $uid)->where('agent_level',$levelId)->sum('dividend_amount');
|
||||
|
||||
|
||||
return $this->successJson('success',compact('level_list','list','all_income','credited'));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue