'use strict'; const Base = require('../base'); // 商城接口控制器 module.exports = class ShopController extends Base { /** * [orderPayValidate 微信支付验证器] * @return {[type]} [description] */ get orderPayValidate() { const that = this; return { pay_id: that.ctx.rules.name('支付ID').required().notEmpty() .number(), order_id: that.ctx.rules.name('订单ID').required().notEmpty() .number(), user_id: that.ctx.rules.default(that.service.shop.getWebUserId()).number(), }; } /** * [shopConfig 商城配置] * @return {[type]} [description] */ async shopConfig() { const that = this; const keys = [ 'website_title', 'website_logo', 'shop_home_swipers', 'shop_share_title', 'shop_share_logo', 'shop_share_desc', 'shop_theme_color', 'shop_price_color', 'shop_start_close', 'shop_close_desc', 'can_discount_category', 'activity_share_show' ]; const config = await that.service.configs.getConfigMoreValue(keys); config.shop_start_close = Number(config.shop_start_close); const temA = config.can_discount_category.replace('[', ''); const temB = temA.replace(']', ''); let canDiscountCategory = temB.split(','); canDiscountCategory = canDiscountCategory.map(Number); config.canDiscountCategory = canDiscountCategory; return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', config, false)); } /** * [payConfig 获取支付配置] * @return {[type]} [description] */ async payConfig() { const that = this; try { const result = await that.service.shop.payConfig(); return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false)); } catch (err) { return that.ctx.appJson(that.app.szjcomo.appResult(err.message)); } } /** * [orderPay 订单支付接口] * @return {[type]} [description] */ async orderPay() { const that = this; try { const data = await that.ctx.validate(that.orderPayValidate, await that.ctx.getParse()); const orderInfo = await that.app.model.Orders.findOne({ where: { order_id: data.order_id }, attributes: [ 'order_amount', 'surplus_amout', ] }); const userInfo = await that.app.model.Users.findOne({ where: { user_id: data.user_id }, attributes: [ 'openid' ] }); } catch (err) { return that.ctx.appJson(that.app.szjcomo.appResult(err.message)); } } };