/www/server/php/80/bin/php /www/wwwroot/digital-platform/artisan hotel_confirm
<?php
namespace App\Console\Commands;
use App\Constant\HotelConstant;
use App\Models\GoodsOrder;
use App\Models\HotelOrder;
use App\Models\HotelRoom;
use App\Models\HotelRoomCalendar;
use App\Services\Goods\Interfaces\GoodsOrderServiceInterface;
use App\Services\Goods\Services\GoodsAutoService;
use App\Services\Hotel\Interfaces\HotelServiceInterface;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class HotelAutoOrderConfirm extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'hotel_confirm';
/**
* The console command description.
*
* @var string
*/
protected $description = '酒店已经入住订单自动退房';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->line('start');
Log::channel('hotellog')->debug('酒店定时-start');
$this->orderConfirm();
Log::channel('hotellog')->debug('酒店定时-ok');
}
public function orderConfirm()
{
$order_model = new HotelOrder();
$order_service = app()->make(HotelServiceInterface::class);
// 将订单状态为 1(未支付)时间在超过 配置时间的订单取消 minutes
$order_list = $order_model->where('order_status',HotelConstant::CONFIRM_LIVING)->where('end_at','=',today_())->get(); //update(['order_status'=>0,'updated_at'=>now()])
if($order_list->isEmpty()){
return 'nothing';
}
$ids = [];
foreach($order_list as $v){
try{
DB::beginTransaction();
$rs = $order_service->editOrderStatus($v['id'],HotelConstant::ORDER_DONE,'admin');
if(!$rs['code']){
Log::channel('hotellog')->debug('fail');
}
DB::commit();
}catch(\Exception $e){
DB::rollBack();
Log::channel('qwlog')->debug($e->getMessage());
}
}
return 'success';
}
}