Procházet zdrojové kódy

add live award patch function

abiao před 5 roky
rodič
revize
b36695ae9f

+ 106 - 0
go/gopath/src/fohow.com/apps/controllers/railsadmin_controller/live_award_controller.go

@@ -0,0 +1,106 @@
+package railsadmin_controller
+
+import (
+	"fmt"
+	"fohow.com/apps/models/balance_model"
+	"fohow.com/apps/models/cent_model"
+	"fohow.com/apps/models/live_model"
+	"fohow.com/apps/models/order_model"
+	"fohow.com/apps/models/product_model"
+	"fohow.com/apps/models/user_model"
+	"github.com/astaxie/beego"
+	"strconv"
+)
+
+//
+func (self *RailsadminController) LiveAward() {
+
+	_id := self.Ctx.Input.Param(":id")
+	id, _ := strconv.ParseInt(_id, 10, 64)
+
+	beego.BeeLogger.Warn("LiveAward id:(%d)", id)
+
+	go PatchLiveAward(id)
+
+	self.ServeJSON()
+}
+
+func PatchLiveAward(id int64) {
+	LiveAward := live_model.GetLiveAwardById(id, true)
+	if LiveAward == nil {
+		beego.BeeLogger.Warn("----------------LiveAward not exist ")
+		return
+	}
+	if LiveAward.Status {
+		beego.BeeLogger.Warn("----------------LiveAward has patched ")
+		return
+	}
+	wxUserId := LiveAward.WxUserId
+	wxUser := user_model.GetWxUserById(wxUserId, true)
+	if wxUser == nil {
+		return
+	}
+	if (LiveAward.Prod1 > 0 && LiveAward.Nums1 > 0) || (LiveAward.Prod2 > 0 && LiveAward.Nums2 > 0) || (LiveAward.Prod3 > 0 && LiveAward.Nums3 > 0) {
+		//创建赠品订单
+		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
+		}
+		totalPrice := int64(0)
+		if LiveAward.Prod1 > 0 && LiveAward.Nums1 > 0 {
+			sendNums1 := LiveAward.Nums1
+			//赠送赠品1
+			product := product_model.GetProductById(LiveAward.Prod1, true)
+			if product != nil {
+				totalPrice += LiveAward.Nums1 * product.Price
+				go order_model.SendCreate(order.OrderId, order.Id, product.Id, product.Price, product.Price, product.Name, sendNums1)
+			}
+
+		}
+		if LiveAward.Prod2 > 0 && LiveAward.Nums2 > 0 {
+			sendNums2 := LiveAward.Nums2
+			//赠送赠品1
+			product := product_model.GetProductById(LiveAward.Prod2, true)
+			if product != nil {
+				totalPrice += LiveAward.Nums2 * product.Price
+				go order_model.SendCreate(order.OrderId, order.Id, product.Id, product.Price, product.Price, product.Name, sendNums2)
+			}
+		}
+
+		if LiveAward.Prod3 > 0 && LiveAward.Nums3 > 0 {
+			sendNums3 := LiveAward.Nums3
+			product := product_model.GetProductById(LiveAward.Prod3, true)
+
+			//赠送赠品1
+			if product != nil {
+				totalPrice += LiveAward.Nums3 * product.Price
+				go order_model.SendCreate(order.OrderId, order.Id, product.Id, product.Price, product.Price, product.Name, sendNums3)
+			}
+		}
+		order.TotalPrice = totalPrice
+		order.Save()
+	}
+
+	orderId := fmt.Sprintf("live_award--%d", LiveAward.Id)
+
+	//赠送积分 or 代办费
+	if LiveAward.Cash > 0 {
+		totalCash := LiveAward.Cash
+		source := balance_model.BALANCE_SOURCE_PROMOTION
+		remark := LiveAward.Remark
+		new(balance_model.Balance).Create(wxUser.Id, wxUser.UserId, totalCash, source, orderId, remark)
+	}
+	if LiveAward.Cent > 0 {
+		totalCent := LiveAward.Cent
+		source := cent_model.PROMOTION_SEND
+		remark := LiveAward.Remark
+		new(cent_model.CentBalance).Create(wxUser.Id, totalCent, source, orderId, remark)
+	}
+
+	//发放成功标记
+	LiveAward.Status = true
+	LiveAward.Save()
+	beego.BeeLogger.Warn("----------------end patch live awards ---%d ", id)
+	return
+}

+ 62 - 0
go/gopath/src/fohow.com/apps/models/live_model/live_award.go

@@ -0,0 +1,62 @@
+package live_model
+
+import (
+	"fmt"
+	"fohow.com/cache"
+	"github.com/astaxie/beego"
+	"github.com/astaxie/beego/orm"
+	"time"
+)
+
+const (
+	live_awards_tablename = "live_awards"
+)
+
+type LiveAward struct {
+	Id        int64     `orm:"column(id);pk"                           json:"id"` // int(11)
+	OpenId    string    `orm:"column(openid)"                          json:"-"`  // varchar(64)
+	WxUserId  int64     `orm:"column(wx_user_id)"                      json:"-"`  // int(11)
+	Remark    string    `orm:"column(remark)"                          json:"-"`  // varchar(64)
+	RoomId    int64     `orm:"column(room_id)"                         json:"-"`  // int(11)
+	Prod1     int64     `orm:"column(prod1)"                           json:"-"`  // int(11)
+	Nums1     int64     `orm:"column(nums1)"                           json:"-"`  // int(11)
+	Prod2     int64     `orm:"column(prod2)"                           json:"-"`  // int(11)
+	Nums2     int64     `orm:"column(nums2)"                           json:"="`  // int(11)
+	Prod3     int64     `orm:"column(prod3)"                           json:"-"`  // int(11)
+	Nums3     int64     `orm:"column(nums3)"                           json:"-"`  // int(11)
+	Address   string    `orm:"column(address)"                         json:"-"`  // varchar(64)
+	Status    bool      `orm:"column(status)"                          json:"-"`
+	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
+	UpdatedAt time.Time `orm:"column(updated_at);null;auto_now;type(datetime)"     json:"-"` // datetime
+}
+
+func (self *LiveAward) TableName() string {
+	return live_awards_tablename
+}
+
+//根据奖励Id,获取奖励信息
+func GetLiveAwardById(id int64, useCache bool) *LiveAward {
+	k := fmt.Sprintf("live_model.GetLiveAwardById[%d]", id)
+	if useCache {
+		if v, ok := cache.Cache.Get(k).(*LiveAward); ok {
+			return v
+		}
+	}
+	item := new(LiveAward)
+	o := orm.NewOrm()
+	if err := o.QueryTable(item).Filter("id", id).One(item); err != nil {
+		return nil
+	}
+	cache.Cache.Put(k, item, 5*time.Minute)
+	return item
+}
+
+func (self *LiveAward) Save() error {
+	if _, err := orm.NewOrm().Update(self); err != nil {
+		beego.BeeLogger.Error("Save LiveAward id=[%d] .err=[%s]", self.Id, err)
+		return err
+	}
+	return nil
+}

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

@@ -42,11 +42,12 @@ const (
 	OPERATE_CONFIRM = "confirm" //确认收货
 	OPERATE_CANCEL  = "cancel"  //取消订单
 
-	//订单类型 0:普通订单, 1:秒杀订单, 2:店铺订单, 3:积分订单
+	//订单类型 0:普通订单, 1:秒杀订单, 2:店铺订单, 3:积分订单, 4:赠品订单
 	ORDER_TYPE_NORMAL = int64(0)
 	ORDER_TYPE_SEKILL = int64(1)
 	ORDER_TYPE_SHOP   = int64(2)
 	ORDER_TYPE_CENT   = int64(3)
+	ORDER_TYPE_LIVE   = int64(4)
 
 	CENT_LIMIT       = int64(9900)
 	FREIGHT_LIMIT    = int64(9900)

+ 1 - 0
go/gopath/src/fohow.com/routers/routes.go

@@ -220,6 +220,7 @@ func init() {
 	beego.Router("/railsadmin/order/static/:id([0-9]+)", &railsadmin_controller.RailsadminController{}, "get:OrderStatic")
 	beego.Router("/railsadmin/order/refund/:id([0-9]+)", &railsadmin_controller.RailsadminController{}, "get:OrderRefund")
 	beego.Router("/railsadmin/user/perfomance/:id([0-9]+)", &railsadmin_controller.RailsadminController{}, "get:UserPerfomance")
+	beego.Router("/railsadmin/live/award/:id([0-9]+)", &railsadmin_controller.RailsadminController{}, "get:LiveAward")
 
 	//设置群主
 	beego.Router("/railsadmin/update/intro/:id([0-9]+)", &railsadmin_controller.RailsadminController{}, "get:UpdateIntroUser")