Переглянути джерело

product package item develop---order base dt add send

abiao 4 роки тому
батько
коміт
b3c53a6376

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

@@ -121,8 +121,9 @@ func (self *OrderController) Create() {
 	}
 	order.Save()
 	//创建订单明细
-	go new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.Price, product.RoboBalancePrice, product.Name,
+	new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.Price, product.RoboBalancePrice, product.Name,
 		sizeName, colorName, count, wxUser.Depart)
+
 	//未支付订单加入取消队列
 	cancelKey := lib_redis.GetOrderCancelList()
 	lib_redis.ThrowInRedisList(cancelKey, order.OrderId)

+ 7 - 0
go/gopath/src/fohow.com/apps/models/order_model/order_detail.go

@@ -67,6 +67,10 @@ func (self *OrderDetail) Create(oId string, orderId, pId, pPrice, unitRoboBalanc
 		return nil
 	}
 	item.Id = id
+	if item != nil {
+		go GenerateOrderDtItem(item)
+	}
+
 	return item
 }
 
@@ -90,6 +94,9 @@ func SendCreate(oId string, orderId, pId, pPrice, unitRoboBalancePrice int64, pN
 		return nil
 	}
 	item.Id = id
+	if item != nil {
+		go GenerateOrderDtItem(item)
+	}
 	return item
 }
 

+ 47 - 7
go/gopath/src/fohow.com/apps/models/order_model/order_dt_item.go

@@ -1,6 +1,9 @@
 package order_model
 
 import (
+	"fohow.com/apps/models/product_model"
+	"github.com/astaxie/beego"
+	"github.com/astaxie/beego/orm"
 	"time"
 )
 
@@ -9,13 +12,14 @@ const (
 )
 
 type OrderDtItem struct {
-	Id        int64     `orm:"column(id);pk"                json:"id"`                  // int(11)
-	OrderId   int64     `orm:"column(order_id)"             json:"order_id"`            // int(11)
-	OrderNo   string    `orm:"column(order_no);null"        json:"order_no"`            // varchar(64)
-	OrderDtId int64     `orm:"column(order_dt_id)"          json:"order_dt_id"`         // int(11)
-	ProductId int64     `orm:"column(product_id)"           json:"product_id"`          // int(11)
-	Title     string    `orm:"column(title);null"           json:"title"`               // varchar(64)
-	Nums      int64     `orm:"column(nums);null"            json:"nums"`                // tinyint(1)
+	Id        int64     `orm:"column(id);pk"                json:"id"`          // int(11)
+	OrderId   int64     `orm:"column(order_id)"             json:"order_id"`    // int(11)
+	OrderNo   string    `orm:"column(order_no);null"        json:"order_no"`    // varchar(64)
+	OrderDtId int64     `orm:"column(order_dt_id)"          json:"order_dt_id"` // int(11)
+	ProductId int64     `orm:"column(product_id)"           json:"product_id"`  // int(11)
+	Title     string    `orm:"column(title);null"           json:"title"`       // varchar(64)
+	Nums      int64     `orm:"column(nums);null"            json:"nums"`        // tinyint(1)
+	Send      bool      `orm:"column(send)"                                json:"send"`
 	CreatedAt time.Time `orm:"column(created_at);auto_now_add;type(datetime)" json:"-"` // datetime
 	UpdatedAt time.Time `orm:"column(updated_at);auto_now;type(datetime)"     json:"-"` // datetime
 }
@@ -31,3 +35,39 @@ type ProductItem struct {
 	ItemTitle string `orm:"column(item_title);null"      json:"item_title"` // varchar(64)
 	Nums      int64  `orm:"column(nums);null"            json:"nums"`       // tinyint(1)
 }
+
+//创建订单明细项
+func (self *OrderDtItem) Create(orderNo, title string, pId, pCount, orderId, orderDtId int64, send bool) *OrderDtItem {
+	item := &OrderDtItem{
+		OrderNo:   orderNo,
+		OrderId:   orderId,
+		OrderDtId: orderDtId,
+		ProductId: pId,
+		Title:     title,
+		Nums:      pCount,
+		Send:      send,
+	}
+	id, err := orm.NewOrm().Insert(item)
+	if err != nil {
+		beego.BeeLogger.Error("insert cart item err=[%s]", err)
+		return nil
+	}
+	item.Id = id
+	return item
+}
+
+//生成订单明细
+func GenerateOrderDtItem(detail_item *OrderDetail) error {
+	product := product_model.GetProductById(detail_item.ProductId, true)
+	if product.Package {
+		product_list := product_model.GetPackageList(product.Id, true)
+		for _, pd := range product_list {
+			count := detail_item.Count * pd.Nums
+			new(OrderDtItem).Create(detail_item.OrderNo, pd.ItemTitle, pd.Id, count, detail_item.OrderId, detail_item.Id, detail_item.Send)
+		}
+	} else {
+		new(OrderDtItem).Create(detail_item.OrderNo, product.Name, product.Id, detail_item.Count, detail_item.OrderId, detail_item.Id, detail_item.Send)
+	}
+	beego.BeeLogger.Warn("orderdtbase  GenerateOrderDtItem ")
+	return nil
+}