|
@@ -3,7 +3,7 @@ package com.caimei365.manager.service.caimei.svip.impl;
|
|
|
import com.caimei.utils.AppUtils;
|
|
|
import com.caimei.utils.MathUtil;
|
|
|
import com.caimei.utils.StringUtil;
|
|
|
-import com.caimei.utils.StringUtils;
|
|
|
+import com.caimei365.manager.config.utils.DateUtil;
|
|
|
import com.caimei365.manager.config.utils.UploadPicUtils;
|
|
|
import com.caimei365.manager.dao.svip.CmSvipHistoryDao;
|
|
|
import com.caimei365.manager.entity.PaginationVo;
|
|
@@ -16,6 +16,7 @@ import com.caimei365.manager.service.SendSmsService;
|
|
|
import com.caimei365.manager.service.caimei.svip.CmSvipHistoryService;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -252,19 +253,234 @@ public class CmSvipHistoryServiceImpl implements CmSvipHistoryService {
|
|
|
|
|
|
/**
|
|
|
* 编辑超级会员优惠券
|
|
|
- *
|
|
|
- * @param cmVipCoupon
|
|
|
+ * @param id
|
|
|
+ * @param configure
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public Map<String, Object> cmVipCouponForm(CmVipCoupon cmVipCoupon) {
|
|
|
+ public ResponseJson<Map<String, Object>> cmVipCouponForm(Integer id,Integer configure) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
-// SvipCouponForm svipcouponForm = cmVipCouponService.setSvipcouponForms(cmVipCoupon);
|
|
|
- List<String> useDateList = historyDao.getAllUseDateList();
|
|
|
-// map.put("svipcouponForm", svipcouponForm);
|
|
|
- map.put("useDateList", useDateList);
|
|
|
+ CmVipCoupon vipCoupon = null;
|
|
|
+ List<CmCoupon> couponList = null;
|
|
|
+ // 初始化优惠券信息
|
|
|
+ SvipCouponForm svipcouponForm = new SvipCouponForm();
|
|
|
+ if ( 1 == configure) {
|
|
|
+ // 专属优惠券配置
|
|
|
+ couponList = historyDao.selconfigure();
|
|
|
+ // 专属优惠券配置
|
|
|
+ CmVipCoupon cmVipCoupon = historyDao.selMonthTime();
|
|
|
+ // 开始时间
|
|
|
+ if (null != cmVipCoupon) {
|
|
|
+ svipcouponForm.setMonth(cmVipCoupon.getUseTime());
|
|
|
+ svipcouponForm.setId(cmVipCoupon.getId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 编辑优惠券
|
|
|
+ if (null == id) {
|
|
|
+ return ResponseJson.error(-1,"id不能为空",null);
|
|
|
+ }
|
|
|
+ vipCoupon = get(id.toString());
|
|
|
+ if (null != vipCoupon.getCouponList()) {
|
|
|
+ couponList = vipCoupon.getCouponList();
|
|
|
+ }
|
|
|
+ // 开始时间
|
|
|
+ svipcouponForm.setId(id.toString());
|
|
|
+ svipcouponForm.setMonth(vipCoupon.getUseTime());
|
|
|
+ svipcouponForm.setEndMonth(vipCoupon.getEndTime());
|
|
|
+ List<String> useDateList = historyDao.getAllUseDateList();
|
|
|
+ map.put("useDateList", useDateList);
|
|
|
+ }
|
|
|
+ ArrayList<CmCoupon> arr = new ArrayList<>();
|
|
|
+ // 设置券信息
|
|
|
+ if (null != couponList){
|
|
|
+ for (int i = 0; i < couponList.size(); i++) {
|
|
|
+ CmCoupon cmCoupon = new CmCoupon();
|
|
|
+ cmCoupon.setId(couponList.get(i).getId());
|
|
|
+ cmCoupon.setCouponAmount(couponList.get(i).getCouponAmount());
|
|
|
+ cmCoupon.setTouchPrice(couponList.get(i).getTouchPrice());
|
|
|
+ cmCoupon.setCouponType(couponList.get(i).getCouponType());
|
|
|
+ cmCoupon.setCategoryType(couponList.get(i).getCategoryType());
|
|
|
+ cmCoupon.setProductType(couponList.get(i).getProductType());
|
|
|
+ cmCoupon.setShopId(couponList.get(i).getShopId());
|
|
|
+ if (couponList.get(i).getCouponType() == 0) {
|
|
|
+ // 活动券,查询活动商品
|
|
|
+ if ("2".equals(couponList.get(i).getProductType())) {
|
|
|
+ List<CmCouponAssociate> associateList = findByProductType(couponList.get(i));
|
|
|
+ if (associateList.size() > 0) {
|
|
|
+ cmCoupon.setAssociateList(associateList);
|
|
|
+ } else {
|
|
|
+ cmCoupon.setAssociateList(new ArrayList<>());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ cmCoupon.setAssociateList(new ArrayList<>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (couponList.get(i).getCouponType() == 3) {
|
|
|
+ // 店铺券
|
|
|
+ NewCmShop shop = historyDao.getShopInfoByShopId(couponList.get(i).getShopId());
|
|
|
+ cmCoupon.setShopName(shop.getName());
|
|
|
+ cmCoupon.setShop(shop);
|
|
|
+ }
|
|
|
+ arr.add(cmCoupon);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ svipcouponForm.setCoupons(arr);
|
|
|
+ map.put("svipcouponForm", svipcouponForm);
|
|
|
+
|
|
|
+ return ResponseJson.success(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<CmCouponAssociate> findByProductType(CmCoupon cmCoupon) {
|
|
|
+ List<CmCouponAssociate> associateList = historyDao.findByProductType(cmCoupon.getId());
|
|
|
+ if (associateList != null && associateList.size() > 0) {
|
|
|
+ associateList.forEach(item -> {
|
|
|
+ item.setMainImage(AppUtils.getImageURL("product", item.getMainImage(), 0, "https://www.caimei365.com/"));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return associateList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存超级会员优惠券
|
|
|
+ *
|
|
|
+ * @param svipcouponForm
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson saveVipCoupon(SvipCouponForm svipcouponForm) {
|
|
|
+ CmVipCoupon cmVipCoupon = new CmVipCoupon();
|
|
|
+ cmVipCoupon.setId(svipcouponForm.getId());
|
|
|
+ if (1 == svipcouponForm.getConfigure()) {
|
|
|
+ cmVipCoupon.setUseTime(countMonth(new SimpleDateFormat("yyyy-MM").format(new Date())));
|
|
|
+ svipcouponForm.setMonth(new SimpleDateFormat("yyyy-MM").format(new Date()));
|
|
|
+ cmVipCoupon.setStatus("1");
|
|
|
+ cmVipCoupon.setDelFlag("1");
|
|
|
+ } else {
|
|
|
+ cmVipCoupon.setUseTime(svipcouponForm.getMonth());
|
|
|
+ cmVipCoupon.setStatus("1");
|
|
|
+ cmVipCoupon.setDelFlag("0");
|
|
|
+ }
|
|
|
+ cmVipCoupon.setUpdateTime(new Date());
|
|
|
+ setVipCouponStatus(cmVipCoupon);
|
|
|
+ // 解析 svipcouponForm -> 组装 CmCoupon 列表 保存
|
|
|
+ boolean flag = false;
|
|
|
+ if(StringUtils.isNotBlank(cmVipCoupon.getId())){
|
|
|
+ // 修改
|
|
|
+ historyDao.updateVipCouponMonth(cmVipCoupon);
|
|
|
+ } else {
|
|
|
+ // 新增
|
|
|
+ flag = true;
|
|
|
+ historyDao.insertVipCouponMonth(cmVipCoupon);
|
|
|
+ }
|
|
|
+ Date beginTime = DateUtil.getMinDay(svipcouponForm.getMonth());
|
|
|
+ // 结束时间为一个季度
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
|
|
|
+ Date dateMonth = null;
|
|
|
+ try {
|
|
|
+ dateMonth = dateFormat.parse(svipcouponForm.getMonth());
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(dateMonth);
|
|
|
+ calendar.add(Calendar.MONTH,2);
|
|
|
+ Date time = calendar.getTime();
|
|
|
+ String format = dateFormat.format(time);
|
|
|
+ Date endTime = DateUtil.getMaxDay(format);
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 券信息
|
|
|
+ */
|
|
|
+ if (null != svipcouponForm.getCoupons()) {
|
|
|
+ List<CmCoupon> coupons = svipcouponForm.getCoupons();
|
|
|
+ coupons.forEach(cp -> {
|
|
|
+ cp.setName("超级会员优惠券"+svipcouponForm.getMonth());
|
|
|
+ cp.setStartDate(beginTime);
|
|
|
+ cp.setEndDate(endTime);
|
|
|
+ cp.setStatus("1");
|
|
|
+ cp.setDelFlag("0");
|
|
|
+ cp.setVipFlag(1);
|
|
|
+ if (1 == svipcouponForm.getConfigure()) {
|
|
|
+ cp.setConfigure(1);
|
|
|
+ }
|
|
|
+ // 0活动券 1品类券 3店铺券
|
|
|
+ if (0 == cp.getCouponType()){
|
|
|
+ cp.setCouponType(0);
|
|
|
+// cp.setProductType(svipcouponForm.getProductType1());
|
|
|
+ if ("2".equals(cp.getProductType())){
|
|
|
+ // 指定商品
|
|
|
+ cp.setProductInfo(cp.getProductInfo());
|
|
|
+ }
|
|
|
+ } else if (1==cp.getCouponType()) {
|
|
|
+ cp.setCategoryType(cp.getCategoryType());
|
|
|
+ cp.setCouponType(1);
|
|
|
+ } else if (3==cp.getCouponType()) {
|
|
|
+ cp.setShopId(cp.getShopId());
|
|
|
+ cp.setCouponType(3);
|
|
|
+ }
|
|
|
|
|
|
- return map;
|
|
|
+ cmCouponService.save(cp);
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ /*coupon1.setName("超级会员优惠券"+svipcouponForm.getMonth());
|
|
|
+ coupon1.setStartDate(beginTime);
|
|
|
+ coupon1.setEndDate(endTime);
|
|
|
+ coupon1.setCouponAmount(svipcouponForm.getCouponAmount1());
|
|
|
+ coupon1.setTouchPrice(svipcouponForm.getTouchPrice1());
|
|
|
+ coupon1.setStatus("1");
|
|
|
+ coupon1.setVipFlag(1);
|
|
|
+ // 0活动券 1品类券 3店铺券
|
|
|
+ if ("0".equals(svipcouponForm.getCouponType1())){
|
|
|
+ coupon1.setCouponType(0);
|
|
|
+ coupon1.setProductType(svipcouponForm.getProductType1());
|
|
|
+ if ("2".equals(svipcouponForm.getProductType1())){
|
|
|
+ // 指定商品
|
|
|
+ coupon1.setProductInfo(svipcouponForm.getProductInfo1());
|
|
|
+ }
|
|
|
+ } else if ("1".equals(svipcouponForm.getCouponType1())) {
|
|
|
+ coupon1.setCategoryType(svipcouponForm.getCategoryType1());
|
|
|
+ coupon1.setCouponType(1);
|
|
|
+ } else if ("3".equals(svipcouponForm.getCouponType1())) {
|
|
|
+ coupon1.setShopId(svipcouponForm.getShopId1());
|
|
|
+ coupon1.setCouponType(3);
|
|
|
+ }*/
|
|
|
+ /*
|
|
|
+ * vip优惠券月份关系
|
|
|
+ */
|
|
|
+ CmVipCouponRelation relation = new CmVipCouponRelation();
|
|
|
+ for (int i = 0; i < svipcouponForm.getCoupons().size() ; i++) {
|
|
|
+ relation.setMontId(cmVipCoupon.getId());
|
|
|
+ relation.setCouponId(svipcouponForm.getCoupons().get(i).getId());
|
|
|
+ relation.setUpdateTime(new Date());
|
|
|
+ relation.setDelFlag("0");
|
|
|
+ if (flag) {
|
|
|
+ // 新增
|
|
|
+ historyDao.insertVipCouponRelation(relation);
|
|
|
+ }
|
|
|
+ /*else {
|
|
|
+ // 修改
|
|
|
+ historyDao.updateVipCouponRelation(relation);
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return ResponseJson.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除优惠券
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson delCoupon(Integer id) {
|
|
|
+ historyDao.delCoupon(id);
|
|
|
+ historyDao.delSvipCoupon(id);
|
|
|
+ historyDao.delSvipProduct(id);
|
|
|
+ return ResponseJson.success();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -448,13 +664,12 @@ public class CmSvipHistoryServiceImpl implements CmSvipHistoryService {
|
|
|
/**
|
|
|
* 保存超级会员商品
|
|
|
*
|
|
|
- * @param productId
|
|
|
+ * @param cmSvipProduct
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResponseJson saveSvipProduct(Integer productId) {
|
|
|
- CmSvipProduct cmSvipProduct = new CmSvipProduct();
|
|
|
- cmSvipProduct.setProductId(productId);
|
|
|
+ public ResponseJson saveSvipProduct(CmSvipProduct cmSvipProduct) {
|
|
|
+ cmSvipProduct.setProductId(cmSvipProduct.getProductId());
|
|
|
//保存/修改同步处理cm_svip_product_sku表数据
|
|
|
if (null == cmSvipProduct.getId()) {
|
|
|
cmSvipProduct.setSort(1);
|
|
@@ -698,4 +913,21 @@ public class CmSvipHistoryServiceImpl implements CmSvipHistoryService {
|
|
|
cmVipCoupon.setEndDate(endDate);
|
|
|
return cmVipCoupon;
|
|
|
}
|
|
|
+ public String countMonth(String countMonth) {
|
|
|
+ String year = countMonth.substring(0,countMonth.length() - 2);
|
|
|
+ String month = countMonth.substring(countMonth.length() - 2);
|
|
|
+ if (month.equals("02") || month.equals("03") || month.equals("04")) {
|
|
|
+ month = "02";
|
|
|
+ }
|
|
|
+ if (month.equals("05") || month.equals("06") || month.equals("07")) {
|
|
|
+ month = "05";
|
|
|
+ }
|
|
|
+ if (month.equals("08") || month.equals("09") || month.equals("10")) {
|
|
|
+ month = "08";
|
|
|
+ }
|
|
|
+ if (month.equals("11") || month.equals("12") || month.equals("1")) {
|
|
|
+ month = "11";
|
|
|
+ }
|
|
|
+ return year + month;
|
|
|
+ }
|
|
|
}
|