|
@@ -1,15 +1,20 @@
|
|
|
package com.caimei.modules.coupon.service;
|
|
|
|
|
|
import com.caimei.modules.coupon.dao.CmCouponVipDao;
|
|
|
+import com.caimei.modules.coupon.dao.SvipCouponListDao;
|
|
|
import com.caimei.modules.coupon.entity.CmCoupon;
|
|
|
import com.caimei.modules.coupon.entity.CmVipCoupon;
|
|
|
import com.caimei.modules.coupon.entity.SvipCouponForm;
|
|
|
+import com.caimei.modules.coupon.entity.SvipCouponList;
|
|
|
import com.caimei.modules.utils.DateUtil;
|
|
|
+import com.thinkgem.jeesite.common.persistence.Page;
|
|
|
+import com.thinkgem.jeesite.common.service.CrudService;
|
|
|
+import org.apache.poi.ss.formula.functions.Now;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -17,15 +22,17 @@ import java.util.Date;
|
|
|
*/
|
|
|
@Service
|
|
|
@Transactional(readOnly = true)
|
|
|
-public class CmVipCouponService{
|
|
|
+public class CmVipCouponService extends CrudService<SvipCouponListDao, SvipCouponList> {
|
|
|
|
|
|
@Autowired
|
|
|
private CmCouponService cmCouponService;
|
|
|
@Autowired
|
|
|
private CmCouponVipDao vipDao;
|
|
|
+ @Autowired
|
|
|
+ private SvipCouponListDao listDao;
|
|
|
|
|
|
@Transactional(readOnly = false)
|
|
|
- public void addCoupon(SvipCouponForm svipcouponForm){
|
|
|
+ public void addCoupon(SvipCouponForm svipcouponForm) {
|
|
|
String month = svipcouponForm.getMonth();
|
|
|
Date beginTime = DateUtil.getMinDay(month);
|
|
|
Date lastTime = DateUtil.getMaxDay(month);
|
|
@@ -136,6 +143,11 @@ public class CmVipCouponService{
|
|
|
vipCoupon2.setCreateTime(date);
|
|
|
vipCoupon3.setCreateTime(date);
|
|
|
vipCoupon4.setCreateTime(date);
|
|
|
+ String s = vipCoupon1.getCouponId() + "," + vipCoupon2.getCouponId() + "," + vipCoupon3.getCouponId() + "," + vipCoupon4.getCouponId();
|
|
|
+ vipCoupon1.setBindCoupon(s);
|
|
|
+ vipCoupon2.setBindCoupon(s);
|
|
|
+ vipCoupon3.setBindCoupon(s);
|
|
|
+ vipCoupon4.setBindCoupon(s);
|
|
|
vipDao.addVipCoupon(vipCoupon1);
|
|
|
vipDao.addVipCoupon(vipCoupon2);
|
|
|
vipDao.addVipCoupon(vipCoupon3);
|
|
@@ -143,6 +155,152 @@ public class CmVipCouponService{
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
+ public Page<SvipCouponList> findPage(Page<SvipCouponList> page, SvipCouponList svipCouponList) {
|
|
|
+// 0 "未生效
|
|
|
+// 1 "已生效"
|
|
|
+// 2 "已关闭"
|
|
|
+// 3 "已失效"
|
|
|
+ Page<SvipCouponList> couponPage = super.findPage(page, svipCouponList);
|
|
|
+ List<SvipCouponList> list = couponPage.getList();
|
|
|
+ List<Integer> couponIds = new ArrayList<>();
|
|
|
+ ArrayList<SvipCouponForm> forms = new ArrayList<>();
|
|
|
+ for (SvipCouponList svipCoupon : list) {
|
|
|
+ String bindCoupon = svipCoupon.getBindCoupon();
|
|
|
+ String[] split = bindCoupon.split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ Integer in = Integer.valueOf(s);
|
|
|
+ couponIds.add(in);
|
|
|
+ }
|
|
|
+ SvipCouponForm form = getForm(couponIds);
|
|
|
+ //todo 状态判断
|
|
|
+ Integer couponId1 = form.getCouponId1();
|
|
|
+ CmCoupon status = listDao.findStatus(couponId1);
|
|
|
+ Date endDate = status.getEndDate();
|
|
|
+ Date startDate = status.getStartDate();
|
|
|
+ Date now = new Date();
|
|
|
+ //结束>现在,开始<现在
|
|
|
+ if(endDate.after(now) && startDate.before(now)){
|
|
|
+ form.setStatus("1");
|
|
|
+ }
|
|
|
+ //开始时间>现在
|
|
|
+ if(startDate.after(now)){
|
|
|
+ form.setStatus("0");
|
|
|
+ }
|
|
|
+ //结束>现在
|
|
|
+ if(endDate.before(now)){
|
|
|
+ form.setStatus("3");
|
|
|
+ }
|
|
|
+ Integer vipStatus = listDao.findVipStatus(couponId1);
|
|
|
+ if(vipStatus != 1){
|
|
|
+ form.setStatus("2");
|
|
|
+ }
|
|
|
+ forms.add(form);
|
|
|
+ svipCoupon.setSvipCoupons(forms);
|
|
|
+ couponIds.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+// List<String> bind = vipDao.findBind();
|
|
|
+// List<Integer> couponIds = new ArrayList<>();
|
|
|
+// List<SvipCouponForm> forms = new ArrayList<>();
|
|
|
+//
|
|
|
+// for (String s : bind) {
|
|
|
+// String[] split = s.split(",");
|
|
|
+// for (String s1 : split) {
|
|
|
+// Integer in = Integer.valueOf(s1);
|
|
|
+// couponIds.add(in);
|
|
|
+// }
|
|
|
+// SvipCouponForm form = getForm(couponIds);
|
|
|
+// //todo 状态判断
|
|
|
+// form.setStatus("0");
|
|
|
+// forms.add(form);
|
|
|
+// couponIds.clear();
|
|
|
+// }
|
|
|
+//
|
|
|
+//// bind.forEach(b -> {
|
|
|
+//// for (String s : b.split(",")) {
|
|
|
+//// couponIds.add(Integer.valueOf(s));
|
|
|
+//// }
|
|
|
+//// SvipCouponForm form = getForm(couponIds);
|
|
|
+//// forms.add(form);
|
|
|
+//// });
|
|
|
+// couponPage.setList(forms);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ private SvipCouponForm getForm(List<Integer> couponIds) {
|
|
|
+ ArrayList<CmVipCoupon> group = new ArrayList<>();
|
|
|
+ SvipCouponForm form = new SvipCouponForm();
|
|
|
+ //根据couponId查4张优惠券,装进form
|
|
|
+ for (Integer couponId : couponIds) {
|
|
|
+ group.add(vipDao.findAllVipCoupon(null, null, couponId).get(0));
|
|
|
+ }
|
|
|
+ CmVipCoupon coupon1 = group.get(0);
|
|
|
+ CmVipCoupon coupon2 = group.get(1);
|
|
|
+ CmVipCoupon coupon3 = group.get(2);
|
|
|
+ CmVipCoupon coupon4 = group.get(3);
|
|
|
+ form.setMonth(coupon1.getUseTime());
|
|
|
+ form.setCouponId1(coupon1.getCouponId());
|
|
|
+ form.setCouponAmount1(coupon1.getCouponAmount());
|
|
|
+ form.setTouchPrice1(coupon1.getTouchPrice());
|
|
|
+ form.setCouponType1(coupon1.getCouponType());
|
|
|
+
|
|
|
+ form.setCouponId2(coupon2.getCouponId());
|
|
|
+ form.setCouponAmount2(coupon2.getCouponAmount());
|
|
|
+ form.setTouchPrice2(coupon2.getTouchPrice());
|
|
|
+ form.setCouponType2(coupon2.getCouponType());
|
|
|
+
|
|
|
+ form.setCouponId3(coupon3.getCouponId());
|
|
|
+ form.setCouponAmount3(coupon3.getCouponAmount());
|
|
|
+ form.setTouchPrice3(coupon3.getTouchPrice());
|
|
|
+ form.setCouponType3(coupon3.getCouponType());
|
|
|
+
|
|
|
+ form.setCouponId4(coupon4.getCouponId());
|
|
|
+ form.setCouponAmount4(coupon4.getCouponAmount());
|
|
|
+ form.setTouchPrice4(coupon4.getTouchPrice());
|
|
|
+ form.setCouponType4(coupon4.getCouponType());
|
|
|
|
|
|
+ if (coupon1.getCouponType() == 0) {
|
|
|
+ form.setProductType1(coupon1.getProductType());
|
|
|
+ }
|
|
|
+ if (coupon1.getCouponType() == 1) {
|
|
|
+ form.setCategoryType1(coupon1.getCategoryType());
|
|
|
+ }
|
|
|
+ if (coupon1.getCouponType() == 3) {
|
|
|
+ form.setShopId1(coupon1.getShopId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (coupon2.getCouponType() == 0) {
|
|
|
+ form.setProductType2(coupon2.getProductType());
|
|
|
+ }
|
|
|
+ if (coupon2.getCouponType() == 1) {
|
|
|
+ form.setCategoryType2(coupon2.getCategoryType());
|
|
|
+ }
|
|
|
+ if (coupon2.getCouponType() == 3) {
|
|
|
+ form.setShopId2(coupon2.getShopId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (coupon3.getCouponType() == 0) {
|
|
|
+ form.setProductType3(coupon3.getProductType());
|
|
|
+ }
|
|
|
+ if (coupon3.getCouponType() == 1) {
|
|
|
+ form.setCategoryType3(coupon3.getCategoryType());
|
|
|
+ }
|
|
|
+ if (coupon3.getCouponType() == 3) {
|
|
|
+ form.setShopId3(coupon3.getShopId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (coupon4.getCouponType() == 0) {
|
|
|
+ form.setProductType4(coupon4.getProductType());
|
|
|
+ }
|
|
|
+ if (coupon4.getCouponType() == 1) {
|
|
|
+ form.setCategoryType4(coupon4.getCategoryType());
|
|
|
+ }
|
|
|
+ if (coupon4.getCouponType() == 3) {
|
|
|
+ form.setShopId4(coupon4.getShopId());
|
|
|
+ }
|
|
|
+
|
|
|
+ return form;
|
|
|
+ }
|
|
|
|
|
|
}
|