8 Revize 8425ad46d0 ... d1091bd6b2

Autor SHA1 Zpráva Datum
  abiao d1091bd6b2 order detail list před 1 rokem
  abiao e476be72fa SaleNumsMap před 1 rokem
  abiao e6ac72516c total_price před 1 rokem
  abiao c0e8d6b2d7 orderLimt před 1 rokem
  abiao f01b317474 orderLimt před 1 rokem
  abiao 5dc853b997 orderLimt před 1 rokem
  abiao 0ce0a08f1d Order QueryPayInfo před 1 rokem
  abiao 5db7d139f9 Order QueryPayInfo před 1 rokem

+ 2 - 0
go/gopath/src/fohow.com/apps/controllers/order_controller/order_controller.go

@@ -843,6 +843,8 @@ func (self *OrderController) Operate() {
 				self.ReturnError(403, apps.OrderRefundError, "", nil)
 			}
 		}
+		//已支付订单退商品库存
+		helpers.UpdatePdSaleNums(o, 1)
 	} else if operate == order_model.OPERATE_CONFIRM && o.Status == order_model.STATUS_DISPATCH {
 		o.Status = order_model.STATUS_COMPLETE
 		o.ReceiveTime = time.Now()

+ 2 - 20
go/gopath/src/fohow.com/apps/controllers/pay_controller/after_pay_controller.go

@@ -189,8 +189,8 @@ func (self *PayController) wxPayExchangeAsync() {
 	//已支付订单移除队列
 	cancelKey := lib_redis.GetOrderCancelList()
 	lib_redis.ThrowOutRedisList(cancelKey, order.OrderId)
-	//更新商品售量
-	UpdatePdSaleNums(order)
+	//0 减少商品售量
+	helpers.UpdatePdSaleNums(order, 0)
 	//赠品写入订单
 	helpers.PresentTransferToOrder(order.OrderId, order.WxUserId)
 
@@ -200,24 +200,6 @@ func (self *PayController) wxPayExchangeAsync() {
 	return
 }
 
-// 更新已售数量
-func UpdatePdSaleNums(order *order_model.Order) {
-	if order == nil {
-		return
-	}
-
-	orderDtList := order_model.GetAllDetailsOrderId(order.OrderId, false)
-
-	if len(orderDtList) == 0 {
-		return
-	}
-	SaleNumsMap := make(map[int64]int64)
-	for _, item := range orderDtList {
-		SaleNumsMap[item.ProductId] = item.Count
-	}
-	order_model.UpdateSaleNums(SaleNumsMap)
-}
-
 // 微信余额充值
 func (self *PayController) wxPayCashczAsync() {
 

+ 156 - 25
go/gopath/src/fohow.com/apps/controllers/pay_controller/pay_exchange_controller.go

@@ -88,8 +88,6 @@ func (self *PayController) payExchange(oId, payWay, returnUrl, source, remark st
 		self.ReturnError(403, apps.NotUnPay, "", nil)
 	}
 	SaleNumsMap := make(map[int64]int64)
-
-	storeMap := make(map[int64]int64)
 	specialPromotion = order.SpecialPro
 	//支付方式判断
 	if order.OrderType == order_model.ORDER_TYPE_SHOP && payWay == pay_model.PAYWAY_BALANCE {
@@ -171,17 +169,9 @@ func (self *PayController) payExchange(oId, payWay, returnUrl, source, remark st
 		} else {
 			SaleNumsMap[product.Id] = item.Count
 		}
-
-		if _, ok := storeMap[product.Id]; ok {
-			storeMap[product.Id] = item.Count + storeMap[product.Id]
-		} else {
-			storeMap[product.Id] = item.Count
-		}
-
 	}
 	dis_amount := order.DisAmount
-
-	resultStore, prdName := FindNotEnoughPrd(storeMap)
+	resultStore, prdName := FindNotEnoughPrd(SaleNumsMap)
 	if resultStore {
 		self.ReturnError(403, []string{apps.ProductStockNotEnough[0], fmt.Sprintf("%s商品库存不足", prdName)}, "", nil)
 	}
@@ -323,7 +313,7 @@ func (self *PayController) payExchange(oId, payWay, returnUrl, source, remark st
 			cancelKey := lib_redis.GetOrderCancelList()
 			lib_redis.ThrowOutRedisList(cancelKey, order.OrderId)
 			//更新已售数量
-			order_model.UpdateSaleNums(SaleNumsMap)
+			helpers.UpdatePdSaleNums(order, 0)
 			//赠品写入订单
 			helpers.PresentTransferToOrder(order.OrderId, wxUId)
 			//go CreateOrderNotify(order, product)
@@ -518,8 +508,7 @@ func (self *PayController) payCentExchange(oId, returnUrl, source, remark string
 		total_price += product.Price * item.Count
 		SaleNumsMap[product.Id] = item.Count
 	}
-	storeMap := SaleNumsMap
-	resultStore, prdName := FindNotEnoughPrd(storeMap)
+	resultStore, prdName := FindNotEnoughPrd(SaleNumsMap)
 	if resultStore {
 		self.ReturnError(403, []string{apps.ProductStockNotEnough[0], fmt.Sprintf("%s商品库存不足", prdName)}, "", nil)
 	}
@@ -570,9 +559,8 @@ func (self *PayController) payCentExchange(oId, returnUrl, source, remark string
 	//已支付订单移除未支付队列
 	cancelKey := lib_redis.GetOrderCancelList()
 	lib_redis.ThrowOutRedisList(cancelKey, order.OrderId)
-	//更新已售数量
-	order_model.UpdateSaleNums(SaleNumsMap)
-
+	//0 减少 -- 更新已售数量
+	helpers.UpdatePdSaleNums(order, 0)
 	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})
@@ -583,22 +571,25 @@ func (self *PayController) payCentExchange(oId, returnUrl, source, remark string
 // 获取库存不足商品
 func FindNotEnoughPrd(storeMap map[int64]int64) (bool, string) {
 	//判断商品库存
+	tempStoreMap := make(map[int64]int64) // 创建一个临时map来存储修改后的库存信息
+
 	for pId, nums := range storeMap {
 		product := product_model.GetProductById(pId, true)
 		if product.Package {
-			//beego.BeeLogger.Error("product id %d", product.Id)
+			//如果产品是一个包装,则遍历包装中的每个项目
 			packageList := product_model.GetPackageList(pId, true)
 			for _, one := range packageList {
-				if _, ok := storeMap[one.ItemId]; ok {
-					//基本商品存在
-					storeMap[one.ItemId] = storeMap[one.ItemId] + nums*one.Nums
-				} else {
-					storeMap[one.ItemId] = nums * one.Nums
-				}
+				//累加或设置基本商品的库存数量
+				tempStoreMap[one.ItemId] += nums * one.Nums
 			}
+		} else {
+			//如果产品不是包装,则直接复制到临时map
+			tempStoreMap[pId] = nums
 		}
 	}
-	for r_pid, r_nums := range storeMap {
+
+	//遍历临时库存map来检查是否有不足的商品
+	for r_pid, r_nums := range tempStoreMap {
 		product := product_model.GetProductById(r_pid, false)
 		if product.Count > int64(0) && product.Count < (r_nums+product.SaleNums) {
 			return true, product.Name
@@ -621,3 +612,143 @@ func FindMaxPaymentMethod(total_weixin, totalCoupon, paiedCash int64) string {
 
 	return paymentMethod
 }
+
+type PaymentDetails struct {
+	FirstPay   bool  // 是否首次支付
+	OrderLimit int64 // 免运费订单金额
+	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 == nil {
+		self.ReturnError(403, apps.OrderNotExist, "", nil)
+	}
+
+	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)
+	paiedCash := int64(0) //抵扣佣金
+	firstPay := true
+	//店长折扣
+	dis_amount := order.DisAmount
+	//若账户有提货券则优先抵扣提货券
+	totalCoupon := 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 !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()
+	orderLimt := sys_config.GetOrderLimit()
+	//第一次支付已更新支付方式,第一次支付才计算支付金额
+	if len(order.PayWay) <= 0 {
+		//计算运费
+		if total_price >= orderLimt || pickWay == order_model.PICK_SHOP {
+			freight = int64(0)
+		}
+		tp := total_price
+		//抵扣银豆
+		if paiedSilver > tp {
+			paiedSilver = tp
+		}
+		tp -= paiedSilver
+		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
+		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
+		totalCoupon = order.CouponPrice
+		total_weixin = order.PaiedPrice
+		paiedCash = order.PaiedCash
+	}
+
+	details.FirstPay = firstPay
+	details.OrderLimit = orderLimt
+	details.Freight = freight
+	details.TotalPrice = total_price
+	details.PayBalance = paiedCash
+	details.PaySilver = paiedSilver
+	details.PayCoupon = totalCoupon
+	details.Discount = dis_amount
+	details.ShouldPay = total_weixin
+
+	self.Data["json"] = details
+	self.ServeJSON()
+}

+ 16 - 0
go/gopath/src/fohow.com/apps/helpers/promotion_helper.go

@@ -806,3 +806,19 @@ func CreateShopApplyOrder(shopAppplyId int64) {
 	beego.BeeLogger.Warn("----------------end generate shopapply order ---%d ", shopApply.Id)
 	return
 }
+
+// 更新已售数量
+func UpdatePdSaleNums(order *order_model.Order, dirction int) {
+	if order == nil {
+		return
+	}
+	orderDtList := order_model.GetAllDetailsOrderId(order.OrderId, false)
+	if len(orderDtList) == 0 {
+		return
+	}
+	SaleNumsMap := make(map[int64]int64)
+	for _, item := range orderDtList {
+		SaleNumsMap[item.ProductId] = item.Count
+	}
+	order_model.UpdateSaleNums(SaleNumsMap, dirction)
+}

+ 14 - 10
go/gopath/src/fohow.com/apps/models/order_model/order.go

@@ -733,32 +733,36 @@ func GetPaiedOrderByWxUIdAndPayWayLimitOne(wxUserId int64, payWay string, useCac
 }
 
 // 更新商品已售数量
-func UpdateSaleNums(saleProducts map[int64]int64) bool {
-
+func UpdateSaleNums(saleProducts map[int64]int64, direction int) bool {
 	for pId, nums := range saleProducts {
-
-		//beego.BeeLogger.Error("pId,Nums %d--%d", pId, nums)
-
 		product := product_model.GetProductById(pId, true)
 		if product == nil {
 			continue
 		}
-		product.SaleNums += nums
-		product.Save()
-		//套装商品拆分更新销量
+		// 套装商品拆分更新销量
 		if product.Package {
 			package_list := product_model.GetPackageList(product.Id, true)
 			for _, item := range package_list {
 				item_pd := product_model.GetProductById(item.ItemId, true)
 				count := item.Nums * nums
-				item_pd.SaleNums += count
+				if direction == 0 {
+					item_pd.SaleNums += count
+				} else if direction == 1 {
+					item_pd.SaleNums -= count
+				}
 				item_pd.Save()
 			}
+		} else {
+			if direction == 0 {
+				product.SaleNums += nums
+			} else if direction == 1 {
+				product.SaleNums -= nums
+			}
+			product.Save()
 		}
 	}
 	return true
 }
-
 func GetDistrictOrders(tcBl, page, perPage int64, tcArea string) (orders []*Order) {
 
 	beginSql := "select order_id,contact,paied_at, "

+ 2 - 0
go/gopath/src/fohow.com/routers/routes.go

@@ -128,6 +128,8 @@ func init() {
 	beego.Router("/v1/order_detail/:detail_id/commend", &order_controller.OrderController{}, "put:OrderCommend")
 	//----------- 支付相关 -----------
 	beego.Router("/v1/pay", &pay_controller.PayController{}, "post,get:Pay")
+	beego.Router("/v1/pay/query", &pay_controller.PayController{}, "post,get:QueryPayInfo")
+
 	beego.Router("/v1/pay/:target:string/async/:payway:string", &pay_controller.PayController{}, "post,get:PayAsync")
 	//生成充值提货券订单
 	beego.Router("/v1/balance_order/generate", &pay_controller.PayController{}, "post:CreateBalanceOrder")