58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Peidikeji\Order\Console;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Peidikeji\Order\Enums\ShipStatus;
|
|
use Peidikeji\Order\Models\Order;
|
|
use Peidikeji\Order\OrderService;
|
|
|
|
class OrdeReceive extends Command
|
|
{
|
|
protected $signature = 'order:receive {id?}';
|
|
|
|
protected $description = '订单自动确认收货';
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
$id = $this->argument('id');
|
|
if ($id) {
|
|
$this->receive(Order::findOrFail($id));
|
|
} else {
|
|
$query = Order::where('ship_status', ShipStatus::Finished)
|
|
->where('is_closed', 0)
|
|
->where('ship_at', '<', now()->subDays(7));
|
|
$list = $query->get();
|
|
foreach($list as $item) {
|
|
$this->receive($item);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected function receive(Order $order)
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
OrderService::make()->receive($order);
|
|
|
|
$order->options()->create([
|
|
'description' => '系统自动确认收货',
|
|
'attribute' => [
|
|
'ship_status' => ShipStatus::Received
|
|
],
|
|
]);
|
|
DB::commit();
|
|
} catch (\Exception $e) {
|
|
DB::rollBack();
|
|
$this->error('系统自动确认收货失败: ' . $order->id);
|
|
$this->error($e->getMessage());
|
|
}
|
|
}
|
|
}
|