123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types=1);
- namespace app\console\task;
- use app\console\service\Order as OrderService;
- use app\console\model\Setting as SettingModel;
- use app\common\model\order\RiceCardOrder;
- use app\common\model\card\UserRiceCard;
- /**
- * 定时任务:商城订单
- * Class Order
- * @package app\console\task
- */
- class OrderCancel extends Task
- {
- // 当前任务唯一标识
- private $taskKey = 'OrderCancel';
- // 任务执行间隔时长 (单位:秒)
- protected $taskExpire = 30;
- // 当前商城ID
- private $storeId;
- /**
- * 任务处理
- * @param array $param
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function handle(array $param)
- {
- ['storeId' => $this->storeId] = $param;
- $this->setInterval($this->storeId, $this->taskKey, $this->taskExpire, function () {
- // echo $this->taskKey . PHP_EOL;
- $this->closeEvent();// 未支付订单自动关闭
- $this->closeRiceCardEvent();//超时自动关闭米卡订单
- $this->riceCardRevodeEvent();//超时自动撤回米卡
- });
- }
- /**
- * 未支付订单自动关闭
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function closeEvent()
- {
- // 自动关闭订单的分钟数
- $closeMinutes = (int)$this->getOrderCancelSetting()['close_minutes'];
- if(env('SERVE_ENV')=='test'){
- $closeMinutes = 5;//测试超时订单5分钟
- }
- // 执行自动关闭
- if ($closeMinutes > 0) {
- $service = new OrderService;
- $service->closeEvent($this->storeId, $closeMinutes);
- }
- }
- //关闭米卡订单
- private function closeRiceCardEvent(){
- // 自动关闭订单的分钟数
- $closeMinutes = (int)$this->getOrderCancelSetting()['close_minutes'];
- // 执行自动关闭
- if ($closeMinutes > 0) {
- $riceCardOrder = new RiceCardOrder;
- $riceCardOrder->closeEvent($this->storeId, $closeMinutes);
- }
- }
- //米卡撤回
- private function riceCardRevodeEvent(){
- $userRiceCard = new UserRiceCard;
- $minute = 60*24;//一天不领 给撤回
- // $minute = 5;
- $userRiceCard->revokeEvent($minute);
- }
- /**
- * 获取商城交易设置
- * @return array|mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- private function getOrderCancelSetting()
- {
- return SettingModel::getItem('order_cancel', $this->storeId);
- }
- }
|