Просмотр исходного кода

订单明细增加规格明细

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

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

@@ -211,6 +211,19 @@ func (self *OrderController) GetCartList() {
 		if wxUser != nil {
 			wxUser.Head = user_model.GetFullImgUrl(wxUser.Head)
 		}
+		//获取商品属性详情
+		if product.SizeId > 0 {
+			productSize := product_model.GetProductAttrValueById(product.SizeId)
+			if productSize != nil {
+				item.SizeName = productSize.Name
+			}
+		}
+		if product.ColorId > 0 {
+			productColor := product_model.GetProductAttrValueById(product.ColorId)
+			if productColor != nil {
+				item.ColorName = productColor.Name
+			}
+		}
 		item.Cover = product_model.GetCoverByPId(item.ProductId, cache)
 		item.OriginalPrice = product.Price
 		item.ProductName = product.Name

+ 33 - 3
go/gopath/src/fohow.com/apps/controllers/order_controller/order_controller.go

@@ -56,6 +56,21 @@ func (self *OrderController) Create() {
 		}
 		orderType = order_model.ORDER_TYPE_SEKILL
 	}
+	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 {
+			sizeName = productColor.Name
+		}
+	}
 	totalPrice := product.Price * count
 	//小兔微信,测试微信支付
 	if wxUId == 76 {
@@ -74,7 +89,7 @@ func (self *OrderController) Create() {
 	order.Save()
 	//创建订单明细
 	go new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.Price, product.RoboBalancePrice, product.Name,
-		count)
+		sizeName, colorName, count)
 
 	type Order struct {
 		OrderId string `json:"order_id"`
@@ -138,9 +153,24 @@ 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 {
+				sizeName = productColor.Name
+			}
+		}
 		totalPrice += product.Price * cNums
-		go new(order_model.OrderDetail).Create(order.OrderId, order.Id, cartItem.ProductId, product.Price, product.RoboBalancePrice, product.Name,
-			cNums)
+		go new(order_model.OrderDetail).Create(order.OrderId, order.Id, cartItem.ProductId, product.Price, product.RoboBalancePrice, product.Name, sizeName, colorName, cNums)
 	}
 	freight := order_model.FREIGHT
 	if totalPrice >= order_model.FREIGHT_LIMIT || beego.AppConfig.String("RunMode") == "dev" {

+ 2 - 0
go/gopath/src/fohow.com/apps/models/order_model/cart.go

@@ -26,6 +26,8 @@ type Cart struct {
 	Count         int64     `orm:"column(nums)"                                       json:"count"` // int(11)
 	IsBuy         bool      `orm:"column(is_buy)" 			json:"is_under_seckill"`
 	ProductName   string    `orm:"-"     json:"product_name"`   // decimal(10,2)
+	SizeName      string    `orm:"-"     json:"size_name"`      //   varchar(64)
+	ColorName     string    `orm:"-"     json:"color_name"`     //  varchar(64)
 	Cover         string    `orm:"-"     json:"cover"`          // decimal(10,2)
 	OriginalPrice int64     `orm:"-"     json:"original_price"` // decimal(10,2)
 	Attrs         string    `orm:"-"     json:"attrs"`          // decimal(10,2)

+ 5 - 1
go/gopath/src/fohow.com/apps/models/order_model/order_detail.go

@@ -27,6 +27,8 @@ type OrderDetail struct {
 	CreatedAt            time.Time `orm:"column(created_at);null;auto_now_add;type(datetime)" json:"-"`            // datetime
 	Count                int64     `orm:"column(nums)"                                       json:"count"`         // int(11)
 	ProductName          string    `orm:"column(product_name)"                                json:"product_name"` // varchar(255)
+	SizeName             string    `orm:"column(size_name)"                                json:"size_name"`       // varchar(255)
+	ColorName            string    `orm:"column(color_name)"                                json:"color_name"`     // varchar(255)
 	Cover                string    `orm:"-"     json:"cover"`                                                      // decimal(10,2)
 	OriginalPrice        float64   `orm:"-"     json:"original_price"`                                             // decimal(10,2)
 	UnitRoboBalancePrice int64     `orm:"column(unit_robo_balance_price)"                     json:"unit_robo_balance_price"`
@@ -38,7 +40,7 @@ func (self *OrderDetail) TableName() string {
 }
 
 //创建订单项
-func (self *OrderDetail) Create(oId string, orderId, pId, pPrice, unitRoboBalancePrice int64, pName string,
+func (self *OrderDetail) Create(oId string, orderId, pId, pPrice, unitRoboBalancePrice int64, pName, sizeName, colorName string,
 	pCount int64) *OrderDetail {
 	item := &OrderDetail{
 		OrderNo:              oId,
@@ -48,6 +50,8 @@ func (self *OrderDetail) Create(oId string, orderId, pId, pPrice, unitRoboBalanc
 		Price:                pPrice,
 		UnitRoboBalancePrice: unitRoboBalancePrice,
 		ProductName:          pName,
+		SizeName:             sizeName,
+		ColorName:            colorName,
 		Send:                 false,
 	}
 	id, err := orm.NewOrm().Insert(item)

+ 11 - 0
go/gopath/src/fohow.com/apps/models/product_model/product_attr.go

@@ -96,3 +96,14 @@ func GetProductAttrKey(kId int64) (pk *ProductAttrKey) {
 	}
 	return pk
 }
+
+// 根据product_attrs表Id查找记录
+func GetProductAttrValueById(id int64) (pdAttr *ProductAttr) {
+	pdAttr = &ProductAttr{}
+	if err := orm.NewOrm().QueryTable(pdAttr).Filter("id", id).Limit(1).
+		One(pdAttr); err != nil {
+		beego.BeeLogger.Error("get product attr  by record_id=%s err=%s", id, err)
+		return nil
+	}
+	return pdAttr
+}