6/14 解决了精度问题和购物车金额数据可能被前端篡改的问题
This commit is contained in:
parent
df5e2b7b43
commit
c407d63f2f
@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : 张宇轩
|
* @author : 张宇轩
|
||||||
@ -45,7 +46,7 @@ public class AlipayController {
|
|||||||
//商户订单号,商家自定义,保持唯一性
|
//商户订单号,商家自定义,保持唯一性
|
||||||
bizContent.put("out_trade_no", out_trade_no);
|
bizContent.put("out_trade_no", out_trade_no);
|
||||||
//支付金额,最小值0.01元
|
//支付金额,最小值0.01元
|
||||||
bizContent.put("total_amount", total_amount);
|
bizContent.put("total_amount", total_amount.divide(BigDecimal.valueOf(100),2, RoundingMode.HALF_UP));
|
||||||
//订单标题,不可使用特殊符号
|
//订单标题,不可使用特殊符号
|
||||||
bizContent.put("subject", "美食元素订单支付");
|
bizContent.put("subject", "美食元素订单支付");
|
||||||
|
|
||||||
|
@ -2,12 +2,18 @@ package io.renren.modules.front.service.impl;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import io.renren.modules.front.bean.Dish;
|
||||||
|
import io.renren.modules.front.bean.Setmeal;
|
||||||
import io.renren.modules.front.bean.ShoppingCart;
|
import io.renren.modules.front.bean.ShoppingCart;
|
||||||
import io.renren.modules.front.dao.ShoppingCartMapper;
|
import io.renren.modules.front.dao.ShoppingCartMapper;
|
||||||
|
import io.renren.modules.front.service.DishService;
|
||||||
|
import io.renren.modules.front.service.SetmealService;
|
||||||
import io.renren.modules.front.service.ShoppingCartService;
|
import io.renren.modules.front.service.ShoppingCartService;
|
||||||
import io.renren.modules.front.utils.BaseContext;
|
import io.renren.modules.front.utils.BaseContext;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,6 +24,10 @@ import java.time.LocalDateTime;
|
|||||||
*/
|
*/
|
||||||
@Service(value = "shoppingCartServiceImplFront")
|
@Service(value = "shoppingCartServiceImplFront")
|
||||||
public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, ShoppingCart> implements ShoppingCartService {
|
public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, ShoppingCart> implements ShoppingCartService {
|
||||||
|
@Autowired
|
||||||
|
DishService dishService;
|
||||||
|
@Autowired
|
||||||
|
SetmealService setmealService;
|
||||||
@Override
|
@Override
|
||||||
public ShoppingCart add(ShoppingCart shoppingCart) {
|
public ShoppingCart add(ShoppingCart shoppingCart) {
|
||||||
//查询当前购物车的菜品/套餐是否在数据库存在
|
//查询当前购物车的菜品/套餐是否在数据库存在
|
||||||
@ -28,8 +38,12 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, Sho
|
|||||||
//1.2.判断查询的是菜品还是套餐
|
//1.2.判断查询的是菜品还是套餐
|
||||||
Long dishId = shoppingCart.getDishId();
|
Long dishId = shoppingCart.getDishId();
|
||||||
if(dishId != null){
|
if(dishId != null){
|
||||||
|
Dish dish = dishService.getById(dishId);
|
||||||
|
shoppingCart.setAmount(BigDecimal.valueOf(dish.getPrice()));
|
||||||
lqw.eq(ShoppingCart::getDishId, dishId);
|
lqw.eq(ShoppingCart::getDishId, dishId);
|
||||||
} else {
|
} else {
|
||||||
|
Setmeal setmeal = setmealService.getById(shoppingCart.getSetmealId());
|
||||||
|
shoppingCart.setAmount(BigDecimal.valueOf(setmeal.getPrice()));
|
||||||
lqw.eq(ShoppingCart::getSetmealId, shoppingCart.getSetmealId());
|
lqw.eq(ShoppingCart::getSetmealId, shoppingCart.getSetmealId());
|
||||||
}
|
}
|
||||||
//1.3.执行查询
|
//1.3.执行查询
|
||||||
@ -39,6 +53,7 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, Sho
|
|||||||
cart.setNumber(cart.getNumber()+1);
|
cart.setNumber(cart.getNumber()+1);
|
||||||
this.updateById(cart);
|
this.updateById(cart);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
//3 不存在,添加到购物车表中
|
//3 不存在,添加到购物车表中
|
||||||
shoppingCart.setCreateDate(LocalDateTime.now());
|
shoppingCart.setCreateDate(LocalDateTime.now());
|
||||||
shoppingCart.setUserId(BaseContext.getCurrentId());
|
shoppingCart.setUserId(BaseContext.getCurrentId());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user