Selaa lähdekoodia

add balance ,shop promotion

abiao 4 vuotta sitten
vanhempi
commit
de6af36656

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

@@ -10,7 +10,7 @@ import (
 	"time"
 )
 
-//发放促销商品
+//订单促销
 /*
 	如果促销条件中,设置的项目有一项不满足即视为不满足促销条件
 */
@@ -231,3 +231,168 @@ func min(vals ...int64) int64 {
 	找下一个促销记录
 }
 */
+
+//充值促销
+/*
+	如果促销条件中,设置的项目有一项不满足即视为不满足促销条件
+*/
+func BalanceOrderPromotion(orderId string, wxUid int64) {
+	beego.BeeLogger.Warn("******* BalanceOrderPromotion orderId:%s wxUid:%d", orderId, wxUid)
+
+	//获取订单明细
+	order := balance_model.GetBalanceOrderByOId(orderId, false)
+	if order == nil {
+		return
+	}
+
+	queryDate := time.Now()
+	// 获取所有有效促销记录
+	effectivePromotions := order_model.GetEffetivePromotions(queryDate, false)
+	for _, item := range effectivePromotions {
+		//beego.Warn("item_name%d", item.Name)
+
+		firstFlag := true
+		totalFlag := true
+		numsFlag := true
+		if item.MaxTotal > 0 && order.TotalPrice > item.MaxTotal {
+			totalFlag = false
+			continue
+		}
+
+		if item.MinTotal > 0 && order.TotalPrice < item.MinTotal {
+			totalFlag = false
+			firstFlag = false
+			continue
+		}
+		nums := int64(99)
+		nums1 := int64(99)
+		nums2 := int64(99)
+		nums3 := int64(99)
+		nums4 := int64(99)
+		nums5 := int64(99)
+		nums6 := int64(99)
+		if item.Prod1 > 0 {
+			prd := product_model.GetProductById(item.Prod1, true)
+			nums1 = int64(0)
+			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)
+			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 {
+			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 {
+			nums4 = int64(order.TotalPrice / item.MinTotal)
+		}
+
+		if item.Prod4 > 0 {
+			prd := product_model.GetProductById(item.Prod4, true)
+			nums5 = int64(0)
+			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)
+			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)
+				}
+			}
+		}
+
+		val := []int64{nums1, nums2, nums3, nums4, nums5, nums6}
+		nums = min(val...)
+		if !item.IsMore {
+			val := []int64{nums, 1}
+			nums = min(val...)
+		}
+		if nums == int64(99) || nums == int64(0) {
+			numsFlag = false
+		}
+		/*	beego.Warn("item_name-1%d", item.Name)
+			beego.Warn("firstFlag%v", firstFlag)
+			beego.Warn("totalFlag%v", totalFlag)
+			beego.Warn("numsFlag%v", numsFlag)
+			beego.Warn("nums%d", nums)*/
+
+		//满足促销条件
+		if firstFlag && totalFlag && numsFlag {
+
+			if item.SendProd1 > 0 && item.SendNums1 > 0 {
+				sendNums1 := nums * item.SendNums1
+				//赠送赠品1
+				product := product_model.GetProductById(item.SendProd1, true)
+				go order_model.SendCreate(order.OrderId, order.Id, product.Id, product.Price, product.Price, product.Name, sendNums1, order.Depart)
+			}
+			if item.SendProd2 > 0 && item.SendNums2 > 0 {
+				sendNums2 := nums * item.SendNums2
+				//赠送赠品1
+				product := product_model.GetProductById(item.SendProd2, true)
+				go order_model.SendCreate(order.OrderId, order.Id, product.Id, product.Price, product.Price, product.Name, sendNums2, order.Depart)
+			}
+
+			if item.SendProd3 > 0 && item.SendNums3 > 0 {
+				sendNums3 := nums * item.SendNums3
+				//赠送赠品1
+				product := product_model.GetProductById(item.SendProd3, true)
+				go order_model.SendCreate(order.OrderId, order.Id, product.Id, product.Price, product.Price, product.Name, sendNums3, order.Depart)
+			}
+
+			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, order.Depart)
+			}
+
+			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, order.Depart)
+			}
+			//赠送积分 or 代办费
+			if item.Cash > 0 {
+				totalCash := nums * item.Cash
+				source := balance_model.BALANCE_SOURCE_PROMOTION
+				remark := fmt.Sprintf("促销赠送提货券")
+				new(balance_model.Balance).Create(order.WxUserId, order.UserId, totalCash, source, order.OrderId, remark)
+			}
+			if item.Cent > 0 {
+				totalCent := nums * item.Cent
+				source := cent_model.PROMOTION_SEND
+				remark := fmt.Sprintf("促销活动赠送")
+				new(cent_model.CentBalance).Create(order.WxUserId, totalCent, source, order.OrderId, remark)
+			}
+		}
+	}
+}

+ 9 - 0
go/gopath/src/fohow.com/apps/models/promotion_model/init.go

@@ -0,0 +1,9 @@
+package promotion_model
+
+import (
+	"github.com/astaxie/beego/orm"
+)
+
+func init() {
+	orm.RegisterModel(new(AdPosition))
+}

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

@@ -1,4 +1,4 @@
-package order_model
+package promotion_model
 
 import (
 	"fmt"

+ 61 - 0
go/gopath/src/fohow.com/apps/models/promotion_model/present.go

@@ -0,0 +1,61 @@
+package promotion_model
+
+import (
+	// "fmt"
+	"time"
+
+	"github.com/astaxie/beego"
+	"github.com/astaxie/beego/orm"
+)
+
+const (
+	presents_tablename = "presents"
+)
+
+type Present struct {
+	Id        int64     `orm:"column(id);pk"                                       json:"id"`             // int(11)
+	WxUId     int64     `orm:"column(wx_user_id)"                                  json:"wx_user_id"`     // int(11)
+	Price     int64     `orm:"column(price)"                                        json:"price"`         // int(11)
+	Total     int64     `orm:"column(total)"                                        json:"total"`         // int(11)
+	SendProd  int64     `orm:"column(send_prod1)"                                  json:"send_prod1"`     // int(11)
+	SendNums  int64     `orm:"column(send_nums1)"                                  json:"send_nums1"`     // int(11)
+	OrderId   string    `orm:"column(order_id);null"                                     json:"order_id"` // varchar(32)
+	Source    string    `orm:"column(source);null"                                     json:"source"`     // varchar(32)
+	Remark    string    `orm:"column(remark);null"                                     json:"remark"`     // varchar(32)
+	Status    bool      `orm:"column(status)"                         json:"-"`                           // int(11)
+	CreatedAt time.Time `orm:"column(created_at);null;auto_now_add;type(datetime)" json:"created_at"`     // datetime
+	UpdatedAt time.Time `orm:"column(updated_at);null;auto_now;type(datetime)"     json:"updated_at"`     // datetime
+}
+
+func (self *Present) TableName() string {
+	return presents_tablename
+}
+
+//创建点击统计项
+func (self *Present) Create(wxUId, price, total, prd, nums int64, source, remark string) *Present {
+	item := &Present{
+		WxUId:    wxUId,
+		Price:    price,
+		Total:    total,
+		SendProd: prd,
+		SendNums: nums,
+		Source:   source,
+		Status:   false,
+		Remark:   remark,
+	}
+	id, err := orm.NewOrm().Insert(item)
+	if err != nil {
+		beego.BeeLogger.Error("insert Present err=[%s]", err)
+		return nil
+	}
+	item.Id = id
+	return item
+}
+
+func (self *Present) Save() error {
+	if _, err := orm.NewOrm().Update(self); err != nil {
+		beego.BeeLogger.Error("Save Present id=[%d] .err=[%s]", self.Id, err)
+		return err
+	}
+	return nil
+}

+ 65 - 0
go/gopath/src/fohow.com/apps/models/promotion_model/promotion_model.go

@@ -0,0 +1,65 @@
+package promotion_model
+
+import (
+	// "strings"
+	"time"
+)
+
+const (
+	balance_promotions_tablename = "balance_promotions"
+	shop_promotions_tablename    = "shop_promotions"
+)
+
+type BalancePromotion struct {
+	Id        int64     `orm:"column(id);pk"                           json:"-"` // int(11)
+	Name      string    `orm:"column(name)"                            json:"-"` // varchar(64)
+	BeginTime time.Time `orm:"column(begin_time)"                      json:"-"`
+	EndTime   time.Time `orm:"column(end_time)"                        json:"-"`
+	IsEnable  bool      `orm:"column(is_enable)"                       json:"-"`             // int(11)
+	IsMore    bool      `orm:"column(is_more)"                         json:"-"`             // int(11)
+	Depart    int64     `orm:"column(depart)"                          json:"-"`             // varchar(64)
+	MinTotal  int64     `orm:"column(min_total)"                       json:"-"`             // int(11)
+	MaxTotal  int64     `orm:"column(max_total)"                       json:"-"`             // datetime
+	SendProd1 int64     `orm:"column(send_prod1)"                      json:"-"`             // int(11)
+	SendNums1 int64     `orm:"column(send_nums1)"                      json:"-"`             // int(11)
+	SendProd2 int64     `orm:"column(send_prod2)"                      json:"-"`             // int(11)
+	SendNums2 int64     `orm:"column(send_nums2)"                      json:"-"`             // int(11)
+	SendProd3 int64     `orm:"column(send_prod3)"                      json:"-"`             // int(11)
+	SendNums3 int64     `orm:"column(send_nums3)"                      json:"-"`             // int(11)
+	Cash      int64     `orm:"column(cash)"                            json:"-"`             // int(11)
+	Cent      int64     `orm:"column(cent)"                            json:"-"`             // int(11)
+	CreatedAt time.Time `orm:"column(created_at);null;auto_now_add;type(datetime)" json:"-"` // datetime
+	UpdatedAt time.Time `orm:"column(updated_at);null;auto_now;type(datetime)"     json:"-"` // datetime
+}
+
+type ShopPromotion struct {
+	Id        int64     `orm:"column(id);pk"                           json:"-"` // int(11)
+	Name      string    `orm:"column(name)"                            json:"-"` // varchar(64)
+	BeginTime time.Time `orm:"column(begin_time)"                      json:"-"`
+	EndTime   time.Time `orm:"column(end_time)"                        json:"-"`
+	IsEnable  bool      `orm:"column(is_enable)"                       json:"-"`             // int(11)
+	Depart    int64     `orm:"column(depart)"                          json:"-"`             // varchar(64)
+	Total     int64     `orm:"column(total)"                           json:"-"`             // int(11)
+	SendProd1 int64     `orm:"column(send_prod1)"                      json:"-"`             // int(11)
+	SendNums1 int64     `orm:"column(send_nums1)"                      json:"-"`             // int(11)
+	SendProd2 int64     `orm:"column(send_prod2)"                      json:"-"`             // int(11)
+	SendNums2 int64     `orm:"column(send_nums2)"                      json:"-"`             // int(11)
+	SendProd3 int64     `orm:"column(send_prod3)"                      json:"-"`             // int(11)
+	SendNums3 int64     `orm:"column(send_nums3)"                      json:"-"`             // 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:"-"`             // int(11)
+	Cent      int64     `orm:"column(cent)"                            json:"-"`             // int(11)
+	CreatedAt time.Time `orm:"column(created_at);null;auto_now_add;type(datetime)" json:"-"` // datetime
+	UpdatedAt time.Time `orm:"column(updated_at);null;auto_now;type(datetime)"     json:"-"` // datetime
+}
+
+func (self *ShopPromotion) TableName() string {
+	return shop_promotions_tablename
+}
+
+func (self *BalancePromotion) TableName() string {
+	return balance_promotions_tablename
+}