| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace Modules\Manage\Controllers;
- use App\Model\Mongo\HotelLogModel;
- use Hyperf\Validation\Contract\ValidatorFactoryInterface;
- use MongoDB\Client;
- /**
- * 酒店记录
- */
- class HotelRecordController extends BaseController
- {
- /**
- * 开房记录列表
- */
- public function lists(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->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);
- }
- }
|