正在显示
10 个修改的文件
包含
172 行增加
和
7 行删除
@@ -41,3 +41,8 @@ func CreatePartnerInfoRepositoryIn(transactionContext *transaction.TransactionCo | @@ -41,3 +41,8 @@ func CreatePartnerInfoRepositoryIn(transactionContext *transaction.TransactionCo | ||
41 | func CreatePartnerSubAccountRepository(transactionContext *transaction.TransactionContext) (domain.PartnerSubAccountRepository, error) { | 41 | func CreatePartnerSubAccountRepository(transactionContext *transaction.TransactionContext) (domain.PartnerSubAccountRepository, error) { |
42 | return repository.NewPartnerSubAccountRepository(transactionContext) | 42 | return repository.NewPartnerSubAccountRepository(transactionContext) |
43 | } | 43 | } |
44 | + | ||
45 | +//公司信息 | ||
46 | +func CreateCompanyRepository(transactionContext *transaction.TransactionContext) (domain.CompanyRepository, error) { | ||
47 | + return repository.NewCompanyRepository(transactionContext) | ||
48 | +} |
@@ -14,21 +14,36 @@ import ( | @@ -14,21 +14,36 @@ import ( | ||
14 | //用户信息 | 14 | //用户信息 |
15 | func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp *protocol.UserInfoResponse, err error) { | 15 | func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp *protocol.UserInfoResponse, err error) { |
16 | var ( | 16 | var ( |
17 | - PartnerInfoService = service.NewPartnerInfoService(nil) | ||
18 | - partnerInfo *domain.PartnerInfo | 17 | + PartnerInfoService = service.NewPartnerInfoService(nil) |
18 | + partnerInfo *domain.PartnerInfo | ||
19 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
20 | + CompanyResponsitory, _ = factory.CreateCompanyRepository(transactionContext) | ||
21 | + company *domain.Company | ||
19 | ) | 22 | ) |
23 | + if err = transactionContext.StartTransaction(); err != nil { | ||
24 | + return nil, err | ||
25 | + } | ||
26 | + defer func() { | ||
27 | + if err != nil { | ||
28 | + transactionContext.RollbackTransaction() | ||
29 | + } | ||
30 | + }() | ||
20 | rsp = &protocol.UserInfoResponse{} | 31 | rsp = &protocol.UserInfoResponse{} |
21 | if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil { | 32 | if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil { |
22 | err = protocol.NewErrWithMessage(502, err) //账号不存在 | 33 | err = protocol.NewErrWithMessage(502, err) //账号不存在 |
23 | return | 34 | return |
24 | } | 35 | } |
36 | + if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": 1}); err != nil { | ||
37 | + return | ||
38 | + } | ||
25 | rsp.User = protocol.User{ | 39 | rsp.User = protocol.User{ |
26 | Id: partnerInfo.Id, | 40 | Id: partnerInfo.Id, |
27 | PartnerName: partnerInfo.PartnerName, | 41 | PartnerName: partnerInfo.PartnerName, |
28 | Phone: partnerInfo.Account, | 42 | Phone: partnerInfo.Account, |
29 | CooperateCompany: protocol.Company{ | 43 | CooperateCompany: protocol.Company{ |
30 | - Id: 1, | ||
31 | - Name: "福州素天下有限公司", | 44 | + Id: company.Id, |
45 | + Name: company.Name, | ||
46 | + Phone: company.Phone, | ||
32 | }, | 47 | }, |
33 | JoinWay: partnerInfo.PartnerCategoryInfo(), | 48 | JoinWay: partnerInfo.PartnerCategoryInfo(), |
34 | District: map[string]interface{}{"id": partnerInfo.RegionInfo.RegionId, "name": partnerInfo.RegionInfo.RegionName}, | 49 | District: map[string]interface{}{"id": partnerInfo.RegionInfo.RegionId, "name": partnerInfo.RegionInfo.RegionName}, |
@@ -40,6 +55,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) | @@ -40,6 +55,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) | ||
40 | } else { | 55 | } else { |
41 | rsp.User.Salesman = map[string]interface{}{} | 56 | rsp.User.Salesman = map[string]interface{}{} |
42 | } | 57 | } |
58 | + err = transactionContext.CommitTransaction() | ||
43 | return | 59 | return |
44 | } | 60 | } |
45 | 61 |
@@ -5,3 +5,10 @@ type Company struct { | @@ -5,3 +5,10 @@ type Company struct { | ||
5 | Name string `json:"name"` | 5 | Name string `json:"name"` |
6 | Phone string `json:"phone"` | 6 | Phone string `json:"phone"` |
7 | } | 7 | } |
8 | + | ||
9 | +type CompanyRepository interface { | ||
10 | + Save(dm *Company) (*Company, error) | ||
11 | + Remove(dm *Company) (*Company, error) | ||
12 | + FindOne(queryOptions map[string]interface{}) (*Company, error) | ||
13 | + Find(queryOptions map[string]interface{}) (int64, []*Company, error) | ||
14 | +} |
pkg/infrastructure/dao/pg_company_dao.go
0 → 100644
1 | +package dao | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | ||
6 | +) | ||
7 | + | ||
8 | +type CompanyDao struct { | ||
9 | + transactionContext *transaction.TransactionContext | ||
10 | +} | ||
11 | + | ||
12 | +func NewCompanyDao(transactionContext *transaction.TransactionContext) (*CompanyDao, error) { | ||
13 | + if transactionContext == nil { | ||
14 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
15 | + } else { | ||
16 | + return &CompanyDao{ | ||
17 | + transactionContext: transactionContext, | ||
18 | + }, nil | ||
19 | + } | ||
20 | +} |
@@ -29,6 +29,7 @@ func init() { | @@ -29,6 +29,7 @@ func init() { | ||
29 | (*models.Order)(nil), | 29 | (*models.Order)(nil), |
30 | (*models.OrderPayment)(nil), | 30 | (*models.OrderPayment)(nil), |
31 | (*models.PartnerSubAccount)(nil), | 31 | (*models.PartnerSubAccount)(nil), |
32 | + (*models.Company)(nil), | ||
32 | } { | 33 | } { |
33 | err := DB.CreateTable(model, &orm.CreateTableOptions{ | 34 | err := DB.CreateTable(model, &orm.CreateTableOptions{ |
34 | Temp: false, | 35 | Temp: false, |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | ||
7 | + . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
8 | +) | ||
9 | + | ||
10 | +type CompanyRepository struct { | ||
11 | + transactionContext *transaction.TransactionContext | ||
12 | +} | ||
13 | + | ||
14 | +func (repository *CompanyRepository) Save(dm *domain.Company) (*domain.Company, error) { | ||
15 | + var ( | ||
16 | + err error | ||
17 | + m = &models.Company{} | ||
18 | + tx = repository.transactionContext.PgTx | ||
19 | + ) | ||
20 | + if err = GobModelTransform(m, dm); err != nil { | ||
21 | + return nil, err | ||
22 | + } | ||
23 | + if dm.Id == 0 { | ||
24 | + if err = tx.Insert(m); err != nil { | ||
25 | + return nil, err | ||
26 | + } | ||
27 | + return dm, nil | ||
28 | + } | ||
29 | + if err = tx.Update(m); err != nil { | ||
30 | + return nil, err | ||
31 | + } | ||
32 | + return dm, nil | ||
33 | +} | ||
34 | + | ||
35 | +func (repository *CompanyRepository) Remove(Company *domain.Company) (*domain.Company, error) { | ||
36 | + var ( | ||
37 | + tx = repository.transactionContext.PgTx | ||
38 | + CompanyModel = &models.Company{Id: Company.Id} | ||
39 | + ) | ||
40 | + if _, err := tx.Model(CompanyModel).Where("id = ?", Company.Id).Delete(); err != nil { | ||
41 | + return Company, err | ||
42 | + } | ||
43 | + return Company, nil | ||
44 | +} | ||
45 | + | ||
46 | +func (repository *CompanyRepository) FindOne(queryOptions map[string]interface{}) (*domain.Company, error) { | ||
47 | + tx := repository.transactionContext.PgTx | ||
48 | + CompanyModel := new(models.Company) | ||
49 | + query := NewQuery(tx.Model(CompanyModel), queryOptions) | ||
50 | + query.SetWhere(`"company".id = ?`, "id") | ||
51 | + if err := query.First(); err != nil { | ||
52 | + return nil, query.HandleError(err, "没有此订单") | ||
53 | + } | ||
54 | + if CompanyModel.Id == 0 { | ||
55 | + return nil, nil | ||
56 | + } | ||
57 | + return repository.transformPgModelToDomainModel(CompanyModel) | ||
58 | +} | ||
59 | + | ||
60 | +func (repository *CompanyRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Company, error) { | ||
61 | + tx := repository.transactionContext.PgTx | ||
62 | + var CompanyModels []*models.Company | ||
63 | + Companys := make([]*domain.Company, 0) | ||
64 | + query := NewQuery(tx.Model(&CompanyModels), queryOptions) | ||
65 | + var err error | ||
66 | + if query.AffectRow, err = query.SelectAndCount(); err != nil { | ||
67 | + return 0, Companys, err | ||
68 | + } | ||
69 | + for _, CompanyModel := range CompanyModels { | ||
70 | + if Company, err := repository.transformPgModelToDomainModel(CompanyModel); err != nil { | ||
71 | + return 0, Companys, err | ||
72 | + } else { | ||
73 | + Companys = append(Companys, Company) | ||
74 | + } | ||
75 | + } | ||
76 | + return int64(query.AffectRow), Companys, nil | ||
77 | +} | ||
78 | + | ||
79 | +func (repository *CompanyRepository) transformPgModelToDomainModel(CompanyModel *models.Company) (*domain.Company, error) { | ||
80 | + m := &domain.Company{} | ||
81 | + err := GobModelTransform(m, CompanyModel) | ||
82 | + return m, err | ||
83 | +} | ||
84 | + | ||
85 | +func NewCompanyRepository(transactionContext *transaction.TransactionContext) (*CompanyRepository, error) { | ||
86 | + if transactionContext == nil { | ||
87 | + return nil, ERR_EMPTY_TC | ||
88 | + } | ||
89 | + return &CompanyRepository{transactionContext: transactionContext}, nil | ||
90 | +} |
@@ -2,7 +2,9 @@ package controllers | @@ -2,7 +2,9 @@ package controllers | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/order" | 4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/order" |
5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" |
7 | + "time" | ||
6 | ) | 8 | ) |
7 | 9 | ||
8 | type OrderController struct { | 10 | type OrderController struct { |
@@ -64,6 +66,28 @@ func (this *OrderController) OrderList() { | @@ -64,6 +66,28 @@ func (this *OrderController) OrderList() { | ||
64 | msg = m | 66 | msg = m |
65 | return | 67 | return |
66 | } | 68 | } |
69 | + request.OrderAction = domain.OrderReal | ||
70 | + header := this.GetRequestHeader(this.Ctx) | ||
71 | + msg = protocol.NewReturnResponse(order.OrderList(header, request)) | ||
72 | +} | ||
73 | + | ||
74 | +//OrderList | ||
75 | +func (this *OrderController) Intentions() { | ||
76 | + var msg *protocol.ResponseMessage | ||
77 | + defer func() { | ||
78 | + this.Resp(msg) | ||
79 | + }() | ||
80 | + var request *protocol.OrderListRequest | ||
81 | + if err := this.JsonUnmarshal(&request); err != nil { | ||
82 | + msg = protocol.BadRequestParam(1) | ||
83 | + return | ||
84 | + } | ||
85 | + if b, m := this.Valid(request); !b { | ||
86 | + msg = m | ||
87 | + return | ||
88 | + } | ||
89 | + request.EndTime = time.Now().Unix() * 1000 | ||
90 | + request.OrderAction = domain.OrderIntention | ||
67 | header := this.GetRequestHeader(this.Ctx) | 91 | header := this.GetRequestHeader(this.Ctx) |
68 | msg = protocol.NewReturnResponse(order.OrderList(header, request)) | 92 | msg = protocol.NewReturnResponse(order.OrderList(header, request)) |
69 | } | 93 | } |
@@ -26,6 +26,7 @@ func init() { | @@ -26,6 +26,7 @@ func init() { | ||
26 | nsV1.Router("/order/statistics", &controllers.OrderController{}, "Post:Statistics") | 26 | nsV1.Router("/order/statistics", &controllers.OrderController{}, "Post:Statistics") |
27 | nsV1.Router("/order/details", &controllers.OrderController{}, "Post:OrderDetail") | 27 | nsV1.Router("/order/details", &controllers.OrderController{}, "Post:OrderDetail") |
28 | nsV1.Router("/order/list", &controllers.OrderController{}, "Post:OrderList") | 28 | nsV1.Router("/order/list", &controllers.OrderController{}, "Post:OrderList") |
29 | + nsV1.Router("/order/intentions", &controllers.OrderController{}, "Post:Intentions") | ||
29 | 30 | ||
30 | nsV1.Router("/dividend/statistics", &controllers.DividendController{}, "Post:DividendStatistics") | 31 | nsV1.Router("/dividend/statistics", &controllers.DividendController{}, "Post:DividendStatistics") |
31 | nsV1.Router("/dividend/orders", &controllers.DividendController{}, "Post:DividendOrders") | 32 | nsV1.Router("/dividend/orders", &controllers.DividendController{}, "Post:DividendOrders") |
@@ -46,7 +46,7 @@ type OrderStatics struct { | @@ -46,7 +46,7 @@ type OrderStatics struct { | ||
46 | type OrderListRequest struct { | 46 | type OrderListRequest struct { |
47 | StartTime int64 `json:"startTime" valid:"Required"` | 47 | StartTime int64 `json:"startTime" valid:"Required"` |
48 | EndTime int64 `json:"endTime" valid:"Required"` | 48 | EndTime int64 `json:"endTime" valid:"Required"` |
49 | - OrderAction int `json:"orderAction" valid:"Required"` | 49 | + OrderAction int `json:"orderAction"` |
50 | PageIndex int `json:"pageIndex"` | 50 | PageIndex int `json:"pageIndex"` |
51 | PageSize int `json:"pageSize" valid:"Required"` | 51 | PageSize int `json:"pageSize" valid:"Required"` |
52 | } | 52 | } |
@@ -31,8 +31,9 @@ type User struct { | @@ -31,8 +31,9 @@ type User struct { | ||
31 | } | 31 | } |
32 | 32 | ||
33 | type Company struct { | 33 | type Company struct { |
34 | - Id int `json:"id"` | ||
35 | - Name string `json:"name"` | 34 | + Id int64 `json:"id"` |
35 | + Name string `json:"name"` | ||
36 | + Phone string `json:"phone"` | ||
36 | } | 37 | } |
37 | 38 | ||
38 | /*修改手机号-验证旧手机验证码 */ | 39 | /*修改手机号-验证旧手机验证码 */ |
-
请 注册 或 登录 后发表评论