|
@@ -3,7 +3,10 @@
|
|
namespace App\Modules\Mini\Services;
|
|
namespace App\Modules\Mini\Services;
|
|
|
|
|
|
use App\Base\BaseService;
|
|
use App\Base\BaseService;
|
|
|
|
+use App\Models\Goods\Category;
|
|
|
|
+use App\Models\Goods\Goods;
|
|
use App\Models\Setting;
|
|
use App\Models\Setting;
|
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class PageService extends BaseService
|
|
class PageService extends BaseService
|
|
{
|
|
{
|
|
@@ -22,4 +25,60 @@ class PageService extends BaseService
|
|
];
|
|
];
|
|
})->values();
|
|
})->values();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public function categoryTree()
|
|
|
|
+ {
|
|
|
|
+ $categoryS = Category::with("childS")->where("parent_id", 0)->where("index_weight", ">", 0)->get(["id", "name", "thumb", "parent_id", "level", "weight"]);
|
|
|
|
+ return $categoryS->map(function (Category $category) {
|
|
|
|
+ return [
|
|
|
|
+ "id" => $category->id,
|
|
|
|
+ "name" => $category->name,
|
|
|
|
+ "thumb" => $category->thumb,
|
|
|
|
+ "child" => $this->childTree($category),
|
|
|
|
+ ];
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected function childTree(Category $category)
|
|
|
|
+ {
|
|
|
|
+ if ($category->childS->isEmpty()) {
|
|
|
|
+ return [];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $category->childS->map(function (Category $category) {
|
|
|
|
+ return [
|
|
|
|
+ "id" => $category->id,
|
|
|
|
+ "name" => $category->name,
|
|
|
|
+ "thumb" => $category->thumb,
|
|
|
|
+ "child" => $this->childTree($category),
|
|
|
|
+ ];
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function hotGoods($num = 10)
|
|
|
|
+ {
|
|
|
|
+ $goods = Goods::orderByDesc("view_total")->limit($num)->get();
|
|
|
|
+
|
|
|
|
+ return $goods->map(function (Goods $g) {
|
|
|
|
+ return [
|
|
|
|
+ "id" => $g->id,
|
|
|
|
+ "name" => $g->name,
|
|
|
|
+ "thumb" => $g->thumb,
|
|
|
|
+ "view_total" => $g->view_total,
|
|
|
|
+ ];
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function recommendedGoods($num = 10)
|
|
|
|
+ {
|
|
|
|
+ $goods = Goods::orderBy(DB::raw("rand() "))->limit($num)->get();
|
|
|
|
+
|
|
|
|
+ return $goods->map(function (Goods $g) {
|
|
|
|
+ return [
|
|
|
|
+ "id" => $g->id,
|
|
|
|
+ "name" => $g->name,
|
|
|
|
+ "thumb" => $g->thumb,
|
|
|
|
+ ];
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|