Explorar el Código

promotion add products

abiao hace 4 años
padre
commit
1105ed4b24

+ 33 - 1
go/gopath/src/fohow.com/apps/helpers/promotion_helper.go

@@ -56,6 +56,8 @@ func SetOrderPromotion(orderId string, wxUid int64) {
 		nums2 := int64(99)
 		nums3 := int64(99)
 		nums4 := int64(99)
+		nums5 := int64(99)
+		nums6 := int64(99)
 		if item.Prod1 > 0 {
 			nums1 = int64(0)
 			detail1 := order_model.GetDetailsByOrderIdAndPid(orderId, item.Prod1)
@@ -81,9 +83,25 @@ func SetOrderPromotion(orderId string, wxUid int64) {
 		}
 		if item.MinTotal > 0 {
 			nums4 = int64(order.TotalPrice / item.MinTotal)
+		}
+
+		if item.Prod4 > 0 {
+			nums5 = int64(0)
+			detail4 := order_model.GetDetailsByOrderIdAndPid(orderId, item.Prod3)
+			if detail4 != nil && item.Prod4 > 0 && item.Nums4 > 0 {
+				nums5 = int64(detail4.Count / item.Nums4)
+			}
+		}
 
+		if item.Prod5 > 0 {
+			nums6 = int64(0)
+			detail5 := order_model.GetDetailsByOrderIdAndPid(orderId, item.Prod5)
+			if detail5 != nil && item.Prod5 > 0 && item.Nums5 > 0 {
+				nums6 = int64(detail5.Count / item.Nums4)
+			}
 		}
-		val := []int64{nums1, nums2, nums3, nums4}
+
+		val := []int64{nums1, nums2, nums3, nums4, nums5, nums6}
 		nums = min(val...)
 		if !item.IsMore {
 			val := []int64{nums, 1}
@@ -120,6 +138,20 @@ func SetOrderPromotion(orderId string, wxUid int64) {
 				product := product_model.GetProductById(item.SendProd3, true)
 				go order_model.SendCreate(order.OrderId, order.Id, product.Id, product.Price, product.Price, product.Name, sendNums3)
 			}
+
+			if item.SendProd4 > 0 && item.SendNums4 > 0 {
+				sendNums4 := nums * item.SendNums4
+				//赠送赠品1
+				product := product_model.GetProductById(item.SendProd4, true)
+				go order_model.SendCreate(order.OrderId, order.Id, product.Id, product.Price, product.Price, product.Name, sendNums4)
+			}
+
+			if item.SendProd5 > 0 && item.SendNums5 > 0 {
+				sendNums5 := nums * item.SendNums5
+				//赠送赠品1
+				product := product_model.GetProductById(item.SendProd5, true)
+				go order_model.SendCreate(order.OrderId, order.Id, product.Id, product.Price, product.Price, product.Name, sendNums5)
+			}
 			//赠送积分 or 代办费
 			if item.Cash > 0 {
 				totalCash := nums * item.Cash

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

@@ -29,12 +29,20 @@ type Promotion struct {
 	Nums2     int64     `orm:"column(nums2)"                           json:"nums2"`         // int(11)
 	Prod3     int64     `orm:"column(prod3)"                           json:"prod3"`         // int(11)
 	Nums3     int64     `orm:"column(nums3)"                           json:"nums3"`         // int(11)
+	Prod4     int64     `orm:"column(prod4)"                           json:"-"`             // int(11)
+	Nums4     int64     `orm:"column(nums4)"                           json:"-"`             // int(11)
+	Prod5     int64     `orm:"column(prod5)"                           json:"-"`             // int(11)
+	Nums5     int64     `orm:"column(nums5)"                           json:"-"`             // int(11)
 	SendProd1 int64     `orm:"column(send_prod1)"                      json:"send_prod1"`    // int(11)
 	SendNums1 int64     `orm:"column(send_nums1)"                      json:"send_nums1"`    // int(11)
 	SendProd2 int64     `orm:"column(send_prod2)"                      json:"send_prod2"`    // int(11)
 	SendNums2 int64     `orm:"column(send_nums2)"                      json:"send_nums2"`    // int(11)
 	SendProd3 int64     `orm:"column(send_prod3)"                      json:"send_prod3"`    // int(11)
 	SendNums3 int64     `orm:"column(send_nums3)"                      json:"send_nums3"`    // int(11)
+	SendProd4 int64     `orm:"column(send_prod4)"                      json:"-"`             // int(11)
+	SendNums4 int64     `orm:"column(send_nums4)"                      json:"-"`             // int(11)
+	SendProd5 int64     `orm:"column(send_prod5)"                      json:"-"`             // int(11)
+	SendNums5 int64     `orm:"column(send_nums5)"                      json:"-"`             // int(11)
 	Cash      int64     `orm:"column(cash)"                            json:"cash"`          // int(11)
 	Cent      int64     `orm:"column(cent)"                            json:"cent"`          // int(11)
 	CreatedAt time.Time `orm:"column(created_at);null;auto_now_add;type(datetime)" json:"-"` // datetime