经销商总进货业绩
parent
ecfe9a4200
commit
64ec251c1f
|
|
@ -18,11 +18,11 @@ class DealerResource extends JsonResource
|
||||||
'lvl' => $this->lvl,
|
'lvl' => $this->lvl,
|
||||||
'lvl_name'=> $this->lvl_text,
|
'lvl_name'=> $this->lvl_text,
|
||||||
'is_sale' => $this->is_sale,
|
'is_sale' => $this->is_sale,
|
||||||
'sale_values'=> $this->sale_values, //团队销售业绩基数
|
|
||||||
'guanli_values'=> $this->calculate_total_amount, //预计管理津贴
|
'guanli_values'=> $this->calculate_total_amount, //预计管理津贴
|
||||||
'team_sales_value' => $this->team_sales_value,
|
'team_sales_value' => $this->team_sales_value, // 团队业绩
|
||||||
'pay_info'=>$this->pay_info ?: null,
|
'pay_info'=>$this->pay_info ?: null,
|
||||||
'can_withdraw'=> $this->canWithdraw(),
|
'can_withdraw'=> $this->canWithdraw(),
|
||||||
|
'total_purchase_amount'=> $this->total_purchase_amount, // 总进货业绩
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use App\Casts\JsonArray;
|
||||||
use App\Enums\DealerLvl;
|
use App\Enums\DealerLvl;
|
||||||
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
class Dealer extends Model
|
class Dealer extends Model
|
||||||
{
|
{
|
||||||
|
|
@ -81,35 +82,29 @@ class Dealer extends Model
|
||||||
return $this->hasMany(DealerUpgradeLog::class, 'user_id', 'user_id');
|
return $this->hasMany(DealerUpgradeLog::class, 'user_id', 'user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 属于此经销商的进货补贴
|
||||||
|
*/
|
||||||
|
public function purchaseSubsidies()
|
||||||
|
{
|
||||||
|
return $this->hasMany(DealerPurchaseSubsidy::class, 'user_id', 'user_id');
|
||||||
|
}
|
||||||
|
|
||||||
public function getLvlTextAttribute()
|
public function getLvlTextAttribute()
|
||||||
{
|
{
|
||||||
return $this->lvl->text();
|
return $this->lvl->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统计经销商进货补贴实时的【基数业绩】
|
* 获取已结算的进货业绩
|
||||||
*
|
*
|
||||||
* @return void
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getSaleValuesAttribute()
|
public function getTotalPurchaseAmountAttribute()
|
||||||
{
|
{
|
||||||
// return $this->self_sales_value + $this->team_sales_value;
|
return Cache::remember('dealer_total_purchase_amount:'.$this->user_id, 3600, function () {
|
||||||
$tz = now();
|
return $this->purchaseSubsidies()->sum('total_purchase_amount');
|
||||||
|
});
|
||||||
if ($tz->day >= 20) {
|
|
||||||
// 结算当月20号开始的业绩
|
|
||||||
$startAt = $tz->copy()->setDay(20)->startOfDay();
|
|
||||||
} elseif ($tz->day >= 5) {
|
|
||||||
// 结算当月5号开始的的业绩
|
|
||||||
$startAt = $tz->copy()->setDay(5)->startOfDay();
|
|
||||||
} else {
|
|
||||||
// 结算上月20号开始的业绩
|
|
||||||
$startAt = $tz->copy()->subMonthNoOverflow()->setDay(20)->startOfDay();
|
|
||||||
}
|
|
||||||
|
|
||||||
return DealerPurchaseLog::query()->where('order_completed_at', '>=', $startAt)
|
|
||||||
->where('path', 'like', "{$this->userInfo->full_path}%")
|
|
||||||
->sum('total_amount');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -273,7 +268,7 @@ class Dealer extends Model
|
||||||
|
|
||||||
$remark = '';
|
$remark = '';
|
||||||
|
|
||||||
if ($lvl === DealerLvl::Gold && $this->getDirectGoldDealersCount() >=5) {
|
if ($lvl === DealerLvl::Gold && $this->getDirectGoldDealersCount() >= 5) {
|
||||||
$lvl = DealerLvl::Special;
|
$lvl = DealerLvl::Special;
|
||||||
|
|
||||||
$remark .= '有5个直推金牌';
|
$remark .= '有5个直推金牌';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue