|
|
@@ -22,25 +22,26 @@ const (
|
|
|
)
|
|
|
|
|
|
type OrderDetail struct {
|
|
|
- Id int64 `orm:"column(id);pk" json:"id"` // int(11)
|
|
|
- ProductId int64 `orm:"column(product_id)" json:"product_id"` // int(11)
|
|
|
- OrderId int64 `orm:"column(order_id)" json:"-"` // int(11)
|
|
|
- Send bool `orm:"column(is_zeng)" json:"send"`
|
|
|
- OrderNo string `orm:"column(order_no)" json:"order_id"` // varchar(64)
|
|
|
+ Id int64 `orm:"column(id);pk" json:"id"` // int(11)
|
|
|
+ ProductId int64 `orm:"column(product_id)" json:"product_id"` // int(11)
|
|
|
+ OrderId int64 `orm:"column(order_id)" json:"-"` // int(11)
|
|
|
+ Send bool `orm:"column(is_zeng)" json:"send"`
|
|
|
+ OrderNo string `orm:"column(order_no)" json:"order_id"` // varchar(64)
|
|
|
Price int64 `orm:"column(price)" json:"price"` // int(11)
|
|
|
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)
|
|
|
+ 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)
|
|
|
- Commend bool `orm:"column(commend)" json:"commend"`
|
|
|
- UnitRoboBalancePrice int64 `orm:"column(unit_robo_balance_price)" json:"unit_robo_balance_price"`
|
|
|
- Attrs string `orm:"-" json:"attrs"` // decimal(10,2)
|
|
|
- Depart int64 `orm:"column(depart)" json:"-"` // datetime
|
|
|
- Package bool `orm:"-" json:"package"`
|
|
|
- PacakageList []*ProductItem `orm:"-" json:"package_list"` // varchar(255)
|
|
|
+ Commend bool `orm:"column(commend)" json:"commend"`
|
|
|
+ UnitRoboBalancePrice int64 `orm:"column(unit_robo_balance_price)" json:"unit_robo_balance_price"`
|
|
|
+ RelateProductId int64 `orm:"column(relate_product_id)" json:"-"`
|
|
|
+ Attrs string `orm:"-" json:"attrs"` // decimal(10,2)
|
|
|
+ Depart int64 `orm:"column(depart)" json:"-"` // datetime
|
|
|
+ Package bool `orm:"-" json:"package"`
|
|
|
+ PacakageList []*ProductItem `orm:"-" json:"package_list"` // varchar(255)
|
|
|
}
|
|
|
|
|
|
func (self *OrderDetail) TableName() string {
|
|
|
@@ -48,13 +49,14 @@ func (self *OrderDetail) TableName() string {
|
|
|
}
|
|
|
|
|
|
//创建订单项
|
|
|
-func (self *OrderDetail) Create(oId string, orderId, pId, pPrice, unitRoboBalancePrice int64, pName, sizeName, colorName string,
|
|
|
+func (self *OrderDetail) Create(oId string, orderId, pId, relatePId, pPrice, unitRoboBalancePrice int64, pName, sizeName, colorName string,
|
|
|
pCount, depart int64) *OrderDetail {
|
|
|
item := &OrderDetail{
|
|
|
OrderNo: oId,
|
|
|
OrderId: orderId,
|
|
|
Count: pCount,
|
|
|
ProductId: pId,
|
|
|
+ RelateProductId: relatePId,
|
|
|
Price: pPrice,
|
|
|
UnitRoboBalancePrice: unitRoboBalancePrice,
|
|
|
ProductName: pName,
|
|
|
@@ -173,6 +175,32 @@ func GetDetailsByOrderIdAndPid(oId string, pId int64) (orderDetail *OrderDetail)
|
|
|
return orderDetail
|
|
|
}
|
|
|
|
|
|
+//根据订单Id,获取所有订单项
|
|
|
+func GetDetailsByOrderIdAndRelatePid(oId string, pId int64) int64 {
|
|
|
+ sql := `
|
|
|
+ SELECT
|
|
|
+ sum(nums) as count
|
|
|
+ FROM
|
|
|
+ order_details
|
|
|
+ WHERE
|
|
|
+ order_no =?
|
|
|
+ and
|
|
|
+ relate_product_id = ?
|
|
|
+ `
|
|
|
+ type Ret struct {
|
|
|
+ Count int64 `json:"count"`
|
|
|
+ }
|
|
|
+
|
|
|
+ var ret Ret
|
|
|
+ err := orm.NewOrm().Raw(sql, oId, pId).QueryRow(&ret)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ beego.BeeLogger.Warn("order_models.GetDetailsByOrderIdAndRelatePid(%d, %s) err[%s]", pId, oId, err)
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ return ret.Count
|
|
|
+}
|
|
|
+
|
|
|
//根据订单明细ID获取明细
|
|
|
func GetOrderDetailById(id int64) *OrderDetail {
|
|
|
detail := &OrderDetail{Id: id}
|