正在显示
20 个修改的文件
包含
423 行增加
和
278 行删除
@@ -44,10 +44,11 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | @@ -44,10 +44,11 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | ||
44 | return | 44 | return |
45 | } | 45 | } |
46 | 46 | ||
47 | -func SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.LoginResponse, err error) { | 47 | +func SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, err error) { |
48 | var data map[string]interface{} | 48 | var data map[string]interface{} |
49 | sms := svr.NewHttplibMmmSmsApiServiceGateway() | 49 | sms := svr.NewHttplibMmmSmsApiServiceGateway() |
50 | data, err = sms.SendSms(request.Phone) | 50 | data, err = sms.SendSms(request.Phone) |
51 | + rsp = &protocol.SmsCodeResponse{} | ||
51 | if err != nil { | 52 | if err != nil { |
52 | if msg, ok := data["msg"]; ok { | 53 | if msg, ok := data["msg"]; ok { |
53 | err = protocol.NewCustomMessage(1, msg.(string)) | 54 | err = protocol.NewCustomMessage(1, msg.(string)) |
@@ -109,3 +110,15 @@ func CheckSmsCode(phone, code string) (result bool, err error) { | @@ -109,3 +110,15 @@ func CheckSmsCode(phone, code string) (result bool, err error) { | ||
109 | } | 110 | } |
110 | return | 111 | return |
111 | } | 112 | } |
113 | + | ||
114 | +//验证手机号码(修改手机号码、重置密码的前一步) | ||
115 | +func AuthCheckSmsCode(header *protocol.RequestHeader, request *protocol.AuthCheckSmsCodeRequest) (rsp *protocol.AuthCheckSmsCodeResponse, err error) { | ||
116 | + var () | ||
117 | + if _, err = CheckSmsCode(request.Phone, request.Captcha); err != nil { | ||
118 | + return | ||
119 | + } | ||
120 | + rsp = &protocol.AuthCheckSmsCodeResponse{ | ||
121 | + CaptchaCertificate: fmt.Sprintf("%v", utils.GenerateRangeNum(100000, 799999)), | ||
122 | + } | ||
123 | + return | ||
124 | +} |
@@ -16,3 +16,7 @@ import ( | @@ -16,3 +16,7 @@ import ( | ||
16 | func CreateOrderDao(ctx *transaction.TransactionContext) (*dao.OrderDao, error) { | 16 | func CreateOrderDao(ctx *transaction.TransactionContext) (*dao.OrderDao, error) { |
17 | return dao.NewOrderDao(ctx) | 17 | return dao.NewOrderDao(ctx) |
18 | } | 18 | } |
19 | + | ||
20 | +func CreatePartnerInfoDao(ctx *transaction.TransactionContext) (*dao.PartnerInfoDao, error) { | ||
21 | + return dao.NewPartnerInfoDao(ctx) | ||
22 | +} |
@@ -31,8 +31,8 @@ func OrderDetail(header *protocol.RequestHeader, request *protocol.OrderDetailRe | @@ -31,8 +31,8 @@ func OrderDetail(header *protocol.RequestHeader, request *protocol.OrderDetailRe | ||
31 | var ( | 31 | var ( |
32 | transactionContext, _ = factory.CreateTransactionContext(nil) | 32 | transactionContext, _ = factory.CreateTransactionContext(nil) |
33 | OrderResponsitory, _ = factory.CreateOrderRepository(transactionContext) | 33 | OrderResponsitory, _ = factory.CreateOrderRepository(transactionContext) |
34 | - //PartnerInfoRepository, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) | ||
35 | - order *domain.Order | 34 | + OrderDao, _ = factory.CreateOrderDao(transactionContext) |
35 | + order *domain.Order | ||
36 | ) | 36 | ) |
37 | if err = transactionContext.StartTransaction(); err != nil { | 37 | if err = transactionContext.StartTransaction(); err != nil { |
38 | return nil, err | 38 | return nil, err |
@@ -47,9 +47,6 @@ func OrderDetail(header *protocol.RequestHeader, request *protocol.OrderDetailRe | @@ -47,9 +47,6 @@ func OrderDetail(header *protocol.RequestHeader, request *protocol.OrderDetailRe | ||
47 | if order, err = OrderResponsitory.FindOne(utils.ObjectJsonToMap(request)); err != nil { | 47 | if order, err = OrderResponsitory.FindOne(utils.ObjectJsonToMap(request)); err != nil { |
48 | return | 48 | return |
49 | } | 49 | } |
50 | - //if partner, err = PartnerInfoRepository.FindOne(map[string]interface{}{"partnerId": order.PartnerId}); err != nil { | ||
51 | - // return | ||
52 | - //} | ||
53 | rsp.Order = protocol.OrderDetail{ | 50 | rsp.Order = protocol.OrderDetail{ |
54 | Id: order.Id, | 51 | Id: order.Id, |
55 | OrderNo: order.OrderCode, | 52 | OrderNo: order.OrderCode, |
@@ -65,6 +62,11 @@ func OrderDetail(header *protocol.RequestHeader, request *protocol.OrderDetailRe | @@ -65,6 +62,11 @@ func OrderDetail(header *protocol.RequestHeader, request *protocol.OrderDetailRe | ||
65 | MyDividend: order.OrderTotalBonus(), | 62 | MyDividend: order.OrderTotalBonus(), |
66 | MyDividendPercent: order.PartnerBonusPercent, | 63 | MyDividendPercent: order.PartnerBonusPercent, |
67 | } | 64 | } |
65 | + if header.UserId == order.PartnerId && order.UpdateAt.After(order.LastViewTime) { | ||
66 | + if err = OrderDao.UpdateLastViewTime(order.Id, time.Now()); err != nil { | ||
67 | + return | ||
68 | + } | ||
69 | + } | ||
68 | err = transactionContext.CommitTransaction() | 70 | err = transactionContext.CommitTransaction() |
69 | return | 71 | return |
70 | } | 72 | } |
@@ -2,7 +2,7 @@ package user | @@ -2,7 +2,7 @@ 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/auth" |
5 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/command" | 5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" |
6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query" |
7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service" | 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service" |
8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" |
@@ -61,21 +61,37 @@ func CheckSmsCode(header *protocol.RequestHeader, request *protocol.CheckSmsCode | @@ -61,21 +61,37 @@ func CheckSmsCode(header *protocol.RequestHeader, request *protocol.CheckSmsCode | ||
61 | //修改手机号 | 61 | //修改手机号 |
62 | func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRequest) (rsp *protocol.ChangePhoneResponse, err error) { | 62 | func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRequest) (rsp *protocol.ChangePhoneResponse, err error) { |
63 | var ( | 63 | var ( |
64 | - PartnerInfoService = service.NewPartnerInfoService(nil) | 64 | + PartnerInfoService = service.NewPartnerInfoService(nil) |
65 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
66 | + PartnerInfoDao, _ = factory.CreatePartnerInfoDao(transactionContext) | ||
67 | + partnerInfo *domain.PartnerInfo | ||
65 | ) | 68 | ) |
66 | - if _, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil { | 69 | + if err = transactionContext.StartTransaction(); err != nil { |
70 | + return nil, err | ||
71 | + } | ||
72 | + defer func() { | ||
73 | + if err != nil { | ||
74 | + transactionContext.RollbackTransaction() | ||
75 | + return | ||
76 | + } | ||
77 | + err = transactionContext.CommitTransaction() | ||
78 | + }() | ||
79 | + if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil { | ||
67 | err = protocol.NewErrWithMessage(502, err) //账号不存在 | 80 | err = protocol.NewErrWithMessage(502, err) //账号不存在 |
68 | return | 81 | return |
69 | } | 82 | } |
70 | if _, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Account: request.Phone}); err == nil { | 83 | if _, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Account: request.Phone}); err == nil { |
71 | - err = protocol.NewErrWithMessage(2029, err) //账号不存在 | 84 | + err = protocol.NewErrWithMessage(2029, err) //账号已存在 |
72 | return | 85 | return |
73 | } | 86 | } |
74 | if _, err = auth.CheckSmsCode(request.Phone, request.Captcha); err != nil { | 87 | if _, err = auth.CheckSmsCode(request.Phone, request.Captcha); err != nil { |
75 | log.Error(err) | 88 | log.Error(err) |
76 | return | 89 | return |
77 | } | 90 | } |
78 | - if _, err = PartnerInfoService.UpdatePartnerInfo(&command.UpdatePartnerInfoCommand{Account: request.Phone}); err == nil { | 91 | + if err = PartnerInfoDao.Update(map[string]interface{}{ |
92 | + "Id": partnerInfo.Id, | ||
93 | + "Account": request.Phone, | ||
94 | + }); err != nil { | ||
79 | return | 95 | return |
80 | } | 96 | } |
81 | return | 97 | return |
@@ -84,9 +100,22 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe | @@ -84,9 +100,22 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe | ||
84 | //重置密码 | 100 | //重置密码 |
85 | func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswordRequest) (rsp *protocol.ResetPasswordResponse, err error) { | 101 | func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswordRequest) (rsp *protocol.ResetPasswordResponse, err error) { |
86 | var ( | 102 | var ( |
87 | - PartnerInfoService = service.NewPartnerInfoService(nil) | ||
88 | - partnerInfo *domain.PartnerInfo | 103 | + PartnerInfoService = service.NewPartnerInfoService(nil) |
104 | + partnerInfo *domain.PartnerInfo | ||
105 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
106 | + PartnerInfoDao, _ = factory.CreatePartnerInfoDao(transactionContext) | ||
89 | ) | 107 | ) |
108 | + rsp = &protocol.ResetPasswordResponse{} | ||
109 | + if err = transactionContext.StartTransaction(); err != nil { | ||
110 | + return nil, err | ||
111 | + } | ||
112 | + defer func() { | ||
113 | + if err != nil { | ||
114 | + transactionContext.RollbackTransaction() | ||
115 | + return | ||
116 | + } | ||
117 | + err = transactionContext.CommitTransaction() | ||
118 | + }() | ||
90 | if len(request.NewPwd) < 6 { | 119 | if len(request.NewPwd) < 6 { |
91 | err = protocol.NewErrWithMessage(2027) | 120 | err = protocol.NewErrWithMessage(2027) |
92 | return | 121 | return |
@@ -99,11 +128,14 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo | @@ -99,11 +128,14 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo | ||
99 | err = protocol.NewErrWithMessage(502, err) //账号不存在 | 128 | err = protocol.NewErrWithMessage(502, err) //账号不存在 |
100 | return | 129 | return |
101 | } | 130 | } |
102 | - if _, err = auth.CheckSmsCode(partnerInfo.Account, request.Captcha); err != nil { | ||
103 | - log.Error(err) | ||
104 | - return | ||
105 | - } | ||
106 | - if _, err = PartnerInfoService.UpdatePartnerInfo(&command.UpdatePartnerInfoCommand{Password: request.ConfirmPwd}); err == nil { | 131 | + //if _, err = auth.CheckSmsCode(partnerInfo.Account, request.Captcha); err != nil { |
132 | + // log.Error(err) | ||
133 | + // return | ||
134 | + //} | ||
135 | + if err = PartnerInfoDao.Update(map[string]interface{}{ | ||
136 | + "Id": partnerInfo.Id, | ||
137 | + "Password": request.ConfirmPwd, | ||
138 | + }); err != nil { | ||
107 | return | 139 | return |
108 | } | 140 | } |
109 | return | 141 | return |
@@ -112,9 +144,21 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo | @@ -112,9 +144,21 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo | ||
112 | //修改密码 | 144 | //修改密码 |
113 | func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePasswordRequest) (rsp *protocol.ChangePasswordResponse, err error) { | 145 | func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePasswordRequest) (rsp *protocol.ChangePasswordResponse, err error) { |
114 | var ( | 146 | var ( |
115 | - PartnerInfoService = service.NewPartnerInfoService(nil) | ||
116 | - partnerInfo *domain.PartnerInfo | 147 | + PartnerInfoService = service.NewPartnerInfoService(nil) |
148 | + partnerInfo *domain.PartnerInfo | ||
149 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
150 | + PartnerInfoDao, _ = factory.CreatePartnerInfoDao(transactionContext) | ||
117 | ) | 151 | ) |
152 | + if err = transactionContext.StartTransaction(); err != nil { | ||
153 | + return nil, err | ||
154 | + } | ||
155 | + defer func() { | ||
156 | + if err != nil { | ||
157 | + transactionContext.RollbackTransaction() | ||
158 | + return | ||
159 | + } | ||
160 | + err = transactionContext.CommitTransaction() | ||
161 | + }() | ||
118 | rsp = &protocol.ChangePasswordResponse{} | 162 | rsp = &protocol.ChangePasswordResponse{} |
119 | if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) { | 163 | if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) { |
120 | err = protocol.NewErrWithMessage(2026) | 164 | err = protocol.NewErrWithMessage(2026) |
@@ -137,7 +181,10 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass | @@ -137,7 +181,10 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass | ||
137 | err = protocol.NewErrWithMessage(2028, err) //账号不存在 | 181 | err = protocol.NewErrWithMessage(2028, err) //账号不存在 |
138 | return | 182 | return |
139 | } | 183 | } |
140 | - if _, err = PartnerInfoService.UpdatePartnerInfo(&command.UpdatePartnerInfoCommand{Password: request.ConfirmPwd}); err == nil { | 184 | + if err = PartnerInfoDao.Update(map[string]interface{}{ |
185 | + "Id": partnerInfo.Id, | ||
186 | + "Password": request.ConfirmPwd, | ||
187 | + }); err != nil { | ||
141 | return | 188 | return |
142 | } | 189 | } |
143 | return | 190 | return |
1 | -package dao | ||
2 | - | ||
3 | -//import ( | ||
4 | -// "fmt" | ||
5 | -// "github.com/go-pg/pg/v10" | ||
6 | -// pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
7 | -// "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
8 | -// "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models" | ||
9 | -// "time" | ||
10 | -//) | ||
11 | -// | ||
12 | -//type EmployeeDao struct { | ||
13 | -// transactionContext *pgTransaction.TransactionContext | ||
14 | -//} | ||
15 | -// | ||
16 | -//func (dao *EmployeeDao) BatchRemove(uids []int64) error { | ||
17 | -// tx := dao.transactionContext.PgTx | ||
18 | -// _, err := tx.QueryOne( | ||
19 | -// pg.Scan(), | ||
20 | -// "DELETE FROM employees WHERE uid IN (?)", | ||
21 | -// pg.In(uids)) | ||
22 | -// return err | ||
23 | -//} | ||
24 | -// | ||
25 | -//func (dao *EmployeeDao) BatchSetStatus(uids []int64, status int) error { | ||
26 | -// tx := dao.transactionContext.PgTx | ||
27 | -// _, err := tx.QueryOne( | ||
28 | -// pg.Scan(), | ||
29 | -// "UPDATE employees SET status=? WHERE uid IN (?)", | ||
30 | -// status, pg.In(uids)) | ||
31 | -// return err | ||
32 | -//} | ||
33 | -// | ||
34 | -//func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string) error { | ||
35 | -// tx := dao.transactionContext.PgTx | ||
36 | -// if _, err := tx.Query( | ||
37 | -// pg.Scan(), | ||
38 | -// "UPDATE employees SET is_principal=? WHERE company_id=?", | ||
39 | -// false, companyId); err != nil { | ||
40 | -// return err | ||
41 | -// } | ||
42 | -// if _, err := tx.QueryOne( | ||
43 | -// pg.Scan(), | ||
44 | -// "UPDATE employees SET is_principal=? WHERE company_id=? AND employee_account=?", | ||
45 | -// true, companyId, employeeAccount); err != nil { | ||
46 | -// return err | ||
47 | -// } | ||
48 | -// return nil | ||
49 | -//} | ||
50 | -// | ||
51 | -//func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error { | ||
52 | -// tx := dao.transactionContext.PgTx | ||
53 | -// _, err := tx.QueryOne( | ||
54 | -// pg.Scan(), | ||
55 | -// "UPDATE employees SET su_money=su_money+? WHERE uid=?", | ||
56 | -// suMoney, uid) | ||
57 | -// return err | ||
58 | -//} | ||
59 | -// | ||
60 | -//func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string]int, error) { | ||
61 | -// var unReadSystemNotification int | ||
62 | -// var unReadInteractionNotification int | ||
63 | -// tx := dao.transactionContext.PgTx | ||
64 | -// sentNotificationModel := new(models.SentNotification) | ||
65 | -// if count, err := tx.Model(sentNotificationModel).Relation("Notification"). | ||
66 | -// Where(`sent_notification.receiver @> '{"uid":?}'`, uid). | ||
67 | -// Where("notification.notification_type = ?", domain.NOTIFICATION_TYPE_SYSTEM). | ||
68 | -// Where("sent_notification.is_read = ?", false). | ||
69 | -// Count(); err != nil { | ||
70 | -// return nil, err | ||
71 | -// } else { | ||
72 | -// unReadSystemNotification = count | ||
73 | -// } | ||
74 | -// if count, err := tx.Model(sentNotificationModel).Relation("Notification"). | ||
75 | -// Where(`sent_notification.receiver @> '{"uid":?}'`, uid). | ||
76 | -// Where("notification.notification_type = ?", domain.NOTIFICATION_TYPE_INTERACTION). | ||
77 | -// Where("sent_notification.is_read = ?", false). | ||
78 | -// Count(); err != nil { | ||
79 | -// return nil, err | ||
80 | -// } else { | ||
81 | -// unReadInteractionNotification = count | ||
82 | -// } | ||
83 | -// return map[string]int{ | ||
84 | -// "unReadSystemNotification": unReadSystemNotification, | ||
85 | -// "unReadInteractionNotification": unReadInteractionNotification, | ||
86 | -// }, nil | ||
87 | -//} | ||
88 | -// | ||
89 | -//func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{}, error) { | ||
90 | -// var incomeSuMoney float64 | ||
91 | -// var incomeSuMoneyOfYesterday float64 | ||
92 | -// tx := dao.transactionContext.PgTx | ||
93 | -// suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) | ||
94 | -// yesterday := time.Now().AddDate(0, 0, -1) | ||
95 | -// if err := tx.Model(suMoneyTransactionRecordModel). | ||
96 | -// ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). | ||
97 | -// Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). | ||
98 | -// Where(`su_money_transaction_record.record_type = ?`, 2). | ||
99 | -// Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())). | ||
100 | -// Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())). | ||
101 | -// Select(&incomeSuMoneyOfYesterday); err != nil { | ||
102 | -// return nil, err | ||
103 | -// } | ||
104 | -// if err := tx.Model(suMoneyTransactionRecordModel). | ||
105 | -// ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). | ||
106 | -// Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). | ||
107 | -// Where(`su_money_transaction_record.record_type = ?`, 2). | ||
108 | -// Select(&incomeSuMoney); err != nil { | ||
109 | -// return nil, err | ||
110 | -// } | ||
111 | -// return map[string]interface{}{ | ||
112 | -// "incomeSuMoney": incomeSuMoney, | ||
113 | -// "incomeSuMoneyOfYesterday": incomeSuMoneyOfYesterday, | ||
114 | -// }, nil | ||
115 | -//} | ||
116 | -// | ||
117 | -//func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) { | ||
118 | -// var incomeSuMoney float64 | ||
119 | -// var expendSuMoney float64 | ||
120 | -// tx := dao.transactionContext.PgTx | ||
121 | -// suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) | ||
122 | -// if err := tx.Model(suMoneyTransactionRecordModel). | ||
123 | -// ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). | ||
124 | -// Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). | ||
125 | -// Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). | ||
126 | -// Where(`su_money_transaction_record.create_time > ?`, transactionStartTime). | ||
127 | -// Where(`su_money_transaction_record.create_time < ?`, transactionEndTime). | ||
128 | -// Select(&incomeSuMoney); err != nil { | ||
129 | -// return nil, err | ||
130 | -// } | ||
131 | -// if err := tx.Model(suMoneyTransactionRecordModel). | ||
132 | -// ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money"). | ||
133 | -// Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). | ||
134 | -// Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4})). | ||
135 | -// Where(`su_money_transaction_record.create_time > ?`, transactionStartTime). | ||
136 | -// Where(`su_money_transaction_record.create_time < ?`, transactionEndTime). | ||
137 | -// Select(&expendSuMoney); err != nil { | ||
138 | -// return nil, err | ||
139 | -// } | ||
140 | -// return map[string]interface{}{ | ||
141 | -// "incomeSuMoney": incomeSuMoney, | ||
142 | -// "expendSuMoney": expendSuMoney, | ||
143 | -// }, nil | ||
144 | -//} | ||
145 | -// | ||
146 | -//func NewEmployeeDao(transactionContext *pgTransaction.TransactionContext) (*EmployeeDao, error) { | ||
147 | -// if transactionContext == nil { | ||
148 | -// return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
149 | -// } else { | ||
150 | -// return &EmployeeDao{ | ||
151 | -// transactionContext: transactionContext, | ||
152 | -// }, nil | ||
153 | -// } | ||
154 | -//} |
@@ -12,6 +12,7 @@ type OrderDao struct { | @@ -12,6 +12,7 @@ type OrderDao struct { | ||
12 | transactionContext *transaction.TransactionContext | 12 | transactionContext *transaction.TransactionContext |
13 | } | 13 | } |
14 | 14 | ||
15 | +//订单统计 | ||
15 | func (dao *OrderDao) OrderStatics(option *domain.OrderStaticQuery) (count int, amount float64, err error) { | 16 | func (dao *OrderDao) OrderStatics(option *domain.OrderStaticQuery) (count int, amount float64, err error) { |
16 | tx := dao.transactionContext.PgTx | 17 | tx := dao.transactionContext.PgTx |
17 | order := new(models.Order) | 18 | order := new(models.Order) |
@@ -44,17 +45,17 @@ func (dao *OrderDao) DividendOrders(option *domain.DividendOrdersQueryOption) (c | @@ -44,17 +45,17 @@ func (dao *OrderDao) DividendOrders(option *domain.DividendOrdersQueryOption) (c | ||
44 | q.Column(`order.id`, `order.order_code`, `order.order_actual_amount`, `order.partner_bonus_percent`) | 45 | q.Column(`order.id`, `order.order_code`, `order.order_actual_amount`, `order.partner_bonus_percent`) |
45 | q.Where(`"order".order_status >=?`, domain.OrderStatusDeliverSome) //已经发货 | 46 | q.Where(`"order".order_status >=?`, domain.OrderStatusDeliverSome) //已经发货 |
46 | if option.StartTime > 0 { | 47 | if option.StartTime > 0 { |
47 | - q.Where(`"order".delivery_time >=?`, time.Unix(option.StartTime/1000, 0)) | 48 | + q.Where(`"order".create_at >=?`, time.Unix(option.StartTime/1000, 0)) |
48 | } | 49 | } |
49 | if option.EndTime > 0 { | 50 | if option.EndTime > 0 { |
50 | - q.Where(`"order".delivery_time <?`, time.Unix(option.EndTime/1000, 0)) | 51 | + q.Where(`"order".create_at <?`, time.Unix(option.EndTime/1000, 0)) |
51 | } | 52 | } |
52 | if option.DividendAction == 0 { //累计分红 | 53 | if option.DividendAction == 0 { //累计分红 |
53 | if option.DetailAction == 0 { //已收明细 | 54 | if option.DetailAction == 0 { //已收明细 |
54 | q.Join(`JOIN order_payment as a ON a.order_id="order".id`) | 55 | q.Join(`JOIN order_payment as a ON a.order_id="order".id`) |
55 | q.Where(`"a".bonus_status=?`, domain.BonusPaid) | 56 | q.Where(`"a".bonus_status=?`, domain.BonusPaid) |
56 | } else if option.DetailAction == 1 { //未收明细 | 57 | } else if option.DetailAction == 1 { //未收明细 |
57 | - q.Where(`"order".order_actual_amount>"order".order_payment_amount`, domain.BonusWaitPay) | 58 | + q.Where(`"order".order_actual_amount>"order".order_payment_amount`) |
58 | } | 59 | } |
59 | } else if option.DividendAction == 1 { //分红支出 | 60 | } else if option.DividendAction == 1 { //分红支出 |
60 | q.Where(`"order".order_amount>"order".order_actual_amount`) | 61 | q.Where(`"order".order_amount>"order".order_actual_amount`) |
@@ -69,6 +70,15 @@ func (dao *OrderDao) DividendOrders(option *domain.DividendOrdersQueryOption) (c | @@ -69,6 +70,15 @@ func (dao *OrderDao) DividendOrders(option *domain.DividendOrdersQueryOption) (c | ||
69 | return | 70 | return |
70 | } | 71 | } |
71 | 72 | ||
73 | +func (dao *OrderDao) UpdateLastViewTime(id int64, lastViewTime time.Time) (err error) { | ||
74 | + tx := dao.transactionContext.PgTx | ||
75 | + order := new(models.Order) | ||
76 | + q := tx.Model(order).Set("last_view_time = ?", lastViewTime) | ||
77 | + q.Where("id=?", id) | ||
78 | + _, err = q.Update() | ||
79 | + return | ||
80 | +} | ||
81 | + | ||
72 | func NewOrderDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) { | 82 | func NewOrderDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) { |
73 | if transactionContext == nil { | 83 | if transactionContext == nil { |
74 | return nil, fmt.Errorf("transactionContext参数不能为nil") | 84 | return nil, fmt.Errorf("transactionContext参数不能为nil") |
pkg/infrastructure/dao/pg_partner_dao.go
0 → 100644
1 | +package dao | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
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 PartnerInfoDao struct { | ||
11 | + transactionContext *transaction.TransactionContext | ||
12 | +} | ||
13 | + | ||
14 | +func (dao *PartnerInfoDao) Update(queryOptions map[string]interface{}) error { | ||
15 | + tx := dao.transactionContext.PgTx | ||
16 | + m := new(models.PartnerInfo) | ||
17 | + query := NewQuery(tx.Model(m), queryOptions) | ||
18 | + query.SetUpdate(`account=?`, "Account") | ||
19 | + query.SetUpdate(`password=?`, "Password") | ||
20 | + query.SetWhere(`id=?`, "Id") | ||
21 | + if _, ok := queryOptions["Id"]; !ok { | ||
22 | + return fmt.Errorf(`error: miss param "Id"`) | ||
23 | + } | ||
24 | + _, err := query.Update() | ||
25 | + return err | ||
26 | +} | ||
27 | + | ||
28 | +func NewPartnerInfoDao(transactionContext *transaction.TransactionContext) (*PartnerInfoDao, error) { | ||
29 | + if transactionContext == nil { | ||
30 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
31 | + } else { | ||
32 | + return &PartnerInfoDao{ | ||
33 | + transactionContext: transactionContext, | ||
34 | + }, nil | ||
35 | + } | ||
36 | +} |
@@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | 4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" |
5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" |
6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" |
7 | + . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
7 | ) | 8 | ) |
8 | 9 | ||
9 | type AdminUserRepository struct { | 10 | type AdminUserRepository struct { |
@@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | 4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" |
5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" |
6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" |
7 | + . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
7 | ) | 8 | ) |
8 | 9 | ||
9 | type OrderPaymentRepository struct { | 10 | type OrderPaymentRepository struct { |
@@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | 4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" |
5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" |
6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" |
7 | + . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
7 | ) | 8 | ) |
8 | 9 | ||
9 | type OrderRepository struct { | 10 | type OrderRepository struct { |
@@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | 4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" |
5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" |
6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" |
7 | + . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
7 | ) | 8 | ) |
8 | 9 | ||
9 | type PartnerInfoRepository struct { | 10 | type PartnerInfoRepository struct { |
1 | package repository | 1 | package repository |
2 | 2 | ||
3 | -import ( | ||
4 | - "bytes" | ||
5 | - "encoding/gob" | ||
6 | - "fmt" | ||
7 | - "github.com/go-pg/pg/v10/orm" | ||
8 | - "github.com/linmadan/egglib-go/utils/snowflake" | ||
9 | - "strconv" | ||
10 | - "time" | ||
11 | -) | ||
12 | - | ||
13 | -var ( | ||
14 | - ERR_EMPTY_TC = fmt.Errorf("transactionContext参数不能为nil") | ||
15 | -) | ||
16 | - | ||
17 | -type Query struct { | ||
18 | - *orm.Query | ||
19 | - queryOptions map[string]interface{} | ||
20 | - AffectRow int | ||
21 | -} | ||
22 | - | ||
23 | -func NewQuery(query *orm.Query, queryOptions map[string]interface{}) *Query { | ||
24 | - return &Query{ | ||
25 | - query, | ||
26 | - queryOptions, | ||
27 | - 0, | ||
28 | - } | ||
29 | -} | ||
30 | - | ||
31 | -func (query *Query) SetWhere(condition, key string) *Query { | ||
32 | - if v, ok := query.queryOptions[key]; ok { | ||
33 | - if t, e := time.Parse(time.RFC3339, fmt.Sprintf("%v", v)); e == nil { | ||
34 | - if t.IsZero() { | ||
35 | - return query | ||
36 | - } | ||
37 | - } | ||
38 | - query.Where(condition, v) | ||
39 | - } | ||
40 | - return query | ||
41 | -} | ||
42 | - | ||
43 | -func (query *Query) SetLimit() *Query { | ||
44 | - if offset, ok := query.queryOptions["offset"]; ok { | ||
45 | - offset, _ := strconv.ParseInt(fmt.Sprintf("%v", offset), 10, 64) | ||
46 | - if offset > -1 { | ||
47 | - query.Offset(int(offset)) | ||
48 | - } | ||
49 | - } else { | ||
50 | - query.Offset(0) | ||
51 | - } | ||
52 | - if limit, ok := query.queryOptions["limit"]; ok { | ||
53 | - limit, _ := strconv.ParseInt(fmt.Sprintf("%v", limit), 10, 64) | ||
54 | - if limit > -1 { | ||
55 | - query.Limit(int(limit)) | ||
56 | - } else { | ||
57 | - query.Limit(20) | ||
58 | - } | ||
59 | - } | ||
60 | - return query | ||
61 | -} | ||
62 | - | ||
63 | -func (query *Query) SetOrder(orderColumn string, key string) *Query { | ||
64 | - //query.Order(condition...) | ||
65 | - //return query | ||
66 | - if v, ok := query.queryOptions[key]; ok { | ||
67 | - query.Order(fmt.Sprintf("%v %v", orderColumn, v)) | ||
68 | - } | ||
69 | - return query | ||
70 | -} | ||
71 | - | ||
72 | -func (query *Query) HandleError(err error, errMsg string) error { | ||
73 | - if err.Error() == "pg: no rows in result set" { | ||
74 | - return fmt.Errorf(errMsg) | ||
75 | - } else { | ||
76 | - return err | ||
77 | - } | ||
78 | -} | ||
79 | - | ||
80 | -func NewSnowflakeId() (int64, error) { | ||
81 | - IdWorker, err := snowflake.NewIdWorker(2) | ||
82 | - if err != nil { | ||
83 | - return 0, err | ||
84 | - } | ||
85 | - id, err := IdWorker.NextId() | ||
86 | - return id, err | ||
87 | -} | ||
88 | - | ||
89 | -//GobModelTransform 模型转换 | ||
90 | -func GobModelTransform(dst interface{}, src interface{}) error { | ||
91 | - var data bytes.Buffer | ||
92 | - enc := gob.NewEncoder(&data) | ||
93 | - if err := enc.Encode(src); err != nil { | ||
94 | - return err | ||
95 | - } | ||
96 | - dec := gob.NewDecoder(&data) | ||
97 | - if err := dec.Decode(dst); err != nil { | ||
98 | - return err | ||
99 | - } | ||
100 | - return nil | ||
101 | -} | 3 | +//import ( |
4 | +// "bytes" | ||
5 | +// "encoding/gob" | ||
6 | +// "fmt" | ||
7 | +// "github.com/go-pg/pg/v10/orm" | ||
8 | +// "github.com/linmadan/egglib-go/utils/snowflake" | ||
9 | +// "strconv" | ||
10 | +// "time" | ||
11 | +//) | ||
12 | +// | ||
13 | +//var ( | ||
14 | +// ERR_EMPTY_TC = fmt.Errorf("transactionContext参数不能为nil") | ||
15 | +//) | ||
16 | +// | ||
17 | +//type Query struct { | ||
18 | +// *orm.Query | ||
19 | +// queryOptions map[string]interface{} | ||
20 | +// AffectRow int | ||
21 | +//} | ||
22 | +// | ||
23 | +//func NewQuery(query *orm.Query, queryOptions map[string]interface{}) *Query { | ||
24 | +// return &Query{ | ||
25 | +// query, | ||
26 | +// queryOptions, | ||
27 | +// 0, | ||
28 | +// } | ||
29 | +//} | ||
30 | +// | ||
31 | +//func (query *Query) SetWhere(condition, key string) *Query { | ||
32 | +// if v, ok := query.queryOptions[key]; ok { | ||
33 | +// if t, e := time.Parse(time.RFC3339, fmt.Sprintf("%v", v)); e == nil { | ||
34 | +// if t.IsZero() { | ||
35 | +// return query | ||
36 | +// } | ||
37 | +// } | ||
38 | +// query.Where(condition, v) | ||
39 | +// } | ||
40 | +// return query | ||
41 | +//} | ||
42 | +// | ||
43 | +//func (query *Query) SetLimit() *Query { | ||
44 | +// if offset, ok := query.queryOptions["offset"]; ok { | ||
45 | +// offset, _ := strconv.ParseInt(fmt.Sprintf("%v", offset), 10, 64) | ||
46 | +// if offset > -1 { | ||
47 | +// query.Offset(int(offset)) | ||
48 | +// } | ||
49 | +// } else { | ||
50 | +// query.Offset(0) | ||
51 | +// } | ||
52 | +// if limit, ok := query.queryOptions["limit"]; ok { | ||
53 | +// limit, _ := strconv.ParseInt(fmt.Sprintf("%v", limit), 10, 64) | ||
54 | +// if limit > -1 { | ||
55 | +// query.Limit(int(limit)) | ||
56 | +// } else { | ||
57 | +// query.Limit(20) | ||
58 | +// } | ||
59 | +// } | ||
60 | +// return query | ||
61 | +//} | ||
62 | +// | ||
63 | +//func (query *Query) SetOrder(orderColumn string, key string) *Query { | ||
64 | +// //query.Order(condition...) | ||
65 | +// //return query | ||
66 | +// if v, ok := query.queryOptions[key]; ok { | ||
67 | +// query.Order(fmt.Sprintf("%v %v", orderColumn, v)) | ||
68 | +// } | ||
69 | +// return query | ||
70 | +//} | ||
71 | +// | ||
72 | +//func (query *Query) HandleError(err error, errMsg string) error { | ||
73 | +// if err.Error() == "pg: no rows in result set" { | ||
74 | +// return fmt.Errorf(errMsg) | ||
75 | +// } else { | ||
76 | +// return err | ||
77 | +// } | ||
78 | +//} | ||
79 | +// | ||
80 | +//func NewSnowflakeId() (int64, error) { | ||
81 | +// IdWorker, err := snowflake.NewIdWorker(2) | ||
82 | +// if err != nil { | ||
83 | +// return 0, err | ||
84 | +// } | ||
85 | +// id, err := IdWorker.NextId() | ||
86 | +// return id, err | ||
87 | +//} | ||
88 | +// | ||
89 | +////GobModelTransform 模型转换 | ||
90 | +//func GobModelTransform(dst interface{}, src interface{}) error { | ||
91 | +// var data bytes.Buffer | ||
92 | +// enc := gob.NewEncoder(&data) | ||
93 | +// if err := enc.Encode(src); err != nil { | ||
94 | +// return err | ||
95 | +// } | ||
96 | +// dec := gob.NewDecoder(&data) | ||
97 | +// if err := dec.Decode(dst); err != nil { | ||
98 | +// return err | ||
99 | +// } | ||
100 | +// return nil | ||
101 | +//} |
@@ -3,6 +3,8 @@ package utils | @@ -3,6 +3,8 @@ package utils | ||
3 | import ( | 3 | import ( |
4 | "github.com/shopspring/decimal" | 4 | "github.com/shopspring/decimal" |
5 | "math" | 5 | "math" |
6 | + "math/rand" | ||
7 | + "time" | ||
6 | ) | 8 | ) |
7 | 9 | ||
8 | func decimal1(value float64) float64 { | 10 | func decimal1(value float64) float64 { |
@@ -23,3 +25,9 @@ func Decimal(value float64) float64 { | @@ -23,3 +25,9 @@ func Decimal(value float64) float64 { | ||
23 | func DecimalToNumber(value float64) float64 { | 25 | func DecimalToNumber(value float64) float64 { |
24 | return Round(value, 2) | 26 | return Round(value, 2) |
25 | } | 27 | } |
28 | + | ||
29 | +func GenerateRangeNum(min, max int) int { | ||
30 | + rand.Seed(time.Now().Unix()) | ||
31 | + randNum := rand.Intn(max-min) + min | ||
32 | + return randNum | ||
33 | +} |
pkg/infrastructure/utils/sql.go
0 → 100644
1 | +package utils | ||
2 | + | ||
3 | +import ( | ||
4 | + "bytes" | ||
5 | + "encoding/gob" | ||
6 | + "fmt" | ||
7 | + "github.com/go-pg/pg/v10/orm" | ||
8 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
9 | + "strconv" | ||
10 | + "time" | ||
11 | +) | ||
12 | + | ||
13 | +var ( | ||
14 | + ERR_EMPTY_TC = fmt.Errorf("transactionContext参数不能为nil") | ||
15 | +) | ||
16 | + | ||
17 | +type Query struct { | ||
18 | + *orm.Query | ||
19 | + queryOptions map[string]interface{} | ||
20 | + AffectRow int | ||
21 | +} | ||
22 | + | ||
23 | +func NewQuery(query *orm.Query, queryOptions map[string]interface{}) *Query { | ||
24 | + return &Query{ | ||
25 | + query, | ||
26 | + queryOptions, | ||
27 | + 0, | ||
28 | + } | ||
29 | +} | ||
30 | + | ||
31 | +func (query *Query) SetWhere(condition, key string) *Query { | ||
32 | + if v, ok := query.queryOptions[key]; ok { | ||
33 | + if t, e := time.Parse(time.RFC3339, fmt.Sprintf("%v", v)); e == nil { | ||
34 | + if t.IsZero() { | ||
35 | + return query | ||
36 | + } | ||
37 | + } | ||
38 | + query.Where(condition, v) | ||
39 | + } | ||
40 | + return query | ||
41 | +} | ||
42 | + | ||
43 | +func (query *Query) SetUpdate(condition, key string) *Query { | ||
44 | + if v, ok := query.queryOptions[key]; ok { | ||
45 | + query.Set(condition, v) | ||
46 | + } | ||
47 | + return query | ||
48 | +} | ||
49 | + | ||
50 | +func (query *Query) SetLimit() *Query { | ||
51 | + if offset, ok := query.queryOptions["offset"]; ok { | ||
52 | + offset, _ := strconv.ParseInt(fmt.Sprintf("%v", offset), 10, 64) | ||
53 | + if offset > -1 { | ||
54 | + query.Offset(int(offset)) | ||
55 | + } | ||
56 | + } else { | ||
57 | + query.Offset(0) | ||
58 | + } | ||
59 | + if limit, ok := query.queryOptions["limit"]; ok { | ||
60 | + limit, _ := strconv.ParseInt(fmt.Sprintf("%v", limit), 10, 64) | ||
61 | + if limit > -1 { | ||
62 | + query.Limit(int(limit)) | ||
63 | + } else { | ||
64 | + query.Limit(20) | ||
65 | + } | ||
66 | + } | ||
67 | + return query | ||
68 | +} | ||
69 | + | ||
70 | +func (query *Query) SetOrder(orderColumn string, key string) *Query { | ||
71 | + //query.Order(condition...) | ||
72 | + //return query | ||
73 | + if v, ok := query.queryOptions[key]; ok { | ||
74 | + query.Order(fmt.Sprintf("%v %v", orderColumn, v)) | ||
75 | + } | ||
76 | + return query | ||
77 | +} | ||
78 | + | ||
79 | +func (query *Query) HandleError(err error, errMsg string) error { | ||
80 | + if err.Error() == "pg: no rows in result set" { | ||
81 | + return fmt.Errorf(errMsg) | ||
82 | + } else { | ||
83 | + return err | ||
84 | + } | ||
85 | +} | ||
86 | + | ||
87 | +func NewSnowflakeId() (int64, error) { | ||
88 | + IdWorker, err := snowflake.NewIdWorker(2) | ||
89 | + if err != nil { | ||
90 | + return 0, err | ||
91 | + } | ||
92 | + id, err := IdWorker.NextId() | ||
93 | + return id, err | ||
94 | +} | ||
95 | + | ||
96 | +//GobModelTransform 模型转换 | ||
97 | +func GobModelTransform(dst interface{}, src interface{}) error { | ||
98 | + var data bytes.Buffer | ||
99 | + enc := gob.NewEncoder(&data) | ||
100 | + if err := enc.Encode(src); err != nil { | ||
101 | + return err | ||
102 | + } | ||
103 | + dec := gob.NewDecoder(&data) | ||
104 | + if err := dec.Decode(dst); err != nil { | ||
105 | + return err | ||
106 | + } | ||
107 | + return nil | ||
108 | +} |
@@ -3,6 +3,7 @@ package controllers | @@ -3,6 +3,7 @@ package controllers | ||
3 | import ( | 3 | import ( |
4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/auth" | 4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/auth" |
5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" |
6 | + "time" | ||
6 | ) | 7 | ) |
7 | 8 | ||
8 | type AuthController struct { | 9 | type AuthController struct { |
@@ -127,3 +128,25 @@ func (this *AuthController) UpdateDevice() { | @@ -127,3 +128,25 @@ func (this *AuthController) UpdateDevice() { | ||
127 | //header := controllers.GetRequestHeader(this.Ctx) | 128 | //header := controllers.GetRequestHeader(this.Ctx) |
128 | //msg = protocol.NewReturnResponse(auth.UpdateDevice(header, request)) | 129 | //msg = protocol.NewReturnResponse(auth.UpdateDevice(header, request)) |
129 | } | 130 | } |
131 | + | ||
132 | +//AuthCheckSmsCode 验证手机号码(修改手机号码、重置密码的前一步) | ||
133 | +//@router /checkSmsCod [post] | ||
134 | +func (this *AuthController) AuthCheckSmsCode() { | ||
135 | + var msg *protocol.ResponseMessage | ||
136 | + defer func() { | ||
137 | + this.Resp(msg) | ||
138 | + }() | ||
139 | + var request *protocol.AuthCheckSmsCodeRequest | ||
140 | + if err := this.JsonUnmarshal(&request); err != nil { | ||
141 | + msg = protocol.BadRequestParam(1) | ||
142 | + return | ||
143 | + } | ||
144 | + if b, m := this.Valid(request); !b { | ||
145 | + msg = m | ||
146 | + return | ||
147 | + } | ||
148 | + header := this.GetRequestHeader(this.Ctx) | ||
149 | + rsp, err := auth.AuthCheckSmsCode(header, request) | ||
150 | + err = CacheSms.Put(request.Phone, rsp.CaptchaCertificate, 5*time.Minute) | ||
151 | + msg = protocol.NewReturnResponse(rsp, err) | ||
152 | +} |
@@ -3,6 +3,7 @@ package controllers | @@ -3,6 +3,7 @@ package controllers | ||
3 | import ( | 3 | import ( |
4 | "encoding/json" | 4 | "encoding/json" |
5 | "github.com/astaxie/beego" | 5 | "github.com/astaxie/beego" |
6 | + "github.com/astaxie/beego/cache" | ||
6 | "github.com/astaxie/beego/context" | 7 | "github.com/astaxie/beego/context" |
7 | "github.com/astaxie/beego/validation" | 8 | "github.com/astaxie/beego/validation" |
8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | 9 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" |
@@ -10,6 +11,9 @@ import ( | @@ -10,6 +11,9 @@ import ( | ||
10 | "strconv" | 11 | "strconv" |
11 | ) | 12 | ) |
12 | 13 | ||
14 | +//缓存 | ||
15 | +var CacheSms = cache.NewMemoryCache() | ||
16 | + | ||
13 | type BaseController struct { | 17 | type BaseController struct { |
14 | beego.Controller | 18 | beego.Controller |
15 | } | 19 | } |
1 | package controllers | 1 | package controllers |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/user" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/user" |
5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" |
7 | + "strings" | ||
6 | ) | 8 | ) |
7 | 9 | ||
8 | type UserController struct { | 10 | type UserController struct { |
@@ -65,6 +67,17 @@ func (this *UserController) ChangePhone() { | @@ -65,6 +67,17 @@ func (this *UserController) ChangePhone() { | ||
65 | msg = m | 67 | msg = m |
66 | return | 68 | return |
67 | } | 69 | } |
70 | + if !CacheSms.IsExist(request.OldPhone) { | ||
71 | + msg = protocol.NewMesage(1009) //验证码失效 | ||
72 | + return | ||
73 | + } | ||
74 | + if v := CacheSms.Get(request.OldPhone); v != nil { | ||
75 | + if !strings.EqualFold(fmt.Sprintf("%v", v), strings.TrimSpace(request.CaptchaCertificate)) { | ||
76 | + msg = protocol.NewMesage(1012) //验证码不一致 | ||
77 | + return | ||
78 | + } | ||
79 | + CacheSms.Delete(request.OldPhone) | ||
80 | + } | ||
68 | header := this.GetRequestHeader(this.Ctx) | 81 | header := this.GetRequestHeader(this.Ctx) |
69 | msg = protocol.NewReturnResponse(user.ChangePhone(header, request)) | 82 | msg = protocol.NewReturnResponse(user.ChangePhone(header, request)) |
70 | } | 83 | } |
@@ -85,6 +98,17 @@ func (this *UserController) ResetPassword() { | @@ -85,6 +98,17 @@ func (this *UserController) ResetPassword() { | ||
85 | msg = m | 98 | msg = m |
86 | return | 99 | return |
87 | } | 100 | } |
101 | + if !CacheSms.IsExist(request.Phone) { | ||
102 | + msg = protocol.NewMesage(1009) //验证码失效 | ||
103 | + return | ||
104 | + } | ||
105 | + if v := CacheSms.Get(request.Phone); v != nil { | ||
106 | + if !strings.EqualFold(fmt.Sprintf("%v", v), strings.TrimSpace(request.CaptchaCertificate)) { | ||
107 | + msg = protocol.NewMesage(1012) //验证码不一致 | ||
108 | + return | ||
109 | + } | ||
110 | + CacheSms.Delete(request.Phone) | ||
111 | + } | ||
88 | header := this.GetRequestHeader(this.Ctx) | 112 | header := this.GetRequestHeader(this.Ctx) |
89 | msg = protocol.NewReturnResponse(user.ResetPassword(header, request)) | 113 | msg = protocol.NewReturnResponse(user.ResetPassword(header, request)) |
90 | } | 114 | } |
@@ -15,6 +15,7 @@ func init() { | @@ -15,6 +15,7 @@ func init() { | ||
15 | nsV1.Router("auth/refreshToken", &controllers.AuthController{}, "Post:RefreshToken") | 15 | nsV1.Router("auth/refreshToken", &controllers.AuthController{}, "Post:RefreshToken") |
16 | nsV1.Router("auth/revoke", &controllers.AuthController{}, "Post:Revoke") | 16 | nsV1.Router("auth/revoke", &controllers.AuthController{}, "Post:Revoke") |
17 | nsV1.Router("auth/updateDevice", &controllers.AuthController{}, "Post:UpdateDevice") | 17 | nsV1.Router("auth/updateDevice", &controllers.AuthController{}, "Post:UpdateDevice") |
18 | + nsV1.Router("auth/checkSmsCod", &controllers.AuthController{}, "Post:AuthCheckSmsCode") | ||
18 | 19 | ||
19 | nsV1.Router("user/userInfo", &controllers.UserController{}, "Post:UserInfo") | 20 | nsV1.Router("user/userInfo", &controllers.UserController{}, "Post:UserInfo") |
20 | nsV1.Router("user/checkSmsCode", &controllers.UserController{}, "Post:CheckSmsCode") | 21 | nsV1.Router("user/checkSmsCode", &controllers.UserController{}, "Post:CheckSmsCode") |
@@ -78,3 +78,12 @@ type RevokeRequest struct { | @@ -78,3 +78,12 @@ type RevokeRequest struct { | ||
78 | } | 78 | } |
79 | type RevokeResponse struct { | 79 | type RevokeResponse struct { |
80 | } | 80 | } |
81 | + | ||
82 | +/*AuthCheckSmsCode */ | ||
83 | +type AuthCheckSmsCodeRequest struct { | ||
84 | + Phone string `json:"phone" valid:"Required;"` | ||
85 | + Captcha string `json:"captcha" valid:"Required;"` | ||
86 | +} | ||
87 | +type AuthCheckSmsCodeResponse struct { | ||
88 | + CaptchaCertificate string `json:"captchaCertificate"` //短信验证码通过凭证 | ||
89 | +} |
@@ -46,15 +46,21 @@ type CheckSmsCodeResponse struct { | @@ -46,15 +46,21 @@ type CheckSmsCodeResponse struct { | ||
46 | type ChangePhoneRequest struct { | 46 | type ChangePhoneRequest struct { |
47 | Phone string `json:"phone" valid:"Mobile"` | 47 | Phone string `json:"phone" valid:"Mobile"` |
48 | Captcha string `json:"captcha" valid:"Required"` | 48 | Captcha string `json:"captcha" valid:"Required"` |
49 | + | ||
50 | + OldPhone string `json:"oldPhone" valid:"Required"` | ||
51 | + CaptchaCertificate string `json:"captchaCertificate" valid:"Required"` | ||
49 | } | 52 | } |
50 | type ChangePhoneResponse struct { | 53 | type ChangePhoneResponse struct { |
51 | } | 54 | } |
52 | 55 | ||
53 | /*ResetPassword */ | 56 | /*ResetPassword */ |
54 | type ResetPasswordRequest struct { | 57 | type ResetPasswordRequest struct { |
55 | - Captcha string `json:"captcha" valid:"Required"` | 58 | + //Captcha string `json:"captcha" valid:"Required"` |
56 | NewPwd string `json:"newPwd" valid:"Required"` | 59 | NewPwd string `json:"newPwd" valid:"Required"` |
57 | ConfirmPwd string `json:"confirmPwd" valid:"Required"` | 60 | ConfirmPwd string `json:"confirmPwd" valid:"Required"` |
61 | + | ||
62 | + Phone string `json:"phone" valid:"Required"` | ||
63 | + CaptchaCertificate string `json:"captchaCertificate" valid:"Required"` | ||
58 | } | 64 | } |
59 | type ResetPasswordResponse struct { | 65 | type ResetPasswordResponse struct { |
60 | } | 66 | } |
-
请 注册 或 登录 后发表评论