|
@@ -1,24 +1,28 @@
|
|
|
package com.chelvc.cloud.vehicle.server.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.parser.Feature;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.chelvc.cloud.user.client.UserClient;
|
|
|
import com.chelvc.cloud.vehicle.client.constant.TradeConstant;
|
|
|
+import com.chelvc.cloud.vehicle.client.util.SFTPUtils;
|
|
|
import com.chelvc.cloud.vehicle.server.dao.MerchantRelationMapper;
|
|
|
-import com.chelvc.cloud.vehicle.server.entity.Merchant;
|
|
|
-import com.chelvc.cloud.vehicle.server.entity.MerchantApplyRecord;
|
|
|
-import com.chelvc.cloud.vehicle.server.entity.MerchantAuth;
|
|
|
-import com.chelvc.cloud.vehicle.server.entity.MerchantRelation;
|
|
|
+import com.chelvc.cloud.vehicle.server.entity.*;
|
|
|
import com.chelvc.cloud.vehicle.server.handle.TradeHandle;
|
|
|
import com.chelvc.cloud.vehicle.server.service.MerchantApplyRecordService;
|
|
|
import com.chelvc.cloud.vehicle.server.service.MerchantRelationService;
|
|
|
import com.chelvc.cloud.vehicle.server.service.MerchantService;
|
|
|
+import com.chelvc.framework.common.exception.ResourceUnavailableException;
|
|
|
+import com.upay.sdk.Constants;
|
|
|
+import com.upay.sdk.core.CipherWrapper;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.UUID;
|
|
|
|
|
@@ -38,7 +42,7 @@ public class MerchantRelationServiceImpl extends ServiceImpl<MerchantRelationMap
|
|
|
|
|
|
@Override
|
|
|
public void registerMerchantId(MerchantAuth merchantAuth) {
|
|
|
- Merchant merchant = merchantService.getById(merchantAuth.getId());
|
|
|
+ Merchant merchant = merchantService.queryByApplicant(merchantAuth.getApplicant());
|
|
|
String requestId = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
String operationType = "CREATE";
|
|
@@ -51,9 +55,9 @@ public class MerchantRelationServiceImpl extends ServiceImpl<MerchantRelationMap
|
|
|
//商户基本信息
|
|
|
JSONObject baseInfo = new JSONObject();
|
|
|
baseInfo.put("signedType", "BY_SPLIT_BILL");
|
|
|
- baseInfo.put("signedName", merchantAuth.getLegalRepresentativeName());
|
|
|
+ baseInfo.put("signedName", merchantAuth.getBusinessName());
|
|
|
baseInfo.put("registerRole", "INDIVIDUAL_BUSINESS"); //个体工商户
|
|
|
- baseInfo.put("cerType", "INDIVIDUAL_BUSINESS_LICENCE "); //个体工商户营业执照
|
|
|
+ baseInfo.put("cerType", "INDIVIDUAL_BUSINESS_LICENCE"); //个体工商户营业执照
|
|
|
baseInfo.put("signedShorthand", merchantAuth.getStoreName());
|
|
|
baseInfo.put("businessAddressProvince", merchant.getProvince());
|
|
|
baseInfo.put("businessAddressCity", merchant.getCity());
|
|
@@ -66,9 +70,7 @@ public class MerchantRelationServiceImpl extends ServiceImpl<MerchantRelationMap
|
|
|
|
|
|
//结算信息
|
|
|
JSONObject bankCardInfo = new JSONObject();
|
|
|
- //bankCardInfo.put("bankName", ""); //开户行名称
|
|
|
- //bankCardInfo.put("bankBranchName", ""); //支行名称
|
|
|
- bankCardInfo.put("accountName", merchantAuth.getAccountName()); //开户名称
|
|
|
+ bankCardInfo.put("accountName", merchantAuth.getLegalRepresentativeName()); //开户名称
|
|
|
bankCardInfo.put("bankCardNo", merchantAuth.getBankCardNo()); //开户账号
|
|
|
bankCardInfo.put("accountType", "PRIVATE");
|
|
|
bankCardInfo.put("liquidationType", "WITHDRAW");
|
|
@@ -83,16 +85,33 @@ public class MerchantRelationServiceImpl extends ServiceImpl<MerchantRelationMap
|
|
|
certificateInfo.put("legalPersonPhone", merchantAuth.getMobileNumber());
|
|
|
certificateInfo.put("legalPersonIdType", "IDCARD");
|
|
|
certificateInfo.put("legalPersonIdNo", merchantAuth.getIdCardNumber());
|
|
|
- certificateInfo.put("idEffectiveDateStart", merchantAuth.getIdCardExpirationDateStart()); //身份证号有效期开始
|
|
|
- certificateInfo.put("idEffectiveDateEnd", merchantAuth.getIdCardExpirationDate());
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ Date idCardExpirationDateStart = merchantAuth.getIdCardExpirationDateStart();
|
|
|
+ certificateInfo.put("idEffectiveDateStart", formatter.format(idCardExpirationDateStart)); //身份证号有效期开始
|
|
|
+ Date idCardExpirationDate = merchantAuth.getIdCardExpirationDate();
|
|
|
+ certificateInfo.put("idEffectiveDateEnd", formatter.format(idCardExpirationDate));
|
|
|
certificateInfo.put("cerNo", merchantAuth.getBusinessLicenseId());
|
|
|
certificateInfo.put("sellingArea", "C");
|
|
|
certificateInfo.put("staffSize", "C");
|
|
|
- certificateInfo.put("businessLicensePath", ""); //营业执照照片路径
|
|
|
- certificateInfo.put("openAccountPath", ""); // 开户许可证照片路径
|
|
|
- certificateInfo.put("legalIdCardProsPath", ""); // 法人证件人像面路径
|
|
|
- certificateInfo.put("legalIdCardConsPath", ""); // 法人证件国徽面路径
|
|
|
- certificateInfo.put("legalPersonBankCardPath", ""); // 法人银行卡图影印件路径
|
|
|
+ String businessPhoto = merchantAuth.getBusinessPhoto();
|
|
|
+ String businessPhotoPath = SFTPUtils.ftpUpload(businessPhoto,
|
|
|
+ merchant.getId() + "-businessLicensePath." + SFTPUtils.getSuffix(businessPhoto));
|
|
|
+ certificateInfo.put("businessLicensePath", businessPhotoPath); //营业执照照片路径
|
|
|
+
|
|
|
+ /*String businessLicensePhoto = merchantAuth.getBusinessLicensePhoto();
|
|
|
+ String openAccountPath = SFTPUtils.ftpUpload(businessLicensePhoto,
|
|
|
+ merchant.getId() + "-openAccountPath." + SFTPUtils.getSuffix(businessLicensePhoto));
|
|
|
+ certificateInfo.put("openAccountPath", openAccountPath);*/ // 开户许可证照片路径
|
|
|
+
|
|
|
+ String idCardFrontPhoto = merchantAuth.getIdCardFrontPhoto();
|
|
|
+ String legalIdCardProsPath = SFTPUtils.ftpUpload(idCardFrontPhoto,
|
|
|
+ merchant.getId() + "-legalIdCardProsPath." + SFTPUtils.getSuffix(idCardFrontPhoto));
|
|
|
+ certificateInfo.put("legalIdCardProsPath", legalIdCardProsPath); // 法人证件人像面路径
|
|
|
+
|
|
|
+ String idCardBackPhoto = merchantAuth.getIdCardBackPhoto();
|
|
|
+ String legalIdCardConsPath = SFTPUtils.ftpUpload(idCardBackPhoto,
|
|
|
+ merchant.getId() + "-legalIdCardConsPath." + SFTPUtils.getSuffix(idCardBackPhoto));
|
|
|
+ certificateInfo.put("legalIdCardConsPath", legalIdCardConsPath); // 法人证件国徽面路径
|
|
|
jsonObject.put("certificateInfo", certificateInfo);
|
|
|
|
|
|
//商户合同信息
|
|
@@ -110,6 +129,8 @@ public class MerchantRelationServiceImpl extends ServiceImpl<MerchantRelationMap
|
|
|
recordStatus = 2;
|
|
|
} else {
|
|
|
recordStatus = 1;
|
|
|
+ String errorMessage = json.getString("errorMessage");
|
|
|
+ throw new ResourceUnavailableException("【首信易】:"+errorMessage);
|
|
|
}
|
|
|
String subMerchantId = json.getString("subMerchantId");
|
|
|
MerchantApplyRecord record = new MerchantApplyRecord();
|
|
@@ -124,8 +145,105 @@ public class MerchantRelationServiceImpl extends ServiceImpl<MerchantRelationMap
|
|
|
merchantApplyRecordService.insert(record);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void registerMerchantId(UserAuth userAuth) {
|
|
|
+ String requestId = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ String operationType = "CREATE";
|
|
|
+ jsonObject.put("merchantId", TradeConstant.PARTNER_ID);
|
|
|
+ jsonObject.put("requestId", requestId);
|
|
|
+ jsonObject.put("operationType", operationType);
|
|
|
+ jsonObject.put("notifyUrl", TradeConstant.MERCHANT_NET_IN_NOTIFY_URL);
|
|
|
+ jsonObject.put("extendedParameters", "sendActiveEmail:FALSE,sendExpressPayMsg:FALSE");
|
|
|
+
|
|
|
+ //商户基本信息
|
|
|
+ JSONObject baseInfo = new JSONObject();
|
|
|
+ baseInfo.put("signedType", "BY_SPLIT_BILL");
|
|
|
+ baseInfo.put("signedName", userAuth.getUserName());
|
|
|
+ baseInfo.put("registerRole", "NATURAL_PERSON"); //个体工商户
|
|
|
+ baseInfo.put("signedShorthand", userAuth.getUserName()); //商户简称
|
|
|
+ baseInfo.put("businessAddressProvince", userAuth.getProvince()); //省
|
|
|
+ baseInfo.put("businessAddressCity", userAuth.getCity()); //市
|
|
|
+ baseInfo.put("businessAddressArea", userAuth.getDistrict()); //区
|
|
|
+ baseInfo.put("businessAddress", userAuth.getAddress()); //经营地址
|
|
|
+ baseInfo.put("contactName", userAuth.getUserName()); //联系人姓名
|
|
|
+ baseInfo.put("contactEmail", userAuth.getEmail()); //联系人邮箱
|
|
|
+ baseInfo.put("contactPhone", userAuth.getPhone()); //联系人电话
|
|
|
+ jsonObject.put("baseInfo", baseInfo);
|
|
|
+
|
|
|
+ //结算信息
|
|
|
+ JSONObject bankCardInfo = new JSONObject();
|
|
|
+ bankCardInfo.put("accountName", userAuth.getUserName()); //开户名称
|
|
|
+ bankCardInfo.put("bankCardNo", userAuth.getBankCardNo()); //开户账号
|
|
|
+ bankCardInfo.put("liquidationType", "WITHDRAW");
|
|
|
+ bankCardInfo.put("withdrawRateType", "SINGLE");
|
|
|
+ bankCardInfo.put("withdrawRate", "1.00");
|
|
|
+ jsonObject.put("bankCardInfo", bankCardInfo);
|
|
|
+
|
|
|
+ //商户资质信息
|
|
|
+ JSONObject certificateInfo = new JSONObject();
|
|
|
+ certificateInfo.put("legalPersonName", userAuth.getUserName()); //法人姓名
|
|
|
+ certificateInfo.put("profession", "2"); //职业 固定销售
|
|
|
+ certificateInfo.put("legalPersonIdType", "IDCARD");
|
|
|
+ certificateInfo.put("legalPersonIdNo", userAuth.getIdCardNo()); //身份证号
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ Date idCardExpirationDateStart = userAuth.getIdCardExpirationDateStart();
|
|
|
+ certificateInfo.put("idEffectiveDateStart", formatter.format(idCardExpirationDateStart)); //身份证号有效期开始
|
|
|
+ Date idCardExpirationDate = userAuth.getIdCardExpirationDate();
|
|
|
+ certificateInfo.put("idEffectiveDateEnd", formatter.format(idCardExpirationDate));
|
|
|
+
|
|
|
+ String idCardFrontPhoto = userAuth.getIdCardFrontPhoto();
|
|
|
+ String legalIdCardProsPath = SFTPUtils.ftpUpload(idCardFrontPhoto,
|
|
|
+ userAuth.getUserId() + "-legalIdCardProsPath." + SFTPUtils.getSuffix(idCardFrontPhoto));
|
|
|
+ certificateInfo.put("legalIdCardProsPath", legalIdCardProsPath); // 法人证件人像面路径
|
|
|
+
|
|
|
+ String idCardBackPhoto = userAuth.getIdCardBackPhoto();
|
|
|
+ String legalIdCardConsPath = SFTPUtils.ftpUpload(idCardBackPhoto,
|
|
|
+ userAuth.getUserId() + "-legalIdCardConsPath." + SFTPUtils.getSuffix(idCardBackPhoto));
|
|
|
+ certificateInfo.put("legalIdCardConsPath", legalIdCardConsPath); // 法人证件国徽面路径
|
|
|
+ jsonObject.put("certificateInfo", certificateInfo);
|
|
|
+
|
|
|
+ //商户合同信息
|
|
|
+ JSONObject contractInfo = new JSONObject();
|
|
|
+ contractInfo.put("receiverName", userAuth.getUserName());
|
|
|
+ contractInfo.put("receiverPhone", userAuth.getPhone());
|
|
|
+ contractInfo.put("receiverAddress", userAuth.getAddress());
|
|
|
+ jsonObject.put("contractInfo", contractInfo);
|
|
|
+
|
|
|
+ JSONObject json = TradeHandle.handle(String.valueOf(jsonObject), TradeConstant.DECLARE_URL,
|
|
|
+ TradeConstant.PARTNER_ID, null);
|
|
|
+ String status = json.getString("status");
|
|
|
+ int recordStatus = 0;
|
|
|
+ if("SUCCESS".equals(status)){
|
|
|
+ recordStatus = 2;
|
|
|
+ } else {
|
|
|
+ recordStatus = 1;
|
|
|
+ String errorMessage = json.getString("errorMessage");
|
|
|
+ throw new ResourceUnavailableException("【首信易】:"+errorMessage);
|
|
|
+ }
|
|
|
+ String subMerchantId = json.getString("subMerchantId");
|
|
|
+ MerchantApplyRecord record = new MerchantApplyRecord();
|
|
|
+ record.setUserId(userAuth.getUserId());
|
|
|
+ record.setType(1);
|
|
|
+ record.setRequestId(requestId);
|
|
|
+ record.setStatus(recordStatus);
|
|
|
+ record.setOperationType("CREATE");
|
|
|
+ record.setExamineStatus("PROCESSING");
|
|
|
+ record.setSubMerchantId(subMerchantId);
|
|
|
+ record.setCreateTime(new Date());
|
|
|
+ merchantApplyRecordService.insert(record);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public int insert(Long userId, Integer type, String sxyMerchantId) {
|
|
|
+ LambdaQueryWrapper<MerchantRelation> wrapper = Wrappers.lambdaQuery();
|
|
|
+ wrapper.eq(MerchantRelation::getType, type);
|
|
|
+ wrapper.eq(MerchantRelation::getUserId, userId);
|
|
|
+ MerchantRelation merchantRelation = baseMapper.selectOne(wrapper);
|
|
|
+ if(merchantRelation != null){
|
|
|
+ merchantRelation.setSxyMerchantId(sxyMerchantId);
|
|
|
+ return baseMapper.updateById(merchantRelation);
|
|
|
+ }
|
|
|
MerchantRelation relation = new MerchantRelation();
|
|
|
relation.setType(type);
|
|
|
relation.setUserId(userId);
|