update
This commit is contained in:
@@ -159,7 +159,7 @@ type GetUserInfoResponse struct {
|
||||
Uid int64 `json:"uid"`
|
||||
NickName string `json:"nickName"`
|
||||
HeadImgUrl string `json:"headImgUrl"`
|
||||
Discount float32 `json:"discount"`
|
||||
Discount float64 `json:"discount"`
|
||||
Amount int `json:"amount"`
|
||||
Role int `json:"role"`
|
||||
UserPets []UserPetInfo `json:"userPets"`
|
||||
@@ -182,7 +182,7 @@ func (p DefParty) getUserInfo() web_iris.Party {
|
||||
NickName: userInfo.NickName,
|
||||
HeadImgUrl: userInfo.HeadImgUrl,
|
||||
Amount: userInfo.Amount,
|
||||
Discount: float32(userInfo.Discount) / 100,
|
||||
Discount: float64(userInfo.Discount) / 100,
|
||||
Role: userInfo.Role,
|
||||
UserPets: GetUserPets(userInfo.Id),
|
||||
}
|
||||
|
||||
@@ -54,6 +54,8 @@ var (
|
||||
OrderError = Error{Code: 212, Msg: "当前订单无法修改"}
|
||||
CarNotExistError = Error{Code: 213, Msg: "当前用户未关联车辆"}
|
||||
OrderExistError = Error{Code: 214, Msg: "订单不存在"}
|
||||
PetInfoNotDelError = Error{Code: 215, Msg: "当前宠物存在待服务订单,无法删除"}
|
||||
PetInfoNotUpdateError = Error{Code: 216, Msg: "当前宠物存在待服务订单,无法修改"}
|
||||
)
|
||||
|
||||
func Success(ctx *context.Context, request any, data any) {
|
||||
|
||||
@@ -30,6 +30,7 @@ func (p DefParty) RegisterList() []web_iris.Party {
|
||||
p.orderDetail(),
|
||||
p.orderGoodsUpdate(),
|
||||
p.orderPay(),
|
||||
p.orderCancel(),
|
||||
//宠物
|
||||
p.petList(),
|
||||
p.petInfo(),
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"github.com/kataras/iris/v12/context"
|
||||
"go.uber.org/zap"
|
||||
"io"
|
||||
"pet-house.com/business/models"
|
||||
"pet-house.com/core/server/database"
|
||||
"pet-house.com/core/server/web/web_iris"
|
||||
"pet-house.com/core/server/zap_server"
|
||||
"strconv"
|
||||
@@ -41,7 +43,9 @@ func (p DefParty) goodsList() web_iris.Party {
|
||||
var goodsListRequest GoodsListRequest
|
||||
json.Unmarshal(body, &goodsListRequest)
|
||||
userPetInfo := GetUserPet(headerBaseInfo.Uid, goodsListRequest.Pid)
|
||||
if userPetInfo.PetInfo.Id == 0 {
|
||||
var userInfo *models.User
|
||||
database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo)
|
||||
if userPetInfo.PetInfo.Id == 0 && userInfo.Role == 0 {
|
||||
PetNotExistError.Fail(ctx, goodsListRequest)
|
||||
return
|
||||
}
|
||||
|
||||
+25
-14
@@ -8,6 +8,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"io"
|
||||
"math"
|
||||
"pet-house.com/business/models"
|
||||
"pet-house.com/business/utils"
|
||||
"pet-house.com/core/server/database"
|
||||
@@ -71,7 +72,7 @@ func (p DefParty) orderCreate() web_iris.Party {
|
||||
}
|
||||
haveReserve := checkOrderServiceTime(orderCreateRequest.ServiceTime, projectionServiceTime)
|
||||
if haveReserve {
|
||||
OrderCreateError.DefFail(ctx, orderCreateRequest, "当前时间点不可预约")
|
||||
OrderCreateError.DefFail(ctx, orderCreateRequest, "当前订单预估服务时长预计:"+strconv.Itoa(projectionServiceTime)+"分钟,服务时间过长,请更换时间段预约")
|
||||
return
|
||||
}
|
||||
for _, value := range orderCreateRequest.PetGoodsInfos {
|
||||
@@ -100,6 +101,7 @@ func (p DefParty) orderCreate() web_iris.Party {
|
||||
subOrderId := NextId.Generate().String()
|
||||
var totalAmount int32 = 0
|
||||
var projectionServiceTime = 0
|
||||
var goodsName string
|
||||
for _, value := range value.GoodsIds {
|
||||
goods := GoodsMap[value]
|
||||
totalAmount = totalAmount + goods.Price
|
||||
@@ -111,18 +113,22 @@ func (p DefParty) orderCreate() web_iris.Party {
|
||||
if goods.GoodsType == 1 || goods.GoodsType == 2 {
|
||||
mainGoods++
|
||||
}
|
||||
goodsName = goods.Name + "、" + goodsName
|
||||
}
|
||||
userPetInfo := GetUserPet(headerBaseInfo.Uid, value.PetId)
|
||||
var petInfo = "宠物名称:" + userPetInfo.PetInfo.NickName + "</br>品种:" + userPetInfo.PetBaseInfo.Assortment + "</br>服务项目:" + goodsName
|
||||
projectionServiceTimeAll += projectionServiceTime
|
||||
orderSub := models.OrderSub{
|
||||
OrderId: subOrderId,
|
||||
MainOrderId: orderMain.OrderId,
|
||||
OrderStatus: 1,
|
||||
PetId: value.PetId,
|
||||
PayType: 1,
|
||||
Discount: 100,
|
||||
TotalAmount: totalAmount,
|
||||
PayAmount: totalAmount,
|
||||
PayTime: time.Now(),
|
||||
OrderId: subOrderId,
|
||||
MainOrderId: orderMain.OrderId,
|
||||
OrderStatus: 1,
|
||||
PetId: value.PetId,
|
||||
PayType: 1,
|
||||
Discount: 100,
|
||||
TotalAmount: totalAmount,
|
||||
PayAmount: totalAmount,
|
||||
PetInfo: petInfo,
|
||||
//PayTime: time.Now(),
|
||||
ProjectionServiceTime: projectionServiceTime,
|
||||
}
|
||||
orderTotalAmount = orderTotalAmount + int(totalAmount)
|
||||
@@ -136,11 +142,13 @@ func (p DefParty) orderCreate() web_iris.Party {
|
||||
var userInfo *models.User
|
||||
database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo)
|
||||
if userInfo.Discount > 0 {
|
||||
orderTotalAmount = orderTotalAmount * (userInfo.Discount / 100)
|
||||
discount := float64(userInfo.Discount)
|
||||
orderTotalAmount = int(math.Round(float64(orderTotalAmount) * (discount / 100.0)))
|
||||
}
|
||||
tx := database.Instance().Begin()
|
||||
var db4 *gorm.DB
|
||||
if userInfo.Amount >= orderTotalAmount {
|
||||
var currAmount = userInfo.Amount
|
||||
orderMain.PayStatus = 1
|
||||
orderMain.PayTotalAmount = orderTotalAmount
|
||||
userInfo.Amount = userInfo.Amount - orderTotalAmount
|
||||
@@ -148,14 +156,16 @@ func (p DefParty) orderCreate() web_iris.Party {
|
||||
"Amount": userInfo.Amount,
|
||||
}
|
||||
db4 = tx.Model(&userInfo).Updates(&updateValues)
|
||||
orderMain.PayDiscount = userInfo.Discount
|
||||
zap_server.ZAPLOG.Info("会员金额扣除", zap.Any("用户ID", userInfo.Id), zap.Any("当前余额", currAmount), zap.Any("扣除余额", orderTotalAmount), zap.Any("剩余余额", userInfo.Amount), zap.Any("折扣", userInfo.Discount))
|
||||
}
|
||||
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)
|
||||
if db4.Error != nil || db.Error != nil || db1.Error != nil || db2.Error != nil {
|
||||
if (db4 != nil && db4.Error != nil) || db.Error != nil || db1.Error != nil || db2.Error != nil {
|
||||
tx.Callback()
|
||||
orderLock.Unlock()
|
||||
zap_server.ZAPLOG.Error("订单插入失败", zap.Any("db", db.Error), zap.Any("db1", db1.Error), zap.Any("db2", db2.Error))
|
||||
zap_server.ZAPLOG.Error("订单插入失败", zap.Any("db", db.Error), zap.Any("db1", db1.Error), zap.Any("db2", db2.Error), zap.Any("db4", db4.Error))
|
||||
OrderCreateError.Fail(ctx, orderCreateRequest)
|
||||
return
|
||||
}
|
||||
@@ -362,13 +372,14 @@ func (p DefParty) orderCancel() web_iris.Party {
|
||||
orderMain.PayTotalAmount = 0
|
||||
orderMain.PayStatus = 0
|
||||
}
|
||||
orderMain.OrderStatus = 5
|
||||
orderMain.OrderStatus = 4
|
||||
updateValues := map[string]interface{}{
|
||||
"OrderStatus": orderMain.OrderStatus,
|
||||
"PayStatus": orderMain.PayStatus,
|
||||
"PayTotalAmount": orderMain.PayTotalAmount,
|
||||
}
|
||||
database.Instance().Model(&orderMain).Updates(&updateValues)
|
||||
Success(ctx, orderCancelRequest, OrderCancelResponse{GetOrderDetail(orderMain.OrderId)})
|
||||
})
|
||||
}}
|
||||
}
|
||||
|
||||
+23
-4
@@ -34,7 +34,7 @@ type UserPetInfo struct {
|
||||
|
||||
func GetUserPets(uId int64) []UserPetInfo {
|
||||
var userPetList []models.Pet
|
||||
database.Instance().Model(&models.Pet{}).Where("uid = ?", uId).Find(&userPetList)
|
||||
database.Instance().Model(&models.Pet{}).Where("uid = ? and status = 1", uId).Find(&userPetList)
|
||||
var userPets []UserPetInfo
|
||||
if len(userPetList) > 0 {
|
||||
for _, pet := range userPetList {
|
||||
@@ -46,7 +46,7 @@ func GetUserPets(uId int64) []UserPetInfo {
|
||||
|
||||
func GetUserPet(uId int64, pId int64) UserPetInfo {
|
||||
var userPet models.Pet
|
||||
database.Instance().Model(&models.Pet{}).Where("uid = ? and id = ?", uId, pId).Find(&userPet)
|
||||
database.Instance().Model(&models.Pet{}).Where("uid = ? and id = ? and status = 1", uId, pId).Find(&userPet)
|
||||
return UserPetInfo{userPet, PetBaseInfoMap[userPet.PetId]}
|
||||
}
|
||||
|
||||
@@ -139,10 +139,20 @@ func (p DefParty) petAddOrEdit() web_iris.Party {
|
||||
pet.Id = petAddOrEditRequest.Id
|
||||
var userPetInfo models.Pet
|
||||
database.Instance().Model(&models.Pet{}).Where("id = ? and uid = ?", pet.Id, headerBaseInfo.Uid).Find(&userPetInfo)
|
||||
if userPetInfo.Id == 0 {
|
||||
var userInfo *models.User
|
||||
database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo)
|
||||
if userPetInfo.Id == 0 && userInfo.Role == 0 {
|
||||
PetNotExistError.Fail(ctx, petAddOrEditRequest)
|
||||
return
|
||||
}
|
||||
if userInfo.Role == 0 {
|
||||
var count int64
|
||||
database.Instance().Model(&models.OrderSub{}).Where("pet_id = ? and (order_status = 1 or order_status = 2)", userPetInfo.Id).Count(&count)
|
||||
if count > 0 {
|
||||
PetInfoNotUpdateError.Fail(ctx, petAddOrEditRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
updateValues := map[string]interface{}{
|
||||
"NickName": pet.NickName,
|
||||
"HeadImgType": pet.HeadImgType,
|
||||
@@ -201,7 +211,16 @@ func (p DefParty) delPet() web_iris.Party {
|
||||
PetNotExistError.Fail(ctx, delPetRequest)
|
||||
return
|
||||
}
|
||||
database.Instance().Where("id = ?", userPetInfo.PetId).Delete(&models.Pet{})
|
||||
var count int64
|
||||
database.Instance().Model(&models.OrderSub{}).Where("pet_id = ? and (order_status = 1 or order_status = 2)", userPetInfo.Id).Count(&count)
|
||||
if count > 0 {
|
||||
PetInfoNotDelError.Fail(ctx, delPetRequest)
|
||||
return
|
||||
}
|
||||
updateValues := map[string]interface{}{
|
||||
"Status": 0,
|
||||
}
|
||||
database.Instance().Model(&userPetInfo).Updates(&updateValues)
|
||||
Success(ctx, nil, nil)
|
||||
})
|
||||
}}
|
||||
|
||||
@@ -100,6 +100,7 @@ func (p DefParty) serviceAddOrEdit() web_iris.Party {
|
||||
}
|
||||
}*/
|
||||
//userServiceAddr.AddrArea = recogResponse.County
|
||||
|
||||
if serviceAddOrEditRequest.Id == 0 {
|
||||
database.Instance().Model(&models.UserServiceAddr{}).Create(&userServiceAddr)
|
||||
} else {
|
||||
@@ -121,6 +122,12 @@ func (p DefParty) serviceAddOrEdit() web_iris.Party {
|
||||
}
|
||||
database.Instance().Model(&userServiceAddr).Updates(&updateValues)
|
||||
}
|
||||
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)
|
||||
var userServiceAddrList []*models.UserServiceAddr
|
||||
database.Instance().Model(&models.UserServiceAddr{}).Where("uid = ?", headerBaseInfo.Uid).Find(&userServiceAddrList)
|
||||
for _, value := range userServiceAddrList {
|
||||
|
||||
Reference in New Issue
Block a user