cbcustomermodel.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package model
  2. import (
  3. "fmt"
  4. "github.com/zeromicro/go-zero/core/stores/sqlx"
  5. )
  6. var _ CbCustomerModel = (*customCbCustomerModel)(nil)
  7. type (
  8. // CbCustomerModel is an interface to be customized, add more methods here,
  9. // and implement the added methods in customCbCustomerModel.
  10. CbCustomerModel interface {
  11. cbCustomerModel
  12. GetCustomerByExternalUserid(openKfid, externalUserid string) (d *CbCustomer, err error)
  13. GetCustomerByPage(page, size int) (list []CbCustomer, err error)
  14. UpdateServiceState(openKfid, externalUserid string, state int) (err error)
  15. }
  16. customCbCustomerModel struct {
  17. *defaultCbCustomerModel
  18. }
  19. )
  20. // NewCbCustomerModel returns a model for the database table.
  21. func NewCbCustomerModel(conn sqlx.SqlConn) CbCustomerModel {
  22. return &customCbCustomerModel{
  23. defaultCbCustomerModel: newCbCustomerModel(conn),
  24. }
  25. }
  26. func (m *customCbCustomerModel) GetCustomerByExternalUserid(openKfid, externalUserid string) (d *CbCustomer, err error) {
  27. query := fmt.Sprintf("select * from %s where `open_kfid` = ? AND `external_userid` = ? limit 1", m.table)
  28. var resp CbCustomer
  29. err = m.conn.QueryRow(&resp, query, openKfid, externalUserid)
  30. d = &resp
  31. return
  32. }
  33. func (m *customCbCustomerModel) UpdateServiceState(openKfid, externalUserid string, state int) (err error) {
  34. query := fmt.Sprintf("update %s set `service_state` = ? where `open_kfid` = ? AND `external_userid` = ?", m.table)
  35. _, err = m.conn.Exec(query, state, openKfid, externalUserid)
  36. return err
  37. }
  38. func (m *customCbCustomerModel) GetCustomerByPage(page, size int) (list []CbCustomer, err error) {
  39. query := fmt.Sprintf("select * from %s where service_state != 4 limit ?,?", m.table)
  40. err = m.conn.QueryRows(&list, query, (page-1)*size, size)
  41. return
  42. }