present.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package promotion_model
  2. import (
  3. // "fmt"
  4. "time"
  5. "github.com/astaxie/beego"
  6. "github.com/astaxie/beego/orm"
  7. )
  8. const (
  9. SOURCE_BALANCE = "balance"
  10. SOURCE_SHOP = "shop"
  11. SOURCE_OTHERS = "others"
  12. presents_tablename = "presents"
  13. )
  14. var SOURCE_CN = map[string]string{
  15. SOURCE_SHOP: "店长促销发放",
  16. SOURCE_BALANCE: "充值促销发放",
  17. SOURCE_OTHERS: "手工添加",
  18. }
  19. type Present struct {
  20. Id int64 `orm:"column(id);pk" json:"id"` // int(11)
  21. WxUId int64 `orm:"column(wx_user_id)" json:"wx_user_id"` // int(11)
  22. Price int64 `orm:"column(price)" json:"price"` // int(11)
  23. Total int64 `orm:"column(total)" json:"total"` // int(11)
  24. SendProd int64 `orm:"column(send_prod1)" json:"send_prod1"` // int(11)
  25. SendNums int64 `orm:"column(send_nums1)" json:"send_nums1"` // int(11)
  26. OrderId string `orm:"column(order_id);null" json:"order_id"` // varchar(32)
  27. Source string `orm:"column(source);null" json:"source"` // varchar(32)
  28. Remark string `orm:"column(remark);null" json:"remark"` // varchar(32)
  29. Status bool `orm:"column(status)" json:"-"` // int(11)
  30. SourceName string `orm:"-" json:"source_name"` // varchar(255)
  31. ProductName string `orm:"-" json:"product_name"` // varchar(255)
  32. CreatedAt time.Time `orm:"column(created_at);null;auto_now_add;type(datetime)" json:"created_at"` // datetime
  33. UpdatedAt time.Time `orm:"column(updated_at);null;auto_now;type(datetime)" json:"updated_at"` // datetime
  34. }
  35. func (self *Present) TableName() string {
  36. return presents_tablename
  37. }
  38. //创建点击统计项
  39. func (self *Present) CreatePresent(wxUId, price, total, prd, nums int64, source, remark string) *Present {
  40. item := &Present{
  41. WxUId: wxUId,
  42. Price: price,
  43. Total: total,
  44. SendProd: prd,
  45. SendNums: nums,
  46. Source: source,
  47. Status: false,
  48. Remark: remark,
  49. }
  50. id, err := orm.NewOrm().Insert(item)
  51. if err != nil {
  52. beego.BeeLogger.Error("insert Present err=[%s]", err)
  53. return nil
  54. }
  55. item.Id = id
  56. return item
  57. }
  58. func (self *Present) Save() error {
  59. if _, err := orm.NewOrm().Update(self); err != nil {
  60. beego.BeeLogger.Error("Save Present id=[%d] .err=[%s]", self.Id, err)
  61. return err
  62. }
  63. return nil
  64. }
  65. //获取所有未写入订单赠品
  66. func GetAllNoPatchPresents(wxUId int64) (presents []*Present) {
  67. present := new(Present)
  68. qs := orm.NewOrm().QueryTable(present)
  69. qs = qs.Filter("wx_user_id", wxUId)
  70. qs = qs.Filter("status", false)
  71. if _, err := qs.OrderBy("-created_at").All(&presents); err != nil {
  72. beego.BeeLogger.Debug("GetAllNoPatchPresents, wxUId=[%d] order list err=[%s]", wxUId, err)
  73. return nil
  74. }
  75. return presents
  76. }