feat:硬件核销相关
This commit is contained in:
1 parent
255b88a948
commit
a2623df7e2
19 files changed
+455
-37
No files matched your search
+18
@@ -0,0 +1,18 @@
|
||||
package com.bsd.pjcloud.hard.api.dto.hard;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HandCancelActCodeDto {
|
||||
|
||||
@Schema(description = "核销活动i子d")
|
||||
@NotNull(message = "核销活动子id不能为空")
|
||||
private Long actItemId;
|
||||
|
||||
@Schema(description = "设备id")
|
||||
@NotNull(message = "设备id不能为空")
|
||||
private Long hardwareId;
|
||||
|
||||
}
|
||||
+9
-5
@@ -9,10 +9,7 @@ import com.bsd.pjcloud.hard.api.constant.HardProductNatureEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.HardTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.dto.async.SyncOfflineReqVo;
|
||||
import com.bsd.pjcloud.hard.api.dto.hard.HandCancelCodeDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.hard.HardBindDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.hard.HardCreateOrderDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.hard.HardDoneHardQrCodeScanOrderDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.hard.*;
|
||||
import com.bsd.pjcloud.hard.api.dto.order.HardChartLatitudeVo;
|
||||
import com.bsd.pjcloud.hard.api.dto.order.HardCreateCarDto;
|
||||
import com.bsd.pjcloud.hard.api.vo.HardInvoiceVo;
|
||||
@@ -121,7 +118,7 @@ public class HardApiController {
|
||||
|
||||
@PostMapping("/cancel-code")
|
||||
@Operation(summary = "核销二维码")
|
||||
@Idempotent(expireTime = 10, info = "正在核销中,请勿重复操作")
|
||||
@Idempotent(expireTime = 10, key = "'/hard-api/ad/cancel-code' + #dto.getOrderId() ", info = "正在核销中,请勿重复操作")
|
||||
public R<Boolean> handCancelCode(@RequestBody HandCancelCodeDto dto) {
|
||||
if (!ObjectUtil.isAllNotEmpty(dto.getOrderId(), dto.getHardwareId())) {
|
||||
throw new RuntimeException("参数不正确");
|
||||
@@ -129,6 +126,13 @@ public class HardApiController {
|
||||
return R.ok(hardwareOrderService.handCancelCode(dto));
|
||||
}
|
||||
|
||||
@PostMapping("/cancel-act-code")
|
||||
@Operation(summary = "核销二维码")
|
||||
@Idempotent(expireTime = 10, key = "'/hard-api/ad/cancel-act-code' + #dto.getActItemId() ", info = "正在核销中,请勿重复操作")
|
||||
public R<Boolean> handCancelActCode(@Validated @RequestBody HandCancelActCodeDto dto) {
|
||||
return R.ok(hardwareOrderService.handCancelActCode(dto));
|
||||
}
|
||||
|
||||
@GetMapping("/generate-invoice")
|
||||
@Operation(summary = "生成发票")
|
||||
@Idempotent(expireTime = 10, info = "正在生成中,请勿重复操作")
|
||||
|
||||
+6
-1
@@ -10,6 +10,7 @@ import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.security.service.PjcloudUser;
|
||||
import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.dto.hard.HandCancelActCodeDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.hard.HandCancelCodeDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.hard.HardCreateOrderDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.hard.HardDoneHardQrCodeScanOrderDto;
|
||||
@@ -142,6 +143,11 @@ public interface HardOrderService extends IService<HardOrderEntity> {
|
||||
*/
|
||||
Boolean handCancelCode(HandCancelCodeDto dto);
|
||||
|
||||
/**
|
||||
* 核销活动二维码
|
||||
*/
|
||||
Boolean handCancelActCode(HandCancelActCodeDto dto);
|
||||
|
||||
/**
|
||||
* 创建订单后发送mq消息
|
||||
*/
|
||||
@@ -151,5 +157,4 @@ public interface HardOrderService extends IService<HardOrderEntity> {
|
||||
* 是否需要支付
|
||||
*/
|
||||
boolean isPay(HardOrderTypeEnum type, HardPayTypeEnum payType);
|
||||
|
||||
}
|
||||
+12
@@ -38,6 +38,7 @@ import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.dto.ali.AliMicropayDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.ali.AliReverseDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.hard.HandCancelActCodeDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.hard.HardDoneHardQrCodeScanOrderDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.manager.HardManagerDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.hard.HandCancelCodeDto;
|
||||
@@ -1143,6 +1144,17 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
return baseMapper.updateById(updateObj) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 核销活动二维码
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean handCancelActCode(HandCancelActCodeDto dto) {
|
||||
// 查看该优惠券
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
// @GlobalTransactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
|
||||
+1
@@ -15,6 +15,7 @@ public enum WalletCodeBizEnum {
|
||||
SUPERMARKET_RESERVE("4", "超市线上预订"),
|
||||
USER_WALLET("5", "用户钱包二维码"),
|
||||
FARMER_RESERVE("6", "用户钱包二维码"),
|
||||
ACT("6", "活动二维码"),
|
||||
;
|
||||
private final String code;
|
||||
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.bsd.pjcloud.wallet.api.dto.act;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ActComCancelDto {
|
||||
|
||||
/**
|
||||
* 活动子id
|
||||
*/
|
||||
@NotNull(message = "活动子id不能为空")
|
||||
private Long actItemId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@NotNull(message = "用户id不能为空")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 订单id
|
||||
*/
|
||||
private Long orderId;
|
||||
|
||||
/**
|
||||
* 活动提现金额
|
||||
*/
|
||||
private Integer useAmountPrice;
|
||||
|
||||
}
|
||||
-6
@@ -45,12 +45,6 @@ public interface RemoteCodeUseService {
|
||||
|
||||
/**
|
||||
* 生成二维码
|
||||
*
|
||||
* @param id
|
||||
* @param userId
|
||||
* @param walletCodeBiz
|
||||
* @param count
|
||||
* @return
|
||||
*/
|
||||
@NoToken
|
||||
@GetMapping("/wallet-code-use/generate-code")
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.bsd.pjcloud.wallet.api.feign;
|
||||
|
||||
import com.bsd.pjcloud.common.core.constant.ServiceNameConstants;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.feign.annotation.NoToken;
|
||||
import com.bsd.pjcloud.wallet.api.dto.act.ActComCancelDto;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletCodeUseEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.act.ActComItemVo;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(contextId = "RemoteComActService", value = ServiceNameConstants.WALLET_SERVICE)
|
||||
public interface RemoteComActService {
|
||||
|
||||
/**
|
||||
* 根据公告id查询对应的活动
|
||||
*/
|
||||
@NoToken
|
||||
@GetMapping("/act/com/remote/get-act")
|
||||
R<ActComItemVo> remoteGetComAct(@RequestParam Long actItemId, @RequestParam Long userId);
|
||||
|
||||
/**
|
||||
* 活动是否能够核销
|
||||
*/
|
||||
@NoToken
|
||||
@GetMapping("/act/com/remote/is-can-cancel")
|
||||
R<String> remoteIsCanCancel(@RequestParam Long actItemId, @RequestParam Long userId);
|
||||
|
||||
/**
|
||||
* 核销活动
|
||||
*/
|
||||
@NoToken
|
||||
@PostMapping("/act/com/remote/do-cancel")
|
||||
R<Boolean> remoteDoCancel(@Validated @RequestBody ActComCancelDto body);
|
||||
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.bsd.pjcloud.wallet.api.vo.act;
|
||||
|
||||
import com.bsd.pjcloud.wallet.api.constant.act.ActTypeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ActComItemVo<T> {
|
||||
|
||||
private String actType;
|
||||
|
||||
private Long actItemId;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String username;
|
||||
|
||||
private String userAvatar;
|
||||
|
||||
private T detail;
|
||||
|
||||
}
|
||||
+11
@@ -95,6 +95,17 @@ public class WalletCodeUseController {
|
||||
dto.setUserId(user.getId());
|
||||
return R.ok(walletCodeUseService.pageJoin(page, dto));
|
||||
}
|
||||
|
||||
@Operation(summary = "查询二维码", description = "查询二维码")
|
||||
@GetMapping("/app/user-code")
|
||||
public R<WalletCodeUseEntity> appUserCode(@RequestParam Long id) {
|
||||
PjcloudUser user = SecurityUtils.getUser();
|
||||
WalletCodeUseEntity detail = walletCodeUseService.getOne(new LambdaQueryWrapper<WalletCodeUseEntity>()
|
||||
.eq(WalletCodeUseEntity::getBizId, id)
|
||||
.eq(WalletCodeUseEntity::getUserId, user.getId())
|
||||
);
|
||||
return R.ok(detail);
|
||||
}
|
||||
/* ************************************* end app end ************************************* */
|
||||
|
||||
/* ************************************* start android start ************************************* */
|
||||
|
||||
+37
-7
@@ -1,12 +1,12 @@
|
||||
package com.bsd.pjcloud.wallet.controller.act;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.security.annotation.Inner;
|
||||
import com.bsd.pjcloud.common.security.service.PjcloudUser;
|
||||
import com.bsd.pjcloud.common.security.util.SecurityUtils;
|
||||
import com.bsd.pjcloud.wallet.api.constant.act.ActTypeEnum;
|
||||
import com.bsd.pjcloud.wallet.api.constant.act.ActUserReceiveEnum;
|
||||
import com.bsd.pjcloud.wallet.api.vo.act.ActCouponVo;
|
||||
import com.bsd.pjcloud.wallet.api.dto.act.ActComCancelDto;
|
||||
import com.bsd.pjcloud.wallet.api.vo.act.ActComItemVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.act.ActSimpleNotfiyVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.act.ActUserTotalVo;
|
||||
import com.bsd.pjcloud.wallet.service.ActComService;
|
||||
@@ -15,10 +15,8 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
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 org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 活动公用方法
|
||||
@@ -32,6 +30,38 @@ public class ActComController {
|
||||
|
||||
private final ActComService actComService;
|
||||
|
||||
/* ************************************* start 远程调用 start ************************************* */
|
||||
@Operation(summary = "根据公告id查询对应的活动", description = "根据公告id查询对应的活动")
|
||||
@GetMapping("/remote/get-act")
|
||||
@Inner
|
||||
public R<ActComItemVo> remoteGetComAct(@RequestParam Long actItemId, @RequestParam Long userId) {
|
||||
return R.ok(actComService.getComAct(actItemId, userId));
|
||||
}
|
||||
|
||||
@Operation(summary = "活动是否能够核销", description = "活动是否能够核销")
|
||||
@GetMapping("/remote/is-can-cancel")
|
||||
@Inner
|
||||
public R<String> remoteIsCanCancel(@RequestParam Long actItemId, @RequestParam Long userId) {
|
||||
return R.ok(actComService.actIsCanCancel(actItemId, userId));
|
||||
}
|
||||
|
||||
@Operation(summary = "核销活动", description = "核销活动")
|
||||
@PostMapping("/remote/do-cancel")
|
||||
@Inner
|
||||
public R<Boolean> remoteDoCancel(@Validated @RequestBody ActComCancelDto body) {
|
||||
return R.ok(actComService.doCancel(body));
|
||||
}
|
||||
/* ************************************* end 远程调用 end ************************************* */
|
||||
|
||||
|
||||
/* ************************************* start ad start ************************************* */
|
||||
@Operation(summary = "根据公告id查询对应的活动", description = "根据公告id查询对应的活动")
|
||||
@GetMapping("/ad/get-act")
|
||||
public R<ActComItemVo> getComAct(@RequestParam Long actItemId, @RequestParam Long userId) {
|
||||
return R.ok(actComService.getComAct(actItemId, userId));
|
||||
}
|
||||
/* ************************************* end ad end ************************************* */
|
||||
|
||||
@Operation(summary = "根据公告id查询对应的活动", description = "根据公告id查询对应的活动")
|
||||
@GetMapping("/app/get-act-by-notify-id")
|
||||
public R<ActSimpleNotfiyVo> getActByNotifyId(@RequestParam Long notifyId) {
|
||||
|
||||
+7
@@ -38,11 +38,18 @@ public interface ActCancelItemService extends IService<ActCancelItemEntity> {
|
||||
*/
|
||||
Boolean cancel(ActCancelItemDto dto);
|
||||
|
||||
/**
|
||||
* 活动是否能够核销
|
||||
*/
|
||||
String actIsCanCancel(ActCancelItemDto detail);
|
||||
|
||||
/**
|
||||
* 查询详情
|
||||
*/
|
||||
ActCancelItemVo getDetail(Long cancelId);
|
||||
|
||||
ActCancelItemVo getDetail(Long actItemId, Long userId);
|
||||
|
||||
/**
|
||||
* 用户参加活动的数量统计
|
||||
*/
|
||||
|
||||
+19
@@ -2,11 +2,30 @@ package com.bsd.pjcloud.wallet.service;
|
||||
|
||||
|
||||
import com.bsd.pjcloud.wallet.api.constant.act.ActTypeEnum;
|
||||
import com.bsd.pjcloud.wallet.api.dto.act.ActComCancelDto;
|
||||
import com.bsd.pjcloud.wallet.api.vo.act.ActComItemVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.act.ActSimpleNotfiyVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.act.ActUserTotalVo;
|
||||
|
||||
public interface ActComService {
|
||||
|
||||
/**
|
||||
* 获取活动
|
||||
*/
|
||||
ActComItemVo getComAct(Long actId, Long userId);
|
||||
|
||||
/**
|
||||
* 活动是否能够核销
|
||||
*
|
||||
* @return 错误信息
|
||||
*/
|
||||
String actIsCanCancel(Long actItemId, Long userId);
|
||||
|
||||
/**
|
||||
* 核销活动
|
||||
*/
|
||||
Boolean doCancel(ActComCancelDto body);
|
||||
|
||||
/**
|
||||
* 根据公告id查询对应的活动
|
||||
*/
|
||||
|
||||
+17
-1
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bsd.pjcloud.wallet.api.constant.act.ActUserReceiveEnum;
|
||||
import com.bsd.pjcloud.wallet.api.dto.act.ActCouponReceiveDto;
|
||||
import com.bsd.pjcloud.wallet.api.dto.act.ActCouponRecordDto;
|
||||
import com.bsd.pjcloud.wallet.api.entity.act.ActCouponEntity;
|
||||
import com.bsd.pjcloud.wallet.api.entity.act.ActCouponRecordEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.act.ActCouponRecordVo;
|
||||
|
||||
@@ -15,11 +16,27 @@ public interface ActCouponRecordService extends IService<ActCouponRecordEntity>
|
||||
*/
|
||||
Page<ActCouponRecordVo> pageList(Page page, ActCouponRecordDto dto);
|
||||
|
||||
/**
|
||||
* 查询详情
|
||||
*/
|
||||
ActCouponRecordEntity getDetail(Long actItemId, Long userId);
|
||||
|
||||
/**
|
||||
* 领取优惠券
|
||||
*/
|
||||
Long appReceive(ActCouponReceiveDto dto);
|
||||
|
||||
/**
|
||||
* 核销优惠券
|
||||
* @param useAmountPrice 优惠券抵消的金额
|
||||
*/
|
||||
void cancel(ActCouponRecordEntity dto, Long orderId, Integer useAmountPrice);
|
||||
|
||||
/**
|
||||
* 活动是否能够核销
|
||||
*/
|
||||
String actIsCanCancel(ActCouponRecordEntity detail);
|
||||
|
||||
/**
|
||||
* 判断用户是否可以参加活动
|
||||
*/
|
||||
@@ -29,5 +46,4 @@ public interface ActCouponRecordService extends IService<ActCouponRecordEntity>
|
||||
* 用户参加活动的数量统计
|
||||
*/
|
||||
Long userTotal(Long userId);
|
||||
|
||||
}
|
||||
+4
@@ -104,6 +104,10 @@ public class WalletCodeUseServiceImpl extends ServiceImpl<WalletCodeUseMapper, W
|
||||
orderType = HardOrderTypeEnum.FARMER;
|
||||
payType = HardPayTypeEnum.WALLET_DEFAULT;
|
||||
}
|
||||
if (biz == WalletCodeBizEnum.ACT) {
|
||||
orderType = HardOrderTypeEnum.RESERVE;
|
||||
payType = HardPayTypeEnum.ACT_CANCEL;
|
||||
}
|
||||
for (int i = 0; i < count; i++) {
|
||||
WalletCodeUseEntity item = WalletCodeUseEntity.builder().bizId(id).userId(userId).bizType(biz.getCode()).build();
|
||||
int insert = baseMapper.insert(item);
|
||||
|
||||
+48
@@ -299,6 +299,35 @@ public class ActCancelItemServiceImpl extends ServiceImpl<ActCancelItemMapper, A
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 活动是否能够核销
|
||||
*/
|
||||
@Override
|
||||
public String actIsCanCancel(ActCancelItemDto dto) {
|
||||
if (ObjectUtil.isEmpty(dto.getId()) || ObjectUtil.isEmpty(dto.getCancelUserId())) {
|
||||
return "核销失败,参数错误";
|
||||
}
|
||||
// 查询活动
|
||||
ActCancelItemEntity detail = baseMapper.selectById(dto.getId());
|
||||
if (ObjectUtil.isEmpty(detail)) {
|
||||
return "核销失败,活动不存在";
|
||||
}
|
||||
// 查询核销用户
|
||||
UserInfo userDetail = remoteUserService.getInnerByUserId(dto.getCancelUserId()).getData();
|
||||
if (ObjectUtil.isEmpty(userDetail)) {
|
||||
return "核销失败,核销用户不存在";
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(detail.getExpireTime())) {
|
||||
if (detail.getExpireTime().isBefore(LocalDateTime.now())) {
|
||||
return "核销失败,您领取的优惠券已过期";
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.equals(detail.getActStatus(), ActCancelStatusEnum.CANCEL_SUCCESS.getCode())) {
|
||||
return "核销失败,您领取的优惠券已核销";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询详情
|
||||
*/
|
||||
@@ -320,6 +349,25 @@ public class ActCancelItemServiceImpl extends ServiceImpl<ActCancelItemMapper, A
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActCancelItemVo getDetail(Long cancelId, Long userId) {
|
||||
ActCancelItemVo result = new ActCancelItemVo();
|
||||
ActCancelItemEntity detail = baseMapper.selectOne(new LambdaQueryWrapper<ActCancelItemEntity>()
|
||||
.eq(ActCancelItemEntity::getId, cancelId)
|
||||
.eq(ActCancelItemEntity::getReceiverUserId, userId)
|
||||
);
|
||||
if (ObjectUtil.isEmpty(detail)) return null;
|
||||
result = BeanUtils.toBean(detail, ActCancelItemVo.class);
|
||||
// 查询活动
|
||||
ActCancelEntity actDetail = actCancelMapper.selectById(detail.getActId());
|
||||
if (ObjectUtil.isNotEmpty(actDetail)) {
|
||||
result.setActiveCancelPrice(actDetail.getActiveCancelPrice());
|
||||
}
|
||||
result.setActStartTime(actDetail.getStartTime());
|
||||
result.setActExpireTime(actDetail.getExpireTime());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户参加活动的数量统计
|
||||
*/
|
||||
|
||||
+86
@@ -1,10 +1,18 @@
|
||||
package com.bsd.pjcloud.wallet.service.impl.act;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.bsd.pjcloud.admin.api.dto.UserInfo;
|
||||
import com.bsd.pjcloud.admin.api.entity.SysUser;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
|
||||
import com.bsd.pjcloud.wallet.api.constant.act.ActTypeEnum;
|
||||
import com.bsd.pjcloud.wallet.api.constant.act.ActUserReceiveEnum;
|
||||
import com.bsd.pjcloud.wallet.api.dto.act.ActCancelItemDto;
|
||||
import com.bsd.pjcloud.wallet.api.dto.act.ActComCancelDto;
|
||||
import com.bsd.pjcloud.wallet.api.entity.act.ActCancelEntity;
|
||||
import com.bsd.pjcloud.wallet.api.entity.act.ActCouponEntity;
|
||||
import com.bsd.pjcloud.wallet.api.entity.act.ActCouponRecordEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.act.ActCancelItemVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.act.ActComItemVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.act.ActSimpleNotfiyVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.act.ActUserTotalVo;
|
||||
import com.bsd.pjcloud.wallet.service.*;
|
||||
@@ -28,6 +36,84 @@ public class ActComServiceImpl implements ActComService {
|
||||
private final ActCouponService actCouponService;
|
||||
private final ActCouponRecordService actCouponRecordService;
|
||||
|
||||
private final RemoteUserService remoteUserService;
|
||||
|
||||
/**
|
||||
* 获取活动
|
||||
*/
|
||||
@Override
|
||||
public ActComItemVo getComAct(Long actItemId, Long userId) {
|
||||
ActComItemVo result = new ActComItemVo<>();
|
||||
List<ActTypeEnum> actEnumList = ActTypeEnum.sortList();
|
||||
for (ActTypeEnum act : actEnumList) {
|
||||
if (ObjectUtil.equals(act, ActTypeEnum.CANCEL_ACT)) {
|
||||
ActCancelItemVo detail = actCancelItemService.getDetail(actItemId, userId);
|
||||
if (ObjectUtil.isNotEmpty(detail)) {
|
||||
result.setActItemId(detail.getId());
|
||||
result.setActType(act.getCode());
|
||||
result.setDetail(detail);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.equals(act, ActTypeEnum.COUPON_ACT)) {
|
||||
ActCouponRecordEntity detail = actCouponRecordService.getDetail(actItemId, userId);
|
||||
if (ObjectUtil.isNotEmpty(detail)) {
|
||||
result.setActItemId(detail.getId());
|
||||
result.setActType(act.getCode());
|
||||
result.setDetail(detail);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isEmpty(result)) return null;
|
||||
// 查询用户
|
||||
UserInfo userInfo = remoteUserService.getByUserId(userId).getData();
|
||||
if (ObjectUtil.isNotEmpty(userInfo)) {
|
||||
SysUser sysUser = userInfo.getSysUser();
|
||||
result.setUserId(sysUser.getUserId());
|
||||
result.setUsername(sysUser.getName());
|
||||
result.setUserAvatar(sysUser.getAvatar());
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 活动是否能够核销
|
||||
*
|
||||
* @return 错误信息
|
||||
*/
|
||||
@Override
|
||||
public String actIsCanCancel(Long actItemId, Long userId) {
|
||||
ActComItemVo comAct = getComAct(actItemId, userId);
|
||||
ActTypeEnum actType = ActTypeEnum.valueOfByType(comAct.getActType());
|
||||
switch (actType) {
|
||||
case CANCEL_ACT:
|
||||
return actCancelItemService.actIsCanCancel((ActCancelItemDto) comAct.getDetail());
|
||||
case COUPON_ACT:
|
||||
return actCouponRecordService.actIsCanCancel((ActCouponRecordEntity) comAct.getDetail());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 核销活动
|
||||
*/
|
||||
@Override
|
||||
public Boolean doCancel(ActComCancelDto body) {
|
||||
ActComItemVo comAct = getComAct(body.getActItemId(), body.getUserId());
|
||||
ActTypeEnum actType = ActTypeEnum.valueOfByType(comAct.getActType());
|
||||
switch (actType) {
|
||||
case CANCEL_ACT:
|
||||
actCancelItemService.cancel((ActCancelItemDto) comAct.getDetail());
|
||||
return true;
|
||||
case COUPON_ACT:
|
||||
actCouponRecordService.cancel((ActCouponRecordEntity) comAct.getDetail(), body.getOrderId(), body.getUseAmountPrice());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据公告id查询对应的活动
|
||||
*/
|
||||
|
||||
+59
@@ -1,6 +1,7 @@
|
||||
package com.bsd.pjcloud.wallet.service.impl.act;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bsd.pjcloud.admin.api.dto.UserInfo;
|
||||
@@ -14,6 +15,7 @@ import com.bsd.pjcloud.common.core.util.CollectionUtils;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.hard.api.vo.HardAuthVo;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletCodeBizEnum;
|
||||
import com.bsd.pjcloud.wallet.api.constant.act.ActCouponRecordStatusEnum;
|
||||
import com.bsd.pjcloud.wallet.api.constant.act.ActUserReceiveEnum;
|
||||
import com.bsd.pjcloud.wallet.api.dto.WalletTransactionDto;
|
||||
@@ -29,6 +31,7 @@ import com.bsd.pjcloud.wallet.mapper.act.ActCouponMapper;
|
||||
import com.bsd.pjcloud.wallet.mapper.act.ActCouponRecordMapper;
|
||||
import com.bsd.pjcloud.wallet.service.ActCouponRecordService;
|
||||
import com.bsd.pjcloud.wallet.service.MchManageService;
|
||||
import com.bsd.pjcloud.wallet.service.WalletCodeUseService;
|
||||
import com.bsd.pjcloud.wallet.utils.act.service.ActCouponComUtilService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -53,6 +56,7 @@ public class ActCouponRecordServiceImpl extends ServiceImpl<ActCouponRecordMappe
|
||||
|
||||
private final MchManageService mchManageService;
|
||||
private final ActCouponComUtilService actCouponComUtilService;
|
||||
private final WalletCodeUseService walletCodeUseService;
|
||||
|
||||
private final RemoteUserService remoteUserService;
|
||||
|
||||
@@ -66,6 +70,20 @@ public class ActCouponRecordServiceImpl extends ServiceImpl<ActCouponRecordMappe
|
||||
return pageList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询详情
|
||||
*/
|
||||
@Override
|
||||
public ActCouponRecordEntity getDetail(Long actItemId, Long userId) {
|
||||
return baseMapper.selectOne(new LambdaQueryWrapper<ActCouponRecordEntity>()
|
||||
.eq(ActCouponRecordEntity::getId, actItemId)
|
||||
.eq(ActCouponRecordEntity::getUserId, userId)
|
||||
.orderByDesc(ActCouponRecordEntity::getCreateTime)
|
||||
.orderByDesc(ActCouponRecordEntity::getId)
|
||||
.last("limit 1")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取优惠券
|
||||
*/
|
||||
@@ -92,10 +110,51 @@ public class ActCouponRecordServiceImpl extends ServiceImpl<ActCouponRecordMappe
|
||||
ActCouponRecordEntity record = actCouponComUtilService.doReceive(actCouponEntity, sysUser);
|
||||
// 5. 优惠券领取成功后,执行生命周期方法
|
||||
actCouponComUtilService.afterReceive(record);
|
||||
// 6. 生成核销二维码
|
||||
walletCodeUseService.generate(record.getId(), record.getUserId(), WalletCodeBizEnum.ACT, 1);
|
||||
return record.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 核销优惠券
|
||||
*/
|
||||
@Override
|
||||
public void cancel(ActCouponRecordEntity dto, Long orderId, Integer useAmountPrice) {
|
||||
// 1. 获取当前用户
|
||||
UserInfo userInfo = remoteUserService.getByUserId(dto.getUserId()).getData();
|
||||
if (ObjectUtil.isEmpty(userInfo)) {
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
SysUser sysUser = userInfo.getSysUser();
|
||||
ActCouponRecordEntity record = getDetail(dto.getId(), dto.getUserId());
|
||||
if (ObjectUtil.isEmpty(record)) {
|
||||
throw new ServiceException("优惠券不存在");
|
||||
}
|
||||
// 2. 预处理
|
||||
ActCouponRecordEntity actCouponEntity = actCouponComUtilService.preCancel(record);
|
||||
if (ObjectUtil.isEmpty(actCouponEntity)) {
|
||||
return;
|
||||
}
|
||||
// 3. 执行核销逻辑
|
||||
actCouponComUtilService.doCancel(actCouponEntity.getId(), orderId, useAmountPrice);
|
||||
// 4. 优惠券核销成功后,执行生命周期方法
|
||||
actCouponComUtilService.afterCancel(actCouponEntity);
|
||||
// 5. 核销短码
|
||||
walletCodeUseService.cancelCode(actCouponEntity.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 活动是否能够核销
|
||||
*/
|
||||
@Override
|
||||
public String actIsCanCancel(ActCouponRecordEntity detail) {
|
||||
return actCouponComUtilService.actIsCanCancel(detail);
|
||||
}
|
||||
|
||||
public ActUserReceiveEnum specialCoupon(ActCouponEntity actCouponEntity, SysUser sysUser) {
|
||||
if (true) {
|
||||
return ActUserReceiveEnum.USER_CAN_JOIN_ACT;
|
||||
}
|
||||
// 食堂生日券
|
||||
if (ObjectUtil.equals(actCouponEntity.getUniqueCode(), "1qRgFo")) {
|
||||
// 判断是否为食堂用户
|
||||
|
||||
+27
-17
@@ -92,25 +92,14 @@ public class ActCouponComUtilService implements ActCouponLifecycleService {
|
||||
@Override
|
||||
public ActCouponRecordEntity preCancel(ActCouponRecordEntity record) {
|
||||
ActCouponRecordEntity couponRecord = actCouponRecordMapper.selectById(record.getCouponId());
|
||||
if (ObjectUtil.isEmpty(couponRecord)) {
|
||||
throw new RuntimeException("优惠券不存在");
|
||||
}
|
||||
// 基本校验:状态是否可用
|
||||
if (ObjectUtil.notEqual(ActCouponRecordStatusEnum.UNUSED.getCode(), couponRecord.getStatus())) {
|
||||
throw new RuntimeException("优惠券不可用");
|
||||
}
|
||||
// 校验有效期
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if (ObjectUtil.isNotEmpty(couponRecord.getStartTime()) && now.isBefore(couponRecord.getStartTime())) {
|
||||
throw new RuntimeException("优惠券尚未生效");
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(couponRecord.getEndTime()) && now.isAfter(couponRecord.getEndTime())) {
|
||||
throw new RuntimeException("优惠券已过期");
|
||||
String error = actIsCanCancel(record);
|
||||
if (ObjectUtil.isNotEmpty(error)) {
|
||||
throw new RuntimeException(error);
|
||||
}
|
||||
return couponRecord;
|
||||
}
|
||||
|
||||
public void doCancel(Long couponRecordId, Long orderId, int carTotalPrice) {
|
||||
public void doCancel(Long couponRecordId, Long orderId, int useAmountPrice) {
|
||||
ActCouponRecordEntity couponRecord = actCouponRecordMapper.selectById(couponRecordId);
|
||||
if (ObjectUtil.isEmpty(couponRecord)) {
|
||||
throw new RuntimeException("此优惠券不存在");
|
||||
@@ -120,7 +109,7 @@ public class ActCouponComUtilService implements ActCouponLifecycleService {
|
||||
updateObj.setStatus(ActCouponRecordStatusEnum.USED.getCode());
|
||||
updateObj.setUseTime(LocalDateTime.now());
|
||||
updateObj.setOrderId(String.valueOf(orderId));
|
||||
updateObj.setUseAmount(carTotalPrice);
|
||||
updateObj.setUseAmount(useAmountPrice);
|
||||
actCouponRecordMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@@ -132,6 +121,28 @@ public class ActCouponComUtilService implements ActCouponLifecycleService {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 活动是否能够核销
|
||||
*/
|
||||
public String actIsCanCancel(ActCouponRecordEntity couponRecord) {
|
||||
if (ObjectUtil.isEmpty(couponRecord)) {
|
||||
return "优惠券不存在";
|
||||
}
|
||||
// 基本校验:状态是否可用
|
||||
if (ObjectUtil.notEqual(ActCouponRecordStatusEnum.UNUSED.getCode(), couponRecord.getStatus())) {
|
||||
return "优惠券不可用";
|
||||
}
|
||||
// 校验有效期
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if (ObjectUtil.isNotEmpty(couponRecord.getStartTime()) && now.isBefore(couponRecord.getStartTime())) {
|
||||
return "优惠券尚未生效";
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(couponRecord.getEndTime()) && now.isAfter(couponRecord.getEndTime())) {
|
||||
return "优惠券已过期";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户是否可以参加活动
|
||||
*/
|
||||
@@ -248,5 +259,4 @@ public class ActCouponComUtilService implements ActCouponLifecycleService {
|
||||
}
|
||||
return "已达到领取上限";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user