|
@@ -4,12 +4,17 @@ import com.caimei.modules.coupon.dao.CmCouponClubDao;
|
|
|
import com.caimei.modules.coupon.entity.CmCoupon;
|
|
|
import com.caimei.modules.coupon.entity.CmCouponClub;
|
|
|
import com.caimei.modules.coupon.entity.CmCouponRedemptionCode;
|
|
|
+import com.caimei.modules.user.dao.CmUserDao;
|
|
|
+import com.caimei.modules.user.entity.CmUser;
|
|
|
import com.thinkgem.jeesite.common.persistence.Page;
|
|
|
import com.thinkgem.jeesite.common.service.CrudService;
|
|
|
+import com.thinkgem.jeesite.common.utils.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -26,6 +31,8 @@ import java.util.Map;
|
|
|
public class CmCouponClubService extends CrudService<CmCouponClubDao, CmCouponClub> {
|
|
|
@Autowired
|
|
|
private CmCouponClubDao cmCouponClubDao;
|
|
|
+ @Autowired
|
|
|
+ private CmUserDao cmUserDao;
|
|
|
|
|
|
public CmCouponClub get(String id) {
|
|
|
return super.get(id);
|
|
@@ -57,7 +64,7 @@ public class CmCouponClubService extends CrudService<CmCouponClubDao, CmCouponCl
|
|
|
if (couponList != null && couponList.size() > 0) {
|
|
|
Date date = new Date();
|
|
|
couponList.forEach(couponClub -> {
|
|
|
- if ("2".equals(couponClub.getCouponStatus())) {
|
|
|
+ if (!"2".equals(couponClub.getCouponStatus())) {
|
|
|
if (date.compareTo(couponClub.getStartDate()) < 0) {
|
|
|
couponClub.setCouponStatus("0");
|
|
|
} else if (date.compareTo(couponClub.getEndDate()) > 0) {
|
|
@@ -93,6 +100,35 @@ public class CmCouponClubService extends CrudService<CmCouponClubDao, CmCouponCl
|
|
|
map.put("msg", "兑换的优惠券已失效");
|
|
|
return map;
|
|
|
}
|
|
|
+ if (coupon.getCouponType() == 2 && !redemptionCode.getUserId().equals(coupon.getUserId())) {
|
|
|
+ map.put("code", -1);
|
|
|
+ map.put("msg", "该优惠券属于其他用户,您不能兑换");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ if (coupon.getCouponType() == 4) {
|
|
|
+ CmUser cmUser = cmUserDao.get(redemptionCode.getUserId().toString());
|
|
|
+ if (cmUser != null && StringUtils.isNotBlank(cmUser.getRegisterTime())) {
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
+ Date registerTime = null;
|
|
|
+ try {
|
|
|
+ registerTime = format.parse(cmUser.getRegisterTime());
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ map.put("code", -1);
|
|
|
+ map.put("msg", "该优惠券只供新用户使用,您不能兑换");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ if (registerTime.compareTo(coupon.getStartDate()) < 0) {
|
|
|
+ map.put("code", -1);
|
|
|
+ map.put("msg", "该优惠券只供新用户使用,您不能兑换");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ map.put("code", -1);
|
|
|
+ map.put("msg", "该优惠券只供新用户使用,您不能兑换");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ }
|
|
|
CmCouponClub couponClub = new CmCouponClub();
|
|
|
couponClub.setCouponId(cmCouponRedemptionCode.getCouponId());
|
|
|
couponClub.setUserId(redemptionCode.getUserId());
|