添加:分销商升级添加升级条件 - 团队业绩满多少元
This commit is contained in:
parent
feb50ab76d
commit
5caf09c315
|
|
@ -32,7 +32,7 @@ class GoodsServiceListener
|
||||||
foreach ($uniAccount as $u) {
|
foreach ($uniAccount as $u) {
|
||||||
\YunShop::app()->uniacid = $u->uniacid;
|
\YunShop::app()->uniacid = $u->uniacid;
|
||||||
\Setting::$uniqueAccountId = $u->uniacid;
|
\Setting::$uniqueAccountId = $u->uniacid;
|
||||||
\Log::debug('-----------商品服务提供定时上下架-----------------uniacid:'.\YunShop::app()->uniacid);
|
// \Log::debug('-----------商品服务提供定时上下架-----------------uniacid:'.\YunShop::app()->uniacid);
|
||||||
$goods = Goods::select(['id', 'stock','status','updated_at'])
|
$goods = Goods::select(['id', 'stock','status','updated_at'])
|
||||||
->whereHas('hasOneGoodsService', function ($query) {
|
->whereHas('hasOneGoodsService', function ($query) {
|
||||||
return $query->where('is_automatic', 1);
|
return $query->where('is_automatic', 1);
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ class UpperLowerShelves
|
||||||
foreach ($uniAccount as $u) {
|
foreach ($uniAccount as $u) {
|
||||||
\YunShop::app()->uniacid = $u->uniacid;
|
\YunShop::app()->uniacid = $u->uniacid;
|
||||||
\Setting::$uniqueAccountId = $u->uniacid;
|
\Setting::$uniqueAccountId = $u->uniacid;
|
||||||
\Log::debug('-----------商品服务提供定时上下架-----------------uniacid:'.\YunShop::app()->uniacid);
|
// \Log::debug('-----------商品服务提供定时上下架-----------------uniacid:'.\YunShop::app()->uniacid);
|
||||||
$goods = Goods::select(['id', 'stock','status','updated_at'])
|
$goods = Goods::select(['id', 'stock','status','updated_at'])
|
||||||
->whereHas('hasOneGoodsService', function ($query) {
|
->whereHas('hasOneGoodsService', function ($query) {
|
||||||
return $query->where('is_automatic', 1);
|
return $query->where('is_automatic', 1);
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ class GoodsStock
|
||||||
public function reduce($num)
|
public function reduce($num)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
\Log::debug('商品扣库存', "商品(" . get_class($this->source()) . ":{$this->source()->id}-{$this->source()->stock})减库存{$num}件");
|
// \Log::debug('商品扣库存', "商品(" . get_class($this->source()) . ":{$this->source()->id}-{$this->source()->stock})减库存{$num}件");
|
||||||
}catch (\Exception $e){
|
}catch (\Exception $e){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +53,7 @@ class GoodsStock
|
||||||
public function createReduce($num)
|
public function createReduce($num)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
\Log::debug('商品扣库存', "商品(" . get_class($this->source()) . ":{$this->source()->id}-{$this->source()->stock})减库存{$num}件");
|
// \Log::debug('商品扣库存', "商品(" . get_class($this->source()) . ":{$this->source()->id}-{$this->source()->stock})减库存{$num}件");
|
||||||
}catch (\Exception $e){
|
}catch (\Exception $e){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ class OrderCreatedListener
|
||||||
public function handle($order,$is_fix = false)
|
public function handle($order,$is_fix = false)
|
||||||
{
|
{
|
||||||
$this->is_fix = $is_fix;
|
$this->is_fix = $is_fix;
|
||||||
\Log::debug('区域分红:订单创建事件handle()');
|
// \Log::debug('区域分红:订单创建事件handle()');
|
||||||
$this->set = $order->getSetting('plugin.area_dividend');
|
$this->set = $order->getSetting('plugin.area_dividend');
|
||||||
|
|
||||||
$this->dividend($order);
|
$this->dividend($order);
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ class OrderCreatedListener
|
||||||
public function handle($order, $is_fix = false)
|
public function handle($order, $is_fix = false)
|
||||||
{
|
{
|
||||||
$this->is_fix = $is_fix;
|
$this->is_fix = $is_fix;
|
||||||
\Log::debug('区域分红:订单创建事件handle()');
|
// \Log::debug('区域分红:订单创建事件handle()');
|
||||||
|
|
||||||
$before_event = new BeforeAreaDividendCreatedEvent($order, $this->extra_plugin_id, $this->extra_id);
|
$before_event = new BeforeAreaDividendCreatedEvent($order, $this->extra_plugin_id, $this->extra_id);
|
||||||
event($before_event);
|
event($before_event);
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ class OrderCreatedOldListener
|
||||||
public function handle($order,$is_fix = false)
|
public function handle($order,$is_fix = false)
|
||||||
{
|
{
|
||||||
$this->is_fix = $is_fix;
|
$this->is_fix = $is_fix;
|
||||||
\Log::debug('区域分红:订单创建事件handle()');
|
// \Log::debug('区域分红:订单创建事件handle()');
|
||||||
$this->set = $order->getSetting('plugin.area_dividend');
|
$this->set = $order->getSetting('plugin.area_dividend');
|
||||||
|
|
||||||
$this->dividend($order);
|
$this->dividend($order);
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ class AppointmentService
|
||||||
{
|
{
|
||||||
foreach ($area_agents as $areaLevel => $area_agent) {
|
foreach ($area_agents as $areaLevel => $area_agent) {
|
||||||
if ($area_agent->isEmpty()) {
|
if ($area_agent->isEmpty()) {
|
||||||
\Log::debug('门店预约区域分红' . $this->order->id .$areaLevel.'团队为空');
|
// \Log::debug('门店预约区域分红' . $this->order->id .$areaLevel.'团队为空');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ class OrderCreatedNewService
|
||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
if ($area_agents->isEmpty()) {
|
if ($area_agents->isEmpty()) {
|
||||||
\Log::debug('区域分红' . $this->order->id .$areaLevel.'团队为空');
|
// \Log::debug('区域分红' . $this->order->id .$areaLevel.'团队为空');
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,8 @@ class OrderPaidListener
|
||||||
|
|
||||||
// 直推间推满多少人
|
// 直推间推满多少人
|
||||||
UpgradeService::oneOrTwo($model->uid, 'order_paid');
|
UpgradeService::oneOrTwo($model->uid, 'order_paid');
|
||||||
|
// 团队业绩满多少
|
||||||
|
UpgradeService::teamPerformance($model->uid, 'order_paid');
|
||||||
}
|
}
|
||||||
\Log::debug('分销商升级 - 订单支付<-');
|
\Log::debug('分销商升级 - 订单支付<-');
|
||||||
}catch(\Exception $e){
|
}catch(\Exception $e){
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,8 @@ class OrderReceiveListener
|
||||||
}
|
}
|
||||||
// 直推间推满多少人
|
// 直推间推满多少人
|
||||||
UpgradeService::oneOrTwo($model->uid, 'order_receive');
|
UpgradeService::oneOrTwo($model->uid, 'order_receive');
|
||||||
|
// 团队业绩满多少
|
||||||
|
UpgradeService::teamPerformance($model->uid, 'order_receive');
|
||||||
}
|
}
|
||||||
\Log::debug('分销商升级 - 订单完成<-');
|
\Log::debug('分销商升级 - 订单完成<-');
|
||||||
}catch(\Exception $e){
|
}catch(\Exception $e){
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ class AgentLevelService
|
||||||
$data['buy_and_sum'] = $upgrade['buy_and_sum'];
|
$data['buy_and_sum'] = $upgrade['buy_and_sum'];
|
||||||
$data['team_buy_sum'] = $upgrade['team_buy_sum'];
|
$data['team_buy_sum'] = $upgrade['team_buy_sum'];
|
||||||
$data['one_or_two'] = $upgrade['one_or_two'];
|
$data['one_or_two'] = $upgrade['one_or_two'];
|
||||||
|
$data['team_performance'] = $upgrade['team_performance'];
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,6 +65,9 @@ class AgentLevelService
|
||||||
if ($key == 'one_or_two' && intval($upgradeValue['one_or_two'])) {
|
if ($key == 'one_or_two' && intval($upgradeValue['one_or_two'])) {
|
||||||
$upgrades[$key] = $upgradeValue['one_or_two'];
|
$upgrades[$key] = $upgradeValue['one_or_two'];
|
||||||
}
|
}
|
||||||
|
if ($key == 'team_performance' && intval($upgradeValue['team_performance'])) {
|
||||||
|
$upgrades[$key] = $upgradeValue['team_performance'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,6 +105,10 @@ class AgentLevelService
|
||||||
$lvName = AgentLevel::uniacid()->where('id',$levelId)->value('name');
|
$lvName = AgentLevel::uniacid()->where('id',$levelId)->value('name');
|
||||||
$upgrades['one_or_two']['type'] = '直推间推'.$lvName.'满'.$upgrade['one_or_two']['one_or_two_people'].'人';
|
$upgrades['one_or_two']['type'] = '直推间推'.$lvName.'满'.$upgrade['one_or_two']['one_or_two_people'].'人';
|
||||||
}
|
}
|
||||||
|
if ($type == 'team_performance') {
|
||||||
|
$upgrades['team_performance']['type'] = "团队业绩满{$upgrade['team_performance']['team_performance_total']}元";
|
||||||
|
if($upgrade['team_performance']['team_performance_close_max']) $upgrades['team_performance']['type'] .= ';去除最大业绩最大的线';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$level->upgrades = $upgrades;
|
$level->upgrades = $upgrades;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ use Yunshop\Commission\models\YzMember;
|
||||||
use Yunshop\Love\Common\Models\LoveRecords;
|
use Yunshop\Love\Common\Models\LoveRecords;
|
||||||
use Yunshop\Love\Common\Services\ConstService;
|
use Yunshop\Love\Common\Services\ConstService;
|
||||||
use Yunshop\Merchant\common\services\CenterUpgradeService;
|
use Yunshop\Merchant\common\services\CenterUpgradeService;
|
||||||
|
use Yunshop\TeamDividend\admin\models\MemberChild;
|
||||||
|
|
||||||
class UpgradeService
|
class UpgradeService
|
||||||
{
|
{
|
||||||
|
|
@ -187,6 +188,63 @@ class UpgradeService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 升级条件判断 - 团队业绩满多少
|
||||||
|
public static function teamPerformance($memberId, $type = 'order_receive'){
|
||||||
|
try{
|
||||||
|
// 等级 升级条件
|
||||||
|
$levels = static::getLevelUpgraded();
|
||||||
|
if (!$levels) return;
|
||||||
|
// 分销商数据
|
||||||
|
$agentModel = Agents::getAgentByMemberId($memberId)->first();
|
||||||
|
if (!$agentModel) return;
|
||||||
|
// 获取全部上级
|
||||||
|
$parentAgent = self::getParentsCommission($memberId);
|
||||||
|
foreach($levels as $levelIndex => $levelItem){
|
||||||
|
$upgraded = $levelItem['upgraded'] ?? [];
|
||||||
|
$teamPerformance = $upgraded['team_performance'] ?? [];
|
||||||
|
// 判断:支付后 完成后 是否存在对应的设置
|
||||||
|
if(!empty($teamPerformance) && (($type == 'order_receive' && (int)$upgraded['self_order_after'] != 1) || ($type == 'order_paid' && (int)$upgraded['self_order_after'] == 1))){
|
||||||
|
// \Log::debug('分销商升级 - 团队业绩满多少 - 升级条件:',$teamPerformance);
|
||||||
|
// 循环所有上级 判断是否可以升级到当前等级
|
||||||
|
foreach($parentAgent as $parentUser){
|
||||||
|
if((int)$parentUser['agent_level']['level'] < (int)$levelItem['level']){
|
||||||
|
// 获取直推下级列表
|
||||||
|
$subIds = MemberChild::uniacid()
|
||||||
|
->where('level',1)
|
||||||
|
->where('member_id',$parentUser['member_id'])
|
||||||
|
->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::whereIn('uid',$lineAllUid)->where('status','>=',0)->sum('yz_order.price');
|
||||||
|
}
|
||||||
|
// 计算团队总业绩 判断:是否去除最大业绩
|
||||||
|
$maxAmount = 0;
|
||||||
|
if((int)$teamPerformance['team_performance_close_max'] == 1) $maxAmount = max($subPerformance);
|
||||||
|
$teamOrderPrice = (float)sprintf("%.2f",array_sum($subPerformance) - $maxAmount);
|
||||||
|
// 是否达到升级条件
|
||||||
|
$validateResult = static::validate($levelItem['level'], $parentUser['member_id']);
|
||||||
|
if($teamOrderPrice >= (float)$teamPerformance['team_performance_total'] && $validateResult) {
|
||||||
|
\Yunshop\Commission\models\Log::addLog(
|
||||||
|
$validateResult['agent_level_id'],
|
||||||
|
$levelItem['id'],
|
||||||
|
$validateResult,
|
||||||
|
"团队业绩满{$teamPerformance['team_performance_total']}元"
|
||||||
|
);
|
||||||
|
static::upgrade($levelItem, $parentUser['member_id'], $validateResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch(\Exception $e){
|
||||||
|
\Log::debug('分销商升级 - 团队业绩满多少 - 错误:',$e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function teamBuySum($uid, $level_model)
|
public static function teamBuySum($uid, $level_model)
|
||||||
{
|
{
|
||||||
$isUpgrade = UpgrateConditionsService::teamBuySum($uid,$level_model,'', '');
|
$isUpgrade = UpgrateConditionsService::teamBuySum($uid,$level_model,'', '');
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,27 @@
|
||||||
</div>
|
</div>
|
||||||
{{-- 直推间推 某个等级 满多少人 END --}}
|
{{-- 直推间推 某个等级 满多少人 END --}}
|
||||||
|
|
||||||
|
{{-- 团队业绩满 START --}}
|
||||||
|
<div class="input-group row">
|
||||||
|
<label class="radio-inline col-xs-12 col-sm-12">
|
||||||
|
<div class="col-xs-12 col-sm-12" style="padding-left: 0">
|
||||||
|
<div class='input-group'>
|
||||||
|
<div class='input-group-addon waytxt'>
|
||||||
|
<input type="checkbox" name="upgrade_type[team_performance]" value="1" @if ($upgrade_data['team_performance']) checked @endif>
|
||||||
|
</div>
|
||||||
|
<div class='input-group-addon waytxt'>团队业绩满</div>
|
||||||
|
<input type="number" name="upgrade_value[team_performance][team_performance_total]" value="{{$upgrade_data['team_performance']['team_performance_total']}}" class="form-control">
|
||||||
|
<div class='input-group-addon waytxt'>元;</div>
|
||||||
|
<div class='input-group-addon waytxt'>
|
||||||
|
<input type="checkbox" name="upgrade_value[team_performance][team_performance_close_max]" value="1" @if ($upgrade_data['team_performance']['team_performance_close_max']) checked @endif>
|
||||||
|
</div>
|
||||||
|
<div class='input-group-addon waytxt'>去除业绩最大的那条线</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{{-- 直推间推 某个等级 满多少人 END --}}
|
||||||
|
|
||||||
@foreach($upgrade_config as $key=>$config)
|
@foreach($upgrade_config as $key=>$config)
|
||||||
@if($config['key'] != 'goods' && $config['key'] != 'self_order_after' && $config['key'] != 'many_good')
|
@if($config['key'] != 'goods' && $config['key'] != 'self_order_after' && $config['key'] != 'many_good')
|
||||||
@if($key%2==0)
|
@if($key%2==0)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue