From 8072b584f22a78e4594615a0f3fec39bb757b39f Mon Sep 17 00:00:00 2001 From: masterspirit Date: Thu, 30 Aug 2018 00:29:59 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=9C=BA=E6=99=AF=E6=8A=95=E6=94=BE][?= =?UTF-8?q?=E4=BF=AE=E6=94=B9]=20=E5=8A=A0=E5=85=A5=E5=BC=80=E5=85=B3?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/simple/mapper/WxCouponMapper.java | 2 ++ .../com/simple/service/WxCouponService.java | 2 ++ .../service/impl/WxCouponSendServiceImpl.java | 34 ++++++++++++++----- .../service/impl/WxCouponServiceImpl.java | 5 +++ .../main/resources/mapper/WxCouponMapper.xml | 5 +++ 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/mallinkService/src/main/java/com/simple/mapper/WxCouponMapper.java b/mallinkService/src/main/java/com/simple/mapper/WxCouponMapper.java index 9cc89637a..45c8d18c8 100644 --- a/mallinkService/src/main/java/com/simple/mapper/WxCouponMapper.java +++ b/mallinkService/src/main/java/com/simple/mapper/WxCouponMapper.java @@ -13,5 +13,7 @@ public interface WxCouponMapper extends CommonMapper { WxCouponCVo selectDetailForCUser(WxCouponChannel wxCouponChannel); WxCouponCVo selectDetailForCUserC(WxCoupon wxCoupon); + + void reduceInventory(@Param("id")Long id,@Param("number")Integer number); } diff --git a/mallinkService/src/main/java/com/simple/service/WxCouponService.java b/mallinkService/src/main/java/com/simple/service/WxCouponService.java index 53cee462b..044712aa2 100644 --- a/mallinkService/src/main/java/com/simple/service/WxCouponService.java +++ b/mallinkService/src/main/java/com/simple/service/WxCouponService.java @@ -53,4 +53,6 @@ public interface WxCouponService { WxCouponCVo selectDetailForCUser(WxCoupon record); ResultData updateCoupon(WxCoupon wxCoupon); + void reduceInventory(Long id,Integer number); + } diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxCouponSendServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxCouponSendServiceImpl.java index 5f131c8d1..0e5eab49d 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxCouponSendServiceImpl.java +++ b/mallinkService/src/main/java/com/simple/service/impl/WxCouponSendServiceImpl.java @@ -6,15 +6,14 @@ import com.github.pagehelper.PageInfo; import com.simple.domain.po.WxCoupon; import com.simple.domain.po.WxCouponOrder; import com.simple.domain.po.WxCouponSend; +import com.simple.domain.po.WxMallConfig; import com.simple.mapper.WxCouponSendMapper; -import com.simple.service.WxCouponActionLogService; -import com.simple.service.WxCouponOrderService; -import com.simple.service.WxCouponSendService; -import com.simple.service.WxCouponService; +import com.simple.service.*; import org.apache.commons.lang.time.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.simple.common.IdWorker; +import org.springframework.transaction.annotation.Transactional; @Service public class WxCouponSendServiceImpl implements WxCouponSendService { @@ -27,6 +26,8 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { WxCouponService wxCouponService; @Autowired WxCouponActionLogService wxCouponActionLogService; + @Autowired + WxMallConfigService wxMallConfigService; @Override @@ -57,24 +58,40 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { } @Override + @Transactional public void sendCouponToUser(String tenantId, Long cUserId, int type) { //查询开关是否打开 - //查询停车或者核销的券 + //查询停车或者核销的券 stopCarCouponSwitch verifyConponSwitch WxCouponSend wxCouponSendQuery = new WxCouponSend(); wxCouponSendQuery.setTenantId(tenantId); int actionLogType=0; + String configKey=""; if(type==2){ //停车 wxCouponSendQuery.setSendType(2); actionLogType=3; + configKey="stopCarCouponSwitch"; } if(type==3){ //核销 wxCouponSendQuery.setSendType(3); actionLogType=4; + configKey="verifyConponSwitch"; }else{ return; } + WxMallConfig wxMallConfigQuery = new WxMallConfig(); + wxMallConfigQuery.setKey(configKey); + wxMallConfigQuery.setTenantId(tenantId); + PageInfo page = wxMallConfigService.listAsPage(wxMallConfigQuery, 1, 1); + if(page.getSize()>0) { + WxMallConfig config = page.getList().get(0); + if(config.getValue()==1){ + return; + } + } + + List wxCouponSends = wxCouponSendMapper.findList(wxCouponSendQuery); for (WxCouponSend send:wxCouponSends) { WxCoupon wxCoupon= wxCouponService.getById(send.getCouponId()); @@ -85,6 +102,9 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { wxCouponOrder.setCouponPrice(0); wxCouponOrder.setCreateDate(new Date()); if (wxCoupon.getValidType() == 1) { //时间范围区间 + if(new Date().after(wxCoupon.getValidEndDate())){ + continue; + } wxCouponOrder.setExpiredTime(wxCoupon.getValidEndDate()); } else { Date date = DateUtils.addDays(new Date(), wxCoupon.getValidDays()); @@ -93,10 +113,8 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { wxCouponOrder.setTenantId(wxCoupon.getTenantId()); Long couponOrderId = wxCouponOrderService.insertOne(wxCouponOrder); wxCouponActionLogService.addOne(tenantId, wxCoupon.getId(), couponOrderId, actionLogType, send.getId()); + wxCouponService.reduceInventory(wxCoupon.getId(),1); } - - - } @Override diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxCouponServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxCouponServiceImpl.java index 66017887a..154ccd4bf 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/simple/service/impl/WxCouponServiceImpl.java @@ -90,5 +90,10 @@ public class WxCouponServiceImpl implements WxCouponService { } + @Override + public void reduceInventory(Long id, Integer number) { + wxCouponMapper.reduceInventory(id,number); + } + } diff --git a/mallinkService/src/main/resources/mapper/WxCouponMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponMapper.xml index 6586311f0..8dd689d7c 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponMapper.xml @@ -291,4 +291,9 @@ + + update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and remain_inventory>= #{number} + + +