From: qiaowei Date: Thu, 11 Jul 2019 08:44:52 +0000 (+0800) Subject: 修改绑定接口 X-Git-Tag: 1.0.0^2~69 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=d79ed5303cf1ecd5155203ab02cadce244f0d457;p=epayment%2Ffood_payapi.git 修改绑定接口 --- diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/mobile/MobileApi.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/mobile/MobileApi.kt index 6694d817..cf71a6d6 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/mobile/MobileApi.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/mobile/MobileApi.kt @@ -11,6 +11,7 @@ import com.supwisdom.dlpay.framework.service.SystemUtilService import com.supwisdom.dlpay.framework.util.* import com.supwisdom.dlpay.mobile.domain.TBMobileUser import com.supwisdom.dlpay.mobile.service.MobileApiService +import com.supwisdom.dlpay.system.service.DictionaryProxy import com.supwisdom.dlpay.util.ConstantUtil import org.apache.commons.lang.StringUtils import org.springframework.beans.factory.annotation.Autowired @@ -187,10 +188,10 @@ class ApiInit { if (!user.paypwd.isNullOrEmpty()) { payseted = true } - var signed="" - if(!user.userid.isNullOrEmpty()){ + var signed = "" + if (!user.userid.isNullOrEmpty()) { val card = mobileApiService.findCardByUserid(user.userid!!) - if(card!=null&&card.signed){ + if (card != null && card.signed) { signed = TradeDict.STATUS_YES } } @@ -215,6 +216,14 @@ class ApiV1 { lateinit var userService: UserService @Autowired lateinit var redisTemplate: RedisTemplate + @Autowired + lateinit var dictionaryProxy: DictionaryProxy + + @RequestMapping("/idtypes") + fun idtypes(): JsonResult { + var dict = dictionaryProxy.getDictionaryAsMap(Dictionary.IDTYPE) + return JsonResult.ok("OK").put("idtypes", dict)!! + } /** * 用户信息 @@ -248,7 +257,7 @@ class ApiV1 { } @RequestMapping("/checkcode") - fun check(@RequestParam code: String + fun check(@RequestParam code: String, @RequestParam personid: String? ): JsonResult { val p = SecurityContextHolder.getContext().authentication val user = mobileApiService.findUserById(p.name) @@ -261,6 +270,13 @@ class ApiV1 { val newCode = RandomUtils.getRandomString(30) redisTemplate.opsForValue().set(user.uid, newCode, Duration.ofHours(1)) redisTemplate.delete(user.phone) + if (!personid.isNullOrEmpty()) { + //绑定用户 + val person = userService.findOnePersonByUserid(personid) + user.bindtime = DateUtil.getNow() + user.userid = person.userid + mobileApiService.saveUser(user) + } return JsonResult.ok("OK").put("randcode", newCode)!! } else { return JsonResult.error(-1, "验证码无效或已过期,请重新获取") @@ -271,51 +287,41 @@ class ApiV1 { * 绑卡 * */ @RequestMapping("/bindcard") - fun bindcard(cardno: String, name: String, code: String): JsonResult { + fun bindcard(cardno: String, name: String, idtype: String, idno: String): JsonResult { val p = SecurityContextHolder.getContext().authentication val user = mobileApiService.findUserById(p.name) ?: return JsonResult.error("用户不存在,请注册") val phone = user.phone - val temp = redisTemplate.opsForValue().get(phone) - if (!temp.isNullOrEmpty()) { - if (temp != code) { - return JsonResult.error("验证码错误") - } - val card = mobileApiService.findCardByNo(cardno) - ?: return JsonResult.error("银行卡号有误") - if (card.userid.isNullOrEmpty() || card.status != TradeDict.STATUS_NORMAL) { - return JsonResult.error("银行卡号信息有误") - } - if (card.transStatus==TradeDict.STATUS_NORMAL) { - return JsonResult.error("该卡片非正常卡,无法绑定,请联系客服人员,更新卡状态") - } - val person = userService.findOnePersonByUserid(card.userid) - if(name!=person.name){ - return JsonResult.error("姓名错误") - } - val exsitUser = mobileApiService.findUserById(card.userid) - if (exsitUser != null) { - return JsonResult.error("该银行卡号已被绑定,如有疑问,请联系客服") - } - user.bindtime = DateUtil.getNow() - user.userid = card.userid - mobileApiService.saveUser(user) - redisTemplate.delete(phone) - var payseted = false - if (!user.paypwd.isNullOrEmpty()) { - payseted = true - } - var signed="" - if(card.signed){ - signed = TradeDict.STATUS_YES - } - return JsonResult.ok("OK").put("userid", user.userid) - ?.put("paypwdset", payseted) - ?.put("signed", signed)!! - - } else { - return JsonResult.error(-1, "验证码无效或已过期,请重新获取") + val card = mobileApiService.findCardByNo(cardno) + ?: return JsonResult.error("银行卡号有误") + if (card.userid.isNullOrEmpty() || card.status != TradeDict.STATUS_NORMAL) { + return JsonResult.error("银行卡号信息有误") + } + val exsitUser = mobileApiService.findUserById(card.userid) + if (exsitUser != null) { + return JsonResult.error("该银行卡号已被绑定,如有疑问,请联系客服") + } + //TODO call api + //user.bindtime = DateUtil.getNow() + //user.userid = card.userid + //mobileApiService.saveUser(user) + val code = RandomUtils.randomNumber(6) + System.out.println(code) + redisTemplate.opsForValue().set(user.phone, code, Duration.ofMinutes(5)) + var payseted = false + if (!user.paypwd.isNullOrEmpty()) { + payseted = true } + var signed = "" + if (card.signed) { + signed = TradeDict.STATUS_YES + } + return JsonResult.ok("OK").put("personid", card.userid) + ?.put("paypwdset", payseted) + ?.put("phonex", StringUtil.phoneReplace(phone)) + ?.put("signed", signed)!! + + } /** @@ -349,19 +355,19 @@ class ApiV1 { return JsonResult.error("原支付密码错误") } val paypwdtimes = user.checkPaypwdtime() - if(paypwdtimes==-1){ + if (paypwdtimes == -1) { return JsonResult.error("密码错误次数过多,请30分钟后再试") - }else if(paypwdtimes==1){ + } else if (paypwdtimes == 1) { mobileApiService.saveUser(user) } - if(!encoder.matches(oldpwd, user.paypwd)){ + if (!encoder.matches(oldpwd, user.paypwd)) { user.updatePaypwderror(false).also { - if(it) mobileApiService.saveUser(user) + if (it) mobileApiService.saveUser(user) } return JsonResult.error("原支付密码错误") - }else{ + } else { user.updatePaypwderror(true).also { - if(it) mobileApiService.saveUser(user) + if (it) mobileApiService.saveUser(user) } } user.paypwd = encoder.encode(pwd) @@ -398,16 +404,17 @@ class ApiV1 { val p = SecurityContextHolder.getContext().authentication val user = mobileApiService.findUserById(p.name) ?: return JsonResult.error("用户不存在,请注册") - var signed="" - if(!user.userid.isNullOrEmpty()){ - var card = mobileApiService.findCardByUserid(user.userid!!) ?: return JsonResult.error(-1,"卡片不存在,请重新绑定") - if(card.signed){ + var signed = "" + if (!user.userid.isNullOrEmpty()) { + var card = mobileApiService.findCardByUserid(user.userid!!) + ?: return JsonResult.error(-1, "卡片不存在,请重新绑定") + if (card.signed) { signed = TradeDict.STATUS_YES } - }else{ - return JsonResult.error(-1,"请先绑定银行卡") + } else { + return JsonResult.error(-1, "请先绑定银行卡") } - return JsonResult.ok("OK").put("page", page.pageContent)?.put("signed",signed)!! + return JsonResult.ok("OK").put("page", page.pageContent)?.put("signed", signed)!! } return JsonResult.error("页面未配置") } @@ -423,17 +430,21 @@ class ApiV1 { ?: return JsonResult.error("用户不存在,请注册") user.issigned = TradeDict.STATUS_YES user.signedtime = DateUtil.getNow() - var signed="" - if(!user.userid.isNullOrEmpty()){ + var signed: String + if (!user.userid.isNullOrEmpty()) { var card = mobileApiService.findCardByUserid(user.userid!!) ?: return JsonResult.error("卡片不存在,请重新绑定") - if(card.signed){ + if (card.signed) { + signed = TradeDict.STATUS_YES + }else{ + //TODO call sign api + card.signed = true + mobileApiService.saveCard(card) signed = TradeDict.STATUS_YES } - card.signed = true - mobileApiService.saveCard(card) + }else{ + return JsonResult.error("请先绑定银行卡") } mobileApiService.saveUser(user) - //TODO 调用第三方接口签约 return JsonResult.ok("ok") .put("signed", signed)!! } @@ -478,12 +489,12 @@ class ApiV1 { val person = userService.findOnePersonByUserid(user.userid!!) val card = mobileApiService.findCardByUserid(user.userid!!) var needrebind = false - var signed="" - if(card==null){ + var signed = "" + if (card == null) { //卡片已补办,或绑定失败,需要重新绑定 needrebind = true - }else{ - if(card.signed){ + } else { + if (card.signed) { signed = TradeDict.STATUS_YES } } @@ -496,7 +507,7 @@ class ApiV1 { ?.put("amount", amount) ?.put("paypwdset", payseted) ?.put("name", name) - ?.put("needrebind",needrebind) + ?.put("needrebind", needrebind) ?.put("signed", signed) ?.put("userid", if (user.userid.isNullOrEmpty()) "" else user.userid)!!.put("t", t)!! } @@ -531,24 +542,25 @@ class ApiV1 { return JsonResult.error("请重新设置密码,密码不能小于6位字符") } val pwdtimes = user.checkLoginpwdtime() - if(pwdtimes==-1){ - return JsonResult.error(-1,"原密码错误次数过多,将退出系统,请重新登录系统或点击忘记密码功能找回密码") - }else if(pwdtimes==1){ + if (pwdtimes == -1) { + return JsonResult.error(-1, "原密码错误次数过多,将退出系统,请重新登录系统或点击忘记密码功能找回密码") + } else if (pwdtimes == 1) { mobileApiService.saveUser(user) } val encoder = BCryptPasswordEncoder() - if(!encoder.matches(oldpwd, user.loginpwd)){ + if (!encoder.matches(oldpwd, user.loginpwd)) { user.updateLoginpwderror(false).also { - if(it) mobileApiService.saveUser(user) + if (it) mobileApiService.saveUser(user) } return JsonResult.error("原密码错误") - }else{ + } else { user.updateLoginpwderror(true) } user.loginpwd = encoder.encode(newpwd) mobileApiService.saveUser(user) return JsonResult.ok("密码修改成功") } + /** * * 市民卡挂失 @@ -558,23 +570,24 @@ class ApiV1 { val p = SecurityContextHolder.getContext().authentication val user = mobileApiService.findUserById(p.name) ?: return JsonResult.error("用户不存在,请注册") - if(user.userid.isNullOrEmpty()){ - return JsonResult.error(-1,"银行卡未绑定,请先绑定") + if (user.userid.isNullOrEmpty()) { + return JsonResult.error(-1, "银行卡未绑定,请先绑定") } val person = userService.findOnePersonByUserid(user.userid!!) - val card = mobileApiService.findCardByUserid(user.userid!!) ?: return JsonResult.error(-1,"银行卡未绑定,请先绑定") - var status="" + val card = mobileApiService.findCardByUserid(user.userid!!) ?: return JsonResult.error(-1, "银行卡未绑定,请先绑定") + var status = "" //normal/loss/frozen/locked - when(card.transStatus){ - TradeDict.STATUS_NORMAL-> status = "正常" - TradeDict.STATUS_LOST-> status = "已挂失" - TradeDict.STATUS_LOCKED-> status = "已锁定" - TradeDict.STATUS_FROZEN-> status = "已冻结" - } - return JsonResult.ok("ok").put("name",person.name) - ?.put("cardno",card.cardno) - ?.put("cardstatus",status)!! + when (card.transStatus) { + TradeDict.STATUS_NORMAL -> status = "正常" + TradeDict.STATUS_LOST -> status = "已挂失" + TradeDict.STATUS_LOCKED -> status = "已锁定" + TradeDict.STATUS_FROZEN -> status = "已冻结" + } + return JsonResult.ok("ok").put("name", person.name) + ?.put("cardno", card.cardno) + ?.put("cardstatus", status)!! } + /** * * 市民卡挂失 @@ -585,27 +598,27 @@ class ApiV1 { val user = mobileApiService.findUserById(p.name) ?: return JsonResult.error("用户不存在,请注册") val paypwdtimes = user.checkPaypwdtime() - if(paypwdtimes==-1){ + if (paypwdtimes == -1) { return JsonResult.error("支付密码错误次数过多,请30分钟后再试") - }else if(paypwdtimes==1){ + } else if (paypwdtimes == 1) { mobileApiService.saveUser(user) } val encoder = BCryptPasswordEncoder() - if(!encoder.matches(paypwd, user.paypwd)){ + if (!encoder.matches(paypwd, user.paypwd)) { user.updatePaypwderror(false).also { - if(it) mobileApiService.saveUser(user) + if (it) mobileApiService.saveUser(user) } return JsonResult.error("支付密码错误") - }else{ + } else { user.updatePaypwderror(true).also { - if(it) mobileApiService.saveUser(user) + if (it) mobileApiService.saveUser(user) } } - var card = mobileApiService.findCardByUserid(user.userid!!) ?: return JsonResult.error(-1,"银行卡未绑定,请先绑定") - if(card.transStatus!=TradeDict.STATUS_NORMAL){ + var card = mobileApiService.findCardByUserid(user.userid!!) ?: return JsonResult.error(-1, "银行卡未绑定,请先绑定") + if (card.transStatus != TradeDict.STATUS_NORMAL) { return JsonResult.error("卡状态非正常,不能挂失") } - card.transStatus=TradeDict.STATUS_LOST + card.transStatus = TradeDict.STATUS_LOST mobileApiService.saveCard(card) return JsonResult.ok("ok") }