| 
					
				 | 
			
			
				@@ -223,13 +223,13 @@ module.exports = class OrderController extends shopController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const seq = that.app.Sequelize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let commentInclude = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if (data.comment_id) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      commentInclude = [{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      commentInclude = [ { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         model: that.app.model.ProductComment, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         as: 'product_comment', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         attributes: [ 'comment' ], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         where: { order_id: data.order_id }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         required: false, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      }]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } ]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const options = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       where: { order_id: data.order_id }, 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -264,11 +264,11 @@ module.exports = class OrderController extends shopController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           model: that.app.model.OrdersProducts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           as: 'orders_products', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           attributes: [ 'product_count', 'product_name', 'product_image', 'product_id', 'category_id', 'shop_price', 'volume', 'price' ], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          order: [[ 'rec_id', 'asc' ]], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          order: [ [ 'rec_id', 'asc' ] ], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       ], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       attributes: [ 'order_sn', 'create_time', 'order_status', 'order_amount', 'surplus_amout', 'order_id', 'is_urge' ], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      order: [[ 'order_id', 'desc' ]], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      order: [ [ 'order_id', 'desc' ] ], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if (data.order_status > -1) options.where.order_status = data.order_status; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const selectBean = await that.app.comoBean.instance(data, options); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -367,39 +367,9 @@ module.exports = class OrderController extends shopController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   // ======================以下为用户下单所需要方法============================== 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * [create 用户下单] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * @return {[type]} [description] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  /*  async create() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    const that = this; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    let transaction; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      const data = await that.ctx.validate(that.createValidate, await that.ctx.postParse()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      const inviteCode = data.inviteCode ? Number(data.inviteCode) : -1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      that.logger.error('用户下单绑定的邀请码: %s ', inviteCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      transaction = await that.app.model.transaction(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      const products = await that.getCartProducts(data.user_id, transaction); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      const orderAmount = await that.caclOrderAmount(products); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      const result = await that.orderCreateBefore(data, orderAmount, transaction, inviteCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      const cartIds = await that.orderProductsAfter(result.order.order_id, products, data, transaction); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      await that.clearCartProducts(cartIds, transaction); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      await transaction.commit(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result.payParmas, false)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } catch (err) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      if (transaction) await transaction.rollback(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      await that.logs('order.js', err); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      return that.ctx.appJson(that.app.szjcomo.appResult(err.message)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  }*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * [createV2 用户下单] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * @return {[type]} [description] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   async createV2() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const that = this; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -427,20 +397,10 @@ module.exports = class OrderController extends shopController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * [caclOrderAmount 计算订单总价] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * @param  {[type]} products [description] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * @param  {Object} data     [description] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * @return {[type]}          [description] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * @param products 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * @param pid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  // eslint-disable-next-line no-unused-vars 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  /*  async caclOrderAmount(products, data = {}) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // const that = this; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    let order_amount = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    products.forEach(item => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      order_amount += (Number(item.shop_price) * item.product_count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    return order_amount; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  }*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   async caclOrderAmountV2(products, pid = 4) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const that = this; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const keys = [ 'can_discount_category' ]; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -458,77 +418,18 @@ module.exports = class OrderController extends shopController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         orderAmount.orderPriceCanDiscount += ((Number(item.price > 0 ? item.price : item.shop_price) * item.product_count) * (pid === 1 ? 0.8 : 1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    /* console.log('orderAmount'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    console.log(orderAmount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    console.log('pid'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    console.log(pid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    console.log('item'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    console.log(products);*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return orderAmount; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * [orderCreateBefore 用户下单前置] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * @param  {Object} data [description] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * @param order_amount 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * @param  data data [description] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * @param orderAmount 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * @param transaction 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * @param inviteCode 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * @param isUseMoney 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * @return {[type]}      [description] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  /*  async orderCreateBefore(data = {}, order_amount = 0, transaction = null, inviteCode = -1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    const that = this; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    const address = await that.getUserAddress(data.user_id, transaction); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (!address) throw new Error('您还没有完善收货信息,请完善后再下单吧!'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // 计算用户需要支付的金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    const tmpPayMentMoney = await that.service.order.caclPaymentMoney(data, order_amount, transaction); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    const opts = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      order_sn: data.order_sn, user_id: data.user_id, order_status: 0, order_source: data.order_source, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      surplus_amout: tmpPayMentMoney.surplus_amout, consignee: address.uname, mobile: address.mobile, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      order_amount, province_id: address.province_id, city_id: address.city_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      user_remarks: data.user_remarks, county_id: address.county_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      address: [ address.province_name, address.city_name, address.county_name, address.address ].join(''), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      create_time: data.create_time, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      pay_id: data.pay_id, shipping_fee: 0, is_urge: 0, inviter_id: inviteCode, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    const orderBean = await that.app.comoBean.instance(opts, { transaction }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // 2022/11/11 创建订单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    const order = await that.service.base.create(orderBean, that.useModel, '订单提交失败,请重试'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (tmpPayMentMoney.surplus_amout) await that.service.shop.userMoneySub(data.user_id, tmpPayMentMoney.surplus_amout, transaction, `商品下单时余额抵扣,订单编号是:${data.order_sn}`); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // 用户全部使用余额支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (!tmpPayMentMoney.payment_money) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      const payParmas = await that.service.order.getSurplusPayParams(order.order_id, data.user_id, tmpPayMentMoney.surplus_amout, transaction); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      // 订单发货时扣除库存,受控于后台配置的扣除时机 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      await that.service.order.productStockSub(order.order_id, transaction, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      return { order, payParmas }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    let payParmas = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    const userInfo = await that.app.model.Users.findOne({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      where: { user_id: data.user_id }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      attributes: [ 'openid' ], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      transaction, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      raw: true, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (data.order_source === 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      payParmas = await that.service.wechat.wechatAccountJsApiPay({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        body: '订单支付', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        openid: userInfo.openid, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        total_fee: (tmpPayMentMoney.payment_money * 100), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        trade_type: 'JSAPI', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        attach: that.app.szjcomo.base64_encode(that.app.szjcomo.json_encode({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          user_id: data.user_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          order_id: order.order_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          pay_id: data.pay_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        })), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    return { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      order, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      payParmas: { payment_money: tmpPayMentMoney.payment_money, params: payParmas, order_id: order.order_id }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  }*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   async orderCreateBeforeV2(data = {}, orderAmount = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     orderPriceCanDiscount: 0, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     orderPriceNotDiscount: 0, 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -741,9 +642,9 @@ module.exports = class OrderController extends shopController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       const data = await that.ctx.validate(that.cancelValidate, await that.ctx.getParse()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       const seq = that.app.Sequelize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       const info = await that.useModel.findOne({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        include: [{ model: that.app.model.Users, as: 'users', attributes: [] }], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        include: [ { model: that.app.model.Users, as: 'users', attributes: [] } ], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         where: { order_id: data.order_id }, raw: true, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        attributes: [ 'order_amount', 'surplus_amout', 'pay_id', [ seq.col('users.openid'), 'openid' ]], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        attributes: [ 'order_amount', 'surplus_amout', 'pay_id', [ seq.col('users.openid'), 'openid' ] ], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       if (!info) throw new Error('订单信息不存在,请勿非法操作'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       const result = await that.service.wechat.wechatAccountJsApiPay({ 
			 |