|
@@ -621,3 +621,137 @@ func FindMaxPaymentMethod(total_weixin, totalCoupon, paiedCash int64) string {
|
|
|
|
|
|
|
|
return paymentMethod
|
|
return paymentMethod
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+type PaymentDetails struct {
|
|
|
|
|
+ FirstPay bool // 是否首次支付
|
|
|
|
|
+ TotalPrice int64 // 订单总金额
|
|
|
|
|
+ Freight int64 // 运费
|
|
|
|
|
+ PaySilver int64 // 用银币支付的金额
|
|
|
|
|
+ PayCoupon int64 // 用优惠券支付的金额
|
|
|
|
|
+ PayBalance int64 // 用余额支付的金额
|
|
|
|
|
+ Discount int64 // 折扣金额
|
|
|
|
|
+ ShouldPay int64 // 应支付金额
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (self *PayController) QueryPayInfo() {
|
|
|
|
|
+
|
|
|
|
|
+ oId := self.GetString("order_id")
|
|
|
|
|
+ pickWay, _ := self.GetInt64("pick_way")
|
|
|
|
|
+ useCoupon, _ := self.GetBool("use_coupon", false)
|
|
|
|
|
+ useBalance, _ := self.GetBool("use_balance", false)
|
|
|
|
|
+
|
|
|
|
|
+ payOrder.Lock()
|
|
|
|
|
+ defer payOrder.Unlock()
|
|
|
|
|
+ var details PaymentDetails
|
|
|
|
|
+
|
|
|
|
|
+ wxUId := self.GetCurrentWxUserIdByToken()
|
|
|
|
|
+ wxUser := user_model.GetWxUserById(wxUId, false)
|
|
|
|
|
+ if wxUser == nil {
|
|
|
|
|
+ self.ReturnError(403, apps.UserNeedLogin, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //订单状态
|
|
|
|
|
+ order := order_model.GetOrderById(oId, false)
|
|
|
|
|
+ if order.Status != order_model.STATUS_UNPAY {
|
|
|
|
|
+ self.ReturnError(403, apps.NotUnPay, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+ specialPromotion := order.SpecialPro
|
|
|
|
|
+ //获取购物商品明细
|
|
|
|
|
+ total_price := int64(0)
|
|
|
|
|
+ total_quan := int64(0)
|
|
|
|
|
+ total_weixin := int64(0)
|
|
|
|
|
+ paiedSilver := int64(0)
|
|
|
|
|
+ firstPay := true
|
|
|
|
|
+ //店长折扣
|
|
|
|
|
+ dis_amount := order.DisAmount
|
|
|
|
|
+ list := order_model.GetAllDetailsOrderId(order.OrderId, false)
|
|
|
|
|
+ for _, item := range list {
|
|
|
|
|
+ //商品状态
|
|
|
|
|
+ product := product_model.GetProductById(item.ProductId, false)
|
|
|
|
|
+ if product == nil {
|
|
|
|
|
+ self.ReturnError(403, []string{apps.ProductNotExist[0], fmt.Sprintf("%s产品不存在", product.Name)}, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+ //非赠品计入价格
|
|
|
|
|
+ if !item.Send {
|
|
|
|
|
+ //微信支付金额统计
|
|
|
|
|
+ if product.UseQuan || specialPromotion {
|
|
|
|
|
+ total_quan += product.Price*item.Count - item.Silver
|
|
|
|
|
+ }
|
|
|
|
|
+ total_price += product.Price * item.Count
|
|
|
|
|
+ paiedSilver += item.Silver
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //运费
|
|
|
|
|
+ freight := sys_config.GetFreight()
|
|
|
|
|
+ //第一次支付已更新支付方式,第一次支付才计算支付金额
|
|
|
|
|
+ if len(order.PayWay) <= 0 {
|
|
|
|
|
+ //计算运费
|
|
|
|
|
+ if total_price >= sys_config.GetOrderLimit() || pickWay == order_model.PICK_SHOP {
|
|
|
|
|
+ freight = int64(0)
|
|
|
|
|
+ }
|
|
|
|
|
+ tp := total_price
|
|
|
|
|
+ //抵扣银豆
|
|
|
|
|
+ if paiedSilver > tp {
|
|
|
|
|
+ paiedSilver = tp
|
|
|
|
|
+ }
|
|
|
|
|
+ tp -= paiedSilver
|
|
|
|
|
+
|
|
|
|
|
+ //若账户有提货券则优先抵扣提货券
|
|
|
|
|
+ totalCoupon := int64(0)
|
|
|
|
|
+ userLeftBalanceCount := balance_model.GetUserTotalBalance(wxUId)
|
|
|
|
|
+ tp += freight
|
|
|
|
|
+ total_quan = total_quan + freight
|
|
|
|
|
+ useCoupon = true
|
|
|
|
|
+ if useCoupon && userLeftBalanceCount > 0 {
|
|
|
|
|
+ if userLeftBalanceCount < total_quan {
|
|
|
|
|
+ totalCoupon = userLeftBalanceCount
|
|
|
|
|
+ } else {
|
|
|
|
|
+ totalCoupon = total_quan
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ total_weixin = tp - totalCoupon
|
|
|
|
|
+
|
|
|
|
|
+ //店长先抵扣折扣
|
|
|
|
|
+ paiedDis := int64(0)
|
|
|
|
|
+ if wxUser.Rank >= user_model.WX_USER_RANK_ONE && dis_amount > int64(0) {
|
|
|
|
|
+ if dis_amount < total_weixin {
|
|
|
|
|
+ paiedDis = dis_amount
|
|
|
|
|
+ } else {
|
|
|
|
|
+ paiedDis = total_weixin
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ total_weixin = total_weixin - paiedDis
|
|
|
|
|
+
|
|
|
|
|
+ //抵扣佣金
|
|
|
|
|
+ paiedCash := int64(0)
|
|
|
|
|
+ userLeftBalanceCash := balance_model.GetCashTotalBalance(wxUId)
|
|
|
|
|
+ if userLeftBalanceCash > int64(0) && useBalance {
|
|
|
|
|
+ if userLeftBalanceCash < total_weixin && total_weixin > 0 {
|
|
|
|
|
+ paiedCash = userLeftBalanceCash
|
|
|
|
|
+ } else {
|
|
|
|
|
+ paiedCash = total_weixin
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ total_weixin = total_weixin - paiedCash
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ firstPay = false
|
|
|
|
|
+ freight = order.Freight
|
|
|
|
|
+ paiedSilver = order.PaiedSilver
|
|
|
|
|
+ total_quan = order.CouponPrice
|
|
|
|
|
+ total_weixin = order.PaiedPrice
|
|
|
|
|
+ }
|
|
|
|
|
+ details.FirstPay = firstPay
|
|
|
|
|
+ details.Freight = freight
|
|
|
|
|
+ details.TotalPrice = total_price
|
|
|
|
|
+ details.PaySilver = paiedSilver
|
|
|
|
|
+ details.PayCoupon = total_quan
|
|
|
|
|
+ details.Discount = dis_amount
|
|
|
|
|
+ details.ShouldPay = total_weixin
|
|
|
|
|
+
|
|
|
|
|
+ self.Data["json"] = details
|
|
|
|
|
+ self.ServeJSON()
|
|
|
|
|
+}
|