model = $model; $this->wxappId = $model::$wxapp_id; // 秒杀订单行为管理 $this->sharp(); return true; } /** * 秒杀订单行为管理 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ private function sharp() { // 未支付订单自动关闭 $this->close(); } /** * 未支付订单自动关闭 * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \Exception */ private function close() { $key = "__task_space__sharp_order__{$this->wxappId}"; if (Cache::has($key)) return true; // 取消n分钟以前的的未付款订单 $minute = SettingModel::getItem('basic')['order']['order_close']; if ($minute < 1) return false; // 截止时间 $deadlineTime = time() - ((int)$minute * 60); // 执行自动关闭 $service = new OrderService; $service->close($deadlineTime, ['order_source' => OrderSourceEnum::SHARP]); // 记录日志 $this->dologs('close', [ 'close_minute' => (int)$minute, 'deadline_time' => $deadlineTime, 'orderIds' => json_encode($service->getCloseOrderIds()), ]); return true; } /** * 记录日志 * @param $method * @param array $params * @return bool|int */ private function dologs($method, $params = []) { $value = 'behavior sharp Order --' . $method; foreach ($params as $key => $val) $value .= ' --' . $key . ' ' . $val; return log_write($value); } }