12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace App\Modules\Mini\Controllers;
- use App\Base\BaseController;
- use App\Models\Cart;
- use App\Modules\Mini\Services\CartService;
- use Faker\Provider\Image;
- use Illuminate\Support\Facades\Auth;
- class CartController extends BaseController
- {
- protected CartService $service;
- /**
- * @param CartService $service
- */
- public function __construct(CartService $service)
- {
- $this->service = $service;
- }
- public function index()
- {
- $params = $this->valid([
- "page_size" => "int",
- ]);
- return $this->ok($this->service->paginate(Auth::user(), $params));
- }
- public function del()
- {
- $params = $this->valid([
- "ids" => "required|array",
- ]);
- $row = Cart::whereIn("id", $params['ids'])->where("user_id", Auth::id())->delete();
- return $this->ok([
- "row" => $row,
- ]);
- }
- public function ask()
- {
- $params = $this->valid([
- "ids" => "required|array",
- ]);
- return $this->ok($this->service->ask(Auth::user(), $params));
- }
- public function store()
- {
- $params = $this->valid([
- "id" => "required",
- "count" => "required",
- ]);
- $cart = app(CartService::class)->update(Auth::user(), $params);
- return $this->ok([
- "id" => $cart->id,
- ]);
- }
- }
|