This commit is contained in:
yan.y 2024-05-15 21:14:43 +08:00
parent 8c37bf7e93
commit 6d86177676
6 changed files with 77 additions and 15 deletions

View File

@ -129,17 +129,17 @@ func (p DefParty) carServiceProcess() web_iris.Party {
return
}
subOrderInfo.OrderStatus = 3
subOrderInfo.PayStatus = 1
subOrderInfo.PayTime = time.Now()
if carServiceProcessRequest.PayAmount > 0 {
subOrderInfo.PayAmount = carServiceProcessRequest.PayAmount
subOrderInfo.PayTime = time.Now()
subOrderInfo.PayStatus = 1
}
subOrderInfo.PayRemark = carServiceProcessRequest.PayRemark
database.Instance().Save(&subOrderInfo)
var count int64
database.Instance().Model(&models.OrderSub{}).Where("main_order_id = ?", subOrderInfo.MainOrderId).Count(&count)
var countStatus int64
database.Instance().Model(&models.OrderSub{}).Where("main_order_id = ? and status = 3", subOrderInfo.MainOrderId).Count(&countStatus)
database.Instance().Model(&models.OrderSub{}).Where("main_order_id = ? and order_status = 3", subOrderInfo.MainOrderId).Count(&countStatus)
var payStatus int64
database.Instance().Model(&models.OrderSub{}).Where("main_order_id = ? and pay_status = 1", subOrderInfo.MainOrderId).Count(&payStatus)
if count == payStatus {

View File

@ -56,6 +56,7 @@ var (
OrderExistError = Error{Code: 214, Msg: "订单不存在"}
PetInfoNotDelError = Error{Code: 215, Msg: "当前宠物存在待服务订单,无法删除"}
PetInfoNotUpdateError = Error{Code: 216, Msg: "当前宠物存在待服务订单,无法修改"}
OrderUpdateBalanceNotEnough = Error{Code: 217, Msg: "当前余额不足"}
)
func Success(ctx *context.Context, request any, data any) {

View File

@ -157,8 +157,18 @@ func (p DefParty) orderCreate() web_iris.Party {
}
db4 = tx.Model(&userInfo).Updates(&updateValues)
orderMain.PayDiscount = userInfo.Discount
for index := range orderSubList {
orderSubList[index].PayType = 3
}
zap_server.ZAPLOG.Info("会员金额扣除", zap.Any("用户ID", userInfo.Id), zap.Any("当前余额", currAmount), zap.Any("扣除余额", orderTotalAmount), zap.Any("剩余余额", userInfo.Amount), zap.Any("折扣", userInfo.Discount))
}
var findUserServiceAddr models.UserServiceAddr
database.Instance().Model(&models.UserServiceAddr{}).Where("id = ? and uid = ?", orderCreateRequest.ServiceAddrId, headerBaseInfo.Uid).Find(&findUserServiceAddr)
userInfo.Mobile = findUserServiceAddr.Mobile
updateValues := map[string]interface{}{
"Mobile": userInfo.Mobile,
}
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)
@ -231,7 +241,7 @@ func checkOrderServiceTime(serviceTime string, projectionServiceTime int) bool {
var orderMainTmpList []orderMainTmp
//服务时间>=预约时间 and 服务时间<=预计结束时间 时间范围内无订单才可预约
database.Instance().Model(&models.OrderMain{}).Where("service_time >= ? and service_time <= DATE_FORMAT(DATE_ADD('"+serviceTime+"', INTERVAL "+strconv.Itoa(projectionServiceTime)+" MINUTE), '%Y-%m-%d %H:%i')", serviceTime).Find(&orderMainTmpList)
database.Instance().Model(&models.OrderMain{}).Where("service_time >= ? and service_time <= DATE_FORMAT(DATE_ADD('"+serviceTime+"', INTERVAL "+strconv.Itoa(projectionServiceTime)+" MINUTE), '%Y-%m-%d %H:%i') and order_status != 3 and order_status != 4", serviceTime).Find(&orderMainTmpList)
//时间点订单数量<服务车辆*车辆单次服务数量 才可接受预约
if len(orderMainTmpList) > 0 {
return len(orderMainTmpList) >= len(CarMap)*CarServiceNum
@ -414,7 +424,7 @@ func (p DefParty) orderServiceTime() web_iris.Party {
ProjectionServiceTime int
}
var orderMainTmpList []orderMainTmp
database.Instance().Model(&models.OrderMain{}).Where("service_time >= DATE_SUB(NOW(), INTERVAL 7 DAY) and status != 3 and status != 5").Find(&orderMainTmpList)
database.Instance().Model(&models.OrderMain{}).Where("service_time >= DATE_SUB(NOW(), INTERVAL 7 DAY) and order_status != 3 and order_status != 4").Find(&orderMainTmpList)
var orderTimeMap = make(map[string]string)
var orderTimeNum = make(map[string]int)
for _, value := range orderMainTmpList {
@ -535,16 +545,60 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party {
OrderExistError.Fail(ctx, orderGoodsUpdateRequest)
return
}
database.Instance().Where("sub_order_id = ?", orderGoodsUpdateRequest.OrderId).Delete(&models.OrderDetail{})
var totalAmount int32 = 0
var orderMain models.OrderMain
database.Instance().Model(&models.OrderMain{}).Where("order_id = ?", orderSub.MainOrderId).Find(&orderMain)
var totalAmount = 0
var projectionServiceTime = 0
for _, value := range orderGoodsUpdateRequest.GoodsIds {
goods := GoodsMap[value]
totalAmount = totalAmount + goods.Price
totalAmount = totalAmount + int(goods.Price)
if goods.Time != "/" && len(goods.Time) > 0 {
goodsTime, _ := strconv.Atoi(goods.Time)
projectionServiceTime += goodsTime
}
}
//非当前订单
var orderSubList []models.OrderSub
database.Instance().Model(&models.OrderSub{}).Where("main_order_id = ? and order_id != ", orderMain.OrderId, orderGoodsUpdateRequest.OrderId).Find(&orderSubList)
//新价格
var newAmount = totalAmount
var allProjectionServiceTime = projectionServiceTime
for _, value := range orderSubList {
newAmount = newAmount + int(value.TotalAmount)
allProjectionServiceTime = allProjectionServiceTime + value.ProjectionServiceTime
}
//已支付
if orderMain.PayStatus == 1 {
var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", orderMain.Uid).Find(&userInfo)
//先退还
userInfo.Amount = userInfo.Amount + orderMain.PayTotalAmount
if userInfo.Discount > 0 {
discount := float64(userInfo.Discount)
newAmount = int(math.Round(float64(newAmount) * (discount / 100.0)))
}
//余额不足
if userInfo.Amount < newAmount {
OrderUpdateBalanceNotEnough.DefFail(ctx, orderGoodsUpdateRequest, "原订单金额:"+strconv.Itoa(orderMain.PayTotalAmount)+" 修改后订单金额:"+strconv.Itoa(newAmount)+";修改服务项目后余额不足,请充值后再修改")
return
}
var preAmount = orderMain.PayTotalAmount
orderMain.PayTotalAmount = newAmount
userInfo.Amount = userInfo.Amount - newAmount
updateValues := map[string]interface{}{
"Amount": userInfo.Amount,
}
database.Instance().Model(&userInfo).Updates(&updateValues)
orderMain.PayDiscount = userInfo.Discount
zap_server.ZAPLOG.Info("会员金额扣除", zap.Any("用户ID", userInfo.Id), zap.Any("当前余额", userInfo.Amount), zap.Any("商品修改之前金额", preAmount), zap.Any("商品修改之后金额", orderMain.PayTotalAmount), zap.Any("折扣", userInfo.Discount))
}
database.Instance().Where("sub_order_id = ?", orderGoodsUpdateRequest.OrderId).Delete(&models.OrderDetail{})
for _, value := range orderGoodsUpdateRequest.GoodsIds {
goods := GoodsMap[value]
orderDetail := models.OrderDetail{
SubOrderId: orderGoodsUpdateRequest.OrderId,
GoodsId: goods.Id,
@ -552,14 +606,20 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party {
}
database.Instance().Model(&models.OrderDetail{}).Create(&orderDetail)
}
orderSub.TotalAmount = totalAmount
orderSub.TotalAmount = int32(totalAmount)
orderSub.ProjectionServiceTime = projectionServiceTime
updateValues := map[string]interface{}{
"TotalAmount": orderSub.TotalAmount,
"ProjectionServiceTime": orderSub.ProjectionServiceTime,
}
orderMain.ProjectionServiceTime = allProjectionServiceTime
updateValues1 := map[string]interface{}{
"PayTotalAmount": orderMain.PayTotalAmount,
"ProjectionServiceTime": orderMain.ProjectionServiceTime,
}
database.Instance().Model(&orderMain).Updates(&updateValues1)
database.Instance().Model(&orderSub).Updates(&updateValues)
Success(ctx, orderGoodsUpdateRequest, OrderDetailResponse{GetOrderDetail(orderSub.MainOrderId)})
})
}}

View File

@ -122,12 +122,12 @@ func (p DefParty) serviceAddOrEdit() web_iris.Party {
}
database.Instance().Model(&userServiceAddr).Updates(&updateValues)
}
var userInfo *models.User
/*var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo)
updateValues := map[string]interface{}{
"Mobile": userInfo.Mobile,
}
database.Instance().Model(&userInfo).Updates(&updateValues)
database.Instance().Model(&userInfo).Updates(&updateValues)*/
var userServiceAddrList []*models.UserServiceAddr
database.Instance().Model(&models.UserServiceAddr{}).Where("uid = ?", headerBaseInfo.Uid).Find(&userServiceAddrList)
for _, value := range userServiceAddrList {

View File

@ -122,7 +122,7 @@ 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
OrderStatus int `json:"status"` //主订单状态 1待服务 2服务中 3已完成 4已派单 5已取消
OrderStatus int `json:"status"` //主订单状态 1待服务 2服务中 3已完成 4已取消
ServiceTime string `json:"serviceTime"` //服务时间
ProjectionServiceTime int `json:"projectionServiceTime"` //服务预估时长
ServiceAddrId int64 `json:"serviceAddrId"` //服务地址信息
@ -141,7 +141,7 @@ type OrderSub struct {
MainOrderId string `gorm:"index" json:"mainOrderId"` //主订单ID
OrderStatus 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线上
PayType int `gorm:"not null" json:"payType"` //支付方式 1线下 2线上 3会员余额
Discount int `json:"discount"` //折扣
TotalAmount int32 `gorm:"not null" json:"totalAmount"` //总金额
ProjectionServiceTime int `json:"projectionServiceTime"` //服务预估时长

View File

@ -40,11 +40,12 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil
// 工作时间范围
workStart := 9
workEnd := 19
workEnd := 22
var dayHoursMap = make(map[string][]TimeObject)
var serviceDaysMap = make(map[string]string)
// 循环生成每半个小时的整点时间列表,直到一周后
oneWeekLater := currentTime.Add(time.Duration(day) * 24 * time.Hour)
oneWeekLater = time.Date(oneWeekLater.Year(), oneWeekLater.Month(), oneWeekLater.Day(), 23, 0, 0, 0, oneWeekLater.Location())
for _, dayTime := range times {
serviceDaysMap[dayTime] = dayTime
}