| @@ -1,5 +1,6 @@ | |||||
| package com.iformall.controller.market; | package com.iformall.controller.market; | ||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.annotation.SystemControllerLog; | import com.iformall.annotation.SystemControllerLog; | ||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| @@ -105,6 +106,24 @@ public class WxCouponSendController extends BaseController { | |||||
| if (!EnumCouponSendType.PASSIVE.getCode().equals(wxCoupon.getSendType())) { | if (!EnumCouponSendType.PASSIVE.getCode().equals(wxCoupon.getSendType())) { | ||||
| return new ResultData(ErrorCode.COUPON_TYPE_IS_NOT_PASSIVE); | return new ResultData(ErrorCode.COUPON_TYPE_IS_NOT_PASSIVE); | ||||
| } | } | ||||
| //商户卡库存校验 | |||||
| if(Objects.equals(wxCouponSend.getSendType(),EnumCouponSendSendType.MERCHANT.getCode())) { | |||||
| JSONObject jo = JSONObject.parseObject(wxCouponSend.getConditions()) ; | |||||
| if(Objects.isNull(jo)||!jo.containsKey(WxCouponSend.KEY_LIMIT)) { | |||||
| return new ResultData(ErrorCode.COUPON_SEND_LIMIT_VERIFY); | |||||
| } | |||||
| WxCoupon queryById = new WxCoupon() ; | |||||
| queryById.setId(wxCouponSend.getId()); | |||||
| WxCoupon wxCouponOfDb = wxCouponService.findById(queryById); | |||||
| if(Objects.isNull(wxCouponOfDb)) { | |||||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | |||||
| } | |||||
| if(jo.getInteger(WxCouponSend.KEY_LIMIT) >wxCouponOfDb.getRemainInventory()) { | |||||
| return new ResultData(ErrorCode.REMAIN_IS_EMPTY); | |||||
| } | |||||
| } | |||||
| wxCouponSend.setTenantId(wxCoupon.getTenantId()); | wxCouponSend.setTenantId(wxCoupon.getTenantId()); | ||||
| wxCouponSend.setTitle(wxCoupon.getTitle()); | wxCouponSend.setTitle(wxCoupon.getTitle()); | ||||
| @@ -0,0 +1,52 @@ | |||||
| package com.iformall.controller; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.BaseEntity; | |||||
| import com.iformall.domain.po.WxCouponSend; | |||||
| import com.iformall.domain.vo.WxCouponSendVo; | |||||
| import com.iformall.enums.EnumCouponSendStatus; | |||||
| import com.iformall.service.WxCouponActionLogService; | |||||
| import com.iformall.service.WxCouponSendService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.GetMapping; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | |||||
| import org.springframework.web.bind.annotation.RestController; | |||||
| @RestController | |||||
| @RequestMapping("/api/couponSend") | |||||
| @Api(description = "商户卡券相关接口") | |||||
| public class WxCouponSendController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxCouponSendService wxCouponSendService; | |||||
| @Autowired | |||||
| private WxCouponActionLogService wxCouponActionLogService; | |||||
| @ApiOperation("查询商户卡券列表") | |||||
| @GetMapping("/list") | |||||
| @ApiImplicitParam(name = "sendType", value = "sendType", dataType = "Long", paramType = "query", required = true) | |||||
| public ResultData list(Integer sendType, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponSendController::list"); | |||||
| WxCouponSend wxCouponSend = new WxCouponSend(); | |||||
| wxCouponSend.setSendType(sendType); | |||||
| wxCouponSend.setTenantId(getTenantId()); | |||||
| wxCouponSend.setStatus(EnumCouponSendStatus.VALID.getCode()); | |||||
| //库存大于0 | |||||
| wxCouponSend.setInventory(0); | |||||
| wxCouponSend.setSortColumns(BaseEntity.SortField.CreateDate_DESC); | |||||
| final PageInfo<WxCouponSendVo> page = wxCouponSendService.listAsPage(wxCouponSend, pageNum, pageSize); | |||||
| for (WxCouponSendVo cs : page.getList()) { | |||||
| cs.setSendCount(wxCouponActionLogService.getCountByChannelId(getTenantId(), cs.getSendType(), cs.getId())); | |||||
| } | |||||
| return new ResultData(page); | |||||
| } | |||||
| } | |||||
| @@ -191,6 +191,7 @@ public enum ErrorCode{ | |||||
| COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE(4006, "卡券使用期还未开始"), | COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE(4006, "卡券使用期还未开始"), | ||||
| COUPON_ORDER_IS_LATER_THAN_VALIDDATE(4007, "卡券使用期已结束"), | COUPON_ORDER_IS_LATER_THAN_VALIDDATE(4007, "卡券使用期已结束"), | ||||
| COUPON_ORDER_IS_PRE_VERIFY(4008, "卡券已被预核销"), | COUPON_ORDER_IS_PRE_VERIFY(4008, "卡券已被预核销"), | ||||
| COUPON_SEND_LIMIT_VERIFY(4009, "商户卡库存错误"), | |||||
| /** | /** | ||||
| * 卡 | * 卡 | ||||
| @@ -16,10 +16,21 @@ import java.util.List; | |||||
| @EqualsAndHashCode(callSuper = true) | @EqualsAndHashCode(callSuper = true) | ||||
| public class WxCouponSend extends BaseEntity { | public class WxCouponSend extends BaseEntity { | ||||
| /** | |||||
| * 卡券ids | |||||
| */ | |||||
| @Transient | @Transient | ||||
| public static final String KEY_COUPONIDS = "couponIds" ; | public static final String KEY_COUPONIDS = "couponIds" ; | ||||
| /** | |||||
| * beforeDays | |||||
| */ | |||||
| @Transient | @Transient | ||||
| public static final String KEY_BEFOREDAYS = "beforeDays" ; | public static final String KEY_BEFOREDAYS = "beforeDays" ; | ||||
| /** | |||||
| * limit 商户券库存 | |||||
| */ | |||||
| @Transient | |||||
| public static final String KEY_LIMIT = "limit" ; | |||||
| @Id | @Id | ||||
| protected Long id; | protected Long id; | ||||
| @@ -27,6 +38,12 @@ public class WxCouponSend extends BaseEntity { | |||||
| @Transient | @Transient | ||||
| protected List<Long> ids; | protected List<Long> ids; | ||||
| /** | |||||
| * 库存条件 | |||||
| */ | |||||
| @Transient | |||||
| protected Integer inventory; | |||||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | ||||
| private String tenantId; | private String tenantId; | ||||
| @io.swagger.annotations.ApiModelProperty(value="卡券id",name="couponId") | @io.swagger.annotations.ApiModelProperty(value="卡券id",name="couponId") | ||||
| @@ -87,6 +87,9 @@ | |||||
| and cs.send_sms = #{sendSms} | and cs.send_sms = #{sendSms} | ||||
| </if> | </if> | ||||
| <if test=" null != inventory "> | |||||
| and c.remain_inventory > #{inventory} | |||||
| </if> | |||||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | <if test=" null != sortColumns"> order by ${sortColumns} </if> | ||||
| </sql> | </sql> | ||||