Compare commits

...

27 Commits
master ... v1

Author SHA1 Message Date
yan.y 4338653110 体重修改 2025-05-21 11:47:16 +08:00
yan.y ee2b52ebf1 体重修改 2025-03-14 14:27:00 +08:00
yan.y 1898623537 预约时间修正 2025-02-18 18:13:25 +08:00
yan.y 0080963f2b 预约时间修正 2025-02-14 14:11:30 +08:00
yan.y 385439997b update 2025-01-22 18:42:11 +08:00
yiyan 7e018a1e68 优惠券问题修复 2025-01-09 22:43:19 +08:00
yan.y 35251458c6 优惠券修正 2025-01-09 15:07:42 +08:00
yan.y 596645cbf1 update 2025-01-04 23:05:32 +08:00
yiyan 54a082f8f1 接口更新 2024-12-29 20:51:14 +08:00
yan.y da28f930a9 Merge remote-tracking branch 'origin/v1' into v1 2024-12-29 12:38:47 +08:00
yan.y e0d302c5f5 update 2024-12-28 19:10:40 +08:00
yiyan 315b9d9050 接口更新 2024-12-21 21:59:20 +08:00
yan.y 346412fef8 update 2024-12-21 20:57:59 +08:00
yan.y d12f459f39 update 2024-12-21 20:08:14 +08:00
yan.y 059191317c update 2024-12-21 20:00:53 +08:00
yiyan ce1a74983a 接口更新 2024-12-15 21:49:17 +08:00
yan.y 6da775c9bd 新增接口 2024-12-01 16:37:46 +08:00
yiyan 7973cd9ca8 接口更新 2024-11-25 00:36:01 +08:00
yan.y 101e819b66 新增接口 2024-11-18 15:17:25 +08:00
yiyan bfcee075b6 新增字段 2024-11-18 01:12:08 +08:00
yiyan 3e2ccbeb41 新增接口 2024-11-18 00:59:54 +08:00
yan.y cc4957813b 新增字段 2024-11-17 23:54:05 +08:00
yan.y 25dafdf7e5 新增系列配置 2024-11-16 15:25:21 +08:00
yan.y ef52ecc2be 新增系列配置 2024-10-12 14:56:25 +08:00
yan.y e112772826 优惠券相关逻辑 2024-08-14 16:11:31 +08:00
yan.y 39aa34f6c2 优惠券相关逻辑 2024-08-14 15:45:17 +08:00
yan.y 3cd4e4b335 优惠券相关逻辑 2024-08-12 13:37:43 +08:00
25 changed files with 1897 additions and 290 deletions

View File

@ -12,12 +12,14 @@ import (
"pet-house.com/core/server/web"
"pet-house.com/core/server/web/web_iris"
"pet-house.com/core/server/zap_server"
"time"
)
type LoginRequest struct {
Code string
NickName string
HeadImgUrl string
Code string
NickName string
HeadImgUrl string
InviteUserId int64
}
type LoginResponse struct {
@ -72,19 +74,31 @@ func (p DefParty) login() web_iris.Party {
database.Instance().Model(&models.User{}).Where("open_id = ?", info.Openid).Find(&userInfo)
if userInfo.Id == 0 {
newUser := models.User{
NickName: loginRequest.NickName,
HeadImgUrl: loginRequest.HeadImgUrl,
Amount: 0,
OpenId: info.Openid,
UnionId: info.Unionid,
UserType: 0,
Mobile: "",
Role: 0,
Status: 1,
NickName: loginRequest.NickName,
HeadImgUrl: loginRequest.HeadImgUrl,
Amount: 0,
OpenId: info.Openid,
UnionId: info.Unionid,
UserType: 0,
Mobile: "",
Role: 0,
Status: 1,
InviteUserId: loginRequest.InviteUserId,
}
err := database.Instance().Create(&newUser).Error
zap_server.ZAPLOG.Info("create", zap.Any("err", err))
userInfo = newUser
for _, coupons := range CouponsMap {
if coupons.SendStatus == 2 {
//新注册用户下发优惠券
newUserCoupons := models.UserCoupons{
Uid: userInfo.Id,
Cid: coupons.Id,
LastExpireTime: time.Now().AddDate(0, 0, coupons.DrawDay),
}
database.Instance().Create(&newUserCoupons)
}
}
}
token := genToken(userInfo.Id)
response := LoginResponse{

View File

@ -2,13 +2,14 @@ package api
import (
"encoding/json"
"fmt"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
"gorm.io/gorm/clause"
"io"
"pet-house.com/business/models"
"pet-house.com/business/utils"
"pet-house.com/core/server/database"
"pet-house.com/core/server/web"
"pet-house.com/core/server/web/web_iris"
"time"
)
@ -70,7 +71,9 @@ type CarServiceProcessRequest struct {
}
type CarServiceProcessResponse struct {
OrderDetail OrderDetail `json:"orderDetail"`
OrderDetail OrderDetail `json:"orderDetail"` //订单详情
Desc string `json:"desc"` //支付描述
PayImgUrl string `json:"payImgUrl"` //支付二维码
}
// 服务处理
@ -122,22 +125,21 @@ func (p DefParty) carServiceProcess() web_iris.Party {
return
}
}
desc := ""
payImgUrl := ""
var orderUserInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", mainOrder.Uid).Find(&orderUserInfo)
var processPayAmount = carServiceProcessRequest.PayAmount
var originTotalAmount = float64(subOrderInfo.TotalAmount)
var originTotalAmount = float64(subOrderInfo.PayAmount) / 10.0
if processPayAmount > 0 && originTotalAmount != processPayAmount {
//原价
originAmount := subOrderInfo.PayAmount
userOriginAmount := orderUserInfo.Amount
p := int(utils.RoundToOneDecimalPlace(processPayAmount))
p1 := int(processPayAmount * 10)
mainOrder.TotalAmount = mainOrder.TotalAmount - subOrderInfo.TotalAmount + p
if mainOrder.PayTotalAmount > 0 && originTotalAmount != processPayAmount {
mainOrder.PayTotalAmount = mainOrder.PayTotalAmount - originAmount + p1
}
subOrderInfo.TotalAmount = p
subOrderInfo.PayAmount = p1
if mainOrder.PayStatus == 1 {
recordType := 2
@ -172,10 +174,21 @@ func (p DefParty) carServiceProcess() web_iris.Party {
}
database.Instance().Model(&models.UserAmountRecord{}).Create(&userAmountRecord)
}
} else {
userAmountRecord := models.UserAmountRecord{
UserId: orderUserInfo.Id,
Type: 3,
OriginAmount: userOriginAmount,
ProAmount: p1,
CurrAmount: orderUserInfo.Amount,
OrderId: mainOrder.OrderId,
ProScene: "修改订单金额",
Status: 1,
}
database.Instance().Model(&models.UserAmountRecord{}).Create(&userAmountRecord)
}
subOrderInfo.PayTime = time.Now()
subOrderInfo.PayStatus = 1
}
if carServiceProcessRequest.Type == 1 {
subOrderInfo.OrderStatus = 2
@ -208,6 +221,19 @@ func (p DefParty) carServiceProcess() web_iris.Party {
"LastServiceDate": pet.PetInfo.LastServiceDate,
}
database.Instance().Model(&pet.PetInfo).Updates(&updateValues)
if orderUserInfo.InviteUserId > 0 {
for _, coupons := range CouponsMap {
if coupons.SendStatus == 3 {
//完成订单给邀请用户发送优惠券
newUserCoupons := models.UserCoupons{
Uid: orderUserInfo.InviteUserId,
Cid: coupons.Id,
LastExpireTime: time.Now().AddDate(0, 0, coupons.DrawDay),
}
database.Instance().Create(&newUserCoupons)
}
}
}
} else if carServiceProcessRequest.Type == 3 {
subOrderInfo.PayRemark = carServiceProcessRequest.PayRemark
database.Instance().Save(&subOrderInfo)
@ -216,8 +242,16 @@ func (p DefParty) carServiceProcess() web_iris.Party {
FilePath: carServiceProcessRequest.FileName,
Type: carServiceProcessRequest.Type,
})
var payOrder *models.PayOrder
database.Instance().Model(&models.PayOrder{}).Where("order_id = ?", mainOrder.PayOrderId).Find(&payOrder)
//已支付成功且主订单未支付
if payOrder.Id == 0 || payOrder.OrderStatus == 0 {
payPrice := subOrderInfo.PayAmount
desc = "您还需支付" + fmt.Sprintf("%.1f", float64(payPrice)/10.0)
payImgUrl = web.CONFIG.System.Domain + "/static/img/pay.png"
}
}
Success(ctx, carServiceProcessRequest, CarServiceProcessResponse{GetOrderDetail(mainOrder.OrderId)})
Success(ctx, carServiceProcessRequest, CarServiceProcessResponse{GetOrderDetail(mainOrder.OrderId), desc, payImgUrl})
})
}}
}

View File

@ -42,6 +42,7 @@ var (
ParamError = Error{Code: 201, Msg: "参数错误"}
IllegalError = Error{Code: 202, Msg: "非法请求"}
UserError = Error{Code: 203, Msg: "用户错误"}
ServerError = Error{Code: 203, Msg: "服务器异常"}
TokenError = Error{Code: 204, Msg: "Token失效请重新登录"}
UserNotExistError = Error{Code: 205, Msg: "用户不存在"}
PetNotExistError = Error{Code: 206, Msg: "用户宠物不存在"}
@ -57,6 +58,12 @@ var (
PetInfoNotDelError = Error{Code: 215, Msg: "当前宠物存在待服务订单,无法删除"}
PetInfoNotUpdateError = Error{Code: 216, Msg: "当前宠物存在待服务订单,无法修改"}
OrderUpdateBalanceNotEnough = Error{Code: 217, Msg: "当前余额不足"}
CouponsNotExistError = Error{Code: 218, Msg: "优惠券不存在"}
UserCouponsNExistError = Error{Code: 219, Msg: "已领取同类型优惠券"}
UserCouponsNExistOrUseError = Error{Code: 220, Msg: "用户不存在优惠券或已使用"}
PayError = Error{Code: 221, Msg: "支付失败"}
OrderNotPayError = Error{Code: 222, Msg: "订单未支付定金"}
OrderNotDispachError = Error{Code: 223, Msg: "当前订单暂未派单,无法查看护理车辆位置"}
)
func Success(ctx *context.Context, request any, data any) {
@ -123,8 +130,10 @@ var ServiceAddrMap map[int64]models.ServiceAddr
var PetGoodsMap map[string][]models.PetGoods
var GoodsMap map[int64]models.Goods
var CarMap map[int]models.ServiceCar
var ReserveMap map[string]models.ReserveTimeFilter
var AddrServiceMap map[int64]models.AddrServiceTime
// var ReserveMap map[string]models.ReserveTimeFilter
// var AddrServiceMap map[int64]models.AddrServiceTime
var CouponsMap map[int]models.Coupons
func DataInit() {
//--------------------------------------------------宠物基础信息数据---------------------------------------------------------
@ -135,20 +144,19 @@ func DataInit() {
PetBaseInfoMapC1[value.Id] = value
}
PetBaseInfoMap = PetBaseInfoMapC1
zap_server.ZAPLOG.Info("dataInit petBastInfoMap : ", zap.Any("petBastInfoMap", PetBaseInfoMap))
//zap_server.ZAPLOG.Info("dataInit petBastInfoMap : ", zap.Any("petBastInfoMap", PetBaseInfoMap))
//--------------------------------------------------服务地址数据---------------------------------------------------------
var serviceAddrList []models.ServiceAddr
database.Instance().Model(&models.ServiceAddr{}).Find(&serviceAddrList)
database.Instance().Model(&models.ServiceAddr{}).Where("status = 1").Find(&serviceAddrList)
var ServiceAddrMapC1 = make(map[int64]models.ServiceAddr)
for _, value := range serviceAddrList {
ServiceAddrMapC1[value.Id] = value
}
ServiceAddrMap := ServiceAddrMapC1
zap_server.ZAPLOG.Info("dataInit ServiceAddrMap : ", zap.Any("ServiceAddrMap", ServiceAddrMap))
ServiceAddrMap = ServiceAddrMapC1
//zap_server.ZAPLOG.Info("dataInit ServiceAddrMap : ", zap.Any("ServiceAddrMap", ServiceAddrMap))
//--------------------------------------------------宠物商品关联数据---------------------------------------------------------
var petGoodsList []models.PetGoods
database.Instance().Model(&models.PetGoods{}).Where("status = 1").Find(&petGoodsList)
zap_server.ZAPLOG.Info("111111", zap.Any("222", petGoodsList))
var PetGoodsMapC1 = make(map[string][]models.PetGoods)
for _, value := range petGoodsList {
key := strconv.Itoa(value.Assortment) + strconv.Itoa(value.PetType) + strconv.Itoa(value.Weight) + strconv.Itoa(value.Hair)
@ -159,7 +167,7 @@ func DataInit() {
}
}
PetGoodsMap = PetGoodsMapC1
zap_server.ZAPLOG.Info("dataInit petGoodsMap : ", zap.Any("petGoodsMap", PetGoodsMap))
//zap_server.ZAPLOG.Info("dataInit petGoodsMap : ", zap.Any("petGoodsMap", PetGoodsMap))
//--------------------------------------------------商品数据---------------------------------------------------------
var goodsList []models.Goods
database.Instance().Model(&models.Goods{}).Where("status = 1").Find(&goodsList)
@ -168,31 +176,39 @@ func DataInit() {
GoodsMapC1[value.Id] = value
}
GoodsMap = GoodsMapC1
zap_server.ZAPLOG.Info("dataInit GoodsMap : ", zap.Any("GoodsMap", GoodsMap))
//zap_server.ZAPLOG.Info("dataInit GoodsMap : ", zap.Any("GoodsMap", GoodsMap))
var carList []models.ServiceCar
database.Instance().Model(&models.ServiceCar{}).Find(&carList)
database.Instance().Model(&models.ServiceCar{}).Where("car_status = 1").Find(&carList)
var CarMapC1 = make(map[int]models.ServiceCar)
for _, value := range carList {
CarMapC1[value.Id] = value
}
CarMap = CarMapC1
zap_server.ZAPLOG.Info("dataInit CarMap : ", zap.Any("CarMap", CarMap))
var timesList []models.ReserveTimeFilter
database.Instance().Model(&models.ReserveTimeFilter{}).Find(&timesList)
var ReserveMapC1 = make(map[string]models.ReserveTimeFilter)
for _, value := range timesList {
ReserveMapC1[value.Content] = value
//zap_server.ZAPLOG.Info("dataInit CarMap : ", zap.Any("CarMap", CarMap))
//var timesList []models.ReserveTimeFilter
//database.Instance().Model(&models.ReserveTimeFilter{}).Find(&timesList)
//var ReserveMapC1 = make(map[string]models.ReserveTimeFilter)
//for _, value := range timesList {
// ReserveMapC1[value.Content] = value
//}
//ReserveMap = ReserveMapC1
//zap_server.ZAPLOG.Info("dataInit ReserveMap : ", zap.Any("ReserveMap", ReserveMap))
//var serviceTimesList []models.AddrServiceTime
//database.Instance().Model(&models.AddrServiceTime{}).Find(&serviceTimesList)
//var AddrServiceMapC1 = make(map[int64]models.AddrServiceTime)
//for _, value := range serviceTimesList {
// AddrServiceMapC1[value.ServiceAddrId] = value
//}
//AddrServiceMap = AddrServiceMapC1
//zap_server.ZAPLOG.Info("dataInit AddrServiceMap : ", zap.Any("AddrServiceMap", AddrServiceMap))
var couponsList []models.Coupons
database.Instance().Model(&models.Coupons{}).Where("status = 1 and expire_time > ?", time.Now().UnixNano()/int64(time.Millisecond)).Find(&couponsList)
var CouponsMapC1 = make(map[int]models.Coupons)
for _, value := range couponsList {
CouponsMapC1[value.Id] = value
}
ReserveMap = ReserveMapC1
zap_server.ZAPLOG.Info("dataInit ReserveMap : ", zap.Any("ReserveMap", ReserveMap))
var serviceTimesList []models.AddrServiceTime
database.Instance().Model(&models.AddrServiceTime{}).Find(&serviceTimesList)
var AddrServiceMapC1 = make(map[int64]models.AddrServiceTime)
for _, value := range serviceTimesList {
AddrServiceMapC1[value.ServiceAddrId] = value
}
AddrServiceMap = AddrServiceMapC1
zap_server.ZAPLOG.Info("dataInit AddrServiceMap : ", zap.Any("AddrServiceMap", AddrServiceMap))
CouponsMap = CouponsMapC1
//zap_server.ZAPLOG.Info("dataInit CouponsMap : ", zap.Any("Coupons", CouponsMap))
}
func DataCacheJob() {

View File

@ -10,6 +10,8 @@ var PetBase = "/pet"
var CarBase = "/car"
var Admin = "/admin"
var System = "/system"
var CouponsBase = "/coupons"
var PayBase = "/pay"
func (p DefParty) RegisterList() []web_iris.Party {
ps := []web_iris.Party{
@ -29,9 +31,10 @@ func (p DefParty) RegisterList() []web_iris.Party {
p.orderEdit(),
p.orderDetail(),
p.orderGoodsUpdate(),
p.orderPay(),
p.orderCancel(),
p.orderCreatePreCheck(),
p.orderMarkRecord(),
p.orderMarkRecordInfo(),
//宠物
p.petList(),
p.petInfo(),
@ -42,13 +45,24 @@ func (p DefParty) RegisterList() []web_iris.Party {
p.serviceAddrList(),
p.serviceAddOrEdit(),
p.serviceAreaAddrList(),
p.serviceCarLocationUpload(),
p.serviceCarLocationList(),
//车辆
p.carServiceOrderList(),
p.carServiceProcess(),
p.index(),
//优惠券
p.getCouponsList(),
p.getUserCouponsList(),
p.drawCoupons(),
//支付
p.rechargeInfoList(),
p.toPay(),
p.payNotify(),
//系统
p.systemConfigInfo(),
p.systemBanners(),
p.getPayoff(),
}
return ps
}

144
business/api/coupons.go Normal file
View File

@ -0,0 +1,144 @@
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/business/utils"
"pet-house.com/core/server/database"
"pet-house.com/core/server/web/web_iris"
"strings"
"time"
)
func (p DefParty) getCouponsList() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(CouponsBase+"/getCouponsList", func(ctx *context.Context) {
headerInfo := GetHeaderBaseInfo(ctx)
var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", headerInfo.Uid).Find(&userInfo)
if userInfo == nil || userInfo.Id == 0 {
UserNotExistError.Fail(ctx, nil)
return
}
var userCoupons []*models.UserCoupons
database.Instance().Model(&models.UserCoupons{}).Where("uid = ? and coupons_status = 1", headerInfo.Uid).Find(&userCoupons)
var userCouponsMap = make(map[int]*models.UserCoupons)
for _, value := range userCoupons {
userCouponsMap[value.Cid] = value
}
var coupons []models.Coupons
database.Instance().Model(&models.Coupons{}).Where("status = 1 and send_status = 1 and expire_time > ?", time.Now().UnixNano()/int64(time.Millisecond)).Find(&coupons)
for index, coupon := range coupons {
m := userCouponsMap[coupon.Id]
if m != nil && m.Id > 0 {
coupons[index].ReceiverStatus = 1
}
coupons[index].PeriodInfo = strings.Split(coupon.Period, ",")
}
Success(ctx, headerInfo, coupons)
})
}}
}
type GetUserCouponsListRequest struct {
Status int
}
func (p DefParty) getUserCouponsList() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(CouponsBase+"/getUserCouponsList", func(ctx *context.Context) {
headerInfo := GetHeaderBaseInfo(ctx)
var getUserCouponsListRequest GetUserCouponsListRequest
body, _ := io.ReadAll(ctx.Request().Body)
json.Unmarshal(body, &getUserCouponsListRequest)
if getUserCouponsListRequest.Status == 0 {
ParamError.Fail(ctx, nil)
return
}
var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", headerInfo.Uid).Find(&userInfo)
if userInfo == nil || userInfo.Id == 0 {
UserNotExistError.Fail(ctx, nil)
return
}
var userCoupons []models.UserCoupons
var coupons []models.Coupons
database.Instance().Model(&models.UserCoupons{}).Where("uid = ? and coupons_status = ?", headerInfo.Uid, getUserCouponsListRequest.Status).Find(&userCoupons)
for _, userCoupon := range userCoupons {
uc := CouponsMap[userCoupon.Cid]
if uc.Id == 0 {
var couponsData *models.Coupons
database.Instance().Model(&models.Coupons{}).Where("id = ?", userCoupon.Cid).Find(&couponsData)
uc = models.Coupons{Id: couponsData.Id, Name: couponsData.Name, Source: couponsData.Source, Discount: couponsData.Discount, GoodsSubType: couponsData.GoodsSubType}
}
uc.LastExpireTime = userCoupon.LastExpireTime.Format("2006-01-02")
uc.PeriodInfo = strings.Split(uc.Period, ",")
uc.Id = userCoupon.Id
coupons = append(coupons, uc)
}
Success(ctx, headerInfo, coupons)
})
}}
}
type DrawCouponsRequest struct {
Cid int
}
func (p DefParty) drawCoupons() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(CouponsBase+"/drawCoupons", func(ctx *context.Context) {
headerInfo := GetHeaderBaseInfo(ctx)
var drawCouponsRequest DrawCouponsRequest
body, _ := io.ReadAll(ctx.Request().Body)
json.Unmarshal(body, &drawCouponsRequest)
if drawCouponsRequest.Cid == 0 {
ParamError.Fail(ctx, nil)
return
}
var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", headerInfo.Uid).Find(&userInfo)
if userInfo == nil || userInfo.Id == 0 {
UserNotExistError.Fail(ctx, nil)
return
}
var coupons *models.Coupons
database.Instance().Model(&models.Coupons{}).Where("id = ? and status = 1", drawCouponsRequest.Cid).Find(&coupons)
if coupons.Id == 0 {
CouponsNotExistError.Fail(ctx, nil)
return
}
lockMap := &utils.KeyedMutex{}
lockMap.Lock(headerInfo.Token)
var userCoupons *models.UserCoupons
database.Instance().Model(&models.UserCoupons{}).Where("uid = ? and cid = ? and coupons_status = 1", headerInfo.Uid, drawCouponsRequest.Cid).Find(&userCoupons)
if userCoupons.Id > 0 {
UserCouponsNExistError.Fail(ctx, nil)
lockMap.Unlock(headerInfo.Token)
return
}
newUserCoupons := models.UserCoupons{
Uid: headerInfo.Uid,
Cid: drawCouponsRequest.Cid,
//领取后最后过期时间
LastExpireTime: time.Now().AddDate(0, 0, coupons.DrawDay),
}
err := database.Instance().Create(&newUserCoupons).Error
if err != nil {
ServerError.Fail(ctx, nil)
lockMap.Unlock(headerInfo.Token)
return
}
lockMap.Unlock(headerInfo.Token)
Success(ctx, headerInfo, nil)
})
}}
}

View File

@ -18,15 +18,16 @@ type GoodsListRequest struct {
}
type GoodsDetail struct {
Id int64 `json:"id"` //商品ID
Name string `json:"name"` //商品名称
GoodsType int `json:"goodsType"` //商品类型 1基础服务 2附加产品 3附加服务
Time string `json:"time"` //时间
Price int `json:"price"` //价格
ParentId int64 `json:"parentId"` //商品父ID
BuyMany int `json:"buyMany"` //同类型是否可购买多个 0否 1是
GoodsDetail string `json:"goodsDetail"` //商品详情 图片URL
GoodsIcon string `json:"goodsIcon"` //iconUrl
Id int64 `json:"id"` //商品ID
Name string `json:"name"` //商品名称
GoodsType int `json:"goodsType"` //商品类型 1基础服务 2附加产品 3附加服务
Time string `json:"time"` //时间
Price int `json:"price"` //价格
ParentId int64 `json:"parentId"` //商品父ID
BuyMany int `json:"buyMany"` //同类型是否可购买多个 0否 1是
GoodsDetail string `json:"goodsDetail"` //商品详情 图片URL
GoodsIcon string `json:"goodsIcon"` //iconUrl
GoodsSubType int `json:"goodsSubType"` //商品子类型
GoodsSubList []GoodsDetail `json:"goodsSubList,omitempty"`
}
@ -54,15 +55,15 @@ func (p DefParty) goodsList() web_iris.Party {
}
//先取默认的商品
key := "0" + strconv.Itoa(userPetInfo.PetBaseInfo.PetType) + "0" + "0"
goodsList := getPetGoodsList(key)
goodsList := GetPetGoodsList(key)
key1 := strconv.Itoa(userPetInfo.PetBaseInfo.Id) + strconv.Itoa(userPetInfo.PetBaseInfo.PetType) + strconv.Itoa(userPetInfo.PetInfo.Weight) + "0"
goodsList = append(goodsList, getPetGoodsList(key1)...)
goodsList = append(goodsList, GetPetGoodsList(key1)...)
key2 := strconv.Itoa(userPetInfo.PetBaseInfo.Id) + strconv.Itoa(userPetInfo.PetBaseInfo.PetType) + strconv.Itoa(userPetInfo.PetInfo.Weight) + strconv.Itoa(userPetInfo.PetBaseInfo.Hair)
goodsList = append(goodsList, getPetGoodsList(key2)...)
goodsList = append(goodsList, GetPetGoodsList(key2)...)
key3 := "0" + strconv.Itoa(userPetInfo.PetBaseInfo.PetType) + strconv.Itoa(userPetInfo.PetInfo.Weight) + strconv.Itoa(userPetInfo.PetBaseInfo.Hair)
goodsList = append(goodsList, getPetGoodsList(key3)...)
goodsList = append(goodsList, GetPetGoodsList(key3)...)
key4 := "0" + strconv.Itoa(userPetInfo.PetBaseInfo.PetType) + strconv.Itoa(userPetInfo.PetInfo.Weight) + "0"
goodsList = append(goodsList, getPetGoodsList(key4)...)
goodsList = append(goodsList, GetPetGoodsList(key4)...)
var goodsT1 []GoodsDetail
var goodsT2 []GoodsDetail
var goodsT3 []GoodsDetail
@ -109,11 +110,14 @@ func (p DefParty) goodsList() web_iris.Party {
}}
}
func getPetGoodsList(key string) []GoodsDetail {
func GetPetGoodsList(key string) []GoodsDetail {
var goodsList []GoodsDetail
baseGoodsList := PetGoodsMap[key]
for _, value := range baseGoodsList {
goods := GoodsMap[value.GoodsId]
if goods.Id == 0 {
continue
}
goodsDetail := GoodsDetail{
Id: goods.Id,
Name: goods.Name,
@ -123,19 +127,21 @@ func getPetGoodsList(key string) []GoodsDetail {
BuyMany: goods.BuyMany,
GoodsDetail: goods.GoodsDetail,
GoodsIcon: goods.GoodsIcon,
GoodsSubType: goods.GoodsSubType,
GoodsSubList: nil,
}
for _, goodsSub := range GoodsMap {
if goodsSub.ParentId == goodsDetail.Id {
goodsDetail.GoodsSubList = append(goodsDetail.GoodsSubList, GoodsDetail{
Id: goodsSub.Id,
Name: goodsSub.Name,
GoodsType: goodsSub.GoodsType,
Time: goodsSub.Time,
Price: goodsSub.Price,
BuyMany: goodsSub.BuyMany,
GoodsDetail: goodsSub.GoodsDetail,
GoodsIcon: goodsSub.GoodsIcon,
Id: goodsSub.Id,
Name: goodsSub.Name,
GoodsType: goodsSub.GoodsType,
Time: goodsSub.Time,
Price: goodsSub.Price,
BuyMany: goodsSub.BuyMany,
GoodsDetail: goodsSub.GoodsDetail,
GoodsIcon: goodsSub.GoodsIcon,
GoodsSubType: goodsSub.GoodsSubType,
})
}
}

View File

@ -18,6 +18,7 @@ var ExcludeBase = "/static"
var ExcludeBase1 = "/debug"
var ExcludeBase2 = "/admin"
var ExcludeBase3 = "/system"
var ExcludeBase4 = "/payNotify"
var frontExcludes = [...]string{
Root + AuthBase + "/login",
@ -25,7 +26,7 @@ var frontExcludes = [...]string{
func ModuleInit() {
utils.WechatInit()
_ = database.Instance().AutoMigrate(
_err := database.Instance().AutoMigrate(
//&models.User{},
//&models.Pet{},
//&models.PetBaseInfo{},
@ -45,8 +46,15 @@ func ModuleInit() {
//&models.ReserveTimeFilter{},
//&models.OrderServiceRecord{},
//&models.AddrServiceTime{},
&models.UserAmountRecord{},
//&models.UserAmountRecord{},
//&models.Coupons{},
//&models.UserCoupons{},
//&models.RechargeInfo{},
//&models.PayOrder{},
&models.ServiceUserMarkRecord{},
//&models.ServiceCarLocation{},
)
zap_server.ZAPLOG.Info("data init ", zap.Any("err", _err))
DataInit()
DataCacheJob()
}
@ -68,6 +76,10 @@ func FrontAuth(ctx *context.Context) {
ctx.Next()
return
}
if strings.Contains(ctx.Path(), ExcludeBase4) {
ctx.Next()
return
}
frontExcludesStr := strings.Join(frontExcludes[:], ",")
if strings.Contains(frontExcludesStr, ctx.Path()) {
ctx.Next()

View File

@ -2,6 +2,7 @@ package api
import (
"encoding/json"
"fmt"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
"go.uber.org/zap"
@ -14,20 +15,21 @@ import (
"pet-house.com/core/server/web/web_iris"
"pet-house.com/core/server/zap_server"
"strconv"
"strings"
"sync"
"time"
)
type PetGoodsInfo struct {
PetId int64
GoodsIds []int64
Cid int //优惠券ID
PetId int64 //宠物ID
GoodsIds []int64 //商品列表
}
type OrderCreateRequest struct {
PetGoodsInfos []PetGoodsInfo //宠物商品信息列表
ServiceTime string //预约时间 yyyy-MM-dd HH:mm
ServiceAddrId int64 //预约服务地址
PayOrderId string //支付单号
}
type OrderCreateResponse struct {
@ -37,6 +39,7 @@ type OrderCreateResponse struct {
type OrderCreatePreCheckResponse struct {
HasAlert bool `json:"hasAlert"` //是否弹窗提示 返回false直接下单返回ture弹出确认框确认框点击是之后调用下单接口
AlertMsg string `json:"alertMsg"` //弹窗消息
PayType int `json:"payType"` //扣款类型
}
func (p DefParty) orderCreatePreCheck() web_iris.Party {
@ -52,25 +55,60 @@ func (p DefParty) orderCreatePreCheck() web_iris.Party {
}
var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo)
var orderTotalAmount = 0
var goodsDiscountAmount = 0
var goodsNotDiscountAmount = 0
var projectionServiceTime = 0
for _, value := range orderCreateRequest.PetGoodsInfos {
for _, value := range value.GoodsIds {
goods := GoodsMap[value]
orderTotalAmount = orderTotalAmount + int(goods.Price)
for _, gid := range value.GoodsIds {
goods := GoodsMap[gid]
if goods.Time != "/" && len(goods.Time) > 0 {
goodsTime, _ := strconv.Atoi(goods.Time)
projectionServiceTime += goodsTime
}
if value.Cid > 0 {
var userCouponsInfo models.UserCoupons
database.Instance().Model(&models.UserCoupons{}).Where("id = ?", value.Cid).Order(clause.OrderByColumn{Column: clause.Column{Name: "update_time"}, Desc: true}).Find(&userCouponsInfo)
var coupons = CouponsMap[userCouponsInfo.Cid]
if coupons.Id == 0 {
var couponsData *models.Coupons
database.Instance().Model(&models.Coupons{}).Where("id = ?", coupons.Id).Find(&couponsData)
coupons = models.Coupons{Id: couponsData.Id, Discount: couponsData.Discount, GoodsSubType: couponsData.GoodsSubType}
}
if goods.GoodsSubType == coupons.GoodsSubType {
goodsDiscountAmount = goodsDiscountAmount + int(utils.RoundToOneDecimalPlace(float64(goods.Price)*(float64(coupons.Discount)/100.0))*10)
} else {
goodsNotDiscountAmount = goodsNotDiscountAmount + goods.Price
}
}
}
}
haveReserve := checkOrderServiceTime(orderCreateRequest.ServiceTime, projectionServiceTime)
if haveReserve {
OrderCreateError.DefFail(ctx, orderCreateRequest, "当前订单预估服务时长预计:"+strconv.Itoa(projectionServiceTime)+"分钟,服务时间过长,请更换时间段预约或联系客服协助预约")
return
}
orderCreatePreCheckResponse := OrderCreatePreCheckResponse{
HasAlert: false,
PayType: 0,
}
var discountAmount = orderTotalAmount
if userInfo.Discount > 0 {
discount := float64(userInfo.Discount)
discountAmount = int(utils.RoundToOneDecimalPlace(float64(orderTotalAmount)*(discount/100.0)) * 10)
//此处计算享受会员折扣及优惠券折扣的价格
var discountAmount = int(utils.RoundToOneDecimalPlace(float64(goodsNotDiscountAmount)*(discount/100.0))*10) + goodsDiscountAmount
if userInfo.Amount < discountAmount {
orderCreatePreCheckResponse.HasAlert = true
orderCreatePreCheckResponse.AlertMsg = "您的会员余额不够,需要进行线下支付,当前订单将不享受会员折扣优惠价格"
//orderCreatePreCheckResponse.HasAlert = false
//orderCreatePreCheckResponse.AlertMsg = "您的会员余额不够,需要进行线下支付,当前订单将不享受会员折扣优惠价格"
//orderCreatePreCheckResponse.PayType = 0
} else {
orderCreatePreCheckResponse.PayType = 1
}
}
var systemConfigPay models.SystemConfig
database.Instance().Model(&models.SystemConfig{}).Where("config_type = 4").Order(clause.OrderByColumn{Column: clause.Column{Name: "sort"}, Desc: true}).Limit(1).Find(&systemConfigPay)
if systemConfigPay.Name == "payOff" {
orderCreatePreCheckResponse.PayType = 1
}
Success(ctx, orderCreateRequest, orderCreatePreCheckResponse)
})
@ -93,8 +131,13 @@ func (p DefParty) orderCreate() web_iris.Party {
UserServiceAddrNotExistError.Fail(ctx, nil)
return
}
var userCouponsList []*models.UserCoupons
var projectionServiceTime = 0
var userCoupons *models.UserCoupons
for _, value := range orderCreateRequest.PetGoodsInfos {
database.Instance().Model(&models.UserCoupons{}).Where("id = ? and coupons_status = 1", value.Cid).Find(&userCoupons)
userCouponsList = append(userCouponsList, userCoupons)
userPet := GetUserPet(headerBaseInfo.Uid, value.PetId)
var dog = userPet.PetBaseInfo.PetType == 2
var goodsType1 = false
@ -130,7 +173,16 @@ func (p DefParty) orderCreate() web_iris.Party {
}
}
/*var payOrder *models.PayOrder
database.Instance().Model(&models.PayOrder{}).Where("order_id = ? and order_status = 0", orderCreateRequest.PayOrderId).Find(&payOrder)
if payOrder.Id > 0 {
OrderNotPayError.DefFail(ctx, orderCreateRequest, nil)
return
}*/
//订单总金额
var orderTotalAmount = 0
orderLock.Lock()
orderId := NextId.Generate().String()
orderMain := models.OrderMain{
@ -147,7 +199,32 @@ func (p DefParty) orderCreate() web_iris.Party {
var orderSubList []models.OrderSub
var orderSubDetailList []models.OrderDetail
var mainGoods = 0
var coupons models.Coupons
for _, value := range orderCreateRequest.PetGoodsInfos {
//2025-02-06 00:00:00
givenTimestamp := int64(1738771200000)
// 获取当前的系统时间戳(毫秒级)
currentTimestamp := time.Now().UnixMilli()
//时间小于2025-02-06 00:00:00 不使用优惠券
if currentTimestamp < givenTimestamp {
value.Cid = 0
}
//可以参与会员折扣的金额
var needDiscountAmount = 0
//不可参与会员折扣的金额
var notDiscountAmount = 0
var userCouponsInfo models.UserCoupons
database.Instance().Model(&models.UserCoupons{}).Where("id = ?", value.Cid).Order(clause.OrderByColumn{Column: clause.Column{Name: "update_time"}, Desc: true}).Find(&userCouponsInfo)
coupons = CouponsMap[userCouponsInfo.Cid]
if coupons.Id == 0 {
var couponsData *models.Coupons
database.Instance().Model(&models.Coupons{}).Where("id = ?", userCouponsInfo.Cid).Find(&couponsData)
coupons = models.Coupons{Id: couponsData.Id, Discount: couponsData.Discount, GoodsSubType: couponsData.GoodsSubType}
}
subOrderId := NextId.Generate().String()
var totalAmount = 0
var projectionServiceTime = 0
@ -155,7 +232,15 @@ func (p DefParty) orderCreate() web_iris.Party {
for _, value := range value.GoodsIds {
goods := GoodsMap[value]
totalAmount = totalAmount + goods.Price
orderSubDetailList = append(orderSubDetailList, models.OrderDetail{SubOrderId: subOrderId, GoodsId: value, Amount: goods.Price})
orderDetail := models.OrderDetail{SubOrderId: subOrderId, GoodsId: value, Amount: goods.Price}
//设置订单详情折扣
if coupons.Id > 0 && coupons.GoodsSubType == goods.GoodsSubType {
orderDetail.Cid = coupons.Id
orderDetail.Discount = coupons.Discount
orderDetail.DiscountAmount = int(utils.RoundToOneDecimalPlace(float64(orderDetail.Amount)*(float64(coupons.Discount)/100.0)) * 10)
}
orderSubDetailList = append(orderSubDetailList, orderDetail)
if goods.Time != "/" && len(goods.Time) > 0 {
goodsTime, _ := strconv.Atoi(goods.Time)
projectionServiceTime += goodsTime
@ -164,10 +249,29 @@ func (p DefParty) orderCreate() web_iris.Party {
mainGoods++
}
goodsName = goods.Name + "、" + goodsName
//符合折扣金额才计入折扣价
if orderDetail.Cid > 0 && coupons.GoodsSubType == goods.GoodsSubType {
notDiscountAmount = notDiscountAmount + orderDetail.DiscountAmount
} else {
needDiscountAmount = needDiscountAmount + orderDetail.Amount
}
}
userPetInfo := GetUserPet(headerBaseInfo.Uid, value.PetId)
var petInfo = "宠物名称:" + userPetInfo.PetInfo.NickName + "</br>品种:" + userPetInfo.PetBaseInfo.Assortment + "</br>服务项目:" + goodsName
var weightStr = "无"
if userPetInfo.PetBaseInfo.PetType == 1 {
weightStr = CatWeightMap[userPetInfo.PetInfo.Weight]
} else {
weightStr = DogWeightMap[userPetInfo.PetInfo.Weight]
}
var petInfo = "宠物名称:" + userPetInfo.PetInfo.NickName + "</br>品种:" + userPetInfo.PetBaseInfo.Assortment + "</br>体重:" + weightStr + "</br>服务项目:" + goodsName
projectionServiceTimeAll += projectionServiceTime
/*for _, orderDetail := range orderSubDetailList {
goods := GoodsMap[orderDetail.GoodsId]
}*/
orderSub := models.OrderSub{
OrderId: subOrderId,
MainOrderId: orderMain.OrderId,
@ -176,12 +280,20 @@ func (p DefParty) orderCreate() web_iris.Party {
PayType: 1,
Discount: 100,
TotalAmount: totalAmount,
PayAmount: totalAmount,
PetInfo: petInfo,
Status: 1,
//PayTime: time.Now(),
//折扣价格 默认*10
PayAmount: notDiscountAmount + needDiscountAmount*10,
//设置商品折扣金额用于后续打折计算
GoodsDiscountAmount: notDiscountAmount,
//设置商品非折扣金额
GoodsOriginAmount: needDiscountAmount,
//宠物信息
PetInfo: petInfo,
Status: 1,
ProjectionServiceTime: projectionServiceTime,
Cid: coupons.Id,
Ucid: userCoupons.Id,
}
//订单总金额
orderTotalAmount = orderTotalAmount + totalAmount
orderSubList = append(orderSubList, orderSub)
}
@ -190,25 +302,36 @@ func (p DefParty) orderCreate() web_iris.Party {
orderLock.Unlock()
return
}
orderMain.ProjectionServiceTime = projectionServiceTimeAll
var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo)
var discountAmount = orderTotalAmount
//计算参与折扣计算的金额
var discountAmount = 0
var orderGoodsDiscountAmount = 0
//参与计算折扣的金额
var inDiscountAmount = 0
for _, orderSub := range orderSubList {
inDiscountAmount = inDiscountAmount + orderSub.GoodsOriginAmount
orderGoodsDiscountAmount = orderGoodsDiscountAmount + orderSub.GoodsDiscountAmount
}
//用户折扣排除使用优惠券的商品总金额
if userInfo.Discount > 0 {
discount := float64(userInfo.Discount)
discountAmount = int(utils.RoundToOneDecimalPlace(float64(orderTotalAmount)*(discount/100.0)) * 10)
discountAmount = int(utils.RoundToOneDecimalPlace(float64(inDiscountAmount)*(discount/100.0)) * 10)
} else {
discountAmount = int(utils.RoundToOneDecimalPlace(float64(orderTotalAmount) * 10))
discountAmount = int(utils.RoundToOneDecimalPlace(float64(inDiscountAmount) * 10))
}
orderMain.TotalAmount = orderTotalAmount
tx := database.Instance().Begin()
var db4 *gorm.DB
if userInfo.Amount >= discountAmount {
//用户需要扣除总金额
if userInfo.Amount >= discountAmount+orderGoodsDiscountAmount {
var currAmount = userInfo.Amount
orderMain.PayStatus = 1
orderMain.PayTotalAmount = discountAmount
userInfo.Amount = userInfo.Amount - discountAmount
orderMain.PayTotalAmount = discountAmount + orderGoodsDiscountAmount
userInfo.Amount = userInfo.Amount - discountAmount - orderGoodsDiscountAmount
updateValues := map[string]interface{}{
"Amount": userInfo.Amount,
}
@ -222,21 +345,51 @@ func (p DefParty) orderCreate() web_iris.Party {
UserId: userInfo.Id,
Type: 2,
OriginAmount: currAmount,
ProAmount: discountAmount,
ProAmount: discountAmount + orderGoodsDiscountAmount,
CurrAmount: userInfo.Amount,
OrderId: orderId,
ProScene: "下单",
Status: 1,
}
price := 0.0
for index_, orderSub := range orderSubList {
if userInfo.Discount > 0 {
discount := float64(userInfo.Discount)
discountAmount1 := int(utils.RoundToOneDecimalPlace(float64(orderSub.GoodsOriginAmount)*(discount/100.0)) * 10)
orderSubList[index_].PayAmount = discountAmount1 + orderSub.GoodsDiscountAmount
}
price = price + float64(orderSub.PayAmount)
}
tx.Model(&models.UserAmountRecord{}).Create(&userAmountRecord)
zap_server.ZAPLOG.Info("会员金额扣除", zap.Any("用户ID", userInfo.Id), zap.Any("订单号", orderMain.OrderId), zap.Any("当前余额", currAmount), zap.Any("扣除余额", discountAmount+orderGoodsDiscountAmount), zap.Any("剩余余额", userInfo.Amount), zap.Any("折扣", userInfo.Discount), zap.Any("优惠券折扣信息", coupons))
for index_, _ := range orderSubList {
orderSubList[index_].Discount = userInfo.Discount
}
payOrder := models.PayOrder{
OrderId: orderId,
OrderName: "宠物洗护付款(会员余额)-" + orderMain.OrderId,
OrderPrice: fmt.Sprintf("%.1f", price),
RechargeId: 0,
PayId: "",
Uid: headerBaseInfo.Uid,
OrderStatus: 3,
}
database.Instance().Model(&models.PayOrder{}).Create(&payOrder)
} else {
userAmountRecord := models.UserAmountRecord{
UserId: userInfo.Id,
Type: 3,
OriginAmount: userInfo.Amount,
ProAmount: inDiscountAmount*10 + orderGoodsDiscountAmount,
CurrAmount: userInfo.Amount,
OrderId: orderId,
ProScene: "下单",
Status: 1,
}
tx.Model(&models.UserAmountRecord{}).Create(&userAmountRecord)
zap_server.ZAPLOG.Info("会员金额扣除", zap.Any("用户ID", userInfo.Id), zap.Any("订单号", orderMain.OrderId), zap.Any("当前余额", currAmount), zap.Any("扣除余额", discountAmount), zap.Any("剩余余额", userInfo.Amount), zap.Any("折扣", userInfo.Discount))
discount := float64(userInfo.Discount)
for index, _ := range orderSubList {
orderSubList[index].Discount = userInfo.Discount
//orderSubList[index].PayAmount = int32(math.Round(float64(orderSubList[index].TotalAmount) * (discount / 100.0)))
orderSubList[index].PayAmount = int(utils.RoundToOneDecimalPlace(float64(orderSubList[index].TotalAmount)*(discount/100.0)) * 10)
}
}
orderMain.PayOrderId = orderCreateRequest.PayOrderId
var findUserServiceAddr models.UserServiceAddr
database.Instance().Model(&models.UserServiceAddr{}).Where("id = ? and uid = ?", orderCreateRequest.ServiceAddrId, headerBaseInfo.Uid).Find(&findUserServiceAddr)
userInfo.Mobile = findUserServiceAddr.Mobile
@ -247,6 +400,13 @@ func (p DefParty) orderCreate() web_iris.Party {
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)
for _, userCoupons := range userCouponsList {
updateUserCoupons := map[string]interface{}{
"CouponsStatus": 2,
}
//更新用户优惠券状态
tx.Model(&userCoupons).Updates(&updateUserCoupons)
}
if (db4 != nil && db4.Error != nil) || db.Error != nil || db1.Error != nil || db2.Error != nil {
tx.Callback()
orderLock.Unlock()
@ -283,10 +443,13 @@ func GetOrderDetail(orderId string) OrderDetail {
Discount: float64(orderMain.PayDiscount) / 100,
Uid: orderMain.Uid,
UserAmount: float64(userInfo.Amount) / 10.0,
MarkStatus: orderMain.MarkStatus,
}
if orderMain.PayDiscount > 0 {
if orderMain.PayStatus == 1 {
orderDetail.DiscountAmount = strconv.FormatFloat(float64(orderMain.PayTotalAmount)/10.0, 'f', 1, 64)
}
var discountTotalAmount = 0
var subOrderList []SubOrder
var orderSubList []models.OrderSub
database.Instance().Model(&models.OrderSub{}).Where("main_order_id = ? ", orderMain.OrderId).Find(&orderSubList)
@ -294,32 +457,95 @@ func GetOrderDetail(orderId string) OrderDetail {
var orderDetailList []models.OrderDetail
database.Instance().Model(&models.OrderDetail{}).Where("sub_order_id = ? ", orderSub.OrderId).Find(&orderDetailList)
var goods []models.Goods
var couponsGoods models.Goods
var coupons models.Coupons
for _, orderDetail := range orderDetailList {
good := GoodsMap[orderDetail.GoodsId]
goods = append(goods, good)
coupons = CouponsMap[orderSub.Cid]
if coupons.Id == 0 {
var couponsS *models.Coupons
database.Instance().Model(&models.Coupons{}).Where("id = ?", orderSub.Cid).Find(&couponsS)
coupons = models.Coupons{
Id: couponsS.Id,
Name: couponsS.Name,
GoodsSubType: couponsS.GoodsSubType,
Discount: couponsS.Discount,
Source: couponsS.Source,
PeriodType: couponsS.PeriodType,
Period: couponsS.Period,
PeriodInfo: couponsS.PeriodInfo,
ExpireTime: couponsS.ExpireTime,
CreateTime: couponsS.CreateTime,
UpdateTime: couponsS.UpdateTime,
Status: couponsS.Status,
SendStatus: couponsS.SendStatus,
ReceiverStatus: couponsS.ReceiverStatus,
}
}
if orderSub.Cid > 0 {
if coupons.GoodsSubType == good.GoodsSubType {
couponsGoods = good
}
}
}
orderSubR1 := SubOrder{
OrderId: orderSub.OrderId,
Status: orderSub.OrderStatus,
UserPetInfo: GetUserPet(orderMain.Uid, orderSub.PetId),
TotalAmount: orderSub.TotalAmount,
PayAmount: strconv.Itoa(orderSub.PayAmount),
Discount: float64(orderSub.Discount),
Goods: goods,
OrderId: orderSub.OrderId,
Status: orderSub.OrderStatus,
UserPetInfo: GetUserPet(orderMain.Uid, orderSub.PetId),
TotalAmount: orderSub.TotalAmount,
PayAmount: strconv.Itoa(orderSub.PayAmount),
Discount: float64(orderSub.Discount),
Goods: goods,
Coupons: nil,
CouponsAmount: "0",
}
if orderSub.OrderStatus == 1 {
if coupons.Id > 0 {
orderSubR1.Coupons = &models.Coupons{
Id: coupons.Id,
Name: coupons.Name,
GoodsSubType: coupons.GoodsSubType,
Discount: coupons.Discount,
Source: coupons.Source,
PeriodType: coupons.PeriodType,
Period: coupons.Period,
PeriodInfo: coupons.PeriodInfo,
SendStatus: coupons.SendStatus,
}
orderSubR1.CouponsAmount = strconv.FormatFloat(float64(couponsGoods.Price*10-orderSub.GoodsDiscountAmount)/10, 'f', 1, 64)
} else {
orderSubR1.Coupons = nil
}
discountTotalAmount = discountTotalAmount + orderSub.GoodsOriginAmount*10 + orderSub.GoodsDiscountAmount
if orderSub.PayType == 3 || orderSubR1.Coupons != nil {
x := float64(orderSub.PayAmount) / 10
orderSubR1.PayAmount = strconv.FormatFloat(x, 'f', 1, 64)
}
if orderSubR1.Discount < 100 {
//orderSubR1.PayAmount = int32(math.Round(float64(orderSubR1.TotalAmount) * (orderSubR1.Discount / 100.0)))
//x := float64(orderSubR1.TotalAmount) * (orderSubR1.Discount / 100.0) / 10
if orderSubR1.Discount < 100 || orderSubR1.Coupons != nil {
orderSubR1.DiscountAmount = orderSubR1.PayAmount
} else {
orderSubR1.DiscountAmount = strconv.Itoa(orderSubR1.TotalAmount)
if orderSub.PayAmount > 0 {
orderSubR1.DiscountAmount = strconv.FormatFloat(float64(orderSub.PayAmount)/10, 'f', 1, 64)
} else {
orderSubR1.DiscountAmount = strconv.Itoa(orderSubR1.TotalAmount)
}
}
if orderSub.PayType == 1 && orderSubR1.Coupons == nil {
orderSubR1.PayAmount = strconv.Itoa(orderSubR1.TotalAmount)
}
if len(orderSubR1.PayAmount) == 0 {
orderSubR1.PayAmount = "0"
}
if len(orderSubR1.PayAmount) == 0 {
orderSubR1.PayAmount = "0"
}
subOrderList = append(subOrderList, orderSubR1)
}
if discountTotalAmount > 0 {
orderDetail.DiscountAmount = strconv.Itoa(discountTotalAmount / 10.0)
}
var carOrder models.CarOrder
database.Instance().Model(&models.CarOrder{}).Where("order_id = ?", orderMain.OrderId).Find(&carOrder)
if carOrder.Id > 0 {
@ -333,10 +559,7 @@ func GetOrderDetail(orderId string) OrderDetail {
}
func checkOrderServiceTime(serviceTime string, projectionServiceTime int) bool {
type orderMainTmp struct {
ServiceTime string
ProjectionServiceTime int
}
serviceTimeD, _ := time.Parse("2006-01-02 15:04", serviceTime)
hour := serviceTimeD.Hour()
if hour == 20 && projectionServiceTime > 2*60 {
@ -346,14 +569,9 @@ func checkOrderServiceTime(serviceTime string, projectionServiceTime int) bool {
return true
}
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') and order_status != 3 and order_status != 4 and status = 1", serviceTime).Find(&orderMainTmpList)
//时间点订单数量<服务车辆*车辆单次服务数量 才可接受预约
if len(orderMainTmpList) > 0 {
return len(orderMainTmpList) >= len(CarMap)*CarServiceNum
}
return false
var orderTempList []utils.OrderTemp
database.Instance().Model(&models.OrderMain{}).Where("service_time >= DATE_SUB(NOW(), INTERVAL 7 DAY) and order_status != 3 and order_status != 4 and status = 1").Find(&orderTempList)
return utils.CheckAvailability(orderTempList, len(CarMap), serviceTime, projectionServiceTime)
}
type OrderListRequest struct {
@ -363,14 +581,16 @@ type OrderListRequest struct {
}
type SubOrder struct {
OrderId string `json:"orderId"` //子订单ID
Status int `json:"status"` //子订单状态 0待派单 1待服务 2服务中 3已完成 4已取消
UserPetInfo UserPetInfo `json:"userPetInfo"` //用户宠物信息
TotalAmount int `json:"totalAmount"` //总金额
PayAmount string `json:"payAmount"` //实际支付金额
DiscountAmount string `json:"discountAmount"` //折扣金额
Discount float64 `json:"discount"` //用户折扣
Goods []models.Goods `json:"goods"` //商品信息
OrderId string `json:"orderId"` //子订单ID
Status int `json:"status"` //子订单状态 0待派单 1待服务 2服务中 3已完成 4已取消
UserPetInfo UserPetInfo `json:"userPetInfo"` //用户宠物信息
TotalAmount int `json:"totalAmount"` //总金额
PayAmount string `json:"payAmount"` //实际支付金额
DiscountAmount string `json:"discountAmount"` //折扣金额
Discount float64 `json:"discount"` //用户折扣
Goods []models.Goods `json:"goods"` //商品信息
Coupons *models.Coupons `json:"coupons"` //优惠券信息
CouponsAmount string `json:"couponsAmount"` //优惠券减免金额
}
type OrderDetail struct {
@ -389,6 +609,7 @@ type OrderDetail struct {
DiscountAmount string `json:"discountAmount"` //折扣金额
Uid int64 `json:"uid"` //用户ID
UserAmount float64 `json:"userAmount"` //用户余额
MarkStatus int `json:"markStatus"` //订单是否已评价
}
type OrderListResponse struct {
@ -411,9 +632,9 @@ func (p DefParty) orderList() web_iris.Party {
}
var orderList []models.OrderMain
if orderListRequest.Status == 0 {
database.Instance().Model(&models.OrderMain{}).Where("uid = ? and status = 1", headerBaseInfo.Uid).Offset((orderListRequest.PageNo - 1) * orderListRequest.PageSize).Limit(orderListRequest.PageSize).Order(clause.OrderByColumn{Column: clause.Column{Name: "create_time"}, Desc: true}).Find(&orderList)
database.Instance().Model(&models.OrderMain{}).Where("uid = ? and status = 1", headerBaseInfo.Uid).Order(clause.OrderByColumn{Column: clause.Column{Name: "create_time"}, Desc: true}).Offset((orderListRequest.PageNo - 1) * orderListRequest.PageSize).Limit(orderListRequest.PageSize).Find(&orderList)
} else {
database.Instance().Model(&models.OrderMain{}).Where("uid = ? and order_status = ? and status = 1", headerBaseInfo.Uid, orderListRequest.Status).Offset((orderListRequest.PageNo - 1) * orderListRequest.PageSize).Limit(orderListRequest.PageSize).Order(clause.OrderByColumn{Column: clause.Column{Name: "create_time"}, Desc: true}).Find(&orderList)
database.Instance().Model(&models.OrderMain{}).Where("uid = ? and order_status = ? and status = 1", headerBaseInfo.Uid, orderListRequest.Status).Order(clause.OrderByColumn{Column: clause.Column{Name: "create_time"}, Desc: true}).Offset((orderListRequest.PageNo - 1) * orderListRequest.PageSize).Limit(orderListRequest.PageSize).Find(&orderList)
}
var orderDetails []OrderDetail
for _, value := range orderList {
@ -431,6 +652,7 @@ func (p DefParty) orderList() web_iris.Party {
TotalAmount: value.TotalAmount,
DiscountAmount: strconv.FormatFloat(float64(value.PayTotalAmount)/10.0, 'f', 1, 64),
Discount: float64(value.PayDiscount / 100.0),
MarkStatus: value.MarkStatus,
}
var subOrderList []SubOrder
var orderSubList []models.OrderSub
@ -539,6 +761,16 @@ func (p DefParty) orderCancel() web_iris.Party {
"OrderStatus": 4,
}
database.Instance().Model(&orderSub).Updates(&updateValuesSub)
//返还优惠券
if orderSub.Cid > 0 {
var userCoupons []models.UserCoupons
database.Instance().Model(&models.UserCoupons{}).Where("uid = ? and cid = ? and coupons_status = 2", headerBaseInfo.Uid, orderSub.Cid).Order(clause.OrderByColumn{Column: clause.Column{Name: "update_time"}, Desc: true}).Find(&userCoupons)
coupons := userCoupons[0]
updateValuesCoupons := map[string]interface{}{
"CouponsStatus": 1,
}
database.Instance().Model(&coupons).Updates(updateValuesCoupons)
}
}
Success(ctx, orderCancelRequest, OrderCancelResponse{GetOrderDetail(orderMain.OrderId)})
})
@ -554,10 +786,6 @@ type OrderServiceTimeRequest struct {
ServiceAddrId int64
}
type OrderServiceTimeResponse struct {
Times map[string][]TimeObject `json:"times"`
}
// 获取订单可预约时间
func (p DefParty) orderServiceTime() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
@ -570,50 +798,9 @@ func (p DefParty) orderServiceTime() web_iris.Party {
ParamError.Fail(ctx, orderServiceTimeRequest)
return
}
type orderMainTmp struct {
ServiceTime string
ProjectionServiceTime int
}
var orderMainTmpList []orderMainTmp
database.Instance().Model(&models.OrderMain{}).Where("service_time >= DATE_SUB(NOW(), INTERVAL 7 DAY) and order_status != 3 and order_status != 4 and status = 1").Find(&orderMainTmpList)
var orderTimeMap = make(map[string]string)
var orderTimeNum = make(map[string]int)
for _, value := range orderMainTmpList {
orderTimeMap[value.ServiceTime] = value.ServiceTime
orderTimeNum[value.ServiceTime] = orderTimeNum[value.ServiceTime] + 1
if value.ProjectionServiceTime > 0 {
//计算出服务时间点之后累计延长时间
date, _ := time.Parse("2006-01-02 15:04", value.ServiceTime)
lastDate := date.Add(time.Minute * time.Duration(value.ProjectionServiceTime))
for t := date; t.Before(lastDate); t = t.Add(time.Hour) {
timeStr := t.Format("2006-01-02 15:04")
orderTimeMap[timeStr] = timeStr
orderTimeNum[timeStr] = orderTimeNum[timeStr] + 1
}
}
}
serviceTime := AddrServiceMap[orderServiceTimeRequest.ServiceAddrId]
times := strings.Split(serviceTime.Times, ",")
carNum := len(CarMap)
daysMap := utils.GetStrDays(7, 60, ReserveMap, orderTimeMap, carNum, orderTimeNum, CarServiceNum, times)
var dayHoursMap = make(map[string][]TimeObject)
for day, values := range daysMap {
key := day
for _, value := range values {
if _, ok := dayHoursMap[key]; ok {
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
Time: value.Time,
Y: value.Y,
})
} else {
dayHoursMap[key] = []TimeObject{{
Time: value.Time,
Y: value.Y,
}}
}
}
}
Success(ctx, headerBaseInfo, OrderServiceTimeResponse{dayHoursMap})
var orderTempList []utils.OrderTemp
database.Instance().Model(&models.OrderMain{}).Where("service_time >= DATE_SUB(NOW(), INTERVAL 7 DAY) and order_status != 3 and order_status != 4 and status = 1").Find(&orderTempList)
Success(ctx, headerBaseInfo, utils.ProcessOrders(orderTempList, len(CarMap), 7))
})
}}
}
@ -700,8 +887,23 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party {
database.Instance().Model(&models.OrderMain{}).Where("order_id = ? and status = 1", orderSub.MainOrderId).Find(&orderMain)
var nowOrderTotalAmount = 0
var projectionServiceTime = 0
//商品优惠券价格
var goodsDiscountAmount = 0
//商品非优惠券价格
var goodsNotDiscountAmount = 0
var coupons models.Coupons
for _, value := range orderGoodsUpdateRequest.GoodsIds {
goods := GoodsMap[value]
if orderSub.Cid > 0 {
coupons = CouponsMap[orderSub.Cid]
}
if coupons.Id > 0 && coupons.GoodsSubType == goods.GoodsSubType {
goodsDiscountAmount = goodsDiscountAmount + int(utils.RoundToOneDecimalPlace(float64(goods.Price)*(float64(coupons.Discount)/100.0))*10)
} else {
goodsNotDiscountAmount = goodsNotDiscountAmount + goods.Price
}
nowOrderTotalAmount = nowOrderTotalAmount + goods.Price
if goods.Time != "/" && len(goods.Time) > 0 {
goodsTime, _ := strconv.Atoi(goods.Time)
@ -723,24 +925,26 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party {
allProjectionServiceTime = allProjectionServiceTime + value.ProjectionServiceTime
}
var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", orderMain.Uid).Find(&userInfo)
//已支付
if orderMain.PayStatus == 1 {
if orderMain.PayType == 3 {
var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", orderMain.Uid).Find(&userInfo)
var originAmount = userInfo.Amount
//先退还 当前订单
userInfo.Amount = userInfo.Amount + orderSub.PayAmount
if userInfo.Discount > 0 {
discount := float64(userInfo.Discount)
subOrderAmount = int(utils.RoundToOneDecimalPlace(float64(subOrderAmount)*(discount/100.0)) * 10)
//计算非折扣商品
subOrderAmount = int(utils.RoundToOneDecimalPlace(float64(goodsNotDiscountAmount)*(discount/100.0)) * 10)
} else {
subOrderAmount = goodsNotDiscountAmount * 10
}
orderMain.PayTotalAmount = orderMain.PayTotalAmount - originOrderPayAmount + subOrderAmount
orderMain.TotalAmount = orderMain.TotalAmount - originOrderTotalAmount + nowOrderTotalAmount
orderMain.PayTotalAmount = orderMain.PayTotalAmount - originOrderPayAmount + subOrderAmount + goodsDiscountAmount
//余额不足
if userInfo.Amount < subOrderAmount {
if userInfo.Amount < subOrderAmount+goodsDiscountAmount {
OrderUpdateBalanceNotEnough.DefFail(ctx, orderGoodsUpdateRequest, "原订单金额:"+strconv.FormatFloat(float64(orderMain.PayTotalAmount)/10, 'f', 1, 64)+" 修改后订单金额:"+strconv.FormatFloat(float64(orderMain.PayTotalAmount)/10, 'f', 1, 64)+";修改服务项目后余额不足,请充值后再支付")
return
}
@ -748,13 +952,13 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party {
var amountType = 2
var proAmount = 0
//原始价格小于新价格 扣,原始价格大于新价格 加
if originOrderPayAmount < subOrderAmount {
if originOrderPayAmount < subOrderAmount+goodsDiscountAmount {
} else {
amountType = 1
}
var preAmount = orderMain.PayTotalAmount
userInfo.Amount = userInfo.Amount - subOrderAmount
userInfo.Amount = userInfo.Amount - (subOrderAmount + goodsDiscountAmount)
updateValues := map[string]interface{}{
"Amount": userInfo.Amount,
}
@ -780,45 +984,202 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party {
database.Instance().Model(&models.UserAmountRecord{}).Create(&userAmountRecord)
zap_server.ZAPLOG.Info("会员金额扣除", zap.Any("用户ID", userInfo.Id), zap.Any("订单ID", orderMain.OrderId), zap.Any("用户修改之前余额", originAmount), zap.Any("当前余额", userInfo.Amount), zap.Any("商品修改之前金额", preAmount), zap.Any("商品修改之后金额", orderMain.PayTotalAmount), zap.Any("折扣", userInfo.Discount))
}
orderSub.PayAmount = subOrderAmount + goodsDiscountAmount
} else {
var x = 0
if originOrderTotalAmount > nowOrderTotalAmount {
x = originOrderTotalAmount - nowOrderTotalAmount
} else if nowOrderTotalAmount > originOrderTotalAmount {
x = nowOrderTotalAmount - originOrderTotalAmount
}
userAmountRecord := models.UserAmountRecord{
UserId: userInfo.Id,
Type: 3,
OriginAmount: userInfo.Amount,
ProAmount: x * 10,
CurrAmount: userInfo.Amount,
OrderId: orderMain.OrderId,
ProScene: "修改订单服务项目",
Status: 1,
}
database.Instance().Model(&models.UserAmountRecord{}).Create(&userAmountRecord)
orderSub.PayAmount = goodsNotDiscountAmount*10 + goodsDiscountAmount
}
database.Instance().Where("sub_order_id = ?", orderGoodsUpdateRequest.OrderId).Delete(&models.OrderDetail{})
var goodsName = ""
for _, value := range orderGoodsUpdateRequest.GoodsIds {
goods := GoodsMap[value]
orderDetail := models.OrderDetail{
SubOrderId: orderGoodsUpdateRequest.OrderId,
GoodsId: goods.Id,
Amount: goods.Price,
Cid: orderSub.Cid,
}
goodsName = goods.Name + "、" + goodsName
database.Instance().Model(&models.OrderDetail{}).Create(&orderDetail)
}
userPetInfo := GetUserPet(orderMain.Uid, orderSub.PetId)
var weightStr = "无"
if userPetInfo.PetBaseInfo.PetType == 1 {
weightStr = CatWeightMap[userPetInfo.PetInfo.Weight]
} else {
weightStr = DogWeightMap[userPetInfo.PetInfo.Weight]
}
var petInfo = "宠物名称:" + userPetInfo.PetInfo.NickName + "</br>品种:" + userPetInfo.PetBaseInfo.Assortment + "</br>体重:" + weightStr + "</br>服务项目:" + goodsName
orderSub.PetInfo = petInfo
orderSub.TotalAmount = nowOrderTotalAmount
orderSub.PayAmount = subOrderAmount
orderSub.ProjectionServiceTime = projectionServiceTime
updateValues := map[string]interface{}{
"TotalAmount": orderSub.TotalAmount,
"PayAmount": orderSub.PayAmount,
"ProjectionServiceTime": orderSub.ProjectionServiceTime,
"GoodsDiscountAmount": goodsDiscountAmount,
"GoodsOriginAmount": goodsNotDiscountAmount,
"PetInfo": orderSub.PetInfo,
}
database.Instance().Model(&orderSub).Updates(&updateValues)
//当前所有订单
var orderSubListAll []models.OrderSub
database.Instance().Model(&models.OrderSub{}).Where("main_order_id = ?", orderMain.OrderId).Find(&orderSubListAll)
var totalAmount = 0
for _, sub := range orderSubListAll {
totalAmount = totalAmount + sub.TotalAmount
}
orderMain.ProjectionServiceTime = allProjectionServiceTime
orderMain.TotalAmount = totalAmount
updateValues1 := map[string]interface{}{
"PayTotalAmount": orderMain.PayTotalAmount,
"TotalAmount": orderMain.TotalAmount,
"ProjectionServiceTime": orderMain.ProjectionServiceTime,
}
database.Instance().Model(&orderMain).Updates(&updateValues1)
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) {
index.Post(OrderBase+"/orderPay", func(ctx *context.Context) {
type OrderMarkRecord struct {
OrderId string
Lab1 int
Lab2 int
Lab3 int
Message string
}
// 评价
func (p DefParty) orderMarkRecord() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(OrderBase+"/orderMarkRecord", func(ctx *context.Context) {
headerBaseInfo := GetHeaderBaseInfo(ctx)
body, _ := io.ReadAll(ctx.Request().Body)
var orderMarkRecordRequest OrderMarkRecord
json.Unmarshal(body, &orderMarkRecordRequest)
if len(orderMarkRecordRequest.OrderId) == 0 {
OrderExistError.Fail(ctx, orderMarkRecordRequest)
return
}
serviceUserMarkRecord1 := models.ServiceUserMarkRecord{
Uid: headerBaseInfo.Uid,
OrderId: orderMarkRecordRequest.OrderId,
ServiceStar: orderMarkRecordRequest.Lab1,
ServiceLabels: "1",
Status: 1,
}
database.Instance().Model(&models.ServiceUserMarkRecord{}).Create(&serviceUserMarkRecord1)
serviceUserMarkRecord2 := models.ServiceUserMarkRecord{
Uid: headerBaseInfo.Uid,
OrderId: orderMarkRecordRequest.OrderId,
ServiceStar: orderMarkRecordRequest.Lab2,
ServiceLabels: "2",
Status: 1,
}
database.Instance().Model(&models.ServiceUserMarkRecord{}).Create(&serviceUserMarkRecord2)
serviceUserMarkRecord3 := models.ServiceUserMarkRecord{
Uid: headerBaseInfo.Uid,
OrderId: orderMarkRecordRequest.OrderId,
ServiceStar: orderMarkRecordRequest.Lab2,
ServiceLabels: "3",
Status: 1,
}
database.Instance().Model(&models.ServiceUserMarkRecord{}).Create(&serviceUserMarkRecord3)
serviceUserMarkRecord4 := models.ServiceUserMarkRecord{
Uid: headerBaseInfo.Uid,
OrderId: orderMarkRecordRequest.OrderId,
ServiceStar: 0,
MarkContext: orderMarkRecordRequest.Message,
ServiceLabels: "4",
Status: 1,
}
var orderMain models.OrderMain
database.Instance().Model(&models.OrderMain{}).Where("order_id = ?", orderMarkRecordRequest.OrderId).Find(&orderMain)
updateValues1 := map[string]interface{}{
"MarkStatus": 1,
}
database.Instance().Model(&orderMain).Updates(&updateValues1)
database.Instance().Model(&models.ServiceUserMarkRecord{}).Create(&serviceUserMarkRecord4)
Success(ctx, orderMarkRecordRequest, nil)
})
}}
}
type OrderMarkRecordInfoRequest struct {
OrderId string
}
type OrderMarkRecordInfoResponse struct {
Lab1 int `json:"lab1"`
Lab2 int `json:"lab2"`
Lab3 int `json:"lab3"`
Message string `json:"message"`
}
// 查看评价
func (p DefParty) orderMarkRecordInfo() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(OrderBase+"/orderMarkRecordInfo", func(ctx *context.Context) {
body, _ := io.ReadAll(ctx.Request().Body)
var orderMarkRecordRequest OrderMarkRecordInfoRequest
json.Unmarshal(body, &orderMarkRecordRequest)
if len(orderMarkRecordRequest.OrderId) == 0 {
OrderExistError.Fail(ctx, orderMarkRecordRequest)
return
}
var serviceUserMarkRecord []models.ServiceUserMarkRecord
database.Instance().Model(&models.ServiceUserMarkRecord{}).Where("order_id = ?", orderMarkRecordRequest.OrderId).Find(&serviceUserMarkRecord)
var lab1, lab2, lab3 int
var lab4 string
for _, markRecord := range serviceUserMarkRecord {
if markRecord.ServiceLabels == "1" {
lab1 = markRecord.ServiceStar
}
if markRecord.ServiceLabels == "2" {
lab2 = markRecord.ServiceStar
}
if markRecord.ServiceLabels == "3" {
lab3 = markRecord.ServiceStar
}
if markRecord.ServiceLabels == "4" {
lab4 = markRecord.MarkContext
}
}
Success(ctx, orderMarkRecordRequest, OrderMarkRecordInfoResponse{
Lab1: lab1,
Lab2: lab2,
Lab3: lab3,
Message: lab4,
})
})
}}
}

225
business/api/pay.go Normal file
View File

@ -0,0 +1,225 @@
package api
import (
"crypto/x509"
"encoding/json"
"fmt"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers"
"github.com/wechatpay-apiv3/wechatpay-go/core/notify"
"github.com/wechatpay-apiv3/wechatpay-go/services/payments"
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/jsapi"
utils2 "github.com/wechatpay-apiv3/wechatpay-go/utils"
"go.uber.org/zap"
"io"
"pet-house.com/business/models"
"pet-house.com/business/utils"
"pet-house.com/core/server/database"
"pet-house.com/core/server/web"
"pet-house.com/core/server/web/web_iris"
"pet-house.com/core/server/zap_server"
"strconv"
)
// 充值挡位列表
func (p DefParty) rechargeInfoList() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(PayBase+"/rechargeInfoList", func(ctx *context.Context) {
var rechargeInfoList []models.RechargeInfo
database.Instance().Model(&models.RechargeInfo{}).Where("type = 1 and status = 1").Find(&rechargeInfoList)
Success(ctx, nil, rechargeInfoList)
})
}}
}
type ToPayRequest struct {
PayId int //支付ID
OrderId string //订单号
}
type ToPayResponse struct {
Content *jsapi.PrepayWithRequestPaymentResponse `json:"content"`
PayOrderId string `json:"payOrderId"`
PayType int `json:"payType"` //支付类型 0在线支付 1会员余额支付
}
// 充值
func (p DefParty) toPay() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(PayBase+"/toPay", func(ctx *context.Context) {
headerBaseInfo := GetHeaderBaseInfo(ctx)
body, _ := io.ReadAll(ctx.Request().Body)
var toPayRequest ToPayRequest
json.Unmarshal(body, &toPayRequest)
var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo)
price := 0.0
desc := "充值"
id := 0
if len(toPayRequest.OrderId) == 0 {
var rechargeInfo *models.RechargeInfo
database.Instance().Model(&models.RechargeInfo{}).Where("id = ?", toPayRequest.PayId).Find(&rechargeInfo)
price1, _ := strconv.ParseFloat(rechargeInfo.Price, 64)
price = price1
desc = rechargeInfo.Name
id = rechargeInfo.Id
}
svc := jsapi.JsapiApiService{Client: utils.GetWxPayService()}
var payPrice = core.Int64(int64(price * 100.0))
orderId := NextId.Generate().String()
//支付订单
if len(toPayRequest.OrderId) > 0 {
var orderSubList []models.OrderSub
database.Instance().Model(&models.OrderSub{}).Where("main_order_id = ? ", toPayRequest.OrderId).Find(&orderSubList)
if len(orderSubList) == 0 {
OrderExistError.Fail(ctx, toPayRequest)
return
}
//取出折扣价
price1 := 0.0
for _, orderSub := range orderSubList {
price1 = price1 + float64(orderSub.PayAmount)
}
var orderMain models.OrderMain
database.Instance().Model(&models.OrderMain{}).Where("order_id = ? and status = 1", toPayRequest.OrderId).Find(&orderMain)
if len(orderMain.PayOrderId) > 0 {
var payOrder *models.PayOrder
database.Instance().Model(&models.PayOrder{}).Where("order_id = ?", orderMain.PayOrderId).Find(&payOrder)
if payOrder.OrderStatus == 1 {
//去除定金扣除金额
price1 = price1 - (30.0 * 10)
}
}
payPrice = core.Int64(int64(price1 * 10.0))
desc = "宠物洗护付款-" + toPayRequest.OrderId
orderId = toPayRequest.OrderId
price = price1 / 10.0
}
// 得到prepay_id以及调起支付所需的参数和签名
resp, _, err := svc.PrepayWithRequestPayment(ctx,
jsapi.PrepayRequest{
Appid: core.String(utils.CONFIG.AppId),
Mchid: core.String(utils.CONFIG.MchId),
Description: core.String(desc),
OutTradeNo: core.String(orderId),
NotifyUrl: core.String(web.CONFIG.System.Domain + "/pet-house/pay/payNotify"),
Amount: &jsapi.Amount{
Total: payPrice,
},
Payer: &jsapi.Payer{
Openid: core.String(userInfo.OpenId),
},
},
)
if err != nil {
PayError.DefFail(ctx, toPayRequest, nil)
return
}
payOrder := models.PayOrder{
OrderId: orderId,
OrderName: desc,
OrderPrice: fmt.Sprintf("%.1f", price),
RechargeId: id,
PayId: "",
Uid: headerBaseInfo.Uid,
}
database.Instance().Model(&models.PayOrder{}).Create(&payOrder)
Success(ctx, toPayRequest, ToPayResponse{Content: resp, PayOrderId: orderId, PayType: 0})
})
}}
}
// 充值通知
func (p DefParty) payNotify() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(PayBase+"/payNotify", func(ctx *context.Context) {
var cert = `-----BEGIN CERTIFICATE-----
MIIEFDCCAvygAwIBAgIUXfrnoWdj8YwsOsPDsHsB8Exd/nQwDQYJKoZIhvcNAQEL
BQAwXjELMAkGA1UEBhMCQ04xEzARBgNVBAoTClRlbnBheS5jb20xHTAbBgNVBAsT
FFRlbnBheS5jb20gQ0EgQ2VudGVyMRswGQYDVQQDExJUZW5wYXkuY29tIFJvb3Qg
Q0EwHhcNMjQwOTEwMDc0NDUyWhcNMjkwOTA5MDc0NDUyWjBuMRgwFgYDVQQDDA9U
ZW5wYXkuY29tIHNpZ24xEzARBgNVBAoMClRlbnBheS5jb20xHTAbBgNVBAsMFFRl
bnBheS5jb20gQ0EgQ2VudGVyMQswCQYDVQQGEwJDTjERMA8GA1UEBwwIU2hlblpo
ZW4wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCnZzIY5opDpRJQU6KX
xtwVtyvq3u20pQgjUSYy4HxbEWbyTujrgEm+d6CrJrey0wLa9RBOwQMOuyYKbx3Y
t+WNxYnrkBDv5bbJtSTv6wA2/sINbFFSIP9GAiIAdGP/ii0BXjxG1pxGhrPDHW1Q
vSzJphyHO9s3gBDBNUW8BT/XxoLhxlOrbYNV+kv4Mr/oh9U+/KsNT1Ba1Pt8s4As
AQOJ7oE7xHzzUOgoFSyU+RvuYhIx6ZV0gTkZDmzu5cwj+FlCaxYFYnKPtxm5m9hj
eM39rTUl5jmsZXRQUyI9Ez1AkwVOjolbrJ3f5kpkpXoJvesfowOL53DfS/th+x3I
12QzAgMBAAGjgbkwgbYwCQYDVR0TBAIwADALBgNVHQ8EBAMCA/gwgZsGA1UdHwSB
kzCBkDCBjaCBiqCBh4aBhGh0dHA6Ly9ldmNhLml0cnVzLmNvbS5jbi9wdWJsaWMv
aXRydXNjcmw/Q0E9MUJENDIyMEU1MERCQzA0QjA2QUQzOTc1NDk4NDZDMDFDM0U4
RUJEMiZzZz1IQUNDNDcxQjY1NDIyRTEyQjI3QTlEMzNBODdBRDFDREY1OTI2RTE0
MDM3MTANBgkqhkiG9w0BAQsFAAOCAQEAgL/Bfpy6kS6qCBZycuGvwdqYWU9exf1a
ZfbG8eop1ADUD5j6LjZcBrLyaVZDNZMRafqDiWI1OBypEtAxC3MScN3B0rxiJ3uQ
LHn/YOel6DKKJdMjANC36NpseC/PXZrdMMdCFLzQuc2FcG2ObOhRKcfTRnR/zdcU
Tw88WZqCW0thBcOXcQ9e7R2fIk+W4YqQ7C1O1/17qDpViPOTGWWnJBnUYpi5lTlX
JIhayMjkemIO27X1j1ZdtA314xZpPrO4uqrVFiLahoZ9y6az0RhNpPadYcT6D24G
2boO3JsJZ1X/MNiW78pfDUra7a+yEoH+JjiPNtaw9ztbtKtDcLIgWQ==
-----END CERTIFICATE-----`
wechatPayCert, err1 := utils2.LoadCertificate(cert)
if err1 != nil {
panic(err1)
}
// 2. 使用本地管理的微信支付平台证书获取微信支付平台证书访问器
certificateVisitor := core.NewCertificateMapWithList([]*x509.Certificate{wechatPayCert})
// 3. 使用apiv3 key、证书访问器初始化 `notify.Handler`
handler := notify.NewNotifyHandler(utils.CONFIG.MchAPIv3Key, verifiers.NewSHA256WithRSAVerifier(certificateVisitor))
transaction := new(payments.Transaction)
notifyReq, err := handler.ParseNotifyRequest(ctx, ctx.Request(), transaction)
zap_server.ZAPLOG.Info("payNotify", zap.Any("notifyReq", notifyReq), zap.Any("transaction", transaction), zap.Any("err", err))
state := *transaction.TradeState
OrderStatus := 0
if "SUCCESS" == state {
OrderStatus = 1
} else if "REFUND" == state {
OrderStatus = 2
} else {
zap_server.ZAPLOG.Info("payNotify", zap.Any("notifyReq", notifyReq), zap.Any("transaction", transaction), zap.Any("state", state))
return
}
var payOrder *models.PayOrder
database.Instance().Model(&models.PayOrder{}).Where("order_id = ?", transaction.OutTradeNo).Find(&payOrder)
payOrderD := map[string]interface{}{
"OrderStatus": OrderStatus,
"PayId": *transaction.TransactionId,
}
database.Instance().Model(&payOrder).Updates(&payOrderD)
if payOrder.RechargeId > 1 {
var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", payOrder.Uid).Find(&userInfo)
var rechargeInfo *models.RechargeInfo
database.Instance().Model(&models.RechargeInfo{}).Where("id = ?", payOrder.RechargeId).Find(&rechargeInfo)
rechargePrice, _ := strconv.ParseInt(rechargeInfo.RechargePrice, 10, 64)
//充值
userAmountRecord := models.UserAmountRecord{
UserId: payOrder.Uid,
Type: 1,
OriginAmount: userInfo.Amount,
ProAmount: int(rechargePrice),
CurrAmount: userInfo.Amount + int(rechargePrice),
OrderId: payOrder.OrderId,
ProScene: "充值",
Status: 1,
}
database.Instance().Model(&models.UserAmountRecord{}).Create(&userAmountRecord)
userInfo.Amount = userInfo.Amount + (int(rechargePrice) * 10)
updateValues := map[string]interface{}{
"Amount": userInfo.Amount,
}
database.Instance().Model(&userInfo).Updates(&updateValues)
} else {
var orderMain models.OrderMain
database.Instance().Model(&models.OrderMain{}).Where("order_id = ? and status = 1", payOrder.OrderId).Find(&orderMain)
//设置订单状态
orderMain.PayStatus = 1
database.Instance().Save(&orderMain)
}
})
}}
}

View File

@ -4,27 +4,32 @@ import (
"encoding/json"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
"go.uber.org/zap"
"io"
"pet-house.com/business/models"
"pet-house.com/business/utils"
"pet-house.com/core/server/database"
"pet-house.com/core/server/web/web_iris"
"pet-house.com/core/server/zap_server"
"strconv"
)
var CatWeightMap = map[int]string{
1: "0-1.5kg",
2: "1.5-3kg",
//1: "0-1.5kg",
2: "0-3kg",
3: "3-5kg",
4: "5-8kg",
//5: "8kg以上",
6: "8kg以上",
}
var DogWeightMap = map[int]string{
1: "0-3kg",
1: "0-5kg",
2: "3-6kg",
3: "6-9kg",
3: "5-9kg",
4: "9-13kg",
5: "13-18kg",
6: "18-22kg",
7: "22-30kg",
8: "0-3kg",
}
type UserPetInfo struct {
@ -145,7 +150,7 @@ func (p DefParty) petAddOrEdit() web_iris.Party {
} else {
pet.Id = petAddOrEditRequest.Id
var userPetInfo models.Pet
database.Instance().Model(&models.Pet{}).Where("id = ? and uid = ?", pet.Id, headerBaseInfo.Uid).Find(&userPetInfo)
database.Instance().Model(&models.Pet{}).Where("id = ?", pet.Id).Find(&userPetInfo)
var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo)
if userPetInfo.Id == 0 && userInfo.Role == 0 {
@ -159,6 +164,83 @@ func (p DefParty) petAddOrEdit() web_iris.Party {
PetInfoNotUpdateError.Fail(ctx, petAddOrEditRequest)
return
}
} else {
if userPetInfo.Weight != pet.Weight {
//护理人员修改体重,需要更新对应的服务项目
var orderMainList []models.OrderMain
database.Instance().Model(&models.OrderMain{}).Where("uid = ? and order_status in (1,2)", userPetInfo.Uid).Find(&orderMainList)
for _, orderMain := range orderMainList {
if orderMain.PayStatus == 1 {
continue
}
var orderSubList []models.OrderSub
database.Instance().Model(&models.OrderSub{}).Where("main_order_id = ? ", orderMain.OrderId).Find(&orderSubList)
for orderSubIndex, orderSub := range orderSubList {
var orderDetailList []models.OrderDetail
database.Instance().Model(&models.OrderDetail{}).Where("sub_order_id = ? ", orderSub.OrderId).Find(&orderDetailList)
for orderDetailIndex, orderDetail := range orderDetailList {
var newGoodsDetail GoodsDetail
orderGoods := GoodsMap[orderDetail.GoodsId]
var goodsList []GoodsDetail
petBaseInfo := PetBaseInfoMap[userPetInfo.PetId]
key1 := strconv.Itoa(petBaseInfo.Id) + strconv.Itoa(petBaseInfo.PetType) + strconv.Itoa(pet.Weight) + "0"
goodsList = append(goodsList, GetPetGoodsList(key1)...)
key2 := strconv.Itoa(petBaseInfo.Id) + strconv.Itoa(petBaseInfo.PetType) + strconv.Itoa(pet.Weight) + strconv.Itoa(petBaseInfo.Hair)
goodsList = append(goodsList, GetPetGoodsList(key2)...)
key3 := "0" + strconv.Itoa(petBaseInfo.PetType) + strconv.Itoa(pet.Weight) + strconv.Itoa(petBaseInfo.Hair)
goodsList = append(goodsList, GetPetGoodsList(key3)...)
key4 := "0" + strconv.Itoa(petBaseInfo.PetType) + strconv.Itoa(pet.Weight) + "0"
goodsList = append(goodsList, GetPetGoodsList(key4)...)
for _, goodsDetail := range goodsList {
//取同名称 同类型 同子类型的商品
if goodsDetail.Name == orderGoods.Name && goodsDetail.GoodsType == orderGoods.GoodsType && goodsDetail.GoodsSubType == orderGoods.GoodsSubType {
zap_server.ZAPLOG.Info("更新体重命中的商品", zap.Any("原价", orderGoods.Price), zap.Any("Name", goodsDetail.Name), zap.Any("Price", goodsDetail.Price), zap.Any("GoodsType", goodsDetail.GoodsType), zap.Any("GoodsSubType", goodsDetail.GoodsSubType))
newGoodsDetail = goodsDetail
break
}
}
if newGoodsDetail.Id > 0 {
zap_server.ZAPLOG.Info("订单更新前", zap.Any("orderDetailId", orderDetail.SubOrderId), zap.Any("GoodsId", orderDetail.GoodsId), zap.Any("Amount", orderDetail.Amount), zap.Any("DiscountAmount", orderDetail.DiscountAmount))
//更新订单商品
orderDetail.GoodsId = newGoodsDetail.Id
orderDetail.Amount = newGoodsDetail.Price
orderDetail.DiscountAmount = int(utils.RoundToOneDecimalPlace(float64(orderDetail.Amount)*(float64(orderDetail.Discount)/100.0)) * 10)
zap_server.ZAPLOG.Info("商品订单更新后", zap.Any("orderDetailId", orderDetail.SubOrderId), zap.Any("GoodsId", orderDetail.GoodsId), zap.Any("Amount", orderDetail.Amount), zap.Any("DiscountAmount", orderDetail.DiscountAmount))
database.Instance().Model(&orderDetail).Updates(&orderDetail)
orderDetailList[orderDetailIndex] = orderDetail
}
}
var totalAmount = 0
var goodsOriginAmount = 0
var goodsDiscountAmount = 0
for _, orderDetail := range orderDetailList {
if orderDetail.DiscountAmount > 0 {
goodsDiscountAmount = goodsDiscountAmount + orderDetail.DiscountAmount
} else {
goodsOriginAmount = goodsOriginAmount + orderDetail.Amount
}
totalAmount = totalAmount + orderDetail.Amount
}
zap_server.ZAPLOG.Info("子订单更新前", zap.Any("orderSubId", orderSub.OrderId), zap.Any("goodsOriginAmount", orderSub.GoodsOriginAmount), zap.Any("goodsDiscountAmount", orderSub.GoodsDiscountAmount), zap.Any("totalAmount", orderSub.TotalAmount), zap.Any("PayAmount", orderSub.PayAmount))
orderSub.GoodsOriginAmount = goodsOriginAmount
orderSub.GoodsDiscountAmount = goodsDiscountAmount
orderSub.TotalAmount = totalAmount
orderSub.PayAmount = goodsDiscountAmount + (goodsOriginAmount * 10)
zap_server.ZAPLOG.Info("子订单更新后", zap.Any("orderSubId", orderSub.OrderId), zap.Any("goodsOriginAmount", orderSub.GoodsOriginAmount), zap.Any("goodsDiscountAmount", orderSub.GoodsDiscountAmount), zap.Any("totalAmount", orderSub.TotalAmount), zap.Any("PayAmount", orderSub.PayAmount))
database.Instance().Model(&orderSub).Updates(&orderSub)
orderSubList[orderSubIndex] = orderSub
}
var totalAmount = 0
for _, orderSub := range orderSubList {
totalAmount = totalAmount + orderSub.TotalAmount
}
zap_server.ZAPLOG.Info("主订单更新前", zap.Any("orderMainId", orderMain.OrderId), zap.Any("totalAmount", orderMain.TotalAmount))
orderMain.TotalAmount = totalAmount
zap_server.ZAPLOG.Info("主订单更新后", zap.Any("orderMainId", orderMain.OrderId), zap.Any("totalAmount", orderMain.TotalAmount))
database.Instance().Model(&orderMain).Updates(&orderMain)
}
}
}
updateValues := map[string]interface{}{
"NickName": pet.NickName,

View File

@ -67,6 +67,7 @@ func (p DefParty) serviceAddOrEdit() web_iris.Party {
Addr: serviceAddOrEditRequest.Addr,
Longitude: serviceAddOrEditRequest.Longitude,
Latitude: serviceAddOrEditRequest.Latitude,
Status: 1,
}
if len(serviceAddOrEditRequest.Longitude) == 0 || len(serviceAddOrEditRequest.Latitude) == 0 {
addrGeocoding := utils.GetAddrGeocoding(utils.BmapGeoCodingRequest{Address: serviceAddOrEditRequest.Addr})
@ -152,3 +153,74 @@ func (p DefParty) serviceAreaAddrList() web_iris.Party {
})
}}
}
type ServiceCarLocationUploadRequest struct {
Longitude string //经度
Latitude string //纬度
}
// 服务车辆位置上报
func (p DefParty) serviceCarLocationUpload() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(ServiceBase+"/serviceCarLocationUpload", func(ctx *context.Context) {
headerBaseInfo := GetHeaderBaseInfo(ctx)
body, _ := io.ReadAll(ctx.Request().Body)
var serviceCarLocationUploadRequest ServiceCarLocationUploadRequest
json.Unmarshal(body, &serviceCarLocationUploadRequest)
var serviceCarUser models.ServiceCarUser
database.Instance().Model(&models.ServiceCarUser{}).Where("uid = ?", headerBaseInfo.Uid).Find(&serviceCarUser)
if serviceCarUser.Uid == 0 {
CarNotExistError.Fail(ctx, serviceCarLocationUploadRequest)
return
}
if len(serviceCarLocationUploadRequest.Longitude) == 0 || len(serviceCarLocationUploadRequest.Latitude) == 0 {
Success(ctx, serviceCarLocationUploadRequest, nil)
return
}
serviceCarLocation := models.ServiceCarLocation{
Uid: headerBaseInfo.Uid,
Longitude: serviceCarLocationUploadRequest.Longitude,
Latitude: serviceCarLocationUploadRequest.Latitude,
CarId: serviceCarUser.CarId,
Status: 1,
}
database.Instance().Model(&models.ServiceCarLocation{}).Create(&serviceCarLocation)
Success(ctx, serviceCarLocationUploadRequest, nil)
})
}}
}
type ServiceCarLocationListRequest struct {
OrderId string //订单ID
}
type ServiceCarLocationListResponse struct {
ServiceCarLocationList []models.ServiceCarLocation `json:"serviceCarLocationList"`
}
// 服务车辆经纬度列表
func (p DefParty) serviceCarLocationList() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(ServiceBase+"/serviceCarLocationList", func(ctx *context.Context) {
body, _ := io.ReadAll(ctx.Request().Body)
var serviceCarLocationListRequest ServiceCarLocationListRequest
json.Unmarshal(body, &serviceCarLocationListRequest)
var carOrder models.CarOrder
database.Instance().Model(&models.CarOrder{}).Where("order_id = ?", serviceCarLocationListRequest.OrderId).Find(&carOrder)
if carOrder.Id == 0 {
OrderNotDispachError.Fail(ctx, serviceCarLocationListRequest)
return
}
var serviceCarLocation []models.ServiceCarLocation
database.Instance().Model(&models.ServiceCarLocation{}).Where("car_id = ? and create_time >= CURDATE()", carOrder.CarId).Find(&serviceCarLocation)
Success(ctx, serviceCarLocationListRequest, ServiceCarLocationListResponse{serviceCarLocation})
})
}}
}

View File

@ -25,7 +25,9 @@ func (p DefParty) systemConfigInfo() web_iris.Party {
}
type SystemBannersResponse struct {
Banners []models.SystemConfig `json:"banners"`
Banners []models.SystemConfig `json:"banners"`
ShareText string `json:"shareText"`
ShareImg string `json:"shareImg"`
}
// 获取系统banner
@ -34,7 +36,24 @@ func (p DefParty) systemBanners() web_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})
var systemConfigShare models.SystemConfig
database.Instance().Model(&models.SystemConfig{}).Where("config_type = 3").Order(clause.OrderByColumn{Column: clause.Column{Name: "sort"}, Desc: true}).Limit(1).Find(&systemConfigShare)
Success(ctx, nil, SystemBannersResponse{systemConfig, systemConfigShare.Content, systemConfigShare.JumpUrl})
})
}}
}
type PayoffResponse struct {
Payoff bool `json:"payoff"`
}
// 获取支付开关
func (p DefParty) getPayoff() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(System+"/getPayoff", func(ctx *context.Context) {
var systemConfigPayOnOff models.SystemConfig
database.Instance().Model(&models.SystemConfig{}).Where("config_type = 4").Order(clause.OrderByColumn{Column: clause.Column{Name: "sort"}, Desc: true}).Limit(1).Find(&systemConfigPayOnOff)
Success(ctx, nil, PayoffResponse{systemConfigPayOnOff.Name == "payOff"})
})
}}
}

View File

@ -0,0 +1,25 @@
-----BEGIN CERTIFICATE-----
MIIEKzCCAxOgAwIBAgIUfaIQgSDkxBhTe888BhqrEJzPiKkwDQYJKoZIhvcNAQEL
BQAwXjELMAkGA1UEBhMCQ04xEzARBgNVBAoTClRlbnBheS5jb20xHTAbBgNVBAsT
FFRlbnBheS5jb20gQ0EgQ2VudGVyMRswGQYDVQQDExJUZW5wYXkuY29tIFJvb3Qg
Q0EwHhcNMjQwOTEwMDc0NDUzWhcNMjkwOTA5MDc0NDUzWjCBhDETMBEGA1UEAwwK
MTY4MjYzNzYxMjEbMBkGA1UECgwS5b6u5L+h5ZWG5oi357O757ufMTAwLgYDVQQL
DCflroHms6LlrqDmiqTlrrblrqDnianmnI3liqHmnInpmZDlhazlj7gxCzAJBgNV
BAYTAkNOMREwDwYDVQQHDAhTaGVuWmhlbjCCASIwDQYJKoZIhvcNAQEBBQADggEP
ADCCAQoCggEBALoZ/ZK7BdW1DKCzsqQnS9ElkWhv8Df4JidAupVoaaGa0Iz8cukj
8JgqzzmOA0fSief3z0OvOvmXQujNLXka38Y+8KB/K/BnqRYVGSvLWKwfdalSS+ca
JZUNLVQVv1zDrPVPb3JmoJMADPIq2sOfLqjmWPIxRcpa7sPeall5fMx07aVrpi2O
v1ueRUphIYNT6aV6KnPrRf/lcRwZxE0+l30l45sDNrd7l5tUsnJq/1OLP+kgidkp
ic6W1f3jrHZTwYakgShEUgkRsHeUjIQ0ZRYSsD4Mxn/bqdAxDSDWB6aWGwMrY1ku
bsPkE/AcXTpgpaC+2kQVhaYrWuly0w0T1jMCAwEAAaOBuTCBtjAJBgNVHRMEAjAA
MAsGA1UdDwQEAwID+DCBmwYDVR0fBIGTMIGQMIGNoIGKoIGHhoGEaHR0cDovL2V2
Y2EuaXRydXMuY29tLmNuL3B1YmxpYy9pdHJ1c2NybD9DQT0xQkQ0MjIwRTUwREJD
MDRCMDZBRDM5NzU0OTg0NkMwMUMzRThFQkQyJnNnPUhBQ0M0NzFCNjU0MjJFMTJC
MjdBOUQzM0E4N0FEMUNERjU5MjZFMTQwMzcxMA0GCSqGSIb3DQEBCwUAA4IBAQC7
Zgux40pvNohZx721rygjo0yUbx54docNS79Eh5J9ukSKMf0cTsORlAnrsCbSYnIo
MiqdPqccRYJUefUUuhOrKtuzaka4T+VSiaDTnZ07kB3I8xlvZtW32jHOstVPrJsB
fEg53sl5sfWHY+OfuEhwOkoH3v/Fs4nH4hQxjO8RW9tNXqLvTrl1JeEwV4bMZxCA
wCvoMPqn19WBFsaFb0kXF46oGeH5kId6oon0RCi+vXb8nSZ4oPXIJwxi9u/uy+wD
rVlHohjCK+bRbxGgaIcX5uMPK/M73mzuuLFCbIWN4CLz9yyZGKxNJBq4YuGe+jWa
gh1GheVuvTdcJ4ZGDhQT
-----END CERTIFICATE-----

View File

@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC6Gf2SuwXVtQyg
s7KkJ0vRJZFob/A3+CYnQLqVaGmhmtCM/HLpI/CYKs85jgNH0onn989Drzr5l0Lo
zS15Gt/GPvCgfyvwZ6kWFRkry1isH3WpUkvnGiWVDS1UFb9cw6z1T29yZqCTAAzy
KtrDny6o5ljyMUXKWu7D3mpZeXzMdO2la6Ytjr9bnkVKYSGDU+mleipz60X/5XEc
GcRNPpd9JeObAza3e5ebVLJyav9Tiz/pIInZKYnOltX946x2U8GGpIEoRFIJEbB3
lIyENGUWErA+DMZ/26nQMQ0g1gemlhsDK2NZLm7D5BPwHF06YKWgvtpEFYWmK1rp
ctMNE9YzAgMBAAECggEBAKaAmHGOKLNCb9Db1amuitPNw+HnvMmmmCQococ4SsHO
rGZnezwB7sGGE69P0rmQsde7zFGnVqF2ZuO4psWieLF7IHjILvzBEfPy3nljTqt4
3iGmwsg6iYNorbR8XKDXZUh5UKHPFj1PH0YPd3jsU6fDp7LQyLs6TkMqHIZ+/lxB
fsU2IDg9TjyeXDHrtjhAEhEkj9ehWYrgNfZtFTDSv6Bwu3fbSvUaMwJCJsxi11n3
s15UK+TI7rOh65+cCFlAAF5Xa+z4KLkhMQuUSgwNnoe1kK3JA2ATzqdvCHU/WLu+
o2ZJvGG7lmjWHFkGhafIRbf0zSPHg+j7qWPOcTCYHekCgYEA25qDi9z2LlLTRt+U
KfdsRZasHpncK16o15NBYrU9Va9BJlTaLWnOOqikYpqiM2OugUiUoy4mSSep4By4
nr/mqmHfj0Q9qQ3u0gw6YVoEI8ULNM/abYyhn4ov3UhBe3pMsOdkhXqj9qzB7UL3
j8M90WgRwBbdImAHHLf/M6dIjQcCgYEA2PIHmOEGa+x6FGYTudwLthfC2hm3/RWM
P8+EclnSAZ1XlBZK53ca/QH28dYcAT8fTp4RkKCpZNf6rWN/ulImncAEJnOCd8eE
dykFyMnreIKNYY93hYSMSbJ6pjhPVEU6YtgEGeZP/8U+GNTIfmnTD2NpoTkWqo0P
bbpiDczjDnUCgYBmc6SxaKnVnMCCzSYDmjICGTQ9poxoE2Z0BHg5w9JUmkmrx2Ru
UXFsPmdKtVe83+F24VSu+IXWFVIUg3HCZkcH8FdrMGwP5bcoeZn29xb9VR1QSzRd
bYGtu7tu4hnisID8+0cTWs8J8zkaJub2RCEgBAxb8I7ETcajqFfAUmfvmwKBgESt
oiAQpKLH0wHgKsB826xCq2m2GJvjFWoh/LDipGvkbpQv1nieKQoNdCqs+GKgo/2U
ZsUdR2LoSLBZPlcyqIzp+6ZcjOH0ZIgAkZc17PhShAVtkI3RH0Q5X0B9tQddfxVJ
g0rbsVmsDHN58Rqrz6ggdZEXbIiDbW30QhRSV1L9AoGBAKUuj3NUd2595U2eZQyP
IUmTSUrS4sK8zBdGGkSDfDZlyUHf2drz6h6650YVY78h0GHIivJj39PoSFGgD1Oa
ec0LF6hFiPDStNHtZHbShPxlIQSyOjm938EBmhAbSkJDzbDadVbBJlmVBY8a08ep
mvCcYE/i1K/t6tO/lZ6NJi82
-----END PRIVATE KEY-----

View File

@ -24,7 +24,7 @@
"session-timeout": 60,
"system": {
"addr": "127.0.0.1:18005",
"domain": "http://49.232.45.133:18005",
"domain": "https://test-pet-house.ifish7.com",
"db-type": "mysql",
"level": "debug",
"time-format": "2006-01-02 15:04:05",

View File

@ -3,5 +3,10 @@
"secret": "a29358be9ca3e34fa23d23994f5a386a",
"token": "",
"aesKey": "",
"msgDataFormat": ""
"msgDataFormat": "",
"mchId": "1682637612",
"mchCertificateSerialNumber": "7DA2108120E4C418537BCF3C061AAB109CCF88A9",
"mchAPIv3Key": "chonghujiapanlei1234567891234567",
"privateKeyPath": "F:\\work\\go\\pet-house\\business\\config\\apiclient_key.pem",
"wechatCert": "`-----BEGIN CERTIFICATE-----\nMIIEKzCCAxOgAwIBAgIUfaIQgSDkxBhTe888BhqrEJzPiKkwDQYJKoZIhvcNAQEL\nBQAwXjELMAkGA1UEBhMCQ04xEzARBgNVBAoTClRlbnBheS5jb20xHTAbBgNVBAsT\nFFRlbnBheS5jb20gQ0EgQ2VudGVyMRswGQYDVQQDExJUZW5wYXkuY29tIFJvb3Qg\nQ0EwHhcNMjQwOTEwMDc0NDUzWhcNMjkwOTA5MDc0NDUzWjCBhDETMBEGA1UEAwwK\nMTY4MjYzNzYxMjEbMBkGA1UECgwS5b6u5L+h5ZWG5oi357O757ufMTAwLgYDVQQL\nDCflroHms6LlrqDmiqTlrrblrqDnianmnI3liqHmnInpmZDlhazlj7gxCzAJBgNV\nBAYTAkNOMREwDwYDVQQHDAhTaGVuWmhlbjCCASIwDQYJKoZIhvcNAQEBBQADggEP\nADCCAQoCggEBALoZ/ZK7BdW1DKCzsqQnS9ElkWhv8Df4JidAupVoaaGa0Iz8cukj\n8JgqzzmOA0fSief3z0OvOvmXQujNLXka38Y+8KB/K/BnqRYVGSvLWKwfdalSS+ca\nJZUNLVQVv1zDrPVPb3JmoJMADPIq2sOfLqjmWPIxRcpa7sPeall5fMx07aVrpi2O\nv1ueRUphIYNT6aV6KnPrRf/lcRwZxE0+l30l45sDNrd7l5tUsnJq/1OLP+kgidkp\nic6W1f3jrHZTwYakgShEUgkRsHeUjIQ0ZRYSsD4Mxn/bqdAxDSDWB6aWGwMrY1ku\nbsPkE/AcXTpgpaC+2kQVhaYrWuly0w0T1jMCAwEAAaOBuTCBtjAJBgNVHRMEAjAA\nMAsGA1UdDwQEAwID+DCBmwYDVR0fBIGTMIGQMIGNoIGKoIGHhoGEaHR0cDovL2V2\nY2EuaXRydXMuY29tLmNuL3B1YmxpYy9pdHJ1c2NybD9DQT0xQkQ0MjIwRTUwREJD\nMDRCMDZBRDM5NzU0OTg0NkMwMUMzRThFQkQyJnNnPUhBQ0M0NzFCNjU0MjJFMTJC\nMjdBOUQzM0E4N0FEMUNERjU5MjZFMTQwMzcxMA0GCSqGSIb3DQEBCwUAA4IBAQC7\nZgux40pvNohZx721rygjo0yUbx54docNS79Eh5J9ukSKMf0cTsORlAnrsCbSYnIo\nMiqdPqccRYJUefUUuhOrKtuzaka4T+VSiaDTnZ07kB3I8xlvZtW32jHOstVPrJsB\nfEg53sl5sfWHY+OfuEhwOkoH3v/Fs4nH4hQxjO8RW9tNXqLvTrl1JeEwV4bMZxCA\nwCvoMPqn19WBFsaFb0kXF46oGeH5kId6oon0RCi+vXb8nSZ4oPXIJwxi9u/uy+wD\nrVlHohjCK+bRbxGgaIcX5uMPK/M73mzuuLFCbIWN4CLz9yyZGKxNJBq4YuGe+jWa\ngh1GheVuvTdcJ4ZGDhQT\n-----END CERTIFICATE-----`"
}

View File

@ -6,9 +6,10 @@ require (
github.com/bwmarrin/snowflake v0.3.0
github.com/dgb8901/go-wechat-miniapp-sdk v1.0.1-release
github.com/kataras/iris/v12 v12.2.10
github.com/kellydunn/golang-geo v0.7.0
github.com/spf13/viper v1.18.2
github.com/wechatpay-apiv3/wechatpay-go v0.2.20
go.uber.org/zap v1.27.0
golang.org/x/net v0.21.0
gorm.io/gorm v1.25.8
pet-house.com/core v0.0.0
)
@ -24,7 +25,6 @@ require (
github.com/aymerick/douceur v0.2.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/flosch/pongo2/v4 v4.0.2 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
@ -51,11 +51,9 @@ require (
github.com/kataras/sitemap v0.0.6 // indirect
github.com/kataras/tunnel v0.0.4 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/kylelemons/go-gypsy v1.0.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible // indirect
github.com/lestrrat-go/strftime v1.0.6 // indirect
github.com/lib/pq v1.3.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailgun/raymond/v2 v2.0.48 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
@ -83,11 +81,9 @@ require (
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yosssi/ace v0.0.5 // indirect
github.com/ziutek/mymysql v1.5.4 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect

View File

@ -12,6 +12,8 @@ github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8L
github.com/OwnLocal/goes v1.0.0/go.mod h1:8rIFjBGTue3lCU0wplczcUgt9Gxgrkkrw7etMIcn8TM=
github.com/Shopify/goreferrer v0.0.0-20220729165902-8cddb4f5de06 h1:KkH3I3sJuOLP3TjA/dfr4NAY8bghDwnXiU7cTKxQqo0=
github.com/Shopify/goreferrer v0.0.0-20220729165902-8cddb4f5de06/go.mod h1:7erjKLwalezA0k99cWs5L11HWOAPNjdUZ6RxH1BXbbM=
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
@ -47,8 +49,6 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y=
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
@ -125,8 +125,6 @@ github.com/kataras/sitemap v0.0.6 h1:w71CRMMKYMJh6LR2wTgnk5hSgjVNB9KL60n5e2KHvLY
github.com/kataras/sitemap v0.0.6/go.mod h1:dW4dOCNs896OR1HmG+dMLdT7JjDk7mYBzoIRwuj5jA4=
github.com/kataras/tunnel v0.0.4 h1:sCAqWuJV7nPzGrlb0os3j49lk2JhILT0rID38NHNLpA=
github.com/kataras/tunnel v0.0.4/go.mod h1:9FkU4LaeifdMWqZu7o20ojmW4B7hdhv2CMLwfnHGpYw=
github.com/kellydunn/golang-geo v0.7.0 h1:A5j0/BvNgGwY6Yb6inXQxzYwlPHc6WVZR+MrarZYNNg=
github.com/kellydunn/golang-geo v0.7.0/go.mod h1:YYlQPJ+DPEzrHx8kT3oPHC/NjyvCCXE+IuKGKdrjrcU=
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
@ -135,8 +133,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/go-gypsy v1.0.0 h1:7/wQ7A3UL1bnqRMnZ6T8cwCOArfZCxFmb1iTxaOOo1s=
github.com/kylelemons/go-gypsy v1.0.0/go.mod h1:chkXM0zjdpXOiqkCW1XcCHDfjfk14PH2KKkQWxfJUcU=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8=
@ -146,8 +142,6 @@ github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECae
github.com/lestrrat-go/strftime v1.0.6 h1:CFGsDEt1pOpFNU+TJB0nhz9jl+K0hZSLE205AhTIGQQ=
github.com/lestrrat-go/strftime v1.0.6/go.mod h1:f7jQKgV5nnJpYgdEasS+/y7EsTb8ykN2z68n3TtcTaw=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU=
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mailgun/raymond/v2 v2.0.48 h1:5dmlB680ZkFG2RN/0lvTAghrSxIESeu9/2aeDqACtjw=
@ -219,6 +213,7 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
@ -237,6 +232,8 @@ github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IU
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/wechatpay-apiv3/wechatpay-go v0.2.20 h1:gS8oFn1bHGnyapR2Zb4aqTV6l4kJWgbtqjCq6k1L9DQ=
github.com/wechatpay-apiv3/wechatpay-go v0.2.20/go.mod h1:A254AUBVB6R+EqQFo3yTgeh7HtyqRRtN2w9hQSOrd4Q=
github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
@ -253,8 +250,6 @@ github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FB
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M=
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=

View File

@ -8,18 +8,19 @@ import "time"
// User 用户
type User struct {
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //用户ID
NickName string `json:"nickName"` //昵称
HeadImgUrl string `json:"headImgUrl"` //用户头像URL
Amount int `json:"amount"` //用户余额
OpenId string `gorm:"index;unique;not null" json:"openId"` //三方openid
UnionId string `gorm:"index;unique;not null" json:"unionId"` //三方unionid
UserType int `json:"userType"` //用户类型 0微信 1手机号
Mobile string `json:"mobile"` //手机号
Role int `json:"role"` //用户角色 0普通用户 1护理人员
Discount int `json:"discount"` //折扣
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP;not null" json:"createTime"` //创建时间
Status int `json:"status"` //信息状态
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //用户ID
NickName string `json:"nickName"` //昵称
HeadImgUrl string `json:"headImgUrl"` //用户头像URL
Amount int `json:"amount"` //用户余额
OpenId string `gorm:"index;unique;not null" json:"openId"` //三方openid
UnionId string `gorm:"index;unique;not null" json:"unionId"` //三方unionid
UserType int `json:"userType"` //用户类型 0微信 1手机号
Mobile string `json:"mobile"` //手机号
Role int `json:"role"` //用户角色 0普通用户 1护理人员
Discount int `json:"discount"` //折扣
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP;not null" json:"createTime"` //创建时间
Status int `json:"status"` //信息状态
InviteUserId int64 `json:"inviteUserId"` //邀请用户
}
// Pet 宠物信息
@ -83,17 +84,18 @@ type UserServiceAddr struct {
// Goods 商品信息
type Goods struct {
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //商品ID
Name string `gorm:"not null" json:"name"` //商品名称
GoodsType int `gorm:"not null" json:"goodsType"` //商品类型 1基础服务 2附加产品 3附加服务
Time string `json:"time"` //时间
Price int `gorm:"not null" json:"price"` //价格
ParentId int64 `gorm:"not null" json:"parentId"` //商品父ID
BuyMany int `gorm:"not null" json:"buyMany"` //同类型是否可购买多个 0否 1是
GoodsDetail string `gorm:"not null" json:"goodsDetail"` //商品详情 图片URL
GoodsIcon string `json:"goodsIcon"` //iconUrl
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间
Status int `json:"status"` //信息状态
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //商品ID
Name string `gorm:"not null" json:"name"` //商品名称
GoodsType int `gorm:"not null" json:"goodsType"` //商品类型 1基础服务 2附加产品 3附加服务
Time string `json:"time"` //时间
Price int `gorm:"not null" json:"price"` //价格
ParentId int64 `gorm:"not null" json:"parentId"` //商品父ID
BuyMany int `gorm:"not null" json:"buyMany"` //同类型是否可购买多个 0否 1是
GoodsDetail string `gorm:"not null" json:"goodsDetail"` //商品详情 图片URL
GoodsIcon string `json:"goodsIcon"` //iconUrl
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间
Status int `json:"status"` //信息状态
GoodsSubType int `gorm:"not null" json:"goodsSubType"` //商品子类型
}
// PetGoods 宠物商品
@ -115,7 +117,7 @@ type SystemConfig struct {
Id int `gorm:"primaryKey;autoIncrement" json:"id"` //id
Name string `json:"name"` //名称
Content string `json:"content"` //内容
ConfigType string `json:"configType"` //类型 0banner 1关于我们 2客服电话
ConfigType string `json:"configType"` //类型 0banner 1关于我们 2客服电话 3分享信息
ContentType int `json:"contentType"` //1文本 2链接
Sort int `json:"sort"` //排序位
JumpType int `gorm:"default:0" json:"JumpType"` //跳转类型 0无法跳转 1跳转外部 2跳转内部
@ -141,6 +143,8 @@ type OrderMain struct {
PayDiscount int `gorm:"default:0" json:"payDiscount"` //支付折扣
PayType int `json:"payType"` //支付方式 1线下 2线上 3会员余额
Status int `json:"status1"` //信息状态
PayOrderId string `json:"payOrderId"` //支付订单号
MarkStatus int `gorm:"default:0" json:"markStatus"` //评价状态
}
// OrderSub 子订单
@ -152,24 +156,31 @@ type OrderSub struct {
PetId int64 `gorm:"index" json:"petId"` //宠物ID
PayType int `gorm:"not null" json:"payType"` //支付方式 1线下 2线上 3会员余额
Discount int `json:"discount"` //折扣
TotalAmount int `gorm:"not null" json:"totalAmount"` //总金额
TotalAmount int `gorm:"not null" json:"totalAmount"` //总金额 - 原价
ProjectionServiceTime int `json:"projectionServiceTime"` //服务预估时长
PayStatus int `gorm:"default:0" json:"payStatus"` //支付状态 0未支付 1已支付
PayAmount int `json:"payAmount"` //实际支付金额
PayAmount int `json:"payAmount"` //实际支付金额 - 折扣金额
GoodsDiscountAmount int `json:"-"` //商品折扣金额
GoodsOriginAmount int `json:"-"` //商品原价 除去折扣价的金额
PayTime time.Time `gorm:"type:timestamp;" json:"payTime"` //支付时间
PayRemark string `json:"payRemark"` //支付备注
PetInfo string `json:"petInfo"` //宠物快照信息
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:"-"` //更新时间
Status int `json:"status1"`
Cid int `gorm:"not null" json:"cid"` //优惠券ID
Ucid int `gorm:"not null" json:"ucid"` //优惠券ID - user
}
// OrderDetail 订单明细
type OrderDetail struct {
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
SubOrderId string `gorm:"index;not null" json:"subOrderId"` //子订单ID
GoodsId int64 `gorm:"index;not null" json:"goodsId"` //商品ID
Amount int `gorm:"not null" json:"amount"` //价格
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
Cid int `json:"cid"` //子订单ID
Discount int `json:"discount"` //折扣
SubOrderId string `gorm:"index;not null" json:"subOrderId"` //子订单ID
GoodsId int64 `gorm:"index;not null" json:"goodsId"` //商品ID
Amount int `gorm:"not null" json:"amount"` //价格
DiscountAmount int `json:"-"` //折扣价格
}
// OrderServiceRecord 订单服务记录
@ -208,6 +219,7 @@ type ServiceCar struct {
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间
UpdateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP" json:"-"` //更新时间
ServiceAddr ServiceAddr `gorm:"-" json:"serviceAddr"` //当前服务区域
CarStatus int `gorm:"not null"` //车辆状态 1在线 2下线
}
// CarOrder 车辆订单
@ -243,11 +255,13 @@ type ServiceUserMark struct {
type ServiceUserMarkRecord struct {
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
Uid int64 `gorm:"index;not null" json:"uid"` //评价用户
OrderId string `gorm:"not null" json:"orderId"` //订单ID
ServiceStar int `gorm:"default:5" json:"serviceStar"` //服务星级
ServiceLabels string `json:"serviceLabels"` //服务标签
MarkContext string `json:"markContext"` //评价内容
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间
UpdateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP" json:"-"` //更新时间
Status int `json:"status"` //信息状态
}
// ReserveTimeFilter 服务过滤时间
@ -263,3 +277,75 @@ type AddrServiceTime struct {
ServiceAddrId int64 `gorm:"not null" json:"ServiceAddrId"` //服务地址ID
Times string `gorm:"not null" json:"times"` //时间列表
}
// Coupons 优惠券
type Coupons struct {
Id int `gorm:"primaryKey;autoIncrement" json:"id"` //id
Name string `gorm:"not null" json:"name"`
GoodsSubType int `gorm:"not null" json:"goodsSubType"` //商品子类型 1:洗护 2:美容 3:SPA 4:驱虫 5:洁牙
Discount int `gorm:"not null" json:"discount"` //折扣
Source string `gorm:"not null" json:"source"` //来源
PeriodType int `gorm:"not null" json:"periodType"` //使用类型 0、无 1、星期 2、截至时间 3、指定日期可用
Period string `json:"-"` //使用信息 具体时间 星期类型1,2,3截止日期2024-09-01 23:59:59指定日期2024-08-10
PeriodInfo []string `gorm:"-" json:"periodInfo"`
ExpireTime int64 `json:"expireTime"` //优惠券过期时间
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:"-"` //更新时间
Status int `gorm:"default:1" json:"-"` //数据状态
SendStatus int `gorm:"not null" json:"-"` //下发类型 1领取 2新用户注册赠送 3邀请新用户赠送
ReceiverStatus int `gorm:"-" json:"receiverStatus"` //领取状态 0未领取 1已领取
DrawDay int `gorm:"not null" json:"drawDay"` //优惠券领取后过期天数
LastExpireTime string `gorm:"-" json:"lastExpireTime"` //优惠券最后过期时间
}
// UserCoupons 用户优惠券
type UserCoupons struct {
Id int `gorm:"primaryKey;autoIncrement" json:"id"` //id
Uid int64 `gorm:"not null" json:"uid"` //用户id
Cid int `gorm:"not null" json:"cid"` //优惠券ID
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:"-"` //更新时间
Status int `gorm:"default:1" json:"-"`
CouponsStatus int `gorm:"default:1" json:"status"` //状态 1未使用 2已使用 3已过期
LastExpireTime time.Time `gorm:"not null" json:"lastExpireTime"` //优惠券最后过期时间
}
// RechargeInfo 充值挡位信息
type RechargeInfo struct {
Id int `gorm:"primaryKey;autoIncrement" json:"id"` //id
Name string `gorm:"not null" json:"name"` //挡位名称
Desc string `json:"desc"` //挡位描述
Price string `gorm:"not null" json:"price"` //价格
RechargePrice string `gorm:"not null;default:0" json:"rechargePrice"` //实际充值
Give string `gorm:"default:无" json:"give"` //赠送
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间
UpdateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP" json:"-"` //更新时间
Status int `gorm:"default:1" json:"-" json:"-"` //状态
Type int `gorm:"default:1" json:"type" json:"type"` //类型 1充值挡位 2押金
}
// PayOrder 支付订单
type PayOrder struct {
Id int `gorm:"primaryKey;autoIncrement"` //id
Uid int64 `gorm:"not null;default:0" json:"uid"` //uid
OrderId string `gorm:"not null"` //订单ID
OrderName string `gorm:"not null"` //订单名称
OrderPrice string `gorm:"not null"` //订单金额
OrderStatus int `gorm:"not null;default:0"` //订单状态 0未支付 1已支付 2已退款
PayId string //三方交易号
RechargeId int `gorm:"not null;default:0"` //充值ID
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:"-"` //更新时间
Status int `gorm:"default:1" json:"-"` //状态
}
// ServiceCarLocation 服务车辆定位
type ServiceCarLocation struct {
Id int `gorm:"primaryKey;autoIncrement"` //id
Uid int64 `gorm:"not null" json:"uid"` //用户ID
CarId int `gorm:"not null" json:"carId"` //车辆ID
Longitude string `json:"longitude"` //经度
Latitude string `json:"latitude"` //纬度
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间
Status int `gorm:"default:1" json:"-"` //状态
}

125
business/utils/Test1.go Normal file
View File

@ -0,0 +1,125 @@
package utils
/*import (
"encoding/json"
"fmt"
"time"
)
type TimeObject1 struct {
Time string `json:"time"` // 时间格式 "HH:MM"
Y bool `json:"y"` // Y=true: 可预约 (空闲)Y=false: 不可预约 (已占用)
}
type OrderServiceTimeResponse struct {
Times map[string][]TimeObject1 `json:"times"` // 按日期分组
}
func generateTimeSlots(startTime time.Time, maxDays int) []string {
var timeSlots []string
// 生成当前时间起未来 maxDays 天9点到22点每小时整点的时间段
for d := 0; d < maxDays; d++ {
// 计算当前天的9点到22点时间段
day := startTime.Add(time.Duration(d) * 24 * time.Hour) // 当前日期
for h := 9; h <= 22; h++ {
timeSlots = append(timeSlots, fmt.Sprintf("%04d-%02d-%02d %02d:00:00", day.Year(), day.Month(), day.Day(), h))
}
}
return timeSlots
}
func processOrders(orders []Order, maxCars int, maxDays int) OrderServiceTimeResponse {
// 存储每个时间段的车辆占用情况
response := OrderServiceTimeResponse{
Times: make(map[string][]TimeObject1),
}
// 用来记录每个时间段的车占用情况
occupiedSlots := make(map[string]int) // key: 时间段, value: 占用的车数
// 遍历每个订单
for _, order := range orders {
startTime, err := time.Parse("2006-01-02 15:04", order.ServiceTime)
if err != nil {
fmt.Println("Error parsing time:", err)
continue
}
// 计算每个时间段的结束时间
endTime := startTime.Add(time.Duration(order.ProjectionServiceTime) * time.Minute)
// 处理服务时间占用
for t := startTime; t.Before(endTime); t = t.Add(time.Hour) {
// 格式化每个小时的整点
timeSlot := fmt.Sprintf("%04d-%02d-%02d %02d:00:00", t.Year(), t.Month(), t.Day(), t.Hour())
// 如果这个时间段已经被占用了,则增加占用车数
occupiedSlots[timeSlot]++
}
}
// 计算时间段的范围生成当前时间到未来7天内的每小时时间段
startTime := time.Now()
allTimeSlots := generateTimeSlots(startTime, maxDays)
// 填充每个时间段的占用情况
for _, slot := range allTimeSlots {
isOccupied := false
// 格式化时间为 "HH:MM"
timeOnly := slot[11:16]
// 当前时间段的占用车数
occupiedCars := occupiedSlots[slot]
// 如果当前时间段的车占用数大于或等于最大车数,则标记为占用
if occupiedCars >= maxCars {
isOccupied = true
}
// 提取日期作为 key
date := slot[:10]
// 根据占用情况设置 Y 的值true 表示可预约false 表示不可预约
response.Times[date] = append(response.Times[date], TimeObject1{
Time: timeOnly,
Y: !isOccupied, // true 是可预约false 是不可预约
})
}
return response
}
// 模拟的订单结构
type Order struct {
OrderID string
UID int64
ServiceTime string // 格式: "2025-02-11 09:00"
ProjectionServiceTime int64 // 服务时长,单位:分钟
}
func main() {
// 假设我们从数据库获取的订单数据
orders := []Order{
{"1886746333474197504", 10012, "2025-02-11 10:00", 600},
{"1887103577298571264", 11089, "2025-02-12 19:00", 125},
{"1887680412080148480", 10575, "2025-02-11 18:00", 120},
{"1888482012872839168", 10273, "2025-02-14 19:00", 65},
{"1888834477728206848", 10012, "2025-02-13 17:00", 180},
{"1888932349274492928", 10012, "2025-02-15 10:00", 60},
{"1889211058120298496", 10462, "2025-02-12 10:00", 120},
{"1889211312915877888", 10462, "2025-02-12 11:00", 120},
{"1889211441857171456", 10462, "2025-02-12 12:00", 120},
{"1889211684388605952", 10462, "2025-02-12 13:00", 120},
{"1889214115952463872", 10012, "2025-02-12 14:00", 120},
}
response := processOrders(orders, 2, 7) // 假设有2台车查询近7天的预约情况
jsonData, err := json.MarshalIndent(response, "", " ")
if err != nil {
fmt.Println("Error marshaling to JSON:", err)
return
}
fmt.Println(string(jsonData))
}
*/

View File

@ -2,6 +2,7 @@ package utils
import (
"encoding/json"
"fmt"
"github.com/kataras/iris/v12/context"
"io"
"math"
@ -21,7 +22,7 @@ type TimeObject struct {
Y bool `json:"y"`
}
func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFilter, orderTimeMap map[string]string, carNum int, orderNumMap map[string]int, carServiceNum int, times []string) map[string][]TimeObject {
func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFilter, orderTimeMap map[string]string, carNum int, orderNumMap map[string]int, carServiceNum int, times []string, orderTimeCount map[string]int, projectionTime map[string]int) map[string][]TimeObject {
// 获取当前时间
currentTime := time.Now()
// 计算半小时后的时间
@ -51,23 +52,27 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil
serviceDaysMap[dayTime] = dayTime
}
for nextHour.Before(oneWeekLater) {
key := nextHour.Format("2006-01-02")
key1 := nextHour.Format("2006-01-02 15:04")
if nextHour.Hour() < workStart || nextHour.Hour() > workEnd {
nextHour = nextHour.Add(time.Duration(minute) * time.Minute)
continue
}
if _, ok := serviceDaysMap[key1]; len(serviceDaysMap) > 0 && !ok {
//不存在服务配置中返回false
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
Time: nextHour.Format("15:04"),
Y: false,
})
nextHour = nextHour.Add(time.Duration(minute) * time.Minute)
continue
}
//且不存在过滤时间中
_, existsDay := reserveMap[nextHour.Format("2006-01-02")]
_, existsHour := reserveMap[nextHour.Format("15")]
_, existOrderTime := orderTimeMap[nextHour.Format("2006-01-02 15:04")]
orderNum, existOrderNum := orderNumMap[nextHour.Format("2006-01-02 15:04")]
if (nextHour.Hour() >= workStart && nextHour.Hour() < workEnd) && (!existsDay && !existsHour) && !existOrderTime {
key := nextHour.Format("2006-01-02")
key1 := nextHour.Format("2006-01-02 15:04")
if _, ok := serviceDaysMap[key1]; len(serviceDaysMap) > 0 && !ok {
//不存在服务配置中返回false
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
Time: nextHour.Format("15:04"),
Y: false,
})
nextHour = nextHour.Add(time.Duration(minute) * time.Minute)
continue
}
if (!existsDay && !existsHour) && !existOrderTime {
if _, ok := dayHoursMap[key]; ok {
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
Time: nextHour.Format("15:04"),
@ -81,7 +86,8 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil
}
} else {
key := nextHour.Format("2006-01-02")
//当前订单数小于车辆数 可接单
key1 := nextHour.Format("2006-01-02 15:04")
//当前订单数小于车辆数 可接单 时间范围可能会超出到11点
if existOrderNum && orderNum < carNum*carServiceNum {
if _, ok := dayHoursMap[key]; ok {
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
@ -95,17 +101,29 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil
}}
}
} else if nextHour.Hour() >= workStart && nextHour.Hour() < workEnd {
if _, ok := dayHoursMap[key]; ok {
//查看当前时间对应的订单数量
orderCount := orderTimeCount[key1]
time := projectionTime[key1]
//预约时间对应的订单数<车辆数量 当前时间可以预约 且是1笔订单
if orderCount < carNum*carServiceNum && time > 60 {
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
Time: nextHour.Format("15:04"),
Y: false,
Y: true,
})
} else {
dayHoursMap[key] = []TimeObject{{
Time: nextHour.Format("15:04"),
Y: false,
}}
if _, ok := dayHoursMap[key]; ok {
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
Time: nextHour.Format("15:04"),
Y: false,
})
} else {
dayHoursMap[key] = []TimeObject{{
Time: nextHour.Format("15:04"),
Y: false,
}}
}
}
}
}
@ -117,3 +135,178 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil
func RoundToOneDecimalPlace(value float64) float64 {
return math.Round(value*10) / 10
}
func generateTimeSlots(startTime time.Time, maxDays int) []string {
var timeSlots []string
// 生成当前时间起未来 maxDays 天9点到22点每小时整点的时间段
for d := 0; d < maxDays; d++ {
// 计算当前天的9点到22点时间段
day := startTime.Add(time.Duration(d) * 24 * time.Hour) // 当前日期
for h := 10; h <= 19; h++ {
timeSlots = append(timeSlots, fmt.Sprintf("%04d-%02d-%02d %02d:00:00", day.Year(), day.Month(), day.Day(), h))
}
}
return timeSlots
}
type OrderServiceTimeResponse struct {
Times map[string][]TimeObject `json:"times"`
}
type OrderTemp struct {
OrderId string
Uid int64
ServiceTime string // 格式: "2025-02-11 09:00"
ProjectionServiceTime int64 // 服务时长,单位:分钟
}
func ProcessOrders(orders []OrderTemp, maxCars int, maxDays int) OrderServiceTimeResponse {
// 存储每个时间段的车辆占用情况
response := OrderServiceTimeResponse{
Times: make(map[string][]TimeObject),
}
// 用来记录每个用户的占用时间
userOccupiedTime := make(map[int64]map[string]bool)
// 遍历每个订单
for _, order := range orders {
startTime, err := time.Parse("2006-01-02 15:04", order.ServiceTime)
if err != nil {
fmt.Println("Error parsing time:", err)
continue
}
// 计算每个时间段的结束时间
endTime := startTime.Add(time.Duration(order.ProjectionServiceTime) * time.Minute)
// 记录用户的占用时间
if userOccupiedTime[order.Uid] == nil {
userOccupiedTime[order.Uid] = make(map[string]bool)
}
// 处理服务时间占用
for t := startTime; t.Before(endTime); t = t.Add(time.Hour) {
// 格式化每个小时的整点
timeSlot := fmt.Sprintf("%04d-%02d-%02d %02d:00:00", t.Year(), t.Month(), t.Day(), t.Hour())
// 用户在该时间段占用时间,标记为已占用
userOccupiedTime[order.Uid][timeSlot] = true
}
}
// 计算时间段的范围,生成当前时间到未来 maxDays 天内的每小时时间段
startTime := time.Now()
allTimeSlots := generateTimeSlots(startTime, maxDays)
// 填充每个时间段的占用情况
for _, slot := range allTimeSlots {
isOccupied := false
// 格式化时间为 "HH:MM"
timeOnly := slot[11:16]
// 计算该时间段的总占用情况
occupiedCars := 0
for _, userTimes := range userOccupiedTime {
if userTimes[slot] {
occupiedCars++
}
}
// 如果当前时间段的车占用数大于或等于最大车数,则标记为占用
if occupiedCars >= maxCars {
isOccupied = true
}
// 获取当前时间
currentTime := time.Now()
// 指定时区,例如 "Asia/Shanghai"
location, err := time.LoadLocation("Asia/Shanghai")
if err != nil {
fmt.Println("Error loading location:", err)
continue
}
// 如果当前时间 >= 当前时间段的开始时间,则直接标记为占用
slotTime, err := time.ParseInLocation("2006-01-02 15:04:05", slot, location)
if err != nil {
fmt.Println("Error parsing time slot:", err)
continue
}
// 如果当前时间大于等于这个时间段的开始时间,则表示该时间段已经占用
if currentTime.UnixMilli() >= slotTime.UnixMilli() {
isOccupied = true
}
// 提取日期作为 key
date := slot[:10]
// 根据占用情况设置 Y 的值true 表示可预约false 表示不可预约
response.Times[date] = append(response.Times[date], TimeObject{
Time: timeOnly,
Y: !isOccupied, // true 是可预约false 是不可预约
})
}
return response
}
func CheckAvailability(orders []OrderTemp, maxCars int, checkTime string, durationMinutes int) bool {
// 解析传入的时间字符串
startTime, err := time.Parse("2006-01-02 15:04", checkTime)
if err != nil {
fmt.Println("Error parsing check time:", err)
return true // 出现解析错误时直接返回不可预约
}
// 计算结束时间
endTime := startTime.Add(time.Duration(durationMinutes) * time.Minute)
// 用来记录每个用户的占用时间
userOccupiedTime := make(map[int64]map[string]bool)
// 遍历每个订单
for _, order := range orders {
orderStartTime, err := time.Parse("2006-01-02 15:04", order.ServiceTime)
if err != nil {
fmt.Println("Error parsing order time:", err)
continue
}
// 计算每个订单的结束时间
orderEndTime := orderStartTime.Add(time.Duration(order.ProjectionServiceTime) * time.Minute)
// 记录用户的占用时间
if userOccupiedTime[order.Uid] == nil {
userOccupiedTime[order.Uid] = make(map[string]bool)
}
// 处理服务时间占用
for t := orderStartTime; t.Before(orderEndTime); t = t.Add(time.Hour) {
// 格式化每个小时的整点
timeSlot := fmt.Sprintf("%04d-%02d-%02d %02d:00:00", t.Year(), t.Month(), t.Day(), t.Hour())
// 用户在该时间段占用时间,标记为已占用
userOccupiedTime[order.Uid][timeSlot] = true
}
}
// 检查指定时间段是否有足够的空闲时间
for t := startTime; t.Before(endTime); t = t.Add(time.Hour) {
timeSlot := fmt.Sprintf("%04d-%02d-%02d %02d:00:00", t.Year(), t.Month(), t.Day(), t.Hour())
// 计算该时间段的总占用情况
occupiedCars := 0
for _, userTimes := range userOccupiedTime {
if userTimes[timeSlot] {
occupiedCars++
}
}
// 如果当前时间段的车占用数大于或等于最大车数,则表示不可预约
if occupiedCars >= maxCars {
return true // 如果不可预约返回true
}
}
// 如果没有占用冲突,则可以预约
return false // 如果可以预约返回false
}

View File

@ -2,10 +2,12 @@ package utils
import (
"fmt"
utils2 "github.com/wechatpay-apiv3/wechatpay-go/utils"
"math"
"pet-house.com/business/models"
"strconv"
"testing"
"time"
)
func TestGetStrDays(t *testing.T) {
@ -27,6 +29,10 @@ func TestCalc(t *testing.T) {
i := math.Round(386 * (float64(85) / 100))
fmt.Println(i)
}
func TestCalc7(t *testing.T) {
float, _ := strconv.ParseFloat("0.01", 64)
fmt.Println(int64(float * 100.0))
}
func TestCalc1(t *testing.T) {
i := float64(85) / 100
fmt.Println(i)
@ -50,7 +56,53 @@ func TestCalc5(t *testing.T) {
float := strconv.FormatFloat(float64(a/10.0), 'f', 1, 64)
fmt.Printf(float)
}
func TestCalc8(t *testing.T) {
var a = `-----BEGIN CERTIFICATE-----
MIIDVzCCAj+gAwIBAgIJANfOWdH1ItcBMA0GCSqGSIb3DQEBCwUAMEIxCzAJBgNV
BAYTAlhYMRUwEwYDVQQHDAxEZWZhdWx0IENpdHkxHDAaBgNVBAoME0RlZmF1bHQg
Q29tcGFueSBMdGQwHhcNMjEwNDI3MDg1NTIzWhcNMzEwNDI1MDg1NTIzWjBCMQsw
CQYDVQQGEwJYWDEVMBMGA1UEBwwMRGVmYXVsdCBDaXR5MRwwGgYDVQQKDBNEZWZh
dWx0IENvbXBhbnkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
2VCTd91fnUn73Xy9DLvt/V62TVxRTEEstVdeRaZ3B3leO0pldE806mXO4RwdHXag
HQ4vGeZN0yqm++rDsGK+U3AH7kejyD2pXshNP9Cq5YwbptiLGtjcquw4HNxJQUOm
DeJf2vg6byms9RUipiq4SzbJKqJFlUpbuIPDpSpWz10PYmyCNeDGUUK65E5h2B83
4uxl1zNLYQCrkdBzb8oUxwYeP5a2DNxmjL5lsJML7DGr5znsevnoqGRwTm9fxCGf
y8wus7hwKz6clt3Whmmda7UAdb1c08hEQFVRbF14AR73xbnd8N0obCWJPCbzMCtk
aSef4FdEEgEXJiw0VAJT8wIDAQABo1AwTjAdBgNVHQ4EFgQUT1c7nd/SUO76HSoZ
umNUJv1R5PwwHwYDVR0jBBgwFoAUT1c7nd/SUO76HSoZumNUJv1R5PwwDAYDVR0T
BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAfTjxKRQMzNB/U6ZoCUS+BSNfa2Oh
0plMN6ZuzwiVVZwg1jywvv5yv04koS7Pd4i9E4gt9ZBUQXlpq+A3oOCEEHNRR6b2
kyazGRM7s0OP5X21WrbpSmKmU6K7hkfx30yYs08LVs/Q8DIhvaj1FCFeJzUCzYn/
fHMq4tsbKO0dKAeydPM/nrUZBmaYQVKMVOORGLFjFKVO7JV6Kq/R86ouhjEPgJOe
2xulNBUcjicqtZlBdEh/PWCYP2SpGVDclKm8jeo175T3EVAkdKzzmfpxtMmnMlmq
cTJOU9TxuGvNASMtjj7pYIerTx+xgZDXEVBWFW9PjJ0TV06tCRsgSHItgg==
-----END CERTIFICATE-----`
x, err := utils2.LoadCertificate(a)
fmt.Println(err)
fmt.Println(x)
}
func TestMath(t *testing.T) {
var a = int(RoundToOneDecimalPlace(float64(150)*(95/100.0)) * 10)
fmt.Println(a)
}
func TestMap(t *testing.T) {
var c1 = make(map[int]models.Coupons)
c1[1] = models.Coupons{
Id: 1,
Name: "111",
GoodsSubType: 0,
Discount: 0,
Source: "",
PeriodType: 0,
Period: "",
PeriodInfo: nil,
ExpireTime: 0,
CreateTime: time.Time{},
UpdateTime: time.Time{},
Status: 0,
}
print("12345", c1[2].Id)
}
func Test22(t *testing.T) {
fmt.Println("您还需支付" + fmt.Sprintf("%.1f", float64(1298)/10.0))
}

23
business/utils/lock.go Normal file
View File

@ -0,0 +1,23 @@
package utils
import "sync"
// KeyedMutex 提供基于键的锁定
type KeyedMutex struct {
mutexes sync.Map
}
// Lock 锁定指定键
func (km *KeyedMutex) Lock(key string) {
mu, _ := km.mutexes.LoadOrStore(key, &sync.Mutex{})
mu.(*sync.Mutex).Lock()
}
// Unlock 解锁指定键
func (km *KeyedMutex) Unlock(key string) {
mu, ok := km.mutexes.Load(key)
if ok {
mu.(*sync.Mutex).Unlock()
km.mutexes.Delete(key)
}
}

View File

@ -2,28 +2,48 @@ package utils
import (
"fmt"
"github.com/bwmarrin/snowflake"
"github.com/dgb8901/go-wechat-miniapp-sdk/config"
"github.com/dgb8901/go-wechat-miniapp-sdk/models/response"
"github.com/dgb8901/go-wechat-miniapp-sdk/service"
"github.com/spf13/viper"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
"github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
"github.com/wechatpay-apiv3/wechatpay-go/utils"
"go.uber.org/zap"
"golang.org/x/net/context"
"log"
"pet-house.com/core/g"
"pet-house.com/core/server/viper_server"
"pet-house.com/core/server/web"
"pet-house.com/core/server/zap_server"
)
var CONFIG = WxConfig{
AppId: "",
Secret: "",
Token: "",
AesKey: "",
MsgDataFormat: "",
AppId: "",
Secret: "",
Token: "",
AesKey: "",
MsgDataFormat: "",
MchId: "",
MchCertificateSerialNumber: "",
MchAPIv3Key: "",
PrivateKeyPath: "",
WechatCert: "",
}
type WxConfig struct {
AppId string `mapstructure:"appId" json:"appId" yaml:"appId"`
Secret string `mapstructure:"secret" json:"secret" yaml:"secret"`
Token string `mapstructure:"token" json:"token" yaml:"token"`
AesKey string `mapstructure:"aesKey" json:"aesKey" yaml:"aesKey"`
MsgDataFormat string `mapstructure:"msgDataFormat" json:"msgDataFormat" yaml:"msgDataFormat"`
AppId string `mapstructure:"appId" json:"appId" yaml:"appId"`
Secret string `mapstructure:"secret" json:"secret" yaml:"secret"`
Token string `mapstructure:"token" json:"token" yaml:"token"`
AesKey string `mapstructure:"aesKey" json:"aesKey" yaml:"aesKey"`
MsgDataFormat string `mapstructure:"msgDataFormat" json:"msgDataFormat" yaml:"msgDataFormat"`
MchId string `mapstructure:"mchId" json:"mchId" yaml:"mchId"`
MchCertificateSerialNumber string `mapstructure:"mchCertificateSerialNumber" json:"mchCertificateSerialNumber" yaml:"mchCertificateSerialNumber"`
MchAPIv3Key string `mapstructure:"mchAPIv3Key" json:"mchAPIv3Key" yaml:"mchAPIv3Key"`
PrivateKeyPath string `mapstructure:"privateKeyPath" json:"privateKeyPath" yaml:"privateKeyPath"`
WechatCert string `mapstructure:"wechatCert" json:"wechatCert" yaml:"wechatCert"`
}
// getViperConfig get viper config
@ -49,12 +69,18 @@ func getViperConfig() viper_server.ViperConfig {
"token": "` + CONFIG.Token + `",
"aesKey": "` + CONFIG.AesKey + `",
"msgDataFormat": ` + CONFIG.MsgDataFormat + `
"mchId": ` + CONFIG.MchId + `
"mchCertificateSerialNumber": ` + CONFIG.MchCertificateSerialNumber + `
"mchAPIv3Key": ` + CONFIG.MchAPIv3Key + `
"privateKeyPath": ` + CONFIG.PrivateKeyPath + `
"wechatCert": ` + CONFIG.WechatCert + `
}`),
}
}
type WechatHelper struct {
wechatService *service.WxaService
wechatService *service.WxaService
wechatPayClient *core.Client
}
var wxHelper = &WechatHelper{}
@ -71,12 +97,36 @@ func WechatInit() {
wxaConfig := config.NewInMemory(cfg)
wxaService := service.NewService(wxaConfig)
wxHelper.wechatService = wxaService
getPayApi()
}
func getPayApi() {
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
mchPrivateKey, err := utils.LoadPrivateKeyWithPath(CONFIG.PrivateKeyPath)
if err != nil {
log.Fatal("load merchant private key error")
}
ctx := context.Background()
// 使用商户私钥等初始化 client并使它具有自动定时获取微信支付平台证书的能力
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(CONFIG.MchId, CONFIG.MchCertificateSerialNumber, mchPrivateKey, CONFIG.MchAPIv3Key),
}
client, err := core.NewClient(ctx, opts...)
if err != nil {
log.Fatalf("new wechat pay client err:%s", err)
}
wxHelper.wechatPayClient = client
}
func getWxaService() *service.WxaService {
return wxHelper.wechatService
}
func GetWxPayService() *core.Client {
return wxHelper.wechatPayClient
}
type WxUserInfo struct {
OpenId string
UnionId string
@ -89,3 +139,33 @@ func GetWxUserInfo(code string) (*response.JsCode2SessionResult, error) {
}
return info, nil
}
func WxPayRefund(payId string, payOrderId string, orderAmount int64, ctx context.Context) {
ras := refunddomestic.RefundsApiService{Client: wxHelper.wechatPayClient}
var refundNo = new(string)
reason := "取消订单"
currency := "CNY"
notifyUrl := web.CONFIG.System.Domain + "/pet-house/pay/payNotify"
amount := refunddomestic.AmountReq{
Refund: &orderAmount,
Total: &orderAmount,
Currency: &currency,
}
var NextId, _ = snowflake.NewNode(1)
*refundNo = NextId.Generate().String()
var req = refunddomestic.CreateRequest{
TransactionId: &payId,
OutTradeNo: &payOrderId,
OutRefundNo: refundNo,
Reason: &reason,
NotifyUrl: &notifyUrl,
Amount: &amount,
}
createResult, _, err := ras.Create(ctx, req)
if err != nil {
return
}
zap_server.ZAPLOG.Info("WxPayRefund", zap.Any("request", req), zap.Any("response", createResult))
}

View File

@ -21,7 +21,7 @@ type otheraccounts struct {
func TestMain(m *testing.M) {
CONFIG.DbName = "pikauser"
CONFIG.Path = "172.31.65.221:3306"
CONFIG.Ip = "172.31.65.221"
CONFIG.Password = "qC#5Lp%9AF=6BmR5Ny!6aaabbb"
CONFIG.Username = "pikauser_dev"