From a65efe577788bb7c5f3c2577055717c58db6b725 Mon Sep 17 00:00:00 2001 From: Hiven Date: Fri, 21 Jul 2023 18:17:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- constants/order.go | 20 ++- constants/webset.go | 8 + go.mod | 2 +- go.sum | 4 +- .../internal/logic/userorderlistlogic.go | 76 +++++---- server/home-user-auth/internal/types/types.go | 1 + server_api/home-user-auth.api | 35 +++-- utils/order/order_status.go | 147 +++++++++++++++++- 8 files changed, 245 insertions(+), 48 deletions(-) diff --git a/constants/order.go b/constants/order.go index 08fe2bac..79fa6497 100644 --- a/constants/order.go +++ b/constants/order.go @@ -122,7 +122,25 @@ const ( STATUS_FONT_COMPLETED_CLOUD Order = 8 ) +type Day int64 + // 订单取消时间 const ( - CANCLE_ORDER_EXPIRE int64 = 48 * 3600 + CANCLE_ORDER_EXPIRE Day = 48 * 3600 +) + +// 订单时间配置 +const ( + ORDER_PRODUCT_DAY Day = 25 //产品制作周期(天) + ORDER_FACTORY_DELIVER_DAY Day = 2 //厂家发货到货代周期(天) + ORDER_DELIVER_UPS_DAY Day = 35 //货代发货至UPS周期(天) + ORDER_UPS_TRANS_DAY Day = 5 //UPS运输周期(天) +) + +const ( + LOGISTICS_STATUS_DRAW Order = 1 + LOGISTICS_STATUS_SHIPPING Order = 2 + LOGISTICS_STATUS_UPS Order = 3 + LOGISTICS_STATUS_UPS_ARRIVAL Order = 4 + LOGISTICS_STATUS_ARRIVAL Order = 5 ) diff --git a/constants/webset.go b/constants/webset.go index 84a7f102..433359d2 100644 --- a/constants/webset.go +++ b/constants/webset.go @@ -17,4 +17,12 @@ const ( TEMPLATE_PRODUCT TypeWebSet = "product_template_" //模板数据 后接产品id CART_NUM TypeWebSet = "cart_num_" //购物车数量 后接uid USER_ORDERNO TypeWebSet = "order_no_" //用户最新订单编号 + + WEBSET_TIME_INFO TypeWebSet = "time_info" //配置时间 + + WEBSET_TIME_INFO_PRODUCT_DAY TypeWebSet = "product_day" //配置时间--产品制作周期(天) + WEBSET_TIME_INFO_FACTORY_DELIVER_DAY TypeWebSet = "factory_deliver_day" //配置时间--厂家发货到货代周期(天) + WEBSET_TIME_INFO_DELIVER_UPS_DAY TypeWebSet = "deliver_ups_day" //配置时间--货代发货至UPS周期(天) + WEBSET_TIME_INFO_UPS_TRANS_DAY TypeWebSet = "ups_trans_day" //配置时间--UPS运输周期(天) + ) diff --git a/go.mod b/go.mod index 97759c15..f586919c 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/google/uuid v1.3.0 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e - github.com/stripe/stripe-go/v74 v74.22.0 + github.com/stripe/stripe-go/v74 v74.26.0 github.com/zeromicro/go-zero v1.5.4 golang.org/x/image v0.0.0-20190802002840-cff245a6509b golang.org/x/oauth2 v0.10.0 diff --git a/go.sum b/go.sum index 58ebcc9a..1fef35de 100644 --- a/go.sum +++ b/go.sum @@ -240,8 +240,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stripe/stripe-go/v74 v74.22.0 h1:A6yqbyS61JYWhq6H4b0PFZukM8Ltx1VOXxsLYBNL+wE= -github.com/stripe/stripe-go/v74 v74.22.0/go.mod h1:f9L6LvaXa35ja7eyvP6GQswoaIPaBRvGAimAO+udbBw= +github.com/stripe/stripe-go/v74 v74.26.0 h1:enbhLtjKGWvJKcGM0f2CazqFSXzpHXcQ42nG2PNsWK0= +github.com/stripe/stripe-go/v74 v74.26.0/go.mod h1:f9L6LvaXa35ja7eyvP6GQswoaIPaBRvGAimAO+udbBw= github.com/tidwall/gjson v1.12.0 h1:61wEp/qfvFnqKH/WCI3M8HuRut+mHT6Mr82QrFmM2SY= github.com/tidwall/gjson v1.12.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= diff --git a/server/home-user-auth/internal/logic/userorderlistlogic.go b/server/home-user-auth/internal/logic/userorderlistlogic.go index 9e4af349..f75db264 100644 --- a/server/home-user-auth/internal/logic/userorderlistlogic.go +++ b/server/home-user-auth/internal/logic/userorderlistlogic.go @@ -6,7 +6,9 @@ import ( "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" + "fusenapi/utils/configs" "fusenapi/utils/format" + "fusenapi/utils/order" "math" "time" @@ -83,6 +85,12 @@ func (l *UserOrderListLogic) UserOrderList(req *types.UserOrderListReq, userinfo var respList []types.Items if listResLen > 0 { + // 获取订单时间配置 + orderTimeConfig, err := configs.GetOrderTimeConfig(l.ctx, l.svcCtx.MysqlConn) + if err != nil { + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get config time info") + } + // 数据处理 for _, item := range listRes { var pbData types.Items @@ -100,6 +108,48 @@ func (l *UserOrderListLogic) UserOrderList(req *types.UserOrderListReq, userinfo var pcsBox int64 var pcs int64 var productList []*types.Product + + var surplusAt int64 + + //如果是部分支付状态,那么取消订单倒计时2天 + if *item.Status == int64(constants.STATUS_NEW_PART_PAY) { + surplusAt = (*item.Ctime + int64(constants.CANCLE_ORDER_EXPIRE)) - time.Now().Unix() + if surplusAt < 0 { + surplusAt = 0 + } + } + + fsOrderAffiliateInfo := item.FsOrderAffiliateInfo + + statusAndLogisticsRes := order.GetOrderStatusAndLogistics(order.GetOrderStatusAndLogisticsReq{ + OrderStatus: constants.Order(*item.Status), + DeliveryMethod: constants.DeliveryMethod(*item.DeliveryMethod), + IsPayCompleted: *item.IsAllProductCompleted, + SureTime: *fsOrderAffiliateInfo.SureTime, + ProductTime: *fsOrderAffiliateInfo.SureTime, + ProductEndtime: *fsOrderAffiliateInfo.SureTime, + DeliverTime: *fsOrderAffiliateInfo.SureTime, + UpsDeliverTime: *fsOrderAffiliateInfo.SureTime, + UpsTime: *fsOrderAffiliateInfo.SureTime, + ArrivalTime: *fsOrderAffiliateInfo.SureTime, + RecevieTime: *fsOrderAffiliateInfo.SureTime, + + OrderCtime: *item.Ctime, + WebSetTimeInfo: orderTimeConfig, + }) + + // 流程控制 + statusTime := make([]*types.StatusTime, 5) + for _, itemTimes := range statusAndLogisticsRes.Times { + statusTime = append(statusTime, &types.StatusTime{ + Key: itemTimes.Key, + Time: itemTimes.Time, + }) + } + pbData.StatusTimes = statusTime + pbData.LogisticsStatus = int64(statusAndLogisticsRes.LogisticsStatus) + pbData.Status = int64(statusAndLogisticsRes.OrderStatus) + if len(item.FsOrderDetails) > 0 { for _, fsOrderDetailItem := range item.FsOrderDetails { fsOrderDetailBuyNum := *fsOrderDetailItem.FsOrderDetail.BuyNum @@ -130,35 +180,9 @@ func (l *UserOrderListLogic) UserOrderList(req *types.UserOrderListReq, userinfo pbData.ProductList = productList } - var surplusAt int64 - surplusAt = (*item.Ctime + constants.CANCLE_ORDER_EXPIRE) - time.Now().Unix() - if surplusAt < 0 { - surplusAt = 0 - } - //fsOrderAffiliateInfo := item.FsOrderAffiliateInfo - - // 流程控制 - // statusTime := make([]*types.StatusTime,8) - // statusTime[0] = &types.StatusTime{ - // Key: 1,Time:*fsOrderAffiliateInfo.SureTime, - // } - // statusTime[1] = &types.StatusTime{ - // Key: 1,Time:*ifsOrderAffiliateInfo.ProductTime, - // } - - // `sure_time` int(10) unsigned DEFAULT '0' COMMENT '确认时间', - // `product_time` int(10) unsigned DEFAULT '0' COMMENT '生产时间', - // `product_endtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '生成完成时间', - // `deliver_time` int(10) unsigned DEFAULT '0' COMMENT '发货时间', - // `ups_deliver_time` int(10) unsigned DEFAULT '0' COMMENT 'ups发货时间', - // `ups_time` int(10) unsigned DEFAULT '0' COMMENT 'UPS提货时间', - // `arrival_time` int(10) unsigned DEFAULT '0' COMMENT '到达云仓的时间', - // `recevie_time` int(10) unsigned DEFAULT '0' COMMENT '云仓收货时间', - pbData.PcsBox = pcsBox pbData.Pcs = pcs pbData.SurplusAt = surplusAt - pbData.LogisticsStatus = 1 pbData.Deposit = *item.TotalAmount / 2 pbData.Remaining = pbData.Deposit respList = append(respList, pbData) diff --git a/server/home-user-auth/internal/types/types.go b/server/home-user-auth/internal/types/types.go index 648d0eba..9679e889 100644 --- a/server/home-user-auth/internal/types/types.go +++ b/server/home-user-auth/internal/types/types.go @@ -67,6 +67,7 @@ type Product struct { ProductId int64 `json:"product_id"` Size string `json:"size"` Title string `json:"title"` + IsStop int64 `json:"is_stop"` } type RequestGoogleLogin struct { diff --git a/server_api/home-user-auth.api b/server_api/home-user-auth.api index bbc0575a..1ad9b6a4 100644 --- a/server_api/home-user-auth.api +++ b/server_api/home-user-auth.api @@ -10,57 +10,57 @@ info ( import "basic.api" service home-user-auth { - + // @handler UserRegisterHandler // post /api/user/register(RequestUserRegister) returns (response); - + @handler UserLoginHandler post /api/user/login(RequestUserLogin) returns (response); - + @handler AcceptCookieHandler post /api/user/accept-cookie(request) returns (response); - + @handler UserFontsHandler get /api/user/fonts(request) returns (response); - + @handler UserGetTypeHandler get /api/user/get-type(request) returns (response); - + @handler UserSaveBasicInfoHandler post /api/user/basic-info(RequestBasicInfoForm) returns (response); - + @handler UserStatusConfigHandler get /api/user/status-config(request) returns (response); - + @handler UserBasicInfoHandler get /api/user/basic-info(request) returns (response); - + @handler UserAddressListHandler get /api/user/address-list(request) returns (response); - + @handler UserAddAddressHandler post /api/user/add-address(RequestAddAddress) returns (response); - + @handler UserContactServiceHandler post /api/user/contact-service (RequestContactService) returns (response); - + // @handler UserOderListHandler // get /api/user/order-list(RequestOrderId) returns (response); - + @handler UserOderDeleteHandler post /api/user/order-delete(RequestOrderId) returns (response); - + @handler UserGoogleLoginHandler get /api/user/oauth2/login/google(RequestGoogleLogin) returns (response); - + //订单列表 @handler UserOrderListHandler get /api/user/order-list (UserOrderListReq) returns (response); - + //取消订单 @handler UserOrderCancelHandler get /api/user/order-cancel (UserOrderCancelReq) returns (response); - + } //取消订单 @@ -130,6 +130,7 @@ type Product { ProductId int64 `json:"product_id"` Size string `json:"size"` Title string `json:"title"` + IsStop int64 `json:"is_stop"` } type RequestGoogleLogin { diff --git a/utils/order/order_status.go b/utils/order/order_status.go index c3f7dba8..5c3b0da4 100644 --- a/utils/order/order_status.go +++ b/utils/order/order_status.go @@ -1,6 +1,10 @@ package order -import "fusenapi/constants" +import ( + "fusenapi/constants" + "fusenapi/utils/configs" + "fusenapi/utils/format" +) // 获取订单生产状态 func GetOrderStatus(orderStatus constants.Order, deliveryMethod constants.DeliveryMethod) constants.Order { @@ -28,3 +32,144 @@ func GetOrderStatus(orderStatus constants.Order, deliveryMethod constants.Delive return constants.STATUS_FONT_CLOSED } } + +type GetOrderStatusAndLogisticsReq struct { + OrderStatus constants.Order + DeliveryMethod constants.DeliveryMethod + IsPayCompleted int64 + SureTime int64 + ProductTime int64 + ProductEndtime int64 + DeliverTime int64 + UpsDeliverTime int64 + UpsTime int64 + ArrivalTime int64 + RecevieTime int64 + + OrderCtime int64 + WebSetTimeInfo configs.WebSetTimeInfo +} + +type GetOrderStatusAndLogisticsRes struct { + OrderStatus constants.Order + LogisticsStatus constants.Order + + Times []GetOrderStatusAndLogisticsResTimes +} + +type GetOrderStatusAndLogisticsResTimes struct { + Key int `json:"key"` + Time string `json:"time"` +} + +// 获取订单物流状态 +func GetOrderStatusAndLogistics(req GetOrderStatusAndLogisticsReq) (res GetOrderStatusAndLogisticsRes) { + var status constants.Order + logisticsStatus := constants.LOGISTICS_STATUS_DRAW + + times := make([]GetOrderStatusAndLogisticsResTimes, 5) + m := 1 + for i := 0; i < 5; i++ { + m++ + times[i] = GetOrderStatusAndLogisticsResTimes{ + Key: m, + Time: "", + } + } + + switch req.OrderStatus { + //已支付 + case constants.STATUS_NEW_PART_PAY, constants.STATUS_NEW_PAY_COMPLETED, constants.STATUS_NEW_SURE: + status = constants.STATUS_FONT_PAID + logisticsStatus = constants.LOGISTICS_STATUS_DRAW + //生产中 + case constants.STATUS_NEW_PRODUTING, constants.STATUS_NEW_PRODUT_COMPLETED: + //直邮单有完成的物流状态 + if req.DeliveryMethod == constants.DELIVERY_METHOD_ADDRESS { + if req.OrderStatus == constants.STATUS_NEW_PRODUTING { + logisticsStatus = constants.LOGISTICS_STATUS_DRAW + } else { + logisticsStatus = constants.LOGISTICS_STATUS_SHIPPING + } + } + status = constants.STATUS_FONT_PRODUCTION + //运输中-直邮单 + case constants.STATUS_NEW_DELIVER, constants.STATUS_NEW_UPS: + if req.DeliveryMethod == constants.DELIVERY_METHOD_ADDRESS { + if req.OrderStatus == constants.STATUS_NEW_DELIVER { + logisticsStatus = constants.LOGISTICS_STATUS_UPS + } else { + logisticsStatus = constants.LOGISTICS_STATUS_UPS_ARRIVAL + } + } + status = constants.STATUS_FONT_SHIPPED + //到达-云仓 + case constants.STATUS_NEW_ARRIVAL: + if req.DeliveryMethod == constants.DELIVERY_METHOD_CLOUD { + logisticsStatus = constants.LOGISTICS_STATUS_SHIPPING + } + status = constants.STATUS_FONT_INVENTORY + //订单完成 + case constants.STATUS_NEW_COMPLETED: + if req.DeliveryMethod == constants.DELIVERY_METHOD_CLOUD { + status = constants.STATUS_FONT_COMPLETED_CLOUD + logisticsStatus = constants.LOGISTICS_STATUS_UPS + } else { + status = constants.STATUS_FONT_COMPLETED + logisticsStatus = constants.LOGISTICS_STATUS_ARRIVAL + } + + //订单关闭 + default: + status = constants.STATUS_FONT_CLOSED + } + res.OrderStatus = status + res.LogisticsStatus = logisticsStatus + + var daySecond int64 = 3600 * 24 + + if req.DeliveryMethod == constants.DELIVERY_METHOD_ADDRESS { + switch logisticsStatus { + case constants.LOGISTICS_STATUS_DRAW: + times[1].Time = format.TimeIntToFormat(req.OrderCtime + req.WebSetTimeInfo.ProductDay*daySecond) + case constants.LOGISTICS_STATUS_SHIPPING: + if req.ProductEndtime > 0 { + times[2].Time = format.TimeIntToFormat(req.ProductEndtime + req.WebSetTimeInfo.FactoryDeliverDay*daySecond) + } else { + times[2].Time = format.TimeIntToFormat(req.OrderCtime + req.WebSetTimeInfo.FactoryDeliverDay*daySecond) + } + case constants.LOGISTICS_STATUS_UPS: + if req.DeliverTime > 0 { + times[2].Time = format.TimeIntToFormat(req.DeliverTime) + times[3].Time = format.TimeIntToFormat(req.DeliverTime + req.WebSetTimeInfo.DeliverUpsDay*daySecond) + } + case constants.LOGISTICS_STATUS_UPS_ARRIVAL: + if req.DeliverTime > 0 { + times[2].Time = format.TimeIntToFormat(req.DeliverTime) + } + if req.UpsDeliverTime > 0 { + times[3].Time = format.TimeIntToFormat(req.UpsDeliverTime) + times[4].Time = format.TimeIntToFormat(req.UpsDeliverTime + req.WebSetTimeInfo.UpsTransDay*daySecond) + } + case constants.LOGISTICS_STATUS_ARRIVAL: + if req.DeliverTime > 0 { + times[2].Time = format.TimeIntToFormat(req.DeliverTime) + } + if req.UpsDeliverTime > 0 { + times[3].Time = format.TimeIntToFormat(req.UpsDeliverTime) + } + if req.UpsTime > 0 { + times[4].Time = format.TimeIntToFormat(req.UpsTime) + } + } + res.Times = times + } else { + timesData := times[0:3] + if logisticsStatus == constants.LOGISTICS_STATUS_DRAW { + timesData[1].Time = format.TimeIntToFormat(req.OrderCtime + req.WebSetTimeInfo.ProductDay*daySecond) + } + res.Times = timesData + } + + return res +}