getJsonData(); $rules = [ 'ct_type' => 'nullable', 'ct_fid' => 'nullable', 'page' => 'nullable|numeric', 'page_size' => 'nullable|numeric' ]; $validator = $validatorFactory->make($inputData, $rules); if ($validator->fails()) { return json_fail($validator->errors()->first()); } if ($inputData['ct_type']) { // 判断类型 if (!in_array($inputData['ct_type'], ['OTH', 'ID', 'VSA', 'TXZ', 'GID', 'TBZ', 'HXZ'])) { return json_fail('ct_type 错误'); } } $where = []; // 存在且不等于空的情况下添加条件 if (isset($inputData['ct_type']) && $inputData['ct_type'] != '') { $where['ct_type'] = $inputData['ct_type']; } if (isset($inputData['ct_fid']) && $inputData['ct_fid'] != '') { $where['ct_fid'] = $inputData['ct_fid']; } if (count($where) !== 2) { return json_fail('两个条件必须存在才执行搜索!'); } $options = [ 'skip'=>0, 'limit' => 30, 'sort' => [ 'check_time' => -1, ], ]; // 查询数据 $hotelRecordModel = make(HotelLogModel::class); $hotelRecordData = $hotelRecordModel->db() ->find($where, $options) ->toArray(); return json_success($hotelRecordData); } }