会员商品 优惠卷列表

This commit is contained in:
2024-09-02 15:30:32 +08:00
parent 119b6ba9c7
commit b3850469ec
14 changed files with 240 additions and 26 deletions

View File

@@ -0,0 +1,32 @@
package com.chaozhanggui.system.cashierservice.controller;
import com.chaozhanggui.system.cashierservice.entity.dto.UserCouponDto;
import com.chaozhanggui.system.cashierservice.service.TbUserCouponsService;
import com.chaozhanggui.system.cashierservice.sign.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("userConpons")
public class TbUserCouponsController {
/**
* 服务对象
*/
@Autowired
private TbUserCouponsService tbUserCouponsService;
/**
* 查询优惠卷
* @param conponDto
* @return
*/
@RequestMapping("find")
public Result queryByPage(@RequestBody UserCouponDto conponDto) {
return tbUserCouponsService.queryByPage(conponDto);
}
}

View File

@@ -2,6 +2,8 @@ package com.chaozhanggui.system.cashierservice.dao;
import com.chaozhanggui.system.cashierservice.entity.TbActivateInRecord;
import com.chaozhanggui.system.cashierservice.entity.TbProduct;
import com.chaozhanggui.system.cashierservice.entity.TbUserCoupons;
import com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@@ -31,6 +33,7 @@ public interface TbActivateInRecordMapper {
List<TbActivateInRecord> queryAll(TbActivateInRecord tbActivateInRecord);
List<TbProduct> queryByVipIdAndShopId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId);
List<UserCouponVo> queryVipPro(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId);
int queryByVipIdAndShopIdAndProId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId,@Param("productId") Integer productId);
List<TbActivateInRecord> queryAllByVipIdAndShopIdAndProId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId,@Param("productId") Integer productId);

View File

@@ -1,6 +1,7 @@
package com.chaozhanggui.system.cashierservice.dao;
import com.chaozhanggui.system.cashierservice.entity.TbActivateOutRecord;
import com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@@ -29,6 +30,8 @@ public interface TbActivateOutRecordMapper {
*/
List<TbActivateOutRecord> queryAll(TbActivateOutRecord tbActivateOutRecord);
List<UserCouponVo> queryVipPro(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId);
/**
* 新增数据

View File

@@ -1,6 +1,8 @@
package com.chaozhanggui.system.cashierservice.dao;
import com.chaozhanggui.system.cashierservice.entity.TbUserCoupons;
import com.chaozhanggui.system.cashierservice.entity.dto.UserCouponDto;
import com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
@@ -18,6 +20,7 @@ public interface TbUserCouponsMapper {
int insertSelective(TbUserCoupons record);
TbUserCoupons selectByPrimaryKey(Integer id);
List<UserCouponVo> queryAllSelective(UserCouponDto record);
int updateByPrimaryKeySelective(TbUserCoupons record);

View File

@@ -7,10 +7,11 @@ import java.math.BigDecimal;
import java.util.Date;
@Data
public class TbUserCoupons implements Serializable {
public class TbUserCoupons implements Serializable{
private Integer id;
private String userId;
private String detail;
private Integer orderId;
private BigDecimal couponsPrice;

View File

@@ -0,0 +1,11 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import lombok.Data;
@Data
public class UserCouponDto extends BasePageDto{
private Integer userId;
private Integer status;
private Integer shopId;
}

View File

@@ -0,0 +1,33 @@
package com.chaozhanggui.system.cashierservice.entity.vo;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class UserCouponVo {
/**
* 2 会员商品卷
*/
private Integer type;
/**
* 卷描述
*/
private String detail;
/**
* 优惠金额
*/
private BigDecimal couponsPrice = BigDecimal.ZERO;
/**
* 多少可用
*/
private BigDecimal couponsAmount = BigDecimal.ZERO;
/**
* 数量
*/
private Integer num;
/**
* 卷状态 0 未使用
*/
private String status;
}

View File

@@ -654,28 +654,7 @@ public class CartService {
couponAmount = userCoupons.getCouponsAmount();
} else {
TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(couponsId);
if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")) {
log.info("开始处理订单");
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "优惠券已使用");
jsonObject1.put("type", jsonObject.getString("type"));
jsonObject1.put("data", "");
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
log.info("消息推送");
return;
}
if (N.gt(userCoupons.getCouponsAmount(), totalAmount)) {
log.info("开始处理订单");
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "订单金额小于优惠价金额");
jsonObject1.put("type", jsonObject.getString("type"));
jsonObject1.put("data", "");
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
log.info("消息推送");
return;
}
totalAmount = totalAmount.subtract(userCoupons.getCouponsAmount());
userCoupons.setStatus("1");
userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 5, 30));

View File

@@ -0,0 +1,22 @@
package com.chaozhanggui.system.cashierservice.service;
import com.chaozhanggui.system.cashierservice.entity.dto.UserCouponDto;
import com.chaozhanggui.system.cashierservice.sign.Result;
/**
* (TbUserCoupons)表服务接口
*
* @author ww
* @since 2024-09-02 13:38:20
*/
public interface TbUserCouponsService {
/**
* 分页查询
*
* @param tbUserCoupons 筛选条件
* @return 查询结果
*/
Result queryByPage(UserCouponDto tbUserCoupons);
}

View File

@@ -0,0 +1,70 @@
package com.chaozhanggui.system.cashierservice.service.impl;
import com.chaozhanggui.system.cashierservice.dao.TbActivateInRecordMapper;
import com.chaozhanggui.system.cashierservice.dao.TbActivateOutRecordMapper;
import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
import com.chaozhanggui.system.cashierservice.dao.TbUserCouponsMapper;
import com.chaozhanggui.system.cashierservice.entity.dto.UserCouponDto;
import com.chaozhanggui.system.cashierservice.entity.vo.ShopUserListVo;
import com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo;
import com.chaozhanggui.system.cashierservice.service.TbUserCouponsService;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* (TbUserCoupons)表服务实现类
*
* @author ww
* @since 2024-09-02 13:38:20
*/
@Primary
@Service
public class TbUserCouponsServiceImpl implements TbUserCouponsService {
@Resource
private TbUserCouponsMapper tbUserCouponsMapper;
@Resource
private TbActivateInRecordMapper inRecordMapper;
@Resource
private TbActivateOutRecordMapper outRecordMapper;
@Autowired
private TbShopUserMapper tbShopUserMapper;
/**
* 分页查询
* @return 查询结果
*/
@Override
public Result queryByPage(UserCouponDto couponDto) {
// PageHelper.startPage(couponDto.getPage(), couponDto.getSize());
// List<TbUserCoupons> result = tbUserCouponsMapper.queryAllSelective(couponDto);
// return new Result(CodeEnum.SUCCESS, new PageInfo<>(result));
// List<UserCouponVo> result = tbUserCouponsMapper.queryAllSelective(couponDto);
List<UserCouponVo> result = new ArrayList<>();
List<ShopUserListVo> tbShopUsers = tbShopUserMapper.selectByUserId(couponDto.getUserId().toString(), couponDto.getShopId()==null?null:couponDto.getShopId().toString());
if (!CollectionUtils.isEmpty(tbShopUsers)) {
tbShopUsers.forEach(s -> {
if (couponDto.getStatus()==null || (couponDto.getStatus() != null && couponDto.getStatus() != 0)) {
List<UserCouponVo> unuseCoupon = inRecordMapper.queryVipPro(s.getMemberId().intValue(), s.getShopId().intValue());
result.addAll(unuseCoupon);
}
if (couponDto.getStatus()==null || (couponDto.getStatus() != null && couponDto.getStatus() != 1)) {
List<UserCouponVo> useCoupon = outRecordMapper.queryVipPro(s.getMemberId().intValue(), s.getShopId().intValue());
result.addAll(useCoupon);
}
});
}
return new Result(CodeEnum.SUCCESS, result);
}
}

View File

@@ -39,6 +39,19 @@
group by tb_activate_in_record.pro_id
</select>
<select id="queryVipPro" resultType="com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo">
SELECT tb_product.name as detail,
0 as status,
sum(tb_activate_in_record.over_num) as num,
2 as type
FROM tb_activate_in_record
LEFT JOIN tb_product ON tb_activate_in_record.pro_id = tb_product.id
WHERE vip_user_id = #{vipUserId}
and tb_activate_in_record.shop_id = #{shopId}
and num!=0
group by tb_activate_in_record.pro_id
</select>
<select id="queryByVipIdAndShopIdAndProId" resultType="INTEGER">
SELECT
sum(tb_activate_in_record.num)

View File

@@ -27,6 +27,20 @@
where id = #{id}
</select>
<select id="queryVipPro" resultType="com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo">
SELECT tb_product.NAME AS detail,
1 AS status,
tb_activate_out_record.use_num AS num,
2 AS type
FROM tb_activate_out_record
LEFT JOIN tb_product ON tb_activate_out_record.pro_id = tb_product.id
LEFT JOIN tb_activate_in_record ON tb_activate_in_record.id = tb_activate_out_record.give_id
WHERE vip_user_id = #{vipUserId}
AND tb_activate_in_record.shop_id = #{shopId}
AND tb_activate_out_record.STATUS = 'closed'
</select>
<!--查询指定行数据-->
<select id="queryAll" resultMap="TbActivateOutRecordMap">
select

View File

@@ -414,6 +414,10 @@
select * from tb_shop_user where user_id=#{userId}
</select>
<select id="selectVipByUserId" resultMap="BaseResultMap">
select * from tb_shop_user where user_id=#{userId} and is_vip = 1
</select>
<select id="selectByOpenId" resultType="com.chaozhanggui.system.cashierservice.entity.TbShopUser">
select * from tb_shop_user where mini_open_id = #{openId}
</select>

View File

@@ -4,6 +4,7 @@
<resultMap id="BaseResultMap" type="com.chaozhanggui.system.cashierservice.entity.TbUserCoupons">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="user_id" jdbcType="VARCHAR" property="userId" />
<result column="detail" jdbcType="VARCHAR" property="detail" />
<result column="coupons_price" jdbcType="DECIMAL" property="couponsPrice" />
<result column="coupons_amount" jdbcType="DECIMAL" property="couponsAmount" />
<result column="status" jdbcType="VARCHAR" property="status" />
@@ -13,7 +14,7 @@
<result column="end_time" jdbcType="TIMESTAMP" property="endTime" />
</resultMap>
<sql id="Base_Column_List">
id, user_id, coupons_price, coupons_amount, status, create_time, update_time, end_time,is_double
id, user_id, detail, coupons_price, coupons_amount, status, create_time, update_time, end_time,is_double
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
@@ -21,6 +22,21 @@
from tb_user_coupons
where id = #{id,jdbcType=INTEGER}
</select>
<select id="queryAllSelective" resultMap="BaseResultMap">
select
detail,coupons_price as couponsPrice,coupons_amount as couponsAmount,status,1 as num,0 as type
from tb_user_coupons
<where>
<if test="userId != null and userId != ''">
and user_id = #{userId}
</if>
<if test="status != null and status != ''">
and status = #{status}
</if>
</where>
</select>
<select id="selectByUserId" resultType="com.chaozhanggui.system.cashierservice.entity.TbUserCoupons">
select * from tb_user_coupons where user_id = #{userId}
<if test="status != null and status != ''">
@@ -44,10 +60,10 @@
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.chaozhanggui.system.cashierservice.entity.TbUserCoupons" useGeneratedKeys="true" keyProperty="id">
insert into tb_user_coupons (id, user_id, coupons_price,
insert into tb_user_coupons (id, user_id, detail, coupons_price,
coupons_amount, status, create_time,
update_time, end_time,is_double)
values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=VARCHAR}, #{couponsPrice,jdbcType=DECIMAL},
values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=VARCHAR}, #{detail,jdbcType=VARCHAR}, #{couponsPrice,jdbcType=DECIMAL},
#{couponsAmount,jdbcType=DECIMAL}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}, #{isDouble,jdbcType=VARCHAR})
</insert>
@@ -60,6 +76,9 @@
<if test="userId != null">
user_id,
</if>
<if test="detail != null">
detail,
</if>
<if test="couponsPrice != null">
coupons_price,
</if>
@@ -86,6 +105,9 @@
<if test="userId != null">
#{userId,jdbcType=VARCHAR},
</if>
<if test="detail != null">
#{detail,jdbcType=VARCHAR},
</if>
<if test="couponsPrice != null">
#{couponsPrice,jdbcType=DECIMAL},
</if>
@@ -112,6 +134,9 @@
<if test="userId != null">
user_id = #{userId,jdbcType=VARCHAR},
</if>
<if test="detail != null">
detail = #{detail,jdbcType=VARCHAR},
</if>
<if test="couponsPrice != null">
coupons_price = #{couponsPrice,jdbcType=DECIMAL},
</if>
@@ -137,6 +162,7 @@
update tb_user_coupons
set user_id = #{userId,jdbcType=VARCHAR},
coupons_price = #{couponsPrice,jdbcType=DECIMAL},
detail = #{detail,jdbcType=VARCHAR},
coupons_amount = #{couponsAmount,jdbcType=DECIMAL},
status = #{status,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},