|
|
@@ -67,243 +67,185 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source,
|
|
|
if pick_dept == nil || pick_address == nil || pick_address.WxUserId != wxUId {
|
|
|
self.ReturnError(403, apps.AddressNotMatch, "", nil)
|
|
|
}
|
|
|
+ concat = pick_address.Contact
|
|
|
+ tel = pick_address.Tel
|
|
|
+ addr = pick_dept.PickAddress
|
|
|
+ }
|
|
|
+ if source != order_model.SOURCE_XCX && source != order_model.SOURCE_APP {
|
|
|
+ self.ReturnError(403, apps.ParamsError, "", nil)
|
|
|
+ }
|
|
|
|
|
|
- if source != order_model.SOURCE_XCX && source != order_model.SOURCE_APP {
|
|
|
- concat = pick_address.Contact
|
|
|
- tel = pick_address.Tel
|
|
|
- addr = pick_dept.PickAddress
|
|
|
- }
|
|
|
+ wxUser := user_model.GetWxUserById(wxUId, false)
|
|
|
+ if wxUser == nil {
|
|
|
+ self.ReturnError(403, apps.UserNeedLogin, "", nil)
|
|
|
+ }
|
|
|
+ //订单状态
|
|
|
+ order := order_model.GetOrderById(oId, false)
|
|
|
+ if order == nil || order.WxUserId != wxUId {
|
|
|
+ self.ReturnError(404, apps.OrderNotExist, "", nil)
|
|
|
+ }
|
|
|
+ if order.Status != order_model.STATUS_UNPAY {
|
|
|
+ self.ReturnError(403, apps.NotUnPay, "", nil)
|
|
|
+ }
|
|
|
+ SaleNumsMap := make(map[int64]int64)
|
|
|
+ storeMap := make(map[int64]int64)
|
|
|
|
|
|
- if source != order_model.SOURCE_XCX && source != order_model.SOURCE_GZH {
|
|
|
- self.ReturnError(403, apps.ParamsError, "", nil)
|
|
|
- }
|
|
|
- wxUser := user_model.GetWxUserById(wxUId, false)
|
|
|
- if wxUser == nil {
|
|
|
- self.ReturnError(403, apps.UserNeedLogin, "", nil)
|
|
|
- }
|
|
|
- //订单状态
|
|
|
- order := order_model.GetOrderById(oId, false)
|
|
|
- if order == nil || order.WxUserId != wxUId {
|
|
|
- self.ReturnError(404, apps.OrderNotExist, "", nil)
|
|
|
- }
|
|
|
- if order.Status != order_model.STATUS_UNPAY {
|
|
|
- self.ReturnError(403, apps.NotUnPay, "", nil)
|
|
|
- }
|
|
|
- SaleNumsMap := make(map[int64]int64)
|
|
|
- storeMap := make(map[int64]int64)
|
|
|
+ //支付方式判断
|
|
|
+ if (order.OrderType == order_model.ORDER_TYPE_SEKILL || order.OrderType == order_model.ORDER_TYPE_SHOP) && payWay == pay_model.PAYWAY_BALANCE {
|
|
|
+ self.ReturnError(403, apps.NotRightPayWay, "", nil)
|
|
|
+ }
|
|
|
|
|
|
- //支付方式判断
|
|
|
- if (order.OrderType == order_model.ORDER_TYPE_SEKILL || order.OrderType == order_model.ORDER_TYPE_SHOP) && payWay == pay_model.PAYWAY_BALANCE {
|
|
|
- self.ReturnError(403, apps.NotRightPayWay, "", nil)
|
|
|
- }
|
|
|
+ //普通订单总价大于pv只支持微信支付
|
|
|
+ if order.OrderType == order_model.ORDER_TYPE_NORMAL && useCoupon && order.Pv < order.TotalPrice {
|
|
|
+ self.ReturnError(403, apps.NotRightPayWay, "", nil)
|
|
|
+ }
|
|
|
|
|
|
- //普通订单总价大于pv只支持微信支付
|
|
|
- if order.OrderType == order_model.ORDER_TYPE_NORMAL && useCoupon && order.Pv < order.TotalPrice {
|
|
|
- self.ReturnError(403, apps.NotRightPayWay, "", nil)
|
|
|
+ //获取购物商品明细
|
|
|
+ buy_price_total := int64(0)
|
|
|
+ total_price := int64(0)
|
|
|
+ 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)
|
|
|
}
|
|
|
-
|
|
|
- //获取购物商品明细
|
|
|
- buy_price_total := int64(0)
|
|
|
- total_price := int64(0)
|
|
|
- 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 product.Status == product_model.PRODUCT_STATUS_DOWN {
|
|
|
- self.ReturnError(403, []string{apps.ProductOffSale[0], fmt.Sprintf("%s产品已经下架", product.Name)}, "", nil)
|
|
|
+ //商品下架
|
|
|
+ if product.Status == product_model.PRODUCT_STATUS_DOWN {
|
|
|
+ self.ReturnError(403, []string{apps.ProductOffSale[0], fmt.Sprintf("%s产品已经下架", product.Name)}, "", nil)
|
|
|
+ }
|
|
|
+ //秒杀逻辑: 判断是否处于秒杀时间段内
|
|
|
+ if product.SeckilShowPrice > 0 {
|
|
|
+ now := time.Now()
|
|
|
+ if now.Unix() < product.SeckillStart.Unix() {
|
|
|
+ self.ReturnError(403, []string{apps.SeckillNotStart[0], fmt.Sprintf("%s秒杀活动尚未开始", product.Name)}, "", nil)
|
|
|
+ } else if now.Unix() > product.SeckillEnd.Unix() {
|
|
|
+ self.ReturnError(403, []string{apps.SeckillIsEnd[0], fmt.Sprintf("%s秒杀活动已经结束", product.Name)}, "", nil)
|
|
|
}
|
|
|
- //秒杀逻辑: 判断是否处于秒杀时间段内
|
|
|
- if product.SeckilShowPrice > 0 {
|
|
|
- now := time.Now()
|
|
|
- if now.Unix() < product.SeckillStart.Unix() {
|
|
|
- self.ReturnError(403, []string{apps.SeckillNotStart[0], fmt.Sprintf("%s秒杀活动尚未开始", product.Name)}, "", nil)
|
|
|
- } else if now.Unix() > product.SeckillEnd.Unix() {
|
|
|
- self.ReturnError(403, []string{apps.SeckillIsEnd[0], fmt.Sprintf("%s秒杀活动已经结束", product.Name)}, "", nil)
|
|
|
+ }
|
|
|
+ //限购逻辑
|
|
|
+ if product.PurchaseLimitCount > 0 {
|
|
|
+ if product.PurchaseLimitCount < item.Count {
|
|
|
+ self.ReturnError(403, []string{apps.OverLimitCount[0], fmt.Sprintf("%s商品限购%d件", product.Name, product.PurchaseLimitCount)}, "", nil)
|
|
|
+ } else {
|
|
|
+ purchaseTotalCount := order_model.GetOrderCountByPIdAndWxUId(product.Id, wxUId)
|
|
|
+ //历史已经买够到限购数量了
|
|
|
+ if product.PurchaseLimitCount <= purchaseTotalCount {
|
|
|
+ self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("%s商品限购%d件", product.Name, product.PurchaseLimitCount)}, "", nil)
|
|
|
}
|
|
|
- }
|
|
|
- //限购逻辑
|
|
|
- if product.PurchaseLimitCount > 0 {
|
|
|
- if product.PurchaseLimitCount < item.Count {
|
|
|
- self.ReturnError(403, []string{apps.OverLimitCount[0], fmt.Sprintf("%s商品限购%d件", product.Name, product.PurchaseLimitCount)}, "", nil)
|
|
|
- } else {
|
|
|
- purchaseTotalCount := order_model.GetOrderCountByPIdAndWxUId(product.Id, wxUId)
|
|
|
- //历史已经买够到限购数量了
|
|
|
- if product.PurchaseLimitCount <= purchaseTotalCount {
|
|
|
- self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("%s商品限购%d件", product.Name, product.PurchaseLimitCount)}, "", nil)
|
|
|
- }
|
|
|
- //历史没买够数量,但是历史总数+想购买的数量 超过限购数量
|
|
|
- if product.PurchaseLimitCount < (purchaseTotalCount + item.Count) {
|
|
|
- canBuyCount := product.PurchaseLimitCount - purchaseTotalCount
|
|
|
- self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("%s您还可以购买%d件", product.Name, canBuyCount)}, "", nil)
|
|
|
- }
|
|
|
+ //历史没买够数量,但是历史总数+想购买的数量 超过限购数量
|
|
|
+ if product.PurchaseLimitCount < (purchaseTotalCount + item.Count) {
|
|
|
+ canBuyCount := product.PurchaseLimitCount - purchaseTotalCount
|
|
|
+ self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("%s您还可以购买%d件", product.Name, canBuyCount)}, "", nil)
|
|
|
}
|
|
|
}
|
|
|
- buy_price_total += product.BuyPrice * item.Count
|
|
|
- total_price += product.Price * item.Count
|
|
|
- SaleNumsMap[product.Id] = item.Count
|
|
|
- storeMap[product.Id] = item.Count
|
|
|
}
|
|
|
- //beego.BeeLogger.Error("SaleNumsMap1 %v", SaleNumsMap)
|
|
|
+ buy_price_total += product.BuyPrice * item.Count
|
|
|
+ total_price += product.Price * item.Count
|
|
|
+ SaleNumsMap[product.Id] = item.Count
|
|
|
+ storeMap[product.Id] = item.Count
|
|
|
+ }
|
|
|
+ //beego.BeeLogger.Error("SaleNumsMap1 %v", SaleNumsMap)
|
|
|
|
|
|
- resultStore, prdName := FindNotEnoughPrd(storeMap)
|
|
|
- if resultStore {
|
|
|
- self.ReturnError(403, []string{apps.ProductStockNotEnough[0], fmt.Sprintf("%s商品库存不足", prdName)}, "", nil)
|
|
|
+ resultStore, prdName := FindNotEnoughPrd(storeMap)
|
|
|
+ if resultStore {
|
|
|
+ self.ReturnError(403, []string{apps.ProductStockNotEnough[0], fmt.Sprintf("%s商品库存不足", prdName)}, "", nil)
|
|
|
+ }
|
|
|
+ //beego.BeeLogger.Error("SaleNumsMap2 %v", SaleNumsMap)
|
|
|
+
|
|
|
+ //第一次支付已更新支付方式,第一次支付才计算支付金额
|
|
|
+ if len(order.PayWay) <= 0 {
|
|
|
+
|
|
|
+ order.Remark = remark
|
|
|
+ order.PayWay = payWay
|
|
|
+ order.Contact = concat
|
|
|
+ order.Tel = tel
|
|
|
+ order.Address = addr
|
|
|
+ order.BuyPrice = buy_price_total
|
|
|
+ order.TotalPrice = total_price
|
|
|
+ //支付信息判断
|
|
|
+ //黑名单用户
|
|
|
+ curUser := user_model.GetUserById(wxUser.UserId, false)
|
|
|
+ if curUser != nil && curUser.IsBlackUser == 1 {
|
|
|
+ self.ReturnError(403, apps.NetworkBusy, "", nil)
|
|
|
}
|
|
|
- //beego.BeeLogger.Error("SaleNumsMap2 %v", SaleNumsMap)
|
|
|
-
|
|
|
- //第一次支付已更新支付方式,第一次支付才计算支付金额
|
|
|
- if len(order.PayWay) <= 0 {
|
|
|
-
|
|
|
- order.Remark = remark
|
|
|
- order.PayWay = payWay
|
|
|
+ //再次增加订单状态判断
|
|
|
+ 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 := sys_config.GetFreight()
|
|
|
+ if tp >= sys_config.GetOrderLimit() || pick_way == order_model.PICK_SHOP {
|
|
|
+ freight = int64(0)
|
|
|
+ }
|
|
|
+ tp += freight
|
|
|
+ if order.OrderType != order_model.ORDER_TYPE_SEKILL && useCoupon {
|
|
|
+ if userLeftBalanceCount < tp {
|
|
|
+ totalCoupon = userLeftBalanceCount
|
|
|
+ } else {
|
|
|
+ needWx = false
|
|
|
+ totalCoupon = tp
|
|
|
+ }
|
|
|
+ }
|
|
|
+ order.Freight = freight
|
|
|
+ order.PickDept = pick_dept_id
|
|
|
+ order.PickWay = pick_way
|
|
|
+ //先扣减提货券
|
|
|
+ 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 = 0
|
|
|
+ order.PayWay = pay_model.PAYWAY_BALANCE
|
|
|
+ order.Source = source
|
|
|
+ order.Save()
|
|
|
+ //发放赠品
|
|
|
+ go helpers.SetOrderPromotion(order.OrderId, wxUser.Id)
|
|
|
+ //已支付订单移除未支付队列
|
|
|
+ cancelKey := lib_redis.GetOrderCancelList()
|
|
|
+ lib_redis.ThrowOutRedisList(cancelKey, order.OrderId)
|
|
|
+ //更新已售数量
|
|
|
+ go order_model.UpdateSaleNums(SaleNumsMap)
|
|
|
+ //赠品写入订单
|
|
|
+ go helpers.PresentTransferToOrder(order.OrderId, wxUId)
|
|
|
+ //go CreateOrderNotify(order, product)
|
|
|
+ //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{NeedWx: false, PayUrl: payUrl, PayData: payData, OrderId: order.OrderId}
|
|
|
+ //self.Data["json"] = self.FormatResult([]interface{}{result})
|
|
|
+ self.Data["json"] = result
|
|
|
+ case true: // 微信支付
|
|
|
order.Contact = concat
|
|
|
order.Tel = tel
|
|
|
order.Address = addr
|
|
|
- order.BuyPrice = buy_price_total
|
|
|
- order.TotalPrice = total_price
|
|
|
- //支付信息判断
|
|
|
- //黑名单用户
|
|
|
- curUser := user_model.GetUserById(wxUser.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 := sys_config.GetFreight()
|
|
|
- if tp >= sys_config.GetOrderLimit() || pick_way == order_model.PICK_SHOP {
|
|
|
- freight = int64(0)
|
|
|
- }
|
|
|
- tp += freight
|
|
|
- if order.OrderType != order_model.ORDER_TYPE_SEKILL && useCoupon {
|
|
|
- if userLeftBalanceCount < tp {
|
|
|
- totalCoupon = userLeftBalanceCount
|
|
|
- } else {
|
|
|
- needWx = false
|
|
|
- totalCoupon = tp
|
|
|
- }
|
|
|
- }
|
|
|
- order.Freight = freight
|
|
|
- order.PickDept = pick_dept_id
|
|
|
- order.PickWay = pick_way
|
|
|
- //先扣减提货券
|
|
|
- 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 = 0
|
|
|
- order.PayWay = pay_model.PAYWAY_BALANCE
|
|
|
- order.Source = source
|
|
|
- order.Save()
|
|
|
- //发放赠品
|
|
|
- go helpers.SetOrderPromotion(order.OrderId, wxUser.Id)
|
|
|
- //已支付订单移除未支付队列
|
|
|
- cancelKey := lib_redis.GetOrderCancelList()
|
|
|
- lib_redis.ThrowOutRedisList(cancelKey, order.OrderId)
|
|
|
- //更新已售数量
|
|
|
- go order_model.UpdateSaleNums(SaleNumsMap)
|
|
|
- //赠品写入订单
|
|
|
- go helpers.PresentTransferToOrder(order.OrderId, wxUId)
|
|
|
- //go CreateOrderNotify(order, product)
|
|
|
- //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{NeedWx: false, PayUrl: payUrl, PayData: payData, OrderId: order.OrderId}
|
|
|
- //self.Data["json"] = self.FormatResult([]interface{}{result})
|
|
|
- self.Data["json"] = result
|
|
|
- case true: // 微信支付
|
|
|
- order.Contact = concat
|
|
|
- order.Tel = tel
|
|
|
- order.Address = addr
|
|
|
- order.PaiedPrice = tp - totalCoupon
|
|
|
- order.Source = source
|
|
|
- order.Save()
|
|
|
- if source == order_model.SOURCE_XCX { //小程序微信支付
|
|
|
- freight := sys_config.GetFreight()
|
|
|
- if order.TotalPrice >= sys_config.GetOrderLimit() {
|
|
|
- freight = int64(0)
|
|
|
- }
|
|
|
- order.TotalPrice += freight
|
|
|
- notifyUrl := fmt.Sprintf("%s/v1/pay/%s/async/%s", beego.AppConfig.String("ApiHost"), EXCHANGE_TARGET, pay_model.PAYWAY_WEIXINPAY)
|
|
|
- body := fmt.Sprintf("FOHOW玖玖-购买商品")
|
|
|
- //获取paycode
|
|
|
- payCode := sys_config.GetPayConfigByDepart(wxUser.Depart, false)
|
|
|
-
|
|
|
- beego.BeeLogger.Warn("payCode--%s", payCode)
|
|
|
- payData := wx_mp.GetPayData(wxUser.Openid, order.OrderId, order.PaiedPrice, body, notifyUrl, self.Ctx.Input.IP(), payCode)
|
|
|
-
|
|
|
- //返回数据
|
|
|
- type PayData struct {
|
|
|
- NeedWx bool `json:"need_wx"`
|
|
|
- PayData map[string]string `json:"pay_data"`
|
|
|
- }
|
|
|
- self.Data["json"] = &PayData{NeedWx: true, PayData: payData}
|
|
|
-
|
|
|
- } else if source == order_model.SOURCE_APP {
|
|
|
- freight := sys_config.GetFreight()
|
|
|
- if order.TotalPrice >= sys_config.GetOrderLimit() {
|
|
|
- freight = int64(0)
|
|
|
- }
|
|
|
- order.TotalPrice += freight
|
|
|
- notifyUrl := fmt.Sprintf("%s/v1/pay/%s/async/%s", beego.AppConfig.String("ApiHost"), EXCHANGE_TARGET, pay_model.PAYWAY_WEIXINPAY)
|
|
|
- body := fmt.Sprintf("FOHOW玖玖-购买商品")
|
|
|
- //获取paycode
|
|
|
- payCode := sys_config.GetPayConfigByDepart(wxUser.Depart, true)
|
|
|
- payData := wx_mp.GetAppPayData(order.OrderId, order.PaiedPrice, body, notifyUrl, self.Ctx.Input.IP(), payCode)
|
|
|
- beego.BeeLogger.Warn("pay_data --%v", payData)
|
|
|
- //返回数据
|
|
|
- type PayData struct {
|
|
|
- NeedWx bool `json:"need_wx"`
|
|
|
- PayData map[string]string `json:"pay_data"`
|
|
|
- }
|
|
|
- self.Data["json"] = &PayData{NeedWx: true, PayData: payData}
|
|
|
-
|
|
|
- } else { //公众号微信支付
|
|
|
-
|
|
|
- notifyUrl := fmt.Sprintf("%s/v1/pay/%s/async/%s", beego.AppConfig.String("ApiHost"), EXCHANGE_TARGET, pay_model.PAYWAY_WEIXINPAY)
|
|
|
- body := fmt.Sprintf("FOHOW玖玖-购买商品")
|
|
|
- wxGzh := user_model.GetWxUserGzhByWxUIdAndAppId(wxUser.Id, beego.AppConfig.String("WxMPAppId"), false)
|
|
|
- if wxGzh == nil {
|
|
|
- self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
- }
|
|
|
- payCode := sys_config.GetPayConfigByDepart(wxUser.Depart, true)
|
|
|
- payData := wx_mp.GetPayData(wxGzh.GzhOpenId, order.OrderId, order.PaiedPrice, body, notifyUrl, self.Ctx.Input.IP(), payCode)
|
|
|
-
|
|
|
- //返回数据
|
|
|
- type PayData struct {
|
|
|
- NeedWx bool `json:"need_wx"`
|
|
|
- PayData map[string]string `json:"pay_data"`
|
|
|
- }
|
|
|
- self.Data["json"] = &PayData{NeedWx: true, PayData: payData}
|
|
|
- }
|
|
|
- default:
|
|
|
- beego.BeeLogger.Error("pay way not match, payway:%s", payWay)
|
|
|
- }
|
|
|
- } else {
|
|
|
- //如果是第二次支付
|
|
|
+ order.PaiedPrice = tp - totalCoupon
|
|
|
+ order.Source = source
|
|
|
+ order.Save()
|
|
|
if source == order_model.SOURCE_XCX { //小程序微信支付
|
|
|
-
|
|
|
+ freight := sys_config.GetFreight()
|
|
|
+ if order.TotalPrice >= sys_config.GetOrderLimit() {
|
|
|
+ freight = int64(0)
|
|
|
+ }
|
|
|
+ order.TotalPrice += freight
|
|
|
notifyUrl := fmt.Sprintf("%s/v1/pay/%s/async/%s", beego.AppConfig.String("ApiHost"), EXCHANGE_TARGET, pay_model.PAYWAY_WEIXINPAY)
|
|
|
body := fmt.Sprintf("FOHOW玖玖-购买商品")
|
|
|
- payCode := sys_config.GetPayConfigByDepart(wxUser.Depart, true)
|
|
|
+ //获取paycode
|
|
|
+ payCode := sys_config.GetPayConfigByDepart(wxUser.Depart, false)
|
|
|
+
|
|
|
+ beego.BeeLogger.Warn("payCode--%s", payCode)
|
|
|
payData := wx_mp.GetPayData(wxUser.Openid, order.OrderId, order.PaiedPrice, body, notifyUrl, self.Ctx.Input.IP(), payCode)
|
|
|
|
|
|
//返回数据
|
|
|
@@ -314,11 +256,17 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source,
|
|
|
self.Data["json"] = &PayData{NeedWx: true, PayData: payData}
|
|
|
|
|
|
} else if source == order_model.SOURCE_APP {
|
|
|
+ freight := sys_config.GetFreight()
|
|
|
+ if order.TotalPrice >= sys_config.GetOrderLimit() {
|
|
|
+ freight = int64(0)
|
|
|
+ }
|
|
|
+ order.TotalPrice += freight
|
|
|
notifyUrl := fmt.Sprintf("%s/v1/pay/%s/async/%s", beego.AppConfig.String("ApiHost"), EXCHANGE_TARGET, pay_model.PAYWAY_WEIXINPAY)
|
|
|
body := fmt.Sprintf("FOHOW玖玖-购买商品")
|
|
|
+ //获取paycode
|
|
|
payCode := sys_config.GetPayConfigByDepart(wxUser.Depart, true)
|
|
|
payData := wx_mp.GetAppPayData(order.OrderId, order.PaiedPrice, body, notifyUrl, self.Ctx.Input.IP(), payCode)
|
|
|
-
|
|
|
+ beego.BeeLogger.Warn("pay_data --%v", payData)
|
|
|
//返回数据
|
|
|
type PayData struct {
|
|
|
NeedWx bool `json:"need_wx"`
|
|
|
@@ -335,8 +283,6 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source,
|
|
|
self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
}
|
|
|
payCode := sys_config.GetPayConfigByDepart(wxUser.Depart, true)
|
|
|
-
|
|
|
- //payData := wx_mp.GetPayData(wxGzh.GzhOpenId, order.OrderId , order.TotalPrice, body,notifyUrl, self.Ctx.Input.IP())
|
|
|
payData := wx_mp.GetPayData(wxGzh.GzhOpenId, order.OrderId, order.PaiedPrice, body, notifyUrl, self.Ctx.Input.IP(), payCode)
|
|
|
|
|
|
//返回数据
|
|
|
@@ -346,9 +292,60 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source,
|
|
|
}
|
|
|
self.Data["json"] = &PayData{NeedWx: true, PayData: payData}
|
|
|
}
|
|
|
+ default:
|
|
|
+ beego.BeeLogger.Error("pay way not match, payway:%s", payWay)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //如果是第二次支付
|
|
|
+ if source == order_model.SOURCE_XCX { //小程序微信支付
|
|
|
+
|
|
|
+ notifyUrl := fmt.Sprintf("%s/v1/pay/%s/async/%s", beego.AppConfig.String("ApiHost"), EXCHANGE_TARGET, pay_model.PAYWAY_WEIXINPAY)
|
|
|
+ body := fmt.Sprintf("FOHOW玖玖-购买商品")
|
|
|
+ payCode := sys_config.GetPayConfigByDepart(wxUser.Depart, true)
|
|
|
+ payData := wx_mp.GetPayData(wxUser.Openid, order.OrderId, order.PaiedPrice, body, notifyUrl, self.Ctx.Input.IP(), payCode)
|
|
|
+
|
|
|
+ //返回数据
|
|
|
+ type PayData struct {
|
|
|
+ NeedWx bool `json:"need_wx"`
|
|
|
+ PayData map[string]string `json:"pay_data"`
|
|
|
+ }
|
|
|
+ self.Data["json"] = &PayData{NeedWx: true, PayData: payData}
|
|
|
+
|
|
|
+ } else if source == order_model.SOURCE_APP {
|
|
|
+ notifyUrl := fmt.Sprintf("%s/v1/pay/%s/async/%s", beego.AppConfig.String("ApiHost"), EXCHANGE_TARGET, pay_model.PAYWAY_WEIXINPAY)
|
|
|
+ body := fmt.Sprintf("FOHOW玖玖-购买商品")
|
|
|
+ payCode := sys_config.GetPayConfigByDepart(wxUser.Depart, true)
|
|
|
+ payData := wx_mp.GetAppPayData(order.OrderId, order.PaiedPrice, body, notifyUrl, self.Ctx.Input.IP(), payCode)
|
|
|
+
|
|
|
+ //返回数据
|
|
|
+ type PayData struct {
|
|
|
+ NeedWx bool `json:"need_wx"`
|
|
|
+ PayData map[string]string `json:"pay_data"`
|
|
|
+ }
|
|
|
+ self.Data["json"] = &PayData{NeedWx: true, PayData: payData}
|
|
|
+
|
|
|
+ } else { //公众号微信支付
|
|
|
+
|
|
|
+ notifyUrl := fmt.Sprintf("%s/v1/pay/%s/async/%s", beego.AppConfig.String("ApiHost"), EXCHANGE_TARGET, pay_model.PAYWAY_WEIXINPAY)
|
|
|
+ body := fmt.Sprintf("FOHOW玖玖-购买商品")
|
|
|
+ wxGzh := user_model.GetWxUserGzhByWxUIdAndAppId(wxUser.Id, beego.AppConfig.String("WxMPAppId"), false)
|
|
|
+ if wxGzh == nil {
|
|
|
+ self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
+ }
|
|
|
+ payCode := sys_config.GetPayConfigByDepart(wxUser.Depart, true)
|
|
|
+
|
|
|
+ //payData := wx_mp.GetPayData(wxGzh.GzhOpenId, order.OrderId , order.TotalPrice, body,notifyUrl, self.Ctx.Input.IP())
|
|
|
+ payData := wx_mp.GetPayData(wxGzh.GzhOpenId, order.OrderId, order.PaiedPrice, body, notifyUrl, self.Ctx.Input.IP(), payCode)
|
|
|
+
|
|
|
+ //返回数据
|
|
|
+ type PayData struct {
|
|
|
+ NeedWx bool `json:"need_wx"`
|
|
|
+ PayData map[string]string `json:"pay_data"`
|
|
|
+ }
|
|
|
+ self.Data["json"] = &PayData{NeedWx: true, PayData: payData}
|
|
|
}
|
|
|
- self.ServeJSON()
|
|
|
}
|
|
|
+ self.ServeJSON()
|
|
|
}
|
|
|
|
|
|
//支付积分订单
|