HotelRecordController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Modules\Manage\Controllers;
  3. use App\Model\Mongo\HotelLogModel;
  4. use Hyperf\Validation\Contract\ValidatorFactoryInterface;
  5. use MongoDB\Client;
  6. /**
  7. * 酒店记录
  8. */
  9. class HotelRecordController extends BaseController
  10. {
  11. /**
  12. * 开房记录列表
  13. */
  14. public function lists(ValidatorFactoryInterface $validatorFactory)
  15. {
  16. $inputData = $this->getJsonData();
  17. $rules = [
  18. 'ct_type' => 'nullable',
  19. 'ct_fid' => 'nullable',
  20. 'page' => 'nullable|numeric',
  21. 'page_size' => 'nullable|numeric'
  22. ];
  23. $validator = $validatorFactory->make($inputData, $rules);
  24. if ($validator->fails()) {
  25. return json_fail($validator->errors()->first());
  26. }
  27. if ($inputData['ct_type']) {
  28. // 判断类型
  29. if (!in_array($inputData['ct_type'], ['OTH', 'ID', 'VSA', 'TXZ', 'GID', 'TBZ', 'HXZ'])) {
  30. return json_fail('ct_type 错误');
  31. }
  32. }
  33. $where = [];
  34. // 存在且不等于空的情况下添加条件
  35. if (isset($inputData['ct_type']) && $inputData['ct_type'] != '') {
  36. $where['ct_type'] = $inputData['ct_type'];
  37. }
  38. if (isset($inputData['ct_fid']) && $inputData['ct_fid'] != '') {
  39. $where['ct_fid'] = $inputData['ct_fid'];
  40. }
  41. if (count($where) !== 2) {
  42. return json_fail('两个条件必须存在才执行搜索!');
  43. }
  44. $options = [
  45. 'skip'=>0,
  46. 'limit' => 30,
  47. 'sort' => [
  48. 'check_time' => -1,
  49. ],
  50. ];
  51. // 查询数据
  52. $hotelRecordModel = make(HotelLogModel::class);
  53. $hotelRecordData = $hotelRecordModel->db()
  54. ->find($where, $options)
  55. ->toArray();
  56. return json_success($hotelRecordData);
  57. }
  58. }