CouponServiceImpl.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. package com.kmall.admin.service.impl;
  3. import com.google.common.collect.ImmutableBiMap;
  4. import com.kmall.admin.dao.CouponDao;
  5. import com.kmall.admin.dao.CouponGoodsDao;
  6. import com.kmall.admin.dao.UserCouponDao;
  7. import com.kmall.admin.dao.UserDao;
  8. import com.kmall.admin.entity.CouponEntity;
  9. import com.kmall.admin.entity.CouponGoodsEntity;
  10. import com.kmall.admin.entity.UserCouponEntity;
  11. import com.kmall.admin.entity.UserEntity;
  12. import com.kmall.admin.service.CouponService;
  13. import com.kmall.common.utils.MapBeanUtil;
  14. import com.kmall.common.utils.R;
  15. import com.kmall.common.utils.RRException;
  16. import com.kmall.common.utils.ValidatorUtil;
  17. import org.apache.commons.collections.MapUtils;
  18. import org.apache.commons.lang.StringUtils;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Service;
  21. import java.util.Date;
  22. import java.util.List;
  23. import java.util.Map;
  24. */
  25. /**
  26. * Service实现类
  27. *
  28. * @author Scott
  29. * @email
  30. * @date 2017-08-19 12:53:26
  31. *//*
  32. @Service("couponService")
  33. public class CouponServiceImpl implements CouponService {
  34. @Autowired
  35. private CouponDao couponDao;
  36. @Autowired
  37. private UserCouponDao userCouponDao;
  38. @Autowired
  39. private CouponGoodsDao couponGoodsDao;
  40. @Autowired
  41. private UserDao userDao;
  42. @Override
  43. public CouponEntity queryObject(Integer id) {
  44. return couponDao.queryObject(id);
  45. }
  46. @Override
  47. public List<CouponEntity> queryList(Map<String, Object> map) {
  48. return couponDao.queryList(map);
  49. }
  50. @Override
  51. public int queryTotal(Map<String, Object> map) {
  52. return couponDao.queryTotal(map);
  53. }
  54. @Override
  55. public int save(CouponEntity coupon) {
  56. Map<String, Object> valideDate = MapBeanUtil.fromObject(coupon);
  57. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  58. builder.put("merchSn", "商户");
  59. builder.put("storeId", "门店");
  60. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  61. if (Integer.valueOf(r.get("code").toString()) != 0) {
  62. throw new RRException(r.get("msg").toString());
  63. }
  64. return couponDao.save(coupon);
  65. }
  66. @Override
  67. public int update(CouponEntity coupon) {
  68. Map<String, Object> valideDate = MapBeanUtil.fromObject(coupon);
  69. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  70. builder.put("merchSn", "商户");
  71. builder.put("storeId", "门店");
  72. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  73. if (Integer.valueOf(r.get("code").toString()) != 0) {
  74. throw new RRException(r.get("msg").toString());
  75. }
  76. return couponDao.update(coupon);
  77. }
  78. @Override
  79. public int delete(Integer id) {
  80. return couponDao.delete(id);
  81. }
  82. @Override
  83. public int deleteBatch(Integer[] ids) {
  84. return couponDao.deleteBatch(ids);
  85. }
  86. @Override
  87. public R publish(Map<String, Object> params) {
  88. // 发放方式 0:按订单发放 1:按用户发放 2:商品转发送券 3:按商品发放 4:新用户注册 5:线下发放 6评价好评红包(固定或随机红包)
  89. Integer sendType = MapUtils.getInteger(params, "sendType");
  90. Integer couponId = MapUtils.getInteger(params, "couponId");
  91. if (null == sendType) {
  92. return R.error("发放方式不能为空");
  93. }
  94. if (null == couponId) {
  95. return R.error("优惠券不能为空");
  96. }
  97. if (1 == sendType) {
  98. String userIds = MapUtils.getString(params, "userIds"); // 下发用户逗号分割
  99. if (StringUtils.isEmpty(userIds)) {
  100. return R.error("用户不能为空");
  101. }
  102. //是否发送短信通知
  103. boolean sendSms = "true".equals(MapUtils.getString(params, "sendSms"));
  104. for (String strUserId : userIds.split(",")) {
  105. if (StringUtils.isEmpty(strUserId)) {
  106. continue;
  107. }
  108. Integer userId = Integer.valueOf(strUserId);
  109. UserCouponEntity userCouponVo = new UserCouponEntity();
  110. userCouponVo.setUserId(userId);
  111. userCouponVo.setCouponId(couponId);
  112. userCouponVo.setCouponNumber("1");
  113. userCouponVo.setAddTime(new Date());
  114. userCouponDao.save(userCouponVo);
  115. if (sendSms) {
  116. UserEntity userEntity = userDao.queryObject(userId);
  117. // todo 发送短信
  118. }
  119. }
  120. } else if (3 == sendType) {
  121. String goodsIds = MapUtils.getString(params, "goodsIds"); // 下发商品逗号分割
  122. if (StringUtils.isEmpty(goodsIds)) {
  123. return R.error("商品Id不能为空");
  124. }
  125. for (String goodsId : goodsIds.split(",")) {
  126. if (StringUtils.isEmpty(goodsId)) {
  127. continue;
  128. }
  129. CouponGoodsEntity couponGoodsVo = new CouponGoodsEntity();
  130. couponGoodsVo.setCouponId(couponId);
  131. couponGoodsVo.setGoodsId(Integer.valueOf(goodsId));
  132. couponGoodsDao.save(couponGoodsVo);
  133. }
  134. } else {
  135. return R.error("此类优惠券不支持手动发放");
  136. }
  137. return R.ok("发放成功");
  138. }
  139. }
  140. */