System.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\model\dynamic\Topic;
  4. use app\admin\model\Hotel;
  5. use app\admin\model\membership\Config;
  6. use app\admin\model\Protocol;
  7. use app\admin\model\Question;
  8. use app\api\model\Area;
  9. use app\api\model\system\Feedback;
  10. use app\api\model\Tags;
  11. use app\api\model\Voucher;
  12. use app\api\validate\BaseApiValidate;
  13. use app\common\controller\Api;
  14. use think\Request;
  15. class System extends Api
  16. {
  17. protected $noNeedLogin = ["*"];
  18. private $systemVoucherModel;
  19. public function __construct(Request $request = null)
  20. {
  21. parent::__construct($request);
  22. $this->systemVoucherModel = new Voucher();
  23. }
  24. function fetchVoucher()
  25. {
  26. $this->success($this->systemVoucherModel->order("takeAmount", "desc")->where("exchange_score", ">", 0)->select());
  27. }
  28. function findConfig()
  29. {
  30. $params = (new BaseApiValidate([
  31. 'config_name' => "require",
  32. ]))->checkBody();
  33. $value = config("site." . $params["config_name"]);
  34. if (is_null($value)) {
  35. $protocol = Protocol::where('code', $params["config_name"])->find();
  36. if ($protocol) {
  37. $value = $protocol["content"];
  38. }
  39. }
  40. $this->success($value);
  41. }
  42. public function findAreaCode()
  43. {
  44. $params = (new BaseApiValidate([
  45. "city_name" => "require",
  46. ]))->checkBody();
  47. $area = (new Area())->where([
  48. "name" => $params["city_name"],
  49. "level" => 2
  50. ])->find();
  51. $area ? $this->success($area) : $this->error("城市不存在!");
  52. }
  53. public function getCitys()
  54. {
  55. $this->success((new Area())->where("use", 1)->where("level", "in", [1, 2])->select());
  56. }
  57. public function getAllCitys()
  58. {
  59. $this->success((new Area())->where("use", 1)->select());
  60. }
  61. public function getTags()
  62. {
  63. $this->success((new Tags())->select());
  64. }
  65. public function fetchFeedbackReason()
  66. {
  67. $this->success([
  68. "私单问题",
  69. "助教服务问题",
  70. "APP体验问题",
  71. "其他问题"
  72. ]);
  73. }
  74. public function fetchMembershipConfig()
  75. {
  76. $this->success((new Config())->select());
  77. }
  78. public function question()
  79. {
  80. $this->success(
  81. (new Question())
  82. ->order("weight", "ASC")
  83. ->select()
  84. );
  85. }
  86. public function dynamicTopic()
  87. {
  88. $this->success((new Topic())->select());
  89. }
  90. public function fetchFeedback($type = '*', $user_id = null, $massager_id = null, $agency_id = null, $page = 1, $size = 10)
  91. {
  92. $model = new Feedback();
  93. $query = $model->where("status", 'in', $type == '*' ? ['default', 'dispose', 'refuse'] : [$type]);
  94. if ($user_id > 0) {
  95. $query->where("user_id", $user_id);
  96. }
  97. if ($massager_id > 0) {
  98. $query->where("massager_id", $massager_id);
  99. }
  100. if ($agency_id > 0) {
  101. $query->where("agency_id", $agency_id);
  102. }
  103. $paginate = $query
  104. ->page($page)
  105. ->paginate($size);
  106. $this->success([
  107. $paginate->items(),
  108. $paginate->total()
  109. ]);
  110. }
  111. public function fetchHotel()
  112. {
  113. $params = (new BaseApiValidate())->checkBody([
  114. "lng" => "require",
  115. "lat" => "require"
  116. ]);
  117. $model = new Hotel();
  118. $subQuery = $model->field("*,round(st_distance_sphere (point({$params["lng"]},{$params["lat"]}),point ( `lng`, `lat` ))) distance");
  119. $query = $model->table($subQuery->buildSql() . ' distance');
  120. $paginate = $query
  121. ->order('distance', 'ASC')
  122. ->order("sort", "DESC")
  123. ->page(isset($params["page"]) ? $params["page"] : 1)
  124. ->paginate(isset($params["size"]) ? $params["size"] : 30);
  125. $this->success([
  126. $paginate->items(),
  127. $paginate->total()
  128. ]);
  129. }
  130. }