计算进货经销商补贴
parent
2ebc5d9658
commit
9b2d2c9af1
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Dealer;
|
||||||
|
|
||||||
|
use App\Models\Dealer;
|
||||||
|
use App\Models\DealerPurchaseLog;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
|
class CalculatePurchaseAmount
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 计算经销商的进货业绩
|
||||||
|
*
|
||||||
|
* @param \App\Models\Dealer $dealer
|
||||||
|
* @param \Illuminate\Support\Carbon|null $start
|
||||||
|
* @param \Illuminate\Support\Carbon|null $end
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function handle(Dealer $dealer, ?Carbon $start = null, ?Carbon $end = null): string
|
||||||
|
{
|
||||||
|
$query = DealerPurchaseLog::query();
|
||||||
|
|
||||||
|
if ($start && $end) {
|
||||||
|
$query->whereBetween('order_completed_at', [$start, $end]);
|
||||||
|
} else {
|
||||||
|
$query->when($start, function ($query, $start) {
|
||||||
|
$query->where('order_completed_at', '>=', $start);
|
||||||
|
})->when($end, function ($query, $end) {
|
||||||
|
$query->where('order_completed_at', '<=', $end);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query->where('path', 'like', "{$dealer->userInfo->full_path}%")->sum('total_amount');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Console\Commands\Dealer;
|
namespace App\Console\Commands\Dealer;
|
||||||
|
|
||||||
|
use App\Actions\Dealer\CalculatePurchaseAmount;
|
||||||
use App\Enums\DealerEarningStatus;
|
use App\Enums\DealerEarningStatus;
|
||||||
use App\Enums\DealerLvl;
|
use App\Enums\DealerLvl;
|
||||||
use App\Enums\DealerOrderSettleState;
|
use App\Enums\DealerOrderSettleState;
|
||||||
|
|
@ -9,7 +10,6 @@ use App\Enums\DealerPurchaseSubsidySettleState;
|
||||||
use App\Enums\DealerPurchaseSubsidyStatus;
|
use App\Enums\DealerPurchaseSubsidyStatus;
|
||||||
use App\Models\Dealer;
|
use App\Models\Dealer;
|
||||||
use App\Models\DealerOrder;
|
use App\Models\DealerOrder;
|
||||||
use App\Models\DealerPurchaseLog;
|
|
||||||
use App\Models\DealerPurchaseSubsidy;
|
use App\Models\DealerPurchaseSubsidy;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
|
@ -31,6 +31,21 @@ class PurchaseSubsidySettleCommand extends Command
|
||||||
*/
|
*/
|
||||||
protected $description = '结算签约经销商的进货补贴';
|
protected $description = '结算签约经销商的进货补贴';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \App\Actions\Dealer\CalculatePurchaseAmount
|
||||||
|
*/
|
||||||
|
protected $calculatePurchaseAmount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \App\Actions\Dealer\CalculatePurchaseAmount $calculatePurchaseAmount
|
||||||
|
*/
|
||||||
|
public function __construct(CalculatePurchaseAmount $calculatePurchaseAmount)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->calculatePurchaseAmount = $calculatePurchaseAmount;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*
|
*
|
||||||
|
|
@ -265,11 +280,10 @@ class PurchaseSubsidySettleCommand extends Command
|
||||||
*/
|
*/
|
||||||
protected function initializePurchaseSubsidy(Dealer $dealer, Carbon $startAt, Carbon $endAt, $feeRate, array $purchaseRules)
|
protected function initializePurchaseSubsidy(Dealer $dealer, Carbon $startAt, Carbon $endAt, $feeRate, array $purchaseRules)
|
||||||
{
|
{
|
||||||
|
$this->calculatePurchaseAmount->handle($dealer, $startAt, $endAt);
|
||||||
|
|
||||||
// 进货总额
|
// 进货总额
|
||||||
$totalPurchaseAmount = DealerPurchaseLog::query()
|
$totalPurchaseAmount = $this->calculatePurchaseAmount->handle($dealer, $startAt, $endAt);
|
||||||
->whereBetween('order_completed_at', [$startAt, $endAt])
|
|
||||||
->where('path', 'like', "{$dealer->userInfo->full_path}%")
|
|
||||||
->sum('total_amount');
|
|
||||||
|
|
||||||
// 如果没有进货总额,则返回
|
// 如果没有进货总额,则返回
|
||||||
if (bccomp($totalPurchaseAmount, '0', 2) <= 0) {
|
if (bccomp($totalPurchaseAmount, '0', 2) <= 0) {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,15 @@ use Symfony\Component\HttpFoundation\HeaderUtils;
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* All of the container singletons that should be registered.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $singletons = [
|
||||||
|
\App\Actions\Dealer\CalculatePurchaseAmount::class => \App\Actions\Dealer\CalculatePurchaseAmount::class,
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register any application services.
|
* Register any application services.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue