diff --git a/app/common/models/member/MemberParent.php b/app/common/models/member/MemberParent.php index 8c799232..c756dbb7 100644 --- a/app/common/models/member/MemberParent.php +++ b/app/common/models/member/MemberParent.php @@ -24,4 +24,27 @@ class MemberParent extends BaseModel $builder->uniacid(); }); } + + + /** + * Common: 获取某个用户的全部直推间推成员 + * Author: wu-hui + * Time: 2023/10/25 14:20 + * @param $uid + * @return array + */ + public function getOneOrTwoList($uid){ + return self::uniacid() + ->where('parent_id', $uid) + ->whereIn('level',[1,2])// 只获取直推间推 + ->select(['parent_id','member_id','level']) + ->orderBy('level', 'asc') + ->get() + ->toArray(); + } + + + + + } \ No newline at end of file diff --git a/plugins/commission/src/observers/AgentsObserver.php b/plugins/commission/src/observers/AgentsObserver.php index f8b39bf6..aae59d03 100644 --- a/plugins/commission/src/observers/AgentsObserver.php +++ b/plugins/commission/src/observers/AgentsObserver.php @@ -5,8 +5,10 @@ namespace Yunshop\Commission\observers; use app\common\observers\BaseObserver; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\DB; use Yunshop\Commission\models\AgentLevel; use Yunshop\Commission\models\Agents; +use Yunshop\Commission\models\Log; class AgentsObserver extends BaseObserver{ @@ -15,8 +17,15 @@ class AgentsObserver extends BaseObserver{ // \Log::debug('修改分销商 - 信息:',$model->toArray()); if ($model->getOriginal('agent_level_id') != $model->agent_level_id) { // 判断:如果当前等级人数已经达到限制 则不升级(上限小于等于已存在数量 不能升级到该等级) - $hasNum = (int)Agents::uniacid()->where('member_id','!=',$model->member_id)->count(); - $levelNumberLimit = (int)AgentLevel::uniacid()->where('id',$model->agent_level_id)->value('number_limit'); + $hasNum = (int)Log::uniacid()->where('after_level_id',$model->level)->where('uid','!=',$model->uid)->count(DB::raw('DISTINCT(uid)')); + $levelNumberLimit = (int)AgentLevel::uniacid()->where('id',$model->agent_level_id)->value('number_limit');// 限制人数 + \Log::debug("分销商等级变更 - 人数限制判断", [ + 'next_lv_id' => $model->agent_level_id, + 'current_lv_id' => $model->getOriginal('agent_level_id'), + 'next_lv_limit' => $levelNumberLimit, + 'has_num' => $hasNum, + ]); + if((int)$levelNumberLimit <= $hasNum && (int)$levelNumberLimit > 0) return false; } } diff --git a/plugins/commission/src/services/UpgradeService.php b/plugins/commission/src/services/UpgradeService.php index a6862624..921d3822 100644 --- a/plugins/commission/src/services/UpgradeService.php +++ b/plugins/commission/src/services/UpgradeService.php @@ -6,6 +6,7 @@ namespace Yunshop\Commission\services; use app\common\facades\Setting; use app\common\models\Order; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Yunshop\Commission\models\AgentLevel; use Yunshop\Commission\models\Agents; @@ -855,10 +856,9 @@ class UpgradeService $newLevel = $newLevel->toArray(); $oldLevel = AgentLevel::getAgentLevelByid($agent->agent_level_id); // 判断:如果当前等级人数已经达到限制 则不升级(上限小于等于已存在数量 不能升级到该等级) - // \Log::debug('修改分销商等级信息 - 分销商升级',['level_id'=>$level['id'],'member_id' => $memberId]); - $hasNum = (int)Agents::uniacid()->where('member_id','!=',$memberId)->count(); + $hasNum = (int)\Yunshop\Commission\models\Log::uniacid()->where('after_level_id',$level['id'])->where('uid','!=',$memberId)->count(DB::raw('DISTINCT(uid)')); if((int)$newLevel['number_limit'] <= $hasNum && (int)$newLevel['number_limit'] > 0) { - \Log::debug("当前等级已达到人数上限", [ + \Log::debug("分销商等级变更 - 人数限制判断", [ 'next_lv_id' => $level['id'], 'current_lv_id' => $agent->agent_level_id, 'next_lv_limit' => $newLevel['number_limit'], diff --git a/plugins/team-dividend/src/jobs/NewUpgrateJob.php b/plugins/team-dividend/src/jobs/NewUpgrateJob.php index 76e39856..ee64ca92 100644 --- a/plugins/team-dividend/src/jobs/NewUpgrateJob.php +++ b/plugins/team-dividend/src/jobs/NewUpgrateJob.php @@ -113,7 +113,7 @@ class NewUpgrateJob implements ShouldQueue return; } - + \Log::debug('经销商升级 - 开始处理:'); // 默认可以升级 $upgradeRet = false; foreach ($upgradeLevels as $level) { @@ -205,15 +205,13 @@ class NewUpgrateJob implements ShouldQueue $next = true; // 如果升级方式为 或 $upgradeRet 为真 不继续 if ($this->setting['upgrate_type'] == 1) { - if ($upgradeRet) { - $next = false; - } + if ($upgradeRet) $next = false; + } else { // 如果升级方式为 与 $upgradeRet 为假 不继续 - if (!$upgradeRet && $upgradeGroup) { - $next = false; - } + if (!$upgradeRet && $upgradeGroup) $next = false; } + // \Log::debug('经销商升级 - 是否继续:',$next); // 升级条件 单个 与 升级结果为false if ($next) { $upgradeOnly = $parase[0]; @@ -236,7 +234,7 @@ class NewUpgrateJob implements ShouldQueue foreach ($upgradeToFirstChildLevel as $levelId => $ret) { $upgradeOnly['first_child_level_' . $levelId . '_' . $parase[1]['first_child_level'][$levelId]] = '1'; } - + // \Log::debug('经销商升级 - 继续 - 循环体:',$upgradeOnly); foreach ($upgradeOnly as $upgrade => $only_item) { // 升级类 $upgrateService = new UpgrateConditionService($agent['uid'], $this->setting, $parase[1], $this->uniacid, $upgrade, $order_status, $this->order, $this->uplogService); diff --git a/plugins/team-dividend/src/models/TeamDividendLevelUpgrade.php b/plugins/team-dividend/src/models/TeamDividendLevelUpgrade.php index c1308fbf..6adb4181 100644 --- a/plugins/team-dividend/src/models/TeamDividendLevelUpgrade.php +++ b/plugins/team-dividend/src/models/TeamDividendLevelUpgrade.php @@ -70,7 +70,7 @@ class TeamDividendLevelUpgrade extends BackendModel '1030' => 'agent_love', // 会员累计获得{{ LOVE_NAME }}数量达到 '1031' => 'team_new_order_number', // 团队新订单数量满 '1032' => 'team_shop_order_amount', // 团队自营订单实付金额满 - // '1050' => 'one_or_two', // 直推间推 某个等级 满多少人 + '1050' => 'one_or_two', // 直推间推 某个等级 满多少人 ]; // 等级为 2000 + 等级id diff --git a/plugins/team-dividend/src/services/upgrate/UpgrateConditionService.php b/plugins/team-dividend/src/services/upgrate/UpgrateConditionService.php index f3730a07..a65f9f02 100644 --- a/plugins/team-dividend/src/services/upgrate/UpgrateConditionService.php +++ b/plugins/team-dividend/src/services/upgrate/UpgrateConditionService.php @@ -1,13 +1,12 @@ uid = $uid; - $this->set = $set; - $this->upgradeParase = $upgradeParase; - $this->typeName = $typeName; - $this->order_status = $order_status; - $this->order = $order; + public function __construct($uid,$set,$upgradeParase,$uniacid,$typeName,$order_status,$order,$uplogService){ + $this->uid = $uid; + $this->set = $set; + $this->upgradeParase = $upgradeParase; + $this->typeName = $typeName; + $this->order_status = $order_status; + $this->order = $order; \YunShop::app()->uniacid = $uniacid; - $this->uplogService = $uplogService; } - - private function addLogChild($result, $condition = null) - { + private function addLogChild($result,$condition = NULL){ $data = [ //'log_id' => $this->log_id, 'type_name' => $this->typeName, - 'result' => $result + 'result' => $result ]; - if ($condition == null) { + if($condition == NULL){ $data['condition'] = $this->upgradeParase[$this->typeName]; - } else { + } + else{ $data['condition'] = $condition; } // 记录详情 LogChild::create($data); } - - private function addErrorChild($condition) - { + private function addErrorChild($condition){ $data = [ //'log_id' => $this->log_id, 'type_name' => $this->typeName, - 'result' => -1 + 'result' => -1 ]; - if ($condition == null) { + if($condition == NULL){ $data['condition'] = $this->upgradeParase[$this->typeName]; - } else { + } + else{ $data['condition'] = $condition; } // 记录详情 LogChild::create($data); } - /** * @name 一级客户订单金额满,不加[订单状态]限制 - * @author * @return bool + * @author */ - public function firstMoney() - { + public function firstMoney(){ $type = intval($this->upgradeParase[$this->typeName]); - if (Setting::get('plugin.team_dividend.level_up_choose') == 1){ - $column = 'yz_order.goods_price'; + if(Setting::get('plugin.team_dividend.level_up_choose') == 1){ + $column = 'yz_order.goods_price'; $amount_name = '订单商品现价'; - }else{ - $column = 'yz_order.price'; + } + else{ + $column = 'yz_order.price'; $amount_name = '订单实付金额'; } - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一级客户'.$amount_name.'满', 'func_name' => 'firstMoney', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $orderPrice = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) - ->join('yz_order','yz_member_children.child_id', '=', 'yz_order.uid') - ->where('yz_order.status', '>=', $this->order_status) - ->where('yz_member_children.member_id', $this->uid) - ->where('yz_member_children.level', 1) + $orderPrice = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) + ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') + ->where('yz_order.status','>=',$this->order_status) + ->where('yz_member_children.member_id',$this->uid) + ->where('yz_member_children.level',1) ->sum($column); - $condition = $orderPrice >= $this->upgradeParase[$this->typeName]; - + $condition = $orderPrice >= $this->upgradeParase[$this->typeName]; // 记录详情 //$this->addLogChild($orderPrice); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一级客户'.$amount_name.'满', 'func_name' => 'firstMoney', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $orderPrice, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $orderPrice, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 一级客户订单数量满,指定商品ID,不加[订单状态]限制 - * @author * @return bool + * @author */ - public function firstOrderCount() - { + public function firstOrderCount(){ $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一级客户订单数量满,指定商品ID', 'func_name' => 'firstOrderCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_order_count_to_goods']), - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $orderCount = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) - ->join('yz_order','yz_member_children.child_id', '=', 'yz_order.uid') - ->where('yz_order.status', '>=', $this->order_status) - ->where('yz_member_children.member_id', $this->uid) - ->where('yz_member_children.level', 1) + $orderCount = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) + ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') + ->where('yz_order.status','>=',$this->order_status) + ->where('yz_member_children.member_id',$this->uid) + ->where('yz_member_children.level',1) ->count('yz_order.id'); // first_order_count_to_goods $firstOrderCountToGoods = intval($this->upgradeParase['first_order_count_to_goods']); - if ($firstOrderCountToGoods > 0) { - $orderCount = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) + if($firstOrderCountToGoods > 0){ + $orderCount = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') - ->join('yz_order_goods',function ($join){ - $join->on('yz_order_goods.order_id', '=', 'yz_order.id'); + ->join('yz_order_goods',function($join){ + $join->on('yz_order_goods.order_id','=','yz_order.id'); }) - ->where('yz_order.status', '>=', $this->order_status) - ->where('yz_member_children.member_id', $this->uid) - ->where('yz_member_children.level', 1) - ->where('yz_order_goods.goods_id', $firstOrderCountToGoods) + ->where('yz_order.status','>=',$this->order_status) + ->where('yz_member_children.member_id',$this->uid) + ->where('yz_member_children.level',1) + ->where('yz_order_goods.goods_id',$firstOrderCountToGoods) ->count('yz_order.id'); } - $condition = $orderCount >= $this->upgradeParase[$this->typeName]; - // 记录详情 //$this->addLogChild($orderCount); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一级客户订单数量满,指定商品ID', 'func_name' => 'firstOrderCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_order_count_to_goods']), - 'complete' => $orderCount, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $orderCount, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 二级客户订单金额满or一、二级客户订单金额满,不加[订单状态]限制 order_money_2 or order_money - * @author * @return bool + * @author */ - public function orderMoney() - { - if (Setting::get('plugin.team_dividend.level_up_choose') == 1){ - $column = 'yz_order.goods_price'; + public function orderMoney(){ + if(Setting::get('plugin.team_dividend.level_up_choose') == 1){ + $column = 'yz_order.goods_price'; $amount_name = '订单商品现价'; - }else{ - $column = 'yz_order.price'; + } + else{ + $column = 'yz_order.price'; $amount_name = '订单实付金额'; } - $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一、二级客户'.$amount_name.'满', 'func_name' => 'orderMoney', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - // order_money_2 $ret[2] = 2 or order_money - $ret = explode('_', $this->typeName); - if (isset($ret[2]) && intval($ret[2]) > 0) { + $ret = explode('_',$this->typeName); + if(isset($ret[2]) && intval($ret[2]) > 0){ $logremark = '只统计二级'; - $build = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) - ->join('yz_order','yz_member_children.child_id', '=', 'yz_order.uid') - ->where('yz_order.status', '>=', $this->order_status) - ->where('yz_member_children.member_id', $this->uid) - ->where('yz_member_children.level', intval($ret[2])); - } else { - $logremark = '统计一二级'; - $build = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) - ->join('yz_order','yz_member_children.child_id', '=', 'yz_order.uid') - ->where('yz_order.status', '>=', $this->order_status) - ->where('yz_member_children.member_id', $this->uid) - ->whereIn('yz_member_children.level', [1, 2]); + $build = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) + ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') + ->where('yz_order.status','>=',$this->order_status) + ->where('yz_member_children.member_id',$this->uid) + ->where('yz_member_children.level',intval($ret[2])); + } + else{ + $logremark = '统计一二级'; + $build = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) + ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') + ->where('yz_order.status','>=',$this->order_status) + ->where('yz_member_children.member_id',$this->uid) + ->whereIn('yz_member_children.level',[1,2]); } - $orderPrice = $build->sum($column); - $condition = $orderPrice >= $this->upgradeParase[$this->typeName]; - // 记录详情 //$this->addLogChild($orderPrice); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一、二级客户'.$amount_name.'满['.$logremark.']', 'func_name' => 'orderMoney', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $orderPrice, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $orderPrice, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 二级客户订单数量满,不加[订单状态]限制 - * @author * @return bool + * @author */ - public function orderNum() - { + public function orderNum(){ $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '二级客户订单数量满', 'func_name' => 'orderNum', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - // order_num_2 $ret[2] = 2 - $ret = explode('_', $this->typeName); - $orderCount = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) - ->join('yz_order','yz_member_children.child_id', '=', 'yz_order.uid') - ->where('yz_order.status', '>=', $this->order_status) - ->where('yz_member_children.member_id', $this->uid) - ->where('yz_member_children.level', intval($ret[2])) + $ret = explode('_',$this->typeName); + $orderCount = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) + ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') + ->where('yz_order.status','>=',$this->order_status) + ->where('yz_member_children.member_id',$this->uid) + ->where('yz_member_children.level',intval($ret[2])) ->count('yz_order.id'); - $condition = $orderCount >= $this->upgradeParase[$this->typeName]; - // 记录详情 //$this->addLogChild($orderCount); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '二级客户订单数量满', 'func_name' => 'orderNum', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $orderCount, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $orderCount, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 一、二级客户订单数量满,不加[订单状态]限制 - * @author * @return bool + * @author */ - public function orderCount() - { + public function orderCount(){ $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一、二级客户订单数量满', 'func_name' => 'orderCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $orderPrice = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) - ->join('yz_order','yz_member_children.child_id', '=', 'yz_order.uid') - ->where('yz_order.status', '>=', $this->order_status) - ->where('yz_member_children.member_id', $this->uid) - ->whereIn('yz_member_children.level', [1, 2]) + $orderPrice = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) + ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') + ->where('yz_order.status','>=',$this->order_status) + ->where('yz_member_children.member_id',$this->uid) + ->whereIn('yz_member_children.level',[1,2]) ->count('yz_order.id'); - $condition = $orderPrice >= $this->upgradeParase[$this->typeName]; - // 记录详情 //$this->addLogChild($orderPrice); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一、二级客户订单数量满', 'func_name' => 'orderCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $orderPrice, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $orderPrice, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 直推参与认购人数达到xx人 - * @author * @return bool + * @author */ - public function firstLowerSubscription() - { - if (!app('plugins')->isEnabled('subscription')) { - return false; + public function firstLowerSubscription(){ + if(!app('plugins')->isEnabled('subscription')){ + return FALSE; } $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '直推参与认购人数达到xx人', 'func_name' => 'firstLowerSubscription', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - $childIds = MemberChild::select() ->where('member_id',$this->uid) ->where('level',1) ->pluck('child_id'); - if ($childIds->isEmpty()) { - return false; + if($childIds->isEmpty()){ + return FALSE; } - - $count = BuyModel::whereIn('uid', $childIds)->where('quantity', '>', 0)->count(DB::raw('DISTINCT(uid)')); + $count = BuyModel::whereIn('uid',$childIds) + ->where('quantity','>',0) + ->count(DB::raw('DISTINCT(uid)')); $condition = $count >= $this->upgradeParase[$this->typeName]; - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '直推参与认购人数达到['.$count.']人', 'func_name' => 'firstLowerSubscription', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $count, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $count, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - - return false; + return FALSE; } - /** * @name 团队参与认购额度累计达到xx额度 - * @author * @return bool + * @author */ - public function teamSubscription() - { - if (!app('plugins')->isEnabled('subscription')) { - return false; + public function teamSubscription(){ + if(!app('plugins')->isEnabled('subscription')){ + return FALSE; } $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队参与认购额度累计达到xx额度', 'func_name' => 'teamSubscription', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $total = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id'])->join('yz_subscription_user_buy','yz_member_children.child_id','=','yz_subscription_user_buy.uid') + $total = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) + ->join('yz_subscription_user_buy','yz_member_children.child_id','=','yz_subscription_user_buy.uid') ->where('yz_member_children.member_id',$this->uid) ->sum('yz_subscription_user_buy.quantity'); - $condition = $total >= $this->upgradeParase[$this->typeName]; $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队参与认购额度累计达到['.$total.']额度', 'func_name' => 'teamSubscription', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $total, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $total, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - - return false; + return FALSE; } - /** * @name 团队业绩金额满,[订单状态]-已完成 - * @author * @return bool + * @author */ - public function teamOrderAmount() - { + public function teamOrderAmount(){ $type = intval($this->upgradeParase[$this->typeName]); - if (Setting::get('plugin.team_dividend.level_up_choose') == 1){ - $column = 'yz_order.goods_price'; + if(Setting::get('plugin.team_dividend.level_up_choose') == 1){ + $column = 'yz_order.goods_price'; $amount_name = '订单商品现价'; - }else{ - $column = 'yz_order.price'; + } + else{ + $column = 'yz_order.price'; $amount_name = '订单实付金额'; } - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队业绩'.$amount_name.'满', 'func_name' => 'teamOrderAmount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $teamOrderPrice = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id'])->join('yz_order','yz_member_children.child_id','=','yz_order.uid') - ->where('yz_order.status', '>=', $this->order_status) + $teamOrderPrice = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) + ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') + ->where('yz_order.status','>=',$this->order_status) ->where('yz_member_children.member_id',$this->uid) ->sum($column); - $logremark = '不计算自购订单'; + $logremark = '不计算自购订单'; if($this->set['including_self'] == 1){ - $logremark = '计算自购订单'; - $teamOrderPrice += Order::where('uid', $this->uid) - ->where('status', '>=', $this->order_status) + $logremark = '计算自购订单'; + $teamOrderPrice += Order::where('uid',$this->uid) + ->where('status','>=',$this->order_status) ->sum($column); } - - $condition = $teamOrderPrice >= $this->upgradeParase[$this->typeName]; - /*dump($this->typeName); dump($this->upgradeParase[$this->typeName]); dump($teamOrderPrice); - return true;*/ - - // 记录详情 + return true;*/ // 记录详情 //$this->addLogChild($teamOrderPrice); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队业绩'.$amount_name.'满['.$logremark.']', 'func_name' => 'teamOrderAmount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $teamOrderPrice, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $teamOrderPrice, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } /** * @name 团队自营订单实付金额满,[订单状态]-已完成 - * @author * @return bool + * @author */ - public function teamShopOrderAmount() - { + public function teamShopOrderAmount(){ $type = intval($this->upgradeParase[$this->typeName]); - - if (!$type) { + if(!$type){ $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队自营订单实付金额满', 'func_name' => 'teamShopOrderAmount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $teamOrderPrice = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id'])->join('yz_order','yz_member_children.child_id','=','yz_order.uid') - ->where('yz_order.status', '>=', $this->order_status) - ->where('yz_order.plugin_id', 0) + $teamOrderPrice = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) + ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') + ->where('yz_order.status','>=',$this->order_status) + ->where('yz_order.plugin_id',0) ->where('yz_member_children.member_id',$this->uid) ->sum('yz_order.price'); - $logremark = '不计算自购订单'; + $logremark = '不计算自购订单'; if($this->set['including_self'] == 1){ - $logremark = '计算自购订单'; - $teamOrderPrice += Order::where('uid', $this->uid) - ->where('status', '>=', $this->order_status) - ->where('plugin_id', 0) + $logremark = '计算自购订单'; + $teamOrderPrice += Order::where('uid',$this->uid) + ->where('status','>=',$this->order_status) + ->where('plugin_id',0) ->sum('yz_order.price'); } - - $condition = $teamOrderPrice >= $this->upgradeParase[$this->typeName]; - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队自营订单实付金额满['.$logremark.']', 'func_name' => 'teamShopOrderAmount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $teamOrderPrice, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $teamOrderPrice, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 团队商品数量满,指定商品ID,[订单状态]-已完成 - * @author * @return bool + * @author */ - public function teamGoodsAmount() - { + public function teamGoodsAmount(){ $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队商品数量满,指定商品ID', 'func_name' => 'teamGoodsAmount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['team_goods_amount_to_goods']), - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $build = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) + $build = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') - ->join('yz_order_goods',function ($join){ - $join->on('yz_order_goods.order_id', '=', 'yz_order.id'); + ->join('yz_order_goods',function($join){ + $join->on('yz_order_goods.order_id','=','yz_order.id'); }) - ->where('yz_order.status', '>=', $this->order_status) - ->where('yz_member_children.member_id', $this->uid); - + ->where('yz_order.status','>=',$this->order_status) + ->where('yz_member_children.member_id',$this->uid); $countToGoods = intval($this->upgradeParase['team_goods_amount_to_goods']); - if ($countToGoods > 0) { - $build->where('yz_order_goods.goods_id', $countToGoods); + if($countToGoods > 0){ + $build->where('yz_order_goods.goods_id',$countToGoods); } $team_goods_total = $build->sum('yz_order_goods.total'); - $logremark = '不计算自购订单'; + $logremark = '不计算自购订单'; if($this->set['including_self'] == 1){ $logremark = '计算自购订单'; //加上指定商品的条件 - $self_build = Order::where('uid', $this->uid)->where('status', '>=', $this->order_status); - if ($countToGoods > 0) { - $self_build ->whereHas('orderGoods',function ($query) use($countToGoods){ + $self_build = Order::where('uid',$this->uid) + ->where('status','>=',$this->order_status); + if($countToGoods > 0){ + $self_build->whereHas('orderGoods',function($query) use ($countToGoods){ $query->where('goods_id',$countToGoods); }); } $team_goods_total += $self_build->sum('goods_total'); } - $condition = $team_goods_total >= $this->upgradeParase[$this->typeName]; - // 记录详情 //$this->addLogChild($team_goods_total); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队商品数量满,指定商品ID['.$logremark.']', 'func_name' => 'teamGoodsAmount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['team_goods_amount_to_goods']), - 'complete' => $team_goods_total, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $team_goods_total, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 直属经销商人数,指定商品ID - * @author * @return bool + * @author */ - public function firstLowerTeamCount() - { + public function firstLowerTeamCount(){ $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '直属经销商人数,指定商品ID', 'func_name' => 'firstLowerTeamCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_lower_team_count_to_goods']), - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - $agentCount = TeamDividendAgencyModel::getFirstAgencyNum($this->uid); - $firstLowerTeamCountToGoods = intval($this->upgradeParase['first_lower_team_count_to_goods']); - if ($firstLowerTeamCountToGoods > 0) { + if($firstLowerTeamCountToGoods > 0){ $agentCount = MemberChild::select() - ->whereHas('hasOneTeam', function ($team) { - $team->select(['id', 'uid']); + ->whereHas('hasOneTeam',function($team){ + $team->select(['id','uid']); }) - ->whereHas('hasManyOrder', function ($order) use ($firstLowerTeamCountToGoods) { - $order->whereHas('hasManyOrderGoods', function ($order_goods) use ($firstLowerTeamCountToGoods) { - $order_goods->where('goods_id', $firstLowerTeamCountToGoods); + ->whereHas('hasManyOrder',function($order) use ($firstLowerTeamCountToGoods){ + $order->whereHas('hasManyOrderGoods',function($order_goods) use ($firstLowerTeamCountToGoods){ + $order_goods->where('goods_id',$firstLowerTeamCountToGoods); }); }) - ->where('member_id', $this->uid) - ->where('level', 1) + ->where('member_id',$this->uid) + ->where('level',1) ->uniacid() ->count(); } - $condition = $agentCount >= $this->upgradeParase[$this->typeName]; - // 记录详情 //$this->addLogChild($agentCount); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '直属经销商人数,指定商品ID', 'func_name' => 'firstLowerTeamCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_lower_team_count_to_goods']), - 'complete' => $agentCount, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $agentCount, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 团队经销商人数 - * @author * @return bool + * @author */ - public function allLowerTeamCount() - { + public function allLowerTeamCount(){ $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队经销商人数', 'func_name' => 'allLowerTeamCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $children = MemberChild::uniacid()->select(['child_id'])->where('member_id',$this->uid)->get()->toArray(); - $total_ids = array_column($children,'child_id'); + $children = MemberChild::uniacid() + ->select(['child_id']) + ->where('member_id',$this->uid) + ->get() + ->toArray(); + $total_ids = array_column($children,'child_id'); $agentCount = 0; - foreach (array_chunk($total_ids,5000) as $ids) { - $agentCount += TeamDividendAgencyModel::whereIn('uid', $ids)->count(); + foreach(array_chunk($total_ids,5000) as $ids){ + $agentCount += TeamDividendAgencyModel::whereIn('uid',$ids) + ->count(); } $condition = $agentCount >= $this->upgradeParase[$this->typeName]; - // 记录详情 //$this->addLogChild($agentCount); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队经销商人数', 'func_name' => 'allLowerTeamCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $agentCount, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $agentCount, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 一级客户人数满 - * @author * @return bool + * @author */ - public function firstLowerCount() - { + public function firstLowerCount(){ $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一级客户人数满', 'func_name' => 'firstLowerCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - $fisrtCount = MemberChild::select() - ->where('member_id', $this->uid) - ->where('level', 1) + ->where('member_id',$this->uid) + ->where('level',1) ->count(); - $condition = $fisrtCount >= $this->upgradeParase[$this->typeName]; - // 记录详情 //$this->addLogChild($fisrtCount); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一级客户人数满', 'func_name' => 'firstLowerCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $fisrtCount, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $fisrtCount, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 自购订单金额满 - * @author * @return bool + * @author */ - public function selfBuyMoney() - { + public function selfBuyMoney(){ $type = intval($this->upgradeParase[$this->typeName]); - if (Setting::get('plugin.team_dividend.level_up_choose') == 1){ - $column = 'yz_order.goods_price'; + if(Setting::get('plugin.team_dividend.level_up_choose') == 1){ + $column = 'yz_order.goods_price'; $amount_name = '订单商品现价'; - }else{ - $column = 'yz_order.price'; + } + else{ + $column = 'yz_order.price'; $amount_name = '订单实付金额'; } - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '自购'.$amount_name.'满', 'func_name' => 'selfBuyMoney', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $orderPrice = Order::where('uid', $this->uid) - ->where('status', '>=', $this->order_status) + $orderPrice = Order::where('uid',$this->uid) + ->where('status','>=',$this->order_status) ->sum($column); - $condition = $orderPrice >= $this->upgradeParase[$this->typeName]; - - + $condition = $orderPrice >= $this->upgradeParase[$this->typeName]; // 记录详情 //$this->addLogChild($orderPrice); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '自购'.$amount_name.'满', 'func_name' => 'selfBuyMoney', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $orderPrice, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $orderPrice, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 自购订单数量满 - * @author * @return bool + * @author */ - public function selfBuyCount() - { + public function selfBuyCount(){ $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '自购订单数量满', 'func_name' => 'selfBuyCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $orderCount = Order::where('uid', $this->uid) - ->where('status', '>=', $this->order_status) + $orderCount = Order::where('uid',$this->uid) + ->where('status','>=',$this->order_status) ->count(); - $condition = $orderCount >= $this->upgradeParase[$this->typeName]; - // 记录详情 //$this->addLogChild($orderCount); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '自购订单数量满', 'func_name' => 'selfBuyCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $orderCount, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $orderCount, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 结算分红金额满 - * @author * @return bool + * @author */ - public function settleMoney() - { + public function settleMoney(){ $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '结算分红金额满', 'func_name' => 'settleMoney', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $amount = TeamDividendModel::uniacid() - ->where('member_id', $this->uid) - ->where('status', 1) + $amount = TeamDividendModel::uniacid() + ->where('member_id',$this->uid) + ->where('status',1) ->sum('dividend_amount'); $condition = $amount >= $this->upgradeParase[$this->typeName]; - // 记录详情 //$this->addLogChild($amount); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '结算分红金额满', 'func_name' => 'settleMoney', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $amount, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $amount, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 一级客户消费满first_cost_count,人数达到 first_cost_num - * @author * @return bool + * @author */ - public function firstCostCount() - { + public function firstCostCount(){ $type = intval($this->upgradeParase[$this->typeName]); - - if (!$type || !intval($this->upgradeParase['first_cost_num'])) { + if(!$type || !intval($this->upgradeParase['first_cost_num'])){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一级客户消费满,人数达到', 'func_name' => 'firstCostCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_cost_num']), - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $member = YzMemberModel::childFirstMember($this->uid)->get(); - $count = 0; - if ($member) { - foreach ($member as $rows) { - $price_total = OrderModel::statisticsMemberGoodsPrice($rows->member_id, $this->order_status); - if ($price_total >= $this->upgradeParase[$this->typeName]) { + $member = YzMemberModel::childFirstMember($this->uid) + ->get(); + $count = 0; + if($member){ + foreach($member as $rows){ + $price_total = OrderModel::statisticsMemberGoodsPrice($rows->member_id,$this->order_status); + if($price_total >= $this->upgradeParase[$this->typeName]){ $count++; } } } $condition = $count >= $this->upgradeParase['first_cost_num']; - // 记录详情 //$this->addLogChild($count, $this->upgradeParase['first_cost_num']); - /*$data = [ 'log_id' => $this->log_id, 'type_name' => 'first_cost_num', @@ -1058,875 +917,767 @@ class UpgrateConditionService 'condition' => $this->upgradeParase['first_cost_num'] ]; LogChild::create($data);*/ - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一级客户消费满,人数达到', 'func_name' => 'firstCostCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_cost_num']), - 'complete' => $count, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $count, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 一级客户消费满first_second_cost_count,人数达到 first_second_cost_num - * @author * @return bool + * @author */ - public function firstSecondCostCount() - { + public function firstSecondCostCount(){ $type = intval($this->upgradeParase[$this->typeName]); - - if (!$type || !intval($this->upgradeParase['first_second_cost_num'])) { + if(!$type || !intval($this->upgradeParase['first_second_cost_num'])){ $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一、二级客户消费满,人数达到', 'func_name' => 'firstSecondCostCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_second_cost_num']), - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $member = MemberParent::uniacid()->where('parent_id',$this->uid)->whereIn('level',[1,2])->get(); - - $count = 0; - $condition = false; - if ($member) { - foreach ($member as $rows) { - $price_total = OrderModel::statisticsMemberGoodsPrice($rows->member_id, $this->order_status); - if ($price_total >= $this->upgradeParase[$this->typeName]) { + $member = MemberParent::uniacid() + ->where('parent_id',$this->uid) + ->whereIn('level',[1,2]) + ->get(); + $count = 0; + $condition = FALSE; + if($member){ + foreach($member as $rows){ + $price_total = OrderModel::statisticsMemberGoodsPrice($rows->member_id,$this->order_status); + if($price_total >= $this->upgradeParase[$this->typeName]){ $count++; if($count >= $this->upgradeParase['first_second_cost_num']){ - $condition = true; + $condition = TRUE; break; } } } } - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一、二级客户消费满,人数达到', 'func_name' => 'firstSecondCostCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_second_cost_num']), - 'complete' => $count, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $count, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - - /** * @name 团队商家数量满 - * @author * @return bool + * @author */ - public function teamMerchantsCount() - { + public function teamMerchantsCount(){ $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队商家数量满', 'func_name' => 'teamMerchantsCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - $exist_supplier = app('plugins')->isEnabled('supplier'); - $exist_store = app('plugins')->isEnabled('store-cashier'); - $count = 0; - if ($exist_supplier || $exist_store) { + $exist_store = app('plugins')->isEnabled('store-cashier'); + $count = 0; + if($exist_supplier || $exist_store){ $childIds = MemberChild::select('child_id') - ->where('member_id', $this->uid) + ->where('member_id',$this->uid) ->pluck('child_id'); - if ($exist_supplier) { + if($exist_supplier){ - $supplierCount = Supplier::whereIn('member_id', $childIds) + $supplierCount = Supplier::whereIn('member_id',$childIds) ->count(); - $count += $supplierCount; } - if ($exist_store) { + if($exist_store){ - $storeCount = Store::whereIn('uid', $childIds) + $storeCount = Store::whereIn('uid',$childIds) ->count(); - $count += $storeCount; } - $condition = $count >= $this->upgradeParase[$this->typeName]; - // 记录详情 //$this->addLogChild($count); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队商家数量满', 'func_name' => 'teamMerchantsCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $count, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $count, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } } $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队商家数量满', 'func_name' => 'teamMerchantsCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行[没开启供应商或门店插件(供应商状态:'.$exist_supplier.'|门店状态'.$exist_store.')]' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行[没开启供应商或门店插件(供应商状态:'.$exist_supplier.'|门店状态'.$exist_store.')]' ]); - return false; + return FALSE; } - /** * @name 团队下级人数满,指定商品ID - * @author * @return bool + * @author */ - public function teamMemberCount() - { + public function teamMemberCount(){ $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队下级人数满,指定商品ID', 'func_name' => 'teamMemberCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['team_member_count_to_goods']), - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - $count = MemberChild::select() - ->where('member_id', $this->uid) + ->where('member_id',$this->uid) ->uniacid() ->count(); // 指定商品的团队下级人数 $teamMemberCountToGoods = intval($this->upgradeParase['team_member_count_to_goods']); - if ($teamMemberCountToGoods > 0) { + if($teamMemberCountToGoods > 0){ $count = MemberChild::select() - ->whereHas('hasManyOrder', function ($order) use ($teamMemberCountToGoods) { - $order->whereHas('hasManyOrderGoods', function ($order_goods) use ($teamMemberCountToGoods) { - $order_goods->where('goods_id', $teamMemberCountToGoods); + ->whereHas('hasManyOrder',function($order) use ($teamMemberCountToGoods){ + $order->whereHas('hasManyOrderGoods',function($order_goods) use ($teamMemberCountToGoods){ + $order_goods->where('goods_id',$teamMemberCountToGoods); }); }) - ->where('member_id', $this->uid) + ->where('member_id',$this->uid) ->uniacid() ->count(); } $condition = $count >= $this->upgradeParase[$this->typeName]; - // 记录详情 //$this->addLogChild($count); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队下级人数满,指定商品ID', 'func_name' => 'teamMemberCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['team_member_count_to_goods']), - 'complete' => $count, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $count, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 购买指定商品 - * @author * @return bool + * @author */ - public function goods() - { + public function goods(){ $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '购买指定商品', 'func_name' => 'goods', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - if ($this->order) { - $order_goods = $this->order->hasManyOrderGoods->where('goods_id', $this->upgradeParase[$this->typeName])->where('uid',$this->uid)->first(); - if ($order_goods) { + if($this->order){ + $order_goods = $this->order->hasManyOrderGoods->where('goods_id',$this->upgradeParase[$this->typeName]) + ->where('uid',$this->uid) + ->first(); + if($order_goods){ //$this->addLogChild(1); //return true; - $condition = true; + $condition = TRUE; } } - - if (!$condition) { - $condition = OrderModel::assignGoodsToMember($this->uid, $this->upgradeParase[$this->typeName], $this->order_status); + if(!$condition){ + $condition = OrderModel::assignGoodsToMember($this->uid,$this->upgradeParase[$this->typeName],$this->order_status); } - - /*dump($this->typeName); dump($condition); - return true;*/ - - // 记录详情 + return true;*/ // 记录详情 //$this->addLogChild($condition); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '购买指定商品', 'func_name' => 'goods', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $condition, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $condition, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 购买指定商品之一 - * @author * @return bool + * @author */ - public function manyGood() - { - if (!$this->upgradeParase[$this->typeName]) { + public function manyGood(){ + if(!$this->upgradeParase[$this->typeName]){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '购买指定商品之一', 'func_name' => 'manyGood', 'condition' => '', - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $condition = OrderModel::assignManyGoodToMember($this->uid, $this->upgradeParase[$this->typeName], $this->order_status); - + $condition = OrderModel::assignManyGoodToMember($this->uid,$this->upgradeParase[$this->typeName],$this->order_status); // 记录详情 //$this->addLogChild($condition); - if (is_array($this->upgradeParase[$this->typeName])) { + if(is_array($this->upgradeParase[$this->typeName])){ $goodsIds = '|'; - foreach ($this->upgradeParase[$this->typeName] as $item) { - $goodsIds .= $item . '|'; + foreach($this->upgradeParase[$this->typeName] as $item){ + $goodsIds .= $item.'|'; } } $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '购买指定商品之一', 'func_name' => 'manyGood', 'condition' => $goodsIds, - 'complete' => $condition, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $condition, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 指定一个经销商等级下的人数满足多少人(直推) - * @author * @return bool + * @author */ - public function level() - { - $ret = explode('_', $this->typeName); - + public function level(){ + $ret = explode('_',$this->typeName); $type = intval($ret[2]); - if (!$type) { + if(!$type){ //$this->addErrorChild($ret[2]); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '指定一个经销商等级下的人数满足多少人(直推)', 'func_name' => 'level', 'condition' => '等级id['.$ret[1].']', - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - $count = TeamDividendAgencyModel::getLevelNumAgency($this->uid, $ret[1]); + $count = TeamDividendAgencyModel::getLevelNumAgency($this->uid,$ret[1]); $condition = $count >= $ret[2]; - // 记录详情 //$this->addLogChild($count, $ret[2]); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '指定一个经销商等级下的人数满足多少人(直推)', 'func_name' => 'level', 'condition' => '等级id['.$ret[1].']条件['.$ret[1].']', - 'complete' => $count, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $count, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - - public function teamDividendLevelList() - { - if (!$this->team_dividend_level_list) { - $this->team_dividend_level_list = TeamDividendLevelModel::uniacid()->get(); + public function teamDividendLevelList(){ + if(!$this->team_dividend_level_list){ + $this->team_dividend_level_list = TeamDividendLevelModel::uniacid() + ->get(); } return $this->team_dividend_level_list; } - - public function firstChildLevel(){ - $ret = explode('_', $this->typeName); - - if (!$type = intval($ret[4])) { + $ret = explode('_',$this->typeName); + if(!$type = intval($ret[4])){ $msg = '未设置升级人数,不执行'; - } elseif (!$level_id = intval($ret[3])) { + } + elseif(!$level_id = intval($ret[3])){ $msg = '未设置升级等级,不执行'; - } elseif ((!$team_dividend_level_list = $this->teamDividendLevelList()) || $team_dividend_level_list->isEmpty()) { + } + elseif((!$team_dividend_level_list = $this->teamDividendLevelList()) || $team_dividend_level_list->isEmpty()){ $msg = '经销商等级为空'; - } else { + } + else{ $msg = ''; } - - if (!$msg) { - if (!$min_level = $team_dividend_level_list->where('id', intval($level_id))->first()) { + if(!$msg){ + if(!$min_level = $team_dividend_level_list->where('id',intval($level_id)) + ->first()){ $msg = '指定经销商等级不存在'; } - - if (!$higher_ids = $this->team_dividend_level_list->where('level_weight', '>=', $min_level->level_weight)->pluck('id')->toArray()) { + if(!$higher_ids = $this->team_dividend_level_list->where('level_weight','>=',$min_level->level_weight) + ->pluck('id') + ->toArray()){ $msg = '不存在更高的等级'; } } - - if ($msg) { + if($msg){ //$this->addErrorChild($ret[3]); $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '指定权重不低于指定经销商等级的直属下级满足多少人', 'func_name' => 'firstChildLevel', 'condition' => '权重不低于等级id['.$level_id.']的直属下级人数['.$type.']', - 'complete' => '', - 'result' => '', - 'remark' => $msg + 'complete' => '', + 'result' => '', + 'remark' => $msg ]); - return false; + return FALSE; } - - $count = MemberChild::uniacid() - ->where('member_id', $this->uid) - ->where('level', 1) - ->whereHas('hasOneTeam', function ($query) use ($higher_ids) { - $query->whereIn('level', $higher_ids); + $count = MemberChild::uniacid() + ->where('member_id',$this->uid) + ->where('level',1) + ->whereHas('hasOneTeam',function($query) use ($higher_ids){ + $query->whereIn('level',$higher_ids); }) ->count(); $condition = $count >= $type; - - // 记录详情 //$this->addLogChild($count, $ret[3]); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '指定权重不低于指定经销商等级的直属下级满足多少人', 'func_name' => 'firstChildLevel', 'condition' => '权重不低于等级id['.$level_id.']直属下级人数['.$type.']', - 'complete' => $count, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $count, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 指定一个经销商等级下的人数满足多少人(团队) - * @author * @return bool + * @author */ - public function groupLevel() - { - $ret = explode('_', $this->typeName); - + public function groupLevel(){ + $ret = explode('_',$this->typeName); $type = intval($ret[3]); - if (!$type) { + if(!$type){ //$this->addErrorChild($ret[3]); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '指定一个经销商等级下的人数满足多少人(团队)', 'func_name' => 'groupLevel', 'condition' => '等级id['.$ret[2].']人数['.$type.']', - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $count = MemberChild::uniacid() - ->where('member_id', $this->uid) - ->whereHas('hasOneTeam', function ($query) use ($ret) { - $query->where('level', $ret[2]); + $count = MemberChild::uniacid() + ->where('member_id',$this->uid) + ->whereHas('hasOneTeam',function($query) use ($ret){ + $query->where('level',$ret[2]); }) ->count(); $condition = $count >= $ret[3]; - - // 记录详情 //$this->addLogChild($count, $ret[3]); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '指定一个经销商等级下的人数满足多少人(团队)', 'func_name' => 'groupLevel', 'condition' => '等级id['.$ret[2].']人数['.$type.']', - 'complete' => $count, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $count, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * 团队业绩利润满XXX元 */ - public function teamProfitAmount() - { + public function teamProfitAmount(){ $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队业绩利润满XXX元', 'func_name' => 'teamProfitAmount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $children = MemberChild::uniacid()->select(['child_id'])->where('member_id',$this->uid)->get()->toArray(); - $ids = array_column($children,'child_id'); + $children = MemberChild::uniacid() + ->select(['child_id']) + ->where('member_id',$this->uid) + ->get() + ->toArray(); + $ids = array_column($children,'child_id'); if($this->set['including_self'] == 1){ - array_push ($ids, $this->uid); + array_push($ids,$this->uid); } - $teamProfitPrice = OrderIncomeCount::uniacid() ->selectRaw('sum(price - cost_price) as profit') ->whereIn('uid',$ids) - ->where('status', '>=', $this->order_status) - ->first() - ->profit; - + ->where('status','>=',$this->order_status) + ->first()->profit; $condition = $teamProfitPrice >= $this->upgradeParase[$this->typeName]; - // 记录详情 //$this->addLogChild($teamProfitPrice); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队业绩利润满XXX元', 'func_name' => 'teamProfitAmount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $teamProfitPrice, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $teamProfitPrice, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } /** * 会员持有爱心值数量达到 */ - public function agentLove() - { + public function agentLove(){ $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '会员持有爱心值数量达到XXX', 'func_name' => 'agentLove', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - if (!app('plugins')->isEnabled('love')) { - return false; + if(!app('plugins')->isEnabled('love')){ + return FALSE; } - $total = LoveRecords::where('member_id', $this->uid)->where('type',1)->sum('change_value'); - + $total = LoveRecords::where('member_id',$this->uid) + ->where('type',1) + ->sum('change_value'); $condition = $total >= $this->upgradeParase[$this->typeName]; // 记录详情 //$this->addLogChild($teamProfitPrice); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '会员持有爱心值数量达到XXX', 'func_name' => 'agentLove', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $total, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $total, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } /** * 会员持有消费积分数量达到 */ - public function agentIntegral() - { + public function agentIntegral(){ $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '会员持有消费积分数量达到XXX', 'func_name' => 'agentIntegral', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - if (!app('plugins')->isEnabled('integral')) { - return false; + if(!app('plugins')->isEnabled('integral')){ + return FALSE; } - $total = IntegralMemberModel::where('uid', $this->uid)->value('integral'); - + $total = IntegralMemberModel::where('uid',$this->uid) + ->value('integral'); $condition = $total >= $this->upgradeParase[$this->typeName]; // 记录详情 //$this->addLogChild($teamProfitPrice); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '会员持有消费积分数量达到XXX', 'func_name' => 'agentIntegral', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $total, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $total, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - /** * @name 团队新订单数量满,指定商品ID - * @author * @return bool + * @author */ - public function teamNewOrderNumber() - { + public function teamNewOrderNumber(){ $type = intval($this->upgradeParase[$this->typeName]); - if (!$type) { + if(!$type){ //$this->addErrorChild($type); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队新订单数量满,指定商品ID', 'func_name' => 'teamNewOrderNumber', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['team_new_order_number_to_goods']), - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - $agent = TeamDividendAgencyModel::uniacid()->where('uid', $this->uid)->first(); - if (!$agent) { + $agent = TeamDividendAgencyModel::uniacid() + ->where('uid',$this->uid) + ->first(); + if(!$agent){ $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队新订单数量满,指定商品ID', 'func_name' => 'teamNewOrderNumber', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['team_new_order_number_to_goods']), - 'complete' => '', - 'result' => '', - 'remark' => '不是经销商身份不触发该升级条件' + 'complete' => '', + 'result' => '', + 'remark' => '不是经销商身份不触发该升级条件' ]); - - return false; + return FALSE; } - $build = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) + $build = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') - ->join('yz_order_goods',function ($join){ - $join->on('yz_order_goods.order_id', '=', 'yz_order.id'); + ->join('yz_order_goods',function($join){ + $join->on('yz_order_goods.order_id','=','yz_order.id'); }) - ->where('yz_order.status', '>=', $this->order_status) - ->where('yz_order.created_at', '>=', $agent->upgrade_at) - ->where('yz_member_children.member_id', $this->uid); - + ->where('yz_order.status','>=',$this->order_status) + ->where('yz_order.created_at','>=',$agent->upgrade_at) + ->where('yz_member_children.member_id',$this->uid); $countToGoods = intval($this->upgradeParase['team_new_order_number_to_goods']); - if ($countToGoods > 0) { - $build->where('yz_order_goods.goods_id', $countToGoods); + if($countToGoods > 0){ + $build->where('yz_order_goods.goods_id',$countToGoods); } - $team_goods_total = $build->get()->count(); - + $team_goods_total = $build->get() + ->count(); $logremark = '不计算自购订单'; if($this->set['including_self'] == 1){ $logremark = '计算自购订单'; //加上指定商品的条件 - $self_build = Order::where('uid', $this->uid)->where('status', '>=', $this->order_status)->where('created_at', '>=', $agent->upgrade_at); - if ($countToGoods > 0) { - $self_build ->whereHas('orderGoods',function ($query) use($countToGoods){ + $self_build = Order::where('uid',$this->uid) + ->where('status','>=',$this->order_status) + ->where('created_at','>=',$agent->upgrade_at); + if($countToGoods > 0){ + $self_build->whereHas('orderGoods',function($query) use ($countToGoods){ $query->where('goods_id',$countToGoods); }); } $team_goods_total += $self_build->count(); } $condition = $team_goods_total >= $this->upgradeParase[$this->typeName]; - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队新订单数量满,指定商品ID['.$logremark.']', 'func_name' => 'teamNewOrderNumber', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['team_new_order_number_to_goods']), - 'complete' => $team_goods_total, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $team_goods_total, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - - if ($condition) { - return true; + if($condition){ + return TRUE; } - return false; + return FALSE; } - - public function dividendAndPeerSum() - { - $type = bcadd($this->upgradeParase[$this->typeName] ?: 0, 0, 2); - if (bccomp($type, 0, 2) != 1) { + public function dividendAndPeerSum(){ + $type = bcadd($this->upgradeParase[$this->typeName] ?: 0,0,2); + if(bccomp($type,0,2) != 1){ $this->uplogService->pushCondition([ - 'type' => $this->typeName, - 'type_name' => '个人获得佣金(含经销商提成和平级奖)满' . $type, + 'type' => $this->typeName, + 'type_name' => '个人获得佣金(含经销商提成和平级奖)满'.$type, 'func_name' => 'dividendAndPeerSum', 'condition' => $type, - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return false; + return FALSE; } - $sum = TeamDividendModel::uniacid()->where('member_id', $this->uid) - ->where('status', 1) - ->whereIn('type', [0, 1]) + $sum = TeamDividendModel::uniacid() + ->where('member_id',$this->uid) + ->where('status',1) + ->whereIn('type',[0,1]) ->sum('dividend_amount'); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, - 'type_name' => '个人获得佣金(含经销商提成和平级奖)满' . $type, + 'type' => $this->typeName, + 'type_name' => '个人获得佣金(含经销商提成和平级奖)满'.$type, 'func_name' => 'dividendAndPeerSum', 'condition' => $type, - 'complete' => $sum, - 'result' => '', - 'remark' => bccomp($sum, $type, 2) == -1 ? '不满足条件' : '满足条件', + 'complete' => $sum, + 'result' => '', + 'remark' => bccomp($sum,$type,2) == -1 ? '不满足条件' : '满足条件', ]); - - return bccomp($sum, $type, 2) == -1 ? false : true; - + return bccomp($sum,$type,2) == -1 ? FALSE : TRUE; } - - - public function groupLoveAfterBlack() - { + public function groupLoveAfterBlack(){ $msg = ''; - if (!app('plugins')->isEnabled('love')) { + if(!app('plugins')->isEnabled('love')){ $msg = '爱心值插件未开启'; } - - $type = bcadd($this->upgradeParase[$this->typeName] ?: 0, 0, 2); - if (bccomp($type, 0, 2) != 1) { + $type = bcadd($this->upgradeParase[$this->typeName] ?: 0,0,2); + if(bccomp($type,0,2) != 1){ $msg = '未设置条件,不执行'; } - - if ($msg){ + if($msg){ $this->uplogService->pushCondition([ - 'type' => $this->typeName, - 'type_name' => '移出黑名单后团队累计自购赠送冻结' . (defined('LOVE_NAME') ? LOVE_NAME : '爱心值') . '满' . $type, + 'type' => $this->typeName, + 'type_name' => '移出黑名单后团队累计自购赠送冻结'.(defined('LOVE_NAME') ? LOVE_NAME : '爱心值').'满'.$type, 'func_name' => 'groupLoveAfterBlack', 'condition' => $type, - 'complete' => '', - 'result' => '', - 'remark' => $msg + 'complete' => '', + 'result' => '', + 'remark' => $msg ]); - return false; + return FALSE; } - - $sum = 0; - $group_ids = MemberChildren::where('member_id', $this->uid)->pluck('child_id')->toArray(); - if ($group_ids) { + $sum = 0; + $group_ids = MemberChildren::where('member_id',$this->uid) + ->pluck('child_id') + ->toArray(); + if($group_ids){ $black_time = 0; - if ($agent = TeamDividendAgencyModel::where('member_id',$this->uid)->first()){ - if ($agent->black_time){ + if($agent = TeamDividendAgencyModel::where('member_id',$this->uid) + ->first()){ + if($agent->black_time){ $black_time = $agent->black_time; } } - $sum = LoveRecords::whereIn('member_id', $group_ids) - ->where('source', ConstService::SOURCE_AWARD) - ->where('value_type', ConstService::VALUE_TYPE_FROZE) + $sum = LoveRecords::whereIn('member_id',$group_ids) + ->where('source',ConstService::SOURCE_AWARD) + ->where('value_type',ConstService::VALUE_TYPE_FROZE) ->where('created_at','>',$black_time) ->sum('change_value'); } - $this->uplogService->pushCondition([ - 'type' => $this->typeName, - 'type_name' => '移出黑名单后团队累计自购赠送冻结' . (defined('LOVE_NAME') ? LOVE_NAME : '爱心值') . '满' . $type, + 'type' => $this->typeName, + 'type_name' => '移出黑名单后团队累计自购赠送冻结'.(defined('LOVE_NAME') ? LOVE_NAME : '爱心值').'满'.$type, 'func_name' => 'groupLove', 'condition' => $type, - 'complete' => $sum, - 'result' => '', - 'remark' => bccomp($sum, $type, 2) == -1 ? '不满足条件' : '满足条件', + 'complete' => $sum, + 'result' => '', + 'remark' => bccomp($sum,$type,2) == -1 ? '不满足条件' : '满足条件', ]); - - return bccomp($sum, $type, 2) == -1 ? false : true; + return bccomp($sum,$type,2) == -1 ? FALSE : TRUE; } - - - public function groupLove() - { + public function groupLove(){ $msg = ''; - if (!app('plugins')->isEnabled('love')) { + if(!app('plugins')->isEnabled('love')){ $msg = '爱心值插件未开启'; } - - $type = bcadd($this->upgradeParase[$this->typeName] ?: 0, 0, 2); - if (bccomp($type, 0, 2) != 1) { + $type = bcadd($this->upgradeParase[$this->typeName] ?: 0,0,2); + if(bccomp($type,0,2) != 1){ $msg = '未设置条件,不执行'; } - - if ($msg){ + if($msg){ $this->uplogService->pushCondition([ - 'type' => $this->typeName, - 'type_name' => '团队累计自购赠送冻结' . (defined('LOVE_NAME') ? LOVE_NAME : '爱心值') . '满' . $type, + 'type' => $this->typeName, + 'type_name' => '团队累计自购赠送冻结'.(defined('LOVE_NAME') ? LOVE_NAME : '爱心值').'满'.$type, 'func_name' => 'groupLove', 'condition' => $type, - 'complete' => '', - 'result' => '', - 'remark' => $msg + 'complete' => '', + 'result' => '', + 'remark' => $msg ]); - return false; + return FALSE; } - - $sum = 0; - $group_ids = MemberChildren::where('member_id', $this->uid)->pluck('child_id')->toArray(); - if ($group_ids) { - $sum = LoveRecords::whereIn('member_id', $group_ids) - ->where('source', ConstService::SOURCE_AWARD) - ->where('value_type', ConstService::VALUE_TYPE_FROZE) + $sum = 0; + $group_ids = MemberChildren::where('member_id',$this->uid) + ->pluck('child_id') + ->toArray(); + if($group_ids){ + $sum = LoveRecords::whereIn('member_id',$group_ids) + ->where('source',ConstService::SOURCE_AWARD) + ->where('value_type',ConstService::VALUE_TYPE_FROZE) ->sum('change_value'); } - $this->uplogService->pushCondition([ - 'type' => $this->typeName, - 'type_name' => '团队累计冻结' . (defined('LOVE_NAME') ? LOVE_NAME : '爱心值') . '满' . $type, + 'type' => $this->typeName, + 'type_name' => '团队累计冻结'.(defined('LOVE_NAME') ? LOVE_NAME : '爱心值').'满'.$type, 'func_name' => 'groupLove', 'condition' => $type, - 'complete' => $sum, - 'result' => '', - 'remark' => bccomp($sum, $type, 2) == -1 ? '不满足条件' : '满足条件', + 'complete' => $sum, + 'result' => '', + 'remark' => bccomp($sum,$type,2) == -1 ? '不满足条件' : '满足条件', ]); - - return bccomp($sum, $type, 2) == -1 ? false : true; + return bccomp($sum,$type,2) == -1 ? FALSE : TRUE; } - - - /** * 几条线 $this->upgradeParase['level_line_num'] * 等级id $this->upgradeParase['level_line_level_id'] @@ -1935,119 +1686,98 @@ class UpgrateConditionService * 每条线必须有多少会员以上 $this->upgradeParase['level_line_people'] * @return bool */ - public function levelLine() - { + public function levelLine(){ // 0条线 - if ($this->upgradeParase['level_line_num'] <= 0) { + if($this->upgradeParase['level_line_num'] <= 0){ //$this->addErrorChild($this->upgradeParase['level_line_num']); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该等级', 'func_name' => 'levelLine', 'condition' => '', - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - \Log::debug('经销商升级条件:几条线', $this->upgradeParase); + \Log::debug('经销商升级条件:几条线',$this->upgradeParase); //查询 会员一级下线 的集合 $firstLowers = YzMemberModel::select('member_id') - ->where('parent_id', $this->uid) + ->where('parent_id',$this->uid) ->get(); - \Log::debug('经销商升级条件:几条线,下级', $firstLowers); + \Log::debug('经销商升级条件:几条线,下级',$firstLowers); // 没有直属下级 返回 false - if ($firstLowers->isEmpty()) { + if($firstLowers->isEmpty()){ //$this->addErrorChild(0); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该等级', 'func_name' => 'levelLine', 'condition' => '几条线['.$this->upgradeParase['level_line_num'].'],没有直属下级', - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - // 升级条件的等级id $levelId = $this->upgradeParase['level_line_level_id']; - //人数为空或0默认赋值1 $this->upgradeParase['level_line_people'] = $this->upgradeParase['level_line_people'] ?: 1; - $ret = 0; - - foreach ($firstLowers as $firstLower) { + $ret = 0; + foreach($firstLowers as $firstLower){ // 执行次数 大于等于 条件设置的几条线 /*if ($num >= $this->upgradeParase['level_line_num']) { break; } $num += 1;*/ - $people = 0; - $buildRet = $this->getBuild($levelId); - //一级下级 - $selfRet = $buildRet['selfBuild']->where('uid', $firstLower->member_id)->first(); - if ($selfRet) { + $selfRet = $buildRet['selfBuild']->where('uid',$firstLower->member_id) + ->first(); + if($selfRet){ $people += 1; } - - $count = $buildRet['build'] - ->where('member_id', $firstLower->member_id) + $count = $buildRet['build']->where('member_id',$firstLower->member_id) ->count(); - - if ($count > 0) { + if($count > 0){ $people += $count; } // 满足指定人数 - if ($people >= $this->upgradeParase['level_line_people']) { + if($people >= $this->upgradeParase['level_line_people']){ $ret += 1; continue; } - - } - - if ($ret >= $this->upgradeParase['level_line_num']) { + if($ret >= $this->upgradeParase['level_line_num']){ //$this->addLogChild($ret, $this->upgradeParase['level_line_num']); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该等级', 'func_name' => 'levelLine', 'condition' => '几条线['.$this->upgradeParase['level_line_num'].']需满足人数['.$this->upgradeParase['level_line_people'].']', - 'complete' => $ret, - 'result' => '', - 'remark' => '满足条件' + 'complete' => $ret, + 'result' => '', + 'remark' => '满足条件' ]); - - return true; - } else { + return TRUE; + } + else{ //$this->addLogChild($ret, $this->upgradeParase['level_line_num']); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该等级', 'func_name' => 'levelLine', 'condition' => '几条线['.$this->upgradeParase['level_line_num'].']需满足人数['.$this->upgradeParase['level_line_people'].']', - 'complete' => $ret, - 'result' => '', - 'remark' => '不满足条件' + 'complete' => $ret, + 'result' => '', + 'remark' => '不满足条件' ]); - - return false; + return FALSE; } } - /** * 区域代理 * 几条线 $this->upgradeParase['level_line_area_num'] @@ -2057,185 +1787,222 @@ class UpgrateConditionService * 每条线必须有多少会员以上 $this->upgradeParase['level_line_area_people'] * @return bool */ - public function levelLineArea() - { - if (!app('plugins')->isEnabled('area-dividend')) return false; + public function levelLineArea(){ + if(!app('plugins')->isEnabled('area-dividend')) return FALSE; // 0条线 - if ($this->upgradeParase['level_line_area_num'] <= 0) { + if($this->upgradeParase['level_line_area_num'] <= 0){ $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该区域等级', 'func_name' => 'levelLineArea', 'condition' => '', - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - - \Log::debug('经销商升级条件:区域几条线', $this->upgradeParase); + \Log::debug('经销商升级条件:区域几条线',$this->upgradeParase); //查询 会员一级下线 的集合 $firstLowers = YzMemberModel::select('member_id') - ->where('parent_id', $this->uid) + ->where('parent_id',$this->uid) ->get(); - \Log::debug('经销商升级条件:区域几条线,下级', $firstLowers); + \Log::debug('经销商升级条件:区域几条线,下级',$firstLowers); // 没有直属下级 返回 false - if ($firstLowers->isEmpty()) { + if($firstLowers->isEmpty()){ $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足区域该等级', 'func_name' => 'levelLineArea', 'condition' => '几条线['.$this->upgradeParase['level_line_area_num'].'],没有直属下级', - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - - return false; + return FALSE; } - // 升级条件的等级id $levelId = $this->upgradeParase['level_line_area_level_id']; - //人数为空或0默认赋值1 $this->upgradeParase['level_line_area_people'] = $this->upgradeParase['level_line_area_people'] ?: 1; - $ret = 0; - - foreach ($firstLowers as $firstLower) { + $ret = 0; + foreach($firstLowers as $firstLower){ // 执行次数 大于等于 条件设置的几条线 - $people = 0; - $buildRet = $this->getAreaBuild($levelId); - //一级下级 - $selfRet = $buildRet['selfBuild']->where('member_id', $firstLower->member_id)->first(); - if ($selfRet) { + $selfRet = $buildRet['selfBuild']->where('member_id',$firstLower->member_id) + ->first(); + if($selfRet){ $people += 1; } - - $count = $buildRet['build'] - ->where('yz_area_dividend_agent.member_id', $firstLower->member_id) + $count = $buildRet['build']->where('yz_area_dividend_agent.member_id',$firstLower->member_id) ->count(); - - if ($count > 0) { + if($count > 0){ $people += $count; } // 满足指定人数 - if ($people >= $this->upgradeParase['level_line_area_people']) { + if($people >= $this->upgradeParase['level_line_area_people']){ $ret += 1; continue; } - - } - - if ($ret >= $this->upgradeParase['level_line_area_num']) { + if($ret >= $this->upgradeParase['level_line_area_num']){ $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该区域等级', 'func_name' => 'levelLineArea', 'condition' => '几条线['.$this->upgradeParase['level_line_area_num'].']需满足人数['.$this->upgradeParase['level_line_area_people'].']', - 'complete' => $ret, - 'result' => '', - 'remark' => '满足条件' + 'complete' => $ret, + 'result' => '', + 'remark' => '满足条件' ]); - - return true; - } else { + return TRUE; + } + else{ $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该区域等级', 'func_name' => 'levelLineArea', 'condition' => '几条线['.$this->upgradeParase['level_line_area_num'].']需满足人数['.$this->upgradeParase['level_line_area_people'].']', - 'complete' => $ret, - 'result' => '', - 'remark' => '不满足条件' + 'complete' => $ret, + 'result' => '', + 'remark' => '不满足条件' ]); - - return false; + return FALSE; } } - - - - - private function getBuild($levelId) - { + private function getBuild($levelId){ $nowLevel = TeamDividendLevelModel::select() - ->where('id', $levelId) + ->where('id',$levelId) ->first(); // 本级 else 以上 - if ($this->upgradeParase['oneself'] == 0) { + if($this->upgradeParase['oneself'] == 0){ $build = MemberChild::select(['yz_member_children.child_id','yz_team_dividend_agency.level','yz_member_children.member_id']) ->join('yz_team_dividend_agency','yz_member_children.child_id','yz_team_dividend_agency.uid') ->where('yz_team_dividend_agency.level',$levelId); -// ->whereHas('hasOneTeam', function ($teamModel) use ($levelId) { -// $teamModel->where('level', $levelId); -// }); + // ->whereHas('hasOneTeam', function ($teamModel) use ($levelId) { + // $teamModel->where('level', $levelId); + // }); $selfBuild = TeamDividendAgencyModel::select() - ->where('level', $nowLevel ? $levelId : -99); - } else { + ->where('level',$nowLevel ? $levelId : -99); + } + else{ // 条件等级 // 比 大于等级权重的等级id的集合 $levelIds = [-999]; - if ($nowLevel){ + if($nowLevel){ $levelIds = TeamDividendLevelModel::select() - ->where('level_weight', '>=', $nowLevel->level_weight) + ->where('level_weight','>=',$nowLevel->level_weight) ->pluck('id') ->toArray(); // 把 条件等级id 加入数组 $levelIds[] = $levelId; } - $build = MemberChild::select(['yz_member_children.child_id','yz_team_dividend_agency.level','yz_member_children.member_id']) + $build = MemberChild::select(['yz_member_children.child_id','yz_team_dividend_agency.level','yz_member_children.member_id']) ->join('yz_team_dividend_agency','yz_member_children.child_id','yz_team_dividend_agency.uid') ->whereIn('yz_team_dividend_agency.level',$levelIds); $selfBuild = TeamDividendAgencyModel::select() - ->whereIn('level', $levelIds); + ->whereIn('level',$levelIds); } return [ - 'build' => $build, + 'build' => $build, 'selfBuild' => $selfBuild ]; } - - private function getAreaBuild($levelId) - { + private function getAreaBuild($levelId){ // 本级 else 以上 -// if ($this->upgradeParase['area_oneself'] == 0) { - $build = MemberChild::select(['yz_member_children.child_id','yz_area_dividend_agent.agent_level','yz_member_children.member_id']) - ->join('yz_area_dividend_agent','yz_member_children.child_id','yz_area_dividend_agent.member_id') - ->where('yz_area_dividend_agent.agent_level',$levelId); - - $selfBuild = AreaDividendAgent::select() - ->where('agent_level', $levelId); -// } else { - // 条件等级 - // 比 大于等级权重的等级id的集合 -// $levelIds = []; -// for ($i=1;$i<5;$i++) { -// if ($i >= $levelId) { -// // 把 条件等级id 加入数组 -// $levelIds[] = $i; -// } -// } -// -// $build = MemberChild::select(['yz_member_children.child_id','yz_area_dividend_agent.agent_level','yz_member_children.member_id']) -// ->join('yz_area_dividend_agent','yz_member_children.child_id','yz_area_dividend_agent.member_id') -// ->whereIn('yz_area_dividend_agent.agent_level',$levelId); -// $selfBuild = AreaDividendAgent::select() -// ->whereIn('agent_level', $levelIds); -// } + // if ($this->upgradeParase['area_oneself'] == 0) { + $build = MemberChild::select(['yz_member_children.child_id','yz_area_dividend_agent.agent_level','yz_member_children.member_id']) + ->join('yz_area_dividend_agent','yz_member_children.child_id','yz_area_dividend_agent.member_id') + ->where('yz_area_dividend_agent.agent_level',$levelId); + $selfBuild = AreaDividendAgent::select() + ->where('agent_level',$levelId); + // } else { + // 条件等级 + // 比 大于等级权重的等级id的集合 + // $levelIds = []; + // for ($i=1;$i<5;$i++) { + // if ($i >= $levelId) { + // // 把 条件等级id 加入数组 + // $levelIds[] = $i; + // } + // } + // + // $build = MemberChild::select(['yz_member_children.child_id','yz_area_dividend_agent.agent_level','yz_member_children.member_id']) + // ->join('yz_area_dividend_agent','yz_member_children.child_id','yz_area_dividend_agent.member_id') + // ->whereIn('yz_area_dividend_agent.agent_level',$levelId); + // $selfBuild = AreaDividendAgent::select() + // ->whereIn('agent_level', $levelIds); + // } return [ - 'build' => $build, + 'build' => $build, 'selfBuild' => $selfBuild ]; } + /** + * Common: 升级条件 - 直推间推多少人 + * Author: wu-hui + * Time: 2023/10/25 14:37 + * @return bool + */ + public function oneOrTwo(){ + try{ + // \Log::debug('经销商升级 - 升级条件 - 直推间推人数 - 开始处理:',$this->uid); + $upgradeSet = $this->upgradeParase[$this->typeName]; + // \Log::debug('经销商升级 - 升级条件 - 直推间推人数 - 基本设置:',$upgradeSet); + if(!$upgradeSet){ + $this->uplogService->pushCondition([ + 'type' => $this->typeName, + 'type_name' => '直推间推人数', + 'func_name' => 'oneOrTwo', + 'condition' => '', + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' + ]); + return FALSE; + } + // 条件判断 + $oneLvAndTwoLvNum = MemberParent::getOneOrTwoList($this->uid); + $subMemberIds = array_column($oneLvAndTwoLvNum,'member_id'); + // \Log::debug('经销商升级 - 升级条件 - 直推间推人数 - 下级UID:',$subMemberIds); + // 获取 直推间推成员中有多少 现在或者曾经是某个等级的经销商 + $hasNum = (int)Uplog::uniacid() + ->where('after_level_id',$upgradeSet['one_or_two_level_id']) + ->whereIn('uid',$subMemberIds) + ->count(DB::raw('DISTINCT(uid)')); + // \Log::debug('经销商升级 - 升级条件 - 直推间推人数 - 人数:',$hasNum); + // 判断:是否达到升级要求 需求人数小于等于当前人数-达成升级条件 + $people = (int)$upgradeSet['one_or_two_people'] > 0 ? (int)$upgradeSet['one_or_two_people'] : 1; + $isReach = (boolean)($people <= $hasNum); + $this->uplogService->pushCondition([ + 'type' => $this->typeName, + 'type_name' => '直推间推人数', + 'func_name' => 'oneOrTwo', + 'condition' => '', + 'result' => '', + 'remark' => $isReach ? '满足条件' : '不满足条件' + ]); + + \Log::debug('经销商升级 - 升级条件 - 直推间推人数 - 是否达到条件:',[ + '需求人数' => $people, + '当前人数' => $hasNum, + 'is_reach' => $isReach + ]); + if($isReach) return true; + + }catch(\Exception $e){ + \Log::debug('经销商升级 - 升级条件 - 直推间推人数 - 错误:',$e->getMessage()); + } + + return false; + } + + } \ No newline at end of file diff --git a/plugins/team-dividend/views/admin/level-set-add.blade.php b/plugins/team-dividend/views/admin/level-set-add.blade.php index 6a05c962..4b4bb586 100644 --- a/plugins/team-dividend/views/admin/level-set-add.blade.php +++ b/plugins/team-dividend/views/admin/level-set-add.blade.php @@ -707,25 +707,28 @@ {{-- 直推间推 某个等级 满多少人 START --}} - {{--