diff --git a/deploy/apisix/lua/auth.lua b/deploy/apisix/lua/auth.lua index 9039569..2f68dbf 100644 --- a/deploy/apisix/lua/auth.lua +++ b/deploy/apisix/lua/auth.lua @@ -108,6 +108,12 @@ function _M.access(conf, ctx) if json.store_id then ngx.req.set_header("X-Store-Id", tostring(json.store_id)) end + if json.sale_province then + 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)) + end if json.sale_name then ngx.req.set_header("X-Sale-Name", json.sale_name) end diff --git a/pkg/utils/encrypt.go b/pkg/utils/encrypt.go index 1ca2f45..8c7c674 100644 --- a/pkg/utils/encrypt.go +++ b/pkg/utils/encrypt.go @@ -44,7 +44,7 @@ func GetSaltPassword(salt, password string) string { // GetRandstring 取得随机字符串:使用字符串拼接 func GetRandString(length int) string { - if length < 1 { + if length < NumberOne { return "" } char := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" @@ -53,7 +53,7 @@ func GetRandString(length int) string { ran := rand.New(rand.NewSource(time.Now().Unix())) var rchar string = "" - for i := 1; i <= length; i++ { + for i := NumberOne; i <= length; i++ { rchar = rchar + charArr[ran.Intn(charlen)] } return rchar @@ -133,8 +133,8 @@ func DecryptPhoneReplace(mobile string) string { func GetSearchPhone(mobile string) string { phone := StringEmpty - if len(mobile) == 11 { - prefix := mobile[NumberZero:3] // 前三位 + if len(mobile) == NumberEleven { + prefix := mobile[NumberZero:NumberThree] // 前三位 username, cErr := Crypto{}.AESEncryptECB(prefix) if cErr == nil { phone = username @@ -171,7 +171,7 @@ func GetSearchPhone(mobile string) string { // GetRandstring 取得随机字符串:使用字符串拼接 func GetRandstring(length int) string { - if length < 1 { + if length < NumberOne { return StringEmpty } char := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" @@ -180,7 +180,7 @@ func GetRandstring(length int) string { ran := rand.New(rand.NewSource(time.Now().Unix())) var rchar string = StringEmpty - for i := 1; i <= length; i++ { + for i := NumberOne; i <= length; i++ { rchar = rchar + charArr[ran.Intn(charlen)] } return rchar diff --git a/pkg/utils/loginInfo.go b/pkg/utils/loginInfo.go index 3594ec9..6874d9a 100644 --- a/pkg/utils/loginInfo.go +++ b/pkg/utils/loginInfo.go @@ -10,20 +10,22 @@ import ( ) type UserInfo struct { - ID int64 - Name string - RawUID string - Refresh string - ClientIP string // 客户端ip - UserAgent string // 完整原始ua - BrowserName string // 浏览器名称 - BrowserVer string // 浏览器版本 - StoreName string // 店铺名称 - StoreId int64 // 店铺id - SaleName string // 销售名称 - SaleId int64 // 销售id - GroupId int64 // 分组ID - Valid bool + ID int64 + Name string + RawUID string + Refresh string + ClientIP string // 客户端ip + UserAgent string // 完整原始ua + BrowserName string // 浏览器名称 + BrowserVer string // 浏览器版本 + StoreName string // 店铺名称 + StoreId int64 // 店铺id + SaleName string // 销售名称 + SaleId int64 // 销售id + SaleMobile string // 销售手机 + SaleProvince int64 // 销售省份 + GroupId int64 // 分组ID + Valid bool } func GetUserFromCtx(ctx context.Context) UserInfo { @@ -42,6 +44,8 @@ func GetUserFromCtx(ctx context.Context) UserInfo { saleName := md.Get("x-sale-name") saleId := md.Get("x-sale-id") groupId := md.Get("x-group-id") + province := md.Get("x-sale-province") + mobile := md.Get("x-sale-mobile") if len(refreshList) == NumberZero { refreshList = md.Get("X-Refresh") @@ -62,6 +66,12 @@ func GetUserFromCtx(ctx context.Context) UserInfo { if len(saleName) > NumberZero { userInfo.SaleName = saleName[NumberZero] } + if len(province) > NumberZero { + userInfo.SaleProvince, _ = strconv.ParseInt(province[NumberZero], NumberTen, NumberSixtyFourth) + } + if len(mobile) > NumberZero { + userInfo.SaleMobile = mobile[NumberZero] + } if len(saleId) > NumberZero { userInfo.SaleId, _ = strconv.ParseInt(saleId[NumberZero], NumberTen, NumberSixtyFourth) } diff --git a/pkg/utils/status.go b/pkg/utils/status.go index a53ec20..82ce699 100644 --- a/pkg/utils/status.go +++ b/pkg/utils/status.go @@ -31,6 +31,7 @@ const ( NumberSixteen = 16 NumberThirtyTwo = 32 NumberSixtyFourth = 64 + NumberThirty = 30 MaxSort uint16 = 999 //全局基础最大排序 MinSort uint8 = 1 //全局基础最小排序 diff --git a/pkg/utils/time.go b/pkg/utils/time.go index 8d883f1..c5f224e 100644 --- a/pkg/utils/time.go +++ b/pkg/utils/time.go @@ -25,6 +25,11 @@ type CustomTime struct { time.Time } +func GetAfterMinutes(minutes int) CustomTime { + t := time.Now().In(AsiaShanghai).Add(time.Duration(minutes) * time.Minute) + return CustomTime{Time: t} +} + // Now 获取当前时间 func Now() CustomTime { return CustomTime{time.Now().In(AsiaShanghai)} diff --git a/pkg/utils/tools.go b/pkg/utils/tools.go index f84808b..e796816 100644 --- a/pkg/utils/tools.go +++ b/pkg/utils/tools.go @@ -8,7 +8,6 @@ import ( "math" "math/rand" "reflect" - "regexp" "strconv" "strings" "sync" @@ -25,57 +24,6 @@ var ( once sync.Once // 保证全局只初始化一次,并发安全 ) -func IsMobile(mobile string) bool { - // 手机号验证正则表达式(支持国内手机号) - phoneRegex := regexp.MustCompile(`^1[3-9]\d{9}$`) - return phoneRegex.MatchString(mobile) -} - -// 初始化随机数生成器(内部方法,外部无需调用) -func initRandGenerator() { - // 创建随机数源 - source := rand.NewSource(time.Now().UnixNano()) - // 基于源创建生成器 - randGen = rand.New(source) -} - -// GetRandNum 工程化生成四位随机数(0000-9999) -func GetRandNum(number int) int { - // 首次调用时初始化,后续调用直接复用,无重复初始化开销 - once.Do(initRandGenerator) - // 生成0-9999随机数,格式化补零为4位 - return randGen.Intn(number) -} - -func UniqueId(typeStr string, id int) string { - // 格式化补零:%04d 表示数字占4位,不足左侧补0 - return fmt.Sprintf("%s%010d%s%s", typeStr, id, time.Now().Format("20060102150405"), fmt.Sprintf("%04d", GetRandNum(10000))) -} - -// GenerateNickname 生成风格1:形容词+名词+随机数字(例:帅气小猫668) -func GenerateNickname() string { - var ( - // 形容词(修饰昵称) - adjectives = []string{ - "帅气", "可爱", "温柔", "霸气", "呆萌", "高冷", "暖心", "潇洒", - "元气", "佛系", "硬核", "软萌", "酷飒", "慵懒", "清爽", - } - // 名词(核心昵称) - nouns = []string{ - "小猫", "小狗", "星辰", "大海", "清风", "明月", "云朵", "小鹿", - "枫叶", "晚风", "暖阳", "星辰", "鲸鱼", "兔子", "小熊", - } - ) - adj := adjectives[rand.Intn(len(adjectives))] - noun := nouns[rand.Intn(len(nouns))] - var numStr strings.Builder - for i := 0; i < 3; i++ { - numStr.WriteByte(byte('0' + rand.Intn(10))) - } - num := numStr.String() // 2位随机数字 - return fmt.Sprintf("%s%s%s", adj, noun, num) -} - // MD5Encrypt 封装MD5加密函数:输入字符串,返回32位小写MD5哈希值 func MD5Encrypt(str string) string { // 1. 创建MD5哈希对象 diff --git a/rpc/express/express.pb b/rpc/express/express.pb index e06ab43..5fde36b 100644 Binary files a/rpc/express/express.pb and b/rpc/express/express.pb differ diff --git a/rpc/express/express.proto b/rpc/express/express.proto index a04b156..8f765f5 100644 --- a/rpc/express/express.proto +++ b/rpc/express/express.proto @@ -5,10 +5,6 @@ option go_package="./express"; import "google/api/annotations.proto"; -message Request { - string ping = 1; -} - message Response { int32 code = 1; string msg = 2; @@ -18,16 +14,69 @@ message Response { message EmtpyRequest { } +message CreateRequest { + int64 id = 1; + string name = 2; + int32 transit_id = 3; + string app_code = 4; + string app_secret_key = 5; + string app_url = 6; + string card_number = 7; + string province = 8; + string city = 9; + string county = 10; + string address = 11; + string company_name = 12; + string contact = 13; + string mobile = 14; + string pdf_code = 15; + string other = 16; +} + +message IdRequest { + int64 id = 1; +} + +message StatusRequest { + int64 id = 1; + int32 status = 2; + string reason = 3; +} + service Express { - rpc Ping(Request) returns(Response){ + rpc Items(EmtpyRequest) returns(Response){ option (google.api.http) = { - post: "/admin/v3/express/ping" + get: "/admin/v3/express/items" body: "*" }; }; - rpc Items(EmtpyRequest) returns(Response){ + rpc Create(CreateRequest) returns(Response){ option (google.api.http) = { - post: "/admin/v3/express/items" + post: "/admin/v3/express/create" + body: "*" + }; + }; + rpc Edit(CreateRequest) returns(Response){ + option (google.api.http) = { + post: "/admin/v3/express/edit" + body: "*" + }; + }; + rpc Info(IdRequest) returns(Response){ + option (google.api.http) = { + get: "/admin/v3/express/info" + body: "*" + }; + }; + rpc Names(EmtpyRequest) returns(Response){ + option (google.api.http) = { + get: "/admin/v3/express/names" + body: "*" + }; + }; + rpc Status(StatusRequest) returns(Response){ + option (google.api.http) = { + post: "/admin/v3/express/status" body: "*" }; }; diff --git a/rpc/express/pb/express.pb.go b/rpc/express/pb/express.pb.go index 131ff5b..11d4e5f 100644 --- a/rpc/express/pb/express.pb.go +++ b/rpc/express/pb/express.pb.go @@ -22,50 +22,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -type Request struct { - state protoimpl.MessageState `protogen:"open.v1"` - Ping string `protobuf:"bytes,1,opt,name=ping,proto3" json:"ping,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache -} - -func (x *Request) Reset() { - *x = Request{} - mi := &file_express_express_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *Request) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Request) ProtoMessage() {} - -func (x *Request) ProtoReflect() protoreflect.Message { - mi := &file_express_express_proto_msgTypes[0] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Request.ProtoReflect.Descriptor instead. -func (*Request) Descriptor() ([]byte, []int) { - return file_express_express_proto_rawDescGZIP(), []int{0} -} - -func (x *Request) GetPing() string { - if x != nil { - return x.Ping - } - return "" -} - type Response struct { state protoimpl.MessageState `protogen:"open.v1"` Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` @@ -77,7 +33,7 @@ type Response struct { func (x *Response) Reset() { *x = Response{} - mi := &file_express_express_proto_msgTypes[1] + mi := &file_express_express_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -89,7 +45,7 @@ func (x *Response) String() string { func (*Response) ProtoMessage() {} func (x *Response) ProtoReflect() protoreflect.Message { - mi := &file_express_express_proto_msgTypes[1] + mi := &file_express_express_proto_msgTypes[0] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -102,7 +58,7 @@ func (x *Response) ProtoReflect() protoreflect.Message { // Deprecated: Use Response.ProtoReflect.Descriptor instead. func (*Response) Descriptor() ([]byte, []int) { - return file_express_express_proto_rawDescGZIP(), []int{1} + return file_express_express_proto_rawDescGZIP(), []int{0} } func (x *Response) GetCode() int32 { @@ -134,7 +90,7 @@ type EmtpyRequest struct { func (x *EmtpyRequest) Reset() { *x = EmtpyRequest{} - mi := &file_express_express_proto_msgTypes[2] + mi := &file_express_express_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -146,7 +102,7 @@ func (x *EmtpyRequest) String() string { func (*EmtpyRequest) ProtoMessage() {} func (x *EmtpyRequest) ProtoReflect() protoreflect.Message { - mi := &file_express_express_proto_msgTypes[2] + mi := &file_express_express_proto_msgTypes[1] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -159,24 +115,320 @@ func (x *EmtpyRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use EmtpyRequest.ProtoReflect.Descriptor instead. func (*EmtpyRequest) Descriptor() ([]byte, []int) { + return file_express_express_proto_rawDescGZIP(), []int{1} +} + +type CreateRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + TransitId int32 `protobuf:"varint,3,opt,name=transit_id,json=transitId,proto3" json:"transit_id,omitempty"` + AppCode string `protobuf:"bytes,4,opt,name=app_code,json=appCode,proto3" json:"app_code,omitempty"` + AppSecretKey string `protobuf:"bytes,5,opt,name=app_secret_key,json=appSecretKey,proto3" json:"app_secret_key,omitempty"` + AppUrl string `protobuf:"bytes,6,opt,name=app_url,json=appUrl,proto3" json:"app_url,omitempty"` + CardNumber string `protobuf:"bytes,7,opt,name=card_number,json=cardNumber,proto3" json:"card_number,omitempty"` + Province string `protobuf:"bytes,8,opt,name=province,proto3" json:"province,omitempty"` + City string `protobuf:"bytes,9,opt,name=city,proto3" json:"city,omitempty"` + County string `protobuf:"bytes,10,opt,name=county,proto3" json:"county,omitempty"` + Address string `protobuf:"bytes,11,opt,name=address,proto3" json:"address,omitempty"` + CompanyName string `protobuf:"bytes,12,opt,name=company_name,json=companyName,proto3" json:"company_name,omitempty"` + Contact string `protobuf:"bytes,13,opt,name=contact,proto3" json:"contact,omitempty"` + Mobile string `protobuf:"bytes,14,opt,name=mobile,proto3" json:"mobile,omitempty"` + PdfCode string `protobuf:"bytes,15,opt,name=pdf_code,json=pdfCode,proto3" json:"pdf_code,omitempty"` + Other string `protobuf:"bytes,16,opt,name=other,proto3" json:"other,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *CreateRequest) Reset() { + *x = CreateRequest{} + mi := &file_express_express_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CreateRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateRequest) ProtoMessage() {} + +func (x *CreateRequest) ProtoReflect() protoreflect.Message { + mi := &file_express_express_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CreateRequest.ProtoReflect.Descriptor instead. +func (*CreateRequest) Descriptor() ([]byte, []int) { return file_express_express_proto_rawDescGZIP(), []int{2} } +func (x *CreateRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *CreateRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *CreateRequest) GetTransitId() int32 { + if x != nil { + return x.TransitId + } + return 0 +} + +func (x *CreateRequest) GetAppCode() string { + if x != nil { + return x.AppCode + } + return "" +} + +func (x *CreateRequest) GetAppSecretKey() string { + if x != nil { + return x.AppSecretKey + } + return "" +} + +func (x *CreateRequest) GetAppUrl() string { + if x != nil { + return x.AppUrl + } + return "" +} + +func (x *CreateRequest) GetCardNumber() string { + if x != nil { + return x.CardNumber + } + return "" +} + +func (x *CreateRequest) GetProvince() string { + if x != nil { + return x.Province + } + return "" +} + +func (x *CreateRequest) GetCity() string { + if x != nil { + return x.City + } + return "" +} + +func (x *CreateRequest) GetCounty() string { + if x != nil { + return x.County + } + return "" +} + +func (x *CreateRequest) GetAddress() string { + if x != nil { + return x.Address + } + return "" +} + +func (x *CreateRequest) GetCompanyName() string { + if x != nil { + return x.CompanyName + } + return "" +} + +func (x *CreateRequest) GetContact() string { + if x != nil { + return x.Contact + } + return "" +} + +func (x *CreateRequest) GetMobile() string { + if x != nil { + return x.Mobile + } + return "" +} + +func (x *CreateRequest) GetPdfCode() string { + if x != nil { + return x.PdfCode + } + return "" +} + +func (x *CreateRequest) GetOther() string { + if x != nil { + return x.Other + } + return "" +} + +type IdRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *IdRequest) Reset() { + *x = IdRequest{} + mi := &file_express_express_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *IdRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IdRequest) ProtoMessage() {} + +func (x *IdRequest) ProtoReflect() protoreflect.Message { + mi := &file_express_express_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use IdRequest.ProtoReflect.Descriptor instead. +func (*IdRequest) Descriptor() ([]byte, []int) { + return file_express_express_proto_rawDescGZIP(), []int{3} +} + +func (x *IdRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type StatusRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Status int32 `protobuf:"varint,2,opt,name=status,proto3" json:"status,omitempty"` + Reason string `protobuf:"bytes,3,opt,name=reason,proto3" json:"reason,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *StatusRequest) Reset() { + *x = StatusRequest{} + mi := &file_express_express_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *StatusRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatusRequest) ProtoMessage() {} + +func (x *StatusRequest) ProtoReflect() protoreflect.Message { + mi := &file_express_express_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StatusRequest.ProtoReflect.Descriptor instead. +func (*StatusRequest) Descriptor() ([]byte, []int) { + return file_express_express_proto_rawDescGZIP(), []int{4} +} + +func (x *StatusRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *StatusRequest) GetStatus() int32 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *StatusRequest) GetReason() string { + if x != nil { + return x.Reason + } + return "" +} + var File_express_express_proto protoreflect.FileDescriptor const file_express_express_proto_rawDesc = "" + "\n" + - "\x15express/express.proto\x12\aexpress\x1a\x1cgoogle/api/annotations.proto\"\x1d\n" + - "\aRequest\x12\x12\n" + - "\x04ping\x18\x01 \x01(\tR\x04ping\"D\n" + + "\x15express/express.proto\x12\aexpress\x1a\x1cgoogle/api/annotations.proto\"D\n" + "\bResponse\x12\x12\n" + "\x04code\x18\x01 \x01(\x05R\x04code\x12\x10\n" + "\x03msg\x18\x02 \x01(\tR\x03msg\x12\x12\n" + "\x04data\x18\x03 \x01(\tR\x04data\"\x0e\n" + - "\fEmtpyRequest2\xb0\x01\n" + - "\aExpress\x12N\n" + - "\x04Ping\x12\x10.express.Request\x1a\x11.express.Response\"!\x82\xd3\xe4\x93\x02\x1b:\x01*\"\x16/admin/v3/express/ping\x12U\n" + - "\x05Items\x12\x15.express.EmtpyRequest\x1a\x11.express.Response\"\"\x82\xd3\xe4\x93\x02\x1c:\x01*\"\x17/admin/v3/express/itemsB\vZ\t./expressb\x06proto3" + "\fEmtpyRequest\"\xb5\x03\n" + + "\rCreateRequest\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x12\n" + + "\x04name\x18\x02 \x01(\tR\x04name\x12\x1d\n" + + "\n" + + "transit_id\x18\x03 \x01(\x05R\ttransitId\x12\x19\n" + + "\bapp_code\x18\x04 \x01(\tR\aappCode\x12$\n" + + "\x0eapp_secret_key\x18\x05 \x01(\tR\fappSecretKey\x12\x17\n" + + "\aapp_url\x18\x06 \x01(\tR\x06appUrl\x12\x1f\n" + + "\vcard_number\x18\a \x01(\tR\n" + + "cardNumber\x12\x1a\n" + + "\bprovince\x18\b \x01(\tR\bprovince\x12\x12\n" + + "\x04city\x18\t \x01(\tR\x04city\x12\x16\n" + + "\x06county\x18\n" + + " \x01(\tR\x06county\x12\x18\n" + + "\aaddress\x18\v \x01(\tR\aaddress\x12!\n" + + "\fcompany_name\x18\f \x01(\tR\vcompanyName\x12\x18\n" + + "\acontact\x18\r \x01(\tR\acontact\x12\x16\n" + + "\x06mobile\x18\x0e \x01(\tR\x06mobile\x12\x19\n" + + "\bpdf_code\x18\x0f \x01(\tR\apdfCode\x12\x14\n" + + "\x05other\x18\x10 \x01(\tR\x05other\"\x1b\n" + + "\tIdRequest\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\"O\n" + + "\rStatusRequest\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x16\n" + + "\x06status\x18\x02 \x01(\x05R\x06status\x12\x16\n" + + "\x06reason\x18\x03 \x01(\tR\x06reason2\x93\x04\n" + + "\aExpress\x12U\n" + + "\x05Items\x12\x15.express.EmtpyRequest\x1a\x11.express.Response\"\"\x82\xd3\xe4\x93\x02\x1c:\x01*\x12\x17/admin/v3/express/items\x12X\n" + + "\x06Create\x12\x16.express.CreateRequest\x1a\x11.express.Response\"#\x82\xd3\xe4\x93\x02\x1d:\x01*\"\x18/admin/v3/express/create\x12T\n" + + "\x04Edit\x12\x16.express.CreateRequest\x1a\x11.express.Response\"!\x82\xd3\xe4\x93\x02\x1b:\x01*\"\x16/admin/v3/express/edit\x12P\n" + + "\x04Info\x12\x12.express.IdRequest\x1a\x11.express.Response\"!\x82\xd3\xe4\x93\x02\x1b:\x01*\x12\x16/admin/v3/express/info\x12U\n" + + "\x05Names\x12\x15.express.EmtpyRequest\x1a\x11.express.Response\"\"\x82\xd3\xe4\x93\x02\x1c:\x01*\x12\x17/admin/v3/express/names\x12X\n" + + "\x06Status\x12\x16.express.StatusRequest\x1a\x11.express.Response\"#\x82\xd3\xe4\x93\x02\x1d:\x01*\"\x18/admin/v3/express/statusB\vZ\t./expressb\x06proto3" var ( file_express_express_proto_rawDescOnce sync.Once @@ -190,19 +442,29 @@ func file_express_express_proto_rawDescGZIP() []byte { return file_express_express_proto_rawDescData } -var file_express_express_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_express_express_proto_msgTypes = make([]protoimpl.MessageInfo, 5) var file_express_express_proto_goTypes = []any{ - (*Request)(nil), // 0: express.Request - (*Response)(nil), // 1: express.Response - (*EmtpyRequest)(nil), // 2: express.EmtpyRequest + (*Response)(nil), // 0: express.Response + (*EmtpyRequest)(nil), // 1: express.EmtpyRequest + (*CreateRequest)(nil), // 2: express.CreateRequest + (*IdRequest)(nil), // 3: express.IdRequest + (*StatusRequest)(nil), // 4: express.StatusRequest } var file_express_express_proto_depIdxs = []int32{ - 0, // 0: express.Express.Ping:input_type -> express.Request - 2, // 1: express.Express.Items:input_type -> express.EmtpyRequest - 1, // 2: express.Express.Ping:output_type -> express.Response - 1, // 3: express.Express.Items:output_type -> express.Response - 2, // [2:4] is the sub-list for method output_type - 0, // [0:2] is the sub-list for method input_type + 1, // 0: express.Express.Items:input_type -> express.EmtpyRequest + 2, // 1: express.Express.Create:input_type -> express.CreateRequest + 2, // 2: express.Express.Edit:input_type -> express.CreateRequest + 3, // 3: express.Express.Info:input_type -> express.IdRequest + 1, // 4: express.Express.Names:input_type -> express.EmtpyRequest + 4, // 5: express.Express.Status:input_type -> express.StatusRequest + 0, // 6: express.Express.Items:output_type -> express.Response + 0, // 7: express.Express.Create:output_type -> express.Response + 0, // 8: express.Express.Edit:output_type -> express.Response + 0, // 9: express.Express.Info:output_type -> express.Response + 0, // 10: express.Express.Names:output_type -> express.Response + 0, // 11: express.Express.Status:output_type -> express.Response + 6, // [6:12] is the sub-list for method output_type + 0, // [0:6] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name @@ -219,7 +481,7 @@ func file_express_express_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_express_express_proto_rawDesc), len(file_express_express_proto_rawDesc)), NumEnums: 0, - NumMessages: 3, + NumMessages: 5, NumExtensions: 0, NumServices: 1, }, diff --git a/rpc/express/pb/express_grpc.pb.go b/rpc/express/pb/express_grpc.pb.go index fd1c711..15d08db 100644 --- a/rpc/express/pb/express_grpc.pb.go +++ b/rpc/express/pb/express_grpc.pb.go @@ -19,16 +19,24 @@ import ( const _ = grpc.SupportPackageIsVersion9 const ( - Express_Ping_FullMethodName = "/express.Express/Ping" - Express_Items_FullMethodName = "/express.Express/Items" + Express_Items_FullMethodName = "/express.Express/Items" + Express_Create_FullMethodName = "/express.Express/Create" + Express_Edit_FullMethodName = "/express.Express/Edit" + Express_Info_FullMethodName = "/express.Express/Info" + Express_Names_FullMethodName = "/express.Express/Names" + Express_Status_FullMethodName = "/express.Express/Status" ) // ExpressClient is the client API for Express service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type ExpressClient interface { - Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) Items(ctx context.Context, in *EmtpyRequest, opts ...grpc.CallOption) (*Response, error) + Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error) + Edit(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error) + Info(ctx context.Context, in *IdRequest, opts ...grpc.CallOption) (*Response, error) + Names(ctx context.Context, in *EmtpyRequest, opts ...grpc.CallOption) (*Response, error) + Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error) } type expressClient struct { @@ -39,16 +47,6 @@ func NewExpressClient(cc grpc.ClientConnInterface) ExpressClient { return &expressClient{cc} } -func (c *expressClient) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(Response) - err := c.cc.Invoke(ctx, Express_Ping_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *expressClient) Items(ctx context.Context, in *EmtpyRequest, opts ...grpc.CallOption) (*Response, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(Response) @@ -59,12 +57,66 @@ func (c *expressClient) Items(ctx context.Context, in *EmtpyRequest, opts ...grp return out, nil } +func (c *expressClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Express_Create_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *expressClient) Edit(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Express_Edit_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *expressClient) Info(ctx context.Context, in *IdRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Express_Info_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *expressClient) Names(ctx context.Context, in *EmtpyRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Express_Names_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *expressClient) Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Express_Status_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // ExpressServer is the server API for Express service. // All implementations must embed UnimplementedExpressServer // for forward compatibility. type ExpressServer interface { - Ping(context.Context, *Request) (*Response, error) Items(context.Context, *EmtpyRequest) (*Response, error) + Create(context.Context, *CreateRequest) (*Response, error) + Edit(context.Context, *CreateRequest) (*Response, error) + Info(context.Context, *IdRequest) (*Response, error) + Names(context.Context, *EmtpyRequest) (*Response, error) + Status(context.Context, *StatusRequest) (*Response, error) mustEmbedUnimplementedExpressServer() } @@ -75,12 +127,24 @@ type ExpressServer interface { // pointer dereference when methods are called. type UnimplementedExpressServer struct{} -func (UnimplementedExpressServer) Ping(context.Context, *Request) (*Response, error) { - return nil, status.Error(codes.Unimplemented, "method Ping not implemented") -} func (UnimplementedExpressServer) Items(context.Context, *EmtpyRequest) (*Response, error) { return nil, status.Error(codes.Unimplemented, "method Items not implemented") } +func (UnimplementedExpressServer) Create(context.Context, *CreateRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method Create not implemented") +} +func (UnimplementedExpressServer) Edit(context.Context, *CreateRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method Edit not implemented") +} +func (UnimplementedExpressServer) Info(context.Context, *IdRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method Info not implemented") +} +func (UnimplementedExpressServer) Names(context.Context, *EmtpyRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method Names not implemented") +} +func (UnimplementedExpressServer) Status(context.Context, *StatusRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method Status not implemented") +} func (UnimplementedExpressServer) mustEmbedUnimplementedExpressServer() {} func (UnimplementedExpressServer) testEmbeddedByValue() {} @@ -102,24 +166,6 @@ func RegisterExpressServer(s grpc.ServiceRegistrar, srv ExpressServer) { s.RegisterService(&Express_ServiceDesc, srv) } -func _Express_Ping_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(Request) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ExpressServer).Ping(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Express_Ping_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ExpressServer).Ping(ctx, req.(*Request)) - } - return interceptor(ctx, in, info, handler) -} - func _Express_Items_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(EmtpyRequest) if err := dec(in); err != nil { @@ -138,6 +184,96 @@ func _Express_Items_Handler(srv interface{}, ctx context.Context, dec func(inter return interceptor(ctx, in, info, handler) } +func _Express_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ExpressServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Express_Create_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ExpressServer).Create(ctx, req.(*CreateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Express_Edit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ExpressServer).Edit(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Express_Edit_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ExpressServer).Edit(ctx, req.(*CreateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Express_Info_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(IdRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ExpressServer).Info(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Express_Info_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ExpressServer).Info(ctx, req.(*IdRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Express_Names_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EmtpyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ExpressServer).Names(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Express_Names_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ExpressServer).Names(ctx, req.(*EmtpyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Express_Status_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(StatusRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ExpressServer).Status(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Express_Status_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ExpressServer).Status(ctx, req.(*StatusRequest)) + } + return interceptor(ctx, in, info, handler) +} + // Express_ServiceDesc is the grpc.ServiceDesc for Express service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -145,14 +281,30 @@ var Express_ServiceDesc = grpc.ServiceDesc{ ServiceName: "express.Express", HandlerType: (*ExpressServer)(nil), Methods: []grpc.MethodDesc{ - { - MethodName: "Ping", - Handler: _Express_Ping_Handler, - }, { MethodName: "Items", Handler: _Express_Items_Handler, }, + { + MethodName: "Create", + Handler: _Express_Create_Handler, + }, + { + MethodName: "Edit", + Handler: _Express_Edit_Handler, + }, + { + MethodName: "Info", + Handler: _Express_Info_Handler, + }, + { + MethodName: "Names", + Handler: _Express_Names_Handler, + }, + { + MethodName: "Status", + Handler: _Express_Status_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "express/express.proto", diff --git a/rpc/order/order.pb b/rpc/order/order.pb index 337aaf6..46626dd 100644 Binary files a/rpc/order/order.pb and b/rpc/order/order.pb differ diff --git a/rpc/order/order.proto b/rpc/order/order.proto index 6dedb70..83c8b1e 100644 --- a/rpc/order/order.proto +++ b/rpc/order/order.proto @@ -27,6 +27,7 @@ message Response { message CreateOrderRequest { int64 address_id = 1; string note = 2; + int32 type = 3; } message CreateOrderOneRequest { @@ -34,6 +35,7 @@ message CreateOrderOneRequest { string note = 2; int64 productid = 3; int32 num = 4; + int32 type = 5; } message EditAddressRequest { diff --git a/rpc/order/pb/order.pb.go b/rpc/order/pb/order.pb.go index c415883..28198ec 100644 --- a/rpc/order/pb/order.pb.go +++ b/rpc/order/pb/order.pb.go @@ -194,6 +194,7 @@ type CreateOrderRequest struct { state protoimpl.MessageState `protogen:"open.v1"` AddressId int64 `protobuf:"varint,1,opt,name=address_id,json=addressId,proto3" json:"address_id,omitempty"` Note string `protobuf:"bytes,2,opt,name=note,proto3" json:"note,omitempty"` + Type int32 `protobuf:"varint,3,opt,name=type,proto3" json:"type,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -242,12 +243,20 @@ func (x *CreateOrderRequest) GetNote() string { return "" } +func (x *CreateOrderRequest) GetType() int32 { + if x != nil { + return x.Type + } + return 0 +} + type CreateOrderOneRequest struct { state protoimpl.MessageState `protogen:"open.v1"` AddressId int64 `protobuf:"varint,1,opt,name=address_id,json=addressId,proto3" json:"address_id,omitempty"` Note string `protobuf:"bytes,2,opt,name=note,proto3" json:"note,omitempty"` Productid int64 `protobuf:"varint,3,opt,name=productid,proto3" json:"productid,omitempty"` Num int32 `protobuf:"varint,4,opt,name=num,proto3" json:"num,omitempty"` + Type int32 `protobuf:"varint,5,opt,name=type,proto3" json:"type,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -310,6 +319,13 @@ func (x *CreateOrderOneRequest) GetNum() int32 { return 0 } +func (x *CreateOrderOneRequest) GetType() int32 { + if x != nil { + return x.Type + } + return 0 +} + type EditAddressRequest struct { state protoimpl.MessageState `protogen:"open.v1"` District string `protobuf:"bytes,1,opt,name=district,proto3" json:"district,omitempty"` @@ -1033,17 +1049,19 @@ const file_order_order_proto_rawDesc = "" + "\bResponse\x12\x12\n" + "\x04code\x18\x01 \x01(\x05R\x04code\x12\x10\n" + "\x03msg\x18\x02 \x01(\tR\x03msg\x12\x12\n" + - "\x04data\x18\x03 \x01(\tR\x04data\"G\n" + + "\x04data\x18\x03 \x01(\tR\x04data\"[\n" + "\x12CreateOrderRequest\x12\x1d\n" + "\n" + "address_id\x18\x01 \x01(\x03R\taddressId\x12\x12\n" + - "\x04note\x18\x02 \x01(\tR\x04note\"z\n" + + "\x04note\x18\x02 \x01(\tR\x04note\x12\x12\n" + + "\x04type\x18\x03 \x01(\x05R\x04type\"\x8e\x01\n" + "\x15CreateOrderOneRequest\x12\x1d\n" + "\n" + "address_id\x18\x01 \x01(\x03R\taddressId\x12\x12\n" + "\x04note\x18\x02 \x01(\tR\x04note\x12\x1c\n" + "\tproductid\x18\x03 \x01(\x03R\tproductid\x12\x10\n" + - "\x03num\x18\x04 \x01(\x05R\x03num\"\xd7\x01\n" + + "\x03num\x18\x04 \x01(\x05R\x03num\x12\x12\n" + + "\x04type\x18\x05 \x01(\x05R\x04type\"\xd7\x01\n" + "\x12EditAddressRequest\x12\x1a\n" + "\bdistrict\x18\x01 \x01(\tR\bdistrict\x12\x18\n" + "\aaddress\x18\x02 \x01(\tR\aaddress\x12\x12\n" + diff --git a/services/express/express.go b/services/express/express.go index 1a5dd28..348b24c 100644 --- a/services/express/express.go +++ b/services/express/express.go @@ -3,6 +3,7 @@ package main import ( "flag" "lone-services/pkg/discovery" + "lone-services/pkg/logRedis" "lone-services/pkg/modelbase" "lone-services/pkg/mysql" "lone-services/pkg/redis" @@ -124,6 +125,16 @@ func main() { os.Exit(1) } + if err := logRedis.Init(logRedis.LogRedisConfig{ + Host: utils.GetConfigString("log-redis.host"), + Port: utils.GetConfigInt("log-redis.port"), + Password: utils.GetConfigString("log-redis.password"), + DB: utils.GetConfigInt("log-redis.db"), + }); err != nil { + logx.Errorf("log redis init: %v", err) + os.Exit(1) + } + debug := utils.GetConfigBool("mysql.debug") modelbase.Init(db, modelbase.Config{Prefix: utils.GetConfigString("mysql.prefix"), Debug: debug}) diff --git a/services/express/expressclient/express.go b/services/express/expressclient/express.go index 263ce84..d842cde 100644 --- a/services/express/expressclient/express.go +++ b/services/express/expressclient/express.go @@ -14,13 +14,19 @@ import ( ) type ( - EmtpyRequest = express.EmtpyRequest - Request = express.Request - Response = express.Response + CreateRequest = express.CreateRequest + EmtpyRequest = express.EmtpyRequest + IdRequest = express.IdRequest + Response = express.Response + StatusRequest = express.StatusRequest Express interface { - Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) Items(ctx context.Context, in *EmtpyRequest, opts ...grpc.CallOption) (*Response, error) + Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error) + Edit(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error) + Info(ctx context.Context, in *IdRequest, opts ...grpc.CallOption) (*Response, error) + Names(ctx context.Context, in *EmtpyRequest, opts ...grpc.CallOption) (*Response, error) + Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error) } defaultExpress struct { @@ -34,12 +40,32 @@ func NewExpress(cli zrpc.Client) Express { } } -func (m *defaultExpress) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) { - client := express.NewExpressClient(m.cli.Conn()) - return client.Ping(ctx, in, opts...) -} - func (m *defaultExpress) Items(ctx context.Context, in *EmtpyRequest, opts ...grpc.CallOption) (*Response, error) { client := express.NewExpressClient(m.cli.Conn()) return client.Items(ctx, in, opts...) } + +func (m *defaultExpress) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error) { + client := express.NewExpressClient(m.cli.Conn()) + return client.Create(ctx, in, opts...) +} + +func (m *defaultExpress) Edit(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error) { + client := express.NewExpressClient(m.cli.Conn()) + return client.Edit(ctx, in, opts...) +} + +func (m *defaultExpress) Info(ctx context.Context, in *IdRequest, opts ...grpc.CallOption) (*Response, error) { + client := express.NewExpressClient(m.cli.Conn()) + return client.Info(ctx, in, opts...) +} + +func (m *defaultExpress) Names(ctx context.Context, in *EmtpyRequest, opts ...grpc.CallOption) (*Response, error) { + client := express.NewExpressClient(m.cli.Conn()) + return client.Names(ctx, in, opts...) +} + +func (m *defaultExpress) Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error) { + client := express.NewExpressClient(m.cli.Conn()) + return client.Status(ctx, in, opts...) +} diff --git a/services/express/internal/dao/express.go b/services/express/internal/dao/express.go new file mode 100644 index 0000000..3bd0a4f --- /dev/null +++ b/services/express/internal/dao/express.go @@ -0,0 +1,55 @@ +package dao + +type Express struct { + Id int64 `json:"id" gorm:"id"` // ID + Name string `json:"name" gorm:"name"` // 名称 + TransitId uint8 `json:"transit_id" gorm:"transit_id"` // 快递公司,1为顺丰,2为京东,3为。。。 + AppCode string `json:"app_code" gorm:"app_code"` // app 代码 + AppSecretKey string `json:"app_secret_key" gorm:"app_secret_key"` // app 密钥 + AppUrl string `json:"app_url" gorm:"app_url"` // 接口地址 + CardNumber string `json:"card_number" gorm:"card_number"` // 月结卡号 + PdfCode string `json:"pdf_code" gorm:"pdf_code"` // pdf文件编码 + Province string `json:"province" gorm:"province"` // 省 + City string `json:"city" gorm:"city"` // 市 + County string `json:"county" gorm:"county"` // 县/区 + Address string `json:"address" gorm:"address"` // 地址 + CompanyName string `json:"company_name" gorm:"company_name"` // 公司名 + Contact string `json:"contact" gorm:"contact"` // 联系人 + Mobile string `json:"mobile" gorm:"mobile"` // 联系人手机号 + Other string `json:"other" gorm:"other"` // 基它数据 + Status uint8 `json:"status" gorm:"status"` // 状态,1为正常,2为禁用 + Reason string `json:"reason" gorm:"reason"` // 原因 + AdminId int64 `json:"admin_id" gorm:"admin_id"` // 操作人ID + AdminName string `json:"admin_name" gorm:"admin_name"` // 操作人姓名 +} +type ExpressInfo struct { + Id int64 `json:"id" gorm:"id"` // ID + Name string `json:"name" gorm:"name"` // 名称 + TransitId uint8 `json:"transit_id" gorm:"transit_id"` // 快递公司,1为顺丰,2为京东,3为。。。 + AppCode string `json:"app_code" gorm:"app_code"` // app 代码 + AppSecretKey string `json:"app_secret_key" gorm:"app_secret_key"` // app 密钥 + AppUrl string `json:"app_url" gorm:"app_url"` // 接口地址 + CardNumber string `json:"card_number" gorm:"card_number"` // 月结卡号 + PdfCode string `json:"pdf_code" gorm:"pdf_code"` // pdf文件编码 + Province string `json:"province" gorm:"province"` // 省 + City string `json:"city" gorm:"city"` // 市 + County string `json:"county" gorm:"county"` // 县/区 + Address string `json:"address" gorm:"address"` // 地址 + CompanyName string `json:"company_name" gorm:"company_name"` // 公司名 + Contact string `json:"contact" gorm:"contact"` // 联系人 + Mobile string `json:"mobile" gorm:"mobile"` // 联系人手机号 + Other string `json:"other" gorm:"other"` // 基它数据 + Status uint8 `json:"status" gorm:"status"` // 状态,1为正常,2为禁用 + Reason string `json:"reason" gorm:"reason"` // 原因 +} + +type ExpressNames struct { + Id int64 `json:"id" gorm:"id"` // ID + Name string `json:"name" gorm:"name"` // 名称 +} + +type ExpressStatus struct { + Id int64 `json:"id" gorm:"id"` // ID + Status uint8 `json:"status" gorm:"status"` // 状态,1为正常,2为禁用 + Reason string `json:"reason" gorm:"reason"` // 原因 +} diff --git a/services/express/internal/logic/createLogic.go b/services/express/internal/logic/createLogic.go new file mode 100644 index 0000000..6d73b62 --- /dev/null +++ b/services/express/internal/logic/createLogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "lone-services/rpc/express/pb" + "lone-services/services/express/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type CreateLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLogic { + return &CreateLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *CreateLogic) Create(in *express.CreateRequest) (*express.Response, error) { + // todo: add your logic here and delete this line + + return &express.Response{}, nil +} diff --git a/services/express/internal/logic/pinglogic.go b/services/express/internal/logic/editLogic.go similarity index 55% rename from services/express/internal/logic/pinglogic.go rename to services/express/internal/logic/editLogic.go index ef3efb3..c751486 100644 --- a/services/express/internal/logic/pinglogic.go +++ b/services/express/internal/logic/editLogic.go @@ -2,30 +2,30 @@ package logic import ( "context" - express "lone-services/rpc/express/pb" + "lone-services/rpc/express/pb" "lone-services/services/express/internal/svc" "github.com/zeromicro/go-zero/core/logx" ) -type PingLogic struct { +type EditLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger BaseLogic } -func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic { - return &PingLogic{ +func NewEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditLogic { + return &EditLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } -func (l *PingLogic) Ping(in *express.Request) (*express.Response, error) { +func (l *EditLogic) Edit(in *express.CreateRequest) (*express.Response, error) { // todo: add your logic here and delete this line - return l.ok("this is a test") + return &express.Response{}, nil } diff --git a/services/express/internal/logic/infoLogic.go b/services/express/internal/logic/infoLogic.go new file mode 100644 index 0000000..d6829bb --- /dev/null +++ b/services/express/internal/logic/infoLogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "lone-services/rpc/express/pb" + "lone-services/services/express/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type InfoLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoLogic { + return &InfoLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *InfoLogic) Info(in *express.IdRequest) (*express.Response, error) { + // todo: add your logic here and delete this line + + return &express.Response{}, nil +} diff --git a/services/express/internal/logic/itemsLogic.go b/services/express/internal/logic/itemsLogic.go index 01d7980..c7b7876 100644 --- a/services/express/internal/logic/itemsLogic.go +++ b/services/express/internal/logic/itemsLogic.go @@ -2,8 +2,10 @@ package logic import ( "context" - + "lone-services/pkg/modelbase" "lone-services/rpc/express/pb" + "lone-services/services/express/internal/dao" + "lone-services/services/express/internal/model" "lone-services/services/express/internal/svc" "github.com/zeromicro/go-zero/core/logx" @@ -13,6 +15,7 @@ type ItemsLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger + BaseLogic } func NewItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsLogic { @@ -24,7 +27,12 @@ func NewItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsLogic } func (l *ItemsLogic) Items(in *express.EmtpyRequest) (*express.Response, error) { - // todo: add your logic here and delete this line + modelObj := model.ExpressModel{}.Init() + w := modelbase.Params{} + + var data []dao.ExpressInfo + items, _ := modelObj.Page(w, &data) + + return l.ok(items) - return &express.Response{}, nil } diff --git a/services/express/internal/logic/namesLogic.go b/services/express/internal/logic/namesLogic.go new file mode 100644 index 0000000..102bb3f --- /dev/null +++ b/services/express/internal/logic/namesLogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "lone-services/rpc/express/pb" + "lone-services/services/express/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type NamesLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewNamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NamesLogic { + return &NamesLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *NamesLogic) Names(in *express.EmtpyRequest) (*express.Response, error) { + // todo: add your logic here and delete this line + + return &express.Response{}, nil +} diff --git a/services/express/internal/logic/statusLogic.go b/services/express/internal/logic/statusLogic.go new file mode 100644 index 0000000..dafba27 --- /dev/null +++ b/services/express/internal/logic/statusLogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "lone-services/rpc/express/pb" + "lone-services/services/express/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type StatusLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatusLogic { + return &StatusLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *StatusLogic) Status(in *express.StatusRequest) (*express.Response, error) { + // todo: add your logic here and delete this line + + return &express.Response{}, nil +} diff --git a/services/express/internal/model/express.go b/services/express/internal/model/express.go new file mode 100644 index 0000000..d074902 --- /dev/null +++ b/services/express/internal/model/express.go @@ -0,0 +1,23 @@ +package model + +import ( + "lone-services/pkg/modelbase" + "lone-services/services/express/internal/dao" +) + +type ExpressModel struct { + modelbase.Base +} + +func (m ExpressModel) TableName() string { + return modelbase.Prefix() + "express" +} + +func (m ExpressModel) Init() ExpressModel { + m.Table = m.TableName() + return m +} + +func (m ExpressModel) Create(data *dao.Express) error { + return m.Base.Create(data) +} diff --git a/services/express/internal/server/expressServer.go b/services/express/internal/server/expressServer.go index 1f51ebe..ddff4bf 100644 --- a/services/express/internal/server/expressServer.go +++ b/services/express/internal/server/expressServer.go @@ -23,12 +23,32 @@ func NewExpressServer(svcCtx *svc.ServiceContext) *ExpressServer { } } -func (s *ExpressServer) Ping(ctx context.Context, in *express.Request) (*express.Response, error) { - l := logic.NewPingLogic(ctx, s.svcCtx) - return l.Ping(in) -} - func (s *ExpressServer) Items(ctx context.Context, in *express.EmtpyRequest) (*express.Response, error) { l := logic.NewItemsLogic(ctx, s.svcCtx) return l.Items(in) } + +func (s *ExpressServer) Create(ctx context.Context, in *express.CreateRequest) (*express.Response, error) { + l := logic.NewCreateLogic(ctx, s.svcCtx) + return l.Create(in) +} + +func (s *ExpressServer) Edit(ctx context.Context, in *express.CreateRequest) (*express.Response, error) { + l := logic.NewEditLogic(ctx, s.svcCtx) + return l.Edit(in) +} + +func (s *ExpressServer) Info(ctx context.Context, in *express.IdRequest) (*express.Response, error) { + l := logic.NewInfoLogic(ctx, s.svcCtx) + return l.Info(in) +} + +func (s *ExpressServer) Names(ctx context.Context, in *express.EmtpyRequest) (*express.Response, error) { + l := logic.NewNamesLogic(ctx, s.svcCtx) + return l.Names(in) +} + +func (s *ExpressServer) Status(ctx context.Context, in *express.StatusRequest) (*express.Response, error) { + l := logic.NewStatusLogic(ctx, s.svcCtx) + return l.Status(in) +} diff --git a/services/express/validator/express.go b/services/express/validator/express.go new file mode 100644 index 0000000..c2d6dfc --- /dev/null +++ b/services/express/validator/express.go @@ -0,0 +1,60 @@ +package validator + +import "lone-services/pkg/validate" + +type EditValidator struct { + Id int64 `validate:""` + Name string `validate:"required"` + TransitId int32 `validate:"required"` + AppCode string `validate:"required"` + AppSecretKey string `validate:"required"` + AppUrl string `validate:"required"` + CardNumber string `validate:"required"` + Province string + City string + County string + Address string + CompanyName string + Contact string + Mobile string + PdfCode string + Other string +} + +// GetMessage 校验提示消息 +func (p EditValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Name.required": "请输入名称", + "TransitId.required": "缺少快递ID", + "AppCode.required": "请输入APP代码", + "AppSecretKey.required": "请输入APP密钥", + "AppUrl.required": "请输入接口地址", + "CardNumber.required": "请输入月结卡号", + } +} + +type StatusValidator struct { + Id int64 `validate:"required"` + Status int32 `validate:"required,oneof=1 2"` + Reason string `validate:"required_if=Status 2"` +} + +// GetMessage 修改状态 - 提示消息 +func (p StatusValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Id.required": "ID不能为空", + "Status.required": "状态不能为空", + "Status.oneof": "状态传值不对", + "Reason.required_if": "理由不能为空", + } +} + +type InfoValidator struct { + Id int64 `validate:"required"` +} + +func (p InfoValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Id.required": "ID不能为空", + } +} diff --git a/services/order/internal/dao/cart.go b/services/order/internal/dao/cart.go index 55ca739..f3ee22a 100644 --- a/services/order/internal/dao/cart.go +++ b/services/order/internal/dao/cart.go @@ -16,3 +16,12 @@ type Cart struct { type CartInfo struct { Content string `json:"content" gorm:"content"` // 内容 } + +type ProductInfo struct { + Id int64 `json:"id" gorm:"id"` + Price float64 `json:"price" gorm:"price"` + Number int `json:"number" gorm:"number"` + Name string `json:"name" gorm:"name"` + Images string `json:"images" gorm:"images"` + Stock int `json:"stock" gorm:"stock"` +} diff --git a/services/order/internal/dao/order.go b/services/order/internal/dao/order.go index aab1a6f..9e46bf2 100644 --- a/services/order/internal/dao/order.go +++ b/services/order/internal/dao/order.go @@ -22,30 +22,32 @@ 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"` - 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"` - SaleMobile string `gorm:"column:sale_mobile;type:char(60);comment:销售电话" json:"sale_mobile"` - SaleProvince int `gorm:"column:sale_province;type:int(11);default:0;comment:销售到的地域" json:"sale_province"` - UserId int `gorm:"column:user_id;type:int(11);comment:用户ID" json:"user_id"` - UserName string `gorm:"column:user_name;type:varchar(255);comment:用户名" json:"user_name"` - SaleId int `gorm:"column:sale_id;type:int(11);comment:销售员ID号" json:"sale_id"` - Mobile string `gorm:"column:mobile;type:char(60);comment:收货人手机号;NOT NULL" json:"mobile"` - Address string `gorm:"column:address;type:varchar(255);comment:收货人地址;NOT NULL" json:"address"` - Addressee string `gorm:"column:addressee;type:varchar(50);comment:收货人姓名;NOT NULL" json:"addressee"` - DistrictIds string `gorm:"column:district_ids;type:varchar(255);comment:地区IDS;NOT NULL" json:"district_ids"` - TotalPrice float64 `gorm:"column:total_price;type:decimal(10,2);comment:总价;NOT NULL" json:"total_price"` - GroupId int `gorm:"column:group_id;type:int(11);default:0" json:"group_id"` - PayPrice float64 `gorm:"column:pay_price;type:decimal(10,2);comment:实际支付金额" json:"pay_price"` - PayType uint8 `gorm:"column:pay_type;type:tinyint(1);default:1;comment:支付类型,1为微信,2为支付宝,3为余额支付" json:"pay_type"` - Status uint8 `gorm:"column:status;type:tinyint(1);default:2;comment:支付状态,1为已支付,2为未支付,3为支付中,4支付失败,5已失效;NOT NULL" json:"status"` - IsSupply uint8 `gorm:"column:is_supply;type:tinyint(1);default:1;comment:是否补过货,1为没有,2为补过" json:"is_supply"` - Note string `gorm:"column:note;type:varchar(255);comment:备注" json:"note"` - VerifyStatus uint8 `gorm:"column:verify_status;type:tinyint(1);default:0;comment:审核状态,1为通过,2为失败,3为待审核,0为正常订单不需要审核" json:"verify_status"` - ProductIds string `gorm:"column:product_ids;type:varchar(150);comment:产品IDs" json:"product_ids"` - Type uint8 `gorm:"column:type;type:tinyint(1);default:0;comment:类型 1 销售,2为门店,3为个人,4为个人家庭试用,5为个人门店试用" json:"type"` + 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"` + 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"` + SaleMobile string `gorm:"column:sale_mobile;type:char(60);comment:销售电话" json:"sale_mobile"` + SaleProvince int `gorm:"column:sale_province;type:int(11);default:0;comment:销售到的地域" json:"sale_province"` + UserId int `gorm:"column:user_id;type:int(11);comment:用户ID" json:"user_id"` + UserName string `gorm:"column:user_name;type:varchar(255);comment:用户名" json:"user_name"` + SaleId int `gorm:"column:sale_id;type:int(11);comment:销售员ID号" json:"sale_id"` + Mobile string `gorm:"column:mobile;type:char(60);comment:收货人手机号;NOT NULL" json:"mobile"` + Address string `gorm:"column:address;type:varchar(255);comment:收货人地址;NOT NULL" json:"address"` + Addressee string `gorm:"column:addressee;type:varchar(50);comment:收货人姓名;NOT NULL" json:"addressee"` + DistrictIds string `gorm:"column:district_ids;type:varchar(255);comment:地区IDS;NOT NULL" json:"district_ids"` + TotalPrice float64 `gorm:"column:total_price;type:decimal(10,2);comment:总价;NOT NULL" json:"total_price"` + GroupId int `gorm:"column:group_id;type:int(11);default:0" json:"group_id"` + PayPrice float64 `gorm:"column:pay_price;type:decimal(10,2);comment:实际支付金额" json:"pay_price"` + PayType uint8 `gorm:"column:pay_type;type:tinyint(1);default:1;comment:支付类型,1为微信,2为支付宝,3为余额支付" json:"pay_type"` + Status uint8 `gorm:"column:status;type:tinyint(1);default:2;comment:支付状态,1为已支付,2为未支付,3为支付中,4支付失败,5已失效;NOT NULL" json:"status"` + IsSupply uint8 `gorm:"column:is_supply;type:tinyint(1);default:1;comment:是否补过货,1为没有,2为补过" json:"is_supply"` + Note string `gorm:"column:note;type:varchar(255);comment:备注" json:"note"` + VerifyStatus uint8 `gorm:"column:verify_status;type:tinyint(1);default:0;comment:审核状态,1为通过,2为失败,3为待审核,0为正常订单不需要审核" json:"verify_status"` + ExpiredTime utils.CustomTime `json:"expired_time" gorm:"expired_time"` // 过期时间 + ProductIds string `gorm:"column:product_ids;type:varchar(150);comment:产品IDs" json:"product_ids"` + CreateType uint8 `gorm:"column:create_type;type:tinyint(1);default:1;comment:下单人类型,1为销售,2为门店,3为个人;NOT NULL" json:"create_type"` + Type uint8 `gorm:"column:type;type:tinyint(1);default:0;comment:类型 1 销售,2为门店,3为个人,4为个人家庭试用,5为个人门店试用" json:"type"` } type OrderInfo struct { diff --git a/services/order/internal/logic/addressItemLogic.go b/services/order/internal/logic/addressItemLogic.go index 0dcf428..64b16ed 100644 --- a/services/order/internal/logic/addressItemLogic.go +++ b/services/order/internal/logic/addressItemLogic.go @@ -82,9 +82,7 @@ func (l *AddressItemLogic) AddressItem(in *order.AddressItemsRequest) (*order.Re mobile, aErr := utils.DecryptPhone(v.Mobile) if aErr == nil { info[key].AesMobile = v.Mobile - l.Logger.Error(mobile) info[key].Mobile = utils.DecryptPhoneReplace(mobile) - l.Logger.Error(utils.DecryptPhoneReplace(mobile)) } } return l.ok(info) diff --git a/services/order/internal/logic/itemsLogic.go b/services/order/internal/logic/itemsLogic.go index ef7867b..cf43517 100644 --- a/services/order/internal/logic/itemsLogic.go +++ b/services/order/internal/logic/itemsLogic.go @@ -2,6 +2,12 @@ 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" order "lone-services/rpc/order/pb" "lone-services/services/order/internal/svc" @@ -25,16 +31,67 @@ func NewItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsLogic } func (l *ItemsLogic) Items(in *order.OrderItemsRequest) (*order.Response, error) { - //调用其它服务实例 - //cli, err := svc.GetRpcClient(l.svcCtx.ExpressSvcName) - //if err != nil { - // l.Logger.Errorf("get express rpc err: %v", err) - // //降级逻辑 - // return l.out(utils.ErrorInternalServer, "express"+utils.ErrorInternalServer.Msg) - //} - //expClient := express.NewExpressClient(cli.Conn()) - //res, _ := expClient.Ping(context.Background(), &express.Request{}) - //l.Logger.Error("res: %v", res) + var v validator.OrderItemsValidator + 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.OrderInfo + w := modelbase.Params{ + Page: int(in.Page), + Size: int(in.Size), + Order: "id desc", + } + + w.Like = make(map[string]string) + w.Eq = make(map[string]string) + w.Other = make(map[string]string) + if in.ProductId > utils.NumberZero { + w.Other["FIND_IN_SET(?, product_ids)"] = strconv.FormatInt(in.ProductId, utils.NumberTen) + } + + //Time string + if len(in.Mobile) > utils.NumberZero { + phone := utils.GetSearchPhone(in.Mobile) + if len(phone) > utils.NumberZero { + w.Like["mobile LIKE ? "] = "%%" + phone + "%%" + } + } + + if len(in.OrderSn) > utils.NumberZero { + w.Like["order_sn LIKE ? "] = "%%" + in.OrderSn + "%%" + } + + if in.StoreId > utils.NumberZero { + w.Eq["store_id"] = strconv.FormatInt(in.StoreId, utils.NumberTen) + } + if in.SaleId > utils.NumberZero { + w.Eq["sale_id"] = strconv.FormatInt(in.SaleId, utils.NumberTen) + } + if in.Status > utils.NumberZero { + w.Eq["status"] = string(in.Status) + } + + if len(in.Time) > utils.NumberZero { + w.Other["create_time > ?"] = strconv.Itoa(int(in.Time[utils.NumberZero])) + w.Other["create_time < ?"] = strconv.Itoa(int(in.Time[utils.NumberOne])) + } + + err := model.OrderModel{}.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) - return &order.Response{}, nil } diff --git a/services/order/internal/logic/webCreateLogic.go b/services/order/internal/logic/webCreateLogic.go index ed4445e..7c3c6ca 100644 --- a/services/order/internal/logic/webCreateLogic.go +++ b/services/order/internal/logic/webCreateLogic.go @@ -2,6 +2,13 @@ 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" + "strings" "lone-services/rpc/order/pb" "lone-services/services/order/internal/svc" @@ -25,7 +32,142 @@ func NewWebCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebCrea } func (l *WebCreateLogic) WebCreate(in *order.CreateOrderRequest) (*order.Response, error) { - // todo: add your logic here and delete this line + var v validator.OrderCreateValidator + 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, + } + + w = 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 + w.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) + 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 + w.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) + if err != nil { + return l.fail(utils.Fail) + } + if cart.Id < utils.NumberOne { + return l.out(utils.Fail, "购买信息不存在") + } + + ids, pErr := svc.GetCartInfo(cart.Content) + if pErr != utils.Ok { + return l.fail(utils.Fail) + } + products, pErr := svc.GetCartData(ids) + if pErr != utils.Ok { + return l.fail(utils.Fail) + } + keys := make([]string, utils.NumberZero, len(products)) + var totalPrice float64 + for _, item := range products { + keys = append(keys, strconv.Itoa(int(item.Id))) + totalPrice += item.Price * float64(item.Number) + } + data.ProductIds = strings.Join(keys, utils.DecollatorComma) + data.TotalPrice = totalPrice + + mobileObj := model.OrderModel{}.Init() + mobileObj.Begin() + err = mobileObj.Create(&data) + if err != nil { + mobileObj.Rollback() + 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) + 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; + } + + mobileObj.Commit() + + return l.ok(utils.NumberOne) } diff --git a/services/order/internal/svc/order.go b/services/order/internal/svc/order.go new file mode 100644 index 0000000..03bdded --- /dev/null +++ b/services/order/internal/svc/order.go @@ -0,0 +1,61 @@ +package svc + +import ( + "fmt" + "lone-services/pkg/utils" + "lone-services/services/order/internal/dao" + "math/rand" + "strconv" + "time" + + jsoniter "github.com/json-iterator/go" +) + +func GetOrderSn(orderType string, adminId int64) string { + now := time.Now().Format("20060102150405") + r := rand.New(rand.NewSource(time.Now().UnixNano())) + rnd := r.Intn(90000000) + 10000000 + + sn := fmt.Sprintf("O%s%s%d%d", now, orderType, adminId, rnd) + return sn +} + +func GetCartData(info map[string]int) ([]dao.ProductInfo, utils.Status) { + keys := make([]string, utils.NumberZero, len(info)) + for k := range info { + keys = append(keys, k) + } + //TODO keys 查询产品 + + var products []dao.ProductInfo + + 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 + err := jsoniter.Unmarshal([]byte(info), &list) + if err != nil { + return nil, utils.ErrorJsonDataError + } + + m := make(map[string]int, len(list)) + for _, item := range list { + if len(item) >= 2 { + m[strconv.Itoa(item[0])] = item[1] + } + } + return m, utils.Ok +} diff --git a/services/order/validator/order.go b/services/order/validator/order.go index 1ddb16e..a16c935 100644 --- a/services/order/validator/order.go +++ b/services/order/validator/order.go @@ -45,11 +45,32 @@ func (p AdminOrderCreateValidator) GetMessage() validate.ValidatorMessages { type OrderCreateValidator struct { AddressId int64 `validate:"required"` Note string + Type int32 `validate:"required,oneof=1 2 3"` //类型 1门店 , 2销售,3为用户 } func (p OrderCreateValidator) GetMessage() validate.ValidatorMessages { return validate.ValidatorMessages{ "AddressId.required": "地址ID不能为空", + "Type.required": "类型不能为空", + "Type.oneof": "类型不对", + } +} + +type OrderOneCreateValidator struct { + AddressId int64 `validate:"required"` + Note string + ProductId int64 `validate:"required"` + Num int32 `validate:"required"` + Type int32 `validate:"required,oneof=1 2 3"` //类型 1门店 , 2销售,3为用户 +} + +func (p OrderOneCreateValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "AddressId.required": "地址ID不能为空", + "Type.required": "类型不能为空", + "Type.oneof": "类型不对", + "ProductId.required": "产品不能为空", + "Num.required": "产品数量不能为空", } }