| @@ -6,6 +6,7 @@ import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
| import com.iformall.domain.po.WxCouponSendConfig; | import com.iformall.domain.po.WxCouponSendConfig; | ||||
| import com.iformall.enums.EnumCouponSendSendType; | |||||
| import com.iformall.service.WxCouponSendConfigService; | import com.iformall.service.WxCouponSendConfigService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| @@ -37,8 +38,12 @@ public class WxCouponSendConfigController extends BaseController { | |||||
| PageInfo<WxCouponSendConfig> page = wxCouponSendConfigService.listAsPage(wxCouponSendConfig, 1, 1); | PageInfo<WxCouponSendConfig> page = wxCouponSendConfigService.listAsPage(wxCouponSendConfig, 1, 1); | ||||
| if (page.getSize() > 0) { | if (page.getSize() > 0) { | ||||
| return new ResultData(page.getList().get(0)); | return new ResultData(page.getList().get(0)); | ||||
| } else { | |||||
| //默认停用 | |||||
| wxCouponSendConfig.setRemark(EnumCouponSendSendType.getEnum(wxCouponSendConfig.getSendType()).getMessage() + "开关"); | |||||
| wxCouponSendConfig.setValue(0); | |||||
| return new ResultData(wxCouponSendConfig); | |||||
| } | } | ||||
| return new ResultData(); | |||||
| } | } | ||||
| @@ -126,15 +126,15 @@ public class WxCouponSendController extends BaseController { | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @ApiOperation("根据id更新接口") | |||||
| @PostMapping("update") | |||||
| @SystemControllerLog(description = "注券-更新") | |||||
| public ResultData update(@RequestBody WxCouponSend wxCouponSend) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponSendController::update"); | |||||
| wxCouponSend.setTenantId(getTenantId()); | |||||
| wxCouponSendService.saveOrUpdate(wxCouponSend); | |||||
| return new ResultData(); | |||||
| } | |||||
| // @ApiOperation("根据id更新接口") | |||||
| // @PostMapping("update") | |||||
| // @SystemControllerLog(description = "注券-更新") | |||||
| // public ResultData update(@RequestBody WxCouponSend wxCouponSend) { | |||||
| // logger.debug("[" + getIpAddr() + "] WxCouponSendController::update"); | |||||
| // wxCouponSend.setTenantId(getTenantId()); | |||||
| // wxCouponSendService.saveOrUpdate(wxCouponSend); | |||||
| // return new ResultData(); | |||||
| // } | |||||
| @ApiOperation("根据id删除接口") | @ApiOperation("根据id删除接口") | ||||
| @GetMapping("/del") | @GetMapping("/del") | ||||
| @@ -146,11 +146,10 @@ public class WxCouponSendController extends BaseController { | |||||
| public ResultData delete(Long id) { | public ResultData delete(Long id) { | ||||
| logger.debug("[" + getIpAddr() + "] WxCouponSendController::delete"); | logger.debug("[" + getIpAddr() + "] WxCouponSendController::delete"); | ||||
| WxCouponSend wxCouponSend = wxCouponSendService.getById(id); | WxCouponSend wxCouponSend = wxCouponSendService.getById(id); | ||||
| if (wxCouponSend == null) | |||||
| if (wxCouponSend == null) { | |||||
| return new ResultData(ErrorCode.COUPON_SEND_IS_INVALID); | return new ResultData(ErrorCode.COUPON_SEND_IS_INVALID); | ||||
| wxCouponSend.setStatus(EnumCouponSendStatus.INVALID.getCode()); | |||||
| wxCouponSend.setUpdateDate(new Date()); | |||||
| wxCouponSendService.saveOrUpdate(wxCouponSend); | |||||
| } | |||||
| wxCouponSendService.updateInvalid(wxCouponSend); | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @@ -1,17 +1,20 @@ | |||||
| package com.iformall.controller; | package com.iformall.controller; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.BaseEntity; | import com.iformall.domain.po.BaseEntity; | ||||
| import com.iformall.domain.po.WxCouponSend; | import com.iformall.domain.po.WxCouponSend; | ||||
| import com.iformall.domain.vo.WxCouponSendVo; | import com.iformall.domain.vo.WxCouponSendVo; | ||||
| import com.iformall.enums.EnumCouponSendStatus; | import com.iformall.enums.EnumCouponSendStatus; | ||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.service.WxCouponActionLogService; | import com.iformall.service.WxCouponActionLogService; | ||||
| import com.iformall.service.WxCouponSendService; | import com.iformall.service.WxCouponSendService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import org.apache.commons.lang3.ArrayUtils; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -19,9 +22,12 @@ import org.springframework.web.bind.annotation.GetMapping; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | import org.springframework.web.bind.annotation.RestController; | ||||
| import javax.validation.constraints.NotNull; | |||||
| import java.util.Objects; | |||||
| @RestController | @RestController | ||||
| @RequestMapping("/api/couponSend") | @RequestMapping("/api/couponSend") | ||||
| @Api(description = "商户卡券相关接口") | |||||
| @Api(description = "商户注券相关接口") | |||||
| public class WxCouponSendController extends BaseController { | public class WxCouponSendController extends BaseController { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @@ -30,19 +36,20 @@ public class WxCouponSendController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxCouponActionLogService wxCouponActionLogService; | private WxCouponActionLogService wxCouponActionLogService; | ||||
| @ApiOperation("查询商户卡券列表") | |||||
| @ApiOperation("查询商户注券列表") | |||||
| @GetMapping("/list") | @GetMapping("/list") | ||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | ||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | ||||
| @ApiImplicitParam(name = "sendType", value = "2:停车发券 3:核销发券 4: B端刷卡发券 5:商户发卷 6:定时发券 7:商户发券", dataType = "int", paramType = "query",required = true), | |||||
| @ApiImplicitParam(name = "merchantId", value = "商户ID", dataType = "long", paramType = "query",required = true), | |||||
| }) | }) | ||||
| public ResultData list(Integer sendType, Integer pageNum, Integer pageSize) { | |||||
| public ResultData list(WxCouponSend wxCouponSend, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponSendController::list"); | logger.debug("[" + getIpAddr() + "] WxCouponSendController::list"); | ||||
| WxCouponSend wxCouponSend = new WxCouponSend(); | |||||
| wxCouponSend.setSendType(sendType); | |||||
| if (Objects.isNull(wxCouponSend.getMerchantId()) || Objects.equals(wxCouponSend.getMerchantId(), 0) || Objects.isNull(wxCouponSend.getSendType())) { | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| wxCouponSend.setTenantId(getTenantId()); | wxCouponSend.setTenantId(getTenantId()); | ||||
| wxCouponSend.setStatus(EnumCouponSendStatus.VALID.getCode()); | |||||
| wxCouponSend.setStatus(Objects.isNull(wxCouponSend.getStatus()) ? null : wxCouponSend.getStatus()); | |||||
| //库存大于0 | //库存大于0 | ||||
| wxCouponSend.setMerchantLnventory(0); | wxCouponSend.setMerchantLnventory(0); | ||||
| wxCouponSend.setSortColumns(BaseEntity.SortField.CreateDate_DESC); | wxCouponSend.setSortColumns(BaseEntity.SortField.CreateDate_DESC); | ||||
| @@ -54,4 +61,18 @@ public class WxCouponSendController extends BaseController { | |||||
| return new ResultData(page); | return new ResultData(page); | ||||
| } | } | ||||
| @ApiOperation("商户注券") | |||||
| @GetMapping("/handsel") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "wxCouponSendId", value = "wxCouponSendId", dataType = "long", paramType = "query",required = true), | |||||
| @ApiImplicitParam(name = "cUserId", value = "用户ID", dataType = "long", paramType = "query",required = true), | |||||
| }) | |||||
| public ResultData handsel(Long[] wxCouponSendIds,Long cUserId) { | |||||
| if(ArrayUtils.isEmpty(wxCouponSendIds)||Objects.isNull(cUserId)) { | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| } | } | ||||
| @@ -257,20 +257,27 @@ public class CouponSendSchedule { | |||||
| return; | return; | ||||
| } | } | ||||
| WxCouponSend config = wxCouponSendService.getConfig(EnumCouponSendSendType.BIRTHDAY.getCode(), cu.getTenantId()); | |||||
| if (Objects.isNull(config) || Objects.isNull(config.getConditions())) { | |||||
| logger.info("生日发券: 会员生日券配置不存在 config = {}, 任务跳过不执行", config); | |||||
| return; | |||||
| } | |||||
| //默认生日当天发送 | |||||
| int beforeDays = 0; | |||||
| JSONObject configJo = JSONObject.parseObject(config.getConditions()); | |||||
| if (configJo.containsKey(WxCouponSend.KEY_BEFOREDAYS)) { | |||||
| beforeDays = configJo.getIntValue(WxCouponSend.KEY_BEFOREDAYS); | |||||
| } | |||||
| // WxCouponSend config = wxCouponSendService.getConfig(EnumCouponSendSendType.BIRTHDAY.getCode(), cu.getTenantId()); | |||||
| // | |||||
| boolean sent = false; | |||||
| for (WxCouponSendVo cs : couponSendList) { | for (WxCouponSendVo cs : couponSendList) { | ||||
| String conditions = cs.getConditions(); | |||||
| JSONObject configJo = null; | |||||
| try { | |||||
| configJo = JSONObject.parseObject(conditions); | |||||
| } catch (Exception e) { | |||||
| logger.error("生日发券: 解析conditions异常: {}",e.getMessage()); | |||||
| } | |||||
| if (Objects.isNull(conditions)||Objects.isNull(configJo)) { | |||||
| logger.info("生日发券: 会员生日券配置不存在 conditions = {}, 任务跳过不执行", conditions); | |||||
| return; | |||||
| } | |||||
| //默认生日当天发送 | |||||
| int beforeDays = 0; | |||||
| if (configJo.containsKey(WxCouponSend.KEY_BEFOREDAYS)) { | |||||
| beforeDays = configJo.getIntValue(WxCouponSend.KEY_BEFOREDAYS); | |||||
| } | |||||
| Map<String, Object> params = new HashMap<>(); | Map<String, Object> params = new HashMap<>(); | ||||
| params.put("tenantId", cs.getTenantId()); | params.put("tenantId", cs.getTenantId()); | ||||
| params.put("cUserId", cu.getId()); | params.put("cUserId", cu.getId()); | ||||
| @@ -287,7 +294,8 @@ public class CouponSendSchedule { | |||||
| continue; | continue; | ||||
| } | } | ||||
| //提前n天发送生日券,不满足跳过不执行 | //提前n天发送生日券,不满足跳过不执行 | ||||
| if (DateUtils.birthdaysBetween(cu.getBirthdate()) == beforeDays) { | |||||
| if (DateUtils.birthdaysBetween(cu.getBirthdate()) != beforeDays) { | |||||
| logger.info("生日发券: [会员={},生日={}不满足提前{}天发券]", cu.getNickName(), cu.getBirthdate(),beforeDays); | |||||
| continue; | continue; | ||||
| } | } | ||||
| if (cs.getRemainInventory() <= 0) { | if (cs.getRemainInventory() <= 0) { | ||||
| @@ -297,14 +305,12 @@ public class CouponSendSchedule { | |||||
| // 发放免费券 | // 发放免费券 | ||||
| try { | try { | ||||
| WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cu.getId(), cs.getCouponId()); | WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cu.getId(), cs.getCouponId()); | ||||
| sendSMS(cu, mall); | |||||
| wxCouponActionLogService.addOne(cu.getTenantId(), cs.getCouponId(), couponOrder.getId(), cs.getSendType(), cs.getId()); | wxCouponActionLogService.addOne(cu.getTenantId(), cs.getCouponId(), couponOrder.getId(), cs.getSendType(), cs.getId()); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("定时发券:发券失败 levelId=" + cu.getId() + " couponId=" + cs.getCouponId() + " userId=" + cu.getId() + e.getMessage()); | logger.error("定时发券:发券失败 levelId=" + cu.getId() + " couponId=" + cs.getCouponId() + " userId=" + cu.getId() + e.getMessage()); | ||||
| logger.info("定时发券:发券失败 levelId=" + cu.getId() + " couponId=" + cs.getCouponId() + " userId=" + cu.getId() + e.getMessage()); | |||||
| continue; | continue; | ||||
| } | } | ||||
| sent = true ; | |||||
| logger.info("定时发券:商场[" + mall.getName() + | logger.info("定时发券:商场[" + mall.getName() + | ||||
| "]会员生日[" + cu.getBirthdate().toInstant() + | "]会员生日[" + cu.getBirthdate().toInstant() + | ||||
| "]发送券[" + cs.getTitle() + | "]发送券[" + cs.getTitle() + | ||||
| @@ -312,6 +318,9 @@ public class CouponSendSchedule { | |||||
| " 电话-" + cu.getPhone() + | " 电话-" + cu.getPhone() + | ||||
| " id-" + cu.getId()); | " id-" + cu.getId()); | ||||
| } | } | ||||
| if(sent) { | |||||
| sendSMS(cu, mall); | |||||
| } | |||||
| }); | }); | ||||
| }); | }); | ||||
| logger.info("生日发券: 任务结束"); | logger.info("生日发券: 任务结束"); | ||||
| @@ -352,7 +361,7 @@ public class CouponSendSchedule { | |||||
| //没有配置积分规则 | //没有配置积分规则 | ||||
| wxMsgRecord.setModelType(EnumMsgModel.COUPON_BIRTHDAY_OPENED_NO.getCode()); | wxMsgRecord.setModelType(EnumMsgModel.COUPON_BIRTHDAY_OPENED_NO.getCode()); | ||||
| } | } | ||||
| dynamicContentMap.put("userName", cUserBasicInfo.getNickName()); | |||||
| dynamicContentMap.put("userName", Objects.isNull(cUserBasicInfo.getNickName()) ? "" : cUserBasicInfo.getNickName()); | |||||
| dynamicContentMap.put("mallName", mall.getName()); | dynamicContentMap.put("mallName", mall.getName()); | ||||
| wxMsgRecord.setDynamicContentMap(dynamicContentMap); | wxMsgRecord.setDynamicContentMap(dynamicContentMap); | ||||
| mqBaseProducer.sendMessage(wxMsgRecord, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | mqBaseProducer.sendMessage(wxMsgRecord, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | ||||
| @@ -47,6 +47,11 @@ public class WxCouponSend extends BaseEntity { | |||||
| /**发卷所属商户名**/ | /**发卷所属商户名**/ | ||||
| @Transient | @Transient | ||||
| private String merchantName; | private String merchantName; | ||||
| /** | |||||
| * 商户ID | |||||
| */ | |||||
| @Transient | |||||
| private Long merchantId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | ||||
| private String tenantId; | private String tenantId; | ||||
| @@ -59,7 +64,7 @@ public class WxCouponSend extends BaseEntity { | |||||
| private Integer sendType; | private Integer sendType; | ||||
| @io.swagger.annotations.ApiModelProperty(value="发券条件",name="condition") | @io.swagger.annotations.ApiModelProperty(value="发券条件",name="condition") | ||||
| private String conditions; | private String conditions; | ||||
| @io.swagger.annotations.ApiModelProperty(value="0:有效 1:无效",name="status") | |||||
| @io.swagger.annotations.ApiModelProperty(value="0:有效 1:无效,全部时不传",name="status") | |||||
| private Integer status; | private Integer status; | ||||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | ||||
| @@ -34,6 +34,12 @@ public interface WxCouponSendService { | |||||
| */ | */ | ||||
| void saveOrUpdate(WxCouponSend record); | void saveOrUpdate(WxCouponSend record); | ||||
| /** | |||||
| * 更新为无效 | |||||
| * @param record | |||||
| */ | |||||
| void updateInvalid(WxCouponSend record) ; | |||||
| /** | /** | ||||
| * 根据Id删除实体 | * 根据Id删除实体 | ||||
| * | * | ||||
| @@ -77,6 +77,15 @@ | |||||
| and cs.update_date = #{updateDate} | and cs.update_date = #{updateDate} | ||||
| </if> | </if> | ||||
| <if test=" null != merchantName and ''!=merchantName"> | |||||
| and cs.conditions -> '$.title' like concat('%',#{merchantName},'%') | |||||
| </if> | |||||
| <if test=" null != merchantId and ''!=merchantId "> | |||||
| and cs.conditions->'$.id' = concat(#{merchantId},'') | |||||
| </if> | |||||
| <if test=" null != merchantLnventory "> | |||||
| and cs.conditions -> '$.merchantLnventory'> #{merchantLnventory} | |||||
| </if> | |||||
| <if test=" null != ids "> | <if test=" null != ids "> | ||||
| and id in | and id in | ||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | ||||
| @@ -87,9 +96,6 @@ | |||||
| and cs.send_sms = #{sendSms} | and cs.send_sms = #{sendSms} | ||||
| </if> | </if> | ||||
| <if test=" null != merchantLnventory "> | |||||
| and c.remain_inventory > #{merchantLnventory} | |||||
| </if> | |||||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | <if test=" null != sortColumns"> order by ${sortColumns} </if> | ||||
| </sql> | </sql> | ||||
| @@ -104,9 +110,6 @@ | |||||
| from wx_coupon_send cs left join wx_coupon c on c.id = cs.coupon_id | from wx_coupon_send cs left join wx_coupon c on c.id = cs.coupon_id | ||||
| <include refid="dynamicWhereConditions"/>) as tt | <include refid="dynamicWhereConditions"/>) as tt | ||||
| where 1=1 | where 1=1 | ||||
| <if test=" null != merchantName "> | |||||
| and tt.conditions like concat('%', #{merchantName},'%') | |||||
| </if> | |||||
| <choose> | <choose> | ||||
| <when test="expired == 0"> | <when test="expired == 0"> | ||||
| and <![CDATA[ tt.valid_end_date <= now() ]]> | and <![CDATA[ tt.valid_end_date <= now() ]]> | ||||