You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.6 KiB
57 lines
1.6 KiB
<?php
|
|
declare (strict_types=1);
|
|
|
|
namespace app\command\hygl;
|
|
|
|
use addon\hygl\app\model\coupons\Coupons;
|
|
use addon\hygl\app\model\transaction_history\TransactionHistory;
|
|
use addon\hygl\app\model\user_coupons\UserCoupons;
|
|
use think\console\Command;
|
|
use think\console\Input;
|
|
use think\console\input\Argument;
|
|
use think\console\input\Option;
|
|
use think\console\Output;
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 30分钟自动关闭尚未支付的订单
|
|
* Class OrderClose
|
|
* @package app\command\hygl
|
|
*/
|
|
class OrderClose extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
// 指令配置
|
|
$this->setName('OrderClose')
|
|
->setDescription('会员管理-30分钟自动关闭尚未支付的订单');
|
|
}
|
|
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
// 指令输出
|
|
$output->writeln('开始执行-会员管理-30分钟自动关闭尚未支付的订单');
|
|
|
|
$time = time();
|
|
$end_create_time = $time - 30 * 60;
|
|
//查询超过30分钟未支付的订单,返回使用的优惠券,修改订单状态为关闭
|
|
$order_list = TransactionHistory::where('pay_status', 0)
|
|
->where('create_time', '<', $end_create_time)
|
|
->select();
|
|
|
|
Db::startTrans();
|
|
try {
|
|
foreach ($order_list as $v) {
|
|
//关闭订单
|
|
TransactionHistory::where('id', $v['id'])->update([
|
|
'pay_status' => 3,//超时关闭
|
|
]);
|
|
}
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $exception) {
|
|
Db::rollback();
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|