pg_order_base_dao.go
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package dao
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type OrderBaseDao struct {
transactionContext *transaction.TransactionContext
}
func NewOrderBaseDao(transactionContext *transaction.TransactionContext) (*OrderBaseDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &OrderBaseDao{
transactionContext: transactionContext,
}, nil
}
}
func (dao OrderBaseDao) OrderCodeExist(code string, notId ...int64) (bool, error) {
tx := dao.transactionContext.PgDd
m := &models.OrderBase{}
query := tx.Model(m).Where("order_code=?", code)
if len(notId) > 0 {
query = query.WhereIn("id not in(?)", notId)
}
ok, err := query.Exists()
return ok, err
}
func (dao OrderBaseDao) DeliveryCodeExist(code string, companyId int64, notId ...int64) (bool, error) {
tx := dao.transactionContext.PgDd
m := &models.OrderBase{}
query := tx.Model(m).Where("delivery_code=?", code).Where("company_id=?", companyId)
if len(notId) > 0 {
query = query.WhereIn("id not in(?)", notId)
}
ok, err := query.Exists()
return ok, err
}