Service.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace app\api\model\service;
  3. use app\api\model\BaseModel;
  4. use redis\RedisClient;
  5. class Service extends BaseModel
  6. {
  7. // 表名
  8. protected $name = 'service';
  9. public function fetchServices($type, $params, $page = 1, $size = 10, $user = null)
  10. {
  11. $where = [
  12. 'type' => $type,
  13. 'status' => \E_BASE_STATUS::Normal
  14. ];
  15. if (isset($params['category_id']) && $params['category_id'] > 0)
  16. $where['category_id'] = $params['category_id'];
  17. if (isset($params['hot']) && $params['hot'])
  18. $where['hot'] = 1;
  19. if (isset($params['store_id']) && $params['store_id'] > 0)
  20. $where['store_id'] = $params['store_id'];
  21. if (isset($params["sift"]) && $params['sift'])
  22. $where['sift'] = 1;
  23. if (!isset($params["is_add_clock"]) || $params["is_add_clock"] != 1) {
  24. $where['is_add_clock'] = 0;
  25. }
  26. $q = ["id", "<>", "276"];
  27. if ($user) {
  28. $exist = RedisClient::of()->get("scan:qr:codes:" . $user["id"]);
  29. if ($exist) {
  30. $q = ["id", ">", "0"];
  31. }
  32. }
  33. return $this->where($where)
  34. ->where($q[0], $q[1], $q[2])
  35. ->order('sort', 'desc')
  36. ->order('real_price', 'ASC')
  37. ->page($page)
  38. ->paginate($size);
  39. }
  40. }