新增接口及逻辑处理

This commit is contained in:
yan.y
2024-04-11 17:10:19 +08:00
parent c9e0142da0
commit 1ae553d0d2
7 changed files with 141 additions and 35 deletions
+47
View File
@@ -0,0 +1,47 @@
package api
import (
"encoding/json"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
"io"
"pet-house.com/business/models"
"pet-house.com/core/server/database"
"pet-house.com/core/server/web/web_iris"
)
type DispatchOrderRequest struct {
OrderId string //订单号
CarId int //车辆ID
Remark string //派单备注
}
// 派单
func (p DefParty) dispatchOrder() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(Admin+"/dispatchOrder", func(ctx *context.Context) {
body, _ := io.ReadAll(ctx.Request().Body)
var dispatchOrderRequest DispatchOrderRequest
json.Unmarshal(body, &dispatchOrderRequest)
var orderMain models.OrderMain
database.Instance().Model(&models.OrderMain{}).Where("order_id = ?", dispatchOrderRequest.OrderId).Find(&orderMain)
if orderMain.Id == 0 {
OrderExistError.Fail(ctx, dispatchOrderRequest)
return
}
car := CarMap[dispatchOrderRequest.CarId]
if car.Id == 0 {
CarNotExistError.Fail(ctx, dispatchOrderRequest)
return
}
carOrder := models.CarOrder{
CarId: car.Id,
OrderId: orderMain.OrderId,
Remark: dispatchOrderRequest.Remark,
PredictionServiceTime: orderMain.ProjectionServiceTime,
}
database.Instance().Model(&models.CarOrder{}).Create(&carOrder)
Success(ctx, dispatchOrderRequest, nil)
})
}}
}
+5
View File
@@ -8,6 +8,8 @@ var OrderBase = "/order"
var ServiceBase = "/service"
var PetBase = "/pet"
var CarBase = "/car"
var Admin = "/admin"
var System = "/system"
func (p DefParty) RegisterList() []web_iris.Party {
ps := []web_iris.Party{
@@ -39,6 +41,9 @@ func (p DefParty) RegisterList() []web_iris.Party {
p.carServiceOrderList(),
p.carServiceProcess(),
p.index(),
//系统
p.systemConfigInfo(),
p.systemBanners(),
}
return ps
}
+17 -8
View File
@@ -11,6 +11,7 @@ import (
"pet-house.com/core/server/database"
"pet-house.com/core/server/web/web_iris"
"pet-house.com/core/server/zap_server"
"strconv"
"sync"
"time"
)
@@ -66,25 +67,33 @@ func (p DefParty) orderCreate() web_iris.Party {
ServiceAddrId: orderCreateRequest.ServiceAddrId,
ServiceRemark: "",
}
var projectionServiceTimeAll = 0
var orderSubList []models.OrderSub
var orderSubDetailList []models.OrderDetail
for _, value := range orderCreateRequest.PetGoodsInfos {
subOrderId := NextId.Generate().String()
var totalAmount int32 = 0
var projectionServiceTime = 0
for _, value := range value.GoodsIds {
goods := GoodsMap[value]
totalAmount = totalAmount + goods.Price
orderSubDetailList = append(orderSubDetailList, models.OrderDetail{SubOrderId: subOrderId, GoodsId: value, Amount: goods.Price})
if goods.Time != "/" && len(goods.Time) > 0 {
goodsTime, _ := strconv.Atoi(goods.Time)
projectionServiceTime += goodsTime
}
}
projectionServiceTimeAll += projectionServiceTime
orderSub := models.OrderSub{
OrderId: subOrderId,
MainOrderId: orderMain.OrderId,
Status: 1,
PetId: value.PetId,
PayType: 1,
Discount: 100,
TotalAmount: totalAmount,
PayAmount: 0,
OrderId: subOrderId,
MainOrderId: orderMain.OrderId,
Status: 1,
PetId: value.PetId,
PayType: 1,
Discount: 100,
TotalAmount: totalAmount,
PayAmount: 0,
ProjectionServiceTime: projectionServiceTime,
}
orderSubList = append(orderSubList, orderSub)
}
+40
View File
@@ -0,0 +1,40 @@
package api
import (
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
"gorm.io/gorm/clause"
"pet-house.com/business/models"
"pet-house.com/core/server/database"
"pet-house.com/core/server/web/web_iris"
)
type SystemInfoResponse struct {
SystemInfos []models.SystemConfig `json:"systemInfos"`
}
// 获取系统配置
func (p DefParty) systemConfigInfo() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(System+"/systemConfigInfo", func(ctx *context.Context) {
var systemConfig []models.SystemConfig
database.Instance().Model(&models.SystemConfig{}).Where("config_type > 0").Find(&systemConfig)
Success(ctx, nil, SystemInfoResponse{systemConfig})
})
}}
}
type SystemBannersResponse struct {
Banners []models.SystemConfig `json:"banners"`
}
// 获取系统banner
func (p DefParty) systemBanners() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(System+"/systemBanners", func(ctx *context.Context) {
var systemConfig []models.SystemConfig
database.Instance().Model(&models.SystemConfig{}).Where("config_type = 0").Order(clause.OrderByColumn{Column: clause.Column{Name: "sort"}, Desc: true}).Find(&systemConfig)
Success(ctx, nil, SystemBannersResponse{systemConfig})
})
}}
}