From 23ea6659c281d7306fb4094ebd86eae3814ec43b Mon Sep 17 00:00:00 2001 From: gjs Date: Fri, 28 Aug 2026 16:34:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=99=BB=E5=BD=95=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/apisix/lua/auth.lua | 8 ++++- services/admin/internal/dao/login.go | 29 ++++++++-------- services/admin/internal/logic/loginlogic.go | 1 + .../order/internal/logic/orderCreateLogic.go | 34 +++++++++++-------- .../order/internal/logic/webCreateLogic.go | 2 +- 5 files changed, 43 insertions(+), 31 deletions(-) diff --git a/deploy/apisix/lua/auth.lua b/deploy/apisix/lua/auth.lua index 2f68dbf..0ae0bea 100644 --- a/deploy/apisix/lua/auth.lua +++ b/deploy/apisix/lua/auth.lua @@ -112,7 +112,7 @@ function _M.access(conf, ctx) ngx.req.set_header("X-Sale-Province", tostring(json.province)) end if json.sale_mobile then - ngx.req.set_header("X-Sale-Mobile", tostring(json.mobile)) + ngx.req.set_header("X-Sale-Mobile", tostring(json.sale_mobile)) end if json.sale_name then ngx.req.set_header("X-Sale-Name", json.sale_name) @@ -123,6 +123,12 @@ function _M.access(conf, ctx) if json.group_id then ngx.req.set_header("X-Group-Id", tostring(json.group_id)) end + if json.group_name then + ngx.req.set_header("X-Group-Name", tostring(json.group_name)) + end + if json.type then + ngx.req.set_header("X-User-Type", tostring(json.type)) + end end ngx.req.set_header("X-Refresh", refresh or "") diff --git a/services/admin/internal/dao/login.go b/services/admin/internal/dao/login.go index 04fe37a..29751e2 100644 --- a/services/admin/internal/dao/login.go +++ b/services/admin/internal/dao/login.go @@ -3,20 +3,21 @@ package dao import "lone-services/pkg/utils" type JwtInfo struct { - Id int64 `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"` - Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"` - Name string `gorm:"column:name;type:varchar(30);comment:真实姓名;NOT NULL" json:"name"` - Phone string `gorm:"column:phone;type:char(12);comment:电话" json:"phone"` - Email string `gorm:"column:email;type:varchar(255);comment:邮箱" json:"email"` - LastTime utils.CustomTime `gorm:"column:last_time;type:datetime;comment:最后一次登录时间" json:"last_time"` - Time int `json:"time"` - Roles []JwtInfoServices `json:"roles"` - Refresh string `json:"refresh"` - SaleId int64 `json:"sale_id" gorm:"sale_id"` // 销售ID - Type uint8 `json:"type" gorm:"type"` // 销售ID - SaleName string `json:"sale_name" gorm:"-"` - GroupId int64 `json:"group_id" gorm:"-"` - GroupName string `json:"group_name" gorm:"-"` + Id int64 `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"` + Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"` + Name string `gorm:"column:name;type:varchar(30);comment:真实姓名;NOT NULL" json:"name"` + Phone string `gorm:"column:phone;type:char(12);comment:电话" json:"phone"` + Email string `gorm:"column:email;type:varchar(255);comment:邮箱" json:"email"` + LastTime utils.CustomTime `gorm:"column:last_time;type:datetime;comment:最后一次登录时间" json:"last_time"` + Time int `json:"time"` + Roles []JwtInfoServices `json:"roles"` + Refresh string `json:"refresh"` + Type uint8 `json:"type" gorm:"type"` // 销售ID + SaleId int64 `json:"sale_id" gorm:"sale_id"` // 销售ID + SaleMobile string `json:"sale_mobile" gorm:"-"` + SaleName string `json:"sale_name" gorm:"-"` + GroupId int64 `json:"group_id" gorm:"-"` + GroupName string `json:"group_name" gorm:"-"` } type JwtOutInfo struct { diff --git a/services/admin/internal/logic/loginlogic.go b/services/admin/internal/logic/loginlogic.go index 134dd1c..56c4487 100644 --- a/services/admin/internal/logic/loginlogic.go +++ b/services/admin/internal/logic/loginlogic.go @@ -92,6 +92,7 @@ func (l *LoginLogic) Login(in *admin.LoginRequest) (*admin.Response, error) { data.GroupId = saleInfo.GroupId data.SaleId = saleInfo.Id data.SaleName = saleInfo.Name + data.SaleMobile = saleInfo.OriginMobile } data.Phone, _ = utils.DecryptPhone(info.Phone) diff --git a/services/order/internal/logic/orderCreateLogic.go b/services/order/internal/logic/orderCreateLogic.go index 261d3eb..2652052 100644 --- a/services/order/internal/logic/orderCreateLogic.go +++ b/services/order/internal/logic/orderCreateLogic.go @@ -4,6 +4,7 @@ import ( "context" "lone-services/pkg/modelbase" "lone-services/pkg/utils" + product "lone-services/rpc/product/pb" "lone-services/services/order/internal/dao" "lone-services/services/order/internal/model" "lone-services/services/order/validator" @@ -68,7 +69,8 @@ func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*orde ww := modelbase.Params{ Eq: map[string]string{ - "type": strconv.Itoa(dao.OrderTypeStore), + "type": strconv.Itoa(dao.OrderTypeStore), + "store_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen), }, } data.StoreId = int(adminInfo.ID) @@ -79,7 +81,6 @@ func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*orde data.SaleProvince = int(adminInfo.SaleProvince) data.CreateType = dao.OrderTypeStore data.Type = dao.OrderTypeStore - ww.Eq["store_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen) data.OrderSn = svc.GetOrderSn(strconv.Itoa(dao.OrderTypeStore), adminInfo.ID) var cart dao.Cart @@ -96,6 +97,8 @@ func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*orde var totalPrice float64 errData := make(map[int64]int64) productItems := []dao.OrderProductCreate{} + + NumItems := make([]*product.NumberItem, utils.NumberZero) for _, item := range products.Items { if buyNum, ok := ids[item.Id]; ok { if buyNum > int64(item.Number) { @@ -103,6 +106,8 @@ func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*orde return l.out(utils.Fail, item.Name+"购买数量超出库存,目前可以够买:"+strconv.Itoa(int(item.Number))) } else { + numItem := &product.NumberItem{Id: item.Id, Number: uint32(buyNum)} + NumItems = append(NumItems, numItem) keys = append(keys, strconv.Itoa(int(item.Id))) totalPrice += item.Price * float64(buyNum) productItems = append(productItems, dao.OrderProductCreate{ @@ -143,20 +148,19 @@ func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*orde return l.fail(utils.Fail) } - //TODO 扣库存接口 - //cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName) - //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: item.Id, Type: utils.NumberOne, Number: buyNum}) - //if err != nil { - // mobileObj.Rollback() - // logx.Errorf("get products err: %v", err) - // return l.fail(utils.Fail, "产品库存不足") - //} + productClient := product.NewProductClient(cli.Conn()) + _, err = productClient.NumberItems(l.ctx, &product.NumberItemsReq{Type: utils.NumberOne, Items: NumItems}) + if err != nil { + mobileObj.Rollback() + logx.Errorf("get products err: %v", err) + return l.out(utils.Fail, "产品库存不足") + } mobileObj.Commit() diff --git a/services/order/internal/logic/webCreateLogic.go b/services/order/internal/logic/webCreateLogic.go index 61863e6..0e362d8 100644 --- a/services/order/internal/logic/webCreateLogic.go +++ b/services/order/internal/logic/webCreateLogic.go @@ -126,7 +126,7 @@ func (l *WebCreateLogic) WebCreate(in *order.CreateOrderRequest) (*order.Respons errData := make(map[int64]int64) productItems := []dao.OrderProductCreate{} - NumItems := make([]*product.NumberItem, 0) + NumItems := make([]*product.NumberItem, utils.NumberZero) for _, item := range products.Items { if buyNum, ok := ids[item.Id]; ok { if buyNum > int64(item.Number) {