feat: 支付宝相关支付

pull/2/head
tangqian 2023-05-19 16:45:37 +08:00
parent 5f5497875e
commit 3a209f056b
20 changed files with 185 additions and 98 deletions

View File

@ -36,5 +36,9 @@ public class AliPayProperties {
* .
*/
private String notifyUrl;
/**
* .
*/
private String refundNotify;
}

View File

@ -1,47 +0,0 @@
package cn.iocoder.yudao.module.shop.request.member;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* @Title:AlipayNotifyParamRequest
* @Description: TODO
* @author: tangqian
* @date: 2023/5/19 10:27
* @version: V1.0.0
*/
@Data
@Accessors(chain = true)
public class AlipayNotifyParamRequest implements Serializable {
private static final long serialVersionUID = 5839750515063699319L;
private String appId;
private String tradeNo; // 支付宝交易凭证号
private String outTradeNo; // 原支付请求的商户订单号
private String outBizNo; // 商户业务ID主要是退款通知中返回退款申请的流水号
private String buyerId; // 买家支付宝账号对应的支付宝唯一用户号。以2088开头的纯16位数字
private String buyerLogonId; // 买家支付宝账号
private String sellerId; // 卖家支付宝用户号
private String sellerEmail; // 卖家支付宝账号
private String tradeStatus; // 交易目前所处的状态,见交易状态说明
private String totalAmount; // 本次交易支付的订单金额
private String receiptAmount; // 商家在交易中实际收到的款项
private String buyerPayAmount; // 用户在交易中支付的金额
private String refundFee; // 退款通知中,返回总退款金额,单位为元,支持两位小数
private String subject; // 商品的标题/交易标题/订单标题/订单关键字等
private String body; // 该订单的备注、描述、明细等。对应请求时的body参数原样通知回来
private Date gmtCreate; // 该笔交易创建的时间。格式为yyyy-MM-dd HH:mm:ss
private Date gmtPayment; // 该笔交易的买家付款时间。格式为yyyy-MM-dd HH:mm:ss
private Date notifyTime; // 通知时间。格式为yyyy-MM-dd HH:mm:ss
private Date gmtRefund; // 该笔交易的退款时间。格式为yyyy-MM-dd HH:mm:ss.S
private Date gmtClose; // 该笔交易结束时间。格式为yyyy-MM-dd HH:mm:ss
private String fundBillList; // 支付成功的各个渠道金额信息,array
private String passbackParams; // 公共回传参数,如果请求时传递了该参数,则返回给商户时会在异步通知时将该参数原样返回。
private String authAppId;
private String notifyId;
private String notifyType;
private String version;
private String invoiceAmount;//交易中可给用户开具发票的金额
}

View File

@ -7,6 +7,7 @@ import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.List;
@ -43,7 +44,7 @@ public class OrderContentRequest implements Serializable {
private static final long serialVersionUID = -4967251473044468810L;
@Schema(description = "订单id")
@NotNull(message = "挡位id不能为空")
private String gearId;
private Long gearId;
@Schema(description = "档位名称")
@NotEmpty(message = "挡位名称不能为空")

View File

@ -1,8 +1,12 @@
package cn.iocoder.yudao.module.shop.controller.admin.notify;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderDO;
import cn.iocoder.yudao.module.shop.dal.mysql.recharge.RechargeOrderMapper;
import cn.iocoder.yudao.module.shop.service.order.StoreOrderService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.binarywang.wxpay.bean.notify.OriginNotifyResponse;
import com.github.binarywang.wxpay.bean.notify.SignatureHeader;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyV3Result;
@ -19,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
/**
@ -38,6 +43,8 @@ public class WxPayNotifyController {
@Autowired
private StoreOrderService storeOrderService;
@Autowired
private RechargeOrderMapper rechargeOrderMapper;
/**
@ -113,13 +120,21 @@ public class WxPayNotifyController {
log.info("退款原始通知=" + JSONUtil.toJsonPrettyStr(jsonData));
try {
//解密后的数据
v3Result = wxPayService.parseRefundNotifyV3Result(JSONUtil.toJsonPrettyStr(notifyResponse), this.getRequestHeader(request));
v3Result = wxPayService.parseRefundNotifyV3Result(jsonData, this.getRequestHeader(request));
WxPayRefundNotifyV3Result.DecryptNotifyResult result = v3Result.getResult();
log.info("退款通知=" + JSONUtil.toJsonPrettyStr(result));
//退款状态
if (StringUtils.equals("SUCCESS", result.getRefundId())) {
if (StringUtils.equals("SUCCESS", result.getRefundStatus())) {
log.info("微信退款回调成功");
// 验证相关参数-金额
// 用户支付金额
BigDecimal payerTotal = NumberUtil.div(result.getAmount().getPayerTotal() + "", "100", 2);
// 处理相关逻辑
RechargeOrderDO orderDO = rechargeOrderMapper.selectOne(Wrappers.<RechargeOrderDO>lambdaQuery().eq(RechargeOrderDO::getOrderId, result.getOutRefundNo()));
if (payerTotal.compareTo(orderDO.getPayPrice()) != 0) {
log.error("支付金额不匹配,订单实际支付金额:{},微信入参验证金额:{}", orderDO.getPayPrice(), payerTotal);
return "failure";
}
// 修改订单状态
// 写入
response.setStatus(HttpServletResponse.SC_OK);

View File

@ -27,6 +27,7 @@ import cn.iocoder.yudao.module.shop.controller.admin.recharge.vo.*;
import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderInfoDO;
import cn.iocoder.yudao.module.shop.convert.recharge.RechargeOrderInfoConvert;
import cn.iocoder.yudao.module.shop.service.recharge.RechargeOrderInfoService;
import sun.rmi.runtime.Log;
@Tag(name = "管理后台 - 订单购物详情")
@RestController
@ -40,7 +41,7 @@ public class RechargeOrderInfoController {
@PostMapping("/create")
@Operation(summary = "创建订单购物详情")
@PreAuthorize("@ss.hasPermission('shop:recharge-order-info:create')")
public CommonResult<Integer> createRechargeOrderInfo(@Valid @RequestBody RechargeOrderInfoCreateReqVO createReqVO) {
public CommonResult<Long> createRechargeOrderInfo(@Valid @RequestBody RechargeOrderInfoCreateReqVO createReqVO) {
return success(rechargeOrderInfoService.createRechargeOrderInfo(createReqVO));
}

View File

@ -11,7 +11,7 @@ import java.time.LocalDateTime;
public class RechargeGearRespVO extends RechargeGearBaseVO {
@Schema(description = "主键", required = true, example = "3324")
private String id;
private Long id;
@Schema(description = "创建时间", required = true)
private LocalDateTime createTime;

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.shop.controller.app.buy;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.shop.request.member.OrderContentRequest;
import cn.iocoder.yudao.module.shop.request.member.RefundRequest;
import cn.iocoder.yudao.module.shop.response.member.InitOrderResponse;
@ -38,6 +39,7 @@ public class TopUpOrderController {
log.info("initOrder会员充值===>{}", request);
return CommonResult.success(storeOrderService.memberTopUp(request, servletRequest));
}
@TenantIgnore
@PreAuthenticated
@Operation(summary = "退款")
@RequestMapping(value = "/memberRefund", method = RequestMethod.POST)
@ -45,6 +47,7 @@ public class TopUpOrderController {
log.info("memberRefund会员退款===>{}", request);
return CommonResult.success(storeOrderService.memberRefund(request, servletRequest));
}
@TenantIgnore
@PreAuthenticated
@Operation(summary = "申请退款")
@RequestMapping(value = "/memberApplyRefund", method = RequestMethod.POST)

View File

@ -169,4 +169,14 @@ public class RechargeOrderDO extends BaseDO {
private String updater;
private Boolean deleted;
/**
* 广id
*/
private Long promoterId;
/**
* id
*/
private Long deptId;
}

View File

@ -28,7 +28,7 @@ public class RechargeOrderInfoDO extends BaseDO {
*
*/
@TableId
private Integer id;
private Long id;
/**
* id
*/
@ -36,7 +36,7 @@ public class RechargeOrderInfoDO extends BaseDO {
/**
*
*/
private Integer rechargeGearId;
private Long rechargeGearId;
/**
*
*/
@ -74,5 +74,19 @@ public class RechargeOrderInfoDO extends BaseDO {
private String updater;
private LocalDateTime createTime;
private LocalDateTime updateTime;
/**
* 广id
*/
private Long promoterId;
/**
* id
*/
private Long deptId;
/**
* id
*/
private Long uid;
}

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.shop.service.order.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
@ -15,9 +14,9 @@ import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.pay.properties.AliPayProperties;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.infra.api.config.ApiConfigApi;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.member.api.user.dto.PromoterDTO;
import cn.iocoder.yudao.module.shop.dal.dataobject.express.ExpressDO;
import cn.iocoder.yudao.module.shop.dal.dataobject.order.StoreOrder;
import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.PhoneRecordDO;
@ -27,7 +26,6 @@ import cn.iocoder.yudao.module.shop.dal.mysql.order.StoreOrderMapper;
import cn.iocoder.yudao.module.shop.dal.mysql.recharge.PhoneRecordMapper;
import cn.iocoder.yudao.module.shop.dal.mysql.recharge.RechargeOrderInfoMapper;
import cn.iocoder.yudao.module.shop.dal.mysql.recharge.RechargeOrderMapper;
import cn.iocoder.yudao.module.shop.request.member.AlipayNotifyParamRequest;
import cn.iocoder.yudao.module.shop.request.member.OrderContentRequest;
import cn.iocoder.yudao.module.shop.request.member.RefundRequest;
import cn.iocoder.yudao.module.shop.request.order.StoreOrderRefundRequest;
@ -43,7 +41,9 @@ import cn.iocoder.yudao.module.shop.service.order.StoreOrderService;
import cn.iocoder.yudao.module.shop.service.order.StoreOrderStatusService;
import cn.iocoder.yudao.module.shop.support.StrategySupport;
import cn.iocoder.yudao.module.shop.support.pay.IPayStrategy;
import cn.iocoder.yudao.module.shop.utils.*;
import cn.iocoder.yudao.module.shop.utils.CommonPage;
import cn.iocoder.yudao.module.shop.utils.OrderUtil;
import cn.iocoder.yudao.module.shop.utils.RedisUtil;
import cn.iocoder.yudao.module.shop.vo.order.LogisticsResultVo;
import cn.iocoder.yudao.module.shop.vo.order.StoreDateRangeSqlPram;
import cn.iocoder.yudao.module.shop.vo.order.StoreOrderInfoOldVo;
@ -61,7 +61,6 @@ import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.service.WxOAuth2Service;
import me.chanjar.weixin.mp.api.WxMpService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
@ -75,12 +74,12 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
@ -1154,12 +1153,13 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOr
public InitOrderResponse memberTopUp(OrderContentRequest request, HttpServletRequest servletRequest) {
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
Assert.notNull(loginUser, "登录失效,请重新登录!");
// 订单相关检查
orderCheck(request);
// 初始化订单
MemberUserRespDTO user = userService.getUser(loginUser.getId());
PromoterDTO promoterDTO = userService.getPromoterDOByUserId(user.getId());
// 订单相关检查
orderCheck(request, user);
// 初始化订单
String code = OrderUtil.generateBillNo("MEMBER");
RechargeOrderDO orderDO = initializeOrder(request, code, user);
RechargeOrderDO orderDO = initializeOrder(request, code, user, promoterDTO);
// 获取支付策略
IPayStrategy payStrategy = strategySupport.getPayStrategy(request.getPayType());
@ -1193,17 +1193,28 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOr
return "failure";
}
// 验证相关参数-金额
String amount = params.get("receipt_amount");
String amount;
if (null == params.get("receipt_amount")) {
amount = params.get("refund_fee");
orderDO.setPaid(2);
orderDO.setRefundStatus(2);
// 表示退款
} else {
// 表示支付
amount = params.get("receipt_amount");
orderDO.setPaySerialNumber(params.get("trade_no"));
orderDO.setPaid(1);
}
if (new BigDecimal(amount).compareTo(orderDO.getPayPrice()) != 0) {
log.error("支付金额不匹配,订单实际支付金额:{},支付宝入参验证金额:{}", orderDO.getPayPrice(), amount);
return "failure";
}
// 修改订单状态
orderDO.setPaid(1);
orderDO.setPaySerialNumber(params.get("trade_no"));
rechargeOrderMapper.updateById(orderDO);
// 写入 充值档位记录表
addPhoneRecord(orderDO, orderId);
if (null != params.get("receipt_amount")) {
addPhoneRecord(orderDO, orderId);
}
log.debug(">>>>>>>>>>>>>>支付宝订单交易成功!订单号:{}<<<<<<<<<<<<<<<<<<<<", orderId);
return "success";
} else {
@ -1253,6 +1264,8 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOr
@Override
public Object refundNotify(HttpServletRequest request, HttpServletResponse response) {
Map<String, String> params = new HashMap<String, String>();
Map requestParams = request.getParameterMap();
for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
@ -1338,7 +1351,7 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOr
}
private RechargeOrderDO initializeOrder(OrderContentRequest request, String code, MemberUserRespDTO user) {
private RechargeOrderDO initializeOrder(OrderContentRequest request, String code, MemberUserRespDTO user, PromoterDTO promoterDTO) {
RechargeOrderDO orderDO = new RechargeOrderDO();
List<OrderContentRequest.OrderInfo> orderInfos = request.getOrderInfos();
orderDO.setOrderId(code);
@ -1357,6 +1370,8 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOr
orderDO.setCost(sum);
orderDO.setProTotalPrice(sum);
orderDO.setBeforePayPrice(sum);
orderDO.setPromoterId(user.getPromoterId());
orderDO.setDeptId(promoterDTO.getDeptId());
rechargeOrderMapper.insert(orderDO);
List<RechargeOrderInfoDO> infoDOS = new ArrayList<>();
orderInfos.forEach(info -> {
@ -1368,16 +1383,31 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOr
infoDO.setPayNum(1);
infoDO.setGiveIntegral(info.getGearAmount());
infoDO.setVipPrice(new BigDecimal(info.getGearAmount()));
infoDO.setPromoterId(user.getPromoterId());
infoDO.setDeptId(promoterDTO.getDeptId());
infoDO.setUid(user.getId());
infoDO.setRechargeGearId(info.getGearId());
infoDOS.add(infoDO);
});
rechargeOrderInfoMapper.insertBatch(infoDOS);
return orderDO;
}
private void orderCheck(OrderContentRequest request) {
Assert.isTrue(!CollectionUtils.isEmpty(request.getOrderInfos()), "订单信息不能为空!");
private void orderCheck(OrderContentRequest request, MemberUserRespDTO user) {
List<OrderContentRequest.OrderInfo> orderInfos = request.getOrderInfos();
Assert.isTrue(!CollectionUtils.isEmpty(orderInfos), "订单信息不能为空!");
List<Long> collect = orderInfos.stream().map(OrderContentRequest.OrderInfo::getGearId).collect(Collectors.toList());
List<RechargeOrderInfoDO> infoDOS = rechargeOrderInfoMapper.selectList(Wrappers.<RechargeOrderInfoDO>lambdaQuery()
.eq(RechargeOrderInfoDO::getUid, user.getId())
.in(RechargeOrderInfoDO::getRechargeGearId, collect));
if (!CollectionUtils.isEmpty(infoDOS)) {
Map<Long, List<RechargeOrderInfoDO>> collect1 = infoDOS.stream().collect(Collectors.groupingBy(RechargeOrderInfoDO::getRechargeGearId));
orderInfos.forEach(info -> {
Assert.isTrue(CollectionUtils.isEmpty(collect1.get(info.getGearId())), "该挡位:" + info.getName() + "你已购买,请勿重复操作");
});
}
if (StringUtils.isNotBlank(request.getUserPhone()) && StringUtils.isNotBlank(request.getConfirmPhone())) {
Assert.isTrue(StringUtils.equals(request.getUserPhone(), request.getConfirmPhone()), "输入号码不一致!");
Assert.isTrue(Pattern.matches("^[1][3,4,5,7,8][0,1,2,4,5,6,7,8,9][0-9]{8}$", request.getUserPhone()), "手机号前三位不能是190或193!");
MemberUserRespDTO userByMobile = userService.getUserByMobile(request.getUserPhone());
// 初始化一个账号
if (Objects.isNull(userByMobile)) {

View File

@ -106,7 +106,7 @@ public class RechargeGearServiceImpl implements RechargeGearService {
RechargeOrderDO orderDO = orderMapper.selectOne(Wrappers.<RechargeOrderDO>lambdaQuery().eq(RechargeOrderDO::getUid, loginUser.getId()).last("LIMIT 1"));
if (Objects.nonNull(orderDO)) {
List<RechargeOrderInfoDO> infoDOS = orderInfoMapper.selectList(Wrappers.<RechargeOrderInfoDO>lambdaQuery().eq(RechargeOrderInfoDO::getOrderNo, orderDO.getOrderId()));
Map<Integer, List<RechargeOrderInfoDO>> collect = infoDOS.stream().collect(Collectors.groupingBy(RechargeOrderInfoDO::getRechargeGearId));
Map<Long, List<RechargeOrderInfoDO>> collect = infoDOS.stream().collect(Collectors.groupingBy(RechargeOrderInfoDO::getRechargeGearId));
rechargeGearRespVOS.forEach(vo -> {
List<RechargeOrderInfoDO> infoDOS1 = collect.get(vo.getId());
if (!CollectionUtils.isEmpty(infoDOS1)) {

View File

@ -19,7 +19,7 @@ public interface RechargeOrderInfoService {
* @param createReqVO
* @return
*/
Integer createRechargeOrderInfo(@Valid RechargeOrderInfoCreateReqVO createReqVO);
Long createRechargeOrderInfo(@Valid RechargeOrderInfoCreateReqVO createReqVO);
/**
*

View File

@ -29,7 +29,7 @@ public class RechargeOrderInfoServiceImpl implements RechargeOrderInfoService {
private RechargeOrderInfoMapper rechargeOrderInfoMapper;
@Override
public Integer createRechargeOrderInfo(RechargeOrderInfoCreateReqVO createReqVO) {
public Long createRechargeOrderInfo(RechargeOrderInfoCreateReqVO createReqVO) {
// 插入
RechargeOrderInfoDO rechargeOrderInfo = RechargeOrderInfoConvert.INSTANCE.convert(createReqVO);
rechargeOrderInfoMapper.insert(rechargeOrderInfo);

View File

@ -72,7 +72,7 @@ public class AliPayStrategy implements IPayStrategy {
bizContent.put("trade_no", orderDO.getPaySerialNumber());
bizContent.put("refund_amount", orderDO.getPayPrice());
bizContent.put("out_request_no", orderDO.getOrderId());
bizContent.put("notify_url",aliPayProperties.getRefundNotify());
request.setBizContent(bizContent.toString());
AlipayTradeRefundResponse response = null;
try {

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.member.api.user;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserBillDTO;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.member.api.user.dto.PromoterDTO;
import java.util.Collection;
import java.util.List;
@ -80,4 +81,6 @@ public interface MemberUserApi {
void saveMemberUser(String phone);
PromoterDTO getPromoterDOByUserId(Long userId);
}

View File

@ -36,5 +36,8 @@ public class MemberUserRespDTO {
*/
private String mobile;
/**
* 广id
*/
private Long promoterId;
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.member.api.user.dto;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
/**
* @Title:PromoterDTO
* @Description: TODO
* @author: tangqian
* @date: 2023/5/19 14:06
* @version: V1.0.0
*/
@Data
public class PromoterDTO {
/**
*
*/
private Long id;
/**
* id
*/
private Long deptId;
/**
* id
*/
private Long userId;
}

View File

@ -4,8 +4,11 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.member.api.user.dto.PromoterDTO;
import cn.iocoder.yudao.module.member.convert.user.UserConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.promoter.PromoterDO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.service.promoter.PromoterService;
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import com.thoughtworks.xstream.core.SecurityUtils;
import org.springframework.stereotype.Service;
@ -26,6 +29,8 @@ public class MemberUserApiImpl implements MemberUserApi {
@Resource
private MemberUserService userService;
@Resource
private PromoterService promoterService;
@Override
@TenantIgnore
@ -102,6 +107,15 @@ public class MemberUserApiImpl implements MemberUserApi {
userService.saveMemberUser(phone);
}
@Override
public PromoterDTO getPromoterDOByUserId(Long userId) {
PromoterDTO promoterDTO = new PromoterDTO();
PromoterDO promoterDO = promoterService.getPromoterDOByUserId(userId);
promoterDTO.setDeptId(promoterDO.getDeptId());
promoterDO.setId(promoterDO.getId());
return promoterDTO;
}
/**
*
*

View File

@ -86,4 +86,5 @@ public interface PromoterService {
*/
PromoterImportRespVO importUserList(List<PromoterImportExcelVO> importUsers, boolean isUpdateSupport);
PromoterDO getPromoterDOByUserId(Long userId);
}

View File

@ -16,6 +16,7 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.validation.Validator;
@ -24,6 +25,7 @@ import org.springframework.validation.annotation.Validated;
import java.time.LocalDateTime;
import java.util.*;
import cn.iocoder.yudao.module.member.controller.admin.promoter.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.promoter.PromoterDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -62,20 +64,20 @@ public class PromoterServiceImpl implements PromoterService {
public Long createPromoter(PromoterCreateReqVO createReqVO) {
//判断手机号是否注册
MemberUserDO memberUserDO = memberUserService.getUserByMobile(createReqVO.getMobile());
if(memberUserDO==null){
if (memberUserDO == null) {
//创建用户
memberUserDO = new MemberUserDO();
memberUserDO.setNickname(createReqVO.getNickname());
memberUserDO.setMobile(createReqVO.getMobile());
memberUserDO.setStatus(createReqVO.getStatus());
memberUserDO.setPassword(createReqVO.getMobile().substring(createReqVO.getMobile().length()-6));
memberUserService.createUserIfAbsent(createReqVO.getMobile(),createReqVO.getNickname(),getClientIP());
memberUserDO.setPassword(createReqVO.getMobile().substring(createReqVO.getMobile().length() - 6));
memberUserService.createUserIfAbsent(createReqVO.getMobile(), createReqVO.getNickname(), getClientIP());
}
// 插入
PromoterDO promoter = PromoterConvert.INSTANCE.convert(createReqVO);
promoter.setTenantId(SecurityFrameworkUtils.getLoginUser().getTenantId());
Long count = promoterMapper.selectCount(Wrappers.lambdaQuery(PromoterDO.class).eq(PromoterDO::getUserId,memberUserDO.getId()));
if(count>0){
Long count = promoterMapper.selectCount(Wrappers.lambdaQuery(PromoterDO.class).eq(PromoterDO::getUserId, memberUserDO.getId()));
if (count > 0) {
throw new ServiceException(PROMOTER_EXISTS);
}
promoter.setUserId(memberUserDO.getId());
@ -94,9 +96,9 @@ public class PromoterServiceImpl implements PromoterService {
PromoterDO updateObj = PromoterConvert.INSTANCE.convert(updateReqVO);
promoterMapper.updateById(updateObj);
MemberUserDO memberUserDO = memberUserService.getUserByMobile(updateReqVO.getMobile());
if(memberUserDO!=null&&!promoterDO.getUserId().equals(memberUserDO.getId())){
if (memberUserDO != null && !promoterDO.getUserId().equals(memberUserDO.getId())) {
throw new ServiceException(ErrorCodeConstants.USER_PHONE_EXISTS);
}else {
} else {
memberUserDO.setMobile(updateReqVO.getMobile());
memberUserDO.setNickname(updateReqVO.getNickname());
memberUserService.updateById(memberUserDO);
@ -131,8 +133,8 @@ public class PromoterServiceImpl implements PromoterService {
*/
@Override
public Boolean checkIsPromoterByUserId(Long userId) {
Long count = this.promoterMapper.selectCount(Wrappers.lambdaQuery(PromoterDO.class).eq(PromoterDO::getUserId,userId));
return count>0;
Long count = this.promoterMapper.selectCount(Wrappers.lambdaQuery(PromoterDO.class).eq(PromoterDO::getUserId, userId));
return count > 0;
}
@Override
@ -143,14 +145,14 @@ public class PromoterServiceImpl implements PromoterService {
@Override
public PageResult<PromoterRespVO> getPromoterPage(PromoterPageReqVO pageReqVO) {
Page<PromoterRespVO> page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
if(StrUtil.isNotBlank(pageReqVO.getDeptId())){
if (StrUtil.isNotBlank(pageReqVO.getDeptId())) {
DeptRespDTO deptRespDTO = deptApi.getDept(Long.parseLong(pageReqVO.getDeptId()));
if(deptRespDTO!=null){
if (deptRespDTO != null) {
pageReqVO.setDeptId(deptRespDTO.getParentOrganizationIds());
}
}
promoterMapper.findListPage(page,pageReqVO);
promoterMapper.findListPage(page, pageReqVO);
return new PageResult<>(page.getRecords(), page.getTotal());
}
@ -174,37 +176,37 @@ public class PromoterServiceImpl implements PromoterService {
PromoterImportRespVO respVO = PromoterImportRespVO.builder().createUsernames(new ArrayList<>())
.updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build();
List<DeptRespDTO> deptRespDTOList = deptApi.getDeptList();
Map<String,DeptRespDTO> nameList = deptRespDTOList.stream().collect(toMap(DeptRespDTO::getParentOrganizationName, value -> value,(value1,value2)->value1));
Map<String, DeptRespDTO> nameList = deptRespDTOList.stream().collect(toMap(DeptRespDTO::getParentOrganizationName, value -> value, (value1, value2) -> value1));
importUsers.forEach(importUser -> {
try {
ValidationUtils.validate(validator,importUser);
ValidationUtils.validate(validator, importUser);
} catch (ServiceException ex) {
respVO.getFailureUsernames().put(importUser.getNickName(), ex.getMessage());
return;
}
//判断手机号是否注册
MemberUserDO memberUserDO = memberUserService.getUserByMobile(importUser.getMobile());
if(memberUserDO==null){
if (memberUserDO == null) {
//创建用户
memberUserDO = new MemberUserDO();
memberUserDO.setNickname(importUser.getNickName());
memberUserDO.setMobile(importUser.getMobile());
memberUserDO.setPassword(importUser.getMobile().substring(importUser.getMobile().length()-6));
memberUserDO.setPassword(importUser.getMobile().substring(importUser.getMobile().length() - 6));
memberUserDO.setStatus(1);
memberUserService.createUserIfAbsent(importUser.getMobile(),importUser.getNickName(),getClientIP());
memberUserService.createUserIfAbsent(importUser.getMobile(), importUser.getNickName(), getClientIP());
}
// 插入
PromoterDO promoter = new PromoterDO();
promoter.setTenantId(SecurityFrameworkUtils.getLoginUser().getTenantId());
promoter.setUserId(memberUserDO.getId());
promoter.setCreateTime(LocalDateTime.now());
Long count = promoterMapper.selectCount(Wrappers.lambdaQuery(PromoterDO.class).eq(PromoterDO::getUserId,memberUserDO.getId()));
if(count>0){
Long count = promoterMapper.selectCount(Wrappers.lambdaQuery(PromoterDO.class).eq(PromoterDO::getUserId, memberUserDO.getId()));
if (count > 0) {
respVO.getFailureUsernames().put(importUser.getNickName(), "已经是推广员");
return;
}
DeptRespDTO deptRespDTO = nameList.get(importUser.getOrgName());
if(deptRespDTO==null){
if (deptRespDTO == null) {
respVO.getFailureUsernames().put(importUser.getNickName(), "组织不存在");
return;
}
@ -215,6 +217,12 @@ public class PromoterServiceImpl implements PromoterService {
});
return respVO;
}
@Override
public PromoterDO getPromoterDOByUserId(Long userId) {
return promoterMapper.selectOne(Wrappers.<PromoterDO>lambdaQuery().eq(PromoterDO::getUserId, userId).last("LIMIT 1"));
}
/**
*
*