-
Notifications
You must be signed in to change notification settings - Fork 263
/
delivery_repo.go
executable file
·80 lines (70 loc) · 1.84 KB
/
delivery_repo.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* Copyright 2014 @ 56x.net.
* name :
* author : jarryliu
* date : 2015-02-16 10:28
* description :
* history :
*/
package repos
import (
deliverImpl "github.com/ixre/go2o/core/domain/delivery"
"github.com/ixre/go2o/core/domain/interface/delivery"
"github.com/ixre/gof/db"
"github.com/ixre/gof/db/orm"
)
var _ delivery.IDeliveryRepo = new(deliveryRepo)
type deliveryRepo struct {
db.Connector
o orm.Orm
}
func NewDeliverRepo(o orm.Orm) delivery.IDeliveryRepo {
return &deliveryRepo{
Connector: o.Connector(),
o: o,
}
}
// 获取配送
func (this *deliveryRepo) GetDelivery(id int32) delivery.IDelivery {
return deliverImpl.NewDelivery(id, this)
}
// 根据区名获取区域
func (this *deliveryRepo) GetAreaByArea(name string) []*delivery.AreaValue {
arr := make([]*delivery.AreaValue, 0)
if err := this.o.Select(&arr, "name LIKE $1",
"%"+name+"%"); err == nil {
return arr
}
return nil
}
// 保存覆盖区域
func (this *deliveryRepo) SaveCoverageArea(v *delivery.CoverageValue) (int32, error) {
return orm.I32(orm.Save(this.o, v, int(v.Id)))
}
// 获取覆盖区域
func (this *deliveryRepo) GetCoverageArea(areaId, id int32) *delivery.CoverageValue {
e := new(delivery.CoverageValue)
err := this.o.GetBy(e, "id= $1 AND area_id= $2", id, areaId)
if err != nil {
return nil
}
return e
}
// 获取所有的覆盖区域
func (this *deliveryRepo) GetAllCoverageAreas(areaId int32) []*delivery.CoverageValue {
e := make([]*delivery.CoverageValue, 0)
err := this.o.Select(&e, "area_id= $1", areaId)
if err != nil {
return nil
}
return e
}
// 获取配送绑定
func (this *deliveryRepo) GetDeliveryBind(mchId, coverageId int32) *delivery.MerchantDeliverBind {
e := new(delivery.MerchantDeliverBind)
err := this.o.GetBy(e, "merchant_id= $1 AND coverage_id= $2", mchId, coverageId)
if err != nil {
return nil
}
return e
}