eta_business_contract.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package eta_business
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strings"
  6. "time"
  7. )
  8. // EtaBusinessContract ETA商家合同表
  9. type EtaBusinessContract struct {
  10. EtaBusinessContractId int `orm:"column(eta_business_contract_id);pk"`
  11. EtaBusinessId int `description:"ETA商家ID"`
  12. SigningTime time.Time `description:"签约时间"`
  13. ExpiredTime time.Time `description:"到期时间"`
  14. IsFirst int `description:"是否为首份签约"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"更新时间"`
  17. }
  18. func (m *EtaBusinessContract) TableName() string {
  19. return "eta_business_contract"
  20. }
  21. func (m *EtaBusinessContract) PrimaryId() string {
  22. return EtaBusinessContractColumns.EtaBusinessContractId
  23. }
  24. var EtaBusinessContractColumns = struct {
  25. EtaBusinessContractId string
  26. EtaBusinessId string
  27. SigningTime string
  28. ExpiredTime string
  29. CreateTime string
  30. ModifyTime string
  31. }{
  32. EtaBusinessContractId: "eta_business_contract_id",
  33. EtaBusinessId: "eta_business_id",
  34. SigningTime: "signing_time",
  35. ExpiredTime: "expired_time",
  36. CreateTime: "create_time",
  37. ModifyTime: "modify_time",
  38. }
  39. func (m *EtaBusinessContract) Create() (err error) {
  40. o := orm.NewOrm()
  41. id, err := o.Insert(m)
  42. if err != nil {
  43. return
  44. }
  45. m.EtaBusinessContractId = int(id)
  46. return
  47. }
  48. func (m *EtaBusinessContract) CreateMulti(items []*EtaBusinessContract) (err error) {
  49. if len(items) == 0 {
  50. return
  51. }
  52. o := orm.NewOrm()
  53. _, err = o.InsertMulti(len(items), items)
  54. return
  55. }
  56. func (m *EtaBusinessContract) Update(cols []string) (err error) {
  57. o := orm.NewOrm()
  58. _, err = o.Update(m, cols...)
  59. return
  60. }
  61. func (m *EtaBusinessContract) Del() (err error) {
  62. o := orm.NewOrm()
  63. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  64. _, err = o.Raw(sql, m.EtaBusinessContractId).Exec()
  65. return
  66. }
  67. func (m *EtaBusinessContract) GetItemById(id int) (item *EtaBusinessContract, err error) {
  68. o := orm.NewOrm()
  69. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  70. err = o.Raw(sql, id).QueryRow(&item)
  71. return
  72. }
  73. func (m *EtaBusinessContract) GetItemByCondition(condition string, pars []interface{}) (err error) {
  74. o := orm.NewOrm()
  75. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
  76. err = o.Raw(sql, pars).QueryRow(&m)
  77. return
  78. }
  79. func (m *EtaBusinessContract) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  80. o := orm.NewOrm()
  81. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  82. err = o.Raw(sql, pars).QueryRow(&count)
  83. return
  84. }
  85. func (m *EtaBusinessContract) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*EtaBusinessContract, err error) {
  86. o := orm.NewOrm()
  87. fields := strings.Join(fieldArr, ",")
  88. if len(fieldArr) == 0 {
  89. fields = `*`
  90. }
  91. order := `ORDER BY create_time DESC`
  92. if orderRule != "" {
  93. order = ` ORDER BY ` + orderRule
  94. }
  95. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  96. _, err = o.Raw(sql, pars).QueryRows(&items)
  97. return
  98. }
  99. // EtaBusinessContractItem 商家签约信息
  100. type EtaBusinessContractItem struct {
  101. EtaBusinessContractId int
  102. EtaBusinessId int `description:"ETA商家ID"`
  103. SigningTime string `description:"签约时间"`
  104. ExpiredTime string `description:"到期时间"`
  105. ExpireDay string `description:"到期天数"`
  106. Using bool `description:"是否当前合约"`
  107. }