2023-03-04 16:29:55 +08:00
|
|
|
|
package com.jsowell.service;
|
|
|
|
|
|
|
2023-05-16 16:24:26 +08:00
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
|
import com.alibaba.fastjson2.TypeReference;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
|
import com.github.pagehelper.PageInfo;
|
2023-05-16 16:24:26 +08:00
|
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
|
|
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
|
|
|
|
|
import com.huifu.adapay.model.Payment;
|
|
|
|
|
|
import com.jsowell.adapay.common.CreateAdaPaymentParam;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.common.constant.CacheConstants;
|
|
|
|
|
|
import com.jsowell.common.constant.Constants;
|
|
|
|
|
|
import com.jsowell.common.core.page.PageResponse;
|
|
|
|
|
|
import com.jsowell.common.core.redis.RedisCache;
|
2023-04-13 15:31:04 +08:00
|
|
|
|
import com.jsowell.common.enums.TitleTypeEnum;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.common.enums.uniapp.BalanceChangesEnum;
|
|
|
|
|
|
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
2023-05-16 16:24:26 +08:00
|
|
|
|
import com.jsowell.common.enums.ykc.ScenarioEnum;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.common.exception.BusinessException;
|
2023-05-16 16:24:26 +08:00
|
|
|
|
import com.jsowell.common.util.AdapayUtil;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.common.util.JWTUtils;
|
|
|
|
|
|
import com.jsowell.common.util.StringUtils;
|
|
|
|
|
|
import com.jsowell.common.util.id.IdUtils;
|
|
|
|
|
|
import com.jsowell.pile.domain.MemberBasicInfo;
|
2023-04-13 15:31:04 +08:00
|
|
|
|
import com.jsowell.pile.domain.MemberInvoiceTitle;
|
2023-03-07 11:12:01 +08:00
|
|
|
|
import com.jsowell.pile.domain.MemberPlateNumberRelation;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.pile.domain.MemberWalletInfo;
|
2023-03-18 10:59:02 +08:00
|
|
|
|
import com.jsowell.pile.domain.PileAuthCard;
|
2023-04-13 15:31:04 +08:00
|
|
|
|
import com.jsowell.pile.dto.BindingCarNoDTO;
|
|
|
|
|
|
import com.jsowell.pile.dto.BindingCardDTO;
|
2023-05-23 10:59:16 +08:00
|
|
|
|
import com.jsowell.pile.dto.InvoiceTitleDTO;
|
2023-04-13 15:31:04 +08:00
|
|
|
|
import com.jsowell.pile.dto.MemberRegisterAndLoginDTO;
|
|
|
|
|
|
import com.jsowell.pile.dto.MemberRegisterDTO;
|
2023-05-16 16:24:26 +08:00
|
|
|
|
import com.jsowell.pile.dto.PaymentScenarioDTO;
|
2023-04-13 15:31:04 +08:00
|
|
|
|
import com.jsowell.pile.dto.UniAppQueryMemberBalanceDTO;
|
|
|
|
|
|
import com.jsowell.pile.dto.WechatLoginDTO;
|
2023-05-16 16:24:26 +08:00
|
|
|
|
import com.jsowell.pile.dto.WeixinPayDTO;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.pile.service.IMemberBasicInfoService;
|
2023-04-13 15:31:04 +08:00
|
|
|
|
import com.jsowell.pile.service.IMemberInvoiceTitleService;
|
2023-03-07 11:12:01 +08:00
|
|
|
|
import com.jsowell.pile.service.IMemberPlateNumberRelationService;
|
2023-03-18 10:59:02 +08:00
|
|
|
|
import com.jsowell.pile.service.IPileAuthCardService;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.pile.service.IPileMerchantInfoService;
|
|
|
|
|
|
import com.jsowell.pile.transaction.dto.MemberTransactionDTO;
|
|
|
|
|
|
import com.jsowell.pile.transaction.service.TransactionService;
|
2023-04-13 15:31:04 +08:00
|
|
|
|
import com.jsowell.pile.vo.uniapp.InvoiceTitleVO;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.pile.vo.uniapp.MemberVO;
|
|
|
|
|
|
import com.jsowell.pile.vo.uniapp.MemberWalletLogVO;
|
|
|
|
|
|
import com.jsowell.wxpay.service.WxAppletRemoteService;
|
2023-03-06 15:17:04 +08:00
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
2023-04-13 15:31:04 +08:00
|
|
|
|
import org.apache.commons.compress.utils.Lists;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
2023-04-13 15:31:04 +08:00
|
|
|
|
import org.springframework.beans.BeanUtils;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2023-05-16 16:24:26 +08:00
|
|
|
|
import org.springframework.cglib.beans.BeanMap;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
2023-03-28 14:31:31 +08:00
|
|
|
|
import java.util.Locale;
|
2023-05-16 16:24:26 +08:00
|
|
|
|
import java.util.Map;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class MemberService {
|
|
|
|
|
|
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private RedisCache redisCache;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private TransactionService transactionService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private IMemberBasicInfoService memberBasicInfoService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private IPileMerchantInfoService pileMerchantInfoService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private WxAppletRemoteService wxAppletRemoteService;
|
|
|
|
|
|
|
2023-03-06 15:17:04 +08:00
|
|
|
|
@Autowired
|
2023-03-07 11:12:01 +08:00
|
|
|
|
private IMemberPlateNumberRelationService memberPlateNumberRelationService;
|
2023-03-06 15:17:04 +08:00
|
|
|
|
|
2023-03-18 10:59:02 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private IPileAuthCardService pileAuthCardService;
|
|
|
|
|
|
|
2023-04-13 15:31:04 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private IMemberInvoiceTitleService memberInvoiceTitleService;
|
|
|
|
|
|
|
2023-05-16 16:24:26 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private OrderService orderService;
|
|
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 校验短信验证码
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void checkVerificationCode(MemberRegisterAndLoginDTO dto) {
|
|
|
|
|
|
// 取出缓存中的验证码进行对比,如果缓存中没有,则超时
|
|
|
|
|
|
String captchaCode = redisCache.getCacheObject(CacheConstants.SMS_VERIFICATION_CODE_KEY + dto.getMobileNumber());
|
|
|
|
|
|
if (StringUtils.isEmpty(captchaCode)) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_VERIFICATION_CODE_TIMEOUT_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 如果缓存中有,但与实际不一致,则为验证码错误
|
|
|
|
|
|
if (!StringUtils.equals(captchaCode, dto.getVerificationCode())) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_VERIFICATION_CODE_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 短信验证码登录注册
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public String memberRegisterAndLogin(MemberRegisterAndLoginDTO dto) {
|
|
|
|
|
|
// 校验短信验证码 两种情况不能通过校验,1-验证码错误;2-超时 验证码10分钟有效
|
|
|
|
|
|
checkVerificationCode(dto);
|
|
|
|
|
|
String merchantId = "";
|
2023-05-06 17:05:20 +08:00
|
|
|
|
return memberRegisterAndLogin(dto.getMobileNumber(), dto.getMerchantId(), dto.getOpenId());
|
2023-03-04 16:29:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 公共登陆注册方法
|
|
|
|
|
|
* @param phoneNumber 手机号
|
|
|
|
|
|
* @param merchantId 商户id
|
2023-05-06 17:05:20 +08:00
|
|
|
|
* @return token返给前端
|
2023-03-04 16:29:55 +08:00
|
|
|
|
*/
|
|
|
|
|
|
private String memberRegisterAndLogin(String phoneNumber, String merchantId, String openId) {
|
|
|
|
|
|
if (StringUtils.isBlank(phoneNumber)) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_GET_MOBILE_NUMBER_BY_CODE_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
// if (Objects.isNull(merchantId)) {
|
|
|
|
|
|
// throw new BusinessException(ReturnCodeEnum.CODE_GET_MERCHANT_ID_BY_APP_ID_ERROR);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// 查询手机号码是否注册过
|
|
|
|
|
|
MemberBasicInfo memberBasicInfo = memberBasicInfoService.selectInfoByMobileNumberAndMerchantId(phoneNumber, merchantId);
|
|
|
|
|
|
if (Objects.isNull(memberBasicInfo)) {
|
|
|
|
|
|
// 不存在则新增数据
|
2023-05-06 16:02:25 +08:00
|
|
|
|
String memberId = generateNewMemberId();
|
2023-03-04 16:29:55 +08:00
|
|
|
|
memberBasicInfo = new MemberBasicInfo();
|
|
|
|
|
|
memberBasicInfo.setStatus(Constants.ONE);
|
|
|
|
|
|
memberBasicInfo.setMemberId(memberId);
|
|
|
|
|
|
memberBasicInfo.setNickName("会员" + memberId);
|
|
|
|
|
|
memberBasicInfo.setMobileNumber(phoneNumber);
|
|
|
|
|
|
memberBasicInfo.setMerchantId(Long.valueOf(merchantId));
|
|
|
|
|
|
memberBasicInfo.setOpenId(openId);
|
|
|
|
|
|
|
|
|
|
|
|
// 首次新建会员,同时新建会员钱包
|
|
|
|
|
|
MemberWalletInfo memberWalletInfo = MemberWalletInfo.builder().memberId(memberId).build();
|
|
|
|
|
|
MemberTransactionDTO memberTransactionDTO = MemberTransactionDTO.builder()
|
|
|
|
|
|
.memberBasicInfo(memberBasicInfo)
|
|
|
|
|
|
.memberWalletInfo(memberWalletInfo)
|
|
|
|
|
|
.build();
|
|
|
|
|
|
transactionService.createMember(memberTransactionDTO);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (StringUtils.isBlank(memberBasicInfo.getOpenId()) && StringUtils.isNotBlank(openId)) {
|
|
|
|
|
|
memberBasicInfo.setOpenId(openId);
|
|
|
|
|
|
memberBasicInfoService.updateMemberBasicInfo(memberBasicInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 服务器生成token返给前端
|
|
|
|
|
|
String memberToken = JWTUtils.createMemberToken(memberBasicInfo.getMemberId(), memberBasicInfo.getNickName());
|
|
|
|
|
|
// log.info("memToken:{}", memberToken);
|
|
|
|
|
|
return memberToken;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-06 16:02:25 +08:00
|
|
|
|
private String generateNewMemberId() {
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
String memberId = IdUtils.getMemberId();
|
|
|
|
|
|
// 通过memberId查询是否已经存在
|
|
|
|
|
|
MemberVO memberVO = memberBasicInfoService.queryMemberInfoByMemberId(memberId);
|
|
|
|
|
|
if (memberVO == null) {
|
|
|
|
|
|
return memberId;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 微信一键登录
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
*/
|
|
|
|
|
|
public String wechatLogin(WechatLoginDTO dto) {
|
|
|
|
|
|
// 通过微信传的code获取手机号码
|
|
|
|
|
|
String mobileNumber = wxAppletRemoteService.getMobileNumberByCode(dto.getCode());
|
|
|
|
|
|
if (StringUtils.isBlank(mobileNumber)) {
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_GET_MOBILE_NUMBER_BY_CODE_ERROR);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 通过appid获取运营商id
|
|
|
|
|
|
String merchantId = pileMerchantInfoService.getMerchantIdByAppId(dto.getAppId());
|
|
|
|
|
|
// if (Objects.isNull(merchantId)) {
|
|
|
|
|
|
// throw new BusinessException(ReturnCodeEnum.CODE_GET_MERCHANT_ID_BY_APP_ID_ERROR);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// 通过code获取openId
|
|
|
|
|
|
String openId = "";
|
|
|
|
|
|
try {
|
|
|
|
|
|
openId = getOpenIdByCode(dto.getOpenIdCode());
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.error("getOpenIdByCode发生异常", e);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 查询手机号码是否注册过
|
|
|
|
|
|
return memberRegisterAndLogin(mobileNumber, merchantId, openId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取openId
|
|
|
|
|
|
* @param code
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public String getOpenIdByCode(String code) {
|
|
|
|
|
|
return wxAppletRemoteService.getOpenIdByCode(code);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 处理用户信息
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param dto 用户个人信息
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void handleUserInfo(MemberRegisterDTO dto) {
|
|
|
|
|
|
// 通过用户手机号查询数据库,如果数据库中存在,则更新
|
|
|
|
|
|
MemberBasicInfo memberBasicInfo = memberBasicInfoService.selectInfoByMobileNumber(dto.getMobileNumber());
|
|
|
|
|
|
if (Objects.nonNull(memberBasicInfo)) {
|
|
|
|
|
|
MemberBasicInfo memberInfo = MemberBasicInfo.builder()
|
|
|
|
|
|
.avatarUrl(dto.getAvatarUrl())
|
|
|
|
|
|
.mobileNumber(dto.getMobileNumber())
|
|
|
|
|
|
.nickName(dto.getNickName())
|
|
|
|
|
|
.build();
|
|
|
|
|
|
memberBasicInfoService.updateMemberBasicInfo(memberInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 通过memberToken获取用户账户信息
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param memberId
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public MemberVO getMemberInfoByMemberId(String memberId) {
|
|
|
|
|
|
MemberVO memberVO = memberBasicInfoService.queryMemberInfoByMemberId(memberId);
|
2023-03-30 15:35:14 +08:00
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
return memberVO;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询用户账户余额变动信息
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
*/
|
|
|
|
|
|
public PageResponse getMemberBalanceChanges(UniAppQueryMemberBalanceDTO dto) {
|
|
|
|
|
|
|
|
|
|
|
|
// 获取分页信息以及memberId
|
|
|
|
|
|
int pageNum = dto.getPageNum() == 0 ? 1 : dto.getPageNum();
|
|
|
|
|
|
int pageSize = dto.getPageSize() == 0 ? 10 : dto.getPageSize();
|
|
|
|
|
|
String memberId = dto.getMemberId();
|
|
|
|
|
|
String type = dto.getType();
|
|
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.equals("1", type) && !StringUtils.equals("2", type)) {
|
|
|
|
|
|
type = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
// 分页
|
|
|
|
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
|
|
|
|
List<MemberWalletLogVO> list = memberBasicInfoService.getMemberBalanceChanges(memberId, type);
|
|
|
|
|
|
PageInfo<MemberWalletLogVO> pageInfo = new PageInfo<>(list);
|
|
|
|
|
|
|
|
|
|
|
|
for (MemberWalletLogVO walletLogVO : pageInfo.getList()) {
|
|
|
|
|
|
String subType = walletLogVO.getSubType();
|
|
|
|
|
|
String subTypeValue = BalanceChangesEnum.getValueByCode(subType);
|
|
|
|
|
|
if (StringUtils.isNotBlank(subTypeValue)) {
|
|
|
|
|
|
walletLogVO.setSubType(subTypeValue);
|
|
|
|
|
|
}
|
|
|
|
|
|
// walletLogVO.setTotalAccountAmount(walletLogVO.getPrincipalBalance().add(walletLogVO.getGiftBalance()));
|
|
|
|
|
|
}
|
|
|
|
|
|
PageResponse pageResponse = PageResponse.builder()
|
|
|
|
|
|
.pageSize(pageSize)
|
|
|
|
|
|
.pageNum(pageNum)
|
|
|
|
|
|
.list(pageInfo.getList())
|
|
|
|
|
|
.pages(pageInfo.getPages())
|
|
|
|
|
|
.total(pageInfo.getTotal())
|
|
|
|
|
|
.build();
|
|
|
|
|
|
return pageResponse;
|
|
|
|
|
|
}
|
2023-03-06 08:36:39 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 用户绑定车牌号
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void memberBindingCarNo(BindingCarNoDTO dto){
|
|
|
|
|
|
// 校验短信验证码
|
|
|
|
|
|
MemberRegisterAndLoginDTO registerAndLoginDTO = MemberRegisterAndLoginDTO.builder()
|
|
|
|
|
|
.mobileNumber(dto.getPhoneNumber())
|
|
|
|
|
|
.verificationCode(dto.getVerificationCode())
|
|
|
|
|
|
.build();
|
2023-03-06 16:38:28 +08:00
|
|
|
|
checkVerificationCode(registerAndLoginDTO);
|
2023-03-06 08:36:39 +08:00
|
|
|
|
|
2023-03-06 13:52:41 +08:00
|
|
|
|
// 判断当前车牌号是否已经绑定
|
2023-03-07 11:12:01 +08:00
|
|
|
|
MemberPlateNumberRelation relation = new MemberPlateNumberRelation();
|
2023-03-06 15:17:04 +08:00
|
|
|
|
relation.setMemberId(dto.getMemberId());
|
|
|
|
|
|
relation.setLicensePlateNumber(dto.getCarNo());
|
2023-03-10 14:12:01 +08:00
|
|
|
|
List<MemberPlateNumberRelation> list = memberPlateNumberRelationService.selectMemberPlateNumberRelationList(relation);
|
2023-03-06 15:17:04 +08:00
|
|
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
|
|
|
|
// 不为空说明该用户绑定过此车牌号
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_THIS_CARNO_HAS_BEEN_BINDING);
|
2023-03-06 13:52:41 +08:00
|
|
|
|
}
|
2023-03-06 15:17:04 +08:00
|
|
|
|
relation.setPhoneNumber(dto.getPhoneNumber());
|
2023-03-11 15:57:20 +08:00
|
|
|
|
memberPlateNumberRelationService.insertMemberPlateNumberRelation(relation);
|
2023-03-06 08:36:39 +08:00
|
|
|
|
}
|
2023-03-18 10:59:02 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 用户绑定鉴权卡
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
*/
|
|
|
|
|
|
public int memberBindCard(BindingCardDTO dto){
|
|
|
|
|
|
// 校验短信验证码
|
|
|
|
|
|
MemberRegisterAndLoginDTO registerAndLoginDTO = MemberRegisterAndLoginDTO.builder()
|
|
|
|
|
|
.mobileNumber(dto.getPhoneNumber())
|
|
|
|
|
|
.verificationCode(dto.getVerificationCode())
|
|
|
|
|
|
.build();
|
2023-03-20 17:02:30 +08:00
|
|
|
|
checkVerificationCode(registerAndLoginDTO);
|
2023-03-18 10:59:02 +08:00
|
|
|
|
// 判断当前鉴权卡是否被绑定过
|
2023-03-30 10:54:02 +08:00
|
|
|
|
PileAuthCard pileAuthCardInfo = pileAuthCardService.selectCardInfoByLogicCard(dto.getLogicCard());
|
2023-03-18 10:59:02 +08:00
|
|
|
|
if (pileAuthCardInfo == null){
|
|
|
|
|
|
// 为空说明没查到此卡信息
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_THIS_CARD_HAS_NO_INFO);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isNotBlank(pileAuthCardInfo.getMemberId())) {
|
|
|
|
|
|
// memberId 不为空,说明此卡已被绑定
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_THIS_CARD_HAS_BEEN_BINDING);
|
|
|
|
|
|
}
|
2023-03-28 14:31:31 +08:00
|
|
|
|
if (!StringUtils.equals(pileAuthCardInfo.getSecretKey(), dto.getSecretKey().toUpperCase(Locale.ROOT))) {
|
|
|
|
|
|
// 密钥不一致,不能绑定
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_SECRET_KEY_NOT_SAME);
|
|
|
|
|
|
}
|
2023-03-30 10:54:02 +08:00
|
|
|
|
PileAuthCard authCard = PileAuthCard.builder()
|
|
|
|
|
|
.memberId(dto.getMemberId())
|
|
|
|
|
|
.status("1") // 1-正常使用
|
|
|
|
|
|
.createBy(dto.getMemberId())
|
|
|
|
|
|
.id(pileAuthCardInfo.getId())
|
|
|
|
|
|
.build();
|
2023-03-18 10:59:02 +08:00
|
|
|
|
return pileAuthCardService.updatePileAuthCard(authCard);
|
|
|
|
|
|
}
|
2023-03-20 17:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 用户解绑鉴权卡
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public int memberUnbindCard(BindingCardDTO dto) {
|
|
|
|
|
|
// 校验短信验证码
|
|
|
|
|
|
MemberRegisterAndLoginDTO registerAndLoginDTO = MemberRegisterAndLoginDTO.builder()
|
|
|
|
|
|
.mobileNumber(dto.getPhoneNumber())
|
|
|
|
|
|
.verificationCode(dto.getVerificationCode())
|
|
|
|
|
|
.build();
|
|
|
|
|
|
// checkVerificationCode(registerAndLoginDTO);
|
|
|
|
|
|
// 校验身份信息
|
|
|
|
|
|
PileAuthCard authCard = PileAuthCard.builder()
|
|
|
|
|
|
.logicCard(dto.getLogicCard())
|
|
|
|
|
|
.memberId(dto.getMemberId())
|
|
|
|
|
|
.build();
|
|
|
|
|
|
PileAuthCard pileAuthCardInfo = pileAuthCardService.selectPileAuthCardInfo(authCard);
|
|
|
|
|
|
if (pileAuthCardInfo == null){
|
|
|
|
|
|
// 为空说明没查到此卡信息
|
|
|
|
|
|
throw new BusinessException(ReturnCodeEnum.CODE_THIS_CARD_HAS_NO_INFO);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 解绑鉴权卡
|
|
|
|
|
|
return pileAuthCardService.unBindingCard(authCard);
|
|
|
|
|
|
}
|
2023-04-13 15:31:04 +08:00
|
|
|
|
|
|
|
|
|
|
public List<InvoiceTitleVO> queryMemberInvoiceTitles(String memberId) {
|
|
|
|
|
|
List<InvoiceTitleVO> resultList = Lists.newArrayList();
|
2023-05-20 16:25:24 +08:00
|
|
|
|
List<MemberInvoiceTitle> memberInvoiceTitles = memberInvoiceTitleService.selectMemberInvoiceTitleList(memberId);
|
2023-04-13 15:31:04 +08:00
|
|
|
|
if (CollectionUtils.isEmpty(memberInvoiceTitles)) {
|
|
|
|
|
|
return resultList;
|
|
|
|
|
|
}
|
|
|
|
|
|
for (MemberInvoiceTitle memberInvoiceTitle : memberInvoiceTitles) {
|
|
|
|
|
|
resultList.add(
|
|
|
|
|
|
InvoiceTitleVO.builder()
|
|
|
|
|
|
.titleId(memberInvoiceTitle.getId() + "")
|
|
|
|
|
|
.titleName(memberInvoiceTitle.getName())
|
|
|
|
|
|
.titleType(TitleTypeEnum.getLabel(memberInvoiceTitle.getTitleType()))
|
2023-05-12 11:21:13 +08:00
|
|
|
|
.taxId(memberInvoiceTitle.getTaxId())
|
|
|
|
|
|
.unitAddress(memberInvoiceTitle.getUnitAddress())
|
|
|
|
|
|
.phoneNumber(memberInvoiceTitle.getPhoneNumber())
|
|
|
|
|
|
.bankName(memberInvoiceTitle.getBankName())
|
|
|
|
|
|
.bankAccountNumber(memberInvoiceTitle.getBankAccountNumber())
|
2023-05-20 16:25:24 +08:00
|
|
|
|
.defaultFlag(memberInvoiceTitle.getDefaultFlag())
|
2023-04-13 15:31:04 +08:00
|
|
|
|
.build()
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
return resultList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-23 10:59:16 +08:00
|
|
|
|
public void createMemberInvoiceTitle(InvoiceTitleDTO dto) {
|
2023-04-13 15:31:04 +08:00
|
|
|
|
MemberInvoiceTitle title = new MemberInvoiceTitle();
|
|
|
|
|
|
BeanUtils.copyProperties(dto, title);
|
2023-05-23 09:02:58 +08:00
|
|
|
|
if (StringUtils.isEmail(dto.getReception())) {
|
|
|
|
|
|
title.setEmail(dto.getReception());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
title.setPhoneNumber(dto.getReception());
|
|
|
|
|
|
}
|
2023-04-13 15:31:04 +08:00
|
|
|
|
int i = memberInvoiceTitleService.insertMemberInvoiceTitle(title);
|
2023-05-23 10:59:16 +08:00
|
|
|
|
// log.info("新增{}条发票抬头", i);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void updateMemberInvoiceTitle(InvoiceTitleDTO dto) {
|
|
|
|
|
|
MemberInvoiceTitle title = new MemberInvoiceTitle();
|
|
|
|
|
|
BeanUtils.copyProperties(dto, title);
|
|
|
|
|
|
if (StringUtils.isEmail(dto.getReception())) {
|
|
|
|
|
|
title.setEmail(dto.getReception());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
title.setPhoneNumber(dto.getReception());
|
|
|
|
|
|
}
|
|
|
|
|
|
int i = memberInvoiceTitleService.updateMemberInvoiceTitle(title);
|
2023-04-13 15:31:04 +08:00
|
|
|
|
}
|
2023-05-16 16:24:26 +08:00
|
|
|
|
|
|
|
|
|
|
public Map<String, Object> rechargeBalance(WeixinPayDTO dto) throws Exception {
|
|
|
|
|
|
PaymentScenarioDTO paymentScenarioDTO = new PaymentScenarioDTO();
|
|
|
|
|
|
paymentScenarioDTO.setType(ScenarioEnum.BALANCE.getValue());
|
|
|
|
|
|
paymentScenarioDTO.setMemberId(dto.getMemberId());
|
|
|
|
|
|
dto.setAttach(JSONObject.toJSONString(paymentScenarioDTO));
|
|
|
|
|
|
dto.setDescription("会员充值余额");
|
|
|
|
|
|
return orderService.weixinPayV3(dto);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String, Object> rechargeBalanceWithAdapay(WeixinPayDTO dto) throws Exception {
|
|
|
|
|
|
// 封装对象
|
|
|
|
|
|
CreateAdaPaymentParam createAdaPaymentParam = new CreateAdaPaymentParam();
|
|
|
|
|
|
createAdaPaymentParam.setOrder_no(IdUtils.fastSimpleUUID());
|
|
|
|
|
|
createAdaPaymentParam.setPay_amt(AdapayUtil.formatAmount(dto.getAmount()));
|
|
|
|
|
|
createAdaPaymentParam.setApp_id("app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa"); // todo 后面移动到配置文件中
|
|
|
|
|
|
createAdaPaymentParam.setPay_channel("wx_lite"); // todo 如果以后有支付宝等别的渠道,这里需要做修改,判断是什么渠道的请求
|
|
|
|
|
|
createAdaPaymentParam.setGoods_title("充电费用1");
|
|
|
|
|
|
createAdaPaymentParam.setGoods_desc("充电费用2");
|
|
|
|
|
|
createAdaPaymentParam.setDescription("充电费用3");
|
|
|
|
|
|
createAdaPaymentParam.setExpend(JSONObject.toJSONString( ImmutableMap.of("open_id", dto.getOpenId())));
|
2023-05-17 15:59:16 +08:00
|
|
|
|
//异步通知地址,url为http/https路径,服务器POST回调,URL 上请勿附带参数
|
|
|
|
|
|
createAdaPaymentParam.setNotify_url("https://api.jsowellcloud.com/uniapp/pay/adapayCallback");
|
2023-05-16 16:24:26 +08:00
|
|
|
|
try {
|
|
|
|
|
|
log.info("创建汇付支付参数:{}", JSONObject.toJSONString(createAdaPaymentParam));
|
|
|
|
|
|
Map<String, Object> response = Payment.create(BeanMap.create(createAdaPaymentParam));
|
2023-05-16 17:14:21 +08:00
|
|
|
|
log.info("创建汇付支付参数反参:{}", JSONObject.toJSONString(response));
|
2023-05-16 16:24:26 +08:00
|
|
|
|
if (response != null && !response.isEmpty()) {
|
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(response.get("expend").toString());
|
|
|
|
|
|
JSONObject pay_info = jsonObject.getJSONObject("pay_info");
|
|
|
|
|
|
Map<String, Object> resultMap = JSONObject.parseObject(pay_info.toJSONString(), new TypeReference<Map<String, Object>>() {});
|
|
|
|
|
|
return resultMap;
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (BaseAdaPayException e) {
|
|
|
|
|
|
log.error("汇付-获取支付对象发生异常", e);
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2023-05-23 10:59:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
}
|