request->isGet()) { return json(['code' => 400, 'msg' => '请使用GET请求', 'data' => []]); } $refresh = (int)$this->request->get('refresh', 0); $defaultStart = date('Y-m-d 00:00:00', strtotime('-1 year')); $defaultEnd = date('Y-m-d 23:59:59'); $startTime = trim((string)$this->request->get('start_time', $defaultStart)); $endTime = trim((string)$this->request->get('end_time', $defaultEnd)); $limitParam = $this->request->get('limit', ''); $useLimit = ($limitParam !== '' && $limitParam !== null); $limit = $useLimit ? max(1, min(500, (int)$limitParam)) : 0; $redisKey = 'procuremen_redis'; $redis = null; try { $redis = redis(); } catch (\Exception $e) { $redis = null; } if (!$refresh && $redis) { try { $cached = $redis->get($redisKey); if ($cached !== false && $cached !== '') { $decoded = json_decode($cached, true); if (is_array($decoded)) { return json($decoded); } } } catch (\Exception $e) { // 读缓存失败则继续走库 } } $list = []; $dbOk = false; try { $query = Db::table('scydgy') ->alias('a') ->join('mcyd b', 'b.ICYDID = a.ICYDID AND b.iStatus >= 10', 'inner') ->field('a.ID, b.CCYDH, b.CYJMC, a.CDXMC, a.CGYBH, a.CGYMC, a.CDW, a.NGZL, b.CDF, a.cGzzxMc, a.MBZ, a.bwjg, a.iStatus, a.dStamp, b.dputrecord, b.cywyxm') ->where([ 'a.bwjg' => 1, 'a.iEndBz' => 0, 'a.iType' => 0, 'a.iStatus' => 10, ]) ->where('a.dStamp', '>=', $startTime) ->where('a.dStamp', '<=', $endTime) ->order('a.dStamp', 'desc'); if ($limit > 0) { $query->limit($limit); } $list = $query->select(); $dbOk = true; } catch (\Exception $e) { $list = []; $dbOk = false; } $result = [ 'code' => 200, 'msg' => 'success', 'data' => $list ?: [], ]; if ($redis && $dbOk) { try { $redis->set($redisKey, json_encode($result, JSON_UNESCAPED_UNICODE)); } catch (\Exception $e) { // 写缓存失败仍返回本次查询结果 } } if (!$dbOk && $redis) { try { $cached = $redis->get($redisKey); if ($cached !== false && $cached !== '') { $decoded = json_decode($cached, true); if (is_array($decoded)) { return json($decoded); } } } catch (\Exception $e) { } } return json($result); } }