Merge branch 'ww' into test
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package cn.ysk.cashier.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CouponDto {
|
||||
private Integer shopId;
|
||||
private Integer userId;
|
||||
//-1已过期 1未使用 2已使用
|
||||
private Integer status;
|
||||
private Integer orderId;
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
package cn.ysk.cashier.mybatis.mapper;
|
||||
|
||||
import cn.ysk.cashier.vo.TbUserCouponVo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivateInRecord;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 活动商品赠送表(TbActivateInRecord)表数据库访问层
|
||||
@@ -11,5 +16,26 @@ import cn.ysk.cashier.mybatis.entity.TbActivateInRecord;
|
||||
*/
|
||||
public interface TbActivateInRecordMapper extends BaseMapper<TbActivateInRecord> {
|
||||
|
||||
@Select("SELECT" +
|
||||
" inRecord.coupon_id as couponId," +
|
||||
" pro.id as proId," +
|
||||
" CASE" +
|
||||
" WHEN inRecord.type = 1 THEN inRecord.NAME" +
|
||||
" WHEN inRecord.type = 2 THEN pro.NAME" +
|
||||
" END AS `name`," +
|
||||
" inRecord.type," +
|
||||
" inRecord.over_num as num," +
|
||||
" inRecord.use_end_time as endTime" +
|
||||
" FROM" +
|
||||
" tb_activate_in_record inRecord" +
|
||||
" LEFT JOIN tb_product pro ON inRecord.pro_id = pro.id and pro.shop_id = #{shopId}" +
|
||||
" WHERE" +
|
||||
" inRecord.vip_user_id = #{vipUserId}" +
|
||||
" and inRecord.shop_id = #{shopId}" +
|
||||
" and inRecord.over_num != 0" +
|
||||
" and inRecord.use_start_time < now()" +
|
||||
" and inRecord.use_end_time > now()" +
|
||||
" order by inRecord.use_end_time asc")
|
||||
List<TbUserCouponVo> queryByVipIdAndShopId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package cn.ysk.cashier.mybatis.rest;
|
||||
|
||||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.dto.CouponDto;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivate;
|
||||
import cn.ysk.cashier.mybatis.service.TbActivateService;
|
||||
import cn.ysk.cashier.mybatis.service.TbShopCouponService;
|
||||
import cn.ysk.cashier.service.WxService;
|
||||
import cn.ysk.cashier.utils.CacheKey;
|
||||
import cn.ysk.cashier.utils.RedisUtils;
|
||||
@@ -15,6 +17,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@@ -24,6 +27,7 @@ import java.util.Map;
|
||||
@RequestMapping("/shop/storage")
|
||||
public class StorageController {
|
||||
|
||||
private final TbShopCouponService tbShopCouponService;
|
||||
private final TbActivateService tbActivateService;
|
||||
private final RedisUtils redisUtils;
|
||||
private final WxService wxService;
|
||||
@@ -40,6 +44,11 @@ public class StorageController {
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
//获取订单可用优惠券
|
||||
@RequestMapping("find")
|
||||
public ResponseEntity<Object> find(@RequestBody CouponDto param) {
|
||||
return tbShopCouponService.find(param);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param params
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package cn.ysk.cashier.mybatis.service;
|
||||
|
||||
import cn.ysk.cashier.dto.CouponDto;
|
||||
import cn.ysk.cashier.mybatis.entity.TbCouponProduct;
|
||||
import cn.ysk.cashier.mybatis.vo.TbShopCouponVo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopCoupon;
|
||||
import cn.ysk.cashier.dto.TbShopCouponQueryCriteria;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -22,6 +24,7 @@ public interface TbShopCouponService extends IService<TbShopCoupon> {
|
||||
|
||||
TbShopCoupon findById (Integer id);
|
||||
|
||||
ResponseEntity<Object> find(CouponDto param);
|
||||
|
||||
boolean update(TbShopCouponVo param);
|
||||
boolean delete(Integer id);
|
||||
|
||||
@@ -3,27 +3,44 @@ package cn.ysk.cashier.mybatis.service.impl;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.ysk.cashier.dto.CouponDto;
|
||||
import cn.ysk.cashier.dto.TbShopCouponQueryCriteria;
|
||||
import cn.ysk.cashier.mybatis.entity.TbCouponProduct;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopCoupon;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbActivateInRecordMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbShopCouponMapper;
|
||||
import cn.ysk.cashier.mybatis.service.TbActivateInRecordService;
|
||||
import cn.ysk.cashier.mybatis.service.TbCouponProductService;
|
||||
import cn.ysk.cashier.mybatis.service.TbShopCouponService;
|
||||
import cn.ysk.cashier.mybatis.vo.TbShopCouponVo;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
import cn.ysk.cashier.pojo.product.TbProduct;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopUser;
|
||||
import cn.ysk.cashier.repository.order.TbOrderDetailRepository;
|
||||
import cn.ysk.cashier.repository.order.TbOrderInfoRepository;
|
||||
import cn.ysk.cashier.repository.product.TbProductRepository;
|
||||
import cn.ysk.cashier.repository.shop.TbShopUserRepository;
|
||||
import cn.ysk.cashier.service.shop.TbShopUserService;
|
||||
import cn.ysk.cashier.utils.PageUtil;
|
||||
import cn.ysk.cashier.vo.TbUserCouponVo;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -41,6 +58,15 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
||||
private TbCouponProductService couProductService;
|
||||
@Autowired
|
||||
private TbProductRepository tbProductRepository;
|
||||
@Autowired
|
||||
private TbShopUserRepository shopUserRepository;
|
||||
@Autowired
|
||||
private TbOrderInfoRepository orderInfoRepository;
|
||||
@Autowired
|
||||
private TbOrderDetailRepository orderDetailRepository;
|
||||
@Autowired
|
||||
private TbActivateInRecordMapper inRecordMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAll(TbShopCouponQueryCriteria criteria) {
|
||||
@@ -63,14 +89,87 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
||||
public TbShopCouponVo findById(Integer id) {
|
||||
TbShopCouponVo tbShopCouponVo = new TbShopCouponVo();
|
||||
TbShopCoupon tbShopCoupon = tbShopCouponmapper.selectById(id);
|
||||
BeanUtil.copyProperties(tbShopCoupon,tbShopCouponVo, CopyOptions.create().setIgnoreNullValue(true));
|
||||
if(tbShopCoupon.getType()==2){
|
||||
BeanUtil.copyProperties(tbShopCoupon, tbShopCouponVo, CopyOptions.create().setIgnoreNullValue(true));
|
||||
if (tbShopCoupon.getType() == 2) {
|
||||
List<TbCouponProduct> activatePros = findActivatePros(id);
|
||||
tbShopCouponVo.setProducts(activatePros);
|
||||
}
|
||||
return tbShopCouponVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Object> find(CouponDto param) {
|
||||
TbShopUser tbShopUser = shopUserRepository.selectByUserIdAndShopId(param.getUserId().toString(), param.getShopId().toString());
|
||||
if (param.getOrderId() != null) {
|
||||
TbOrderInfo tbOrderInfo = orderInfoRepository.findById(param.getOrderId()).orElse(null);
|
||||
if (tbOrderInfo != null) {
|
||||
List<TbOrderDetail> tbOrderDetails = orderDetailRepository.searchDetailByOrderId(param.getOrderId());
|
||||
Set<Integer> pros = tbOrderDetails.stream().map(TbOrderDetail::getProductId).collect(Collectors.toSet());
|
||||
if (CollectionUtil.isNotEmpty(tbOrderDetails)) {
|
||||
List<TbUserCouponVo> tbUserCouponVos = inRecordMapper.queryByVipIdAndShopId(tbShopUser.getId(), param.getShopId());
|
||||
if (CollectionUtil.isNotEmpty(tbUserCouponVos)) {
|
||||
String week = DateUtil.dayOfWeekEnum(new Date()).toChinese("周");
|
||||
LocalTime now = LocalTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||
|
||||
//券id 券使用描述
|
||||
Map<Integer, JsonObject> coupons = new HashMap<>();
|
||||
for (TbUserCouponVo tbUserCouponVo : tbUserCouponVos) {
|
||||
if (!coupons.containsKey(tbUserCouponVo.getCouponId())) {
|
||||
JsonObject json = new JsonObject();
|
||||
boolean isUse = true;
|
||||
TbShopCoupon tbShopCoupon = tbShopCouponmapper.selectById(tbUserCouponVo.getCouponId());
|
||||
StringBuilder useRestrictions = new StringBuilder("每天 ");
|
||||
if (tbShopCoupon.getType().equals(1)) {
|
||||
if (tbOrderInfo.getOrderAmount().compareTo(new BigDecimal(tbShopCoupon.getFullAmount())) < 0) {
|
||||
isUse = false;
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(tbShopCoupon.getUserDays())) {
|
||||
String[] split = tbShopCoupon.getUserDays().split(",");
|
||||
if (split.length != 7) {
|
||||
useRestrictions = new StringBuilder(tbShopCoupon.getUserDays() + " ");
|
||||
}
|
||||
if (!tbShopCoupon.getUserDays().contains(week)) {
|
||||
isUse = false;
|
||||
}
|
||||
}
|
||||
if (tbShopCoupon.getUseTimeType().equals("custom")) {
|
||||
if (now.isBefore(tbShopCoupon.getUseStartTime()) || now.isAfter(tbShopCoupon.getUseEndTime())) {
|
||||
isUse = false;
|
||||
}
|
||||
useRestrictions.append(
|
||||
tbShopCoupon.getUseStartTime().format(formatter)
|
||||
+ "-"
|
||||
+ tbShopCoupon.getUseEndTime().format(formatter));
|
||||
} else {
|
||||
useRestrictions.append("全时段");
|
||||
}
|
||||
useRestrictions.append(" 可用");
|
||||
json.addProperty("isUse", isUse);
|
||||
json.addProperty("useRestrictions", useRestrictions.toString());
|
||||
|
||||
coupons.put(tbUserCouponVo.getCouponId(), json);
|
||||
}
|
||||
JsonObject couponJson = coupons.get(tbUserCouponVo.getCouponId());
|
||||
tbUserCouponVo.setUseRestrictions(couponJson.get("useRestrictions").toString());
|
||||
if (tbUserCouponVo.getType().equals(1)) {
|
||||
tbUserCouponVo.setUse(couponJson.get("isUse").getAsBoolean());
|
||||
} else if (tbUserCouponVo.getType().equals(2) && couponJson.get("isUse").getAsBoolean()) {
|
||||
if (!pros.contains(tbUserCouponVo.getProId())) {
|
||||
tbUserCouponVo.setUse(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
tbUserCouponVos.sort(Comparator.comparing(TbUserCouponVo::isUse).reversed().thenComparing(TbUserCouponVo::getExpireTime));
|
||||
return new ResponseEntity<>(tbUserCouponVos, HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean update(TbShopCouponVo param) {
|
||||
|
||||
@@ -51,4 +51,6 @@ public interface TbShopUserRepository extends JpaRepository<TbShopUser, Integer>
|
||||
@Query(value = "select IFNULL(sum(amount),0) from tb_shop_user_flow where shop_user_id=:userId and biz_code in ('cashMemberIn','scanMemberIn')",nativeQuery = true)
|
||||
BigDecimal sumAmount(Integer userId);
|
||||
|
||||
@Query("SELECT user from TbShopUser user where user.shopId = :shopId and user.userId = :userId")
|
||||
TbShopUser selectByUserIdAndShopId(@Param("userId") String userId,@Param("shopId") String shopId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.ysk.cashier.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class TbUserCouponVo {
|
||||
private Integer couponId;
|
||||
private Integer proId;
|
||||
//优惠券名称
|
||||
private String name;
|
||||
//优惠券类型 1 满减 2 商品券
|
||||
private Integer type;
|
||||
//数量
|
||||
private Integer num;
|
||||
//到期时间
|
||||
private Date endTime;
|
||||
private Long expireTime;
|
||||
private String useRestrictions;
|
||||
private boolean isUse = false;
|
||||
|
||||
|
||||
public void setEndTime(Date endTime) {
|
||||
this.endTime = endTime;
|
||||
if(endTime!=null){
|
||||
expireTime=endTime.getTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user