小程序登录优化
This commit is contained in:
@@ -16,34 +16,34 @@ use Modules\AnnoRoute\Attribute\PostRoute;
|
||||
use Modules\AnnoRoute\Attribute\PutRoute;
|
||||
use Modules\AnnoRoute\Attribute\RequestAttribute;
|
||||
use Modules\SystemTool\Models\SysFileModel;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* 小程序购物车(门店订货车:加购 / 列表 / 改数量 / 删项 / 清空)
|
||||
* 提交订货单复用 POST /mini/order,购物车仅作前置编辑容器
|
||||
* 小程序购物车
|
||||
*/
|
||||
#[RequestAttribute('/mini', 'mini', authGuard: 'users')]
|
||||
class CartController extends BaseMiniController
|
||||
{
|
||||
/** decimal(10,2) 上限 */
|
||||
private const MAX_QUANTITY = '99999999.99';
|
||||
private const string MAX_QUANTITY = '99999999.99';
|
||||
|
||||
/**
|
||||
* 加购:商品上架 + 门店有等级价(与下单一致 fail-fast),同商品合并累加
|
||||
* 加购
|
||||
* @throws Throwable
|
||||
*/
|
||||
#[PostRoute('/cart', authorize: true)]
|
||||
#[PostRoute('/cart')]
|
||||
public function store(MiniCartRequest $request): JsonResponse
|
||||
{
|
||||
$user = $this->currentUser($request);
|
||||
$store = $this->ensureStoreBound($user);
|
||||
if ($store->level_id <= 0) {
|
||||
throw new RepositoryException('门店未设置客户等级,无法加购,请联系客服');
|
||||
return $this->error('门店未设置客户等级,无法加购,请联系客服');
|
||||
}
|
||||
|
||||
$productId = (int) $request->validated('product_id');
|
||||
// Eloquent 查询自带 SoftDeletes 全局作用域:软删除/下架一并在内
|
||||
$product = ProductModel::where('status', ProductModel::STATUS_ON)->find($productId);
|
||||
if ($product === null) {
|
||||
throw new RepositoryException('商品不存在或已下架,请刷新后重试');
|
||||
return $this->error('商品不存在或已下架,请刷新后重试');
|
||||
}
|
||||
// 存在性校验与计价类型无关(百分比行 price 可能为 0 也能加购)
|
||||
$hasPrice = ProductPriceModel::query()
|
||||
@@ -51,7 +51,7 @@ class CartController extends BaseMiniController
|
||||
->where('level_id', $store->level_id)
|
||||
->exists();
|
||||
if (! $hasPrice) {
|
||||
throw new RepositoryException('商品「' . $product->name . '」未设置您所在等级的价格,无法加购');
|
||||
return $this->error('商品「' . $product->name . '」价格未设置,无法加购');
|
||||
}
|
||||
|
||||
$quantity = (string) $request->validated('quantity');
|
||||
@@ -88,8 +88,7 @@ class CartController extends BaseMiniController
|
||||
}
|
||||
|
||||
/**
|
||||
* 购物车列表:当前用户全部项 + 实时等级价,逐项服务端 bcmul 算金额;
|
||||
* status=1 可购 / 0 商品下架、缺失或未设等级价;汇总只统计可购项
|
||||
* 购物车列表
|
||||
*/
|
||||
#[GetRoute('/cart', authorize: true)]
|
||||
public function index(Request $request): JsonResponse
|
||||
|
||||
Reference in New Issue
Block a user