新增扣款逻辑及新字段

This commit is contained in:
yan.y 2024-05-08 19:08:58 +08:00
parent 6d9923b4f2
commit bf7b74d922
4 changed files with 75 additions and 0 deletions

View File

@ -28,6 +28,7 @@ func (p DefParty) RegisterList() []web_iris.Party {
p.orderList(), p.orderList(),
p.orderEdit(), p.orderEdit(),
p.orderDetail(), p.orderDetail(),
p.orderGoodsUpdate(),
p.orderPay(), p.orderPay(),
//宠物 //宠物
p.petList(), p.petList(),

View File

@ -57,6 +57,14 @@ func (p DefParty) orderCreate() web_iris.Party {
OrderCreateError.DefFail(ctx, orderCreateRequest, "当前时间点不可预约") OrderCreateError.DefFail(ctx, orderCreateRequest, "当前时间点不可预约")
return return
} }
for _, value := range orderCreateRequest.PetGoodsInfos {
userPet := GetUserPet(headerBaseInfo.Uid, value.PetId)
if userPet.PetInfo.Vaccine == 0 {
OrderCreateError.DefFail(ctx, orderCreateRequest, "当前订单存在未接种疫苗的宠物,无法下单")
return
}
}
var orderTotalAmount = 0
orderLock.Lock() orderLock.Lock()
orderId := NextId.Generate().String() orderId := NextId.Generate().String()
orderMain := models.OrderMain{ orderMain := models.OrderMain{
@ -95,9 +103,20 @@ func (p DefParty) orderCreate() web_iris.Party {
PayAmount: 0, PayAmount: 0,
ProjectionServiceTime: projectionServiceTime, ProjectionServiceTime: projectionServiceTime,
} }
orderTotalAmount = orderTotalAmount + int(totalAmount)
orderSubList = append(orderSubList, orderSub) orderSubList = append(orderSubList, orderSub)
} }
var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo)
tx := database.Instance().Begin() tx := database.Instance().Begin()
if userInfo.Amount >= orderTotalAmount {
orderMain.PayStatus = 1
userInfo.Amount = userInfo.Amount - orderTotalAmount
updateValues := map[string]interface{}{
"Amount": userInfo.Amount,
}
tx.Model(&userInfo).Updates(&updateValues)
}
db := tx.Model(&models.OrderDetail{}).CreateInBatches(&orderSubDetailList, len(orderSubDetailList)) db := tx.Model(&models.OrderDetail{}).CreateInBatches(&orderSubDetailList, len(orderSubDetailList))
db1 := tx.Model(&models.OrderSub{}).CreateInBatches(&orderSubList, len(orderSubList)) db1 := tx.Model(&models.OrderSub{}).CreateInBatches(&orderSubList, len(orderSubList))
db2 := tx.Model(&models.OrderMain{}).Create(&orderMain) db2 := tx.Model(&models.OrderMain{}).Create(&orderMain)
@ -127,6 +146,7 @@ func GetOrderDetail(orderId string) OrderDetail {
ServiceAddr: findUserServiceAddr, ServiceAddr: findUserServiceAddr,
ServiceRemark: orderMain.ServiceRemark, ServiceRemark: orderMain.ServiceRemark,
CreateTime: orderMain.CreateTime.Format("2006-01-02 15:04:05"), CreateTime: orderMain.CreateTime.Format("2006-01-02 15:04:05"),
PayStatus: orderMain.PayStatus,
} }
var subOrderList []SubOrder var subOrderList []SubOrder
var orderSubList []models.OrderSub var orderSubList []models.OrderSub
@ -198,6 +218,7 @@ type OrderDetail struct {
CreateTime string `json:"createTime"` //创建时间 CreateTime string `json:"createTime"` //创建时间
SubOrderList []SubOrder `json:"subOrderList"` //子订单列表 SubOrderList []SubOrder `json:"subOrderList"` //子订单列表
ServiceCar *models.ServiceCar `json:"serviceCar"` //服务车辆 只有主订单状态为 1 2 3的时候才会存在 ServiceCar *models.ServiceCar `json:"serviceCar"` //服务车辆 只有主订单状态为 1 2 3的时候才会存在
PayStatus int `json:"payStatus"` //支付状态 0未支付 1已支付
} }
type OrderListResponse struct { type OrderListResponse struct {
@ -380,6 +401,54 @@ func (p DefParty) orderDetail() web_iris.Party {
}} }}
} }
type OrderGoodsUpdateRequest struct {
OrderId string
GoodsIds []int64
}
// 修改订单商品
func (p DefParty) orderGoodsUpdate() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(OrderBase+"/orderGoodsUpdate", func(ctx *context.Context) {
body, _ := io.ReadAll(ctx.Request().Body)
var orderGoodsUpdateRequest OrderGoodsUpdateRequest
json.Unmarshal(body, &orderGoodsUpdateRequest)
var orderSub models.OrderSub
database.Instance().Model(&models.OrderSub{}).Where("order_id = ?", orderGoodsUpdateRequest.OrderId).Find(&orderSub)
if len(orderSub.OrderId) == 0 {
OrderExistError.Fail(ctx, orderGoodsUpdateRequest)
return
}
database.Instance().Where("sub_order_id = ?", orderGoodsUpdateRequest.OrderId).Delete(&models.OrderDetail{})
var totalAmount int32 = 0
var projectionServiceTime = 0
for _, value := range orderGoodsUpdateRequest.GoodsIds {
goods := GoodsMap[value]
totalAmount = totalAmount + goods.Price
if goods.Time != "/" && len(goods.Time) > 0 {
goodsTime, _ := strconv.Atoi(goods.Time)
projectionServiceTime += goodsTime
}
orderDetail := models.OrderDetail{
SubOrderId: orderGoodsUpdateRequest.OrderId,
GoodsId: goods.Id,
Amount: goods.Price,
}
database.Instance().Model(&models.OrderDetail{}).Create(&orderDetail)
}
orderSub.TotalAmount = totalAmount
orderSub.ProjectionServiceTime = projectionServiceTime
updateValues := map[string]interface{}{
"TotalAmount": orderSub.TotalAmount,
"ProjectionServiceTime": orderSub.ProjectionServiceTime,
}
database.Instance().Model(&orderSub).Updates(&updateValues)
Success(ctx, orderGoodsUpdateRequest, OrderDetailResponse{GetOrderDetail(orderSub.MainOrderId)})
})
}}
}
// 支付 // 支付
func (p DefParty) orderPay() web_iris.Party { func (p DefParty) orderPay() 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) {

View File

@ -100,6 +100,7 @@ type PetAddOrEditRequest struct {
Birthday string //生日 Birthday string //生日
PetId int //宠物类型 PetId int //宠物类型
Eunuch int //是否绝育 0否 1是 2未知 Eunuch int //是否绝育 0否 1是 2未知
Vaccine int //是否接种疫苗 0否 1是
} }
type PetAddOrEditResponse struct { type PetAddOrEditResponse struct {
@ -130,6 +131,7 @@ func (p DefParty) petAddOrEdit() web_iris.Party {
Birthday: petAddOrEditRequest.Birthday, Birthday: petAddOrEditRequest.Birthday,
PetId: petAddOrEditRequest.PetId, PetId: petAddOrEditRequest.PetId,
Eunuch: petAddOrEditRequest.Eunuch, Eunuch: petAddOrEditRequest.Eunuch,
Vaccine: petAddOrEditRequest.Vaccine,
} }
if petAddOrEditRequest.Id == 0 { if petAddOrEditRequest.Id == 0 {
database.Instance().Model(&models.Pet{}).Create(&pet) database.Instance().Model(&models.Pet{}).Create(&pet)
@ -152,6 +154,7 @@ func (p DefParty) petAddOrEdit() web_iris.Party {
"Birthday": pet.Birthday, "Birthday": pet.Birthday,
"PetId": pet.PetId, "PetId": pet.PetId,
"Eunuch": pet.Eunuch, "Eunuch": pet.Eunuch,
"Vaccine": pet.Vaccine,
} }
database.Instance().Model(&pet).Updates(&updateValues) database.Instance().Model(&pet).Updates(&updateValues)
} }

View File

@ -35,6 +35,7 @@ type Pet struct {
Birthday string `json:"birthday"` //生日 Birthday string `json:"birthday"` //生日
PetId int `json:"petId"` //宠物类型 PetId int `json:"petId"` //宠物类型
Eunuch int `json:"eunuch"` //是否绝育 0否 1是 2未知 Eunuch int `json:"eunuch"` //是否绝育 0否 1是 2未知
Vaccine int `gorm:"default:0" json:"vaccine"` //是否打疫苗 0否 1是
LastServiceProj string `gorm:"default:'-'" json:"lastServiceProj"` //上次服务项目 LastServiceProj string `gorm:"default:'-'" json:"lastServiceProj"` //上次服务项目
LastServiceDate string `gorm:"default:'-'" json:"lastServiceDate"` //上次服务时间 LastServiceDate string `gorm:"default:'-'" json:"lastServiceDate"` //上次服务时间
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP;not null" json:"createTime"` //创建时间 CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP;not null" json:"createTime"` //创建时间
@ -122,6 +123,7 @@ type OrderMain struct {
ServiceAddrId int64 `json:"serviceAddrId"` //服务地址信息 ServiceAddrId int64 `json:"serviceAddrId"` //服务地址信息
ServiceRemark string `json:"serviceRemark"` //服务备注 ServiceRemark string `json:"serviceRemark"` //服务备注
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间 CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间
PayStatus int `gorm:"default:0" json:"payStatus"` //支付状态 0未支付 1已支付
} }
// OrderSub 子订单 // OrderSub 子订单