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
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ type (
|
||||
UpdateOrderDeliverStatusResponse = order.UpdateOrderDeliverStatusResponse
|
||||
UpdateOrderPayStatusRequest = order.UpdateOrderPayStatusRequest
|
||||
UpdateOrderPayStatusResponse = order.UpdateOrderPayStatusResponse
|
||||
WebSaleItemsRequest = order.WebSaleItemsRequest
|
||||
WebStoreItemsRequest = order.WebStoreItemsRequest
|
||||
|
||||
Order interface {
|
||||
Items(ctx context.Context, in *OrderItemsRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
@@ -75,6 +77,8 @@ type (
|
||||
WebAddressItems(ctx context.Context, in *TypeRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
WebCart(ctx context.Context, in *CartRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
WebCartEdit(ctx context.Context, in *EditCartRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
WebSaleItems(ctx context.Context, in *WebSaleItemsRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
WebStoreItems(ctx context.Context, in *WebStoreItemsRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
}
|
||||
|
||||
defaultOrder struct {
|
||||
@@ -220,3 +224,13 @@ func (m *defaultOrder) WebCartEdit(ctx context.Context, in *EditCartRequest, opt
|
||||
client := order.NewOrderClient(m.cli.Conn())
|
||||
return client.WebCartEdit(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultOrder) WebSaleItems(ctx context.Context, in *WebSaleItemsRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := order.NewOrderClient(m.cli.Conn())
|
||||
return client.WebSaleItems(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultOrder) WebStoreItems(ctx context.Context, in *WebStoreItemsRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := order.NewOrderClient(m.cli.Conn())
|
||||
return client.WebStoreItems(ctx, in, opts...)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
"lone-services/pkg/wecomrpc"
|
||||
"lone-services/services/sale/internal/dao"
|
||||
"lone-services/services/sale/internal/model"
|
||||
"lone-services/services/sale/validator"
|
||||
@@ -159,6 +160,14 @@ func (l *ApiSaleAddLogic) ApiSaleAdd(in *sale.ApiSaleAddReq) (*sale.Response, er
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
m.Commit()
|
||||
Time := utils.Now().String()
|
||||
md5 := utils.MD5Encrypt(strconv.Itoa(int(data.Id)) + data.Name + Time)
|
||||
wecomrpc.SendMessage(l.ctx, l.svcCtx.WecomSvcName, wecomrpc.SendMessageJob{
|
||||
BizId: int(data.Id), // 门店ID
|
||||
BizType: wecomrpc.BizTypeSales,
|
||||
Type: wecomrpc.ProductSubmitReview,
|
||||
Key: md5,
|
||||
})
|
||||
|
||||
return okResponse(nil), nil
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ type ServiceContext struct {
|
||||
Prefix string
|
||||
ChoreSvcName string
|
||||
UserSvcName string
|
||||
WecomSvcName string
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext {
|
||||
@@ -25,6 +26,10 @@ func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext {
|
||||
if userSvc == utils.StringEmpty {
|
||||
logx.Error("config services.user empty")
|
||||
}
|
||||
wecomSvc := utils.GetConfigString("services.wecom")
|
||||
if wecomSvc == utils.StringEmpty {
|
||||
logx.Error("config services.wecom empty")
|
||||
}
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
@@ -32,5 +37,6 @@ func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext {
|
||||
Prefix: utils.GetConfigString("mysql.prefix"),
|
||||
ChoreSvcName: choreSvc,
|
||||
UserSvcName: userSvc,
|
||||
WecomSvcName: wecomSvc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
[base]
|
||||
login_out_time=43200 #api接口超时时间分
|
||||
login_refresh_out_time=83200
|
||||
name = "sale-service"
|
||||
listenOn = "0.0.0.0:10700"
|
||||
mode = "dev"
|
||||
[log]
|
||||
path = "logs"
|
||||
serviceName = "sale-service"
|
||||
mode = "file"
|
||||
encoding = "plain"
|
||||
level = "info"
|
||||
keepDays = 7
|
||||
maxSize = 50
|
||||
maxBackups = 5
|
||||
compress = false
|
||||
|
||||
[oss]
|
||||
accessKeyId = "LTAI5t7U8KvxSiPE5auwQUuu"
|
||||
accessKeySecret = "xjfgbQQRpL4TcIspNuClg6bYADa3pk"
|
||||
roleArn = "acs:ram::1663896742753915:role/oss-upload"
|
||||
roleSessionName = "oss-upload"
|
||||
region = "oss-cn-hangzhou"
|
||||
bucketName = "lone-images"
|
||||
endpoint = "https://oss-accelerate.aliyuncs.com"
|
||||
host = "https://images.ailuowan.com"
|
||||
dir = "upload/"
|
||||
expireSeconds = 3600
|
||||
|
||||
[mysql]
|
||||
host = '39.106.171.204'
|
||||
port = 33066
|
||||
user = 'root'
|
||||
password = 'MOLXRZNOU4Y4'
|
||||
database = 'dms-sale'
|
||||
charset = 'utf8mb4'
|
||||
prefix = ''
|
||||
debug = true
|
||||
[mysql_read]
|
||||
host = '39.106.171.204'
|
||||
port = 33066
|
||||
user = 'root'
|
||||
password = 'MOLXRZNOU4Y4'
|
||||
database = 'dms-sale'
|
||||
charset = 'utf8mb4'
|
||||
prefix = ''
|
||||
|
||||
[redis]
|
||||
host = '39.106.171.204'
|
||||
password = 'lLMLcuPpzSj'
|
||||
port = 6379
|
||||
db = 0
|
||||
|
||||
[encrypt]
|
||||
data_key = "u2t9T3luZtoRfhBstkFN6TiIMW38BA8a"
|
||||
[services]
|
||||
chore = "chore-service"
|
||||
user = "user-service"
|
||||
wecom = "wecom-service"
|
||||
Reference in New Issue
Block a user