其余文件
This commit is contained in:
68
app/common/command/OrderFinish.php
Normal file
68
app/common/command/OrderFinish.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\OrderLogEnum;
|
||||
use app\common\logic\OrderLogLogic;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Log;
|
||||
|
||||
class OrderFinish extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('order_finish')
|
||||
->setDescription('普通订单自动确认收货');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
try {
|
||||
$time = time();
|
||||
$config = ConfigServer::get('transaction', 'order_auto_receipt_days', 7);
|
||||
if ($config == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$finish_limit = $config * 24 * 60 * 60;
|
||||
$model = new Order();
|
||||
$orders = $model->field(true)->where([
|
||||
['order_status', '=', OrderEnum::ORDER_STATUS_GOODS],
|
||||
['pay_status', '=', OrderEnum::PAY_STATUS_PAID],
|
||||
['delivery_type', '<>', OrderEnum::DELIVERY_TYPE_SELF],
|
||||
['del', '=', 0]
|
||||
])->whereRaw("shipping_time+$finish_limit < $time")
|
||||
->select()->toArray();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
$model->where(['id' => $order['id']])
|
||||
->update([
|
||||
'order_status' => OrderEnum::ORDER_STATUS_COMPLETE,
|
||||
'update_time' => $time,
|
||||
'confirm_take_time' => $time,
|
||||
]);
|
||||
|
||||
//订单日志
|
||||
OrderLogLogic::record(
|
||||
OrderLogEnum::TYPE_SYSTEM,
|
||||
OrderLogEnum::SYSTEM_CONFIRM_ORDER,
|
||||
$order['id'],
|
||||
0,
|
||||
OrderLogEnum::SYSTEM_CONFIRM_ORDER
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Log::write('自动确认收货异常:'.$e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user