i2bill_acquirer_mkt_qr_model.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package model
  2. import (
  3. "database/sql"
  4. "fmt"
  5. "github.com/xormplus/xorm"
  6. "strings"
  7. "time"
  8. "git.i2edu.net/i2/go-zero/core/stores/sqlc"
  9. "git.i2edu.net/i2/go-zero/core/stores/sqlx"
  10. "git.i2edu.net/i2/go-zero/core/stringx"
  11. "git.i2edu.net/i2/go-zero/tools/goctl/model/sql/builderx"
  12. )
  13. var (
  14. i2billAcquirerMktQrFieldNames = builderx.RawFieldNames(&I2billAcquirerMktQr{})
  15. i2billAcquirerMktQrRows = strings.Join(i2billAcquirerMktQrFieldNames, ",")
  16. i2billAcquirerMktQrRowsExpectAutoSet = strings.Join(stringx.Remove(i2billAcquirerMktQrFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
  17. i2billAcquirerMktQrRowsWithPlaceHolder = strings.Join(stringx.Remove(i2billAcquirerMktQrFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
  18. )
  19. type (
  20. I2billAcquirerMktQrModel interface {
  21. Insert(data I2billAcquirerMktQr) (sql.Result, error)
  22. FindOne(id int64) (*I2billAcquirerMktQr, error)
  23. Update(data I2billAcquirerMktQr) error
  24. Delete(id int64) error
  25. }
  26. defaultI2billAcquirerMktQrModel struct {
  27. conn sqlx.SqlConn
  28. table string
  29. }
  30. I2billAcquirerMktQr struct {
  31. SchoolId sql.NullInt64 `db:"school_id" json:"school_id"` // 校区id
  32. Qr sql.NullString `db:"qr" json:"qr"` // 二维码url
  33. LastUpdateBy sql.NullInt64 `db:"last_update_by" json:"last_update_by"`
  34. Id int64 `db:"id" json:"id"` // 主键
  35. UserId sql.NullInt64 `db:"user_id" json:"user_id"` // 用户id
  36. ActivityId sql.NullInt64 `db:"activity_id" json:"activity_id"` // 活动id
  37. CreateBy sql.NullInt64 `db:"create_by" json:"create_by"`
  38. LastUpdateTime sql.NullTime `db:"last_update_time" json:"last_update_time"`
  39. QuaoYji sql.NullInt64 `db:"quao_yji" json:"quao_yji"` // 渠道一级
  40. CallType sql.NullInt64 `db:"call_type" json:"call_type"` // 渠道二级
  41. MaType sql.NullInt64 `db:"ma_type" json:"ma_type"` //渠道三级
  42. NetworkDetailId sql.NullInt64 `db:"network_detail_id" json:"network_detail_id"` //渠道四级
  43. DelFlag sql.NullInt64 `db:"del_flag" json:"del_flag"`
  44. CreateTime sql.NullTime `db:"create_time" json:"create_time"`
  45. Role sql.NullInt64 `db:"role" json:"role"` //1-兼职2-mk
  46. }
  47. I2billAcquirerMktQrXorm struct {
  48. SchoolId int64 `json:"school_id"`
  49. Qr string `json:"qr"`
  50. LastUpdateBy int64 `json:"last_update_by"`
  51. Id int64 `json:"id"`
  52. UserId int64 `json:"user_id"`
  53. ActivityId int64 `json:"activity_id"`
  54. CreateBy int64 `json:"create_by"`
  55. LastUpdateTime time.Time `json:"last_update_time"`
  56. QuaoYji int64 `json:"quao_yji"` // 渠道一级
  57. CallType int64 `json:"call_type"` // 渠道二级
  58. MaType int64 `json:"ma_type"` //渠道三级
  59. NetworkDetailId int64 `json:"network_detail_id"` //渠道四级
  60. DelFlag int64 `json:"del_flag"`
  61. CreateTime time.Time `json:"create_time"`
  62. Role int64 `json:"role"` //1-兼职2-mk
  63. }
  64. )
  65. func NewI2billAcquirerMktQrModel(conn sqlx.SqlConn) I2billAcquirerMktQrModel {
  66. return &defaultI2billAcquirerMktQrModel{
  67. conn: conn,
  68. table: "`i2bill_acquirer_mkt_qr`",
  69. }
  70. }
  71. func (m *defaultI2billAcquirerMktQrModel) Insert(data I2billAcquirerMktQr) (sql.Result, error) {
  72. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, i2billAcquirerMktQrRowsExpectAutoSet)
  73. ret, err := m.conn.Exec(query, data.SchoolId, data.Qr, data.LastUpdateBy, data.UserId, data.ActivityId, data.CreateBy, data.LastUpdateTime, data.QuaoYji, data.CallType, data.MaType, data.NetworkDetailId, data.DelFlag)
  74. return ret, err
  75. }
  76. func (m *defaultI2billAcquirerMktQrModel) FindOne(id int64) (*I2billAcquirerMktQr, error) {
  77. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", i2billAcquirerMktQrRows, m.table)
  78. var resp I2billAcquirerMktQr
  79. err := m.conn.QueryRow(&resp, query, id)
  80. switch err {
  81. case nil:
  82. return &resp, nil
  83. case sqlc.ErrNotFound:
  84. return nil, ErrNotFound
  85. default:
  86. return nil, err
  87. }
  88. }
  89. func (m *defaultI2billAcquirerMktQrModel) Update(data I2billAcquirerMktQr) error {
  90. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, i2billAcquirerMktQrRowsWithPlaceHolder)
  91. _, err := m.conn.Exec(query, data.SchoolId, data.Qr, data.LastUpdateBy, data.UserId, data.ActivityId, data.CreateBy, data.LastUpdateTime, data.QuaoYji, data.CallType, data.MaType, data.NetworkDetailId, data.DelFlag, data.Id)
  92. return err
  93. }
  94. func (m *defaultI2billAcquirerMktQrModel) Delete(id int64) error {
  95. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  96. _, err := m.conn.Exec(query, id)
  97. return err
  98. }
  99. func (t *I2billAcquirerMktQrXorm) TableName() string {
  100. return "i2bill_acquirer_mkt_qr"
  101. }
  102. func GetAcquirerMktQr(userId int64, engine *xorm.Engine) (*I2billAcquirerMktQrXorm, error) {
  103. bean := new(I2billAcquirerMktQrXorm)
  104. _, err := engine.Where("user_id = ? and del_flag = 0", userId).Get(bean)
  105. return bean, err
  106. }