Service.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. 'city_code' => "require|number",
  40. 'category_id' => "number",
  41. 'hot' => "number",
  42. // 'is_add_clock'
  43. ]))->checkBody();
  44. $user = $this->auth->getUser();
  45. list($page, $size) = [$params['page'] ?? 1, $params['size'] ?? 10];
  46. $paginate = $this->serviceModel->fetchServices(\E_SERVICE_TYPE::App, $params, $page, $size, $user);
  47. $items = collection($paginate->items())->toArray();
  48. $membership_discount_rate = config("site.membership_discount_rate") / 100;
  49. foreach ($items as &$item) {
  50. $item["membership_discount_price"] = fixed2Float($item["real_price"] * $membership_discount_rate);
  51. }
  52. $this->success([
  53. $items,
  54. $paginate->total()
  55. ]);
  56. }
  57. /**
  58. * 获取球房服务分类
  59. */
  60. public function fetchStoreCategory()
  61. {
  62. $params = (new BaseApiValidate([
  63. 'store_id' => "require|number",
  64. ]))->checkBody();
  65. $category = $this->serviceCategoryModel->fetchServiceCategory(\E_SERVICE_TYPE::Store, $params['store_id']);
  66. $this->success($category);
  67. }
  68. public function fetchStore()
  69. {
  70. $params = (new BaseApiValidate([
  71. 'store_id' => "require|number",
  72. 'category_id' => "number",
  73. 'hot' => "number"
  74. ]))->checkBody();
  75. list($page, $size) = [$params['page'] ?? 1, $params['size'] ?? 10];
  76. $paginate = $this->serviceModel->fetchServices(\E_SERVICE_TYPE::Store, $params, $page, $size);
  77. $items = collection($paginate->items())->toArray();
  78. $membership_discount_rate = config("site.membership_discount_rate") / 100;
  79. foreach ($items as &$item) {
  80. $item["membership_discount_price"] = fixed2Float($item["real_price"] * $membership_discount_rate);
  81. }
  82. $this->success([
  83. $items,
  84. $paginate->total()
  85. ]);
  86. }
  87. public function siftService()
  88. {
  89. $user = $this->auth->getUser();
  90. $params = (new BaseApiValidate([
  91. "page" => "require|number",
  92. "size" => "require|number"
  93. ]))->checkBody();
  94. $paginate = $this->serviceModel->fetchServices(\E_SERVICE_TYPE::App, ["is_add_clock" => $params["is_add_clock"] ?? null, "sift" => 1], $params['page'], $params['size'], $user);
  95. $items = collection($paginate->items())->toArray();
  96. $membership_discount_rate = config("site.membership_discount_rate") / 100;
  97. foreach ($items as &$item) {
  98. $item["membership_discount_price"] = fixed2Float($item["real_price"] * $membership_discount_rate);
  99. }
  100. $this->success([
  101. $items,
  102. $paginate->total()
  103. ]);
  104. }
  105. }