user.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. /* eslint-disable eqeqeq */
  2. 'use strict';
  3. const shopController = require('./shop.js');
  4. const Decimal = require('decimal.js');
  5. // 用户控制器
  6. module.exports = class UserController extends shopController {
  7. // 使用模型
  8. get useModel() {
  9. const that = this;
  10. return that.app.model.Users;
  11. }
  12. /**
  13. * [registerValidate 用户注册验证器]
  14. * @return {[type]} [description]
  15. */
  16. get registerValidate() {
  17. const that = this;
  18. return {
  19. account_name: that.ctx.rules.name('账号')
  20. .required()
  21. .trim()
  22. .notEmpty(),
  23. password: that.ctx.rules.name('密码')
  24. .required()
  25. .trim()
  26. .notEmpty()
  27. .extend((field, value, row) => {
  28. row[field] = that.app.szjcomo.MD5(value);
  29. }),
  30. create_time: that.ctx.rules.default(that.app.szjcomo.date('Y-m-d H:i:s'))
  31. .required(),
  32. };
  33. }
  34. /**
  35. * [wxRegisterAdnLoginValidate 微信登录和注册验证器]
  36. * @return {[type]} [description]
  37. */
  38. get wxRegisterAdnLoginValidate() {
  39. const that = this;
  40. return {
  41. code: that.ctx.rules.name('微信授权code')
  42. .required()
  43. .notEmpty()
  44. .trim(),
  45. };
  46. }
  47. /**
  48. * [loginValidate 用户登录]
  49. * @return {[type]} [description]
  50. */
  51. get loginValidate() {
  52. const that = this;
  53. return {
  54. account_name: that.ctx.rules.name('用户账号')
  55. .required()
  56. .notEmpty()
  57. .trim(),
  58. password: that.ctx.rules.name('登录密码')
  59. .required()
  60. .notEmpty()
  61. .trim()
  62. .extend((field, value, row) => {
  63. row[field] = that.app.szjcomo.MD5(value);
  64. }),
  65. };
  66. }
  67. /**
  68. * 更新用户信息
  69. * @date:2023/10/20
  70. */
  71. get updateValidate() {
  72. const that = this;
  73. return {
  74. user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
  75. .number(),
  76. };
  77. }
  78. /**
  79. * [wxuserValidate 微信用户写入]
  80. * @return {[type]} [description]
  81. */
  82. get wxuserValidate() {
  83. const that = this;
  84. return {
  85. nickname: that.ctx.rules.name('用户昵称')
  86. .required()
  87. .notEmpty()
  88. .trim(),
  89. openid: that.ctx.rules.name('openid')
  90. .required()
  91. .notEmpty()
  92. .trim(),
  93. password: that.ctx.rules.default(that.app.szjcomo.MD5('123456'))
  94. .required(),
  95. account_name: that.ctx.rules.default(`${that.app.szjcomo.str_rand(6)}${that.app.szjcomo.date('His')}`)
  96. .required(),
  97. money: that.ctx.rules.default(0)
  98. .number(),
  99. intergral: that.ctx.rules.default(0)
  100. .number(),
  101. headimgurl: that.ctx.rules.default('')
  102. .required(),
  103. login_time: that.ctx.rules.default(that.app.szjcomo.date('Y-m-d H:i:s'))
  104. .required(),
  105. city: that.ctx.rules.default('')
  106. .required(),
  107. province: that.ctx.rules.default('')
  108. .required(),
  109. country: that.ctx.rules.default('')
  110. .required(),
  111. sex: that.ctx.rules.default(0)
  112. .number(),
  113. subscribe: that.ctx.rules.default(0)
  114. .number(),
  115. unionid: that.ctx.rules.default('')
  116. .required(),
  117. create_time: that.ctx.rules.default(that.app.szjcomo.date('Y-m-d H:i:s'))
  118. .required(),
  119. };
  120. }
  121. /**
  122. * [wxloginURLValidate 获取微信登录地址]
  123. * @return {[type]} [description]
  124. */
  125. get wxloginURLValidate() {
  126. const that = this;
  127. return {
  128. page_uri: that.ctx.rules.name('当前地址')
  129. .required()
  130. .notEmpty()
  131. .trim(),
  132. };
  133. }
  134. /**
  135. * [userMoneyValidate 获取用户余额]
  136. * @return {[type]} [description]
  137. */
  138. get userMoneyValidate() {
  139. const that = this;
  140. return {
  141. user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
  142. .number(),
  143. page: that.ctx.rules.default(1)
  144. .number(),
  145. limit: that.ctx.rules.default(50)
  146. .number(),
  147. };
  148. }
  149. get luckyValidate() {
  150. const that = this;
  151. return {
  152. user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
  153. .number(),
  154. };
  155. }
  156. get userTransferValidate() {
  157. const that = this;
  158. return {
  159. user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
  160. .number(),
  161. diningCoinCode: that.ctx.rules.default('')
  162. .required(),
  163. page: that.ctx.rules.default(1)
  164. .number(),
  165. limit: that.ctx.rules.default(50)
  166. .number(),
  167. };
  168. }
  169. get businessCashCoinValidate() {
  170. const that = this;
  171. return {
  172. user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
  173. .number(),
  174. };
  175. }
  176. // 2023/1/13 提现验证器
  177. get cashOutValidate() {
  178. const that = this;
  179. return {
  180. user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
  181. .number(),
  182. cash_amount: that.ctx.rules.name('提现金额')
  183. .required()
  184. .notEmpty()
  185. .number(),
  186. remark: that.ctx.rules.name('备注说明')
  187. .default('')
  188. .trim(),
  189. };
  190. }
  191. // 2023/2/28 餐币核销验证
  192. get coinTransferValidate() {
  193. const that = this;
  194. return {
  195. user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
  196. .number(),
  197. coinAmount: that.ctx.rules.name('核销收取餐币')
  198. .required()
  199. .notEmpty()
  200. .number(),
  201. time: that.ctx.rules.name('餐币二维码刷新时间')
  202. .required()
  203. .notEmpty()
  204. .number(),
  205. diningCoinCode: that.ctx.rules.name('餐币二维码特征')
  206. .required()
  207. .notEmpty(),
  208. };
  209. }
  210. /**
  211. * [login 用户登录 - 账号密码]
  212. * @return {[type]} [description]
  213. */
  214. async login() {
  215. const that = this;
  216. try {
  217. const data = await that.ctx.validate(that.loginValidate, await that.ctx.postParse());
  218. const user = await that.useModel.findOne({
  219. where: { account_name: data.account_name, password: data.password },
  220. // include: [
  221. // { model: that.app.model.ProxyApplyLogs, as: 'proxyApplyLogs', attributes: [ 'verify_status' ] },
  222. // ],
  223. attributes: [ 'user_id', 'account_name', 'nickname', 'headimgurl', 'openid', 'intergral', 'is_proxy', 'partner_id', 'is_office', 'is_family', 'lucky_time' ],
  224. raw: true,
  225. });
  226. if (!user) throw new Error('登录失败,请检查账号密码是否正确');
  227. user.isNew = false;
  228. const result = await that.loginHandle(user);
  229. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  230. } catch (err) {
  231. console.log(err);
  232. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  233. }
  234. }
  235. /**
  236. * [loginHandle 登录处理]
  237. * @param {Object} user [description]
  238. * @return {[type]} [description]
  239. */
  240. async loginHandle(user = {}) {
  241. const that = this;
  242. const token = that.app.jwt.sign(user, that.app.config.jwt.secret, { expiresIn: '24h' });
  243. const result = { token, user };
  244. return result;
  245. }
  246. /**
  247. * [register 用户注册]
  248. * @return {[type]} [description]
  249. */
  250. async register() {
  251. const that = this;
  252. try {
  253. const data = await that.ctx.validate(that.registerValidate, await that.ctx.postParse());
  254. const createBean = that.app.comoBean.instance(data, {});
  255. const result = await that.service.manager.create(createBean, that.useModel, '注册失败,请稍候重试');
  256. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  257. } catch (err) {
  258. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  259. }
  260. }
  261. /**
  262. * [wxRegisterAdnLogin 用户登录 - 微信注册登录]
  263. * @return {[type]} [description]
  264. */
  265. async wxRegisterAdnLogin() {
  266. const that = this;
  267. try {
  268. const appid = await that.service.configs.getConfigValue('wechat_account_appid');
  269. const secret = await that.service.configs.getConfigValue('wechat_account_secret');
  270. const data = await that.ctx.validate(that.wxRegisterAdnLoginValidate, await that.ctx.getParse());
  271. const result = await that.service.wechat.authLogin(appid, secret, data.code);
  272. if (result.errcode) throw new Error(`微信通讯失败,错误信息:${result.errmsg}`);
  273. const userInfo = await that.service.wechat.authUserInfo(result);
  274. const user = await that.wxRegisterAdnLoginHandle(userInfo, data.inviteCode);
  275. const loginRes = await that.loginHandle(user);
  276. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', loginRes, false));
  277. } catch (err) {
  278. await that.logs('user.js', err);
  279. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  280. }
  281. }
  282. /**
  283. * [wxloginURL 微信登录地址]
  284. * @return {[type]} [description]
  285. */
  286. async wxloginURL() {
  287. const that = this;
  288. try {
  289. const data = await that.ctx.validate(that.wxloginURLValidate, await that.ctx.postParse());
  290. const appid = await that.service.configs.getConfigValue('wechat_account_appid');
  291. const curarr = data.page_uri.split('#');
  292. const result = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(curarr[0] + '#/shop/wxauth')}&response_type=code&scope=snsapi_userinfo&state=${that.app.szjcomo.base64_encode(data.page_uri)}#wechat_redirect`;
  293. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  294. } catch (err) {
  295. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  296. }
  297. }
  298. /**
  299. * [wxRegisterAdnLoginHandle 注册并登录]
  300. * @param {Object} userInfo [description]
  301. * @param {Number} inviteCode
  302. * @return {[type]} [description]
  303. */
  304. async wxRegisterAdnLoginHandle(userInfo = {}, inviteCode = -1) {
  305. const that = this;
  306. const inviter_id = inviteCode;
  307. // console.log('==========inviteCode========== : ' + inviter_id);
  308. const options = {
  309. where: { openid: userInfo.openid },
  310. attributes: [ 'user_id', 'account_name', 'nickname', 'headimgurl', 'openid', 'partner_id', 'is_office', 'is_family', 'lucky_time' ],
  311. raw: true,
  312. };
  313. let user = await that.useModel.findOne(options);
  314. if (!user) {
  315. // 2022/9/27 新用户注册 写入信息
  316. user = await that.writeWxUser(userInfo);
  317. user.isNew = true;
  318. // 2022/9/27: 新用户红包奖励8.8元
  319. await that.service.shop.userMoneyAdd(user.user_id, 8.8, null, '新用户注册奖励', 0, 1, -1);
  320. // 2022/9/29 受邀注册奖励 和 邀请新用户奖励
  321. if (inviter_id > 0) {
  322. try {
  323. const inviterInfo = await that.useModel.findOne({
  324. where: { user_id: inviter_id },
  325. attributes: [ 'user_id', 'nickname', 'headimgurl' ],
  326. raw: true,
  327. });
  328. await that.service.shop.userMoneyAdd(user.user_id, 1.68, null, '受邀注册奖励', 0, 2, inviter_id, inviterInfo.nickname, inviterInfo.headimgurl);
  329. await that.service.shop.userMoneyAdd(inviter_id, 1.68, null, '邀请新用户奖励', 0, 3, user.user_id, user.nickname, user.headimgurl);
  330. // 2022/11/17 邀请关系绑定
  331. await that.service.inviter.addRelUserInviter(user.user_id, inviter_id);
  332. } catch (e) {
  333. // 邀请人id不存在
  334. }
  335. }
  336. } else {
  337. user.isNew = false;
  338. // 2023/8/25 更新登录时间
  339. const updateBean = await that.app.comoBean.instance({
  340. login_time: that.app.szjcomo.date('Y-m-d H:i:s'),
  341. update_ttime: that.app.szjcomo.date('Y-m-d H:i:s'),
  342. unionid: userInfo.unionid,
  343. }, { where: { user_id: user.user_id } });
  344. await that.service.base.update(updateBean, that.useModel, '微信用户登录时间更新失败,请重试');
  345. }
  346. return user;
  347. }
  348. /**
  349. * [writeWxUser 写入微信用户]
  350. * @param {Object} userInfo [description]
  351. * @return {[type]} [description]
  352. */
  353. async writeWxUser(userInfo = {}) {
  354. const that = this;
  355. const data = await that.ctx.validate(that.wxuserValidate, userInfo);
  356. const createBean = await that.app.comoBean.instance(data);
  357. const result = await that.service.base.create(createBean, that.useModel, '添加微信用户失败,请重试');
  358. return {
  359. user_id: result.dataValues.user_id,
  360. account_name: result.dataValues.account_name,
  361. nickname: result.dataValues.nickname,
  362. headimgurl: result.dataValues.headimgurl,
  363. openid: result.dataValues.openid,
  364. unionid: result.dataValues.unionid,
  365. is_office: result.dataValues.is_office,
  366. is_family: result.dataValues.is_family,
  367. };
  368. }
  369. /**
  370. * [userMoney 获取用户余额]
  371. * @return {[type]} [description]
  372. */
  373. async userMoney() {
  374. const that = this;
  375. try {
  376. const data = await that.ctx.validate(that.userMoneyValidate, await that.ctx.getParse());
  377. const result = await that.service.shop.getUserMoney(data.user_id);
  378. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  379. } catch (err) {
  380. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  381. }
  382. }
  383. /**
  384. * [userMoney 获取用户账户余额]
  385. * @return {[type]} [description]
  386. */
  387. async userAccount() {
  388. const that = this;
  389. try {
  390. const data = await that.ctx.validate(that.userMoneyValidate, await that.ctx.getParse());
  391. const result = await that.service.shop.getUserAccount(data.user_id);
  392. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  393. } catch (err) {
  394. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  395. }
  396. }
  397. /**
  398. * [userMoneyLog 用户资金明细]
  399. * @return {[type]} [description]
  400. */
  401. async userMoneyLog() {
  402. const that = this;
  403. try {
  404. const data = await that.ctx.validate(that.userMoneyValidate, await that.ctx.getParse());
  405. const selectBean = await that.app.comoBean.instance(data, {
  406. offset: (data.page - 1) * data.limit,
  407. limit: data.limit,
  408. where: { user_id: data.user_id },
  409. order: [ [ 'log_id', 'desc' ] ],
  410. attributes: [ 'log_id', 'log_desc', 'change_time', 'money', 'type', 'inviter_id', 'inviter_name', 'inviter_img' ],
  411. });
  412. const result = await that.service.base.select(selectBean, that.app.model.UsersMoneyLogs, '查询资金明细失败,请稍候重试', true, true);
  413. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  414. } catch (err) {
  415. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  416. }
  417. }
  418. /**
  419. * [userMoneyLog 用户分佣明细]
  420. * @return {[type]} [description]
  421. */
  422. async userCommissionLog() {
  423. const that = this;
  424. const seq = that.app.Sequelize;
  425. try {
  426. const data = await that.ctx.validate(that.userMoneyValidate, await that.ctx.getParse());
  427. const selectBean = await that.app.comoBean.instance(data, {
  428. // offset: (data.page - 1) * data.limit, limit: data.limit,
  429. where: { user_id: data.user_id },
  430. order: [ [ 'log_id', 'desc' ] ],
  431. include: [ {
  432. model: that.app.model.Orders,
  433. where: { order_status: { [seq.Op.in]: [ 1, 2, 3, 4 ] } },
  434. attributes: [ 'order_id', 'order_status', 'order_amount', ],
  435. as: 'order'
  436. } ],
  437. attributes: [ 'log_desc', 'create_time', 'commission', 'type', 'inviter_id', 'inviter_name', 'inviter_img' ],
  438. });
  439. // 2022/11/28 直接查询所有数据 不分页
  440. const result = await that.service.base.select(selectBean, that.app.model.UsersCommissionLogs, '查询分佣明细失败,请稍候重试', false, true);
  441. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  442. } catch (err) {
  443. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  444. }
  445. }
  446. /**
  447. * [userMoneyLog 用户餐币明细]
  448. * @return {[type]} [description]
  449. */
  450. async coinDetail() {
  451. const that = this;
  452. try {
  453. const data = await that.ctx.validate(that.userMoneyValidate, await that.ctx.getParse());
  454. const selectBean = await that.app.comoBean.instance(data, {
  455. where: { user_id: data.user_id },
  456. order: [ [ 'log_id', 'desc' ] ],
  457. });
  458. // 2022/11/28 直接查询所有数据 不分页
  459. const result = await that.service.base.select(selectBean, that.app.model.DinnerCoinLogs, '查询分佣明细失败,请稍候重试', false, true);
  460. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  461. } catch (err) {
  462. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  463. }
  464. }
  465. // 2023/2/28 用户餐饮币账户列表
  466. async userDiningCoin() {
  467. const that = this;
  468. try {
  469. const data = await that.ctx.validate(that.userMoneyValidate, await that.ctx.getParse());
  470. const selectBean = await that.app.comoBean.instance(data, {
  471. where: { user_id: data.user_id, expired: false },
  472. });
  473. // 2023/2/28 直接查询所有数据 不分页
  474. const result = await that.service.base.select(selectBean, that.app.model.DinnerCoins, '查询餐饮币账户失败,请稍候重试', false, true);
  475. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  476. } catch (err) {
  477. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  478. }
  479. }
  480. /**
  481. * 用户指定商家餐币账户余额
  482. * @return {Promise<*>}
  483. */
  484. async userCouldTransferCoin() {
  485. const that = this;
  486. try {
  487. const data = await that.ctx.validate(that.userTransferValidate, await that.ctx.getParse());
  488. const res = await that.getCouldTransferCoin(data);
  489. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', { couldTransferCoins: res.account }, false));
  490. } catch (err) {
  491. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  492. }
  493. }
  494. /**
  495. * 用户可在指定商家消费的餐币账户余额
  496. * @param data
  497. */
  498. async getCouldTransferCoin(data) {
  499. const that = this;
  500. if (!data.diningCoinCode) {
  501. throw new Error('参数错误');
  502. }
  503. const userInfo = await that.app.model.Users.findOne({
  504. where: { openid: data.diningCoinCode },
  505. attributes: [ 'user_id' ],
  506. });
  507. if (!userInfo || userInfo.user_id < 0) {
  508. throw new Error('参数错误');
  509. }
  510. const businessInfo = await that.app.model.Users.findOne({
  511. where: { user_id: data.user_id },
  512. attributes: [ 'partner_id' ],
  513. });
  514. if (!businessInfo || businessInfo.partner_id < 1) {
  515. throw new Error('抱歉,您不是源森家具的合作商户,无权收款。');
  516. }
  517. const seq = that.app.Sequelize;
  518. const selectBean = await that.app.comoBean.instance({}, {
  519. where: {
  520. user_id: userInfo.user_id,
  521. // partner_id: businessInfo.partner_id,
  522. // 2023/4/11 补充通用餐币
  523. partner_id: { [seq.Op.in]: [ businessInfo.partner_id, 1 ] },
  524. expired: false,
  525. },
  526. attributes: [ [ seq.fn('sum', seq.col('account')), 'account' ] ],
  527. });
  528. const result = await that.service.base.select(selectBean, that.app.model.DinnerCoins, '查询餐饮币账户余额失败,请稍候重试', false, false);
  529. const res = JSON.parse(JSON.stringify(result));
  530. res.customer_id = userInfo.user_id;
  531. res.partner_id = businessInfo.partner_id;
  532. res.business_id = data.user_id;
  533. return res;
  534. }
  535. /**
  536. * 商家可提现餐币金额
  537. * @return {Promise<*>}
  538. */
  539. async businessDiningCoinCouldCash() {
  540. const that = this;
  541. try {
  542. const data = await that.ctx.validate(that.businessCashCoinValidate, await that.ctx.getParse());
  543. const res = await that.getDiningCoinCouldCash(data);
  544. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', res, false));
  545. } catch (err) {
  546. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  547. }
  548. }
  549. /**
  550. * 商家可提现餐币金额
  551. * @param data
  552. */
  553. async getDiningCoinCouldCash(data) {
  554. const that = this;
  555. const businessInfo = await that.app.model.Users.findOne({
  556. where: { user_id: data.user_id },
  557. });
  558. if (!businessInfo || businessInfo.partner_id < 0) {
  559. throw new Error('您的账号还没有绑定的合作商铺哦');
  560. }
  561. const partnerInfo = await that.app.model.PartnerInfo.findOne({
  562. where: { id: businessInfo.partner_id },
  563. });
  564. if (!partnerInfo || partnerInfo.user_id !== data.user_id) {
  565. throw new Error('您的账号没有权限提现餐费哦');
  566. }
  567. const seq = that.app.Sequelize;
  568. const currentDateTime = that.app.szjcomo.date('Y-m-d H:i:s');
  569. const sevenDayTime = 24 * 60 * 60 * 1000; // 2023/3/1 24小时后可提现
  570. const endTimeStamp = Date.parse(currentDateTime) - sevenDayTime;
  571. const endDateTime = that.app.szjcomo.date('Y-m-d H:i:s', endTimeStamp / 1000);
  572. // 2023/3/1 查询24小时前的所得餐币总和 以及所有时间提现的总和 再求和 即为 可提现餐币金额
  573. // todo : 特殊情况 商家管理员有自家绑定的商铺 餐币消费支出
  574. const selectBean = await that.app.comoBean.instance({}, {
  575. where: {
  576. user_id: businessInfo.user_id,
  577. partner_id: businessInfo.partner_id,
  578. create_time: { [seq.Op.lte]: endDateTime },
  579. account: { [seq.Op.gte]: 0 },
  580. },
  581. attributes: [ [ seq.fn('sum', seq.col('account')), 'account' ] ],
  582. });
  583. const coinResult = await that.service.base.select(selectBean, that.app.model.DinnerCoinLogs, '查询商家可提现餐币金额失败,请稍候重试', false, false);
  584. const selectBean2 = await that.app.comoBean.instance({}, {
  585. where: {
  586. user_id: businessInfo.user_id,
  587. partner_id: businessInfo.partner_id,
  588. account: { [seq.Op.lte]: 0 },
  589. type: { [seq.Op.ne]: -1 },
  590. },
  591. attributes: [ [ seq.fn('sum', seq.col('account')), 'account' ] ],
  592. });
  593. const cashResult = await that.service.base.select(selectBean2, that.app.model.DinnerCoinLogs, '查询商家可提现餐币金额失败,请稍候重试', false, false);
  594. const coinRes = JSON.parse(JSON.stringify(coinResult));
  595. const cashRes = JSON.parse(JSON.stringify(cashResult));
  596. const couldCash = new Decimal(coinRes.account ? coinRes.account : 0)
  597. .add(new Decimal(cashRes.account ? cashRes.account : 0))
  598. .toNumber();
  599. coinRes.all_coin_could_cash = couldCash > 0 ? couldCash : 0;
  600. coinRes.all_cash = cashRes.account;
  601. coinRes.partner_id = businessInfo.partner_id;
  602. coinRes.partner_fees = partnerInfo.partner_fees;
  603. return coinRes;
  604. }
  605. /**
  606. * 商家申请核销餐币
  607. * @return {Promise<void>}
  608. */
  609. async coinTransfer() {
  610. const that = this;
  611. const seq = that.app.Sequelize;
  612. const transaction = await that.app.model.transaction();
  613. try {
  614. const data = await that.ctx.validate(that.coinTransferValidate, await that.ctx.postParse());
  615. // 2023/2/28 获取可核销餐币
  616. const intervalTime = Date.parse(that.app.szjcomo.date('Y-m-d H:i:s')) - data.time;
  617. if (intervalTime > 10 * 60 * 1000) {
  618. throw new Error('顾客付款码已超时失效,请重新扫码!');
  619. }
  620. const transferParams = await that.getCouldTransferCoin(data);
  621. if (data.coinAmount > 0 && data.coinAmount <= transferParams.account) {
  622. // 2023/2/28 发起核销收取餐币
  623. const partnerInfo = await that.app.model.PartnerInfo.findOne({
  624. where: { id: transferParams.partner_id },
  625. });
  626. // 2023/4/12 核销餐币 包含通用电子餐币
  627. const selectBean = await that.app.comoBean.instance({}, {
  628. where: {
  629. user_id: transferParams.customer_id,
  630. // partner_id: transferParams.partner_id,
  631. partner_id: { [seq.Op.in]: [ transferParams.partner_id, 1 ] },
  632. expired: false,
  633. },
  634. order: [ [ 'partner_id', 'desc' ], [ 'ori_partner', 'desc' ] ],
  635. });
  636. // 2023/2/28 查询所有指定商家餐币
  637. const result = await that.service.base.select(selectBean, that.app.model.DinnerCoins, '查询餐饮币账户失败,请稍候重试', false, true);
  638. const customerAccounts = [];
  639. let needAccount = 0;
  640. for (const resultElement of result) {
  641. needAccount += resultElement.account;
  642. customerAccounts.push(JSON.parse(JSON.stringify(resultElement)));
  643. if (needAccount >= data.coinAmount) {
  644. break;
  645. }
  646. }
  647. let firstCoinAmount;
  648. let secondCoinAmount;
  649. let thirdCoinAmount;
  650. let fourthCoinAmount;
  651. let incomeCoinAmount = 0;
  652. switch (customerAccounts.length) {
  653. case 1:
  654. firstCoinAmount = data.coinAmount;
  655. secondCoinAmount = 0;
  656. thirdCoinAmount = 0;
  657. fourthCoinAmount = 0;
  658. break;
  659. case 2:
  660. firstCoinAmount = customerAccounts[0].account;
  661. secondCoinAmount = data.coinAmount - firstCoinAmount;
  662. thirdCoinAmount = 0;
  663. fourthCoinAmount = 0;
  664. break;
  665. case 3:
  666. firstCoinAmount = customerAccounts[0].account;
  667. secondCoinAmount = customerAccounts[1].account;
  668. thirdCoinAmount = data.coinAmount - firstCoinAmount - secondCoinAmount;
  669. fourthCoinAmount = 0;
  670. break;
  671. case 4:
  672. firstCoinAmount = customerAccounts[0].account;
  673. secondCoinAmount = customerAccounts[1].account;
  674. thirdCoinAmount = customerAccounts[2].account;
  675. fourthCoinAmount = data.coinAmount - firstCoinAmount - secondCoinAmount - thirdCoinAmount;
  676. break;
  677. default:
  678. break;
  679. }
  680. // =========================================== 2023/3/1 第一个账户划账======================================
  681. await that.doTransferCoins(that, transferParams, firstCoinAmount, partnerInfo, transaction, customerAccounts, 0);
  682. incomeCoinAmount += firstCoinAmount * (customerAccounts[0].ori_partner ? partnerInfo.rate_from_partner : partnerInfo.rate_default);
  683. // =============================== 2023/3/1 需要第二个账户来继续划账 ==========================================
  684. if (customerAccounts.length > 1 && secondCoinAmount > 0) {
  685. await that.doTransferCoins(that, transferParams, secondCoinAmount, partnerInfo, transaction, customerAccounts, 1);
  686. incomeCoinAmount += secondCoinAmount * (customerAccounts[1].ori_partner ? partnerInfo.rate_from_partner : partnerInfo.rate_default);
  687. }
  688. // =============================== 2023/3/18 需要第三个账户来继续划账 ==========================================
  689. if (customerAccounts.length > 2 && thirdCoinAmount > 0) {
  690. await that.doTransferCoins(that, transferParams, thirdCoinAmount, partnerInfo, transaction, customerAccounts, 2);
  691. incomeCoinAmount += thirdCoinAmount * (customerAccounts[2].ori_partner ? partnerInfo.rate_from_partner : partnerInfo.rate_default);
  692. }
  693. // =============================== 2023/3/18 需要第四个账户来继续划账 ==========================================
  694. if (customerAccounts.length > 3 && fourthCoinAmount > 0) {
  695. await that.doTransferCoins(that, transferParams, fourthCoinAmount, partnerInfo, transaction, customerAccounts, 3);
  696. incomeCoinAmount += fourthCoinAmount * (customerAccounts[3].ori_partner ? partnerInfo.rate_from_partner : partnerInfo.rate_default);
  697. }
  698. await transaction.commit();
  699. incomeCoinAmount = incomeCoinAmount.toFixed(2);
  700. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', {
  701. incomeCoinAmount,
  702. transferCoinAmount: data.coinAmount,
  703. }, false));
  704. }
  705. throw new Error('输入的核销金额有误,请稍后重试');
  706. } catch (e) {
  707. if (transaction) transaction.rollback();
  708. return that.ctx.appJson(that.app.szjcomo.appResult(e.message));
  709. }
  710. }
  711. // 2023/3/1 餐币划账 具体逻辑和操作
  712. async doTransferCoins(that, transferParams, coinAmount, partnerInfo, transaction, customerAccounts, index) {
  713. // 2023/3/6 获取顾客信息
  714. const customerInfo = await that.app.model.Users.findOne({
  715. where: { user_id: transferParams.customer_id },
  716. transaction,
  717. raw: true,
  718. });
  719. // 2023/3/1 扣去顾客餐币
  720. await that.service.diningCoin.addDiningCoinChangeLog({
  721. user_id: transferParams.customer_id,
  722. order_id: -1,
  723. partner_id: customerAccounts[index].partner_id,
  724. type: 3,
  725. account: -coinAmount,
  726. log_desc: partnerInfo.name + ' 消费',
  727. }, transaction);
  728. // 2023/3/1 更新顾客账户
  729. const customerAccountBean = await that.app.comoBean.instance({
  730. account: customerAccounts[index].account - coinAmount,
  731. update_time: that.app.szjcomo.date('Y-m-d H:i:s'),
  732. }, {
  733. where: {
  734. user_id: transferParams.customer_id,
  735. ori_partner: customerAccounts[index].ori_partner,
  736. partner_id: customerAccounts[index].partner_id,
  737. expired: false,
  738. }, transaction,
  739. });
  740. if (customerAccounts[index].account === coinAmount) {
  741. // 2023/3/1 删除0元账户
  742. await that.service.base.delete(customerAccountBean, that.app.model.DinnerCoins, '顾客餐饮币清零更新失败,请重试');
  743. } else {
  744. await that.service.base.update(customerAccountBean, that.app.model.DinnerCoins, '顾客餐饮币余额更新失败,请重试');
  745. }
  746. // 2023/3/1 划入商家账户记录
  747. const businessCoinAmount = coinAmount * (customerAccounts[index].ori_partner ? partnerInfo.rate_from_partner : partnerInfo.rate_default);
  748. await that.service.diningCoin.addDiningCoinChangeLog({
  749. user_id: transferParams.business_id,
  750. order_id: -1,
  751. partner_id: transferParams.partner_id,
  752. type: 4,
  753. account: businessCoinAmount,
  754. log_desc: '核销收取餐币',
  755. ori_partner: customerAccounts[index].ori_partner,
  756. customer_id: customerInfo.user_id,
  757. customer_name: customerInfo.nickname,
  758. customer_img: customerInfo.headimgurl,
  759. }, transaction);
  760. // 2023/2/28 查询商家餐饮币账户列表 添加 或 更新账户余额
  761. const info = await that.app.model.DinnerCoins.findOne({
  762. where: {
  763. user_id: transferParams.business_id,
  764. // ori_partner: customerAccounts[index].ori_partner,
  765. partner_id: transferParams.partner_id,
  766. expired: false,
  767. },
  768. transaction,
  769. raw: true,
  770. });
  771. if (!info) {
  772. // 2023/2/27 没有对应类型的餐饮币 则插入该类型的餐饮币账户
  773. const createData = {
  774. user_id: transferParams.business_id,
  775. account: businessCoinAmount,
  776. // ori_partner: customerAccounts[index].ori_partner,
  777. ori_partner: true,
  778. partner_id: transferParams.partner_id,
  779. create_time: that.app.szjcomo.date('Y-m-d H:i:s'),
  780. expired: false,
  781. expired_time: that.app.szjcomo.date('Y-m-d H:i:s', parseInt(+new Date() + '') / 1000 + 90 * 24 * 60 * 60),
  782. };
  783. createData.partner_name = partnerInfo.name;
  784. createData.partner_address = partnerInfo.address;
  785. createData.partner_tel = partnerInfo.tel_num;
  786. createData.partner_opening_time = partnerInfo.opening_time;
  787. const createBean = await that.app.comoBean.instance(createData, { transaction });
  788. await that.service.base.create(createBean, that.app.model.DinnerCoins, '餐饮币发放失败,请重试');
  789. } else {
  790. const updateBean = await that.app.comoBean.instance({
  791. account: info.account + businessCoinAmount,
  792. update_time: that.app.szjcomo.date('Y-m-d H:i:s'),
  793. expired: false,
  794. expired_time: that.app.szjcomo.date('Y-m-d H:i:s', parseInt(+new Date() + '') / 1000 + 90 * 24 * 60 * 60),
  795. }, {
  796. where: {
  797. user_id: transferParams.business_id,
  798. // ori_partner: customerAccounts[index].ori_partner,
  799. partner_id: transferParams.partner_id,
  800. }, transaction,
  801. });
  802. await that.service.base.update(updateBean, that.app.model.DinnerCoins, '餐饮币余额更新失败,请重试');
  803. }
  804. }
  805. /**
  806. * 用户可提现金额(求和)
  807. * @return {Promise<*>}
  808. */
  809. async userCommissionCouldCash() {
  810. const that = this;
  811. try {
  812. const data = await that.ctx.validate(that.userMoneyValidate, await that.ctx.getParse());
  813. const result = await that.getCouldCashCommission(data.user_id);
  814. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  815. } catch (err) {
  816. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  817. }
  818. }
  819. /**
  820. * 获取用户可提现金额(求和)
  821. * @return {Promise<void>}
  822. */
  823. async getCouldCashCommission(user_id = -1) {
  824. if (user_id <= 0) {
  825. throw new Error('参数错误');
  826. }
  827. const that = this;
  828. const seq = that.app.Sequelize;
  829. // 2024/2/26 所有分佣金额
  830. const selectBean = await that.app.comoBean.instance({ user_id }, {
  831. where: { user_id, commission: { [seq.Op.gte]: 0 } },
  832. include: [ {
  833. model: that.app.model.Orders,
  834. where: { order_status: { [seq.Op.in]: [ 1, 2, 3, 4 ] } },
  835. attributes: [ 'order_id', 'order_status', 'order_amount', ],
  836. as: 'order'
  837. } ],
  838. attributes: [ 'user_id', [ seq.fn('sum', seq.col('commission')), 'all_commission' ] ],
  839. });
  840. const allCommissionResult = await that.service.base.select(selectBean, that.app.model.UsersCommissionLogs, '查询佣金失败,请稍候重试', false, false);
  841. // 2024/2/26 订单完成可提现金额
  842. const selectBean3 = await that.app.comoBean.instance({ user_id }, {
  843. where: { user_id, commission: { [seq.Op.gte]: 0 } },
  844. include: [ {
  845. model: that.app.model.Orders,
  846. where: { order_status: { [seq.Op.in]: [ 3, 4 ] } },
  847. attributes: [ 'order_id', 'order_status', 'order_amount', ],
  848. as: 'order'
  849. } ],
  850. attributes: [ 'user_id', [ seq.fn('sum', seq.col('commission')), 'order_done_commission' ] ],
  851. });
  852. const orderCommissionResult = await that.service.base.select(selectBean3, that.app.model.UsersCommissionLogs, '查询佣金失败,请稍候重试', false, false);
  853. // 2024/2/26 已提现金额
  854. const selectBean2 = await that.app.comoBean.instance({ user_id }, {
  855. where: { user_id, commission: { [seq.Op.lte]: 0 }, type: { [seq.Op.ne]: -1 } }, // type-1提现失败类型
  856. attributes: [ 'user_id', [ seq.fn('sum', seq.col('commission')), 'all_cash' ] ],
  857. });
  858. const cashResult = await that.service.base.select(selectBean2, that.app.model.UsersCommissionLogs, '查询佣金失败,请稍候重试', false, false);
  859. const allCommRes = JSON.parse(JSON.stringify(allCommissionResult));
  860. const orderCommRes = JSON.parse(JSON.stringify(orderCommissionResult));
  861. const cashRes = JSON.parse(JSON.stringify(cashResult));
  862. // 2024/2/26 待提现分佣金额
  863. cashRes.all_commission_tobe_cash = new Decimal(allCommRes.all_commission ? allCommRes.all_commission : 0)
  864. .add(new Decimal(cashRes.all_cash ? cashRes.all_cash : 0))
  865. .toNumber();
  866. // 2024/2/26 可提现分佣金额
  867. cashRes.all_commission_could_cash = new Decimal(orderCommRes.order_done_commission ? orderCommRes.order_done_commission : 0)
  868. .add(new Decimal(cashRes.all_cash ? cashRes.all_cash : 0))
  869. .toNumber();
  870. cashRes.all_commission = allCommRes.all_commission;
  871. // 2024/2/26 待订单确认收货分佣
  872. cashRes.all_commission_order_not_done = new Decimal(allCommRes.all_commission ? allCommRes.all_commission : 0)
  873. .add(new Decimal(cashRes.all_cash ? cashRes.all_cash : 0))
  874. .sub(cashRes.all_commission_could_cash)
  875. .toNumber();
  876. return cashRes;
  877. }
  878. /**
  879. * 用户佣金提现
  880. * @return {Promise<void>}
  881. */
  882. async userCashOut() {
  883. const that = this;
  884. try {
  885. const data = await that.ctx.validate(that.cashOutValidate, await that.ctx.postParse());
  886. // 2023/1/17 获取可提现佣金额度
  887. const res = await that.getCouldCashCommission(data.user_id);
  888. if (data.cash_amount >= 0.1 && data.cash_amount <= res.all_commission_could_cash) {
  889. // 2023/1/31 发起提现
  890. const result = await that.service.wxPay.transfer(data);
  891. // 2023/1/31 提现状态
  892. if (result.status != 200) {
  893. throw new Error('提现转账出现异常,请联系客服后再重试');
  894. }
  895. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  896. }
  897. throw new Error('输入提现金额有误,请稍后重试');
  898. } catch (e) {
  899. return that.ctx.appJson(that.app.szjcomo.appResult(e.message));
  900. }
  901. }
  902. /**
  903. * 用户佣金转电子餐费
  904. * @return {Promise<void>}
  905. */
  906. async commission2DiningCoin() {
  907. // 2023/11/17 todo: 佣金转电子餐费
  908. }
  909. /**
  910. * 商家餐币提现
  911. * @return {Promise<*>}
  912. */
  913. async userCoinCashOut() {
  914. const that = this;
  915. try {
  916. const data = await that.ctx.validate(that.cashOutValidate, await that.ctx.postParse());
  917. // 2023/1/17 获取可提现佣金额度
  918. const res = await that.getDiningCoinCouldCash(data);
  919. data.partner_id = res.partner_id;
  920. if (data.cash_amount >= 0.1 && data.cash_amount <= (res.all_coin_could_cash - res.partner_fees)) {
  921. // 2023/1/31 发起提现
  922. const result = await that.service.businessPayService.transfer(data);
  923. // 2023/1/31 提现状态
  924. if (result.status != 200) {
  925. throw new Error('提现转账出现异常,请联系客服后再重试');
  926. }
  927. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  928. }
  929. throw new Error('输入提现金额有误,请稍后重试');
  930. } catch (e) {
  931. return that.ctx.appJson(that.app.szjcomo.appResult(e.message));
  932. }
  933. }
  934. /**
  935. * [newUserBenefits 查询新用户福利]
  936. * @return {[type]} [description]
  937. */
  938. async newUserBenefits() {
  939. const that = this;
  940. try {
  941. const data = await that.ctx.validate(that.userMoneyValidate, await that.ctx.getParse());
  942. const seq = that.app.Sequelize;
  943. const selectBean = await that.app.comoBean.instance(data, {
  944. offset: (data.page - 1) * data.limit, limit: data.limit, where: {
  945. user_id: data.user_id,
  946. type: { [seq.Op.in]: [ 1, 2 ] },
  947. },
  948. order: [ [ 'type', 'asc' ] ],
  949. });
  950. const result = await that.service.base.select(selectBean, that.app.model.UsersMoneyLogs, '新用户福利查询失败,请稍候重试', true, true);
  951. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  952. } catch (err) {
  953. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  954. }
  955. }
  956. /**
  957. * [newUserBenefits 获取每日红包]
  958. * @return {[type]} [description]
  959. */
  960. async dayLucky() {
  961. const that = this;
  962. try {
  963. const data = await that.ctx.validate(that.luckyValidate, await that.ctx.anyParse());
  964. // 2023/11/17 用户今天是否已经抽奖
  965. const user = await that.useModel.findOne({
  966. where: { user_id: data.user_id },
  967. });
  968. const isTodayLucky = await that.service.baseUtils.isToday(user.lucky_time);
  969. // const isTodayLucky = false;
  970. if (isTodayLucky) {
  971. throw new Error('您今天已经抽奖了哦,明天再来吧!');
  972. } else {
  973. // 2023/11/17 : 发起概率抽奖 发放奖项 (红包上限)
  974. let prizes;
  975. if (user.money > 999) {
  976. prizes = [
  977. { reward: 6, weight: 1 },
  978. { reward: 1, weight: 95 },
  979. { reward: 10, weight: 1 },
  980. { reward: 8, weight: 1 },
  981. { reward: 30, weight: 1 },
  982. { reward: 20, weight: 1 }
  983. ];
  984. } else {
  985. prizes = [
  986. { reward: 6, weight: 4 },
  987. { reward: 1, weight: 1 },
  988. { reward: 10, weight: 50 },
  989. { reward: 8, weight: 10 },
  990. { reward: 30, weight: 5 },
  991. { reward: 20, weight: 30 }
  992. ];
  993. }
  994. const prizeAward = await that.lottery(prizes);
  995. // 2023/11/21 发放红包奖励
  996. // console.log(prizeAward);
  997. await that.service.shop.userMoneyAdd(user.user_id, prizeAward.reward, null, '每日抽奖红包', 0, 4);
  998. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', prizeAward, false));
  999. }
  1000. } catch (err) {
  1001. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  1002. }
  1003. }
  1004. //权重抽奖函数
  1005. async lottery(prizes) {
  1006. let total = 0;
  1007. let percent;
  1008. //下标标记数组
  1009. let index = [];
  1010. for (let i = 0; i < prizes.length; i++) {
  1011. //判断元素的权重,为了实现小数权重,先将所有的值放大100倍
  1012. percent = 'undefined' != typeof (prizes[i].weight) ? prizes[i].weight : 0;
  1013. for (let j = 0; j < percent; j++) {
  1014. index.push(i);
  1015. }
  1016. total += percent;
  1017. }
  1018. //随机数值
  1019. let rand = Math.floor(Math.random() * total);
  1020. return prizes[index[rand]];
  1021. };
  1022. /**
  1023. * 更新用户信息
  1024. * @date:2023/10/20
  1025. */
  1026. async updateUserInfo() {
  1027. const that = this;
  1028. try {
  1029. const data = await that.ctx.validate(that.updateValidate, await that.ctx.anyParse());
  1030. // 2023/10/20 更新用户信息
  1031. const dataParam = {};
  1032. if (data.is_office) {
  1033. dataParam.is_office = true;
  1034. }
  1035. if (data.is_family) {
  1036. dataParam.is_family = true;
  1037. }
  1038. dataParam.update_ttime = that.app.szjcomo.date('Y-m-d H:i:s');
  1039. const updateBean = await that.app.comoBean.instance(dataParam, { where: { user_id: data.user_id } });
  1040. const result = await that.service.base.update(updateBean, that.useModel, '微信用户信息更新失败,请重试');
  1041. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  1042. } catch (e) {
  1043. return that.ctx.appJson(that.app.szjcomo.appResult(e.message));
  1044. }
  1045. }
  1046. };