订单列表--完善

This commit is contained in:
Hiven 2023-07-24 18:04:24 +08:00
parent 95e6491de5
commit fd9e30ea74
7 changed files with 217 additions and 98 deletions

View File

@ -25,3 +25,7 @@ func (dt *FsOrderDetailTemplateModel) FindOne(ctx context.Context, id int64) (re
err = dt.db.WithContext(ctx).Model(&FsOrderDetailTemplate{}).Where("`id` = ?", id).Take(&resp).Error
return resp, err
}
func (m *FsOrderDetailTemplateModel) TableName() string {
return m.name
}

View File

@ -77,7 +77,7 @@ func (o *FsOrderModel) FindPageListByPage(ctx context.Context, rowBuilder *gorm.
rowBuilder = rowBuilder.Scopes(handler.Paginate(page, pageSize))
// 结果
result := rowBuilder.WithContext(ctx).Find(&resp)
result := rowBuilder.Debug().WithContext(ctx).Find(&resp)
if result.Error != nil {
return nil, result.Error
} else {
@ -93,8 +93,20 @@ type FsOrderRel struct {
type FsOrderDetails struct {
FsOrderDetail
FsOrderDetailTemplateInfo FsOrderDetailTemplate `gorm:"foreignKey:id;references:order_detail_template_id"`
FsProductInfo FsProduct `gorm:"foreignKey:id;references:product_id"`
FsOrderDetailTemplateInfo FsOrderDetailTemplateInfo `gorm:"foreignKey:id;references:order_detail_template_id"`
FsProductInfo FsProduct `gorm:"foreignKey:id;references:product_id"`
}
type FsOrderDetailTemplateInfo struct {
FsOrderDetailTemplate
FsProductDesignInfo FsProductDesignInfo `gorm:"foreignKey:id;references:design_id"` //获取设计数据
FsProductSizeInfo FsProductSize `gorm:"foreignKey:id;references:size_id"`
}
type FsProductDesignInfo struct {
FsProductDesign
OptionData FsProduct `gorm:"foreignKey:id;references:optional_id"` //获取配件信息
TemplateData FsProductTemplateV2 `gorm:"foreignKey:id;references:template_id"` //获取模板信息
}
func (m *FsOrderModel) RowSelectBuilder(selectData []string) *gorm.DB {

View File

@ -34,3 +34,7 @@ func (d *FsProductDesignModel) Create(ctx context.Context, data *FsProductDesign
func (d *FsProductDesignModel) UpdateBySn(ctx context.Context, sn string, data *FsProductDesign) error {
return d.db.WithContext(ctx).Model(&FsProductDesign{}).Where("`sn` = ?", sn).Updates(&data).Error
}
func (m *FsProductDesignModel) TableName() string {
return m.name
}

View File

@ -8,6 +8,8 @@ import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/configs"
"fusenapi/utils/image"
"strings"
"fusenapi/utils/format"
"fusenapi/utils/order"
@ -41,10 +43,15 @@ func (l *UserOrderListLogic) UserOrderList(req *types.UserOrderListReq, userinfo
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
// 测试
userinfo.UserId = 39
size := req.Size
if size > 0 {
size = int64(image.GetCurrentSize(uint32(size)))
}
orderDetailModel := gmodel.NewFsOrderDetailModel(l.svcCtx.MysqlConn)
orderDetailTemplateModel := gmodel.NewFsOrderDetailTemplateModel(l.svcCtx.MysqlConn)
fsProductDesignModel := gmodel.NewFsProductDesignModel(l.svcCtx.MysqlConn)
orderModel := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn)
rowBuilder := orderModel.RowSelectBuilder(nil)
if userinfo == nil || userinfo.UserId == 0 {
@ -55,10 +62,39 @@ func (l *UserOrderListLogic) UserOrderList(req *types.UserOrderListReq, userinfo
var page = req.Page
var pageSize = req.PageSize
var listRes []*gmodel.FsOrderRel
rowBuilder = rowBuilder.Where("user_id =?", userinfo.UserId)
rowBuilder = rowBuilder.Where("user_id =?", userinfo.UserId).Where("status <> ?", constants.STATUS_NEW_NOT_PAY).Where("status <>?", constants.STATUS_NEW_DELETE)
// 根据时间来查询不同范围的订单
switch req.Time {
case 1:
rowBuilder = rowBuilder.Where("ctime >?", time.Now().AddDate(0, -1, 0).Unix())
case 2:
rowBuilder = rowBuilder.Where("ctime >?", time.Now().AddDate(0, -3, 0).Unix())
case 3:
rowBuilder = rowBuilder.Where("ctime >?", time.Now().AddDate(0, -6, 0).Unix())
case 4:
rowBuilder = rowBuilder.Where("ctime >?", time.Now().AddDate(-1, 0, 0).Unix())
default:
}
//按照订单状态查询不同的订单
if req.Status != -1 {
rowBuilder = rowBuilder.Where("status = ?", req.Status)
switch req.Status {
case 1:
rowBuilder = rowBuilder.Where("status in ?", [3]constants.Order{constants.STATUS_NEW_PART_PAY, constants.STATUS_NEW_PAY_COMPLETED, constants.STATUS_NEW_SURE})
case 2:
rowBuilder = rowBuilder.Where("status in ?", [2]constants.Order{constants.STATUS_NEW_PRODUTING, constants.STATUS_NEW_PRODUT_COMPLETED})
case 3:
rowBuilder = rowBuilder.Where("status in ?", [2]constants.Order{constants.STATUS_NEW_DELIVER, constants.STATUS_NEW_UPS})
case 4:
rowBuilder = rowBuilder.Where("status =?", constants.STATUS_NEW_ARRIVAL)
case 5:
rowBuilder = rowBuilder.Where("status =?", constants.STATUS_NEW_COMPLETED).Where("delivery_method =?", constants.DELIVERY_METHOD_ADDRESS)
case 7:
rowBuilder = rowBuilder.Where("status in ?", [3]constants.Order{constants.STATUS_NEW_CANCEL, constants.STATUS_NEW_REFUNDED, constants.STATUS_NEW_REFUNDING})
case 8:
rowBuilder = rowBuilder.Where("status =?", constants.STATUS_NEW_COMPLETED).Where("delivery_method =?", constants.DELIVERY_METHOD_CLOUD)
}
}
// 查询总数
@ -74,7 +110,11 @@ func (l *UserOrderListLogic) UserOrderList(req *types.UserOrderListReq, userinfo
// 查询数据
if total > 0 {
rowBuilder = rowBuilder.Preload("FsOrderAffiliateInfo").Preload("FsOrderDetails", func(dbPreload *gorm.DB) *gorm.DB {
return dbPreload.Table(orderDetailModel.TableName()).Preload("FsOrderDetailTemplateInfo").Preload("FsProductInfo")
return dbPreload.Table(orderDetailModel.TableName()).Preload("FsOrderDetailTemplateInfo", func(dbPreload *gorm.DB) *gorm.DB {
return dbPreload.Table(orderDetailTemplateModel.TableName()).Preload("FsProductDesignInfo", func(dbPreload *gorm.DB) *gorm.DB {
return dbPreload.Table(fsProductDesignModel.TableName()).Preload("OptionData").Preload("TemplateData")
}).Preload("FsProductSizeInfo")
}).Preload("FsProductInfo")
})
listRes, err = orderModel.FindPageListByPage(l.ctx, rowBuilder, &page, &pageSize, nil, "")
}
@ -112,7 +152,7 @@ func (l *UserOrderListLogic) UserOrderList(req *types.UserOrderListReq, userinfo
var pcsBox int64
var pcs int64
var productList []*types.Product
var productList []types.Product
var surplusAt int64
@ -124,31 +164,51 @@ func (l *UserOrderListLogic) UserOrderList(req *types.UserOrderListReq, userinfo
}
}
//fsOrderAffiliateInfo := item.FsOrderAffiliateInfo
fmt.Println(orderTimeConfig)
var getOrderStatusAndLogisticsReq = order.GetOrderStatusAndLogisticsReq{
OrderStatus: 1,
DeliveryMethod: 1,
// 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,
fsOrderAffiliateInfo := item.FsOrderAffiliateInfo
// // OrderCtime: *item.Ctime,
// WebSetTimeInfo: orderTimeConfig,
var sureTime int64
var productTime int64
var ProductEndtime int64
var deliverTime int64
var upsDeliverTime int64
var upsTime int64
var arrivalTime int64
var recevieTime int64
if fsOrderAffiliateInfo.Id > 0 {
sureTime = *fsOrderAffiliateInfo.SureTime
productTime = *fsOrderAffiliateInfo.ProductTime
ProductEndtime = *fsOrderAffiliateInfo.ProductEndtime
deliverTime = *fsOrderAffiliateInfo.DeliverTime
upsDeliverTime = *fsOrderAffiliateInfo.UpsDeliverTime
upsTime = *fsOrderAffiliateInfo.UpsTime
arrivalTime = *fsOrderAffiliateInfo.ArrivalTime
recevieTime = *fsOrderAffiliateInfo.RecevieTime
}
var getOrderStatusAndLogisticsReq = order.GetOrderStatusAndLogisticsReq{
OrderStatus: constants.Order(*item.Status),
DeliveryMethod: constants.DeliveryMethod(*item.DeliveryMethod),
IsPayCompleted: *item.IsAllProductCompleted,
OrderCtime: *item.Ctime,
SureTime: sureTime,
ProductTime: productTime,
ProductEndtime: ProductEndtime,
DeliverTime: deliverTime,
UpsDeliverTime: upsDeliverTime,
UpsTime: upsTime,
ArrivalTime: arrivalTime,
RecevieTime: recevieTime,
WebSetTimeInfo: orderTimeConfig,
}
statusAndLogisticsRes := order.GetOrderStatusAndLogistics(getOrderStatusAndLogisticsReq)
// 流程控制
statusTime := make([]*types.StatusTime, 5)
var statusTime []types.StatusTime
for _, itemTimes := range statusAndLogisticsRes.Times {
statusTime = append(statusTime, &types.StatusTime{
statusTime = append(statusTime, types.StatusTime{
Key: itemTimes.Key,
Time: itemTimes.Time,
})
@ -157,8 +217,10 @@ func (l *UserOrderListLogic) UserOrderList(req *types.UserOrderListReq, userinfo
pbData.LogisticsStatus = int64(statusAndLogisticsRes.LogisticsStatus)
pbData.Status = int64(statusAndLogisticsRes.OrderStatus)
var isStopMax int64
if len(item.FsOrderDetails) > 0 {
for _, fsOrderDetailItem := range item.FsOrderDetails {
fsOrderDetailBuyNum := *fsOrderDetailItem.FsOrderDetail.BuyNum
fsOrderDetailEachBoxNum := *fsOrderDetailItem.FsOrderDetailTemplateInfo.EachBoxNum
pcs = pcs + fsOrderDetailBuyNum
@ -169,23 +231,58 @@ func (l *UserOrderListLogic) UserOrderList(req *types.UserOrderListReq, userinfo
}
pcsBox = pcsBox + pcsBoxNum + csBoxNumF
var product types.Product
product.Cover = *fsOrderDetailItem.Cover
product.Fitting = *fsOrderDetailItem.OptionalTitle
product.OptionPrice = *fsOrderDetailItem.OptionPrice
product.OrderDetailTemplateId = *fsOrderDetailItem.OrderDetailTemplateId
product.OrderId = *fsOrderDetailItem.OrderId
product.Pcs = fsOrderDetailBuyNum
product.PcsBox = pcsBox
product.Price = *fsOrderDetailItem.FsOrderDetail.Amount
product.ProductId = *fsOrderDetailItem.OptionPrice
product.Title = *fsOrderDetailItem.FsProductInfo.Title
productCover := *fsOrderDetailItem.Cover
// 尺寸
if size >= 200 {
coverArr := strings.Split(*fsOrderDetailItem.Cover, ".")
if len(coverArr) < 2 {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "cover split slice item count is less than 2")
}
productCover = fmt.Sprintf("%s_%d.%s", coverArr[0], req.Size, coverArr[1])
}
productList = append(productList, &product)
// 判断stop
var isStop int64
if fsOrderDetailItem.FsOrderDetailTemplateInfo.FsProductDesignInfo.OptionData.Id != 0 {
// 尺寸或者模板下架
if fsOrderDetailItem.FsOrderDetailTemplateInfo.FsProductDesignInfo.Id != 0 {
isStop = 1
} else {
isStop = 3
}
} else {
if fsOrderDetailItem.FsOrderDetailTemplateInfo.FsProductDesignInfo.Id != 0 {
isStop = 1
}
}
// 判断产品是否下架
if *fsOrderDetailItem.FsProductInfo.IsShelf == 0 || *fsOrderDetailItem.FsProductInfo.IsDel == 1 {
isStop = 2
}
if isStop > isStopMax {
isStopMax = isStop
}
productList = append(productList, types.Product{
Cover: productCover,
Fitting: *fsOrderDetailItem.OptionalTitle,
OptionPrice: *fsOrderDetailItem.OptionPrice,
OrderDetailTemplateId: *fsOrderDetailItem.OrderDetailTemplateId,
OrderId: *fsOrderDetailItem.OrderId,
Pcs: fsOrderDetailBuyNum,
PcsBox: pcsBox,
Price: *fsOrderDetailItem.FsOrderDetail.Amount,
ProductId: *fsOrderDetailItem.OptionPrice,
Title: *fsOrderDetailItem.FsProductInfo.Title,
Size: *fsOrderDetailItem.FsOrderDetailTemplateInfo.FsProductSizeInfo.Capacity,
IsStop: isStop,
})
}
pbData.ProductList = productList
}
pbData.IsStop = isStopMax
pbData.PcsBox = pcsBox
pbData.Pcs = pcs
pbData.SurplusAt = surplusAt

View File

@ -29,25 +29,25 @@ type UserOrderListRsp struct {
}
type Items struct {
ID int64 `json:"id"`
Sn string `json:"sn"`
UserID int64 `json:"user_id"`
TotalAmount int64 `json:"total_amount"`
Ctime string `json:"ctime"`
Status int64 `json:"status"`
DeliveryMethod int64 `json:"delivery_method"`
TsTime string `json:"ts_time"`
IsPayCompleted int64 `json:"is_pay_completed"`
DeliverSn string `json:"deliver_sn"`
PcsBox int64 `json:"pcs_box"`
Pcs int64 `json:"pcs"`
SurplusAt int64 `json:"surplus_at"`
LogisticsStatus int64 `json:"logistics_status"`
StatusTimes []*StatusTime `json:"status_times"`
Deposit int64 `json:"deposit"`
Remaining int64 `json:"remaining"`
ProductList []*Product `json:"productList"`
IsStop int64 `json:"is_stop"`
ID int64 `json:"id"`
Sn string `json:"sn"`
UserID int64 `json:"user_id"`
TotalAmount int64 `json:"total_amount"`
Ctime string `json:"ctime"`
Status int64 `json:"status"`
DeliveryMethod int64 `json:"delivery_method"`
TsTime string `json:"ts_time"`
IsPayCompleted int64 `json:"is_pay_completed"`
DeliverSn string `json:"deliver_sn"`
PcsBox int64 `json:"pcs_box"`
Pcs int64 `json:"pcs"`
SurplusAt int64 `json:"surplus_at"`
LogisticsStatus int64 `json:"logistics_status"`
StatusTimes []StatusTime `json:"status_times"`
Deposit int64 `json:"deposit"`
Remaining int64 `json:"remaining"`
ProductList []Product `json:"productList"`
IsStop int64 `json:"is_stop"`
}
type StatusTime struct {

View File

@ -10,60 +10,60 @@ 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 UserEmailRegisterHandler
get /api/user/oauth2/login/register(RequestEmailRegister) returns (response);
//订单列表
@handler UserOrderListHandler
get /api/user/order-list (UserOrderListReq) returns (response);
//取消订单
@handler UserOrderCancelHandler
get /api/user/order-cancel (UserOrderCancelReq) returns (response);
}
//取消订单
@ -95,25 +95,25 @@ type (
)
type Items {
ID int64 `json:"id"`
Sn string `json:"sn"`
UserID int64 `json:"user_id"`
TotalAmount int64 `json:"total_amount"`
Ctime string `json:"ctime"`
Status int64 `json:"status"`
DeliveryMethod int64 `json:"delivery_method"`
TsTime string `json:"ts_time"`
IsPayCompleted int64 `json:"is_pay_completed"`
DeliverSn string `json:"deliver_sn"`
PcsBox int64 `json:"pcs_box"`
Pcs int64 `json:"pcs"`
SurplusAt int64 `json:"surplus_at"`
LogisticsStatus int64 `json:"logistics_status"`
StatusTimes []*StatusTime `json:"status_times"`
Deposit int64 `json:"deposit"`
Remaining int64 `json:"remaining"`
ProductList []*Product `json:"productList"`
IsStop int64 `json:"is_stop"`
ID int64 `json:"id"`
Sn string `json:"sn"`
UserID int64 `json:"user_id"`
TotalAmount int64 `json:"total_amount"`
Ctime string `json:"ctime"`
Status int64 `json:"status"`
DeliveryMethod int64 `json:"delivery_method"`
TsTime string `json:"ts_time"`
IsPayCompleted int64 `json:"is_pay_completed"`
DeliverSn string `json:"deliver_sn"`
PcsBox int64 `json:"pcs_box"`
Pcs int64 `json:"pcs"`
SurplusAt int64 `json:"surplus_at"`
LogisticsStatus int64 `json:"logistics_status"`
StatusTimes []StatusTime `json:"status_times"`
Deposit int64 `json:"deposit"`
Remaining int64 `json:"remaining"`
ProductList []Product `json:"productList"`
IsStop int64 `json:"is_stop"`
}
type StatusTime {

View File

@ -38,7 +38,7 @@ type GetOrderStatusAndLogisticsReq struct {
DeliveryMethod constants.DeliveryMethod
IsPayCompleted int64
OrderCtime int64
SureTime int64
ProductTime int64
ProductEndtime int64
@ -48,7 +48,6 @@ type GetOrderStatusAndLogisticsReq struct {
ArrivalTime int64
RecevieTime int64
WebSetTimeInfo configs.WebSetTimeInfo
}
@ -72,11 +71,11 @@ func GetOrderStatusAndLogistics(req GetOrderStatusAndLogisticsReq) (res GetOrder
times := make([]GetOrderStatusAndLogisticsResTimes, 5)
m := 1
for i := 0; i < 5; i++ {
m++
times[i] = GetOrderStatusAndLogisticsResTimes{
Key: m,
Time: "",
}
m++
}
switch req.OrderStatus {
@ -162,6 +161,9 @@ func GetOrderStatusAndLogistics(req GetOrderStatusAndLogisticsReq) (res GetOrder
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