Merge branch 'feat/order-domain' into 6-order-domain-service
正在显示
66 个修改的文件
包含
1428 行增加
和
334 行删除
document/partner01/schemas/companyAdmin.yaml
0 → 100644
1 | version: v1 | 1 | version: v1 |
2 | kind: Schema | 2 | kind: Schema |
3 | metadata: | 3 | metadata: |
4 | - name: goods | 4 | + name: good |
5 | description: 订单商品实体 | 5 | description: 订单商品实体 |
6 | attributes: | 6 | attributes: |
7 | - - ref: goodsId | 7 | + - ref: goodId |
8 | required: true | 8 | required: true |
9 | - - ref: goodsNum | 9 | + - ref: goodNum |
10 | required: true | 10 | required: true |
11 | - - ref: goodsDividend | 11 | + - ref: goodDividend |
12 | required: true | 12 | required: true |
13 | - - ref: goodsDividendStatus | 13 | + - ref: goodDividendStatus |
14 | required: true | 14 | required: true |
15 | - - ref: goodsName | 15 | + - ref: goodName |
16 | required: true | 16 | required: true |
17 | - - ref: goodsTotalPrice | 17 | + - ref: goodTotalPrice |
18 | required: true | 18 | required: true |
19 | - ref: remarks | 19 | - ref: remarks |
20 | required: true | 20 | required: true |
21 | - ref: orderNo | 21 | - ref: orderNo |
22 | required: true | 22 | required: true |
23 | - - name: goodsDetail | 23 | + - name: goodDetail |
24 | required: true | 24 | required: true |
25 | - ref: createAt | 25 | - ref: createAt |
26 | required: true | 26 | required: true |
1 | version: v1 | 1 | version: v1 |
2 | kind: Schema | 2 | kind: Schema |
3 | metadata: | 3 | metadata: |
4 | - name: goodsDetail | 4 | + name: goodDetail |
5 | description: 商品详情值对象 | 5 | description: 商品详情值对象 |
6 | attributes: | 6 | attributes: |
7 | - - ref: goodsDetailId | 7 | + - ref: goodDetailId |
8 | required: true | 8 | required: true |
9 | - ref: adjustedNum | 9 | - ref: adjustedNum |
10 | required: true | 10 | required: true |
@@ -10,7 +10,7 @@ metadata: | @@ -10,7 +10,7 @@ metadata: | ||
10 | required: true | 10 | required: true |
11 | - ref: companyId | 11 | - ref: companyId |
12 | required: true | 12 | required: true |
13 | - - ref: partnerId | 13 | + - ref: userId |
14 | required: true | 14 | required: true |
15 | - ref: deliveryCode | 15 | - ref: deliveryCode |
16 | required: true | 16 | required: true |
document/partner01/schemas/partner.yaml
已删除
100644 → 0
1 | -version: v1 | ||
2 | -kind: Schema | ||
3 | -metadata: | ||
4 | - name: partner | ||
5 | - description: 合伙人实体 | ||
6 | - attributes: | ||
7 | - - ref: partnerId | ||
8 | - required: true | ||
9 | - - ref: cooperateTime | ||
10 | - required: true | ||
11 | - - ref: partnerCategory | ||
12 | - required: true | ||
13 | - - ref: partnerCategoryInfos | ||
14 | - required: true | ||
15 | - - ref: partnerInfo | ||
16 | - required: true | ||
17 | - - ref: salesman | ||
18 | - required: true | ||
19 | - - ref: status | ||
20 | - required: true |
@@ -13,13 +13,11 @@ metadata: | @@ -13,13 +13,11 @@ metadata: | ||
13 | required: true | 13 | required: true |
14 | - ref: remarks | 14 | - ref: remarks |
15 | required: false | 15 | required: false |
16 | - - name: adminId | ||
17 | - description: 公司主管理员Id | ||
18 | - type: | ||
19 | - primitive: int64 | ||
20 | - result: | ||
21 | - - ref: count | 16 | + - ref: userAccount |
17 | + required: true | ||
18 | + - ref: userName | ||
22 | required: true | 19 | required: true |
20 | + result: | ||
23 | - name: company | 21 | - name: company |
24 | type: | 22 | type: |
25 | schema: company | 23 | schema: company |
@@ -7,7 +7,9 @@ metadata: | @@ -7,7 +7,9 @@ metadata: | ||
7 | payload: | 7 | payload: |
8 | - ref: companyId | 8 | - ref: companyId |
9 | required: true | 9 | required: true |
10 | - - ref: userId | 10 | + - ref: userAccount |
11 | + required: true | ||
12 | + - ref: userName | ||
11 | required: true | 13 | required: true |
12 | result: | 14 | result: |
13 | - name: company | 15 | - name: company |
@@ -15,11 +15,10 @@ metadata: | @@ -15,11 +15,10 @@ metadata: | ||
15 | required: false | 15 | required: false |
16 | - ref: remarks | 16 | - ref: remarks |
17 | required: false | 17 | required: false |
18 | - - name: adminId | ||
19 | - description: 公司主管理员Id | ||
20 | - type: | ||
21 | - primitive: int64 | ||
22 | - required: false | 18 | + - ref: userAccount |
19 | + required: false | ||
20 | + - ref: userName | ||
21 | + required: false | ||
23 | result: | 22 | result: |
24 | - name: company | 23 | - name: company |
25 | type: | 24 | type: |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type ConvertCompanyStatusCommand struct { | ||
10 | + // 公司Id | ||
11 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
12 | + // 状态 1正常 2禁用 | ||
13 | + Status int64 `json:"status" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (convertCompanyStatusCommand *ConvertCompanyStatusCommand) Valid(validation *validation.Validation) { | ||
17 | + // _ = validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (convertCompanyStatusCommand *ConvertCompanyStatusCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(convertCompanyStatusCommand) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + for _, validErr := range valid.Errors { | ||
28 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
29 | + } | ||
30 | + } | ||
31 | + return nil | ||
32 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type CreateCompanyCommand struct { | ||
10 | + // 公司名称 | ||
11 | + Name string `json:"name" valid:"Required"` | ||
12 | + // 公司简称 | ||
13 | + Abbreviation string `json:"abbreviation" valid:"Required"` | ||
14 | + // 状态 1正常 2禁用 | ||
15 | + Status int64 `json:"status" valid:"Required"` | ||
16 | + // 备注 | ||
17 | + Remarks string `json:"remarks,omitempty"` | ||
18 | + // 公司主管理员账号 | ||
19 | + UserAccount string `json:"userAccount" valid:"Required"` | ||
20 | + // 公司主管理员姓名 | ||
21 | + UserName string `json:"userName" valid:"Required"` | ||
22 | +} | ||
23 | + | ||
24 | +func (createCompanyCommand *CreateCompanyCommand) Valid(validation *validation.Validation) { | ||
25 | + // _ = validation.SetError("CustomValid", "未实现的自定义认证") | ||
26 | +} | ||
27 | + | ||
28 | +func (createCompanyCommand *CreateCompanyCommand) ValidateCommand() error { | ||
29 | + valid := validation.Validation{} | ||
30 | + b, err := valid.Valid(createCompanyCommand) | ||
31 | + if err != nil { | ||
32 | + return err | ||
33 | + } | ||
34 | + if !b { | ||
35 | + for _, validErr := range valid.Errors { | ||
36 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
37 | + } | ||
38 | + } | ||
39 | + return nil | ||
40 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type RemoveCompanyCommand struct { | ||
10 | + // 公司Id | ||
11 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (removeCompanyCommand *RemoveCompanyCommand) Valid(validation *validation.Validation) { | ||
15 | + // _ = validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (removeCompanyCommand *RemoveCompanyCommand) ValidateCommand() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(removeCompanyCommand) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type SetCompanyAdminCommand struct { | ||
10 | + // 公司Id | ||
11 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
12 | + // 公司主管理员账号 | ||
13 | + UserAccount string `json:"userAccount" valid:"Required"` | ||
14 | + // 公司主管理员姓名 | ||
15 | + UserName string `json:"userName" valid:"Required"` | ||
16 | +} | ||
17 | + | ||
18 | +func (setCompanyAdminCommand *SetCompanyAdminCommand) Valid(validation *validation.Validation) { | ||
19 | + // _ = validation.SetError("CustomValid", "未实现的自定义认证") | ||
20 | +} | ||
21 | + | ||
22 | +func (setCompanyAdminCommand *SetCompanyAdminCommand) ValidateCommand() error { | ||
23 | + valid := validation.Validation{} | ||
24 | + b, err := valid.Valid(setCompanyAdminCommand) | ||
25 | + if err != nil { | ||
26 | + return err | ||
27 | + } | ||
28 | + if !b { | ||
29 | + for _, validErr := range valid.Errors { | ||
30 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
31 | + } | ||
32 | + } | ||
33 | + return nil | ||
34 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type UpdateCompanyCommand struct { | ||
10 | + // 公司Id | ||
11 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
12 | + // 公司名称 | ||
13 | + Name string `json:"name,omitempty"` | ||
14 | + // 公司简称 | ||
15 | + Abbreviation string `json:"abbreviation,omitempty"` | ||
16 | + // 状态 1正常 2禁用 | ||
17 | + Status int64 `json:"status,omitempty"` | ||
18 | + // 备注 | ||
19 | + Remarks string `json:"remarks,omitempty"` | ||
20 | + // 公司主管理员账号 | ||
21 | + UserAccount string `json:"userAccount,omitempty"` | ||
22 | + // 公司主管理员姓名 | ||
23 | + UserName string `json:"userName,omitempty"` | ||
24 | +} | ||
25 | + | ||
26 | +func (updateCompanyCommand *UpdateCompanyCommand) Valid(validation *validation.Validation) { | ||
27 | + // _ = validation.SetError("CustomValid", "未实现的自定义认证") | ||
28 | +} | ||
29 | + | ||
30 | +func (updateCompanyCommand *UpdateCompanyCommand) ValidateCommand() error { | ||
31 | + valid := validation.Validation{} | ||
32 | + b, err := valid.Valid(updateCompanyCommand) | ||
33 | + if err != nil { | ||
34 | + return err | ||
35 | + } | ||
36 | + if !b { | ||
37 | + for _, validErr := range valid.Errors { | ||
38 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
39 | + } | ||
40 | + } | ||
41 | + return nil | ||
42 | +} |
pkg/application/company/query/get_company.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type GetCompanyQuery struct { | ||
10 | + // 公司Id | ||
11 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (getCompanyQuery *GetCompanyQuery) Valid(validation *validation.Validation) { | ||
15 | + // _ = validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (getCompanyQuery *GetCompanyQuery) ValidateQuery() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(getCompanyQuery) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type ListCompanyQuery struct { | ||
10 | + // 查询偏离量 | ||
11 | + Offset int `json:"offset" valid:"Required"` | ||
12 | + // 查询限制 | ||
13 | + Limit int `json:"limit" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (listCompanyQuery *ListCompanyQuery) Valid(validation *validation.Validation) { | ||
17 | + // _ = validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (listCompanyQuery *ListCompanyQuery) ValidateQuery() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(listCompanyQuery) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + for _, validErr := range valid.Errors { | ||
28 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
29 | + } | ||
30 | + } | ||
31 | + return nil | ||
32 | +} |
pkg/application/company/service/company.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/linmadan/egglib-go/core/application" | ||
6 | + "github.com/linmadan/egglib-go/utils/tool_funs" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/company/command" | ||
8 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/company/query" | ||
9 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/factory" | ||
10 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
11 | + "time" | ||
12 | +) | ||
13 | + | ||
14 | +// 公司服务 | ||
15 | +type CompanyService struct { | ||
16 | +} | ||
17 | + | ||
18 | +// 公司状态转换 禁用、启用 | ||
19 | +func (companyService *CompanyService) ConvertCompanyStatus(convertCompanyStatusCommand *command.ConvertCompanyStatusCommand) (interface{}, error) { | ||
20 | + if err := convertCompanyStatusCommand.ValidateCommand(); err != nil { | ||
21 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
22 | + } | ||
23 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
24 | + if err != nil { | ||
25 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
26 | + } | ||
27 | + if err := transactionContext.StartTransaction(); err != nil { | ||
28 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
29 | + } | ||
30 | + defer func() { | ||
31 | + transactionContext.RollbackTransaction() | ||
32 | + }() | ||
33 | + var companyRepository domain.CompanyRepository | ||
34 | + if value, err := factory.CreateCompanyRepository(map[string]interface{}{ | ||
35 | + "transactionContext": transactionContext, | ||
36 | + }); err != nil { | ||
37 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
38 | + } else { | ||
39 | + companyRepository = value | ||
40 | + } | ||
41 | + company, err := companyRepository.FindOne(map[string]interface{}{"companyId": convertCompanyStatusCommand.CompanyId}) | ||
42 | + if err != nil { | ||
43 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
44 | + } | ||
45 | + if company == nil { | ||
46 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(convertCompanyStatusCommand.CompanyId))) | ||
47 | + } | ||
48 | + if err := company.Update(tool_funs.SimpleStructToMap(convertCompanyStatusCommand)); err != nil { | ||
49 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
50 | + } | ||
51 | + if company, err := companyRepository.Save(company); err != nil { | ||
52 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
53 | + } else { | ||
54 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
55 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
56 | + } | ||
57 | + return company, nil | ||
58 | + } | ||
59 | +} | ||
60 | + | ||
61 | +// 创建 | ||
62 | +func (companyService *CompanyService) CreateCompany(createCompanyCommand *command.CreateCompanyCommand) (interface{}, error) { | ||
63 | + if err := createCompanyCommand.ValidateCommand(); err != nil { | ||
64 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
65 | + } | ||
66 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
67 | + if err != nil { | ||
68 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
69 | + } | ||
70 | + if err := transactionContext.StartTransaction(); err != nil { | ||
71 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
72 | + } | ||
73 | + defer func() { | ||
74 | + transactionContext.RollbackTransaction() | ||
75 | + }() | ||
76 | + | ||
77 | + newCompany := &domain.Company{ | ||
78 | + CompanyInfo: &domain.CompanyInfo{ | ||
79 | + Name: createCompanyCommand.Name, // 公司名称 | ||
80 | + Abbreviation: createCompanyCommand.Abbreviation, // 公司简称 | ||
81 | + Logo: "", // 公司logo | ||
82 | + Phone: "", // 公司联系电话 | ||
83 | + Status: createCompanyCommand.Status, // 状态 1正常 2禁用 | ||
84 | + Remarks: createCompanyCommand.Remarks, // 备注 | ||
85 | + Enable: 1, // 是否有效【1:有效】【2:无效】 | ||
86 | + Admin: &domain.CompanyAdmin{ | ||
87 | + UserAccount: createCompanyCommand.UserAccount, // 用户手机号 | ||
88 | + UserName: createCompanyCommand.UserName, // 用户名称 | ||
89 | + }, // 公司主管理员 | ||
90 | + }, | ||
91 | + CreateAt: time.Now(), | ||
92 | + UpdateAt: time.Now(), | ||
93 | + } | ||
94 | + var companyRepository domain.CompanyRepository | ||
95 | + if value, err := factory.CreateCompanyRepository(map[string]interface{}{ | ||
96 | + "transactionContext": transactionContext, | ||
97 | + }); err != nil { | ||
98 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
99 | + } else { | ||
100 | + companyRepository = value | ||
101 | + } | ||
102 | + if company, err := companyRepository.Save(newCompany); err != nil { | ||
103 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
104 | + } else { | ||
105 | + // todo 新增公司管理员 | ||
106 | + | ||
107 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
108 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
109 | + } | ||
110 | + return company, nil | ||
111 | + } | ||
112 | +} | ||
113 | + | ||
114 | +// 返回 | ||
115 | +func (companyService *CompanyService) GetCompany(getCompanyQuery *query.GetCompanyQuery) (interface{}, error) { | ||
116 | + if err := getCompanyQuery.ValidateQuery(); err != nil { | ||
117 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
118 | + } | ||
119 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
120 | + if err != nil { | ||
121 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
122 | + } | ||
123 | + if err := transactionContext.StartTransaction(); err != nil { | ||
124 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
125 | + } | ||
126 | + defer func() { | ||
127 | + transactionContext.RollbackTransaction() | ||
128 | + }() | ||
129 | + var companyRepository domain.CompanyRepository | ||
130 | + if value, err := factory.CreateCompanyRepository(map[string]interface{}{ | ||
131 | + "transactionContext": transactionContext, | ||
132 | + }); err != nil { | ||
133 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
134 | + } else { | ||
135 | + companyRepository = value | ||
136 | + } | ||
137 | + company, err := companyRepository.FindOne(map[string]interface{}{"companyId": getCompanyQuery.CompanyId}) | ||
138 | + if err != nil { | ||
139 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
140 | + } | ||
141 | + if company == nil { | ||
142 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getCompanyQuery.CompanyId))) | ||
143 | + } else { | ||
144 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
145 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
146 | + } | ||
147 | + return company, nil | ||
148 | + } | ||
149 | +} | ||
150 | + | ||
151 | +// 返回列表 | ||
152 | +func (companyService *CompanyService) ListCompany(listCompanyQuery *query.ListCompanyQuery) (interface{}, error) { | ||
153 | + if err := listCompanyQuery.ValidateQuery(); err != nil { | ||
154 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
155 | + } | ||
156 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
157 | + if err != nil { | ||
158 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
159 | + } | ||
160 | + if err := transactionContext.StartTransaction(); err != nil { | ||
161 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
162 | + } | ||
163 | + defer func() { | ||
164 | + transactionContext.RollbackTransaction() | ||
165 | + }() | ||
166 | + var companyRepository domain.CompanyRepository | ||
167 | + if value, err := factory.CreateCompanyRepository(map[string]interface{}{ | ||
168 | + "transactionContext": transactionContext, | ||
169 | + }); err != nil { | ||
170 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
171 | + } else { | ||
172 | + companyRepository = value | ||
173 | + } | ||
174 | + if count, companies, err := companyRepository.Find(tool_funs.SimpleStructToMap(listCompanyQuery)); err != nil { | ||
175 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
176 | + } else { | ||
177 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
178 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
179 | + } | ||
180 | + return map[string]interface{}{ | ||
181 | + "count": count, | ||
182 | + "companies": companies, | ||
183 | + }, nil | ||
184 | + } | ||
185 | +} | ||
186 | + | ||
187 | +// 移除 | ||
188 | +func (companyService *CompanyService) RemoveCompany(removeCompanyCommand *command.RemoveCompanyCommand) (interface{}, error) { | ||
189 | + if err := removeCompanyCommand.ValidateCommand(); err != nil { | ||
190 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
191 | + } | ||
192 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
193 | + if err != nil { | ||
194 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
195 | + } | ||
196 | + if err := transactionContext.StartTransaction(); err != nil { | ||
197 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
198 | + } | ||
199 | + defer func() { | ||
200 | + transactionContext.RollbackTransaction() | ||
201 | + }() | ||
202 | + var companyRepository domain.CompanyRepository | ||
203 | + if value, err := factory.CreateCompanyRepository(map[string]interface{}{ | ||
204 | + "transactionContext": transactionContext, | ||
205 | + }); err != nil { | ||
206 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
207 | + } else { | ||
208 | + companyRepository = value | ||
209 | + } | ||
210 | + company, err := companyRepository.FindOne(map[string]interface{}{"companyId": removeCompanyCommand.CompanyId}) | ||
211 | + if err != nil { | ||
212 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
213 | + } | ||
214 | + if company == nil { | ||
215 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeCompanyCommand.CompanyId))) | ||
216 | + } | ||
217 | + if company, err := companyRepository.Remove(company); err != nil { | ||
218 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
219 | + } else { | ||
220 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
221 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
222 | + } | ||
223 | + return company, nil | ||
224 | + } | ||
225 | +} | ||
226 | + | ||
227 | +// 设置公司管理员 | ||
228 | +func (companyService *CompanyService) SetCompanyAdmin(setCompanyAdminCommand *command.SetCompanyAdminCommand) (interface{}, error) { | ||
229 | + if err := setCompanyAdminCommand.ValidateCommand(); err != nil { | ||
230 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
231 | + } | ||
232 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
233 | + if err != nil { | ||
234 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
235 | + } | ||
236 | + if err := transactionContext.StartTransaction(); err != nil { | ||
237 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
238 | + } | ||
239 | + defer func() { | ||
240 | + transactionContext.RollbackTransaction() | ||
241 | + }() | ||
242 | + var companyRepository domain.CompanyRepository | ||
243 | + if value, err := factory.CreateCompanyRepository(map[string]interface{}{ | ||
244 | + "transactionContext": transactionContext, | ||
245 | + }); err != nil { | ||
246 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
247 | + } else { | ||
248 | + companyRepository = value | ||
249 | + } | ||
250 | + company, err := companyRepository.FindOne(map[string]interface{}{"companyId": setCompanyAdminCommand.CompanyId}) | ||
251 | + if err != nil { | ||
252 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
253 | + } | ||
254 | + if company == nil { | ||
255 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(setCompanyAdminCommand.CompanyId))) | ||
256 | + } | ||
257 | + | ||
258 | + newCompanyAdmin := &domain.CompanyAdmin{ | ||
259 | + UserAccount: setCompanyAdminCommand.UserAccount, // 用户手机号 | ||
260 | + UserName: setCompanyAdminCommand.UserName, // 用户名称 | ||
261 | + } | ||
262 | + // 更改公司管理员信息 | ||
263 | + if err := company.SetCompanyAdmin(newCompanyAdmin); err != nil { | ||
264 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
265 | + } | ||
266 | + | ||
267 | + if company, err := companyRepository.Save(company); err != nil { | ||
268 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
269 | + } else { | ||
270 | + // todo 更改公司管理员 | ||
271 | + | ||
272 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
273 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
274 | + } | ||
275 | + return company, nil | ||
276 | + } | ||
277 | +} | ||
278 | + | ||
279 | +// 更新 | ||
280 | +func (companyService *CompanyService) UpdateCompany(updateCompanyCommand *command.UpdateCompanyCommand) (interface{}, error) { | ||
281 | + if err := updateCompanyCommand.ValidateCommand(); err != nil { | ||
282 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
283 | + } | ||
284 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
285 | + if err != nil { | ||
286 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
287 | + } | ||
288 | + if err := transactionContext.StartTransaction(); err != nil { | ||
289 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
290 | + } | ||
291 | + defer func() { | ||
292 | + transactionContext.RollbackTransaction() | ||
293 | + }() | ||
294 | + var companyRepository domain.CompanyRepository | ||
295 | + if value, err := factory.CreateCompanyRepository(map[string]interface{}{ | ||
296 | + "transactionContext": transactionContext, | ||
297 | + }); err != nil { | ||
298 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
299 | + } else { | ||
300 | + companyRepository = value | ||
301 | + } | ||
302 | + company, err := companyRepository.FindOne(map[string]interface{}{"companyId": updateCompanyCommand.CompanyId}) | ||
303 | + if err != nil { | ||
304 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
305 | + } | ||
306 | + if company == nil { | ||
307 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCompanyCommand.CompanyId))) | ||
308 | + } | ||
309 | + if err := company.Update(tool_funs.SimpleStructToMap(updateCompanyCommand)); err != nil { | ||
310 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
311 | + } | ||
312 | + | ||
313 | + // 更改公司管理员信息 | ||
314 | + if updateCompanyCommand.UserAccount != "" || updateCompanyCommand.UserName != "" { | ||
315 | + companyAdmin := company.CompanyInfo.Admin | ||
316 | + if updateCompanyCommand.UserAccount != "" { | ||
317 | + companyAdmin.UserAccount = updateCompanyCommand.UserAccount // 用户手机号 | ||
318 | + } | ||
319 | + if updateCompanyCommand.UserName != "" { | ||
320 | + companyAdmin.UserName = updateCompanyCommand.UserName // 用户名称 | ||
321 | + } | ||
322 | + if err := company.SetCompanyAdmin(companyAdmin); err != nil { | ||
323 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
324 | + } | ||
325 | + | ||
326 | + // todo 更改公司管理员 | ||
327 | + } | ||
328 | + | ||
329 | + if company, err := companyRepository.Save(company); err != nil { | ||
330 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
331 | + } else { | ||
332 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
333 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
334 | + } | ||
335 | + return company, nil | ||
336 | + } | ||
337 | +} | ||
338 | + | ||
339 | +func NewCompanyService(options map[string]interface{}) *CompanyService { | ||
340 | + newCompanyService := &CompanyService{} | ||
341 | + return newCompanyService | ||
342 | +} |
@@ -38,7 +38,7 @@ func CreateOrderRepository(options map[string]interface{}) (domain.OrderReposito | @@ -38,7 +38,7 @@ func CreateOrderRepository(options map[string]interface{}) (domain.OrderReposito | ||
38 | return repository.NewOrderRepository(transactionContext) | 38 | return repository.NewOrderRepository(transactionContext) |
39 | } | 39 | } |
40 | 40 | ||
41 | -func CreateGoodsRepository(options map[string]interface{}) (domain.GoodsRepository, error) { | 41 | +func CreateGoodsRepository(options map[string]interface{}) (domain.GoodRepository, error) { |
42 | var transactionContext *pg.TransactionContext | 42 | var transactionContext *pg.TransactionContext |
43 | if value, ok := options["transactionContext"]; ok { | 43 | if value, ok := options["transactionContext"]; ok { |
44 | transactionContext = value.(*pg.TransactionContext) | 44 | transactionContext = value.(*pg.TransactionContext) |
@@ -7,6 +7,8 @@ import ( | @@ -7,6 +7,8 @@ import ( | ||
7 | ) | 7 | ) |
8 | 8 | ||
9 | type CreateOrderCommand struct { | 9 | type CreateOrderCommand struct { |
10 | + // 订单ID | ||
11 | + OrderId int64 `json:"orderId"` | ||
10 | // 订单编号 | 12 | // 订单编号 |
11 | OrderNo string `json:"orderNo" valid:"Required"` | 13 | OrderNo string `json:"orderNo" valid:"Required"` |
12 | // 公司Id | 14 | // 公司Id |
@@ -15,16 +17,24 @@ type CreateOrderCommand struct { | @@ -15,16 +17,24 @@ type CreateOrderCommand struct { | ||
15 | BuyerName string `json:"buyerName,omitempty"` | 17 | BuyerName string `json:"buyerName,omitempty"` |
16 | // 联系信息 | 18 | // 联系信息 |
17 | ContactInfo string `json:"contactInfo,omitempty"` | 19 | ContactInfo string `json:"contactInfo,omitempty"` |
18 | - // 发货地址 | 20 | + // 收货地址 |
19 | ShippingAddress string `json:"shippingAddress,omitempty"` | 21 | ShippingAddress string `json:"shippingAddress,omitempty"` |
22 | + // 买家备注 | ||
23 | + Remarks string `json:"remarks,omitempty"` | ||
20 | // 订单商品总数 | 24 | // 订单商品总数 |
21 | OrderNum int64 `json:"orderNum" valid:"Required"` | 25 | OrderNum int64 `json:"orderNum" valid:"Required"` |
22 | // 订单总价 | 26 | // 订单总价 |
23 | TotalPrice float64 `json:"totalPrice" valid:"Required"` | 27 | TotalPrice float64 `json:"totalPrice" valid:"Required"` |
28 | + // 订单合伙人ID | ||
29 | + PartnerId int64 `json:"partnerId"` | ||
30 | + // 订单状态 | ||
31 | + OrderStatus int `json:"orderStatus"` | ||
32 | + // 订单类型 | ||
33 | + OrderType int `json:"orderType"` | ||
24 | } | 34 | } |
25 | 35 | ||
26 | func (createOrderCommand *CreateOrderCommand) Valid(validation *validation.Validation) { | 36 | func (createOrderCommand *CreateOrderCommand) Valid(validation *validation.Validation) { |
27 | - validation.SetError("CustomValid", "未实现的自定义认证") | 37 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
28 | } | 38 | } |
29 | 39 | ||
30 | func (createOrderCommand *CreateOrderCommand) ValidateCommand() error { | 40 | func (createOrderCommand *CreateOrderCommand) ValidateCommand() error { |
@@ -14,7 +14,7 @@ type DrawDividendsCommand struct { | @@ -14,7 +14,7 @@ type DrawDividendsCommand struct { | ||
14 | } | 14 | } |
15 | 15 | ||
16 | func (drawDividendsCommand *DrawDividendsCommand) Valid(validation *validation.Validation) { | 16 | func (drawDividendsCommand *DrawDividendsCommand) Valid(validation *validation.Validation) { |
17 | - validation.SetError("CustomValid", "未实现的自定义认证") | 17 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
18 | } | 18 | } |
19 | 19 | ||
20 | func (drawDividendsCommand *DrawDividendsCommand) ValidateCommand() error { | 20 | func (drawDividendsCommand *DrawDividendsCommand) ValidateCommand() error { |
@@ -2,40 +2,16 @@ package command | @@ -2,40 +2,16 @@ package command | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | - "time" | ||
6 | - | ||
7 | "github.com/beego/beego/v2/core/validation" | 5 | "github.com/beego/beego/v2/core/validation" |
8 | ) | 6 | ) |
9 | 7 | ||
10 | type ReturnGoodsCommand struct { | 8 | type ReturnGoodsCommand struct { |
9 | + // 订单ID | ||
10 | + OrderId int64 `json:"orderId" valid:"Required"` | ||
11 | // 订单号 | 11 | // 订单号 |
12 | OrderNo string `json:"orderNo" valid:"Required"` | 12 | OrderNo string `json:"orderNo" valid:"Required"` |
13 | - // 是否是公司负责人 | ||
14 | - IsPrincipal bool `json:"isPrincipal" valid:"Required"` | ||
15 | // 统一用户id | 13 | // 统一用户id |
16 | Uid int64 `json:"uid" valid:"Required"` | 14 | Uid int64 `json:"uid" valid:"Required"` |
17 | - // 用户账号 | ||
18 | - UserAccount string `json:"userAccount" valid:"Required"` | ||
19 | - // 用户头像URL | ||
20 | - UserAvatarUrl string `json:"userAvatarUrl" valid:"Required"` | ||
21 | - // 用户名称 | ||
22 | - UserName string `json:"userName" valid:"Required"` | ||
23 | - // 邮件地址 | ||
24 | - Email string `json:"email" valid:"Required"` | ||
25 | - // 性别 | ||
26 | - Gender int `json:"gender" valid:"Required"` | ||
27 | - // 入职时间 | ||
28 | - EntryTime time.Time `json:"entryTime" valid:"Required"` | ||
29 | - // 分机 | ||
30 | - Extension string `json:"extension" valid:"Required"` | ||
31 | - // 工作地 | ||
32 | - Workplace string `json:"workplace" valid:"Required"` | ||
33 | - // 私人电话 | ||
34 | - PrivateNumber string `json:"privateNumber" valid:"Required"` | ||
35 | - // 工号 | ||
36 | - JobNumber string `json:"jobNumber" valid:"Required"` | ||
37 | - // 公司id | ||
38 | - CompanyId int64 `json:"companyId" valid:"Required"` | ||
39 | } | 15 | } |
40 | 16 | ||
41 | func (returnGoodsCommand *ReturnGoodsCommand) Valid(validation *validation.Validation) { | 17 | func (returnGoodsCommand *ReturnGoodsCommand) Valid(validation *validation.Validation) { |
@@ -9,10 +9,18 @@ import ( | @@ -9,10 +9,18 @@ import ( | ||
9 | type UpdateOrderCommand struct { | 9 | type UpdateOrderCommand struct { |
10 | // 订单id | 10 | // 订单id |
11 | OrderId int64 `json:"orderId" valid:"Required"` | 11 | OrderId int64 `json:"orderId" valid:"Required"` |
12 | + // 发货地址 | ||
13 | + BuyerName string `json:"buyerName"` | ||
14 | + // 订单商品总数 | ||
15 | + OrderNum string `json:"orderNum"` | ||
16 | + // 订单总价 | ||
17 | + TotalPrice float64 `json:"totalPrice"` | ||
18 | + // 收货地址 | ||
19 | + ShippingAddress string `json:"shippingAddress" valid:"omitempty"` | ||
12 | } | 20 | } |
13 | 21 | ||
14 | func (updateOrderCommand *UpdateOrderCommand) Valid(validation *validation.Validation) { | 22 | func (updateOrderCommand *UpdateOrderCommand) Valid(validation *validation.Validation) { |
15 | - validation.SetError("CustomValid", "未实现的自定义认证") | 23 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
16 | } | 24 | } |
17 | 25 | ||
18 | func (updateOrderCommand *UpdateOrderCommand) ValidateCommand() error { | 26 | func (updateOrderCommand *UpdateOrderCommand) ValidateCommand() error { |
@@ -8,4 +8,6 @@ type BuyerInfo struct { | @@ -8,4 +8,6 @@ type BuyerInfo struct { | ||
8 | ContactInfo string `json:"contactInfo"` | 8 | ContactInfo string `json:"contactInfo"` |
9 | // 发货地址 | 9 | // 发货地址 |
10 | ShippingAddress string `json:"shippingAddress"` | 10 | ShippingAddress string `json:"shippingAddress"` |
11 | + // 买家备注 | ||
12 | + Remarks string `json:"remarks"` | ||
11 | } | 13 | } |
@@ -34,9 +34,6 @@ func (company *Company) Update(data map[string]interface{}) error { | @@ -34,9 +34,6 @@ func (company *Company) Update(data map[string]interface{}) error { | ||
34 | if companyId, ok := data["companyId"]; ok { | 34 | if companyId, ok := data["companyId"]; ok { |
35 | company.CompanyId = companyId.(int64) | 35 | company.CompanyId = companyId.(int64) |
36 | } | 36 | } |
37 | - if companyId, ok := data["companyId"]; ok { | ||
38 | - company.CompanyInfo.CompanyId = companyId.(int64) | ||
39 | - } | ||
40 | if name, ok := data["name"]; ok { | 37 | if name, ok := data["name"]; ok { |
41 | company.CompanyInfo.Name = name.(string) | 38 | company.CompanyInfo.Name = name.(string) |
42 | } | 39 | } |
@@ -58,5 +55,28 @@ func (company *Company) Update(data map[string]interface{}) error { | @@ -58,5 +55,28 @@ func (company *Company) Update(data map[string]interface{}) error { | ||
58 | if enable, ok := data["enable"]; ok { | 55 | if enable, ok := data["enable"]; ok { |
59 | company.CompanyInfo.Enable = enable.(int64) | 56 | company.CompanyInfo.Enable = enable.(int64) |
60 | } | 57 | } |
58 | + if userAccount, ok := data["userAccount"]; ok { | ||
59 | + company.CompanyInfo.Admin.UserAccount = userAccount.(string) | ||
60 | + } | ||
61 | + if userName, ok := data["userName"]; ok { | ||
62 | + company.CompanyInfo.Admin.UserName = userName.(string) | ||
63 | + } | ||
64 | + | ||
65 | + if createAt, ok := data["createAt"]; ok { | ||
66 | + company.CreateAt = createAt.(time.Time) | ||
67 | + } | ||
68 | + if updateAt, ok := data["updateAt"]; ok { | ||
69 | + company.UpdateAt = updateAt.(time.Time) | ||
70 | + } | ||
71 | + if deleteAt, ok := data["deleteAt"]; ok { | ||
72 | + company.DeleteAt = deleteAt.(time.Time) | ||
73 | + } | ||
74 | + | ||
75 | + return nil | ||
76 | +} | ||
77 | + | ||
78 | +// 更改公司管理员信息 | ||
79 | +func (company *Company) SetCompanyAdmin(admin *CompanyAdmin) error { | ||
80 | + company.CompanyInfo.Admin = admin | ||
61 | return nil | 81 | return nil |
62 | } | 82 | } |
@@ -2,22 +2,18 @@ package domain | @@ -2,22 +2,18 @@ package domain | ||
2 | 2 | ||
3 | // 公司信息 | 3 | // 公司信息 |
4 | type CompanyInfo struct { | 4 | type CompanyInfo struct { |
5 | - // 公司Id | ||
6 | - CompanyId int64 `json:"companyId"` | ||
7 | - // 公司名称 | ||
8 | - Name string `json:"name"` | ||
9 | - // 公司简称 | ||
10 | - Abbreviation string `json:"abbreviation"` | ||
11 | - // 公司logo | ||
12 | - Logo string `json:"logo"` | ||
13 | - // 公司联系电话 | ||
14 | - Phone string `json:"phone"` | ||
15 | - // 状态 1正常 2禁用 | ||
16 | - Status int64 `json:"status"` | ||
17 | - // 备注 | ||
18 | - Remarks string `json:"remarks"` | ||
19 | - // 是否有效【1:有效】【2:无效】 | ||
20 | - Enable int64 `json:"enable"` | ||
21 | - // 公司主管理员 | ||
22 | - Admin *UserInfo `json:"admin"` | 5 | + Name string `json:"name"` // 公司名称 |
6 | + Abbreviation string `json:"abbreviation"` // 公司简称 | ||
7 | + Logo string `json:"logo"` // 公司logo | ||
8 | + Phone string `json:"phone"` // 公司联系电话 | ||
9 | + Status int64 `json:"status"` // 状态 1正常 2禁用 | ||
10 | + Remarks string `json:"remarks"` // 备注 | ||
11 | + Enable int64 `json:"enable"` // 是否有效【1:有效】【2:无效】 | ||
12 | + Admin *CompanyAdmin `json:"admin"` // 公司主管理员 | ||
13 | +} | ||
14 | + | ||
15 | +// 公司管理员信息值对象 | ||
16 | +type CompanyAdmin struct { | ||
17 | + UserAccount string `json:"userPhone"` // 用户手机号 | ||
18 | + UserName string `json:"userName"` // 用户名称 | ||
23 | } | 19 | } |
@@ -3,24 +3,25 @@ package domain | @@ -3,24 +3,25 @@ package domain | ||
3 | import "time" | 3 | import "time" |
4 | 4 | ||
5 | // 订单商品实体 | 5 | // 订单商品实体 |
6 | -type Goods struct { | 6 | +type Good struct { |
7 | // 商品id | 7 | // 商品id |
8 | - GoodsId int64 `json:"goodsId"` | 8 | + GoodId int64 `json:"goodId"` |
9 | // 预定的货品数量 | 9 | // 预定的货品数量 |
10 | - GoodsNum int `json:"goodsNum"` | 10 | + GoodNum int `json:"goodNum"` |
11 | // 商品分红支付信息 | 11 | // 商品分红支付信息 |
12 | - GoodsDividend *Dividend `json:"goodsDividend"` | 12 | + GoodDividend *Dividend `json:"goodDividend"` |
13 | // 商品分红支付状态 | 13 | // 商品分红支付状态 |
14 | - GoodsDividendStatus int `json:"goodsDividendStatus"` | 14 | + GoodDividendStatus int `json:"goodDividendStatus"` |
15 | // 商品名称 | 15 | // 商品名称 |
16 | - GoodsName string `json:"goodsName"` | 16 | + GoodName string `json:"goodName"` |
17 | // 商品单价 | 17 | // 商品单价 |
18 | - GoodsTotalPrice float64 `json:"goodsTotalPrice"` | 18 | + GoodTotalPrice float64 `json:"goodTotalPrice"` |
19 | // 备注 | 19 | // 备注 |
20 | Remarks string `json:"remarks"` | 20 | Remarks string `json:"remarks"` |
21 | // 订单编号 | 21 | // 订单编号 |
22 | - OrderNo string `json:"orderNo"` | ||
23 | - GoodsDetail string `json:"goodsDetail"` | 22 | + OrderNo string `json:"orderNo"` |
23 | + // 商品详情 | ||
24 | + GoodDetail string `json:"goodDetail"` | ||
24 | // 创建时间 | 25 | // 创建时间 |
25 | CreateAt time.Time `json:"createAt"` | 26 | CreateAt time.Time `json:"createAt"` |
26 | // 更新时间 | 27 | // 更新时间 |
@@ -29,80 +30,80 @@ type Goods struct { | @@ -29,80 +30,80 @@ type Goods struct { | ||
29 | DeleteAt time.Time `json:"deleteAt"` | 30 | DeleteAt time.Time `json:"deleteAt"` |
30 | } | 31 | } |
31 | 32 | ||
32 | -type GoodsRepository interface { | ||
33 | - Save(goods *Goods) (*Goods, error) | ||
34 | - Remove(goods *Goods) (*Goods, error) | ||
35 | - FindOne(queryOptions map[string]interface{}) (*Goods, error) | ||
36 | - Find(queryOptions map[string]interface{}) (int64, []*Goods, error) | 33 | +type GoodRepository interface { |
34 | + Save(good *Good) (*Good, error) | ||
35 | + Remove(good *Good) (*Good, error) | ||
36 | + FindOne(queryOptions map[string]interface{}) (*Good, error) | ||
37 | + Find(queryOptions map[string]interface{}) (int64, []*Good, error) | ||
37 | } | 38 | } |
38 | 39 | ||
39 | -func (goods *Goods) Identify() interface{} { | ||
40 | - if goods.GoodsId == 0 { | 40 | +func (good *Good) Identify() interface{} { |
41 | + if good.GoodId == 0 { | ||
41 | return nil | 42 | return nil |
42 | } | 43 | } |
43 | - return goods.GoodsId | 44 | + return good.GoodId |
44 | } | 45 | } |
45 | 46 | ||
46 | -func (goods *Goods) Update(data map[string]interface{}) error { | ||
47 | - if goodsId, ok := data["goodsId"]; ok { | ||
48 | - goods.GoodsId = goodsId.(int64) | 47 | +func (good *Good) Update(data map[string]interface{}) error { |
48 | + if goodId, ok := data["goodId"]; ok { | ||
49 | + good.GoodId = goodId.(int64) | ||
49 | } | 50 | } |
50 | - if goodsNum, ok := data["goodsNum"]; ok { | ||
51 | - goods.GoodsNum = goodsNum.(int) | 51 | + if goodNum, ok := data["goodNum"]; ok { |
52 | + good.GoodNum = goodNum.(int) | ||
52 | } | 53 | } |
53 | if planBonus, ok := data["planBonus"]; ok { | 54 | if planBonus, ok := data["planBonus"]; ok { |
54 | - goods.GoodsDividend.PlanBonus = planBonus.(float64) | 55 | + good.GoodDividend.PlanBonus = planBonus.(float64) |
55 | } | 56 | } |
56 | if useBonus, ok := data["useBonus"]; ok { | 57 | if useBonus, ok := data["useBonus"]; ok { |
57 | - goods.GoodsDividend.UseBonus = useBonus.(float64) | 58 | + good.GoodDividend.UseBonus = useBonus.(float64) |
58 | } | 59 | } |
59 | if bonusHas, ok := data["bonusHas"]; ok { | 60 | if bonusHas, ok := data["bonusHas"]; ok { |
60 | - goods.GoodsDividend.BonusHas = bonusHas.(float64) | 61 | + good.GoodDividend.BonusHas = bonusHas.(float64) |
61 | } | 62 | } |
62 | if bonusNot, ok := data["bonusNot"]; ok { | 63 | if bonusNot, ok := data["bonusNot"]; ok { |
63 | - goods.GoodsDividend.BonusNot = bonusNot.(float64) | 64 | + good.GoodDividend.BonusNot = bonusNot.(float64) |
64 | } | 65 | } |
65 | if bonusExpense, ok := data["bonusExpense"]; ok { | 66 | if bonusExpense, ok := data["bonusExpense"]; ok { |
66 | - goods.GoodsDividend.BonusExpense = bonusExpense.(float64) | 67 | + good.GoodDividend.BonusExpense = bonusExpense.(float64) |
67 | } | 68 | } |
68 | if bonusStatus, ok := data["bonusStatus"]; ok { | 69 | if bonusStatus, ok := data["bonusStatus"]; ok { |
69 | - goods.GoodsDividend.BonusStatus = bonusStatus.(int) | 70 | + good.GoodDividend.BonusStatus = bonusStatus.(int) |
70 | } | 71 | } |
71 | if partnerBonusPercent, ok := data["partnerBonusPercent"]; ok { | 72 | if partnerBonusPercent, ok := data["partnerBonusPercent"]; ok { |
72 | - goods.GoodsDividend.PartnerBonusPercent = partnerBonusPercent.(float64) | 73 | + good.GoodDividend.PartnerBonusPercent = partnerBonusPercent.(float64) |
73 | } | 74 | } |
74 | if salesmanBonusPercent, ok := data["salesmanBonusPercent"]; ok { | 75 | if salesmanBonusPercent, ok := data["salesmanBonusPercent"]; ok { |
75 | - goods.GoodsDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64) | 76 | + good.GoodDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64) |
76 | } | 77 | } |
77 | if salesmanBonus, ok := data["salesmanBonus"]; ok { | 78 | if salesmanBonus, ok := data["salesmanBonus"]; ok { |
78 | - goods.GoodsDividend.SalesmanBonus = salesmanBonus.(float64) | 79 | + good.GoodDividend.SalesmanBonus = salesmanBonus.(float64) |
79 | } | 80 | } |
80 | - if goodsDividendStatus, ok := data["goodsDividendStatus"]; ok { | ||
81 | - goods.GoodsDividendStatus = goodsDividendStatus.(int) | 81 | + if goodDividendStatus, ok := data["goodDividendStatus"]; ok { |
82 | + good.GoodDividendStatus = goodDividendStatus.(int) | ||
82 | } | 83 | } |
83 | - if goodsName, ok := data["goodsName"]; ok { | ||
84 | - goods.GoodsName = goodsName.(string) | 84 | + if goodName, ok := data["goodName"]; ok { |
85 | + good.GoodName = goodName.(string) | ||
85 | } | 86 | } |
86 | - if goodsTotalPrice, ok := data["goodsTotalPrice"]; ok { | ||
87 | - goods.GoodsTotalPrice = goodsTotalPrice.(float64) | 87 | + if goodTotalPrice, ok := data["goodTotalPrice"]; ok { |
88 | + good.GoodTotalPrice = goodTotalPrice.(float64) | ||
88 | } | 89 | } |
89 | if remarks, ok := data["remarks"]; ok { | 90 | if remarks, ok := data["remarks"]; ok { |
90 | - goods.Remarks = remarks.(string) | 91 | + good.Remarks = remarks.(string) |
91 | } | 92 | } |
92 | if orderNo, ok := data["orderNo"]; ok { | 93 | if orderNo, ok := data["orderNo"]; ok { |
93 | - goods.OrderNo = orderNo.(string) | 94 | + good.OrderNo = orderNo.(string) |
94 | } | 95 | } |
95 | - if goodsDetail, ok := data["goodsDetail"]; ok { | ||
96 | - goods.GoodsDetail = goodsDetail.(string) | 96 | + if goodDetail, ok := data["goodDetail"]; ok { |
97 | + good.GoodDetail = goodDetail.(string) | ||
97 | } | 98 | } |
98 | if createAt, ok := data["createAt"]; ok { | 99 | if createAt, ok := data["createAt"]; ok { |
99 | - goods.CreateAt = createAt.(time.Time) | 100 | + good.CreateAt = createAt.(time.Time) |
100 | } | 101 | } |
101 | if updateAt, ok := data["updateAt"]; ok { | 102 | if updateAt, ok := data["updateAt"]; ok { |
102 | - goods.UpdateAt = updateAt.(time.Time) | 103 | + good.UpdateAt = updateAt.(time.Time) |
103 | } | 104 | } |
104 | if deleteAt, ok := data["deleteAt"]; ok { | 105 | if deleteAt, ok := data["deleteAt"]; ok { |
105 | - goods.DeleteAt = deleteAt.(time.Time) | 106 | + good.DeleteAt = deleteAt.(time.Time) |
106 | } | 107 | } |
107 | return nil | 108 | return nil |
108 | } | 109 | } |
@@ -13,13 +13,14 @@ const ( | @@ -13,13 +13,14 @@ const ( | ||
13 | 13 | ||
14 | // 订单状态 | 14 | // 订单状态 |
15 | const ( | 15 | const ( |
16 | - ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货 | ||
17 | - ORDER_STATUS_TRANSIT // 待收货(运输中) | ||
18 | - ORDER_STATUS_RECEIVED // 已收货 | ||
19 | - ORDER_STATUS_RETURN // 退换货 | ||
20 | - ORDER_STATUS_CANCELED // 已取消(关闭) | ||
21 | - ORDER_STATUS_COMPLETED // 已完成 | ||
22 | - ORDER_STATUS_CLOSED // 已关闭 | 16 | + ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货 |
17 | + ORDER_STATUS_SHIPPING // 已发货 | ||
18 | + ORDER_STATUS_PART_SHIPPING // 部分发货 | ||
19 | + ORDER_STATUS_RECEIVED // 已收货 | ||
20 | + ORDER_STATUS_RETURN // 退换货 | ||
21 | + ORDER_STATUS_CANCELED // 已取消 | ||
22 | + ORDER_STATUS_COMPLETED // 已完成 | ||
23 | + ORDER_STATUS_CLOSED // 已关闭 | ||
23 | ) | 24 | ) |
24 | 25 | ||
25 | // 订单实体 | 26 | // 订单实体 |
@@ -37,7 +38,7 @@ type Order struct { | @@ -37,7 +38,7 @@ type Order struct { | ||
37 | // 发货时间 | 38 | // 发货时间 |
38 | DeliveryTime time.Time `json:"deliveryTime"` | 39 | DeliveryTime time.Time `json:"deliveryTime"` |
39 | // 是否关闭订单标志 | 40 | // 是否关闭订单标志 |
40 | - IsDisable int `json:"isDisable"` | 41 | + IsDisable bool `json:"isDisable"` |
41 | // 订单编号 | 42 | // 订单编号 |
42 | OrderNo string `json:"orderNo"` | 43 | OrderNo string `json:"orderNo"` |
43 | // 订单详情 | 44 | // 订单详情 |
@@ -47,7 +48,7 @@ type Order struct { | @@ -47,7 +48,7 @@ type Order struct { | ||
47 | // 订单分红支付状态 | 48 | // 订单分红支付状态 |
48 | OrderDividendStatus int `json:"orderDividendStatus"` | 49 | OrderDividendStatus int `json:"orderDividendStatus"` |
49 | // 订单货品 | 50 | // 订单货品 |
50 | - OrderGoods []*Goods `json:"orderGoods"` | 51 | + OrderGoods []*Good `json:"orderGoods"` |
51 | // 订单数据来源 | 52 | // 订单数据来源 |
52 | OrderSource *OrderSource `json:"orderSource"` | 53 | OrderSource *OrderSource `json:"orderSource"` |
53 | // 订单类型(1.实际订单;2.意向订单) | 54 | // 订单类型(1.实际订单;2.意向订单) |
@@ -73,8 +74,8 @@ type Order struct { | @@ -73,8 +74,8 @@ type Order struct { | ||
73 | // 订单状态机 | 74 | // 订单状态机 |
74 | type OrderStatus interface { | 75 | type OrderStatus interface { |
75 | Update(order *Order, data map[string]interface{}) error // 更新订单 | 76 | Update(order *Order, data map[string]interface{}) error // 更新订单 |
76 | - Shipping(order *Order) error // 发货 | ||
77 | - Return(order *Order) error // 退换/货 | 77 | + Shipping(order *Order) error // 发货(全部发货,部分发货) |
78 | + Return(order *Order) error // 退换货 | ||
78 | Cancel(order *Order) error // 取消订单 | 79 | Cancel(order *Order) error // 取消订单 |
79 | Receive(order *Order) error // 收货 | 80 | Receive(order *Order) error // 收货 |
80 | Close(order *Order) error // 关闭订单 | 81 | Close(order *Order) error // 关闭订单 |
@@ -107,7 +108,7 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) | @@ -107,7 +108,7 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) | ||
107 | order.DeliveryCode = deliveryCode.(string) | 108 | order.DeliveryCode = deliveryCode.(string) |
108 | } | 109 | } |
109 | if isDisable, ok := data["isDisable"]; ok { | 110 | if isDisable, ok := data["isDisable"]; ok { |
110 | - order.IsDisable = isDisable.(int) | 111 | + order.IsDisable = isDisable.(bool) |
111 | } | 112 | } |
112 | if orderNo, ok := data["orderNo"]; ok { | 113 | if orderNo, ok := data["orderNo"]; ok { |
113 | order.OrderNo = orderNo.(string) | 114 | order.OrderNo = orderNo.(string) |
@@ -161,7 +162,7 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) | @@ -161,7 +162,7 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) | ||
161 | order.OrderDividendStatus = orderDividendStatus.(int) | 162 | order.OrderDividendStatus = orderDividendStatus.(int) |
162 | } | 163 | } |
163 | if orderGoods, ok := data["orderGoods"]; ok { | 164 | if orderGoods, ok := data["orderGoods"]; ok { |
164 | - order.OrderGoods = orderGoods.([]*Goods) | 165 | + order.OrderGoods = orderGoods.([]*Good) |
165 | } | 166 | } |
166 | if dataSourceId, ok := data["dataSourceId"]; ok { | 167 | if dataSourceId, ok := data["dataSourceId"]; ok { |
167 | order.OrderSource.DataSourceId = dataSourceId.(int64) | 168 | order.OrderSource.DataSourceId = dataSourceId.(int64) |
@@ -204,13 +205,13 @@ func (status *UnShippedStatus) Shipping(order *Order) error { | @@ -204,13 +205,13 @@ func (status *UnShippedStatus) Shipping(order *Order) error { | ||
204 | currentTime := time.Now() | 205 | currentTime := time.Now() |
205 | order.DeliveryTime = currentTime | 206 | order.DeliveryTime = currentTime |
206 | if order.OrderType == ORDER_TYPE_INTENTION { | 207 | if order.OrderType == ORDER_TYPE_INTENTION { |
207 | - order.OrderStatus = ORDER_STATUS_TRANSIT | 208 | + order.OrderStatus = ORDER_STATUS_SHIPPING |
208 | order.CurrentStatus = &TransitStatus{} | 209 | order.CurrentStatus = &TransitStatus{} |
209 | } | 210 | } |
210 | return nil | 211 | return nil |
211 | } | 212 | } |
212 | 213 | ||
213 | -// 退货 | 214 | +// 待发货订单不能退货 |
214 | func (status *UnShippedStatus) Return(order *Order) error { | 215 | func (status *UnShippedStatus) Return(order *Order) error { |
215 | return fmt.Errorf("待发货订单不能退货") | 216 | return fmt.Errorf("待发货订单不能退货") |
216 | } | 217 | } |
@@ -221,7 +222,7 @@ func (status *UnShippedStatus) Cancel(order *Order) error { | @@ -221,7 +222,7 @@ func (status *UnShippedStatus) Cancel(order *Order) error { | ||
221 | return nil | 222 | return nil |
222 | } | 223 | } |
223 | 224 | ||
224 | -// 收货 | 225 | +// 待发货订单不能收货 |
225 | func (status *UnShippedStatus) Receive(order *Order) error { | 226 | func (status *UnShippedStatus) Receive(order *Order) error { |
226 | return fmt.Errorf("待发货订单不能收货") | 227 | return fmt.Errorf("待发货订单不能收货") |
227 | } | 228 | } |
@@ -234,11 +235,6 @@ func (status *TransitStatus) Shipping(order *Order) error { | @@ -234,11 +235,6 @@ func (status *TransitStatus) Shipping(order *Order) error { | ||
234 | return fmt.Errorf("待收货订单不能重复发货") | 235 | return fmt.Errorf("待收货订单不能重复发货") |
235 | } | 236 | } |
236 | 237 | ||
237 | -// 待收货订单不能关闭 | ||
238 | -func (status *TransitStatus) Close(order *Order) error { | ||
239 | - return fmt.Errorf("待收货订单不能关闭") | ||
240 | -} | ||
241 | - | ||
242 | // 待收货订单不允许编辑 | 238 | // 待收货订单不允许编辑 |
243 | func (status *TransitStatus) Update(order *Order, data map[string]interface{}) error { | 239 | func (status *TransitStatus) Update(order *Order, data map[string]interface{}) error { |
244 | return fmt.Errorf("已发货订单不允许编辑") | 240 | return fmt.Errorf("已发货订单不允许编辑") |
@@ -261,10 +257,15 @@ func (status *TransitStatus) Receive(order *Order) error { | @@ -261,10 +257,15 @@ func (status *TransitStatus) Receive(order *Order) error { | ||
261 | return nil | 257 | return nil |
262 | } | 258 | } |
263 | 259 | ||
260 | +// 待收货订单不能关闭 | ||
261 | +func (status *TransitStatus) Close(order *Order) error { | ||
262 | + return fmt.Errorf("待收货订单不能关闭") | ||
263 | +} | ||
264 | + | ||
264 | // 收货状态 | 265 | // 收货状态 |
265 | type ReceivedStatus struct{} | 266 | type ReceivedStatus struct{} |
266 | 267 | ||
267 | -// 编辑订单 | 268 | +// 已收货订单不能编辑 |
268 | func (status *ReceivedStatus) Update(order *Order, data map[string]interface{}) error { | 269 | func (status *ReceivedStatus) Update(order *Order, data map[string]interface{}) error { |
269 | return fmt.Errorf("已收货订单不能编辑") | 270 | return fmt.Errorf("已收货订单不能编辑") |
270 | } | 271 | } |
@@ -292,6 +293,8 @@ func (status *ReceivedStatus) Receive(order *Order) error { | @@ -292,6 +293,8 @@ func (status *ReceivedStatus) Receive(order *Order) error { | ||
292 | 293 | ||
293 | // 关闭订单 | 294 | // 关闭订单 |
294 | func (status *ReceivedStatus) Close(order *Order) error { | 295 | func (status *ReceivedStatus) Close(order *Order) error { |
296 | + order.IsDisable = true | ||
297 | + order.CurrentStatus = &ClosedStatus{} | ||
295 | return nil | 298 | return nil |
296 | } | 299 | } |
297 | 300 | ||
@@ -323,9 +326,10 @@ func (status *ReturnedStatus) Receive(order *Order) error { | @@ -323,9 +326,10 @@ func (status *ReturnedStatus) Receive(order *Order) error { | ||
323 | return fmt.Errorf("已退货订单不能收货") | 326 | return fmt.Errorf("已退货订单不能收货") |
324 | } | 327 | } |
325 | 328 | ||
326 | -// 关闭订单 | 329 | +// 关闭已退货订单 |
327 | func (status *ReturnedStatus) Close(order *Order) error { | 330 | func (status *ReturnedStatus) Close(order *Order) error { |
328 | - | 331 | + order.IsDisable = true |
332 | + order.CurrentStatus = &ClosedStatus{} | ||
329 | return nil | 333 | return nil |
330 | } | 334 | } |
331 | 335 | ||
@@ -359,6 +363,8 @@ func (status *CanceledStatus) Receive(order *Order) error { | @@ -359,6 +363,8 @@ func (status *CanceledStatus) Receive(order *Order) error { | ||
359 | 363 | ||
360 | // 关闭订单 | 364 | // 关闭订单 |
361 | func (status *CanceledStatus) Close(order *Order) error { | 365 | func (status *CanceledStatus) Close(order *Order) error { |
366 | + order.IsDisable = true | ||
367 | + order.CurrentStatus = &ClosedStatus{} | ||
362 | return nil | 368 | return nil |
363 | } | 369 | } |
364 | 370 | ||
@@ -367,7 +373,36 @@ type CompletedStatus struct{} | @@ -367,7 +373,36 @@ type CompletedStatus struct{} | ||
367 | 373 | ||
368 | // 编辑已完成订单分红 | 374 | // 编辑已完成订单分红 |
369 | func (status *CompletedStatus) Update(order *Order, data map[string]interface{}) error { | 375 | func (status *CompletedStatus) Update(order *Order, data map[string]interface{}) error { |
370 | - | 376 | + if planBonus, ok := data["planBonus"]; ok { |
377 | + order.OrderDividend.PlanBonus = planBonus.(float64) | ||
378 | + } | ||
379 | + if useBonus, ok := data["useBonus"]; ok { | ||
380 | + order.OrderDividend.UseBonus = useBonus.(float64) | ||
381 | + } | ||
382 | + if bonusHas, ok := data["bonusHas"]; ok { | ||
383 | + order.OrderDividend.BonusHas = bonusHas.(float64) | ||
384 | + } | ||
385 | + if bonusNot, ok := data["bonusNot"]; ok { | ||
386 | + order.OrderDividend.BonusNot = bonusNot.(float64) | ||
387 | + } | ||
388 | + if bonusExpense, ok := data["bonusExpense"]; ok { | ||
389 | + order.OrderDividend.BonusExpense = bonusExpense.(float64) | ||
390 | + } | ||
391 | + if bonusStatus, ok := data["bonusStatus"]; ok { | ||
392 | + order.OrderDividend.BonusStatus = bonusStatus.(int) | ||
393 | + } | ||
394 | + if partnerBonusPercent, ok := data["partnerBonusPercent"]; ok { | ||
395 | + order.OrderDividend.PartnerBonusPercent = partnerBonusPercent.(float64) | ||
396 | + } | ||
397 | + if salesmanBonusPercent, ok := data["salesmanBonusPercent"]; ok { | ||
398 | + order.OrderDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64) | ||
399 | + } | ||
400 | + if salesmanBonus, ok := data["salesmanBonus"]; ok { | ||
401 | + order.OrderDividend.SalesmanBonus = salesmanBonus.(float64) | ||
402 | + } | ||
403 | + if orderDividendStatus, ok := data["orderDividendStatus"]; ok { | ||
404 | + order.OrderDividendStatus = orderDividendStatus.(int) | ||
405 | + } | ||
371 | return nil | 406 | return nil |
372 | } | 407 | } |
373 | 408 | ||
@@ -393,12 +428,47 @@ func (status *CompletedStatus) Receive(order *Order) error { | @@ -393,12 +428,47 @@ func (status *CompletedStatus) Receive(order *Order) error { | ||
393 | 428 | ||
394 | // 关闭已完成订单 | 429 | // 关闭已完成订单 |
395 | func (status *CompletedStatus) Close(order *Order) error { | 430 | func (status *CompletedStatus) Close(order *Order) error { |
431 | + order.IsDisable = true | ||
432 | + order.CurrentStatus = &ClosedStatus{} | ||
396 | return nil | 433 | return nil |
397 | } | 434 | } |
398 | 435 | ||
436 | +// 关闭状态 | ||
437 | +type ClosedStatus struct{} | ||
438 | + | ||
439 | +// 已关闭订单不能进行编辑 | ||
440 | +func (status *ClosedStatus) Update(order *Order, data map[string]interface{}) error { | ||
441 | + return fmt.Errorf("已关闭订单不能进行编辑") | ||
442 | +} | ||
443 | + | ||
444 | +// 已关闭订单不能发货 | ||
445 | +func (status *ClosedStatus) Shipping(order *Order) error { | ||
446 | + return fmt.Errorf("已关闭订单不能发货") | ||
447 | +} | ||
448 | + | ||
449 | +// 已关闭订单不能退货 | ||
450 | +func (status *ClosedStatus) Return(order *Order) error { | ||
451 | + return fmt.Errorf("已关闭订单不能退货") | ||
452 | +} | ||
453 | + | ||
454 | +// 已关闭订单不能取消 | ||
455 | +func (status *ClosedStatus) Cancel(order *Order) error { | ||
456 | + return fmt.Errorf("已关闭订单不能取消") | ||
457 | +} | ||
458 | + | ||
459 | +// 已关闭订单不能收货 | ||
460 | +func (status *ClosedStatus) Receive(order *Order) error { | ||
461 | + return fmt.Errorf("已关闭订单不能收货") | ||
462 | +} | ||
463 | + | ||
464 | +// 已关闭订单不能再次关闭 | ||
465 | +func (status *ClosedStatus) Close(order *Order) error { | ||
466 | + return fmt.Errorf("已关闭订单不能再次关闭") | ||
467 | +} | ||
468 | + | ||
399 | // 订单仓储 | 469 | // 订单仓储 |
400 | type OrderRepository interface { | 470 | type OrderRepository interface { |
401 | - Save(order *Order) (*Order, error) // 下单/编辑订单 | 471 | + Save(order *Order) (*Order, error) |
402 | Remove(order *Order) (*Order, error) | 472 | Remove(order *Order) (*Order, error) |
403 | FindOne(queryOptions map[string]interface{}) (*Order, error) | 473 | FindOne(queryOptions map[string]interface{}) (*Order, error) |
404 | Find(queryOptions map[string]interface{}) (int64, []*Order, error) | 474 | Find(queryOptions map[string]interface{}) (int64, []*Order, error) |
@@ -15,7 +15,7 @@ type PartnerInfo struct { | @@ -15,7 +15,7 @@ type PartnerInfo struct { | ||
15 | // 合伙时间 | 15 | // 合伙时间 |
16 | CooperateTime time.Time `json:"cooperateTime"` | 16 | CooperateTime time.Time `json:"cooperateTime"` |
17 | // 业务员 | 17 | // 业务员 |
18 | - Salesmans []*Salesman `json:"salesmans"` | 18 | + Salesmen []*Salesman `json:"salesmen"` |
19 | // 合伙人类型 | 19 | // 合伙人类型 |
20 | - PartnerCategorys []*PartnerCategory `json:"partnerCategorys"` | 20 | + PartnerCategories []*PartnerCategory `json:"partnerCategories"` |
21 | } | 21 | } |
@@ -27,7 +27,7 @@ func init() { | @@ -27,7 +27,7 @@ func init() { | ||
27 | &models.Permission{}, | 27 | &models.Permission{}, |
28 | &models.PartnerCategory{}, | 28 | &models.PartnerCategory{}, |
29 | &models.UserAuth{}, | 29 | &models.UserAuth{}, |
30 | - &models.Goods{}, | 30 | + &models.Good{}, |
31 | &models.Order{}, | 31 | &models.Order{}, |
32 | &models.User{}, | 32 | &models.User{}, |
33 | &models.Company{}, | 33 | &models.Company{}, |
@@ -6,7 +6,7 @@ import ( | @@ -6,7 +6,7 @@ import ( | ||
6 | ) | 6 | ) |
7 | 7 | ||
8 | type Company struct { | 8 | type Company struct { |
9 | - tableName string `pg:"companys,alias:company"` | 9 | + tableName string `pg:"companies,alias:company"` |
10 | // 公司Id | 10 | // 公司Id |
11 | CompanyId int64 `pg:",pk"` | 11 | CompanyId int64 `pg:",pk"` |
12 | // 公司信息 | 12 | // 公司信息 |
@@ -16,5 +16,5 @@ type Company struct { | @@ -16,5 +16,5 @@ type Company struct { | ||
16 | // 更新时间 | 16 | // 更新时间 |
17 | UpdateAt time.Time | 17 | UpdateAt time.Time |
18 | // 删除时间 | 18 | // 删除时间 |
19 | - DeleteAt time.Time | 19 | + DeleteAt time.Time `pg:",soft_delete"` |
20 | } | 20 | } |
@@ -5,30 +5,30 @@ import ( | @@ -5,30 +5,30 @@ import ( | ||
5 | "time" | 5 | "time" |
6 | ) | 6 | ) |
7 | 7 | ||
8 | -type Goods struct { | ||
9 | - tableName string `pg:"goodss,alias:goods"` | 8 | +type Good struct { |
9 | + tableName string `pg:"goods,alias:good"` | ||
10 | // 商品id | 10 | // 商品id |
11 | - GoodsId int64 | 11 | + GoodId int64 `pg:",pk"` |
12 | // 预定的货品数量 | 12 | // 预定的货品数量 |
13 | - GoodsNum int | 13 | + GoodNum int |
14 | // 商品分红支付信息 | 14 | // 商品分红支付信息 |
15 | - GoodsDividend *domain.Dividend | 15 | + GoodDividend *domain.Dividend |
16 | // 商品分红支付状态 | 16 | // 商品分红支付状态 |
17 | - GoodsDividendStatus int | 17 | + GoodDividendStatus int |
18 | // 商品名称 | 18 | // 商品名称 |
19 | - GoodsName string | 19 | + GoodName string |
20 | // 商品单价 | 20 | // 商品单价 |
21 | - GoodsTotalPrice float64 | 21 | + GoodTotalPrice float64 |
22 | // 备注 | 22 | // 备注 |
23 | Remarks string | 23 | Remarks string |
24 | // 订单编号 | 24 | // 订单编号 |
25 | - OrderNo string | 25 | + OrderNo string |
26 | // 商品详情 | 26 | // 商品详情 |
27 | - GoodsDetail string | 27 | + GoodDetail string |
28 | // 创建时间 | 28 | // 创建时间 |
29 | CreateAt time.Time | 29 | CreateAt time.Time |
30 | // 更新时间 | 30 | // 更新时间 |
31 | UpdateAt time.Time | 31 | UpdateAt time.Time |
32 | // 删除时间 | 32 | // 删除时间 |
33 | - DeleteAt time.Time | 33 | + DeleteAt time.Time `pg:",soft_delete"` |
34 | } | 34 | } |
@@ -8,7 +8,7 @@ import ( | @@ -8,7 +8,7 @@ import ( | ||
8 | type Order struct { | 8 | type Order struct { |
9 | tableName string `pg:"orders,alias:order"` | 9 | tableName string `pg:"orders,alias:order"` |
10 | // 订单id | 10 | // 订单id |
11 | - OrderId int64 | 11 | + OrderId int64 `pg:",pk"` |
12 | // 买家信息 | 12 | // 买家信息 |
13 | Buyer *domain.BuyerInfo | 13 | Buyer *domain.BuyerInfo |
14 | // 公司Id | 14 | // 公司Id |
@@ -18,7 +18,7 @@ type Order struct { | @@ -18,7 +18,7 @@ type Order struct { | ||
18 | // 发货单号 | 18 | // 发货单号 |
19 | DeliveryCode string | 19 | DeliveryCode string |
20 | // 是否关闭订单标志 | 20 | // 是否关闭订单标志 |
21 | - IsDisable int | 21 | + IsDisable bool |
22 | // 订单编号 | 22 | // 订单编号 |
23 | OrderNo string | 23 | OrderNo string |
24 | // 订单详情 | 24 | // 订单详情 |
@@ -28,7 +28,7 @@ type Order struct { | @@ -28,7 +28,7 @@ type Order struct { | ||
28 | // 订单分红支付状态 | 28 | // 订单分红支付状态 |
29 | OrderDividendStatus int | 29 | OrderDividendStatus int |
30 | // 订单货品 | 30 | // 订单货品 |
31 | - OrderGoods []*domain.Goods | 31 | + OrderGoods []*domain.Good |
32 | // 订单数据来源 | 32 | // 订单数据来源 |
33 | OrderSource *domain.OrderSource | 33 | OrderSource *domain.OrderSource |
34 | // 订单类型(1.实际订单;2.意向订单) | 34 | // 订单类型(1.实际订单;2.意向订单) |
@@ -46,5 +46,5 @@ type Order struct { | @@ -46,5 +46,5 @@ type Order struct { | ||
46 | // 更新时间 | 46 | // 更新时间 |
47 | UpdateAt time.Time | 47 | UpdateAt time.Time |
48 | // 软删 | 48 | // 软删 |
49 | - DeleteAt time.Time | 49 | + DeleteAt time.Time `pg:",soft_delete"` |
50 | } | 50 | } |
pkg/infrastructure/pg/transform/good.go
0 → 100644
1 | +package transform | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/models" | ||
6 | +) | ||
7 | + | ||
8 | +func TransformToGoodDomainModelFromPgModels(goodModel *models.Good) (*domain.Good, error) { | ||
9 | + return &domain.Good{ | ||
10 | + GoodId: goodModel.GoodId, | ||
11 | + GoodNum: goodModel.GoodNum, | ||
12 | + GoodDividend: goodModel.GoodDividend, | ||
13 | + GoodDividendStatus: goodModel.GoodDividendStatus, | ||
14 | + GoodName: goodModel.GoodName, | ||
15 | + GoodTotalPrice: goodModel.GoodTotalPrice, | ||
16 | + Remarks: goodModel.Remarks, | ||
17 | + OrderNo: goodModel.OrderNo, | ||
18 | + GoodDetail: goodModel.GoodDetail, | ||
19 | + CreateAt: goodModel.CreateAt, | ||
20 | + UpdateAt: goodModel.UpdateAt, | ||
21 | + DeleteAt: goodModel.DeleteAt, | ||
22 | + }, nil | ||
23 | +} |
pkg/infrastructure/pg/transform/goods.go
已删除
100644 → 0
1 | -package transform | ||
2 | - | ||
3 | -import ( | ||
4 | - "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
5 | - "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/models" | ||
6 | -) | ||
7 | - | ||
8 | -func TransformToGoodsDomainModelFromPgModels(goodsModel *models.Goods) (*domain.Goods, error) { | ||
9 | - return &domain.Goods{ | ||
10 | - GoodsId: goodsModel.GoodsId, | ||
11 | - GoodsNum: goodsModel.GoodsNum, | ||
12 | - GoodsDividend: goodsModel.GoodsDividend, | ||
13 | - GoodsDividendStatus: goodsModel.GoodsDividendStatus, | ||
14 | - GoodsName: goodsModel.GoodsName, | ||
15 | - GoodsTotalPrice: goodsModel.GoodsTotalPrice, | ||
16 | - Remarks: goodsModel.Remarks, | ||
17 | - OrderNo: goodsModel.OrderNo, | ||
18 | - GoodsDetail: goodsModel.GoodsDetail, | ||
19 | - CreateAt: goodsModel.CreateAt, | ||
20 | - UpdateAt: goodsModel.UpdateAt, | ||
21 | - DeleteAt: goodsModel.DeleteAt, | ||
22 | - }, nil | ||
23 | -} |
@@ -30,7 +30,6 @@ func (repository *CompanyRepository) Save(company *domain.Company) (*domain.Comp | @@ -30,7 +30,6 @@ func (repository *CompanyRepository) Save(company *domain.Company) (*domain.Comp | ||
30 | "company_info", | 30 | "company_info", |
31 | "create_at", | 31 | "create_at", |
32 | "update_at", | 32 | "update_at", |
33 | - "delete_at", | ||
34 | } | 33 | } |
35 | insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | 34 | insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) |
36 | insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | 35 | insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) |
@@ -53,7 +52,9 @@ func (repository *CompanyRepository) Save(company *domain.Company) (*domain.Comp | @@ -53,7 +52,9 @@ func (repository *CompanyRepository) Save(company *domain.Company) (*domain.Comp | ||
53 | &company.UpdateAt, | 52 | &company.UpdateAt, |
54 | &company.DeleteAt, | 53 | &company.DeleteAt, |
55 | ), | 54 | ), |
56 | - fmt.Sprintf("INSERT INTO companys (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | 55 | + |
56 | + fmt.Sprintf("INSERT INTO companies (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
57 | + | ||
57 | company.CompanyId, | 58 | company.CompanyId, |
58 | company.CompanyInfo, | 59 | company.CompanyInfo, |
59 | company.CreateAt, | 60 | company.CreateAt, |
@@ -71,8 +72,9 @@ func (repository *CompanyRepository) Save(company *domain.Company) (*domain.Comp | @@ -71,8 +72,9 @@ func (repository *CompanyRepository) Save(company *domain.Company) (*domain.Comp | ||
71 | &company.UpdateAt, | 72 | &company.UpdateAt, |
72 | &company.DeleteAt, | 73 | &company.DeleteAt, |
73 | ), | 74 | ), |
74 | - fmt.Sprintf("UPDATE companys SET %s WHERE company_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
75 | - company.CompanyId, | 75 | + |
76 | + fmt.Sprintf("UPDATE companies SET %s WHERE company_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
77 | + | ||
76 | company.CompanyInfo, | 78 | company.CompanyInfo, |
77 | company.CreateAt, | 79 | company.CreateAt, |
78 | company.UpdateAt, | 80 | company.UpdateAt, |
@@ -115,21 +117,23 @@ func (repository *CompanyRepository) FindOne(queryOptions map[string]interface{} | @@ -115,21 +117,23 @@ func (repository *CompanyRepository) FindOne(queryOptions map[string]interface{} | ||
115 | func (repository *CompanyRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Company, error) { | 117 | func (repository *CompanyRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Company, error) { |
116 | tx := repository.transactionContext.PgTx | 118 | tx := repository.transactionContext.PgTx |
117 | var companyModels []*models.Company | 119 | var companyModels []*models.Company |
118 | - companys := make([]*domain.Company, 0) | 120 | + |
121 | + companies := make([]*domain.Company, 0) | ||
122 | + | ||
119 | query := sqlbuilder.BuildQuery(tx.Model(&companyModels), queryOptions) | 123 | query := sqlbuilder.BuildQuery(tx.Model(&companyModels), queryOptions) |
120 | query.SetOffsetAndLimit(20) | 124 | query.SetOffsetAndLimit(20) |
121 | query.SetOrderDirect("company_id", "DESC") | 125 | query.SetOrderDirect("company_id", "DESC") |
122 | if count, err := query.SelectAndCount(); err != nil { | 126 | if count, err := query.SelectAndCount(); err != nil { |
123 | - return 0, companys, err | 127 | + return 0, companies, err |
124 | } else { | 128 | } else { |
125 | for _, companyModel := range companyModels { | 129 | for _, companyModel := range companyModels { |
126 | if company, err := transform.TransformToCompanyDomainModelFromPgModels(companyModel); err != nil { | 130 | if company, err := transform.TransformToCompanyDomainModelFromPgModels(companyModel); err != nil { |
127 | - return 0, companys, err | 131 | + return 0, companies, err |
128 | } else { | 132 | } else { |
129 | - companys = append(companys, company) | 133 | + companies = append(companies, company) |
130 | } | 134 | } |
131 | } | 135 | } |
132 | - return int64(count), companys, nil | 136 | + return int64(count), companies, nil |
133 | } | 137 | } |
134 | } | 138 | } |
135 | func NewCompanyRepository(transactionContext *pgTransaction.TransactionContext) (*CompanyRepository, error) { | 139 | func NewCompanyRepository(transactionContext *pgTransaction.TransactionContext) (*CompanyRepository, error) { |
@@ -12,11 +12,11 @@ import ( | @@ -12,11 +12,11 @@ import ( | ||
12 | "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/transform" | 12 | "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/transform" |
13 | ) | 13 | ) |
14 | 14 | ||
15 | -type GoodsRepository struct { | 15 | +type GoodRepository struct { |
16 | transactionContext *pgTransaction.TransactionContext | 16 | transactionContext *pgTransaction.TransactionContext |
17 | } | 17 | } |
18 | 18 | ||
19 | -func (repository *GoodsRepository) nextIdentify() (int64, error) { | 19 | +func (repository *GoodRepository) nextIdentify() (int64, error) { |
20 | IdWorker, err := snowflake.NewIdWorker(1) | 20 | IdWorker, err := snowflake.NewIdWorker(1) |
21 | if err != nil { | 21 | if err != nil { |
22 | return 0, err | 22 | return 0, err |
@@ -24,17 +24,17 @@ func (repository *GoodsRepository) nextIdentify() (int64, error) { | @@ -24,17 +24,17 @@ func (repository *GoodsRepository) nextIdentify() (int64, error) { | ||
24 | id, err := IdWorker.NextId() | 24 | id, err := IdWorker.NextId() |
25 | return id, err | 25 | return id, err |
26 | } | 26 | } |
27 | -func (repository *GoodsRepository) Save(goods *domain.Goods) (*domain.Goods, error) { | 27 | +func (repository *GoodRepository) Save(good *domain.Good) (*domain.Good, error) { |
28 | sqlBuildFields := []string{ | 28 | sqlBuildFields := []string{ |
29 | - "goods_id", | ||
30 | - "goods_num", | ||
31 | - "goods_dividend", | ||
32 | - "goods_dividend_status", | ||
33 | - "goods_name", | ||
34 | - "goods_total_price", | 29 | + "good_id", |
30 | + "good_num", | ||
31 | + "good_dividend", | ||
32 | + "good_dividend_status", | ||
33 | + "good_name", | ||
34 | + "good_total_price", | ||
35 | "remarks", | 35 | "remarks", |
36 | "order_no", | 36 | "order_no", |
37 | - "goods_detail", | 37 | + "good_detail", |
38 | "create_at", | 38 | "create_at", |
39 | "update_at", | 39 | "update_at", |
40 | "delete_at", | 40 | "delete_at", |
@@ -45,94 +45,94 @@ func (repository *GoodsRepository) Save(goods *domain.Goods) (*domain.Goods, err | @@ -45,94 +45,94 @@ func (repository *GoodsRepository) Save(goods *domain.Goods) (*domain.Goods, err | ||
45 | updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "goods_id") | 45 | updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "goods_id") |
46 | updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | 46 | updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) |
47 | tx := repository.transactionContext.PgTx | 47 | tx := repository.transactionContext.PgTx |
48 | - if goods.Identify() == nil { | ||
49 | - goodsId, err := repository.nextIdentify() | 48 | + if good.Identify() == nil { |
49 | + goodId, err := repository.nextIdentify() | ||
50 | if err != nil { | 50 | if err != nil { |
51 | - return goods, err | 51 | + return good, err |
52 | } else { | 52 | } else { |
53 | - goods.GoodsId = goodsId | 53 | + good.GoodId = goodId |
54 | } | 54 | } |
55 | if _, err := tx.QueryOne( | 55 | if _, err := tx.QueryOne( |
56 | pg.Scan( | 56 | pg.Scan( |
57 | - &goods.GoodsId, | ||
58 | - &goods.GoodsNum, | ||
59 | - &goods.GoodsDividend, | ||
60 | - &goods.GoodsDividendStatus, | ||
61 | - &goods.GoodsName, | ||
62 | - &goods.GoodsTotalPrice, | ||
63 | - &goods.Remarks, | ||
64 | - &goods.OrderNo, | ||
65 | - &goods.GoodsDetail, | ||
66 | - &goods.CreateAt, | ||
67 | - &goods.UpdateAt, | ||
68 | - &goods.DeleteAt, | 57 | + &good.GoodId, |
58 | + &good.GoodNum, | ||
59 | + &good.GoodDividend, | ||
60 | + &good.GoodDividendStatus, | ||
61 | + &good.GoodName, | ||
62 | + &good.GoodTotalPrice, | ||
63 | + &good.Remarks, | ||
64 | + &good.OrderNo, | ||
65 | + &good.GoodDetail, | ||
66 | + &good.CreateAt, | ||
67 | + &good.UpdateAt, | ||
68 | + &good.DeleteAt, | ||
69 | ), | 69 | ), |
70 | - fmt.Sprintf("INSERT INTO goodss (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
71 | - goods.GoodsId, | ||
72 | - goods.GoodsNum, | ||
73 | - goods.GoodsDividend, | ||
74 | - goods.GoodsDividendStatus, | ||
75 | - goods.GoodsName, | ||
76 | - goods.GoodsTotalPrice, | ||
77 | - goods.Remarks, | ||
78 | - goods.OrderNo, | ||
79 | - goods.GoodsDetail, | ||
80 | - goods.CreateAt, | ||
81 | - goods.UpdateAt, | ||
82 | - goods.DeleteAt, | 70 | + fmt.Sprintf("INSERT INTO good (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), |
71 | + good.GoodId, | ||
72 | + good.GoodNum, | ||
73 | + good.GoodDividend, | ||
74 | + good.GoodDividendStatus, | ||
75 | + good.GoodName, | ||
76 | + good.GoodTotalPrice, | ||
77 | + good.Remarks, | ||
78 | + good.OrderNo, | ||
79 | + good.GoodDetail, | ||
80 | + good.CreateAt, | ||
81 | + good.UpdateAt, | ||
82 | + good.DeleteAt, | ||
83 | ); err != nil { | 83 | ); err != nil { |
84 | - return goods, err | 84 | + return good, err |
85 | } | 85 | } |
86 | } else { | 86 | } else { |
87 | if _, err := tx.QueryOne( | 87 | if _, err := tx.QueryOne( |
88 | pg.Scan( | 88 | pg.Scan( |
89 | - &goods.GoodsId, | ||
90 | - &goods.GoodsNum, | ||
91 | - &goods.GoodsDividend, | ||
92 | - &goods.GoodsDividendStatus, | ||
93 | - &goods.GoodsName, | ||
94 | - &goods.GoodsTotalPrice, | ||
95 | - &goods.Remarks, | ||
96 | - &goods.OrderNo, | ||
97 | - &goods.GoodsDetail, | ||
98 | - &goods.CreateAt, | ||
99 | - &goods.UpdateAt, | ||
100 | - &goods.DeleteAt, | 89 | + &good.GoodId, |
90 | + &good.GoodNum, | ||
91 | + &good.GoodDividend, | ||
92 | + &good.GoodDividendStatus, | ||
93 | + &good.GoodName, | ||
94 | + &good.GoodTotalPrice, | ||
95 | + &good.Remarks, | ||
96 | + &good.OrderNo, | ||
97 | + &good.GoodDetail, | ||
98 | + &good.CreateAt, | ||
99 | + &good.UpdateAt, | ||
100 | + &good.DeleteAt, | ||
101 | ), | 101 | ), |
102 | - fmt.Sprintf("UPDATE goodss SET %s WHERE goods_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
103 | - goods.GoodsId, | ||
104 | - goods.GoodsNum, | ||
105 | - goods.GoodsDividend, | ||
106 | - goods.GoodsDividendStatus, | ||
107 | - goods.GoodsName, | ||
108 | - goods.GoodsTotalPrice, | ||
109 | - goods.Remarks, | ||
110 | - goods.OrderNo, | ||
111 | - goods.GoodsDetail, | ||
112 | - goods.CreateAt, | ||
113 | - goods.UpdateAt, | ||
114 | - goods.DeleteAt, | ||
115 | - goods.Identify(), | 102 | + fmt.Sprintf("UPDATE good SET %s WHERE goods_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), |
103 | + good.GoodId, | ||
104 | + good.GoodNum, | ||
105 | + good.GoodDividend, | ||
106 | + good.GoodDividendStatus, | ||
107 | + good.GoodName, | ||
108 | + good.GoodTotalPrice, | ||
109 | + good.Remarks, | ||
110 | + good.OrderNo, | ||
111 | + good.GoodDetail, | ||
112 | + good.CreateAt, | ||
113 | + good.UpdateAt, | ||
114 | + good.DeleteAt, | ||
115 | + good.Identify(), | ||
116 | ); err != nil { | 116 | ); err != nil { |
117 | - return goods, err | 117 | + return good, err |
118 | } | 118 | } |
119 | } | 119 | } |
120 | - return goods, nil | 120 | + return good, nil |
121 | } | 121 | } |
122 | -func (repository *GoodsRepository) Remove(goods *domain.Goods) (*domain.Goods, error) { | 122 | +func (repository *GoodRepository) Remove(good *domain.Good) (*domain.Good, error) { |
123 | tx := repository.transactionContext.PgTx | 123 | tx := repository.transactionContext.PgTx |
124 | - goodsModel := new(models.Goods) | ||
125 | - goodsModel.GoodsId = goods.Identify().(int64) | ||
126 | - if _, err := tx.Model(goodsModel).WherePK().Delete(); err != nil { | ||
127 | - return goods, err | 124 | + goodModel := new(models.Good) |
125 | + goodModel.GoodId = good.Identify().(int64) | ||
126 | + if _, err := tx.Model(goodModel).WherePK().Delete(); err != nil { | ||
127 | + return good, err | ||
128 | } | 128 | } |
129 | - return goods, nil | 129 | + return good, nil |
130 | } | 130 | } |
131 | -func (repository *GoodsRepository) FindOne(queryOptions map[string]interface{}) (*domain.Goods, error) { | 131 | +func (repository *GoodRepository) FindOne(queryOptions map[string]interface{}) (*domain.Good, error) { |
132 | tx := repository.transactionContext.PgTx | 132 | tx := repository.transactionContext.PgTx |
133 | - goodsModel := new(models.Goods) | ||
134 | - query := sqlbuilder.BuildQuery(tx.Model(goodsModel), queryOptions) | ||
135 | - query.SetWhereByQueryOption("goods.goods_id = ?", "goodsId") | 133 | + goodModel := new(models.Good) |
134 | + query := sqlbuilder.BuildQuery(tx.Model(goodModel), queryOptions) | ||
135 | + query.SetWhereByQueryOption("good.goods_id = ?", "goodsId") | ||
136 | if err := query.First(); err != nil { | 136 | if err := query.First(); err != nil { |
137 | if err.Error() == "pg: no rows in result set" { | 137 | if err.Error() == "pg: no rows in result set" { |
138 | return nil, fmt.Errorf("没有此资源") | 138 | return nil, fmt.Errorf("没有此资源") |
@@ -140,37 +140,37 @@ func (repository *GoodsRepository) FindOne(queryOptions map[string]interface{}) | @@ -140,37 +140,37 @@ func (repository *GoodsRepository) FindOne(queryOptions map[string]interface{}) | ||
140 | return nil, err | 140 | return nil, err |
141 | } | 141 | } |
142 | } | 142 | } |
143 | - if goodsModel.GoodsId == 0 { | 143 | + if goodModel.GoodId == 0 { |
144 | return nil, nil | 144 | return nil, nil |
145 | } else { | 145 | } else { |
146 | - return transform.TransformToGoodsDomainModelFromPgModels(goodsModel) | 146 | + return transform.TransformToGoodDomainModelFromPgModels(goodModel) |
147 | } | 147 | } |
148 | } | 148 | } |
149 | -func (repository *GoodsRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Goods, error) { | 149 | +func (repository *GoodRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Good, error) { |
150 | tx := repository.transactionContext.PgTx | 150 | tx := repository.transactionContext.PgTx |
151 | - var goodsModels []*models.Goods | ||
152 | - goodss := make([]*domain.Goods, 0) | ||
153 | - query := sqlbuilder.BuildQuery(tx.Model(&goodsModels), queryOptions) | 151 | + var goodModels []*models.Good |
152 | + goods := make([]*domain.Good, 0) | ||
153 | + query := sqlbuilder.BuildQuery(tx.Model(&goodModels), queryOptions) | ||
154 | query.SetOffsetAndLimit(20) | 154 | query.SetOffsetAndLimit(20) |
155 | query.SetOrderDirect("goods_id", "DESC") | 155 | query.SetOrderDirect("goods_id", "DESC") |
156 | if count, err := query.SelectAndCount(); err != nil { | 156 | if count, err := query.SelectAndCount(); err != nil { |
157 | - return 0, goodss, err | 157 | + return 0, goods, err |
158 | } else { | 158 | } else { |
159 | - for _, goodsModel := range goodsModels { | ||
160 | - if goods, err := transform.TransformToGoodsDomainModelFromPgModels(goodsModel); err != nil { | ||
161 | - return 0, goodss, err | 159 | + for _, goodModel := range goodModels { |
160 | + if good, err := transform.TransformToGoodDomainModelFromPgModels(goodModel); err != nil { | ||
161 | + return 0, goods, err | ||
162 | } else { | 162 | } else { |
163 | - goodss = append(goodss, goods) | 163 | + goods = append(goods, good) |
164 | } | 164 | } |
165 | } | 165 | } |
166 | - return int64(count), goodss, nil | 166 | + return int64(count), goods, nil |
167 | } | 167 | } |
168 | } | 168 | } |
169 | -func NewGoodsRepository(transactionContext *pgTransaction.TransactionContext) (*GoodsRepository, error) { | 169 | +func NewGoodsRepository(transactionContext *pgTransaction.TransactionContext) (*GoodRepository, error) { |
170 | if transactionContext == nil { | 170 | if transactionContext == nil { |
171 | return nil, fmt.Errorf("transactionContext参数不能为nil") | 171 | return nil, fmt.Errorf("transactionContext参数不能为nil") |
172 | } else { | 172 | } else { |
173 | - return &GoodsRepository{ | 173 | + return &GoodRepository{ |
174 | transactionContext: transactionContext, | 174 | transactionContext: transactionContext, |
175 | }, nil | 175 | }, nil |
176 | } | 176 | } |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/web/beego" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/company/command" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/company/query" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/company/service" | ||
8 | +) | ||
9 | + | ||
10 | +type CompanyController struct { | ||
11 | + beego.BaseController | ||
12 | +} | ||
13 | + | ||
14 | +func (controller *CompanyController) CreateCompany() { | ||
15 | + companyService := service.NewCompanyService(nil) | ||
16 | + createCompanyCommand := &command.CreateCompanyCommand{} | ||
17 | + controller.Unmarshal(createCompanyCommand) | ||
18 | + data, err := companyService.CreateCompany(createCompanyCommand) | ||
19 | + controller.Response(data, err) | ||
20 | +} | ||
21 | + | ||
22 | +func (controller *CompanyController) UpdateCompany() { | ||
23 | + companyService := service.NewCompanyService(nil) | ||
24 | + updateCompanyCommand := &command.UpdateCompanyCommand{} | ||
25 | + controller.Unmarshal(updateCompanyCommand) | ||
26 | + companyId, _ := controller.GetInt64(":companyId") | ||
27 | + updateCompanyCommand.CompanyId = companyId | ||
28 | + data, err := companyService.UpdateCompany(updateCompanyCommand) | ||
29 | + controller.Response(data, err) | ||
30 | +} | ||
31 | + | ||
32 | +func (controller *CompanyController) GetCompany() { | ||
33 | + companyService := service.NewCompanyService(nil) | ||
34 | + getCompanyQuery := &query.GetCompanyQuery{} | ||
35 | + companyId, _ := controller.GetInt64(":companyId") | ||
36 | + getCompanyQuery.CompanyId = companyId | ||
37 | + data, err := companyService.GetCompany(getCompanyQuery) | ||
38 | + controller.Response(data, err) | ||
39 | +} | ||
40 | + | ||
41 | +func (controller *CompanyController) RemoveCompany() { | ||
42 | + companyService := service.NewCompanyService(nil) | ||
43 | + removeCompanyCommand := &command.RemoveCompanyCommand{} | ||
44 | + controller.Unmarshal(removeCompanyCommand) | ||
45 | + companyId, _ := controller.GetInt64(":companyId") | ||
46 | + removeCompanyCommand.CompanyId = companyId | ||
47 | + data, err := companyService.RemoveCompany(removeCompanyCommand) | ||
48 | + controller.Response(data, err) | ||
49 | +} | ||
50 | + | ||
51 | +func (controller *CompanyController) ListCompany() { | ||
52 | + companyService := service.NewCompanyService(nil) | ||
53 | + listCompanyQuery := &query.ListCompanyQuery{} | ||
54 | + offset, _ := controller.GetInt("offset") | ||
55 | + listCompanyQuery.Offset = offset | ||
56 | + limit, _ := controller.GetInt("limit") | ||
57 | + listCompanyQuery.Limit = limit | ||
58 | + data, err := companyService.ListCompany(listCompanyQuery) | ||
59 | + controller.Response(data, err) | ||
60 | +} | ||
61 | + | ||
62 | +func (controller *CompanyController) ConvertCompanyStatus() { | ||
63 | + companyService := service.NewCompanyService(nil) | ||
64 | + convertCompanyStatusCommand := &command.ConvertCompanyStatusCommand{} | ||
65 | + controller.Unmarshal(convertCompanyStatusCommand) | ||
66 | + data, err := companyService.ConvertCompanyStatus(convertCompanyStatusCommand) | ||
67 | + controller.Response(data, err) | ||
68 | +} | ||
69 | + | ||
70 | +func (controller *CompanyController) SetCompanyAdmin() { | ||
71 | + companyService := service.NewCompanyService(nil) | ||
72 | + setCompanyAdminCommand := &command.SetCompanyAdminCommand{} | ||
73 | + controller.Unmarshal(setCompanyAdminCommand) | ||
74 | + data, err := companyService.SetCompanyAdmin(setCompanyAdminCommand) | ||
75 | + controller.Response(data, err) | ||
76 | +} |
@@ -14,7 +14,7 @@ type OrderController struct { | @@ -14,7 +14,7 @@ type OrderController struct { | ||
14 | func (controller *OrderController) CreateOrder() { | 14 | func (controller *OrderController) CreateOrder() { |
15 | orderService := service.NewOrderService(nil) | 15 | orderService := service.NewOrderService(nil) |
16 | createOrderCommand := &command.CreateOrderCommand{} | 16 | createOrderCommand := &command.CreateOrderCommand{} |
17 | - controller.Unmarshal(createOrderCommand) | 17 | + _ = controller.Unmarshal(createOrderCommand) |
18 | data, err := orderService.CreateOrder(createOrderCommand) | 18 | data, err := orderService.CreateOrder(createOrderCommand) |
19 | controller.Response(data, err) | 19 | controller.Response(data, err) |
20 | } | 20 | } |
pkg/port/beego/routers/company_router.go
0 → 100644
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + web.Router("/companies/", &controllers.CompanyController{}, "Post:CreateCompany") | ||
10 | + web.Router("/companies/:companyId", &controllers.CompanyController{}, "Put:UpdateCompany") | ||
11 | + web.Router("/companies/:companyId", &controllers.CompanyController{}, "Get:GetCompany") | ||
12 | + web.Router("/companies/:companyId", &controllers.CompanyController{}, "Delete:RemoveCompany") | ||
13 | + web.Router("/companies/", &controllers.CompanyController{}, "Get:ListCompany") | ||
14 | + web.Router("/companies/convertCompanyStatus", &controllers.CompanyController{}, "Post:ConvertCompanyStatus") | ||
15 | + web.Router("/companies/setCompanyAdmin", &controllers.CompanyController{}, "Post:SetCompanyAdmin") | ||
16 | +} |
1 | +package company | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + "net/http/httptest" | ||
6 | + "testing" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/server/web" | ||
9 | + . "github.com/onsi/ginkgo" | ||
10 | + . "github.com/onsi/gomega" | ||
11 | + _ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg" | ||
12 | + _ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/port/beego" | ||
13 | +) | ||
14 | + | ||
15 | +func TestCompany(t *testing.T) { | ||
16 | + RegisterFailHandler(Fail) | ||
17 | + RunSpecs(t, "Beego Port Company Correlations Test Case Suite") | ||
18 | +} | ||
19 | + | ||
20 | +var handler http.Handler | ||
21 | +var server *httptest.Server | ||
22 | + | ||
23 | +var _ = BeforeSuite(func() { | ||
24 | + handler = web.BeeApp.Handlers | ||
25 | + server = httptest.NewServer(handler) | ||
26 | +}) | ||
27 | + | ||
28 | +var _ = AfterSuite(func() { | ||
29 | + server.Close() | ||
30 | +}) |
1 | +package company | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + . "github.com/onsi/ginkgo" | ||
8 | + . "github.com/onsi/gomega" | ||
9 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg" | ||
10 | +) | ||
11 | + | ||
12 | +var _ = Describe("公司状态转换 禁用、启用", func() { | ||
13 | + var companyId int64 | ||
14 | + BeforeEach(func() { | ||
15 | + _, err := pG.DB.QueryOne( | ||
16 | + pg.Scan(&companyId), | ||
17 | + "INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id", | ||
18 | + "testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
19 | + Expect(err).NotTo(HaveOccurred()) | ||
20 | + }) | ||
21 | + Describe("公司状态转换 禁用、启用", func() { | ||
22 | + Context("", func() { | ||
23 | + It("", func() { | ||
24 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
25 | + body := map[string]interface{}{ | ||
26 | + "companyId": "int64", | ||
27 | + "status": "int64", | ||
28 | + } | ||
29 | + httpExpect.POST("/companys/convertCompanyStatus"). | ||
30 | + WithJSON(body). | ||
31 | + Expect(). | ||
32 | + Status(http.StatusOK). | ||
33 | + JSON(). | ||
34 | + Object(). | ||
35 | + ContainsKey("code").ValueEqual("code", 0). | ||
36 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
37 | + ContainsKey("data").Value("data").Object() | ||
38 | + }) | ||
39 | + }) | ||
40 | + }) | ||
41 | + AfterEach(func() { | ||
42 | + _, err := pG.DB.Exec("DELETE FROM companys WHERE true") | ||
43 | + Expect(err).NotTo(HaveOccurred()) | ||
44 | + }) | ||
45 | +}) |
1 | +package company | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + . "github.com/onsi/ginkgo" | ||
8 | + . "github.com/onsi/gomega" | ||
9 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg" | ||
10 | +) | ||
11 | + | ||
12 | +var _ = Describe("创建", func() { | ||
13 | + Describe("提交数据创建", func() { | ||
14 | + Context("提交正确的新公司信息数据", func() { | ||
15 | + It("返回公司信息数据", func() { | ||
16 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
17 | + body := map[string]interface{}{ | ||
18 | + "name": "string", | ||
19 | + "abbreviation": "string", | ||
20 | + "status": "int64", | ||
21 | + "remarks": "string", | ||
22 | + "userAccount": "string", | ||
23 | + "userName": "string", | ||
24 | + } | ||
25 | + httpExpect.POST("/companys/"). | ||
26 | + WithJSON(body). | ||
27 | + Expect(). | ||
28 | + Status(http.StatusOK). | ||
29 | + JSON(). | ||
30 | + Object(). | ||
31 | + ContainsKey("code").ValueEqual("code", 0). | ||
32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
33 | + ContainsKey("data").Value("data").Object(). | ||
34 | + ContainsKey("companyId").ValueNotEqual("companyId", BeZero()) | ||
35 | + }) | ||
36 | + }) | ||
37 | + }) | ||
38 | + AfterEach(func() { | ||
39 | + _, err := pG.DB.Exec("DELETE FROM companys WHERE true") | ||
40 | + Expect(err).NotTo(HaveOccurred()) | ||
41 | + }) | ||
42 | +}) |
1 | +package company | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + . "github.com/onsi/ginkgo" | ||
8 | + . "github.com/onsi/gomega" | ||
9 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg" | ||
10 | +) | ||
11 | + | ||
12 | +var _ = Describe("返回", func() { | ||
13 | + var companyId int64 | ||
14 | + BeforeEach(func() { | ||
15 | + _, err := pG.DB.QueryOne( | ||
16 | + pg.Scan(&companyId), | ||
17 | + "INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id", | ||
18 | + "testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
19 | + Expect(err).NotTo(HaveOccurred()) | ||
20 | + }) | ||
21 | + Describe("根据companyId参数返回公司信息", func() { | ||
22 | + Context("传入有效的companyId", func() { | ||
23 | + It("返回公司信息数据", func() { | ||
24 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
25 | + httpExpect.GET("/companys/{companyId}"). | ||
26 | + Expect(). | ||
27 | + Status(http.StatusOK). | ||
28 | + JSON(). | ||
29 | + Object(). | ||
30 | + ContainsKey("code").ValueEqual("code", 0). | ||
31 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
32 | + ContainsKey("data").Value("data").Object() | ||
33 | + }) | ||
34 | + }) | ||
35 | + }) | ||
36 | + AfterEach(func() { | ||
37 | + _, err := pG.DB.Exec("DELETE FROM companys WHERE true") | ||
38 | + Expect(err).NotTo(HaveOccurred()) | ||
39 | + }) | ||
40 | +}) |
1 | +package company | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + . "github.com/onsi/ginkgo" | ||
8 | + . "github.com/onsi/gomega" | ||
9 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg" | ||
10 | +) | ||
11 | + | ||
12 | +var _ = Describe("返回列表", func() { | ||
13 | + var companyId int64 | ||
14 | + BeforeEach(func() { | ||
15 | + _, err := pG.DB.QueryOne( | ||
16 | + pg.Scan(&companyId), | ||
17 | + "INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id", | ||
18 | + "testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
19 | + Expect(err).NotTo(HaveOccurred()) | ||
20 | + }) | ||
21 | + Describe("根据参数返回公司信息列表", func() { | ||
22 | + Context("传入有效的参数", func() { | ||
23 | + It("返回公司信息数据列表", func() { | ||
24 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
25 | + httpExpect.GET("/companys/"). | ||
26 | + WithQuery("offset", "int"). | ||
27 | + WithQuery("limit", "int"). | ||
28 | + Expect(). | ||
29 | + Status(http.StatusOK). | ||
30 | + JSON(). | ||
31 | + Object(). | ||
32 | + ContainsKey("code").ValueEqual("code", 0). | ||
33 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
34 | + ContainsKey("data").Value("data").Object(). | ||
35 | + ContainsKey("count").ValueEqual("count", 1). | ||
36 | + ContainsKey("companys").Value("companys").Array() | ||
37 | + }) | ||
38 | + }) | ||
39 | + }) | ||
40 | + AfterEach(func() { | ||
41 | + _, err := pG.DB.Exec("DELETE FROM companys WHERE true") | ||
42 | + Expect(err).NotTo(HaveOccurred()) | ||
43 | + }) | ||
44 | +}) |
1 | +package company | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + . "github.com/onsi/ginkgo" | ||
8 | + . "github.com/onsi/gomega" | ||
9 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg" | ||
10 | +) | ||
11 | + | ||
12 | +var _ = Describe("移除", func() { | ||
13 | + var companyId int64 | ||
14 | + BeforeEach(func() { | ||
15 | + _, err := pG.DB.QueryOne( | ||
16 | + pg.Scan(&companyId), | ||
17 | + "INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id", | ||
18 | + "testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
19 | + Expect(err).NotTo(HaveOccurred()) | ||
20 | + }) | ||
21 | + Describe("根据参数移除", func() { | ||
22 | + Context("传入有效的companyId", func() { | ||
23 | + It("返回被移除公司信息的数据", func() { | ||
24 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
25 | + httpExpect.DELETE("/companys/{companyId}"). | ||
26 | + Expect(). | ||
27 | + Status(http.StatusOK). | ||
28 | + JSON(). | ||
29 | + Object(). | ||
30 | + ContainsKey("code").ValueEqual("code", 0). | ||
31 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
32 | + ContainsKey("data").Value("data").Object() | ||
33 | + }) | ||
34 | + }) | ||
35 | + }) | ||
36 | + AfterEach(func() { | ||
37 | + _, err := pG.DB.Exec("DELETE FROM companys WHERE true") | ||
38 | + Expect(err).NotTo(HaveOccurred()) | ||
39 | + }) | ||
40 | +}) |
1 | +package company | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + . "github.com/onsi/ginkgo" | ||
8 | + . "github.com/onsi/gomega" | ||
9 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg" | ||
10 | +) | ||
11 | + | ||
12 | +var _ = Describe("设置公司管理员", func() { | ||
13 | + var companyId int64 | ||
14 | + BeforeEach(func() { | ||
15 | + _, err := pG.DB.QueryOne( | ||
16 | + pg.Scan(&companyId), | ||
17 | + "INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id", | ||
18 | + "testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
19 | + Expect(err).NotTo(HaveOccurred()) | ||
20 | + }) | ||
21 | + Describe("设置公司管理员", func() { | ||
22 | + Context("", func() { | ||
23 | + It("", func() { | ||
24 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
25 | + body := map[string]interface{}{ | ||
26 | + "companyId": "int64", | ||
27 | + "userAccount": "string", | ||
28 | + "userName": "string", | ||
29 | + } | ||
30 | + httpExpect.POST("/companys/setCompanyAdmin"). | ||
31 | + WithJSON(body). | ||
32 | + Expect(). | ||
33 | + Status(http.StatusOK). | ||
34 | + JSON(). | ||
35 | + Object(). | ||
36 | + ContainsKey("code").ValueEqual("code", 0). | ||
37 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
38 | + ContainsKey("data").Value("data").Object() | ||
39 | + }) | ||
40 | + }) | ||
41 | + }) | ||
42 | + AfterEach(func() { | ||
43 | + _, err := pG.DB.Exec("DELETE FROM companys WHERE true") | ||
44 | + Expect(err).NotTo(HaveOccurred()) | ||
45 | + }) | ||
46 | +}) |
1 | +package company | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + . "github.com/onsi/ginkgo" | ||
8 | + . "github.com/onsi/gomega" | ||
9 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg" | ||
10 | +) | ||
11 | + | ||
12 | +var _ = Describe("更新", func() { | ||
13 | + var companyId int64 | ||
14 | + BeforeEach(func() { | ||
15 | + _, err := pG.DB.QueryOne( | ||
16 | + pg.Scan(&companyId), | ||
17 | + "INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id", | ||
18 | + "testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
19 | + Expect(err).NotTo(HaveOccurred()) | ||
20 | + }) | ||
21 | + Describe("提交数据更新", func() { | ||
22 | + Context("提交正确的公司信息数据", func() { | ||
23 | + It("返回更新后的公司信息数据", func() { | ||
24 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
25 | + body := map[string]interface{}{ | ||
26 | + "name": "string", | ||
27 | + "abbreviation": "string", | ||
28 | + "status": "int64", | ||
29 | + "remarks": "string", | ||
30 | + "userAccount": "string", | ||
31 | + "userName": "string", | ||
32 | + } | ||
33 | + httpExpect.PUT("/companys/{companyId}"). | ||
34 | + WithJSON(body). | ||
35 | + Expect(). | ||
36 | + Status(http.StatusOK). | ||
37 | + JSON(). | ||
38 | + Object(). | ||
39 | + ContainsKey("code").ValueEqual("code", 0). | ||
40 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
41 | + ContainsKey("data").Value("data").Object(). | ||
42 | + ContainsKey("companyId").ValueEqual("companyId", companyId) | ||
43 | + }) | ||
44 | + }) | ||
45 | + }) | ||
46 | + AfterEach(func() { | ||
47 | + _, err := pG.DB.Exec("DELETE FROM companys WHERE true") | ||
48 | + Expect(err).NotTo(HaveOccurred()) | ||
49 | + }) | ||
50 | +}) |
@@ -16,12 +16,13 @@ var _ = FDescribe("创建订单增删改查", func() { | @@ -16,12 +16,13 @@ var _ = FDescribe("创建订单增删改查", func() { | ||
16 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 16 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
17 | body := map[string]interface{}{ | 17 | body := map[string]interface{}{ |
18 | "orderNo": "string", | 18 | "orderNo": "string", |
19 | - "companyId": "int64", | 19 | + "companyId": 1, |
20 | "buyerName": "string", | 20 | "buyerName": "string", |
21 | "contactInfo": "string", | 21 | "contactInfo": "string", |
22 | "shippingAddress": "string", | 22 | "shippingAddress": "string", |
23 | - "orderNum": "int64", | ||
24 | - "totalPrice": "float64", | 23 | + "orderNum": 10, |
24 | + "totalPrice": 10, | ||
25 | + "partnerId": "1213", | ||
25 | } | 26 | } |
26 | httpExpect.POST("/orders/"). | 27 | httpExpect.POST("/orders/"). |
27 | WithJSON(body). | 28 | WithJSON(body). |
@@ -10,14 +10,21 @@ import ( | @@ -10,14 +10,21 @@ import ( | ||
10 | pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg" | 10 | pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg" |
11 | ) | 11 | ) |
12 | 12 | ||
13 | -var _ = Describe("返回订单增删改查", func() { | 13 | +var _ = FDescribe("返回订单增删改查", func() { |
14 | var orderId int64 | 14 | var orderId int64 |
15 | BeforeEach(func() { | 15 | BeforeEach(func() { |
16 | - _, err := pG.DB.QueryOne( | 16 | + // 新增合伙人测试数据 |
17 | + _, err1 := pG.DB.QueryOne( | ||
18 | + pg.Scan(), | ||
19 | + "", | ||
20 | + "") | ||
21 | + Expect(err1).NotTo(HaveOccurred()) | ||
22 | + // 新增订单测试数据 | ||
23 | + _, err2 := pG.DB.QueryOne( | ||
17 | pg.Scan(&orderId), | 24 | pg.Scan(&orderId), |
18 | - "INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id", | ||
19 | - "testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
20 | - Expect(err).NotTo(HaveOccurred()) | 25 | + "INSERT INTO orders ( buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id", |
26 | + "testBuyer", 1, "testPartnerId", "testDeliveryCode", false, "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
27 | + Expect(err2).NotTo(HaveOccurred()) | ||
21 | }) | 28 | }) |
22 | Describe("根据orderId参数返回订单实体", func() { | 29 | Describe("根据orderId参数返回订单实体", func() { |
23 | Context("传入有效的orderId", func() { | 30 | Context("传入有效的orderId", func() { |
1 | +package order |
-
请 注册 或 登录 后发表评论