| | |
| | |
|
| | | @Component
|
| | | public class CommonGoodsUtil {
|
| | | |
| | |
|
| | | /**
|
| | | * 商品佣金包含¥符号
|
| | | * |
| | | * @param goods
|
| | | * @param rate
|
| | | * @return
|
| | |
| | | public static String getCommissionInfo(CommonGoods goods, BigDecimal rate) {
|
| | | return "¥" + getCommission(goods, rate).toString();
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 商品佣金
|
| | | * 商品佣金
|
| | | * |
| | | * @param goods
|
| | | * @param rate
|
| | | * @return
|
| | |
| | | public static BigDecimal getCommission(CommonGoods goods, BigDecimal rate) {
|
| | | BigDecimal money = null;
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(goods.getCouponInfo())
|
| | | || goods.getCouponInfo().trim().equalsIgnoreCase("无")) {
|
| | | money = MoneyBigDecimalUtil.mul(
|
| | | MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(goods.getPrice(), goods.getRate()),
|
| | | new BigDecimal("0.01")),
|
| | | if (StringUtil.isNullOrEmpty(goods.getCouponInfo()) || goods.getCouponInfo().trim().equalsIgnoreCase("无")) {
|
| | | money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil
|
| | | .mul(MoneyBigDecimalUtil.mul(goods.getPrice(), goods.getRate()), new BigDecimal("0.01")),
|
| | | MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
|
| | | } else// 有券
|
| | | {
|
| | | List<BigDecimal> list = TaoBaoCouponUtil.getCouponInfo(goods.getCouponInfo());
|
| | | BigDecimal startFee = list.get(0);
|
| | | BigDecimal couponAccount = list.get(1);
|
| | | if (startFee.compareTo(goods.getPrice()) <= 0
|
| | | && goods.getPrice().compareTo(couponAccount) > 0) {
|
| | | if (startFee.compareTo(goods.getPrice()) <= 0 && goods.getPrice().compareTo(couponAccount) > 0) {
|
| | | BigDecimal finalPrice = goods.getPrice().subtract(couponAccount);
|
| | | money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil
|
| | | .mul(MoneyBigDecimalUtil.mul(finalPrice, goods.getRate()), new BigDecimal("0.01")),
|
| | | MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
|
| | |
|
| | | } else {// 不能用券
|
| | | money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(
|
| | | MoneyBigDecimalUtil.mul(goods.getPrice(), goods.getRate()),
|
| | | new BigDecimal("0.01")), MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
|
| | | money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil
|
| | | .mul(MoneyBigDecimalUtil.mul(goods.getPrice(), goods.getRate()), new BigDecimal("0.01")),
|
| | | MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
|
| | | }
|
| | | }
|
| | | return BigDecimalUtil.getWithNoZera(money);
|
| | |
|
| | | // 京东商品特殊处理
|
| | | if (goods.getGoodsType() == Constant.SOURCE_TYPE_JD)
|
| | | return BigDecimalUtil.getWithNoZera(MoneyBigDecimalUtil.mul(money, new BigDecimal("0.9")));
|
| | | else
|
| | | return BigDecimalUtil.getWithNoZera(money);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 计算商品券后价,没有券则返回原价
|
| | | * |
| | | * @param goodsBrief
|
| | | * @return
|
| | | */
|
| | | public static BigDecimal getAfterUseCouplePrice(CommonGoods goods) {
|
| | | if (StringUtil.isNullOrEmpty(goods.getCouponInfo()) || "无".equals(goods.getCouponInfo())) {
|
| | | return goods.getPrice();
|
| | | } else {
|
| | | List<BigDecimal> list = TaoBaoCouponUtil.getCouponInfo(goods.getCouponInfo());
|
| | | BigDecimal startFee = list.get(0);
|
| | | BigDecimal couponAccount = list.get(1);
|
| | | if (startFee.compareTo(goods.getPrice()) <= 0 && goods.getPrice().compareTo(couponAccount) > 0) {
|
| | | BigDecimal finalPrice = goods.getPrice().subtract(couponAccount);
|
| | | return finalPrice;
|
| | | } else {// 不能用券
|
| | | return goods.getPrice();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|