|
|
@@ -6,6 +6,8 @@ import (
|
|
|
"fohow.com/apps/models/cent_model"
|
|
|
"fohow.com/apps/models/order_model"
|
|
|
"fohow.com/apps/models/product_model"
|
|
|
+ "fohow.com/apps/models/promotion_model"
|
|
|
+ "fohow.com/apps/models/user_model"
|
|
|
"github.com/astaxie/beego"
|
|
|
"time"
|
|
|
)
|
|
|
@@ -31,7 +33,7 @@ func SetOrderPromotion(orderId string, wxUid int64) {
|
|
|
|
|
|
queryDate := time.Now()
|
|
|
// 获取所有有效促销记录
|
|
|
- effectivePromotions := order_model.GetEffetivePromotions(queryDate, order.OrderType, false)
|
|
|
+ effectivePromotions := promotion_model.GetEffetivePromotions(queryDate, order.OrderType, false)
|
|
|
for _, item := range effectivePromotions {
|
|
|
//beego.Warn("item_name%d", item.Name)
|
|
|
|
|
|
@@ -233,165 +235,201 @@ func min(vals ...int64) int64 {
|
|
|
*/
|
|
|
|
|
|
//充值促销
|
|
|
-/*
|
|
|
- 如果促销条件中,设置的项目有一项不满足即视为不满足促销条件
|
|
|
-*/
|
|
|
-func BalanceOrderPromotion(orderId string, wxUid int64) {
|
|
|
+
|
|
|
+func BalanceOrderPromotion(orderId string, wxUid, depart int64) {
|
|
|
beego.BeeLogger.Warn("******* BalanceOrderPromotion orderId:%s wxUid:%d", orderId, wxUid)
|
|
|
|
|
|
//获取订单明细
|
|
|
- order := balance_model.GetBalanceOrderByOId(orderId, false)
|
|
|
- if order == nil {
|
|
|
+ balanceOrder := balance_model.GetBalanceOrderByOId(orderId, false)
|
|
|
+ if balanceOrder == nil {
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
queryDate := time.Now()
|
|
|
// 获取所有有效促销记录
|
|
|
- effectivePromotions := order_model.GetEffetivePromotions(queryDate, false)
|
|
|
+ effectivePromotions := promotion_model.GetBalanceEffetivePromotions(queryDate, depart, 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 {
|
|
|
+ if item.MaxTotal > 0 && balanceOrder.PaiedPrice > item.MaxTotal {
|
|
|
totalFlag = false
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
- if item.MinTotal > 0 && order.TotalPrice < item.MinTotal {
|
|
|
+ if item.MinTotal > 0 && balanceOrder.PaiedPrice < 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)
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ count := int64(0)
|
|
|
+
|
|
|
+ if item.MinTotal > 0 {
|
|
|
+ count = int64(balanceOrder.PaiedPrice / item.MinTotal)
|
|
|
}
|
|
|
|
|
|
- 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 count == int64(0) {
|
|
|
+ numsFlag = false
|
|
|
}
|
|
|
+ beego.Warn("item_name-1%d", item.Name)
|
|
|
+ beego.Warn("totalFlag%v", totalFlag)
|
|
|
+ beego.Warn("numsFlag%v", numsFlag)
|
|
|
+ beego.Warn("nums%d", count)
|
|
|
|
|
|
- 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 totalFlag && numsFlag {
|
|
|
+ source := promotion_model.SOURCE_BALANCE
|
|
|
+ remark := fmt.Sprintf("充值订单(%s)充值成功--促销(%s)", orderId, item.Name)
|
|
|
+ if item.SendProd1 > 0 && item.SendNums1 > 0 {
|
|
|
+ sendNums1 := count * item.SendNums1
|
|
|
+ //生成赠品
|
|
|
+ product := product_model.GetProductById(item.SendProd1, true)
|
|
|
+ if product != nil {
|
|
|
+ total := sendNums1 * product.Price
|
|
|
+ go new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums1, source, remark)
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- 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.SendProd2 > 0 && item.SendNums2 > 0 {
|
|
|
+ sendNums2 := count * item.SendNums2
|
|
|
+ //赠送赠品1
|
|
|
+ product := product_model.GetProductById(item.SendProd2, true)
|
|
|
+ if product != nil {
|
|
|
+ total := sendNums2 * product.Price
|
|
|
+ go new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums2, source, remark)
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- 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)
|
|
|
+ if item.SendProd3 > 0 && item.SendNums3 > 0 {
|
|
|
+ sendNums3 := count * item.SendNums3
|
|
|
+ //赠送赠品3
|
|
|
+ product := product_model.GetProductById(item.SendProd3, true)
|
|
|
+ if product != nil {
|
|
|
+ total := sendNums3 * product.Price
|
|
|
+ go new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums3, source, remark)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //赠送积分 or 代办费
|
|
|
+ if item.Cash > 0 {
|
|
|
+ totalCash := count * item.Cash
|
|
|
+ source := balance_model.BALANCE_SOURCE_BALANCE_RECHARGE_PROMOTION
|
|
|
+ remark := fmt.Sprintf("充值促销赠送提货券")
|
|
|
+ new(balance_model.Balance).Create(balanceOrder.WxUserId, balanceOrder.UserId, totalCash, source, balanceOrder.OrderId, remark)
|
|
|
+ }
|
|
|
+
|
|
|
+ if item.Cent > 0 {
|
|
|
+ totalCent := count * item.Cent
|
|
|
+ source := cent_model.PROMOTION_SEND
|
|
|
+ remark := fmt.Sprintf("充值促销活动赠送")
|
|
|
+ new(cent_model.CentBalance).Create(balanceOrder.WxUserId, totalCent, source, balanceOrder.OrderId, remark)
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- val := []int64{nums1, nums2, nums3, nums4, nums5, nums6}
|
|
|
- nums = min(val...)
|
|
|
- if !item.IsMore {
|
|
|
- val := []int64{nums, 1}
|
|
|
- nums = min(val...)
|
|
|
+//店长申请促销
|
|
|
+func ShopOrderPromotion(shopApplyId, wxUid, depart int64) {
|
|
|
+ beego.BeeLogger.Warn("******* ShopOrderPromotion shopApplyId:%d wxUid:%d", shopApplyId, wxUid)
|
|
|
+
|
|
|
+ //获取订单明细
|
|
|
+ shopApply := user_model.GetShopApplicationById(shopApplyId)
|
|
|
+ if shopApply == nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ queryDate := time.Now()
|
|
|
+ // 获取所有有效促销记录
|
|
|
+ effectivePromotions := promotion_model.GetShopEffetivePromotions(queryDate, depart, false)
|
|
|
+ for _, item := range effectivePromotions {
|
|
|
+ //beego.Warn("item_name%d", item.Name)
|
|
|
+
|
|
|
+ totalFlag := true
|
|
|
+ numsFlag := true
|
|
|
+ if item.Total > 0 && shopApply.Total != item.Total {
|
|
|
+ totalFlag = false
|
|
|
+ continue
|
|
|
}
|
|
|
- if nums == int64(99) || nums == int64(0) {
|
|
|
+ count := int64(0)
|
|
|
+
|
|
|
+ if item.Total > 0 {
|
|
|
+ count = int64(1)
|
|
|
+ }
|
|
|
+
|
|
|
+ if count == 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 {
|
|
|
+ beego.Warn("item_name-1%d", item.Name)
|
|
|
+ beego.Warn("totalFlag%v", totalFlag)
|
|
|
+ beego.Warn("numsFlag%v", numsFlag)
|
|
|
+ beego.Warn("nums%d", count)
|
|
|
|
|
|
+ //满足促销条件
|
|
|
+ if totalFlag && numsFlag {
|
|
|
+ orderId := fmt.Sprintf("shopapply-(%d)", shopApply.Id)
|
|
|
+ source := promotion_model.SOURCE_SHOP
|
|
|
+ remark := fmt.Sprintf("店长申请成功(%d)--促销(%s)", shopApply.Id, item.Name)
|
|
|
if item.SendProd1 > 0 && item.SendNums1 > 0 {
|
|
|
- sendNums1 := nums * item.SendNums1
|
|
|
- //赠送赠品1
|
|
|
+ sendNums1 := count * item.SendNums1
|
|
|
+ //生成赠品
|
|
|
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 product != nil {
|
|
|
+ total := sendNums1 * product.Price
|
|
|
+ go new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums1, source, remark)
|
|
|
+ }
|
|
|
}
|
|
|
if item.SendProd2 > 0 && item.SendNums2 > 0 {
|
|
|
- sendNums2 := nums * item.SendNums2
|
|
|
+ sendNums2 := count * 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 product != nil {
|
|
|
+ total := sendNums2 * product.Price
|
|
|
+ go new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums2, source, remark)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if item.SendProd3 > 0 && item.SendNums3 > 0 {
|
|
|
- sendNums3 := nums * item.SendNums3
|
|
|
- //赠送赠品1
|
|
|
+ sendNums3 := count * item.SendNums3
|
|
|
+ //赠送赠品3
|
|
|
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 product != nil {
|
|
|
+ total := sendNums3 * product.Price
|
|
|
+ go new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums3, source, remark)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if item.SendProd4 > 0 && item.SendNums4 > 0 {
|
|
|
- sendNums4 := nums * item.SendNums4
|
|
|
- //赠送赠品1
|
|
|
+ sendNums4 := count * item.SendNums4
|
|
|
+ //赠送赠品4
|
|
|
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 product != nil {
|
|
|
+ total := sendNums4 * product.Price
|
|
|
+ go new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums4, source, remark)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if item.SendProd5 > 0 && item.SendNums5 > 0 {
|
|
|
- sendNums5 := nums * item.SendNums5
|
|
|
- //赠送赠品1
|
|
|
+ sendNums5 := count * item.SendNums5
|
|
|
+ //赠送赠品3
|
|
|
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)
|
|
|
+ if product != nil {
|
|
|
+ total := sendNums5 * product.Price
|
|
|
+ go new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums5, source, remark)
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
//赠送积分 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)
|
|
|
+ totalCash := count * item.Cash
|
|
|
+ source := balance_model.BALANCE_SOURCE_SHOP_PROMOTION
|
|
|
+ remark := fmt.Sprintf("店长申请促销赠送提货券")
|
|
|
+ new(balance_model.Balance).Create(shopApply.WxUId, shopApply.UserId, totalCash, source, orderId, remark)
|
|
|
}
|
|
|
+
|
|
|
if item.Cent > 0 {
|
|
|
- totalCent := nums * item.Cent
|
|
|
+ totalCent := count * item.Cent
|
|
|
source := cent_model.PROMOTION_SEND
|
|
|
- remark := fmt.Sprintf("促销活动赠送")
|
|
|
- new(cent_model.CentBalance).Create(order.WxUserId, totalCent, source, order.OrderId, remark)
|
|
|
+ remark := fmt.Sprintf("店长申请促销活动赠送")
|
|
|
+ new(cent_model.CentBalance).Create(shopApply.WxUId, totalCent, source, orderId, remark)
|
|
|
}
|
|
|
}
|
|
|
}
|