Parcourir la source

shop apply generate order

abiao il y a 4 ans
Parent
commit
bb8ebf2959

+ 2 - 1
go/gopath/src/fohow.com/apps/controllers/railsadmin_controller/update_shop_application.go

@@ -46,7 +46,8 @@ func (self *RailsadminController) UpdateShopApplication() {
 	inviteList := user_model.GetWxUsersByInviteIdAll(wxUser.Id, false)
 	go user_model.UpdateClass(inviteList, wxUser.Id, wxUser.IntroUserId)
 	//发放赠品
-	helpers.ShopOrderPromotion(shopApplication.Id, wxUser.Id, wxUser.Depart)
+	//helpers.ShopOrderPromotion(shopApplication.Id, wxUser.Id, wxUser.Depart)
+	helpers.CreateShopApplyOrder(shopApplication.Id)
 	//消除user,wxuser缓存
 	userKey := fmt.Sprintf("user.GetByUid[%d]", wxUser.UserId)
 	wxUserKey := cache.GetKey(cache.GetWxUserById, wxUser.Id)

+ 141 - 0
go/gopath/src/fohow.com/apps/helpers/promotion_helper.go

@@ -463,3 +463,144 @@ func PresentTransferToOrder(orderId string, wxUid int64) {
 	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 || shopApply.Status {
+		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_LIVE, 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
+					go new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, product.RoboBalancePrice, 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
+					go new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, product.RoboBalancePrice, 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
+					go new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, product.RoboBalancePrice, 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
+					go new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, product.RoboBalancePrice, 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
+					go new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.RelateProductId, product.Price, product.RoboBalancePrice, 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.TotalPrice = total
+		order.Save()
+	} else {
+		order.Delete()
+	}
+
+	beego.BeeLogger.Warn("----------------end generate shopapply order ---%d ", shopApply.Id)
+	return
+}

+ 9 - 0
go/gopath/src/fohow.com/apps/models/order_model/order.go

@@ -220,6 +220,15 @@ func (self *Order) Save() bool {
 	return true
 }
 
+func (self *Order) Delete() error {
+	o := orm.NewOrm()
+	if _, err := o.Delete(&Order{Id: self.Id}); err != nil {
+		beego.BeeLogger.Error("Delete Order id=[%d] .err=[%s]", self.Id, err)
+		return err
+	}
+	return nil
+}
+
 //生成订单ID
 func createOrderId(prefix string) string {
 	n := time.Now().Format("20060102")