Commit 504364c6 by 郑勇

feat-1002828 兑换券兑换配置功能

parent e765df56
......@@ -330,4 +330,6 @@ public class BookConstant {
public static final String TIME_CONTROL_UPDATE_SEND = "TIME_CONTROL_UPDATE_SEND";
public static final String TIME_CONTROL_SEND = "TIME_CONTROL_SEND_";
public static final String DEFAULT_COVER_PIC="https://oss.5rs.me/oss/uploadfe/jpg/b10f42694d17429fe9ebd8dfd85704e0.jpg";
}
package com.pcloud.book.giftcoupon.service;
import com.pcloud.book.giftcoupon.vo.GiftCouponVo;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@FeignClient(value = "pcloud-service-book", qualifier = "giftCouponServiceCloud", path = "book/v1.0/giftCouponService")
@Api(description = "小程序劵包")
public interface GiftCouponService {
@ApiOperation(value = "拿券的基本信息", httpMethod = "POST")
@RequestMapping(value = "/getCouponBaseInfo", method = RequestMethod.GET)
ResponseEntity<ResponseDto<GiftCouponVo>> getCouponBaseInfo(@RequestParam("couponId") Long couponId) throws BizException;
}
package com.pcloud.book.giftcoupon.vo;
import com.pcloud.common.entity.BaseEntity;
import lombok.Data;
/**
* 专享礼券包表(GiftCouponPackage)实体类
*
* @author makejava
* @since 2020-04-19 14:59:19
*/
@Data
public class GiftCouponVo extends BaseEntity {
/**
* 封面图
*/
private String coverPic;
/**
* 名称
*/
private String title;
/**
* 有效期开始时间
*/
private String validDateBegin;
/**
* 有效期结束时间
*/
private String validDateEnd;
/**
* 面额
*/
private Integer denomination;
private Integer stock;
/**
* 每人领取上限
*/
private Integer receiveLimit;
/**
* 券类型(1-书币券,2-课程券)
*/
private Integer couponType;
/**
* 使用说明
*/
private String instructions;
/**
* 课程券使用方式(1-链接兑取,2-复制码)
*/
private Integer useType;
/**
* 兑换地址
*/
private String exchangeAddress;
}
\ No newline at end of file
......@@ -6,6 +6,8 @@ import com.pcloud.book.giftcoupon.entity.GiftCouponPackage;
import com.pcloud.book.giftcoupon.entity.GiftReceive;
import com.pcloud.common.page.PageBeanNew;
import java.util.List;
public interface GiftCouponPackageBiz {
void createGiftPackage(GiftCouponPackage giftCouponPackage);
......@@ -17,9 +19,11 @@ public interface GiftCouponPackageBiz {
void createGiftReceive(GiftReceive giftReceive);
PageBeanNew<GiftPackageDTO> list4GiftPackage(String title, Integer state, Integer currentPage, Integer numPerPage);
PageBeanNew<GiftPackageDTO> list4GiftPackage(String title, Integer state,Integer couponType, Integer currentPage, Integer numPerPage);
PageBeanNew<MyGiftPackageDTO> list4MyGiftPackage(Integer state,Long wechatUserId,Integer currentPage, Integer numPerPage);
void useGiftCoupon(Long wechatUserId, Long giftPackageId);
void createGiftReceiveBatch(List<Long> giftPackageIds, Long wechatUserId);
}
package com.pcloud.book.giftcoupon.biz.impl;
import com.google.common.collect.Lists;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.book.constant.BookConstant;
import com.pcloud.book.giftcoupon.biz.GiftCouponPackageBiz;
import com.pcloud.book.giftcoupon.check.GiftParamCheck;
import com.pcloud.book.giftcoupon.dao.GiftCouponPackageDao;
......@@ -14,6 +17,7 @@ import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.page.PageParam;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.string.StringUtil;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -24,6 +28,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@Component("giftCouponPackageBiz")
......@@ -41,6 +46,9 @@ public class GiftCouponPackageBizImpl implements GiftCouponPackageBiz {
@Override
public void createGiftPackage(GiftCouponPackage giftCouponPackage) {
giftParamCheck.checkGiftAddParam(giftCouponPackage);
if(StringUtil.isBlank(giftCouponPackage.getCoverPic())){
giftCouponPackage.setCoverPic(BookConstant.DEFAULT_COVER_PIC);
}
giftCouponPackageDao.insert(giftCouponPackage);
}
......@@ -49,6 +57,9 @@ public class GiftCouponPackageBizImpl implements GiftCouponPackageBiz {
@Override
public void updateGiftPackage(GiftCouponPackage giftCouponPackage) {
giftParamCheck.checkGiftAddParam(giftCouponPackage);
if(StringUtil.isBlank(giftCouponPackage.getCoverPic())){
giftCouponPackage.setCoverPic(BookConstant.DEFAULT_COVER_PIC);
}
giftCouponPackageDao.update(giftCouponPackage);
}
......@@ -64,10 +75,11 @@ public class GiftCouponPackageBizImpl implements GiftCouponPackageBiz {
}
@Override
public PageBeanNew<GiftPackageDTO> list4GiftPackage(String title, Integer state, Integer currentPage, Integer numPerPage) {
public PageBeanNew<GiftPackageDTO> list4GiftPackage(String title, Integer state, Integer couponType,Integer currentPage, Integer numPerPage) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("title", title);
paramMap.put("state", state);
paramMap.put("couponType", couponType);
PageBeanNew<GiftPackageDTO> pageBeanNew=giftCouponPackageDao.listPageNew(new PageParam(currentPage, numPerPage), paramMap, "list4GiftPackage");
if (pageBeanNew == null || ListUtils.isEmpty(pageBeanNew.getRecordList())) {
return new PageBeanNew<>(currentPage, numPerPage, new ArrayList<>());
......@@ -92,7 +104,7 @@ public class GiftCouponPackageBizImpl implements GiftCouponPackageBiz {
}
@Transactional(rollbackFor = Exception.class)
@ParamLog("新增专享礼包")
@ParamLog(value = "新增专享礼包", isAfterReturn = false)
@Override
public void createGiftReceive(GiftReceive giftReceive) {
giftParamCheck.checkGiftReceiveAddParam(giftReceive);
......@@ -101,13 +113,18 @@ public class GiftCouponPackageBizImpl implements GiftCouponPackageBiz {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "当前奖券包不存在");
}
GiftReceive receive = giftReceiveDao.getGiftReceive(giftReceive.getWechatUserId(), giftReceive.getGiftPackageId());
//库存减一
if(giftCouponPackage.getStock()<1){
throw new BookBizException(BookBizException.PARAM_IS_NULL, "库存不够");
}
giftCouponPackageDao.reduceStock(giftReceive.getGiftPackageId());
if(null==receive){
giftReceive.setReceiveNum(1);
giftReceive.setUsedNum(0);
giftReceiveDao.insert(giftReceive);
}else{
if(receive.getReceiveNum()>=giftCouponPackage.getReceiveLimit()){
throw new BookBizException(BookBizException.PARAM_IS_NULL, "领取数量已超过奖券包最大领取数量");
if(receive.getReceiveNum()+1>=giftCouponPackage.getReceiveLimit()){
throw new BookBizException(BookBizException.PARAM_IS_NULL, "该类型的兑换券您已经领取过,请前往“我的券库”使用吧");
}
receive.setReceiveNum(receive.getReceiveNum()+1);
giftReceiveDao.update(receive);
......@@ -140,4 +157,69 @@ public class GiftCouponPackageBizImpl implements GiftCouponPackageBiz {
//todo 可能有其他操作,如果点击不跳转页面,需要控制重复点击
giftReceiveDao.useGiftCoupon(wechatUserId,giftPackageId);
}
@Override
@Transactional(rollbackFor = Exception.class)
@ParamLog(value = "礼券包一键领取", isAfterReturn = false)
public void createGiftReceiveBatch(List<Long> giftPackageIds, Long wechatUserId) {
if (ListUtils.isEmpty(giftPackageIds)) {
return;
}
List<Long> packageIdsBy = giftCouponPackageDao.getPackageIdsBy(giftPackageIds);
if (ListUtils.isEmpty(packageIdsBy) || packageIdsBy.size() != giftPackageIds.size()) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "有奖券包不存在,不能一键领取");
}
Integer noStockCount = giftCouponPackageDao.getNoStockCount(giftPackageIds);
if (noStockCount > 0) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "有奖券包无库存,不能一键领取");
}
//批量减库存
giftCouponPackageDao.reduceStockBatch(giftPackageIds);
Map<Long, GiftReceive> receiveMap = giftReceiveDao.getMapByIds(giftPackageIds, wechatUserId);
if (MapUtils.isEmpty(receiveMap)) {
//如果之前都没有领取过
List<GiftReceive> list = new ArrayList<>();
GiftReceive receive = null;
for (Long giftPackageId : giftPackageIds) {
receive = new GiftReceive();
receive.setReceiveNum(1);
receive.setUsedNum(0);
receive.setGiftPackageId(giftPackageId);
receive.setWechatUserId(wechatUserId);
list.add(receive);
}
giftReceiveDao.insert(list);
} else {
//去掉已经领取的直接插入
List<Long> hasReceiveIds = new ArrayList<>(receiveMap.keySet());
giftPackageIds.removeAll(hasReceiveIds);
List<GiftReceive> list = new ArrayList<>();
GiftReceive receive = null;
for (Long giftPackageId : giftPackageIds) {
receive = new GiftReceive();
receive.setReceiveNum(1);
receive.setUsedNum(0);
receive.setGiftPackageId(giftPackageId);
receive.setWechatUserId(wechatUserId);
list.add(receive);
}
giftReceiveDao.insert(list);
//已经领取过得要做修改
Map<Long, GiftCouponPackage> couponMap = giftCouponPackageDao.getMapByIds(hasReceiveIds);
List<Long> receives = Lists.newArrayList();
for (Long giftPackageId : hasReceiveIds) {
GiftCouponPackage giftCouponPackage = couponMap.get(giftPackageId);
GiftReceive giftReceive = receiveMap.get(giftPackageId);
if (giftReceive.getReceiveNum() + 1 >= giftCouponPackage.getReceiveLimit()) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "该类型的兑换券您已经领取过,请前往“我的券库”使用吧");
}
giftReceive.setReceiveNum(giftReceive.getReceiveNum() + 1);
receives.add(giftReceive.getId());
}
if(!ListUtils.isEmpty(receives)){
giftReceiveDao.updateReceiveNum(receives);
}
}
}
}
......@@ -3,6 +3,7 @@ package com.pcloud.book.giftcoupon.check;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.giftcoupon.entity.GiftCouponPackage;
import com.pcloud.book.giftcoupon.entity.GiftReceive;
import com.pcloud.book.giftcoupon.enums.CouponTypeEnum;
import com.pcloud.common.utils.DateUtils;
import com.pcloud.common.utils.string.StringUtil;
......@@ -16,33 +17,55 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GiftParamCheck {
private final Integer COUPON_MAX_TITLE_LENGTH=20;
private final Integer COUPON_MAX_DENOMINATION=999;
private final Integer COUPON_MAX_ADDRESS_LENGTH=800;
private final Integer COUPON_MAX_STOCK=99999;
private final Integer COUPON_MAX_RECEIVE=5;
public void checkGiftAddParam(GiftCouponPackage giftCouponPackage) {
if (null == giftCouponPackage) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "参数为空");
}
if(null==giftCouponPackage.getCouponType()){
throw new BookBizException(BookBizException.PARAM_IS_NULL, "请选择礼券类型");
}
if (StringUtil.isEmpty(giftCouponPackage.getTitle())) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "名称为空");
}
if (giftCouponPackage.getTitle().length()>20) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "标题名称最多20个字");
if (giftCouponPackage.getTitle().length()>COUPON_MAX_TITLE_LENGTH) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "标题名称最多"+COUPON_MAX_TITLE_LENGTH+"个字");
}
if (null == giftCouponPackage.getDenomination()) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "面额为空");
if(CouponTypeEnum.BOOK_COIN_COUPON.value.equals(giftCouponPackage.getCouponType())) {
if (null == giftCouponPackage.getDenomination()) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "面额为空");
}
if (giftCouponPackage.getDenomination() > COUPON_MAX_DENOMINATION) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "面额最多"+COUPON_MAX_DENOMINATION);
}
}
if (giftCouponPackage.getDenomination()>999) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "面额最多999");
if(CouponTypeEnum.COURSE_COUPON.value.equals(giftCouponPackage.getCouponType())){
if(null==giftCouponPackage.getUseType()){
throw new BookBizException(BookBizException.PARAM_IS_NULL, "使用方式为空");
}
if(StringUtil.isBlank(giftCouponPackage.getExchangeAddress())){
throw new BookBizException(BookBizException.PARAM_IS_NULL, "兑换地址为空");
}
if(giftCouponPackage.getExchangeAddress().length()>COUPON_MAX_ADDRESS_LENGTH){
throw new BookBizException(BookBizException.PARAM_IS_NULL, "兑换地址太长,最多"+COUPON_MAX_ADDRESS_LENGTH+"个字");
}
}
if (null == giftCouponPackage.getStock()) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "库存为空");
}
if (giftCouponPackage.getStock()>99999) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "库存最多99999");
if (giftCouponPackage.getStock()>COUPON_MAX_STOCK) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "库存最多"+COUPON_MAX_STOCK);
}
if (null == giftCouponPackage.getReceiveLimit()) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "领取上限为空");
}
if (giftCouponPackage.getReceiveLimit()>5) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "领取上限最多5张");
if (giftCouponPackage.getReceiveLimit()>COUPON_MAX_RECEIVE) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "领取上限最多"+COUPON_MAX_RECEIVE+"张");
}
if (null == giftCouponPackage.getValidDateBegin() || null==giftCouponPackage.getValidDateEnd()) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "有效期为空");
......@@ -53,6 +76,9 @@ public class GiftParamCheck {
if (DateUtils.getDateByStr(giftCouponPackage.getValidDateEnd()).before(new Date())) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "有效期结束时间不能小于当前时间");
}
if(StringUtil.isBlank(giftCouponPackage.getInstructions())){
throw new BookBizException(BookBizException.PARAM_IS_NULL, "使用说明不能为空");
}
}
public void checkGiftReceiveAddParam(GiftReceive giftReceive) {
......
......@@ -17,4 +17,12 @@ public interface GiftCouponPackageDao extends BaseDao<GiftCouponPackage> {
Map<Long,GiftCouponPackage> getMapByIds(List<Long> list);
List<Long> getPackageIdsBy(List<Long> packageIds);
Integer getNoStockCount(List<Long> packageIds);
void reduceStock(Long id);
void reduceStockBatch(List<Long> packageIds);
}
\ No newline at end of file
package com.pcloud.book.giftcoupon.dao;
import com.pcloud.book.giftcoupon.dto.GiftReceiveDTO;
import com.pcloud.book.giftcoupon.entity.GiftCouponPackage;
import com.pcloud.book.giftcoupon.entity.GiftReceive;
import com.pcloud.common.core.dao.BaseDao;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* 专享礼券包领取表(GiftReceive)表数据库访问层
......@@ -28,9 +30,10 @@ public interface GiftReceiveDao extends BaseDao<GiftReceive> {
List<GiftReceiveDTO> getGiftReceiveNumList(List<Long> giftPackageIds);
List<Long> getUserReceiveGiftId(Long wechatUserId);
Map<Long,GiftReceive> getMapByIds(List<Long> giftPackageIds,Long wechatUserId);
void updateReceiveNum(List<Long> receives);
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -17,4 +18,32 @@ public class GiftCouponPackageDaoImpl extends BaseDaoImpl<GiftCouponPackage> imp
public Map<Long,GiftCouponPackage> getMapByIds(List<Long> list) {
return super.getSqlSession().selectMap(super.getStatement("getMapByIds"), list, "id");
}
@Override
public List<Long> getPackageIdsBy(List<Long> packageIds) {
Map<String,Object> map=new HashMap<>();
map.put("packageIds",packageIds);
return super.getSqlSession().selectList(getStatement("getPackageIdsBy"),map);
}
@Override
public Integer getNoStockCount(List<Long> packageIds) {
Map<String,Object> map=new HashMap<>();
map.put("packageIds",packageIds);
return super.getSqlSession().selectOne(getStatement("getNoStockCount"),map);
}
@Override
public void reduceStock(Long id) {
Map<String,Object> map=new HashMap<>();
map.put("id",id);
super.getSqlSession().update(getStatement("reduceStock"),map);
}
@Override
public void reduceStockBatch(List<Long> packageIds) {
Map<String,Object> map=new HashMap<>();
map.put("packageIds",packageIds);
super.getSqlSession().update(getStatement("reduceStockBatch"),map);
}
}
......@@ -43,4 +43,19 @@ public class GiftReceiveDaoImpl extends BaseDaoImpl<GiftReceive> implements Gift
public List<Long> getUserReceiveGiftId(Long wechatUserId) {
return super.getSessionTemplate().selectList(getStatement("getUserReceiveGiftId"),wechatUserId);
}
@Override
public Map<Long, GiftReceive> getMapByIds(List<Long> giftPackageIds,Long wechatUserId) {
Map<String,Object> map=new HashMap<>();
map.put("giftPackageIds",giftPackageIds);
map.put("wechatUserId",wechatUserId);
return super.getSqlSession().selectMap(super.getStatement("getMapByIds"), map, "gift_package_id");
}
@Override
public void updateReceiveNum(List<Long> receives) {
Map<String,Object> map=new HashMap<>();
map.put("receives",receives);
super.getSessionTemplate().update(getStatement("updateReceiveNum"),map);
}
}
......@@ -56,4 +56,13 @@ public class GiftPackageDTO {
* 领取数量
*/
private Integer receiveNum;
/**
* 券类型(2-书币券,1-课程券)
*/
private Integer couponType;
/**
* 使用说明
*/
private String instructions;
}
......@@ -46,4 +46,22 @@ public class MyGiftPackageDTO {
* 未使用数量
*/
private Integer notUsedNum;
/**
* 券类型(2-书币券,1-课程券)
*/
private Integer couponType;
/**
* 使用说明
*/
private String instructions;
/**
* 课程券使用方式(1-链接兑取,2-复制码)
*/
private Integer useType;
/**
* 兑换地址
*/
private String exchangeAddress;
}
......@@ -42,6 +42,22 @@ public class GiftCouponPackage extends BaseEntity {
*/
private Integer receiveLimit;
/**
* 券类型(2-书币券,1-课程券)
*/
private Integer couponType;
/**
* 使用说明
*/
private String instructions;
/**
* 课程券使用方式(1-链接兑取,2-复制码)
*/
private Integer useType;
/**
* 兑换地址
*/
private String exchangeAddress;
}
\ No newline at end of file
package com.pcloud.book.giftcoupon.enums;
/**
* 礼券分类
*/
public enum CouponTypeEnum {
/**
* 课程券
*/
COURSE_COUPON(1),
/**
* 书币券
*/
BOOK_COIN_COUPON(2);
public final Integer value;
CouponTypeEnum(Integer value) {
this.value = value;
}
}
package com.pcloud.book.giftcoupon.enums;
/**
* 礼券使用方式
*/
public enum CouponUseTypeEnum {
/**
* 链接兑取
*/
LINK(1),
/**
* 复制码
*/
COPY_CODE(2);
public final Integer value;
CouponUseTypeEnum(Integer value) {
this.value = value;
}
}
......@@ -13,6 +13,7 @@ import com.pcloud.book.cultivate.entity.CultivateBookUser;
import com.pcloud.book.cultivate.entity.CultivateRobotClassify;
import com.pcloud.book.giftcoupon.biz.GiftCouponPackageBiz;
import com.pcloud.book.giftcoupon.dto.GiftPackageDTO;
import com.pcloud.book.giftcoupon.dto.GiftReceiveDTO;
import com.pcloud.book.giftcoupon.dto.MyGiftPackageDTO;
import com.pcloud.book.giftcoupon.entity.GiftCouponPackage;
import com.pcloud.book.giftcoupon.entity.GiftReceive;
......@@ -32,6 +33,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import javax.ws.rs.POST;
import io.swagger.annotations.Api;
......@@ -87,10 +90,11 @@ public class GiftCouponPackageFacade {
public ResponseDto<PageBeanNew<GiftPackageDTO>> list4GiftPackage(
@RequestParam(value = "title",required = false) @ApiParam("礼包券名称") String title,
@RequestParam(value = "state",required = false) @ApiParam("状态") Integer state,
@RequestParam(value = "couponType",required = false) @ApiParam("券类型") Integer couponType,
@RequestParam(value = "currentPage", required = false) Integer currentPage,
@RequestParam(value = "numPerPage", required = false) Integer numPerPage
) throws BizException, PermissionException {
return new ResponseDto<>(giftCouponPackageBiz.list4GiftPackage(title,state,currentPage,numPerPage));
return new ResponseDto<>(giftCouponPackageBiz.list4GiftPackage(title,state,couponType,currentPage,numPerPage));
}
@ApiOperation("新增礼券包领取")
......@@ -105,6 +109,17 @@ public class GiftCouponPackageFacade {
return new ResponseDto<>();
}
@ApiOperation("礼券包一键领取")
@PostMapping("/createGiftReceiveBatch")
public ResponseDto<?> createGiftReceiveBatch(
@CookieValue(value = "userInfo") String userInfo ,
@RequestBody List<Long> giftPackageIds
) throws BizException, PermissionException {
Long wechatUserId = Cookie.getId(userInfo, Cookie._WECHAT_USER_ID);
giftCouponPackageBiz.createGiftReceiveBatch(giftPackageIds,wechatUserId);
return new ResponseDto<>();
}
@ApiOperation("我的礼券包列表")
@GetMapping("/list4MyGiftPackage")
public ResponseDto<PageBeanNew<MyGiftPackageDTO>> list4MyGiftPackage(
......@@ -121,10 +136,10 @@ public class GiftCouponPackageFacade {
@PostMapping("/useGiftCoupon")
public ResponseDto<?> useGiftCoupon(
@CookieValue(value = "userInfo") String userInfo ,
@RequestParam(value = "giftPackageId",required = false) @ApiParam("礼券id") Long giftPackageId
@RequestBody GiftReceiveDTO giftReceiveDTO
) throws BizException, PermissionException {
Long wechatUserId = Cookie.getId(userInfo, Cookie._WECHAT_USER_ID);
giftCouponPackageBiz.useGiftCoupon(wechatUserId,giftPackageId);
giftCouponPackageBiz.useGiftCoupon(wechatUserId,giftReceiveDTO.getGiftPackageId());
return new ResponseDto<>();
}
......
package com.pcloud.book.giftcoupon.service.impl;
import com.pcloud.book.giftcoupon.biz.GiftCouponPackageBiz;
import com.pcloud.book.giftcoupon.entity.GiftCouponPackage;
import com.pcloud.book.giftcoupon.service.GiftCouponService;
import com.pcloud.book.giftcoupon.vo.GiftCouponVo;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.utils.ResponseHandleUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController("giftCouponService")
@RequestMapping("giftCouponService")
public class GiftCouponServiceImpl implements GiftCouponService {
@Autowired
private GiftCouponPackageBiz giftCouponPackageBiz;
@Override
@RequestMapping(value = "/getCouponBaseInfo", method = RequestMethod.GET)
public ResponseEntity<ResponseDto<GiftCouponVo>> getCouponBaseInfo(@RequestParam("couponId") Long couponId) throws BizException {
GiftCouponPackage giftPackage = giftCouponPackageBiz.getGiftPackage(couponId);
GiftCouponVo giftCouponVo=new GiftCouponVo();
BeanUtils.copyProperties(giftPackage,giftCouponVo);
return ResponseHandleUtil.toResponse(giftCouponVo);
}
}
......@@ -12,16 +12,23 @@
<result property="receiveLimit" column="receive_limit" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
<result property="couponType" column="coupon_type" jdbcType="INTEGER"/>
<result property="instructions" column="instructions" jdbcType="VARCHAR"/>
<result property="useType" column="use_type" jdbcType="INTEGER"/>
<result property="exchangeAddress" column="exchange_address" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id, cover_pic, title, valid_date_begin, valid_date_end, denomination, stock, receive_limit, create_time, update_time, is_delete
id, cover_pic, title, valid_date_begin, valid_date_end, denomination, stock, receive_limit, create_time, update_time, is_delete,
coupon_type,instructions,use_type,exchange_address
</sql>
<!--查询单个-->
<select id="getById" resultMap="GiftCouplePackageMap">
select
id, cover_pic, title, valid_date_begin, valid_date_end, denomination, stock, receive_limit, create_time, update_time, is_delete
id, cover_pic, title, valid_date_begin, valid_date_end, denomination, stock, receive_limit, create_time, update_time, is_delete,
coupon_type,instructions,use_type,exchange_address
from book.gift_coupon_package
where id = #{id}
and is_delete=0
......@@ -30,7 +37,8 @@
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="GiftCouplePackageMap">
select
id, cover_pic, title, valid_date_begin, valid_date_end, denomination, stock, receive_limit, create_time, update_time, is_delete
id, cover_pic, title, valid_date_begin, valid_date_end, denomination, stock, receive_limit, create_time, update_time, is_delete,
coupon_type,instructions,use_type,exchange_address
from book.gift_coupon_package
limit #{offset}, #{limit}
</select>
......@@ -38,7 +46,8 @@
<!--通过实体作为筛选条件查询-->
<select id="queryAll" resultMap="GiftCouplePackageMap">
select
id, cover_pic, title, valid_date_begin, valid_date_end, denomination, stock, receive_limit, create_time, update_time, is_delete
id, cover_pic, title, valid_date_begin, valid_date_end, denomination, stock, receive_limit, create_time, update_time, is_delete,
coupon_type,instructions,use_type,exchange_address
from book.gift_coupon_package
<where>
<if test="id != null">
......@@ -79,8 +88,10 @@
<!--新增所有列-->
<insert id="insert" parameterType="com.pcloud.book.giftcoupon.entity.GiftCouponPackage" keyProperty="id" useGeneratedKeys="true">
insert into book.gift_coupon_package(cover_pic, title, valid_date_begin, valid_date_end, denomination, stock, receive_limit, create_time, update_time, is_delete)
values (#{coverPic}, #{title}, #{validDateBegin}, #{validDateEnd}, #{denomination}, #{stock}, #{receiveLimit}, now(), now(), 0)
insert into book.gift_coupon_package(cover_pic, title, valid_date_begin, valid_date_end, denomination, stock, receive_limit, create_time, update_time, is_delete,
coupon_type,instructions,use_type,exchange_address)
values (#{coverPic}, #{title}, #{validDateBegin}, #{validDateEnd}, #{denomination}, #{stock}, #{receiveLimit}, now(), now(), 0,
#{couponType},#{instructions},#{useType},#{exchangeAddress})
</insert>
<!--通过主键修改数据-->
......@@ -111,6 +122,18 @@
<if test="createTime != null">
create_time = #{createTime},
</if>
<if test="couponType != null">
coupon_type = #{couponType},
</if>
<if test="instructions != null">
instructions = #{instructions},
</if>
<if test="useType != null">
use_type = #{useType},
</if>
<if test="exchangeAddress != null">
exchange_address = #{exchangeAddress},
</if>
update_time = now()
</set>
where id = #{id}
......@@ -131,10 +154,13 @@
a.stock,
a.valid_date_begin validDateBegin,
a.valid_date_end validDateEnd,
if(NOW()<![CDATA[ < ]]> a.valid_date_begin,1,if(NOW() between a.valid_date_begin and a.valid_date_end,2,3)) state
if(NOW()<![CDATA[ < ]]> a.valid_date_begin,1,if(NOW() between a.valid_date_begin and a.valid_date_end,2,3)) state,
a.coupon_type couponType,
a.instructions instructions
from
gift_coupon_package a
where a.is_delete=0
and a.stock>0
<if test="title !=null and title !=''">
and a.title like concat('%',#{title},'%')
</if>
......@@ -150,6 +176,9 @@
<if test="state !=null and state==4">
and now() <![CDATA[ <= ]]> a.valid_date_end
</if>
<if test="couponType !=null">
and a.coupon_type=#{couponType}
</if>
GROUP BY a.id
order by a.update_time desc
......@@ -165,6 +194,40 @@
</foreach>
</select>
<select id="reduceStock" parameterType="map">
update gift_coupon_package set stock=stock-1
where id=#{id}
</select>
<select id="reduceStockBatch" parameterType="map">
update gift_coupon_package set stock=stock-1
where id in
<foreach collection="packageIds" item="item" index="index" open="(" separator="," close=")">
${item}
</foreach>
</select>
<select id="getPackageIdsBy" parameterType="map" resultType="Long">
select distinct id
from gift_coupon_package
where is_delete=0
and id in
<foreach collection="packageIds" item="item" index="index" open="(" separator="," close=")">
${item}
</foreach>
</select>
<select id="getNoStockCount" parameterType="map" resultType="Integer">
select ifnull(count(1),0)
from gift_coupon_package
where is_delete=0
and id in
<foreach collection="packageIds" item="item" index="index" open="(" separator="," close=")">
${item}
</foreach>
and stock<![CDATA[ <= ]]>0
</select>
</mapper>
\ No newline at end of file
......@@ -12,6 +12,10 @@
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, wechat_user_id, gift_package_id, receive_num, used_num, create_time, update_time
</sql>
<!--查询单个-->
<select id="queryById" resultMap="GiftReceiveMap">
select
......@@ -64,6 +68,14 @@
values (#{wechatUserId}, #{giftPackageId}, #{receiveNum}, #{usedNum}, now(), now())
</insert>
<insert id="batchInsert" parameterType="com.pcloud.book.giftcoupon.entity.GiftReceive" keyProperty="id" useGeneratedKeys="true">
insert into book.gift_receive(wechat_user_id, gift_package_id, receive_num, used_num, create_time, update_time)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.wechatUserId}, #{item.giftPackageId}, #{item.receiveNum}, #{item.usedNum}, now(), now())
</foreach>
</insert>
<!--通过主键修改数据-->
<update id="update">
update book.gift_receive
......@@ -95,7 +107,7 @@
<select id="getGiftReceive" parameterType="map" resultMap="GiftReceiveMap">
select
id, wechat_user_id, gift_package_id, receive_num
id, wechat_user_id, gift_package_id, receive_num, used_num, create_time, update_time
from book.gift_receive
where wechat_user_id=#{wechatUserId}
and gift_package_id=#{giftPackageId}
......@@ -117,7 +129,11 @@
a.valid_date_begin validDateBegin,
a.valid_date_end validDateEnd,
a.id id,
(b.receive_num-ifnull(b.used_num,0)) noUsedNum
(b.receive_num-ifnull(b.used_num,0)) noUsedNum,
a.coupon_type couponType,
a.instructions instructions,
a.use_type useType,
a.exchange_address exchangeAddress
from
gift_receive b LEFT JOIN gift_coupon_package a
on a.id=b.gift_package_id
......@@ -149,4 +165,23 @@
where wechat_user_id=#{wechatUserId}
</select>
<select id="getMapByIds" parameterType="map" resultMap="GiftReceiveMap">
select <include refid="Base_Column_List"/>
from gift_receive
where wechat_user_id=#{wechatUserId}
and gift_package_id in
<foreach collection="giftPackageIds" item="item" index="index" open="(" separator="," close=")">
${item}
</foreach>
</select>
<select id="updateReceiveNum" parameterType="map">
update gift_receive
set receive_num=receive_num+1
where id in
<foreach collection="receives" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</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