| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- // +----------------------------------------------------------------------
- // | 商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.thinkphp.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: thinkphp <admin@yiovo.com>
- // +----------------------------------------------------------------------
- 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)
- ]);
- }
- }
|