Vestmore_GO/model/killara_customer_logic.go

50 lines
1.3 KiB
Go
Raw Normal View History

2024-04-07 16:03:37 +00:00
package model
2024-04-08 10:13:01 +00:00
import (
"context"
"fmt"
"github.com/jmoiron/sqlx"
)
2024-04-09 15:50:42 +00:00
const (
/**
* 禁止A仓交易12
*/
Disable_A_No = 2
Type_2 = 2
)
2024-04-07 16:03:37 +00:00
type KillaraCustomerModel struct {
// fields ...
2024-04-08 10:13:01 +00:00
db *sqlx.DB
TableName string // 表名
}
func (m *KillaraCustomerModel) Find(ctx context.Context) (result []*KillaraCustomer, err error) {
var customer []*KillaraCustomer
err = m.db.SelectContext(ctx, customer, fmt.Sprintf("select * from %s", m.TableName))
if err != nil {
return nil, err
}
return customer, nil
2024-04-07 16:03:37 +00:00
}
2024-04-09 15:50:42 +00:00
func (m *KillaraCustomerModel) InsertCustomer(data *KillaraCustomer) (int64, error) {
result, err := m.db.NamedExec(`INSERT INTO customer (type, realname, code, telephone, email, nickname, name, status, disable_a, parent_id)
VALUES (:type, :realname, :code, :telephone, :email, :nickname, :name, :status, :disable_a, :parent_id)`, data)
if err != nil {
return 0, err
}
id, err := result.LastInsertId()
return id, err
}
func (m *KillaraCustomerModel) UpdateCustomer(id int64, data *KillaraCustomer) error {
_, err := m.db.NamedExec(
`UPDATE customer SET type=:type, realname=:realname, code=:code, telephone=:telephone, email=:email, nickname=:nickname, name=:name, status=:status, disable_a=:disable_a, parent_id=:parent_id WHERE customer_id=:customer_id`,
data,
)
return err
}