// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\console\service; use app\common\enum\book\order\PayStatus; use app\console\model\Book as OrderModel; use app\common\service\BaseService; use app\common\service\Book as OrderService; use app\common\library\helper; use app\console\library\Tools; /** * 服务类:报名订单订单模块 * Class Book * @package app\console\service */ class Book extends BaseService { /** * 未支付订单自动关闭 * @param int $storeId * @param int $closeHours 自定关闭订单有效期 (小时) * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function closeEvent(int $storeId, int $closeHours) { // 截止时间 $deadlineTime = time() - ((int)$closeHours * 60 * 60); // 查询截止时间未支付的订单 $model = new OrderModel; $list = $model->getListByClose($deadlineTime); // 订单ID集 $orderIds = helper::getArrayColumn($list, 'order_id'); if (!empty($orderIds)) { // 取消订单事件处理 /* foreach ($list as $order) { OrderService::cancelEvent($order); }*/ // 批量更新订单状态为已取消 $model->onBatchUpdate($orderIds, ['order_status' => PayStatus::CANCEL]); } // 记录日志 Tools::taskLogs('Book', 'closeEvent', [ 'storeId' => $storeId, 'closeHours' => $closeHours, 'deadlineTime' => $deadlineTime, 'orderIds' => helper::jsonEncode($orderIds) ]); } /** * 已发货订单自动确认收货 * @param int $storeId * @param int $receiveDays 自动收货天数 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function receiveEvent(int $storeId, int $receiveDays) { // 截止时间 $deadlineTime = time() - ((int)$receiveDays * 86400); // 查询截止时间未确认收货的订单ID集 $model = new OrderModel; $orderIds = $model->getOrderIdsByReceive($deadlineTime); // 更新订单收货状态 if (!empty($orderIds)) { // 批量更新订单状态为已收货 $model->onUpdateReceived($orderIds); } // 记录日志 Tools::taskLogs('Book', 'receiveEvent', [ 'storeId' => $storeId, 'receiveDays' => $receiveDays, 'deadlineTime' => $deadlineTime, 'orderIds' => helper::jsonEncode($orderIds) ]); } }