新增逻辑
This commit is contained in:
parent
d002f47478
commit
a7debdb686
|
|
@ -26,6 +26,7 @@ type LoginResponse struct {
|
||||||
Amount int `json:"amount"`
|
Amount int `json:"amount"`
|
||||||
Role int `json:"role"`
|
Role int `json:"role"`
|
||||||
UserPets []UserPetInfo `json:"userPets"`
|
UserPets []UserPetInfo `json:"userPets"`
|
||||||
|
Car models.ServiceCar `json:"car"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultNickName = "微信用户"
|
var defaultNickName = "微信用户"
|
||||||
|
|
@ -85,6 +86,13 @@ func (p DefParty) login() web_iris.Party {
|
||||||
Amount: userInfo.Amount,
|
Amount: userInfo.Amount,
|
||||||
Role: userInfo.Role,
|
Role: userInfo.Role,
|
||||||
}
|
}
|
||||||
|
if userInfo.Role == 1 {
|
||||||
|
var serviceCarUser models.ServiceCarUser
|
||||||
|
database.Instance().Model(&models.ServiceCarUser{}).Where("uid = ?", userInfo.Id).Find(&serviceCarUser)
|
||||||
|
response.Car = CarMap[serviceCarUser.CarId]
|
||||||
|
response.Car.ServiceAddr = ServiceAddrMap[response.Car.ServiceAddrId]
|
||||||
|
}
|
||||||
|
|
||||||
response.UserPets = GetUserPets(userInfo.Id)
|
response.UserPets = GetUserPets(userInfo.Id)
|
||||||
Success(ctx, loginRequest, response)
|
Success(ctx, loginRequest, response)
|
||||||
})
|
})
|
||||||
|
|
@ -124,3 +132,18 @@ func (p DefParty) getUserInfo() web_iris.Party {
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UserUploadFileResponse struct {
|
||||||
|
FileName string `json:"fileName"` //文件名
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取用户信息
|
||||||
|
func (p DefParty) userUploadFile() web_iris.Party {
|
||||||
|
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
|
||||||
|
index.Post(AuthBase+"/userUploadFile", func(ctx *context.Context) {
|
||||||
|
headerInfo := GetHeaderBaseInfo(ctx)
|
||||||
|
fileName := CtxFileUpload(ctx)
|
||||||
|
Success(ctx, headerInfo, UserUploadFileResponse{fileName})
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
"github.com/kataras/iris/v12/context"
|
"github.com/kataras/iris/v12/context"
|
||||||
|
"gorm.io/gorm/clause"
|
||||||
"io"
|
"io"
|
||||||
"pet-house.com/business/models"
|
"pet-house.com/business/models"
|
||||||
"pet-house.com/core/server/database"
|
"pet-house.com/core/server/database"
|
||||||
|
|
@ -45,9 +46,9 @@ func (p DefParty) carServiceOrderList() web_iris.Party {
|
||||||
}
|
}
|
||||||
var orderMains []models.OrderMain
|
var orderMains []models.OrderMain
|
||||||
if carServiceOrderListRequest.Status == 0 {
|
if carServiceOrderListRequest.Status == 0 {
|
||||||
database.Instance().Model(&models.OrderMain{}).Joins("JOIN car_orders ON order_mains.order_id = car_orders.order_id").Where("car_orders.car_id = ? AND order_mains.status > 0", serviceCarUser.CarId).Offset((carServiceOrderListRequest.PageNo - 1) * carServiceOrderListRequest.PageSize).Limit(carServiceOrderListRequest.PageSize).Find(&orderMains)
|
database.Instance().Model(&models.OrderMain{}).Joins("JOIN car_orders ON order_mains.order_id = car_orders.order_id").Where("car_orders.car_id = ? AND order_mains.status > 0", serviceCarUser.CarId).Order(clause.OrderByColumn{Column: clause.Column{Name: "order_mains.service_time"}, Desc: false}).Offset((carServiceOrderListRequest.PageNo - 1) * carServiceOrderListRequest.PageSize).Limit(carServiceOrderListRequest.PageSize).Find(&orderMains)
|
||||||
} else {
|
} else {
|
||||||
database.Instance().Model(&models.OrderMain{}).Joins("JOIN car_orders ON order_mains.order_id = car_orders.order_id").Where("car_orders.car_id = ? AND order_mains.status = ?", serviceCarUser.CarId, carServiceOrderListRequest.Status).Offset((carServiceOrderListRequest.PageNo - 1) * carServiceOrderListRequest.PageSize).Limit(carServiceOrderListRequest.PageSize).Find(&orderMains)
|
database.Instance().Model(&models.OrderMain{}).Joins("JOIN car_orders ON order_mains.order_id = car_orders.order_id").Where("car_orders.car_id = ? AND order_mains.status = ?", serviceCarUser.CarId, carServiceOrderListRequest.Status).Order(clause.OrderByColumn{Column: clause.Column{Name: "order_mains.service_time"}, Desc: false}).Offset((carServiceOrderListRequest.PageNo - 1) * carServiceOrderListRequest.PageSize).Limit(carServiceOrderListRequest.PageSize).Find(&orderMains)
|
||||||
}
|
}
|
||||||
var orderDetails []OrderDetail
|
var orderDetails []OrderDetail
|
||||||
for _, value := range orderMains {
|
for _, value := range orderMains {
|
||||||
|
|
@ -57,3 +58,91 @@ func (p DefParty) carServiceOrderList() web_iris.Party {
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CarServiceProcessRequest struct {
|
||||||
|
Type int //操作类型 1开始 2结束
|
||||||
|
SubOrderId string //子订单ID
|
||||||
|
PayAmount int32 //实际支付金额
|
||||||
|
PayRemark string //支付备注
|
||||||
|
FileName string //拍照文件
|
||||||
|
}
|
||||||
|
|
||||||
|
type CarServiceProcessResponse struct {
|
||||||
|
OrderDetail OrderDetail `json:"orderDetail"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 服务处理
|
||||||
|
func (p DefParty) carServiceProcess() web_iris.Party {
|
||||||
|
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
|
||||||
|
index.Post(CarBase+"/carServiceProcess", func(ctx *context.Context) {
|
||||||
|
headerBaseInfo := GetHeaderBaseInfo(ctx)
|
||||||
|
body, _ := io.ReadAll(ctx.Request().Body)
|
||||||
|
var carServiceProcessRequest CarServiceProcessRequest
|
||||||
|
json.Unmarshal(body, &carServiceProcessRequest)
|
||||||
|
if carServiceProcessRequest.Type == 0 {
|
||||||
|
ParamError.Fail(ctx, carServiceProcessRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var userInfo *models.User
|
||||||
|
database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo)
|
||||||
|
if userInfo.Role == 0 {
|
||||||
|
UserError.Fail(ctx, headerBaseInfo)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var serviceCarUser models.ServiceCarUser
|
||||||
|
database.Instance().Model(&models.ServiceCarUser{}).Where("uid = ?", userInfo.Id).Find(&serviceCarUser)
|
||||||
|
if serviceCarUser.CarId == 0 {
|
||||||
|
CarNotExistError.Fail(ctx, headerBaseInfo)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var subOrderInfo models.OrderSub
|
||||||
|
database.Instance().Model(&models.OrderSub{}).Where("order_id = ?", carServiceProcessRequest.SubOrderId).Find(&subOrderInfo)
|
||||||
|
if subOrderInfo.Id == 0 {
|
||||||
|
OrderExistError.Fail(ctx, carServiceProcessRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
database.Instance().Model(&models.OrderServiceRecord{}).Create(&models.OrderServiceRecord{
|
||||||
|
OrderId: carServiceProcessRequest.SubOrderId,
|
||||||
|
FilePath: carServiceProcessRequest.FileName,
|
||||||
|
Type: carServiceProcessRequest.Type,
|
||||||
|
})
|
||||||
|
var mainOrder models.OrderMain
|
||||||
|
database.Instance().Model(&models.OrderMain{}).Where("order_id = ?", subOrderInfo.MainOrderId).Find(&mainOrder)
|
||||||
|
if mainOrder.Id == 0 {
|
||||||
|
OrderExistError.Fail(ctx, carServiceProcessRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if carServiceProcessRequest.Type == 1 {
|
||||||
|
if subOrderInfo.Status == 3 || subOrderInfo.Status == 2 {
|
||||||
|
OrderError.Fail(ctx, carServiceProcessRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
subOrderInfo.Status = 2
|
||||||
|
mainOrder.Status = 2
|
||||||
|
database.Instance().Save(&mainOrder)
|
||||||
|
database.Instance().Save(&subOrderInfo)
|
||||||
|
} else if carServiceProcessRequest.Type == 2 {
|
||||||
|
if subOrderInfo.Status == 3 {
|
||||||
|
OrderError.Fail(ctx, carServiceProcessRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
subOrderInfo.Status = 3
|
||||||
|
subOrderInfo.PayAmount = carServiceProcessRequest.PayAmount
|
||||||
|
if subOrderInfo.PayAmount == 0 {
|
||||||
|
subOrderInfo.PayAmount = subOrderInfo.TotalAmount
|
||||||
|
}
|
||||||
|
subOrderInfo.PayRemark = carServiceProcessRequest.PayRemark
|
||||||
|
database.Instance().Save(&subOrderInfo)
|
||||||
|
var count int64
|
||||||
|
database.Instance().Model(&models.OrderSub{}).Where("main_order_id = ?", subOrderInfo.MainOrderId).Count(&count)
|
||||||
|
var countStatus int64
|
||||||
|
database.Instance().Model(&models.OrderSub{}).Where("main_order_id = ? and status = 3", subOrderInfo.MainOrderId).Count(&countStatus)
|
||||||
|
if count == countStatus {
|
||||||
|
mainOrder.Status = 3
|
||||||
|
database.Instance().Save(&mainOrder)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Success(ctx, carServiceProcessRequest, CarServiceProcessResponse{GetOrderDetail(mainOrder.OrderId)})
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,10 @@ import (
|
||||||
"github.com/bwmarrin/snowflake"
|
"github.com/bwmarrin/snowflake"
|
||||||
"github.com/kataras/iris/v12/context"
|
"github.com/kataras/iris/v12/context"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"pet-house.com/business/models"
|
"pet-house.com/business/models"
|
||||||
"pet-house.com/core/server/cache"
|
"pet-house.com/core/server/cache"
|
||||||
"pet-house.com/core/server/cron_server"
|
"pet-house.com/core/server/cron_server"
|
||||||
|
|
@ -179,3 +183,27 @@ func DataCacheJob() {
|
||||||
zap_server.ZAPLOG.Info("DataCacheJob c : ", zap.Any("c", c), zap.Any("err", err))
|
zap_server.ZAPLOG.Info("DataCacheJob c : ", zap.Any("c", c), zap.Any("err", err))
|
||||||
cron_server.CronInstance().Start()
|
cron_server.CronInstance().Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CtxFileUpload(ctx *context.Context) string {
|
||||||
|
file, info, _ := ctx.FormFile("file")
|
||||||
|
defer func(file multipart.File) {
|
||||||
|
_ = file.Close()
|
||||||
|
}(file)
|
||||||
|
lastFileName := NextId.Generate().String() + "_" + info.Filename
|
||||||
|
fileName := time.Now().Format("20060102") + "/" + lastFileName
|
||||||
|
targetPath := "./static/uploads/" + time.Now().Format("20060102")
|
||||||
|
if _, err := os.Stat(targetPath); os.IsNotExist(err) {
|
||||||
|
_ = os.MkdirAll(targetPath, os.ModePerm)
|
||||||
|
}
|
||||||
|
filePath := "static/uploads/" + fileName
|
||||||
|
// 创建目标文件
|
||||||
|
destFilePath := filepath.Join(targetPath, lastFileName)
|
||||||
|
destFile, _ := os.Create(destFilePath)
|
||||||
|
defer func(destFile *os.File) {
|
||||||
|
_ = destFile.Close()
|
||||||
|
}(destFile)
|
||||||
|
// 将上传的文件内容复制到目标文件中
|
||||||
|
id, _ := io.Copy(destFile, file)
|
||||||
|
zap_server.ZAPLOG.Info("CtxFileUpload : ", zap.Any("filePath", filePath), zap.Any("id", id))
|
||||||
|
return fileName
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ func (p DefParty) RegisterList() []web_iris.Party {
|
||||||
//用户
|
//用户
|
||||||
p.login(),
|
p.login(),
|
||||||
p.getUserInfo(),
|
p.getUserInfo(),
|
||||||
|
p.userUploadFile(),
|
||||||
//商品
|
//商品
|
||||||
p.goodsList(),
|
p.goodsList(),
|
||||||
p.goodsDetail(),
|
p.goodsDetail(),
|
||||||
|
|
@ -36,6 +37,7 @@ func (p DefParty) RegisterList() []web_iris.Party {
|
||||||
p.serviceAreaAddrList(),
|
p.serviceAreaAddrList(),
|
||||||
//车辆
|
//车辆
|
||||||
p.carServiceOrderList(),
|
p.carServiceOrderList(),
|
||||||
|
p.carServiceProcess(),
|
||||||
p.index(),
|
p.index(),
|
||||||
}
|
}
|
||||||
return ps
|
return ps
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ func ModuleInit() {
|
||||||
&models.ServiceUserMark{},
|
&models.ServiceUserMark{},
|
||||||
&models.ServiceUserMarkRecord{},
|
&models.ServiceUserMarkRecord{},
|
||||||
&models.ReserveTimeFilter{},
|
&models.ReserveTimeFilter{},
|
||||||
|
&models.OrderServiceRecord{},
|
||||||
)
|
)
|
||||||
DataInit()
|
DataInit()
|
||||||
DataCacheJob()
|
DataCacheJob()
|
||||||
|
|
|
||||||
|
|
@ -351,6 +351,10 @@ type OrderDetailRequest struct {
|
||||||
OrderId string
|
OrderId string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OrderDetailResponse struct {
|
||||||
|
OrderDetail OrderDetail `json:"orderDetail"`
|
||||||
|
}
|
||||||
|
|
||||||
// 订单详情
|
// 订单详情
|
||||||
func (p DefParty) orderDetail() web_iris.Party {
|
func (p DefParty) orderDetail() web_iris.Party {
|
||||||
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
|
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
|
||||||
|
|
@ -363,7 +367,7 @@ func (p DefParty) orderDetail() web_iris.Party {
|
||||||
OrderExistError.Fail(ctx, orderDetailRequest)
|
OrderExistError.Fail(ctx, orderDetailRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Success(ctx, orderDetailRequest, orderDetail)
|
Success(ctx, orderDetailRequest, OrderDetailResponse{GetOrderDetail(orderDetailRequest.OrderId)})
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,7 @@ type OrderSub struct {
|
||||||
TotalAmount int32 `gorm:"not null" json:"totalAmount"` //总金额
|
TotalAmount int32 `gorm:"not null" json:"totalAmount"` //总金额
|
||||||
PayAmount int32 `json:"payAmount"` //实际支付金额
|
PayAmount int32 `json:"payAmount"` //实际支付金额
|
||||||
PayTime time.Time `gorm:"type:timestamp;" json:"payTime"` //支付时间
|
PayTime time.Time `gorm:"type:timestamp;" json:"payTime"` //支付时间
|
||||||
|
PayRemark string `json:"payRemark"` //支付备注
|
||||||
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间
|
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间
|
||||||
UpdateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP" json:"-"` //更新时间
|
UpdateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP" json:"-"` //更新时间
|
||||||
}
|
}
|
||||||
|
|
@ -140,6 +141,15 @@ type OrderDetail struct {
|
||||||
Amount int32 `gorm:"not null" json:"amount"` //价格
|
Amount int32 `gorm:"not null" json:"amount"` //价格
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OrderServiceRecord 订单服务记录
|
||||||
|
type OrderServiceRecord struct {
|
||||||
|
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
||||||
|
OrderId string `gorm:"index:not null" json:"orderId"` //订单ID
|
||||||
|
FilePath string `json:"filePath"` //照片路径
|
||||||
|
Type int `gorm:"not null" json:"type"` //服务类型
|
||||||
|
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间
|
||||||
|
}
|
||||||
|
|
||||||
// ServiceCar 服务车辆
|
// ServiceCar 服务车辆
|
||||||
type ServiceCar struct {
|
type ServiceCar struct {
|
||||||
Id int `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
Id int `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
||||||
|
|
@ -152,6 +162,7 @@ type ServiceCar struct {
|
||||||
NowLatitude string `json:"nowLatitude"` //当前服务位置维度
|
NowLatitude string `json:"nowLatitude"` //当前服务位置维度
|
||||||
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间
|
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间
|
||||||
UpdateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP" json:"-"` //更新时间
|
UpdateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP" json:"-"` //更新时间
|
||||||
|
ServiceAddr ServiceAddr `gorm:"-" json:"serviceAddr"` //当前服务区域
|
||||||
}
|
}
|
||||||
|
|
||||||
// CarOrder 车辆订单
|
// CarOrder 车辆订单
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue