56 lines
1.9 KiB
Go
56 lines
1.9 KiB
Go
package dao
|
|
|
|
import (
|
|
"git.rosy.net.cn/jx-print/globals"
|
|
storeModel "git.rosy.net.cn/jx-print/model/app_model"
|
|
)
|
|
|
|
// CreatePrintStoreBind 创建绑定
|
|
func CreatePrintStoreBind(param *storeModel.PrintBindStore) error {
|
|
return Insert(globals.GetDB(), param)
|
|
}
|
|
|
|
// QueryBindNumber 查询门店绑定数量
|
|
func QueryBindNumber(userId, printNo string) (int, error) {
|
|
sql := `SELECT count(*) FROM print_bind_store WHERE user_id = ? AND print_no = ?`
|
|
|
|
count := 0
|
|
row := globals.GetDB().DB.QueryRow(sql, []interface{}{userId, printNo}...)
|
|
if err := row.Scan(&count); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return count, nil
|
|
}
|
|
|
|
// RelieveToken 解除授权绑定门店信息
|
|
func RelieveToken(userId, printNo string, storeId int64) error {
|
|
_, err := globals.GetDB().Exec(`UPDATE print_bind_store SET bind_status = ? WHERE user_id = ? AND print_no = ? AND store_id = ?`, []interface{}{storeModel.StoreBindPrintFail, userId, printNo, storeId}...)
|
|
return err
|
|
}
|
|
|
|
// QueryStoreAndUserManager 查询用户门店的绑定关系
|
|
func QueryStoreAndUserManager(userId, printNo string, storeId int64) (bool, error) {
|
|
count := 0
|
|
err := globals.GetDB().DB.QueryRow(`SELECT count(*) FROM print_bind_store WHERE user_id = ? AND print_no = ? AND store_id = ?`, []interface{}{userId, printNo, storeId}...).Scan(&count)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
if count != 1 {
|
|
return false, nil
|
|
}
|
|
return true, nil
|
|
}
|
|
|
|
// UpdateStoreAuthorize 失去授权
|
|
func UpdateStoreAuthorize(storeId int64) error {
|
|
_, err := globals.GetDB().Exec(`UPDATE print_bind_store SET store_status = ? WHERE store_id = ?`, []interface{}{storeModel.StoreStatusLose, storeId}...)
|
|
return err
|
|
}
|
|
|
|
// PrintLoseUser 门店打印机失去所属用户,一般是打印机解绑在重新绑定!触发
|
|
func PrintLoseUser() {
|
|
//_, err := globals.GetDB().Exec(`UPDATE print_bind_store SET store_status = ? WHERE store_id = ?`, []interface{}{storeModel.StoreStatusLose, storeId}...)
|
|
//return err
|
|
}
|