瀏覽代碼

支付方式调整 && 佣金计算规则调整

abiao 5 年之前
父節點
當前提交
e5c0c27189

+ 4 - 3
go/gopath/src/fohow.com/apps/controllers/pay_controller/after_pay_controller.go

@@ -164,11 +164,12 @@ func newSendInviterBenefit(wxUser *user_model.WxUser, orderId, source string) {
 		return
 	}
 	var benefitWxUser *user_model.WxUser
+	//群主购物不再计算佣金
 	if wxUser.ShowInviteMode == int64(1) && source == user_model.SOURCE_PRODUCT_BENEFIT {
-		benefitWxUser = wxUser
-	} else {
-		benefitWxUser = FindInviter(wxUser)
+		return
 	}
+	//会员购物给群主返佣
+	benefitWxUser = FindInviter(wxUser)
 	if benefitWxUser == nil || benefitWxUser.Id == int64(1) {
 		return
 	}

+ 1 - 0
go/gopath/src/fohow.com/apps/controllers/pay_controller/pay_controller.go

@@ -16,6 +16,7 @@ const (
 )
 
 type PayUrl struct {
+	NeedWx  bool              `json:"need_wx"`
 	PayUrl  string            `json:"pay_url"`
 	PayData map[string]string `json:"pay_data"`
 	OrderId string            `json:"order_id"`

+ 47 - 45
go/gopath/src/fohow.com/apps/controllers/pay_controller/pay_exchange_controller.go

@@ -85,11 +85,7 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source s
 			}
 		}
 		buy_price_total += product.BuyPrice * item.Count
-		if payWay == order_model.PAY_WAY_WEIXIN { //微信支付总价
-			total_price += product.Price * item.Count
-		} else if payWay == order_model.PAY_WAY_BALANCE { //代金券支付总价
-			total_price += product.Price * item.Count
-		}
+		total_price += product.Price * item.Count
 		SaleNumsMap[product.Id] = item.Count
 	}
 	order.PayWay = payWay
@@ -98,46 +94,52 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source s
 	order.Address = fmt.Sprintf("%s%s%s%s", address.Province, address.City, address.District, address.Address)
 	order.BuyPrice = buy_price_total
 	order.TotalPrice = total_price
-
-	switch payWay { // 1.代金券购买 2.微信支付
-	case pay_model.PAYWAY_BALANCE: // 代金券购买
-
-		curWxUser := user_model.GetWxUserById(wxUId, false)
-		if curWxUser == nil {
-			self.ReturnError(403, apps.UserNeedLogin, "", nil)
-		}
-		//黑名单用户
-		curUser := user_model.GetUserById(curWxUser.UserId, false)
-		if curUser != nil && curUser.IsBlackUser == 1 {
-			self.ReturnError(403, apps.NetworkBusy, "", nil)
-		}
-		//再次增加订单状态判断
-		if order.Status != order_model.STATUS_UNPAY {
-			self.ReturnError(403, apps.NotUnPay, "", nil)
-		}
-
-		userLeftBalanceCount := balance_model.GetUserTotalBalance(wxUId)
-		tp := order.TotalPrice
-		freight := order_model.FREIGHT
-		if tp >= order_model.FREIGHT_LIMIT || beego.AppConfig.String("RunMode") == "dev" {
-			freight = int64(0)
-		}
-		tp += freight
+	//支付信息判断
+	curWxUser := user_model.GetWxUserById(wxUId, false)
+	if curWxUser == nil {
+		self.ReturnError(403, apps.UserNeedLogin, "", nil)
+	}
+	//黑名单用户
+	curUser := user_model.GetUserById(curWxUser.UserId, false)
+	if curUser != nil && curUser.IsBlackUser == 1 {
+		self.ReturnError(403, apps.NetworkBusy, "", nil)
+	}
+	//再次增加订单状态判断
+	if order.Status != order_model.STATUS_UNPAY {
+		self.ReturnError(403, apps.NotUnPay, "", nil)
+	}
+	//若账户有代金券则优先抵扣代金券
+	needWx := true
+	totalCoupon := int64(0)
+	userLeftBalanceCount := balance_model.GetUserTotalBalance(wxUId)
+	tp := order.TotalPrice
+	freight := order_model.FREIGHT
+	if tp >= order_model.FREIGHT_LIMIT || beego.AppConfig.String("RunMode") == "dev" {
+		freight = int64(0)
+	}
+	tp += freight
+	if order.OrderType != order_model.ORDER_TYPE_SEKILL {
 		if userLeftBalanceCount < tp {
-			self.ReturnError(403, apps.BalanceNotEnough, "", nil)
-		}
-
-		if tp > 0 {
-			source := balance_model.BALANCE_SOURCE_EXCHANGE_PRODUCT
-			remark := fmt.Sprintf("代金券兑换商品")
-			new(balance_model.Balance).Create(wxUId, uId, -tp, source, oId, remark)
+			totalCoupon = userLeftBalanceCount
+		} else {
+			needWx = false
+			totalCoupon = tp
 		}
-
+	}
+	//先扣减代金券
+	if totalCoupon > 0 {
+		source := balance_model.BALANCE_SOURCE_EXCHANGE_PRODUCT
+		remark := fmt.Sprintf("代金券兑换商品")
+		new(balance_model.Balance).Create(wxUId, uId, -totalCoupon, source, oId, remark)
+	}
+	order.CouponPrice = totalCoupon
+	switch needWx { // 1.true需要微信支付,2.false不需要微信支付
+	case false: // 代金券抵扣完毕
 		//更新订单状态
 		order.Status = order_model.STATUS_PROCESSING
 		order.PaiedAt = time.Now().Unix()
 		order.PaiedTime = time.Now()
-		order.PaiedPrice = order.TotalPrice
+		order.PaiedPrice = 0
 		order.PayWay = pay_model.PAYWAY_BALANCE
 		order.Source = source
 		order.Save()
@@ -162,18 +164,16 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source s
 		//wxUser := user_model.GetWxUserById(order.WxUserId, true)
 		//go sendInviterBenefit(wxUser, order.OrderId, user_model.SOURCE_PRODUCT_BENEFIT)
 		payUrl, payData = fmt.Sprintf("%s?order_id=%s", returnUrl, order.OrderId), nil
-		result := PayUrl{PayUrl: payUrl, PayData: payData, OrderId: order.OrderId}
+		result := PayUrl{NeedWx: false, PayUrl: payUrl, PayData: payData, OrderId: order.OrderId}
 		self.Data["json"] = self.FormatResult([]interface{}{result})
-	case pay_model.PAYWAY_WEIXINPAY: // 微信支付
+	case true: // 微信支付
 
 		wxUser := self.GetCurrentWxUser(false)
-
 		order.Contact = address.Contact
 		order.Tel = address.Tel
 		order.Address = fmt.Sprintf("%s%s%s%s", address.Province, address.City, address.District, address.Address)
 		order.Source = source
 		order.Save()
-
 		if order.Source == order_model.SOURCE_XCX { //小程序微信支付
 			freight := order_model.FREIGHT
 			if order.TotalPrice >= order_model.FREIGHT_LIMIT || beego.AppConfig.String("RunMode") == "dev" {
@@ -186,9 +186,10 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source s
 
 			//返回数据
 			type PayData struct {
+				NeedWx  bool              `json:"need_wx"`
 				PayData map[string]string `json:"pay_data"`
 			}
-			self.Data["json"] = &PayData{PayData: payData}
+			self.Data["json"] = &PayData{NeedWx: true, PayData: payData}
 
 		} else { //公众号微信支付
 
@@ -203,9 +204,10 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source s
 
 			//返回数据
 			type PayData struct {
+				NeedWx  bool              `json:"need_wx"`
 				PayData map[string]string `json:"pay_data"`
 			}
-			self.Data["json"] = &PayData{PayData: payData}
+			self.Data["json"] = &PayData{NeedWx: true, PayData: payData}
 		}
 	default:
 		beego.BeeLogger.Error("pay way not match, payway:%s", payWay)

+ 1 - 0
go/gopath/src/fohow.com/apps/models/order_model/order.go

@@ -75,6 +75,7 @@ type Order struct {
 	UserId         int64                    `orm:"column(user_id)"                                     json:"user_id"`          // int(11)
 	TotalPrice     int64                    `orm:"column(total_price)"                                 json:"total_price"`      // int(11)
 	PaiedPrice     int64                    `orm:"column(paied_price);null"                            json:"paied_price"`      // int(11)
+	CouponPrice    int64                    `orm:"column(coupon_price);null"                           json:"coupon_price"`     // int(11)
 	BuyPrice       int64                    `orm:"column(buy_price);null"                              json:"-"`                // int(11)
 	Count          int64                    `orm:"column(count);null"                                  json:"count"`            // int(11)
 	PaiedAt        int64                    `orm:"column(paied_at);null"                               json:"paied_at"`         // int(11)