package promotion_model import ( // "fmt" "time" "github.com/astaxie/beego" "github.com/astaxie/beego/orm" ) const ( SOURCE_BALANCE = "balance" SOURCE_SHOP = "shop" SOURCE_OTHERS = "others" presents_tablename = "presents" ) var SOURCE_CN = map[string]string{ SOURCE_SHOP: "店长促销发放", SOURCE_BALANCE: "充值促销发放", SOURCE_OTHERS: "手工添加", } 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) SourceName string `orm:"-" json:"source_name"` // varchar(255) ProductName string `orm:"-" json:"product_name"` // varchar(255) 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) CreatePresent(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 } //获取所有未写入订单赠品 func GetAllNoPatchPresents(wxUId int64) (presents []*Present) { present := new(Present) qs := orm.NewOrm().QueryTable(present) qs = qs.Filter("wx_user_id", wxUId) qs = qs.Filter("status", false) if _, err := qs.OrderBy("-created_at").All(&presents); err != nil { beego.BeeLogger.Debug("GetAllNoPatchPresents, wxUId=[%d] order list err=[%s]", wxUId, err) return nil } return presents }