新增接口及逻辑处理

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
business/api/admin.go Normal file
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)
})
}}
}

View File

@ -8,6 +8,8 @@ var OrderBase = "/order"
var ServiceBase = "/service" var ServiceBase = "/service"
var PetBase = "/pet" var PetBase = "/pet"
var CarBase = "/car" var CarBase = "/car"
var Admin = "/admin"
var System = "/system"
func (p DefParty) RegisterList() []web_iris.Party { func (p DefParty) RegisterList() []web_iris.Party {
ps := []web_iris.Party{ ps := []web_iris.Party{
@ -39,6 +41,9 @@ func (p DefParty) RegisterList() []web_iris.Party {
p.carServiceOrderList(), p.carServiceOrderList(),
p.carServiceProcess(), p.carServiceProcess(),
p.index(), p.index(),
//系统
p.systemConfigInfo(),
p.systemBanners(),
} }
return ps return ps
} }

View File

@ -11,6 +11,7 @@ import (
"pet-house.com/core/server/database" "pet-house.com/core/server/database"
"pet-house.com/core/server/web/web_iris" "pet-house.com/core/server/web/web_iris"
"pet-house.com/core/server/zap_server" "pet-house.com/core/server/zap_server"
"strconv"
"sync" "sync"
"time" "time"
) )
@ -66,25 +67,33 @@ func (p DefParty) orderCreate() web_iris.Party {
ServiceAddrId: orderCreateRequest.ServiceAddrId, ServiceAddrId: orderCreateRequest.ServiceAddrId,
ServiceRemark: "", ServiceRemark: "",
} }
var projectionServiceTimeAll = 0
var orderSubList []models.OrderSub var orderSubList []models.OrderSub
var orderSubDetailList []models.OrderDetail var orderSubDetailList []models.OrderDetail
for _, value := range orderCreateRequest.PetGoodsInfos { for _, value := range orderCreateRequest.PetGoodsInfos {
subOrderId := NextId.Generate().String() subOrderId := NextId.Generate().String()
var totalAmount int32 = 0 var totalAmount int32 = 0
var projectionServiceTime = 0
for _, value := range value.GoodsIds { for _, value := range value.GoodsIds {
goods := GoodsMap[value] goods := GoodsMap[value]
totalAmount = totalAmount + goods.Price totalAmount = totalAmount + goods.Price
orderSubDetailList = append(orderSubDetailList, models.OrderDetail{SubOrderId: subOrderId, GoodsId: value, Amount: 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{ orderSub := models.OrderSub{
OrderId: subOrderId, OrderId: subOrderId,
MainOrderId: orderMain.OrderId, MainOrderId: orderMain.OrderId,
Status: 1, Status: 1,
PetId: value.PetId, PetId: value.PetId,
PayType: 1, PayType: 1,
Discount: 100, Discount: 100,
TotalAmount: totalAmount, TotalAmount: totalAmount,
PayAmount: 0, PayAmount: 0,
ProjectionServiceTime: projectionServiceTime,
} }
orderSubList = append(orderSubList, orderSub) orderSubList = append(orderSubList, orderSub)
} }

40
business/api/system.go Normal file
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})
})
}}
}

View File

@ -9,6 +9,7 @@ require (
github.com/kellydunn/golang-geo v0.7.0 github.com/kellydunn/golang-geo v0.7.0
github.com/spf13/viper v1.18.2 github.com/spf13/viper v1.18.2
go.uber.org/zap v1.27.0 go.uber.org/zap v1.27.0
gorm.io/gorm v1.25.8
pet-house.com/core v0.0.0 pet-house.com/core v0.0.0
) )
@ -95,7 +96,6 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/mysql v1.5.6 // indirect gorm.io/driver/mysql v1.5.6 // indirect
gorm.io/gorm v1.25.8 // indirect
) )
replace pet-house.com/core => ../core replace pet-house.com/core => ../core

View File

@ -97,40 +97,44 @@ type PetGoods struct {
// SystemConfig 系统配置 // SystemConfig 系统配置
type SystemConfig struct { type SystemConfig struct {
id int `gorm:"primaryKey;autoIncrement" json:"id"` //id Id int `gorm:"primaryKey;autoIncrement" json:"id"` //id
Name string `json:"name"` //名称 Name string `json:"name"` //名称
Desc string `json:"desc"` //描述 Content string `json:"content"` //内容
ConfigType string `json:"configType"` //类型 1关于我们 2在线客服 3拨打电话 ConfigType string `json:"configType"` //类型 0banner 1关于我们 2客服电话
DescType int `json:"descType"` //1文本 2链接 ContentType int `json:"contentType"` //1文本 2链接
Sort int `json:"sort"` //排序位
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间
} }
// OrderMain 主订单 // OrderMain 主订单
type OrderMain struct { type OrderMain struct {
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
OrderId string `gorm:"index;unique;not null" json:"orderId"` //主订单号 OrderId string `gorm:"index;unique;not null" json:"orderId"` //主订单号
Uid int64 `gorm:"index;not null" json:"uid"` //用户id Uid int64 `gorm:"index;not null" json:"uid"` //用户id
Status int `json:"status"` //主订单状态 1待服务 2服务中 3已完成 4已派单 5已取消 Status int `json:"status"` //主订单状态 1待服务 2服务中 3已完成 4已派单 5已取消
ServiceTime string `json:"serviceTime"` //服务时间 ServiceTime string `json:"serviceTime"` //服务时间
ServiceAddrId int64 `json:"serviceAddrId"` //服务地址信息 ProjectionServiceTime int `json:"projectionServiceTime"` //服务预估时长
ServiceRemark string `json:"serviceRemark"` //服务备注 ServiceAddrId int64 `json:"serviceAddrId"` //服务地址信息
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间 ServiceRemark string `json:"serviceRemark"` //服务备注
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间
} }
// OrderSub 子订单 // OrderSub 子订单
type OrderSub struct { type OrderSub struct {
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
OrderId string `gorm:"index" json:"orderId"` //子订单ID OrderId string `gorm:"index" json:"orderId"` //子订单ID
MainOrderId string `gorm:"index" json:"mainOrderId"` //主订单ID MainOrderId string `gorm:"index" json:"mainOrderId"` //主订单ID
Status int `gorm:"not null" json:"status"` //子订单状态 1待服务 2服务中 3已完成 4已取消 Status int `gorm:"not null" json:"status"` //子订单状态 1待服务 2服务中 3已完成 4已取消
PetId int64 `gorm:"index" json:"petId"` //宠物ID PetId int64 `gorm:"index" json:"petId"` //宠物ID
PayType int `gorm:"not null" json:"payType"` //支付方式 1线下 2线上 PayType int `gorm:"not null" json:"payType"` //支付方式 1线下 2线上
Discount int `json:"discount"` //折扣 Discount int `json:"discount"` //折扣
TotalAmount int32 `gorm:"not null" json:"totalAmount"` //总金额 TotalAmount int32 `gorm:"not null" json:"totalAmount"` //总金额
PayAmount int32 `json:"payAmount"` //实际支付金额 ProjectionServiceTime int `json:"projectionServiceTime"` //服务预估时长
PayTime time.Time `gorm:"type:timestamp;" json:"payTime"` //支付时间 PayAmount int32 `json:"payAmount"` //实际支付金额
PayRemark string `json:"payRemark"` //支付备注 PayTime time.Time `gorm:"type:timestamp;" json:"payTime"` //支付时间
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间 PayRemark string `json:"payRemark"` //支付备注
UpdateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP" json:"-"` //更新时间 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:"-"` //更新时间
} }
// OrderDetail 订单明细 // OrderDetail 订单明细

View File

@ -2,6 +2,7 @@ package orm
import ( import (
"errors" "errors"
"github.com/kataras/iris/v12"
"strings" "strings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"