Service.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\validate\BaseApiValidate;
  4. use app\common\controller\Api;
  5. use think\Request;
  6. class Service extends Api
  7. {
  8. protected $noNeedLogin = [
  9. 'fetchAppCategory',
  10. 'fetchApp',
  11. 'fetchStoreCategory',
  12. 'fetchStore'
  13. ];
  14. private $serviceCategoryModel;
  15. private $serviceModel;
  16. public function __construct(Request $request = null)
  17. {
  18. $this->serviceCategoryModel = new \app\api\model\service\Category();
  19. $this->serviceModel = new \app\api\model\service\Service();
  20. parent::__construct($request);
  21. }
  22. /**
  23. * 获取App服务分类
  24. * @throws \think\db\exception\DataNotFoundException
  25. * @throws \think\db\exception\ModelNotFoundException
  26. * @throws \think\exception\DbException
  27. */
  28. public function fetchAppCategory()
  29. {
  30. $category = $this->serviceCategoryModel->fetchServiceCategory(\E_SERVICE_TYPE::App);
  31. $this->success($category);
  32. }
  33. /**
  34. * 获取App服务
  35. */
  36. public function fetchApp()
  37. {
  38. $params = (new BaseApiValidate([
  39. 'category_id' => "number",
  40. 'hot' => "number",
  41. // 'is_add_clock'
  42. ]))->checkBody();
  43. $user = $this->auth->getUser();
  44. list($page, $size) = [$params['page'] ?? 1, $params['size'] ?? 10];
  45. $paginate = $this->serviceModel->fetchServices(\E_SERVICE_TYPE::App, $params, $page, $size, $user);
  46. $items = collection($paginate->items())->toArray();
  47. $membership_discount_rate = config("site.membership_discount_rate") / 100;
  48. foreach ($items as &$item) {
  49. $item["membership_discount_price"] = fixed2Float($item["real_price"] * $membership_discount_rate);
  50. }
  51. $this->success([
  52. $items,
  53. $paginate->total()
  54. ]);
  55. }
  56. /// 根据地区筛选
  57. public function fetchAppV2()
  58. {
  59. $params = (new BaseApiValidate([
  60. 'p_code' => "require|number",
  61. 'category_id' => "number",
  62. 'hot' => "number"
  63. ]))->checkBody();
  64. $user = $this->auth->getUser();
  65. list($page, $size) = [$params['page'] ?? 1, $params['size'] ?? 10];
  66. $paginate = $this->serviceModel->fetchServicesV2(\E_SERVICE_TYPE::App, $params, $page, $size, $user);
  67. $items = collection($paginate->items())->toArray();
  68. $membership_discount_rate = config("site.membership_discount_rate") / 100;
  69. foreach ($items as &$item) {
  70. $item["membership_discount_price"] = fixed2Float($item["real_price"] * $membership_discount_rate);
  71. }
  72. $this->success([
  73. $items,
  74. $paginate->total()
  75. ]);
  76. }
  77. /**
  78. * 获取球房服务分类
  79. */
  80. public function fetchStoreCategory()
  81. {
  82. $params = (new BaseApiValidate([
  83. 'store_id' => "require|number",
  84. ]))->checkBody();
  85. $category = $this->serviceCategoryModel->fetchServiceCategory(\E_SERVICE_TYPE::Store, $params['store_id']);
  86. $this->success($category);
  87. }
  88. public function fetchStore()
  89. {
  90. $params = (new BaseApiValidate([
  91. 'store_id' => "require|number",
  92. 'category_id' => "number",
  93. 'hot' => "number"
  94. ]))->checkBody();
  95. list($page, $size) = [$params['page'] ?? 1, $params['size'] ?? 10];
  96. $paginate = $this->serviceModel->fetchServices(\E_SERVICE_TYPE::Store, $params, $page, $size);
  97. $items = collection($paginate->items())->toArray();
  98. $membership_discount_rate = config("site.membership_discount_rate") / 100;
  99. foreach ($items as &$item) {
  100. $item["membership_discount_price"] = fixed2Float($item["real_price"] * $membership_discount_rate);
  101. }
  102. $this->success([
  103. $items,
  104. $paginate->total()
  105. ]);
  106. }
  107. public function siftService()
  108. {
  109. $user = $this->auth->getUser();
  110. $params = (new BaseApiValidate([
  111. "page" => "require|number",
  112. "size" => "require|number"
  113. ]))->checkBody();
  114. list($page, $size) = [$params['page'], $params['size']];
  115. $paginate = $this->serviceModel->fetchServices(\E_SERVICE_TYPE::App, [isset($params["is_add_clock"]) ? $params["is_add_clock"] : null, "sift" => 1], $page, $size, $user);
  116. $items = collection($paginate->items())->toArray();
  117. $membership_discount_rate = config("site.membership_discount_rate") / 100;
  118. foreach ($items as &$item) {
  119. $item["membership_discount_price"] = fixed2Float($item["real_price"] * $membership_discount_rate);
  120. }
  121. $this->success([
  122. $items,
  123. $paginate->total()
  124. ]);
  125. }
  126. }