2b19937065
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
228 lines
5.8 KiB
Go
228 lines
5.8 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/pkg/validate"
|
|
order "lone-services/rpc/order/pb"
|
|
sale "lone-services/rpc/sale/pb"
|
|
"lone-services/rpc/store/pb"
|
|
user "lone-services/rpc/user/pb"
|
|
"lone-services/services/store/internal/dao"
|
|
"lone-services/services/store/internal/model"
|
|
"lone-services/services/store/internal/svc"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type ApplyVerifyStatusLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewApplyVerifyStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApplyVerifyStatusLogic {
|
|
return &ApplyVerifyStatusLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *ApplyVerifyStatusLogic) ApplyVerifyStatus(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": {
|
|
strconv.Itoa(utils.StatusAdminFirstVerify),
|
|
strconv.Itoa(utils.StatusAdminSecondVerify)}},
|
|
Eq: map[string]string{"id": strconv.FormatInt(in.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)
|
|
}
|
|
action := utils.ActionAdd{
|
|
OldContent: info,
|
|
Type: utils.LogActionTypeEdit,
|
|
ModuleName: utils.LogActionModuleStore,
|
|
}
|
|
info.Reason = in.Reason
|
|
info.AdminId = adminInfo.ID
|
|
info.AdminName = adminInfo.Name
|
|
|
|
status := utils.StatusOk
|
|
if info.Status == utils.StatusAdminFirstVerify {
|
|
status = utils.StatusAdminSecondVerify
|
|
}
|
|
content := "已通过。"
|
|
if in.Status != utils.StatusOk {
|
|
status = utils.StatusAdminSecondRefuse
|
|
content = "未通过。理由为: " + in.Reason
|
|
}
|
|
|
|
content = "门店 '" + info.Name + "'审核: " + content
|
|
if status != utils.StatusOk {
|
|
info.Status = int32(status)
|
|
info.AdminId = adminInfo.ID
|
|
info.AdminName = adminInfo.Name
|
|
info.Reason = in.Reason
|
|
_, err = modelObj.Edit(w, &info)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.Fail)
|
|
}
|
|
|
|
svc.WeCom(in.Status, utils.StoreFirstReview, info.Id, info.Reason)
|
|
action.NewContent = info
|
|
utils.SetActionLog(adminInfo, action)
|
|
return l.ok(utils.NumberOne)
|
|
}
|
|
|
|
modelObj.Begin()
|
|
if status == utils.StatusOk {
|
|
var newData dao.StoreNewCreate
|
|
if utils.JsonStringToStruct(info.NewContent, &newData) {
|
|
newData.Status = int32(status)
|
|
newData.NewContent = utils.StringEmpty
|
|
newData.Id = info.Id
|
|
groupId, sErr := l.getSaleInfo(newData.SaleId)
|
|
if sErr != utils.Ok {
|
|
modelObj.Rollback()
|
|
return l.fail(sErr)
|
|
}
|
|
if groupId < utils.NumberOne {
|
|
modelObj.Rollback()
|
|
return l.fail(utils.ErrorNotFund)
|
|
}
|
|
|
|
newData.GroupId = groupId
|
|
|
|
_, err = modelObj.Edit(w, &newData)
|
|
if err != nil {
|
|
modelObj.Rollback()
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.Fail)
|
|
}
|
|
|
|
if newData.SaleId != info.SaleId {
|
|
sErr = l.setAddressSaleInfo(newData)
|
|
if sErr != utils.Ok {
|
|
modelObj.Rollback()
|
|
return l.fail(sErr)
|
|
}
|
|
}
|
|
|
|
if newData.UserMobile != info.UserMobile && newData.UserName != info.UserName {
|
|
uErr := l.updateUser(newData)
|
|
if uErr != utils.Ok {
|
|
modelObj.Rollback()
|
|
return l.fail(uErr)
|
|
}
|
|
}
|
|
} else {
|
|
modelObj.Rollback()
|
|
return l.fail(utils.ErrorFormatDataError)
|
|
}
|
|
}
|
|
|
|
reason := utils.StringEmpty
|
|
if in.Reason != utils.StringEmpty {
|
|
reason = in.Reason
|
|
}
|
|
svc.WeCom(in.Status, utils.StoreSecondReview, info.Id, reason)
|
|
|
|
modelObj.Commit()
|
|
action.NewContent = info
|
|
utils.SetActionLog(adminInfo, action)
|
|
return l.ok(utils.NumberOne)
|
|
}
|
|
|
|
func (l *ApplyVerifyStatusLogic) getSaleInfo(id int64) (int64, utils.Status) {
|
|
cli, err := svc.GetRpcClient(l.svcCtx.SaleName)
|
|
if err != nil {
|
|
logx.Errorf("get order err: %v", err)
|
|
return utils.NumberZero, utils.ErrorInternalServer
|
|
}
|
|
|
|
client := sale.NewSaleClient(cli.Conn())
|
|
w := sale.InfoReq{Id: id}
|
|
info, err := client.InfoInternal(context.Background(), &w)
|
|
if err != nil {
|
|
logx.Errorf("get order err: %v", err)
|
|
return utils.NumberZero, utils.ErrorInternalServer
|
|
}
|
|
return info.GroupId, utils.Ok
|
|
}
|
|
|
|
func (l *ApplyVerifyStatusLogic) setAddressSaleInfo(info dao.StoreNewCreate) utils.Status {
|
|
cli, err := svc.GetRpcClient(l.svcCtx.OrderName)
|
|
if err != nil {
|
|
logx.Errorf("get address err: %v", err)
|
|
return utils.ErrorInternalServer
|
|
}
|
|
|
|
client := order.NewOrderClient(cli.Conn())
|
|
data := order.UpdateAddressSaleInfoRequest{
|
|
Id: info.Id,
|
|
SaleId: info.SaleId,
|
|
GroupId: info.GroupId,
|
|
}
|
|
_, err = client.UpdateAddressSaleInfo(context.Background(), &data)
|
|
if err != nil {
|
|
logx.Errorf("get address err: %v", err)
|
|
return utils.ErrorInternalServer
|
|
}
|
|
return utils.Ok
|
|
}
|
|
|
|
func (l *ApplyVerifyStatusLogic) updateUser(info dao.StoreNewCreate) 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
|
|
}
|