q-koa 12.0.7 → 12.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/app.js
CHANGED
|
@@ -1534,9 +1534,8 @@ class APP {
|
|
|
1534
1534
|
app[appName].attributes[modelName] &&
|
|
1535
1535
|
app[appName].attributes[modelName][controller + '_id']
|
|
1536
1536
|
) {
|
|
1537
|
-
const { required, include, where, ...rest } =
|
|
1538
|
-
j
|
|
1539
|
-
]
|
|
1537
|
+
const { required, include, where, ...rest } =
|
|
1538
|
+
myInclude[j]
|
|
1540
1539
|
const list = await model.findAll({
|
|
1541
1540
|
where: {
|
|
1542
1541
|
[controller + '_id']: target.id,
|
|
@@ -1463,6 +1463,39 @@ exports.checkPay = async (ctx) => {
|
|
|
1463
1463
|
ctx.SUCCESS({ prefix, out_trade_no, ...payResult })
|
|
1464
1464
|
}
|
|
1465
1465
|
|
|
1466
|
+
exports.checkPayOnly = async (ctx) => {
|
|
1467
|
+
const { app, appName, controller } = getAppByCtx(ctx)
|
|
1468
|
+
|
|
1469
|
+
const {
|
|
1470
|
+
id,
|
|
1471
|
+
prefix,
|
|
1472
|
+
config = 'weixin_mp',
|
|
1473
|
+
pay_config = 'weixin_pay',
|
|
1474
|
+
type = 'MP-WEIXIN',
|
|
1475
|
+
out_trade_no: _out_trade_no,
|
|
1476
|
+
} = ctx.request.body
|
|
1477
|
+
|
|
1478
|
+
const appConfig = getConfig(app)
|
|
1479
|
+
const app_id = (await appConfig.getObject(config)).app_id
|
|
1480
|
+
const { mchId, key, partner_key } = await appConfig.getObject(pay_config)
|
|
1481
|
+
|
|
1482
|
+
const wxpay = WXPay({
|
|
1483
|
+
appid: app_id,
|
|
1484
|
+
mch_id: mchId,
|
|
1485
|
+
partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
|
|
1486
|
+
})
|
|
1487
|
+
|
|
1488
|
+
const orderPrefix = prefix ? `${prefix}-` : ''
|
|
1489
|
+
const out_trade_no = _out_trade_no
|
|
1490
|
+
? _out_trade_no
|
|
1491
|
+
: `${key}_${orderPrefix}${id}_${type}`
|
|
1492
|
+
const payResult = await wxpay.queryOrderSync({
|
|
1493
|
+
out_trade_no,
|
|
1494
|
+
})
|
|
1495
|
+
|
|
1496
|
+
ctx.SUCCESS({ prefix, out_trade_no, ...payResult })
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1466
1499
|
exports.checkRefund = async (ctx) => {
|
|
1467
1500
|
const { app, appName, controller } = getAppByCtx(ctx)
|
|
1468
1501
|
|
|
@@ -18,6 +18,7 @@ exports.refund = async ({
|
|
|
18
18
|
config = 'weixin_mp',
|
|
19
19
|
pay_config = 'weixin_pay',
|
|
20
20
|
out_trade_no: _out_trade_no,
|
|
21
|
+
out_refund_no: _out_refund_no,
|
|
21
22
|
...rest
|
|
22
23
|
}) => {
|
|
23
24
|
if (!ctx) throw new Error('?ctx')
|
|
@@ -64,11 +65,13 @@ exports.refund = async ({
|
|
|
64
65
|
try {
|
|
65
66
|
const refundRecords = lodash.get(orderDetail, 'order_refund_records', [])
|
|
66
67
|
const refundNumber = refundRecords.length + 1
|
|
67
|
-
|
|
68
|
+
const out_refund_no =
|
|
69
|
+
_out_refund_no || [`${prefix}-${id}`, type, refundNumber].join('_')
|
|
70
|
+
|
|
68
71
|
const data = {
|
|
69
72
|
...rest,
|
|
70
73
|
out_trade_no,
|
|
71
|
-
out_refund_no
|
|
74
|
+
out_refund_no,
|
|
72
75
|
total_fee: Number(payResult.total_fee),
|
|
73
76
|
refund_fee: Math.round((refund_fee || price) * 100),
|
|
74
77
|
notify_url: `https://${
|
|
@@ -76,16 +79,12 @@ exports.refund = async ({
|
|
|
76
79
|
}/${appName}/weixin/refund_notify/${pay_config}`,
|
|
77
80
|
}
|
|
78
81
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
err_code_des,
|
|
82
|
-
out_refund_no,
|
|
83
|
-
...restData
|
|
84
|
-
} = await payObj.refund(data)
|
|
82
|
+
console.log(data)
|
|
83
|
+
const { result_code, err_code_des, ...restData } = await payObj.refund(data)
|
|
85
84
|
if (result_code === 'SUCCESS') {
|
|
86
85
|
const hasResult = await app.model.order_refund_record.findOne({
|
|
87
86
|
where: {
|
|
88
|
-
out_refund_no,
|
|
87
|
+
out_refund_no: restData.out_refund_no,
|
|
89
88
|
},
|
|
90
89
|
})
|
|
91
90
|
if (hasResult) {
|
|
@@ -101,6 +100,73 @@ exports.refund = async ({
|
|
|
101
100
|
}
|
|
102
101
|
}
|
|
103
102
|
|
|
103
|
+
exports.refundOnly = async ({
|
|
104
|
+
ctx,
|
|
105
|
+
id,
|
|
106
|
+
prefix = '',
|
|
107
|
+
total_fee,
|
|
108
|
+
refund_fee,
|
|
109
|
+
price,
|
|
110
|
+
pay_type = 'MP-WEIXIN',
|
|
111
|
+
type = '',
|
|
112
|
+
config = 'weixin_mp',
|
|
113
|
+
pay_config = 'weixin_pay',
|
|
114
|
+
out_trade_no: _out_trade_no,
|
|
115
|
+
out_refund_no: _out_refund_no,
|
|
116
|
+
...rest
|
|
117
|
+
}) => {
|
|
118
|
+
if (!ctx) throw new Error('?ctx')
|
|
119
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
120
|
+
const appConfig = getConfig(app)
|
|
121
|
+
const { mchId, key, appId, partner_key } = await appConfig.getObject(
|
|
122
|
+
pay_config
|
|
123
|
+
)
|
|
124
|
+
const { site_host } = await appConfig.getObject('base')
|
|
125
|
+
|
|
126
|
+
const payObj = new Pay({
|
|
127
|
+
appId: appId,
|
|
128
|
+
mchId: mchId,
|
|
129
|
+
key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥,
|
|
130
|
+
pfx: await fsPromise.readFile(
|
|
131
|
+
path.resolve(
|
|
132
|
+
__dirname,
|
|
133
|
+
`${process.cwd()}/app/${appName}/plugins/weixin/${key}/apiclient_cert.p12`
|
|
134
|
+
)
|
|
135
|
+
), // 微信商户平台证书
|
|
136
|
+
})
|
|
137
|
+
const out_trade_no =
|
|
138
|
+
_out_trade_no ||
|
|
139
|
+
(prefix ? `${key}_${prefix}-${id}_${pay_type}` : `${key}_${id}_${pay_type}`)
|
|
140
|
+
|
|
141
|
+
const wxpay = WXPay({
|
|
142
|
+
appid: appId,
|
|
143
|
+
mch_id: mchId,
|
|
144
|
+
partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
const out_refund_no = _out_refund_no || [`${prefix}-${id}`, type].join('_')
|
|
149
|
+
const data = {
|
|
150
|
+
...rest,
|
|
151
|
+
out_trade_no,
|
|
152
|
+
total_fee: Math.round((refund_fee || price) * 100),
|
|
153
|
+
refund_fee: Math.round((refund_fee || price) * 100),
|
|
154
|
+
out_refund_no,
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
console.log(data)
|
|
158
|
+
const { result_code, err_code_des, ...restData } = await payObj.refund(data)
|
|
159
|
+
if (result_code === 'SUCCESS') {
|
|
160
|
+
return restData
|
|
161
|
+
} else {
|
|
162
|
+
console.error(data)
|
|
163
|
+
throw new Error(err_code_des)
|
|
164
|
+
}
|
|
165
|
+
} catch (e) {
|
|
166
|
+
throw new Error(e.message)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
104
170
|
exports.refund_new = async ({
|
|
105
171
|
ctx,
|
|
106
172
|
id,
|
|
@@ -647,3 +713,64 @@ exports.removereceiver = async ({
|
|
|
647
713
|
})
|
|
648
714
|
return res
|
|
649
715
|
}
|
|
716
|
+
|
|
717
|
+
exports.downloadBill = async ({ ctx, pay_config = 'weixin_pay', ...rest }) => {
|
|
718
|
+
if (!ctx) throw new Error('?ctx')
|
|
719
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
720
|
+
const appConfig = getConfig(app)
|
|
721
|
+
const { mchId, key, appId, partner_key } = await appConfig.getObject(
|
|
722
|
+
pay_config
|
|
723
|
+
)
|
|
724
|
+
const payObj = new Pay({
|
|
725
|
+
appId: appId,
|
|
726
|
+
mchId: mchId,
|
|
727
|
+
key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥,
|
|
728
|
+
pfx: await fsPromise.readFile(
|
|
729
|
+
path.resolve(
|
|
730
|
+
__dirname,
|
|
731
|
+
`${process.cwd()}/app/${appName}/plugins/weixin/${key}/apiclient_cert.p12`
|
|
732
|
+
)
|
|
733
|
+
), // 微信商户平台证书
|
|
734
|
+
})
|
|
735
|
+
|
|
736
|
+
try {
|
|
737
|
+
const result = await payObj.downloadBill(rest)
|
|
738
|
+
|
|
739
|
+
const arr = result.split('\r\n')
|
|
740
|
+
const list = arr.slice(1, arr.length - 3)
|
|
741
|
+
return {
|
|
742
|
+
header: arr[0],
|
|
743
|
+
list,
|
|
744
|
+
result: list.map((item) => {
|
|
745
|
+
const array = item.split(',')
|
|
746
|
+
const orderdate = array[20].substring(1).slice(2, 10)
|
|
747
|
+
return {
|
|
748
|
+
created_at: array[0].substring(1),
|
|
749
|
+
transactionid: array[5].substring(1),
|
|
750
|
+
order_id: Number(array[6].substring(1).split('_')[1]),
|
|
751
|
+
openid: array[7].substring(1),
|
|
752
|
+
price: Number(array[12].substring(1)),
|
|
753
|
+
refund_price: Number(array[16].substring(1)),
|
|
754
|
+
remark: array[20].substring(1),
|
|
755
|
+
rate_price: Number(array[22].substring(1)),
|
|
756
|
+
type: array[9].substring(1),
|
|
757
|
+
order_date: `${orderdate.slice(0, 4)}-${orderdate.slice(
|
|
758
|
+
4,
|
|
759
|
+
6
|
|
760
|
+
)}-${orderdate.slice(6, 8)}`,
|
|
761
|
+
}
|
|
762
|
+
}),
|
|
763
|
+
totalHeader: arr[arr.length - 3],
|
|
764
|
+
total: arr[arr.length - 2],
|
|
765
|
+
totalResult: {
|
|
766
|
+
number: Number(arr[arr.length - 2].split(',')[0].substring(1)),
|
|
767
|
+
total_price: Number(arr[arr.length - 2].split(',')[1].substring(1)),
|
|
768
|
+
refund_price: Number(arr[arr.length - 2].split(',')[2].substring(1)),
|
|
769
|
+
rate_price: Number(arr[arr.length - 2].split(',')[4].substring(1)),
|
|
770
|
+
price: Number(arr[arr.length - 2].split(',')[5].substring(1)),
|
|
771
|
+
},
|
|
772
|
+
}
|
|
773
|
+
} catch {
|
|
774
|
+
return []
|
|
775
|
+
}
|
|
776
|
+
}
|