q-koa 8.9.0 → 8.9.1

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.
@@ -127,7 +127,6 @@ exports.refund_new = async ({
127
127
  total_amount: Math.round((total_fee || refund_fee || price) * 100),
128
128
  refund_amount: Math.round((refund_fee || price) * 100),
129
129
  })
130
- console.log('result', result)
131
130
  return result
132
131
  // if (result_code === 'SUCCESS') {
133
132
  // return true
@@ -296,3 +295,132 @@ exports.url_link = async ({ app, page, scene, config = 'weixin_mp' }) => {
296
295
  })
297
296
  return result
298
297
  }
298
+
299
+ exports.user_enter_tempsession = async ({ app, result }) => {
300
+ console.log('user_enter_tempsession', result)
301
+ }
302
+
303
+ exports.handleUserMessage = async ({ app, result }) => {
304
+ const appConfig = getConfig(app)
305
+
306
+ if (result.ToUserName) {
307
+ const { app_id, app_secrect } = await appConfig.getObject(result.ToUserName)
308
+ const weixinMp = new WeixinMp({
309
+ appid: app_id,
310
+ secrect: app_secrect,
311
+ })
312
+ weixinMp.init()
313
+ await weixinMp.handleMessage({
314
+ touser: result.FromUserName,
315
+ msgtype: 'text',
316
+ text: {
317
+ content: `你说${result.Content},是吗?`,
318
+ },
319
+ })
320
+ }
321
+ }
322
+
323
+ exports.funds_order_pay = async ({ app, result }) => {
324
+ const appConfig = getConfig(app)
325
+
326
+ if (result.ToUserName) {
327
+ const { app_id, app_secrect, mchId } = await appConfig.getObject(
328
+ result.ToUserName
329
+ )
330
+
331
+ const weixinMp = new WeixinMp({
332
+ appid: app_id,
333
+ secrect: app_secrect,
334
+ })
335
+ weixinMp.init()
336
+
337
+ if (result.order_info) {
338
+ let prefix = ''
339
+ let order_id = result.order_info.trade_no.split('_')[1]
340
+ if (order_id.includes('-')) {
341
+ const arr = order_id.split('-')
342
+ order_id = Number(arr[1])
343
+ ;[prefix] = arr
344
+ } else {
345
+ order_id = Number(order_id)
346
+ }
347
+ const model = prefix ? `${prefix}_order` : 'order'
348
+ let transactionid = ''
349
+ try {
350
+ transactionid = result.order_info.transaction_id
351
+ } catch (e) {}
352
+
353
+ const payResult = await weixinMp.getOrder({
354
+ trade_no: result.order_info.trade_no,
355
+ })
356
+
357
+ const { amount } = payResult
358
+
359
+ if (app.service[model] && app.service[model].notify) {
360
+ await app.service[model].notify({
361
+ app,
362
+ order_id,
363
+ order: model,
364
+ order_price: amount / 100,
365
+ transactionid,
366
+ })
367
+ }
368
+ }
369
+ }
370
+ }
371
+
372
+ exports.funds_order_refund = async ({ app, result }) => {
373
+ const appConfig = getConfig(app)
374
+
375
+ if (result.ToUserName) {
376
+ const { app_id, app_secrect, mchId } = await appConfig.getObject(
377
+ result.ToUserName
378
+ )
379
+
380
+ const weixinMp = new WeixinMp({
381
+ appid: app_id,
382
+ secrect: app_secrect,
383
+ })
384
+ weixinMp.init()
385
+
386
+ if (result.order_info) {
387
+ let prefix = ''
388
+ let order_id = result.order_info.refund_no.split('_')[1]
389
+ if (order_id.includes('-')) {
390
+ const arr = order_id.split('-')
391
+ order_id = Number(arr[1])
392
+ ;[prefix] = arr
393
+ } else {
394
+ order_id = Number(order_id)
395
+ }
396
+ const model = prefix ? `${prefix}_order` : 'order'
397
+
398
+ const trade_no = result.order_info.refund_no
399
+ .split('_')
400
+ .slice(0, 2)
401
+ .join('_')
402
+
403
+ const type = trade_no.includes('_') ? trade_no.split('_')[1] : ''
404
+
405
+ const payResult = await weixinMp.getOrder({
406
+ trade_no,
407
+ })
408
+
409
+ const refundTarget = payResult.refund_list.find(
410
+ (t) => t.refund_no === result.order_info.refund_no
411
+ )
412
+
413
+ if (!refundTarget || refundTarget.result !== 'SUCCESS')
414
+ throw new Error('还没退成功')
415
+ if (app.service[model] && app.service[model].refund_notify) {
416
+ await app.service[model].refund_notify({
417
+ app,
418
+ order_id,
419
+ order: model,
420
+ refund_price: refundTarget.amount / 100,
421
+ type,
422
+ })
423
+ }
424
+ }
425
+ }
426
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "8.9.0",
3
+ "version": "8.9.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {