修复:分销商升级条件选择“与”,购买商品升级的条件无效
添加:分销商升级增加直推某个等级人数达到多少升级 添加:分销商升级条件团队消费人数达到多少升级 添加:分销商升级条件增加每条线产生某个等级多少人升级
This commit is contained in:
parent
12f0cc746f
commit
4a64ba37e6
|
|
@ -38,7 +38,16 @@ class MemberChildren extends BaseModel
|
|||
->where('yz_member_children.member_id',$uid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Common: 获取直推查询模型
|
||||
* Author: wu-hui
|
||||
* Time: 2023/12/15 11:52
|
||||
*/
|
||||
public static function getOneLevel($uid){
|
||||
return self::uniacid()
|
||||
->where('level',1)
|
||||
->where('member_id',$uid);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ class UpgrateByOrderJob implements ShouldQueue
|
|||
protected $order;
|
||||
protected $levels;
|
||||
protected $set;
|
||||
protected $methodList = [];
|
||||
|
||||
public function __construct($uid, $self_order_after, $order, $levels, $set)
|
||||
{
|
||||
|
|
@ -40,6 +41,7 @@ class UpgrateByOrderJob implements ShouldQueue
|
|||
// 0 是完成 1 是付款
|
||||
$this->self_order_after = $self_order_after;
|
||||
$this->set = $set;
|
||||
$this->methodList = get_class_methods(new UpgrateConditionsService());
|
||||
// \YunShop::app()->uniacid = $order->uniacid;
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +54,7 @@ class UpgrateByOrderJob implements ShouldQueue
|
|||
// 自己不是分销商 找 上级分销商
|
||||
$one_agent = AgentService::getFirstAgentByUid($this->uid);
|
||||
if (!$one_agent) {
|
||||
\Log::debug('自己不是分销商,上级分销商');
|
||||
// \Log::debug('自己不是分销商,上级分销商');
|
||||
return;
|
||||
}
|
||||
$this->agents($one_agent->member_id);
|
||||
|
|
@ -78,7 +80,7 @@ class UpgrateByOrderJob implements ShouldQueue
|
|||
$culturalLevelWeight = isset($agent->culturalLevel->level) ? $agent->culturalLevel->level : 0;
|
||||
// uid 重新赋值
|
||||
$this->uid = $agent->member_id;
|
||||
\Log::debug('UID['.$this->uid.']要进行升级');
|
||||
\Log::debug('UID['.$this->uid.']要进行升级;'."agent_level_weight={$agent_level_weight}");
|
||||
// file_put_contents(storage_path('logs/Y0914.txt'), print_r('time:'.date('Y-m-d H:i:s').',UID['.$this->uid.']要进行升级'.PHP_EOL,1), FILE_APPEND);
|
||||
// 下一步
|
||||
$this->fecLevels($agent_level_weight,$culturalLevelWeight);
|
||||
|
|
@ -91,21 +93,16 @@ class UpgrateByOrderJob implements ShouldQueue
|
|||
|
||||
private function fecLevels($level_weight,$culturalLevelWeight)
|
||||
{
|
||||
\Log::debug('$level_weight',$level_weight);
|
||||
// \Log::debug('$level_weight',$level_weight);
|
||||
$is_upgrate = true;
|
||||
foreach ($this->levels as $level) {
|
||||
// 当前等级的等级权重 小于等于 分销商等级的等级权重
|
||||
if(($level['level_type'] == 0 && $level['level'] <= $level_weight) || ($level['level_type'] == 1 && $level['level'] <= $culturalLevelWeight)){
|
||||
continue;
|
||||
}
|
||||
// if ($level['level'] <= $level_weight) {
|
||||
// continue;
|
||||
// }
|
||||
// 判断条件
|
||||
$condition = $this->getCondition($level);
|
||||
|
||||
if ($condition) continue;
|
||||
|
||||
// 触发升级条件判断
|
||||
$is_upgrate = $this->upgrateVerdict($level, $is_upgrate);
|
||||
if ($is_upgrate) {
|
||||
|
|
@ -117,8 +114,7 @@ class UpgrateByOrderJob implements ShouldQueue
|
|||
}
|
||||
}
|
||||
|
||||
private function upgrate($level)
|
||||
{
|
||||
private function upgrate($level){
|
||||
// 分销商数据
|
||||
$agentModel = Agents::getAgentByMemberId($this->uid)->first();
|
||||
// 升级
|
||||
|
|
@ -129,7 +125,7 @@ class UpgrateByOrderJob implements ShouldQueue
|
|||
}
|
||||
|
||||
// log
|
||||
// UpgradeService::setLog($agentModel, $level);
|
||||
// UpgradeService::setLog($agentModel, $level);
|
||||
}
|
||||
|
||||
private function upgrateVerdict($level, $is_upgrate){
|
||||
|
|
@ -137,7 +133,7 @@ class UpgrateByOrderJob implements ShouldQueue
|
|||
// 转换字符串格式 [ps:order_count => orderCount]
|
||||
$function_name = Str::camel($upgrateType);
|
||||
// 验证方法是否存在 并 执行
|
||||
if(method_exists(new UpgrateConditionsService(), $function_name)) {
|
||||
if(in_array($function_name, $this->methodList)) {
|
||||
$is_upgrate = UpgrateConditionsService::$function_name($this->uid, $level, $this->order, $level['upgraded']['self_order_after'],$this->self_order_after);
|
||||
// 返回false 跳出循环
|
||||
if (!$is_upgrate) {
|
||||
|
|
@ -153,8 +149,10 @@ class UpgrateByOrderJob implements ShouldQueue
|
|||
$count = count($level['upgraded']);
|
||||
|
||||
$upgraded = $count == 1 ? $level['upgraded']['self_order_after'] :0;
|
||||
return !$level['upgraded'] || $upgraded;
|
||||
|
||||
// 没有升级条件 or 升级条件为:购买指定商品 or 订单状态
|
||||
return (!$level['upgraded'] || $upgraded) || $level['upgraded']['goods'];
|
||||
// return (!$level['upgraded'] || $upgraded) || $level['upgraded']['goods'];
|
||||
// return !$level['upgraded'] || $level['upgraded']['goods'];
|
||||
// todo 我咋觉得没啥用呢
|
||||
// 没有升级条件 or ((升级条件为:购买指定商品 or 自购订单数 or 自购金额) and 订单状态)
|
||||
|
|
|
|||
|
|
@ -30,12 +30,12 @@ class FixController extends BaseController
|
|||
public function test()
|
||||
{
|
||||
|
||||
// $model = Order::find(276);
|
||||
// $model = Order::find(2);
|
||||
// $levels = UpgradeService::getLevelUpgraded();
|
||||
// $set = \Setting::get('plugin.commission');
|
||||
// (new UpgrateByOrderJob($model->uid, 1, $model, $levels, $set))->handle();
|
||||
//
|
||||
// debug("完成")
|
||||
|
||||
debug("完成");
|
||||
//
|
||||
// (new OrderCreatedListener())->handler(Order::find(230995));
|
||||
// dd('ok');
|
||||
|
|
|
|||
|
|
@ -37,6 +37,10 @@ class AgentLevelService
|
|||
$data['team_buy_sum'] = $upgrade['team_buy_sum'];
|
||||
$data['one_or_two'] = $upgrade['one_or_two'];
|
||||
$data['team_performance'] = $upgrade['team_performance'];
|
||||
$data['one_level_count'] = $upgrade['one_level_count'];
|
||||
$data['each_line_lv'] = $upgrade['each_line_lv'];
|
||||
$data['team_consumption_people'] = $upgrade['team_consumption_people'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
@ -54,19 +58,45 @@ class AgentLevelService
|
|||
if ($upgradeValue[$key]) {
|
||||
$upgrades[$key] = $upgradeValue[$key];
|
||||
}
|
||||
if ($key == 'buy_and_sum' && intval($upgradeValue['buy']) && intval($upgradeValue['sum'])) {
|
||||
$upgrades[$key]['buy'] = intval($upgradeValue['buy']);
|
||||
$upgrades[$key]['sum'] = intval($upgradeValue['sum']);
|
||||
}
|
||||
if ($key == 'team_buy_sum' && intval($upgradeValue['team_buy']) && intval($upgradeValue['team_sum'])) {
|
||||
$upgrades[$key]['team_buy'] = intval($upgradeValue['team_buy']);
|
||||
$upgrades[$key]['team_sum'] = intval($upgradeValue['team_sum']);
|
||||
}
|
||||
if ($key == 'one_or_two' && intval($upgradeValue['one_or_two'])) {
|
||||
$upgrades[$key] = $upgradeValue['one_or_two'];
|
||||
}
|
||||
if ($key == 'team_performance' && intval($upgradeValue['team_performance'])) {
|
||||
$upgrades[$key] = $upgradeValue['team_performance'];
|
||||
// 其他处理
|
||||
switch($key){
|
||||
case 'buy_and_sum':
|
||||
if(intval($upgradeValue['buy']) && intval($upgradeValue['sum'])){
|
||||
$upgrades[$key]['buy'] = intval($upgradeValue['buy']);
|
||||
$upgrades[$key]['sum'] = intval($upgradeValue['sum']);
|
||||
}
|
||||
break;
|
||||
case 'team_buy_sum':
|
||||
if(intval($upgradeValue['team_buy']) && intval($upgradeValue['team_sum'])){
|
||||
$upgrades[$key]['team_buy'] = intval($upgradeValue['team_buy']);
|
||||
$upgrades[$key]['team_sum'] = intval($upgradeValue['team_sum']);
|
||||
}
|
||||
break;
|
||||
case 'one_or_two':
|
||||
if(intval($upgradeValue['one_or_two'])){
|
||||
$upgrades[$key] = $upgradeValue['one_or_two'];
|
||||
}
|
||||
break;
|
||||
case 'team_performance':
|
||||
if(intval($upgradeValue['team_performance'])){
|
||||
$upgrades[$key] = $upgradeValue['team_performance'];
|
||||
}
|
||||
break;
|
||||
case 'one_level_count':
|
||||
if(intval($upgradeValue['one_level_count'])){
|
||||
$upgrades[$key] = $upgradeValue['one_level_count'];
|
||||
}
|
||||
break;
|
||||
case 'each_line_lv':
|
||||
if(intval($upgradeValue['each_line_lv'])){
|
||||
$upgrades[$key] = $upgradeValue['each_line_lv'];
|
||||
}
|
||||
break;
|
||||
case 'team_consumption_people':
|
||||
if(intval($upgradeValue['team_consumption_people'])){
|
||||
$upgrades[$key] = $upgradeValue['team_consumption_people'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -94,21 +124,43 @@ class AgentLevelService
|
|||
$level->goods = Goods::getGoodsById($value);
|
||||
}
|
||||
}
|
||||
if ($type == 'buy_and_sum') {
|
||||
$upgrades['buy_and_sum']['type'] = '一级客户消费满'.$upgrade['buy_and_sum']['buy'].'元人数达到'.$upgrade['buy_and_sum']['sum'].'个';
|
||||
}
|
||||
if ($type == 'team_buy_sum') {
|
||||
$upgrades['team_buy_sum']['type'] = '团队下级购买指定商品ID'.$upgrade['team_buy_sum']['team_buy'].'满'.$upgrade['team_buy_sum']['team_sum'].'个';
|
||||
}
|
||||
if ($type == 'one_or_two') {
|
||||
$levelId = $upgrade['one_or_two']['one_or_two_level_id'];
|
||||
$lvName = AgentLevel::uniacid()->where('id',$levelId)->value('name');
|
||||
$upgrades['one_or_two']['type'] = '直推间推'.$lvName.'满'.$upgrade['one_or_two']['one_or_two_people'].'人';
|
||||
}
|
||||
if ($type == 'team_performance') {
|
||||
$upgrades['team_performance']['type'] = "团队业绩满{$upgrade['team_performance']['team_performance_total']}元";
|
||||
if($upgrade['team_performance']['team_performance_close_max']) $upgrades['team_performance']['type'] .= ';去除最大业绩最大的线';
|
||||
// 其他处理
|
||||
switch($type){
|
||||
case 'buy_and_sum':
|
||||
$upgrades['buy_and_sum']['type'] = '一级客户消费满'.$upgrade['buy_and_sum']['buy'].'元人数达到'.$upgrade['buy_and_sum']['sum'].'个';
|
||||
break;
|
||||
case 'team_buy_sum':
|
||||
$upgrades['team_buy_sum']['type'] = '团队下级购买指定商品ID'.$upgrade['team_buy_sum']['team_buy'].'满'.$upgrade['team_buy_sum']['team_sum'].'个';
|
||||
break;
|
||||
case 'one_or_two':
|
||||
$levelId = $upgrade['one_or_two']['one_or_two_level_id'];
|
||||
$lvName = AgentLevel::uniacid()->where('id',$levelId)->value('name');
|
||||
$upgrades['one_or_two']['type'] = '直推间推'.$lvName.'满'.$upgrade['one_or_two']['one_or_two_people'].'人';
|
||||
break;
|
||||
case 'team_performance':
|
||||
$upgrades['team_performance']['type'] = "团队业绩满{$upgrade['team_performance']['team_performance_total']}元";
|
||||
if($upgrade['team_performance']['team_performance_close_max']) $upgrades['team_performance']['type'] .= ';去除最大业绩最大的线';
|
||||
break;
|
||||
case 'one_level_count':
|
||||
$levelId = $upgrade['one_level_count']['one_level_count_level_id'];
|
||||
$lvName = AgentLevel::uniacid()->where('id',$levelId)->value('name');
|
||||
$upgrades['one_level_count']['type'] = '直推 '.$lvName.' 满 '.$upgrade['one_level_count']['one_level_count_people'].' 人';
|
||||
if($upgrade['one_level_count']['one_level_count_history']) $upgrades['one_level_count']['type'] .= ';计算历史人数';
|
||||
break;
|
||||
case 'each_line_lv':
|
||||
$levelId = $upgrade['each_line_lv']['each_line_lv_level_id'];
|
||||
$lvName = AgentLevel::uniacid()->where('id',$levelId)->value('name');
|
||||
$upgrades['each_line_lv']['type'] = '直推间推 '.$lvName.' 每条线满 '.$upgrade['each_line_lv']['each_line_lv_people'].' 人';
|
||||
if($upgrade['each_line_lv']['each_line_lv_history']) $upgrades['each_line_lv']['type'] .= ';计算历史人数';
|
||||
break;
|
||||
case 'team_consumption_people':
|
||||
$upgrades['team_consumption_people']['type'] = "团队消费人数满{$upgrade['team_consumption_people']['team_consumption_people_total']}人";
|
||||
if($upgrade['team_consumption_people']['team_consumption_people_close_max']) $upgrades['team_consumption_people']['type'] .= ';去除人数最多的线';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
$level->upgrades = $upgrades;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1039,7 +1039,7 @@ class UpgradeService{
|
|||
}
|
||||
|
||||
$member = YzMember::getMemberByMemberId($memberId)->first();
|
||||
\Log::debug("监听hasOneFans", [$member->hasOneFans, $member]);
|
||||
// \Log::debug("监听hasOneFans", [$member->hasOneFans, $member]);
|
||||
if ($member->hasOneFans) {
|
||||
$noticeData = [
|
||||
'newLevel' => $newLevel,
|
||||
|
|
@ -1048,7 +1048,7 @@ class UpgradeService{
|
|||
];
|
||||
MessageService::upgrade($noticeData);
|
||||
}
|
||||
\Log::debug("监听分销升级", [$level['id'], $memberId]);
|
||||
\Log::debug("监听分销升级", ['new_level_id'=>$level['id'], 'member_id'=>$memberId]);
|
||||
Agents::updatedLevelByMemberId($level['id'], $memberId);
|
||||
UpgradeService::setLog($agent, $newLevel);
|
||||
$pluginLevel = [
|
||||
|
|
@ -1059,7 +1059,7 @@ class UpgradeService{
|
|||
/**
|
||||
* 会员等级同步
|
||||
*/
|
||||
event(new \app\common\events\PluginLevelEvent($pluginLevel));
|
||||
$res = event(new \app\common\events\PluginLevelEvent($pluginLevel));
|
||||
//招商中心是否可以升级
|
||||
// CenterUpgradeService::handle($memberId);
|
||||
if (app('plugins')->isEnabled('merchant')) {
|
||||
|
|
@ -1094,6 +1094,11 @@ class UpgradeService{
|
|||
'self_love_after_black' => '移出黑名单后累计获得自购赠送冻结' . (defined(LOVE_NAME) ? LOVE_NAME : '爱心值') . '满' . $data['self_love_after_black'],
|
||||
'one_or_two' => "直推间推某个等级满{$data['one_or_two']['one_or_two_people']}人",
|
||||
'team_performance' => "团队业绩满{$data['team_performance']['team_performance_total']}元" . ($data['team_performance']['team_performance_close_max'] == 1 ? ';去除最大的那条线' : ''),
|
||||
'goods' => "购买指定商品",
|
||||
'many_good' => "购买指定商品之一",
|
||||
'one_level_count' => "直推某个等级满{$data['one_level_count']['one_level_count_people']}人",
|
||||
'each_line_lv' => "直推间推某个等级每条线满{$data['each_line_lv']['each_line_lv_people']}人",
|
||||
'team_consumption_people' => "团队消费用户满{$data['team_consumption_people']['team_consumption_people_total']}人" . ($data['team_consumption_people']['team_consumption_people_close_max'] == 1 ? ';去除人数最多的线' : ''),
|
||||
];
|
||||
|
||||
$remark = '[与]';
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ namespace Yunshop\Commission\services;
|
|||
|
||||
|
||||
use app\common\models\member\ChildrenOfMember;
|
||||
use app\common\models\member\MemberChildren;
|
||||
use app\common\models\member\MemberParent;
|
||||
use app\common\models\Order;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
|
@ -140,7 +141,7 @@ class UpgrateConditionsService
|
|||
\YunShop::app()->uniacid = $order_model->uniacid;
|
||||
\Setting::$uniqueAccountId = $order_model->uniacid;
|
||||
$set = \Setting::get('plugin.commission');
|
||||
if (!$set['is_with']) {
|
||||
// if (!$set['is_with']) {
|
||||
if (!$order_model) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -156,30 +157,29 @@ class UpgrateConditionsService
|
|||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
// 购买指定商品之一
|
||||
// public static function manyGood($uid, $level_model, $order_model, $self_order_after)
|
||||
// {
|
||||
// \YunShop::app()->uniacid = $order_model->uniacid;
|
||||
// \Setting::$uniqueAccountId = $order_model->uniacid;
|
||||
// if (!$order_model) {
|
||||
// return false;
|
||||
// }
|
||||
// // 订单商品
|
||||
// foreach ($order_model->hasManyOrderGoods as $order_goods) {
|
||||
// // 等级是否设置购买指定商品之一升级选项
|
||||
// if (isset($level_model['upgraded']['many_good'])) {
|
||||
// // 比较
|
||||
// if (in_array($order_goods->goods_id, $level_model['upgraded']['many_good'])) {
|
||||
// return true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
public static function manyGood($uid,$level_model,$order_model,$self_order_after,$current_self_order_after){
|
||||
\YunShop::app()->uniacid = $order_model->uniacid;
|
||||
\Setting::$uniqueAccountId = $order_model->uniacid;
|
||||
if(!$order_model){
|
||||
return FALSE;
|
||||
}
|
||||
// 订单商品
|
||||
foreach($order_model->hasManyOrderGoods as $order_goods){
|
||||
// 等级是否设置购买指定商品之一升级选项
|
||||
if(isset($level_model['upgraded']['many_good'])){
|
||||
// 比较
|
||||
if(in_array($order_goods->goods_id,$level_model['upgraded']['many_good'])){
|
||||
return TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// 自购订单金额满X元
|
||||
public static function selfBuyMoney($uid, $level_model, $order_model, $self_order_after,$current_self_order_after)
|
||||
|
|
@ -348,7 +348,7 @@ class UpgrateConditionsService
|
|||
return $order;
|
||||
}
|
||||
|
||||
// 升级条件判断 - 直推间推多少人
|
||||
// 升级条件判断 - 直推间推某个等级多少人
|
||||
public static function oneOrTwo($memberId, $level, $order, $self_order_after,$current_self_order_after){
|
||||
try{
|
||||
$isPass = false;
|
||||
|
|
@ -486,6 +486,218 @@ class UpgrateConditionsService
|
|||
}
|
||||
return false;
|
||||
}
|
||||
// 升级条件判断 - 直推某个等级满多少人
|
||||
public static function oneLevelCount($memberId, $level, $order, $self_order_after,$current_self_order_after){
|
||||
try{
|
||||
$isPass = false;
|
||||
$type = (int)$current_self_order_after == 1 ? 'order_paid' : 'order_receive';
|
||||
// \Log::debug('分销商升级 - 直推人数 - 开始处理(与):',['member_id'=>$memberId,'type'=>$type]);
|
||||
// 分销商数据
|
||||
$agentModel = Agents::getAgentByMemberId($memberId)->first();
|
||||
if (!$agentModel) return false;
|
||||
// 获取全部上级
|
||||
$parentAgent = self::getParentsCommission($memberId);
|
||||
// \Log::debug('分销商升级 - 直推人数 - 本人及上级分销商信息:',$parentAgent);
|
||||
// \Log::debug('分销商升级 - 直推人数 - 等级信息:',$levels);
|
||||
$upgraded = $level['upgraded'] ?? [];
|
||||
$oneLevelCount = $upgraded['one_level_count'] ?? [];
|
||||
// 判断:支付后 完成后 是否存在对应的设置
|
||||
if(!empty($oneLevelCount) && (($type == 'order_receive' && (int)$upgraded['self_order_after'] != 1) || ($type == 'order_paid' && (int)$upgraded['self_order_after'] == 1))){
|
||||
// \Log::debug('分销商升级 - 直推人数 - 升级条件:',$oneLevelCount);
|
||||
// 循环所有上级 判断是否可以升级到当前等级
|
||||
foreach($parentAgent as $parentUser){
|
||||
if(($level['level_type'] == 1 ? (int)$parentUser['cultural_level']['level'] : (int)$parentUser['agent_level']['level']) < (int)$level['level']){
|
||||
// 获取直推用户信息
|
||||
$subMemberIds = MemberChildren::getOneLevel($parentUser['member_id'])->pluck('child_id');
|
||||
// 获取指定等级人数 根据设置条件:获取当前该等级人数 OR 历史人数
|
||||
if($oneLevelCount['one_level_count_history'] == 1){
|
||||
// 历史人数
|
||||
$hasNum = (int)\Yunshop\Commission\models\Log::uniacid()
|
||||
->where('after_level_id',$oneLevelCount['one_level_count_level_id'])
|
||||
->whereIn('uid',$subMemberIds)
|
||||
->count(DB::raw('DISTINCT(uid)'));
|
||||
}else{
|
||||
// 当前人数
|
||||
$hasNum = (int)Agents::uniacid()
|
||||
->where(function($query) use ($oneLevelCount){
|
||||
$query->where('agent_level_id',$oneLevelCount['one_level_count_level_id'])
|
||||
->orWhere('cultural_level_id',$oneLevelCount['one_level_count_level_id']);
|
||||
})
|
||||
->whereIn('uid',$subMemberIds)
|
||||
->count(DB::raw('DISTINCT(uid)'));
|
||||
}
|
||||
// 判断:是否达到升级要求 需求人数小于等于当前人数-达成升级条件
|
||||
$people = (int)$oneLevelCount['one_level_count_people'] > 0 ? (int)$oneLevelCount['one_level_count_people'] : 1;
|
||||
$isReach = (boolean)($people <= $hasNum);
|
||||
$validateResult = UpgradeService::validate($level, $parentUser['member_id']);
|
||||
if($isReach && $validateResult) $isPass = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $isPass;
|
||||
}catch(\Exception $e){
|
||||
\Log::debug('分销商升级 - 直推人数 - 错误(与):',$e->getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// 升级条件判断 - 直推间推某个等级每条线多少人
|
||||
public static function eachLineLv($memberId, $level, $order, $self_order_after,$current_self_order_after){
|
||||
try{
|
||||
$isPass = false;
|
||||
$type = (int)$current_self_order_after == 1 ? 'order_paid' : 'order_receive';
|
||||
// 分销商数据
|
||||
$agentModel = Agents::getAgentByMemberId($memberId)->first();
|
||||
if (!$agentModel) return false;
|
||||
// 获取全部上级
|
||||
$parentAgent = self::getParentsCommission($memberId);
|
||||
$upgraded = $level['upgraded'] ?? [];
|
||||
$eachLineLv = $upgraded['each_line_lv'] ?? [];
|
||||
// 判断:支付后 完成后 是否存在对应的设置
|
||||
if(!empty($eachLineLv) && (($type == 'order_receive' && (int)$upgraded['self_order_after'] != 1) || ($type == 'order_paid' && (int)$upgraded['self_order_after'] == 1))){
|
||||
// 循环所有上级 判断是否可以升级到当前等级
|
||||
foreach($parentAgent as $parentUser){
|
||||
if(($level['level_type'] == 1 ? (int)$parentUser['cultural_level']['level'] : (int)$parentUser['agent_level']['level']) < (int)$level['level']){
|
||||
// 获取直推下级列表
|
||||
$subIds = MemberChild::uniacid()
|
||||
->where('level',1)
|
||||
->where('member_id',$parentUser['member_id'])
|
||||
->pluck('child_id')
|
||||
->toArray();
|
||||
if(count($subIds) <= 0) continue;
|
||||
// 循环判断:是否达成条件 根据设置判断:计算当前等级 OR 计算历史等级
|
||||
$isMeetTheConditions = true;// 默认达成条件
|
||||
$people = (int)$eachLineLv['each_line_lv_people'] > 0 ? (int)$eachLineLv['each_line_lv_people'] : 1;// 条件人数
|
||||
if($eachLineLv['each_line_lv_history'] == 1){
|
||||
// 计算历史等级
|
||||
foreach($subIds as $subUid){
|
||||
// 获取每条线的所有下级
|
||||
$lineAllUid = MemberChild::uniacid()->where('member_id',$subUid)->pluck('child_id')->toArray();
|
||||
$lineAllUid[] = $subUid;
|
||||
$hasNum = (int)\Yunshop\Commission\models\Log::uniacid()
|
||||
->where('after_level_id',$eachLineLv['each_line_lv_level_id'])
|
||||
->whereIn('uid',$lineAllUid)
|
||||
->count(DB::raw('DISTINCT(uid)'));
|
||||
// 判断:只要有一条线 未达成条件 则都未达成条件,并且跳出循环
|
||||
if($people > $hasNum){
|
||||
$isMeetTheConditions = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
// 计算当前等级
|
||||
foreach($subIds as $subUid){
|
||||
// 获取每条线的所有下级
|
||||
$lineAllUid = MemberChild::uniacid()->where('member_id',$subUid)->pluck('child_id')->toArray();
|
||||
$lineAllUid[] = $subUid;
|
||||
$hasNum = (int)Agents::uniacid()
|
||||
->where(function($query) use ($eachLineLv){
|
||||
$query->where('agent_level_id',$eachLineLv['each_line_lv_level_id'])
|
||||
->orWhere('cultural_level_id',$eachLineLv['each_line_lv_level_id']);
|
||||
})
|
||||
->whereIn('uid',$lineAllUid)
|
||||
->count(DB::raw('DISTINCT(uid)'));
|
||||
// 判断:只要有一条线 未达成条件 则都未达成条件,并且跳出循环
|
||||
if($people > $hasNum){
|
||||
$isMeetTheConditions = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$isReach = $isMeetTheConditions;
|
||||
$validateResult = UpgradeService::validate($level, $parentUser['member_id']);
|
||||
if($isReach && $validateResult) $isPass = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $isPass;
|
||||
}catch(\Exception $e){
|
||||
\Log::debug('分销商升级 - 直推间推人数 - 错误(与):',$e->getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// 升级条件判断 - 团队消费人数满多少人,支持去除人数最多的线
|
||||
public static function teamConsumptionPeople($memberId, $level, $order, $self_order_after,$current_self_order_after){
|
||||
try{
|
||||
$isPass = false;
|
||||
$type = (int)$current_self_order_after == 1 ? 'order_paid' : 'order_receive';
|
||||
// 分销商数据
|
||||
$agentModel = Agents::getAgentByMemberId($memberId)->first();
|
||||
if (!$agentModel) return false;
|
||||
// 获取全部上级
|
||||
$parentAgent = self::getParentsCommission($memberId);
|
||||
$upgraded = $level['upgraded'] ?? [];
|
||||
$teamConsumptionPeople = $upgraded['team_consumption_people'] ?? [];
|
||||
// 判断:支付后 完成后 是否存在对应的设置
|
||||
if(!empty($teamConsumptionPeople) && (($type == 'order_receive' && (int)$upgraded['self_order_after'] != 1) || ($type == 'order_paid' && (int)$upgraded['self_order_after'] == 1))){
|
||||
// 循环所有上级 判断是否可以升级到当前等级
|
||||
foreach($parentAgent as $parentUser){
|
||||
if(($level['level_type'] == 1 ? (int)$parentUser['cultural_level']['level'] : (int)$parentUser['agent_level']['level']) < (int)$level['level']){
|
||||
// 获取直推下级列表
|
||||
$subIds = MemberChild::uniacid()
|
||||
->where('level',1)
|
||||
->where('member_id',$parentUser['member_id'])
|
||||
->pluck('child_id')
|
||||
->toArray();
|
||||
if(count($subIds) <= 0) continue;
|
||||
$eachLineUid = [];// 每条线的用户id列表
|
||||
$maxPeopleInfo = [
|
||||
'max_num' => 0,// 最大线人数
|
||||
'sub_uid' => 0,// 最大线所属直推用户id
|
||||
];
|
||||
foreach($subIds as $subUid){
|
||||
// 获取每条件的用户id
|
||||
$lineAllUid = MemberChild::uniacid()->where('member_id',$subUid)->pluck('child_id')->toArray();
|
||||
$lineAllUid[] = $subUid;
|
||||
$eachLineUid[$subUid] = $lineAllUid;
|
||||
// 判断:当前线用户数量是否为最多
|
||||
if($maxPeopleInfo['max_num'] <= count($eachLineUid[$subUid])) {
|
||||
$maxPeopleInfo = [
|
||||
'max_num' => count($eachLineUid[$subUid]),// 最大线人数
|
||||
'sub_uid' => $subUid,// 最大线所属直推用户id
|
||||
];
|
||||
}
|
||||
}
|
||||
// 判断:是否去除人数最多的那条线
|
||||
if((int)$teamConsumptionPeople['team_consumption_people_close_max'] == 1) unset($eachLineUid[$maxPeopleInfo['sub_uid']]);
|
||||
// 计算:消费总人数
|
||||
$allSubIds = [];
|
||||
foreach($eachLineUid as $eachLineInfo){
|
||||
$allSubIds = array_merge($allSubIds,$eachLineInfo);
|
||||
}
|
||||
$consumptionPeople = Order::uniacid()
|
||||
->leftJoin('yz_order_goods','yz_order_goods.order_id','yz_order.id')
|
||||
->leftJoin('yz_goods_cultural_space','yz_goods_cultural_space.goods_id','yz_order_goods.goods_id')
|
||||
->whereIn('yz_order.uid',$allSubIds)
|
||||
->where('yz_order.status','>',0)
|
||||
->where('yz_goods_cultural_space.is_open',$level['level_type'] == 1 ? 1 : 0)
|
||||
->distinct('yz_order.uid')
|
||||
->count();
|
||||
// 是否达到升级条件
|
||||
$validateResult = UpgradeService::validate($level, $parentUser['member_id']);
|
||||
if($consumptionPeople >= (float)$teamConsumptionPeople['team_consumption_people_total'] && $validateResult) {
|
||||
$isPass = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $isPass;
|
||||
}catch(\Exception $e){
|
||||
\Log::debug('分销商升级 - 团队业绩满多少 - 错误(与):',$e->getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@
|
|||
<span>个</span>
|
||||
</label>
|
||||
</div>
|
||||
{{-- 直推间推 某个等级 满多少人 START --}}
|
||||
{{-- 直推间推 某个等级 满多少人 --}}
|
||||
<div class="input-group row">
|
||||
<label class="radio-inline col-xs-12 col-sm-12">
|
||||
<div class="col-xs-12 col-sm-12" style="padding-left: 0">
|
||||
|
|
@ -176,9 +176,63 @@
|
|||
</div>
|
||||
</label>
|
||||
</div>
|
||||
{{-- 直推间推 某个等级 满多少人 END --}}
|
||||
|
||||
{{-- 团队业绩满 START --}}
|
||||
{{-- 直推间推 某个等级 每条线满多少人,支持区分当前和历史 --}}
|
||||
<div class="input-group row">
|
||||
<label class="radio-inline col-xs-12 col-sm-12">
|
||||
<div class="col-xs-12 col-sm-12" style="padding-left: 0">
|
||||
<div class='input-group'>
|
||||
<div class='input-group-addon waytxt'>
|
||||
<input type="checkbox" name="upgrade_type[each_line_lv]" value="1" @if ($upgrade_data['each_line_lv']) checked @endif>
|
||||
</div>
|
||||
<div class='input-group-addon waytxt'>直推间推</div>
|
||||
<select name='upgrade_value[each_line_lv][each_line_lv_level_id]' class="form-control" style="width: 150px;">
|
||||
@foreach($level_list as $level)
|
||||
<option value='{{$level['id']}}' @if($level['id'] == $upgrade_data['each_line_lv']['each_line_lv_level_id'])selected @endif >
|
||||
{{$level['name']}}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<div class='input-group-addon waytxt'>等级,每条线达到</div>
|
||||
<input type="number" name="upgrade_value[each_line_lv][each_line_lv_people]" value="{{$upgrade_data['each_line_lv']['each_line_lv_people']}}" class="form-control">
|
||||
<div class='input-group-addon waytxt'>人(不填或0默认为1人)</div>
|
||||
<div class='input-group-addon waytxt'>
|
||||
<input type="checkbox" name="upgrade_value[each_line_lv][each_line_lv_history]" value="1" @if ($upgrade_data['each_line_lv']['each_line_lv_history']) checked @endif>
|
||||
</div>
|
||||
<div class='input-group-addon waytxt'>计算历史人数</div>
|
||||
</div>
|
||||
<span class="help-block">默认计算当前该等级人数,如果计算历史人数则统计当前该等级人数和曾经成为过该等级的人数之和</span>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
{{-- 直推 某个等级 满多少人,支持区分当前和历史 --}}
|
||||
<div class="input-group row">
|
||||
<label class="radio-inline col-xs-12 col-sm-12">
|
||||
<div class="col-xs-12 col-sm-12" style="padding-left: 0">
|
||||
<div class='input-group'>
|
||||
<div class='input-group-addon waytxt'>
|
||||
<input type="checkbox" name="upgrade_type[one_level_count]" value="1" @if ($upgrade_data['one_level_count']) checked @endif>
|
||||
</div>
|
||||
<div class='input-group-addon waytxt'>直推</div>
|
||||
<select name='upgrade_value[one_level_count][one_level_count_level_id]' class="form-control" style="width: 150px;">
|
||||
@foreach($level_list as $level)
|
||||
<option value='{{$level['id']}}' @if($level['id'] == $upgrade_data['one_level_count']['one_level_count_level_id'])selected @endif >
|
||||
{{$level['name']}}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<div class='input-group-addon waytxt'>等级,总人数达到</div>
|
||||
<input type="number" name="upgrade_value[one_level_count][one_level_count_people]" value="{{$upgrade_data['one_level_count']['one_level_count_people']}}" class="form-control">
|
||||
<div class='input-group-addon waytxt'>人(不填或0默认为1人)</div>
|
||||
<div class='input-group-addon waytxt'>
|
||||
<input type="checkbox" name="upgrade_value[one_level_count][one_level_count_history]" value="1" @if ($upgrade_data['one_level_count']['one_level_count_history']) checked @endif>
|
||||
</div>
|
||||
<div class='input-group-addon waytxt'>计算历史人数</div>
|
||||
</div>
|
||||
<span class="help-block">默认计算当前该等级人数,如果计算历史人数则统计当前该等级人数和曾经成为过该等级的人数之和</span>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
{{-- 团队业绩满,支持去除最大业绩那条线 --}}
|
||||
<div class="input-group row">
|
||||
<label class="radio-inline col-xs-12 col-sm-12">
|
||||
<div class="col-xs-12 col-sm-12" style="padding-left: 0">
|
||||
|
|
@ -194,10 +248,31 @@
|
|||
</div>
|
||||
<div class='input-group-addon waytxt'>去除业绩最大的那条线</div>
|
||||
</div>
|
||||
<span class="help-block">根据当前等级类型计算;当前等级类型为文创等级则统计文创商品业绩,为普通商品则统计非文创商品业绩</span>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
{{-- 直推间推 某个等级 满多少人 END --}}
|
||||
{{-- 团队消费人数满多少人,支持去除最多人数那条线 --}}
|
||||
<div class="input-group row">
|
||||
<label class="radio-inline col-xs-12 col-sm-12">
|
||||
<div class="col-xs-12 col-sm-12" style="padding-left: 0">
|
||||
<div class='input-group'>
|
||||
<div class='input-group-addon waytxt'>
|
||||
<input type="checkbox" name="upgrade_type[team_consumption_people]" value="1" @if ($upgrade_data['team_consumption_people']) checked @endif>
|
||||
</div>
|
||||
<div class='input-group-addon waytxt'>团队消费人数满</div>
|
||||
<input type="number" name="upgrade_value[team_consumption_people][team_consumption_people_total]" value="{{$upgrade_data['team_consumption_people']['team_consumption_people_total']}}" class="form-control">
|
||||
<div class='input-group-addon waytxt'>人;</div>
|
||||
<div class='input-group-addon waytxt'>
|
||||
<input type="checkbox" name="upgrade_value[team_consumption_people][team_consumption_people_close_max]" value="1" @if ($upgrade_data['team_consumption_people']['team_consumption_people_close_max']) checked @endif>
|
||||
</div>
|
||||
<div class='input-group-addon waytxt'>去除业绩最大的那条线</div>
|
||||
</div>
|
||||
<span class="help-block">根据当前等级类型计算;当前等级类型为文创等级则统计文创商品业绩,为普通商品则统计非文创商品业绩;先计算所有人数(包含未消费),去除人数最多的线再计算消费用户数量</span>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
|
||||
@foreach($upgrade_config as $key=>$config)
|
||||
@if($config['key'] != 'goods' && $config['key'] != 'self_order_after' && $config['key'] != 'many_good')
|
||||
|
|
@ -216,7 +291,7 @@
|
|||
@if($key%2!=0)
|
||||
</div>
|
||||
@endif
|
||||
@elseif($config['key'] == 'goods' && !$set['is_with'])
|
||||
@elseif($config['key'] == 'goods')
|
||||
<div class='input-group'>
|
||||
<label class="radio-inline">
|
||||
<input type="checkbox" name="upgrade_type[{{$config['key']}}]"
|
||||
|
|
@ -249,7 +324,7 @@
|
|||
src="@if(isset($upgrade_data['goods']->thumb)) {{tomedia($upgrade_data['goods']->thumb) }} @endif"/>
|
||||
</span>
|
||||
</div>
|
||||
@elseif($config['key'] == 'many_good' && !$set['is_with'])
|
||||
@elseif($config['key'] == 'many_good')
|
||||
<div class="input-group row">
|
||||
<div class="input-group">
|
||||
<div class="radio-inline">
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
@if($set['level']>=1)<th style="text-align: center;width: 120px!important;">一级比例</th> @endif
|
||||
@if($set['level']>=2)<th style="text-align: center;width: 120px!important;">二级比例</th> @endif
|
||||
@if($set['level']>=3)<th style="text-align: center;width: 120px!important;">三级比例</th> @endif
|
||||
<th style="width: 210px;">升级条件</th>
|
||||
<th style="width: 300px;">升级条件</th>
|
||||
<th style="text-align: center;width: 120px!important;">等级人数</th>
|
||||
<th style="text-align: center;width: 200px!important;">操作</th>
|
||||
</tr>
|
||||
|
|
|
|||
Loading…
Reference in New Issue