Query.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace UCore\Db;
  3. /**
  4. * 查询构建特性
  5. *
  6. * 提供常用的查询条件构建方法
  7. */
  8. trait Query
  9. {
  10. /**
  11. * 如果是数字,则进行where条件查询
  12. *
  13. * @param string $field 字段名
  14. * @param string $op 操作符
  15. * @param string $fieldSql 自定义SQL字段名
  16. * @return $this
  17. */
  18. public function queryNumber($field, $op = '=', $fieldSql = '')
  19. {
  20. if(!$fieldSql){
  21. $fieldSql= $field;
  22. }
  23. if ($this->isNumber($field)) {
  24. $this->query = $this->query->where($fieldSql, $op, $this->getNumber($field));
  25. }
  26. return $this;
  27. }
  28. public function queryString($field, $op = '=')
  29. {
  30. if ($this->isString($field)) {
  31. $this->query = $this->query->where($field, $op, $this->getNumber($field));
  32. }
  33. return $this;
  34. }
  35. /**
  36. * 存在,且notEmpay
  37. * @param $field
  38. * @param $op
  39. * @return $this
  40. */
  41. public function queryExist($field, $op = '=')
  42. {
  43. if ($this->notNull($field) && $this->notEmpty($field)) {
  44. $this->query = $this->query->where($field, $op, $this->data[$field]);
  45. }
  46. return $this;
  47. }
  48. }