确认订单无法发起售后
parent
7be71e7a6e
commit
9a119e311e
|
|
@ -34,15 +34,27 @@ class OrderSettleCommand extends Command
|
|||
public function handle()
|
||||
{
|
||||
while (true) {
|
||||
$page = 0;
|
||||
Order::where(
|
||||
'completed_at',
|
||||
'<=',
|
||||
now()->subDays(app_settings('distribution.settle_days', 7))
|
||||
)->where([
|
||||
'status' => Order::STATUS_COMPLETED,
|
||||
'is_settlable' => false,
|
||||
'is_settle' => false,
|
||||
])->chunkById(200, function ($orders) {
|
||||
foreach ($orders as $order) {
|
||||
$order->update([
|
||||
'is_settlable' => true,
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
// 只查询可结算的订单,并且没有处理中的售后单
|
||||
// 检查订单是否有未执行的分销任务
|
||||
Order::whereDoesntHave('afterSales', function ($query) {
|
||||
return $query->processing();
|
||||
})->whereDoesntHave('distributionPreIncomeJobs', function ($query) {
|
||||
return $query->pending();
|
||||
})->settlable()->chunkById(200, function ($orders) use (&$page) {
|
||||
})->settlable()->chunkById(200, function ($orders) {
|
||||
$orders->load(['user', 'afterSales']);
|
||||
|
||||
foreach ($orders as $order) {
|
||||
|
|
@ -58,17 +70,9 @@ class OrderSettleCommand extends Command
|
|||
report($e);
|
||||
}
|
||||
}
|
||||
|
||||
$page++;
|
||||
});
|
||||
|
||||
if ($page === 0) {
|
||||
sleep(60);
|
||||
} elseif ($page === 1) {
|
||||
sleep(30);
|
||||
} else {
|
||||
sleep(15);
|
||||
}
|
||||
sleep(60);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ class OrderController extends Controller
|
|||
DB::transaction(function () use ($id, $user) {
|
||||
$order = $user->orders()->lockForUpdate()->findOrFail($id);
|
||||
|
||||
(new OrderService())->confirm($order);
|
||||
(new OrderService())->confirm($order, true);
|
||||
});
|
||||
|
||||
return response()->noContent();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Endpoint\Api\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrderProductSimpleResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'sku_id' => $this->sku_id,
|
||||
'name' => $this->name,
|
||||
'cover' => $this->cover,
|
||||
'specs' => array_values((array) $this->specs),
|
||||
'sell_price' => $this->sell_price_format,
|
||||
'vip_price' => $this->vip_price_format,
|
||||
'total_amount' => $this->total_amount,
|
||||
'quantity' => $this->quantity,
|
||||
'is_gift' => $this->isGift(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,12 @@ class OrderResource extends JsonResource
|
|||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
if ($this->resource->relationLoaded('products')) {
|
||||
foreach ($this->resource->products as $product) {
|
||||
$product->setRelation('order', $this->resource);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'sn' => $this->sn,
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class OrderResourceCollection extends ResourceCollection
|
|||
'total_amount' => $item->total_amount_format,
|
||||
'status' => $item->order_status,
|
||||
'created_date' => $item->created_at->toDateString(),
|
||||
'products' => OrderProductResource::collection($item->whenLoaded('products')),
|
||||
'products' => OrderProductSimpleResource::collection($item->whenLoaded('products')),
|
||||
'expires_at' => $item->expires_at,
|
||||
];
|
||||
})->toArray();
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ class Order extends Model
|
|||
'is_settle' => false,
|
||||
'is_change' => false,
|
||||
'status' => self::STATUS_PENDING,
|
||||
'is_settlable' => false,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -56,6 +57,7 @@ class Order extends Model
|
|||
'status' => 'int',
|
||||
'is_settle' => 'bool',
|
||||
'is_change' => 'bool',
|
||||
'is_settlable' => 'bool',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -88,6 +90,7 @@ class Order extends Model
|
|||
'is_change',
|
||||
'is_settle',
|
||||
'sales_value',
|
||||
'is_settlable',
|
||||
];
|
||||
|
||||
public static $payWayText = [
|
||||
|
|
@ -123,7 +126,7 @@ class Order extends Model
|
|||
public function scopeSettlable($query)
|
||||
{
|
||||
return $query->where('status', static::STATUS_COMPLETED)
|
||||
->where('completed_at', '<=', now()->subDays(app_settings('distribution.settle_days', 7)))
|
||||
->where('is_settlable', true)
|
||||
->where('is_settle', false);
|
||||
}
|
||||
|
||||
|
|
@ -302,19 +305,6 @@ class Order extends Model
|
|||
return $this->status === static::STATUS_CANCELLED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将订单标记为已完成
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function markAsCompleted()
|
||||
{
|
||||
$this->update([
|
||||
'status' => static::STATUS_COMPLETED,
|
||||
'completed_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单券优惠金额
|
||||
*
|
||||
|
|
|
|||
|
|
@ -81,6 +81,15 @@ class OrderProduct extends Model
|
|||
return $this->belongsTo(ProductSku::class, 'sku_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 此订单商品所属的SKU
|
||||
*
|
||||
*/
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(Order::class, 'order_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认此订单商品是否是赠品
|
||||
*
|
||||
|
|
@ -100,11 +109,15 @@ class OrderProduct extends Model
|
|||
{
|
||||
$res = false;
|
||||
|
||||
//老判断,有过期时间,且未到过期时间,未发起过售后
|
||||
if ($this->order->is_settlable) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 老判断,有过期时间,且未到过期时间,未发起过售后
|
||||
// $oldJudge = !is_null($this->after_expire_at) && $this->after_expire_at > now() && $this->after_sale_state == 0;
|
||||
|
||||
//新判断, 有发货单,在售后时间范围内, 当前无售后;
|
||||
if ($this->packages()->where('is_failed', false)->count() >0) {
|
||||
if ($this->packages()->where('is_failed', false)->count() > 0) {
|
||||
if ((is_null($this->after_expire_at) || $this->after_expire_at > now()) && $this->after_sale_state == 0) {
|
||||
$res = true;
|
||||
}
|
||||
|
|
@ -121,9 +134,11 @@ class OrderProduct extends Model
|
|||
public function getHasAfterSaleAttribute(): bool
|
||||
{
|
||||
$res = false;
|
||||
|
||||
if ($this->afterSales()->count() > 0) {
|
||||
$res =true;
|
||||
$res = true;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -819,14 +819,19 @@ class OrderService
|
|||
* 确认订单
|
||||
*
|
||||
* @param \App\Models\Order $order
|
||||
* @param bool $isSettlable
|
||||
* @return void
|
||||
*/
|
||||
public function confirm(Order $order)
|
||||
public function confirm(Order $order, $isSettlable = false)
|
||||
{
|
||||
if (! $order->isShipped()) {
|
||||
throw new BizException('订单包裹未发完');
|
||||
}
|
||||
|
||||
if ($isSettlable && $order->afterSales()->processing()->count() > 0) {
|
||||
throw new BizException('订单商品售后中,不能完成此订单');
|
||||
}
|
||||
|
||||
$orderPackageService = new OrderPackageService();
|
||||
|
||||
$order->loadMissing('packages');
|
||||
|
|
@ -839,7 +844,11 @@ class OrderService
|
|||
$orderPackageService->checkPackage($package, true);
|
||||
}
|
||||
|
||||
$order->markAsCompleted();
|
||||
$order->update([
|
||||
'is_settlable' => $isSettlable,
|
||||
'status' => Order::STATUS_COMPLETED,
|
||||
'completed_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddIsSettlableToOrdersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('orders', function (Blueprint $table) {
|
||||
$table->boolean('is_settlable')->default(false)->comment('是否完成');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('orders', function (Blueprint $table) {
|
||||
$table->dropColumn(['is_settlable']);
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue