present.go 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. ProductImage string `orm:"-" json:"product_image"` // varchar(255)
  33. CreatedAt time.Time `orm:"column(created_at);null;auto_now_add;type(datetime)" json:"created_at"` // datetime
  34. UpdatedAt time.Time `orm:"column(updated_at);null;auto_now;type(datetime)" json:"updated_at"` // datetime
  35. }
  36. func (self *Present) TableName() string {
  37. return presents_tablename
  38. }
  39. //创建点击统计项
  40. func (self *Present) CreatePresent(wxUId, price, total, prd, nums int64, source, remark string) *Present {
  41. item := &Present{
  42. WxUId: wxUId,
  43. Price: price,
  44. Total: total,
  45. SendProd: prd,
  46. SendNums: nums,
  47. Source: source,
  48. Status: false,
  49. Remark: remark,
  50. }
  51. id, err := orm.NewOrm().Insert(item)
  52. if err != nil {
  53. beego.BeeLogger.Error("insert Present err=[%s]", err)
  54. return nil
  55. }
  56. item.Id = id
  57. return item
  58. }
  59. func (self *Present) Save() error {
  60. if _, err := orm.NewOrm().Update(self); err != nil {
  61. beego.BeeLogger.Error("Save Present id=[%d] .err=[%s]", self.Id, err)
  62. return err
  63. }
  64. return nil
  65. }
  66. //获取所有未写入订单赠品
  67. func GetAllNoPatchPresents(wxUId int64) (presents []*Present) {
  68. present := new(Present)
  69. qs := orm.NewOrm().QueryTable(present)
  70. qs = qs.Filter("wx_user_id", wxUId)
  71. qs = qs.Filter("status", false)
  72. if _, err := qs.OrderBy("-created_at").All(&presents); err != nil {
  73. beego.BeeLogger.Debug("GetAllNoPatchPresents, wxUId=[%d] order list err=[%s]", wxUId, err)
  74. return nil
  75. }
  76. return presents
  77. }