微服务项目:尚融宝(51)(核心业务流程:充值服务(1))

2022-11-15 15:12:10 浏览数 (2)

在完成充值服务之前,将标在客户端展示

需求 

一、后端实现

Controller

LendController中创建list方法

代码语言:javascript复制
@Api(tags = "标的")
@RestController
@RequestMapping("/api/core/lend")
@Slf4j
public class LendController {

    @Resource
    private LendService lendService;

    @ApiOperation("获取标的列表")
    @GetMapping("/list")
    public R list() {
        List<Lend> lendList = lendService.selectList();
        return R.ok().data("lendList", lendList);
    }
}

二、前端整合

pages/lend/index.vue

脚本

此处使用了服务器端渲染

代码语言:javascript复制
async asyncData({ $axios }) {
    let response = await $axios.$get('/api/core/lend/list')
    return {
      lendList: response.data.lendList,
    }
},

一、投资人充值

1、需求描述 

标的产生后,平台展示标的,投资人就可以在平台投资标的,获取收益;投资人投资标的必须满足以下条件:

充值过程与绑定过程一致,也是在平台发送充值请求,跳转到资金托管平台,在资金托管平台完成充值,然后同步或异步返回或通知平台

2、相关数据库表

3、参考文档

参考《汇付宝商户账户技术文档》3.9用户充值

二、具体步骤

step1:用户在个人中心点击 “充值” 

step2:尚融宝展示账户充值页面

step3:用户填写充值金额,点击“充值”按钮

step4:跳转到汇付宝页面(资金托管接口调用)

 step5:汇付宝验证用户交易密码

step6:汇付修改账号资金余额(更新user_account记录中的amount的值)

step7:异步回调

(1)账户金额更改

(2)添加交易流水

step8:用户点击“返回平台”,返回尚融宝

一、后端接口实现

1、Controller

UserAccountController 

代码语言:javascript复制
@Api(tags = "会员账户")
@RestController
@RequestMapping("/api/core/userAccount")
@Slf4j
public class UserAccountController {

    @Resource
    private UserAccountService userAccountService;

    @ApiOperation("充值")
    @PostMapping("/auth/commitCharge/{chargeAmt}")
    public R commitCharge(
            @ApiParam(value = "充值金额", required = true)
            @PathVariable BigDecimal chargeAmt, HttpServletRequest request) {

        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        String formStr = userAccountService.commitCharge(chargeAmt, userId);
        return R.ok().data("formStr", formStr);
    }
}

2、Service

接口:UserAccountService

代码语言:javascript复制
String commitCharge(BigDecimal chargeAmt, Long userId);

实现:UserAccountServiceImpl 

代码语言:javascript复制
@Resource
private UserInfoMapper userInfoMapper;

@Override
public String commitCharge(BigDecimal chargeAmt, Long userId) {

    UserInfo userInfo = userInfoMapper.selectById(userId);
    String bindCode = userInfo.getBindCode();
    //判断账户绑定状态
    Assert.notEmpty(bindCode, ResponseEnum.USER_NO_BIND_ERROR);

    Map<String, Object> paramMap = new HashMap<>();
    paramMap.put("agentId", HfbConst.AGENT_ID);
    paramMap.put("agentBillNo", LendNoUtils.getNo());
    paramMap.put("bindCode", bindCode);
    paramMap.put("chargeAmt", chargeAmt);
    paramMap.put("feeAmt", new BigDecimal("0"));
    paramMap.put("notifyUrl", HfbConst.RECHARGE_NOTIFY_URL);//检查常量是否正确
    paramMap.put("returnUrl", HfbConst.RECHARGE_RETURN_URL);
    paramMap.put("timestamp", RequestHelper.getTimestamp());
    String sign = RequestHelper.getSign(paramMap);
    paramMap.put("sign", sign);

    //构建充值自动提交表单
    String formStr = FormHelper.buildForm(HfbConst.RECHARGE_URL, paramMap);
    return formStr;
}

二、前端整合

页面脚本

pages/user/recharge.vue

代码语言:javascript复制
methods: {
    commitCharge() {
      this.$alert(
        '<div style="size: 18px;color: red;">您即将前往汇付宝充值</div>',
        '前往汇付宝资金托管平台',
        {
          dangerouslyUseHTMLString: true,
          confirmButtonText: '立即前往',
          callback: (action) => {
            if (action === 'confirm') {
              this.$axios
                .$post(
                  '/api/core/userAccount/auth/commitCharge/'   this.chargeAmt
                )
                .then((response) => {
                  document.write(response.data.formStr)
                })
            }
          },
        }
      )
    },
},

0 人点赞