Service.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\api\model\service;
  3. use app\api\model\BaseModel;
  4. class Service extends BaseModel
  5. {
  6. // 表名
  7. protected $name = 'service';
  8. /**
  9. * @param $type
  10. * @param $params
  11. * @param $page
  12. * @param $size
  13. * @return \think\Paginator
  14. * @throws \think\exception\DbException
  15. */
  16. public function fetchServices($type, $params, $page = 1, $size = 10)
  17. {
  18. $where = [
  19. 'type' => $type,
  20. 'status' => \E_BASE_STATUS::Normal,
  21. ];
  22. if (isset($params['city_code']) && $params['city_code'] > 0) {
  23. $where['p_code'] = parse_area($params['city_code'])['p_code'];
  24. }
  25. if (isset($params['category_id']) && $params['category_id'] > 0)
  26. $where['category_id'] = $params['category_id'];
  27. if (isset($params['hot']) && $params['hot'])
  28. $where['hot'] = 1;
  29. if (isset($params['store_id']) && $params['store_id'] > 0)
  30. $where['store_id'] = $params['store_id'];
  31. if (isset($params["sift"]) && $params['sift'])
  32. $where['sift'] = 1;
  33. if (!isset($params["is_add_clock"]) || $params["is_add_clock"] != 1) {
  34. $where['is_add_clock'] = 0;
  35. }
  36. return $this->where($where)
  37. ->order('sort', 'desc')
  38. ->order('real_price', 'ASC')
  39. ->page($page)
  40. ->paginate($size);
  41. }
  42. }