购物车

parent 087a1313
<?php
namespace App\Http\Controllers\Api;
use App\Http\Requests\UserRegister;
use App\Models\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Validator;
//购物车控制器
class CartApiController extends Controller
{
use ThrottlesLogins, RegistersUsers;
public function addCart(Request $request)
{
$validator = Validator::make($request->all(), [
'email' => 'required|string|email|max:255',
'password' => 'required|string|min:8',
], [
'password.min' => 'Password must be at least 8 characters long.'
]);
if ($validator->fails()) {
return $this->setError($validator->errors()->first());
}
$this->incrementLoginAttempts($request);
return $this->setError('Login failure');
}
}
<?php
namespace App\Http\Services;
use App\Models\Inquiry;
use App\Models\InquiryItems;
use Illuminate\Support\Facades\DB;
//购物车服务器层
class CartService
{
//添加购物车
public static function addCart($data, $user)
{
return DB::transaction(function () use ($data, $user) {
$items = \Arr::get($data, 'item', []);
$inquiryItems = [];
foreach ($items as $item) {
$inquiryItems[] = [
'user_id' => $user->user_id,
'goods_id' => $item['goods_id'],
'goods_number' => $item['goods_number'],
'create_goods_price' => $item['create_goods_price'],
'create_time' => time(),
'update_time' => time(),
];
}
return InquiryItems::addInquiryItems($inquiryItems);
});
}
}
......@@ -20,4 +20,6 @@ class CartModel extends Model
return ($res) ? $res->toArray() : [];
}
}
......@@ -18,4 +18,4 @@
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
\ No newline at end of file
</IfModule>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment