214 lines
5.4 KiB
Go
214 lines
5.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/pkg/validate"
|
|
chore "lone-services/rpc/chore/pb"
|
|
message "lone-services/rpc/message/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"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type VerifyStatusLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewVerifyStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VerifyStatusLogic {
|
|
return &VerifyStatusLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *VerifyStatusLogic) VerifyStatus(in *store.StatusRequest) (*store.Response, error) {
|
|
var v validate.StatusValidator
|
|
if fail := l.checkParams(in, &v); fail != nil {
|
|
return fail, 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)
|
|
// }
|
|
//}
|
|
//}
|
|
}
|
|
|
|
l.message(utils.NumberOne, utils.NumberTwo, int32(status), info.SaleId, info.Id, content)
|
|
|
|
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 order 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 chore 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 chore err: %v", err)
|
|
return utils.ErrorInternalServer
|
|
}
|
|
|
|
return utils.Ok
|
|
}
|
|
|
|
func (l *VerifyStatusLogic) message(targetType, Type, typeStatus int32, targetId, objId int64, content string) {
|
|
//TargetTypeAgent uint8 = 1 //代理
|
|
//TargetTypeStore uint8 = 2 //门店
|
|
//TargetTypeUser uint8 = 3 //个人
|
|
//// 类型
|
|
//ObjTypeAgent uint8 = 1 //添加代理
|
|
//ObjTypeStore uint8 = 2 //加门店
|
|
//ObjTypeSupply uint8 = 3 //审核补货
|
|
cli, err := svc.GetRpcClient(l.svcCtx.MessageName)
|
|
if err != nil {
|
|
logx.Errorf("get message err: %v", err)
|
|
return
|
|
}
|
|
|
|
client := message.NewMessageClient(cli.Conn())
|
|
|
|
_, err = client.MessageAdd(context.Background(), &message.AddRequest{
|
|
Content: content,
|
|
TargetType: targetType,
|
|
TargetId: targetId,
|
|
TypeStatus: typeStatus,
|
|
Type: Type,
|
|
ObjId: objId,
|
|
})
|
|
if err != nil {
|
|
logx.Errorf("get message err: %v", err)
|
|
return
|
|
}
|
|
}
|