添加:经纪人中心 - 统计明细接口
This commit is contained in:
parent
89b95fb19d
commit
4a0bdf1436
|
|
@ -8,6 +8,7 @@ use app\common\models\Member;
|
|||
use app\common\models\member\MemberChildren;
|
||||
use Yunshop\TeamDividend\models\TeamDividendLevelModel;
|
||||
use Yunshop\WeightValue\models\WeightValue;
|
||||
use Yunshop\WeightValue\models\WeightValueLog;
|
||||
|
||||
class IndexController extends ApiController{
|
||||
/**
|
||||
|
|
@ -32,23 +33,65 @@ class IndexController extends ApiController{
|
|||
// 获取统计信息
|
||||
$data['statistics'] = (new WeightValue())->getStatistics($uid,$teamLevelId);
|
||||
|
||||
|
||||
return $this->successJson('success',$data);
|
||||
}
|
||||
/**
|
||||
* Common: 权重值中心 - 统计信息明细
|
||||
* Author: wu-hui
|
||||
* Time: 2023/10/19 17:35
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getDetails(){
|
||||
// 参数获取
|
||||
$keyName = request()->input('key_name');
|
||||
$uid = \YunShop::app()->getMemberId();
|
||||
$weightValueModel = new WeightValue();
|
||||
$teamLevelId = (int)request()->input('team_level_id');// 经销商等级id
|
||||
// 根据类型获取对应的列表
|
||||
switch($keyName){
|
||||
//直推奖励
|
||||
case 'direct_push_give':
|
||||
$result = $weightValueModel->commissionDetail($uid,0);
|
||||
break;
|
||||
//权重收益
|
||||
case 'weight_income':
|
||||
$result = $weightValueModel->shareholderDividendDetail($uid,$teamLevelId);
|
||||
break;
|
||||
//团队收益
|
||||
case 'team_income':
|
||||
$result = $weightValueModel->teamDividendDetail($uid,$teamLevelId,0);
|
||||
break;
|
||||
//推荐代理
|
||||
case 'recommend_agent':
|
||||
$result = $weightValueModel->commissionDetail($uid,1);
|
||||
break;
|
||||
//平级奖励
|
||||
case 'peer_level_reward':
|
||||
$result = $weightValueModel->teamDividendDetail($uid,$teamLevelId,1);
|
||||
break;
|
||||
//权重值
|
||||
case 'weight_value':
|
||||
$search = [
|
||||
'member_id' => $uid,
|
||||
'team_dividend_agency_level_id' => $teamLevelId
|
||||
];
|
||||
$field = ['id','team_dividend_agency_level_id','change_type','change_quantity','created_at','remark'];
|
||||
$result = (new WeightValueLog)->getList(20,$search,$field);
|
||||
break;
|
||||
//总订单金额&总订单数
|
||||
case 'order_money':
|
||||
case 'order_num':
|
||||
$result = $weightValueModel->orderDetail($uid);
|
||||
break;
|
||||
}
|
||||
|
||||
return $this->successJson('success',[
|
||||
'current_page' => (int)$result['current_page'],
|
||||
'data' => (array)$result['data'],
|
||||
'last_page' => (int)$result['last_page'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -9,8 +9,6 @@ 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;
|
||||
|
|
@ -238,7 +236,10 @@ class WeightValue extends BaseModel{
|
|||
// 循环上级信息 处理每一个用户
|
||||
foreach($parents as $agentKey => $agentInfo){
|
||||
// 判断:当前用户是否已经领取 已领取不可重复领取
|
||||
if(in_array($agentInfo['uid'],$getRecord)) continue;
|
||||
if(in_array($agentInfo['uid'],$getRecord)) {
|
||||
\Log::debug('------经销商升级赠送权重值 - 错误 - 当前用户是否已经领取 ------',$agentInfo['uid']);
|
||||
continue;
|
||||
}
|
||||
// 用户当前持有的权重值
|
||||
$currentAgentHasWeightValue = (float)$parents[$agentKey]['weight_value']['quantity'] ?? 0;
|
||||
// 获取当前用户应得的权重值
|
||||
|
|
@ -261,6 +262,7 @@ class WeightValue extends BaseModel{
|
|||
$parents[$agentKey]['weight_value']['quantity'] = $changeAfter;
|
||||
}
|
||||
}
|
||||
|
||||
// 修改用户权重值变更信息 | 处理权重值变更记录
|
||||
if($changeRecord){
|
||||
$updateWeightValueList = array_column($parents,'weight_value');
|
||||
|
|
@ -413,36 +415,36 @@ class WeightValue extends BaseModel{
|
|||
// 获取权重收益(当前等级相关的股东分红)
|
||||
$weightIncome = ShareholderDividendModel::uniacid()->where('member_id',$uid)->where('team_level',$teamLevelId)->sum('amount');
|
||||
// 团队收益
|
||||
$teamIncomeInfo = $this->getCommissionInfo($uid);
|
||||
$teamIncomeInfo = $this->getTeamDividendInfo($uid,$teamLevelId);
|
||||
// 权重值
|
||||
$weightValue = self::getWeightValueQuantity((int)$uid,(int)$teamLevelId);
|
||||
// 团队订单信息
|
||||
$teamOrderInfo = self::getTeamOrderInfo($uid);
|
||||
$list = [
|
||||
// 下级购买除【升级商品(购买当前商品可以升级到经销商)】外其他商品的 推广奖励(计算分销商奖励)
|
||||
'direct_push_give' => ['title' => '直推奖励','num' => (float)$directPush,'sort' => 1],
|
||||
'direct_push_give' => ['key_name' => 'direct_push_give','title' => '直推奖励','num' => (float)$directPush,'sort' => 1],
|
||||
// 推荐代理 下级购买【升级商品(购买当前商品可以升级到经销商)】的 推广奖励(计算分销商奖励)
|
||||
'recommend_agent' => ['title' => '推荐代理','num' => (float)$recommendAgent,'sort' => 4],
|
||||
'recommend_agent' => ['key_name' => 'recommend_agent','title' => '推荐代理','num' => (float)$recommendAgent,'sort' => 4],
|
||||
// 根据持有权重 在【股东分红】中每周期分红所得金额(仅获取当前等级的权重值分红)
|
||||
'weight_income' => ['title' => '权重收益','num' => (float)$weightIncome,'sort' => 2],
|
||||
'weight_income' => ['key_name' => 'weight_income','title' => '权重收益','num' => (float)$weightIncome,'sort' => 2],
|
||||
// 本人当前持有的 本等级的权重值
|
||||
'weight_value' => ['title' => '权重值','num' => $weightValue,'sort' => 10],
|
||||
'weight_value' => ['key_name' => 'weight_value','title' => '权重值','num' => $weightValue,'sort' => 10],
|
||||
// 本团队所有相关订单的实际支付金额(不包括本人)
|
||||
'order_money' => ['title' => '总订单金额','num' => $teamOrderInfo['total_price'],'sort' => 11],
|
||||
'order_money' => ['key_name' => 'order_money','title' => '总订单金额','num' => $teamOrderInfo['total_price'],'sort' => 11],
|
||||
// 本团队所有相关订单总数 (不包括本人)
|
||||
'order_num' => ['title' => '总订单数','num' => $teamOrderInfo['total'],'sort' => 12],
|
||||
'order_num' => ['key_name' => '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){
|
||||
if((int)$identityType != 1){
|
||||
// 本团队提供的所有推广奖励及其他相关奖励 (不包括本人)
|
||||
$list['team_income'] = ['title' => '团队收益','num' => $teamIncomeInfo['commission'],'sort' => 3];
|
||||
$list['team_income'] = ['key_name' => 'team_income','title' => '团队收益','num' => $teamIncomeInfo['commission'],'sort' => 3];
|
||||
}
|
||||
// 非省公司 追加平级奖励
|
||||
if($identityType != 3){
|
||||
if((int)$identityType != 3){
|
||||
// 平级奖励 本人获得的所有平级奖
|
||||
$list['peer_level_reward'] = ['title' => '平级奖励','num' => $teamIncomeInfo['peer_level_reward'],'sort' => 5];
|
||||
$list['peer_level_reward'] = ['key_name' => 'peer_level_reward','title' => '平级奖励','num' => $teamIncomeInfo['peer_level_reward'],'sort' => 5];
|
||||
}
|
||||
|
||||
// 排序
|
||||
|
|
@ -459,15 +461,11 @@ class WeightValue extends BaseModel{
|
|||
* @return array|false|null
|
||||
*/
|
||||
private function getCommissionGive($uid){
|
||||
$info = DB::table('yz_commission_order_goods')
|
||||
$info = $this->getCommissionModel($uid)
|
||||
->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();
|
||||
|
|
@ -480,15 +478,13 @@ class WeightValue extends BaseModel{
|
|||
* Author: wu-hui
|
||||
* Time: 2023/10/19 10:00
|
||||
* @param $uid
|
||||
* @return array
|
||||
* @param $teamLevelId
|
||||
* @return float[]
|
||||
*/
|
||||
private function getCommissionInfo($uid){
|
||||
private function getTeamDividendInfo($uid,$teamLevelId){
|
||||
// 获取内容
|
||||
$info = TeamDividendModel::uniacid()
|
||||
$info = $this->getTeamDividendModel($uid,$teamLevelId)
|
||||
->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();
|
||||
|
|
@ -530,8 +526,150 @@ class WeightValue extends BaseModel{
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Common: 直推奖励&推荐代理 奖励明细
|
||||
* Author: wu-hui
|
||||
* Time: 2023/10/19 16:17
|
||||
* @param $uid
|
||||
* @param int $commissionType
|
||||
* @return array
|
||||
*/
|
||||
public function commissionDetail($uid,$commissionType = 0){
|
||||
return $this->getCommissionModel($uid)
|
||||
->select([
|
||||
'yz_commission_order_goods.id',
|
||||
'yz_commission_order_goods.name',
|
||||
'yz_commission_order_goods.commission_money',
|
||||
DB::raw('FROM_UNIXTIME(created_at) AS created_at'),
|
||||
])
|
||||
->where('yz_commission_order_goods.commission_type',$commissionType)
|
||||
->groupBy('yz_commission_order_goods.id')
|
||||
->paginate(20)
|
||||
->toArray();
|
||||
}
|
||||
/**
|
||||
* Common: 奖励明细 - 权重收益(股东分红)
|
||||
* Author: wu-hui
|
||||
* Time: 2023/10/19 16:29
|
||||
* @param $uid
|
||||
* @param $teamLevelId
|
||||
* @return mixed
|
||||
*/
|
||||
public function shareholderDividendDetail($uid,$teamLevelId){
|
||||
return ShareholderDividendModel::uniacid()
|
||||
->select(['id','amount','created_at','team_level_name'])
|
||||
->where('member_id',$uid)
|
||||
->where('team_level',$teamLevelId)
|
||||
->paginate(20)
|
||||
->toArray();
|
||||
}
|
||||
/**
|
||||
* Common: 奖励明细 - 团队收益&平级奖励
|
||||
* Author: wu-hui
|
||||
* Time: 2023/10/19 16:47
|
||||
* @param $uid
|
||||
* @param $teamLevelId
|
||||
* @param int $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function teamDividendDetail($uid,$teamLevelId,$type = 0){
|
||||
return $this->getTeamDividendModel($uid,$teamLevelId)
|
||||
->select(['id','dividend_amount','agent_level','created_at','type'])
|
||||
->where('type',$type)
|
||||
->paginate(20)
|
||||
->toArray();
|
||||
}
|
||||
/**
|
||||
* Common: 奖励明细 - 团队订单记录
|
||||
* Author: wu-hui
|
||||
* Time: 2023/10/19 17:10
|
||||
* @param $uid
|
||||
* @return array
|
||||
*/
|
||||
public function orderDetail($uid){
|
||||
$result = [];
|
||||
$subUserIds = MemberChildren::getTeamModel($uid)->pluck('yz_member_children.child_id')->toArray();
|
||||
if(count($subUserIds) > 0){
|
||||
$result = Order::uniacid()
|
||||
->select([
|
||||
'id',
|
||||
'uid',
|
||||
'order_sn',
|
||||
'create_time',
|
||||
'price',
|
||||
'status',
|
||||
])
|
||||
->whereIn('uid',$subUserIds)
|
||||
->where('uid','!=',$uid)
|
||||
->with([
|
||||
'belongsToMember' => function($query){
|
||||
$query->select(['uid','nickname','realname','avatar']);
|
||||
},
|
||||
'orderGoods' => function($query){
|
||||
$query->select(['id','title','thumb','payment_amount','total','order_id']);
|
||||
}
|
||||
])
|
||||
->paginate(20)
|
||||
->toArray();
|
||||
|
||||
|
||||
$result['data'] = array_map(function($item){
|
||||
return [
|
||||
'id' => $item['id'],
|
||||
'uid' => $item['uid'],
|
||||
'order_sn' => $item['order_sn'],
|
||||
'create_time' => $item['create_time'],
|
||||
'price' => $item['price'],
|
||||
'status_name' => $item['status_name'],
|
||||
'member' => $item['belongs_to_member'],
|
||||
'order_goods' => array_map(function($orderGoodsItem){
|
||||
return [
|
||||
'id' => $orderGoodsItem['id'],
|
||||
'title' => $orderGoodsItem['title'],
|
||||
'thumb' => $orderGoodsItem['thumb'],
|
||||
'payment_amount' => $orderGoodsItem['payment_amount'],
|
||||
'total' => $orderGoodsItem['total'],
|
||||
];
|
||||
},$item['order_goods'])
|
||||
];
|
||||
},$result['data']);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Common: 分销商查询model
|
||||
* Author: wu-hui
|
||||
* Time: 2023/10/19 15:54
|
||||
* @param $uid
|
||||
* @return \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
private function getCommissionModel($uid){
|
||||
return DB::table('yz_commission_order_goods')
|
||||
->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);
|
||||
}
|
||||
/**
|
||||
* Common: 经销商查询model
|
||||
* Author: wu-hui
|
||||
* Time: 2023/10/19 16:45
|
||||
* @param $uid
|
||||
* @param $teamLevelId
|
||||
* @return BaseModel
|
||||
*/
|
||||
private function getTeamDividendModel($uid,$teamLevelId){
|
||||
return TeamDividendModel::uniacid()
|
||||
->where('member_id',$uid)
|
||||
->where('agent_level',$teamLevelId)// 已结算
|
||||
->where('status',1)// 已结算
|
||||
->where('settle_money_type',1);// 结算金额类型为 - 收入提现
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Common: 一对一关联 用户信息
|
||||
|
|
|
|||
|
|
@ -61,43 +61,6 @@ class WeightValueLog extends BaseModel{
|
|||
|
||||
return $list ? $list->toArray() : [];
|
||||
}
|
||||
// 获取总数
|
||||
public function getChangeTypeSum($uid,$changeType = -1){
|
||||
$where = [];
|
||||
if($changeType == 0) $where[] = ['change_type','=',0];
|
||||
if($changeType == 1) $where[] = ['change_type','=',1];
|
||||
|
||||
$sum = (float)self::uniacid()->where('member_id',$uid)->where($where)->sum('change_quantity');
|
||||
|
||||
return sprintf("%.2f",$sum);
|
||||
}
|
||||
// 权重值增加|减少操作
|
||||
public function weightValueOperate(int $uid,float $money,int $changeType = 1,string $remark = '',int $type = 0){
|
||||
// 获取当前用户持有数量
|
||||
$changeFront = (float)Member::uniacid()->where('uid',$uid)->value('weight_value');
|
||||
// 变更后的数量
|
||||
$changeAfter = $changeType == 1 ? $changeFront + $money : $changeFront - $money;
|
||||
// 变更记录
|
||||
$data = [
|
||||
'uniacid' => \YunShop::app()->uniacid,
|
||||
'member_id' => $uid,// 用户id
|
||||
'type' => $type,// 权重值类型:0=经纪人(经销商)权重值
|
||||
'goods_id' => 0,// 商品id
|
||||
'order_id' => 0,// 订单id
|
||||
'order_goods_id' => 0,// 订单商品id
|
||||
'change_type' => $changeType,// 变更类型:0=减少,1=增加
|
||||
'change_quantity' => $money,// 变更数量
|
||||
'change_front' => (float)$changeFront,// 变更前拥有的数量
|
||||
'change_after' => sprintf("%.2f",$changeAfter),// 变更后拥有的数量
|
||||
'remark' => $remark,// 备注
|
||||
'created_at' => time(),// 变更时间
|
||||
];
|
||||
$this->insert($data);
|
||||
// 修改用户持有
|
||||
Member::uniacid()->where('uid',$uid)->update([
|
||||
'weight_value' => $changeAfter
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue