package com.supwisdom.dlpay.mobile
import com.supwisdom.dlpay.api.bean.JsonResult
-import com.supwisdom.dlpay.api.dao.PersonDao
-import com.supwisdom.dlpay.api.domain.TPersonIdentity
import com.supwisdom.dlpay.api.service.UserService
+import com.supwisdom.dlpay.api.util.MobileNumberCheck
import com.supwisdom.dlpay.framework.core.JwtConfig
import com.supwisdom.dlpay.framework.core.JwtTokenUtil
import com.supwisdom.dlpay.framework.domain.JwtRedis
* */
@RequestMapping("/code")
fun code(@RequestParam phone: String, @RequestParam type: String?): JsonResult {
- if (phone.isEmpty() || phone.length != 11 || !StringUtil.isMobile(phone)) {
- return JsonResult.error("手机号有误")
+ if (phone.isEmpty() || !MobileNumberCheck.isPhone(phone)) {
+ return JsonResult.error("手机号不合法")
}
val user = mobileApiService.findUserByPhone(phone)
if (type.isNullOrEmpty() || "new" == type) {
if (!user.paypwd.isNullOrEmpty()) {
payseted = true
}
+ var signed=""
+ if(!user.userid.isNullOrEmpty()){
+ val card = mobileApiService.findCardByUserid(user.userid!!)
+ if(card!=null&&card.signed){
+ signed = TradeDict.STATUS_YES
+ }
+ }
return JsonResult.ok("OK").put("token", token.jwtToken)
?.put("userid", if (user.userid.isNullOrEmpty()) "" else user.userid)
?.put("expire", token.expiration.valueInMillis)
?.put("now", System.currentTimeMillis())
?.put("phone", StringUtil.phoneReplace(user.phone))
?.put("paypwdset", payseted)
- ?.put("signed", if (user.issigned.isNullOrEmpty()) "" else user.issigned)
+ ?.put("signed", signed)
?.put("tenantid", "mobile")!!
}
}
lateinit var userService: UserService
@Autowired
lateinit var redisTemplate: RedisTemplate<String, String>
- @Autowired
- lateinit var personDao: PersonDao
/**
* 用户信息
* 绑卡
* */
@RequestMapping("/bindcard")
- fun bindcard(card: String, name: String, code: String): JsonResult {
+ fun bindcard(cardno: String, name: String, code: String): JsonResult {
val p = SecurityContextHolder.getContext().authentication
val user = mobileApiService.findUserById(p.name)
?: return JsonResult.error("用户不存在,请注册")
if (temp != code) {
return JsonResult.error("验证码错误")
}
- if (user.userid.isNullOrEmpty()) {
- val identy: TPersonIdentity? = userService.findPersonIdentity(card)
- ?: return JsonResult.error("银行卡号有误")
- if (identy!!.person == null || identy.status != TradeDict.STATUS_NORMAL) {
- return JsonResult.error("银行卡号信息有误")
- }
- if (identy.person.name != name) {
- return JsonResult.error("姓名有误")
- }
- val exsitUser = mobileApiService.findUserById(identy.person.userid)
- if (exsitUser != null) {
- return JsonResult.error("该银行卡号已被绑定,如有疑问,请联系客服")
- }
- user.bindtime = DateUtil.getNow()
- user.userid = identy.person.userid
- mobileApiService.saveUser(user)
- redisTemplate.delete(phone)
- var payseted = false
- if (!user.paypwd.isNullOrEmpty()) {
- payseted = true
- }
- return JsonResult.ok("OK").put("userid", user.userid)
- ?.put("paypwdset", payseted)
- ?.put("signed", if (user.issigned.isNullOrEmpty()) "" else user.issigned)!!
- } else {
- return JsonResult.error(-1, "用户已绑定银行卡")
- .put("userid", if (user.userid.isNullOrEmpty()) "" else user.userid)!!
+ 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, "验证码无效或已过期,请重新获取")
}
if (oldpwd.isNullOrEmpty()) {
return JsonResult.error("原支付密码错误")
}
- if (user.paypwderror >= 5 && (System.currentTimeMillis() - user.paypwderrortime!!) < 1000 * 60 * 30) {
+ val paypwdtimes = user.checkPaypwdtime()
+ if(paypwdtimes==-1){
return JsonResult.error("密码错误次数过多,请30分钟后再试")
- } else if (user.paypwderror >= 5 && (System.currentTimeMillis() - user.paypwderrortime!!) > 1000 * 60 * 30) {
- //更新时间
- user.paypwderror = 0
- user.paypwderrortime = null
+ }else if(paypwdtimes==1){
+ mobileApiService.saveUser(user)
}
- if (!encoder.matches(oldpwd, user.paypwd)) {
- if (user.paypwderror == 0) {
- user.paypwderror = 0
- user.paypwderrortime = System.currentTimeMillis()
+ if(!encoder.matches(oldpwd, user.paypwd)){
+ user.updatePaypwderror(false).also {
+ if(it) mobileApiService.saveUser(user)
}
- user.paypwderror += 1
- mobileApiService.saveUser(user)
return JsonResult.error("原支付密码错误")
+ }else{
+ user.updatePaypwderror(true).also {
+ if(it) mobileApiService.saveUser(user)
+ }
}
user.paypwd = encoder.encode(pwd)
mobileApiService.saveUser(user)
fun xieyi(): JsonResult {
val page = mobileApiService.findPageById(ConstantUtil.PAGE_BANKXIEYI)
if (page != null) {
- return JsonResult.ok("OK").put("page", page.pageContent)!!
+ 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("卡片不存在,请重新绑定")
+ if(card.signed){
+ signed = TradeDict.STATUS_YES
+ }
+ }
+ return JsonResult.ok("OK").put("page", page.pageContent)?.put("signed",signed)!!
}
return JsonResult.error("页面未配置")
}
?: return JsonResult.error("用户不存在,请注册")
user.issigned = TradeDict.STATUS_YES
user.signedtime = DateUtil.getNow()
+ var signed=""
+ if(!user.userid.isNullOrEmpty()){
+ var card = mobileApiService.findCardByUserid(user.userid!!) ?: return JsonResult.error("卡片不存在,请重新绑定")
+ if(card.signed){
+ signed = TradeDict.STATUS_YES
+ }
+ card.signed = true
+ mobileApiService.saveCard(card)
+ }
mobileApiService.saveUser(user)
//TODO 调用第三方接口签约
return JsonResult.ok("ok")
- .put("signed", if (user.issigned.isNullOrEmpty()) "" else user.issigned)!!
+ .put("signed", signed)!!
}
/**
payseted = true
}
val person = userService.findOnePersonByUserid(user.userid!!)
+ val card = mobileApiService.findCardByUserid(user.userid!!)
+ var needrebind = false
+ var signed=""
+ if(card==null){
+ //卡片已补办,或绑定失败,需要重新绑定
+ needrebind = true
+ }else{
+ if(card.signed){
+ signed = TradeDict.STATUS_YES
+ }
+ }
var name = person.name
val page = userService.findPersondtlByUserid(user.userid!!, no)
return JsonResult.ok("OK").put("page", page)
?.put("amount", amount)
?.put("paypwdset", payseted)
?.put("name", name)
- ?.put("signed", if (user.issigned.isNullOrEmpty()) "" else user.issigned)
+ ?.put("needrebind",needrebind)
+ ?.put("signed", signed)
?.put("userid", if (user.userid.isNullOrEmpty()) "" else user.userid)!!.put("t", t)!!
}
if (newpwd.isEmpty() || newpwd.length < 6) {
return JsonResult.error("请重新设置密码,密码不能小于6位字符")
}
- if (user.loginpwderror > 5) {
- return JsonResult.error(-1, "原密码错误次数过多,将退出系统,请重新登录系统或点击忘记密码功能找回密码")
+ val pwdtimes = user.checkLoginpwdtime()
+ if(pwdtimes==-1){
+ return JsonResult.error(-1,"原密码错误次数过多,将退出系统,请重新登录系统或点击忘记密码功能找回密码")
+ }else if(pwdtimes==1){
+ mobileApiService.saveUser(user)
}
val encoder = BCryptPasswordEncoder()
- if (!encoder.matches(oldpwd, user.loginpwd)) {
- user.loginpwderror += 1
- mobileApiService.saveUser(user)
+ if(!encoder.matches(oldpwd, user.loginpwd)){
+ user.updateLoginpwderror(false).also {
+ if(it) mobileApiService.saveUser(user)
+ }
return JsonResult.error("原密码错误")
- }
- if (user.loginpwderror > 0) {
- user.loginpwderror = 0
- user.loginpwderrortime = null
+ }else{
+ user.updateLoginpwderror(true)
}
user.loginpwd = encoder.encode(newpwd)
mobileApiService.saveUser(user)
return JsonResult.ok("密码修改成功")
}
-
+ /**
+ *
+ * 市民卡挂失
+ * */
+ @RequestMapping("/cardinfor")
+ fun cardinfor(): JsonResult {
+ val p = SecurityContextHolder.getContext().authentication
+ val user = mobileApiService.findUserById(p.name)
+ ?: return JsonResult.error("用户不存在,请注册")
+ 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=""
+ //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)!!
+ }
/**
*
* 市民卡挂失
@RequestMapping("/cardlost")
fun cardlost(paypwd: String): JsonResult {
val p = SecurityContextHolder.getContext().authentication
- mobileApiService.findUserById(p.name)
+ val user = mobileApiService.findUserById(p.name)
?: return JsonResult.error("用户不存在,请注册")
- //TODO cardlost
+ val paypwdtimes = user.checkPaypwdtime()
+ if(paypwdtimes==-1){
+ return JsonResult.error("支付密码错误次数过多,请30分钟后再试")
+ }else if(paypwdtimes==1){
+ mobileApiService.saveUser(user)
+ }
+ val encoder = BCryptPasswordEncoder()
+ if(!encoder.matches(paypwd, user.paypwd)){
+ user.updatePaypwderror(false).also {
+ if(it) mobileApiService.saveUser(user)
+ }
+ return JsonResult.error("支付密码错误")
+ }else{
+ user.updatePaypwderror(true).also {
+ if(it) mobileApiService.saveUser(user)
+ }
+ }
+ var card = mobileApiService.findCardByUserid(user.userid!!) ?: return JsonResult.error(-1,"银行卡未绑定,请先绑定")
+ if(card.transStatus!=TradeDict.STATUS_NORMAL){
+ return JsonResult.error("卡状态非正常,不能挂失")
+ }
+ card.transStatus=TradeDict.STATUS_LOST
+ mobileApiService.saveCard(card)
return JsonResult.ok("ok")
}