| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package model
- import (
- "fmt"
- "github.com/zeromicro/go-zero/core/stores/sqlx"
- )
- var _ CbCustomerModel = (*customCbCustomerModel)(nil)
- type (
- // CbCustomerModel is an interface to be customized, add more methods here,
- // and implement the added methods in customCbCustomerModel.
- CbCustomerModel interface {
- cbCustomerModel
- GetCustomerByExternalUserid(openKfid, externalUserid string) (d *CbCustomer, err error)
- GetCustomerByPage(page, size int) (list []CbCustomer, err error)
- UpdateCustomerState(openKfid, externalUserid string, state int) (err error)
- UpdateCustomerLastMsgTime(openKfid, externalUserid string, t int64) (err error)
- }
- customCbCustomerModel struct {
- *defaultCbCustomerModel
- }
- )
- // NewCbCustomerModel returns a model for the database table.
- func NewCbCustomerModel(conn sqlx.SqlConn) CbCustomerModel {
- return &customCbCustomerModel{
- defaultCbCustomerModel: newCbCustomerModel(conn),
- }
- }
- func (m *customCbCustomerModel) GetCustomerByExternalUserid(openKfid, externalUserid string) (d *CbCustomer, err error) {
- query := fmt.Sprintf("select * from %s where `open_kfid` = ? AND `external_userid` = ? limit 1", m.table)
- var resp CbCustomer
- err = m.conn.QueryRow(&resp, query, openKfid, externalUserid)
- d = &resp
- return
- }
- func (m *customCbCustomerModel) UpdateCustomerState(openKfid, externalUserid string, state int) (err error) {
- query := fmt.Sprintf("update %s set `service_state` = ? where `open_kfid` = ? AND `external_userid` = ?", m.table)
- _, err = m.conn.Exec(query, state, openKfid, externalUserid)
- return err
- }
- func (m *customCbCustomerModel) UpdateCustomerLastMsgTime(openKfid, externalUserid string, t int64) (err error) {
- query := fmt.Sprintf("update %s set `last_msg_time` = ? where `open_kfid` = ? AND `external_userid` = ?", m.table)
- _, err = m.conn.Exec(query, t, openKfid, externalUserid)
- return err
- }
- func (m *customCbCustomerModel) GetCustomerByPage(page, size int) (list []CbCustomer, err error) {
- query := fmt.Sprintf("select * from %s where service_state != 4 limit ?,?", m.table)
- err = m.conn.QueryRows(&list, query, (page-1)*size, size)
- return
- }
|