eta_business_contract.go 3.6 KB

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