address add bystoreid api
This commit is contained in:
@@ -23,7 +23,7 @@ const (
|
||||
|
||||
type OrderCreate struct {
|
||||
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
OrderSn string `gorm:"column:ordersn;type:varchar(100);comment:订单号;NOT NULL" json:"ordersn"`
|
||||
OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"`
|
||||
StoreId int `gorm:"column:store_id;type:int(11);comment:美容院关联ID号" json:"store_id"`
|
||||
StoreName string `gorm:"column:store_name;type:varchar(50);comment:门店名" json:"store_name"`
|
||||
SaleName string `gorm:"column:sale_name;type:varchar(50);comment:销售姓名" json:"sale_name"`
|
||||
|
||||
@@ -4,7 +4,7 @@ import "lone-services/pkg/utils"
|
||||
|
||||
type OrderProductCreate struct {
|
||||
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
Ordersn string `gorm:"column:ordersn;type:varchar(100);comment:订单号;NOT NULL" json:"ordersn"`
|
||||
OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"`
|
||||
ProductId int `gorm:"column:product_id;type:int(11);comment:产品ID;NOT NULL" json:"product_id"`
|
||||
ProductName string `gorm:"column:product_name;type:varchar(255);comment:产品名;NOT NULL" json:"product_name"`
|
||||
Price float64 `gorm:"column:price;type:decimal(10,2);comment:产品单价格;NOT NULL" json:"price"`
|
||||
@@ -15,7 +15,7 @@ type OrderProductCreate struct {
|
||||
|
||||
type OrderProductInfo struct {
|
||||
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
Ordersn string `gorm:"column:ordersn;type:varchar(100);comment:订单号;NOT NULL" json:"ordersn"`
|
||||
OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"`
|
||||
ProductId int `gorm:"column:product_id;type:int(11);comment:产品ID;NOT NULL" json:"product_id"`
|
||||
ProductName string `gorm:"column:product_name;type:varchar(255);comment:产品名;NOT NULL" json:"product_name"`
|
||||
Price float64 `gorm:"column:price;type:decimal(10,2);comment:产品单价格;NOT NULL" json:"price"`
|
||||
@@ -36,7 +36,7 @@ type OrderProductPay struct {
|
||||
|
||||
type OrderProducts struct {
|
||||
Id int `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
OrderSn string `gorm:"column:ordersn;type:varchar(100);comment:订单号;NOT NULL" json:"ordersn"`
|
||||
OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"`
|
||||
ProductId int `gorm:"column:product_id;type:int(11);comment:产品ID;NOT NULL" json:"product_id"`
|
||||
ProductName string `gorm:"column:product_name;type:varchar(255);comment:产品名;NOT NULL" json:"product_name"`
|
||||
Price float32 `gorm:"column:price;type:decimal(10,2);comment:产品单价格;NOT NULL" json:"price"`
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/order/internal/dao"
|
||||
"lone-services/services/order/internal/model"
|
||||
"lone-services/services/order/validator"
|
||||
"strconv"
|
||||
|
||||
"lone-services/rpc/order/pb"
|
||||
"lone-services/services/order/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddressByStoreLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewAddressByStoreLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddressByStoreLogic {
|
||||
return &AddressByStoreLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AddressByStoreLogic) AddressByStore(in *order.AddressByStoreItemsRequest) (*order.Response, error) {
|
||||
var v validator.AddressByStoreItemsValidator
|
||||
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.Address
|
||||
w := modelbase.Params{
|
||||
Order: "id desc",
|
||||
Eq: map[string]string{
|
||||
"target_id": strconv.FormatInt(in.StoreId, utils.NumberTen),
|
||||
"type": strconv.Itoa(dao.AddressTypeStore),
|
||||
"status": utils.StringStatusOk,
|
||||
},
|
||||
}
|
||||
|
||||
err := model.AddressModel{}.Init().Items(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
for key, v := range info {
|
||||
mobile, aErr := utils.DecryptPhone(v.Mobile)
|
||||
if aErr == nil {
|
||||
info[key].AesMobile = v.Mobile
|
||||
info[key].Mobile = utils.DecryptPhoneReplace(mobile)
|
||||
}
|
||||
}
|
||||
return l.ok(info)
|
||||
}
|
||||
@@ -38,6 +38,10 @@ func (l *BaseLogic) out(status utils.Status, msg string) (*order.Response, error
|
||||
return &order.Response{Code: status.Code, Msg: msg}, nil
|
||||
}
|
||||
|
||||
func (l *BaseLogic) outData(status utils.Status, msg, data string) (*order.Response, error) {
|
||||
return &order.Response{Code: status.Code, Msg: msg, Data: data}, nil
|
||||
}
|
||||
|
||||
func (l *BaseLogic) ok(data any) (*order.Response, error) {
|
||||
buf, _ := jsoniter.Marshal(data)
|
||||
return &order.Response{Code: utils.Ok.Code, Msg: utils.Ok.Msg, Data: string(buf)}, nil
|
||||
|
||||
@@ -66,7 +66,7 @@ func (l *WebCreateLogic) WebCreate(in *order.CreateOrderRequest) (*order.Respons
|
||||
DistrictIds: address.DistrictIds,
|
||||
}
|
||||
|
||||
w = modelbase.Params{
|
||||
ww := modelbase.Params{
|
||||
Eq: map[string]string{
|
||||
"type": strconv.Itoa(int(in.Type)),
|
||||
},
|
||||
@@ -78,14 +78,14 @@ func (l *WebCreateLogic) WebCreate(in *order.CreateOrderRequest) (*order.Respons
|
||||
data.SaleName = adminInfo.Name
|
||||
data.CreateType = dao.OrderTypeSale
|
||||
data.Type = dao.OrderTypeSale
|
||||
w.Eq["sale_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
||||
ww.Eq["sale_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
||||
orderSn = svc.GetOrderSn(strconv.Itoa(dao.OrderTypeSale), adminInfo.ID)
|
||||
case dao.CartTypeUser:
|
||||
data.UserId = int(adminInfo.ID)
|
||||
data.UserName = adminInfo.Name
|
||||
data.CreateType = dao.OrderTypePersonal
|
||||
data.Type = dao.OrderTypePersonal
|
||||
w.Eq["user_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
||||
ww.Eq["user_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
||||
orderSn = svc.GetOrderSn(strconv.Itoa(dao.OrderTypePersonal), adminInfo.ID)
|
||||
case dao.CartTypeStore:
|
||||
data.StoreId = int(adminInfo.ID)
|
||||
@@ -96,13 +96,15 @@ func (l *WebCreateLogic) WebCreate(in *order.CreateOrderRequest) (*order.Respons
|
||||
data.SaleProvince = int(adminInfo.SaleProvince)
|
||||
data.CreateType = dao.OrderTypeStore
|
||||
data.Type = dao.OrderTypeStore
|
||||
w.Eq["store_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
||||
ww.Eq["store_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
||||
orderSn = svc.GetOrderSn(strconv.Itoa(dao.OrderTypeStore), adminInfo.ID)
|
||||
}
|
||||
data.OrderSn = orderSn
|
||||
|
||||
var cart dao.Cart
|
||||
err = model.CartModel{}.Init().GetOne(w, &address)
|
||||
|
||||
err = model.CartModel{}.Init().GetOne(ww, &cart)
|
||||
l.Logger.Error(cart)
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
@@ -114,20 +116,40 @@ func (l *WebCreateLogic) WebCreate(in *order.CreateOrderRequest) (*order.Respons
|
||||
if pErr != utils.Ok {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
products, pErr := svc.GetCartData(ids)
|
||||
products, pErr := svc.GetCartData(l.svcCtx.ProductSvcName, ids)
|
||||
if pErr != utils.Ok {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
keys := make([]string, utils.NumberZero, len(products))
|
||||
keys := make([]string, utils.NumberZero, len(products.Items))
|
||||
var totalPrice float64
|
||||
for _, item := range products {
|
||||
keys = append(keys, strconv.Itoa(int(item.Id)))
|
||||
totalPrice += item.Price * float64(item.Number)
|
||||
errData := make(map[int64]int64)
|
||||
productItems := []dao.OrderProductCreate{}
|
||||
for _, item := range products.Items {
|
||||
if buyNum, ok := ids[item.Id]; ok {
|
||||
if buyNum > int64(item.Number) {
|
||||
errData[item.Id] = int64(item.Number)
|
||||
return l.out(utils.Fail,
|
||||
item.Name+"购买数量超出库存,目前可以够买:"+strconv.Itoa(int(item.Number)))
|
||||
} else {
|
||||
keys = append(keys, strconv.Itoa(int(item.Id)))
|
||||
totalPrice += item.Price * float64(buyNum)
|
||||
productItems = append(productItems, dao.OrderProductCreate{
|
||||
OrderSn: data.OrderSn,
|
||||
ProductId: int(item.Id),
|
||||
ProductName: item.Name,
|
||||
Price: item.Price,
|
||||
Number: int(buyNum),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(keys) < utils.NumberOne {
|
||||
return l.out(utils.Fail, "购买信息不存在")
|
||||
}
|
||||
data.ProductIds = strings.Join(keys, utils.DecollatorComma)
|
||||
data.TotalPrice = totalPrice
|
||||
|
||||
mobileObj := model.OrderModel{}.Init()
|
||||
|
||||
mobileObj.Begin()
|
||||
err = mobileObj.Create(&data)
|
||||
if err != nil {
|
||||
@@ -135,38 +157,35 @@ func (l *WebCreateLogic) WebCreate(in *order.CreateOrderRequest) (*order.Respons
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
for _, item := range products {
|
||||
orderProduct := dao.OrderProductCreate{
|
||||
Ordersn: data.OrderSn,
|
||||
ProductId: int(item.Id),
|
||||
ProductName: item.Name,
|
||||
Price: item.Price,
|
||||
Number: item.Number,
|
||||
}
|
||||
err = model.OrderProductModel{}.Init().Create(&orderProduct)
|
||||
for _, item := range productItems {
|
||||
err = model.OrderProductModel{}.Init().Create(&item)
|
||||
if err != nil {
|
||||
mobileObj.Rollback()
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
_, err = model.CartModel{}.Init().Del(w, &cart)
|
||||
if err != nil {
|
||||
mobileObj.Rollback()
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
//TODO 扣除库存
|
||||
//$decrease = Product::decrease(
|
||||
//['id' => $item['id'], ['number', '>=', $item['number']]],
|
||||
//'number',
|
||||
//$item['number']
|
||||
//);
|
||||
//if ($decrease < 1) {
|
||||
//Order::rollBack();
|
||||
//$retData['code'] = Code::code('low_stocks');
|
||||
//$retData['data'] = [$item['id'] => Product::value(['id' => $item['id']], 'number')];
|
||||
//return $retData;
|
||||
}
|
||||
|
||||
_, err = model.CartModel{}.Init().Del(ww, &cart)
|
||||
if err != nil {
|
||||
mobileObj.Rollback()
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
//TODO 扣库存接口
|
||||
//cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName)
|
||||
//if err != nil {
|
||||
// mobileObj.Rollback()
|
||||
// return l.fail(utils.Fail)
|
||||
//}
|
||||
|
||||
//productClient := product.NewProductClient(cli.Conn())
|
||||
//_, err = productClient.Number(l.ctx, &product.NumberReq{Id: item.Id, Type: utils.NumberOne, Number: buyNum})
|
||||
//if err != nil {
|
||||
// mobileObj.Rollback()
|
||||
// logx.Errorf("get products err: %v", err)
|
||||
// return l.fail(utils.Fail, "产品库存不足")
|
||||
//}
|
||||
|
||||
mobileObj.Commit()
|
||||
|
||||
return l.ok(utils.NumberOne)
|
||||
|
||||
@@ -2,9 +2,15 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/rpc/order/pb"
|
||||
product "lone-services/rpc/product/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"
|
||||
)
|
||||
@@ -13,6 +19,7 @@ type WebCreateOneLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewWebCreateOneLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebCreateOneLogic {
|
||||
@@ -24,7 +31,129 @@ func NewWebCreateOneLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebC
|
||||
}
|
||||
|
||||
func (l *WebCreateOneLogic) WebCreateOne(in *order.CreateOrderOneRequest) (*order.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
var v validator.OrderOneCreateValidator
|
||||
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)
|
||||
}
|
||||
|
||||
return &order.Response{}, nil
|
||||
w := modelbase.Params{
|
||||
Eq: map[string]string{
|
||||
"id": strconv.FormatInt(in.AddressId, utils.NumberTen),
|
||||
"type": strconv.Itoa(int(in.Type)),
|
||||
"target_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen),
|
||||
},
|
||||
}
|
||||
var address dao.Address
|
||||
err := model.AddressModel{}.Init().GetOne(w, &address)
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if address.Id < utils.NumberOne {
|
||||
return l.out(utils.Fail, "地址不存在")
|
||||
}
|
||||
|
||||
data := dao.OrderCreate{
|
||||
Note: in.Note,
|
||||
ExpiredTime: utils.GetAfterMinutes(utils.NumberThirty),
|
||||
Mobile: address.Mobile,
|
||||
Address: address.Address,
|
||||
Addressee: address.Name,
|
||||
DistrictIds: address.DistrictIds,
|
||||
}
|
||||
|
||||
ww := modelbase.Params{
|
||||
Eq: map[string]string{
|
||||
"type": strconv.Itoa(int(in.Type)),
|
||||
},
|
||||
}
|
||||
var orderSn string
|
||||
switch in.Type {
|
||||
case dao.CartTypeSale:
|
||||
data.SaleId = int(adminInfo.ID)
|
||||
data.SaleName = adminInfo.Name
|
||||
data.CreateType = dao.OrderTypeSale
|
||||
data.Type = dao.OrderTypeSale
|
||||
ww.Eq["sale_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
||||
orderSn = svc.GetOrderSn(strconv.Itoa(dao.OrderTypeSale), adminInfo.ID)
|
||||
case dao.CartTypeUser:
|
||||
data.UserId = int(adminInfo.ID)
|
||||
data.UserName = adminInfo.Name
|
||||
data.CreateType = dao.OrderTypePersonal
|
||||
data.Type = dao.OrderTypePersonal
|
||||
ww.Eq["user_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
||||
orderSn = svc.GetOrderSn(strconv.Itoa(dao.OrderTypePersonal), adminInfo.ID)
|
||||
case dao.CartTypeStore:
|
||||
data.StoreId = int(adminInfo.ID)
|
||||
data.StoreName = adminInfo.Name
|
||||
data.SaleId = int(adminInfo.SaleId)
|
||||
data.GroupId = int(adminInfo.GroupId)
|
||||
data.SaleMobile = adminInfo.SaleMobile
|
||||
data.SaleProvince = int(adminInfo.SaleProvince)
|
||||
data.CreateType = dao.OrderTypeStore
|
||||
data.Type = dao.OrderTypeStore
|
||||
ww.Eq["store_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
||||
orderSn = svc.GetOrderSn(strconv.Itoa(dao.OrderTypeStore), adminInfo.ID)
|
||||
}
|
||||
data.OrderSn = orderSn
|
||||
|
||||
productInfo, pErr := svc.GetOneData(l.svcCtx.ProductSvcName, in.ProductId)
|
||||
if pErr != utils.Ok {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if productInfo.Id != in.ProductId {
|
||||
return l.out(utils.Fail, "购买信息不存在")
|
||||
}
|
||||
|
||||
if uint32(in.Num) > productInfo.Number {
|
||||
return l.out(utils.Fail,
|
||||
productInfo.Name+"购买数量超出库存,目前可以够买:"+strconv.Itoa(int(in.Num)))
|
||||
}
|
||||
|
||||
orderProduct := dao.OrderProductCreate{
|
||||
OrderSn: data.OrderSn,
|
||||
ProductId: int(in.ProductId),
|
||||
ProductName: productInfo.Name,
|
||||
Price: productInfo.Price,
|
||||
Number: int(in.Num),
|
||||
}
|
||||
|
||||
data.ProductIds = strconv.FormatInt(in.ProductId, utils.NumberTen)
|
||||
data.TotalPrice = float64(in.Num) * productInfo.Price
|
||||
mobileObj := model.OrderModel{}.Init()
|
||||
|
||||
mobileObj.Begin()
|
||||
err = mobileObj.Create(&data)
|
||||
if err != nil {
|
||||
mobileObj.Rollback()
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
err = model.OrderProductModel{}.Init().Create(&orderProduct)
|
||||
if err != nil {
|
||||
mobileObj.Rollback()
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName)
|
||||
if err != nil {
|
||||
mobileObj.Rollback()
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
productClient := product.NewProductClient(cli.Conn())
|
||||
_, err = productClient.Number(l.ctx, &product.NumberReq{Id: in.ProductId, Type: utils.NumberOne, Number: uint32(in.Num)})
|
||||
if err != nil {
|
||||
mobileObj.Rollback()
|
||||
logx.Errorf("get products err: %v", err)
|
||||
return l.out(utils.Fail,
|
||||
productInfo.Name+"购买数量超出库存,目前可以够买:"+strconv.Itoa(int(in.Num)))
|
||||
}
|
||||
|
||||
mobileObj.Commit()
|
||||
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.2
|
||||
// Source: order.proto
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/rpc/order/pb"
|
||||
"lone-services/services/order/internal/logic"
|
||||
"lone-services/services/order/internal/svc"
|
||||
)
|
||||
|
||||
type OrderServer struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
order.UnimplementedOrderServer
|
||||
}
|
||||
|
||||
func NewOrderServer(svcCtx *svc.ServiceContext) *OrderServer {
|
||||
return &OrderServer{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *OrderServer) Items(ctx context.Context, in *order.OrderItemsRequest) (*order.Response, error) {
|
||||
l := logic.NewItemsLogic(ctx, s.svcCtx)
|
||||
return l.Items(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) WebCreate(ctx context.Context, in *order.CreateOrderRequest) (*order.Response, error) {
|
||||
l := logic.NewWebCreateLogic(ctx, s.svcCtx)
|
||||
return l.WebCreate(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) WebCreateOne(ctx context.Context, in *order.CreateOrderOneRequest) (*order.Response, error) {
|
||||
l := logic.NewWebCreateOneLogic(ctx, s.svcCtx)
|
||||
return l.WebCreateOne(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) WebAddressCreate(ctx context.Context, in *order.EditAddressRequest) (*order.Response, error) {
|
||||
l := logic.NewWebAddressCreateLogic(ctx, s.svcCtx)
|
||||
return l.WebAddressCreate(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) WebAddressEdit(ctx context.Context, in *order.EditAddressRequest) (*order.Response, error) {
|
||||
l := logic.NewWebAddressEditLogic(ctx, s.svcCtx)
|
||||
return l.WebAddressEdit(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) WebAddressDel(ctx context.Context, in *order.IdAndTypeRequest) (*order.Response, error) {
|
||||
l := logic.NewWebAddressDelLogic(ctx, s.svcCtx)
|
||||
return l.WebAddressDel(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) WebAddressDef(ctx context.Context, in *order.IdAndTypeRequest) (*order.Response, error) {
|
||||
l := logic.NewWebAddressDefLogic(ctx, s.svcCtx)
|
||||
return l.WebAddressDef(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) WebAddressInfo(ctx context.Context, in *order.IdAndTypeRequest) (*order.Response, error) {
|
||||
l := logic.NewWebAddressInfoLogic(ctx, s.svcCtx)
|
||||
return l.WebAddressInfo(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) WebAddressItems(ctx context.Context, in *order.TypeRequest) (*order.Response, error) {
|
||||
l := logic.NewWebAddressItemsLogic(ctx, s.svcCtx)
|
||||
return l.WebAddressItems(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) WebCart(ctx context.Context, in *order.CartRequest) (*order.Response, error) {
|
||||
l := logic.NewWebCartLogic(ctx, s.svcCtx)
|
||||
return l.WebCart(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) WebCartEdit(ctx context.Context, in *order.EditCartRequest) (*order.Response, error) {
|
||||
l := logic.NewWebCartEditLogic(ctx, s.svcCtx)
|
||||
return l.WebCartEdit(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) AddressItem(ctx context.Context, in *order.AddressItemsRequest) (*order.Response, error) {
|
||||
l := logic.NewAddressItemLogic(ctx, s.svcCtx)
|
||||
return l.AddressItem(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) AddressByStore(ctx context.Context, in *order.AddressByStoreItemsRequest) (*order.Response, error) {
|
||||
l := logic.NewAddressByStoreLogic(ctx, s.svcCtx)
|
||||
return l.AddressByStore(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) OrderAuditingItems(ctx context.Context, in *order.OrderAuditingItemsRequest) (*order.Response, error) {
|
||||
l := logic.NewOrderAuditingItemsLogic(ctx, s.svcCtx)
|
||||
return l.OrderAuditingItems(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) OrderAuditing(ctx context.Context, in *order.OrderAuditingRequest) (*order.Response, error) {
|
||||
l := logic.NewOrderAuditingLogic(ctx, s.svcCtx)
|
||||
return l.OrderAuditing(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) OrderCreate(ctx context.Context, in *order.AdminCreateOrderRequest) (*order.Response, error) {
|
||||
l := logic.NewOrderCreateLogic(ctx, s.svcCtx)
|
||||
return l.OrderCreate(in)
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/order/internal/dao"
|
||||
product "lone-services/rpc/product/pb"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
func GetOrderSn(orderType string, adminId int64) string {
|
||||
@@ -20,42 +21,54 @@ func GetOrderSn(orderType string, adminId int64) string {
|
||||
return sn
|
||||
}
|
||||
|
||||
func GetCartData(info map[string]int) ([]dao.ProductInfo, utils.Status) {
|
||||
keys := make([]string, utils.NumberZero, len(info))
|
||||
func GetCartData(name string, info map[int64]int64) (*product.ItemsByIdsData, utils.Status) {
|
||||
keys := make([]int64, utils.NumberZero, len(info))
|
||||
for k := range info {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
//TODO keys 查询产品
|
||||
|
||||
var products []dao.ProductInfo
|
||||
cli, err := GetRpcClient(name)
|
||||
if err != nil {
|
||||
logx.Errorf("get rpc client err: %v", err)
|
||||
return nil, utils.Fail
|
||||
}
|
||||
productClient := product.NewProductClient(cli.Conn())
|
||||
products, err := productClient.ItemsByIds(context.Background(), &product.ItemsByIdsReq{Ids: keys})
|
||||
if err != nil {
|
||||
logx.Errorf("get products err: %v", err)
|
||||
return nil, utils.Fail
|
||||
}
|
||||
|
||||
products = append(products, dao.ProductInfo{
|
||||
Id: 1, Name: "Product 1",
|
||||
Price: 100,
|
||||
Number: 5,
|
||||
Images: "image1.jpg",
|
||||
Stock: 10})
|
||||
products = append(products, dao.ProductInfo{
|
||||
Id: 2, Name: "Product 2",
|
||||
Price: 100.33,
|
||||
Number: 2,
|
||||
Images: "image1.jpg",
|
||||
Stock: 1033})
|
||||
return products, utils.Ok
|
||||
}
|
||||
|
||||
func GetCartInfo(info string) (map[string]int, utils.Status) {
|
||||
var list [][]int
|
||||
func GetCartInfo(info string) (map[int64]int64, utils.Status) {
|
||||
var list [][]int64
|
||||
err := jsoniter.Unmarshal([]byte(info), &list)
|
||||
if err != nil {
|
||||
return nil, utils.ErrorJsonDataError
|
||||
}
|
||||
|
||||
m := make(map[string]int, len(list))
|
||||
m := make(map[int64]int64, len(list))
|
||||
for _, item := range list {
|
||||
if len(item) >= 2 {
|
||||
m[strconv.Itoa(item[0])] = item[1]
|
||||
m[item[0]] = item[1]
|
||||
}
|
||||
}
|
||||
return m, utils.Ok
|
||||
}
|
||||
|
||||
func GetOneData(name string, id int64) (*product.Item, utils.Status) {
|
||||
cli, err := GetRpcClient(name)
|
||||
if err != nil {
|
||||
logx.Errorf("get rpc client err: %v", err)
|
||||
return nil, utils.Fail
|
||||
}
|
||||
productClient := product.NewProductClient(cli.Conn())
|
||||
productInfo, err := productClient.InfoById(context.Background(), &product.InfoByIdReq{Id: id})
|
||||
if err != nil {
|
||||
logx.Errorf("get products err: %v", err)
|
||||
return nil, utils.Fail
|
||||
}
|
||||
|
||||
return productInfo, utils.Ok
|
||||
}
|
||||
|
||||
@@ -78,22 +78,22 @@ type ServiceContext struct {
|
||||
DB *gorm.DB
|
||||
Prefix string
|
||||
|
||||
ExpressSvcName string //服务名
|
||||
ProductSvcName string //服务名
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext {
|
||||
//启动仅读取配置,不建立rpc连接 多个服务就多个
|
||||
expressSvc := utils.GetConfigString("services.express")
|
||||
productSvc := utils.GetConfigString("services.product")
|
||||
|
||||
if expressSvc == utils.StringEmpty {
|
||||
logx.Error("config services.express empty")
|
||||
if productSvc == utils.StringEmpty {
|
||||
logx.Error("config services.product empty")
|
||||
}
|
||||
|
||||
svcCtx := &ServiceContext{
|
||||
Config: c,
|
||||
DB: db,
|
||||
Prefix: utils.GetConfigString("mysql.prefix"),
|
||||
ExpressSvcName: expressSvc,
|
||||
ProductSvcName: productSvc,
|
||||
}
|
||||
|
||||
return svcCtx
|
||||
|
||||
@@ -14,22 +14,23 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
AddressItemsRequest = order.AddressItemsRequest
|
||||
AdminCreateOrderRequest = order.AdminCreateOrderRequest
|
||||
CartRequest = order.CartRequest
|
||||
CreateOrderOneRequest = order.CreateOrderOneRequest
|
||||
CreateOrderRequest = order.CreateOrderRequest
|
||||
EditAddressRequest = order.EditAddressRequest
|
||||
EditCartRequest = order.EditCartRequest
|
||||
EmptyRequest = order.EmptyRequest
|
||||
IdAndTypeRequest = order.IdAndTypeRequest
|
||||
IdRequest = order.IdRequest
|
||||
OrderAuditingItemsRequest = order.OrderAuditingItemsRequest
|
||||
OrderAuditingRequest = order.OrderAuditingRequest
|
||||
OrderItemsRequest = order.OrderItemsRequest
|
||||
Response = order.Response
|
||||
StatusAddressRequest = order.StatusAddressRequest
|
||||
TypeRequest = order.TypeRequest
|
||||
AddressByStoreItemsRequest = order.AddressByStoreItemsRequest
|
||||
AddressItemsRequest = order.AddressItemsRequest
|
||||
AdminCreateOrderRequest = order.AdminCreateOrderRequest
|
||||
CartRequest = order.CartRequest
|
||||
CreateOrderOneRequest = order.CreateOrderOneRequest
|
||||
CreateOrderRequest = order.CreateOrderRequest
|
||||
EditAddressRequest = order.EditAddressRequest
|
||||
EditCartRequest = order.EditCartRequest
|
||||
EmptyRequest = order.EmptyRequest
|
||||
IdAndTypeRequest = order.IdAndTypeRequest
|
||||
IdRequest = order.IdRequest
|
||||
OrderAuditingItemsRequest = order.OrderAuditingItemsRequest
|
||||
OrderAuditingRequest = order.OrderAuditingRequest
|
||||
OrderItemsRequest = order.OrderItemsRequest
|
||||
Response = order.Response
|
||||
StatusAddressRequest = order.StatusAddressRequest
|
||||
TypeRequest = order.TypeRequest
|
||||
|
||||
Order interface {
|
||||
Items(ctx context.Context, in *OrderItemsRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
@@ -44,6 +45,7 @@ type (
|
||||
WebCart(ctx context.Context, in *CartRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
WebCartEdit(ctx context.Context, in *EditCartRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
AddressItem(ctx context.Context, in *AddressItemsRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
AddressByStore(ctx context.Context, in *AddressByStoreItemsRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
OrderAuditingItems(ctx context.Context, in *OrderAuditingItemsRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
OrderAuditing(ctx context.Context, in *OrderAuditingRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
OrderCreate(ctx context.Context, in *AdminCreateOrderRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
@@ -120,6 +122,11 @@ func (m *defaultOrder) AddressItem(ctx context.Context, in *AddressItemsRequest,
|
||||
return client.AddressItem(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultOrder) AddressByStore(ctx context.Context, in *AddressByStoreItemsRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := order.NewOrderClient(m.cli.Conn())
|
||||
return client.AddressByStore(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultOrder) OrderAuditingItems(ctx context.Context, in *OrderAuditingItemsRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := order.NewOrderClient(m.cli.Conn())
|
||||
return client.OrderAuditingItems(ctx, in, opts...)
|
||||
|
||||
@@ -86,3 +86,14 @@ func (p WebAddressItemsValidator) GetMessage() validate.ValidatorMessages {
|
||||
"Type.oneof": "类型不对",
|
||||
}
|
||||
}
|
||||
|
||||
type AddressByStoreItemsValidator struct {
|
||||
StoreId int64 `validate:"required"`
|
||||
}
|
||||
|
||||
// GetMessage 查看列表 - 提示消息
|
||||
func (p AddressByStoreItemsValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"StoreId.required": "Id不能为空",
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user