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

promotion conditon edit for relate_product_id

abiao лет назад: 4
Родитель
Сommit
0c4cbad6ac

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

@@ -121,7 +121,7 @@ func (self *OrderController) Create() {
 	}
 	order.Save()
 	//创建订单明细
-	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.RelateProductId, product.Price, product.RoboBalancePrice, product.Name,
 		sizeName, colorName, count, wxUser.Depart)
 
 	//未支付订单加入取消队列
@@ -645,7 +645,7 @@ func CreateOrderDetails(product *product_model.Product, order *order_model.Order
 			colorName = productColor.Name
 		}
 	}
-	new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.Price, product.RoboBalancePrice, product.Name, sizeName, colorName, cNums, depart)
+	new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, product.RoboBalancePrice, product.Name, sizeName, colorName, cNums, depart)
 }
 
 //用户评论订单明细

+ 31 - 16
go/gopath/src/fohow.com/apps/helpers/promotion_helper.go

@@ -59,26 +59,35 @@ func SetOrderPromotion(orderId string, wxUid int64) {
 		nums5 := int64(99)
 		nums6 := int64(99)
 		if item.Prod1 > 0 {
+			prd := product_model.GetProductById(item.Prod1, true)
 			nums1 = int64(0)
-			detail1 := order_model.GetDetailsByOrderIdAndPid(orderId, item.Prod1)
-			if detail1 != nil && item.Prod1 > 0 && item.Nums1 > 0 {
-				nums1 = int64(detail1.Count / item.Nums1)
+			if prd != nil {
+				detail_nums1 := order_model.GetDetailsByOrderIdAndRelatePid(orderId, prd.RelateProductId)
+				if detail_nums1 > int64(0) && item.Prod1 > 0 && item.Nums1 > 0 {
+					nums1 = int64(detail_nums1 / item.Nums1)
+				}
 			}
 		}
 
 		if item.Prod2 > 0 {
+			prd := product_model.GetProductById(item.Prod2, true)
 			nums2 = int64(0)
-			detail2 := order_model.GetDetailsByOrderIdAndPid(orderId, item.Prod2)
-			if detail2 != nil && item.Prod2 > 0 && item.Nums2 > 0 {
-				nums2 = int64(detail2.Count / item.Nums2)
+			if prd != nil {
+				detail_nums2 := order_model.GetDetailsByOrderIdAndRelatePid(orderId, prd.RelateProductId)
+				if detail_nums2 > int64(0) && item.Prod2 > 0 && item.Nums2 > 0 {
+					nums2 = int64(detail_nums2 / item.Nums2)
+				}
 			}
 		}
 
 		if item.Prod3 > 0 {
-			nums3 = int64(0)
-			detail3 := order_model.GetDetailsByOrderIdAndPid(orderId, item.Prod3)
-			if detail3 != nil && item.Prod3 > 0 && item.Nums3 > 0 {
-				nums3 = int64(detail3.Count / item.Nums3)
+			prd := product_model.GetProductById(item.Prod3, true)
+			if prd != nil {
+				nums3 = int64(0)
+				detail_nums3 := order_model.GetDetailsByOrderIdAndRelatePid(orderId, prd.RelateProductId)
+				if detail_nums3 > 0 && item.Prod3 > 0 && item.Nums3 > 0 {
+					nums3 = int64(detail_nums3 / item.Nums3)
+				}
 			}
 		}
 		if item.MinTotal > 0 {
@@ -86,18 +95,24 @@ func SetOrderPromotion(orderId string, wxUid int64) {
 		}
 
 		if item.Prod4 > 0 {
+			prd := product_model.GetProductById(item.Prod4, true)
 			nums5 = int64(0)
-			detail4 := order_model.GetDetailsByOrderIdAndPid(orderId, item.Prod4)
-			if detail4 != nil && item.Prod4 > 0 && item.Nums4 > 0 {
-				nums5 = int64(detail4.Count / item.Nums4)
+			if prd != nil {
+				detail_nums4 := order_model.GetDetailsByOrderIdAndRelatePid(orderId, prd.RelateProductId)
+				if detail_nums4 > 0 && item.Prod4 > 0 && item.Nums4 > 0 {
+					nums5 = int64(detail_nums4 / item.Nums4)
+				}
 			}
 		}
 
 		if item.Prod5 > 0 {
+			prd := product_model.GetProductById(item.Prod5, true)
 			nums6 = int64(0)
-			detail5 := order_model.GetDetailsByOrderIdAndPid(orderId, item.Prod5)
-			if detail5 != nil && item.Prod5 > 0 && item.Nums5 > 0 {
-				nums6 = int64(detail5.Count / item.Nums5)
+			if prd != nil {
+				detail_nums5 := order_model.GetDetailsByOrderIdAndRelatePid(orderId, prd.RelateProductId)
+				if detail_nums5 > 0 && item.Prod5 > 0 && item.Nums5 > 0 {
+					nums6 = int64(detail_nums5 / item.Nums5)
+				}
 			}
 		}
 

+ 41 - 13
go/gopath/src/fohow.com/apps/models/order_model/order_detail.go

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

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

@@ -64,10 +64,10 @@ func GetEffetivePromotions(queryDate time.Time, orderType int64, useCache bool)
 	sql := `
 		select * from
 		promotions
-		where DATE_FORMAT(DATE_ADD(begin_time,INTERVAL 8 HOUR),'%Y-%m-%d') <= ? and DATE_FORMAT(DATE_ADD(end_time,INTERVAL 8 HOUR),'%Y-%m-%d') >= ? and order_type = ? and is_enable = 1 ;
+		where DATE_ADD(begin_time,INTERVAL 8 HOUR) <= ? and DATE_ADD(end_time,INTERVAL 8 HOUR) >= ? and order_type = ? and is_enable = 1 ;
 		`
 
-	_, err := orm.NewOrm().Raw(sql, queryDate.Format("2006-01-02"), queryDate.Format("2006-01-02"), orderType).QueryRows(&list)
+	_, err := orm.NewOrm().Raw(sql, queryDate.Format("2006-01-02 15:04:05"), queryDate.Format("2006-01-02 15:04:05"), orderType).QueryRows(&list)
 	if err != nil {
 		beego.BeeLogger.Warn("product_model.GetSeckillPromotions(%s) err=%s", queryDate.Format("2006-01-02"), err)
 		return nil