// +---------------------------------------------------------------------- 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); } }