1557492053 1 jaar geleden
bovenliggende
commit
ee987f40b5
1 gewijzigde bestanden met toevoegingen van 10 en 7 verwijderingen
  1. 10 7
      application/api/controller/Community.php

+ 10 - 7
application/api/controller/Community.php

@@ -5,6 +5,7 @@ namespace app\api\controller;
 
 
 use app\admin\model\dynamic\Dynamic;
+use app\admin\model\dynamic\Topic;
 use app\api\model\massager\Collect;
 use app\api\validate\BaseApiValidate;
 use app\common\controller\Api;
@@ -47,25 +48,25 @@ class Community extends Api
         ];
         $subQuery = $dynamicModel->field("*,round(st_distance_sphere (point({$params["lng"]},{$params["lat"]}), point ( `lng`, `lat` ))) distance");
         if (isset($params["hot"]) && $params["hot"] == 1) {
-            array_push($where, ["hot", "=", 1]);
+            $where[] = ["hot", "=", 1];
         }
         if (isset($params["topic_id"]) && $params["topic_id"] > 0) {
-            array_push($where, ["topic_id", "=", $params["topic_id"]]);
+            $where[] = ["topic_id", "=", $params["topic_id"]];
         }
         if (isset($params["local"]) && $params["local"] == 1) {
             if (!isset($params["city_code"]))
                 $this->error("定位错误!");
-            array_push($where, ["city_code", "=", $params["city_code"]]);
+            $where[] = ["city_code", "=", $params["city_code"]];
         }
         if (isset($params["collect"]) && $params["collect"] == 1) {
             $user = $this->auth->getUser();
             $collects = (new Collect())->where("user_id", $user ? $user["id"] : -1)->select();
-            array_push($where, ["massager_id", "in", array_map(function ($item) {
+            $where[] = ["massager_id", "in", array_map(function ($item) {
                 return $item["massager_id"];
-            }, $collects)]);
+            }, $collects)];
         }
         if (isset($params["search_text"]) && mb_strlen($params["search_text"]) > 0) {
-            array_push($where, ["massager.name", "like", "%{$params["search_text"]}%"]);
+            $where[] = ["massager.name", "like", "%{$params["search_text"]}%"];
         }
         foreach ($where as $item) {
             $subQuery->where($item[0], $item[1], $item[2]);
@@ -89,8 +90,10 @@ class Community extends Api
             return $p;
         }, []);
 
+        $topicModel = new Topic();
         foreach ($items as &$item) {
-            $item["massager"] = isset($f_massager[$item["massager_id"]]) ? $f_massager[$item["massager_id"]] : ["id" => null, "name" => null];
+            $item["massager"] = $f_massager[$item["massager_id"]] ?? ["id" => null, "name" => null];
+            $item["topic"] = $topicModel->get($item["topic_id"]);
         }
 
         $this->success([