Эх сурвалжийг харах

feat:1.用户领优惠券实体,2.认领

wrj 1 жил өмнө
parent
commit
35d11c6715

+ 83 - 0
nightFragrance-admin/src/main/java/com/ylx/web/controller/massage/CouponReceiveController.java

@@ -0,0 +1,83 @@
+package com.ylx.web.controller.massage;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ylx.massage.domain.CouponReceive;
+import com.ylx.common.core.domain.R;
+import com.ylx.massage.service.CouponReceiveService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * 优惠券领取表(CouponReceive)表控制层
+ *
+ * @author makejava
+ * @since 2024-05-14 11:25:44
+ */
+@RestController
+@RequestMapping("couponReceive")
+@Slf4j
+@Api(tags = {"优惠劵认领"})
+public class CouponReceiveController {
+    /**
+     * 服务对象
+     */
+    @Resource
+    private CouponReceiveService couponReceiveService;
+
+    /**
+     * 分页查询所有数据
+     *
+     * @param page          分页对象
+     * @param couponReceive 查询实体
+     * @return 所有数据
+     */
+    @GetMapping("page")
+    @ApiOperation("分页查询优惠认领列表")
+    public R selectAll(Page<CouponReceive> page, CouponReceive couponReceive) {
+        return R.ok(this.couponReceiveService.page(page, new QueryWrapper<>(couponReceive)));
+    }
+
+    /**
+     * 通过主键查询单条数据
+     *
+     * @param id 主键
+     * @return 单条数据
+     */
+    @GetMapping("getById")
+    @ApiOperation("通过主键查询优惠认领")
+    public R selectOne(String id) {
+        return R.ok(this.couponReceiveService.getById(id));
+    }
+
+    /**
+     * 新增数据
+     *
+     * @param couponReceive 实体对象
+     * @return 新增结果
+     */
+    @PostMapping("submit")
+    @ApiOperation("领取优惠卷")
+    public R insert(@RequestBody CouponReceive couponReceive) {
+        return R.ok(this.couponReceiveService.submit(couponReceive));
+    }
+
+    /**
+     * 删除数据
+     *
+     * @param idList 主键结合
+     * @return 删除结果
+     */
+    @DeleteMapping("delete")
+    @ApiOperation("用户删除优惠卷")
+    public R delete(@RequestParam("idList") List<Long> idList) {
+        return R.ok(this.couponReceiveService.removeByIds(idList));
+    }
+}
+

+ 6 - 121
nightFragrance-massage/src/main/java/com/ylx/massage/domain/Coupon.java

@@ -3,7 +3,10 @@ package com.ylx.massage.domain;
 
 import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
+import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
@@ -15,7 +18,9 @@ import java.util.Date;
  * @author makejava
  * @since 2024-05-13 16:32:59
  */
-@SuppressWarnings("serial")
+@Setter
+@Getter
+@ApiModel(value = "Coupon" ,description = "优惠券")
 public class Coupon extends Model<Coupon> {
     //优惠券id
     @ApiModelProperty("优惠券id")
@@ -79,126 +84,6 @@ public class Coupon extends Model<Coupon> {
     private Integer isDelete;
 
 
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    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 getDiscountType() {
-        return discountType;
-    }
-
-    public void setDiscountType(Integer discountType) {
-        this.discountType = discountType;
-    }
-
-    public BigDecimal getDiscountValue() {
-        return discountValue;
-    }
-
-    public void setDiscountValue(BigDecimal discountValue) {
-        this.discountValue = discountValue;
-    }
-
-    public BigDecimal getThresholdAmount() {
-        return thresholdAmount;
-    }
-
-    public void setThresholdAmount(BigDecimal thresholdAmount) {
-        this.thresholdAmount = thresholdAmount;
-    }
-
-    public Integer getObtainWay() {
-        return obtainWay;
-    }
-
-    public void setObtainWay(Integer obtainWay) {
-        this.obtainWay = obtainWay;
-    }
-
-    public Integer getTermDays() {
-        return termDays;
-    }
-
-    public void setTermDays(Integer termDays) {
-        this.termDays = termDays;
-    }
-
-    public Integer getStatus() {
-        return status;
-    }
-
-    public void setStatus(Integer status) {
-        this.status = status;
-    }
-
-    public Integer getUsedNum() {
-        return usedNum;
-    }
-
-    public void setUsedNum(Integer usedNum) {
-        this.usedNum = usedNum;
-    }
-
-    public Integer getUserLimit() {
-        return userLimit;
-    }
-
-    public void setUserLimit(Integer userLimit) {
-        this.userLimit = userLimit;
-    }
-
-    public String getExtParam() {
-        return extParam;
-    }
-
-    public void setExtParam(String extParam) {
-        this.extParam = extParam;
-    }
-
-    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 Integer getIsDelete() {
-        return isDelete;
-    }
-
-    public void setIsDelete(Integer isDelete) {
-        this.isDelete = isDelete;
-    }
-
     /**
      * 获取主键值
      *

+ 65 - 0
nightFragrance-massage/src/main/java/com/ylx/massage/domain/CouponReceive.java

@@ -0,0 +1,65 @@
+package com.ylx.massage.domain;
+
+
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 优惠券领取表(CouponReceive)表实体类
+ *
+ * @author makejava
+ * @since 2024-05-14 11:25:44
+ */
+@Setter
+@Getter
+@ApiModel(value = "CouponReceive" ,description = "优惠券领取")
+public class CouponReceive extends Model<CouponReceive> {
+    //主键
+    @ApiModelProperty("id")
+    private String id;
+
+    //用户openId
+    @ApiModelProperty("用户openId")
+    private String openid;
+
+    //优惠券id
+    @ApiModelProperty("优惠券id")
+    private String couponId;
+
+    //过期时间
+    @ApiModelProperty("过期时间")
+    private Date expirationTime;
+
+    //创建时间
+    @ApiModelProperty("创建时间")
+    private Date createTime;
+
+    //修改时间
+    @ApiModelProperty("修改时间")
+    private Date updateTime;
+
+    //是否删除0否1是
+    @ApiModelProperty("是否删除0否1是")
+    @TableLogic
+    private Integer isDelete;
+
+
+    /**
+     * 获取主键值
+     *
+     * @return 主键值
+     */
+    @Override
+    public Serializable pkVal() {
+        return this.id;
+    }
+}
+

+ 35 - 0
nightFragrance-massage/src/main/java/com/ylx/massage/mapper/CouponReceiveMapper.java

@@ -0,0 +1,35 @@
+package com.ylx.massage.mapper;
+
+import java.util.List;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+import com.ylx.massage.domain.CouponReceive;
+
+/**
+ * 优惠券领取表(CouponReceive)表数据库访问层
+ *
+ * @author makejava
+ * @since 2024-05-14 11:25:44
+ */
+public interface CouponReceiveMapper extends BaseMapper<CouponReceive> {
+
+    /**
+     * 批量新增数据(MyBatis原生foreach方法)
+     *
+     * @param entities List<CouponReceive> 实例对象列表
+     * @return 影响行数
+     */
+    int insertBatch(@Param("entities") List<CouponReceive> entities);
+
+    /**
+     * 批量新增或按主键更新数据(MyBatis原生foreach方法)
+     *
+     * @param entities List<CouponReceive> 实例对象列表
+     * @return 影响行数
+     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参
+     */
+    int insertOrUpdateBatch(@Param("entities") List<CouponReceive> entities);
+
+}
+

+ 17 - 0
nightFragrance-massage/src/main/java/com/ylx/massage/service/CouponReceiveService.java

@@ -0,0 +1,17 @@
+package com.ylx.massage.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ylx.massage.domain.Coupon;
+import com.ylx.massage.domain.CouponReceive;
+
+/**
+ * 优惠券领取表(CouponReceive)表服务接口
+ *
+ * @author makejava
+ * @since 2024-05-14 11:25:45
+ */
+public interface CouponReceiveService extends IService<CouponReceive> {
+
+    Coupon submit(CouponReceive couponReceive);
+}
+

+ 47 - 0
nightFragrance-massage/src/main/java/com/ylx/massage/service/impl/CouponReceiveServiceImpl.java

@@ -0,0 +1,47 @@
+package com.ylx.massage.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ylx.massage.domain.Coupon;
+import com.ylx.massage.mapper.CouponReceiveMapper;
+import com.ylx.massage.domain.CouponReceive;
+import com.ylx.massage.service.CouponReceiveService;
+import com.ylx.massage.service.CouponService;
+import com.ylx.massage.utils.DateTimeUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 优惠券领取表(CouponReceive)表服务实现类
+ *
+ * @author makejava
+ * @since 2024-05-14 11:25:45
+ */
+@Service("couponReceiveService")
+public class CouponReceiveServiceImpl extends ServiceImpl<CouponReceiveMapper, CouponReceive> implements CouponReceiveService {
+
+    @Resource
+    private CouponService couponService;
+
+    @Override
+    public Coupon submit(CouponReceive couponReceive) {
+        LambdaQueryWrapper<CouponReceive> queryWrapper = new LambdaQueryWrapper<>();
+        Coupon coupon = couponService.getById(couponReceive.getCouponId());
+        if (coupon == null) {
+            return null;
+        }
+        queryWrapper.eq(CouponReceive::getOpenid, couponReceive.getOpenid()).eq(CouponReceive::getCouponId, couponReceive.getCouponId());
+        //限制没人只能领x张
+        List<CouponReceive> one = this.list(queryWrapper);
+        if (coupon.getUserLimit() >= one.size()) {
+            return null;
+        }
+        couponReceive.setExpirationTime(DateTimeUtils.addDays(new Date(), coupon.getTermDays()));
+        this.save(couponReceive);
+        return coupon;
+    }
+}
+

+ 3 - 0
nightFragrance-massage/src/main/java/com/ylx/massage/service/impl/TOrderServiceImpl.java

@@ -114,6 +114,9 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
                 order.setFare(bigDecimal.setScale(MassageConstants.INTEGER_TWO, RoundingMode.HALF_UP));
             }
         }
+        //优惠卷减免
+
+
         //订单价格
         List<TXiangmu> list = JSONObject.parseArray(order.getcGoods().toJSONString(), TXiangmu.class);
         BigDecimal sum = list.stream().map(TXiangmu::getSum).reduce(BigDecimal.ZERO, BigDecimal::add);

+ 0 - 4
nightFragrance-massage/src/main/java/com/ylx/massage/utils/DateTimeUtils.java

@@ -53,10 +53,6 @@ public final class DateTimeUtils {
         return formatDate(date, TIME);
     }
 
-    public static void main(String[] args) {
-        System.out.println(numTime(new Date()));
-        System.out.println(Long.valueOf("0523"));
-    }
 
     public static String formatDatetime() {
         return formatDate(DATE_TIME_FORMAT);

+ 36 - 0
nightFragrance-massage/src/main/resources/mapper/massage/CouponReceiveMapper.xml

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ylx.massage.mapper.CouponReceiveMapper">
+
+    <resultMap type="com.ylx.massage.domain.CouponReceive" id="CouponReceiveMap">
+        <result property="id" column="id" jdbcType="VARCHAR"/>
+        <result property="openid" column="openid" jdbcType="VARCHAR"/>
+        <result property="couponId" column="coupon_id" jdbcType="VARCHAR"/>
+        <result property="expirationTime" column="expiration_time" jdbcType="TIMESTAMP"/>
+        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
+        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
+        <result property="isDelete" column="is_delete" jdbcType="INTEGER"/>
+    </resultMap>
+
+    <!-- 批量插入 -->
+    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
+        insert into ry-vue.coupon_receive(openidcoupon_idexpiration_timecreate_timeupdate_timeis_delete)
+        values
+        <foreach collection="entities" item="entity" separator=",">
+            (#{entity.openid}#{entity.couponId}#{entity.expirationTime}#{entity.createTime}#{entity.updateTime}#{entity.isDelete})
+        </foreach>
+    </insert>
+    <!-- 批量插入或按主键更新 -->
+    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
+        insert into ry-vue.coupon_receive(openidcoupon_idexpiration_timecreate_timeupdate_timeis_delete)
+        values
+        <foreach collection="entities" item="entity" separator=",">
+            (#{entity.openid}#{entity.couponId}#{entity.expirationTime}#{entity.createTime}#{entity.updateTime}#{entity.isDelete})
+        </foreach>
+        on duplicate key update
+        openid = values(openid) coupon_id = values(coupon_id) expiration_time = values(expiration_time) create_time =
+        values(create_time) update_time = values(update_time) is_delete = values(is_delete)
+    </insert>
+
+</mapper>
+