|
|
@@ -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
|
|
|
+}
|