123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- /**
- * Created by PhpStorm
- * DateTime: 2022/10/2 13:32
- *
- * @description
- */
- namespace App\Http\Controllers\V1;
- use App\Models\Product;
- use App\Models\Showroom;
- use App\Models\StatShowroom;
- use Dingo\Api\Http\Request;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Http\JsonResponse;
- class CasesController extends Controller
- {
- public function search(Request $request): JsonResponse
- {
- $limit = $request->input('limit');
- $keywords = $request->input('keywords', '');
- $page = request()->input('page',1);
- $offset = ($page - 1) * $limit;
- $lists = Showroom::withCount(['viewer'])
- ->where('is_opened', 1)
- ->when($keywords, function ($query, $keywords) {
- /* @var Builder $query*/
- return $query->where('name','like', "%$keywords%");
- })
- //->orderByDesc('viewer_count')
- ->orderByDesc('sort')
- ->limit($limit)
- ->offset($offset)
- ->get();
- return $this->success($lists);
- }
- public function detail($id): JsonResponse
- {
- $info = Showroom::where('id',$id)
- ->first();
- return $this->success($info);
- }
- public function viewer($id): JsonResponse
- {
- $stat = new StatShowroom();
- $stat->showroom_id = $id;
- $stat->user_id = \user()->id;
- $stat->save();
- return $this->success();
- }
- }
|