Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
commit
912292805e
|
|
@ -2,6 +2,8 @@ package cn.ysk.cashier.dto;
|
|||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class CouponDto {
|
||||
private Integer shopId;
|
||||
|
|
@ -9,4 +11,5 @@ public class CouponDto {
|
|||
//-1已过期 1未使用 2已使用
|
||||
private Integer status;
|
||||
private Integer orderId;
|
||||
private BigDecimal amount;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package cn.ysk.cashier.mybatis.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
|
||||
|
|
@ -17,10 +18,12 @@ public class TbActivate extends Model<TbActivate> {
|
|||
//赠送金额
|
||||
private Integer giftAmount;
|
||||
//赠送积分
|
||||
@TableField(updateStrategy = FieldStrategy.ALWAYS)
|
||||
private Integer giftPoints;
|
||||
//是否使用优惠卷 0否 1是
|
||||
private Integer isUseCoupon;
|
||||
//优惠卷id
|
||||
@TableField(updateStrategy = FieldStrategy.ALWAYS)
|
||||
private Integer couponId;
|
||||
@TableField(exist = false)
|
||||
private String couponName;
|
||||
|
|
|
|||
|
|
@ -44,6 +44,12 @@ public interface TbActivateInRecordMapper extends BaseMapper<TbActivateInRecord>
|
|||
" order by inRecord.use_end_time asc")
|
||||
List<TbUserCouponVo> queryByVipIdAndShopId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId);
|
||||
|
||||
@Select("SELECT sum( over_num ) from tb_activate_in_record" +
|
||||
" where coupon_id = #{couponId} " +
|
||||
" and now() < use_end_time group by coupon_id ")
|
||||
Integer countNoUseCoupon(@Param("couponId") Integer couponId);
|
||||
|
||||
|
||||
@Update("update tb_activate_in_record" +
|
||||
" set over_num = #{overNum}" +
|
||||
" where id = #{id}")
|
||||
|
|
|
|||
|
|
@ -1,7 +1,15 @@
|
|||
package cn.ysk.cashier.mybatis.mapper;
|
||||
|
||||
import cn.ysk.cashier.dto.shop.TbShopUserQueryCriteria;
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivate;
|
||||
import cn.ysk.cashier.vo.ShopUserInfoVo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
|
|
@ -11,6 +19,15 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||
*/
|
||||
public interface TbActivateMapper extends BaseMapper<TbActivate> {
|
||||
|
||||
|
||||
@Select("<script>" +
|
||||
"SELECT " +
|
||||
" * " +
|
||||
"FROM tb_activate act " +
|
||||
"where " +
|
||||
" act.coupon_id=#{couponId}" +
|
||||
"</script>")
|
||||
List<TbActivate> queActByCouponId(@Param("couponId") Integer couponId);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import cn.ysk.cashier.mybatis.mapper.TbActivateMapper;
|
|||
import cn.ysk.cashier.mybatis.service.TbActivateService;
|
||||
import cn.ysk.cashier.mybatis.service.TbShopCouponService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -44,8 +45,22 @@ public class TbActivateServiceImpl extends ServiceImpl<TbActivateMapper, TbActiv
|
|||
@Override
|
||||
public void modifyActivate(TbActivate activate) {
|
||||
if (Objects.nonNull(activate.getId()) && activate.getId() > 0) {
|
||||
if(activate.getIsUseCoupon()==0){
|
||||
activate.setCouponId(null);
|
||||
} else if (activate.getIsUseCoupon()==1) {
|
||||
if (activate.getCouponId() == null) {
|
||||
throw new RuntimeException("优惠券不能为空");
|
||||
}
|
||||
}
|
||||
activateMapper.updateById(activate);
|
||||
} else {
|
||||
if(activate.getIsUseCoupon()==0){
|
||||
activate.setCouponId(null);
|
||||
} else if (activate.getIsUseCoupon()==1) {
|
||||
if (activate.getCouponId() == null) {
|
||||
throw new RuntimeException("优惠券不能为空");
|
||||
}
|
||||
}
|
||||
activateMapper.insert(activate);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,10 +10,7 @@ import cn.ysk.cashier.dto.QueryReceiveDto;
|
|||
import cn.ysk.cashier.dto.TbShopCouponQueryCriteria;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mybatis.entity.*;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbActivateInRecordMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbActivateOutRecordMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbMShopUserMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbShopCouponMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.*;
|
||||
import cn.ysk.cashier.mybatis.service.*;
|
||||
import cn.ysk.cashier.mybatis.vo.TbShopCouponVo;
|
||||
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
||||
|
|
@ -59,6 +56,8 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
|||
@Autowired
|
||||
private TbShopCouponMapper tbShopCouponmapper;
|
||||
@Autowired
|
||||
private TbActivateMapper activateMapper;
|
||||
@Autowired
|
||||
private TbCouponProductService couProductService;
|
||||
@Autowired
|
||||
private TbProductRepository tbProductRepository;
|
||||
|
|
@ -156,6 +155,16 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
|||
|
||||
@Override
|
||||
public boolean delete(Integer[] ids) {
|
||||
for (Integer id : ids) {
|
||||
List<TbActivate> tbActivates = activateMapper.queActByCouponId(id);
|
||||
if (CollectionUtil.isNotEmpty(tbActivates)) {
|
||||
throw new BadRequestException("该优惠券已关联活动,请解绑后删除");
|
||||
}
|
||||
Integer i = inRecordMapper.countNoUseCoupon(id);
|
||||
if (i != null && i > 0) {
|
||||
throw new BadRequestException("该优惠券有发放后未使用,无法删除");
|
||||
}
|
||||
}
|
||||
tbShopCouponmapper.deleteBatchIds(Arrays.asList(ids));
|
||||
for (Integer id : ids) {
|
||||
couProductService.remove(new LambdaQueryWrapper<TbCouponProduct>().eq(TbCouponProduct::getCouponId, id));
|
||||
|
|
@ -235,70 +244,24 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
|||
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");
|
||||
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(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);
|
||||
//券id 券使用描述
|
||||
Map<Integer, JsonObject> coupons = new HashMap<>();
|
||||
for (TbUserCouponVo tbUserCouponVo : tbUserCouponVos) {
|
||||
if (!coupons.containsKey(tbUserCouponVo.getCouponId())) {
|
||||
setCouponInfo(coupons, tbUserCouponVo, null, week, now, formatter);
|
||||
}
|
||||
JsonObject couponJson = coupons.get(tbUserCouponVo.getCouponId());
|
||||
tbUserCouponVo.setUseRestrictions(couponJson.get("useRestrictions").toString());
|
||||
tbUserCouponVo.setUse(couponJson.get("isUse").getAsBoolean());
|
||||
}
|
||||
tbUserCouponVos.sort(Comparator.comparing(TbUserCouponVo::isUse).reversed().thenComparing(TbUserCouponVo::getExpireTime));
|
||||
return new ResponseEntity<>(tbUserCouponVos, HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
|
|
@ -321,7 +284,7 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
|||
TbShopShareRecord shareRecord = shareRecordService.getById(inRecord.getSourceActId());
|
||||
if (shareRecord != null && shareRecord.getMethod().equals("use")) {
|
||||
shareRecord.setStatus(3);
|
||||
shareRecordService.give(shareRecord,shareRecord.getInvitedId());
|
||||
shareRecordService.give(shareRecord, shareRecord.getInvitedId());
|
||||
shareRecordService.updateById(shareRecord);
|
||||
}
|
||||
}
|
||||
|
|
@ -414,7 +377,7 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
|||
productCoupon.add(item);
|
||||
}
|
||||
});
|
||||
return new HashMap<String, Object>(){{
|
||||
return new HashMap<String, Object>() {{
|
||||
put("fullReductionCoupon", fullReductionCoupon);
|
||||
put("productCoupon", productCoupon);
|
||||
}};
|
||||
|
|
|
|||
|
|
@ -54,14 +54,14 @@ public class TbShopShareRecordServiceImpl extends ServiceImpl<TbShopShareRecordM
|
|||
TbShopShare shopShare = tbShopShareMapper.selectById(shareRecord.getShareId());
|
||||
TbShopUser tbShopUser = shopUserRepository.selectByUserIdAndShopId(userId.toString(), shopShare.getShopId().toString());
|
||||
if (userId.equals(shareRecord.getInvitedId())) {
|
||||
giveCoupon(shopShare, tbShopUser, shopShare.getRewardCoupons());
|
||||
giveCoupon(shopShare, tbShopUser, shopShare.getRewardCoupons(),shareRecord.getId(), true);
|
||||
} else if (userId.equals(shareRecord.getBeInvitedId())) {
|
||||
giveCoupon(shopShare, tbShopUser, shopShare.getNewCoupons());
|
||||
giveCoupon(shopShare, tbShopUser, shopShare.getNewCoupons(),shareRecord.getId(),false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void giveCoupon(TbShopShare shopShare, TbShopUser tbShopUser, List<TbShopShare.ShareCoupons> coupons) {
|
||||
public void giveCoupon(TbShopShare shopShare, TbShopUser tbShopUser, List<TbShopShare.ShareCoupons> coupons ,Integer flowId, boolean isReward) {
|
||||
for (TbShopShare.ShareCoupons newCoupon : coupons) {
|
||||
TbShopCoupon tbShopCoupon = couponMapper.selectById(newCoupon.getCouponId());
|
||||
Date start = new Date();
|
||||
|
|
@ -89,9 +89,14 @@ public class TbShopShareRecordServiceImpl extends ServiceImpl<TbShopShareRecordM
|
|||
record.setOverNum(newCoupon.getCouponNum());
|
||||
record.setShopId(Integer.valueOf(tbShopUser.getShopId()));
|
||||
record.setSourceActId(shopShare.getId());
|
||||
record.setSourceFlowId(flowId);
|
||||
record.setUseStartTime(start);
|
||||
record.setUseEndTime(end);
|
||||
record.setSource("invited");
|
||||
if(isReward){
|
||||
record.setSource("invited-reward");
|
||||
}else {
|
||||
record.setSource("invited");
|
||||
}
|
||||
actGiveRecords.add(record);
|
||||
} else if (tbShopCoupon.getType() == 2) {
|
||||
//商品卷
|
||||
|
|
@ -107,13 +112,22 @@ public class TbShopShareRecordServiceImpl extends ServiceImpl<TbShopShareRecordM
|
|||
record.setOverNum(actPro.getNum() * tbShopCoupon.getNumber());
|
||||
record.setShopId(Integer.valueOf(tbShopUser.getShopId()));
|
||||
record.setSourceActId(shopShare.getId());
|
||||
record.setSourceFlowId(flowId);
|
||||
record.setUseStartTime(start);
|
||||
record.setUseEndTime(end);
|
||||
record.setSource("invited");
|
||||
if(isReward){
|
||||
record.setSource("invited-reward");
|
||||
}else {
|
||||
record.setSource("invited");
|
||||
}
|
||||
actGiveRecords.add(record);
|
||||
}
|
||||
}
|
||||
inRecordMapper.insert(actGiveRecords);
|
||||
if(!isReward){
|
||||
tbShopCoupon.setLeftNumber(tbShopCoupon.getLeftNumber()-newCoupon.getCouponNum());
|
||||
couponMapper.updateById(tbShopCoupon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue