appId = $app_id; $this->model = new BranchModel(); // 执行已完成活动的结算 $this->settled(); // 未支付报名自动删除 $this->deleteActivityUser(); } catch (\Throwable $e) { echo 'ERROR ORDER: ' . $e->getMessage() . PHP_EOL; log_write('ORDER TASK : ' . $app_id . '__ ' . $e->getMessage(), 'task'); } return true; } /** * 未支付报名自动删除 */ private function deleteActivityUser() { $key = "task_space__branch__activityUser__{$this->appId}"; if (Cache::has($key)) return true; $orderIds = $this->model->getActivityUserIds($this->appId); $this->model->deleteActivityUser($orderIds); // 记录日志 $this->dologs('close', [ 'orderIds' => json_encode($orderIds), ]); Cache::set($key, time(), 8 * 3600); return true; } /** * 已完成活动结算 */ private function settled() { $key = "task_space__branch__activity__{$this->appId}"; if (Cache::has($key)) return true; // 查询活动列表 $activityList = $this->model->getActivitySettledList($this->appId); // 活动id集 $activityIds = helper::getArrayColumn($activityList, 'activity_id'); $this->model->settledActivity($activityList); // 记录日志 $this->dologs('settled', [ 'activityIds' => json_encode($activityIds), ]); Cache::set($key, time(), 1800); return true; } /** * 记录日志 */ private function dologs($method, $params = []) { $value = 'behavior Branch-Activity --' . $method; foreach ($params as $key => $val) $value .= ' --' . $key . ' ' . $val; return log_write($value, 'task'); } }