新增扣款逻辑及新字段
This commit is contained in:
parent
6d9923b4f2
commit
bf7b74d922
|
|
@ -28,6 +28,7 @@ func (p DefParty) RegisterList() []web_iris.Party {
|
|||
p.orderList(),
|
||||
p.orderEdit(),
|
||||
p.orderDetail(),
|
||||
p.orderGoodsUpdate(),
|
||||
p.orderPay(),
|
||||
//宠物
|
||||
p.petList(),
|
||||
|
|
|
|||
|
|
@ -57,6 +57,14 @@ func (p DefParty) orderCreate() web_iris.Party {
|
|||
OrderCreateError.DefFail(ctx, orderCreateRequest, "当前时间点不可预约")
|
||||
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()
|
||||
orderId := NextId.Generate().String()
|
||||
orderMain := models.OrderMain{
|
||||
|
|
@ -95,9 +103,20 @@ func (p DefParty) orderCreate() web_iris.Party {
|
|||
PayAmount: 0,
|
||||
ProjectionServiceTime: projectionServiceTime,
|
||||
}
|
||||
orderTotalAmount = orderTotalAmount + int(totalAmount)
|
||||
orderSubList = append(orderSubList, orderSub)
|
||||
}
|
||||
var userInfo *models.User
|
||||
database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo)
|
||||
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))
|
||||
db1 := tx.Model(&models.OrderSub{}).CreateInBatches(&orderSubList, len(orderSubList))
|
||||
db2 := tx.Model(&models.OrderMain{}).Create(&orderMain)
|
||||
|
|
@ -127,6 +146,7 @@ func GetOrderDetail(orderId string) OrderDetail {
|
|||
ServiceAddr: findUserServiceAddr,
|
||||
ServiceRemark: orderMain.ServiceRemark,
|
||||
CreateTime: orderMain.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
PayStatus: orderMain.PayStatus,
|
||||
}
|
||||
var subOrderList []SubOrder
|
||||
var orderSubList []models.OrderSub
|
||||
|
|
@ -198,6 +218,7 @@ type OrderDetail struct {
|
|||
CreateTime string `json:"createTime"` //创建时间
|
||||
SubOrderList []SubOrder `json:"subOrderList"` //子订单列表
|
||||
ServiceCar *models.ServiceCar `json:"serviceCar"` //服务车辆 只有主订单状态为 1 2 3的时候才会存在
|
||||
PayStatus int `json:"payStatus"` //支付状态 0未支付 1已支付
|
||||
}
|
||||
|
||||
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 {
|
||||
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ type PetAddOrEditRequest struct {
|
|||
Birthday string //生日
|
||||
PetId int //宠物类型
|
||||
Eunuch int //是否绝育 0否 1是 2未知
|
||||
Vaccine int //是否接种疫苗 0否 1是
|
||||
}
|
||||
|
||||
type PetAddOrEditResponse struct {
|
||||
|
|
@ -130,6 +131,7 @@ func (p DefParty) petAddOrEdit() web_iris.Party {
|
|||
Birthday: petAddOrEditRequest.Birthday,
|
||||
PetId: petAddOrEditRequest.PetId,
|
||||
Eunuch: petAddOrEditRequest.Eunuch,
|
||||
Vaccine: petAddOrEditRequest.Vaccine,
|
||||
}
|
||||
if petAddOrEditRequest.Id == 0 {
|
||||
database.Instance().Model(&models.Pet{}).Create(&pet)
|
||||
|
|
@ -152,6 +154,7 @@ func (p DefParty) petAddOrEdit() web_iris.Party {
|
|||
"Birthday": pet.Birthday,
|
||||
"PetId": pet.PetId,
|
||||
"Eunuch": pet.Eunuch,
|
||||
"Vaccine": pet.Vaccine,
|
||||
}
|
||||
database.Instance().Model(&pet).Updates(&updateValues)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ type Pet struct {
|
|||
Birthday string `json:"birthday"` //生日
|
||||
PetId int `json:"petId"` //宠物类型
|
||||
Eunuch int `json:"eunuch"` //是否绝育 0否 1是 2未知
|
||||
Vaccine int `gorm:"default:0" json:"vaccine"` //是否打疫苗 0否 1是
|
||||
LastServiceProj string `gorm:"default:'-'" json:"lastServiceProj"` //上次服务项目
|
||||
LastServiceDate string `gorm:"default:'-'" json:"lastServiceDate"` //上次服务时间
|
||||
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP;not null" json:"createTime"` //创建时间
|
||||
|
|
@ -122,6 +123,7 @@ type OrderMain struct {
|
|||
ServiceAddrId int64 `json:"serviceAddrId"` //服务地址信息
|
||||
ServiceRemark string `json:"serviceRemark"` //服务备注
|
||||
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间
|
||||
PayStatus int `gorm:"default:0" json:"payStatus"` //支付状态 0未支付 1已支付
|
||||
}
|
||||
|
||||
// OrderSub 子订单
|
||||
|
|
|
|||
Loading…
Reference in New Issue