86 lines
2.0 KiB
Go
86 lines
2.0 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/rpc/order/pb"
|
|
"lone-services/services/order/internal/dao"
|
|
"lone-services/services/order/internal/model"
|
|
"lone-services/services/order/internal/svc"
|
|
"lone-services/services/order/validator"
|
|
"strconv"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type WebCartEditLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewWebCartEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebCartEditLogic {
|
|
return &WebCartEditLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *WebCartEditLogic) WebCartEdit(in *order.EditCartRequest) (*order.Response, error) {
|
|
var v validator.CartEditValidator
|
|
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.Cart
|
|
w := modelbase.Params{
|
|
Eq: map[string]string{
|
|
"type": strconv.Itoa(int(in.Type)),
|
|
},
|
|
}
|
|
switch in.Type {
|
|
case dao.CartTypeSale:
|
|
w.Eq["sale_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
|
case dao.CartTypeUser:
|
|
w.Eq["user_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
|
case dao.CartTypeStore:
|
|
w.Eq["store_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
|
}
|
|
|
|
mobileObj := model.CartModel{}.Init()
|
|
err := mobileObj.GetOne(w, &info)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.ErrorNotFund)
|
|
}
|
|
|
|
info.Content = in.Info
|
|
info.Type = int8(in.Type)
|
|
switch in.Type {
|
|
case dao.CartTypeSale:
|
|
info.SaleId = adminInfo.ID
|
|
case dao.CartTypeUser:
|
|
info.UserId = adminInfo.ID
|
|
case dao.CartTypeStore:
|
|
info.StoreId = adminInfo.ID
|
|
}
|
|
|
|
if info.Id < utils.NumberOne {
|
|
err = mobileObj.Create(&info)
|
|
} else {
|
|
_, err = mobileObj.Edit(w, &info)
|
|
}
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.Fail)
|
|
}
|
|
|
|
return l.ok(utils.NumberOne)
|
|
}
|