添加:权重值中心信息获取

This commit is contained in:
wuhui_zzw 2023-10-19 11:43:12 +08:00
parent a2370485f0
commit 24b2c3aa22
6 changed files with 254 additions and 10 deletions

View File

@ -510,14 +510,16 @@ class Member extends BackendModel
}
/**
* 通过id获取用户信息
*
* @param $member_id
* @return mixed
* Common: 通过id获取用户信息
* Author: wu-hui
* Time: 2023/10/18 10:51
* @param $member_id
* @param string[] $field
* @return BaseModel
*/
public static function getMemberById($member_id)
{
public static function getMemberById($member_id,$field = ['*']){
return self::uniacid()
->select($field)
->where('uid', $member_id)
->first();
}
@ -1128,4 +1130,6 @@ class Member extends BackendModel
{
return $this->hasOne(MemberAggregationAppModel::class, 'member_id', 'uid');
}
}

View File

@ -13,11 +13,32 @@ use app\common\models\BaseModel;
use app\common\models\Order;
use Illuminate\Database\Eloquent\Builder;
use app\common\models\Member;
use Illuminate\Support\Facades\DB;
class MemberChildren extends BaseModel
{
public $table = 'yz_member_children';
/**
* Common: 获取我的客户(团队总人数,不包括已删除用户) 查询模型
* Author: wu-hui
* Time: 2023/10/19 10:20
* @param $uid
* @return BaseModel
*/
public static function getTeamModel($uid){
return self::uniacid()
->join('yz_member', function ($join) {
$join->on('yz_member.member_id', '=', 'yz_member_children.child_id')->whereNull('deleted_at');
})
->where('yz_member_children.uniacid',\YunShop::app()->uniacid)
->where('yz_member_children.member_id',$uid);
}
public static function boot()
{
parent::boot();
@ -39,4 +60,6 @@ class MemberChildren extends BaseModel
{
return $this->hasMany(Order::class,'uid','child_id');
}
}

View File

@ -107,7 +107,7 @@ class IndexController extends BaseController{
public function test(){
CollectionRoomModel::addInfo(1,2);
// CollectionRoomModel::addInfo(1,2);

View File

@ -90,6 +90,25 @@
value="{{$dividend->level_name}}"/>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">身份类型</label>
<div class="col-sm-6 col-xs-6">
<div class="input-group">
<label class="radio-inline">
<input type="radio" name="dividend[identity_type]" value="0" @if (empty($dividend->identity_type)) checked @endif> 无特殊身份
</label>
<label class="radio-inline">
<input type="radio" name="dividend[identity_type]" value="1" @if (1 == $dividend->identity_type) checked @endif style="margin: 4px 0 0; position:inherit"> 经纪人
</label>
<label class="radio-inline">
<input type="radio" name="dividend[identity_type]" value="2" @if (2 == $dividend->identity_type) checked @endif style="margin: 4px 0 0; position:inherit"> 代理商
</label>
<label class="radio-inline">
<input type="radio" name="dividend[identity_type]" value="3" @if (3 == $dividend->identity_type) checked @endif style="margin: 4px 0 0; position:inherit"> 省公司
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">等级人数限制</label>
<div class="col-sm-6 col-xs-6">

View File

@ -3,9 +3,51 @@
namespace Yunshop\WeightValue\Api;
use app\common\components\ApiController;
use app\common\models\Income;
use app\common\models\Member;
use app\common\models\member\MemberChildren;
use Yunshop\TeamDividend\models\TeamDividendLevelModel;
use Yunshop\WeightValue\models\WeightValue;
class IndexController extends ApiController{
/**
* Common: 权重值中心 - 信息获取
* Author: wu-hui
* Time: 2023/10/19 10:50
* @return \Illuminate\Http\JsonResponse
*/
public function getCenterData(){
$data = [];
$uid = \YunShop::app()->getMemberId();
$teamLevelId = request()->input('team_level_id');// 经销商等级id
// 获取等级信息
$data['level_name'] = TeamDividendLevelModel::uniacid()->where('id',$teamLevelId)->value('level_name');
// 获取当前用户信息
$user = Member::getMemberById($uid,['uid','nickname','realname','avatar']);
$data['user'] = $user ? $user->toArray() : [];
// 获取可提现金额&团队人数
$data['income'] = (float)Income::uniacid()->where('member_id', $uid)->where('status', 0)->sum('amount');// 可提现金额(仅计算未提现)
$data['total_income'] = (float)Income::uniacid()->where('member_id', $uid)->sum('amount');// 累计收入(包括已提现收入)
$data['team_total'] = MemberChildren::getTeamModel($uid)->count();
// 获取统计信息
$data['statistics'] = (new WeightValue())->getStatistics($uid,$teamLevelId);
return $this->successJson('success',$data);
}

View File

@ -4,11 +4,17 @@ namespace Yunshop\WeightValue\models;
use app\common\models\BaseModel;
use app\common\models\Member;
use app\common\models\member\MemberChildren;
use app\common\models\member\MemberParent;
use app\common\models\Order;
use app\common\models\OrderGoods;
use Illuminate\Support\Facades\DB;
use Yunshop\Commission\Listener\OrderCreatedListener;
use Yunshop\Commission\models\CommissionOrderGoods;
use Yunshop\ShareholderDividend\models\ShareholderDividendModel;
use Yunshop\TeamDividend\models\TeamDividendAgencyModel;
use Yunshop\TeamDividend\models\TeamDividendLevelModel;
use Yunshop\TeamDividend\models\TeamDividendModel;
class WeightValue extends BaseModel{
@ -280,8 +286,6 @@ class WeightValue extends BaseModel{
}
/**
* Common: 修改信息
* 必须是包含member_id、team_dividend_agency_level_id、quantity的二维数组
@ -375,6 +379,158 @@ class WeightValue extends BaseModel{
return [$total,$ratio];
}
/**
* Common: 获取用户当前持有的权重值总数(支持根据经销商等级id获取某个等级的持有权重值)
* Author: wu-hui
* Time: 2023/10/19 10:12
* @param int $uid
* @param int $teamLevelId
* @return string
*/
public static function getWeightValueQuantity(int $uid,int $teamLevelId = 0){
$sumQuantity = self::uniacid()
->where('member_id',$uid)
->when((int)$teamLevelId > 0,function($query) use ($teamLevelId){
$query->where('team_dividend_agency_level_id',$teamLevelId);
})
->sum('quantity');
return sprintf("%.2f",(float)$sumQuantity);
}
/**
* Common: 统计信息 - 全部统计信息获取及处理
* Author: wu-hui
* Time: 2023/10/19 11:11
* @param $uid
* @param $teamLevelId
* @return array[]
*/
public function getStatistics($uid,$teamLevelId){
// 获取相关统计信息
[$directPush,$recommendAgent] = $this->getCommissionGive($uid);
// 获取权重收益(当前等级相关的股东分红)
$weightIncome = ShareholderDividendModel::uniacid()->where('member_id',$uid)->where('team_level',$teamLevelId)->sum('amount');
// 团队收益
$teamIncomeInfo = $this->getCommissionInfo($uid);
// 权重值
$weightValue = self::getWeightValueQuantity($uid,$teamLevelId);
// 团队订单信息
$teamOrderInfo = self::getTeamOrderInfo($uid);
$list = [
// 下级购买除【升级商品(购买当前商品可以升级到经销商)】外其他商品的 推广奖励(计算分销商奖励)
'direct_push_give' => ['title' => '直推奖励','num' => (float)$directPush,'sort' => 1],
// 推荐代理 下级购买【升级商品(购买当前商品可以升级到经销商)】的 推广奖励(计算分销商奖励)
'recommend_agent' => ['title' => '推荐代理','num' => (float)$recommendAgent,'sort' => 4],
// 根据持有权重 在【股东分红】中每周期分红所得金额(仅获取当前等级的权重值分红)
'weight_income' => ['title' => '权重收益','num' => (float)$weightIncome,'sort' => 2],
// 本人当前持有的 本等级的权重值
'weight_value' => ['title' => '权重值','num' => $weightValue,'sort' => 10],
// 本团队所有相关订单的实际支付金额(不包括本人)
'order_money' => ['title' => '总订单金额','num' => $teamOrderInfo['total_price'],'sort' => 11],
// 本团队所有相关订单总数 (不包括本人)
'order_num' => ['title' => '总订单数','num' => $teamOrderInfo['total'],'sort' => 12],
];
// 获取经销商特殊身份 特殊身份0=无特殊身份1=经纪人2=代理商3=省级代理
$identityType = (int)TeamDividendLevelModel::uniacid()->where('id',$teamLevelId)->value('identity_type');
// 非经纪人 追加团队收益
if($identityType != 1){
// 本团队提供的所有推广奖励及其他相关奖励 (不包括本人)
$list['team_income'] = ['title' => '团队收益','num' => $teamIncomeInfo['commission'],'sort' => 3];
}
// 非省公司 追加平级奖励
if($identityType != 3){
// 平级奖励 本人获得的所有平级奖
$list['peer_level_reward'] = ['title' => '平级奖励','num' => $teamIncomeInfo['peer_level_reward'],'sort' => 5];
}
// 排序
$sorts = array_column($list,'sort');
array_multisort($sorts,SORT_ASC,$list);
return $list;
}
/**
* Common: 统计信息 - 分销商相关统计
* Author: wu-hui
* Time: 2023/10/18 16:34
* @param $uid
* @return array|false|null
*/
private function getCommissionGive($uid){
$info = DB::table('yz_commission_order_goods')
->select([
'yz_commission_order_goods.commission_type',
DB::raw("sum(commission_money) as total_money")
])
->join('yz_commission_order', 'yz_commission_order.id', 'yz_commission_order_goods.commission_order_id')
->where('yz_commission_order.uniacid',\YunShop::app()->uniacid)
->where('yz_commission_order.member_id',$uid)
->where('yz_commission_order.status',2)
->groupBy('yz_commission_order_goods.commission_type')
->get()
->toArray();
$moneyInfo = array_column($info,'total_money','commission_type');
return [(float)$moneyInfo[0],(float)$moneyInfo[1]];
}
/**
* Common: 统计信息 - 获取某个经销商提成统计信息(仅统计已结算且结算金额类型为收入的提成信息)
* Author: wu-hui
* Time: 2023/10/19 10:00
* @param $uid
* @return array
*/
private function getCommissionInfo($uid){
// 获取内容
$info = TeamDividendModel::uniacid()
->select(DB::raw('sum(dividend_amount) as total_sum'),'type')
->where('member_id',$uid)
->where('status',1)
->where('settle_money_type',1)
->groupBy('type')
->get()
->toArray();
$infoTypeGroup = array_flip(array_column($info,'type','total_sum'));
// 分红类型 0分红佣金 1平级奖
return [
'total' => (float)array_sum($infoTypeGroup),// 总计 - 已结算收入提成
'commission' => (float)$infoTypeGroup[0],// 分红佣金 - 已结算收入提成
'peer_level_reward' => (float)$infoTypeGroup[1],// 平级奖 - 已结算收入提成
];
}
/**
* Common: 统计信息 - 获取团队订单统计信息(订单总金额、总订单数)
* Author: wu-hui
* Time: 2023/10/19 10:38
* @param $uid
* @return array
*/
private function getTeamOrderInfo($uid){
$orderStatistics = [
'total_price' => 0.00,
'total' => 0,
];
$subUserIds = MemberChildren::getTeamModel($uid)->pluck('yz_member_children.child_id')->toArray();
if(count($subUserIds) > 0){
$orderInfo = Order::uniacid()
->select(DB::raw('sum(price) as total_price,count(id) as total'))
->whereIn('uid',$subUserIds)
->where('uid','!=',$uid)
->first();
$orderStatistics = [
'total_price' => sprintf("%.2f",(float)$orderInfo->total_price),
'total' => (int)$orderInfo->total,
];
}
return $orderStatistics;
}
/**