| | |
| | | package com.yeshi.fanli.util;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.List;
|
| | |
|
| | | import org.springframework.stereotype.Component;
|
| | | import org.yeshi.utils.BigDecimalUtil;
|
| | |
|
| | | import com.yeshi.fanli.entity.goods.CommonGoods;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoCouponUtil;
|
| | | import org.yeshi.utils.MoneyBigDecimalUtil;
|
| | |
|
| | | @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("无")) {
|
| | | BigDecimal price = goods.getPrice();
|
| | | money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil
|
| | | .mul(MoneyBigDecimalUtil.mul(price, 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) {
|
| | | 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)));
|
| | | }
|
| | | }
|
| | | |
| | | if (goods.getGoodsType() == Constant.SOURCE_TYPE_VIP) {
|
| | | money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil
|
| | | .mul(MoneyBigDecimalUtil.mul(goods.getCouponStartPrice(), goods.getRate()), new BigDecimal("0.01")),
|
| | | MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
|
| | | }
|
| | |
|
| | | // 京东商品特殊处理
|
| | | 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();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | package com.yeshi.fanli.util; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | |
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil; |
| | | import org.springframework.stereotype.Component; |
| | | import org.yeshi.utils.BigDecimalUtil; |
| | | |
| | | import com.yeshi.fanli.entity.goods.CommonGoods; |
| | | import com.yeshi.fanli.util.taobao.TaoBaoCouponUtil; |
| | | import org.yeshi.utils.MoneyBigDecimalUtil; |
| | | |
| | | @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("无")) { |
| | | BigDecimal price = goods.getPrice(); |
| | | money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil |
| | | .mul(MoneyBigDecimalUtil.mul(price, 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) { |
| | | 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))); |
| | | } |
| | | } |
| | | |
| | | if (goods.getGoodsType() == Constant.SOURCE_TYPE_VIP) { |
| | | money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil |
| | | .mul(MoneyBigDecimalUtil.mul(goods.getCouponStartPrice(), goods.getRate()), new BigDecimal("0.01")), |
| | | MoneyBigDecimalUtil.div(rate, new BigDecimal(100))); |
| | | } |
| | | |
| | | // 京东商品特殊处理 |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static String getGoodsId(String goodsId, int goodsType) { |
| | | if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { |
| | | return TaoBaoUtil.getAuctionId(goodsId); |
| | | } |
| | | return goodsId; |
| | | } |
| | | } |