Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wenHuaBu_adminServer
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
node_server
wenHuaBu_adminServer
Commits
2975e41c
Commit
2975e41c
authored
Mar 19, 2024
by
lixinming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
cbd95e61
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
8 deletions
+73
-8
cost.ts
src/biz/member/cost.ts
+63
-6
errorEnum.ts
src/config/errorEnum.ts
+3
-1
system.ts
src/tools/system.ts
+7
-1
No files found.
src/biz/member/cost.ts
View file @
2975e41c
...
@@ -2,20 +2,77 @@
...
@@ -2,20 +2,77 @@
* 收费
* 收费
*/
*/
import
{
PAYMENTTYPE
}
from
"../../config/enum"
;
import
{
ORDERSTATE
,
PAYMENTTYPE
}
from
"../../config/enum"
;
import
{
TABLEENUM
}
from
"../../data/models/model"
;
import
{
TABLEENUM
}
from
"../../data/models/model"
;
import
{
findOnce
}
from
"../../data/select"
;
import
{
findOnce
}
from
"../../data/select"
;
import
{
eccEnumValue
}
from
"../../util/verificationEnum"
;
import
{
eccEnumValue
}
from
"../../util/verificationEnum"
;
import
{
update
}
from
"../portal/fenZhiJiGou/jiGouGuanLi"
;
import
{
update
}
from
"../portal/fenZhiJiGou/jiGouGuanLi"
;
import
*
as
path
from
"path"
;
const
WxPay
=
require
(
'wechatpay-node-v3'
);
const
WxPay
=
require
(
'wechatpay-node-v3'
);
import
*
as
fs
from
'fs'
;
import
*
as
fs
from
'fs'
;
import
{
BizError
}
from
"../../util/bizError"
;
import
{
ERRORENUM
}
from
"../../config/errorEnum"
;
import
{
generateWXOrderId
}
from
"../../tools/system"
;
import
{
updateOneData
}
from
"../../data/update"
;
import
moment
=
require
(
"moment"
);
const
AppId
=
'wx96c0cf11b3babcf6'
;
const
MchId
=
'1614605859'
;
const
pay
=
new
WxPay
({
const
pay
=
new
WxPay
({
appid
:
'wx96c0cf11b3babcf6'
,
appid
:
AppId
,
mchid
:
'1614605859'
,
mchid
:
MchId
,
publicKey
:
fs
.
readFileSync
(
'./apiclient_cert.pem'
),
// 公钥
publicKey
:
fs
.
readFileSync
(
path
.
join
(
__dirname
.
substring
(
0
,
__dirname
.
indexOf
(
"out"
)),
"keys"
,
'apiclient_cert.pem'
)
),
// 公钥
privateKey
:
fs
.
readFileSync
(
'./apiclient_key.pem'
),
// 秘钥
privateKey
:
fs
.
readFileSync
(
path
.
join
(
__dirname
.
substring
(
0
,
__dirname
.
indexOf
(
"out"
)),
"keys"
,
'apiclient_key.pem'
)
),
// 秘钥
});
});
/**
* native下单接口【前端调用】
* @param param0 {id订单列表的id}
* @returns
*/
export
async
function
placeAnOrder
({
id
})
{
let
orderInfo
=
await
findOnce
(
TABLEENUM
.
订单表
,
{
id
},
[
"id"
,
"loginId"
,
"userId"
,
"memberCategory"
,
"money"
,
"orderCycleStart"
,
"orderCycleEnd"
]);
if
(
!
orderInfo
||
!
orderInfo
.
id
)
throw
new
BizError
(
ERRORENUM
.
订单不存在
);
if
(
orderInfo
.
state
!=
ORDERSTATE
.
已支付
)
throw
new
BizError
(
ERRORENUM
.
该订单已支付
);
/**生成 out_trade_no */
let
out_trade_no
=
generateWXOrderId
(
orderInfo
.
memberCategory
,
orderInfo
.
userId
);
let
desc
=
`
${
orderInfo
.
loginId
}
_
${
moment
(
orderInfo
.
orderCycleStart
).
format
(
"YYYY-MM-DD"
)}
至
${
moment
(
orderInfo
.
orderCycleEnd
).
format
(
"YYYY-MM-DD"
)}
`
;
await
updateOneData
(
TABLEENUM
.
订单表
,
{
id
},
{
weChartPR
:
out_trade_no
,
paymentMethod
:
PAYMENTTYPE
.
微信支付
});
/**请求参数 */
const
Param
=
{
appid
:
AppId
,
mchid
:
MchId
,
description
:
desc
,
out_trade_no
,
//订单号
amount
:{
//金额
total
:
orderInfo
.
money
},
notify_url
:
''
,
//测试时先设置白名单地址
};
const
result
=
await
pay
.
transactions_native
(
Param
);
if
(
result
.
status
!=
200
)
throw
new
BizError
(
ERRORENUM
.
调起微信支付失败
);
return
{
code_url
:
result
.
code_url
};
}
/**
* 订单查询状态【前端调用】
*/
export
async
function
orderState
({
orderId
})
{
const
result
=
await
pay
.
query
({
out_trade_no
:
'1609914303237'
});
}
/**
* 关闭订单【前端调用】
*/
export
async
function
orderClose
()
{
}
// var initConfig = {
// var initConfig = {
// partnerKey: "<partnerkey>",
// partnerKey: "<partnerkey>",
...
...
src/config/errorEnum.ts
View file @
2975e41c
...
@@ -35,7 +35,9 @@ export enum ERRORENUM {
...
@@ -35,7 +35,9 @@ export enum ERRORENUM {
用户已注册成功
,
用户已注册成功
,
不具备审批条件
,
不具备审批条件
,
该用户已在宽限期内
,
该用户已在宽限期内
,
该订单已支付
该订单已支付
,
调起微信支付失败
,
订单不存在
}
}
export
enum
ERRORCODEENUM
{
export
enum
ERRORCODEENUM
{
...
...
src/tools/system.ts
View file @
2975e41c
...
@@ -77,8 +77,14 @@ export function generateOrderId(userId:string) {
...
@@ -77,8 +77,14 @@ export function generateOrderId(userId:string) {
* 获取今天开始时刻的时间戳 0时0分
* 获取今天开始时刻的时间戳 0时0分
* @returns
* @returns
*/
*/
export
function
getTodayMs
()
{
export
function
getTodayMs
()
{
return
new
Date
(
`
${
moment
().
format
(
"YYYY-MM-DD"
)}
00:00:00`
).
valueOf
();
return
new
Date
(
`
${
moment
().
format
(
"YYYY-MM-DD"
)}
00:00:00`
).
valueOf
();
}
}
export
function
generateWXOrderId
(
memberType
,
userId
)
{
let
thisDate
=
new
Date
();
return
`
${
memberType
}
_
${
thisDate
.
getFullYear
()}
_
${
md5
(
`
${
userId
}${
Math
.
random
()
*
100
}${
thisDate
.
valueOf
()}${
Math
.
floor
(
Math
.
random
()
*
1000
)}
`
)}
`
}
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