修改了时间计算方法
This commit is contained in:
parent
3dce6ebfc8
commit
6137740b13
@ -266,27 +266,28 @@ func (r *Coupon) AddSystemCoupon(c *gin.Context) {
|
||||
|
||||
// 时间区间
|
||||
if req.ValidStartTime != nil {
|
||||
// 获取本地时区
|
||||
location, err := time.LoadLocation("Local")
|
||||
// 字符串时间转localtime
|
||||
validStartTime, err := utils.StrToLocalTime(*req.ValidStartTime)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("新增失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
t, err := time.ParseInLocation("2006-01-02 15:04:05", *req.ValidStartTime, location)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("新增失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
validStartTime := model.LocalTime(t)
|
||||
|
||||
coupon.ValidStartTime = &validStartTime
|
||||
coupon.ValidStartTime = validStartTime
|
||||
}
|
||||
|
||||
if req.ValidEndTime != nil {
|
||||
// 字符串时间转localtime
|
||||
validEndTime, err := utils.StrToLocalTime(*req.ValidEndTime)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("新增失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
coupon.ValidEndTime = validEndTime
|
||||
|
||||
// 获取本地时区
|
||||
location, err := time.LoadLocation("Local")
|
||||
if err != nil {
|
||||
@ -295,21 +296,11 @@ func (r *Coupon) AddSystemCoupon(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
t, err := time.ParseInLocation("2006-01-02 15:04:05", *req.ValidEndTime, location)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("新增失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
validEndTime := model.LocalTime(t)
|
||||
coupon.ValidEndTime = &validEndTime
|
||||
|
||||
// 检测结束时间-不允许当天结束
|
||||
now := time.Now()
|
||||
year, month, day := now.Date()
|
||||
endOfDay := time.Date(year, month, day, 23, 59, 59, 0, location)
|
||||
if time.Time(validEndTime).Before(endOfDay) {
|
||||
if time.Time(*validEndTime).Before(endOfDay) {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("优惠卷过期时间最低设置为明天", c)
|
||||
return
|
||||
|
||||
@ -10,7 +10,6 @@ import (
|
||||
"hepa-calc-admin-api/global"
|
||||
"hepa-calc-admin-api/utils"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type OrderSingle struct{}
|
||||
@ -49,34 +48,14 @@ func (b *OrderSingle) GetOrderSinglePage(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 获取单项配置
|
||||
systemSingleDao := dao.SystemSingleDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
systemSingle, err := systemSingleDao.GetSystemSingle(maps)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("内部错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetOrderSingleListDto(orderSingles)
|
||||
|
||||
for _, singleDto := range g {
|
||||
// 有效时间
|
||||
var validTime *time.Time
|
||||
|
||||
// 计算有效期
|
||||
if singleDto.IsMember == 1 {
|
||||
validTime = singleDto.MemberExpireDate
|
||||
} else {
|
||||
if singleDto.PayTime != nil {
|
||||
payTime := singleDto.PayTime.Add(time.Duration(systemSingle.ValidDays) * 24 * time.Hour)
|
||||
validTime = &payTime
|
||||
}
|
||||
singleDto.LoadValidDate(singleDto.MemberExpireDate)
|
||||
}
|
||||
|
||||
singleDto.LoadValidDate(validTime)
|
||||
}
|
||||
|
||||
result := make(map[string]interface{})
|
||||
@ -236,27 +215,9 @@ func (b *OrderSingle) GetOrderSingle(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 获取单项配置
|
||||
systemSingleDao := dao.SystemSingleDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
systemSingle, err := systemSingleDao.GetSystemSingle(maps)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("内部错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 有效时间
|
||||
var validTime *time.Time
|
||||
|
||||
// 计算有效期
|
||||
if orderSingle.User.IsMember == 1 {
|
||||
validTime = orderSingle.User.MemberExpireDate
|
||||
} else {
|
||||
if orderSingle.PayTime != nil {
|
||||
payTime := orderSingle.PayTime.Add(time.Duration(systemSingle.ValidDays) * 24 * time.Hour)
|
||||
validTime = &payTime
|
||||
}
|
||||
orderSingle.ValidDate = orderSingle.User.MemberExpireDate
|
||||
}
|
||||
|
||||
g := dto.GetOrderSingleDto(orderSingle)
|
||||
@ -264,9 +225,6 @@ func (b *OrderSingle) GetOrderSingle(c *gin.Context) {
|
||||
// 加载题目数据
|
||||
g.LoadQuestion(orderSingle.Question)
|
||||
|
||||
// 加载到期时间
|
||||
g.LoadValidDate(validTime)
|
||||
|
||||
// 加载用户数据
|
||||
g.LoadUserAttr(orderSingle.User)
|
||||
|
||||
|
||||
@ -287,7 +287,8 @@ func (b *Public) GetIndexData(c *gin.Context) {
|
||||
}
|
||||
|
||||
for _, orderSingle := range orderSingles {
|
||||
date := orderSingle.PayTime.Format("2006-01-02")
|
||||
payTime := time.Time(*orderSingle.PayTime)
|
||||
date := payTime.Format("2006-01-02")
|
||||
results[date]++
|
||||
}
|
||||
}
|
||||
@ -310,7 +311,8 @@ func (b *Public) GetIndexData(c *gin.Context) {
|
||||
}
|
||||
|
||||
for _, orderMember := range orderMembers {
|
||||
date := orderMember.PayTime.Format("2006-01-02")
|
||||
payTime := time.Time(*orderMember.PayTime)
|
||||
date := payTime.Format("2006-01-02")
|
||||
results[date]++
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,7 +11,6 @@ import (
|
||||
"hepa-calc-admin-api/global"
|
||||
"hepa-calc-admin-api/utils"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Question struct{}
|
||||
@ -242,14 +241,8 @@ func (b *Question) PutQuestion(c *gin.Context) {
|
||||
|
||||
// 优惠截止时间
|
||||
if req.DiscountEndTime != nil {
|
||||
// 获取本地时区
|
||||
location, err := time.LoadLocation("Local")
|
||||
if err != nil {
|
||||
responses.FailWithMessage("优惠截止时间错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
discountEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", *req.DiscountEndTime, location)
|
||||
// 字符串时间转localtime
|
||||
discountEndTime, err := utils.StrToLocalTime(*req.DiscountEndTime)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("优惠截止时间错误", c)
|
||||
return
|
||||
@ -258,7 +251,7 @@ func (b *Question) PutQuestion(c *gin.Context) {
|
||||
if question.DiscountEndTime == nil {
|
||||
questionData["discount_end_time"] = discountEndTime
|
||||
} else {
|
||||
if *question.DiscountEndTime != discountEndTime {
|
||||
if *question.DiscountEndTime != *discountEndTime {
|
||||
questionData["discount_end_time"] = discountEndTime
|
||||
}
|
||||
}
|
||||
@ -384,22 +377,15 @@ func (b *Question) AddQuestion(c *gin.Context) {
|
||||
|
||||
// 处理优惠截止时间
|
||||
if req.DiscountEndTime != nil {
|
||||
// 获取本地时区
|
||||
location, err := time.LoadLocation("Local")
|
||||
// 字符串时间转localtime
|
||||
discountEndTime, err := utils.StrToLocalTime(*req.DiscountEndTime)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("优惠截止时间错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
discountEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", *req.DiscountEndTime, location)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("优惠截止时间错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
question.DiscountEndTime = &discountEndTime
|
||||
question.DiscountEndTime = discountEndTime
|
||||
}
|
||||
|
||||
questionDao := dao.QuestionDao{}
|
||||
|
||||
@ -10,7 +10,6 @@ import (
|
||||
"hepa-calc-admin-api/global"
|
||||
"hepa-calc-admin-api/utils"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SystemMember struct{}
|
||||
@ -138,14 +137,8 @@ func (b *SystemMember) PutSystemMember(c *gin.Context) {
|
||||
|
||||
// 优惠截止时间
|
||||
if req.DiscountEndTime != nil {
|
||||
// 获取本地时区
|
||||
location, err := time.LoadLocation("Local")
|
||||
if err != nil {
|
||||
responses.FailWithMessage("优惠截止时间错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
discountEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", *req.DiscountEndTime, location)
|
||||
// 字符串时间转localtime
|
||||
discountEndTime, err := utils.StrToLocalTime(*req.DiscountEndTime)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("优惠截止时间错误", c)
|
||||
return
|
||||
@ -154,7 +147,7 @@ func (b *SystemMember) PutSystemMember(c *gin.Context) {
|
||||
if systemMember.DiscountEndTime == nil {
|
||||
systemMemberData["discount_end_time"] = discountEndTime
|
||||
} else {
|
||||
if *systemMember.DiscountEndTime != discountEndTime {
|
||||
if *systemMember.DiscountEndTime != *discountEndTime {
|
||||
systemMemberData["discount_end_time"] = discountEndTime
|
||||
}
|
||||
}
|
||||
@ -228,22 +221,15 @@ func (b *SystemMember) AddSystemMember(c *gin.Context) {
|
||||
|
||||
// 处理优惠截止时间
|
||||
if req.DiscountEndTime != nil {
|
||||
// 获取本地时区
|
||||
location, err := time.LoadLocation("Local")
|
||||
// 字符串时间转localtime
|
||||
discountEndTime, err := utils.StrToLocalTime(*req.DiscountEndTime)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("优惠截止时间错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
discountEndTime, err := time.ParseInLocation("2006-01-02 15:04:05", *req.DiscountEndTime, location)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("优惠截止时间错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
systemMember.DiscountEndTime = &discountEndTime
|
||||
systemMember.DiscountEndTime = discountEndTime
|
||||
}
|
||||
|
||||
systemMemberDao := dao.SystemMemberDao{}
|
||||
|
||||
@ -1,68 +0,0 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hepa-calc-admin-api/api/model"
|
||||
"hepa-calc-admin-api/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
type WxDto struct {
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
UserName string `json:"user_name"` // 用户名称
|
||||
Mobile string `json:"mobile"` // 手机号
|
||||
OpenId string `json:"open_id"` // 用户微信标识
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
IsMember int `json:"is_member"` // 是否会员(0:否 1:是)
|
||||
MemberExpireDate *time.Time `json:"member_expire_date"` // 会员到期时间(非会员时为null)
|
||||
Token string `json:"token"` // token
|
||||
}
|
||||
|
||||
type MobileDto struct {
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
UserName string `json:"user_name"` // 用户名称
|
||||
Mobile string `json:"mobile"` // 手机号
|
||||
OpenId string `json:"open_id"` // 用户微信标识
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
IsMember int `json:"is_member"` // 是否会员(0:否 1:是)
|
||||
MemberExpireDate *time.Time `json:"member_expire_date"` // 会员到期时间(非会员时为null)
|
||||
Token string `json:"token"` // token
|
||||
}
|
||||
|
||||
// LoginWxDto 微信登陆
|
||||
func LoginWxDto(m *model.User) *WxDto {
|
||||
return &WxDto{
|
||||
UserId: fmt.Sprintf("%d", m.UserId),
|
||||
UserName: m.UserName,
|
||||
Mobile: m.Mobile,
|
||||
OpenId: m.OpenId,
|
||||
Avatar: utils.AddOssDomain(m.Avatar),
|
||||
IsMember: m.IsMember,
|
||||
MemberExpireDate: m.MemberExpireDate,
|
||||
}
|
||||
}
|
||||
|
||||
// LoginMobileDto 手机号登陆
|
||||
func LoginMobileDto(m *model.User) *MobileDto {
|
||||
return &MobileDto{
|
||||
UserId: fmt.Sprintf("%d", m.UserId),
|
||||
UserName: m.UserName,
|
||||
Mobile: m.Mobile,
|
||||
OpenId: m.OpenId,
|
||||
Avatar: utils.AddOssDomain(m.Avatar),
|
||||
IsMember: m.IsMember,
|
||||
MemberExpireDate: m.MemberExpireDate,
|
||||
}
|
||||
}
|
||||
|
||||
// LoadToken 加载token
|
||||
func (r *WxDto) LoadToken(token string) *WxDto {
|
||||
r.Token = token
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadToken 加载token
|
||||
func (r *MobileDto) LoadToken(token string) *MobileDto {
|
||||
r.Token = token
|
||||
return r
|
||||
}
|
||||
@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"hepa-calc-admin-api/api/model"
|
||||
"hepa-calc-admin-api/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
// OrderMemberDto 订单-会员
|
||||
@ -16,7 +15,7 @@ type OrderMemberDto struct {
|
||||
IsDelete int `json:"is_delete"` // 用户删除状态(0:否 1:是)
|
||||
PayChannel int `json:"pay_channel"` // 支付渠道(1:h5支付 2:app支付 3:会员支付)
|
||||
PayStatus int `json:"pay_status"` // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
PayTime *time.Time `json:"pay_time"` // 支付时间
|
||||
PayTime *model.LocalTime `json:"pay_time"` // 支付时间
|
||||
RefundStatus int `json:"refund_status"` // 订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常 7:部分退款)
|
||||
OrderNo string `json:"order_no"` // 系统订单编号
|
||||
EscrowTradeNo string `json:"escrow_trade_no"` // 第三方支付流水号
|
||||
@ -24,7 +23,7 @@ type OrderMemberDto struct {
|
||||
CouponAmountTotal float64 `json:"coupon_amount_total"` // 优惠卷总金额
|
||||
PaymentAmountTotal float64 `json:"payment_amount_total"` // 实际付款金额
|
||||
CancelStatus int `json:"cancel_status"` // 取消状态(0:否 1:是)
|
||||
CancelTime *time.Time `json:"cancel_time"` // 订单取消时间
|
||||
CancelTime *model.LocalTime `json:"cancel_time"` // 订单取消时间
|
||||
CancelRemarks string `json:"cancel_remarks"` // 取消订单备注
|
||||
OrderRemarks string `json:"order_remarks"` // 订单备注
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
|
||||
@ -4,38 +4,37 @@ import (
|
||||
"fmt"
|
||||
"hepa-calc-admin-api/api/model"
|
||||
"hepa-calc-admin-api/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
// OrderSingleDto 订单-单项
|
||||
type OrderSingleDto struct {
|
||||
OrderId string `json:"order_id"` // 主键id
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
QuestionId string `json:"question_id"` // 问题id
|
||||
OrderStatus int `json:"order_status"` // 订单状态(1:待支付 2:已完成 3:已取消)
|
||||
IsDelete int `json:"is_delete"` // 用户删除状态(0:否 1:是)
|
||||
PayChannel int `json:"pay_channel"` // 支付渠道(1:h5支付 2:app支付 3:会员支付)
|
||||
PayStatus int `json:"pay_status"` // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
PayTime *time.Time `json:"pay_time"` // 支付时间
|
||||
RefundStatus int `json:"refund_status"` // 订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常 7:部分退款)
|
||||
OrderNo string `json:"order_no"` // 系统订单编号
|
||||
EscrowTradeNo string `json:"escrow_trade_no"` // 第三方支付流水号
|
||||
AmountTotal float64 `json:"amount_total"` // 订单金额
|
||||
CouponAmountTotal float64 `json:"coupon_amount_total"` // 优惠卷总金额
|
||||
PaymentAmountTotal float64 `json:"payment_amount_total"` // 实际付款金额
|
||||
CancelStatus int `json:"cancel_status"` // 取消状态(0:否 1:是)
|
||||
CancelTime *time.Time `json:"cancel_time"` // 订单取消时间
|
||||
CancelRemarks string `json:"cancel_remarks"` // 取消订单备注
|
||||
OrderRemarks string `json:"order_remarks"` // 订单备注
|
||||
Answer string `json:"answer"` // 算一算答案
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
Question *QuestionDto `json:"question"` // 问题
|
||||
ValidDate model.LocalTime `json:"valid_date"` // 到期时间
|
||||
UserName string `json:"user_name"` // 用户名称
|
||||
Avatar string `json:"avatar"` // 用户头像
|
||||
IsMember int `json:"is_member"` // 是否会员(0:否 1:是)
|
||||
MemberExpireDate *time.Time `json:"member_expire_date"` // 用户会员到期时间(非会员时为null)
|
||||
OrderId string `json:"order_id"` // 主键id
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
QuestionId string `json:"question_id"` // 问题id
|
||||
OrderStatus int `json:"order_status"` // 订单状态(1:待支付 2:已完成 3:已取消)
|
||||
IsDelete int `json:"is_delete"` // 用户删除状态(0:否 1:是)
|
||||
PayChannel int `json:"pay_channel"` // 支付渠道(1:h5支付 2:app支付 3:会员支付)
|
||||
PayStatus int `json:"pay_status"` // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
PayTime *model.LocalTime `json:"pay_time"` // 支付时间
|
||||
RefundStatus int `json:"refund_status"` // 订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常 7:部分退款)
|
||||
OrderNo string `json:"order_no"` // 系统订单编号
|
||||
EscrowTradeNo string `json:"escrow_trade_no"` // 第三方支付流水号
|
||||
AmountTotal float64 `json:"amount_total"` // 订单金额
|
||||
CouponAmountTotal float64 `json:"coupon_amount_total"` // 优惠卷总金额
|
||||
PaymentAmountTotal float64 `json:"payment_amount_total"` // 实际付款金额
|
||||
CancelStatus int `json:"cancel_status"` // 取消状态(0:否 1:是)
|
||||
CancelTime *model.LocalTime `json:"cancel_time"` // 订单取消时间
|
||||
CancelRemarks string `json:"cancel_remarks"` // 取消订单备注
|
||||
ValidDate *model.LocalTime `json:"valid_date"` // 到期时间
|
||||
OrderRemarks string `json:"order_remarks"` // 订单备注
|
||||
Answer string `json:"answer"` // 算一算答案
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
Question *QuestionDto `json:"question"` // 问题
|
||||
UserName string `json:"user_name"` // 用户名称
|
||||
Avatar string `json:"avatar"` // 用户头像
|
||||
IsMember int `json:"is_member"` // 是否会员(0:否 1:是)
|
||||
MemberExpireDate *model.LocalTime `json:"member_expire_date"` // 用户会员到期时间(非会员时为null)
|
||||
}
|
||||
|
||||
// GetOrderSingleListDto 列表
|
||||
@ -63,6 +62,7 @@ func GetOrderSingleListDto(m []*model.OrderSingle) []*OrderSingleDto {
|
||||
CancelStatus: v.CancelStatus,
|
||||
CancelTime: v.CancelTime,
|
||||
CancelRemarks: v.CancelRemarks,
|
||||
ValidDate: v.ValidDate,
|
||||
OrderRemarks: v.OrderRemarks,
|
||||
Answer: v.Answer,
|
||||
CreatedAt: v.CreatedAt,
|
||||
@ -123,9 +123,9 @@ func (r *OrderSingleDto) LoadQuestion(m *model.Question) *OrderSingleDto {
|
||||
}
|
||||
|
||||
// LoadValidDate 加载到期时间
|
||||
func (r *OrderSingleDto) LoadValidDate(m *time.Time) *OrderSingleDto {
|
||||
if m != nil {
|
||||
r.ValidDate = model.LocalTime(*m)
|
||||
func (r *OrderSingleDto) LoadValidDate(t *model.LocalTime) *OrderSingleDto {
|
||||
if t != nil {
|
||||
r.ValidDate = t
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ func GetSystemMemberListDto(m []*model.SystemMember) []*SystemMemberDto {
|
||||
MemberDays: v.MemberDays,
|
||||
Price: v.Price,
|
||||
DiscountPrice: v.DiscountPrice,
|
||||
DiscountEndTime: (*model.LocalTime)(v.DiscountEndTime),
|
||||
DiscountEndTime: v.DiscountEndTime,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
@ -48,7 +48,7 @@ func GetSystemMemberDto(m *model.SystemMember) *SystemMemberDto {
|
||||
MemberDays: m.MemberDays,
|
||||
Price: m.Price,
|
||||
DiscountPrice: m.DiscountPrice,
|
||||
DiscountEndTime: (*model.LocalTime)(m.DiscountEndTime),
|
||||
DiscountEndTime: m.DiscountEndTime,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
|
||||
@ -4,31 +4,30 @@ import (
|
||||
"fmt"
|
||||
"hepa-calc-admin-api/api/model"
|
||||
"hepa-calc-admin-api/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
// UserDto 用户表
|
||||
type UserDto struct {
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
UserName string `json:"user_name"` // 用户名称
|
||||
Mobile string `json:"mobile"` // 手机号
|
||||
UserStatus int `json:"user_status"` // 状态(1:正常 2:禁用)
|
||||
RegisterSource int `json:"register_source"` // 注册来源(1:app注册 2:公众号注册)
|
||||
OpenId string `json:"open_id"` // 用户微信标识
|
||||
UnionId string `json:"union_id"` // 微信开放平台标识
|
||||
Age *uint `json:"age"` // 年龄
|
||||
Sex uint `json:"sex"` // 性别(0:未知 1:男 2:女)
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
IsMember int `json:"is_member"` // 是否会员(0:否 1:是)
|
||||
MemberExpireDate *time.Time `json:"member_expire_date"` // 会员到期时间(非会员时为null)
|
||||
SingleSubmitCount int `json:"single_submit_count"` // 单项提交次数(提交个人信息进行了算算的人次)
|
||||
SinglePayCount int `json:"single_pay_count"` // 单项支付次数(查看报告的人次)
|
||||
MemberBuyCount int `json:"member_buy_count"` // 会员购买次数
|
||||
LoginAt model.LocalTime `json:"login_at"` // 登陆时间
|
||||
LoginIp string `json:"login_ip"` // 登陆ip
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
IsInfoComplete int `json:"is_info_complete"` // 信息完善状态 0:否 1:是
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
UserName string `json:"user_name"` // 用户名称
|
||||
Mobile string `json:"mobile"` // 手机号
|
||||
UserStatus int `json:"user_status"` // 状态(1:正常 2:禁用)
|
||||
RegisterSource int `json:"register_source"` // 注册来源(1:app注册 2:公众号注册)
|
||||
OpenId string `json:"open_id"` // 用户微信标识
|
||||
UnionId string `json:"union_id"` // 微信开放平台标识
|
||||
Age *uint `json:"age"` // 年龄
|
||||
Sex uint `json:"sex"` // 性别(0:未知 1:男 2:女)
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
IsMember int `json:"is_member"` // 是否会员(0:否 1:是)
|
||||
MemberExpireDate *model.LocalTime `json:"member_expire_date"` // 会员到期时间(非会员时为null)
|
||||
SingleSubmitCount int `json:"single_submit_count"` // 单项提交次数(提交个人信息进行了算算的人次)
|
||||
SinglePayCount int `json:"single_pay_count"` // 单项支付次数(查看报告的人次)
|
||||
MemberBuyCount int `json:"member_buy_count"` // 会员购买次数
|
||||
LoginAt model.LocalTime `json:"login_at"` // 登陆时间
|
||||
LoginIp string `json:"login_ip"` // 登陆ip
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
IsInfoComplete int `json:"is_info_complete"` // 信息完善状态 0:否 1:是
|
||||
}
|
||||
|
||||
// GetUserListDto 列表
|
||||
|
||||
@ -15,7 +15,7 @@ type OrderMember struct {
|
||||
IsDelete int `gorm:"column:is_delete;type:tinyint(1);default:0;comment:用户删除状态(0:否 1:是)" json:"is_delete"`
|
||||
PayChannel int `gorm:"column:pay_channel;type:tinyint(1);comment:支付渠道(1:h5支付 2:app支付 3:会员支付);NOT NULL" json:"pay_channel"`
|
||||
PayStatus int `gorm:"column:pay_status;type:tinyint(1);default:1;comment:支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款);NOT NULL" json:"pay_status"`
|
||||
PayTime *time.Time `gorm:"column:pay_time;type:datetime;comment:支付时间" json:"pay_time"`
|
||||
PayTime *LocalTime `gorm:"column:pay_time;type:datetime;comment:支付时间" json:"pay_time"`
|
||||
RefundStatus int `gorm:"column:refund_status;type:tinyint(1);default:0;comment:订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常 7:部分退款);NOT NULL" json:"refund_status"`
|
||||
OrderNo string `gorm:"column:order_no;type:varchar(30);comment:系统订单编号;NOT NULL" json:"order_no"`
|
||||
EscrowTradeNo string `gorm:"column:escrow_trade_no;type:varchar(100);comment:第三方支付流水号;NOT NULL" json:"escrow_trade_no"`
|
||||
@ -23,7 +23,7 @@ type OrderMember struct {
|
||||
CouponAmountTotal float64 `gorm:"column:coupon_amount_total;type:decimal(10,2);default:0.00;comment:优惠卷总金额" json:"coupon_amount_total"`
|
||||
PaymentAmountTotal float64 `gorm:"column:payment_amount_total;type:decimal(10,2);default:0.00;comment:实际付款金额" json:"payment_amount_total"`
|
||||
CancelStatus int `gorm:"column:cancel_status;type:tinyint(1);default:0;comment:取消状态(0:否 1:是)" json:"cancel_status"`
|
||||
CancelTime *time.Time `gorm:"column:cancel_time;type:datetime;comment:订单取消时间" json:"cancel_time"`
|
||||
CancelTime *LocalTime `gorm:"column:cancel_time;type:datetime;comment:订单取消时间" json:"cancel_time"`
|
||||
CancelRemarks string `gorm:"column:cancel_remarks;type:varchar(255);comment:取消订单备注" json:"cancel_remarks"`
|
||||
OrderRemarks string `gorm:"column:order_remarks;type:varchar(255);comment:订单备注" json:"order_remarks"`
|
||||
Model
|
||||
|
||||
@ -15,7 +15,7 @@ type OrderSingle struct {
|
||||
IsDelete int `gorm:"column:is_delete;type:tinyint(1);default:0;comment:用户删除状态(0:否 1:是)" json:"is_delete"`
|
||||
PayChannel int `gorm:"column:pay_channel;type:tinyint(1);comment:支付渠道(1:h5支付 2:app支付 3:会员支付);NOT NULL" json:"pay_channel"`
|
||||
PayStatus int `gorm:"column:pay_status;type:tinyint(1);default:1;comment:支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款);NOT NULL" json:"pay_status"`
|
||||
PayTime *time.Time `gorm:"column:pay_time;type:datetime;comment:支付时间" json:"pay_time"`
|
||||
PayTime *LocalTime `gorm:"column:pay_time;type:datetime;comment:支付时间" json:"pay_time"`
|
||||
RefundStatus int `gorm:"column:refund_status;type:tinyint(1);default:0;comment:订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常 7:部分退款);NOT NULL" json:"refund_status"`
|
||||
OrderNo string `gorm:"column:order_no;type:varchar(30);comment:系统订单编号;NOT NULL" json:"order_no"`
|
||||
EscrowTradeNo string `gorm:"column:escrow_trade_no;type:varchar(100);comment:第三方支付流水号;NOT NULL" json:"escrow_trade_no"`
|
||||
@ -23,8 +23,9 @@ type OrderSingle struct {
|
||||
CouponAmountTotal float64 `gorm:"column:coupon_amount_total;type:decimal(10,2);default:0.00;comment:优惠卷总金额" json:"coupon_amount_total"`
|
||||
PaymentAmountTotal float64 `gorm:"column:payment_amount_total;type:decimal(10,2);default:0.00;comment:实际付款金额" json:"payment_amount_total"`
|
||||
CancelStatus int `gorm:"column:cancel_status;type:tinyint(1);default:0;comment:取消状态(0:否 1:是)" json:"cancel_status"`
|
||||
CancelTime *time.Time `gorm:"column:cancel_time;type:datetime;comment:订单取消时间" json:"cancel_time"`
|
||||
CancelTime *LocalTime `gorm:"column:cancel_time;type:datetime;comment:订单取消时间" json:"cancel_time"`
|
||||
CancelRemarks string `gorm:"column:cancel_remarks;type:varchar(255);comment:取消订单备注" json:"cancel_remarks"`
|
||||
ValidDate *LocalTime `gorm:"column:valid_date;type:datetime;comment:到期时间" json:"valid_date"`
|
||||
OrderRemarks string `gorm:"column:order_remarks;type:varchar(255);comment:订单备注" json:"order_remarks"`
|
||||
Answer string `gorm:"column:answer;type:varchar(500);comment:算一算答案" json:"answer"`
|
||||
Model
|
||||
|
||||
@ -20,7 +20,7 @@ type Question struct {
|
||||
PayCount int `gorm:"column:pay_count;type:int(5);default:0;comment:支付次数(查看报告的人次)" json:"pay_count"`
|
||||
Price float64 `gorm:"column:price;type:decimal(10,2) unsigned;default:0.00;comment:价格(原价)" json:"price"`
|
||||
DiscountPrice *float64 `gorm:"column:discount_price;type:decimal(10,2);comment:优惠价格" json:"discount_price"`
|
||||
DiscountEndTime *time.Time `gorm:"column:discount_end_time;type:datetime;comment:优惠截止时间" json:"discount_end_time"`
|
||||
DiscountEndTime *LocalTime `gorm:"column:discount_end_time;type:datetime;comment:优惠截止时间" json:"discount_end_time"`
|
||||
QuestionBrief string `gorm:"column:question_brief;type:text;comment:问题介绍" json:"question_brief"`
|
||||
QuestionExplain string `gorm:"column:question_explain;type:text;comment:问题解释/科普" json:"question_explain"`
|
||||
Model
|
||||
|
||||
@ -12,7 +12,7 @@ type SystemMember struct {
|
||||
MemberDays uint `gorm:"column:member_days;type:int(10) unsigned;default:0;comment:会员天数" json:"member_days"`
|
||||
Price float64 `gorm:"column:price;type:decimal(10,2);default:0.00;comment:价格(原价)" json:"price"`
|
||||
DiscountPrice *float64 `gorm:"column:discount_price;type:decimal(10,2);comment:优惠价格" json:"discount_price"`
|
||||
DiscountEndTime *time.Time `gorm:"column:discount_end_time;type:datetime;comment:优惠截止时间" json:"discount_end_time"`
|
||||
DiscountEndTime *LocalTime `gorm:"column:discount_end_time;type:datetime;comment:优惠截止时间" json:"discount_end_time"`
|
||||
Model
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ type User struct {
|
||||
Sex int `gorm:"column:sex;type:tinyint(1) unsigned;default:0;comment:性别(0:未知 1:男 2:女)" json:"sex"`
|
||||
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`
|
||||
IsMember int `gorm:"column:is_member;type:tinyint(1);default:0;comment:是否会员(0:否 1:是)" json:"is_member"`
|
||||
MemberExpireDate *time.Time `gorm:"column:member_expire_date;type:datetime;comment:会员到期时间(非会员时为null)" json:"member_expire_date"`
|
||||
MemberExpireDate *LocalTime `gorm:"column:member_expire_date;type:datetime;comment:会员到期时间(非会员时为null)" json:"member_expire_date"`
|
||||
SingleSubmitCount int `gorm:"column:single_submit_count;type:int(5);default:0;comment:单项提交次数(提交个人信息进行了算算的人次)" json:"single_submit_count"`
|
||||
SinglePayCount int `gorm:"column:single_pay_count;type:int(5);default:0;comment:单项支付次数(查看报告的人次)" json:"single_pay_count"`
|
||||
MemberBuyCount int `gorm:"column:member_buy_count;type:int(5);default:0;comment:会员购买次数" json:"member_buy_count"`
|
||||
|
||||
@ -122,8 +122,6 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
|
||||
// 操作单项订单删除状态
|
||||
singleGroup.PUT("/delete/:order_id", api.OrderSingle.PutOrderSingleDeleteStatus)
|
||||
|
||||
// 获取单项订单操作结果
|
||||
}
|
||||
|
||||
// 会员订单
|
||||
|
||||
@ -10,7 +10,6 @@ import (
|
||||
"hepa-calc-admin-api/api/dao"
|
||||
"hepa-calc-admin-api/api/model"
|
||||
"hepa-calc-admin-api/config"
|
||||
"hepa-calc-admin-api/extend/rabbitMq"
|
||||
"hepa-calc-admin-api/extend/weChat"
|
||||
"hepa-calc-admin-api/global"
|
||||
"hepa-calc-admin-api/utils"
|
||||
@ -20,190 +19,6 @@ import (
|
||||
type OrderSingleService struct {
|
||||
}
|
||||
|
||||
// AddOrderSingle 创建单项订单
|
||||
// payChannel:支付渠道(1:h5支付 2:app支付 3:会员支付)
|
||||
func (r *OrderSingleService) AddOrderSingle(tx *gorm.DB, UserId, QuestionId int64, UserCouponId *int64, payChannel int, orderPrice float64) (orderSingle *model.OrderSingle, err error) {
|
||||
// 检测并发请求
|
||||
redisKey := "AddOrderSingle" + fmt.Sprintf("%d", UserId) + fmt.Sprintf("%d", QuestionId)
|
||||
res, _ := global.Redis.Get(context.Background(), redisKey).Result()
|
||||
if res != "" {
|
||||
return nil, errors.New("请勿重复操作")
|
||||
}
|
||||
|
||||
defer func(redisKey string) {
|
||||
global.Redis.Del(context.Background(), redisKey)
|
||||
}(redisKey)
|
||||
|
||||
// 添加缓存
|
||||
_, err = global.Redis.Set(context.Background(), redisKey, "1", (10)*time.Second).Result()
|
||||
if err != nil {
|
||||
return nil, errors.New("生成订单失败")
|
||||
}
|
||||
|
||||
// 获取题目数据
|
||||
questionDao := dao.QuestionDao{}
|
||||
question, err := questionDao.GetQuestionById(QuestionId)
|
||||
if err != nil {
|
||||
return nil, errors.New("题目异常")
|
||||
}
|
||||
|
||||
// 检测题目
|
||||
questionService := &QuestionService{}
|
||||
isNormal, err := questionService.CheckQuestion(question)
|
||||
if err != nil || isNormal == false {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var amountTotal *float64 // 总金额
|
||||
var couponAmountTotal float64 // 优惠卷总金额
|
||||
var paymentAmountTotal float64 // 实际付款金额
|
||||
var orderStatus int // 订单状态(1:待支付 2:已完成 3:已取消)
|
||||
var payStatus int // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
var payTime *time.Time // 支付时间
|
||||
var escrowTradeNo string // 第三方支付流水号
|
||||
|
||||
// 获取问题最终价格
|
||||
amountTotal, err = questionService.GetUserBuyPrice(UserId, QuestionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if amountTotal == nil {
|
||||
return nil, errors.New("价格错误")
|
||||
}
|
||||
|
||||
// 检测用户优惠卷
|
||||
var userCoupon *model.UserCoupon
|
||||
if UserCouponId != nil {
|
||||
// 获取优惠卷数据
|
||||
UserCouponDao := dao.UserCouponDao{}
|
||||
userCoupon, err = UserCouponDao.GetUserCouponPreloadById(*UserCouponId)
|
||||
if err != nil {
|
||||
return nil, errors.New("优惠券异常")
|
||||
}
|
||||
|
||||
userCouponService := &UserCouponService{}
|
||||
isCanUse, err := userCouponService.CheckUserCoupon(userCoupon, QuestionId, 1, *amountTotal)
|
||||
if err != nil || isCanUse == false {
|
||||
return nil, errors.New("价格异常")
|
||||
}
|
||||
|
||||
// 优惠卷总金额
|
||||
couponAmountTotal = userCoupon.Coupon.CouponPrice
|
||||
}
|
||||
|
||||
// 会员支付
|
||||
if payChannel == 3 {
|
||||
paymentAmountTotal = 0 // 实际付款金额
|
||||
orderStatus = 2 // 订单状态(1:待支付 2:已完成 3:已取消)
|
||||
payStatus = 2 // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
|
||||
now := time.Now()
|
||||
payTime = &now // 支付时间
|
||||
|
||||
escrowTradeNo = "GD" + global.Snowflake.Generate().String() // 第三方支付流水号
|
||||
} else {
|
||||
// 实际付款金额
|
||||
paymentAmountTotal = *amountTotal - couponAmountTotal
|
||||
if orderPrice != paymentAmountTotal {
|
||||
return nil, errors.New("价格异常")
|
||||
}
|
||||
|
||||
orderStatus = 1 // 订单状态(1:待支付 2:已完成 3:已取消)
|
||||
payStatus = 1 // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
payTime = nil // 支付时间
|
||||
}
|
||||
|
||||
// 生成订单号
|
||||
orderNo := global.Snowflake.Generate().String()
|
||||
|
||||
// 创建订单
|
||||
orderSingle = &model.OrderSingle{
|
||||
UserId: UserId,
|
||||
QuestionId: QuestionId,
|
||||
OrderStatus: orderStatus,
|
||||
IsDelete: 0,
|
||||
PayChannel: payChannel,
|
||||
PayStatus: payStatus,
|
||||
PayTime: payTime,
|
||||
RefundStatus: 0,
|
||||
OrderNo: orderNo,
|
||||
EscrowTradeNo: escrowTradeNo,
|
||||
AmountTotal: *amountTotal,
|
||||
CouponAmountTotal: couponAmountTotal,
|
||||
PaymentAmountTotal: paymentAmountTotal,
|
||||
CancelStatus: 0,
|
||||
CancelTime: nil,
|
||||
CancelRemarks: "",
|
||||
OrderRemarks: "",
|
||||
}
|
||||
|
||||
orderSingleDao := dao.OrderSingleDao{}
|
||||
orderSingle, err = orderSingleDao.AddOrderSingle(tx, orderSingle)
|
||||
if err != nil {
|
||||
return nil, errors.New("订单创建失败")
|
||||
}
|
||||
|
||||
// 创建优惠卷表
|
||||
if userCoupon != nil {
|
||||
orderSingleCoupon := &model.OrderSingleCoupon{
|
||||
OrderId: orderSingle.OrderId,
|
||||
UserCouponId: *UserCouponId,
|
||||
CouponName: userCoupon.Coupon.CouponName,
|
||||
CouponUsePrice: userCoupon.Coupon.CouponPrice,
|
||||
}
|
||||
|
||||
orderSingleCouponDao := dao.OrderSingleCouponDao{}
|
||||
orderSingleCoupon, err = orderSingleCouponDao.AddOrderSingleCoupon(tx, orderSingleCoupon)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return nil, errors.New("订单创建失败")
|
||||
}
|
||||
|
||||
// 修改优惠卷使用状态
|
||||
userCouponDao := dao.UserCouponDao{}
|
||||
|
||||
userCouponData := make(map[string]interface{})
|
||||
userCouponData["user_coupon_status"] = 1
|
||||
userCouponData["coupon_use_date"] = time.Now().Format("2006-01-02 15:04:05")
|
||||
err := userCouponDao.EditUserCouponById(tx, userCoupon.UserCouponId, userCouponData)
|
||||
if err != nil {
|
||||
return nil, errors.New("订单创建失败")
|
||||
}
|
||||
}
|
||||
|
||||
// 增加未支付取消订单延迟队列
|
||||
if payChannel == 1 || payChannel == 2 {
|
||||
delay := 30 * time.Minute
|
||||
|
||||
if config.C.Env == "dev" {
|
||||
delay = 3 * time.Minute
|
||||
}
|
||||
|
||||
data := make(map[string]interface{})
|
||||
data["order_id"] = fmt.Sprintf("%d", orderSingle.OrderId)
|
||||
data["order_no"] = orderSingle.OrderNo
|
||||
data["user_id"] = fmt.Sprintf("%d", orderSingle.UserId)
|
||||
data["order_type"] = 1
|
||||
data["pay_channel"] = orderSingle.PayChannel
|
||||
|
||||
p := rabbitMq.PublishS{
|
||||
QueueName: "cancel.unpay.order.delay.queue",
|
||||
ExchangeName: "amqp.delay.direct",
|
||||
RoutingKey: "CancelUnPayOrder",
|
||||
Message: data,
|
||||
Delay: delay,
|
||||
}
|
||||
err := p.PublishWithDelay()
|
||||
if err != nil {
|
||||
utils.LogJsonErr("添加处理取消未支付订单队列失败:", err.Error())
|
||||
return nil, errors.New("订单创建失败")
|
||||
}
|
||||
}
|
||||
|
||||
return orderSingle, nil
|
||||
}
|
||||
|
||||
// CancelOrderSingle 取消单项订单
|
||||
// cancelReason:订单取消原因(1:主动取消 2:后台取消 3:支付超时取消)
|
||||
func (r *OrderSingleService) CancelOrderSingle(tx *gorm.DB, userId, orderId int64, cancelReason int) (bool, error) {
|
||||
|
||||
@ -143,42 +143,6 @@ func (r *QuestionService) GetQuestionBuyCount(userId, questionId int64) (c int,
|
||||
return int(buyCount), nil
|
||||
}
|
||||
|
||||
// GetUserBuyPrice 获取问题最终价格
|
||||
func (r *QuestionService) GetUserBuyPrice(userId, questionId int64) (p *float64, err error) {
|
||||
// 获取问题详情
|
||||
questionDao := dao.QuestionDao{}
|
||||
question, err := questionDao.GetQuestionById(questionId)
|
||||
if err != nil {
|
||||
return nil, errors.New("题目异常")
|
||||
}
|
||||
|
||||
// 检测用户是否购买过该问题
|
||||
isFirstBuy := r.CheckUserBuyQuestion(userId, questionId)
|
||||
if isFirstBuy == false {
|
||||
// 未购买过
|
||||
systemSingleDao := dao.SystemSingleDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
systemSingle, err := systemSingleDao.GetSystemSingle(maps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
p = &systemSingle.FirstTimePrice
|
||||
}
|
||||
|
||||
// 处理问题优惠价格
|
||||
if p == nil {
|
||||
p = r.HandleQuestionDiscountPrice(question.DiscountPrice, question.DiscountEndTime)
|
||||
}
|
||||
|
||||
if p == nil {
|
||||
p = &question.Price
|
||||
}
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// CheckQuestion 检测题目
|
||||
func (r *QuestionService) CheckQuestion(m *model.Question) (bool, error) {
|
||||
if m.QuestionStatus != 1 {
|
||||
|
||||
@ -3,9 +3,7 @@ package service
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"hepa-calc-admin-api/api/dao"
|
||||
"hepa-calc-admin-api/api/model"
|
||||
"hepa-calc-admin-api/extend/aliyun"
|
||||
"io"
|
||||
"math/rand"
|
||||
@ -59,20 +57,6 @@ func (r *UserService) HandleUserAvatar(wxAvatar string) (avatar string, err erro
|
||||
return ossPath, nil
|
||||
}
|
||||
|
||||
// CheckUserMember 检测用户会员
|
||||
func (r *UserService) CheckUserMember(user *model.User) bool {
|
||||
if user.IsMember == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
if user.MemberExpireDate.Before(now) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// CheckUserBuyOrderMember 检测用户是否购买过会员
|
||||
func (r *UserService) CheckUserBuyOrderMember(userId int64) bool {
|
||||
orderMemberDao := dao.OrderMemberDao{}
|
||||
@ -83,25 +67,3 @@ func (r *UserService) CheckUserBuyOrderMember(userId int64) bool {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// AddUserMemberValidDate 增加用户会员过期时间
|
||||
func (r *UserService) AddUserMemberValidDate(tx *gorm.DB, user *model.User, d int) bool {
|
||||
userData := make(map[string]interface{})
|
||||
if user.IsMember == 0 {
|
||||
userData["is_member"] = 1
|
||||
}
|
||||
|
||||
if user.MemberExpireDate == nil {
|
||||
userData["is_member"] = time.Now().Format("2006-01-02 15:04:05")
|
||||
} else {
|
||||
userData["is_member"] = user.MemberExpireDate.Add(time.Duration(d) * 24 * time.Hour)
|
||||
}
|
||||
|
||||
userDao := dao.UserDao{}
|
||||
err := userDao.EditUserById(tx, user.UserId, userData)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"hepa-calc-admin-api/api/dao"
|
||||
"hepa-calc-admin-api/api/dto"
|
||||
"hepa-calc-admin-api/api/model"
|
||||
"strings"
|
||||
"time"
|
||||
@ -116,93 +115,3 @@ func (r *UserCouponService) ReturnUserCoupon(tx *gorm.DB, userCouponId int64) bo
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// GetUserUsableQuestionCoupon 获取用户可使用优惠卷-单项
|
||||
func (r *UserCouponService) GetUserUsableQuestionCoupon(userId, questionId int64, amountTotal float64) (g []*dto.UserCouponDto, err error) {
|
||||
// 获取用户数据
|
||||
userDao := dao.UserDao{}
|
||||
user, err := userDao.GetUserById(userId)
|
||||
if err != nil || user == nil {
|
||||
return nil, errors.New("用户错误")
|
||||
}
|
||||
|
||||
// 检测用户会员
|
||||
userService := &UserService{}
|
||||
isMember := userService.CheckUserMember(user)
|
||||
if isMember == true {
|
||||
// 会员无需使用优惠卷
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// 获取用户优惠卷
|
||||
UserCouponDao := dao.UserCouponDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_id"] = userId
|
||||
maps["user_coupon_status"] = 0
|
||||
userCoupons, err := UserCouponDao.GetUserCouponPreloadList(maps)
|
||||
if err != nil {
|
||||
return nil, errors.New("优惠券异常")
|
||||
}
|
||||
|
||||
//定义返回数据
|
||||
var responses []*model.UserCoupon
|
||||
|
||||
for _, userCoupon := range userCoupons {
|
||||
isCanUse, err := r.CheckUserCoupon(userCoupon, questionId, 1, amountTotal)
|
||||
if err != nil || isCanUse == false {
|
||||
continue
|
||||
}
|
||||
|
||||
responses = append(responses, userCoupon)
|
||||
}
|
||||
|
||||
g = dto.GetUserCouponListDto(responses)
|
||||
|
||||
return g, nil
|
||||
}
|
||||
|
||||
// GetUserUsableMemberCoupon 获取用户可使用优惠卷-会员
|
||||
func (r *UserCouponService) GetUserUsableMemberCoupon(userId, systemMemberId int64, amountTotal float64) (g []*dto.UserCouponDto, err error) {
|
||||
// 获取用户数据
|
||||
userDao := dao.UserDao{}
|
||||
user, err := userDao.GetUserById(userId)
|
||||
if err != nil || user == nil {
|
||||
return nil, errors.New("用户错误")
|
||||
}
|
||||
|
||||
// 检测用户会员
|
||||
userService := &UserService{}
|
||||
isMember := userService.CheckUserMember(user)
|
||||
if isMember == true {
|
||||
// 会员无需使用优惠卷
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// 获取用户优惠卷
|
||||
UserCouponDao := dao.UserCouponDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_id"] = userId
|
||||
maps["user_coupon_status"] = 0
|
||||
userCoupons, err := UserCouponDao.GetUserCouponPreloadList(maps)
|
||||
if err != nil {
|
||||
return nil, errors.New("优惠券异常")
|
||||
}
|
||||
|
||||
//定义返回数据
|
||||
var responses []*model.UserCoupon
|
||||
|
||||
for _, userCoupon := range userCoupons {
|
||||
isCanUse, err := r.CheckUserCoupon(userCoupon, systemMemberId, 2, amountTotal)
|
||||
if err != nil || isCanUse == false {
|
||||
continue
|
||||
}
|
||||
|
||||
responses = append(responses, userCoupon)
|
||||
}
|
||||
|
||||
g = dto.GetUserCouponListDto(responses)
|
||||
|
||||
return g, nil
|
||||
}
|
||||
|
||||
24
utils/tz.go
Normal file
24
utils/tz.go
Normal file
@ -0,0 +1,24 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"hepa-calc-admin-api/api/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
// StrToLocalTime 字符串时间转localtime
|
||||
func StrToLocalTime(s string) (*model.LocalTime, error) {
|
||||
// 获取本地时区
|
||||
location, err := time.LoadLocation("Local")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
timeParse, err := time.ParseInLocation("2006-01-02 15:04:05", s, location)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
t := model.LocalTime(timeParse)
|
||||
|
||||
return &t, nil
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user