Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
youka-api
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
java-youka-wallet
youka-api
Commits
1810e8d3
Commit
1810e8d3
authored
Jun 07, 2018
by
tang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
费率相关计算封装
parent
932f54cb
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
160 additions
and
3 deletions
+160
-3
PayApiDao.java
src/main/java/com/thinkgem/jeesite/modules/pay/dao/PayApiDao.java
+3
-2
RateDao.java
src/main/java/com/thinkgem/jeesite/modules/pay/dao/RateDao.java
+20
-0
PayApiService.java
src/main/java/com/thinkgem/jeesite/modules/pay/service/PayApiService.java
+89
-1
PayApiDao.xml
src/main/resources/mappings/modules/pay/PayApiDao.xml
+18
-0
RateDao.xml
src/main/resources/mappings/modules/pay/RateDao.xml
+30
-0
No files found.
src/main/java/com/thinkgem/jeesite/modules/pay/dao/PayApiDao.java
View file @
1810e8d3
...
@@ -7,6 +7,7 @@ import com.thinkgem.jeesite.modules.pay.entity.UserRateEntity;
...
@@ -7,6 +7,7 @@ import com.thinkgem.jeesite.modules.pay.entity.UserRateEntity;
import
com.thinkgem.jeesite.modules.user.entity.CardEntity
;
import
com.thinkgem.jeesite.modules.user.entity.CardEntity
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
@MyBatisDao
@MyBatisDao
public
interface
PayApiDao
{
public
interface
PayApiDao
{
...
@@ -34,6 +35,6 @@ public interface PayApiDao {
...
@@ -34,6 +35,6 @@ public interface PayApiDao {
// 查询状态为支付中的状态
// 查询状态为支付中的状态
List
<
OrderEntity
>
getOrderListTimeing
(
OrderEntity
orderEntity
);
List
<
OrderEntity
>
getOrderListTimeing
(
OrderEntity
orderEntity
);
//获取不同渠道最新使用的额度
Double
getLastLimit
(
Map
<
String
,
String
>
map
);
}
}
src/main/java/com/thinkgem/jeesite/modules/pay/dao/RateDao.java
0 → 100644
View file @
1810e8d3
package
com
.
thinkgem
.
jeesite
.
modules
.
pay
.
dao
;
import
com.thinkgem.jeesite.common.persistence.annotation.MyBatisDao
;
import
com.thinkgem.jeesite.modules.pay.bean.OrderRequest
;
import
com.thinkgem.jeesite.modules.pay.entity.BenefitEntity
;
import
com.thinkgem.jeesite.modules.pay.entity.OrderEntity
;
import
com.thinkgem.jeesite.modules.pay.entity.RateEntity
;
import
java.util.List
;
import
java.util.Map
;
/**
* 费率Dao
*/
@MyBatisDao
public
interface
RateDao
{
public
RateEntity
getRateEntity
(
Map
<
String
,
String
>
map
);
}
\ No newline at end of file
src/main/java/com/thinkgem/jeesite/modules/pay/service/PayApiService.java
View file @
1810e8d3
...
@@ -2,6 +2,7 @@ package com.thinkgem.jeesite.modules.pay.service;
...
@@ -2,6 +2,7 @@ package com.thinkgem.jeesite.modules.pay.service;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alipay.api.AlipayApiException
;
import
com.alipay.api.AlipayApiException
;
import
com.google.common.collect.Maps
;
import
com.thinkgem.jeesite.common.baseBean.Request
;
import
com.thinkgem.jeesite.common.baseBean.Request
;
import
com.thinkgem.jeesite.common.baseBean.Response
;
import
com.thinkgem.jeesite.common.baseBean.Response
;
import
com.thinkgem.jeesite.common.config.Global
;
import
com.thinkgem.jeesite.common.config.Global
;
...
@@ -12,6 +13,7 @@ import com.thinkgem.jeesite.common.utils.StringUtils;
...
@@ -12,6 +13,7 @@ import com.thinkgem.jeesite.common.utils.StringUtils;
import
com.thinkgem.jeesite.modules.commonError.MyException
;
import
com.thinkgem.jeesite.modules.commonError.MyException
;
import
com.thinkgem.jeesite.modules.pay.alipay.service.AlipayService
;
import
com.thinkgem.jeesite.modules.pay.alipay.service.AlipayService
;
import
com.thinkgem.jeesite.modules.pay.dao.PayApiDao
;
import
com.thinkgem.jeesite.modules.pay.dao.PayApiDao
;
import
com.thinkgem.jeesite.modules.pay.dao.RateDao
;
import
com.thinkgem.jeesite.modules.pay.entity.*
;
import
com.thinkgem.jeesite.modules.pay.entity.*
;
import
com.thinkgem.jeesite.modules.pay.huanqiuhuiju.service.HuanqiuhuijuService
;
import
com.thinkgem.jeesite.modules.pay.huanqiuhuiju.service.HuanqiuhuijuService
;
import
com.thinkgem.jeesite.modules.pay.juhezhong.dto.JuhezhongDto
;
import
com.thinkgem.jeesite.modules.pay.juhezhong.dto.JuhezhongDto
;
...
@@ -74,6 +76,9 @@ public class PayApiService {
...
@@ -74,6 +76,9 @@ public class PayApiService {
@Autowired
@Autowired
private
BenefitSevice
benefitSevice
;
private
BenefitSevice
benefitSevice
;
@Autowired
private
RateDao
rateDao
;
/**
/**
* 快捷支付(分为不同的渠道)
* 快捷支付(分为不同的渠道)
...
@@ -97,6 +102,11 @@ public class PayApiService {
...
@@ -97,6 +102,11 @@ public class PayApiService {
CardEntity
cardEntity
=
userService
.
getDebitCardByUserCode
(
userRequest
);
CardEntity
cardEntity
=
userService
.
getDebitCardByUserCode
(
userRequest
);
userEntity
.
getUserDetail
().
setCard
(
cardEntity
);
userEntity
.
getUserDetail
().
setCard
(
cardEntity
);
//获取当前渠道当日剩余额度
BigDecimal
limitNumber
=
getLimitNumber
(
userEntity
.
getLevel
(),
userEntity
.
getCode
(),
request
.
getPayChannel
());
if
(
BigDecimal
.
valueOf
(
Double
.
valueOf
(
request
.
getAmount
())).
compareTo
(
limitNumber
)>
0
){
throw
new
MyException
(
"超出额度"
);
}
// 2. 创建支付订单信息,并保存
// 2. 创建支付订单信息,并保存
String
code
=
IdGen
.
randomBase62
(
64
);
String
code
=
IdGen
.
randomBase62
(
64
);
String
payNo
=
ComCode
.
YYYYMMDDHHMM
.
format
(
new
Date
())
+
IdGen
.
randomBase62
(
8
);
// 订单号
String
payNo
=
ComCode
.
YYYYMMDDHHMM
.
format
(
new
Date
())
+
IdGen
.
randomBase62
(
8
);
// 订单号
...
@@ -707,6 +717,12 @@ public class PayApiService {
...
@@ -707,6 +717,12 @@ public class PayApiService {
@Transactional
(
readOnly
=
false
)
@Transactional
(
readOnly
=
false
)
public
PayBackDto
payJuhezhong
(
JuHeZhongPayRequest
request
,
UserEntity
userEntity
,
OrderEntity
orderEntity
,
CardEntity
cardEntity
)
throws
Exception
{
public
PayBackDto
payJuhezhong
(
JuHeZhongPayRequest
request
,
UserEntity
userEntity
,
OrderEntity
orderEntity
,
CardEntity
cardEntity
)
throws
Exception
{
//获取用户对应等级费率以及每笔需要的手续费
RateEntity
gradeRate
=
getGradeRate
(
userEntity
.
getLevel
(),
request
.
getPayChannel
());
//获取扣除手续费后的金额
BigDecimal
amount
=
calculationAmount
(
gradeRate
,
request
.
getAmount
());
//通过用户code获取user_detail表中数据
//通过用户code获取user_detail表中数据
UserDetailEntity
userDetail
=
userService
.
getUserDetailByCode
(
userEntity
.
getCode
());
UserDetailEntity
userDetail
=
userService
.
getUserDetailByCode
(
userEntity
.
getCode
());
PayBackDto
payBackDto
=
new
PayBackDto
();
PayBackDto
payBackDto
=
new
PayBackDto
();
...
@@ -717,7 +733,7 @@ public class PayApiService {
...
@@ -717,7 +733,7 @@ public class PayApiService {
dto
.
setOrderId
(
MakeOrderNum
.
makeOrderNum
());
//非订单号
dto
.
setOrderId
(
MakeOrderNum
.
makeOrderNum
());
//非订单号
dto
.
setMerchantId
(
ComCode
.
MERCHANT_ID
);
//商户号
dto
.
setMerchantId
(
ComCode
.
MERCHANT_ID
);
//商户号
dto
.
setMerchantKey
(
ComCode
.
MERCHANT_KEY
);
dto
.
setMerchantKey
(
ComCode
.
MERCHANT_KEY
);
dto
.
setAmount
(
Integer
.
valueOf
(
orderEntity
.
getAmount
())*
100
);
//订单金额,单位为分
dto
.
setAmount
(
amount
.
multiply
(
BigDecimal
.
valueOf
(
100
)).
intValue
()
);
//订单金额,单位为分
dto
.
setTrxType
(
3
);
//交易类型,默认传3
dto
.
setTrxType
(
3
);
//交易类型,默认传3
dto
.
setType
(
cardEntity
.
getCardType
().
equals
(
"D"
)?
6
:
5
);
//5 借记卡 只能 D0 6 贷记卡 D0 t1 ,表中 银行卡类型 D储蓄卡 C信用卡'
dto
.
setType
(
cardEntity
.
getCardType
().
equals
(
"D"
)?
6
:
5
);
//5 借记卡 只能 D0 6 贷记卡 D0 t1 ,表中 银行卡类型 D储蓄卡 C信用卡'
dto
.
setBankNo
(
cardEntity
.
getCardNo
());
//支付卡号
dto
.
setBankNo
(
cardEntity
.
getCardNo
());
//支付卡号
...
@@ -1183,4 +1199,76 @@ public class PayApiService {
...
@@ -1183,4 +1199,76 @@ public class PayApiService {
payDao
.
deleteBenefit
(
benefitEntity
);
payDao
.
deleteBenefit
(
benefitEntity
);
}
}
/**
* 获取对应用户等级的费率
* @param user_level
* @param pay_channel
* @return
*/
public
RateEntity
getGradeRate
(
String
user_level
,
String
pay_channel
){
Map
<
String
,
String
>
maps
=
Maps
.
newHashMap
();
maps
.
put
(
"user_level"
,
user_level
);
maps
.
put
(
"pay_channel"
,
pay_channel
);
RateEntity
rateList
=
rateDao
.
getRateEntity
(
maps
);
return
rateList
;
}
/**
* 获取用户当日已使用额度,已支付完成时间为准
* @param user_code
* @param pay_channel
* @return
*/
public
Double
getUseNum
(
String
user_code
,
String
pay_channel
){
HashMap
<
String
,
String
>
maps
=
Maps
.
newHashMap
();
maps
.
put
(
"user_code"
,
user_code
);
maps
.
put
(
"pay_channel"
,
pay_channel
);
Double
lastLimit
=
payDao
.
getLastLimit
(
maps
);
return
lastLimit
;
}
/**
* 计算当日剩余额度
* @param dayLimit
* @param num
* @return
*/
public
BigDecimal
getLimitNum
(
String
dayLimit
,
Double
num
){
return
BigDecimal
.
valueOf
(
Long
.
valueOf
(
dayLimit
)).
subtract
(
BigDecimal
.
valueOf
(
num
));
}
/**
* 计算当日剩余额度(集中)
* @param user_level
* @param user_code
* @param pay_channel
* @return
*/
public
BigDecimal
getLimitNumber
(
String
user_level
,
String
user_code
,
String
pay_channel
){
Map
<
String
,
String
>
maps
=
Maps
.
newHashMap
();
maps
.
put
(
"user_level"
,
user_level
);
maps
.
put
(
"pay_channel"
,
pay_channel
);
maps
.
put
(
"user_code"
,
user_code
);
RateEntity
rateList
=
rateDao
.
getRateEntity
(
maps
);
Double
num
=
payDao
.
getLastLimit
(
maps
);
return
BigDecimal
.
valueOf
(
Long
.
valueOf
(
rateList
.
getDayLimit
())).
subtract
(
BigDecimal
.
valueOf
(
num
));
}
/**
* 计算扣除费率及每笔交易手续费的差值
* @param gradeRate
* @param amount
* @return
*/
public
BigDecimal
calculationAmount
(
RateEntity
gradeRate
,
String
amount
){
Double
siglePrice
=
Double
.
valueOf
(
gradeRate
.
getSiglePrice
());
Double
rate
=
Double
.
valueOf
(
gradeRate
.
getRate
());
Double
amountDouble
=
Double
.
valueOf
(
amount
);
//扣除费率及手续费后的金额
BigDecimal
result
=
BigDecimal
.
valueOf
(
amountDouble
).
subtract
(
BigDecimal
.
valueOf
(
siglePrice
))
.
subtract
(
BigDecimal
.
valueOf
(
amountDouble
*
rate
));
return
result
;
}
}
}
src/main/resources/mappings/modules/pay/PayApiDao.xml
View file @
1810e8d3
...
@@ -172,4 +172,21 @@
...
@@ -172,4 +172,21 @@
SET del_flag = 1
SET del_flag = 1
WHERE order_code = #{orderCode}
WHERE order_code = #{orderCode}
</update>
</update>
<select
id=
"getLastLimit"
resultType=
"java.lang.Double"
>
SELECT
IFNULL(SUM(amount),0)
FROM
youka_orders
WHERE
pay_status = 2
<if
test=
"user_code != null and user_code != ''"
>
AND user_code = #{user_code}
</if>
<if
test=
"pay_channel != null and pay_channel != ''"
>
AND pay_channel >= #{pay_channel}
</if>
AND update_date >= date(now())
AND update_date
<
DATE_ADD(date(now()), INTERVAL 1 DAY)
</select>
</mapper>
</mapper>
\ No newline at end of file
src/main/resources/mappings/modules/pay/RateDao.xml
0 → 100644
View file @
1810e8d3
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.thinkgem.jeesite.modules.pay.dao.RateDao"
>
<select
id=
"getRateEntity"
resultType=
"com.thinkgem.jeesite.modules.pay.entity.RateEntity"
>
SELECT
user_level,
pay_method,
pay_channel,
rate,
rate_type,
sigle_price,
day_limit
FROM
youka_rate
WHERE
1=1
<if
test=
"user_level != null and user_level != ''"
>
AND user_level = #{user_level}
</if>
<if
test=
"pay_channel != null and pay_channel != ''"
>
AND pay_channel = #{pay_channel}
</if>
LIMIT 1
</select>
</mapper>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment