Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
张松 2024-11-11 14:07:20 +08:00
commit 57f682ab44
14 changed files with 368 additions and 155 deletions

View File

@ -4,8 +4,10 @@ import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import java.nio.charset.Charset;
@ -17,6 +19,7 @@ public class fastJsonConfig extends WebMvcConfigurationSupport {
/**
* 使用阿里 fastjson 作为JSON MessageConverter
*
* @param converters
*/
@Override
@ -45,4 +48,10 @@ public class fastJsonConfig extends WebMvcConfigurationSupport {
converter.setSupportedMediaTypes(mediaTypeList);
converters.add(converter);
}
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
// 注册Spring data jpa pageable的参数分解器
argumentResolvers.add(new PageableHandlerMethodArgumentResolver());
}
}

View File

@ -1,7 +1,10 @@
package cn.ysk.cashier.controller;
import cn.ysk.cashier.annotation.rest.AnonymousPostMapping;
import cn.ysk.cashier.dto.TbShopShareRecordQueryCriteria;
import cn.ysk.cashier.mybatis.entity.TbShopShare;
import cn.ysk.cashier.mybatis.service.TbShopShareRecordService;
import cn.ysk.cashier.mybatis.service.TbShopShareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -26,11 +29,22 @@ public class TbShopShareController {
@Resource
private TbShopShareService tbShopShareService;
/**
* 服务对象
*/
@Resource
private TbShopShareRecordService tbShopShareRecordService;
@PostMapping("byShare")
@AnonymousPostMapping
@ApiOperation("分页查询")
public ResponseEntity<Object> selectAllByShare(@RequestBody TbShopShareRecordQueryCriteria criteria) {
return new ResponseEntity<>(tbShopShareRecordService.selectAllByShare(criteria), HttpStatus.OK);
}
@GetMapping("byShopId")
@ApiOperation("通过shopId查询详情")
public ResponseEntity<?> getByShopId(
@RequestParam Integer shopId
) {
public ResponseEntity<?> getByShopId(@RequestParam Integer shopId) {
return ResponseEntity.ok(tbShopShareService.getByShopId(shopId));
}

View File

@ -0,0 +1,26 @@
package cn.ysk.cashier.dto;
import lombok.Data;
/**
* (TbShopShareRecord)表查询类
*
* @author ww
* @since 2024-11-08 09:17:38
*/
@Data
public class TbShopShareRecordQueryCriteria {
private Integer shareId;
//店铺Id
private Integer shopId;
//邀请人名称/被邀请人/昵称/手机号 模糊查询
private String search;
//0 非新用户 1 未领取 2 已领取 3 已使用
private Integer status;
private long page = 1;
private long size = 10;
}

View File

@ -19,6 +19,7 @@ public class TbActivate extends Model<TbActivate> {
private Integer isUseCoupon;
//优惠卷id
private Integer couponId;
private String couponName;
//优惠卷数量
private Integer num;
@ -76,6 +77,14 @@ public class TbActivate extends Model<TbActivate> {
this.couponId = couponId;
}
public String getCouponName() {
return couponName;
}
public void setCouponName(String couponName) {
this.couponName = couponName;
}
public Integer getNum() {
return num;
}

View File

@ -5,6 +5,7 @@ import java.util.Date;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import java.io.Serializable;
@ -12,8 +13,9 @@ import java.io.Serializable;
* 活动商品赠送记录表(TbActivateInRecord)表实体类
*
* @author ww
* @since 2024-10-23 09:49:59
* @since 2024-11-08 09:53:21
*/
@Data
@SuppressWarnings("serial")
public class TbActivateInRecord extends Model<TbActivateInRecord> {
@ -42,140 +44,17 @@ public class TbActivateInRecord extends Model<TbActivateInRecord> {
private Integer sourceActId;
private Integer sourceFlowId;
//可用开始时间
private Date useStartTime;
//可用结束时间
private Date useEndTime;
@TableField(fill = FieldFill.INSERT)
private Date createTime;
@TableField(fill = FieldFill.UPDATE)
private Date updateTime;
private String couponJson;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getVipUserId() {
return vipUserId;
}
public void setVipUserId(Integer vipUserId) {
this.vipUserId = vipUserId;
}
public Integer getCouponId() {
return couponId;
}
public void setCouponId(Integer couponId) {
this.couponId = couponId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Integer getProId() {
return proId;
}
public void setProId(Integer proId) {
this.proId = proId;
}
public Integer getFullAmount() {
return fullAmount;
}
public void setFullAmount(Integer fullAmount) {
this.fullAmount = fullAmount;
}
public Integer getDiscountAmount() {
return discountAmount;
}
public void setDiscountAmount(Integer discountAmount) {
this.discountAmount = discountAmount;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public Integer getOverNum() {
return overNum;
}
public void setOverNum(Integer overNum) {
this.overNum = overNum;
}
public Integer getShopId() {
return shopId;
}
public void setShopId(Integer shopId) {
this.shopId = shopId;
}
public Integer getSourceActId() {
return sourceActId;
}
public void setSourceActId(Integer sourceActId) {
this.sourceActId = sourceActId;
}
public Integer getSourceFlowId() {
return sourceFlowId;
}
public void setSourceFlowId(Integer sourceFlowId) {
this.sourceFlowId = sourceFlowId;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getCouponJson() {
return couponJson;
}
public void setCouponJson(String couponJson) {
this.couponJson = couponJson;
}
//invited/activate
private String source;
}

View File

@ -0,0 +1,50 @@
package cn.ysk.cashier.mybatis.entity;
import java.util.Date;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import java.io.Serializable;
/**
* (TbShopShareRecord)表实体类
*
* @author ww
* @since 2024-11-08 09:17:37
*/
@Data
@SuppressWarnings("serial")
public class TbShopShareRecord extends Model<TbShopShareRecord> {
private Integer id;
//tb_shop_share 主键Id
private Integer shareId;
//店铺Id
private Integer shopId;
private String invitedHeadImg;
//邀请人id
private Integer invitedId;
//邀请人名称
private String invitedName;
private String beInvitedHeadImg;
//被邀请人Id
private Integer beInvitedId;
private String beInvitedName;
//奖励券获得方式 get/use 领取获得/使用获得
private String method;
//0 非新用户 1 未领取 2 已领取 3 已使用
private Integer status;
//生效时间/获得奖励的时间
private Date rewardTime;
private Date createTime;
private Date updateTime;
}

View File

@ -2,6 +2,10 @@ package cn.ysk.cashier.mybatis.mapper;
import cn.ysk.cashier.mybatis.entity.TbCouponProduct;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* 活动赠送商品表(TbActivateProduct)表数据库访问层
@ -11,5 +15,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public interface TbCouponProductMapper extends BaseMapper<TbCouponProduct> {
@Select(" select " +
" *" +
" from tb_coupon_product " +
" where " +
" coupon_id = #{couponId}")
List<TbCouponProduct> queryAllByCouponId(@Param("couponId") Integer couponId);
}

View File

@ -21,8 +21,15 @@ public interface TbShopCouponMapper extends BaseMapper<TbShopCoupon> {
@Select("<script>" +
" SELECT" +
" record.id, vip.id as userId ,vip.`name`,vip.telephone as phone,record.create_time as receiveTime," +
" record.update_time as useTime, record.num ,record.over_num as overNum" +
" record.id, " +
" vip.id as userId ," +
" vip.`name`," +
" vip.telephone as phone," +
" record.create_time as receiveTime," +
" record.update_time as useTime, " +
" record.num ," +
" record.over_num as overNum," +
" record.source as source" +
" FROM" +
" tb_activate_in_record record" +
" LEFT JOIN tb_shop_user vip " +
@ -33,10 +40,10 @@ public interface TbShopCouponMapper extends BaseMapper<TbShopCoupon> {
" <if test=\"param.value != null and param.value != '' \">" +
" and (vip.name like concat('%', #{param.value}, '%') or vip.telephone like concat('%', #{param.value}, '%')) " +
" </if>" +
" <if test=\"param.status != null and param.status = 1\">" +
" <if test=\"param.status != null and param.status == 1\">" +
" and record.over_num != record.num " +
" </if>" +
" <if test=\"param.status != null and param.status = 0\">" +
" <if test=\"param.status != null and param.status == 0\">" +
" and record.over_num = record.num " +
" </if>" +
" <if test=\"param.startTime != null \">" +

View File

@ -0,0 +1,46 @@
package cn.ysk.cashier.mybatis.mapper;
import cn.ysk.cashier.dto.TbShopShareRecordQueryCriteria;
import cn.ysk.cashier.vo.TbUserCouponVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.ysk.cashier.mybatis.entity.TbShopShareRecord;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* (TbShopShareRecord)表数据库访问层
*
* @author ww
* @since 2024-11-08 09:17:37
*/
public interface TbShopShareRecordMapper extends BaseMapper<TbShopShareRecord> {
@Select("<script> " +
"SELECT" +
" record.*," +
" user1.nick_name AS invitedName," +
" user2.nick_name AS beInvitedName," +
" user1.head_img AS invitedHeadImg," +
" user2.head_img AS beInvitedHeadImg " +
"FROM" +
" tb_shop_share_record record" +
" LEFT JOIN tb_user_info user1 ON record.invited_id = user1.id " +
" <if test=\"param.search != null and param.search != '' \"> " +
" AND (user1.nick_name like concat('%', #{param.search}, '%') or user1.telephone like concat('%', #{param.search}, '%')) " +
" </if> " +
" LEFT JOIN tb_user_info user2 ON record.be_invited_id = user2.id " +
" <if test=\"param.search != null and param.search != '' \"> " +
" AND (user2.nick_name like concat('%', #{param.search}, '%') or user2.telephone like concat('%', #{param.search}, '%')) " +
" </if> " +
"WHERE" +
" share_id = #{param.shareId}" +
" <if test=\" param.status != null \"> " +
" and record.status = #{param.status} "+
" </if> " +
"</script>")
Page<TbShopShareRecord> selectAllByShare(@Param("param") TbShopShareRecordQueryCriteria param, Page page);
}

View File

@ -0,0 +1,22 @@
package cn.ysk.cashier.mybatis.service;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.ysk.cashier.mybatis.entity.TbShopShareRecord;
import cn.ysk.cashier.dto.TbShopShareRecordQueryCriteria;
import java.util.Map;
/**
* (TbShopShareRecord)表服务接口
*
* @author ww
* @since 2024-11-08 09:17:37
*/
public interface TbShopShareRecordService extends IService<TbShopShareRecord> {
Map<String, Object> selectAllByShare(TbShopShareRecordQueryCriteria criteria);
void give(TbShopShareRecord shareRecord, Integer userId);
}

View File

@ -1,44 +1,51 @@
package cn.ysk.cashier.mybatis.service.impl;
import cn.ysk.cashier.mybatis.entity.TbActivate;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import cn.ysk.cashier.mybatis.entity.TbShopCoupon;
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.extension.service.impl.ServiceImpl;
import cn.ysk.cashier.mybatis.service.TbActivateService;
import cn.ysk.cashier.mybatis.mapper.TbActivateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* @author Administrator
* @description 针对表tb_activate的数据库操作Service实现
* @createDate 2024-09-03 14:08:30
*/
* @author Administrator
* @description 针对表tb_activate的数据库操作Service实现
* @createDate 2024-09-03 14:08:30
*/
@Service
public class TbActivateServiceImpl extends ServiceImpl<TbActivateMapper, TbActivate> implements TbActivateService{
public class TbActivateServiceImpl extends ServiceImpl<TbActivateMapper, TbActivate> implements TbActivateService {
@Autowired
private TbActivateMapper activateMapper;
@Autowired
private TbShopCouponService tbShopCouponService;
@Override
public Object findActivate(String shopId) {
QueryWrapper<TbActivate> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("shop_id",shopId);
queryWrapper.eq("shop_id", shopId);
queryWrapper.orderByDesc("id");
List<TbActivate> list = activateMapper.selectList(queryWrapper);
for (TbActivate tbActivate : list) {
if (tbActivate.getCouponId() != null) {
TbShopCoupon coupon = tbShopCouponService.findById(tbActivate.getCouponId());
tbActivate.setCouponName(coupon != null ? coupon.getTitle() : "");
}
}
return list;
}
@Override
public void modifyActivate(TbActivate activate) {
if (Objects.nonNull(activate.getId()) && activate.getId() > 0){
if (Objects.nonNull(activate.getId()) && activate.getId() > 0) {
activateMapper.updateById(activate);
}else {
} else {
activateMapper.insert(activate);
}
}

View File

@ -134,13 +134,13 @@ public class TbMemberPointsServiceImpl extends ServiceImpl<TbMemberPointsMapper,
BigDecimal accountYuan = NumberUtil.div(accountPoints, equivalentPoints);
// 下单最高抵扣比例
BigDecimal maxDeductionRatio = basic.getMaxDeductionRatio();
// 计算订单最多可以抵扣多少元
BigDecimal orderYuan = NumberUtil.roundDown(NumberUtil.mul(orderAmount, NumberUtil.div(maxDeductionRatio, new BigDecimal("100"))), 2);
// 计算订单最多可以抵扣多少元向下取整
BigDecimal orderYuan = NumberUtil.roundDown(NumberUtil.mul(orderAmount, NumberUtil.div(maxDeductionRatio, new BigDecimal("100"))), 0);
// 积分余额足够
if (NumberUtil.isGreaterOrEqual(accountYuan, orderYuan)) {
dto.setMaxDeductionAmount(orderYuan);
} else {
dto.setMaxDeductionAmount(NumberUtil.roundDown(accountYuan, 2));
dto.setMaxDeductionAmount(NumberUtil.roundDown(accountYuan, 0));
}
if (NumberUtil.isLess(dto.getMaxDeductionAmount(), BigDecimal.ONE)) {
dto.setUnusableReason("积分不足1元无法进行抵扣");
@ -185,7 +185,7 @@ public class TbMemberPointsServiceImpl extends ServiceImpl<TbMemberPointsMapper,
throw new BadRequestException(StrUtil.format("使用积分不能超过最大使用限制{}", core.getMaxUsablePoints()));
}
BigDecimal money = NumberUtil.mul(points, NumberUtil.div(BigDecimal.ONE, core.getEquivalentPoints()));
BigDecimal maxDeductionAmount = NumberUtil.roundDown(money, 2);
BigDecimal maxDeductionAmount = NumberUtil.roundDown(money, 0);
if (NumberUtil.isGreater(maxDeductionAmount, core.getMaxDeductionAmount())) {
return core.getMaxDeductionAmount();
}

View File

@ -72,6 +72,8 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
private TbActivateInRecordMapper inRecordMapper;
@Autowired
private TbActivateOutRecordMapper outRecordMapper;
@Autowired
private TbShopShareRecordService shareRecordService;
private final TbMShopUserMapper shopUserMapper;
private final MpShopUserService shopUserService;
private final MpOrderInfoService mpOrderInfoService;
@ -318,6 +320,15 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
public boolean use(Integer shopId, Integer orderId, Integer vipUserId, List<TbActivateOutRecord> param) {
for (TbActivateOutRecord outRecord : param) {
TbActivateInRecord inRecord = inRecordMapper.selectById(outRecord.getGiveId());
if (inRecord.getSource().equals("invited")) {
TbShopShareRecord shareRecord = shareRecordService.getById(inRecord.getSourceActId());
if (shareRecord.getMethod().equals("use")) {
shareRecord.setStatus(3);
shareRecordService.give(shareRecord,shareRecord.getInvitedId());
shareRecordService.updateById(shareRecord);
}
}
inRecord.setOverNum(inRecord.getOverNum() - outRecord.getUseNum());
inRecordMapper.updateOverNum(inRecord.getId(), inRecord.getOverNum());

View File

@ -0,0 +1,122 @@
package cn.ysk.cashier.mybatis.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.ysk.cashier.mybatis.entity.*;
import cn.ysk.cashier.mybatis.mapper.*;
import cn.ysk.cashier.mybatis.service.TbCouponProductService;
import cn.ysk.cashier.pojo.shop.TbShopUser;
import cn.ysk.cashier.repository.shop.TbShopUserRepository;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.ysk.cashier.mybatis.service.TbShopShareRecordService;
import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.ysk.cashier.dto.TbShopShareRecordQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import cn.ysk.cashier.utils.PageUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* (TbShopShareRecord)表服务实现类
*
* @author ww
* @since 2024-11-08 09:17:37
*/
@Service("tbShopShareRecordService")
public class TbShopShareRecordServiceImpl extends ServiceImpl<TbShopShareRecordMapper, TbShopShareRecord> implements TbShopShareRecordService {
@Autowired
private TbShopShareRecordMapper tbShopShareRecordmapper;
@Autowired
private TbShopShareMapper tbShopShareMapper;
@Autowired
private TbShopUserRepository shopUserRepository;
@Autowired
private TbShopCouponMapper couponMapper;
@Autowired
private TbCouponProductMapper couProductMapper;
@Autowired
private TbActivateInRecordMapper inRecordMapper;
@Override
public Map<String, Object> selectAllByShare(TbShopShareRecordQueryCriteria criteria) {
Page<TbShopShareRecord> ipage = tbShopShareRecordmapper.selectAllByShare(criteria,new Page<>(criteria.getPage(), criteria.getSize()));
return PageUtil.toPage(ipage.getRecords(), ipage.getTotal());
}
@Override
public void give(TbShopShareRecord shareRecord, Integer userId) {
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());
} else if (userId.equals(shareRecord.getBeInvitedId())) {
giveCoupon(shopShare, tbShopUser, shopShare.getNewCoupons());
}
}
public void giveCoupon(TbShopShare shopShare, TbShopUser tbShopUser, List<TbShopShare.ShareCoupons> coupons) {
for (TbShopShare.ShareCoupons newCoupon : coupons) {
TbShopCoupon tbShopCoupon = couponMapper.selectById(newCoupon.getCouponId());
Date start = new Date();
Date end = new Date();
if ("fixed".equals(tbShopCoupon.getValidityType())) {
//固定时间
end = DateUtil.offsetDay(new Date(), tbShopCoupon.getValidDays());
} else if ("custom".equals(tbShopCoupon.getValidityType())) {
//自定义时间
start = tbShopCoupon.getValidStartTime();
end = tbShopCoupon.getValidEndTime();
}
if (tbShopCoupon != null) {
List<TbActivateInRecord> actGiveRecords = new ArrayList<>();
if (tbShopCoupon.getType() == 1) {
//满减
TbActivateInRecord record = new TbActivateInRecord();
record.setVipUserId(Integer.valueOf(tbShopUser.getId()));
record.setCouponId(tbShopCoupon.getId());
record.setName("" + tbShopCoupon.getFullAmount() + "" + tbShopCoupon.getDiscountAmount());
record.setFullAmount(tbShopCoupon.getFullAmount());
record.setDiscountAmount(tbShopCoupon.getDiscountAmount());
record.setType(1);
record.setNum(newCoupon.getCouponNum());
record.setOverNum(newCoupon.getCouponNum());
record.setShopId(Integer.valueOf(tbShopUser.getShopId()));
record.setSourceActId(shopShare.getId());
record.setUseStartTime(start);
record.setUseEndTime(end);
record.setSource("invited");
actGiveRecords.add(record);
} else if (tbShopCoupon.getType() == 2) {
//商品卷
List<TbCouponProduct> tbCouponProducts = couProductMapper.queryAllByCouponId(tbShopCoupon.getId());
for (TbCouponProduct actPro : tbCouponProducts) {
TbActivateInRecord record = new TbActivateInRecord();
record.setVipUserId(Integer.valueOf(tbShopUser.getId()));
record.setCouponId(tbShopCoupon.getId());
record.setName("商品卷");
record.setType(2);
record.setProId(actPro.getProductId());
record.setNum(actPro.getNum() * tbShopCoupon.getNumber());
record.setOverNum(actPro.getNum() * tbShopCoupon.getNumber());
record.setShopId(Integer.valueOf(tbShopUser.getShopId()));
record.setSourceActId(shopShare.getId());
record.setUseStartTime(start);
record.setUseEndTime(end);
record.setSource("invited");
actGiveRecords.add(record);
}
}
inRecordMapper.insert(actGiveRecords);
}
}
}
}