消费者修改结算银行卡
This commit is contained in:
parent
63a71b5bda
commit
139702efa7
|
|
@ -1,8 +1,8 @@
|
||||||
package com.ghy.web.controller.customer;
|
package com.ghy.web.controller.customer;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.ghy.common.adapay.AdapayConfig;
|
import com.ghy.common.adapay.AdapayConfig;
|
||||||
import com.ghy.payment.service.AdapayService;
|
|
||||||
import com.ghy.common.adapay.model.AdapayStatusEnum;
|
import com.ghy.common.adapay.model.AdapayStatusEnum;
|
||||||
import com.ghy.common.adapay.model.Merchant;
|
import com.ghy.common.adapay.model.Merchant;
|
||||||
import com.ghy.common.core.domain.AjaxResult;
|
import com.ghy.common.core.domain.AjaxResult;
|
||||||
|
|
@ -11,15 +11,16 @@ import com.ghy.common.utils.ExceptionUtil;
|
||||||
import com.ghy.customer.domain.CustomerBank;
|
import com.ghy.customer.domain.CustomerBank;
|
||||||
import com.ghy.customer.request.BindBankCardRequest;
|
import com.ghy.customer.request.BindBankCardRequest;
|
||||||
import com.ghy.customer.service.CustomerBankService;
|
import com.ghy.customer.service.CustomerBankService;
|
||||||
|
import com.ghy.payment.service.AdapayService;
|
||||||
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.validation.Valid;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
@ -41,7 +42,7 @@ public class CustomerBankController {
|
||||||
*/
|
*/
|
||||||
@PostMapping("bind")
|
@PostMapping("bind")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
private AjaxResult bindBankCard(@RequestBody BindBankCardRequest request) throws BaseAdaPayException {
|
private AjaxResult bindBankCard(@RequestBody @Valid BindBankCardRequest request) throws BaseAdaPayException {
|
||||||
Set<Merchant> merchants = AdapayConfig.getMerchants();
|
Set<Merchant> merchants = AdapayConfig.getMerchants();
|
||||||
for (Merchant merchant : merchants) {
|
for (Merchant merchant : merchants) {
|
||||||
String memberId = AdapayUtils.getCustomerMemberId(request.getCustomerId(), merchant.getDeptId());
|
String memberId = AdapayUtils.getCustomerMemberId(request.getCustomerId(), merchant.getDeptId());
|
||||||
|
|
@ -61,7 +62,7 @@ public class CustomerBankController {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 开始创建结算账户
|
// 开始创建结算账户
|
||||||
Map<String, Object> result2 = adapayService.createSettleAccount(merchant.getDeptId(), memberId, request.getBankNum(), request.getName(),
|
JSONObject result2 = adapayService.createSettleAccount(merchant.getDeptId(), memberId, request.getBankNum(), request.getName(),
|
||||||
"2", request.getCertId(), request.getPhone(), null, null, null);
|
"2", request.getCertId(), request.getPhone(), null, null, null);
|
||||||
if (!AdapayStatusEnum.succeeded.code.equals(result2.get("status"))) {
|
if (!AdapayStatusEnum.succeeded.code.equals(result2.get("status"))) {
|
||||||
if ("account_exists".equals(result2.get("error_code"))) {
|
if ("account_exists".equals(result2.get("error_code"))) {
|
||||||
|
|
@ -87,6 +88,50 @@ public class CustomerBankController {
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("update")
|
||||||
|
@ResponseBody
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public AjaxResult updateBankCard(@RequestBody @Valid BindBankCardRequest request) throws BaseAdaPayException {
|
||||||
|
Set<Merchant> merchants = AdapayConfig.getMerchants();
|
||||||
|
for (Merchant merchant : merchants) {
|
||||||
|
String memberId = AdapayUtils.getCustomerMemberId(request.getCustomerId(), merchant.getDeptId());
|
||||||
|
CustomerBank customerBank = customerBankService.getByMemberId(memberId);
|
||||||
|
if (customerBank != null) {
|
||||||
|
if (request.getBankNum().equals(customerBank.getBankNum())) {
|
||||||
|
// 这个银行卡号已经绑定过了
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
boolean equalsName = request.getName().equals(customerBank.getName());
|
||||||
|
boolean equalsCertId = request.getCertId().equals(customerBank.getCertId());
|
||||||
|
// 必须与原来的开户名和身份证一致
|
||||||
|
Assert.isTrue(equalsName && equalsCertId, "银行卡与实名信息不符");
|
||||||
|
JSONObject deleteResponse = adapayService.deleteSettleAccount(merchant.getDeptId(), memberId, customerBank.getSettleAccountId());
|
||||||
|
boolean deleteResult = AdapayStatusEnum.succeeded.code.equals(deleteResponse.getString("status"));
|
||||||
|
Assert.isTrue(deleteResult, "解绑银行卡失败: " + deleteResponse.getString("error_msg"));
|
||||||
|
} else {
|
||||||
|
customerBank = new CustomerBank();
|
||||||
|
customerBank.setAdapayMemberId(memberId);
|
||||||
|
customerBank.setCustomerId(request.getCustomerId());
|
||||||
|
customerBank.setName(request.getName());
|
||||||
|
customerBank.setCertId(request.getCertId());
|
||||||
|
customerBank.setDeptId(merchant.getDeptId());
|
||||||
|
customerBank.setSettleAccount(1);
|
||||||
|
customerBankService.insertCustomerBank(customerBank);
|
||||||
|
}
|
||||||
|
// 绑定新卡
|
||||||
|
JSONObject createResponse = adapayService.createSettleAccount(merchant.getDeptId(), memberId, request.getBankNum(), request.getName(),
|
||||||
|
"2", request.getCertId(), request.getPhone(), null, null, null);
|
||||||
|
boolean createResult = AdapayStatusEnum.succeeded.code.equals(createResponse.get("status"));
|
||||||
|
Assert.isTrue(createResult, "绑定银行卡失败: " + createResponse.getString("error_msg"));
|
||||||
|
// 更新数据库中的手机号和银行卡号
|
||||||
|
customerBank.setPhone(request.getPhone());
|
||||||
|
customerBank.setBankNum(request.getBankNum());
|
||||||
|
customerBank.setSettleAccountId(createResponse.getString("id"));
|
||||||
|
customerBankService.updateByMemberId(customerBank);
|
||||||
|
}
|
||||||
|
return AjaxResult.success("绑定银行卡成功");
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("getByCustomerId")
|
@PostMapping("getByCustomerId")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult getByCustomerId(@RequestBody BindBankCardRequest request) {
|
public AjaxResult getByCustomerId(@RequestBody BindBankCardRequest request) {
|
||||||
|
|
|
||||||
|
|
@ -41,4 +41,7 @@ public class CustomerBank extends BaseEntity {
|
||||||
|
|
||||||
@Excel(name = "是否为结算账户", cellType = Excel.ColumnType.STRING)
|
@Excel(name = "是否为结算账户", cellType = Excel.ColumnType.STRING)
|
||||||
private Integer settleAccount;
|
private Integer settleAccount;
|
||||||
|
|
||||||
|
private String settleAccountId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,4 +63,8 @@ public interface CustomerBankMapper {
|
||||||
* @return 更新成功条数
|
* @return 更新成功条数
|
||||||
*/
|
*/
|
||||||
int updateCustomerBank(CustomerBank customerBank);
|
int updateCustomerBank(CustomerBank customerBank);
|
||||||
|
|
||||||
|
CustomerBank getByMemberId(String memberId);
|
||||||
|
|
||||||
|
int updateByMemberId(CustomerBank customerBank);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ package com.ghy.customer.request;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 个人账户绑定银行卡接口参数
|
* 个人账户绑定银行卡接口参数
|
||||||
*
|
*
|
||||||
|
|
@ -13,25 +16,30 @@ public class BindBankCardRequest {
|
||||||
/**
|
/**
|
||||||
* 消费者ID
|
* 消费者ID
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
private Long customerId;
|
private Long customerId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户真实姓名
|
* 用户真实姓名
|
||||||
*/
|
*/
|
||||||
|
@NotBlank
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 身份证号
|
* 身份证号
|
||||||
*/
|
*/
|
||||||
|
@NotBlank
|
||||||
private String certId;
|
private String certId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 银行卡号
|
* 银行卡号
|
||||||
*/
|
*/
|
||||||
|
@NotBlank
|
||||||
private String bankNum;
|
private String bankNum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 银行卡绑定手机号
|
* 银行卡绑定手机号
|
||||||
*/
|
*/
|
||||||
|
@NotBlank
|
||||||
private String phone;
|
private String phone;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,4 +62,8 @@ public interface CustomerBankService {
|
||||||
* @return 更新成功条数
|
* @return 更新成功条数
|
||||||
*/
|
*/
|
||||||
int updateCustomerBank(CustomerBank customerBank);
|
int updateCustomerBank(CustomerBank customerBank);
|
||||||
|
|
||||||
|
CustomerBank getByMemberId(String memberId);
|
||||||
|
|
||||||
|
int updateByMemberId(CustomerBank customerBank);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,4 +63,14 @@ public class CustomerBankServiceImpl implements CustomerBankService {
|
||||||
return customerBankMapper.updateCustomerBank(customerBank);
|
return customerBankMapper.updateCustomerBank(customerBank);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CustomerBank getByMemberId(String memberId) {
|
||||||
|
return customerBankMapper.getByMemberId(memberId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int updateByMemberId(CustomerBank customerBank) {
|
||||||
|
return customerBankMapper.updateByMemberId(customerBank);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
<resultMap id="CustomerBankResult" type="com.ghy.customer.domain.CustomerBank">
|
<resultMap id="CustomerBankResult" type="com.ghy.customer.domain.CustomerBank">
|
||||||
<result property="customerBankId" column="customer_bank_id"/>
|
<result property="customerBankId" column="customer_bank_id"/>
|
||||||
|
<result property="settleAccountId" column="settle_account_id"/>
|
||||||
<result property="customerId" column="customer_id"/>
|
<result property="customerId" column="customer_id"/>
|
||||||
<result property="name" column="name"/>
|
<result property="name" column="name"/>
|
||||||
<result property="certId" column="cert_id"/>
|
<result property="certId" column="cert_id"/>
|
||||||
|
|
@ -22,6 +23,7 @@
|
||||||
|
|
||||||
<sql id="selectCustomerBank">
|
<sql id="selectCustomerBank">
|
||||||
SELECT customer_bank_id,
|
SELECT customer_bank_id,
|
||||||
|
settle_account_id,
|
||||||
customer_id,
|
customer_id,
|
||||||
name,
|
name,
|
||||||
cert_id,
|
cert_id,
|
||||||
|
|
@ -56,7 +58,7 @@
|
||||||
|
|
||||||
<insert id="insertCustomerBank" parameterType="com.ghy.customer.domain.CustomerBank" useGeneratedKeys="true"
|
<insert id="insertCustomerBank" parameterType="com.ghy.customer.domain.CustomerBank" useGeneratedKeys="true"
|
||||||
keyProperty="customerBankId">
|
keyProperty="customerBankId">
|
||||||
INSERT INTO customer_bank(
|
INSERT INTO customer_bank( settle_account_id,
|
||||||
<if test="customerId != null and customerId != 0">customer_id,</if>
|
<if test="customerId != null and customerId != 0">customer_id,</if>
|
||||||
<if test="name != null and name != ''">name,</if>
|
<if test="name != null and name != ''">name,</if>
|
||||||
<if test="certId != null and certId != ''">cert_id,</if>
|
<if test="certId != null and certId != ''">cert_id,</if>
|
||||||
|
|
@ -69,7 +71,7 @@
|
||||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||||
<if test="remark != null and remark != ''">remark,</if>
|
<if test="remark != null and remark != ''">remark,</if>
|
||||||
create_time
|
create_time
|
||||||
)VALUES(
|
)VALUES( #{settleAccountId},
|
||||||
<if test="customerId != null and customerId != 0">#{customerId},</if>
|
<if test="customerId != null and customerId != 0">#{customerId},</if>
|
||||||
<if test="name != null and name != ''">#{name},</if>
|
<if test="name != null and name != ''">#{name},</if>
|
||||||
<if test="certId != null and certId != ''">#{certId},</if>
|
<if test="certId != null and certId != ''">#{certId},</if>
|
||||||
|
|
@ -130,4 +132,19 @@
|
||||||
<include refid="selectCustomerBank"/> WHERE customer_bank_id = #{customerBankId}
|
<include refid="selectCustomerBank"/> WHERE customer_bank_id = #{customerBankId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getByMemberId" resultMap="CustomerBankResult">
|
||||||
|
<include refid="selectCustomerBank"/>
|
||||||
|
WHERE adapay_member_id = #{adapayMemberId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<update id="updateByMemberId" parameterType="com.ghy.customer.domain.CustomerBank">
|
||||||
|
UPDATE customer_bank
|
||||||
|
<set>
|
||||||
|
<if test="phone != null and phone != ''">phone = #{phone},</if>
|
||||||
|
<if test="bankNum != null and bankNum != ''">bank_num = #{bankNum},</if>
|
||||||
|
<if test="settleAccountId != null and settleAccountId != ''">settle_account_id = #{settleAccountId},</if>
|
||||||
|
update_time = NOW()
|
||||||
|
</set>
|
||||||
|
WHERE adapay_member_id = #{adapayMemberId}
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue