6
0
Fork 0

订单自动完成时间

release
李静 2021-12-28 14:15:48 +08:00
parent 1894cd78bd
commit 63739c1948
4 changed files with 44 additions and 7 deletions

View File

@ -82,7 +82,9 @@ class OrderPackageService
//更新订单状态
if (!OrderProduct::where('order_id', $order->id)->where('remain_quantity', '>', 0)->exists()) {
$order->update([
'shipping_state'=>Order::SHIPPING_STATE_PROCESSED,
'shipping_state'=> Order::SHIPPING_STATE_PROCESSED,
// 订单自动完成时间
'auto_complete_at' => now()->addDays(app_settings('app.order_auto_complete_days', 7)),
]);
} elseif ($order->shipping_state == Order::SHIPPING_STATE_PENDING) {
$order->update([

View File

@ -50,6 +50,7 @@ class Order extends Model
protected $casts = [
'pay_at' => 'datetime',
'completed_at' => 'datetime',
'auto_complete_at' => 'datetime',
'status' => 'int',
'is_change' => 'bool',
];
@ -80,6 +81,7 @@ class Order extends Model
'shipping_state',
'status',
'completed_at',
'auto_complete_at',
'is_change',
];
@ -322,13 +324,13 @@ class Order extends Model
*/
public function getExpiresAtAttribute()
{
if (! $this->isPending()) {
return 0;
}
$seconds = 0;
$seconds = now()->diffInSeconds(
$this->created_at->addSeconds(app_settings('app.order_payment_expires_at')), false
);
if ($this->isPending()) {
$seconds = now()->diffInSeconds(
$this->created_at->addSeconds(app_settings('app.order_payment_expires_at')), false
);
}
return $seconds > 0 ? $seconds : 0;
}

View File

@ -84,6 +84,7 @@ class PayService
'pay_at' => $payLog->pay_at,
'out_trade_no' => $payLog->out_trade_no,
'status' => Order::STATUS_PAID,
'auto_complete_at' => now()->addDays(app_settings('app.order_auto_complete_days', 7)),
]);
DistributionPreIncomeJob::create([

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddAutoCompleteAtToOrdersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('orders', function (Blueprint $table) {
$table->timestamp('auto_complete_at')->nullable()->comment('订单自动完成时间');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('orders', function (Blueprint $table) {
$table->dropColumn(['auto_complete_at']);
});
}
}