package helpers import ( "fmt" "fohow.com/apps/models/balance_model" "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" "fohow.com/libs/tool" "github.com/astaxie/beego" "time" ) //订单促销 /* 如果促销条件中,设置的项目有一项不满足即视为不满足促销条件 */ func SetOrderPromotion(orderId string, wxUid int64) { beego.BeeLogger.Warn("******* SetOrderPromotion orderId:%s wxUid:%d", orderId, wxUid) firstOrder := false //获取订单明细 order := order_model.GetOrderById(orderId, false) if order == nil { return } //检查会员是否首次下单 list := order_model.GetWxUserOrders(wxUid) if len(list) == 1 { firstOrder = true } queryDate := time.Now() // 获取所有有效促销记录 effectivePromotions := promotion_model.GetEffetivePromotions(queryDate, order.OrderType, order.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 { totalFlag = false continue } if item.IsFirst && !firstOrder { firstFlag = false continue } if item.MinTotal > 0 && order.TotalPrice < item.MinTotal { totalFlag = false firstFlag = false continue } nums := int64(999) nums1 := int64(999) nums2 := int64(999) nums3 := int64(999) nums4 := int64(999) nums5 := int64(999) nums6 := int64(999) 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 = tool.Min(val...) if !item.IsMore { val := []int64{nums, 1} nums = tool.Min(val...) } if nums == int64(999) || 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) 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) 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) 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) 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) 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) } } } } //订单促销 /* 如果促销条件中,设置的项目有一项不满足即视为不满足促销条件 */ func SetOrderPromotionPro(orderId string, wxUid int64) { beego.BeeLogger.Warn("******* SetOrderPromotionPro orderId:%s wxUid:%d", orderId, wxUid) firstOrder := false //获取订单明细 order := order_model.GetOrderById(orderId, false) if order == nil { return } //检查会员是否首次下单 list := order_model.GetWxUserOrders(wxUid) if len(list) == 1 { firstOrder = true } var noInovceArr []int64 var promotionsArr []int64 queryDate := time.Now() // 获取所有有效促销记录 effectivePromotions := promotion_model.GetEffetivePromotions(queryDate, order.OrderType, order.Depart, false) for _, item := range effectivePromotions { //beego.Warn("item_name%d", item.Name) noInvovedAmount := order_model.GetNotInvovedAmount(item.Id, order.OrderId) firstFlag := true totalFlag := true numsFlag := true if item.MaxTotal > 0 && (order.TotalPrice-noInvovedAmount) > item.MaxTotal { totalFlag = false continue } if item.IsFirst && !firstOrder { firstFlag = false continue } if item.MinTotal > 0 && (order.TotalPrice-noInvovedAmount) < item.MinTotal { totalFlag = false firstFlag = false continue } nums := int64(999) nums1 := int64(999) nums2 := int64(999) nums3 := int64(999) nums4 := int64(999) nums5 := int64(999) nums6 := int64(999) if item.Prod1 > 0 { prd := product_model.GetProductById(item.Prod1, true) nums1 = int64(0) if prd != nil { detail_nums1 := int64(0) detailItem := order_model.GetDetailsByOrderIdAndPid(orderId, item.Prod1) if detailItem != nil { detail_nums1 = detailItem.Count } 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 := int64(0) detailItem := order_model.GetDetailsByOrderIdAndPid(orderId, item.Prod2) if detailItem != nil { detail_nums2 = detailItem.Count } //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) prd := product_model.GetProductById(item.Prod3, true) if prd != nil { detail_nums3 := int64(0) detailItem := order_model.GetDetailsByOrderIdAndPid(orderId, item.Prod3) if detailItem != nil { detail_nums3 = detailItem.Count } //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 - noInvovedAmount) / item.MinTotal) } if item.Prod4 > 0 { prd := product_model.GetProductById(item.Prod4, true) nums5 = int64(0) if prd != nil { detail_nums4 := int64(0) detailItem := order_model.GetDetailsByOrderIdAndPid(orderId, item.Prod4) if detailItem != nil { detail_nums4 = detailItem.Count } //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 := int64(0) detailItem := order_model.GetDetailsByOrderIdAndPid(orderId, item.Prod5) if detailItem != nil { detail_nums5 = detailItem.Count } //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 = tool.Min(val...) if !item.IsMore { val := []int64{nums, 1} nums = tool.Min(val...) } if nums == int64(999) || 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 { noInovceArr = append(noInovceArr, noInvovedAmount) promotionsArr = append(promotionsArr, item.Id) if item.SendProd1 > 0 && item.SendNums1 > 0 { sendNums1 := nums * item.SendNums1 //赠送赠品1 product := product_model.GetProductById(item.SendProd1, true) 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) 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) 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) 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) 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) } } } //更新促销减去金额 if len(promotionsArr) > 0 { promotions := tool.CombineInt64ToString(promotionsArr) noinvoves := tool.CombineInt64ToString(noInovceArr) order_model.UpdateOrderPromotions(promotions, noinvoves, orderId) } } func max(vals ...int64) int64 { var max int64 for _, val := range vals { if val > max { max = val } } return max } /* 找到所有当前时间>《开始时间》且 当前时间<《结束时间》 且《是否启用》=1的促销记录 { flag1=1,flag2=1,flag3=1 NUMs=99,NUMs1=99,NUMs2=99,NUMs3=99,NUMs4=99 如果《是否首次下单》=是,且当前订单不是首次订单,则flag1=0 如果《最大金额》>0则要求订单金额大于此项值,则flag2=0 如果:《购买产品ID1》>0且《购买数量1》>0则NUMs1=购买产品ID1的数量/《购买数量1》 如果:《购买产品ID2》>0且《购买数量2》>0则当前订单中NUMs2=购买产品ID2的数量/《购买数量2》 如果:《购买产品ID3》>0且《购买数量3》>0则当前订单中NUMs3=购买产品ID3的数量/《购买数量3》 如果:《最小金额》>0则要求订单金额大于或等于此项值,则NUMs4=订单金额/《最小金额》 NUMs=min(NUMs1,NUMs2,NUMs3,NUMs4); if(NUMs=99或NUMs=0) 则flag3=0 如果《是否多买多送》=否,NUMs=MIN(1,NUMs) if(flag1=1并且flag2=1并且flag3=1) { 如果《赠送产品ID1》>0且《赠送数量1》>0,则按《赠送数量1》*NUMs赠送《赠送产品ID1》; 如果《赠送产品ID2》>0且《赠送数量2》>0,则按《赠送数量2》*NUMs赠送《赠送产品ID2》; 如果《赠送产品ID3》>0且《赠送数量3》>0,则按《赠送数量3》*NUMs赠送《赠送产品ID3》; } 找下一个促销记录 } */ //充值促销 func BalanceOrderPromotion(orderId string, wxUid, depart int64) { beego.BeeLogger.Warn("******* BalanceOrderPromotion orderId:%s wxUid:%d", orderId, wxUid) //获取订单明细 balanceOrder := balance_model.GetBalanceOrderByOId(orderId, false) if balanceOrder == nil { return } queryDate := time.Now() // 获取所有有效促销记录 effectivePromotions := promotion_model.GetBalanceEffetivePromotions(queryDate, depart, false) for _, item := range effectivePromotions { //beego.Warn("item_name%d", item.Name) totalFlag := true numsFlag := true if item.MaxTotal > 0 && balanceOrder.PaiedPrice > item.MaxTotal { totalFlag = false continue } if item.MinTotal > 0 && balanceOrder.PaiedPrice < item.MinTotal { totalFlag = false continue } count := int64(0) if item.MinTotal > 0 { count = int64(balanceOrder.PaiedPrice / item.MinTotal) } if count == int64(0) { numsFlag = false } if !item.IsMore { val := []int64{count, 1} count = tool.Min(val...) } 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 { 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 new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums1, source, remark) } } 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 new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums2, source, remark) } } 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 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) } } } } // 店长申请促销 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 } 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("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 := count * item.SendNums1 //生成赠品 product := product_model.GetProductById(item.SendProd1, true) if product != nil { total := sendNums1 * product.Price new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums1, source, remark) } } 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 new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums2, source, remark) } } 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 new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums3, source, remark) } } if item.SendProd4 > 0 && item.SendNums4 > 0 { sendNums4 := count * item.SendNums4 //赠送赠品4 product := product_model.GetProductById(item.SendProd4, true) if product != nil { total := sendNums4 * product.Price new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums4, source, remark) } } if item.SendProd5 > 0 && item.SendNums5 > 0 { sendNums5 := count * item.SendNums5 //赠送赠品3 product := product_model.GetProductById(item.SendProd5, true) if product != nil { total := sendNums5 * product.Price new(promotion_model.Present).CreatePresent(wxUid, product.Price, total, product.Id, sendNums5, source, remark) } } //赠送积分 or 代办费 if item.Cash > 0 { 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 := count * item.Cent source := cent_model.PROMOTION_SEND remark := fmt.Sprintf("店长申请促销活动赠送") new(cent_model.CentBalance).Create(shopApply.WxUId, totalCent, source, orderId, remark) } } } } // 赠品明细写入订单 func PresentTransferToOrder(orderId string, wxUid int64) { beego.BeeLogger.Warn("******* PresentTransferToOrder shopApplyId:%s wxUid:%d", orderId, wxUid) //获取订单明细 order := order_model.GetOrderById(orderId, false) if order == nil { return } // 获取所有未写入赠品记录 presents := promotion_model.GetAllNoPatchPresents(wxUid) for _, item := range presents { //赠送赠品 product := product_model.GetProductById(item.SendProd, true) if product != nil { item.OrderId = orderId item.Status = true item.Save() order_model.SendCreate(order.OrderId, order.Id, product.Id, product.Price, product.Price, product.Name, item.SendNums, order.Depart) } } beego.BeeLogger.Warn("******* End PresentTransferToOrder shopApplyId:%s wxUid:%d", orderId, wxUid) } // 创建店铺申请订单 func CreateShopApplyOrder(shopAppplyId int64) { beego.BeeLogger.Warn("begin do shopAppply id:(%d)", shopAppplyId) shopApply := user_model.GetShopApplicationById(shopAppplyId) if shopApply == nil { beego.BeeLogger.Warn("shopApply error id:(%d)", shopAppplyId) return } wxUser := user_model.GetWxUserById(shopApply.WxUId, false) if wxUser == nil { beego.BeeLogger.Warn("shopApply wxuser no existst id:(%d)", shopAppplyId) return } //创建赠品订单 order := new(order_model.Order).CreateNew(wxUser.Id, wxUser.UserId, int64(0), int64(0), order_model.ORDER_TYPE_NORMAL, wxUser.Depart, order_model.SOURCE_XCX) if order == nil { return } total := int64(0) delOrder := true queryDate := time.Now() // 获取所有有效促销记录 effectivePromotions := promotion_model.GetShopEffetivePromotions(queryDate, shopApply.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 } 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("totalFlag%v", totalFlag) beego.Warn("numsFlag%v", numsFlag) beego.Warn("nums%d", count) //满足促销条件 if totalFlag && numsFlag { orderId := fmt.Sprintf("shopapply-(%d)", shopApply.Id) order.Source = promotion_model.SOURCE_SHOP order.Remark = fmt.Sprintf("店长申请成功(%d)--促销(%s)", shopApply.Id, item.Name) if item.SendProd1 > 0 && item.SendNums1 > 0 { sendNums1 := count * item.SendNums1 //生成赠品 product := product_model.GetProductById(item.SendProd1, true) if product != nil { delOrder = false total += sendNums1 * product.Price new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, int64(0), int64(0), product.Name, "", "", sendNums1, order.Depart) } } if item.SendProd2 > 0 && item.SendNums2 > 0 { sendNums2 := count * item.SendNums2 //赠送赠品1 product := product_model.GetProductById(item.SendProd2, true) if product != nil { delOrder = false total += sendNums2 * product.Price new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, int64(0), int64(0), product.Name, "", "", sendNums2, order.Depart) } } if item.SendProd3 > 0 && item.SendNums3 > 0 { sendNums3 := count * item.SendNums3 //赠送赠品3 product := product_model.GetProductById(item.SendProd3, true) if product != nil { delOrder = false total += sendNums3 * product.Price new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, int64(0), int64(0), product.Name, "", "", sendNums3, order.Depart) } } if item.SendProd4 > 0 && item.SendNums4 > 0 { sendNums4 := count * item.SendNums4 //赠送赠品4 product := product_model.GetProductById(item.SendProd4, true) if product != nil { delOrder = false total += sendNums4 * product.Price new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, int64(0), int64(0), product.Name, "", "", sendNums4, order.Depart) } } if item.SendProd5 > 0 && item.SendNums5 > 0 { sendNums5 := count * item.SendNums5 //赠送赠品5 product := product_model.GetProductById(item.SendProd5, true) if product != nil { delOrder = false total += sendNums5 * product.Price new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, int64(0), int64(0), product.Name, "", "", sendNums5, order.Depart) } } //赠送积分 or 代办费 if item.Cash > 0 { 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 := count * item.Cent source := cent_model.PROMOTION_SEND remark := fmt.Sprintf("店长申请促销活动赠送") new(cent_model.CentBalance).Create(shopApply.WxUId, totalCent, source, orderId, remark) } } } if !delOrder { order.Status = order_model.STATUS_PROCESSING order.TotalPrice = total order.Contact = shopApply.Name order.Address = shopApply.Address order.Tel = shopApply.Mobile order.Save() } else { order.Delete() } beego.BeeLogger.Warn("----------------end generate shopapply order ---%d ", shopApply.Id) return }