q-koa 10.7.3 → 10.7.6

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.
@@ -474,11 +474,50 @@ exports.dashboard = async (ctx) => {
474
474
  ctx.SUCCESS(result)
475
475
  }
476
476
 
477
+ exports.showAllModel = async (ctx) => {
478
+ const { app, appName } = getAppByCtx(ctx)
479
+ const { is_count = false } = ctx.request.body
480
+ const result = await app.sequelize.showAllSchemas()
481
+ const list = result.map(
482
+ (item) => item[`Tables_in_${app.sequelize.config.database}`]
483
+ )
484
+ let tableList = []
485
+ for (let i = 0; i < list.length; i++) {
486
+ if (!app.model[list[i]]) continue
487
+ const defaultConfigPath = path.resolve(__dirname, `../${list[i]}/config.js`)
488
+ const defaultConfigExist = fs.existsSync(defaultConfigPath)
489
+ const target =
490
+ app.config[list[i]] &&
491
+ Object.keys(app.config[list[i]]).length === 0 &&
492
+ defaultConfigExist
493
+ ? require(defaultConfigPath)
494
+ : app.config[list[i]]
495
+ let count = 0
496
+ if (is_count) {
497
+ count = await app.model[list[i]].count()
498
+ }
499
+ tableList = [
500
+ ...tableList,
501
+ {
502
+ count,
503
+ name: target.name,
504
+ model: list[i],
505
+ count,
506
+ },
507
+ ]
508
+ }
509
+ return ctx.SUCCESS(
510
+ tableList.map((item) => lodash.omit(item, is_count ? [] : ['count']))
511
+ )
512
+ }
513
+
477
514
  exports.drop = async (ctx) => {
478
515
  const { app, appName } = getAppByCtx(ctx)
479
516
 
480
517
  const result = await app.sequelize.showAllSchemas()
481
- const list = result.map((item) => item[`Tables_in_${appName}`])
518
+ const list = result.map(
519
+ (item) => item[`Tables_in_${app.sequelize.config.database}`]
520
+ )
482
521
  const filterList = list.filter((item) => !app.model[item])
483
522
  await Promise.all(
484
523
  filterList.map((folder) => {
@@ -542,7 +581,9 @@ exports.copyOther = async (ctx) => {
542
581
  list = [model]
543
582
  } else {
544
583
  const result = await app.sequelize.showAllSchemas()
545
- list = result.map((item) => item[`Tables_in_${appName}`])
584
+ list = result.map(
585
+ (item) => item[`Tables_in_${app.sequelize.config.database}`]
586
+ )
546
587
  }
547
588
  }
548
589
 
@@ -862,6 +862,87 @@ exports.pc_pay = async (ctx) => {
862
862
  return ctx.SUCCESS(result)
863
863
  }
864
864
 
865
+ exports.app_pay = async (ctx) => {
866
+ const { app, appName } = getAppByCtx(ctx)
867
+ const {
868
+ name,
869
+ order_id,
870
+ price,
871
+ return_url,
872
+ prefix = '',
873
+ type,
874
+ out_trade_no: _out_trade_no,
875
+ is_admin = false,
876
+ config = 'weixin_mp',
877
+ pay_config = 'weixin_pay',
878
+ } = ctx.request.body
879
+
880
+ if (price === 0) throw new Error('价格不能为0')
881
+
882
+ // if (
883
+ // !ctx.request[`${appName}-user`] ||
884
+ // !ctx.request[`${appName}-user`].open_user
885
+ // ) {
886
+ // throw new Error('请先微信登录')
887
+ // }
888
+ const appConfig = getConfig(app)
889
+
890
+ const { mchId, key, partner_key, appId: appid } = await appConfig.getObject(
891
+ pay_config
892
+ )
893
+
894
+ if (!appid) throw new Error(`appId不能存在`)
895
+
896
+ const { is_dev, site_host } = await appConfig.getObject('base')
897
+
898
+ const wxpay = WXPay({
899
+ appid,
900
+ mch_id: mchId,
901
+ partner_key: key.length > 10 ? key : partner_key, // 微信商户平台API密钥
902
+ })
903
+
904
+ const out_trade_no = _out_trade_no
905
+ ? _out_trade_no
906
+ : prefix
907
+ ? `${key.length > 10 ? appName : key}_${prefix}-${order_id}_${type}`
908
+ : `${key.length > 10 ? appName : key}_${order_id}_${type}`
909
+
910
+ const notify_url = `https://${
911
+ site_host || 'api.kuashou.com'
912
+ }/${appName}/weixin/notify`
913
+
914
+ const result = await wxpay.appPaySync({
915
+ trade_type: 'APP',
916
+ body: name,
917
+ detail: '公众号支付测试',
918
+ out_trade_no,
919
+ total_fee: is_admin || is_dev ? 1 : Math.round(price * 100),
920
+ spbill_create_ip: '192.168.2.210',
921
+ notify_url,
922
+ })
923
+
924
+ const {
925
+ noncestr,
926
+ package,
927
+ paySign: sign,
928
+ timestamp,
929
+ partnerid,
930
+ prepayid,
931
+ } = result
932
+
933
+ const returnObj = {
934
+ appid,
935
+ partnerid,
936
+ noncestr,
937
+ package,
938
+ prepayid,
939
+ sign,
940
+ timestamp,
941
+ }
942
+
943
+ return ctx.SUCCESS(returnObj)
944
+ }
945
+
865
946
  exports.mp_pay = async (ctx) => {
866
947
  const { app, appName } = getAppByCtx(ctx)
867
948
  const {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "10.7.3",
3
+ "version": "10.7.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -52,7 +52,7 @@
52
52
  "sequelize": "^5.21.3",
53
53
  "static-koa-router": "^1.0.3",
54
54
  "wechat-oauth": "^1.5.0",
55
- "weixin-pay-fork": "^1.0.4",
55
+ "weixin-pay-fork": "^1.0.6",
56
56
  "node-uuid": "^1.4.8",
57
57
  "sha1": "^1.1.1",
58
58
  "redis": "^4.0.3",