From 1ae553d0d25ed00e43274b49baba0e9492dc5e38 Mon Sep 17 00:00:00 2001 From: "yan.y" Date: Thu, 11 Apr 2024 17:10:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3=E5=8F=8A?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/api/admin.go | 47 +++++++++++++++++++++++++ business/api/control.go | 5 +++ business/api/order.go | 25 ++++++++----- business/api/system.go | 40 +++++++++++++++++++++ business/go.mod | 2 +- business/models/dataModel.go | 56 ++++++++++++++++-------------- core/server/database/orm/struct.go | 1 + 7 files changed, 141 insertions(+), 35 deletions(-) create mode 100644 business/api/admin.go create mode 100644 business/api/system.go diff --git a/business/api/admin.go b/business/api/admin.go new file mode 100644 index 0000000..6ef2090 --- /dev/null +++ b/business/api/admin.go @@ -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) + }) + }} +} diff --git a/business/api/control.go b/business/api/control.go index 4822dad..09ec82a 100644 --- a/business/api/control.go +++ b/business/api/control.go @@ -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 } diff --git a/business/api/order.go b/business/api/order.go index 4a098aa..cc4a3f8 100644 --- a/business/api/order.go +++ b/business/api/order.go @@ -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) } diff --git a/business/api/system.go b/business/api/system.go new file mode 100644 index 0000000..439ef96 --- /dev/null +++ b/business/api/system.go @@ -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}) + }) + }} +} diff --git a/business/go.mod b/business/go.mod index 4cf33fd..9e78790 100644 --- a/business/go.mod +++ b/business/go.mod @@ -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 diff --git a/business/models/dataModel.go b/business/models/dataModel.go index d20c683..8ed45e3 100644 --- a/business/models/dataModel.go +++ b/business/models/dataModel.go @@ -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 订单明细 diff --git a/core/server/database/orm/struct.go b/core/server/database/orm/struct.go index fc498b3..7f19273 100644 --- a/core/server/database/orm/struct.go +++ b/core/server/database/orm/struct.go @@ -2,6 +2,7 @@ package orm import ( "errors" + "github.com/kataras/iris/v12" "strings" "github.com/gin-gonic/gin"