确认收货,发放提成
parent
cdc4032c31
commit
9da8638346
|
|
@ -6,6 +6,8 @@ use App\Exceptions\BizException;
|
|||
use App\Models\Order;
|
||||
use App\Services\OrderService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class OrderCompleteCommand extends Command
|
||||
{
|
||||
|
|
@ -36,8 +38,11 @@ class OrderCompleteCommand extends Command
|
|||
Order::with('packages')->completable()->chunkById(200, function ($orders) use ($orderService, &$page) {
|
||||
foreach ($orders as $order) {
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$orderService->confirm($order, true);
|
||||
DB::commit();
|
||||
} catch (BizException $e) {
|
||||
DB::rollBack();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,17 +22,36 @@ class DistributeService
|
|||
if ($order->isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
// 已经添加过返现记录
|
||||
if ($user->salesValueLogs()->where('order_id', $order->id)->exists()) {
|
||||
return false;
|
||||
}
|
||||
// 订单成长值
|
||||
$sales_value = $order->sales_value;
|
||||
$user = $order->user;
|
||||
// $user->salesValueLogs()->create([
|
||||
// 'order_id' => $order->id,
|
||||
// 'order_user_id' => $order->user_id,
|
||||
// 'type' => SalesValueLog::TYPE_INDIVIDUAL,
|
||||
// 'change_sales_value' => $sales_value
|
||||
// ]);
|
||||
// $user->userInfo()->increment('growth_value', $sales_value);
|
||||
|
||||
// 用户获得成长值
|
||||
$user->salesValueLogs()->create([
|
||||
'order_id' => $order->id,
|
||||
'order_user_id' => $order->user_id,
|
||||
'type' => SalesValueLog::TYPE_INDIVIDUAL,
|
||||
'change_sales_value' => $sales_value
|
||||
]);
|
||||
$user->userInfo()->increment('growth_value', $sales_value);
|
||||
// 自动升级代理
|
||||
$levels = Vip::orderBy('sort')->get();
|
||||
$level_up = '';
|
||||
foreach($levels->reverse() as $item) {
|
||||
if ($user->userInfo->growth_value >= $item->growth_value) {
|
||||
$level_up = $item;
|
||||
}
|
||||
}
|
||||
if ($level_up && $level_up->slug === 'favoite') {
|
||||
$user->userVip()->updateOrCreate([], [
|
||||
'vip_id' => $level_up->id,
|
||||
'growth_value' => $level_up->growth_value
|
||||
]);
|
||||
}
|
||||
|
||||
// 上级返现
|
||||
$parent_ids = array_reverse($user->userInfo->parent_ids);
|
||||
|
|
|
|||
|
|
@ -1055,6 +1055,8 @@ class OrderService
|
|||
'status' => Order::STATUS_COMPLETED,
|
||||
'completed_at' => now(),
|
||||
]);
|
||||
|
||||
(new DistributeService())->storeByOrder();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue