正在显示
21 个修改的文件
包含
214 行增加
和
159 行删除
@@ -7,7 +7,7 @@ import ( | @@ -7,7 +7,7 @@ import ( | ||
7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" |
8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/service_gateway" | 8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/service_gateway" |
9 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | 9 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" |
10 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/protocol" | 10 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" |
11 | "strings" | 11 | "strings" |
12 | "time" | 12 | "time" |
13 | ) | 13 | ) |
@@ -23,18 +23,21 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | @@ -23,18 +23,21 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | ||
23 | err = protocol.NewErrWithMessage(502, err) //账号不存在 | 23 | err = protocol.NewErrWithMessage(502, err) //账号不存在 |
24 | return | 24 | return |
25 | } | 25 | } |
26 | - switch request.Type { | 26 | + switch request.GrantType { |
27 | case protocol.LoginByPassword: | 27 | case protocol.LoginByPassword: |
28 | if len(partnerInfo.Password) == 0 { | 28 | if len(partnerInfo.Password) == 0 { |
29 | err = protocol.NewCustomMessage(1, "密码不能为空!") | 29 | err = protocol.NewCustomMessage(1, "密码不能为空!") |
30 | return | 30 | return |
31 | } | 31 | } |
32 | - if result = strings.EqualFold(partnerInfo.Password, request.Password); result { | 32 | + if result = strings.EqualFold(partnerInfo.Password, request.Password); !result { |
33 | err = protocol.NewCustomMessage(1, "密码输入有误!") | 33 | err = protocol.NewCustomMessage(1, "密码输入有误!") |
34 | return | 34 | return |
35 | } | 35 | } |
36 | break | 36 | break |
37 | case protocol.LoginBySmsCode: | 37 | case protocol.LoginBySmsCode: |
38 | + if _, err = CheckSmsCode(request.Phone, request.Captcha); err != nil { | ||
39 | + return | ||
40 | + } | ||
38 | break | 41 | break |
39 | } | 42 | } |
40 | rsp.AuthCode, _ = utils.GenerateToken(partnerInfo.Id, protocol.AuthCodeExpire*time.Second) | 43 | rsp.AuthCode, _ = utils.GenerateToken(partnerInfo.Id, protocol.AuthCodeExpire*time.Second) |
@@ -96,8 +99,8 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT | @@ -96,8 +99,8 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT | ||
96 | //验证短信验证码 T | 99 | //验证短信验证码 T |
97 | func CheckSmsCode(phone, code string) (result bool, err error) { | 100 | func CheckSmsCode(phone, code string) (result bool, err error) { |
98 | sms := service_gateway.NewHttplibMmmSmsApiServiceGateway() | 101 | sms := service_gateway.NewHttplibMmmSmsApiServiceGateway() |
99 | - _, err = sms.CheckSmsCode(phone, code) | ||
100 | var data map[string]interface{} | 102 | var data map[string]interface{} |
103 | + data, err = sms.CheckSmsCode(phone, code) | ||
101 | if err != nil { | 104 | if err != nil { |
102 | if msg, ok := data["msg"]; ok { | 105 | if msg, ok := data["msg"]; ok { |
103 | err = protocol.NewCustomMessage(1, msg.(string)) | 106 | err = protocol.NewCustomMessage(1, msg.(string)) |
@@ -25,19 +25,15 @@ func CreateAdminUserRepository(options map[string]interface{}) (domain.AdminUser | @@ -25,19 +25,15 @@ func CreateAdminUserRepository(options map[string]interface{}) (domain.AdminUser | ||
25 | } | 25 | } |
26 | 26 | ||
27 | //CreateOrderRepository 订单 | 27 | //CreateOrderRepository 订单 |
28 | -func CreateOrderRepository(options map[string]interface{}) (domain.OrderRepository, error) { | ||
29 | - var transactionContext *transaction.TransactionContext | ||
30 | - if value, ok := options["transactionContext"]; ok { | ||
31 | - transactionContext = value.(*transaction.TransactionContext) | ||
32 | - } | 28 | +func CreateOrderRepository(transactionContext *transaction.TransactionContext) (domain.OrderRepository, error) { |
33 | return repository.NewOrderRepository(transactionContext) | 29 | return repository.NewOrderRepository(transactionContext) |
34 | } | 30 | } |
35 | 31 | ||
36 | //CreateOrderRepository 订单 | 32 | //CreateOrderRepository 订单 |
37 | -func CreateOrderPaymentRepository(options map[string]interface{}) (domain.OrderPaymentRepository, error) { | ||
38 | - var transactionContext *transaction.TransactionContext | ||
39 | - if value, ok := options["transactionContext"]; ok { | ||
40 | - transactionContext = value.(*transaction.TransactionContext) | ||
41 | - } | 33 | +func CreateOrderPaymentRepository(transactionContext *transaction.TransactionContext) (domain.OrderPaymentRepository, error) { |
42 | return repository.NewOrderPaymentRepository(transactionContext) | 34 | return repository.NewOrderPaymentRepository(transactionContext) |
43 | } | 35 | } |
36 | + | ||
37 | +func CreatePartnerInfoRepositoryIn(transactionContext *transaction.TransactionContext) (domain.PartnerInfoRepository, error) { | ||
38 | + return repository.NewPartnerInfoRepository(transactionContext) | ||
39 | +} |
1 | package factory | 1 | package factory |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "github.com/linmadan/egglib-go/core/application" | ||
5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg" | 4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg" |
6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" |
7 | ) | 6 | ) |
8 | 7 | ||
9 | -func CreateTransactionContext(options map[string]interface{}) (application.TransactionContext, error) { | 8 | +func CreateTransactionContext(options map[string]interface{}) (*transaction.TransactionContext, error) { |
10 | return &transaction.TransactionContext{ | 9 | return &transaction.TransactionContext{ |
11 | PgDd: pg.DB, | 10 | PgDd: pg.DB, |
12 | }, nil | 11 | }, nil |
pkg/application/order/order.go
0 → 100644
1 | +package order | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | ||
8 | +) | ||
9 | + | ||
10 | +func Template(header *protocol.RequestHeader, request *protocol.OrderDetailRequest) (rsp *protocol.OrderDetailResponse, err error) { | ||
11 | + var ( | ||
12 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
13 | + //OrderResponsitory,_ =factory.CreateOrderRepository(transactionContext) | ||
14 | + | ||
15 | + ) | ||
16 | + if err = transactionContext.StartTransaction(); err != nil { | ||
17 | + return nil, err | ||
18 | + } | ||
19 | + defer func() { | ||
20 | + if err != nil { | ||
21 | + transactionContext.RollbackTransaction() | ||
22 | + } | ||
23 | + }() | ||
24 | + err = transactionContext.CommitTransaction() | ||
25 | + return | ||
26 | +} | ||
27 | + | ||
28 | +func OrderDetail(header *protocol.RequestHeader, request *protocol.OrderDetailRequest) (rsp *protocol.OrderDetailResponse, err error) { | ||
29 | + var ( | ||
30 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
31 | + OrderResponsitory, _ = factory.CreateOrderRepository(transactionContext) | ||
32 | + PartnerInfoRepository, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) | ||
33 | + order *domain.Order | ||
34 | + partner *domain.PartnerInfo | ||
35 | + ) | ||
36 | + if err = transactionContext.StartTransaction(); err != nil { | ||
37 | + return nil, err | ||
38 | + } | ||
39 | + defer func() { | ||
40 | + if err != nil { | ||
41 | + transactionContext.RollbackTransaction() | ||
42 | + } | ||
43 | + }() | ||
44 | + | ||
45 | + rsp = &protocol.OrderDetailResponse{} | ||
46 | + if order, err = OrderResponsitory.FindOne(utils.ObjectJsonToMap(request)); err != nil { | ||
47 | + return | ||
48 | + } | ||
49 | + if partner, err = PartnerInfoRepository.FindOne(map[string]interface{}{"partnerId": order.PartnerId}); err != nil { | ||
50 | + return | ||
51 | + } | ||
52 | + rsp.Order = order | ||
53 | + rsp.Partner = partner | ||
54 | + err = transactionContext.CommitTransaction() | ||
55 | + return | ||
56 | +} |
1 | package user | 1 | package user |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/auth" | ||
4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/command" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/command" |
5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query" |
6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service" | 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service" |
7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" |
8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | 9 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" |
9 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/protocol" | ||
10 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/services/auth" | 10 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" |
11 | "strings" | 11 | "strings" |
12 | ) | 12 | ) |
13 | 13 | ||
@@ -23,14 +23,16 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) | @@ -23,14 +23,16 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) | ||
23 | return | 23 | return |
24 | } | 24 | } |
25 | rsp.User = protocol.User{ | 25 | rsp.User = protocol.User{ |
26 | - Id: partnerInfo.Id, | ||
27 | - PartnerCategory: partnerInfo.PartnerCategory, | ||
28 | - PartnerName: partnerInfo.PartnerName, | ||
29 | - RegionInfo: partnerInfo.RegionInfo, | 26 | + Id: partnerInfo.Id, |
27 | + PartnerName: partnerInfo.PartnerName, | ||
28 | + Phone: partnerInfo.Account, | ||
30 | CooperateCompany: protocol.Company{ | 29 | CooperateCompany: protocol.Company{ |
31 | Id: 1, | 30 | Id: 1, |
32 | Name: "福州素天下有限公司", | 31 | Name: "福州素天下有限公司", |
33 | }, | 32 | }, |
33 | + JoinWay: partnerInfo.PartnerCategoryInfo(), | ||
34 | + District: partnerInfo.RegionInfo, | ||
35 | + SerialNo: partnerInfo.Id, | ||
34 | CooperateTime: partnerInfo.CooperateTime.Unix() * 1000, | 36 | CooperateTime: partnerInfo.CooperateTime.Unix() * 1000, |
35 | } | 37 | } |
36 | if len(partnerInfo.Salesman) > 0 { | 38 | if len(partnerInfo.Salesman) > 0 { |
@@ -44,19 +46,15 @@ func CheckSmsCode(header *protocol.RequestHeader, request *protocol.CheckSmsCode | @@ -44,19 +46,15 @@ func CheckSmsCode(header *protocol.RequestHeader, request *protocol.CheckSmsCode | ||
44 | var ( | 46 | var ( |
45 | PartnerInfoService = service.NewPartnerInfoService(nil) | 47 | PartnerInfoService = service.NewPartnerInfoService(nil) |
46 | partnerInfo *domain.PartnerInfo | 48 | partnerInfo *domain.PartnerInfo |
47 | - result bool | ||
48 | ) | 49 | ) |
49 | if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil { | 50 | if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil { |
50 | err = protocol.NewErrWithMessage(502, err) //账号不存在 | 51 | err = protocol.NewErrWithMessage(502, err) //账号不存在 |
51 | return | 52 | return |
52 | } | 53 | } |
53 | - if result, err = auth.CheckSmsCode(strings.TrimSpace(partnerInfo.Account), request.Captcha); err != nil { | ||
54 | - log.Error(err) | 54 | + if _, err = auth.CheckSmsCode(strings.TrimSpace(partnerInfo.Account), request.Captcha); err != nil { |
55 | + log.Error(err, partnerInfo.Account, request.Captcha) | ||
55 | return | 56 | return |
56 | } | 57 | } |
57 | - if !result { | ||
58 | - err = protocol.NewErrWithMessage(1012) | ||
59 | - } | ||
60 | return | 58 | return |
61 | } | 59 | } |
62 | 60 | ||
@@ -69,12 +67,15 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe | @@ -69,12 +67,15 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe | ||
69 | err = protocol.NewErrWithMessage(502, err) //账号不存在 | 67 | err = protocol.NewErrWithMessage(502, err) //账号不存在 |
70 | return | 68 | return |
71 | } | 69 | } |
70 | + if _, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Account: request.Phone}); err == nil { | ||
71 | + err = protocol.NewErrWithMessage(2029, err) //账号不存在 | ||
72 | + return | ||
73 | + } | ||
72 | if _, err = auth.CheckSmsCode(request.Phone, request.Captcha); err != nil { | 74 | if _, err = auth.CheckSmsCode(request.Phone, request.Captcha); err != nil { |
73 | log.Error(err) | 75 | log.Error(err) |
74 | return | 76 | return |
75 | } | 77 | } |
76 | if _, err = PartnerInfoService.UpdatePartnerInfo(&command.UpdatePartnerInfoCommand{Account: request.Phone}); err == nil { | 78 | if _, err = PartnerInfoService.UpdatePartnerInfo(&command.UpdatePartnerInfoCommand{Account: request.Phone}); err == nil { |
77 | - err = protocol.NewErrWithMessage(502, err) //账号不存在 | ||
78 | return | 79 | return |
79 | } | 80 | } |
80 | return | 81 | return |
@@ -84,7 +85,7 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe | @@ -84,7 +85,7 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe | ||
84 | func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswordRequest) (rsp *protocol.ResetPasswordResponse, err error) { | 85 | func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswordRequest) (rsp *protocol.ResetPasswordResponse, err error) { |
85 | var ( | 86 | var ( |
86 | PartnerInfoService = service.NewPartnerInfoService(nil) | 87 | PartnerInfoService = service.NewPartnerInfoService(nil) |
87 | - //partnerInfo *domain.PartnerInfo | 88 | + partnerInfo *domain.PartnerInfo |
88 | ) | 89 | ) |
89 | if len(request.NewPwd) < 6 { | 90 | if len(request.NewPwd) < 6 { |
90 | err = protocol.NewErrWithMessage(2027) | 91 | err = protocol.NewErrWithMessage(2027) |
@@ -94,10 +95,14 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo | @@ -94,10 +95,14 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo | ||
94 | err = protocol.NewErrWithMessage(2026) | 95 | err = protocol.NewErrWithMessage(2026) |
95 | return | 96 | return |
96 | } | 97 | } |
97 | - if _, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil { | 98 | + if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil { |
98 | err = protocol.NewErrWithMessage(502, err) //账号不存在 | 99 | err = protocol.NewErrWithMessage(502, err) //账号不存在 |
99 | return | 100 | return |
100 | } | 101 | } |
102 | + if _, err = auth.CheckSmsCode(partnerInfo.Account, request.Captcha); err != nil { | ||
103 | + log.Error(err) | ||
104 | + return | ||
105 | + } | ||
101 | if _, err = PartnerInfoService.UpdatePartnerInfo(&command.UpdatePartnerInfoCommand{Password: request.ConfirmPwd}); err == nil { | 106 | if _, err = PartnerInfoService.UpdatePartnerInfo(&command.UpdatePartnerInfoCommand{Password: request.ConfirmPwd}); err == nil { |
102 | return | 107 | return |
103 | } | 108 | } |
@@ -50,7 +50,7 @@ func (m *PartnerInfo) Update(data map[string]interface{}) error { | @@ -50,7 +50,7 @@ func (m *PartnerInfo) Update(data map[string]interface{}) error { | ||
50 | if account, ok := data["account"]; ok && account != "" { | 50 | if account, ok := data["account"]; ok && account != "" { |
51 | m.Account = account.(string) | 51 | m.Account = account.(string) |
52 | } | 52 | } |
53 | - if password, ok := data["account"]; ok && password != "" { | 53 | + if password, ok := data["password"]; ok && password != "" { |
54 | m.Password = password.(string) | 54 | m.Password = password.(string) |
55 | } | 55 | } |
56 | if status, ok := data["status"]; ok && status != 0 { | 56 | if status, ok := data["status"]; ok && status != 0 { |
@@ -65,3 +65,30 @@ func (m *PartnerInfo) Update(data map[string]interface{}) error { | @@ -65,3 +65,30 @@ func (m *PartnerInfo) Update(data map[string]interface{}) error { | ||
65 | m.UpdateAt = time.Now() | 65 | m.UpdateAt = time.Now() |
66 | return nil | 66 | return nil |
67 | } | 67 | } |
68 | + | ||
69 | +func (m *PartnerInfo) PartnerCategoryInfo() *PartnerCategoryInfo { | ||
70 | + var name string | ||
71 | + switch m.PartnerCategory { | ||
72 | + case 1: | ||
73 | + name = "事业合伙人" | ||
74 | + break | ||
75 | + case 2: | ||
76 | + name = "业务合伙人" | ||
77 | + break | ||
78 | + case 3: | ||
79 | + name = "研发合伙人" | ||
80 | + break | ||
81 | + default: | ||
82 | + name = "事业合伙人" | ||
83 | + break | ||
84 | + } | ||
85 | + return &PartnerCategoryInfo{ | ||
86 | + Id: m.PartnerCategory, | ||
87 | + Name: name, | ||
88 | + } | ||
89 | +} | ||
90 | + | ||
91 | +type PartnerCategoryInfo struct { | ||
92 | + Id int `json:"id"` | ||
93 | + Name string `json:"name"` | ||
94 | +} |
pkg/infrastructure/dao/pg_order_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 OrderDao struct { | ||
9 | + transactionContext *transaction.TransactionContext | ||
10 | +} | ||
11 | + | ||
12 | +func NewEmployeeDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) { | ||
13 | + if transactionContext == nil { | ||
14 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
15 | + } else { | ||
16 | + return &OrderDao{ | ||
17 | + transactionContext: transactionContext, | ||
18 | + }, nil | ||
19 | + } | ||
20 | +} |
@@ -50,8 +50,8 @@ func (repository *OrderRepository) FindOne(queryOptions map[string]interface{}) | @@ -50,8 +50,8 @@ func (repository *OrderRepository) FindOne(queryOptions map[string]interface{}) | ||
50 | tx := repository.transactionContext.PgTx | 50 | tx := repository.transactionContext.PgTx |
51 | OrderModel := new(models.Order) | 51 | OrderModel := new(models.Order) |
52 | query := NewQuery(tx.Model(OrderModel), queryOptions) | 52 | query := NewQuery(tx.Model(OrderModel), queryOptions) |
53 | - query.SetWhere("order.id = ?", "id") | ||
54 | - query.SetWhere("order.order_code = ?", "orderCode") | 53 | + query.SetWhere(`"order".id = ?`, "id") |
54 | + query.SetWhere(`"order".order_code = ?`, "orderCode") | ||
55 | if err := query.First(); err != nil { | 55 | if err := query.First(); err != nil { |
56 | return nil, query.HandleError(err, "没有此订单") | 56 | return nil, query.HandleError(err, "没有此订单") |
57 | } | 57 | } |
1 | package controllers | 1 | package controllers |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/protocol" | ||
5 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/services/auth" | 4 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/auth" |
5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | ||
6 | ) | 6 | ) |
7 | 7 | ||
8 | type AuthController struct { | 8 | type AuthController struct { |
@@ -5,10 +5,8 @@ import ( | @@ -5,10 +5,8 @@ import ( | ||
5 | "github.com/astaxie/beego" | 5 | "github.com/astaxie/beego" |
6 | "github.com/astaxie/beego/context" | 6 | "github.com/astaxie/beego/context" |
7 | "github.com/astaxie/beego/validation" | 7 | "github.com/astaxie/beego/validation" |
8 | - "github.com/linmadan/egglib-go/core/application" | ||
9 | - "github.com/linmadan/egglib-go/web/beego/utils" | ||
10 | - comm "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
11 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/protocol" | 8 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" |
9 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | ||
12 | "strconv" | 10 | "strconv" |
13 | ) | 11 | ) |
14 | 12 | ||
@@ -18,46 +16,15 @@ type BaseController struct { | @@ -18,46 +16,15 @@ type BaseController struct { | ||
18 | 16 | ||
19 | func (controller BaseController) JsonUnmarshal(v interface{}) error { | 17 | func (controller BaseController) JsonUnmarshal(v interface{}) error { |
20 | body := controller.Ctx.Input.GetData("requestBody").([]byte) | 18 | body := controller.Ctx.Input.GetData("requestBody").([]byte) |
21 | - //fmt.Println("【RequestBody】 ",controller.Ctx.Input.Method(),controller.Ctx.Input.URL(),string(body)) | ||
22 | return json.Unmarshal(body, v) | 19 | return json.Unmarshal(body, v) |
23 | } | 20 | } |
24 | 21 | ||
25 | -func (controller BaseController) HandlerResponse(data interface{}, err error) { | ||
26 | - var response utils.JsonResponse | ||
27 | - defer func() { | ||
28 | - controller.Data["json"] = response | ||
29 | - controller.ServeJSON() | ||
30 | - }() | ||
31 | - if err == nil { | ||
32 | - response = utils.ResponseData(controller.Ctx, data) | ||
33 | - return | ||
34 | - } | ||
35 | - if _, ok := err.(*application.ServiceError); !ok { | ||
36 | - err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
37 | - } | ||
38 | - if x, ok := err.(protocol.CustomErrParse); ok { | ||
39 | - m := x.ParseToMessage() | ||
40 | - response = ResponseCustomData(controller.Ctx, data, m) | ||
41 | - return | ||
42 | - } | ||
43 | - response = utils.ResponseError(controller.Ctx, err) | ||
44 | -} | ||
45 | - | ||
46 | func (controller BaseController) GetLimitInfo() (offset int, limit int) { | 22 | func (controller BaseController) GetLimitInfo() (offset int, limit int) { |
47 | offset, _ = controller.GetInt("offset") | 23 | offset, _ = controller.GetInt("offset") |
48 | limit, _ = controller.GetInt("limit") | 24 | limit, _ = controller.GetInt("limit") |
49 | return | 25 | return |
50 | } | 26 | } |
51 | 27 | ||
52 | -func ResponseCustomData(ctx *context.Context, data interface{}, msg *protocol.ResponseMessage) utils.JsonResponse { | ||
53 | - jsonResponse := utils.JsonResponse{} | ||
54 | - jsonResponse["code"] = 0 | ||
55 | - jsonResponse["msg"] = "ok" | ||
56 | - jsonResponse["data"] = data | ||
57 | - ctx.Input.SetData("outputData", jsonResponse) | ||
58 | - return jsonResponse | ||
59 | -} | ||
60 | - | ||
61 | //Valid valid struct | 28 | //Valid valid struct |
62 | func (controller *BaseController) Valid(obj interface{}) (result bool, msg *protocol.ResponseMessage) { | 29 | func (controller *BaseController) Valid(obj interface{}) (result bool, msg *protocol.ResponseMessage) { |
63 | /*校验*/ | 30 | /*校验*/ |
@@ -102,7 +69,7 @@ func (this *BaseController) GetRequestHeader(ctx *context.Context) *protocol.Req | @@ -102,7 +69,7 @@ func (this *BaseController) GetRequestHeader(ctx *context.Context) *protocol.Req | ||
102 | h.UserId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-id"), 10, 64) | 69 | h.UserId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-id"), 10, 64) |
103 | 70 | ||
104 | if len(h.AccessToken) > 0 { | 71 | if len(h.AccessToken) > 0 { |
105 | - if claim, err := comm.ParseJWTToken(h.AccessToken); err == nil { | 72 | + if claim, err := utils.ParseJWTToken(h.AccessToken); err == nil { |
106 | h.UserId = claim.UserId | 73 | h.UserId = claim.UserId |
107 | } | 74 | } |
108 | } | 75 | } |
pkg/port/appsvr/controllers/order.go
0 → 100644
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/order" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | ||
6 | +) | ||
7 | + | ||
8 | +type OrderController struct { | ||
9 | + BaseController | ||
10 | +} | ||
11 | + | ||
12 | +//OrderDetail 订单详情 | ||
13 | +// @router /orderDetail [post] | ||
14 | +func (this *OrderController) OrderDetail() { | ||
15 | + var msg *protocol.ResponseMessage | ||
16 | + defer func() { | ||
17 | + this.Resp(msg) | ||
18 | + }() | ||
19 | + var request *protocol.OrderDetailRequest | ||
20 | + if err := this.JsonUnmarshal(&request); err != nil { | ||
21 | + msg = protocol.BadRequestParam(1) | ||
22 | + return | ||
23 | + } | ||
24 | + if b, m := this.Valid(request); !b { | ||
25 | + msg = m | ||
26 | + return | ||
27 | + } | ||
28 | + header := this.GetRequestHeader(this.Ctx) | ||
29 | + msg = protocol.NewReturnResponse(order.OrderDetail(header, request)) | ||
30 | +} |
1 | -package controllers | ||
2 | - | ||
3 | -import ( | ||
4 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/command" | ||
5 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query" | ||
6 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service" | ||
7 | -) | ||
8 | - | ||
9 | -type PartnerInfoController struct { | ||
10 | - BaseController | ||
11 | -} | ||
12 | - | ||
13 | -//CreatePartnerInfo 创建合伙人 | ||
14 | -func (controller *PartnerInfoController) CreatePartnerInfo() { | ||
15 | - var ( | ||
16 | - service = service.NewPartnerInfoService(nil) | ||
17 | - command = &command.CreatePartnerInfoCommand{} | ||
18 | - ) | ||
19 | - controller.JsonUnmarshal(command) | ||
20 | - controller.HandlerResponse(service.CreatePartnerInfo(command)) | ||
21 | -} | ||
22 | - | ||
23 | -//UpdatePartnerInfo 更新合伙人 | ||
24 | -func (controller *PartnerInfoController) UpdatePartnerInfo() { | ||
25 | - var ( | ||
26 | - service = service.NewPartnerInfoService(nil) | ||
27 | - command = &command.UpdatePartnerInfoCommand{} | ||
28 | - ) | ||
29 | - controller.JsonUnmarshal(command) | ||
30 | - id, _ := controller.GetInt(":id") | ||
31 | - command.Id = id | ||
32 | - controller.HandlerResponse(service.UpdatePartnerInfo(command)) | ||
33 | -} | ||
34 | - | ||
35 | -//GetPartnerInfo 获取合伙人 | ||
36 | -func (controller *PartnerInfoController) GetPartnerInfo() { | ||
37 | - var ( | ||
38 | - service = service.NewPartnerInfoService(nil) | ||
39 | - command = &query.GetPartnerInfoQuery{} | ||
40 | - ) | ||
41 | - uid, _ := controller.GetInt(":id") | ||
42 | - command.Id = uid | ||
43 | - controller.HandlerResponse(service.GetPartnerInfo(command)) | ||
44 | -} | ||
45 | - | ||
46 | -//GetPartnerInfo 移除合伙人 | ||
47 | -func (controller *PartnerInfoController) RemovePartnerInfo() { | ||
48 | - var ( | ||
49 | - service = service.NewPartnerInfoService(nil) | ||
50 | - command = &command.RemovePartnerInfoCommand{} | ||
51 | - ) | ||
52 | - uid, _ := controller.GetInt(":id") | ||
53 | - command.Id = uid | ||
54 | - controller.HandlerResponse(service.RemovePartnerInfo(command)) | ||
55 | -} | ||
56 | - | ||
57 | -//ListPartnerInfo 合伙人列表 | ||
58 | -func (controller *PartnerInfoController) ListPartnerInfo() { | ||
59 | - var ( | ||
60 | - service = service.NewPartnerInfoService(nil) | ||
61 | - command = &query.ListPartnerInfoQuery{} | ||
62 | - ) | ||
63 | - command.PartnerCategory, _ = controller.GetInt("partnerCategory") | ||
64 | - command.Status, _ = controller.GetInt("status") | ||
65 | - command.SortByCreateTime = controller.GetString("sortByCreateTime") | ||
66 | - command.SortByUpdateTime = controller.GetString("sortByUpdateTime") | ||
67 | - command.Offset, command.Limit = controller.GetLimitInfo() | ||
68 | - controller.HandlerResponse(service.ListPartnerInfo(command)) | ||
69 | -} |
1 | package controllers | 1 | package controllers |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/protocol" | ||
5 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/services/user" | 4 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/user" |
5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | ||
6 | ) | 6 | ) |
7 | 7 | ||
8 | type UserController struct { | 8 | type UserController struct { |
@@ -3,7 +3,7 @@ package middleware | @@ -3,7 +3,7 @@ package middleware | ||
3 | import ( | 3 | import ( |
4 | "github.com/astaxie/beego/context" | 4 | "github.com/astaxie/beego/context" |
5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" |
6 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr/protocol" | 6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" |
7 | "strings" | 7 | "strings" |
8 | ) | 8 | ) |
9 | 9 |
@@ -18,8 +18,10 @@ func init() { | @@ -18,8 +18,10 @@ func init() { | ||
18 | 18 | ||
19 | nsV1.Router("user/userInfo", &controllers.UserController{}, "Post:UserInfo") | 19 | nsV1.Router("user/userInfo", &controllers.UserController{}, "Post:UserInfo") |
20 | nsV1.Router("user/checkSmsCode", &controllers.UserController{}, "Post:CheckSmsCode") | 20 | nsV1.Router("user/checkSmsCode", &controllers.UserController{}, "Post:CheckSmsCode") |
21 | - nsV1.Router("user/ChangePhone", &controllers.UserController{}, "Post:ChangePhone") | 21 | + nsV1.Router("user/changePhone", &controllers.UserController{}, "Post:ChangePhone") |
22 | nsV1.Router("user/resetPassword", &controllers.UserController{}, "Post:ResetPassword") | 22 | nsV1.Router("user/resetPassword", &controllers.UserController{}, "Post:ResetPassword") |
23 | nsV1.Router("user/changePassword", &controllers.UserController{}, "Post:ChangePassword") | 23 | nsV1.Router("user/changePassword", &controllers.UserController{}, "Post:ChangePassword") |
24 | + | ||
25 | + nsV1.Router("order/details", &controllers.OrderController{}, "Post:OrderDetail") | ||
24 | beego.AddNamespace(nsV1) | 26 | beego.AddNamespace(nsV1) |
25 | } | 27 | } |
1 | package protocol | 1 | package protocol |
2 | 2 | ||
3 | const ( | 3 | const ( |
4 | - LoginByPassword = iota + 1 | ||
5 | - LoginBySmsCode | 4 | + LoginByPassword = "signInPassword" |
5 | + LoginBySmsCode = " signInCaptcha" | ||
6 | ) | 6 | ) |
7 | 7 | ||
8 | const AuthCodeExpire = 60 * 15 | 8 | const AuthCodeExpire = 60 * 15 |
@@ -11,10 +11,11 @@ const RefreshTokenExipre = 3600 * 24 * 30 * 3 //刷新token 三个月过期 | @@ -11,10 +11,11 @@ const RefreshTokenExipre = 3600 * 24 * 30 * 3 //刷新token 三个月过期 | ||
11 | 11 | ||
12 | /*Login */ | 12 | /*Login */ |
13 | type LoginRequest struct { | 13 | type LoginRequest struct { |
14 | - Phone string `json:"phone" valid:"Required;"` | ||
15 | - Password string `json:"password"` | ||
16 | - SmsCode string `json:"smsCode"` | ||
17 | - Type int `json:"type"` // 登录类型 1:密码 2:验证码 | 14 | + Phone string `json:"phone" valid:"Required;"` |
15 | + Password string `json:"password"` | ||
16 | + Captcha string `json:"captcha"` | ||
17 | + GrantType string `json:"grantType"` // 登录类型 1:密码 2:验证码 | ||
18 | + ClientId string `json:"clientId"` | ||
18 | } | 19 | } |
19 | type LoginResponse struct { | 20 | type LoginResponse struct { |
20 | AuthCode string `json:"authCode"` | 21 | AuthCode string `json:"authCode"` |
pkg/protocol/order.go
0 → 100644
@@ -12,15 +12,22 @@ type UserInfoResponse struct { | @@ -12,15 +12,22 @@ type UserInfoResponse struct { | ||
12 | } | 12 | } |
13 | 13 | ||
14 | type User struct { | 14 | type User struct { |
15 | - Id int64 `json:"id"` | 15 | + Id int64 `json:"uid"` |
16 | + //用户名称 | ||
17 | + PartnerName string `json:"uname"` | ||
18 | + //手机号 | ||
19 | + Phone string `json:"phone"` | ||
20 | + //合作公司 | ||
21 | + CooperateCompany Company `json:"company"` | ||
16 | // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业) | 22 | // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业) |
17 | - PartnerCategory int `json:"partnerCategory"` | ||
18 | - PartnerName string `json:"partnerName"` | ||
19 | - //所属区域信息 | ||
20 | - RegionInfo *domain.RegionInfo `json:"regionInfo"` | ||
21 | - CooperateCompany Company `json:"cooperateCompany"` | ||
22 | - CooperateTime int64 `json:"cooperateTime"` | ||
23 | - Salesman *domain.Salesman `json:"salesman"` | 23 | + JoinWay *domain.PartnerCategoryInfo `json:"joinWay"` |
24 | + //合作区域 | ||
25 | + District *domain.RegionInfo `json:"district"` | ||
26 | + //合作编码 | ||
27 | + SerialNo int64 `json:"serialNo"` | ||
28 | + //合作时间 | ||
29 | + CooperateTime int64 `json:"cooperateTime"` | ||
30 | + Salesman *domain.Salesman `json:"salesman"` | ||
24 | } | 31 | } |
25 | 32 | ||
26 | type Company struct { | 33 | type Company struct { |
@@ -45,6 +52,7 @@ type ChangePhoneResponse struct { | @@ -45,6 +52,7 @@ type ChangePhoneResponse struct { | ||
45 | 52 | ||
46 | /*ResetPassword */ | 53 | /*ResetPassword */ |
47 | type ResetPasswordRequest struct { | 54 | type ResetPasswordRequest struct { |
55 | + Captcha string `json:"captcha" valid:"Required"` | ||
48 | NewPwd string `json:"newPwd" valid:"Required"` | 56 | NewPwd string `json:"newPwd" valid:"Required"` |
49 | ConfirmPwd string `json:"confirmPwd" valid:"Required"` | 57 | ConfirmPwd string `json:"confirmPwd" valid:"Required"` |
50 | } | 58 | } |
-
请 注册 或 登录 后发表评论