师傅修改结算银行卡
This commit is contained in:
parent
2ddf5a6bf6
commit
1fbe22585b
|
|
@ -19,9 +19,12 @@ import com.ghy.worker.service.WorkerBankService;
|
||||||
import com.ghy.worker.service.WorkerService;
|
import com.ghy.worker.service.WorkerService;
|
||||||
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
|
@ -47,7 +50,7 @@ public class WorkerBankController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@PostMapping("bind")
|
@PostMapping("bind")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
private AjaxResult bindBankCard(@RequestBody WorkerBindBankCardRequest request) throws BaseAdaPayException {
|
public AjaxResult bindBankCard(@RequestBody @Valid WorkerBindBankCardRequest request) throws BaseAdaPayException {
|
||||||
Set<Merchant> merchants = AdapayConfig.getMerchants();
|
Set<Merchant> merchants = AdapayConfig.getMerchants();
|
||||||
for (Merchant merchant : merchants) {
|
for (Merchant merchant : merchants) {
|
||||||
String memberId = AdapayUtils.getWorkerMemberId(request.getWorkerId(), merchant.getDeptId());
|
String memberId = AdapayUtils.getWorkerMemberId(request.getWorkerId(), merchant.getDeptId());
|
||||||
|
|
@ -106,10 +109,44 @@ public class WorkerBankController extends BaseController {
|
||||||
|
|
||||||
@PutMapping("update")
|
@PutMapping("update")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
private AjaxResult updateBankCard(@RequestBody WorkerBindBankCardRequest request) throws BaseAdaPayException {
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public AjaxResult updateBankCard(@RequestBody @Valid WorkerBindBankCardRequest request) throws BaseAdaPayException {
|
||||||
Set<Merchant> merchants = AdapayConfig.getMerchants();
|
Set<Merchant> merchants = AdapayConfig.getMerchants();
|
||||||
for (Merchant merchant : merchants) {
|
for (Merchant merchant : merchants) {
|
||||||
|
String memberId = AdapayUtils.getWorkerMemberId(request.getWorkerId(), merchant.getDeptId());
|
||||||
|
WorkerBank workerBank = workerBankService.getByMemberId(memberId);
|
||||||
|
if (workerBank != null) {
|
||||||
|
if (request.getBankNum().equals(workerBank.getBankNum())) {
|
||||||
|
// 这个银行卡号已经绑定过了
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
boolean equalsName = request.getName().equals(workerBank.getName());
|
||||||
|
boolean equalsCertId = request.getCertId().equals(workerBank.getCertId());
|
||||||
|
// 必须与原来的开户名和身份证一致
|
||||||
|
Assert.isTrue(equalsName && equalsCertId, "银行卡与实名信息不符");
|
||||||
|
JSONObject deleteResponse = adapayService.deleteSettleAccount(merchant.getDeptId(), memberId, workerBank.getSettleAccountId());
|
||||||
|
boolean deleteResult = AdapayStatusEnum.succeeded.code.equals(deleteResponse.getString("status"));
|
||||||
|
Assert.isTrue(deleteResult, "解绑银行卡失败: " + deleteResponse.getString("error_msg"));
|
||||||
|
} else {
|
||||||
|
workerBank = new WorkerBank();
|
||||||
|
workerBank.setAdapayMemberId(memberId);
|
||||||
|
workerBank.setWorkerId(request.getWorkerId());
|
||||||
|
workerBank.setName(request.getName());
|
||||||
|
workerBank.setCertId(request.getCertId());
|
||||||
|
workerBank.setDeptId(merchant.getDeptId());
|
||||||
|
workerBank.setSettleAccount(1);
|
||||||
|
workerBankService.insertWorkerBank(workerBank);
|
||||||
|
}
|
||||||
|
// 绑定新卡
|
||||||
|
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"));
|
||||||
|
// 更新数据库中的手机号和银行卡号
|
||||||
|
workerBank.setPhone(request.getPhone());
|
||||||
|
workerBank.setBankNum(request.getBankNum());
|
||||||
|
workerBank.setSettleAccountId(createResponse.getString("id"));
|
||||||
|
workerBankService.updateByMemberId(workerBank);
|
||||||
}
|
}
|
||||||
return AjaxResult.success("绑定银行卡成功");
|
return AjaxResult.success("绑定银行卡成功");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.ghy.web.core;
|
||||||
|
|
||||||
|
import com.ghy.common.core.domain.AjaxResult;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@ControllerAdvice
|
||||||
|
public class GhyExceptionHandler {
|
||||||
|
|
||||||
|
@ExceptionHandler(IllegalArgumentException.class)
|
||||||
|
public AjaxResult IllegalArgumentExceptionHandler(IllegalArgumentException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return AjaxResult.error(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -17,6 +17,8 @@ public interface WorkerBankMapper {
|
||||||
*/
|
*/
|
||||||
int insertWorkerBank(WorkerBank workerBank);
|
int insertWorkerBank(WorkerBank workerBank);
|
||||||
|
|
||||||
|
int updateByMemberId(WorkerBank workerBank);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param workerId 师傅id
|
* @param workerId 师傅id
|
||||||
* @return 师傅银行卡对象
|
* @return 师傅银行卡对象
|
||||||
|
|
@ -29,4 +31,5 @@ public interface WorkerBankMapper {
|
||||||
*/
|
*/
|
||||||
List<WorkerBank> getByWorkerIds(@Param("ids") String ids);
|
List<WorkerBank> getByWorkerIds(@Param("ids") String ids);
|
||||||
|
|
||||||
|
WorkerBank getByMemberId(String memberId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,32 +2,40 @@ package com.ghy.worker.request;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class WorkerBindBankCardRequest {
|
public class WorkerBindBankCardRequest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 师傅ID
|
* 师傅ID
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
private Long workerId;
|
private Long workerId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户真实姓名
|
* 用户真实姓名
|
||||||
*/
|
*/
|
||||||
|
@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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,16 @@ public interface WorkerBankService {
|
||||||
*/
|
*/
|
||||||
int insertWorkerBank(WorkerBank workerBank);
|
int insertWorkerBank(WorkerBank workerBank);
|
||||||
|
|
||||||
|
int updateByMemberId(WorkerBank workerBank);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param workerId 师傅id
|
* @param workerId 师傅id
|
||||||
* @return 师傅银行卡对象
|
* @return 师傅银行卡对象
|
||||||
*/
|
*/
|
||||||
WorkerBank getByWorkerId(Long workerId);
|
WorkerBank getByWorkerId(Long workerId);
|
||||||
|
|
||||||
|
WorkerBank getByMemberId(String memberId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ids 师傅ids
|
* @param ids 师傅ids
|
||||||
* @return 师傅银行对象集合
|
* @return 师傅银行对象集合
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,21 @@ public class WorkerBankServiceImpl implements WorkerBankService {
|
||||||
return workerBankMapper.insertWorkerBank(workerBank);
|
return workerBankMapper.insertWorkerBank(workerBank);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int updateByMemberId(WorkerBank workerBank) {
|
||||||
|
return workerBankMapper.updateByMemberId(workerBank);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorkerBank getByWorkerId(Long workerId) {
|
public WorkerBank getByWorkerId(Long workerId) {
|
||||||
return workerBankMapper.getByWorkerId(workerId);
|
return workerBankMapper.getByWorkerId(workerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorkerBank getByMemberId(String memberId) {
|
||||||
|
return workerBankMapper.getByMemberId(memberId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WorkerBank> getByWorkerIds(String ids) {
|
public List<WorkerBank> getByWorkerIds(String ids) {
|
||||||
return workerBankMapper.getByWorkerIds(ids);
|
return workerBankMapper.getByWorkerIds(ids);
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,17 @@
|
||||||
)
|
)
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
<update id="updateByMemberId" parameterType="com.ghy.worker.domain.WorkerBank">
|
||||||
|
UPDATE worker_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>
|
||||||
|
updateTime = NOW()
|
||||||
|
</set>
|
||||||
|
WHERE adapay_member_id = #{memberId}
|
||||||
|
</update>
|
||||||
|
|
||||||
<select id="getByWorkerId" parameterType="Long" resultMap="WorkerBankResult">
|
<select id="getByWorkerId" parameterType="Long" resultMap="WorkerBankResult">
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM worker_bank
|
FROM worker_bank
|
||||||
|
|
@ -62,6 +73,12 @@
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getByMemberId" parameterType="String" resultMap="WorkerBankResult">
|
||||||
|
SELECT *
|
||||||
|
FROM worker_bank
|
||||||
|
WHERE adapay_member_id = #{memberId}
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="getByWorkerIds" resultMap="WorkerBankResult">
|
<select id="getByWorkerIds" resultMap="WorkerBankResult">
|
||||||
SELECT * FROM worker_bank
|
SELECT * FROM worker_bank
|
||||||
WHERE worker_id in ( #{ids} )
|
WHERE worker_id in ( #{ids} )
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue