store and chore
CI / changes (push) Successful in 39s
CI / ad (push) Successful in 1s
CI / admin (push) Successful in 0s
CI / bff (push) Successful in 25s
CI / chore (push) Successful in 24s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 1s
CI / factory (push) Successful in 0s
CI / payment (push) Successful in 0s
CI / product (push) Successful in 1s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 24s
CI / task (push) Successful in 0s
CI / user (push) Successful in 0s
CI / wecom (push) Successful in 0s
CI / changes (push) Successful in 39s
CI / ad (push) Successful in 1s
CI / admin (push) Successful in 0s
CI / bff (push) Successful in 25s
CI / chore (push) Successful in 24s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 1s
CI / factory (push) Successful in 0s
CI / payment (push) Successful in 0s
CI / product (push) Successful in 1s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 24s
CI / task (push) Successful in 0s
CI / user (push) Successful in 0s
CI / wecom (push) Successful in 0s
This commit is contained in:
@@ -2,6 +2,16 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
chore "lone-services/rpc/chore/pb"
|
||||
user "lone-services/rpc/user/pb"
|
||||
"lone-services/services/store/internal/dao"
|
||||
"lone-services/services/store/internal/model"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"lone-services/rpc/store/pb"
|
||||
"lone-services/services/store/internal/svc"
|
||||
@@ -25,7 +35,152 @@ func NewVerifyStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Veri
|
||||
}
|
||||
|
||||
func (l *VerifyStatusLogic) VerifyStatus(in *store.StatusRequest) (*store.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
var v validate.StatusValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
|
||||
return &store.Response{}, nil
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
|
||||
var info dao.StoreStatus
|
||||
w := modelbase.Params{
|
||||
In: map[string][]string{"status": {utils.StatusFailString, strconv.Itoa(utils.StatusWaitPass)}},
|
||||
Eq: map[string]string{"id": strconv.FormatInt(v.Id, utils.NumberTen)}}
|
||||
modelObj := model.StoreModel{}.Init()
|
||||
err := modelObj.GetOne(w, &info)
|
||||
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if info.Status < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
|
||||
info.Status = v.Status
|
||||
info.Reason = v.Reason
|
||||
info.AdminId = adminInfo.ID
|
||||
info.AdminName = adminInfo.Name
|
||||
|
||||
status := utils.StatusOk
|
||||
content := "已通过。"
|
||||
if v.Status != utils.StatusOk {
|
||||
status = utils.StatusFail
|
||||
content = "未通过。理由为: " + v.Reason
|
||||
}
|
||||
|
||||
content = "门店 '" + info.Name + "'审核: " + content
|
||||
|
||||
salt := utils.GetRandString(utils.NumberFive)
|
||||
oldPwd := utils.RandString(utils.NumberEight)
|
||||
pwd := fmt.Sprintf("%s%s", salt, oldPwd)
|
||||
pwd, _ = utils.EncryptPassword(pwd)
|
||||
|
||||
modelObj.Begin()
|
||||
_, err = modelObj.Edit(w, &info)
|
||||
if err != nil {
|
||||
modelObj.Rollback()
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
//TODO 更新登录密码
|
||||
//login := dao.LoginStatusPassword{
|
||||
// Salt: salt,
|
||||
// Password: pwd,
|
||||
// Status: status,
|
||||
// AdminId: u.Id,
|
||||
// AdminName: u.Name,
|
||||
//}
|
||||
//ww := modelbase.Params{Eq: map[string]string{"obj_id": strconv.Itoa(int(v.Id)), "type": strconv.Itoa(dao.TypeStore)}}
|
||||
//_, err = model.LoginModel{}.Init().Edit(ww, &login)
|
||||
//if err != nil {
|
||||
// modelObj.Rollback()
|
||||
// l.Logger.Error(err)
|
||||
// return l.fail(utils.Fail)
|
||||
//}
|
||||
|
||||
if status == utils.StatusOk {
|
||||
mobile, cErr := utils.DecryptPhone(info.UserMobile)
|
||||
if cErr == nil {
|
||||
l.sendPassword(mobile, oldPwd)
|
||||
}
|
||||
|
||||
//mobile, cErr := utils.Crypto{}.AESDecryptECB(info.UserMobile)
|
||||
//if cErr == nil {
|
||||
//result := utils.SendPwdSMS(mobile, oldPwd)
|
||||
//jsonStr, err := json.Marshal(result)
|
||||
//if err == nil {
|
||||
// SmsLogService{}.Add(string(jsonStr))
|
||||
// if result.Code != utils.NumberZero {
|
||||
// modelObj.Rollback()
|
||||
// return l.fail(utils.Fail)
|
||||
// }
|
||||
//}
|
||||
//}
|
||||
}
|
||||
|
||||
//TODO 站内消息
|
||||
//mErr := MessageService{}.Add(dao.TargetTypeAgent, dao.ObjTypeStore, status, info.SaleId, info.Id, content)
|
||||
//if mErr != nil {
|
||||
// model.Rollback()
|
||||
// return mErr
|
||||
//}
|
||||
modelObj.Commit()
|
||||
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
|
||||
func (l *VerifyStatusLogic) updateUserPwd(info dao.StoreCreate) utils.Status {
|
||||
cli, err := svc.GetRpcClient(l.svcCtx.OrderName)
|
||||
if err != nil {
|
||||
logx.Errorf("get user err: %v", err)
|
||||
return utils.ErrorInternalServer
|
||||
}
|
||||
|
||||
client := user.NewUserClient(cli.Conn())
|
||||
|
||||
mobile, sErr := utils.EncryptPhone(info.UserMobile)
|
||||
if sErr != nil {
|
||||
return utils.ErrorEncryptAesError
|
||||
}
|
||||
data := user.InternalUpdateReq{
|
||||
BizId: info.Id,
|
||||
SubjectType: dao.UserTypeName,
|
||||
Mobile: mobile,
|
||||
Name: info.UserName,
|
||||
ClientCode: strings.Split(info.StoreType, utils.DecollatorComma), //哪端
|
||||
CredentialType: []string{dao.LoginTypePassword, dao.LoginTypeSms},
|
||||
Identifier: mobile, //手机号
|
||||
}
|
||||
_, err = client.InternalUpdate(context.Background(), &data)
|
||||
if err != nil {
|
||||
logx.Errorf("get order err: %v", err)
|
||||
return utils.ErrorInternalServer
|
||||
}
|
||||
|
||||
return utils.Ok
|
||||
}
|
||||
|
||||
func (l *VerifyStatusLogic) sendPassword(mobile, password string) utils.Status {
|
||||
cli, err := svc.GetRpcClient(l.svcCtx.ChoreName)
|
||||
if err != nil {
|
||||
logx.Errorf("get user err: %v", err)
|
||||
return utils.ErrorInternalServer
|
||||
}
|
||||
|
||||
client := chore.NewChoreClient(cli.Conn())
|
||||
|
||||
_, err = client.SendPassword(context.Background(), &chore.SendPasswordReq{
|
||||
Mobile: mobile,
|
||||
Password: password,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Errorf("get order err: %v", err)
|
||||
return utils.ErrorInternalServer
|
||||
}
|
||||
|
||||
return utils.Ok
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user