diff --git a/mallinkAdmin/src/main/resources/db/migration/V201906251400__ADD_CONDITION_FOR_COUPON.sql b/mallinkAdmin/src/main/resources/db/migration/V201906251400__ADD_CONDITION_FOR_COUPON.sql new file mode 100644 index 000000000..cf2e0042a --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V201906251400__ADD_CONDITION_FOR_COUPON.sql @@ -0,0 +1,4 @@ +ALTER TABLE `wx_c_user_basic_info` +ADD COLUMN `act_record` INT(11) NULL DEFAULT '0' AFTER `active_time`; +ALTER TABLE `wx_coupon` +ADD COLUMN `condition` JSON NULL DEFAULT NULL AFTER `is_del`; \ No newline at end of file diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxOrderController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxOrderController.java index 2f5b4a698..f0f8d80d3 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxOrderController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxOrderController.java @@ -1,16 +1,18 @@ package com.iformall.controller; +import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageInfo; import com.iformall.common.ErrorCode; import com.iformall.common.Result; import com.iformall.common.ResultData; import com.iformall.domain.dto.OrderSaveDto; import com.iformall.domain.po.*; -import com.iformall.domain.vo.WxMerchantVo; +import com.iformall.domain.vo.WxCouponCVo; import com.iformall.domain.vo.WxOrderCouponPressVo; import com.iformall.domain.vo.WxOrderCouponVo; import com.iformall.enums.*; import com.iformall.exception.MallinkException; +import com.iformall.service.WxCUserBasicInfoService; import com.iformall.service.WxCouponChannelService; import com.iformall.service.WxCouponService; import com.iformall.service.WxOrderService; @@ -44,6 +46,9 @@ public class WxOrderController extends BaseController { @Autowired private WxCouponService wxCouponService; + @Autowired + private WxCUserBasicInfoService wxCUserBasicInfoService; + @ApiOperation(value = "下订单", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"press\":\"String\",\"orderGroupId\":\"String\",\"formId\":\"String\"}") @PostMapping("save") public ResultData saveOrder(@RequestBody OrderSaveDto orderSaveDto) { @@ -55,6 +60,10 @@ public class WxOrderController extends BaseController { ResultData resultData = couponChannelCheck(orderSaveDto, wxCouponChannel); if (resultData != null) return resultData; + WxCUser user = getUser(); + resultData = couponUserCheck(user, wxCouponChannelService.findDetailVo(orderSaveDto.getCouponChannelId())); + if (resultData != null) return resultData; + Long couponId = orderSaveDto.getCouponId() == null ? wxCouponChannel.getCouponId() : orderSaveDto.getCouponId(); if (couponId == null) { logger.error("couponChannelId或者couponId不能为空"); @@ -63,7 +72,6 @@ public class WxOrderController extends BaseController { // 是否砍价 boolean isPress = orderSaveDto.getPress() != null ? orderSaveDto.getPress() : false; - WxCUser user = getUser(); try { WxCoupon coupon = wxCouponService.getById(couponId); @@ -81,6 +89,38 @@ public class WxOrderController extends BaseController { } } + private ResultData couponUserCheck(WxCUser user, WxCouponCVo coupon) { + if (coupon.getCondition() == null) return null; + JSONObject jo = null; + try { + jo = JSONObject.parseObject(coupon.getCondition()); + } catch (Exception e) { + logger.error("购买券条件判断错误:ID=" + coupon.getId() + e.getMessage()); + } + if (jo != null) { + if (jo.getIntValue("type") == EnumCouponConditionType.NEW_MEMBER.getCode()){ + WxCUserBasicInfo cUserBasicInfo = wxCUserBasicInfoService.getById(user.getId()); + if (cUserBasicInfo != null && cUserBasicInfo.getActRecord() > 0) + return new ResultData(ErrorCode.COUPON_ONLY_FOR_NEW_MEMBER); + }else if (jo.getIntValue("type") == EnumCouponConditionType.SCORE_SCOPE.getCode()){ + int max = jo.getIntValue("max"); + int min = jo.getIntValue("min"); + + if (max!=0 && min ==0 && user.getScore() > max) { + return new ResultData(ErrorCode.COUPON_ONLY_FOR_NEW_MEMBER); + } + if (max==0 && min !=0 && user.getScore() < min) { + return new ResultData(ErrorCode.COUPON_ONLY_FOR_NEW_MEMBER); + } + if (max!=0 && min !=0 && (user.getScore() < min || user.getScore() > max)) { + return new ResultData(ErrorCode.COUPON_ONLY_FOR_NEW_MEMBER); + } + } + } + + return null; + } + private ResultData couponChannelCheck(@RequestBody OrderSaveDto orderSaveDto, WxCouponChannel wxCouponChannel) { if (wxCouponChannel == null) { logger.error("couponChannelId convert error, " + orderSaveDto.getCouponChannelId()); diff --git a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java index 6dcbe937d..a3e8f931f 100644 --- a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java +++ b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java @@ -110,6 +110,8 @@ public enum ErrorCode{ COUPON_VALID_DATE_ERR(2035, "券有效期设置错误"), COUPON_STOCK_VALID_DATE_SETTING_ERR(2036, "券库存有效期未修改"), COUPON_STOCK_DATE_NO_CAR(2037, "券库存不支持停车券"), + COUPON_ONLY_FOR_NEW_MEMBER(2038, "您已参加过新会员活动"), + COUPON_SCORE_NOT_IN_RANGE(2038, "您的成长值/等级与要求不符"), PUSH_LIMIT_UP_TO_1DAYLIMIT(2040, "此用户一天内发券到达疲劳度限制"), PUSH_LIMIT_UP_TO_COUPONLIMIT(2041, "此用户发此券到达疲劳度限制"), diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCUserBasicInfo.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCUserBasicInfo.java index 7bcd4b417..57c10b718 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCUserBasicInfo.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCUserBasicInfo.java @@ -101,6 +101,9 @@ public class WxCUserBasicInfo extends BaseEntity { @io.swagger.annotations.ApiModelProperty(value="积分",name="credit") private Integer credit; + @io.swagger.annotations.ApiModelProperty(value="活动记录",name="actRecord") + private Integer actRecord; + @Transient @Excel(name="标签",width = 50,orderNum = "10") private String tagNames; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java index 971213ab9..afd404e97 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java @@ -142,6 +142,10 @@ public class WxCoupon extends BaseEntity { @io.swagger.annotations.ApiModelProperty(value="过期退积分(0:正常,1不退)",name="autoRefund") private Integer creditRefund; + @io.swagger.annotations.ApiModelProperty(value="领取条件",name="condition") + private String condition; + + @Transient private String merchantParams; diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/WxCouponChannelVo.java b/mallinkService/src/main/java/com/iformall/domain/vo/WxCouponChannelVo.java index 681eb130c..2268f36cb 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/WxCouponChannelVo.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/WxCouponChannelVo.java @@ -66,6 +66,9 @@ public class WxCouponChannelVo extends WxCouponChannel implements Serializable { @io.swagger.annotations.ApiModelProperty(value="积分售价(适用于类型10,11)",name="creditPrice") private Integer creditPrice; + @io.swagger.annotations.ApiModelProperty(value="领取条件",name="condition") + private String condition; + @Transient private String salePriceStr; diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumCouponConditionType.java b/mallinkService/src/main/java/com/iformall/enums/EnumCouponConditionType.java new file mode 100644 index 000000000..b460c6b2d --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumCouponConditionType.java @@ -0,0 +1,37 @@ +package com.iformall.enums; + +/** + * Created by Stormeye on 2018/08/09. + */ +public enum EnumCouponConditionType { + + // 0-可投放;1-已作废; + NEW_MEMBER(1, "新会员"), + SCORE_SCOPE(2, "积分值"), + ; + + public static EnumCouponConditionType getEnum(Integer code) { + for (EnumCouponConditionType value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumCouponConditionType(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxCUserBasicInfoMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxCUserBasicInfoMapper.java index ac19428cf..338bab9b7 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxCUserBasicInfoMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxCUserBasicInfoMapper.java @@ -38,5 +38,7 @@ public interface WxCUserBasicInfoMapper extends CommonMapper listAsPage(WxOrder record, Integer pageIndex, Integer pageSize) { return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxOrderMapper.findList(record)); @@ -724,6 +728,20 @@ public class WxOrderServiceImpl implements WxOrderService { logger.error("用户不存在, userId: " + updateOrder.getCUserId()); throw new MallinkException(ErrorCode.USER_IS_EMPTY); } + + // 记录活动 + JSONObject jo = null; + try { + jo = JSONObject.parseObject(coupon.getCondition()); + } catch (Exception e) { + logger.error("购买券条件判断错误:ID=" + coupon.getId() + e.getMessage()); + } + if (jo != null) { + if (jo.getIntValue("type") == EnumCouponConditionType.NEW_MEMBER.getCode()) { + wxCUserBasicInfoMapper.incActRecordById(user.getId()); + } + } + sendInsideOrderSuccessMsg(updateOrder, coupon, user); } diff --git a/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml b/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml index 2c3516f7a..d2888f257 100644 --- a/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml @@ -19,11 +19,12 @@ + `id`,`phone`,`birthdate`,`education`,`sex`,`email`,`address`,`poins`,`tag_id`, - `create_date`,`update_date`,`tenant_id`,`name`,`nick_name`,`credit`,`active_time` + `create_date`,`update_date`,`tenant_id`,`name`,`nick_name`,`credit`,`active_time`,`act_record` ,(select level from wx_level_config where poins >= points and tenant_id=#{tenantId} order by points desc limit 1 ) level @@ -82,6 +83,10 @@ and `update_date` = #{updateDate} + + and `act_record` = #{actRecord} + + and `name` like concat('%', #{name},'%') @@ -112,7 +117,7 @@ c.`id`,c.`phone`,cb.`birthdate`,cb.`education`,cb.`sex`,cb.`email`,cb.`address`,cb.`poins`,cb.`tag_id`, - cb.`create_date`,cb.`update_date`,c.`tenant_id`,cb.`name`,cb.level,cb.nick_name + cb.`create_date`,cb.`update_date`,c.`tenant_id`,cb.`name`,cb.level,cb.nick_name,`cb.act_record` @@ -264,7 +269,7 @@ cu.`id`,cu.`phone`,cu.`birthdate`,cu.`education`,cu.`sex`,cu.`email`,cu.`address`,cu.`poins`,cu.`tag_id`, cu.`create_date`,cu.`update_date`,cu.`tenant_id`,cu.`name`,cu.`level`,cu.`nick_name`, - cut.`tags`,cu.`credit`,cu.`active_time` + cut.`tags`,cu.`credit`,cu.`active_time`,cu.`act_record` @@ -318,6 +323,10 @@ and cu.`update_date` = #{updateDate} + + and cu.`act_record` = #{actRecord} + + and `name` like concat('%', #{name},'%') @@ -450,5 +459,10 @@ and cubi.tenant_id =#{tenantId} + + + UPDATE wx_c_user_basic_info set act_record = act_record +1 where id = #{id} + + diff --git a/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml index 341752d80..b05d0417b 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml @@ -123,7 +123,7 @@ , c.remain_inventory,c.inventory,c.cover_img,c.title,c.sub_title,c.sale_price, - c.use_price,c.price,c.unit,c.use_limit_quantity,c.send_type,c.support_transfer,c.press_limit_num,c.auto_refund, + c.use_price,c.price,c.unit,c.use_limit_quantity,c.send_type,c.support_transfer,c.press_limit_num,c.auto_refund,c.condition, c.valid_type,c.valid_start_date,c.valid_end_date,c.valid_days,c.credit_price @@ -140,6 +140,7 @@ + @@ -159,6 +160,8 @@ + + @@ -244,6 +247,7 @@ + + @@ -91,7 +92,7 @@ `id`,`tenant_id`,`type`,`cover_img`,`cover_picture`,`detail_picture`,`title`,`sub_title`,`sale_price`,`use_price`,`use_limit_quantity`,`send_type`, `valid_type`,`valid_start_date`,`valid_end_date`,`valid_days`,`detail`,`price`,`unit`,`remain_inventory`,`inventory`, `remark`,`status`,`create_date`,`update_date`,`business`,`sub_business`,`support_transfer`,`subsidy_num`,`subsidy_type`, - `press_limit_num`, `press_limit_hours`, `auto_refund`,`credit_price`,`credit_refund` + `press_limit_num`, `press_limit_hours`, `auto_refund`,`credit_price`,`credit_refund`,`condition` @@ -466,7 +467,7 @@ - +