uid = $uid; $this->set = $set; $this->upgradeParase = $upgradeParase; $this->typeName = $typeName; $this->order_status = $order_status; $this->order = $order; \YunShop::app()->uniacid = $uniacid; $this->levelType = $levelType; $this->uplogService = $uplogService; } private function addLogChild($result,$condition = NULL){ $data = [ //'log_id' => $this->log_id, 'type_name' => $this->typeName, 'result' => $result ]; if($condition == NULL){ $data['condition'] = $this->upgradeParase[$this->typeName]; } else{ $data['condition'] = $condition; } // 记录详情 LogChild::create($data); } private function addErrorChild($condition){ $data = [ //'log_id' => $this->log_id, 'type_name' => $this->typeName, 'result' => -1 ]; if($condition == NULL){ $data['condition'] = $this->upgradeParase[$this->typeName]; } else{ $data['condition'] = $condition; } // 记录详情 LogChild::create($data); } /** * @name 一级客户订单金额满,不加[订单状态]限制 * @return bool * @author */ public function firstMoney(){ $type = intval($this->upgradeParase[$this->typeName]); if(Setting::get('plugin.team_dividend.level_up_choose') == 1){ $column = 'yz_order.goods_price'; $amount_name = '订单商品现价'; } else{ $column = 'yz_order.price'; $amount_name = '订单实付金额'; } if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '一级客户'.$amount_name.'满', 'func_name' => 'firstMoney', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); 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) ->sum($column); $condition = $orderPrice >= $this->upgradeParase[$this->typeName]; // 记录详情 //$this->addLogChild($orderPrice); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '一级客户'.$amount_name.'满', 'func_name' => 'firstMoney', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $orderPrice, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 一级客户订单数量满,指定商品ID,不加[订单状态]限制 * @return bool * @author */ public function firstOrderCount(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ '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' => '未设置条件,不执行' ]); 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) ->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']) ->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'); }) ->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_name' => '一级客户订单数量满,指定商品ID', 'func_name' => 'firstOrderCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_order_count_to_goods']), 'complete' => $orderCount, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 二级客户订单金额满or一、二级客户订单金额满,不加[订单状态]限制 order_money_2 or order_money * @return bool * @author */ 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'; $amount_name = '订单实付金额'; } $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '一、二级客户'.$amount_name.'满', 'func_name' => 'orderMoney', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } // order_money_2 $ret[2] = 2 or order_money $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]); } $orderPrice = $build->sum($column); $condition = $orderPrice >= $this->upgradeParase[$this->typeName]; // 记录详情 //$this->addLogChild($orderPrice); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '一、二级客户'.$amount_name.'满['.$logremark.']', 'func_name' => 'orderMoney', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $orderPrice, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 二级客户订单数量满,不加[订单状态]限制 * @return bool * @author */ public function orderNum(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '二级客户订单数量满', 'func_name' => 'orderNum', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); 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])) ->count('yz_order.id'); $condition = $orderCount >= $this->upgradeParase[$this->typeName]; // 记录详情 //$this->addLogChild($orderCount); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '二级客户订单数量满', 'func_name' => 'orderNum', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $orderCount, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 一、二级客户订单数量满,不加[订单状态]限制 * @return bool * @author */ public function orderCount(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '一、二级客户订单数量满', 'func_name' => 'orderCount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); 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]) ->count('yz_order.id'); $condition = $orderPrice >= $this->upgradeParase[$this->typeName]; // 记录详情 //$this->addLogChild($orderPrice); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '一、二级客户订单数量满', 'func_name' => 'orderCount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $orderPrice, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 直推参与认购人数达到xx人 * @return bool * @author */ public function firstLowerSubscription(){ if(!app('plugins')->isEnabled('subscription')){ return FALSE; } $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '直推参与认购人数达到xx人', 'func_name' => 'firstLowerSubscription', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } $childIds = MemberChild::select() ->where('member_id',$this->uid) ->where('level',1) ->pluck('child_id'); if($childIds->isEmpty()){ return FALSE; } $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_name' => '直推参与认购人数达到['.$count.']人', 'func_name' => 'firstLowerSubscription', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $count, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 团队参与认购额度累计达到xx额度 * @return bool * @author */ public function teamSubscription(){ if(!app('plugins')->isEnabled('subscription')){ return FALSE; } $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '团队参与认购额度累计达到xx额度', 'func_name' => 'teamSubscription', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); 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') ->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_name' => '团队参与认购额度累计达到['.$total.']额度', 'func_name' => 'teamSubscription', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $total, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 团队业绩金额满,[订单状态]-已完成 * @return bool * @author */ public function teamOrderAmount(){ $type = intval($this->upgradeParase[$this->typeName]); if(Setting::get('plugin.team_dividend.level_up_choose') == 1){ $column = 'yz_order.goods_price'; $amount_name = '订单商品现价'; }else{ $column = 'yz_order.price'; $amount_name = '订单实付金额'; } if(!$type){ $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '团队业绩'.$amount_name.'满', 'func_name' => 'teamOrderAmount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } // 获取直推下级列表 $subIds = MemberChild::uniacid() ->where('level',1) ->where('member_id',$this->uid) ->pluck('child_id') ->toArray(); $subPerformance = [];// 每条线的业绩 foreach($subIds as $subUid){ $lineAllUid = MemberChild::uniacid()->where('member_id',$subUid)->pluck('child_id')->toArray(); $lineAllUid[] = $subUid; $subPerformance[$subUid] = 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',$lineAllUid) ->where('yz_order.status','>=',$this->order_status) ->where('yz_goods_cultural_space.is_open', $this->levelType == 1 ? 1 : 0) ->sum(Setting::get('plugin.team_dividend.level_up_choose') == 1 ? 'yz_order_goods.goods_price' : 'yz_order_goods.payment_amount'); // $subPerformance[$subUid] = Order::whereIn('uid',$lineAllUid)->where('status','>=',$this->order_status)->sum($column); } // 计算团队总业绩 判断:是否去除最大业绩 $maxAmount = 0; if((int)$this->upgradeParase['team_order_amount_close_max'] == 1) $maxAmount = max($subPerformance); $teamOrderPrice = (float)sprintf("%.2f",array_sum($subPerformance) - $maxAmount); // 判断:是否开启自购 $logremark = '不计算自购订单'; if($this->set['including_self'] == 1){ $logremark = '计算自购订单'; $teamOrderPrice += Order::where('uid',$this->uid) ->where('status','>=',$this->order_status) ->sum($column); } // 判断:是否符合条件 $condition = $teamOrderPrice >= $this->upgradeParase[$this->typeName]; $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '团队业绩'.$amount_name.'满['.$logremark.']', 'func_name' => 'teamOrderAmount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $teamOrderPrice, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition) return TRUE; return FALSE; } /** * @name 团队自营订单实付金额满,[订单状态]-已完成 * @return bool * @author */ public function teamShopOrderAmount(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '团队自营订单实付金额满', 'func_name' => 'teamShopOrderAmount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); 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) ->where('yz_member_children.member_id',$this->uid) ->sum('yz_order.price'); $logremark = '不计算自购订单'; if($this->set['including_self'] == 1){ $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_name' => '团队自营订单实付金额满['.$logremark.']', 'func_name' => 'teamShopOrderAmount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $teamOrderPrice, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 团队商品数量满,指定商品ID,[订单状态]-已完成 * @return bool * @author */ public function teamGoodsAmount(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ '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' => '未设置条件,不执行' ]); return FALSE; } $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'); }) ->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); } $team_goods_total = $build->sum('yz_order_goods.total'); $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){ $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_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 ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 直属经销商人数,指定商品ID * @return bool * @author */ public function firstLowerTeamCount(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ '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' => '未设置条件,不执行' ]); return FALSE; } $agentCount = TeamDividendAgencyModel::getFirstAgencyNum($this->uid); $firstLowerTeamCountToGoods = intval($this->upgradeParase['first_lower_team_count_to_goods']); if($firstLowerTeamCountToGoods > 0){ $agentCount = MemberChild::select() ->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); }); }) ->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_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 ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 团队经销商人数 * @return bool * @author */ public function allLowerTeamCount(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '团队经销商人数', 'func_name' => 'allLowerTeamCount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } $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(); } $condition = $agentCount >= $this->upgradeParase[$this->typeName]; // 记录详情 //$this->addLogChild($agentCount); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '团队经销商人数', 'func_name' => 'allLowerTeamCount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $agentCount, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 一级客户人数满 * @return bool * @author */ public function firstLowerCount(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '一级客户人数满', 'func_name' => 'firstLowerCount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } $fisrtCount = MemberChild::select() ->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_name' => '一级客户人数满', 'func_name' => 'firstLowerCount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $fisrtCount, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 自购订单金额满 * @return bool * @author */ public function selfBuyMoney(){ $type = intval($this->upgradeParase[$this->typeName]); if(Setting::get('plugin.team_dividend.level_up_choose') == 1){ $column = 'yz_order.goods_price'; $amount_name = '订单商品现价'; } else{ $column = 'yz_order.price'; $amount_name = '订单实付金额'; } if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '自购'.$amount_name.'满', 'func_name' => 'selfBuyMoney', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } $orderPrice = Order::where('uid',$this->uid) ->where('status','>=',$this->order_status) ->sum($column); $condition = $orderPrice >= $this->upgradeParase[$this->typeName]; // 记录详情 //$this->addLogChild($orderPrice); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '自购'.$amount_name.'满', 'func_name' => 'selfBuyMoney', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $orderPrice, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 自购订单数量满 * @return bool * @author */ public function selfBuyCount(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '自购订单数量满', 'func_name' => 'selfBuyCount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } $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_name' => '自购订单数量满', 'func_name' => 'selfBuyCount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $orderCount, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 结算分红金额满 * @return bool * @author */ public function settleMoney(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '结算分红金额满', 'func_name' => 'settleMoney', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } $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_name' => '结算分红金额满', 'func_name' => 'settleMoney', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $amount, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 一级客户消费满first_cost_count,人数达到 first_cost_num * @return bool * @author */ public function firstCostCount(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type || !intval($this->upgradeParase['first_cost_num'])){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '一级客户消费满,人数达到', 'func_name' => 'firstCostCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_cost_num']), 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); 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]){ $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', 'result' => $count, 'condition' => $this->upgradeParase['first_cost_num'] ]; LogChild::create($data);*/ $this->uplogService->pushCondition([ '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 ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 一级客户消费满first_second_cost_count,人数达到 first_second_cost_num * @return bool * @author */ public function firstSecondCostCount(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type || !intval($this->upgradeParase['first_second_cost_num'])){ $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '一、二级客户消费满,人数达到', 'func_name' => 'firstSecondCostCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_second_cost_num']), 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); 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]){ $count++; if($count >= $this->upgradeParase['first_second_cost_num']){ $condition = TRUE; break; } } } } $this->uplogService->pushCondition([ '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 ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 团队商家数量满 * @return bool * @author */ public function teamMerchantsCount(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '团队商家数量满', 'func_name' => 'teamMerchantsCount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } $exist_supplier = app('plugins')->isEnabled('supplier'); $exist_store = app('plugins')->isEnabled('store-cashier'); $count = 0; if($exist_supplier || $exist_store){ $childIds = MemberChild::select('child_id') ->where('member_id',$this->uid) ->pluck('child_id'); if($exist_supplier){ $supplierCount = Supplier::whereIn('member_id',$childIds) ->count(); $count += $supplierCount; } if($exist_store){ $storeCount = Store::whereIn('uid',$childIds) ->count(); $count += $storeCount; } $condition = $count >= $this->upgradeParase[$this->typeName]; // 记录详情 //$this->addLogChild($count); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '团队商家数量满', 'func_name' => 'teamMerchantsCount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $count, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } } $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '团队商家数量满', 'func_name' => 'teamMerchantsCount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行[没开启供应商或门店插件(供应商状态:'.$exist_supplier.'|门店状态'.$exist_store.')]' ]); return FALSE; } /** * @name 团队下级人数满,指定商品ID * @return bool * @author */ public function teamMemberCount(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ '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' => '未设置条件,不执行' ]); return FALSE; } $count = MemberChild::select() ->where('member_id',$this->uid) ->uniacid() ->count(); // 指定商品的团队下级人数 $teamMemberCountToGoods = intval($this->upgradeParase['team_member_count_to_goods']); 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); }); }) ->where('member_id',$this->uid) ->uniacid() ->count(); } $condition = $count >= $this->upgradeParase[$this->typeName]; // 记录详情 //$this->addLogChild($count); $this->uplogService->pushCondition([ '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 ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 购买指定商品 * @return bool * @author */ public function goods(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '购买指定商品', 'func_name' => 'goods', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); 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){ //$this->addLogChild(1); //return true; $condition = TRUE; } } if(!$condition){ $condition = OrderModel::assignGoodsToMember($this->uid,$this->upgradeParase[$this->typeName],$this->order_status); } /*dump($this->typeName); dump($condition); return true;*/ // 记录详情 //$this->addLogChild($condition); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '购买指定商品', 'func_name' => 'goods', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $condition, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 购买指定商品之一 * @return bool * @author */ public function manyGood(){ if(!$this->upgradeParase[$this->typeName]){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '购买指定商品之一', 'func_name' => 'manyGood', 'condition' => '', 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } $condition = OrderModel::assignManyGoodToMember($this->uid,$this->upgradeParase[$this->typeName],$this->order_status); // 记录详情 //$this->addLogChild($condition); if(is_array($this->upgradeParase[$this->typeName])){ $goodsIds = '|'; foreach($this->upgradeParase[$this->typeName] as $item){ $goodsIds .= $item.'|'; } } $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '购买指定商品之一', 'func_name' => 'manyGood', 'condition' => $goodsIds, 'complete' => $condition, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 指定一个经销商等级下的人数满足多少人(直推) * @return bool * @author */ public function level(){ $ret = explode('_',$this->typeName); $type = intval($ret[2]); if(!$type){ //$this->addErrorChild($ret[2]); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '指定一个经销商等级下的人数满足多少人(直推)', 'func_name' => 'level', 'condition' => '等级id['.$ret[1].']', 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } $count = TeamDividendAgencyModel::getLevelNumAgency($this->uid,$ret[1]); $condition = $count >= $ret[2]; // 记录详情 //$this->addLogChild($count, $ret[2]); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '指定一个经销商等级下的人数满足多少人(直推)', 'func_name' => 'level', 'condition' => '等级id['.$ret[1].']条件['.$ret[1].']', 'complete' => $count, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } 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])){ $msg = '未设置升级人数,不执行'; } elseif(!$level_id = intval($ret[3])){ $msg = '未设置升级等级,不执行'; } elseif((!$team_dividend_level_list = $this->teamDividendLevelList()) || $team_dividend_level_list->isEmpty()){ $msg = '经销商等级为空'; } else{ $msg = ''; } 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()){ $msg = '不存在更高的等级'; } } if($msg){ //$this->addErrorChild($ret[3]); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '指定权重不低于指定经销商等级的直属下级满足多少人', 'func_name' => 'firstChildLevel', 'condition' => '权重不低于等级id['.$level_id.']的直属下级人数['.$type.']', 'complete' => '', 'result' => '', 'remark' => $msg ]); 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(); $condition = $count >= $type; // 记录详情 //$this->addLogChild($count, $ret[3]); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '指定权重不低于指定经销商等级的直属下级满足多少人', 'func_name' => 'firstChildLevel', 'condition' => '权重不低于等级id['.$level_id.']直属下级人数['.$type.']', 'complete' => $count, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 指定一个经销商等级下的人数满足多少人(团队) * @return bool * @author */ public function groupLevel(){ $ret = explode('_',$this->typeName); $type = intval($ret[3]); if(!$type){ //$this->addErrorChild($ret[3]); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '指定一个经销商等级下的人数满足多少人(团队)', 'func_name' => 'groupLevel', 'condition' => '等级id['.$ret[2].']人数['.$type.']', 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } $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_name' => '指定一个经销商等级下的人数满足多少人(团队)', 'func_name' => 'groupLevel', 'condition' => '等级id['.$ret[2].']人数['.$type.']', 'complete' => $count, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * 团队业绩利润满XXX元 */ public function teamProfitAmount(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '团队业绩利润满XXX元', 'func_name' => 'teamProfitAmount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } $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); } $teamProfitPrice = OrderIncomeCount::uniacid() ->selectRaw('sum(price - cost_price) as profit') ->whereIn('uid',$ids) ->where('status','>=',$this->order_status) ->first()->profit; $condition = $teamProfitPrice >= $this->upgradeParase[$this->typeName]; // 记录详情 //$this->addLogChild($teamProfitPrice); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '团队业绩利润满XXX元', 'func_name' => 'teamProfitAmount', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $teamProfitPrice, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * 会员持有爱心值数量达到 */ public function agentLove(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '会员持有爱心值数量达到XXX', 'func_name' => 'agentLove', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } if(!app('plugins')->isEnabled('love')){ return FALSE; } $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_name' => '会员持有爱心值数量达到XXX', 'func_name' => 'agentLove', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $total, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * 会员持有消费积分数量达到 */ public function agentIntegral(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '会员持有消费积分数量达到XXX', 'func_name' => 'agentIntegral', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } if(!app('plugins')->isEnabled('integral')){ return FALSE; } $total = IntegralMemberModel::where('uid',$this->uid) ->value('integral'); $condition = $total >= $this->upgradeParase[$this->typeName]; // 记录详情 //$this->addLogChild($teamProfitPrice); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '会员持有消费积分数量达到XXX', 'func_name' => 'agentIntegral', 'condition' => $this->upgradeParase[$this->typeName], 'complete' => $total, 'result' => $condition, 'remark' => $condition ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } /** * @name 团队新订单数量满,指定商品ID * @return bool * @author */ public function teamNewOrderNumber(){ $type = intval($this->upgradeParase[$this->typeName]); if(!$type){ //$this->addErrorChild($type); $this->uplogService->pushCondition([ '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' => '未设置条件,不执行' ]); return FALSE; } $agent = TeamDividendAgencyModel::uniacid() ->where('uid',$this->uid) ->first(); if(!$agent){ $this->uplogService->pushCondition([ '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' => '不是经销商身份不触发该升级条件' ]); return FALSE; } $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'); }) ->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); } $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){ $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_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 ? '满足条件' : '不满足条件' ]); if($condition){ return TRUE; } return FALSE; } 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, 'func_name' => 'dividendAndPeerSum', 'condition' => $type, 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } $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, 'func_name' => 'dividendAndPeerSum', 'condition' => $type, 'complete' => $sum, 'result' => '', 'remark' => bccomp($sum,$type,2) == -1 ? '不满足条件' : '满足条件', ]); return bccomp($sum,$type,2) == -1 ? FALSE : TRUE; } public function groupLoveAfterBlack(){ $msg = ''; if(!app('plugins')->isEnabled('love')){ $msg = '爱心值插件未开启'; } $type = bcadd($this->upgradeParase[$this->typeName] ?: 0,0,2); if(bccomp($type,0,2) != 1){ $msg = '未设置条件,不执行'; } if($msg){ $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '移出黑名单后团队累计自购赠送冻结'.(defined('LOVE_NAME') ? LOVE_NAME : '爱心值').'满'.$type, 'func_name' => 'groupLoveAfterBlack', 'condition' => $type, 'complete' => '', 'result' => '', 'remark' => $msg ]); return FALSE; } $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){ $black_time = $agent->black_time; } } $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, 'func_name' => 'groupLove', 'condition' => $type, 'complete' => $sum, 'result' => '', 'remark' => bccomp($sum,$type,2) == -1 ? '不满足条件' : '满足条件', ]); return bccomp($sum,$type,2) == -1 ? FALSE : TRUE; } public function groupLove(){ $msg = ''; if(!app('plugins')->isEnabled('love')){ $msg = '爱心值插件未开启'; } $type = bcadd($this->upgradeParase[$this->typeName] ?: 0,0,2); if(bccomp($type,0,2) != 1){ $msg = '未设置条件,不执行'; } if($msg){ $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '团队累计自购赠送冻结'.(defined('LOVE_NAME') ? LOVE_NAME : '爱心值').'满'.$type, 'func_name' => 'groupLove', 'condition' => $type, 'complete' => '', 'result' => '', 'remark' => $msg ]); 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('change_value'); } $this->uplogService->pushCondition([ '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 ? '不满足条件' : '满足条件', ]); return bccomp($sum,$type,2) == -1 ? FALSE : TRUE; } /** * 几条线 $this->upgradeParase['level_line_num'] * 等级id $this->upgradeParase['level_line_level_id'] * 本级 以上 $this->upgradeParase['oneself'] 0 本级 1 以上 * 3条线 每条线必须有一个会员满足该等级 * 每条线必须有多少会员以上 $this->upgradeParase['level_line_people'] * @return bool */ public function levelLine(){ // 0条线 if($this->upgradeParase['level_line_num'] <= 0){ //$this->addErrorChild($this->upgradeParase['level_line_num']); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该等级', 'func_name' => 'levelLine', 'condition' => '', 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } \Log::debug('经销商升级条件:几条线',$this->upgradeParase); //查询 会员一级下线 的集合 $firstLowers = YzMemberModel::select('member_id') ->where('parent_id',$this->uid) ->get(); \Log::debug('经销商升级条件:几条线,下级',$firstLowers); // 没有直属下级 返回 false if($firstLowers->isEmpty()){ //$this->addErrorChild(0); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该等级', 'func_name' => 'levelLine', 'condition' => '几条线['.$this->upgradeParase['level_line_num'].'],没有直属下级', 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); 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){ // 执行次数 大于等于 条件设置的几条线 /*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){ $people += 1; } $count = $buildRet['build']->where('member_id',$firstLower->member_id) ->count(); if($count > 0){ $people += $count; } // 满足指定人数 if($people >= $this->upgradeParase['level_line_people']){ $ret += 1; continue; } } if($ret >= $this->upgradeParase['level_line_num']){ //$this->addLogChild($ret, $this->upgradeParase['level_line_num']); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该等级', 'func_name' => 'levelLine', 'condition' => '几条线['.$this->upgradeParase['level_line_num'].']需满足人数['.$this->upgradeParase['level_line_people'].']', 'complete' => $ret, 'result' => '', 'remark' => '满足条件' ]); return TRUE; } else{ //$this->addLogChild($ret, $this->upgradeParase['level_line_num']); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该等级', 'func_name' => 'levelLine', 'condition' => '几条线['.$this->upgradeParase['level_line_num'].']需满足人数['.$this->upgradeParase['level_line_people'].']', 'complete' => $ret, 'result' => '', 'remark' => '不满足条件' ]); return FALSE; } } /** * 区域代理 * 几条线 $this->upgradeParase['level_line_area_num'] * 等级id $this->upgradeParase['level_line_area_level_id'] * 本级 以上 $this->upgradeParase['area_oneself'] 0 本级 1 以上 * 3条线 每条线必须有一个会员满足该等级 * 每条线必须有多少会员以上 $this->upgradeParase['level_line_area_people'] * @return bool */ public function levelLineArea(){ if(!app('plugins')->isEnabled('area-dividend')) return FALSE; // 0条线 if($this->upgradeParase['level_line_area_num'] <= 0){ $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该区域等级', 'func_name' => 'levelLineArea', 'condition' => '', 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); return FALSE; } \Log::debug('经销商升级条件:区域几条线',$this->upgradeParase); //查询 会员一级下线 的集合 $firstLowers = YzMemberModel::select('member_id') ->where('parent_id',$this->uid) ->get(); \Log::debug('经销商升级条件:区域几条线,下级',$firstLowers); // 没有直属下级 返回 false if($firstLowers->isEmpty()){ $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足区域该等级', 'func_name' => 'levelLineArea', 'condition' => '几条线['.$this->upgradeParase['level_line_area_num'].'],没有直属下级', 'complete' => '', 'result' => '', 'remark' => '未设置条件,不执行' ]); 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){ // 执行次数 大于等于 条件设置的几条线 $people = 0; $buildRet = $this->getAreaBuild($levelId); //一级下级 $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(); if($count > 0){ $people += $count; } // 满足指定人数 if($people >= $this->upgradeParase['level_line_area_people']){ $ret += 1; continue; } } if($ret >= $this->upgradeParase['level_line_area_num']){ $this->uplogService->pushCondition([ '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' => '满足条件' ]); return TRUE; } else{ $this->uplogService->pushCondition([ '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' => '不满足条件' ]); return FALSE; } } private function getBuild($levelId){ $nowLevel = TeamDividendLevelModel::select() ->where('id',$levelId) ->first(); // 本级 else 以上 if($this->upgradeParase['oneself'] == 0){ $build = MemberChild::select(['yz_member_children.child_id','yz_team_dividend_agency.level','yz_team_dividend_agency.cultural_level_id','yz_member_children.member_id']) ->join('yz_team_dividend_agency','yz_member_children.child_id','yz_team_dividend_agency.uid') ->where(function($query) use ($levelId){ $query->where('yz_team_dividend_agency.level',$levelId) ->orWhere('yz_team_dividend_agency.cultural_level_id',$levelId); }); // ->whereHas('hasOneTeam', function ($teamModel) use ($levelId) { // $teamModel->where('level', $levelId); // }); $selfBuild = TeamDividendAgencyModel::select() ->where('level',$nowLevel ? $levelId : -99); } else{ // 条件等级 // 比 大于等级权重的等级id的集合 $levelIds = [-999]; if($nowLevel){ $levelIds = TeamDividendLevelModel::select() ->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']) ->join('yz_team_dividend_agency','yz_member_children.child_id','yz_team_dividend_agency.uid') ->where(function($query) use ($levelIds){ $query->whereIn('yz_team_dividend_agency.level',$levelIds) ->orWhereIn('yz_team_dividend_agency.cultural_level_id',$levelIds); }); $selfBuild = TeamDividendAgencyModel::select() ->where(function($query) use ($levelIds){ $query->whereIn('yz_team_dividend_agency.level',$levelIds) ->orWhereIn('yz_team_dividend_agency.cultural_level_id',$levelIds); }); } return [ 'build' => $build, 'selfBuild' => $selfBuild ]; } 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); // } return [ '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; } /** * Common: 升级条件 - 团队消费人数多少人,支持去除人数最多的线 * Author: wu-hui * Time: 2023/12/15 17:52 * @return bool */ public function teamConsumptionPeople(){ try{ $upgradeSet = $this->upgradeParase[$this->typeName]; if(!$upgradeSet) throw new \Exception('未设置条件,不执行'); // 获取直推下级列表 $subIds = MemberChild::uniacid() ->where('level',1) ->where('member_id',$this->uid) ->pluck('child_id') ->toArray(); if(count($subIds) <= 0) throw new \Exception('无直推下级信息,不执行'); $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)$upgradeSet['team_consumption_people_close_max'] == 1) unset($eachLineUid[$maxPeopleInfo['sub_uid']]); if(count($eachLineUid) <= 0) throw new \Exception('无有效团队信息,不执行'); // 计算:消费总人数 $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',$this->levelType == 1 ? 1 : 0) ->distinct('yz_order.uid') ->count(); // 判断:是否达到升级要求 需求人数小于等于当前人数-达成升级条件 $people = (int)$upgradeSet['team_consumption_people_total'] > 0 ? (int)$upgradeSet['team_consumption_people_total'] : 1; $isReach = (boolean)($people <= $consumptionPeople); $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '团队消费人数多少人', 'func_name' => 'teamConsumptionPeople', 'condition' => '', 'result' => '', 'remark' => $isReach ? '满足条件' : '不满足条件' ]); if($isReach) return true; }catch(\Exception $e){ $this->uplogService->pushCondition([ 'type' => $this->typeName, 'type_name' => '团队消费人数多少人', 'func_name' => 'teamConsumptionPeople', 'condition' => '', 'complete' => '', 'result' => '', 'remark' => $e->getMessage() ]); \Log::debug('经销商升级 - 升级条件 - 团队消费人数多少人 - 错误:',$e->getMessage()); } return false; } }