q-koa 12.9.3 → 12.9.4

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
@@ -588,24 +588,20 @@ class APP {
588
588
  'page'
589
589
  )
590
590
 
591
- const _id =
592
- belongs === 'setting'
593
- ? {
594
- id: {
595
- type: Sequelize.TINYINT.UNSIGNED,
596
- allowNull: false,
597
- primaryKey: true,
598
- autoIncrement: true,
599
- },
600
- }
601
- : {
602
- id: {
603
- type: Sequelize.MEDIUMINT.UNSIGNED,
604
- allowNull: false,
605
- primaryKey: true,
606
- autoIncrement: true,
607
- },
608
- }
591
+ const idType = _.get(
592
+ this.app[appName].config[folder],
593
+ 'idType',
594
+ belongs === 'setting' ? 'TINYINT' : 'MEDIUMINT'
595
+ )
596
+
597
+ const _id = {
598
+ id: {
599
+ type: Sequelize[idType].UNSIGNED,
600
+ allowNull: false,
601
+ primaryKey: true,
602
+ autoIncrement: true,
603
+ },
604
+ }
609
605
 
610
606
  const attributes = _.defaultsDeep(_.cloneDeep(_attributes), {
611
607
  ..._id,
@@ -793,7 +789,7 @@ class APP {
793
789
  }
794
790
 
795
791
  if (is_dev) {
796
- console.log(moment().valueOf() - start)
792
+ console.log('挂载service bind', moment().valueOf() - start)
797
793
  }
798
794
  }
799
795
 
@@ -959,24 +955,24 @@ class APP {
959
955
  ]
960
956
  for (let i = 0; i < hooksList.length; i++) {
961
957
  if (_.get(app, `${appName}.${hooksList[i]}.${controller}.${fn}`)) {
962
- if (hooksList[i] === 'controller') {
963
- process.once('unhandledRejection', (reason, promise) => {
964
- if (
965
- this.app &&
966
- this.app[appName] &&
967
- this.app[appName].model &&
968
- this.app[appName].model.log
969
- ) {
970
- this.app[appName].model.log.create({
971
- url: ctx.request.href,
972
- body: ctx.request.body,
973
- message: 'promise unhandledRejection',
974
- content: reason.stack,
975
- header: ctx.request.header,
976
- })
977
- }
978
- })
979
- }
958
+ // if (hooksList[i] === 'controller') {
959
+ // process.once('unhandledRejection', (reason, promise) => {
960
+ // if (
961
+ // this.app &&
962
+ // this.app[appName] &&
963
+ // this.app[appName].model &&
964
+ // this.app[appName].model.log
965
+ // ) {
966
+ // this.app[appName].model.log.create({
967
+ // url: ctx.request.href,
968
+ // body: ctx.request.body,
969
+ // message: 'promise unhandledRejection',
970
+ // content: reason.stack,
971
+ // header: ctx.request.header,
972
+ // })
973
+ // }
974
+ // })
975
+ // }
980
976
  await app[appName][hooksList[i]][controller][fn](ctx)
981
977
  }
982
978
  }
@@ -4,7 +4,12 @@ module.exports = {
4
4
  multiple: false,
5
5
  availableSort: false,
6
6
  order: ['created_at'],
7
- select: [{ key: 'user_id' }, { key: 'nick_name' }, { key: 'openid' }],
7
+ select: [
8
+ { key: 'user_id' },
9
+ { key: 'nick_name' },
10
+ { key: 'appid' },
11
+ { key: 'openid' },
12
+ ],
8
13
  excludes: [],
9
14
  limit: 20,
10
15
  defaultOrder: [{ sort: 'descending', type: 'id' }],
@@ -682,6 +682,7 @@ exports.mockPay = async (ctx) => {
682
682
  throw new Error(`没配置${model}支付回调notify`)
683
683
  }
684
684
  await app.service[model].notify({
685
+ ctx,
685
686
  app,
686
687
  order_id,
687
688
  order: model,
@@ -925,9 +925,12 @@ exports.app_pay = async (ctx) => {
925
925
  // }
926
926
  const appConfig = getConfig(app)
927
927
 
928
- const { mchId, key, partner_key, appId: appid } = await appConfig.getObject(
929
- pay_config
930
- )
928
+ const {
929
+ mchId,
930
+ key,
931
+ partner_key,
932
+ appId: appid,
933
+ } = await appConfig.getObject(pay_config)
931
934
 
932
935
  if (!appid) throw new Error(`appId不能存在`)
933
936
 
@@ -72,6 +72,11 @@ const getUserPortraitUrl =
72
72
 
73
73
  const getCommentInfoUrl =
74
74
  'https://api.weixin.qq.com/wxaapi/comment/commentinfo/get?commentId=%s&access_token=%s'
75
+ const createActivityUrl =
76
+ 'https://api.weixin.qq.com/cgi-bin/message/wxopen/activityid/create?access_token=%s'
77
+
78
+ const setUpdatableMsgUrl =
79
+ 'https://api.weixin.qq.com/cgi-bin/message/wxopen/updatablemsg/send?access_token=%s'
75
80
 
76
81
  const fsPromise = require('fs/promises')
77
82
  const LRU = require('lru-cache')
@@ -864,6 +869,75 @@ module.exports = class Singleton {
864
869
  return result
865
870
  }
866
871
 
872
+ async createActivity() {
873
+ const access_token = await this.getAccessToken()
874
+ const url = util.format(createActivityUrl, access_token)
875
+
876
+ const result = await axios.get(url).then((res) => res.data)
877
+ if (result.errcode) {
878
+ if (result.errcode === 40001) {
879
+ cache.reset()
880
+ return await this.createActivity()
881
+ }
882
+ throw new Error(`${result.errcode};${result.errmsg}`)
883
+ }
884
+ return result
885
+ }
886
+
887
+ async setUpdatableMsg(target) {
888
+ const {
889
+ activity_id,
890
+ target_state,
891
+ member_count,
892
+ room_limit,
893
+ version_type,
894
+ path,
895
+ } = target
896
+ const access_token = await this.getAccessToken()
897
+ const url = util.format(setUpdatableMsgUrl, access_token)
898
+ const postData = {
899
+ activity_id,
900
+ target_state,
901
+ template_info: {
902
+ parameter_list: [
903
+ member_count
904
+ ? {
905
+ name: 'member_count',
906
+ value: member_count + '',
907
+ }
908
+ : null,
909
+ room_limit
910
+ ? {
911
+ name: 'room_limit',
912
+ value: room_limit + '',
913
+ }
914
+ : null,
915
+ path
916
+ ? {
917
+ name: 'path',
918
+ value: path + '',
919
+ }
920
+ : null,
921
+ version_type
922
+ ? {
923
+ name: 'version_type',
924
+ value: version_type + '',
925
+ }
926
+ : null,
927
+ ].filter(Boolean),
928
+ },
929
+ }
930
+ const result = await axios.post(url, postData).then((res) => res.data)
931
+ if (result.errcode) {
932
+ if (result.errcode === 40001) {
933
+ cache.reset()
934
+ return await this.setUpdatableMsg(target)
935
+ }
936
+ throw new Error(`${result.errcode};${result.errmsg}`)
937
+ }
938
+ return result
939
+ }
940
+
867
941
  getConfig() {
868
942
  return this.config
869
943
  }
@@ -63,24 +63,26 @@ exports.miResponse = (methods) =>
63
63
  methods,
64
64
  })
65
65
 
66
- exports.miCors = (arr = [], ip = '192.168.0.1') => async (ctx, next) => {
67
- ctx.set('Access-Control-Allow-Origin', `${ctx.header.origin || '*'}`)
68
- ctx.set('Access-Control-Allow-Credentials', true)
69
- // ctx.set('Access-Control-Allow-Headers', '*');
70
- ctx.set(
71
- 'Access-Control-Allow-Headers',
72
- ` Origin, X-Requested-With, Content-Type, client-type, Accept, ${arr
73
- .map((item) => `${item}-token`)
74
- .join(', ')}`
75
- )
76
- ctx.set('server-ip', ip)
77
- ctx.set('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS')
78
- if (ctx.method === 'OPTIONS') {
79
- ctx.body = 200
80
- } else {
81
- await next()
66
+ exports.miCors =
67
+ (arr = [], ip = '192.168.0.1') =>
68
+ async (ctx, next) => {
69
+ ctx.set('Access-Control-Allow-Origin', `${ctx.header.origin || '*'}`)
70
+ ctx.set('Access-Control-Allow-Credentials', true)
71
+ // ctx.set('Access-Control-Allow-Headers', '*');
72
+ ctx.set(
73
+ 'Access-Control-Allow-Headers',
74
+ ` Origin, X-Requested-With, Content-Type, client-type, Accept, ${arr
75
+ .map((item) => `${item}-token`)
76
+ .join(', ')}`
77
+ )
78
+ ctx.set('server-ip', ip)
79
+ ctx.set('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS')
80
+ if (ctx.method === 'OPTIONS') {
81
+ ctx.body = 200
82
+ } else {
83
+ await next()
84
+ }
82
85
  }
83
- }
84
86
 
85
87
  exports.miXmlBody = (config) =>
86
88
  xmlParser({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "12.9.3",
3
+ "version": "12.9.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {