abiao лет назад: 5
Родитель
Сommit
7b1ad1e743

+ 26 - 36
go/gopath/src/fohow.com/apps/controllers/order_controller/order_controller.go

@@ -159,24 +159,9 @@ func (self *OrderController) MultipleCreate() {
 		if product == nil {
 			self.ReturnError(403, apps.NoExist, "", nil)
 		}
-
-		//获取商品属性详情
-		sizeName := ""
-		colorName := ""
-		if product.SizeId > 0 {
-			productSize := product_model.GetProductAttrValueById(product.SizeId)
-			if productSize != nil {
-				sizeName = productSize.Name
-			}
-		}
-		if product.ColorId > 0 {
-			productColor := product_model.GetProductAttrValueById(product.ColorId)
-			if productColor != nil {
-				colorName = productColor.Name
-			}
-		}
+		//创建订单明细
 		totalPrice += product.Price * cNums
-		go new(order_model.OrderDetail).Create(order.OrderId, order.Id, cartItem.ProductId, product.Price, product.RoboBalancePrice, product.Name, sizeName, colorName, cNums)
+		go CreateOrderDetails(product, order, cNums)
 	}
 	freight := order_model.FREIGHT
 	if totalPrice >= order_model.FREIGHT_LIMIT || beego.AppConfig.String("RunMode") == "dev" {
@@ -233,23 +218,9 @@ func (self *OrderController) MultShopCreate() {
 			self.ReturnError(403, apps.NoShopSale, "", nil)
 		}
 
-		//获取商品属性详情
-		sizeName := ""
-		colorName := ""
-		if product.SizeId > 0 {
-			productSize := product_model.GetProductAttrValueById(product.SizeId)
-			if productSize != nil {
-				sizeName = productSize.Name
-			}
-		}
-		if product.ColorId > 0 {
-			productColor := product_model.GetProductAttrValueById(product.ColorId)
-			if productColor != nil {
-				colorName = productColor.Name
-			}
-		}
+		//创建订单明细
 		totalPrice += product.Price * cNums
-		go new(order_model.OrderDetail).Create(order.OrderId, order.Id, pId, product.Price, product.RoboBalancePrice, product.Name, sizeName, colorName, cNums)
+		go CreateOrderDetails(product, order, cNums)
 	}
 	freight := order_model.FREIGHT
 	if totalPrice >= order_model.FREIGHT_LIMIT || beego.AppConfig.String("RunMode") == "dev" {
@@ -270,7 +241,7 @@ func (self *OrderController) MultShopCreate() {
 }
 
 func ClearCart(userId int64, orderId string) {
-	orderDetails := order_model.GetAllDetailsOrderId(orderId)
+	orderDetails := order_model.GetAllDetailsOrderId(orderId, true)
 	for _, item := range orderDetails {
 		cartItem := order_model.GetCartByUidAndPid(userId, item.ProductId)
 		if cartItem != nil {
@@ -289,7 +260,7 @@ func (self *OrderController) Detail() {
 		beego.BeeLogger.Error("order not exist id=[%s]", oId)
 		self.ReturnError(404, apps.OrderNotExist, "", nil)
 	}
-	orderList := order_model.GetAllDetailsOrderId(o.OrderId)
+	orderList := order_model.GetAllDetailsOrderId(o.OrderId, true)
 	for _, item := range orderList {
 		product := product_model.GetProductById(item.ProductId, cache)
 		if product == nil {
@@ -360,7 +331,7 @@ func (self *OrderController) List() {
 	count := order_model.GetUserOrdersCount(wxUId, status)
 
 	for _, item := range orders {
-		orderList := order_model.GetAllDetailsOrderId(item.OrderId)
+		orderList := order_model.GetAllDetailsOrderId(item.OrderId, true)
 		for _, orderItem := range orderList {
 			product := product_model.GetProductById(orderItem.ProductId, cache)
 			if product == nil {
@@ -485,3 +456,22 @@ func (self *OrderController) MerchantListCount() {
 	self.Data["json"] = &Ret{ListCount: count}
 	self.ServeJSON()
 }
+
+func CreateOrderDetails(product *product_model.Product, order *order_model.Order, cNums int64) {
+	//获取商品属性详情
+	sizeName := ""
+	colorName := ""
+	if product.SizeId > 0 {
+		productSize := product_model.GetProductAttrValueById(product.SizeId)
+		if productSize != nil {
+			sizeName = productSize.Name
+		}
+	}
+	if product.ColorId > 0 {
+		productColor := product_model.GetProductAttrValueById(product.ColorId)
+		if productColor != nil {
+			colorName = productColor.Name
+		}
+	}
+	go new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.Price, product.RoboBalancePrice, product.Name, sizeName, colorName, cNums)
+}

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

@@ -7,6 +7,7 @@ import (
 	// "github.com/astaxie/beego"
 
 	"fohow.com/apps"
+	"fohow.com/apps/helpers"
 	"fohow.com/libs/lib_redis"
 	"math"
 
@@ -24,7 +25,6 @@ import (
 	"time"
 	//"fohow.com/apps/models/product_model"
 	"fmt"
-	"fohow.com/apps/models/product_model"
 	"fohow.com/apps/models/user_model"
 )
 
@@ -354,19 +354,7 @@ func (self *PayController) wxPayExchangeAsync() {
 	}
 
 	//发放赠品
-	productId := int64(0)
-	if beego.AppConfig.String("RunMode") == "dev" {
-		productId = int64(91)
-	} else {
-		productId = order_model.SEND_PRODUCT_ID
-	}
-	//saleList := order_model.GetWxUserOrders(wxUser.Id)
-	//beego.BeeLogger.Error("en(saleList)=%d", len(saleList))
-	//	七月注册会员首单赠送赠品
-	if order.TotalPrice >= order_model.PROMOTION_TOTAL {
-		product := product_model.GetProductById(productId, false)
-		go order_model.SendCreate(order.OrderId, order.Id, productId, product.Price, product.Price, product.Name, int64(1))
-	}
+	go helpers.SetOrderPromotion(order.OrderId, wxUser.Id)
 	//已支付订单移除队列
 	cancelKey := lib_redis.GetOrderCancelList()
 	lib_redis.ThrowOutRedisList(cancelKey, order.OrderId)
@@ -384,7 +372,7 @@ func UpdatePdSaleNums(order *order_model.Order) {
 		return
 	}
 
-	orderDtList := order_model.GetAllDetailsOrderId(order.OrderId)
+	orderDtList := order_model.GetAllDetailsOrderId(order.OrderId, true)
 
 	if len(orderDtList) == 0 {
 		return

+ 2 - 14
go/gopath/src/fohow.com/apps/controllers/pay_controller/pay_exchange_controller.go

@@ -70,7 +70,7 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source s
 		//获取购物商品明细
 		buy_price_total := int64(0)
 		total_price := int64(0)
-		list := order_model.GetAllDetailsOrderId(order.OrderId)
+		list := order_model.GetAllDetailsOrderId(order.OrderId, true)
 		for _, item := range list {
 			//商品状态
 			product := product_model.GetProductById(item.ProductId, false)
@@ -147,19 +147,7 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source s
 			order.Source = source
 			order.Save()
 			//发放赠品
-			productId := int64(0)
-			if beego.AppConfig.String("RunMode") == "dev" {
-				productId = int64(91)
-			} else {
-				productId = order_model.SEND_PRODUCT_ID
-			}
-			//saleList := order_model.GetWxUserOrders(wxUser.Id)
-			//beego.BeeLogger.Error("en(saleList)=%d", len(saleList))
-			//	七月注册会员首单赠送赠品
-			if order.TotalPrice >= order_model.PROMOTION_TOTAL {
-				product := product_model.GetProductById(productId, false)
-				go order_model.SendCreate(order.OrderId, order.Id, productId, product.Price, product.Price, product.Name, int64(1))
-			}
+			go helpers.SetOrderPromotion(order.OrderId, wxUser.Id)
 			//已支付订单移除未支付队列
 			cancelKey := lib_redis.GetOrderCancelList()
 			lib_redis.ThrowOutRedisList(cancelKey, order.OrderId)

+ 11 - 2
go/gopath/src/fohow.com/apps/models/order_model/order_detail.go

@@ -10,6 +10,7 @@ import (
 	// "strings"
 	"time"
 
+	"fohow.com/cache"
 	"github.com/astaxie/beego/orm"
 	// "github.com/uuid"
 	// "fohow.com/apps/models/shop_model"
@@ -97,13 +98,21 @@ func (self *OrderDetail) Save() bool {
 }
 
 //根据订单Id,获取所有订单项
-func GetAllDetailsOrderId(oId string) (items []*OrderDetail) {
+func GetAllDetailsOrderId(oId string, useCache bool) (items []*OrderDetail) {
+
+	k := fmt.Sprintf("order_model.GetAllDetailsOrderId(%s)", oId)
+	if useCache {
+		if ret, ok := cache.Cache.Get(k).([]*OrderDetail); ok {
+			return ret
+		}
+	}
 	item := new(OrderDetail)
 	if _, err := orm.NewOrm().QueryTable(item).
 		Filter("order_no", oId).All(&items); err != nil {
-		beego.BeeLogger.Debug("get order[%s] items err=[%s]", oId, err)
+		beego.BeeLogger.Debug("get order details[%s] items err=[%s]", oId, err)
 		return nil
 	}
+	cache.Cache.Put(k, items, 60*time.Minute)
 	return items
 }
 

+ 1 - 1
go/gopath/src/fohow.com/routers/routes.go

@@ -276,7 +276,7 @@ func init() {
 	//批量调整 删除购物车商品项
 	beego.Router("/v1/cart/mult_delele", &order_controller.OrderController{}, "post:MultChangeItemDelete")
 
-	//----------------购物车 -------------------
+	//----------------店铺专区-------------------
 	//店铺专区下单
 	beego.Router("/v1/shop/order_mul", &order_controller.OrderController{}, "post:MultShopCreate")