cbcustomermodel.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. UpdateCustomerState(openKfid, externalUserid string, state int) (err error)
  15. UpdateCustomerLastMsgTime(openKfid, externalUserid string, t int64) (err error)
  16. }
  17. customCbCustomerModel struct {
  18. *defaultCbCustomerModel
  19. }
  20. )
  21. // NewCbCustomerModel returns a model for the database table.
  22. func NewCbCustomerModel(conn sqlx.SqlConn) CbCustomerModel {
  23. return &customCbCustomerModel{
  24. defaultCbCustomerModel: newCbCustomerModel(conn),
  25. }
  26. }
  27. func (m *customCbCustomerModel) GetCustomerByExternalUserid(openKfid, externalUserid string) (d *CbCustomer, err error) {
  28. query := fmt.Sprintf("select * from %s where `open_kfid` = ? AND `external_userid` = ? limit 1", m.table)
  29. var resp CbCustomer
  30. err = m.conn.QueryRow(&resp, query, openKfid, externalUserid)
  31. d = &resp
  32. return
  33. }
  34. func (m *customCbCustomerModel) UpdateCustomerState(openKfid, externalUserid string, state int) (err error) {
  35. query := fmt.Sprintf("update %s set `service_state` = ? where `open_kfid` = ? AND `external_userid` = ?", m.table)
  36. _, err = m.conn.Exec(query, state, openKfid, externalUserid)
  37. return err
  38. }
  39. func (m *customCbCustomerModel) UpdateCustomerLastMsgTime(openKfid, externalUserid string, t int64) (err error) {
  40. query := fmt.Sprintf("update %s set `last_msg_time` = ? where `open_kfid` = ? AND `external_userid` = ?", m.table)
  41. _, err = m.conn.Exec(query, t, openKfid, externalUserid)
  42. return err
  43. }
  44. func (m *customCbCustomerModel) GetCustomerByPage(page, size int) (list []CbCustomer, err error) {
  45. query := fmt.Sprintf("select * from %s where service_state != 4 limit ?,?", m.table)
  46. err = m.conn.QueryRows(&list, query, (page-1)*size, size)
  47. return
  48. }