order
This commit is contained in:
@@ -142,6 +142,18 @@ type OrderSaleItems struct {
|
||||
ProductItems []OrderProducts `gorm:"-" json:"product_items"`
|
||||
}
|
||||
|
||||
type OrderStoreItems struct {
|
||||
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"`
|
||||
StoreName string `gorm:"column:store_name;type:varchar(50);comment:门店名" json:"store_name"`
|
||||
TotalPrice float64 `gorm:"column:total_price;type:decimal(10,2);comment:总价;NOT NULL" json:"total_price"`
|
||||
PayPrice float64 `gorm:"column:pay_price;type:decimal(10,2);comment:实际支付金额" json:"pay_price"`
|
||||
ProductIds string `gorm:"column:product_ids;type:varchar(150);comment:产品IDs" json:"product_ids"`
|
||||
SignTime utils.CustomTime `gorm:"column:sign_time;type:datetime;comment:签收时间" json:"sign_time"`
|
||||
CreateTime utils.CustomTime `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP;comment:订单创建时间" json:"create_time"`
|
||||
ProductItems []OrderProducts `gorm:"-" json:"product_items"`
|
||||
}
|
||||
|
||||
type OrderAccount struct {
|
||||
Id int `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"`
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/order/internal/dao"
|
||||
"lone-services/services/order/internal/model"
|
||||
"strconv"
|
||||
|
||||
"lone-services/rpc/order/pb"
|
||||
"lone-services/services/order/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type WebSaleItemsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewWebSaleItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebSaleItemsLogic {
|
||||
return &WebSaleItemsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *WebSaleItemsLogic) WebSaleItems(in *order.WebSaleItemsRequest) (*order.Response, error) {
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
var info []dao.OrderSaleItems
|
||||
w := modelbase.Params{
|
||||
Page: int(in.Page),
|
||||
Size: int(in.Size),
|
||||
Order: "id desc",
|
||||
Eq: map[string]string{"status": utils.StringStatusOk},
|
||||
}
|
||||
|
||||
w.Like = make(map[string]string)
|
||||
|
||||
if len(in.Name) > utils.NumberZero {
|
||||
w.Like["sale_name LIKE ? "] = "%%" + in.Name + "%%"
|
||||
}
|
||||
|
||||
if in.SaleId > utils.NumberZero {
|
||||
saleInfo, sErr := svc.GetSaleInfo(l.svcCtx.SaleName, in.SaleId)
|
||||
if sErr != utils.Ok {
|
||||
return l.fail(sErr)
|
||||
}
|
||||
if saleInfo.SaleId != adminInfo.SaleId {
|
||||
return l.fail(utils.SetError(utils.Fail, "无权限访问"))
|
||||
}
|
||||
w.Eq["sale_id"] = strconv.FormatInt(in.SaleId, utils.NumberTen)
|
||||
} else {
|
||||
w.Eq["sale_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
||||
}
|
||||
|
||||
if len(in.Time) > utils.NumberOne {
|
||||
w.Other["create_time > ?"] = in.Time[utils.NumberZero]
|
||||
w.Other["create_time < ?"] = in.Time[utils.NumberOne]
|
||||
}
|
||||
|
||||
items, err := model.OrderModel{}.Init().Page(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
var orderSn []string
|
||||
for _, v := range info {
|
||||
orderSn = append(orderSn, v.OrderSn)
|
||||
}
|
||||
|
||||
if len(orderSn) > utils.NumberZero {
|
||||
w = modelbase.Params{In: map[string][]string{"order_sn": orderSn}}
|
||||
var products []dao.OrderProducts
|
||||
err = model.OrderProductModel{}.Init().Items(w, &products)
|
||||
if err != nil {
|
||||
return l.ok(items)
|
||||
}
|
||||
|
||||
tmpProducts := map[string][]dao.OrderProducts{}
|
||||
for _, v := range products {
|
||||
tmpProducts[v.OrderSn] = append(tmpProducts[v.OrderSn], v)
|
||||
}
|
||||
for key, v := range info {
|
||||
if val, ok := tmpProducts[v.OrderSn]; ok {
|
||||
info[key].ProductItems = val
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
items.Items = info
|
||||
return l.ok(items)
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
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"
|
||||
"strconv"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type WebStoreItemsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewWebStoreItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebStoreItemsLogic {
|
||||
return &WebStoreItemsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *WebStoreItemsLogic) WebStoreItems(in *order.WebStoreItemsRequest) (*order.Response, error) {
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
var info []dao.OrderStoreItems
|
||||
w := modelbase.Params{
|
||||
Page: int(in.Page),
|
||||
Size: int(in.Size),
|
||||
Order: "id desc",
|
||||
Eq: map[string]string{"store_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen), "status": utils.StringStatusOk},
|
||||
}
|
||||
|
||||
items, err := model.OrderModel{}.Init().Page(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
var orderSn []string
|
||||
for _, v := range info {
|
||||
orderSn = append(orderSn, v.OrderSn)
|
||||
}
|
||||
|
||||
if len(orderSn) > utils.NumberZero {
|
||||
w = modelbase.Params{In: map[string][]string{"order_sn": orderSn}}
|
||||
var products []dao.OrderProducts
|
||||
err = model.OrderProductModel{}.Init().Items(w, &products)
|
||||
if err != nil {
|
||||
return l.ok(items)
|
||||
}
|
||||
|
||||
tmpProducts := map[string][]dao.OrderProducts{}
|
||||
for _, v := range products {
|
||||
tmpProducts[v.OrderSn] = append(tmpProducts[v.OrderSn], v)
|
||||
}
|
||||
for key, v := range info {
|
||||
if val, ok := tmpProducts[v.OrderSn]; ok {
|
||||
info[key].ProductItems = val
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
items.Items = info
|
||||
return l.ok(items)
|
||||
}
|
||||
@@ -155,3 +155,13 @@ func (s *OrderServer) WebCartEdit(ctx context.Context, in *order.EditCartRequest
|
||||
l := logic.NewWebCartEditLogic(ctx, s.svcCtx)
|
||||
return l.WebCartEdit(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) WebSaleItems(ctx context.Context, in *order.WebSaleItemsRequest) (*order.Response, error) {
|
||||
l := logic.NewWebSaleItemsLogic(ctx, s.svcCtx)
|
||||
return l.WebSaleItems(in)
|
||||
}
|
||||
|
||||
func (s *OrderServer) WebStoreItems(ctx context.Context, in *order.WebStoreItemsRequest) (*order.Response, error) {
|
||||
l := logic.NewWebStoreItemsLogic(ctx, s.svcCtx)
|
||||
return l.WebStoreItems(in)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"lone-services/pkg/utils"
|
||||
express "lone-services/rpc/express/pb"
|
||||
product "lone-services/rpc/product/pb"
|
||||
sale "lone-services/rpc/sale/pb"
|
||||
"lone-services/services/order/internal/dao"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
@@ -129,5 +130,20 @@ func GetDeliveryInfo(name string, id int64, Type uint8) (*express.DeliveryInfoRe
|
||||
}
|
||||
|
||||
return info, utils.Ok
|
||||
|
||||
}
|
||||
|
||||
func GetSaleInfo(name string, id int64) (*sale.InfoData, utils.Status) {
|
||||
cli, err := GetRpcClient(name)
|
||||
if err != nil {
|
||||
logx.Errorf("get rpc client err: %v", err)
|
||||
return nil, utils.Fail
|
||||
}
|
||||
client := sale.NewSaleClient(cli.Conn())
|
||||
info, err := client.InfoInternal(context.Background(), &sale.InfoReq{Id: id})
|
||||
if err != nil {
|
||||
logx.Errorf("get products err: %v", err)
|
||||
return nil, utils.Fail
|
||||
}
|
||||
|
||||
return info, utils.Ok
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user