互动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package models
  2. import (
  3. "hudongzhuanjia/logger"
  4. "time"
  5. "github.com/ouxuanserver/osmanthuswine/src/core"
  6. )
  7. // 用户操作, 主从账号同步信息
  8. // 拔河/摇红包/摇奖券/订单/上墙/霸屏/抽奖/投票/竞拍/打赏/会务
  9. type CustomerOperation struct {
  10. Id int64 `json:"id"`
  11. CustomerId int64 `json:"customer_id" description:"客户id"`
  12. ActivityId int64 `json:"activity_id" description:"主活动id"`
  13. AreaId int64 `json:"area_id" description:"地区id"`
  14. ModuleActivityId int64 `json:"module_activity_id" description:"具体活动id"`
  15. ModuleActivityType string `json:"module_activity_type" description:"具体活动类型"`
  16. Operation string `json:"operation" description:"操作内容"`
  17. OtherData interface{} `json:"other_data" xorm:"-" description:"额外的字段"`
  18. ExtraData string `json:"-" xorm:"text" description:"额外信息"`
  19. IsDelete bool `json:"is_delete" xorm:"default(0)"`
  20. CreatedAt time.Time `json:"created_at" xorm:"created"`
  21. UpdatedAt time.Time `json:"updated_at" xorm:"updated"`
  22. }
  23. func (op *CustomerOperation) SaveCustomerOperation() int64 {
  24. row, err := core.GetXormAuto().InsertOne(op)
  25. if err != nil {
  26. logger.Error("customer operation insert failed. error: %v; content: %s", err, op.ExtraData)
  27. return 0
  28. }
  29. return row
  30. }
  31. func (op *CustomerOperation) GetOpsByCustomerId(customerId int64, areaId int64) []*CustomerOperation {
  32. ops := make([]*CustomerOperation, 0)
  33. var err error
  34. if areaId == 0 {
  35. err = core.GetXormAuto().Where("customer_id=?", customerId).OrderBy("created_at desc").Find(&ops)
  36. } else {
  37. err = core.GetXormAuto().Where("customer_id=? and area_id=?", customerId, areaId).OrderBy("created_at asc").Find(&ops)
  38. }
  39. if err != nil {
  40. logger.Error("customer_operation find failed. error: %v", err)
  41. return nil
  42. }
  43. return ops
  44. }
  45. func (op *CustomerOperation) GetOpByCustomerId(customerId int64) (bool, error) {
  46. return core.GetXormAuto().Where("customer_id=? and is_delete=0", customerId).OrderBy("created_at desc").Get(op)
  47. }
  48. func (op *CustomerOperation) GetOpByActivityId(activityId int64) (bool, error) {
  49. return core.GetXormAuto().Where("activity_id=? and is_delete=0", activityId).OrderBy("created_at desc").Get(op)
  50. }
  51. func (op *CustomerOperation) GetOpByCustomerIdAndActivityId(pid, activityId int64) (bool, error) {
  52. return core.GetXormAuto().Where("customer_id=? and activity_id=?", pid, activityId).OrderBy("created_at desc").Get(op)
  53. }