消费者修改结算银行卡
This commit is contained in:
parent
63a71b5bda
commit
139702efa7
|
|
@ -1,8 +1,8 @@
|
|||
package com.ghy.web.controller.customer;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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.Merchant;
|
||||
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.request.BindBankCardRequest;
|
||||
import com.ghy.customer.service.CustomerBankService;
|
||||
import com.ghy.payment.service.AdapayService;
|
||||
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
|
@ -41,7 +42,7 @@ public class CustomerBankController {
|
|||
*/
|
||||
@PostMapping("bind")
|
||||
@ResponseBody
|
||||
private AjaxResult bindBankCard(@RequestBody BindBankCardRequest request) throws BaseAdaPayException {
|
||||
private AjaxResult bindBankCard(@RequestBody @Valid BindBankCardRequest request) throws BaseAdaPayException {
|
||||
Set<Merchant> merchants = AdapayConfig.getMerchants();
|
||||
for (Merchant merchant : merchants) {
|
||||
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);
|
||||
if (!AdapayStatusEnum.succeeded.code.equals(result2.get("status"))) {
|
||||
if ("account_exists".equals(result2.get("error_code"))) {
|
||||
|
|
@ -87,12 +88,56 @@ public class CustomerBankController {
|
|||
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")
|
||||
@ResponseBody
|
||||
public AjaxResult getByCustomerId(@RequestBody BindBankCardRequest request){
|
||||
public AjaxResult getByCustomerId(@RequestBody BindBankCardRequest request) {
|
||||
try {
|
||||
return AjaxResult.success(customerBankService.selectByCustomerId(request.getCustomerId()));
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return AjaxResult.error(ExceptionUtil.getExceptionMessage(e));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,4 +41,7 @@ public class CustomerBank extends BaseEntity {
|
|||
|
||||
@Excel(name = "是否为结算账户", cellType = Excel.ColumnType.STRING)
|
||||
private Integer settleAccount;
|
||||
|
||||
private String settleAccountId;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,4 +63,8 @@ public interface CustomerBankMapper {
|
|||
* @return 更新成功条数
|
||||
*/
|
||||
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 javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 个人账户绑定银行卡接口参数
|
||||
*
|
||||
|
|
@ -13,25 +16,30 @@ public class BindBankCardRequest {
|
|||
/**
|
||||
* 消费者ID
|
||||
*/
|
||||
@NotNull
|
||||
private Long customerId;
|
||||
|
||||
/**
|
||||
* 用户真实姓名
|
||||
*/
|
||||
@NotBlank
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 身份证号
|
||||
*/
|
||||
@NotBlank
|
||||
private String certId;
|
||||
|
||||
/**
|
||||
* 银行卡号
|
||||
*/
|
||||
@NotBlank
|
||||
private String bankNum;
|
||||
|
||||
/**
|
||||
* 银行卡绑定手机号
|
||||
*/
|
||||
@NotBlank
|
||||
private String phone;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,4 +62,8 @@ public interface CustomerBankService {
|
|||
* @return 更新成功条数
|
||||
*/
|
||||
int updateCustomerBank(CustomerBank customerBank);
|
||||
|
||||
CustomerBank getByMemberId(String memberId);
|
||||
|
||||
int updateByMemberId(CustomerBank customerBank);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ public class CustomerBankServiceImpl implements CustomerBankService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CustomerBank selectByCustomerId(Long customerId){
|
||||
public CustomerBank selectByCustomerId(Long customerId) {
|
||||
List<CustomerBank> list = customerBankMapper.selectByCustomerId(customerId);
|
||||
if(list.size()>0){
|
||||
if (list.size() > 0) {
|
||||
return list.get(0);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -63,4 +63,14 @@ public class CustomerBankServiceImpl implements CustomerBankService {
|
|||
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">
|
||||
<result property="customerBankId" column="customer_bank_id"/>
|
||||
<result property="settleAccountId" column="settle_account_id"/>
|
||||
<result property="customerId" column="customer_id"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="certId" column="cert_id"/>
|
||||
|
|
@ -22,6 +23,7 @@
|
|||
|
||||
<sql id="selectCustomerBank">
|
||||
SELECT customer_bank_id,
|
||||
settle_account_id,
|
||||
customer_id,
|
||||
name,
|
||||
cert_id,
|
||||
|
|
@ -56,7 +58,7 @@
|
|||
|
||||
<insert id="insertCustomerBank" parameterType="com.ghy.customer.domain.CustomerBank" useGeneratedKeys="true"
|
||||
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="name != null and name != ''">name,</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="remark != null and remark != ''">remark,</if>
|
||||
create_time
|
||||
)VALUES(
|
||||
)VALUES( #{settleAccountId},
|
||||
<if test="customerId != null and customerId != 0">#{customerId},</if>
|
||||
<if test="name != null and name != ''">#{name},</if>
|
||||
<if test="certId != null and certId != ''">#{certId},</if>
|
||||
|
|
@ -130,4 +132,19 @@
|
|||
<include refid="selectCustomerBank"/> WHERE customer_bank_id = #{customerBankId}
|
||||
</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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue