原作废代码 删除
This commit is contained in:
parent
e9fa387e02
commit
65ba0e18ce
|
|
@ -1,86 +0,0 @@
|
|||
package com.czg.controller.admin;
|
||||
|
||||
import com.czg.account.dto.ShopActivateDTO;
|
||||
import com.czg.account.service.ShopActivateService;
|
||||
import com.czg.annotation.SaAdminCheckPermission;
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.RedisService;
|
||||
import com.czg.service.account.util.WechatAuthUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 店铺充值活动管理
|
||||
*
|
||||
* @author ww
|
||||
* @description
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/activate")
|
||||
public class ShopActivateController {
|
||||
@Resource
|
||||
private ShopActivateService shopActivateService;
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
@Resource
|
||||
private WechatAuthUtil wechatUtil;
|
||||
|
||||
/**
|
||||
* 店铺充值活动列表
|
||||
* 权限标识: activate:list
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "activate:list", name = "店铺充值活动列表")
|
||||
@GetMapping
|
||||
public CzgResult<List<ShopActivateDTO>> detail(@RequestParam(required = false) Long shopId) {
|
||||
return CzgResult.success(shopActivateService.getList(shopId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 店铺充值活动新增
|
||||
* 权限标识: activate:add
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "activate:add", name = "店铺充值活动新增")
|
||||
@PostMapping
|
||||
public CzgResult<Boolean> add(@RequestBody @Validated ShopActivateDTO activateDTO) {
|
||||
activateDTO.setShopId(StpKit.USER.getShopId());
|
||||
return CzgResult.success(shopActivateService.add(activateDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 店铺充值活动修改
|
||||
* 权限标识: activate:edit
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "activate:edit", name = "店铺充值活动修改")
|
||||
@PutMapping
|
||||
public CzgResult<Boolean> edit(@RequestBody @Validated ShopActivateDTO activateDTO) {
|
||||
return CzgResult.success(shopActivateService.edit(activateDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员码
|
||||
* @param params shopId 必填
|
||||
* env_version 存在即生成体验版
|
||||
*/
|
||||
@PostMapping("/getVipCode")
|
||||
public CzgResult<Object> getVipCode(@RequestBody Map<String, Object> params) throws Exception {
|
||||
if (CollectionUtils.isEmpty(params) || !params.containsKey("shopId")) {
|
||||
throw new CzgException("参数错误");
|
||||
}
|
||||
String redisKey = RedisCst.SHOP_VIP_CODE + params.get("shopId");
|
||||
if (redisService.hasKey(redisKey)) {
|
||||
return CzgResult.success(redisService.get(redisKey));
|
||||
}
|
||||
return CzgResult.success(wechatUtil.getFetchQrCode(params));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
package com.czg.controller.admin;
|
||||
|
||||
import com.czg.account.dto.QueryReceiveDto;
|
||||
import com.czg.account.dto.ShopCouponDTO;
|
||||
import com.czg.account.service.ShopCouponService;
|
||||
import com.czg.account.vo.CouponReceiveVo;
|
||||
import com.czg.account.vo.UserCouponVo;
|
||||
import com.czg.annotation.SaAdminCheckPermission;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 店铺优惠券
|
||||
*
|
||||
* @author ww
|
||||
* @description
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/coupon")
|
||||
public class ShopCouponController {
|
||||
@Resource
|
||||
private ShopCouponService couponService;
|
||||
|
||||
/**
|
||||
* 店铺优惠券列表
|
||||
* 权限标识: coupon:list
|
||||
* 状态 0 未使用 1已使用 2已过期
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "coupon:list", name = "优惠券列表")
|
||||
@GetMapping
|
||||
public CzgResult<List<ShopCouponDTO>> detail(@RequestParam(required = false) Integer type,
|
||||
@RequestParam(required = false) Integer status) {
|
||||
return CzgResult.success(couponService.getList(StpKit.USER.getShopId(), type, status));
|
||||
}
|
||||
|
||||
/**
|
||||
* 店铺优惠券新增
|
||||
* 权限标识: coupon:add
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "coupon:add", name = "优惠券添加")
|
||||
@PostMapping
|
||||
public CzgResult<Boolean> add(@RequestBody @Validated ShopCouponDTO couponDTO) {
|
||||
couponDTO.setShopId(StpKit.USER.getShopId());
|
||||
return CzgResult.success(couponService.add(couponDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 店铺优惠券修改
|
||||
* 权限标识: coupon:edit
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "coupon:edit", name = "优惠券修改")
|
||||
@PutMapping
|
||||
public CzgResult<Boolean> edit(@RequestBody @Validated ShopCouponDTO couponDTO) {
|
||||
couponDTO.setShopId(StpKit.USER.getShopId());
|
||||
return CzgResult.success(couponService.edit(couponDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 店铺优惠券获取记录
|
||||
* 权限标识: coupon:delete
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "coupon:queryReceive", name = "优惠券领取记录")
|
||||
@GetMapping("/queryReceive")
|
||||
public CzgResult<Page<CouponReceiveVo>> queryReceive(@Validated QueryReceiveDto param) {
|
||||
return CzgResult.success(couponService.queryReceive(param));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成订单后使用
|
||||
* 通过用户Id 查找优惠券
|
||||
*
|
||||
* @param shopUserId 店铺用户Id
|
||||
*/
|
||||
@GetMapping("/findCoupon")
|
||||
public CzgResult<List<UserCouponVo>> findCoupon(@RequestParam Long shopUserId, @RequestParam(required = false) Integer type) {
|
||||
return CzgResult.success(couponService.findCoupon(StpKit.USER.getShopId(), shopUserId, type));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
package com.czg.controller.user;
|
||||
|
||||
import com.czg.account.dto.ShopActivateDTO;
|
||||
import com.czg.account.service.ShopActivateService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户店铺充值活动管理
|
||||
*
|
||||
* @author ww
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user/activate")
|
||||
public class UserShopActivateController {
|
||||
@Resource
|
||||
private ShopActivateService shopActivateService;
|
||||
|
||||
/**
|
||||
* 店铺充值活动列表
|
||||
*/
|
||||
@GetMapping
|
||||
public CzgResult<List<ShopActivateDTO>> detail(@RequestParam(required = false) Long shopId) {
|
||||
return CzgResult.success(shopActivateService.getList(shopId));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package com.czg.controller.user;
|
||||
|
||||
import com.czg.account.entity.ShopActivateCouponRecord;
|
||||
import com.czg.account.service.ShopCouponService;
|
||||
import com.czg.account.vo.UserCouponVo;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 店铺优惠券
|
||||
*
|
||||
* @author ww
|
||||
* @description
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/coupon")
|
||||
public class UserShopCouponController {
|
||||
@Resource
|
||||
private ShopCouponService couponService;
|
||||
|
||||
/**
|
||||
* 通过用户Id 查找优惠券
|
||||
*
|
||||
* @param status 0 未使用 1已使用 2已过期
|
||||
*/
|
||||
@GetMapping("/findByUserId")
|
||||
public CzgResult<Page<ShopActivateCouponRecord>> findByUserId(
|
||||
@RequestParam(required = false) Integer status,
|
||||
@RequestParam(required = false) Long shopId) {
|
||||
return CzgResult.success(couponService.find(StpKit.USER.getLoginIdAsLong(), shopId, status));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成订单后使用
|
||||
* 通过用户Id 查找优惠券
|
||||
*
|
||||
* @param shopUserId 店铺用户Id
|
||||
*/
|
||||
@GetMapping("/findCoupon")
|
||||
public CzgResult<List<UserCouponVo>> findCoupon(@RequestHeader String shopId, @RequestParam Long shopUserId, @RequestParam(required = false) Integer type) {
|
||||
AssertUtil.isBlank(shopId, "店铺Id不能为空");
|
||||
return CzgResult.success(couponService.findCoupon(Long.parseLong(shopId), shopUserId, type));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
|
||||
package com.czg.account.dto;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.czg.account.entity.ShopCoupon;
|
||||
import com.czg.validator.group.InsertGroup;
|
||||
import com.czg.validator.group.UpdateGroup;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 活动 实体类。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-02-20
|
||||
*/
|
||||
@Data
|
||||
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ShopActivateDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull(message = "主键不能为空", groups = {UpdateGroup.class})
|
||||
private Long id;
|
||||
|
||||
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 充值金额
|
||||
*/
|
||||
@NotNull(message = "充值金额不能为空", groups = {InsertGroup.class, UpdateGroup.class})
|
||||
private BigDecimal amount;
|
||||
|
||||
/**
|
||||
* 赠送金额
|
||||
*/
|
||||
private BigDecimal giftAmount;
|
||||
|
||||
/**
|
||||
* 赠送积分
|
||||
*/
|
||||
private Integer giftPoints;
|
||||
|
||||
/**
|
||||
* 是否赠送优惠卷 0否 1是
|
||||
*/
|
||||
private Integer isGiftCoupon;
|
||||
|
||||
private List<ShopCoupon> couponList;
|
||||
private String coupons;
|
||||
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
}
|
||||
|
|
@ -1,146 +0,0 @@
|
|||
|
||||
package com.czg.account.dto;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 优惠券 实体类。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-02-17
|
||||
*/
|
||||
@Data
|
||||
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ShopCouponDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 自增
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 状态0-关闭 1 正常
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 名称(无意义)
|
||||
*/
|
||||
private String title;
|
||||
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 已使用数量
|
||||
*/
|
||||
private Integer useNumber;
|
||||
|
||||
/**
|
||||
* 发放数量
|
||||
*/
|
||||
private Integer number;
|
||||
|
||||
/**
|
||||
* 剩余数量
|
||||
*/
|
||||
private Integer leftNumber;
|
||||
|
||||
/**
|
||||
* 有效期类型,可选值为 fixed(固定时间)/custom(自定义时间)
|
||||
*/
|
||||
private String validityType;
|
||||
|
||||
/**
|
||||
* 有效天数
|
||||
*/
|
||||
private Integer validDays;
|
||||
|
||||
/**
|
||||
* 隔多少天生效
|
||||
*/
|
||||
private Integer daysToTakeEffect;
|
||||
|
||||
/**
|
||||
* 有效开始时间
|
||||
*/
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime validStartTime;
|
||||
|
||||
/**
|
||||
* 有效结束时间
|
||||
*/
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime validEndTime;
|
||||
|
||||
/**
|
||||
* 周 数组["周一","周二"]
|
||||
*/
|
||||
private String userDays;
|
||||
|
||||
/**
|
||||
* all-全时段 custom-指定时段
|
||||
*/
|
||||
private String useTimeType;
|
||||
|
||||
/**
|
||||
* 可用开始时间
|
||||
*/
|
||||
private String useStartTime;
|
||||
|
||||
/**
|
||||
* 可用结束时间
|
||||
*/
|
||||
private String useEndTime;
|
||||
|
||||
/**
|
||||
* 1-满减 2-商品
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 满多少金额
|
||||
*/
|
||||
private BigDecimal fullAmount;
|
||||
|
||||
/**
|
||||
* 减多少金额
|
||||
*/
|
||||
private BigDecimal discountAmount;
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Long proId;
|
||||
private String proName;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 发放人
|
||||
*/
|
||||
private String editor;
|
||||
|
||||
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
|
||||
package com.czg.account.dto;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 活动赠送商品表 实体类。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-02-18
|
||||
*/
|
||||
@Data
|
||||
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ShopCouponProductDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 活动Id
|
||||
*/
|
||||
private Long couponId;
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Long productId;
|
||||
|
||||
/**
|
||||
* 数量
|
||||
*/
|
||||
private Integer num;
|
||||
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
}
|
||||
|
|
@ -1,148 +0,0 @@
|
|||
package com.czg.account.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.time.LocalTime;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 优惠券 实体类。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-02-20
|
||||
*/
|
||||
@Data
|
||||
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("tb_shop_coupon")
|
||||
public class ShopCoupon implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 自增
|
||||
*/
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Long id;
|
||||
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 名称(无意义)
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 1-满减 2-商品
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 状态0-关闭 1 正常
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 已使用数量
|
||||
*/
|
||||
private Integer useNumber;
|
||||
|
||||
/**
|
||||
* 发放数量
|
||||
*/
|
||||
private Integer number;
|
||||
|
||||
/**
|
||||
* 剩余数量
|
||||
*/
|
||||
private Integer leftNumber;
|
||||
|
||||
/**
|
||||
* 有效期类型,可选值为 fixed(固定时间)/custom(自定义时间)
|
||||
*/
|
||||
private String validityType;
|
||||
|
||||
/**
|
||||
* 有效天数
|
||||
*/
|
||||
private Integer validDays;
|
||||
|
||||
/**
|
||||
* 隔多少天生效
|
||||
*/
|
||||
private Integer daysToTakeEffect;
|
||||
|
||||
/**
|
||||
* 有效开始时间
|
||||
*/
|
||||
private LocalDateTime validStartTime;
|
||||
|
||||
/**
|
||||
* 有效结束时间
|
||||
*/
|
||||
private LocalDateTime validEndTime;
|
||||
|
||||
/**
|
||||
* 周 数组["周一","周二"]
|
||||
*/
|
||||
private String userDays;
|
||||
|
||||
/**
|
||||
* all-全时段 custom-指定时段
|
||||
*/
|
||||
private String useTimeType;
|
||||
|
||||
/**
|
||||
* 可用开始时间
|
||||
*/
|
||||
private LocalTime useStartTime;
|
||||
|
||||
/**
|
||||
* 可用结束时间
|
||||
*/
|
||||
private LocalTime useEndTime;
|
||||
|
||||
/**
|
||||
* 满多少金额
|
||||
*/
|
||||
private BigDecimal fullAmount;
|
||||
|
||||
/**
|
||||
* 减多少金额
|
||||
*/
|
||||
private BigDecimal discountAmount;
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Long proId;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 发放人
|
||||
*/
|
||||
private String editor;
|
||||
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
package com.czg.account.service;
|
||||
|
||||
import com.czg.account.dto.ShopActivateDTO;
|
||||
import com.czg.account.entity.ShopActivate;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 活动 服务层。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-02-17
|
||||
*/
|
||||
public interface ShopActivateService extends IService<ShopActivate> {
|
||||
|
||||
List<ShopActivateDTO> getList(Long shopId);
|
||||
|
||||
Boolean add(ShopActivateDTO activateDTO);
|
||||
|
||||
Boolean edit(ShopActivateDTO activateDTO);
|
||||
|
||||
/**
|
||||
* @param memAmount 充值金额
|
||||
* @param activateId 参加活动Id
|
||||
* @param relationId 关联Id
|
||||
* 霸王餐时 订单id
|
||||
* 充值奖励 的关联id 是tb_shop_user_flow的充值 记录id
|
||||
* 支付/退款 tb_order_payment.id
|
||||
*/
|
||||
void giveActivate(ShopUser shopUser, BigDecimal memAmount, Long activateId, Long relationId);
|
||||
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
package com.czg.account.service;
|
||||
|
||||
import com.czg.account.dto.QueryReceiveDto;
|
||||
import com.czg.account.dto.ShopCouponDTO;
|
||||
import com.czg.account.entity.ShopActivateCouponRecord;
|
||||
import com.czg.account.entity.ShopCoupon;
|
||||
import com.czg.account.vo.CouponReceiveVo;
|
||||
import com.czg.account.vo.UserCouponVo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 优惠券 服务层。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-02-17
|
||||
*/
|
||||
public interface ShopCouponService extends IService<ShopCoupon> {
|
||||
|
||||
/**
|
||||
* 优惠券列表
|
||||
*
|
||||
* @param shopId 店铺id
|
||||
* @param type 1-满减 2-商品
|
||||
* @param status 状态 0 未使用 1已使用 -1已过期
|
||||
*/
|
||||
List<ShopCouponDTO> getList(Long shopId, Integer type, Integer status);
|
||||
|
||||
Boolean add(ShopCouponDTO couponDTO);
|
||||
|
||||
Boolean edit(ShopCouponDTO couponDTO);
|
||||
|
||||
Page<CouponReceiveVo> queryReceive(QueryReceiveDto param);
|
||||
|
||||
|
||||
Page<ShopActivateCouponRecord> find(Long userId,Long shopId, Integer status);
|
||||
|
||||
List<UserCouponVo> findCoupon(Long shopId, Long shopUserId, Integer type);
|
||||
|
||||
Boolean use(List<Long> ids, Long shopUserId, Long orderId);
|
||||
|
||||
Boolean refund(Long orderId, Long shopUserId);
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
package com.czg.service.account.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.account.entity.ShopCoupon;
|
||||
|
||||
/**
|
||||
* 优惠券 映射层。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-02-17
|
||||
*/
|
||||
public interface ShopCouponMapper extends BaseMapper<ShopCoupon> {
|
||||
|
||||
}
|
||||
|
|
@ -1,191 +0,0 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
import com.czg.account.dto.ShopActivateDTO;
|
||||
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
|
||||
import com.czg.account.entity.ShopActivate;
|
||||
import com.czg.account.entity.ShopActivateCouponRecord;
|
||||
import com.czg.account.entity.ShopCoupon;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.service.*;
|
||||
import com.czg.enums.ShopUserFlowBizEnum;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.account.mapper.ShopActivateMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 活动 服务层实现。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-02-17
|
||||
*/
|
||||
@Slf4j
|
||||
@DubboService
|
||||
public class ShopActivateServiceImpl extends ServiceImpl<ShopActivateMapper, ShopActivate> implements ShopActivateService {
|
||||
|
||||
@Resource
|
||||
private ShopCouponService couponService;
|
||||
@Resource
|
||||
private ShopActivateCouponRecordService inRecordService;
|
||||
@Resource
|
||||
private ShopUserService shopUserService;
|
||||
@Resource
|
||||
private MemberPointsService pointsService;
|
||||
|
||||
@Override
|
||||
public List<ShopActivateDTO> getList(Long shopId) {
|
||||
List<ShopActivateDTO> activateDtoS = queryChain().select()
|
||||
.eq(ShopActivate::getShopId, shopId == null ? StpKit.USER.getShopId() : shopId)
|
||||
.orderBy(ShopActivate::getAmount, true)
|
||||
.listAs(ShopActivateDTO.class);
|
||||
for (ShopActivateDTO activateDTO : activateDtoS) {
|
||||
if (StrUtil.isNotBlank(activateDTO.getCoupons())) {
|
||||
//组装优惠券
|
||||
activateDTO.setCouponList(getCoupons(activateDTO.getCoupons()));
|
||||
}
|
||||
}
|
||||
return activateDtoS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean add(ShopActivateDTO activateDTO) {
|
||||
ShopActivate shopActivate = new ShopActivate();
|
||||
BeanUtil.copyProperties(activateDTO, shopActivate);
|
||||
return save(shopActivate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean edit(ShopActivateDTO activateDTO) {
|
||||
ShopActivate shopActivate = new ShopActivate();
|
||||
BeanUtil.copyProperties(activateDTO, shopActivate);
|
||||
return updateById(shopActivate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveActivate(ShopUser shopUser, BigDecimal memAmount, Long activateId, Long relationId) {
|
||||
if (activateId == null) {
|
||||
return;
|
||||
}
|
||||
ShopActivate activate = getById(activateId);
|
||||
if (ObjectUtil.isNull(activate)) {
|
||||
return;
|
||||
}
|
||||
//赠送优惠券
|
||||
if (activate.getIsGiftCoupon() == 1 && StrUtil.isNotBlank(activate.getCoupons())) {
|
||||
Map<Long, Integer> couponUseMap = JSONObject.parseObject(activate.getCoupons(), new TypeReference<>() {
|
||||
});
|
||||
Map<Long, ShopCoupon> couponMap = new HashMap<>();
|
||||
couponUseMap.forEach((couponId, giftNumber) -> {
|
||||
ShopCoupon shopCoupon;
|
||||
if (couponMap.containsKey(couponId)) {
|
||||
shopCoupon = couponMap.get(couponId);
|
||||
} else {
|
||||
shopCoupon = couponService.queryChain().select().eq(ShopCoupon::getId, couponId).one();
|
||||
couponMap.put(couponId, shopCoupon);
|
||||
}
|
||||
if (shopCoupon != null && shopCoupon.getStatus().equals(1) && shopCoupon.getLeftNumber() > giftNumber) {
|
||||
LocalDateTime start = LocalDateTime.now().with(LocalTime.MIN);
|
||||
LocalDateTime end = null;
|
||||
if ("fixed".equals(shopCoupon.getValidityType())) {
|
||||
//固定时间
|
||||
end = LocalDateTimeUtil.offset(start, shopCoupon.getValidDays(), ChronoUnit.DAYS).with(LocalTime.MAX);
|
||||
} else if ("custom".equals(shopCoupon.getValidityType())) {
|
||||
//自定义时间
|
||||
start = shopCoupon.getValidStartTime();
|
||||
end = shopCoupon.getValidEndTime();
|
||||
}
|
||||
List<ShopActivateCouponRecord> actGiveRecords = new ArrayList<>();
|
||||
ShopActivateCouponRecord record = new ShopActivateCouponRecord();
|
||||
record.setShopUserId(shopUser.getId());
|
||||
record.setCouponId(shopCoupon.getId());
|
||||
record.setShopId(shopUser.getShopId());
|
||||
record.setSourceActId(activate.getId());
|
||||
record.setSourceFlowId(relationId);
|
||||
record.setUseStartTime(start);
|
||||
record.setUseEndTime(end);
|
||||
record.setSource("activate");
|
||||
record.setName(shopCoupon.getTitle());
|
||||
record.setCouponJson(getCouponJson(activate, shopCoupon));
|
||||
if (shopCoupon.getType() == 1) {
|
||||
record.setType(1);
|
||||
record.setFullAmount(shopCoupon.getFullAmount());
|
||||
record.setDiscountAmount(shopCoupon.getDiscountAmount());
|
||||
} else if (shopCoupon.getType() == 2) {
|
||||
record.setType(2);
|
||||
record.setProId(shopCoupon.getProId());
|
||||
}
|
||||
for (int i = 0; i < giftNumber; i++) {
|
||||
actGiveRecords.add(record);
|
||||
}
|
||||
inRecordService.saveBatch(actGiveRecords);
|
||||
couponService.updateChain()
|
||||
.set(ShopCoupon::getLeftNumber, shopCoupon.getLeftNumber() - giftNumber)
|
||||
.eq(ShopCoupon::getId, shopCoupon.getId())
|
||||
.update();
|
||||
}
|
||||
});
|
||||
}
|
||||
//赠送金额
|
||||
if (activate.getGiftAmount() != null && activate.getGiftAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO()
|
||||
.setId(shopUser.getId())
|
||||
.setMoney(activate.getGiftAmount())
|
||||
.setType(1)
|
||||
.setRemark("充值活动赠送")
|
||||
.setRelationId(relationId)
|
||||
.setBizEnum(ShopUserFlowBizEnum.AWARD_IN);
|
||||
//更新会员余额 并生成流水
|
||||
shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
|
||||
}
|
||||
if (activate.getGiftPoints() != null && activate.getGiftPoints() > 0) {
|
||||
pointsService.addPoints(shopUser.getId(), activate.getGiftPoints(), "储值赠送积分", null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取优惠券详细信息 目前仅返回 id 名称 剩余数量 赠送数量
|
||||
*/
|
||||
private List<ShopCoupon> getCoupons(String couponJson) {
|
||||
Map<String, Integer> couponMap;
|
||||
try {
|
||||
couponMap = JSONObject.parseObject(couponJson, new TypeReference<>() {
|
||||
});
|
||||
} catch (Exception e) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
if (couponMap.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<ShopCoupon> list = couponService.queryChain()
|
||||
.select(ShopCoupon::getId, ShopCoupon::getTitle, ShopCoupon::getLeftNumber)
|
||||
.in(ShopCoupon::getId, couponMap.keySet())
|
||||
.list();
|
||||
list.forEach(coupon -> coupon.setNumber(couponMap.get(coupon.getId().toString())));
|
||||
return list;
|
||||
}
|
||||
|
||||
private String getCouponJson(ShopActivate activate, ShopCoupon tbShopCoupon) {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("activate", JSONObject.toJSONString(activate));
|
||||
result.put("coupon", JSONObject.toJSONString(tbShopCoupon));
|
||||
return result.toJSONString();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,222 +1,216 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.account.dto.QueryReceiveDto;
|
||||
import com.czg.account.dto.ShopCouponDTO;
|
||||
import com.czg.account.entity.ShopActivateCouponRecord;
|
||||
import com.czg.account.entity.ShopCoupon;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.service.ShopActivateCouponRecordService;
|
||||
import com.czg.account.service.ShopCouponService;
|
||||
import com.czg.account.service.ShopInfoService;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.account.vo.CouponReceiveVo;
|
||||
import com.czg.account.vo.UserCouponVo;
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.service.ProductService;
|
||||
import com.czg.service.account.mapper.ShopCouponMapper;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 优惠券 服务层实现。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-02-17
|
||||
*/
|
||||
@Slf4j
|
||||
@DubboService
|
||||
public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCoupon> implements ShopCouponService {
|
||||
|
||||
@Resource
|
||||
private ShopActivateCouponRecordService couponRecordService;
|
||||
@Resource
|
||||
private ShopUserService shopUserService;
|
||||
@Resource
|
||||
private ShopInfoService shopInfoService;
|
||||
@DubboReference
|
||||
private ProductService productService;
|
||||
|
||||
@Override
|
||||
public List<ShopCouponDTO> getList(Long shopId, Integer type, Integer status) {
|
||||
List<ShopCouponDTO> coupons = queryChain().select()
|
||||
.eq(ShopCoupon::getShopId, shopId)
|
||||
.eq(ShopCoupon::getType, type)
|
||||
.eq(ShopCoupon::getStatus, status)
|
||||
.orderBy(ShopCoupon::getCreateTime).desc()
|
||||
.listAs(ShopCouponDTO.class);
|
||||
System.out.println(coupons);
|
||||
coupons.forEach(coupon -> {
|
||||
if (coupon.getProId() != null) {
|
||||
Product product = productService.getById(coupon.getProId());
|
||||
coupon.setProName(product.getName());
|
||||
}
|
||||
});
|
||||
return coupons;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean add(ShopCouponDTO couponDTO) {
|
||||
ShopCoupon shopCoupon = new ShopCoupon();
|
||||
BeanUtil.copyProperties(couponDTO, shopCoupon);
|
||||
shopCoupon.setLeftNumber(shopCoupon.getNumber());
|
||||
return save(shopCoupon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean edit(ShopCouponDTO couponDTO) {
|
||||
ShopCoupon shopCoupon = new ShopCoupon();
|
||||
BeanUtil.copyProperties(couponDTO, shopCoupon);
|
||||
if (couponDTO.getNumber() != null) {
|
||||
ShopCoupon tbShopCoupon = getById(couponDTO.getId());
|
||||
if (shopCoupon.getNumber() < tbShopCoupon.getNumber()) {
|
||||
throw new ValidateException("修改失败 发放数量不可减少");
|
||||
} else {
|
||||
shopCoupon.setLeftNumber(shopCoupon.getLeftNumber() + shopCoupon.getNumber() - tbShopCoupon.getNumber());
|
||||
}
|
||||
}
|
||||
return updateById(shopCoupon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<CouponReceiveVo> queryReceive(QueryReceiveDto param) {
|
||||
Page<Object> page = PageUtil.buildPage();
|
||||
PageHelper.startPage(Math.toIntExact(page.getPageNumber()), Math.toIntExact(page.getPageSize()));
|
||||
return PageUtil.convert(new PageInfo<>(couponRecordService.queryReceive(param)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Page<ShopActivateCouponRecord> find(Long userId, Long shopId, Integer status) {
|
||||
Page<Object> page = PageUtil.buildPage();
|
||||
List<Long> shopUserIds = shopUserService.queryChain()
|
||||
.eq(ShopUser::getUserId, userId)
|
||||
.eq(ShopUser::getShopId, shopId)
|
||||
.select(ShopUser::getId).listAs(Long.class);
|
||||
if (CollectionUtil.isNotEmpty(shopUserIds)) {
|
||||
PageHelper.startPage(Math.toIntExact(page.getPageNumber()), Math.toIntExact(page.getPageSize()));
|
||||
return PageUtil.convert(new PageInfo<>(couponRecordService.findByUser(shopUserIds, status)));
|
||||
}
|
||||
return new Page<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserCouponVo> findCoupon(Long shopId, Long shopUserId, Integer type) {
|
||||
List<UserCouponVo> tbUserCouponVos = couponRecordService.queryByVipIdAndShopId(shopId, shopUserId, type);
|
||||
if (CollectionUtil.isNotEmpty(tbUserCouponVos)) {
|
||||
String week = DateUtil.dayOfWeekEnum(new Date()).toChinese("周");
|
||||
LocalTime now = LocalTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||
|
||||
//券id 券使用描述
|
||||
Map<Long, JSONObject> coupons = new HashMap<>();
|
||||
for (UserCouponVo tbUserCouponVo : tbUserCouponVos) {
|
||||
if (!coupons.containsKey(tbUserCouponVo.getCouponId())) {
|
||||
setCouponInfo(coupons, tbUserCouponVo, null, week, now, formatter);
|
||||
}
|
||||
JSONObject couponJson = coupons.get(tbUserCouponVo.getCouponId());
|
||||
tbUserCouponVo.setUseRestrictions(couponJson.getString("useRestrictions"));
|
||||
tbUserCouponVo.setUse(couponJson.getBoolean("isUse"));
|
||||
|
||||
}
|
||||
tbUserCouponVos.sort(Comparator.comparing(UserCouponVo::isUse).reversed());
|
||||
return tbUserCouponVos;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean use(List<Long> ids, Long shopUserId, Long orderId) {
|
||||
List<ShopActivateCouponRecord> records = couponRecordService.listByIds(ids);
|
||||
if (records.isEmpty()) {
|
||||
log.error("优惠券使用失败,订单Id:{}", orderId);
|
||||
return false;
|
||||
}
|
||||
// 使用流来统计 couponId 出现的次数
|
||||
Map<Long, Long> couponIdCountMap = records.stream()
|
||||
.collect(Collectors.groupingBy(ShopActivateCouponRecord::getCouponId,
|
||||
Collectors.counting()
|
||||
));
|
||||
couponIdCountMap.forEach((couponId, count) -> {
|
||||
ShopCoupon tbShopCoupon = getById(couponId);
|
||||
tbShopCoupon.setUseNumber(tbShopCoupon.getUseNumber() + count.intValue());
|
||||
ShopCoupon coupon1 = new ShopCoupon();
|
||||
coupon1.setId(couponId);
|
||||
coupon1.setUseNumber(tbShopCoupon.getUseNumber());
|
||||
updateById(coupon1);
|
||||
});
|
||||
return couponRecordService.updateChain()
|
||||
.set(ShopActivateCouponRecord::getStatus, 1)
|
||||
.set(ShopActivateCouponRecord::getTargetId, orderId)
|
||||
.eq(ShopActivateCouponRecord::getShopUserId, shopUserId)
|
||||
.in(ShopActivateCouponRecord::getId, ids).update();
|
||||
}
|
||||
|
||||
/**
|
||||
* 退还券
|
||||
*/
|
||||
@Override
|
||||
public Boolean refund(Long orderId, Long shopUserId) {
|
||||
return couponRecordService.updateChain()
|
||||
.set(ShopActivateCouponRecord::getStatus, 0)
|
||||
.eq(ShopActivateCouponRecord::getShopUserId, shopUserId)
|
||||
.eq(ShopActivateCouponRecord::getTargetId, orderId)
|
||||
.update();
|
||||
}
|
||||
|
||||
private void setCouponInfo(Map<Long, JSONObject> coupons, UserCouponVo tbUserCouponVo, BigDecimal amount, String week, LocalTime now, DateTimeFormatter formatter) {
|
||||
JSONObject json = new JSONObject();
|
||||
boolean isUse = true;
|
||||
ShopCoupon tbShopCoupon = getById(tbUserCouponVo.getCouponId());
|
||||
StringBuilder useRestrictions = new StringBuilder("每天 ");
|
||||
if (amount != null && tbShopCoupon.getType().equals(1)) {
|
||||
if (amount.compareTo(tbShopCoupon.getFullAmount()) < 0) {
|
||||
isUse = false;
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(tbShopCoupon.getUserDays())) {
|
||||
String[] split = tbShopCoupon.getUserDays().split(",");
|
||||
if (split.length != 7) {
|
||||
useRestrictions = new StringBuilder(STR."\{tbShopCoupon.getUserDays()} ");
|
||||
}
|
||||
if (!tbShopCoupon.getUserDays().contains(week)) {
|
||||
isUse = false;
|
||||
}
|
||||
}
|
||||
if ("custom".equals(tbShopCoupon.getUseTimeType())) {
|
||||
if (now.isBefore(tbShopCoupon.getUseStartTime()) || now.isAfter(tbShopCoupon.getUseEndTime())) {
|
||||
isUse = false;
|
||||
}
|
||||
useRestrictions.append(
|
||||
STR."\{tbShopCoupon.getUseStartTime().format(formatter)}-\{tbShopCoupon.getUseEndTime().format(formatter)}");
|
||||
} else {
|
||||
useRestrictions.append("全时段");
|
||||
}
|
||||
useRestrictions.append(" 可用");
|
||||
json.put("isUse", isUse);
|
||||
json.put("useRestrictions", useRestrictions);
|
||||
|
||||
coupons.put(tbUserCouponVo.getCouponId(), json);
|
||||
}
|
||||
|
||||
}
|
||||
//package com.czg.service.account.service.impl;
|
||||
//
|
||||
//import cn.hutool.core.bean.BeanUtil;
|
||||
//import cn.hutool.core.collection.CollectionUtil;
|
||||
//import cn.hutool.core.date.DateUtil;
|
||||
//import cn.hutool.core.exceptions.ValidateException;
|
||||
//import cn.hutool.core.util.StrUtil;
|
||||
//import com.alibaba.fastjson2.JSONObject;
|
||||
//import com.czg.account.dto.QueryReceiveDto;
|
||||
//import com.czg.account.entity.ShopActivateCouponRecord;
|
||||
//import com.czg.account.entity.ShopUser;
|
||||
//import com.czg.account.service.ShopActivateCouponRecordService;
|
||||
//import com.czg.account.service.ShopInfoService;
|
||||
//import com.czg.account.service.ShopUserService;
|
||||
//import com.czg.account.vo.CouponReceiveVo;
|
||||
//import com.czg.account.vo.UserCouponVo;
|
||||
//import com.czg.product.entity.Product;
|
||||
//import com.czg.product.service.ProductService;
|
||||
//import com.czg.utils.PageUtil;
|
||||
//import com.github.pagehelper.PageHelper;
|
||||
//import com.github.pagehelper.PageInfo;
|
||||
//import com.mybatisflex.core.paginate.Page;
|
||||
//import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
//import jakarta.annotation.Resource;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.apache.dubbo.config.annotation.DubboReference;
|
||||
//import org.apache.dubbo.config.annotation.DubboService;
|
||||
//
|
||||
//import java.math.BigDecimal;
|
||||
//import java.time.LocalTime;
|
||||
//import java.time.format.DateTimeFormatter;
|
||||
//import java.util.*;
|
||||
//import java.util.stream.Collectors;
|
||||
//
|
||||
///**
|
||||
// * 优惠券 服务层实现。
|
||||
// *
|
||||
// * @author ww
|
||||
// * @since 2025-02-17
|
||||
// */
|
||||
//@Slf4j
|
||||
//@DubboService
|
||||
//public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCoupon> implements ShopCouponService {
|
||||
//
|
||||
// @Resource
|
||||
// private ShopActivateCouponRecordService couponRecordService;
|
||||
// @Resource
|
||||
// private ShopUserService shopUserService;
|
||||
// @Resource
|
||||
// private ShopInfoService shopInfoService;
|
||||
// @DubboReference
|
||||
// private ProductService productService;
|
||||
//
|
||||
// @Override
|
||||
// public List<ShopCouponDTO> getList(Long shopId, Integer type, Integer status) {
|
||||
// List<ShopCouponDTO> coupons = queryChain().select()
|
||||
// .eq(ShopCoupon::getShopId, shopId)
|
||||
// .eq(ShopCoupon::getType, type)
|
||||
// .eq(ShopCoupon::getStatus, status)
|
||||
// .orderBy(ShopCoupon::getCreateTime).desc()
|
||||
// .listAs(ShopCouponDTO.class);
|
||||
// System.out.println(coupons);
|
||||
// coupons.forEach(coupon -> {
|
||||
// if (coupon.getProId() != null) {
|
||||
// Product product = productService.getById(coupon.getProId());
|
||||
// coupon.setProName(product.getName());
|
||||
// }
|
||||
// });
|
||||
// return coupons;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Boolean add(ShopCouponDTO couponDTO) {
|
||||
// ShopCoupon shopCoupon = new ShopCoupon();
|
||||
// BeanUtil.copyProperties(couponDTO, shopCoupon);
|
||||
// shopCoupon.setLeftNumber(shopCoupon.getNumber());
|
||||
// return save(shopCoupon);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Boolean edit(ShopCouponDTO couponDTO) {
|
||||
// ShopCoupon shopCoupon = new ShopCoupon();
|
||||
// BeanUtil.copyProperties(couponDTO, shopCoupon);
|
||||
// if (couponDTO.getNumber() != null) {
|
||||
// ShopCoupon tbShopCoupon = getById(couponDTO.getId());
|
||||
// if (shopCoupon.getNumber() < tbShopCoupon.getNumber()) {
|
||||
// throw new ValidateException("修改失败 发放数量不可减少");
|
||||
// } else {
|
||||
// shopCoupon.setLeftNumber(shopCoupon.getLeftNumber() + shopCoupon.getNumber() - tbShopCoupon.getNumber());
|
||||
// }
|
||||
// }
|
||||
// return updateById(shopCoupon);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Page<CouponReceiveVo> queryReceive(QueryReceiveDto param) {
|
||||
// Page<Object> page = PageUtil.buildPage();
|
||||
// PageHelper.startPage(Math.toIntExact(page.getPageNumber()), Math.toIntExact(page.getPageSize()));
|
||||
// return PageUtil.convert(new PageInfo<>(couponRecordService.queryReceive(param)));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public Page<ShopActivateCouponRecord> find(Long userId, Long shopId, Integer status) {
|
||||
// Page<Object> page = PageUtil.buildPage();
|
||||
// List<Long> shopUserIds = shopUserService.queryChain()
|
||||
// .eq(ShopUser::getUserId, userId)
|
||||
// .eq(ShopUser::getShopId, shopId)
|
||||
// .select(ShopUser::getId).listAs(Long.class);
|
||||
// if (CollectionUtil.isNotEmpty(shopUserIds)) {
|
||||
// PageHelper.startPage(Math.toIntExact(page.getPageNumber()), Math.toIntExact(page.getPageSize()));
|
||||
// return PageUtil.convert(new PageInfo<>(couponRecordService.findByUser(shopUserIds, status)));
|
||||
// }
|
||||
// return new Page<>();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<UserCouponVo> findCoupon(Long shopId, Long shopUserId, Integer type) {
|
||||
// List<UserCouponVo> tbUserCouponVos = couponRecordService.queryByVipIdAndShopId(shopId, shopUserId, type);
|
||||
// if (CollectionUtil.isNotEmpty(tbUserCouponVos)) {
|
||||
// String week = DateUtil.dayOfWeekEnum(new Date()).toChinese("周");
|
||||
// LocalTime now = LocalTime.now();
|
||||
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||
//
|
||||
// //券id 券使用描述
|
||||
// Map<Long, JSONObject> coupons = new HashMap<>();
|
||||
// for (UserCouponVo tbUserCouponVo : tbUserCouponVos) {
|
||||
// if (!coupons.containsKey(tbUserCouponVo.getCouponId())) {
|
||||
// setCouponInfo(coupons, tbUserCouponVo, null, week, now, formatter);
|
||||
// }
|
||||
// JSONObject couponJson = coupons.get(tbUserCouponVo.getCouponId());
|
||||
// tbUserCouponVo.setUseRestrictions(couponJson.getString("useRestrictions"));
|
||||
// tbUserCouponVo.setUse(couponJson.getBoolean("isUse"));
|
||||
//
|
||||
// }
|
||||
// tbUserCouponVos.sort(Comparator.comparing(UserCouponVo::isUse).reversed());
|
||||
// return tbUserCouponVos;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Boolean use(List<Long> ids, Long shopUserId, Long orderId) {
|
||||
// List<ShopActivateCouponRecord> records = couponRecordService.listByIds(ids);
|
||||
// if (records.isEmpty()) {
|
||||
// log.error("优惠券使用失败,订单Id:{}", orderId);
|
||||
// return false;
|
||||
// }
|
||||
// // 使用流来统计 couponId 出现的次数
|
||||
// Map<Long, Long> couponIdCountMap = records.stream()
|
||||
// .collect(Collectors.groupingBy(ShopActivateCouponRecord::getCouponId,
|
||||
// Collectors.counting()
|
||||
// ));
|
||||
// couponIdCountMap.forEach((couponId, count) -> {
|
||||
// ShopCoupon tbShopCoupon = getById(couponId);
|
||||
// tbShopCoupon.setUseNumber(tbShopCoupon.getUseNumber() + count.intValue());
|
||||
// ShopCoupon coupon1 = new ShopCoupon();
|
||||
// coupon1.setId(couponId);
|
||||
// coupon1.setUseNumber(tbShopCoupon.getUseNumber());
|
||||
// updateById(coupon1);
|
||||
// });
|
||||
// return couponRecordService.updateChain()
|
||||
// .set(ShopActivateCouponRecord::getStatus, 1)
|
||||
// .set(ShopActivateCouponRecord::getTargetId, orderId)
|
||||
// .eq(ShopActivateCouponRecord::getShopUserId, shopUserId)
|
||||
// .in(ShopActivateCouponRecord::getId, ids).update();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 退还券
|
||||
// */
|
||||
// @Override
|
||||
// public Boolean refund(Long orderId, Long shopUserId) {
|
||||
// return couponRecordService.updateChain()
|
||||
// .set(ShopActivateCouponRecord::getStatus, 0)
|
||||
// .eq(ShopActivateCouponRecord::getShopUserId, shopUserId)
|
||||
// .eq(ShopActivateCouponRecord::getTargetId, orderId)
|
||||
// .update();
|
||||
// }
|
||||
//
|
||||
// private void setCouponInfo(Map<Long, JSONObject> coupons, UserCouponVo tbUserCouponVo, BigDecimal amount, String week, LocalTime now, DateTimeFormatter formatter) {
|
||||
// JSONObject json = new JSONObject();
|
||||
// boolean isUse = true;
|
||||
// ShopCoupon tbShopCoupon = getById(tbUserCouponVo.getCouponId());
|
||||
// StringBuilder useRestrictions = new StringBuilder("每天 ");
|
||||
// if (amount != null && tbShopCoupon.getType().equals(1)) {
|
||||
// if (amount.compareTo(tbShopCoupon.getFullAmount()) < 0) {
|
||||
// isUse = false;
|
||||
// }
|
||||
// }
|
||||
// if (StrUtil.isNotBlank(tbShopCoupon.getUserDays())) {
|
||||
// String[] split = tbShopCoupon.getUserDays().split(",");
|
||||
// if (split.length != 7) {
|
||||
// useRestrictions = new StringBuilder(STR."\{tbShopCoupon.getUserDays()} ");
|
||||
// }
|
||||
// if (!tbShopCoupon.getUserDays().contains(week)) {
|
||||
// isUse = false;
|
||||
// }
|
||||
// }
|
||||
// if ("custom".equals(tbShopCoupon.getUseTimeType())) {
|
||||
// if (now.isBefore(tbShopCoupon.getUseStartTime()) || now.isAfter(tbShopCoupon.getUseEndTime())) {
|
||||
// isUse = false;
|
||||
// }
|
||||
// useRestrictions.append(
|
||||
// STR."\{tbShopCoupon.getUseStartTime().format(formatter)}-\{tbShopCoupon.getUseEndTime().format(formatter)}");
|
||||
// } else {
|
||||
// useRestrictions.append("全时段");
|
||||
// }
|
||||
// useRestrictions.append(" 可用");
|
||||
// json.put("isUse", isUse);
|
||||
// json.put("useRestrictions", useRestrictions);
|
||||
//
|
||||
// coupons.put(tbUserCouponVo.getCouponId(), json);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -1,92 +0,0 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.account.dto.ShopShareCouponDTO;
|
||||
import com.czg.account.dto.ShopShareDTO;
|
||||
import com.czg.account.entity.ShopCoupon;
|
||||
import com.czg.account.service.ShopCouponService;
|
||||
import com.czg.account.vo.ShopShareRecordVO;
|
||||
import com.czg.account.vo.ShopShareVO;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.czg.service.account.mapper.ShopShareRecordMapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.account.entity.ShopShare;
|
||||
import com.czg.account.service.ShopShareService;
|
||||
import com.czg.service.account.mapper.ShopShareMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 店铺分享 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-05
|
||||
*/
|
||||
@Service
|
||||
public class ShopShareServiceImpl extends ServiceImpl<ShopShareMapper, ShopShare> implements ShopShareService{
|
||||
@Resource
|
||||
private ShopCouponService shopCouponService;
|
||||
@Resource
|
||||
private ShopShareRecordMapper shopShareRecordMapper;
|
||||
|
||||
@Override
|
||||
public ShopShareVO get(Long shopId) {
|
||||
ShopShare shopShare = getOne(new QueryWrapper().eq(ShopShare::getShopId, shopId));
|
||||
ShopShareVO shopShareVO = new ShopShareVO();
|
||||
if (shopShare != null) {
|
||||
BeanUtil.copyProperties(shopShare, shopShareVO);
|
||||
if (StrUtil.isNotBlank(shopShare.getRewardCoupon())) {
|
||||
// shopShareVO.setRewardCouponList(shopCouponService.list(new QueryWrapper().eq(ShopCoupon::getShopId, shopId).in(ShopCoupon::getId, JSONArray.parseArray(shopShare.getRewardCoupon()))));
|
||||
shopShareVO.setRewardCouponList(JSONArray.parseArray(shopShare.getRewardCoupon(), ShopShareCouponDTO.class));
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(shopShare.getNewCoupon())) {
|
||||
// shopShareVO.setNewCouponList(shopCouponService.list(new QueryWrapper().eq(ShopCoupon::getShopId, shopId).in(ShopCoupon::getId, JSONArray.parseArray(shopShare.getNewCoupon()))));
|
||||
shopShareVO.setNewCouponList(JSONArray.parseArray(shopShare.getNewCoupon(), ShopShareCouponDTO.class));
|
||||
}
|
||||
}
|
||||
return shopShareVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean add(Long shopId, ShopShareDTO shopShareDTO) {
|
||||
ShopShare shopShare = getOne(new QueryWrapper().eq(ShopShare::getShopId, shopId));
|
||||
if (shopShare == null) {
|
||||
shopShare = new ShopShareVO();
|
||||
shopShare.setShopId(shopId);
|
||||
}
|
||||
|
||||
if (shopShareDTO.getNewCouponList() != null && !shopShareDTO.getNewCouponList().isEmpty()) {
|
||||
long count = shopCouponService.count(new QueryWrapper().in(ShopCoupon::getId, shopShareDTO.getNewCouponList().stream().map(ShopShareCouponDTO::getId).toList()).eq(ShopCoupon::getShopId, shopId));
|
||||
if (count != shopShareDTO.getNewCouponList().size()) {
|
||||
throw new ApiNotPrintException("优惠券不存在");
|
||||
}
|
||||
shopShare.setNewCoupon(JSONArray.toJSONString(shopShareDTO.getNewCouponList()));
|
||||
}
|
||||
|
||||
if (shopShareDTO.getRewardCouponList() != null && !shopShareDTO.getRewardCouponList().isEmpty()) {
|
||||
long count = shopCouponService.count(new QueryWrapper().in(ShopCoupon::getId, shopShareDTO.getRewardCouponList().stream().map(ShopShareCouponDTO::getId).toList()).eq(ShopCoupon::getShopId, shopId));
|
||||
if (count != shopShareDTO.getRewardCouponList().size()) {
|
||||
throw new ApiNotPrintException("优惠券不存在");
|
||||
}
|
||||
shopShare.setRewardCoupon(JSONArray.toJSONString(shopShareDTO.getRewardCouponList()));
|
||||
}
|
||||
BeanUtil.copyProperties(shopShareDTO, shopShare);
|
||||
return saveOrUpdate(shopShare);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ShopShareRecordVO> recordPage(Long shopId, String key, Integer status) {
|
||||
Page<Object> page = PageUtil.buildPage();
|
||||
PageHelper.startPage(Math.toIntExact(page.getPageNumber()), Math.toIntExact(page.getPageSize()));
|
||||
return PageUtil.convert(new PageInfo<>(shopShareRecordMapper.getRecord(shopId, key, status)));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
<?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.czg.service.account.mapper.ShopCouponMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.czg</groupId>
|
||||
<artifactId>cash-service</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>market-service</artifactId>
|
||||
<name>market-service</name>
|
||||
|
||||
<dependencies>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
Loading…
Reference in New Issue