|
@@ -1,5 +1,6 @@
|
|
|
package com.caimei.modules.coupon.service;
|
|
|
|
|
|
+import com.caimei.modules.coupon.dao.CmCouponDao;
|
|
|
import com.caimei.modules.coupon.dao.CmCouponVipDao;
|
|
|
import com.caimei.modules.coupon.dao.SvipCouponListDao;
|
|
|
import com.caimei.modules.coupon.entity.CmCoupon;
|
|
@@ -9,7 +10,6 @@ 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;
|
|
@@ -30,9 +30,11 @@ public class CmVipCouponService extends CrudService<SvipCouponListDao, SvipCoupo
|
|
|
private CmCouponVipDao vipDao;
|
|
|
@Autowired
|
|
|
private SvipCouponListDao listDao;
|
|
|
+ @Autowired
|
|
|
+ private CmCouponDao cmCouponDao;
|
|
|
|
|
|
@Transactional(readOnly = false)
|
|
|
- public void addCoupon(SvipCouponForm svipcouponForm) {
|
|
|
+ public void addCoupon(SvipCouponForm svipcouponForm, Integer couponId1, String flag) {
|
|
|
String month = svipcouponForm.getMonth();
|
|
|
Date beginTime = DateUtil.getMinDay(month);
|
|
|
Date lastTime = DateUtil.getMaxDay(month);
|
|
@@ -130,6 +132,7 @@ public class CmVipCouponService extends CrudService<SvipCouponListDao, SvipCoupo
|
|
|
coupon4.setShopId(svipcouponForm.getShopId4());
|
|
|
coupon4.setCouponType(3);
|
|
|
}
|
|
|
+
|
|
|
cmCouponService.save(coupon1);
|
|
|
cmCouponService.save(coupon2);
|
|
|
cmCouponService.save(coupon3);
|
|
@@ -148,12 +151,59 @@ public class CmVipCouponService extends CrudService<SvipCouponListDao, SvipCoupo
|
|
|
vipCoupon2.setBindCoupon(s);
|
|
|
vipCoupon3.setBindCoupon(s);
|
|
|
vipCoupon4.setBindCoupon(s);
|
|
|
- vipDao.addVipCoupon(vipCoupon1);
|
|
|
- vipDao.addVipCoupon(vipCoupon2);
|
|
|
- vipDao.addVipCoupon(vipCoupon3);
|
|
|
- vipDao.addVipCoupon(vipCoupon4);
|
|
|
+ //0修改,1新增
|
|
|
+ if (flag.equals("0")) {
|
|
|
+ CmVipCoupon byCoupon = vipDao.findByCoupon(couponId1, null);
|
|
|
+ if (byCoupon != null) {
|
|
|
+ vipDao.updateVip(vipCoupon1);
|
|
|
+ vipDao.updateVip(vipCoupon2);
|
|
|
+ vipDao.updateVip(vipCoupon3);
|
|
|
+ vipDao.updateVip(vipCoupon4);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (flag.equals("1")) {
|
|
|
+ vipDao.addVipCoupon(vipCoupon1);
|
|
|
+ vipDao.addVipCoupon(vipCoupon2);
|
|
|
+ vipDao.addVipCoupon(vipCoupon3);
|
|
|
+ vipDao.addVipCoupon(vipCoupon4);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ @Transactional(readOnly = false)
|
|
|
+ public void close(Integer couponId) {
|
|
|
+ SvipCouponList vip = listDao.findVipStatus(couponId);
|
|
|
+ String bindCoupon = vip.getBindCoupon();
|
|
|
+ String[] split = bindCoupon.split(",");
|
|
|
+ SvipCouponList vipCouponList = new SvipCouponList();
|
|
|
+ for (String s : split) {
|
|
|
+ Integer ids = Integer.valueOf(s);
|
|
|
+ CmCoupon coupon = listDao.findCoupon(ids);
|
|
|
+ vipCouponList.setCouponId(ids);
|
|
|
+ vipCouponList.setStatus(0);
|
|
|
+ coupon.setStatus("2");
|
|
|
+ coupon.setCouponsMode("0");
|
|
|
+ cmCouponDao.update(coupon);
|
|
|
+ listDao.updateVip(vipCouponList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(readOnly = false)
|
|
|
+ public void deleteById(Integer couponId) {
|
|
|
+ SvipCouponList vip = listDao.findVipStatus(couponId);
|
|
|
+ String bindCoupon = vip.getBindCoupon();
|
|
|
+ String[] split = bindCoupon.split(",");
|
|
|
+ SvipCouponList vipCouponList = new SvipCouponList();
|
|
|
+ for (String s : split) {
|
|
|
+ Integer ids = Integer.valueOf(s);
|
|
|
+ CmCoupon coupon = listDao.findCoupon(ids);
|
|
|
+ vipCouponList.setCouponId(ids);
|
|
|
+ vipCouponList.setDelFlag("1");
|
|
|
+ coupon.setDelFlag("1");
|
|
|
+ coupon.setCouponsMode("0");
|
|
|
+ cmCouponDao.delete(coupon);
|
|
|
+ listDao.updateVip(vipCouponList);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public Page<SvipCouponList> findPage(Page<SvipCouponList> page, SvipCouponList svipCouponList) {
|
|
@@ -164,7 +214,6 @@ public class CmVipCouponService extends CrudService<SvipCouponListDao, SvipCoupo
|
|
|
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(",");
|
|
@@ -173,58 +222,31 @@ public class CmVipCouponService extends CrudService<SvipCouponListDao, SvipCoupo
|
|
|
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)){
|
|
|
+ if (endDate.after(now) && startDate.before(now)) {
|
|
|
form.setStatus("1");
|
|
|
}
|
|
|
//开始时间>现在
|
|
|
- if(startDate.after(now)){
|
|
|
+ if (startDate.after(now)) {
|
|
|
form.setStatus("0");
|
|
|
}
|
|
|
//结束>现在
|
|
|
- if(endDate.before(now)){
|
|
|
+ if (endDate.before(now)) {
|
|
|
form.setStatus("3");
|
|
|
}
|
|
|
- Integer vipStatus = listDao.findVipStatus(couponId1);
|
|
|
- if(vipStatus != 1){
|
|
|
+ SvipCouponList vipStatus = listDao.findVipStatus(couponId1);
|
|
|
+ if (vipStatus.getStatus() != 1) {
|
|
|
form.setStatus("2");
|
|
|
}
|
|
|
- forms.add(form);
|
|
|
- svipCoupon.setSvipCoupons(forms);
|
|
|
+ svipCoupon.setSvipCoupons(form);
|
|
|
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;
|
|
|
}
|
|
|
|
|
@@ -260,6 +282,7 @@ public class CmVipCouponService extends CrudService<SvipCouponListDao, SvipCoupo
|
|
|
form.setTouchPrice4(coupon4.getTouchPrice());
|
|
|
form.setCouponType4(coupon4.getCouponType());
|
|
|
|
|
|
+ //todo 等于0的时候活动券productinfo查出来还回去
|
|
|
if (coupon1.getCouponType() == 0) {
|
|
|
form.setProductType1(coupon1.getProductType());
|
|
|
}
|
|
@@ -303,4 +326,15 @@ public class CmVipCouponService extends CrudService<SvipCouponListDao, SvipCoupo
|
|
|
return form;
|
|
|
}
|
|
|
|
|
|
+ public SvipCouponForm getVipForm(Integer couponId1) {
|
|
|
+ CmVipCoupon byCoupon = vipDao.findByCoupon(couponId1, null);
|
|
|
+ ArrayList<Integer> couponIds = new ArrayList<>();
|
|
|
+ String[] split = byCoupon.getBindCoupon().split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ Integer ids = Integer.valueOf(s);
|
|
|
+ couponIds.add(ids);
|
|
|
+ }
|
|
|
+ SvipCouponForm form = getForm(couponIds);
|
|
|
+ return form;
|
|
|
+ }
|
|
|
}
|