Commit c79c9281 authored by libin's avatar libin

优惠券

parent 7cf9d0ac
...@@ -117,6 +117,11 @@ public interface UserFeign { ...@@ -117,6 +117,11 @@ public interface UserFeign {
@GetMapping("/api/app/imi/{imiId}") @GetMapping("/api/app/imi/{imiId}")
public ImiVo findUserInfoByImiId(@PathVariable(value = "imiId") Integer imiId); ImiVo findUserInfoByImiId(@PathVariable(value = "imiId") Integer imiId);
@GetMapping("/app/user/findusersByIds")
Map<Integer,AppUserLogin> findAppUsersByUserIds(@RequestParam(value = "userIds") List<Integer> userIds);
@GetMapping("/app/user/finduserIdsByphones")
Map<String, Integer> findAppusersByUserNames(@RequestParam(value = "phones") List<String> phones);
} }
...@@ -18,6 +18,8 @@ import lombok.extern.slf4j.Slf4j; ...@@ -18,6 +18,8 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.ws.rs.GET;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -170,6 +172,13 @@ public class AppUserController extends CommonBaseController { ...@@ -170,6 +172,13 @@ public class AppUserController extends CommonBaseController {
return appUserLoginBiz.getUserByUsername(username); return appUserLoginBiz.getUserByUsername(username);
} }
@GetMapping("/findusersByIds")
public Map<Integer,AppUserLogin> findAppUsersByUserIds(@RequestParam(value = "userIds") List<Integer> userIds){
return appUserLoginBiz.findUserIdAndUserLoginMapByMemberIds(userIds);
}
@GetMapping("/finduserIdsByphones")
Map<String, Integer> findAppusersByUserNames(@RequestParam(value = "phones") List<String> phones){
return appUserLoginBiz.findPhoneAndUserIdMapByPhones(phones);
}
} }
package com.xxfc.platform.activity.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/7/23 15:00
*/
@Data
public class CouponDTO {
@ApiModelProperty("主键id")
private Integer id;
@ApiModelProperty(value = "优惠券标题(有图片则显示图片):无门槛50元优惠券 | 单品最高减2000元")
private String title;
@ApiModelProperty(value = "副标题")
private String subtitle;
@ApiModelProperty(value = "图片")
private String icon;
@ApiModelProperty(value = "可用于:10店铺优惠券 11新人店铺券 20商品优惠券 30类目优惠券 60平台优惠券 61新人平台券")
private Integer used;
@ApiModelProperty(value = "0-全平台;1-租车;2-旅游;3-营地")
private Integer channel;
@ApiModelProperty(value = "0-普通用户;1-会员用户")
private Integer userType;
@ApiModelProperty(value = "1满减券 2叠加满减券 3无门槛券(需要限制大小)")
private Integer type;
@ApiModelProperty(value = "1可用于特价商品 2不能 默认不能(商品优惠卷除外)")
private Integer withSpecial;
@ApiModelProperty(value = "店铺或商品流水号")
private String withSn;
@ApiModelProperty(value = "满多少金额")
private BigDecimal withAmount;
@ApiModelProperty(value = "用券抵扣金额")
private BigDecimal usedAmount;
@ApiModelProperty(value = "配额:发券数量")
private Integer quota;
@ApiModelProperty(value = "每人限领次数")
private Integer limitCollar;
@ApiModelProperty(value = "已领取的优惠券数量")
private Integer takeCount;
@ApiModelProperty(value = "已使用的优惠券数量")
private Integer usedCount;
@ApiModelProperty(value = "发放开始时间")
private Long startTime;
@ApiModelProperty(value = "发放结束时间")
private Long endTime;
@ApiModelProperty(value = "时效:1绝对时效(领取后XXX-XXX时间段有效) 2相对时效(领取后N天有效)")
private Integer validType;
@ApiModelProperty(value = "使用开始时间")
private Long validStartTime;
@ApiModelProperty(value = "使用结束时间")
private Long validEndTime;
@ApiModelProperty(value = "自领取之日起有效天数")
private Integer validDays;
@ApiModelProperty(value = "跳转链接")
private String url;
}
...@@ -14,5 +14,9 @@ public class CouponFindDTO extends PageParam { ...@@ -14,5 +14,9 @@ public class CouponFindDTO extends PageParam {
private String title; private String title;
private Integer channel;
private Integer type; private Integer type;
private Integer status;
} }
package com.xxfc.platform.activity.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/7/23 17:06
*/
@Data
public class UserCouponDTO {
private Integer id;
@ApiModelProperty(value = "用户id")
private Integer userId;
@ApiModelProperty(value = "标题")
private String title;
@ApiModelProperty(value = "抵扣金额")
private BigDecimal usedAmount;
@ApiModelProperty(value = "0-未使用;1-已使用")
private Integer isUse;
@ApiModelProperty(value = "领卷时间", hidden = true )
private Long crtTime;
@ApiModelProperty(value = "到期时间", hidden = true )
private Long expireTime;
@ApiModelProperty(value = "使用时间")
private Long useTime;
}
package com.xxfc.platform.activity.dto;
import com.github.wxiaoqi.security.common.vo.PageParam;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/7/23 16:26
*/
@Data
public class UserCouponFindDTO extends PageParam {
private String phone;
private String title;
private BigDecimal usedAmount;
private Integer status;
private Integer userId;
}
package com.xxfc.platform.activity.dto;
import lombok.Data;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/7/23 18:02
*/
@Data
public class UserCouponSendDTO {
private String phone;
private Integer couponId;
private Integer couponNum;
}
package com.xxfc.platform.activity.vo; package com.xxfc.platform.activity.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal;
/** /**
* @author libin * @author libin
* @version 1.0 * @version 1.0
...@@ -11,4 +14,44 @@ import lombok.Data; ...@@ -11,4 +14,44 @@ import lombok.Data;
@Data @Data
public class CouponPagVo { public class CouponPagVo {
@ApiModelProperty("主键id")
private Integer id;
@ApiModelProperty(value = "优惠券标题(有图片则显示图片):无门槛50元优惠券 | 单品最高减2000元")
private String title;
@ApiModelProperty(value = "图片")
private String icon;
@ApiModelProperty(value = "0-全平台;1-租车;2-旅游;3-营地")
private Integer channel;
@ApiModelProperty(value = "1满减券 2叠加满减券 3无门槛券(需要限制大小)")
private Integer type;
@ApiModelProperty(value = "用券抵扣金额")
private BigDecimal usedAmount;
@ApiModelProperty(value = "配额:发券数量")
private Integer quota;
@ApiModelProperty(value = "已领取的优惠券数量")
private Integer takeCount;
@ApiModelProperty(value = "已使用的优惠券数量")
private Integer usedCount;
@ApiModelProperty(value = "1生效 2失效 3已结束")
private Integer status;
@ApiModelProperty(value = "创建时间", hidden = true)
private Long crtTime;
} }
package com.xxfc.platform.activity.vo;
import lombok.Data;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/7/23 18:11
*/
@Data
public class CouponTitleVo {
private Integer id;
private String title;
}
package com.xxfc.platform.activity.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/7/23 15:00
*/
@Data
public class CouponVo {
@ApiModelProperty("主键id")
private Integer id;
@ApiModelProperty(value = "优惠券标题(有图片则显示图片):无门槛50元优惠券 | 单品最高减2000元")
private String title;
@ApiModelProperty(value = "副标题")
private String subtitle;
@ApiModelProperty(value = "图片")
private String icon;
@ApiModelProperty(value = "可用于:10店铺优惠券 11新人店铺券 20商品优惠券 30类目优惠券 60平台优惠券 61新人平台券")
private Integer used;
@ApiModelProperty(value = "0-全平台;1-租车;2-旅游;3-营地")
private Integer channel;
@ApiModelProperty(value = "0-普通用户;1-会员用户")
private Integer userType;
@ApiModelProperty(value = "1满减券 2叠加满减券 3无门槛券(需要限制大小)")
private Integer type;
@ApiModelProperty(value = "1可用于特价商品 2不能 默认不能(商品优惠卷除外)")
private Integer withSpecial;
@ApiModelProperty(value = "店铺或商品流水号")
private String withSn;
@ApiModelProperty(value = "满多少金额")
private BigDecimal withAmount;
@ApiModelProperty(value = "用券抵扣金额")
private BigDecimal usedAmount;
@ApiModelProperty(value = "配额:发券数量")
private Integer quota;
@ApiModelProperty(value = "每人限领次数")
private Integer limitCollar;
@ApiModelProperty(value = "已领取的优惠券数量")
private Integer takeCount;
@ApiModelProperty(value = "已使用的优惠券数量")
private Integer usedCount;
@ApiModelProperty(value = "发放开始时间")
private Long startTime;
@ApiModelProperty(value = "发放结束时间")
private Long endTime;
@ApiModelProperty(value = "时效:1绝对时效(领取后XXX-XXX时间段有效) 2相对时效(领取后N天有效)")
private Integer validType;
@ApiModelProperty(value = "使用开始时间")
private Long validStartTime;
@ApiModelProperty(value = "使用结束时间")
private Long validEndTime;
@ApiModelProperty(value = "自领取之日起有效天数")
private Integer validDays;
@ApiModelProperty(value = "跳转链接")
private String url;
}
package com.xxfc.platform.activity.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/7/23 16:29
*/
@Data
public class UserCouponPageVo {
private Integer id;
@ApiModelProperty(value = "手机号")
private String phone;
@ApiModelProperty(value = "标题")
private String title;
@ApiModelProperty(value = "抵扣金额")
private BigDecimal usedAmount;
@ApiModelProperty(value = "0-未使用;1-已使用")
private Integer isUse;
@ApiModelProperty(value = "领卷时间", hidden = true )
private Long crtTime;
@ApiModelProperty(value = "到期时间", hidden = true )
private Long expireTime;
@ApiModelProperty(value = "使用时间")
private Long useTime;
}
package com.xxfc.platform.activity.biz; package com.xxfc.platform.activity.biz;
import com.github.wxiaoqi.security.admin.feign.dto.UserDTO;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.activity.constant.CouponUsed; import com.xxfc.platform.activity.constant.CouponUsed;
import com.xxfc.platform.activity.dto.CouponDTO;
import com.xxfc.platform.activity.dto.CouponFindDTO;
import com.xxfc.platform.activity.entity.Coupon; import com.xxfc.platform.activity.entity.Coupon;
import com.xxfc.platform.activity.vo.CouponPagVo;
import com.xxfc.platform.activity.vo.CouponTitleVo;
import com.xxfc.platform.activity.vo.CouponVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.xxfc.platform.activity.mapper.CouponMapper; import com.xxfc.platform.activity.mapper.CouponMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
/** /**
* 优惠券表 * 优惠券表
...@@ -31,4 +44,82 @@ public class CouponBiz extends BaseBiz<CouponMapper, Coupon> { ...@@ -31,4 +44,82 @@ public class CouponBiz extends BaseBiz<CouponMapper, Coupon> {
} }
return null; return null;
} }
public PageDataVO<CouponPagVo> listCouponWithPage(CouponFindDTO couponFindDTO) {
PageDataVO<CouponPagVo> couponPagVo = new PageDataVO<>();
Example example = new Example(Coupon.class);
Example.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(couponFindDTO.getTitle())){
criteria.andLike("title",couponFindDTO.getTitle());
}
if (Objects.nonNull(couponFindDTO.getChannel())){
criteria.andEqualTo("channel",couponFindDTO.getChannel());
}
if (Objects.nonNull(couponFindDTO.getType())){
criteria.andEqualTo("type",couponFindDTO.getType());
}
if (Objects.nonNull(couponFindDTO.getStatus())){
criteria.andEqualTo("status",couponFindDTO.getStatus());
}
criteria.andEqualTo("isDel",0);
example.setOrderByClause("crt_time DESC");
PageDataVO<Coupon> couponPage = PageDataVO.pageInfo(couponFindDTO.getPage(), couponFindDTO.getLimit(), () -> mapper.selectByExample(example));
List<Coupon> data = couponPage.getData();
if (CollectionUtils.isEmpty(data)){
return couponPagVo;
}
List<CouponPagVo> couponPagVos = new ArrayList<>();
CouponPagVo coupon ;
for (Coupon coup : data) {
coupon = new CouponPagVo();
BeanUtils.copyProperties(coupon,coup);
couponPagVos.add(coupon);
}
couponPagVo.setPageNum(couponPage.getPageNum());
couponPagVo.setPageSize(couponPage.getTotalPage());
couponPagVo.setTotalPage(couponPage.getTotalPage());
couponPagVo.setTotalCount(couponPage.getTotalCount());
couponPagVo.setData(couponPagVos);
return couponPagVo;
}
public CouponVo findCouponById(Integer id) {
CouponVo couponVo= new CouponVo();
Coupon coupon = mapper.selectByPrimaryKey(id);
BeanUtils.copyProperties(coupon,couponVo);
return couponVo;
}
public int addCoupon(CouponDTO couponDTO, UserDTO userDTO) {
Coupon coupon = new Coupon();
BeanUtils.copyProperties(couponDTO,coupon);
if (Objects.nonNull(couponDTO.getId())){
coupon.setUpdTime(Instant.now().toEpochMilli());
coupon.setUpdUser(userDTO.getId());
coupon.setUpdName(userDTO.getUsername());
return mapper.updateByPrimaryKeySelective(coupon);
}else {
coupon.setCrtTime(Instant.now().toEpochMilli());
coupon.setCrtUser(userDTO.getId());
coupon.setCrtName(userDTO.getUsername());
return mapper.insertSelective(coupon);
}
}
public int updateCouponDelStateById(Integer id,UserDTO userDTO) {
Coupon coupon = new Coupon();
coupon.setId(id);
coupon.setUpdName(userDTO.getUsername());
coupon.setUpdUser(userDTO.getId());
coupon.setUpdTime(Instant.now().toEpochMilli());
coupon.setIsDel(1);
return mapper.updateByPrimaryKeySelective(coupon);
}
public List<CouponTitleVo> getCouponTitleList() {
return mapper.selectTitles();
}
} }
\ No newline at end of file
package com.xxfc.platform.activity.biz; package com.xxfc.platform.activity.biz;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.admin.entity.AppUserLogin;
import com.github.wxiaoqi.security.admin.feign.UserFeign;
import com.github.wxiaoqi.security.admin.vo.AppUserGroups;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.process.ResultCode; import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.util.process.SystemConfig; import com.github.wxiaoqi.security.common.util.process.SystemConfig;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.activity.constant.CouponUsed; import com.xxfc.platform.activity.constant.CouponUsed;
import com.xxfc.platform.activity.dto.UserCouponDTO;
import com.xxfc.platform.activity.dto.UserCouponFindDTO;
import com.xxfc.platform.activity.dto.UserCouponSendDTO;
import com.xxfc.platform.activity.entity.Coupon; import com.xxfc.platform.activity.entity.Coupon;
import com.xxfc.platform.activity.entity.UserCoupon; import com.xxfc.platform.activity.entity.UserCoupon;
import com.xxfc.platform.activity.vo.CouponVo;
import com.xxfc.platform.activity.vo.UserCouponPageVo;
import com.xxfc.platform.activity.vo.UserCouponVo; import com.xxfc.platform.activity.vo.UserCouponVo;
import com.xxfc.platform.universal.weixin.util.Snowflake; import com.xxfc.platform.universal.weixin.util.Snowflake;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.assertj.core.util.Arrays; import org.assertj.core.util.Arrays;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.xxfc.platform.activity.mapper.UserCouponMapper; import com.xxfc.platform.activity.mapper.UserCouponMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import org.springframework.util.CollectionUtils;
import sun.nio.cs.US_ASCII;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.time.Instant;
import java.util.Comparator; import java.util.*;
import java.util.List; import java.util.stream.Collectors;
/** /**
* 我的优惠卷 * 我的优惠卷
...@@ -38,58 +50,61 @@ public class UserCouponBiz extends BaseBiz<UserCouponMapper, UserCoupon> { ...@@ -38,58 +50,61 @@ public class UserCouponBiz extends BaseBiz<UserCouponMapper, UserCoupon> {
@Autowired @Autowired
private CouponBiz couponBiz; private CouponBiz couponBiz;
private static final Long DAY=86400000L; @Autowired
private UserFeign userFeign;
private static final Long DAY = 86400000L;
//自动发送优惠卷 //自动发送优惠卷
public String authledCoupon(Integer userId){ public String authledCoupon(Integer userId) {
if (userId==null||userId==0){ if (userId == null || userId == 0) {
log.error("----参数不能为空"); log.error("----参数不能为空");
return null; return null;
} }
Coupon coupon=couponBiz.getCouponByUsed(CouponUsed.ALLNEW.getCode()); Coupon coupon = couponBiz.getCouponByUsed(CouponUsed.ALLNEW.getCode());
if (coupon==null){ if (coupon == null) {
log.error(userId+"----无可领取优惠卷"); log.error(userId + "----无可领取优惠卷");
return null; return null;
} }
Integer couponId=coupon.getId(); Integer couponId = coupon.getId();
boolean falg=checkUserLed(userId,couponId); boolean falg = checkUserLed(userId, couponId);
if(falg){ if (falg) {
log.error(userId+"----已领优惠卷"); log.error(userId + "----已领优惠卷");
return null; return null;
} }
return led(coupon,userId); return led(coupon, userId);
} }
//用户领劵 //用户领劵
public String userLedCoupon(Integer userId,Integer couponId){ public String userLedCoupon(Integer userId, Integer couponId) {
Coupon coupon=couponBiz.selectById(couponId); Coupon coupon = couponBiz.selectById(couponId);
if (coupon==null||coupon.getIsDel()!=0||coupon.getStatus()!=1){ if (coupon == null || coupon.getIsDel() != 0 || coupon.getStatus() != 1) {
log.error(userId+"----无可领取优惠卷"); log.error(userId + "----无可领取优惠卷");
return null; return null;
} }
boolean falg=checkUserLed(userId,couponId); boolean falg = checkUserLed(userId, couponId);
if(falg){ if (falg) {
log.error(userId+"----已领优惠卷"); log.error(userId + "----已领优惠卷");
return null; return null;
} }
return led(coupon,userId); return led(coupon, userId);
} }
//领取动作 //领取动作
public String led( Coupon coupon,Integer userId ){ public String led(Coupon coupon, Integer userId) {
int type=coupon.getValidType(); int type = coupon.getValidType();
Integer couponId=coupon.getId(); Integer couponId = coupon.getId();
Long expireTime=System.currentTimeMillis(); Long expireTime = System.currentTimeMillis();
Long startTime=0L; Long startTime = 0L;
if(type==1){ if (type == 1) {
startTime=coupon.getStartTime(); startTime = coupon.getStartTime();
expireTime=coupon.getValidEndTime(); expireTime = coupon.getValidEndTime();
}else { } else {
startTime=expireTime; startTime = expireTime;
expireTime+=DAY*coupon.getValidDays(); expireTime += DAY * coupon.getValidDays();
} }
String ticker_no=Snowflake.build()+""; String ticker_no = Snowflake.build() + "";
UserCoupon userCoupon=new UserCoupon(); UserCoupon userCoupon = new UserCoupon();
userCoupon.setUserId(userId); userCoupon.setUserId(userId);
userCoupon.setCouponId(couponId); userCoupon.setCouponId(couponId);
userCoupon.setTickerNo(ticker_no); userCoupon.setTickerNo(ticker_no);
...@@ -100,34 +115,34 @@ public class UserCouponBiz extends BaseBiz<UserCouponMapper, UserCoupon> { ...@@ -100,34 +115,34 @@ public class UserCouponBiz extends BaseBiz<UserCouponMapper, UserCoupon> {
} }
//检查用户是否领卷 //检查用户是否领卷
public boolean checkUserLed(Integer userId,Integer id){ public boolean checkUserLed(Integer userId, Integer id) {
Example example=new Example(UserCoupon.class); Example example = new Example(UserCoupon.class);
example.createCriteria().andEqualTo("userId",userId).andEqualTo("couponId",id); example.createCriteria().andEqualTo("userId", userId).andEqualTo("couponId", id);
List<UserCoupon> list=selectByExample(example); List<UserCoupon> list = selectByExample(example);
if(list.size()>0){ if (list.size() > 0) {
log.error(userId+"----已领优惠卷"); log.error(userId + "----已领优惠卷");
return true; return true;
} }
return false; return false;
} }
//获取我的优惠卷 //获取我的优惠卷
public ObjectRestResponse getCouponList(Integer userId,int type,Integer channel,BigDecimal amout){ public ObjectRestResponse getCouponList(Integer userId, int type, Integer channel, BigDecimal amout) {
if (userId==null||userId==0){ if (userId == null || userId == 0) {
log.error("----参数不能为空"); log.error("----参数不能为空");
return ObjectRestResponse.createFailedResult(ResultCode.NULL_CODE,"参数不能为空"); return ObjectRestResponse.createFailedResult(ResultCode.NULL_CODE, "参数不能为空");
} }
Long time=System.currentTimeMillis(); Long time = System.currentTimeMillis();
List<UserCouponVo> list=mapper.getUserCouponsByType(userId,type,time,channel); List<UserCouponVo> list = mapper.getUserCouponsByType(userId, type, time, channel);
if(amout.compareTo(new BigDecimal("0.00"))>0&&list.size()>0){ if (amout.compareTo(new BigDecimal("0.00")) > 0 && list.size() > 0) {
for (UserCouponVo couponVo:list){ for (UserCouponVo couponVo : list) {
Integer status=2; Integer status = 2;
if(couponVo.getType()==1){ if (couponVo.getType() == 1) {
if (amout.compareTo(couponVo.getWithAmount())>=0){ if (amout.compareTo(couponVo.getWithAmount()) >= 0) {
status=1; status = 1;
} }
}else if (couponVo.getType()==3){ } else if (couponVo.getType() == 3) {
status=1; status = 1;
} }
couponVo.setStatus(status); couponVo.setStatus(status);
...@@ -140,8 +155,8 @@ public class UserCouponBiz extends BaseBiz<UserCouponMapper, UserCoupon> { ...@@ -140,8 +155,8 @@ public class UserCouponBiz extends BaseBiz<UserCouponMapper, UserCoupon> {
//获取单个优惠卷 //获取单个优惠卷
public UserCouponVo getUserCoupon(String tickerNo){ public UserCouponVo getUserCoupon(String tickerNo) {
if (StringUtils.isBlank(tickerNo)){ if (StringUtils.isBlank(tickerNo)) {
log.error("----参数不能为空"); log.error("----参数不能为空");
return null; return null;
} }
...@@ -149,39 +164,39 @@ public class UserCouponBiz extends BaseBiz<UserCouponMapper, UserCoupon> { ...@@ -149,39 +164,39 @@ public class UserCouponBiz extends BaseBiz<UserCouponMapper, UserCoupon> {
} }
//支付后更新优惠卷状态:type.1- //支付后更新优惠卷状态:type.1-
public BigDecimal useTickerNo(Integer userId, List<String> tickerNos, String orderNo,Integer channel,BigDecimal amout,Integer type){ public BigDecimal useTickerNo(Integer userId, List<String> tickerNos, String orderNo, Integer channel, BigDecimal amout, Integer type) {
BigDecimal couponAmout=new BigDecimal("0.00"); BigDecimal couponAmout = new BigDecimal("0.00");
if(couponAmout.compareTo(amout) >= 0) { if (couponAmout.compareTo(amout) >= 0) {
return BigDecimal.ZERO; return BigDecimal.ZERO;
} }
if (userId==null||userId==0||tickerNos==null||tickerNos.size()==0){ if (userId == null || userId == 0 || tickerNos == null || tickerNos.size() == 0) {
log.error("----参数不能为空"); log.error("----参数不能为空");
return couponAmout; return couponAmout;
} }
Example example=new Example(UserCoupon.class); Example example = new Example(UserCoupon.class);
example.createCriteria().andIn("tickerNo", tickerNos).andEqualTo("isDel",0); example.createCriteria().andIn("tickerNo", tickerNos).andEqualTo("isDel", 0);
List<UserCoupon> list=selectByExample(example); List<UserCoupon> list = selectByExample(example);
if(list.size()==0){ if (list.size() == 0) {
log.error(userId+"----没有可用优惠卷--"); log.error(userId + "----没有可用优惠卷--");
return couponAmout; return couponAmout;
} }
for (UserCoupon userCoupon:list) { for (UserCoupon userCoupon : list) {
if(userCoupon!=null&&userCoupon.getIsUse()==1){ if (userCoupon != null && userCoupon.getIsUse() == 1) {
log.error(userId+"----该优惠卷已使用--tickerNo=="); log.error(userId + "----该优惠卷已使用--tickerNo==");
continue; continue;
} }
if (type==1){ if (type == 1) {
userCoupon.setIsUse(1); userCoupon.setIsUse(1);
userCoupon.setOrderNo(orderNo); userCoupon.setOrderNo(orderNo);
userCoupon.setUseTime(System.currentTimeMillis()); userCoupon.setUseTime(System.currentTimeMillis());
updateSelectiveById(userCoupon); updateSelectiveById(userCoupon);
} }
couponAmout=couponAmout.add(getCouponAmout(userCoupon.getCouponId(),channel,amout)); couponAmout = couponAmout.add(getCouponAmout(userCoupon.getCouponId(), channel, amout));
} }
return couponAmout; return couponAmout;
} }
public BigDecimal getCouponAmout(Integer couponId,Integer channel,BigDecimal amout) { public BigDecimal getCouponAmout(Integer couponId, Integer channel, BigDecimal amout) {
BigDecimal couponAmout = new BigDecimal("0.00"); BigDecimal couponAmout = new BigDecimal("0.00");
Coupon coupon = couponBiz.selectById(couponId); Coupon coupon = couponBiz.selectById(couponId);
if (coupon != null && coupon.getChannel() == channel) { if (coupon != null && coupon.getChannel() == channel) {
...@@ -192,9 +207,9 @@ public class UserCouponBiz extends BaseBiz<UserCouponMapper, UserCoupon> { ...@@ -192,9 +207,9 @@ public class UserCouponBiz extends BaseBiz<UserCouponMapper, UserCoupon> {
if (type == 3 || (type == 1 && (amout.compareTo(coupon.getWithAmount()) >= 0))) { if (type == 3 || (type == 1 && (amout.compareTo(coupon.getWithAmount()) >= 0))) {
//couponAmout = amout.subtract(useAmout); //couponAmout = amout.subtract(useAmout);
if (amout.compareTo(useAmout) > 0) { if (amout.compareTo(useAmout) > 0) {
couponAmout= useAmout; couponAmout = useAmout;
}else { } else {
couponAmout= amout; couponAmout = amout;
} }
} }
} }
...@@ -203,21 +218,21 @@ public class UserCouponBiz extends BaseBiz<UserCouponMapper, UserCoupon> { ...@@ -203,21 +218,21 @@ public class UserCouponBiz extends BaseBiz<UserCouponMapper, UserCoupon> {
} }
//取消使用优惠卷 //取消使用优惠卷
public void cancelTickerNo(String TickerNo){ public void cancelTickerNo(String TickerNo) {
if (StringUtils.isBlank(TickerNo)){ if (StringUtils.isBlank(TickerNo)) {
log.error("----参数不能为空"); log.error("----参数不能为空");
return; return;
} }
Example example=new Example(UserCoupon.class); Example example = new Example(UserCoupon.class);
example.createCriteria().andEqualTo("tickerNo",TickerNo).andEqualTo("isDel",0); example.createCriteria().andEqualTo("tickerNo", TickerNo).andEqualTo("isDel", 0);
List<UserCoupon> list=selectByExample(example); List<UserCoupon> list = selectByExample(example);
if(list.size()==0){ if (list.size() == 0) {
log.error(TickerNo+"----优惠卷不存在"); log.error(TickerNo + "----优惠卷不存在");
return; return;
} }
UserCoupon userCoupon=list.get(0); UserCoupon userCoupon = list.get(0);
if (userCoupon!=null&&userCoupon.getIsUse()!=1){ if (userCoupon != null && userCoupon.getIsUse() != 1) {
log.error(TickerNo+"----没有领优惠卷"); log.error(TickerNo + "----没有领优惠卷");
return; return;
} }
userCoupon.setIsUse(0); userCoupon.setIsUse(0);
...@@ -227,6 +242,79 @@ public class UserCouponBiz extends BaseBiz<UserCouponMapper, UserCoupon> { ...@@ -227,6 +242,79 @@ public class UserCouponBiz extends BaseBiz<UserCouponMapper, UserCoupon> {
} }
public PageDataVO<UserCouponPageVo> listUserCouponWithPage(UserCouponFindDTO userCouponFindDTO) {
PageDataVO<UserCouponPageVo> userCouponPag = new PageDataVO<>();
if (StringUtils.isNotEmpty(userCouponFindDTO.getPhone())) {
AppUserLogin appUserLogin = userFeign.one(userCouponFindDTO.getPhone());
userCouponFindDTO.setUserId(appUserLogin.getId());
}
PageDataVO<UserCouponDTO> pageDataVO = PageDataVO.pageInfo(userCouponFindDTO.getPage(), userCouponFindDTO.getLimit(), () -> mapper.findUserCoupons(userCouponFindDTO));
List<UserCouponDTO> data = pageDataVO.getData();
if (CollectionUtils.isEmpty(data)) {
return userCouponPag;
}
Map<Integer, AppUserLogin> userIdAndAppuserLoginMap = null;
if (Objects.nonNull(userCouponFindDTO.getPhone())) {
List<Integer> userIds = data.stream().map(UserCouponDTO::getUserId).collect(Collectors.toList());
userIdAndAppuserLoginMap = userFeign.findAppUsersByUserIds(userIds);
}
List<UserCouponPageVo> userCouponPageVos = new ArrayList<>();
UserCouponPageVo userCouponPageVo;
for (UserCouponDTO userCouponDTO : data) {
userCouponPageVo = new UserCouponPageVo();
BeanUtils.copyProperties(userCouponDTO, userCouponPageVo);
if (Objects.nonNull(userCouponFindDTO.getPhone())) {
userCouponPageVo.setPhone(userCouponFindDTO.getPhone());
} else {
userCouponPageVo.setPhone(userIdAndAppuserLoginMap == null ? "" : userIdAndAppuserLoginMap.get(userCouponDTO.getUserId()) == null ? "" : userIdAndAppuserLoginMap.get(userCouponDTO.getUserId()).getUsername());
}
userCouponPageVos.add(userCouponPageVo);
}
userCouponPag.setPageSize(pageDataVO.getPageSize());
userCouponPag.setPageNum(pageDataVO.getPageNum());
userCouponPag.setTotalCount(pageDataVO.getTotalCount());
userCouponPag.setTotalPage(pageDataVO.getTotalPage());
userCouponPag.setData(userCouponPageVos);
return userCouponPag;
}
public int sendCoupon(UserCouponSendDTO userCouponSendDTO) {
AppUserLogin appUserLogin = userFeign.one(userCouponSendDTO.getPhone());
CouponVo couponVo = couponBiz.findCouponById(userCouponSendDTO.getCouponId());
UserCoupon userCoupon;
List<UserCoupon> userCoupons = new ArrayList<>();
for (int i=0;i<userCouponSendDTO.getCouponNum();i++){
userCoupon = new UserCoupon();
userCoupon.setCouponId(userCouponSendDTO.getCouponId());
userCoupon.setUserId(appUserLogin.getId());
userCoupon.setCrtTime(Instant.now().toEpochMilli());
userCoupon.setStartTime(couponVo.getValidStartTime());
userCoupon.setExpireTime(couponVo.getValidEndTime());
userCoupons.add(userCoupon);
}
return mapper.insertList(userCoupons);
}
public long importUserCoupon(Integer couponId,List<String[]> userCounponData) {
List<String> phones = userCounponData.stream().map(x -> x[0]).collect(Collectors.toList());
Map<String,Integer> phoneAndAppUserLoginMap = userFeign.findAppusersByUserNames(phones);
CouponVo couponVo = couponBiz.findCouponById(couponId);
UserCoupon userCoupon;
List<UserCoupon> userCoupons = new ArrayList<>();
long length = userCounponData.size();
for (int i=0;i<length;i++){
userCoupon = new UserCoupon();
userCoupon.setCouponId(couponId);
userCoupon.setStartTime(couponVo.getValidStartTime());
userCoupon.setExpireTime(couponVo.getValidEndTime());
userCoupon.setUserId(phoneAndAppUserLoginMap.get(userCounponData.get(i)[0]));
userCoupons.add(userCoupon);
}
return mapper.insertList(userCoupons);
}
} }
\ No newline at end of file
package com.xxfc.platform.activity.mapper; package com.xxfc.platform.activity.mapper;
import com.xxfc.platform.activity.entity.Coupon; import com.xxfc.platform.activity.entity.Coupon;
import com.xxfc.platform.activity.vo.CouponTitleVo;
import tk.mybatis.mapper.common.Mapper; import tk.mybatis.mapper.common.Mapper;
import java.util.List;
/** /**
* 优惠券表 * 优惠券表
* *
...@@ -12,4 +15,5 @@ import tk.mybatis.mapper.common.Mapper; ...@@ -12,4 +15,5 @@ import tk.mybatis.mapper.common.Mapper;
*/ */
public interface CouponMapper extends Mapper<Coupon> { public interface CouponMapper extends Mapper<Coupon> {
List<CouponTitleVo> selectTitles();
} }
package com.xxfc.platform.activity.mapper; package com.xxfc.platform.activity.mapper;
import com.xxfc.platform.activity.dto.UserCouponDTO;
import com.xxfc.platform.activity.dto.UserCouponFindDTO;
import com.xxfc.platform.activity.entity.UserCoupon; import com.xxfc.platform.activity.entity.UserCoupon;
import com.xxfc.platform.activity.vo.UserCouponVo; import com.xxfc.platform.activity.vo.UserCouponVo;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.additional.insert.InsertListMapper;
import tk.mybatis.mapper.common.Mapper; import tk.mybatis.mapper.common.Mapper;
import java.util.List; import java.util.List;
...@@ -14,7 +17,7 @@ import java.util.List; ...@@ -14,7 +17,7 @@ import java.util.List;
* @email 18178966185@163.com * @email 18178966185@163.com
* @date 2019-06-21 14:34:49 * @date 2019-06-21 14:34:49
*/ */
public interface UserCouponMapper extends Mapper<UserCoupon> { public interface UserCouponMapper extends Mapper<UserCoupon> , InsertListMapper<UserCoupon> {
//我的优惠卷 //我的优惠卷
public List<UserCouponVo> getUserCouponsByType(@Param("userId")Integer userId,@Param("type")int type,@Param("time")Long time,@Param("channel")Integer channel); public List<UserCouponVo> getUserCouponsByType(@Param("userId")Integer userId,@Param("type")int type,@Param("time")Long time,@Param("channel")Integer channel);
...@@ -22,4 +25,5 @@ public interface UserCouponMapper extends Mapper<UserCoupon> { ...@@ -22,4 +25,5 @@ public interface UserCouponMapper extends Mapper<UserCoupon> {
//单个优惠卷 //单个优惠卷
public UserCouponVo getUserCoupon(@Param("tickerNo")String tickerNo); public UserCouponVo getUserCoupon(@Param("tickerNo")String tickerNo);
List<UserCouponDTO> findUserCoupons(UserCouponFindDTO userCouponFindDTO);
} }
\ No newline at end of file
package com.xxfc.platform.activity.rest.admin; package com.xxfc.platform.activity.rest.admin;
import com.github.wxiaoqi.security.admin.feign.dto.UserDTO;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.activity.biz.CouponBiz; import com.xxfc.platform.activity.biz.CouponBiz;
import com.xxfc.platform.activity.dto.CouponDTO;
import com.xxfc.platform.activity.dto.CouponFindDTO; import com.xxfc.platform.activity.dto.CouponFindDTO;
import com.xxfc.platform.activity.vo.CouponPagVo;
import com.xxfc.platform.activity.vo.CouponTitleVo;
import com.xxfc.platform.activity.vo.CouponVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import java.util.List;
/** /**
* @author libin * @author libin
...@@ -21,10 +28,44 @@ public class CouponAdminController { ...@@ -21,10 +28,44 @@ public class CouponAdminController {
@Autowired @Autowired
private CouponBiz couponBiz; private CouponBiz couponBiz;
@ApiOperation("优惠券列表")
@GetMapping("/page") @GetMapping("/page")
public ObjectRestResponse listCouponWithPage(CouponFindDTO couponFindDTO){ public ObjectRestResponse<PageDataVO<CouponPagVo>> listCouponWithPage(CouponFindDTO couponFindDTO) {
PageDataVO<CouponPagVo> couponPage = couponBiz.listCouponWithPage(couponFindDTO);
return ObjectRestResponse.succ(couponPage);
}
@ApiOperation("查询优惠券详情")
@GetMapping("/{id}")
public ObjectRestResponse<CouponVo> findCouponById(@PathVariable(value = "id") Integer id){
CouponVo couponVo = couponBiz.findCouponById(id);
return ObjectRestResponse.succ(couponVo);
}
@ApiOperation("获取优惠劵标题列表")
@GetMapping("/titles")
public ObjectRestResponse<List<CouponTitleVo>> getCouponTitleList(){
List<CouponTitleVo> titles = couponBiz.getCouponTitleList();
return ObjectRestResponse.succ(titles);
}
@ApiOperation("优惠劵新增 或 编辑")
@PostMapping
public ObjectRestResponse<Void> addCoupon(@RequestBody CouponDTO couponDTO, UserDTO userDTO){
couponBiz.addCoupon(couponDTO,userDTO);
return ObjectRestResponse.succ();
}
@ApiOperation("优惠劵逻辑删除")
@DeleteMapping("/{id}")
public ObjectRestResponse<Void> deleteCouponById(@PathVariable(value = "id") Integer id,UserDTO userDTO){
couponBiz.updateCouponDelStateById(id,userDTO);
return ObjectRestResponse.succ(); return ObjectRestResponse.succ();
} }
@ApiOperation("检查优惠劵是否已经在使用阶段")
@GetMapping("check/{id}")
public Boolean checkCouponHasUsedById(@PathVariable(value = "id") Integer id){
return true;
}
} }
package com.xxfc.platform.activity.rest.admin;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.excel.ExcelImport;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.activity.ActivityApplication;
import com.xxfc.platform.activity.biz.UserCouponBiz;
import com.xxfc.platform.activity.dto.UserCouponFindDTO;
import com.xxfc.platform.activity.dto.UserCouponSendDTO;
import com.xxfc.platform.activity.vo.UserCouponPageVo;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/7/23 16:22
*/
@RestController
@RequestMapping("/admin/user_coupon")
public class UserCouponAdminController {
@Autowired
private UserCouponBiz userCouponBiz;
@ApiOperation("领劵列表")
@GetMapping("/page")
public ObjectRestResponse<PageDataVO<UserCouponPageVo>> listUserCouponWithPage(UserCouponFindDTO userCouponFindDTO) {
PageDataVO<UserCouponPageVo> userCouponPage = userCouponBiz.listUserCouponWithPage(userCouponFindDTO);
return ObjectRestResponse.succ(userCouponPage);
}
@PostMapping("/sendcoupon")
public ObjectRestResponse<Void> sendCoupon(UserCouponSendDTO userCouponSendDTO){
userCouponBiz.sendCoupon(userCouponSendDTO);
return ObjectRestResponse.succ();
}
@PostMapping("/import")
public ObjectRestResponse<Void> importCouponBatch(@RequestParam("couponId") Integer couponId,@RequestPart(name = "file")MultipartFile couponExcel){
List<String[]> userCounponData = ExcelImport.getExcelData(couponExcel);
if (userCounponData.size() < 1) {
return ObjectRestResponse.createFailedResult(1001, "导入不能没数据!!!");
}
for (String[] userCounponDateNum : userCounponData) {
if (userCounponDateNum.length!=4){
return ObjectRestResponse.createFailedResult(1002, "数据不完整!!!");
}
}
userCounponData.remove(0);
userCouponBiz.importUserCoupon(couponId,userCounponData);
return ObjectRestResponse.succ();
}
@ApiOperation("用户劵excel模板下载")
@GetMapping("/excel_model/dowload")
public ResponseEntity<byte[]> dowloadUserMemberExcelModel(HttpServletResponse response){
// 重置response
response.reset();
response.setCharacterEncoding("utf-8");
response.setContentType("multipart/form-data");
response.addHeader("Content-Disposition", "attachment;filename=usermember.xlsx");
InputStream inputStream = ActivityApplication.class.getClassLoader().getResourceAsStream("file/usercoupon.xlsx");
try {
byte[] bytes = IOUtils.toByteArray(inputStream);
return ResponseEntity.ok(bytes);
} catch (IOException e) {
e.printStackTrace();
}
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
...@@ -37,4 +37,7 @@ ...@@ -37,4 +37,7 @@
<result property="isDel" column="is_del"/> <result property="isDel" column="is_del"/>
</resultMap> </resultMap>
<select id="selectTitles" resultType="string">
select `id`,`title` from `coupon` where `is_del`=0
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -72,4 +72,34 @@ ...@@ -72,4 +72,34 @@
u.is_del = 0 and u.ticker_no=#{tickerNo} limit 1 u.is_del = 0 and u.ticker_no=#{tickerNo} limit 1
</select> </select>
<select id="findUserCoupons" resultType="com.xxfc.platform.activity.dto.UserCouponDTO"
parameterType="com.xxfc.platform.activity.dto.UserCouponFindDTO">
SELECT
uc.id,
uc.user_id AS `userId`,
uc.is_use AS `isUse`,
cp.title,
cp.used_amount AS `usedAmount`,
uc.crt_time AS `crtTime`,
uc.expire_time AS `expireTime`,
uc.use_time AS `useTime`
FROM
( SELECT `id`, coupon_id, `user_id`, `is_use`, `crt_time`, `expire_time`, `use_time` FROM user_coupon WHERE
`is_del` = 0
<if test="userId != null">
`user_id`=#{userId}
</if>
<if test="status != null">
`is_use`=#{status}
</if>) AS `uc`
INNER JOIN ( SELECT `id`, `title`, `used_amount` FROM `coupon` WHERE 1=1
<if test="title != null and title != ''">
AND `title`=#{title}
</if>
<if test="usedAmount != null">
AND `used_amount`=#{usedAmount}
</if>
) AS `cp` ON uc.coupon_id = cp.id;
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment