Compare commits

...
16 Commits
Author SHA1 Message Date
yan.y e0d302c5f5 update 2024-12-28 19:10:40 +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
23 changed files with 1484 additions and 180 deletions
+14
View File
@@ -12,12 +12,14 @@ import (
"pet-house.com/core/server/web" "pet-house.com/core/server/web"
"pet-house.com/core/server/web/web_iris" "pet-house.com/core/server/web/web_iris"
"pet-house.com/core/server/zap_server" "pet-house.com/core/server/zap_server"
"time"
) )
type LoginRequest struct { type LoginRequest struct {
Code string Code string
NickName string NickName string
HeadImgUrl string HeadImgUrl string
InviteUserId int64
} }
type LoginResponse struct { type LoginResponse struct {
@@ -81,10 +83,22 @@ func (p DefParty) login() web_iris.Party {
Mobile: "", Mobile: "",
Role: 0, Role: 0,
Status: 1, Status: 1,
InviteUserId: loginRequest.InviteUserId,
} }
err := database.Instance().Create(&newUser).Error err := database.Instance().Create(&newUser).Error
zap_server.ZAPLOG.Info("create", zap.Any("err", err)) zap_server.ZAPLOG.Info("create", zap.Any("err", err))
userInfo = newUser 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) token := genToken(userInfo.Id)
response := LoginResponse{ response := LoginResponse{
+42 -8
View File
@@ -2,13 +2,14 @@ package api
import ( import (
"encoding/json" "encoding/json"
"fmt"
"github.com/kataras/iris/v12" "github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context" "github.com/kataras/iris/v12/context"
"gorm.io/gorm/clause" "gorm.io/gorm/clause"
"io" "io"
"pet-house.com/business/models" "pet-house.com/business/models"
"pet-house.com/business/utils"
"pet-house.com/core/server/database" "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/web/web_iris"
"time" "time"
) )
@@ -70,7 +71,9 @@ type CarServiceProcessRequest struct {
} }
type CarServiceProcessResponse 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 return
} }
} }
desc := ""
payImgUrl := ""
var orderUserInfo *models.User var orderUserInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", mainOrder.Uid).Find(&orderUserInfo) database.Instance().Model(&models.User{}).Where("id = ?", mainOrder.Uid).Find(&orderUserInfo)
var processPayAmount = carServiceProcessRequest.PayAmount var processPayAmount = carServiceProcessRequest.PayAmount
var originTotalAmount = float64(subOrderInfo.TotalAmount) var originTotalAmount = float64(subOrderInfo.PayAmount) / 10.0
if processPayAmount > 0 && originTotalAmount != processPayAmount { if processPayAmount > 0 && originTotalAmount != processPayAmount {
//原价 //原价
originAmount := subOrderInfo.PayAmount originAmount := subOrderInfo.PayAmount
userOriginAmount := orderUserInfo.Amount userOriginAmount := orderUserInfo.Amount
p := int(utils.RoundToOneDecimalPlace(processPayAmount))
p1 := int(processPayAmount * 10) p1 := int(processPayAmount * 10)
mainOrder.TotalAmount = mainOrder.TotalAmount - subOrderInfo.TotalAmount + p
if mainOrder.PayTotalAmount > 0 && originTotalAmount != processPayAmount { if mainOrder.PayTotalAmount > 0 && originTotalAmount != processPayAmount {
mainOrder.PayTotalAmount = mainOrder.PayTotalAmount - originAmount + p1 mainOrder.PayTotalAmount = mainOrder.PayTotalAmount - originAmount + p1
} }
subOrderInfo.TotalAmount = p
subOrderInfo.PayAmount = p1 subOrderInfo.PayAmount = p1
if mainOrder.PayStatus == 1 { if mainOrder.PayStatus == 1 {
recordType := 2 recordType := 2
@@ -172,10 +174,21 @@ func (p DefParty) carServiceProcess() web_iris.Party {
} }
database.Instance().Model(&models.UserAmountRecord{}).Create(&userAmountRecord) 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.PayTime = time.Now()
subOrderInfo.PayStatus = 1 subOrderInfo.PayStatus = 1
} }
if carServiceProcessRequest.Type == 1 { if carServiceProcessRequest.Type == 1 {
subOrderInfo.OrderStatus = 2 subOrderInfo.OrderStatus = 2
@@ -208,6 +221,19 @@ func (p DefParty) carServiceProcess() web_iris.Party {
"LastServiceDate": pet.PetInfo.LastServiceDate, "LastServiceDate": pet.PetInfo.LastServiceDate,
} }
database.Instance().Model(&pet.PetInfo).Updates(&updateValues) 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 { } else if carServiceProcessRequest.Type == 3 {
subOrderInfo.PayRemark = carServiceProcessRequest.PayRemark subOrderInfo.PayRemark = carServiceProcessRequest.PayRemark
database.Instance().Save(&subOrderInfo) database.Instance().Save(&subOrderInfo)
@@ -216,8 +242,16 @@ func (p DefParty) carServiceProcess() web_iris.Party {
FilePath: carServiceProcessRequest.FileName, FilePath: carServiceProcessRequest.FileName,
Type: carServiceProcessRequest.Type, 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})
}) })
}} }}
} }
+17 -2
View File
@@ -42,6 +42,7 @@ var (
ParamError = Error{Code: 201, Msg: "参数错误"} ParamError = Error{Code: 201, Msg: "参数错误"}
IllegalError = Error{Code: 202, Msg: "非法请求"} IllegalError = Error{Code: 202, Msg: "非法请求"}
UserError = Error{Code: 203, Msg: "用户错误"} UserError = Error{Code: 203, Msg: "用户错误"}
ServerError = Error{Code: 203, Msg: "服务器异常"}
TokenError = Error{Code: 204, Msg: "Token失效,请重新登录"} TokenError = Error{Code: 204, Msg: "Token失效,请重新登录"}
UserNotExistError = Error{Code: 205, Msg: "用户不存在"} UserNotExistError = Error{Code: 205, Msg: "用户不存在"}
PetNotExistError = Error{Code: 206, Msg: "用户宠物不存在"} PetNotExistError = Error{Code: 206, Msg: "用户宠物不存在"}
@@ -57,6 +58,12 @@ var (
PetInfoNotDelError = Error{Code: 215, Msg: "当前宠物存在待服务订单,无法删除"} PetInfoNotDelError = Error{Code: 215, Msg: "当前宠物存在待服务订单,无法删除"}
PetInfoNotUpdateError = Error{Code: 216, Msg: "当前宠物存在待服务订单,无法修改"} PetInfoNotUpdateError = Error{Code: 216, Msg: "当前宠物存在待服务订单,无法修改"}
OrderUpdateBalanceNotEnough = Error{Code: 217, 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) { func Success(ctx *context.Context, request any, data any) {
@@ -125,6 +132,7 @@ var GoodsMap map[int64]models.Goods
var CarMap map[int]models.ServiceCar var CarMap map[int]models.ServiceCar
var ReserveMap map[string]models.ReserveTimeFilter var ReserveMap map[string]models.ReserveTimeFilter
var AddrServiceMap map[int64]models.AddrServiceTime var AddrServiceMap map[int64]models.AddrServiceTime
var CouponsMap map[int]models.Coupons
func DataInit() { func DataInit() {
//--------------------------------------------------宠物基础信息数据--------------------------------------------------------- //--------------------------------------------------宠物基础信息数据---------------------------------------------------------
@@ -138,7 +146,7 @@ func DataInit() {
zap_server.ZAPLOG.Info("dataInit petBastInfoMap : ", zap.Any("petBastInfoMap", PetBaseInfoMap)) zap_server.ZAPLOG.Info("dataInit petBastInfoMap : ", zap.Any("petBastInfoMap", PetBaseInfoMap))
//--------------------------------------------------服务地址数据--------------------------------------------------------- //--------------------------------------------------服务地址数据---------------------------------------------------------
var serviceAddrList []models.ServiceAddr 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) var ServiceAddrMapC1 = make(map[int64]models.ServiceAddr)
for _, value := range serviceAddrList { for _, value := range serviceAddrList {
ServiceAddrMapC1[value.Id] = value ServiceAddrMapC1[value.Id] = value
@@ -148,7 +156,6 @@ func DataInit() {
//--------------------------------------------------宠物商品关联数据--------------------------------------------------------- //--------------------------------------------------宠物商品关联数据---------------------------------------------------------
var petGoodsList []models.PetGoods var petGoodsList []models.PetGoods
database.Instance().Model(&models.PetGoods{}).Where("status = 1").Find(&petGoodsList) 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) var PetGoodsMapC1 = make(map[string][]models.PetGoods)
for _, value := range petGoodsList { for _, value := range petGoodsList {
key := strconv.Itoa(value.Assortment) + strconv.Itoa(value.PetType) + strconv.Itoa(value.Weight) + strconv.Itoa(value.Hair) key := strconv.Itoa(value.Assortment) + strconv.Itoa(value.PetType) + strconv.Itoa(value.Weight) + strconv.Itoa(value.Hair)
@@ -193,6 +200,14 @@ func DataInit() {
} }
AddrServiceMap = AddrServiceMapC1 AddrServiceMap = AddrServiceMapC1
zap_server.ZAPLOG.Info("dataInit AddrServiceMap : ", zap.Any("AddrServiceMap", AddrServiceMap)) 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
}
CouponsMap = CouponsMapC1
zap_server.ZAPLOG.Info("dataInit CouponsMap : ", zap.Any("Coupons", CouponsMap))
} }
func DataCacheJob() { func DataCacheJob() {
+15 -1
View File
@@ -10,6 +10,8 @@ var PetBase = "/pet"
var CarBase = "/car" var CarBase = "/car"
var Admin = "/admin" var Admin = "/admin"
var System = "/system" var System = "/system"
var CouponsBase = "/coupons"
var PayBase = "/pay"
func (p DefParty) RegisterList() []web_iris.Party { func (p DefParty) RegisterList() []web_iris.Party {
ps := []web_iris.Party{ ps := []web_iris.Party{
@@ -29,9 +31,10 @@ func (p DefParty) RegisterList() []web_iris.Party {
p.orderEdit(), p.orderEdit(),
p.orderDetail(), p.orderDetail(),
p.orderGoodsUpdate(), p.orderGoodsUpdate(),
p.orderPay(),
p.orderCancel(), p.orderCancel(),
p.orderCreatePreCheck(), p.orderCreatePreCheck(),
p.orderMarkRecord(),
p.orderMarkRecordInfo(),
//宠物 //宠物
p.petList(), p.petList(),
p.petInfo(), p.petInfo(),
@@ -42,13 +45,24 @@ func (p DefParty) RegisterList() []web_iris.Party {
p.serviceAddrList(), p.serviceAddrList(),
p.serviceAddOrEdit(), p.serviceAddOrEdit(),
p.serviceAreaAddrList(), p.serviceAreaAddrList(),
p.serviceCarLocationUpload(),
p.serviceCarLocationList(),
//车辆 //车辆
p.carServiceOrderList(), p.carServiceOrderList(),
p.carServiceProcess(), p.carServiceProcess(),
p.index(), p.index(),
//优惠券
p.getCouponsList(),
p.getUserCouponsList(),
p.drawCoupons(),
//支付
p.rechargeInfoList(),
p.toPay(),
p.payNotify(),
//系统 //系统
p.systemConfigInfo(), p.systemConfigInfo(),
p.systemBanners(), p.systemBanners(),
p.getPayoff(),
} }
return ps return ps
} }
+144
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)
})
}}
}
+3
View File
@@ -27,6 +27,7 @@ type GoodsDetail struct {
BuyMany int `json:"buyMany"` //同类型是否可购买多个 0否 1是 BuyMany int `json:"buyMany"` //同类型是否可购买多个 0否 1是
GoodsDetail string `json:"goodsDetail"` //商品详情 图片URL GoodsDetail string `json:"goodsDetail"` //商品详情 图片URL
GoodsIcon string `json:"goodsIcon"` //iconUrl GoodsIcon string `json:"goodsIcon"` //iconUrl
GoodsSubType int `json:"goodsSubType"` //商品子类型
GoodsSubList []GoodsDetail `json:"goodsSubList,omitempty"` GoodsSubList []GoodsDetail `json:"goodsSubList,omitempty"`
} }
@@ -123,6 +124,7 @@ func getPetGoodsList(key string) []GoodsDetail {
BuyMany: goods.BuyMany, BuyMany: goods.BuyMany,
GoodsDetail: goods.GoodsDetail, GoodsDetail: goods.GoodsDetail,
GoodsIcon: goods.GoodsIcon, GoodsIcon: goods.GoodsIcon,
GoodsSubType: goods.GoodsSubType,
GoodsSubList: nil, GoodsSubList: nil,
} }
for _, goodsSub := range GoodsMap { for _, goodsSub := range GoodsMap {
@@ -136,6 +138,7 @@ func getPetGoodsList(key string) []GoodsDetail {
BuyMany: goodsSub.BuyMany, BuyMany: goodsSub.BuyMany,
GoodsDetail: goodsSub.GoodsDetail, GoodsDetail: goodsSub.GoodsDetail,
GoodsIcon: goodsSub.GoodsIcon, GoodsIcon: goodsSub.GoodsIcon,
GoodsSubType: goodsSub.GoodsSubType,
}) })
} }
} }
+14 -2
View File
@@ -18,6 +18,7 @@ var ExcludeBase = "/static"
var ExcludeBase1 = "/debug" var ExcludeBase1 = "/debug"
var ExcludeBase2 = "/admin" var ExcludeBase2 = "/admin"
var ExcludeBase3 = "/system" var ExcludeBase3 = "/system"
var ExcludeBase4 = "/payNotify"
var frontExcludes = [...]string{ var frontExcludes = [...]string{
Root + AuthBase + "/login", Root + AuthBase + "/login",
@@ -25,7 +26,7 @@ var frontExcludes = [...]string{
func ModuleInit() { func ModuleInit() {
utils.WechatInit() utils.WechatInit()
_ = database.Instance().AutoMigrate( _err := database.Instance().AutoMigrate(
//&models.User{}, //&models.User{},
//&models.Pet{}, //&models.Pet{},
//&models.PetBaseInfo{}, //&models.PetBaseInfo{},
@@ -45,8 +46,15 @@ func ModuleInit() {
//&models.ReserveTimeFilter{}, //&models.ReserveTimeFilter{},
//&models.OrderServiceRecord{}, //&models.OrderServiceRecord{},
//&models.AddrServiceTime{}, //&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() DataInit()
DataCacheJob() DataCacheJob()
} }
@@ -68,6 +76,10 @@ func FrontAuth(ctx *context.Context) {
ctx.Next() ctx.Next()
return return
} }
if strings.Contains(ctx.Path(), ExcludeBase4) {
ctx.Next()
return
}
frontExcludesStr := strings.Join(frontExcludes[:], ",") frontExcludesStr := strings.Join(frontExcludes[:], ",")
if strings.Contains(frontExcludesStr, ctx.Path()) { if strings.Contains(frontExcludesStr, ctx.Path()) {
ctx.Next() ctx.Next()
+484 -52
View File
@@ -2,6 +2,7 @@ package api
import ( import (
"encoding/json" "encoding/json"
"fmt"
"github.com/kataras/iris/v12" "github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context" "github.com/kataras/iris/v12/context"
"go.uber.org/zap" "go.uber.org/zap"
@@ -20,14 +21,16 @@ import (
) )
type PetGoodsInfo struct { type PetGoodsInfo struct {
PetId int64 Cid int //优惠券ID
GoodsIds []int64 PetId int64 //宠物ID
GoodsIds []int64 //商品列表
} }
type OrderCreateRequest struct { type OrderCreateRequest struct {
PetGoodsInfos []PetGoodsInfo //宠物商品信息列表 PetGoodsInfos []PetGoodsInfo //宠物商品信息列表
ServiceTime string //预约时间 yyyy-MM-dd HH:mm ServiceTime string //预约时间 yyyy-MM-dd HH:mm
ServiceAddrId int64 //预约服务地址 ServiceAddrId int64 //预约服务地址
PayOrderId string //支付单号
} }
type OrderCreateResponse struct { type OrderCreateResponse struct {
@@ -37,6 +40,7 @@ type OrderCreateResponse struct {
type OrderCreatePreCheckResponse struct { type OrderCreatePreCheckResponse struct {
HasAlert bool `json:"hasAlert"` //是否弹窗提示 返回false直接下单,返回ture弹出确认框,确认框点击是之后调用下单接口 HasAlert bool `json:"hasAlert"` //是否弹窗提示 返回false直接下单,返回ture弹出确认框,确认框点击是之后调用下单接口
AlertMsg string `json:"alertMsg"` //弹窗消息 AlertMsg string `json:"alertMsg"` //弹窗消息
PayType int `json:"payType"` //扣款类型
} }
func (p DefParty) orderCreatePreCheck() web_iris.Party { func (p DefParty) orderCreatePreCheck() web_iris.Party {
@@ -52,25 +56,49 @@ func (p DefParty) orderCreatePreCheck() web_iris.Party {
} }
var userInfo *models.User var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo) database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo)
var orderTotalAmount = 0 var goodsDiscountAmount = 0
var goodsNotDiscountAmount = 0
for _, value := range orderCreateRequest.PetGoodsInfos { for _, value := range orderCreateRequest.PetGoodsInfos {
for _, value := range value.GoodsIds { for _, gid := range value.GoodsIds {
goods := GoodsMap[value] goods := GoodsMap[gid]
orderTotalAmount = orderTotalAmount + int(goods.Price) 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
}
}
} }
} }
orderCreatePreCheckResponse := OrderCreatePreCheckResponse{ orderCreatePreCheckResponse := OrderCreatePreCheckResponse{
HasAlert: false, HasAlert: false,
PayType: 0,
} }
var discountAmount = orderTotalAmount
if userInfo.Discount > 0 { if userInfo.Discount > 0 {
discount := float64(userInfo.Discount) 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 { if userInfo.Amount < discountAmount {
orderCreatePreCheckResponse.HasAlert = true orderCreatePreCheckResponse.HasAlert = true
orderCreatePreCheckResponse.AlertMsg = "您的会员余额不够,需要进行线下支付,当前订单将不享受会员折扣优惠价格" 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) Success(ctx, orderCreateRequest, orderCreatePreCheckResponse)
}) })
@@ -93,8 +121,25 @@ func (p DefParty) orderCreate() web_iris.Party {
UserServiceAddrNotExistError.Fail(ctx, nil) UserServiceAddrNotExistError.Fail(ctx, nil)
return return
} }
var userCouponsList []*models.UserCoupons
var projectionServiceTime = 0 var projectionServiceTime = 0
var userCoupons *models.UserCoupons
for _, value := range orderCreateRequest.PetGoodsInfos { for _, value := range orderCreateRequest.PetGoodsInfos {
database.Instance().Model(&models.UserCoupons{}).Where("id = ? and coupons_status = 1", value.Cid).Find(&userCoupons)
userCouponsList = append(userCouponsList, userCoupons)
if value.Cid > 0 {
if userCoupons.Id == 0 {
CouponsNotExistError.Fail(ctx, nil)
return
}
coupons := CouponsMap[userCoupons.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}
}
}
userPet := GetUserPet(headerBaseInfo.Uid, value.PetId) userPet := GetUserPet(headerBaseInfo.Uid, value.PetId)
var dog = userPet.PetBaseInfo.PetType == 2 var dog = userPet.PetBaseInfo.PetType == 2
var goodsType1 = false var goodsType1 = false
@@ -130,7 +175,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 var orderTotalAmount = 0
orderLock.Lock() orderLock.Lock()
orderId := NextId.Generate().String() orderId := NextId.Generate().String()
orderMain := models.OrderMain{ orderMain := models.OrderMain{
@@ -147,7 +201,17 @@ func (p DefParty) orderCreate() web_iris.Party {
var orderSubList []models.OrderSub var orderSubList []models.OrderSub
var orderSubDetailList []models.OrderDetail var orderSubDetailList []models.OrderDetail
var mainGoods = 0 var mainGoods = 0
var coupons models.Coupons
for _, value := range orderCreateRequest.PetGoodsInfos { for _, value := range orderCreateRequest.PetGoodsInfos {
//可以参与会员折扣的金额
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]
subOrderId := NextId.Generate().String() subOrderId := NextId.Generate().String()
var totalAmount = 0 var totalAmount = 0
var projectionServiceTime = 0 var projectionServiceTime = 0
@@ -155,7 +219,15 @@ func (p DefParty) orderCreate() web_iris.Party {
for _, value := range value.GoodsIds { for _, value := range value.GoodsIds {
goods := GoodsMap[value] goods := GoodsMap[value]
totalAmount = totalAmount + goods.Price 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 { if goods.Time != "/" && len(goods.Time) > 0 {
goodsTime, _ := strconv.Atoi(goods.Time) goodsTime, _ := strconv.Atoi(goods.Time)
projectionServiceTime += goodsTime projectionServiceTime += goodsTime
@@ -164,10 +236,29 @@ func (p DefParty) orderCreate() web_iris.Party {
mainGoods++ mainGoods++
} }
goodsName = goods.Name + "、" + goodsName 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) 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 projectionServiceTimeAll += projectionServiceTime
/*for _, orderDetail := range orderSubDetailList {
goods := GoodsMap[orderDetail.GoodsId]
}*/
orderSub := models.OrderSub{ orderSub := models.OrderSub{
OrderId: subOrderId, OrderId: subOrderId,
MainOrderId: orderMain.OrderId, MainOrderId: orderMain.OrderId,
@@ -176,12 +267,20 @@ func (p DefParty) orderCreate() web_iris.Party {
PayType: 1, PayType: 1,
Discount: 100, Discount: 100,
TotalAmount: totalAmount, TotalAmount: totalAmount,
PayAmount: totalAmount, //折扣价格 默认*10
PayAmount: notDiscountAmount + needDiscountAmount*10,
//设置商品折扣金额用于后续打折计算
GoodsDiscountAmount: notDiscountAmount,
//设置商品非折扣金额
GoodsOriginAmount: needDiscountAmount,
//宠物信息
PetInfo: petInfo, PetInfo: petInfo,
Status: 1, Status: 1,
//PayTime: time.Now(),
ProjectionServiceTime: projectionServiceTime, ProjectionServiceTime: projectionServiceTime,
Cid: coupons.Id,
Ucid: userCoupons.Id,
} }
//订单总金额
orderTotalAmount = orderTotalAmount + totalAmount orderTotalAmount = orderTotalAmount + totalAmount
orderSubList = append(orderSubList, orderSub) orderSubList = append(orderSubList, orderSub)
} }
@@ -190,25 +289,36 @@ func (p DefParty) orderCreate() web_iris.Party {
orderLock.Unlock() orderLock.Unlock()
return return
} }
orderMain.ProjectionServiceTime = projectionServiceTimeAll orderMain.ProjectionServiceTime = projectionServiceTimeAll
var userInfo *models.User var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo) 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 { if userInfo.Discount > 0 {
discount := float64(userInfo.Discount) 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 { } else {
discountAmount = int(utils.RoundToOneDecimalPlace(float64(orderTotalAmount) * 10)) discountAmount = int(utils.RoundToOneDecimalPlace(float64(inDiscountAmount) * 10))
} }
orderMain.TotalAmount = orderTotalAmount orderMain.TotalAmount = orderTotalAmount
tx := database.Instance().Begin() tx := database.Instance().Begin()
var db4 *gorm.DB var db4 *gorm.DB
if userInfo.Amount >= discountAmount { //用户需要扣除总金额
if userInfo.Amount >= discountAmount+orderGoodsDiscountAmount {
var currAmount = userInfo.Amount var currAmount = userInfo.Amount
orderMain.PayStatus = 1 orderMain.PayStatus = 1
orderMain.PayTotalAmount = discountAmount orderMain.PayTotalAmount = discountAmount + orderGoodsDiscountAmount
userInfo.Amount = userInfo.Amount - discountAmount userInfo.Amount = userInfo.Amount - discountAmount - orderGoodsDiscountAmount
updateValues := map[string]interface{}{ updateValues := map[string]interface{}{
"Amount": userInfo.Amount, "Amount": userInfo.Amount,
} }
@@ -222,21 +332,51 @@ func (p DefParty) orderCreate() web_iris.Party {
UserId: userInfo.Id, UserId: userInfo.Id,
Type: 2, Type: 2,
OriginAmount: currAmount, 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, CurrAmount: userInfo.Amount,
OrderId: orderId, OrderId: orderId,
ProScene: "下单", ProScene: "下单",
Status: 1, Status: 1,
} }
tx.Model(&models.UserAmountRecord{}).Create(&userAmountRecord) 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 var findUserServiceAddr models.UserServiceAddr
database.Instance().Model(&models.UserServiceAddr{}).Where("id = ? and uid = ?", orderCreateRequest.ServiceAddrId, headerBaseInfo.Uid).Find(&findUserServiceAddr) database.Instance().Model(&models.UserServiceAddr{}).Where("id = ? and uid = ?", orderCreateRequest.ServiceAddrId, headerBaseInfo.Uid).Find(&findUserServiceAddr)
userInfo.Mobile = findUserServiceAddr.Mobile userInfo.Mobile = findUserServiceAddr.Mobile
@@ -247,6 +387,13 @@ func (p DefParty) orderCreate() web_iris.Party {
db := tx.Model(&models.OrderDetail{}).CreateInBatches(&orderSubDetailList, len(orderSubDetailList)) db := tx.Model(&models.OrderDetail{}).CreateInBatches(&orderSubDetailList, len(orderSubDetailList))
db1 := tx.Model(&models.OrderSub{}).CreateInBatches(&orderSubList, len(orderSubList)) db1 := tx.Model(&models.OrderSub{}).CreateInBatches(&orderSubList, len(orderSubList))
db2 := tx.Model(&models.OrderMain{}).Create(&orderMain) db2 := tx.Model(&models.OrderMain{}).Create(&orderMain)
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 { if (db4 != nil && db4.Error != nil) || db.Error != nil || db1.Error != nil || db2.Error != nil {
tx.Callback() tx.Callback()
orderLock.Unlock() orderLock.Unlock()
@@ -283,10 +430,13 @@ func GetOrderDetail(orderId string) OrderDetail {
Discount: float64(orderMain.PayDiscount) / 100, Discount: float64(orderMain.PayDiscount) / 100,
Uid: orderMain.Uid, Uid: orderMain.Uid,
UserAmount: float64(userInfo.Amount) / 10.0, 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) orderDetail.DiscountAmount = strconv.FormatFloat(float64(orderMain.PayTotalAmount)/10.0, 'f', 1, 64)
} }
var discountTotalAmount = 0
var subOrderList []SubOrder var subOrderList []SubOrder
var orderSubList []models.OrderSub var orderSubList []models.OrderSub
database.Instance().Model(&models.OrderSub{}).Where("main_order_id = ? ", orderMain.OrderId).Find(&orderSubList) database.Instance().Model(&models.OrderSub{}).Where("main_order_id = ? ", orderMain.OrderId).Find(&orderSubList)
@@ -294,10 +444,39 @@ func GetOrderDetail(orderId string) OrderDetail {
var orderDetailList []models.OrderDetail var orderDetailList []models.OrderDetail
database.Instance().Model(&models.OrderDetail{}).Where("sub_order_id = ? ", orderSub.OrderId).Find(&orderDetailList) database.Instance().Model(&models.OrderDetail{}).Where("sub_order_id = ? ", orderSub.OrderId).Find(&orderDetailList)
var goods []models.Goods var goods []models.Goods
var couponsGoods models.Goods
var coupons models.Coupons
for _, orderDetail := range orderDetailList { for _, orderDetail := range orderDetailList {
good := GoodsMap[orderDetail.GoodsId] good := GoodsMap[orderDetail.GoodsId]
goods = append(goods, good) 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{ orderSubR1 := SubOrder{
OrderId: orderSub.OrderId, OrderId: orderSub.OrderId,
Status: orderSub.OrderStatus, Status: orderSub.OrderStatus,
@@ -306,20 +485,54 @@ func GetOrderDetail(orderId string) OrderDetail {
PayAmount: strconv.Itoa(orderSub.PayAmount), PayAmount: strconv.Itoa(orderSub.PayAmount),
Discount: float64(orderSub.Discount), Discount: float64(orderSub.Discount),
Goods: goods, 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 x := float64(orderSub.PayAmount) / 10
orderSubR1.PayAmount = strconv.FormatFloat(x, 'f', 1, 64) orderSubR1.PayAmount = strconv.FormatFloat(x, 'f', 1, 64)
} }
if orderSubR1.Discount < 100 { if orderSubR1.Discount < 100 || orderSubR1.Coupons != nil {
//orderSubR1.PayAmount = int32(math.Round(float64(orderSubR1.TotalAmount) * (orderSubR1.Discount / 100.0)))
//x := float64(orderSubR1.TotalAmount) * (orderSubR1.Discount / 100.0) / 10
orderSubR1.DiscountAmount = orderSubR1.PayAmount orderSubR1.DiscountAmount = orderSubR1.PayAmount
} else {
if orderSub.PayAmount > 0 {
orderSubR1.DiscountAmount = strconv.FormatFloat(float64(orderSub.PayAmount)/10, 'f', 1, 64)
} else { } else {
orderSubR1.DiscountAmount = strconv.Itoa(orderSubR1.TotalAmount) 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) subOrderList = append(subOrderList, orderSubR1)
} }
if discountTotalAmount > 0 {
orderDetail.DiscountAmount = strconv.Itoa(discountTotalAmount / 10.0)
}
var carOrder models.CarOrder var carOrder models.CarOrder
database.Instance().Model(&models.CarOrder{}).Where("order_id = ?", orderMain.OrderId).Find(&carOrder) database.Instance().Model(&models.CarOrder{}).Where("order_id = ?", orderMain.OrderId).Find(&carOrder)
if carOrder.Id > 0 { if carOrder.Id > 0 {
@@ -333,7 +546,7 @@ func GetOrderDetail(orderId string) OrderDetail {
} }
func checkOrderServiceTime(serviceTime string, projectionServiceTime int) bool { func checkOrderServiceTime(serviceTime string, projectionServiceTime int) bool {
type orderMainTmp struct { /*type orderMainTmp struct {
ServiceTime string ServiceTime string
ProjectionServiceTime int ProjectionServiceTime int
} }
@@ -352,7 +565,7 @@ func checkOrderServiceTime(serviceTime string, projectionServiceTime int) bool {
//时间点订单数量<服务车辆*车辆单次服务数量 才可接受预约 //时间点订单数量<服务车辆*车辆单次服务数量 才可接受预约
if len(orderMainTmpList) > 0 { if len(orderMainTmpList) > 0 {
return len(orderMainTmpList) >= len(CarMap)*CarServiceNum return len(orderMainTmpList) >= len(CarMap)*CarServiceNum
} }*/
return false return false
} }
@@ -371,6 +584,8 @@ type SubOrder struct {
DiscountAmount string `json:"discountAmount"` //折扣金额 DiscountAmount string `json:"discountAmount"` //折扣金额
Discount float64 `json:"discount"` //用户折扣 Discount float64 `json:"discount"` //用户折扣
Goods []models.Goods `json:"goods"` //商品信息 Goods []models.Goods `json:"goods"` //商品信息
Coupons *models.Coupons `json:"coupons"` //优惠券信息
CouponsAmount string `json:"couponsAmount"` //优惠券减免金额
} }
type OrderDetail struct { type OrderDetail struct {
@@ -389,6 +604,7 @@ type OrderDetail struct {
DiscountAmount string `json:"discountAmount"` //折扣金额 DiscountAmount string `json:"discountAmount"` //折扣金额
Uid int64 `json:"uid"` //用户ID Uid int64 `json:"uid"` //用户ID
UserAmount float64 `json:"userAmount"` //用户余额 UserAmount float64 `json:"userAmount"` //用户余额
MarkStatus int `json:"markStatus"` //订单是否已评价
} }
type OrderListResponse struct { type OrderListResponse struct {
@@ -411,9 +627,9 @@ func (p DefParty) orderList() web_iris.Party {
} }
var orderList []models.OrderMain var orderList []models.OrderMain
if orderListRequest.Status == 0 { 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 { } 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 var orderDetails []OrderDetail
for _, value := range orderList { for _, value := range orderList {
@@ -431,6 +647,7 @@ func (p DefParty) orderList() web_iris.Party {
TotalAmount: value.TotalAmount, TotalAmount: value.TotalAmount,
DiscountAmount: strconv.FormatFloat(float64(value.PayTotalAmount)/10.0, 'f', 1, 64), DiscountAmount: strconv.FormatFloat(float64(value.PayTotalAmount)/10.0, 'f', 1, 64),
Discount: float64(value.PayDiscount / 100.0), Discount: float64(value.PayDiscount / 100.0),
MarkStatus: value.MarkStatus,
} }
var subOrderList []SubOrder var subOrderList []SubOrder
var orderSubList []models.OrderSub var orderSubList []models.OrderSub
@@ -539,6 +756,16 @@ func (p DefParty) orderCancel() web_iris.Party {
"OrderStatus": 4, "OrderStatus": 4,
} }
database.Instance().Model(&orderSub).Updates(&updateValuesSub) 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)}) Success(ctx, orderCancelRequest, OrderCancelResponse{GetOrderDetail(orderMain.OrderId)})
}) })
@@ -576,8 +803,36 @@ func (p DefParty) orderServiceTime() web_iris.Party {
} }
var orderMainTmpList []orderMainTmp 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) 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 orderMainTmp1 []struct {
ServiceTime string
Count int
ProjectionServiceTime int
}
err := database.Instance().Raw(`
SELECT service_time, COUNT(1) AS count, projection_service_time
FROM order_mains
WHERE service_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)
AND order_status != 3
AND order_status != 4
AND status = 1
GROUP BY service_time
HAVING count > 0
`).Scan(&orderMainTmp1).Error
if err != nil {
ServerError.Fail(ctx, err)
return
}
var orderTimeMap = make(map[string]string) var orderTimeMap = make(map[string]string)
var orderTimeNum = make(map[string]int) var orderTimeNum = make(map[string]int)
var orderTimeCount = make(map[string]int)
var orderProjectionTime = make(map[string]int)
for _, val := range orderMainTmp1 {
orderTimeCount[val.ServiceTime] = val.Count
orderProjectionTime[val.ServiceTime] = val.ProjectionServiceTime
}
for _, value := range orderMainTmpList { for _, value := range orderMainTmpList {
orderTimeMap[value.ServiceTime] = value.ServiceTime orderTimeMap[value.ServiceTime] = value.ServiceTime
orderTimeNum[value.ServiceTime] = orderTimeNum[value.ServiceTime] + 1 orderTimeNum[value.ServiceTime] = orderTimeNum[value.ServiceTime] + 1
@@ -587,15 +842,18 @@ func (p DefParty) orderServiceTime() web_iris.Party {
lastDate := date.Add(time.Minute * time.Duration(value.ProjectionServiceTime)) lastDate := date.Add(time.Minute * time.Duration(value.ProjectionServiceTime))
for t := date; t.Before(lastDate); t = t.Add(time.Hour) { for t := date; t.Before(lastDate); t = t.Add(time.Hour) {
timeStr := t.Format("2006-01-02 15:04") timeStr := t.Format("2006-01-02 15:04")
if timeStr != value.ServiceTime {
orderTimeMap[timeStr] = timeStr orderTimeMap[timeStr] = timeStr
orderTimeNum[timeStr] = orderTimeNum[timeStr] + 1 orderTimeNum[timeStr] = orderTimeNum[timeStr] + 1
orderTimeCount[timeStr] = orderTimeCount[timeStr] + 1
}
} }
} }
} }
serviceTime := AddrServiceMap[orderServiceTimeRequest.ServiceAddrId] serviceTime := AddrServiceMap[orderServiceTimeRequest.ServiceAddrId]
times := strings.Split(serviceTime.Times, ",") times := strings.Split(serviceTime.Times, ",")
carNum := len(CarMap) carNum := len(CarMap)
daysMap := utils.GetStrDays(7, 60, ReserveMap, orderTimeMap, carNum, orderTimeNum, CarServiceNum, times) daysMap := utils.GetStrDays(7, 60, ReserveMap, orderTimeMap, carNum, orderTimeNum, CarServiceNum, times, orderTimeCount, orderProjectionTime)
var dayHoursMap = make(map[string][]TimeObject) var dayHoursMap = make(map[string][]TimeObject)
for day, values := range daysMap { for day, values := range daysMap {
key := day key := day
@@ -700,8 +958,23 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party {
database.Instance().Model(&models.OrderMain{}).Where("order_id = ? and status = 1", orderSub.MainOrderId).Find(&orderMain) database.Instance().Model(&models.OrderMain{}).Where("order_id = ? and status = 1", orderSub.MainOrderId).Find(&orderMain)
var nowOrderTotalAmount = 0 var nowOrderTotalAmount = 0
var projectionServiceTime = 0 var projectionServiceTime = 0
//商品优惠券价格
var goodsDiscountAmount = 0
//商品非优惠券价格
var goodsNotDiscountAmount = 0
var coupons models.Coupons
for _, value := range orderGoodsUpdateRequest.GoodsIds { for _, value := range orderGoodsUpdateRequest.GoodsIds {
goods := GoodsMap[value] 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 nowOrderTotalAmount = nowOrderTotalAmount + goods.Price
if goods.Time != "/" && len(goods.Time) > 0 { if goods.Time != "/" && len(goods.Time) > 0 {
goodsTime, _ := strconv.Atoi(goods.Time) goodsTime, _ := strconv.Atoi(goods.Time)
@@ -723,24 +996,26 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party {
allProjectionServiceTime = allProjectionServiceTime + value.ProjectionServiceTime 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.PayStatus == 1 {
if orderMain.PayType == 3 { if orderMain.PayType == 3 {
var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", orderMain.Uid).Find(&userInfo)
var originAmount = userInfo.Amount var originAmount = userInfo.Amount
//先退还 当前订单 //先退还 当前订单
userInfo.Amount = userInfo.Amount + orderSub.PayAmount userInfo.Amount = userInfo.Amount + orderSub.PayAmount
if userInfo.Discount > 0 { if userInfo.Discount > 0 {
discount := float64(userInfo.Discount) 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.PayTotalAmount = orderMain.PayTotalAmount - originOrderPayAmount + subOrderAmount + goodsDiscountAmount
orderMain.TotalAmount = orderMain.TotalAmount - originOrderTotalAmount + nowOrderTotalAmount
//余额不足 //余额不足
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)+";修改服务项目后余额不足,请充值后再支付") OrderUpdateBalanceNotEnough.DefFail(ctx, orderGoodsUpdateRequest, "原订单金额:"+strconv.FormatFloat(float64(orderMain.PayTotalAmount)/10, 'f', 1, 64)+" 修改后订单金额:"+strconv.FormatFloat(float64(orderMain.PayTotalAmount)/10, 'f', 1, 64)+";修改服务项目后余额不足,请充值后再支付")
return return
} }
@@ -748,13 +1023,13 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party {
var amountType = 2 var amountType = 2
var proAmount = 0 var proAmount = 0
//原始价格小于新价格 扣,原始价格大于新价格 加 //原始价格小于新价格 扣,原始价格大于新价格 加
if originOrderPayAmount < subOrderAmount { if originOrderPayAmount < subOrderAmount+goodsDiscountAmount {
} else { } else {
amountType = 1 amountType = 1
} }
var preAmount = orderMain.PayTotalAmount var preAmount = orderMain.PayTotalAmount
userInfo.Amount = userInfo.Amount - subOrderAmount userInfo.Amount = userInfo.Amount - (subOrderAmount + goodsDiscountAmount)
updateValues := map[string]interface{}{ updateValues := map[string]interface{}{
"Amount": userInfo.Amount, "Amount": userInfo.Amount,
} }
@@ -780,45 +1055,202 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party {
database.Instance().Model(&models.UserAmountRecord{}).Create(&userAmountRecord) 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)) 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{}) database.Instance().Where("sub_order_id = ?", orderGoodsUpdateRequest.OrderId).Delete(&models.OrderDetail{})
var goodsName = ""
for _, value := range orderGoodsUpdateRequest.GoodsIds { for _, value := range orderGoodsUpdateRequest.GoodsIds {
goods := GoodsMap[value] goods := GoodsMap[value]
orderDetail := models.OrderDetail{ orderDetail := models.OrderDetail{
SubOrderId: orderGoodsUpdateRequest.OrderId, SubOrderId: orderGoodsUpdateRequest.OrderId,
GoodsId: goods.Id, GoodsId: goods.Id,
Amount: goods.Price, Amount: goods.Price,
Cid: orderSub.Cid,
} }
goodsName = goods.Name + "、" + goodsName
database.Instance().Model(&models.OrderDetail{}).Create(&orderDetail) 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.TotalAmount = nowOrderTotalAmount
orderSub.PayAmount = subOrderAmount
orderSub.ProjectionServiceTime = projectionServiceTime orderSub.ProjectionServiceTime = projectionServiceTime
updateValues := map[string]interface{}{ updateValues := map[string]interface{}{
"TotalAmount": orderSub.TotalAmount, "TotalAmount": orderSub.TotalAmount,
"PayAmount": orderSub.PayAmount, "PayAmount": orderSub.PayAmount,
"ProjectionServiceTime": orderSub.ProjectionServiceTime, "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.ProjectionServiceTime = allProjectionServiceTime
orderMain.TotalAmount = totalAmount
updateValues1 := map[string]interface{}{ updateValues1 := map[string]interface{}{
"PayTotalAmount": orderMain.PayTotalAmount, "PayTotalAmount": orderMain.PayTotalAmount,
"TotalAmount": orderMain.TotalAmount, "TotalAmount": orderMain.TotalAmount,
"ProjectionServiceTime": orderMain.ProjectionServiceTime, "ProjectionServiceTime": orderMain.ProjectionServiceTime,
} }
database.Instance().Model(&orderMain).Updates(&updateValues1) database.Instance().Model(&orderMain).Updates(&updateValues1)
database.Instance().Model(&orderSub).Updates(&updateValues)
Success(ctx, orderGoodsUpdateRequest, OrderDetailResponse{GetOrderDetail(orderSub.MainOrderId)}) Success(ctx, orderGoodsUpdateRequest, OrderDetailResponse{GetOrderDetail(orderSub.MainOrderId)})
}) })
}} }}
} }
// 支付 type OrderMarkRecord struct {
func (p DefParty) orderPay() web_iris.Party { OrderId string
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) { Lab1 int
index.Post(OrderBase+"/orderPay", func(ctx *context.Context) { 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
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)
}
})
}}
}
+72
View File
@@ -67,6 +67,7 @@ func (p DefParty) serviceAddOrEdit() web_iris.Party {
Addr: serviceAddOrEditRequest.Addr, Addr: serviceAddOrEditRequest.Addr,
Longitude: serviceAddOrEditRequest.Longitude, Longitude: serviceAddOrEditRequest.Longitude,
Latitude: serviceAddOrEditRequest.Latitude, Latitude: serviceAddOrEditRequest.Latitude,
Status: 1,
} }
if len(serviceAddOrEditRequest.Longitude) == 0 || len(serviceAddOrEditRequest.Latitude) == 0 { if len(serviceAddOrEditRequest.Longitude) == 0 || len(serviceAddOrEditRequest.Latitude) == 0 {
addrGeocoding := utils.GetAddrGeocoding(utils.BmapGeoCodingRequest{Address: serviceAddOrEditRequest.Addr}) 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})
})
}}
}
+20 -1
View File
@@ -26,6 +26,8 @@ func (p DefParty) systemConfigInfo() web_iris.Party {
type SystemBannersResponse struct { type SystemBannersResponse struct {
Banners []models.SystemConfig `json:"banners"` Banners []models.SystemConfig `json:"banners"`
ShareText string `json:"shareText"`
ShareImg string `json:"shareImg"`
} }
// 获取系统banner // 获取系统banner
@@ -34,7 +36,24 @@ func (p DefParty) systemBanners() web_iris.Party {
index.Post(System+"/systemBanners", func(ctx *context.Context) { index.Post(System+"/systemBanners", func(ctx *context.Context) {
var systemConfig []models.SystemConfig 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) 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"})
}) })
}} }}
} }
+25
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-----
+28
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-----
+1 -1
View File
@@ -24,7 +24,7 @@
"session-timeout": 60, "session-timeout": 60,
"system": { "system": {
"addr": "127.0.0.1:18005", "addr": "127.0.0.1:18005",
"domain": "http://49.232.45.133:18005", "domain": "https://test-pet-house.ifish7.com",
"db-type": "mysql", "db-type": "mysql",
"level": "debug", "level": "debug",
"time-format": "2006-01-02 15:04:05", "time-format": "2006-01-02 15:04:05",
+6 -1
View File
@@ -3,5 +3,10 @@
"secret": "a29358be9ca3e34fa23d23994f5a386a", "secret": "a29358be9ca3e34fa23d23994f5a386a",
"token": "", "token": "",
"aesKey": "", "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-----`"
} }
+1
View File
@@ -82,6 +82,7 @@ require (
github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/wechatpay-apiv3/wechatpay-go v0.2.20 // indirect
github.com/yosssi/ace v0.0.5 // indirect github.com/yosssi/ace v0.0.5 // indirect
github.com/ziutek/mymysql v1.5.4 // indirect github.com/ziutek/mymysql v1.5.4 // indirect
go.uber.org/multierr v1.10.0 // indirect go.uber.org/multierr v1.10.0 // indirect
+4
View File
@@ -12,6 +12,7 @@ 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/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 h1:KkH3I3sJuOLP3TjA/dfr4NAY8bghDwnXiU7cTKxQqo0=
github.com/Shopify/goreferrer v0.0.0-20220729165902-8cddb4f5de06/go.mod h1:7erjKLwalezA0k99cWs5L11HWOAPNjdUZ6RxH1BXbbM= github.com/Shopify/goreferrer v0.0.0-20220729165902-8cddb4f5de06/go.mod h1:7erjKLwalezA0k99cWs5L11HWOAPNjdUZ6RxH1BXbbM=
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 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
@@ -219,6 +220,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.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.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.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 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
@@ -237,6 +239,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/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 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= 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/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 h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
+88 -3
View File
@@ -20,6 +20,7 @@ type User struct {
Discount int `json:"discount"` //折扣 Discount int `json:"discount"` //折扣
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP;not null" json:"createTime"` //创建时间 CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP;not null" json:"createTime"` //创建时间
Status int `json:"status"` //信息状态 Status int `json:"status"` //信息状态
InviteUserId int64 `json:"inviteUserId"` //邀请用户
} }
// Pet 宠物信息 // Pet 宠物信息
@@ -94,6 +95,7 @@ type Goods struct {
GoodsIcon string `json:"goodsIcon"` //iconUrl GoodsIcon string `json:"goodsIcon"` //iconUrl
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间 CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间
Status int `json:"status"` //信息状态 Status int `json:"status"` //信息状态
GoodsSubType int `gorm:"not null" json:"goodsSubType"` //商品子类型
} }
// PetGoods 宠物商品 // PetGoods 宠物商品
@@ -115,7 +117,7 @@ type SystemConfig struct {
Id int `gorm:"primaryKey;autoIncrement" json:"id"` //id Id int `gorm:"primaryKey;autoIncrement" json:"id"` //id
Name string `json:"name"` //名称 Name string `json:"name"` //名称
Content string `json:"content"` //内容 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链接 ContentType int `json:"contentType"` //1文本 2链接
Sort int `json:"sort"` //排序位 Sort int `json:"sort"` //排序位
JumpType int `gorm:"default:0" json:"JumpType"` //跳转类型 0无法跳转 1跳转外部 2跳转内部 JumpType int `gorm:"default:0" json:"JumpType"` //跳转类型 0无法跳转 1跳转外部 2跳转内部
@@ -141,6 +143,8 @@ type OrderMain struct {
PayDiscount int `gorm:"default:0" json:"payDiscount"` //支付折扣 PayDiscount int `gorm:"default:0" json:"payDiscount"` //支付折扣
PayType int `json:"payType"` //支付方式 1线下 2线上 3会员余额 PayType int `json:"payType"` //支付方式 1线下 2线上 3会员余额
Status int `json:"status1"` //信息状态 Status int `json:"status1"` //信息状态
PayOrderId string `json:"payOrderId"` //支付订单号
MarkStatus int `gorm:"default:0" json:"markStatus"` //评价状态
} }
// OrderSub 子订单 // OrderSub 子订单
@@ -152,24 +156,31 @@ type OrderSub struct {
PetId int64 `gorm:"index" json:"petId"` //宠物ID PetId int64 `gorm:"index" json:"petId"` //宠物ID
PayType int `gorm:"not null" json:"payType"` //支付方式 1线下 2线上 3会员余额 PayType int `gorm:"not null" json:"payType"` //支付方式 1线下 2线上 3会员余额
Discount int `json:"discount"` //折扣 Discount int `json:"discount"` //折扣
TotalAmount int `gorm:"not null" json:"totalAmount"` //总金额 TotalAmount int `gorm:"not null" json:"totalAmount"` //总金额 - 原价
ProjectionServiceTime int `json:"projectionServiceTime"` //服务预估时长 ProjectionServiceTime int `json:"projectionServiceTime"` //服务预估时长
PayStatus int `gorm:"default:0" json:"payStatus"` //支付状态 0未支付 1已支付 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"` //支付时间 PayTime time.Time `gorm:"type:timestamp;" json:"payTime"` //支付时间
PayRemark string `json:"payRemark"` //支付备注 PayRemark string `json:"payRemark"` //支付备注
PetInfo string `json:"petInfo"` //宠物快照信息 PetInfo string `json:"petInfo"` //宠物快照信息
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间 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:"-"` //更新时间 UpdateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP" json:"-"` //更新时间
Status int `json:"status1"` Status int `json:"status1"`
Cid int `gorm:"not null" json:"cid"` //优惠券ID
Ucid int `gorm:"not null" json:"ucid"` //优惠券ID - user
} }
// OrderDetail 订单明细 // OrderDetail 订单明细
type OrderDetail struct { type OrderDetail struct {
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id 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 SubOrderId string `gorm:"index;not null" json:"subOrderId"` //子订单ID
GoodsId int64 `gorm:"index;not null" json:"goodsId"` //商品ID GoodsId int64 `gorm:"index;not null" json:"goodsId"` //商品ID
Amount int `gorm:"not null" json:"amount"` //价格 Amount int `gorm:"not null" json:"amount"` //价格
DiscountAmount int `json:"-"` //折扣价格
} }
// OrderServiceRecord 订单服务记录 // OrderServiceRecord 订单服务记录
@@ -243,11 +254,13 @@ type ServiceUserMark struct {
type ServiceUserMarkRecord struct { type ServiceUserMarkRecord struct {
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
Uid int64 `gorm:"index;not null" json:"uid"` //评价用户 Uid int64 `gorm:"index;not null" json:"uid"` //评价用户
OrderId string `gorm:"not null" json:"orderId"` //订单ID
ServiceStar int `gorm:"default:5" json:"serviceStar"` //服务星级 ServiceStar int `gorm:"default:5" json:"serviceStar"` //服务星级
ServiceLabels string `json:"serviceLabels"` //服务标签 ServiceLabels string `json:"serviceLabels"` //服务标签
MarkContext string `json:"markContext"` //评价内容 MarkContext string `json:"markContext"` //评价内容
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间 CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间
UpdateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP" json:"-"` //更新时间 UpdateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP" json:"-"` //更新时间
Status int `json:"status"` //信息状态
} }
// ReserveTimeFilter 服务过滤时间 // ReserveTimeFilter 服务过滤时间
@@ -263,3 +276,75 @@ type AddrServiceTime struct {
ServiceAddrId int64 `gorm:"not null" json:"ServiceAddrId"` //服务地址ID ServiceAddrId int64 `gorm:"not null" json:"ServiceAddrId"` //服务地址ID
Times string `gorm:"not null" json:"times"` //时间列表 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:"-"` //状态
}
+25 -8
View File
@@ -21,7 +21,7 @@ type TimeObject struct {
Y bool `json:"y"` 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() currentTime := time.Now()
// 计算半小时后的时间 // 计算半小时后的时间
@@ -51,14 +51,12 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil
serviceDaysMap[dayTime] = dayTime serviceDaysMap[dayTime] = dayTime
} }
for nextHour.Before(oneWeekLater) { for nextHour.Before(oneWeekLater) {
//且不存在过滤时间中
_, 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") key := nextHour.Format("2006-01-02")
key1 := nextHour.Format("2006-01-02 15:04") 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 { if _, ok := serviceDaysMap[key1]; len(serviceDaysMap) > 0 && !ok {
//不存在服务配置中返回false //不存在服务配置中返回false
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{ dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
@@ -68,6 +66,12 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil
nextHour = nextHour.Add(time.Duration(minute) * time.Minute) nextHour = nextHour.Add(time.Duration(minute) * time.Minute)
continue 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 (!existsDay && !existsHour) && !existOrderTime {
if _, ok := dayHoursMap[key]; ok { if _, ok := dayHoursMap[key]; ok {
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{ dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
Time: nextHour.Format("15:04"), Time: nextHour.Format("15:04"),
@@ -81,7 +85,8 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil
} }
} else { } else {
key := nextHour.Format("2006-01-02") key := nextHour.Format("2006-01-02")
//当前订单数小于车辆数 可接单 key1 := nextHour.Format("2006-01-02 15:04")
//当前订单数小于车辆数 可接单 时间范围可能会超出到11点
if existOrderNum && orderNum < carNum*carServiceNum { if existOrderNum && orderNum < carNum*carServiceNum {
if _, ok := dayHoursMap[key]; ok { if _, ok := dayHoursMap[key]; ok {
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{ dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
@@ -95,6 +100,16 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil
}} }}
} }
} else if nextHour.Hour() >= workStart && nextHour.Hour() < workEnd { } else if nextHour.Hour() >= workStart && nextHour.Hour() < workEnd {
//查看当前时间对应的订单数量
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: true,
})
} else {
if _, ok := dayHoursMap[key]; ok { if _, ok := dayHoursMap[key]; ok {
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{ dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
Time: nextHour.Format("15:04"), Time: nextHour.Format("15:04"),
@@ -109,6 +124,8 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil
} }
} }
}
nextHour = nextHour.Add(time.Duration(minute) * time.Minute) // 下一个整点半时间 nextHour = nextHour.Add(time.Duration(minute) * time.Minute) // 下一个整点半时间
} }
return dayHoursMap return dayHoursMap
+52
View File
@@ -2,10 +2,12 @@ package utils
import ( import (
"fmt" "fmt"
utils2 "github.com/wechatpay-apiv3/wechatpay-go/utils"
"math" "math"
"pet-house.com/business/models" "pet-house.com/business/models"
"strconv" "strconv"
"testing" "testing"
"time"
) )
func TestGetStrDays(t *testing.T) { func TestGetStrDays(t *testing.T) {
@@ -27,6 +29,10 @@ func TestCalc(t *testing.T) {
i := math.Round(386 * (float64(85) / 100)) i := math.Round(386 * (float64(85) / 100))
fmt.Println(i) 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) { func TestCalc1(t *testing.T) {
i := float64(85) / 100 i := float64(85) / 100
fmt.Println(i) fmt.Println(i)
@@ -50,7 +56,53 @@ func TestCalc5(t *testing.T) {
float := strconv.FormatFloat(float64(a/10.0), 'f', 1, 64) float := strconv.FormatFloat(float64(a/10.0), 'f', 1, 64)
fmt.Printf(float) 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) { func TestMath(t *testing.T) {
var a = int(RoundToOneDecimalPlace(float64(150)*(95/100.0)) * 10) var a = int(RoundToOneDecimalPlace(float64(150)*(95/100.0)) * 10)
fmt.Println(a) 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
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)
}
}
+80
View File
@@ -2,12 +2,22 @@ package utils
import ( import (
"fmt" "fmt"
"github.com/bwmarrin/snowflake"
"github.com/dgb8901/go-wechat-miniapp-sdk/config" "github.com/dgb8901/go-wechat-miniapp-sdk/config"
"github.com/dgb8901/go-wechat-miniapp-sdk/models/response" "github.com/dgb8901/go-wechat-miniapp-sdk/models/response"
"github.com/dgb8901/go-wechat-miniapp-sdk/service" "github.com/dgb8901/go-wechat-miniapp-sdk/service"
"github.com/spf13/viper" "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/g"
"pet-house.com/core/server/viper_server" "pet-house.com/core/server/viper_server"
"pet-house.com/core/server/web"
"pet-house.com/core/server/zap_server"
) )
var CONFIG = WxConfig{ var CONFIG = WxConfig{
@@ -16,6 +26,11 @@ var CONFIG = WxConfig{
Token: "", Token: "",
AesKey: "", AesKey: "",
MsgDataFormat: "", MsgDataFormat: "",
MchId: "",
MchCertificateSerialNumber: "",
MchAPIv3Key: "",
PrivateKeyPath: "",
WechatCert: "",
} }
type WxConfig struct { type WxConfig struct {
@@ -24,6 +39,11 @@ type WxConfig struct {
Token string `mapstructure:"token" json:"token" yaml:"token"` Token string `mapstructure:"token" json:"token" yaml:"token"`
AesKey string `mapstructure:"aesKey" json:"aesKey" yaml:"aesKey"` AesKey string `mapstructure:"aesKey" json:"aesKey" yaml:"aesKey"`
MsgDataFormat string `mapstructure:"msgDataFormat" json:"msgDataFormat" yaml:"msgDataFormat"` 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 // getViperConfig get viper config
@@ -49,12 +69,18 @@ func getViperConfig() viper_server.ViperConfig {
"token": "` + CONFIG.Token + `", "token": "` + CONFIG.Token + `",
"aesKey": "` + CONFIG.AesKey + `", "aesKey": "` + CONFIG.AesKey + `",
"msgDataFormat": ` + CONFIG.MsgDataFormat + ` "msgDataFormat": ` + CONFIG.MsgDataFormat + `
"mchId": ` + CONFIG.MchId + `
"mchCertificateSerialNumber": ` + CONFIG.MchCertificateSerialNumber + `
"mchAPIv3Key": ` + CONFIG.MchAPIv3Key + `
"privateKeyPath": ` + CONFIG.PrivateKeyPath + `
"wechatCert": ` + CONFIG.WechatCert + `
}`), }`),
} }
} }
type WechatHelper struct { type WechatHelper struct {
wechatService *service.WxaService wechatService *service.WxaService
wechatPayClient *core.Client
} }
var wxHelper = &WechatHelper{} var wxHelper = &WechatHelper{}
@@ -71,12 +97,36 @@ func WechatInit() {
wxaConfig := config.NewInMemory(cfg) wxaConfig := config.NewInMemory(cfg)
wxaService := service.NewService(wxaConfig) wxaService := service.NewService(wxaConfig)
wxHelper.wechatService = wxaService 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 { func getWxaService() *service.WxaService {
return wxHelper.wechatService return wxHelper.wechatService
} }
func GetWxPayService() *core.Client {
return wxHelper.wechatPayClient
}
type WxUserInfo struct { type WxUserInfo struct {
OpenId string OpenId string
UnionId string UnionId string
@@ -89,3 +139,33 @@ func GetWxUserInfo(code string) (*response.JsCode2SessionResult, error) {
} }
return info, nil 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))
}
+1 -1
View File
@@ -21,7 +21,7 @@ type otheraccounts struct {
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
CONFIG.DbName = "pikauser" CONFIG.DbName = "pikauser"
CONFIG.Path = "172.31.65.221:3306" CONFIG.Ip = "172.31.65.221"
CONFIG.Password = "qC#5Lp%9AF=6BmR5Ny!6aaabbb" CONFIG.Password = "qC#5Lp%9AF=6BmR5Ny!6aaabbb"
CONFIG.Username = "pikauser_dev" CONFIG.Username = "pikauser_dev"