ApiCouponService.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. package com.kmall.api.service;
  2. import com.google.common.collect.Maps;
  3. import com.kmall.api.dao.mk.ApiMkStoreTicketDiscountMapper;
  4. import com.kmall.api.entity.mk.MkStoreTicketDiscountVo;
  5. import com.kmall.common.constant.Dict;
  6. import com.kmall.api.dao.ApiCouponMapper;
  7. import com.kmall.api.dao.ApiUserCouponMapper;
  8. import com.kmall.api.entity.CouponVo;
  9. import com.kmall.api.entity.UserCouponVo;
  10. import com.kmall.common.utils.CharUtil;
  11. import com.kmall.common.utils.Constant;
  12. import com.qiniu.util.StringUtils;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import java.math.BigDecimal;
  16. import java.util.Date;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. @Service
  21. public class ApiCouponService {
  22. @Autowired
  23. private ApiCouponMapper apiCouponMapper;
  24. @Autowired
  25. private ApiMkStoreTicketDiscountMapper mkStoreTicketDiscountMapper;
  26. /**
  27. * 获取优惠信息提示邮费 还差多少邮费
  28. *
  29. * @param userId
  30. * @param goodsTotalPrice
  31. * @return
  32. */
  33. /*
  34. public CouponVo matchShippingSign(Long userId, BigDecimal goodsTotalPrice) {
  35. CouponVo result = new CouponVo();
  36. //
  37. Map couponParam = Maps.newHashMap();
  38. couponParam.put("enabled", true);
  39. Integer[] send_types = new Integer[]{7};
  40. couponParam.put("send_types", send_types);
  41. List<CouponVo> couponVos = apiCouponMapper.queryList(couponParam);
  42. if (null != couponVos && couponVos.size() > 0) {
  43. for (CouponVo couponVo : couponVos) {
  44. BigDecimal difDec = couponVo.getMin_goods_amount().subtract(goodsTotalPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
  45. // 是否最低优惠券
  46. boolean optimal = false;
  47. if (null != result && null != result.getId()) {
  48. // 都是凑单,取小的
  49. if (difDec.doubleValue() > 0.0 && result.getDifDec().doubleValue() > 0.0
  50. && difDec.compareTo(result.getDifDec()) < 0) {
  51. optimal = true;
  52. }
  53. // 一个凑单,一个满足,取凑单
  54. else if (difDec.doubleValue() >= 0.0 && result.getDifDec().doubleValue() <= 0.0) {
  55. optimal = true;
  56. } // 都满足,取type_money小的
  57. else if (difDec.doubleValue() < 0.0 && result.getDifDec().doubleValue() < 0.0
  58. && result.getMoney().compareTo(couponVo.getType_money()) > 0) {
  59. optimal = true;
  60. }
  61. } else {
  62. optimal = true;
  63. }
  64. if (!optimal) {
  65. continue;
  66. }
  67. if (difDec.doubleValue() > 0.0 && couponVo.getType_money().compareTo(Constant.ZERO) == 0) {
  68. couponVo.setMsg("满¥" + couponVo.getMin_goods_amount() + "元免配送费,还差" + difDec + "元");
  69. couponVo.setType(1);
  70. } else if (couponVo.getType_money().doubleValue() > 0.0) {
  71. couponVo.setMsg("满¥" + couponVo.getMin_goods_amount() + "元,配送费" + couponVo.getType_money() + "元,还差" + difDec + "元");
  72. couponVo.setType(1);
  73. } else {
  74. couponVo.setMsg("满¥" + couponVo.getMin_goods_amount() + "元免配送费");
  75. couponVo.setType(0);
  76. }
  77. couponVo.setDifDec(difDec);
  78. couponVo.setMoney(couponVo.getType_money());
  79. result = couponVo;
  80. }
  81. }
  82. return result;
  83. }*/
  84. /**
  85. * 获取可使用的优惠 邮费
  86. *
  87. * @param userId
  88. * @param goodsTotalPrice
  89. * @return
  90. */
  91. /*
  92. public BigDecimal matchShipping(Long userId, BigDecimal goodsTotalPrice) {
  93. BigDecimal result = new BigDecimal(10);
  94. //
  95. Map couponParam = Maps.newHashMap();
  96. couponParam.put("enabled", true);
  97. Integer[] send_types = new Integer[]{7};
  98. couponParam.put("send_types", send_types);
  99. List<CouponVo> couponVos = apiCouponMapper.queryList(couponParam);
  100. if (null != couponVos && couponVos.size() > 0) {
  101. for (CouponVo couponVo : couponVos) {
  102. // 是否免运费
  103. if (couponVo.getMin_goods_amount().compareTo(goodsTotalPrice) <= 0
  104. && result.compareTo(couponVo.getType_money()) > 0) {
  105. result = couponVo.getType_money();
  106. }
  107. }
  108. }
  109. return result;
  110. }*/
  111. /**
  112. * 获取可用的满减券
  113. *
  114. * @param userId
  115. * @param goodsTotalPrice
  116. * @return
  117. */
  118. /*
  119. public CouponVo matchFullSub(Long userId, BigDecimal goodsTotalPrice) {
  120. CouponVo result = new CouponVo();
  121. //
  122. Map couponParam = Maps.newHashMap();
  123. couponParam.put("enabled", true);
  124. // 获取优惠信息提示 满减
  125. Integer[] send_types = new Integer[]{0};
  126. // param.put("unUsed", true);
  127. couponParam.put("send_types", send_types);
  128. List<CouponVo> couponVos = apiCouponMapper.queryList(couponParam);
  129. if (null != couponVos && couponVos.size() > 0) {
  130. CouponVo fullCutVo = new CouponVo();
  131. BigDecimal fullCutDec = Constant.ZERO;
  132. for (CouponVo couponVo : couponVos) {
  133. BigDecimal difDec = couponVo.getMin_goods_amount().subtract(goodsTotalPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
  134. if (difDec.doubleValue() < 0.0 && fullCutDec.compareTo(couponVo.getType_money()) < 0) {
  135. fullCutDec = couponVo.getType_money();
  136. fullCutVo = couponVo;
  137. fullCutVo.setType(0);
  138. fullCutVo.setMsg("可使用满减券" + couponVo.getName());
  139. }
  140. if (!StringUtils.isNullOrEmpty(fullCutVo.getMsg())) {
  141. result = fullCutVo;
  142. }
  143. }
  144. }
  145. return result;
  146. }*/
  147. /**
  148. * 获取优惠信息提示满减券 还差多少满减
  149. *
  150. * @param userId
  151. * @param goodsTotalPrice
  152. * @return
  153. */
  154. /*
  155. public CouponVo matchFullSubSign(Long userId, BigDecimal goodsTotalPrice, long storeId) {
  156. CouponVo result = new CouponVo();
  157. //
  158. Map couponParam = Maps.newHashMap();
  159. couponParam.put("enabled", true);
  160. // 获取优惠信息提示 满减
  161. couponParam.put("storeId", storeId);
  162. // List<CouponVo> couponVos = apiCouponMapper.queryList(couponParam);
  163. List<MkStoreTicketDiscountVo> discountVoList = mkStoreTicketDiscountMapper.queryList(couponParam);
  164. if (null != discountVoList && discountVoList.size() > 0) {
  165. CouponVo fullCutVo = new CouponVo();
  166. BigDecimal fullCutDec = Constant.ZERO;
  167. BigDecimal minAmount = new BigDecimal(100000);
  168. for (MkStoreTicketDiscountVo discountVo : discountVoList) {
  169. BigDecimal cond = Constant.ZERO;
  170. BigDecimal money = Constant.ZERO;
  171. if(discountVo.getTickDiscType().equalsIgnoreCase(Dict.tickDiscType.item_00.getItem())){
  172. cond = discountVo.getVoucherCond();
  173. money = discountVo.getVoucherMoney();
  174. }
  175. if(discountVo.getTickDiscType().equalsIgnoreCase(Dict.tickDiscType.item_01.getItem())){
  176. cond = discountVo.getDiscCond();
  177. money = discountVo.getDiscRatio();//满多少打几折
  178. }
  179. if(discountVo.getTickDiscType().equalsIgnoreCase(Dict.tickDiscType.item_02.getItem())){
  180. cond = discountVo.getExchCond();
  181. money = discountVo.getExchCond();
  182. }
  183. BigDecimal difDec = cond.subtract(goodsTotalPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
  184. if (difDec.doubleValue() > 0.0
  185. && minAmount.compareTo(discountVo.getVoucherCond()) > 0) {
  186. fullCutDec = money;
  187. fullCutVo.setType(1);
  188. fullCutVo.setMsg(discountVo.getName() + ",还差" + difDec + "元");
  189. } else if (difDec.doubleValue() < 0.0 && fullCutDec.compareTo(money) < 0) {
  190. fullCutVo.setType(0);
  191. fullCutVo.setMsg("可使用满减券" + discountVo.getName());
  192. }
  193. if (!StringUtils.isNullOrEmpty(fullCutVo.getMsg())) {
  194. result = fullCutVo;
  195. }
  196. }
  197. }
  198. return result;
  199. }*/
  200. }