v1.1.0 新增通知、暂时性2折

This commit is contained in:
2025-01-01 02:00:06 +08:00
parent 0a79a2435b
commit ac656a4125
10 changed files with 595 additions and 40 deletions

View File

@@ -0,0 +1,17 @@
package notification
import (
"net/http"
"qnc-server/app/user/cmd/api/internal/logic/notification"
"qnc-server/app/user/cmd/api/internal/svc"
"qnc-server/common/result"
)
func GetNotificationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := notification.NewGetNotificationsLogic(r.Context(), svcCtx)
resp, err := l.GetNotifications()
result.HttpResult(r, w, resp, err)
}
}

View File

@@ -5,6 +5,7 @@ import (
"net/http"
auth "qnc-server/app/user/cmd/api/internal/handler/auth"
notification "qnc-server/app/user/cmd/api/internal/handler/notification"
pay "qnc-server/app/user/cmd/api/internal/handler/pay"
product "qnc-server/app/user/cmd/api/internal/handler/product"
query "qnc-server/app/user/cmd/api/internal/handler/query"
@@ -27,6 +28,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithPrefix("/api/v1"),
)
server.AddRoutes(
[]rest.Route{
{
// get notifications
Method: http.MethodGet,
Path: "/notification/list",
Handler: notification.GetNotificationsHandler(serverCtx),
},
},
rest.WithPrefix("/api/v1"),
)
server.AddRoutes(
[]rest.Route{
{

View File

@@ -0,0 +1,56 @@
package notification
import (
"context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"qnc-server/common/xerr"
"time"
"qnc-server/app/user/cmd/api/internal/svc"
"qnc-server/app/user/cmd/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetNotificationsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetNotificationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetNotificationsLogic {
return &GetNotificationsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetNotificationsLogic) GetNotifications() (resp *types.GetNotificationsResp, err error) {
// 获取今天的日期
now := time.Now()
// 获取开始和结束日期的时间戳
todayStart := now.Format("2006-01-02") + " 00:00:00"
todayEnd := now.Format("2006-01-02") + " 23:59:59"
// 构建查询条件
builder := l.svcCtx.GlobalNotificationsModel.SelectBuilder().
Where("status = ?", "active").
Where("(start_date IS NULL OR start_date <= ?)", todayEnd). // start_date 是 NULL 或者小于等于今天结束时间
Where("(end_date IS NULL OR end_date >= ?)", todayStart) // end_date 是 NULL 或者大于等于今天开始时间
notificationsModelList, findErr := l.svcCtx.GlobalNotificationsModel.FindAll(l.ctx, builder, "")
if findErr != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "全局通知, 查找通知失败, err:%+v", findErr)
}
var notifications []types.Notification
copyErr := copier.Copy(&notifications, &notificationsModelList)
if copyErr != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "全局通知, 复制结构体失败, err:%+v", copyErr)
}
return &types.GetNotificationsResp{Notifications: notifications}, nil
}

View File

@@ -8,12 +8,14 @@ import (
"github.com/pkg/errors"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"math"
"qnc-server/app/user/cmd/api/internal/svc"
"qnc-server/app/user/cmd/api/internal/types"
"qnc-server/app/user/model"
"qnc-server/common/ctxdata"
"qnc-server/common/xerr"
"qnc-server/pkg/lzkit/crypto"
"time"
)
type PaymentLogic struct {
@@ -70,10 +72,29 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "生成订单, 获取用户信息失败: %+v", err)
}
currentTime := time.Now()
var mhour int
if user.Inside == 1 {
amount = 0.01
mhour = 0
} else {
amount = product.SellPrice
mhour = 12
}
// 设置时间范围2025年1月1日中午12点到2025年1月2日中午12点
startTime := time.Date(2025, 1, 1, mhour, 0, 0, 0, time.Local)
endTime := time.Date(2025, 1, 2, 12, 0, 0, 0, time.Local)
if currentTime.After(startTime) && currentTime.Before(endTime) {
// 打两折
amount = product.SellPrice * 0.2
amount = math.Round(amount*100) / 100
} else {
if user.Inside == 1 {
amount = 0.01
} else {
amount = product.SellPrice
}
}
var createOrderErr error
if req.PayMethod == "wechatpay" {

View File

@@ -13,25 +13,26 @@ import (
)
type ServiceContext struct {
Config config.Config
Redis *redis.Redis
SourceInterceptor rest.Middleware
UserModel model.UserModel
UserAuthModel model.UserAuthModel
ProductModel model.ProductModel
FeatureModel model.FeatureModel
ProductFeatureModel model.ProductFeatureModel
OrderModel model.OrderModel
QueryModel model.QueryModel
AlipayService *service.AliPayService
WechatPayService *service.WechatPayService
ApplePayService *service.ApplePayService
WestDexService *service.WestDexService
YushanService *service.YushanService
ApiRequestService *service.ApiRequestService
AsynqServer *asynq.Server // 服务端
AsynqService *service.AsynqService // 客户
VerificationService *service.VerificationService
Config config.Config
Redis *redis.Redis
SourceInterceptor rest.Middleware
UserModel model.UserModel
UserAuthModel model.UserAuthModel
ProductModel model.ProductModel
FeatureModel model.FeatureModel
ProductFeatureModel model.ProductFeatureModel
OrderModel model.OrderModel
QueryModel model.QueryModel
GlobalNotificationsModel model.GlobalNotificationsModel
AlipayService *service.AliPayService
WechatPayService *service.WechatPayService
ApplePayService *service.ApplePayService
WestDexService *service.WestDexService
YushanService *service.YushanService
ApiRequestService *service.ApiRequestService
AsynqServer *asynq.Server // 服务
AsynqService *service.AsynqService // 客户端
VerificationService *service.VerificationService
}
func NewServiceContext(c config.Config) *ServiceContext {
@@ -56,25 +57,26 @@ func NewServiceContext(c config.Config) *ServiceContext {
productFeatureModel := model.NewProductFeatureModel(db, c.CacheRedis)
featureModel := model.NewFeatureModel(db, c.CacheRedis)
return &ServiceContext{
Config: c,
Redis: redis.MustNewRedis(redisConf),
SourceInterceptor: middleware.NewSourceInterceptorMiddleware().Handle,
AlipayService: service.NewAliPayService(c),
WechatPayService: service.NewWechatPayService(c),
ApplePayService: service.NewApplePayService(c),
WestDexService: westDexService,
YushanService: yushanService,
VerificationService: service.NewVerificationService(c, westDexService),
AsynqServer: asynqServer,
ApiRequestService: service.NewApiRequestService(c, westDexService, yushanService, featureModel, productFeatureModel),
AsynqService: service.NewAsynqService(c),
UserModel: model.NewUserModel(db, c.CacheRedis),
UserAuthModel: model.NewUserAuthModel(db, c.CacheRedis),
ProductModel: model.NewProductModel(db, c.CacheRedis),
OrderModel: model.NewOrderModel(db, c.CacheRedis),
QueryModel: model.NewQueryModel(db, c.CacheRedis),
FeatureModel: featureModel,
ProductFeatureModel: productFeatureModel,
Config: c,
Redis: redis.MustNewRedis(redisConf),
SourceInterceptor: middleware.NewSourceInterceptorMiddleware().Handle,
AlipayService: service.NewAliPayService(c),
WechatPayService: service.NewWechatPayService(c),
ApplePayService: service.NewApplePayService(c),
WestDexService: westDexService,
YushanService: yushanService,
VerificationService: service.NewVerificationService(c, westDexService),
AsynqServer: asynqServer,
ApiRequestService: service.NewApiRequestService(c, westDexService, yushanService, featureModel, productFeatureModel),
AsynqService: service.NewAsynqService(c),
UserModel: model.NewUserModel(db, c.CacheRedis),
UserAuthModel: model.NewUserAuthModel(db, c.CacheRedis),
ProductModel: model.NewProductModel(db, c.CacheRedis),
OrderModel: model.NewOrderModel(db, c.CacheRedis),
QueryModel: model.NewQueryModel(db, c.CacheRedis),
GlobalNotificationsModel: model.NewGlobalNotificationsModel(db, c.CacheRedis),
FeatureModel: featureModel,
ProductFeatureModel: productFeatureModel,
}
}
func (s *ServiceContext) Close() {

View File

@@ -7,6 +7,11 @@ type Feature struct {
Name string `json:"name"` // 功能描述
}
type GetNotificationsResp struct {
Notifications []Notification `json:"notifications"` // 通知列表
Total int64 `json:"total"` // 总记录数
}
type GetProductByEnRequest struct {
ProductEn string `path:"product_en"`
}
@@ -42,6 +47,16 @@ type MobileLoginResp struct {
RefreshAfter int64 `json:"refreshAfter"`
}
type Notification struct {
Title string `json:"title"` // 通知标题
Content string `json:"content"` // 通知内容 (富文本)
NotificationPage string `json:"notificationPage"` // 通知页面
StartDate string `json:"startDate"` // 通知开始日期,格式 "YYYY-MM-DD"
EndDate string `json:"endDate"` // 通知结束日期,格式 "YYYY-MM-DD"
StartTime string `json:"startTime"` // 每天通知开始时间,格式 "HH:MM:SS"
EndTime string `json:"endTime"` // 每天通知结束时间,格式 "HH:MM:SS"
}
type PaymentReq struct {
Id string `json:"id"`
PayMethod string `json:"pay_method"`