会员充值活动

现金充值
充值记录ID
This commit is contained in:
wangw 2025-02-18 14:25:11 +08:00
parent 02cb55b295
commit 703c4906f9
21 changed files with 465 additions and 71 deletions

View File

@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.*;
/**
* 店铺用户管理
*
* @author Administrator
*/
@RestController
@ -28,6 +29,7 @@ public class ShopUserController {
/**
* 获取店铺用户概述信息
*
* @param isVip 0 非vip 1 vip
* @return 概述信息
*/
@ -39,7 +41,8 @@ public class ShopUserController {
/**
* 获取店铺用户列表
* @param key 昵称或手机号
*
* @param key 昵称或手机号
* @param isVip 0 非vip 1 vip
* @return 用户列表
*/
@ -51,6 +54,7 @@ public class ShopUserController {
/**
* 店铺用户信息添加
*
* @return 是否成功
*/
@SaAdminCheckPermission("shopUser:add")
@ -61,6 +65,7 @@ public class ShopUserController {
/**
* 店铺用户信息修改
*
* @return 是否成功
*/
@SaAdminCheckPermission("shopUser:edit")
@ -71,13 +76,14 @@ public class ShopUserController {
/**
* 店铺用户余额修改
*
* @return 是否成功
*/
@SaAdminCheckPermission("shopUser:editFlow")
@PutMapping("/money")
public CzgResult<Boolean> editMoney(@RequestBody @Validated ShopUserMoneyEditDTO shopUserMoneyEditDTO) {
shopUserMoneyEditDTO.setBizEnum(ShopUserFlowBizEnum.ADMIN_IN);
return CzgResult.success(shopUserService.updateMoney(StpKit.USER.getShopId(), shopUserMoneyEditDTO));
return CzgResult.success(shopUserService.updateMoney(StpKit.USER.getShopId(), shopUserMoneyEditDTO) > 0L);
}
}

View File

@ -11,7 +11,8 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 店铺充值活动管理
* 用户店铺充值活动管理
*
* @author ww
*/
@RestController

View File

@ -27,6 +27,15 @@ public class VipPayController {
@Resource
private PayService payService;
/**
* 现金充值
*/
@PostMapping("cashPayVip")
public CzgResult<Object> cashPayVip(@Validated @RequestBody VipPayParamDTO payParam) {
payParam.setUserId(StpKit.USER.getLoginIdAsLong());
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType"));
return payService.cashPayVip(payParam);
}
/**
* js支付
@ -36,7 +45,7 @@ public class VipPayController {
@PostMapping("jsPayVip")
public CzgResult<Map<String, Object>> jsPayVip(HttpServletRequest request, @Validated @RequestBody VipPayParamDTO payParam) {
payParam.setUserId(StpKit.USER.getLoginIdAsLong());
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(),"platformType"));
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType"));
return payService.jsPayVip(ServletUtil.getClientIPByHeader(request), payParam);
}
@ -48,7 +57,7 @@ public class VipPayController {
@PostMapping("ltPayVip")
public CzgResult<Map<String, Object>> ltPayVip(HttpServletRequest request, @Validated @RequestBody VipPayParamDTO payParam) {
payParam.setUserId(StpKit.USER.getLoginIdAsLong());
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(),"platformType"));
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType"));
return payService.ltPayVip(ServletUtil.getClientIPByHeader(request), payParam);
}
@ -58,7 +67,7 @@ public class VipPayController {
@PostMapping("scanPayVip")
public CzgResult<Map<String, Object>> scanPayVip(HttpServletRequest request, @Validated @RequestBody VipPayParamDTO payParam) {
payParam.setUserId(StpKit.USER.getLoginIdAsLong());
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(),"platformType"));
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType"));
return payService.scanPayVip(ServletUtil.getClientIPByHeader(request), payParam);
}
@ -69,7 +78,7 @@ public class VipPayController {
@PostMapping("microPayVip")
public CzgResult<Map<String, Object>> microPayVip(@Validated @RequestBody VipPayParamDTO payParam) {
payParam.setUserId(StpKit.USER.getLoginIdAsLong());
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(),"platformType"));
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType"));
return payService.microPayVip(payParam);
}
}

View File

@ -12,6 +12,7 @@ import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
@ -39,12 +40,12 @@ public class ShopActivateDTO implements Serializable {
* 充值金额
*/
@NotNull(message = "充值金额不能为空", groups = {InsertGroup.class, UpdateGroup.class})
private Integer amount;
private BigDecimal amount;
/**
* 赠送金额
*/
private Integer giftAmount;
private BigDecimal giftAmount;
/**
* 赠送积分

View File

@ -1,17 +1,18 @@
package com.czg.account.dto;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Time;
import java.time.LocalDateTime;
import com.alibaba.fastjson2.annotation.JSONField;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Time;
import java.time.LocalDateTime;
/**
* 优惠券 实体类
*
@ -37,18 +38,12 @@ public class ShopCouponDTO implements Serializable {
*/
private Integer status;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
/**
* 名称(无意义)
*/
private String title;
private String shopId;
private Long shopId;
/**
* 已使用数量
@ -139,4 +134,11 @@ public class ShopCouponDTO implements Serializable {
*/
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;
}

View File

@ -0,0 +1,52 @@
package com.czg.account.dto;
import com.alibaba.fastjson2.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Builder;
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
@Builder
@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;
}

View File

@ -4,16 +4,16 @@ 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.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 活动 实体类
*
@ -38,12 +38,12 @@ public class ShopActivate implements Serializable {
/**
* 充值金额
*/
private Integer amount;
private BigDecimal amount;
/**
* 赠送金额
*/
private Integer giftAmount;
private BigDecimal giftAmount;
/**
* 赠送积分

View File

@ -1,22 +1,20 @@
package com.czg.account.entity;
import com.alibaba.fastjson2.annotation.JSONField;
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.sql.Time;
import java.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Time;
import java.time.LocalDateTime;
/**
* 优惠券 实体类
*
@ -44,18 +42,12 @@ public class ShopCoupon implements Serializable {
*/
private Integer status;
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
/**
* 名称(无意义)
*/
private String title;
private String shopId;
private Long shopId;
/**
* 已使用数量
@ -80,7 +72,7 @@ public class ShopCoupon implements Serializable {
/**
* 有效天数
*/
private Integer validDays;
private Long validDays;
/**
* 隔多少天生效
@ -142,4 +134,10 @@ public class ShopCoupon implements Serializable {
*/
private String editor;
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
}

View File

@ -0,0 +1,56 @@
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 lombok.AllArgsConstructor;
import lombok.Builder;
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
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_shop_coupon_product")
public class ShopCouponProduct implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 活动Id
*/
private Long couponId;
/**
* 商品id
*/
private Long productId;
/**
* 数量
*/
private Integer num;
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
}

View File

@ -4,6 +4,7 @@ import com.czg.account.dto.ShopActivateDTO;
import com.czg.account.entity.ShopActivate;
import com.mybatisflex.core.service.IService;
import java.math.BigDecimal;
import java.util.List;
/**
@ -20,5 +21,13 @@ public interface ShopActivateService extends IService<ShopActivate> {
Boolean edit(ShopActivateDTO activateDTO);
/**
* @param memAmount 充值金额
* @param relationId 关联Id
* 霸王餐时 订单id
* 充值奖励 的关联id 是tb_shop_user_flow的充值 记录id
* 支付/退款 tb_order_payment.id
*/
void giveActivate(Long shopId, Long vipId, BigDecimal memAmount, Long relationId);
}

View File

@ -0,0 +1,14 @@
package com.czg.account.service;
import com.czg.account.entity.ShopCouponProduct;
import com.mybatisflex.core.service.IService;
/**
* 活动赠送商品表 服务层
*
* @author ww
* @since 2025-02-18
*/
public interface ShopCouponProductService extends IService<ShopCouponProduct> {
}

View File

@ -17,7 +17,10 @@ public interface ShopUserService extends IService<ShopUser> {
Boolean updateInfo(Long shopId, ShopUserEditDTO shopUserEditDTO);
Boolean updateMoney(Long shopId, ShopUserMoneyEditDTO shopUserEditDTO);
/**
* 返回流水Id
*/
Long updateMoney(Long shopId, ShopUserMoneyEditDTO shopUserEditDTO);
ShopUserSummaryDTO getSummary(Long shopId, Integer isVip);

View File

@ -0,0 +1,20 @@
package com.czg.account.vo;
import lombok.Data;
/**
* @author ww
* @description
*/
@Data
public class CouponProductVo {
/**
* 商品id
*/
private Long productId;
/**
* 数量
*/
private Integer num;
}

View File

@ -0,0 +1,14 @@
package com.czg.service.account.mapper;
import com.czg.account.entity.ShopCouponProduct;
import com.mybatisflex.core.BaseMapper;
/**
* 活动赠送商品表 映射层
*
* @author ww
* @since 2025-02-18
*/
public interface ShopCouponProductMapper extends BaseMapper<ShopCouponProduct> {
}

View File

@ -1,15 +1,29 @@
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 com.alibaba.fastjson2.JSONObject;
import com.czg.account.dto.ShopActivateDTO;
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
import com.czg.account.entity.ShopActivate;
import com.czg.account.service.ShopActivateService;
import com.czg.account.entity.ShopActivateInRecord;
import com.czg.account.entity.ShopCoupon;
import com.czg.account.entity.ShopCouponProduct;
import com.czg.account.service.*;
import com.czg.account.vo.CouponProductVo;
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 org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
/**
@ -21,6 +35,15 @@ import java.util.List;
@DubboService
public class ShopActivateServiceImpl extends ServiceImpl<ShopActivateMapper, ShopActivate> implements ShopActivateService {
@Resource
private ShopCouponService couponService;
@Resource
private ShopActivateInRecordService inRecordService;
@Resource
private ShopCouponProductService couProductService;
@Resource
private ShopUserService shopUserService;
@Override
public List<ShopActivateDTO> getList() {
return queryChain().select()
@ -42,4 +65,106 @@ public class ShopActivateServiceImpl extends ServiceImpl<ShopActivateMapper, Sho
BeanUtil.copyProperties(activateDTO, shopActivate);
return updateById(shopActivate);
}
@Override
public void giveActivate(Long shopId, Long vipId, BigDecimal memAmount, Long relationId) {
ShopActivate activate = queryChain().select().eq(ShopActivate::getShopId, shopId)
.le(ShopActivate::getAmount, memAmount)
.orderBy(ShopActivate::getGiftAmount, false)
.one();
if (ObjectUtil.isNull(activate)) {
return;
}
//赠送优惠券
if (activate.getIsGiftCoupon() == 1) {
ShopCoupon shopCoupon = couponService.getById(activate.getCouponId());
if (shopCoupon != null && shopCoupon.getStatus().equals(1) && shopCoupon.getLeftNumber() > activate.getNum()) {
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<ShopActivateInRecord> actGiveRecords = new ArrayList<>();
if (shopCoupon.getType() == 1) {
//满减
ShopActivateInRecord record = new ShopActivateInRecord();
record.setVipUserId(vipId);
record.setCouponId(shopCoupon.getId());
record.setName("" + shopCoupon.getFullAmount() + "" + shopCoupon.getDiscountAmount());
record.setFullAmount(shopCoupon.getFullAmount());
record.setDiscountAmount(shopCoupon.getDiscountAmount());
record.setType(1);
record.setNum(activate.getNum());
record.setOverNum(activate.getNum());
record.setShopId(shopId);
record.setSourceActId(activate.getId());
record.setSourceFlowId(relationId);
record.setUseStartTime(start);
record.setUseEndTime(end);
record.setSource("activate");
record.setCouponJson(getCouponJson(activate, shopCoupon, null));
actGiveRecords.add(record);
} else if (shopCoupon.getType() == 2) {
List<CouponProductVo> couponProducts = couProductService.queryChain()
.select(ShopCouponProduct::getProductId, ShopCouponProduct::getNum)
.eq(ShopCouponProduct::getCouponId, shopCoupon.getId())
.listAs(CouponProductVo.class);
//商品券
for (CouponProductVo actPro : couponProducts) {
ShopActivateInRecord record = new ShopActivateInRecord();
record.setVipUserId(vipId);
record.setCouponId(shopCoupon.getId());
record.setName("商品券");
record.setType(2);
record.setProId(actPro.getProductId());
record.setNum(actPro.getNum() * activate.getNum());
record.setOverNum(actPro.getNum() * activate.getNum());
record.setShopId(shopId);
record.setSourceActId(activate.getId());
record.setSourceFlowId(relationId);
record.setUseStartTime(start);
record.setUseEndTime(end);
record.setSource("activate");
record.setCouponJson(getCouponJson(activate, shopCoupon, actPro));
actGiveRecords.add(record);
}
}
inRecordService.saveBatch(actGiveRecords);
shopCoupon.setLeftNumber(shopCoupon.getLeftNumber() - activate.getNum());
couponService.updateChain()
.set(ShopCoupon::getLeftNumber, shopCoupon.getLeftNumber() - activate.getNum())
.eq(ShopCoupon::getId, shopCoupon.getId())
.update();
}
}
//赠送金额
if (activate.getGiftAmount() != null && activate.getGiftAmount().compareTo(BigDecimal.ZERO) > 0) {
ShopUserMoneyEditDTO shopUserMoneyEditDTO = ShopUserMoneyEditDTO.builder()
.id(vipId)
.money(activate.getGiftAmount())
.type(1)
.remark("充值活动赠送")
.relationId(relationId)
.bizEnum(ShopUserFlowBizEnum.AWARD_IN)
.build();
//更新会员余额 并生成流水
shopUserService.updateMoney(shopId, shopUserMoneyEditDTO);
}
}
private String getCouponJson(ShopActivate activate, ShopCoupon tbShopCoupon, CouponProductVo couProduct) {
JSONObject result = new JSONObject();
result.put("activate", JSONObject.toJSONString(activate));
result.put("coupon", JSONObject.toJSONString(tbShopCoupon));
if (couProduct != null) {
result.put("couProduct", JSONObject.toJSONString(couProduct));
}
return result.toJSONString();
}
}

View File

@ -0,0 +1,18 @@
package com.czg.service.account.service.impl;
import com.czg.account.entity.ShopCouponProduct;
import com.czg.account.service.ShopCouponProductService;
import com.czg.service.account.mapper.ShopCouponProductMapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* 活动赠送商品表 服务层实现
*
* @author ww
* @since 2025-02-18
*/
@Service
public class ShopCouponProductServiceImpl extends ServiceImpl<ShopCouponProductMapper, ShopCouponProduct> implements ShopCouponProductService {
}

View File

@ -2,7 +2,6 @@ package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.dto.shopuser.*;
@ -13,7 +12,6 @@ import com.czg.account.service.ShopUserFlowService;
import com.czg.account.service.ShopUserService;
import com.czg.account.service.UserInfoService;
import com.czg.config.RedisCst;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.exception.ApiNotPrintException;
import com.czg.sa.StpKit;
import com.czg.service.RedisService;
@ -21,12 +19,10 @@ import com.czg.service.account.mapper.ShopUserMapper;
import com.czg.utils.AssertUtil;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;
import java.math.RoundingMode;
@ -77,12 +73,12 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
}
@Override
public Boolean updateMoney(Long shopId, ShopUserMoneyEditDTO shopUserEditDTO) {
public Long updateMoney(Long shopId, ShopUserMoneyEditDTO shopUserEditDTO) {
shopUserEditDTO.setMoney(shopUserEditDTO.getMoney().setScale(2, RoundingMode.DOWN));
ShopUser userInfo = getUserInfo(shopId, shopUserEditDTO.getId());
ShopUserFlow userFlow = new ShopUserFlow();
int flag = 0;
int flag;
if (shopUserEditDTO.getType() == 0) {
flag = mapper.decrAccount(shopId, shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney());
} else {
@ -100,7 +96,8 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
userFlow.setType(shopUserEditDTO.getType() == 0 ? "-" : "+");
userFlow.setRemark(shopUserEditDTO.getRemark());
userFlow.setRelationId(shopUserEditDTO.getRelationId());
return shopUserFlowService.save(userFlow);
shopUserFlowService.save(userFlow);
return userFlow.getId();
}
@Override

View File

@ -0,0 +1,7 @@
<?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.ShopCouponProductMapper">
</mapper>

View File

@ -1,6 +1,7 @@
package com.czg.service.order.service;
import com.czg.entity.resp.*;
import com.czg.entity.resp.CzgBaseResp;
import com.czg.entity.resp.CzgRefundResp;
import com.czg.resp.CzgResult;
import com.czg.service.order.dto.OrderPayParamDTO;
import com.czg.service.order.dto.VipPayParamDTO;
@ -11,6 +12,7 @@ import java.util.Map;
/**
* 支付
*
* @author ww
*/
public interface PayService {
@ -39,6 +41,12 @@ public interface PayService {
*/
CzgResult<Map<String, Object>> microPayOrder(OrderPayParamDTO payParam);
/**
* 现金充值
*/
CzgResult<Object> cashPayVip(VipPayParamDTO payParam);
/**
* js支付
*/
@ -63,7 +71,7 @@ public interface PayService {
/**
* 订单退款
*/
CzgResult<CzgRefundResp> refundOrder(Long shopId, Long orderId,String refundReason,BigDecimal refundAmount);
CzgResult<CzgRefundResp> refundOrder(Long shopId, Long orderId, String refundReason, BigDecimal refundAmount);
/**

View File

@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
import com.czg.account.entity.ShopUser;
import com.czg.account.service.ShopActivateService;
import com.czg.account.service.ShopUserService;
import com.czg.entity.notify.CzgPayNotifyDTO;
import com.czg.enums.ShopUserFlowBizEnum;
@ -51,6 +52,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
private OrderPaymentService paymentService;
@DubboReference
private ShopUserService shopUserService;
@DubboReference
private ShopActivateService activateService;
@Override
public Page<OrderInfoVo> getOrderByPage(OrderInfoQueryDTO param) {
@ -111,10 +114,12 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
if (shopUser == null) {
log.error("会员充值失败会员不存在会员id{}", payment.getSourceId());
} else {
shopUserService.updateChain()
.set(ShopUser::getIsVip, 1)
.eq(ShopUser::getId, payment.getSourceId())
.update();
if (shopUser.getIsVip().equals(0)) {
shopUserService.updateChain()
.set(ShopUser::getIsVip, 1)
.eq(ShopUser::getId, payment.getSourceId())
.update();
}
ShopUserMoneyEditDTO shopUserMoneyEditDTO = ShopUserMoneyEditDTO.builder()
.id(payment.getSourceId())
.money(new BigDecimal(czgCallBackDto.getAmount() / 100L))
@ -124,11 +129,16 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
if ("WECHAT".equals(czgCallBackDto.getPayType())) {
shopUserMoneyEditDTO.setBizEnum(ShopUserFlowBizEnum.WECHAT_IN);
} else if ("ALIPAY".equals(czgCallBackDto.getPayType())) {
shopUserMoneyEditDTO.setBizEnum(ShopUserFlowBizEnum.ADMIN_IN);
shopUserMoneyEditDTO.setBizEnum(ShopUserFlowBizEnum.ALIPAY_IN);
} else {
shopUserMoneyEditDTO.setBizEnum(ShopUserFlowBizEnum.CASH_IN);
}
//更新会员余额 并生成流水
shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
Long flowId = shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
//会员活动
activateService.giveActivate(shopUser.getShopId(), shopUser.getId(),
new BigDecimal(czgCallBackDto.getAmount() / 100L), flowId);
}
}
}

View File

@ -3,12 +3,15 @@ package com.czg.service.order.service.impl;
import cn.hutool.core.exceptions.ValidateException;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
import com.czg.account.entity.ShopMerchant;
import com.czg.account.entity.ShopUser;
import com.czg.account.service.ShopActivateService;
import com.czg.account.service.ShopMerchantService;
import com.czg.account.service.ShopUserService;
import com.czg.entity.req.*;
import com.czg.entity.resp.*;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.order.entity.OrderInfo;
import com.czg.order.entity.OrderPayment;
import com.czg.order.service.OrderInfoService;
@ -27,6 +30,7 @@ import jakarta.validation.constraints.NotBlank;
import lombok.NonNull;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.HashMap;
@ -45,6 +49,8 @@ public class PayServiceImpl implements PayService {
private SysParamsService sysParamsService;
@DubboReference
private ShopUserService shopUserService;
@DubboReference
private ShopActivateService shopActivateService;
@Resource
private CzgPayService czgPayService;
@Resource
@ -55,6 +61,7 @@ public class PayServiceImpl implements PayService {
private final BigDecimal MONEY_RATE = new BigDecimal("100");
@Override
@Transactional
public CzgResult<Map<String, Object>> h5PayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
AssertUtil.isNull(orderInfo, "订单不存在");
@ -67,6 +74,7 @@ public class PayServiceImpl implements PayService {
@Override
@Transactional
public CzgResult<Map<String, Object>> jsPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
AssertUtil.isNull(orderInfo, "订单不存在");
@ -80,6 +88,7 @@ public class PayServiceImpl implements PayService {
}
@Override
@Transactional
public CzgResult<Map<String, Object>> ltPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
AssertUtil.isNull(orderInfo, "订单不存在");
@ -91,6 +100,7 @@ public class PayServiceImpl implements PayService {
}
@Override
@Transactional
public CzgResult<Map<String, Object>> scanPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
AssertUtil.isNull(orderInfo, "订单不存在");
@ -102,6 +112,7 @@ public class PayServiceImpl implements PayService {
}
@Override
@Transactional
public CzgResult<Map<String, Object>> microPayOrder(OrderPayParamDTO payParam) {
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
AssertUtil.isNull(orderInfo, "订单不存在");
@ -114,10 +125,37 @@ public class PayServiceImpl implements PayService {
}
@Override
@Transactional
public CzgResult<Object> cashPayVip(VipPayParamDTO payParam) {
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
.eq(ShopUser::getUserId, payParam.getUserId()).one();
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
if (shopUser.getIsVip().equals(0)) {
shopUserService.updateChain()
.set(ShopUser::getIsVip, 1)
.eq(ShopUser::getId, payParam.getShopId())
.update();
}
ShopUserMoneyEditDTO shopUserMoneyEditDTO = ShopUserMoneyEditDTO.builder()
.id(shopUser.getId())
.money(payParam.getAmount())
.type(1)
.remark("现金充值")
.bizEnum(ShopUserFlowBizEnum.CASH_IN)
.build();
//更新会员余额 并生成流水
Long flowId = shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
//会员活动
shopActivateService.giveActivate(shopUser.getShopId(), shopUser.getId(), payParam.getAmount(), flowId);
return CzgResult.success();
}
@Override
@Transactional
public CzgResult<Map<String, Object>> jsPayVip(String clintIp, VipPayParamDTO payParam) {
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
.eq(ShopUser::getUserId, payParam.getShopUserId()).one();
AssertUtil.isNull(shopUser,"充值失败 该店铺用户不存在");
.eq(ShopUser::getUserId, payParam.getUserId()).one();
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId();
@ -127,10 +165,11 @@ public class PayServiceImpl implements PayService {
}
@Override
@Transactional
public CzgResult<Map<String, Object>> ltPayVip(String clintIp, VipPayParamDTO payParam) {
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
.eq(ShopUser::getUserId, payParam.getShopUserId()).one();
AssertUtil.isNull(shopUser,"充值失败 该店铺用户不存在");
.eq(ShopUser::getUserId, payParam.getUserId()).one();
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId();
@ -140,10 +179,11 @@ public class PayServiceImpl implements PayService {
}
@Override
@Transactional
public CzgResult<Map<String, Object>> scanPayVip(String clintIp, VipPayParamDTO payParam) {
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
.eq(ShopUser::getUserId, payParam.getShopUserId()).one();
AssertUtil.isNull(shopUser,"充值失败 该店铺用户不存在");
.eq(ShopUser::getUserId, payParam.getUserId()).one();
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId();
initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), "memberIn", payOrderNo, "", payParam.getAmount()));
return scanPay(payParam.getShopId(), new CzgScanPayReq(payOrderNo, payParam.getAmount().multiply(MONEY_RATE).longValue(),
@ -151,10 +191,11 @@ public class PayServiceImpl implements PayService {
}
@Override
@Transactional
public CzgResult<Map<String, Object>> microPayVip(VipPayParamDTO payParam) {
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
.eq(ShopUser::getUserId, payParam.getShopUserId()).one();
AssertUtil.isNull(shopUser,"充值失败 该店铺用户不存在");
.eq(ShopUser::getUserId, payParam.getUserId()).one();
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
AssertUtil.isBlank(payParam.getAuthCode(), "扫描码不能为空");
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId();
initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), "memberIn", payOrderNo, payParam.getAuthCode(), payParam.getAmount()));
@ -164,6 +205,7 @@ public class PayServiceImpl implements PayService {
@Override
@Transactional
public CzgResult<CzgRefundResp> refundOrder(@NonNull Long shopId, @NonNull Long orderId, @NonNull String refundReason, @NonNull BigDecimal refundAmount) {
// refund(shopId, new CzgRefundReq("1", refundReason, refundAmount.multiply(MONEY_RATE).longValue(),
@ -172,12 +214,14 @@ public class PayServiceImpl implements PayService {
}
@Override
@Transactional
public CzgResult<CzgBaseResp> queryPayOrder(@NonNull Long shopId, String payOrderId, String mchOrderNo) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
return czgPayService.queryPayOrder(shopMerchant.getAppId(), shopMerchant.getAppSecret(), payOrderId, mchOrderNo);
}
@Override
@Transactional
public CzgResult<CzgRefundResp> queryRefund(@NonNull Long shopId, String mchRefundNo, String refundOrderId) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
return czgPayService.queryRefundOrder(shopMerchant.getAppId(), shopMerchant.getAppSecret(), mchRefundNo, refundOrderId);
@ -250,7 +294,7 @@ public class PayServiceImpl implements PayService {
} else if (firstTwoDigits >= 25 && firstTwoDigits <= 30) {
//支付宝支付
bizData.setSubAppid(shopMerchant.getAlipaySmallAppid());
}else {
} else {
throw new ValidateException("扫描码非法或暂不支持");
}
CzgResult<CzgMicroPayResp> czgScanPayResult = czgPayService.microPay(shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);