diff --git a/app/Http/Middleware/ShopAuthenticate.php b/app/Http/Middleware/ShopAuthenticate.php index 82eb9b3a..6430f8d3 100644 --- a/app/Http/Middleware/ShopAuthenticate.php +++ b/app/Http/Middleware/ShopAuthenticate.php @@ -2,12 +2,38 @@ namespace App\Http\Middleware; +use Beike\Models\Customer; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; use Illuminate\Auth\AuthenticationException; use Illuminate\Auth\Middleware\Authenticate as Middleware; class ShopAuthenticate extends Middleware { + /** + * Handle an incoming request. + * + * @param Request $request + * @param \Closure $next + * @param string[] ...$guards + * @return mixed + * + * @throws AuthenticationException + */ + public function handle($request, \Closure $next, ...$guards) + { + $this->authenticate($request, $guards); + + $customer = current_customer(); + if ($customer->status != 1) { + Auth::guard(Customer::AUTH_GUARD)->logout(); + return redirect(shop_route('account.login')); + } + + return $next($request); + } + + /** * Get the path the user should be redirected to when they are not authenticated. * diff --git a/beike/Installer/config.php b/beike/Installer/config.php index dd0590ef..4cc21c84 100644 --- a/beike/Installer/config.php +++ b/beike/Installer/config.php @@ -43,9 +43,9 @@ return [ | */ 'permissions' => [ - 'storage/framework/' => '775', - 'storage/logs/' => '775', - 'bootstrap/cache/' => '775', + 'storage/framework/' => '755', + 'storage/logs/' => '755', + 'bootstrap/cache/' => '755', ], /* diff --git a/beike/Models/Brand.php b/beike/Models/Brand.php index 84559d4f..c926a8f0 100644 --- a/beike/Models/Brand.php +++ b/beike/Models/Brand.php @@ -18,7 +18,7 @@ class Brand extends Base { use HasFactory; - protected $fillable = ['name', 'country_id', 'first', 'logo', 'code', 'sort_order', 'status']; + protected $fillable = ['name', 'first', 'logo', 'sort_order', 'status']; public function products() :HasMany { diff --git a/beike/Repositories/BrandRepo.php b/beike/Repositories/BrandRepo.php index 907de8cc..95c9c0d8 100644 --- a/beike/Repositories/BrandRepo.php +++ b/beike/Repositories/BrandRepo.php @@ -31,7 +31,14 @@ class BrandRepo */ public static function create($data) { - return Brand::query()->create($data); + $brandData = [ + 'name' => $data['name'] ?? '', + 'first' => $data['first'] ?? '', + 'logo' => $data['logo'] ?? '', + 'sort_order' => (int)($data['sort_order'] ?? 0), + 'status' => (bool)($data['status'] ?? 1), + ]; + return Brand::query()->create($brandData); } /** @@ -48,7 +55,15 @@ class BrandRepo if (!$brand) { throw new Exception("品牌id $brand 不存在"); } - $brand->update($data); + + $brandData = [ + 'name' => $data['name'] ?? '', + 'first' => $data['first'] ?? '', + 'logo' => $data['logo'] ?? '', + 'sort_order' => (int)($data['sort_order'] ?? 0), + 'status' => (bool)($data['status'] ?? 1), + ]; + $brand->update($brandData); return $brand; } diff --git a/beike/Shop/Http/Controllers/Account/LoginController.php b/beike/Shop/Http/Controllers/Account/LoginController.php index 2a42ee4e..e00f65f5 100644 --- a/beike/Shop/Http/Controllers/Account/LoginController.php +++ b/beike/Shop/Http/Controllers/Account/LoginController.php @@ -14,11 +14,7 @@ namespace Beike\Shop\Http\Controllers\Account; use Beike\Models\Customer; use Beike\Shop\Http\Controllers\Controller; use Beike\Shop\Http\Requests\LoginRequest; -use Illuminate\Http\Request; -use function auth; -use function back; -use function redirect; -use function view; +use Illuminate\Support\Facades\Auth; class LoginController extends Controller { @@ -36,6 +32,11 @@ class LoginController extends Controller throw new \Exception("账号密码错误!"); } + $customer = current_customer(); + if ($customer && $customer->status != 1) { + Auth::guard(Customer::AUTH_GUARD)->logout(); + throw new \Exception("用户已被禁用!"); + } return json_success("登录成功!"); } } diff --git a/beike/Shop/Http/Controllers/Account/OrderController.php b/beike/Shop/Http/Controllers/Account/OrderController.php index 5451b4b5..f9f6ef70 100644 --- a/beike/Shop/Http/Controllers/Account/OrderController.php +++ b/beike/Shop/Http/Controllers/Account/OrderController.php @@ -104,6 +104,6 @@ class OrderController extends Controller throw new \Exception('无效的订单'); } StateMachineService::getInstance($order)->changeStatus(StateMachineService::COMPLETED); - return json_success(trans('shop/account.order_completed')); + return json_success(trans('shop/account.order.completed')); } } diff --git a/beike/Shop/Http/Controllers/ProductController.php b/beike/Shop/Http/Controllers/ProductController.php index 3527a1de..9e3d9d14 100644 --- a/beike/Shop/Http/Controllers/ProductController.php +++ b/beike/Shop/Http/Controllers/ProductController.php @@ -20,6 +20,9 @@ class ProductController extends Controller public function show(Request $request, Product $product) { $product = ProductRepo::getProductDetail($product); + if ($product->active == 0) { + return redirect(shop_route('home.index')); + } $data = [ 'product' => (new ProductDetail($product))->jsonSerialize(), ]; @@ -31,7 +34,7 @@ class ProductController extends Controller * 通过关键字搜索产品 * * @param Request $request - * @return AnonymousResourceCollection + * @return mixed */ public function search(Request $request) { diff --git a/composer.json b/composer.json index 8f54e396..87779eb7 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "keywords": ["framework", "laravel"], "license": "MIT", "require": { - "php": "^7.4|^8.0", + "php": "^8.0.2", "ext-json": "*", "ext-zip": "*", "doctrine/dbal": "^3.3", diff --git a/resources/beike/admin/views/pages/brands/index.blade.php b/resources/beike/admin/views/pages/brands/index.blade.php index 607cd07f..fd602b89 100644 --- a/resources/beike/admin/views/pages/brands/index.blade.php +++ b/resources/beike/admin/views/pages/brands/index.blade.php @@ -27,7 +27,9 @@