| @@ -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`; | |||
| @@ -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()); | |||
| @@ -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, "此用户发此券到达疲劳度限制"), | |||
| @@ -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; | |||
| @@ -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; | |||
| @@ -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; | |||
| @@ -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; | |||
| } | |||
| } | |||
| @@ -38,5 +38,7 @@ public interface WxCUserBasicInfoMapper extends CommonMapper<WxCUserBasicInfo, S | |||
| long findGrowUserCount(WxCUserBasicInfoDto dto); | |||
| long findImportUserCount(WxCUserBasicInfoDto dto); | |||
| void incActRecordById(Long id); | |||
| } | |||
| @@ -1,5 +1,6 @@ | |||
| package com.iformall.service.impl; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| @@ -114,6 +115,9 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Autowired | |||
| private MqBaseProducer mqBaseProducer; | |||
| @Autowired | |||
| private WxCUserBasicInfoMapper wxCUserBasicInfoMapper; | |||
| @Override | |||
| public PageInfo<WxOrder> 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); | |||
| } | |||
| @@ -19,11 +19,12 @@ | |||
| <result column="nick_name" jdbcType="VARCHAR" property="nickName"/> | |||
| <result column="credit" jdbcType="INTEGER" property="credit"/> | |||
| <result column="active_time" jdbcType="TIMESTAMP" property="activeTime"/> | |||
| <result column="act_record" jdbcType="INTEGER" property="actRecord"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `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 | |||
| </sql> | |||
| @@ -82,6 +83,10 @@ | |||
| and `update_date` = #{updateDate} | |||
| </if> | |||
| <if test=" null != actRecord "> | |||
| and `act_record` = #{actRecord} | |||
| </if> | |||
| <if test=" null != name "> | |||
| and `name` like concat('%', #{name},'%') | |||
| </if> | |||
| @@ -112,7 +117,7 @@ | |||
| <sql id="allUserColumns"> | |||
| 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` | |||
| </sql> | |||
| <update id="updateScore" parameterType="com.iformall.domain.po.WxCUserBasicInfo"> | |||
| @@ -264,7 +269,7 @@ | |||
| <sql id="allVoColumns"> | |||
| 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` | |||
| </sql> | |||
| <sql id="dynamicVoWhereConditions"> | |||
| @@ -318,6 +323,10 @@ | |||
| and cu.`update_date` = #{updateDate} | |||
| </if> | |||
| <if test=" null != actRecord "> | |||
| and cu.`act_record` = #{actRecord} | |||
| </if> | |||
| <if test=" null != name "> | |||
| and `name` like concat('%', #{name},'%') | |||
| </if> | |||
| @@ -450,5 +459,10 @@ | |||
| and cubi.tenant_id =#{tenantId} | |||
| </if> | |||
| </select> | |||
| <update id="incActRecordById" parameterType="java.lang.Long"> | |||
| UPDATE wx_c_user_basic_info set act_record = act_record +1 where id = #{id} | |||
| </update> | |||
| </mapper> | |||
| @@ -123,7 +123,7 @@ | |||
| <sql id="CouponChannelVoColumns"> | |||
| <include refid="allColumns" />, | |||
| 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 | |||
| </sql> | |||
| @@ -140,6 +140,7 @@ | |||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | |||
| <result column="sub_target_id" jdbcType="BIGINT" property="subTargetId" /> | |||
| <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/> | |||
| <result column="inventory" jdbcType="INTEGER" property="inventory"/> | |||
| <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/> | |||
| @@ -159,6 +160,8 @@ | |||
| <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/> | |||
| <result column="valid_days" jdbcType="INTEGER" property="validDays"/> | |||
| <result column="qr_code" property="qrCode"/> | |||
| <result column="condition" jdbcType="VARCHAR" property="condition" /> | |||
| <collection column="{productId=coupon_id}" property="merchantVoList" | |||
| ofType="com.iformall.domain.vo.WxMerchantVo" | |||
| @@ -202,7 +205,7 @@ | |||
| c.tenant_id,c.type,c.cover_img,c.cover_picture,c.detail_picture,c.title,c.sub_title,c.sale_price,c.use_price, | |||
| c.use_limit_quantity,c.send_type,c.valid_type,c.valid_start_date,c.valid_end_date, | |||
| c.valid_days,c.detail,c.price,c.unit,c.remain_inventory,c.inventory,c.remark,c.status, | |||
| c.create_date,c.update_date,c.business,c.sub_business,c.support_transfer,c.press_limit_num, c.auto_refund,c.credit_price, | |||
| c.create_date,c.update_date,c.business,c.sub_business,c.support_transfer,c.press_limit_num, c.auto_refund,c.credit_price,c.condition, | |||
| cc.qr_code | |||
| </sql> | |||
| @@ -244,6 +247,7 @@ | |||
| <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/> | |||
| <result column="auto_refund" jdbcType="INTEGER" property="autoRefund"/> | |||
| <result column="qr_code" property="qrCode"/> | |||
| <result column="condition" jdbcType="VARCHAR" property="condition" /> | |||
| <collection column="{productId=coupon_id}" property="merchantVoList" | |||
| ofType="com.iformall.domain.vo.WxMerchantVo" | |||
| @@ -38,6 +38,7 @@ | |||
| <result column="credit_price" jdbcType="INTEGER" property="creditPrice"/> | |||
| <result column="credit_refund" jdbcType="INTEGER" property="creditRefund"/> | |||
| <result column="is_del" property="isDel"/> | |||
| <result column="condition" jdbcType="VARCHAR" property="condition"/> | |||
| </resultMap> | |||
| <resultMap id="statisMap" type="com.iformall.domain.vo.WxCouponStatisVo"> | |||
| @@ -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` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -466,7 +467,7 @@ | |||
| <result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/> | |||
| <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/> | |||
| <result column="press_limit_hours" jdbcType="INTEGER" property="pressLimitHours"/> | |||
| <result column="condition" jdbcType="VARCHAR" property="condition"/> | |||
| <collection column="{productId=id}" property="merchantVoList" | |||
| ofType="com.iformall.domain.vo.WxMerchantVo" | |||
| @@ -792,7 +793,7 @@ | |||
| wc.tenant_id,wc.`type`,wc.`cover_img`,wc.`cover_picture`,wc.`detail_picture`,wc.`title`,wc.`sub_title`,wc.`sale_price`,wc.`use_price`,wc.`use_limit_quantity`,wc.`send_type`, | |||
| wc.`valid_type`,wc.`valid_start_date`,wc.`valid_end_date`,wc.`valid_days`,wc.`detail`,wc.`price`,wc.`unit`,wc.`remain_inventory`,wc.`inventory`, | |||
| wc.`remark`,wc.`status`,wc.`create_date`,wc.`update_date`,wc.`business`,wc.`sub_business`,wc.`support_transfer`,wc.`subsidy_num`,wc.`subsidy_type`, | |||
| wc.`press_limit_num`, wc.`press_limit_hours`, wc.`auto_refund`,wc.`credit_price`,wc.`credit_refund` | |||
| wc.`press_limit_num`, wc.`press_limit_hours`, wc.`auto_refund`,wc.`credit_price`,wc.`credit_refund`,wx.`condition` | |||
| ,wc.title as couponName,wc.`cover_img` as couponPic,wc.`cover_picture` as couponPicture,wc.`detail_picture` as detailPicture,wc.id as couponId from wx_coupon_channel ct left join | |||
| wx_coupon wc on wc.id = ct.coupon_id | |||
| where ct.`sub_target_id` = #{id} | |||