pid.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package mysql
  2. import orm "duoduo/database"
  3. type Pid struct {
  4. CreateTime string `gorm:"column:create_time" json:"create_time"`
  5. OpenID string `gorm:"column:open_id" json:"open_id"`
  6. Pid string `gorm:"column:pid" json:"pid"`
  7. PidStatus int `gorm:"column:pid_status" json:"pid_status"` //1-拼多多 2-淘宝天猫 3-京东
  8. UpdateTime string `gorm:"column:update_time" json:"update_time"`
  9. }
  10. // TableName sets the insert table name for this struct type
  11. func (p *Pid) TableName() string {
  12. return "pid"
  13. }
  14. // 自己 上 上上
  15. //级别 0.5 0.15 0.05 70% 交税+
  16. func (p *Pid) Get() (Pid, error) {
  17. var doc Pid
  18. err := orm.Eloquent.Select("pid").Where("open_id = ? and pid_status = ?", p.OpenID, p.PidStatus).Table(p.TableName()).First(&doc).Error
  19. if err != nil {
  20. return doc, err
  21. }
  22. return doc, nil
  23. }
  24. func (p *Pid) GetOpenId() (Pid, error) {
  25. var doc Pid
  26. err := orm.Eloquent.Select("open_id").Where("pid = ? ", p.OpenID).Table(p.TableName()).First(&doc).Error
  27. if err != nil {
  28. return doc, err
  29. }
  30. return doc, nil
  31. }
  32. func (p *Pid) Create() (Pid, error) {
  33. var doc Pid
  34. result := orm.Eloquent.Table(p.TableName()).Create(&p)
  35. if result.Error != nil {
  36. err := result.Error
  37. return doc, err
  38. }
  39. doc = *p
  40. return doc, nil
  41. }