|
@@ -9,6 +9,7 @@
|
|
namespace App\Http\Controllers\V1;
|
|
namespace App\Http\Controllers\V1;
|
|
|
|
|
|
use App\Models\Product;
|
|
use App\Models\Product;
|
|
|
|
+use App\Models\ProductCategory;
|
|
use App\Models\StatProduct;
|
|
use App\Models\StatProduct;
|
|
use App\Models\StatProductDownload;
|
|
use App\Models\StatProductDownload;
|
|
use Dingo\Api\Http\Request;
|
|
use Dingo\Api\Http\Request;
|
|
@@ -17,19 +18,45 @@ use Illuminate\Http\JsonResponse;
|
|
|
|
|
|
class ProductController extends Controller
|
|
class ProductController extends Controller
|
|
{
|
|
{
|
|
|
|
+
|
|
|
|
+ public function cate(Request $request): JsonResponse
|
|
|
|
+ {
|
|
|
|
+ $limit = $request->input('limit', 3);
|
|
|
|
+ $keywords = $request->input('keywords', '');
|
|
|
|
+ $page = request()->input('page',1);
|
|
|
|
+ $offset = ($page - 1) * $limit;
|
|
|
|
+
|
|
|
|
+ $lists = ProductCategory::where('is_opened', 1)
|
|
|
|
+ ->when($keywords, function ($query, $keywords) {
|
|
|
|
+ /* @var Builder $query*/
|
|
|
|
+ return $query->where('name','like', "%$keywords%");
|
|
|
|
+ })
|
|
|
|
+ ->orderByDesc('sort')
|
|
|
|
+ ->limit($limit)
|
|
|
|
+ ->offset($offset)
|
|
|
|
+ ->get();
|
|
|
|
+
|
|
|
|
+ return $this->success($lists);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
public function search(Request $request): JsonResponse
|
|
public function search(Request $request): JsonResponse
|
|
{
|
|
{
|
|
$limit = $request->input('limit');
|
|
$limit = $request->input('limit');
|
|
$keywords = $request->input('keywords', '');
|
|
$keywords = $request->input('keywords', '');
|
|
$page = request()->input('page',1);
|
|
$page = request()->input('page',1);
|
|
|
|
+ $cateId = request()->input('cate_id',0);
|
|
$offset = ($page - 1) * $limit;
|
|
$offset = ($page - 1) * $limit;
|
|
|
|
|
|
-
|
|
|
|
$lists = Product::withCount(['viewer'])->where('is_opened', 1)
|
|
$lists = Product::withCount(['viewer'])->where('is_opened', 1)
|
|
->when($keywords, function ($query, $keywords) {
|
|
->when($keywords, function ($query, $keywords) {
|
|
/* @var Builder $query*/
|
|
/* @var Builder $query*/
|
|
return $query->where('name','like', "%$keywords%");
|
|
return $query->where('name','like', "%$keywords%");
|
|
})
|
|
})
|
|
|
|
+ ->when($cateId, function ($query, $cateId) {
|
|
|
|
+ /* @var Builder $query*/
|
|
|
|
+ return $query->where('cate_id', $cateId);
|
|
|
|
+ })
|
|
->orderByDesc('viewer_count')
|
|
->orderByDesc('viewer_count')
|
|
->orderByDesc('sort')
|
|
->orderByDesc('sort')
|
|
->limit($limit)
|
|
->limit($limit)
|