maycur_public_offering_sale.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strings"
  6. "time"
  7. )
  8. // MaycurPublicOfferingSale 每刻报销-公募销售表
  9. type MaycurPublicOfferingSale struct {
  10. Id int `orm:"column(id);pk"`
  11. UserId string `description:"同步过来的销售ID"`
  12. Mobile string `description:"手机号"`
  13. Nickname string `description:"销售姓名"`
  14. DeptText string `description:"部门描述"`
  15. IsLeader int `description:"是否为负责人: 0-否; 1-是"`
  16. CreateTime time.Time `description:"创建时间"`
  17. ModifyTime time.Time `description:"更新时间"`
  18. }
  19. func (m *MaycurPublicOfferingSale) TableName() string {
  20. return "maycur_public_offering_sale"
  21. }
  22. func (m *MaycurPublicOfferingSale) Create() (err error) {
  23. o := orm.NewOrm()
  24. id, err := o.Insert(m)
  25. if err != nil {
  26. return
  27. }
  28. m.Id = int(id)
  29. return
  30. }
  31. func (m *MaycurPublicOfferingSale) CreateMulti(items []*MaycurPublicOfferingSale) (err error) {
  32. if len(items) == 0 {
  33. return
  34. }
  35. o := orm.NewOrm()
  36. _, err = o.InsertMulti(len(items), items)
  37. return
  38. }
  39. func (m *MaycurPublicOfferingSale) Update(cols []string) (err error) {
  40. o := orm.NewOrm()
  41. _, err = o.Update(m, cols...)
  42. return
  43. }
  44. func (m *MaycurPublicOfferingSale) Del() (err error) {
  45. o := orm.NewOrm()
  46. sql := `DELETE FROM maycur_public_offering_sale WHERE id = ? LIMIT 1`
  47. _, err = o.Raw(sql, m.Id).Exec()
  48. return
  49. }
  50. func (m *MaycurPublicOfferingSale) GetItemById(id int) (err error) {
  51. o := orm.NewOrm()
  52. sql := `SELECT * FROM maycur_public_offering_sale WHERE id = ? LIMIT 1`
  53. err = o.Raw(sql, id).QueryRow(&m)
  54. return
  55. }
  56. func (m *MaycurPublicOfferingSale) GetItemByCondition(condition string, pars []interface{}) (err error) {
  57. o := orm.NewOrm()
  58. sql := `SELECT * FROM maycur_public_offering_sale WHERE 1=1 `
  59. sql += condition
  60. sql += ` LIMIT 1`
  61. err = o.Raw(sql, pars).QueryRow(&m)
  62. return
  63. }
  64. func (m *MaycurPublicOfferingSale) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  65. o := orm.NewOrm()
  66. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  67. err = o.Raw(sql, pars).QueryRow(&count)
  68. return
  69. }
  70. func (m *MaycurPublicOfferingSale) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*MaycurPublicOfferingSale, err error) {
  71. o := orm.NewOrm()
  72. fields := strings.Join(fieldArr, ",")
  73. if len(fieldArr) == 0 {
  74. fields = `*`
  75. }
  76. order := `ORDER BY create_time DESC`
  77. if orderRule != "" {
  78. order = ` ORDER BY ` + orderRule
  79. }
  80. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  81. _, err = o.Raw(sql, pars).QueryRows(&items)
  82. return
  83. }