Robot.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. /**
  5. * 智能问答模型
  6. */
  7. class Robot extends Model
  8. {
  9. /**
  10. * select数据筛选
  11. *
  12. * @access public
  13. * @param mixed $field 字段
  14. * @param mixed $join 关联
  15. * @param mixed $where 条件
  16. * @param mixed $offset 分页开始
  17. * @param mixed $limit 分页大小
  18. * @param mixed $order 排序
  19. * @return array 返回类型
  20. */
  21. public function selectJoin($field, $join, $where=[], $offset='', $limit='', $order=['robot_updateTime'=>'desc'])
  22. {
  23. $result = $this->field($field);
  24. if (empty($join) === false) {
  25. $result = $result->alias('a');
  26. foreach ($join as $k => $v) {
  27. $result = $result->join($k, $v,'left');
  28. }
  29. }
  30. if (empty($where) === false) {
  31. $result = $result->where($where);
  32. }
  33. if (empty($offset) === false && empty($limit) === false) {
  34. $result = $result->limit($offset, $limit);
  35. }
  36. if (empty($order) === false) {
  37. foreach ($order as $k => $v) {
  38. $result = $result->order($k, $v);
  39. }
  40. }
  41. $result = $result->select();
  42. return $result;
  43. }//end selectJoin()
  44. /**
  45. * select数据筛选
  46. *
  47. * @access public
  48. * @param mixed $where 条件
  49. * @return array 返回类型
  50. */
  51. public function count($where=[])
  52. {
  53. $result = $this;
  54. if (empty($where) === false) {
  55. $result = $result->where($where)->count();
  56. }else{
  57. $result = $result->where($where)->count();
  58. }
  59. return $result;
  60. }//end count()
  61. }