更新渠道补贴结算规则
parent
5077e2969f
commit
037a6c3794
|
|
@ -5,14 +5,12 @@ namespace App\Console\Commands\Dealer;
|
||||||
use App\Enums\DealerEarningStatus;
|
use App\Enums\DealerEarningStatus;
|
||||||
use App\Enums\DealerLvl;
|
use App\Enums\DealerLvl;
|
||||||
use App\Enums\DealerOrderSettleState;
|
use App\Enums\DealerOrderSettleState;
|
||||||
use App\Enums\DealerOrderStatus;
|
|
||||||
use App\Models\Dealer;
|
use App\Models\Dealer;
|
||||||
use App\Models\DealerChannelSubsidyLog;
|
use App\Models\DealerChannelSubsidyLog;
|
||||||
use App\Models\DealerManagerSalesLog;
|
use App\Models\DealerManagerSalesLog;
|
||||||
use App\Models\DealerManageSubsidyLog;
|
use App\Models\DealerManageSubsidyLog;
|
||||||
use App\Models\DealerOrder;
|
use App\Models\DealerOrder;
|
||||||
use App\Models\DealerPurchaseLog;
|
use App\Models\DealerPurchaseLog;
|
||||||
use App\Models\UserInfo;
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
@ -43,15 +41,9 @@ class OrderProcessCommand extends Command
|
||||||
while (true) {
|
while (true) {
|
||||||
$page = 0;
|
$page = 0;
|
||||||
|
|
||||||
DealerOrder::where(
|
DealerOrder::settlePending()->chunkById(200, function ($orders) use (&$page) {
|
||||||
'settle_state',
|
|
||||||
DealerOrderSettleState::Pending
|
|
||||||
)->whereIn('status', [
|
|
||||||
DealerOrderStatus::Paid,
|
|
||||||
DealerOrderStatus::Shipped,
|
|
||||||
DealerOrderStatus::Completed,
|
|
||||||
])->chunkById(200, function ($orders) use (&$page) {
|
|
||||||
$orders->load([
|
$orders->load([
|
||||||
|
'userInfo',
|
||||||
'dealer.userInfo',
|
'dealer.userInfo',
|
||||||
'products.productManageSubsidyRules',
|
'products.productManageSubsidyRules',
|
||||||
]);
|
]);
|
||||||
|
|
@ -67,14 +59,12 @@ class OrderProcessCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
$page += 1;
|
$page += 1;
|
||||||
});
|
}, 'paied_time');
|
||||||
|
|
||||||
if ($page === 0) {
|
if ($page === 0) {
|
||||||
sleep(60);
|
sleep(60);
|
||||||
} elseif ($page === 1) {
|
|
||||||
sleep(30);
|
|
||||||
} else {
|
} else {
|
||||||
sleep(15);
|
sleep(5);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -226,7 +216,19 @@ class OrderProcessCommand extends Command
|
||||||
// 最后参与渠道补贴的经销商
|
// 最后参与渠道补贴的经销商
|
||||||
$last = null;
|
$last = null;
|
||||||
|
|
||||||
foreach ($dealer->getRealDealers() as $_dealer) {
|
while (true) {
|
||||||
|
if ($last) {
|
||||||
|
$_dealer = $last->userInfo->realInviterInfo?->dealer;
|
||||||
|
$_dealer?->setRelation('userInfo', $last->userInfo->realInviterInfo);
|
||||||
|
} else {
|
||||||
|
$_dealer = $dealer->userInfo->realInviterInfo?->dealer;
|
||||||
|
$_dealer?->setRelation('userInfo', $dealer->userInfo->realInviterInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_dealer === null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// 如果经销商等级小于金牌, 那么跳过
|
// 如果经销商等级小于金牌, 那么跳过
|
||||||
if ($_dealer->lvl->value < DealerLvl::Gold->value) {
|
if ($_dealer->lvl->value < DealerLvl::Gold->value) {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -496,28 +498,4 @@ class OrderProcessCommand extends Command
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取给定用户的实际上级经销商
|
|
||||||
*
|
|
||||||
* @param \App\Models\UserInfo $userInfo
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function getRealDealers(UserInfo $userInfo): array
|
|
||||||
{
|
|
||||||
$ancestors = [];
|
|
||||||
|
|
||||||
if (empty($pids = $userInfo->real_parent_ids)) {
|
|
||||||
return $ancestors;
|
|
||||||
}
|
|
||||||
|
|
||||||
$ancestors = UserInfo::with(['dealer'])
|
|
||||||
->whereIn('user_id', $pids)
|
|
||||||
->latest('depth')
|
|
||||||
->get(['user_id']);
|
|
||||||
|
|
||||||
return $ancestors->map(function ($item) {
|
|
||||||
return $item->dealer;
|
|
||||||
})->all();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -178,27 +178,6 @@ class Dealer extends Model
|
||||||
})->all();
|
})->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取此用户的所有直属上级经销商
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getRealDealers()
|
|
||||||
{
|
|
||||||
if (empty($pids = $this->userInfo->real_parent_ids)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$ancestors = UserInfo::with(['dealer'])
|
|
||||||
->whereIn('user_id', $pids)
|
|
||||||
->latest('depth')
|
|
||||||
->get(['user_id']);
|
|
||||||
|
|
||||||
return $ancestors->map(function ($item) {
|
|
||||||
return $item->dealer;
|
|
||||||
})->all();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取直属金牌经销商数量
|
* 获取直属金牌经销商数量
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,20 @@ class DealerOrder extends Model
|
||||||
'remark',
|
'remark',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 仅获取待结算的已付款订单
|
||||||
|
*/
|
||||||
|
public function scopeSettlePending($query)
|
||||||
|
{
|
||||||
|
return $query->whereNotNull('paied_time')
|
||||||
|
->where('settle_state', DealerOrderSettleState::Pending)
|
||||||
|
->whereIn('status', [
|
||||||
|
DealerOrderStatus::Paid,
|
||||||
|
DealerOrderStatus::Shipped,
|
||||||
|
DealerOrderStatus::Completed,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取待确认订单
|
* 获取待确认订单
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddPaidTimeIndexToDealerOrdersTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('dealer_orders', function (Blueprint $table) {
|
||||||
|
$table->index('paied_time');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('dealer_orders', function (Blueprint $table) {
|
||||||
|
$table->dropIndex(['paied_time']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue