新增接口及逻辑处理
This commit is contained in:
parent
c9e0142da0
commit
1ae553d0d2
|
|
@ -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)
|
||||
})
|
||||
}}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
})
|
||||
}}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ require (
|
|||
github.com/kellydunn/golang-geo v0.7.0
|
||||
github.com/spf13/viper v1.18.2
|
||||
go.uber.org/zap v1.27.0
|
||||
gorm.io/gorm v1.25.8
|
||||
pet-house.com/core v0.0.0
|
||||
)
|
||||
|
||||
|
|
@ -95,7 +96,6 @@ require (
|
|||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
gorm.io/driver/mysql v1.5.6 // indirect
|
||||
gorm.io/gorm v1.25.8 // indirect
|
||||
)
|
||||
|
||||
replace pet-house.com/core => ../core
|
||||
|
|
|
|||
|
|
@ -97,40 +97,44 @@ type PetGoods struct {
|
|||
|
||||
// SystemConfig 系统配置
|
||||
type SystemConfig struct {
|
||||
id int `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
||||
Name string `json:"name"` //名称
|
||||
Desc string `json:"desc"` //描述
|
||||
ConfigType string `json:"configType"` //类型 1关于我们 2在线客服 3拨打电话
|
||||
DescType int `json:"descType"` //1文本 2链接
|
||||
Id int `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
||||
Name string `json:"name"` //名称
|
||||
Content string `json:"content"` //内容
|
||||
ConfigType string `json:"configType"` //类型 0banner 1关于我们 2客服电话
|
||||
ContentType int `json:"contentType"` //1文本 2链接
|
||||
Sort int `json:"sort"` //排序位
|
||||
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间
|
||||
}
|
||||
|
||||
// OrderMain 主订单
|
||||
type OrderMain struct {
|
||||
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
||||
OrderId string `gorm:"index;unique;not null" json:"orderId"` //主订单号
|
||||
Uid int64 `gorm:"index;not null" json:"uid"` //用户id
|
||||
Status int `json:"status"` //主订单状态 1待服务 2服务中 3已完成 4已派单 5已取消
|
||||
ServiceTime string `json:"serviceTime"` //服务时间
|
||||
ServiceAddrId int64 `json:"serviceAddrId"` //服务地址信息
|
||||
ServiceRemark string `json:"serviceRemark"` //服务备注
|
||||
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间
|
||||
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
||||
OrderId string `gorm:"index;unique;not null" json:"orderId"` //主订单号
|
||||
Uid int64 `gorm:"index;not null" json:"uid"` //用户id
|
||||
Status int `json:"status"` //主订单状态 1待服务 2服务中 3已完成 4已派单 5已取消
|
||||
ServiceTime string `json:"serviceTime"` //服务时间
|
||||
ProjectionServiceTime int `json:"projectionServiceTime"` //服务预估时长
|
||||
ServiceAddrId int64 `json:"serviceAddrId"` //服务地址信息
|
||||
ServiceRemark string `json:"serviceRemark"` //服务备注
|
||||
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间
|
||||
}
|
||||
|
||||
// OrderSub 子订单
|
||||
type OrderSub struct {
|
||||
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
||||
OrderId string `gorm:"index" json:"orderId"` //子订单ID
|
||||
MainOrderId string `gorm:"index" json:"mainOrderId"` //主订单ID
|
||||
Status int `gorm:"not null" json:"status"` //子订单状态 1待服务 2服务中 3已完成 4已取消
|
||||
PetId int64 `gorm:"index" json:"petId"` //宠物ID
|
||||
PayType int `gorm:"not null" json:"payType"` //支付方式 1线下 2线上
|
||||
Discount int `json:"discount"` //折扣
|
||||
TotalAmount int32 `gorm:"not null" json:"totalAmount"` //总金额
|
||||
PayAmount int32 `json:"payAmount"` //实际支付金额
|
||||
PayTime time.Time `gorm:"type:timestamp;" json:"payTime"` //支付时间
|
||||
PayRemark string `json:"payRemark"` //支付备注
|
||||
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:"-"` //更新时间
|
||||
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
||||
OrderId string `gorm:"index" json:"orderId"` //子订单ID
|
||||
MainOrderId string `gorm:"index" json:"mainOrderId"` //主订单ID
|
||||
Status int `gorm:"not null" json:"status"` //子订单状态 1待服务 2服务中 3已完成 4已取消
|
||||
PetId int64 `gorm:"index" json:"petId"` //宠物ID
|
||||
PayType int `gorm:"not null" json:"payType"` //支付方式 1线下 2线上
|
||||
Discount int `json:"discount"` //折扣
|
||||
TotalAmount int32 `gorm:"not null" json:"totalAmount"` //总金额
|
||||
ProjectionServiceTime int `json:"projectionServiceTime"` //服务预估时长
|
||||
PayAmount int32 `json:"payAmount"` //实际支付金额
|
||||
PayTime time.Time `gorm:"type:timestamp;" json:"payTime"` //支付时间
|
||||
PayRemark string `json:"payRemark"` //支付备注
|
||||
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 订单明细
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package orm
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/kataras/iris/v12"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
|
|
|||
Loading…
Reference in New Issue