shop.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use strict';
  2. const Base = require('../base');
  3. // 商城接口控制器
  4. module.exports = class ShopController extends Base {
  5. /**
  6. * [orderPayValidate 微信支付验证器]
  7. * @return {[type]} [description]
  8. */
  9. get orderPayValidate() {
  10. const that = this;
  11. return {
  12. pay_id: that.ctx.rules.name('支付ID').required().notEmpty()
  13. .number(),
  14. order_id: that.ctx.rules.name('订单ID').required().notEmpty()
  15. .number(),
  16. user_id: that.ctx.rules.default(that.service.shop.getWebUserId()).number(),
  17. };
  18. }
  19. /**
  20. * [shopConfig 商城配置]
  21. * @return {[type]} [description]
  22. */
  23. async shopConfig() {
  24. const that = this;
  25. const keys = [ 'website_title', 'website_logo', 'shop_home_swipers', 'shop_share_title', 'shop_share_logo', 'shop_share_desc',
  26. 'shop_theme_color', 'shop_price_color', 'shop_start_close', 'shop_close_desc', 'can_discount_category', 'activity_share_show' ];
  27. const config = await that.service.configs.getConfigMoreValue(keys);
  28. config.shop_start_close = Number(config.shop_start_close);
  29. const temA = config.can_discount_category.replace('[', '');
  30. const temB = temA.replace(']', '');
  31. let canDiscountCategory = temB.split(',');
  32. canDiscountCategory = canDiscountCategory.map(Number);
  33. config.canDiscountCategory = canDiscountCategory;
  34. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', config, false));
  35. }
  36. /**
  37. * [payConfig 获取支付配置]
  38. * @return {[type]} [description]
  39. */
  40. async payConfig() {
  41. const that = this;
  42. try {
  43. const result = await that.service.shop.payConfig();
  44. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  45. } catch (err) {
  46. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  47. }
  48. }
  49. /**
  50. * [orderPay 订单支付接口]
  51. * @return {[type]} [description]
  52. */
  53. async orderPay() {
  54. const that = this;
  55. try {
  56. const data = await that.ctx.validate(that.orderPayValidate, await that.ctx.getParse());
  57. const orderInfo = await that.app.model.Orders.findOne({ where: { order_id: data.order_id }, attributes: [
  58. 'order_amount', 'surplus_amout',
  59. ] });
  60. const userInfo = await that.app.model.Users.findOne({ where: { user_id: data.user_id }, attributes: [ 'openid' ] });
  61. } catch (err) {
  62. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  63. }
  64. }
  65. };