肝病算一算后台api初始化

This commit is contained in:
2024-08-07 14:41:07 +08:00
parent 38ed1a5bd9
commit 4af8640e5f
147 changed files with 13499 additions and 1 deletions
+42
View File
@@ -0,0 +1,42 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// AdminUser 后台-用户表
type AdminUser struct {
UserId int64 `gorm:"column:user_id;type:bigint(19);primary_key;comment:主键id" json:"user_id"`
Access string `gorm:"column:access;type:varchar(64);comment:账号;NOT NULL" json:"access"`
Password string `gorm:"column:password;type:varchar(128);comment:密码;NOT NULL" json:"password"`
Salt string `gorm:"column:salt;type:varchar(255);comment:密码掩码;NOT NULL" json:"salt"`
NickName string `gorm:"column:nick_name;type:varchar(255);comment:昵称" json:"nick_name"`
Status int `gorm:"column:status;type:tinyint(1);default:2;comment:状态(1:正常 2:审核中 3:审核失败)" json:"status"`
IsDeleted int `gorm:"column:is_deleted;type:tinyint(1);default:0;comment:是否被删除(0:否 1:是)" json:"is_deleted"`
IsDisabled int `gorm:"column:is_disabled;type:tinyint(1);default:0;comment:是否被禁用(0:否 1:是)" json:"is_disabled"`
Phone string `gorm:"column:phone;type:varchar(11);comment:手机号" json:"phone"`
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`
Sex int `gorm:"column:sex;type:tinyint(1);comment:性别(1:男 2:女)" json:"sex"`
Email string `gorm:"column:email;type:varchar(100);comment:邮箱" json:"email"`
Model
}
func (m *AdminUser) TableName() string {
return "admin_user"
}
func (m *AdminUser) BeforeCreate(tx *gorm.DB) error {
if m.UserId == 0 {
m.UserId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+33
View File
@@ -0,0 +1,33 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// BaseAgreement 基础数据-协议
type BaseAgreement struct {
AgreementId int64 `gorm:"column:agreement_id;type:bigint(19);primary_key;comment:主键id" json:"agreement_id"`
AgreementTitle string `gorm:"column:agreement_title;type:varchar(100);comment:协议标题" json:"agreement_title"`
AgreementContent string `gorm:"column:agreement_content;type:text;comment:协议内容" json:"agreement_content"`
Model
}
func (m *BaseAgreement) TableName() string {
return "base_agreement"
}
func (m *BaseAgreement) BeforeCreate(tx *gorm.DB) error {
if m.AgreementId == 0 {
m.AgreementId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+36
View File
@@ -0,0 +1,36 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// BaseClass 基础数据-分类表
type BaseClass struct {
ClassId int64 `gorm:"column:class_id;type:bigint(19);primary_key;comment:主键id" json:"class_id"`
ClassName string `gorm:"column:class_name;type:varchar(100);comment:分类名称" json:"class_name"`
ClassStatus int `gorm:"column:class_status;type:tinyint(1);default:1;comment:分类状态(1:正常 2:隐藏)" json:"class_status"`
ClassIcon string `gorm:"column:class_icon;type:varchar(255);comment:图标地址" json:"class_icon"`
ClassBrief string `gorm:"column:class_brief;type:text;comment:分类简介" json:"class_brief"`
Sort uint `gorm:"column:sort;type:int(10) unsigned;default:1;comment:排序值(越大排名越靠前)" json:"sort"`
Model
}
func (m *BaseClass) TableName() string {
return "base_class"
}
func (m *BaseClass) BeforeCreate(tx *gorm.DB) error {
if m.ClassId == 0 {
m.ClassId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+47
View File
@@ -0,0 +1,47 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
type Coupon struct {
CouponId int64 `gorm:"column:coupon_id;type:bigint(19);primary_key;comment:主键id" json:"coupon_id"`
CouponName string `gorm:"column:coupon_name;type:varchar(255);comment:优惠卷名称" json:"coupon_name"`
CouponType int `gorm:"column:coupon_type;type:varchar(255);comment:优惠卷类型(1:无门槛 2:满减)" json:"coupon_type"`
CouponStatus int `gorm:"column:coupon_status;type:tinyint(1);default:1;comment:状态(1:正常 2:强制失效 3:结束 4:删除)" json:"coupon_status"`
ApplicationScope int `gorm:"column:application_scope;type:tinyint(1);default:1;comment:适用范围(1:全场通用 2:单项 3:会员)" json:"application_scope"`
IsMutex int `gorm:"column:is_mutex;type:tinyint(1);default:1;comment:是否互斥(0:否 1:是)互斥情况下无法和其他优惠卷同时使用" json:"is_mutex"`
CouponCount int `gorm:"column:coupon_count;type:int(10);default:1;comment:发放数量;NOT NULL" json:"coupon_count"`
CouponTakeCount int `gorm:"column:coupon_take_count;type:int(10);comment:已领取数量" json:"coupon_take_count"`
CouponUsedCount int `gorm:"column:coupon_used_count;type:int(10);default:0;comment:已使用数量" json:"coupon_used_count"`
CouponPrice float64 `gorm:"column:coupon_price;type:decimal(10,2) unsigned;default:0.00;comment:优惠卷金额" json:"coupon_price"`
WithAmount *float64 `gorm:"column:with_amount;type:decimal(10,2);comment:符合满减标准金额(优惠卷类型为满减时使用)" json:"with_amount"`
ValidType int `gorm:"column:valid_type;type:tinyint(1);comment:有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效);NOT NULL" json:"valid_type"`
ValidDays *int `gorm:"column:valid_days;type:int(3);comment:自领取之日起有效天数" json:"valid_days"`
ValidStartTime *LocalTime `gorm:"column:valid_start_time;type:datetime;comment:开始使用时间" json:"valid_start_time"`
ValidEndTime *LocalTime `gorm:"column:valid_end_time;type:datetime;comment:结束使用时间" json:"valid_end_time"`
QuestionId *int64 `gorm:"column:question_id;type:bigint(19);comment:问题id(适用范围为单项时生效,如果此项为null,则表示所有单项通用)" json:"question_id"`
SystemMemberId *int64 `gorm:"column:system_member_id;type:bigint(19);comment:会员id(适用范围为会员时生效,如果此项为null,则表示所有会员通用)" json:"system_member_id"`
CouponDesc string `gorm:"column:coupon_desc;type:varchar(200);comment:优惠卷描述" json:"coupon_desc"`
Model
}
func (m *Coupon) TableName() string {
return "coupon"
}
func (m *Coupon) BeforeCreate(tx *gorm.DB) error {
if m.CouponId == 0 {
m.CouponId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+50
View File
@@ -0,0 +1,50 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// OrderMember 订单-单项
type OrderMember struct {
OrderId int64 `gorm:"column:order_id;type:bigint(19);primary_key;comment:主键id" json:"order_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
SystemMemberId int64 `gorm:"column:system_member_id;type:bigint(19);comment:会员id;NOT NULL" json:"system_member_id"`
OrderStatus int `gorm:"column:order_status;type:tinyint(1);default:1;comment:订单状态(1:待支付 2:已完成 3:已取消)" json:"order_status"`
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"`
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"`
AmountTotal float64 `gorm:"column:amount_total;type:decimal(10,2) unsigned;default:0.00;comment:订单金额" json:"amount_total"`
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"`
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
SystemMember *SystemMember `gorm:"foreignKey:SystemMemberId;references:system_member_id" json:"system_member"`
User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"`
}
func (m *OrderMember) TableName() string {
return "order_member"
}
func (m *OrderMember) BeforeCreate(tx *gorm.DB) error {
if m.OrderId == 0 {
m.OrderId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+35
View File
@@ -0,0 +1,35 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// OrderMemberCoupon 订单-单项-优惠卷表
type OrderMemberCoupon struct {
OrderCouponId int64 `gorm:"column:order_coupon_id;type:bigint(19);primary_key;comment:主键id" json:"order_coupon_id"`
OrderId int64 `gorm:"column:order_id;type:bigint(19);comment:单项订单id;NOT NULL" json:"order_id"`
UserCouponId int64 `gorm:"column:user_coupon_id;type:bigint(19);comment:用户优惠卷表id;NOT NULL" json:"user_coupon_id"`
CouponName string `gorm:"column:coupon_name;type:varchar(255);comment:优惠卷名称" json:"coupon_name"`
CouponUsePrice float64 `gorm:"column:coupon_use_price;type:decimal(10,2) unsigned;default:0.00;comment:优惠卷使用金额" json:"coupon_use_price"`
Model
}
func (m *OrderMemberCoupon) TableName() string {
return "order_member_coupon"
}
func (m *OrderMemberCoupon) BeforeCreate(tx *gorm.DB) error {
if m.OrderCouponId == 0 {
m.OrderCouponId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+39
View File
@@ -0,0 +1,39 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// OrderMemberRefund 订单-会员-退款表
type OrderMemberRefund struct {
OrderRefundId int64 `gorm:"column:order_refund_id;type:bigint(19);primary_key;comment:主键id" json:"order_refund_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
OrderId int64 `gorm:"column:order_id;type:bigint(19);comment:订单id;NOT NULL" json:"order_id"`
OrderNo string `gorm:"column:order_no;type:varchar(40);comment:系统订单编号" json:"order_no"`
RefundNo string `gorm:"column:refund_no;type:varchar(50);comment:系统退款编号" json:"refund_no"`
RefundId string `gorm:"column:refund_id;type:varchar(50);comment:第三方退款单号" json:"refund_id"`
RefundStatus int `gorm:"column:refund_status;type:tinyint(1);default:0;comment:订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常 7:部分退款)" json:"refund_status"`
RefundTotal float64 `gorm:"column:refund_total;type:decimal(10,2) unsigned;default:0.00;comment:退款金额" json:"refund_total"`
RefundReason string `gorm:"column:refund_reason;type:varchar(255);comment:退款原因" json:"refund_reason"`
SuccessTime LocalTime `gorm:"column:success_time;type:datetime;comment:退款成功时间" json:"success_time"`
Model
}
func (m *OrderMemberRefund) TableName() string {
return "order_member_refund"
}
func (m *OrderMemberRefund) BeforeCreate(tx *gorm.DB) error {
if m.OrderRefundId == 0 {
m.OrderRefundId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+50
View File
@@ -0,0 +1,50 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// OrderSingle 订单-单项
type OrderSingle struct {
OrderId int64 `gorm:"column:order_id;type:bigint(19);primary_key;comment:主键id" json:"order_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:问题id;NOT NULL" json:"question_id"`
OrderStatus int `gorm:"column:order_status;type:tinyint(1);default:1;comment:订单状态(1:待支付 2:已完成 3:已取消)" json:"order_status"`
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"`
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"`
AmountTotal float64 `gorm:"column:amount_total;type:decimal(10,2) unsigned;default:0.00;comment:订单金额" json:"amount_total"`
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"`
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
Question *Question `gorm:"foreignKey:QuestionId;references:question_id" json:"question"`
User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"`
}
func (m *OrderSingle) TableName() string {
return "order_single"
}
func (m *OrderSingle) BeforeCreate(tx *gorm.DB) error {
if m.OrderId == 0 {
m.OrderId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+35
View File
@@ -0,0 +1,35 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// OrderSingleCoupon 订单-单项-优惠卷表
type OrderSingleCoupon struct {
OrderCouponId int64 `gorm:"column:order_coupon_id;type:bigint(19);primary_key;comment:主键id" json:"order_coupon_id"`
OrderId int64 `gorm:"column:order_id;type:bigint(19);comment:单项订单id;NOT NULL" json:"order_id"`
UserCouponId int64 `gorm:"column:user_coupon_id;type:bigint(19);comment:用户优惠卷表id;NOT NULL" json:"user_coupon_id"`
CouponName string `gorm:"column:coupon_name;type:varchar(255);comment:优惠卷名称" json:"coupon_name"`
CouponUsePrice float64 `gorm:"column:coupon_use_price;type:decimal(10,2) unsigned;default:0.00;comment:优惠卷使用金额" json:"coupon_use_price"`
Model
}
func (m *OrderSingleCoupon) TableName() string {
return "order_single_coupon"
}
func (m *OrderSingleCoupon) BeforeCreate(tx *gorm.DB) error {
if m.OrderCouponId == 0 {
m.OrderCouponId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+40
View File
@@ -0,0 +1,40 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// OrderSingleRefund 订单-单项-退款表
type OrderSingleRefund struct {
OrderRefundId int64 `gorm:"column:order_refund_id;type:bigint(19);primary_key;comment:主键id" json:"order_refund_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
OrderId int64 `gorm:"column:order_id;type:bigint(19);comment:订单id;NOT NULL" json:"order_id"`
OrderNo string `gorm:"column:order_no;type:varchar(40);comment:系统订单编号" json:"order_no"`
RefundNo string `gorm:"column:refund_no;type:varchar(50);comment:系统退款编号" json:"refund_no"`
RefundId string `gorm:"column:refund_id;type:varchar(50);comment:第三方退款单号" json:"refund_id"`
RefundStatus int `gorm:"column:refund_status;type:tinyint(1);default:0;comment:订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常 7:部分退款)" json:"refund_status"`
RefundTotal float64 `gorm:"column:refund_total;type:decimal(10,2) unsigned;default:0.00;comment:退款金额" json:"refund_total"`
RefundReason string `gorm:"column:refund_reason;type:varchar(255);comment:退款原因" json:"refund_reason"`
SuccessTime LocalTime `gorm:"column:success_time;type:datetime;comment:退款成功时间" json:"success_time"`
Model
}
func (m *OrderSingleRefund) TableName() string {
return "order_single_refund"
}
func (m *OrderSingleRefund) BeforeCreate(tx *gorm.DB) error {
if m.OrderRefundId == 0 {
m.OrderRefundId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+45
View File
@@ -0,0 +1,45 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// Question 问题表
type Question struct {
QuestionId int64 `gorm:"column:question_id;type:bigint(19);primary_key;comment:主键id" json:"question_id"`
QuestionTitle string `gorm:"column:question_title;type:varchar(200);comment:标题" json:"question_title"`
QuestionSubtitle string `gorm:"column:question_subtitle;type:varchar(200);comment:副标题" json:"question_subtitle"`
QuestionIden string `gorm:"column:question_iden;type:varchar(255);comment:唯一标识(用于和前端对应)" json:"question_iden"`
QuestionStatus int `gorm:"column:question_status;type:tinyint(1);default:2;comment:问题状态(1:正常 2:待发布)" json:"question_status"`
IsHide int `gorm:"column:is_hide;type:tinyint(1);default:0;comment:是否隐藏(0:否 1:是)" json:"is_hide"`
IsRecommend int `gorm:"column:is_recommend;type:tinyint(1);default:0;comment:是否推荐(0:否 1:是)" json:"is_recommend"`
ClickCount int `gorm:"column:click_count;type:int(5);default:0;comment:点击次数(点击进入详情页的人次)" json:"click_count"`
SubmitCount int `gorm:"column:submit_count;type:int(5);default:0;comment:提交次数(提交个人信息进行了算算的人次)" json:"submit_count"`
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"`
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
}
func (m *Question) TableName() string {
return "question"
}
func (m *Question) BeforeCreate(tx *gorm.DB) error {
if m.QuestionId == 0 {
m.QuestionId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+33
View File
@@ -0,0 +1,33 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// QuestionClass 中间表-问题/分类
type QuestionClass struct {
QuestionClassId int64 `gorm:"column:question_class_id;type:bigint(19);primary_key;comment:主键id" json:"question_class_id"`
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:问题id;NOT NULL" json:"question_id"`
ClassId int64 `gorm:"column:class_id;type:bigint(19);comment:分类id;NOT NULL" json:"class_id"`
Model
}
func (m *QuestionClass) TableName() string {
return "question_class"
}
func (m *QuestionClass) BeforeCreate(tx *gorm.DB) error {
if m.QuestionClassId == 0 {
m.QuestionClassId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+35
View File
@@ -0,0 +1,35 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// SystemMember 配置-会员配置
type SystemMember struct {
SystemMemberId int64 `gorm:"column:system_member_id;type:bigint(19);primary_key;comment:主键id" json:"system_member_id"`
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"`
Model
}
func (m *SystemMember) TableName() string {
return "system_member"
}
func (m *SystemMember) BeforeCreate(tx *gorm.DB) error {
if m.SystemMemberId == 0 {
m.SystemMemberId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+33
View File
@@ -0,0 +1,33 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// SystemSingle 配置-单项配置
type SystemSingle struct {
SystemSingleId int64 `gorm:"column:system_single_id;type:bigint(19);primary_key;comment:主键id" json:"system_single_id"`
FirstTimePrice float64 `gorm:"column:first_time_price;type:decimal(10,2);default:0.00;comment:首次购买价格" json:"first_time_price"`
ValidDays int `gorm:"column:valid_days;type:int(5);default:1;comment:购买后有效天数" json:"valid_days"`
Model
}
func (m *SystemSingle) TableName() string {
return "system_single"
}
func (m *SystemSingle) BeforeCreate(tx *gorm.DB) error {
if m.SystemSingleId == 0 {
m.SystemSingleId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+48
View File
@@ -0,0 +1,48 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// User 用户表
type User struct {
UserId int64 `gorm:"column:user_id;type:bigint(19);primary_key;comment:用户id" json:"user_id"`
UserName string `gorm:"column:user_name;type:varchar(200);comment:用户名称" json:"user_name"`
Mobile string `gorm:"column:mobile;type:varchar(20);comment:手机号;NOT NULL" json:"mobile"`
UserStatus int `gorm:"column:user_status;type:tinyint(1);default:1;comment:状态(1:正常 2:禁用)" json:"user_status"`
RegisterSource int `gorm:"column:register_source;type:tinyint(1);default:1;comment:注册来源(1app注册 2:公众号注册)" json:"register_source"`
OpenId string `gorm:"column:open_id;type:varchar(100);comment:用户微信标识" json:"open_id"`
UnionId string `gorm:"column:union_id;type:varchar(100);comment:微信开放平台标识" json:"union_id"`
Age *uint `gorm:"column:age;type:int(10) unsigned;comment:年龄" json:"age"`
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"`
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"`
LoginAt LocalTime `gorm:"column:login_at;type:datetime;comment:登陆时间" json:"login_at"`
LoginIp string `gorm:"column:login_ip;type:varchar(255);comment:登陆ip" json:"login_ip"`
Model
UserInfo *UserInfo `gorm:"foreignKey:UserId;references:user_id" json:"user_info"`
}
func (m *User) TableName() string {
return "user"
}
func (m *User) BeforeCreate(tx *gorm.DB) error {
if m.UserId == 0 {
m.UserId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+34
View File
@@ -0,0 +1,34 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// UserCollection 用户收藏表
type UserCollection struct {
CollectionId int64 `gorm:"column:collection_id;type:bigint(19);primary_key;comment:主键id" json:"collection_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id" json:"user_id"`
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:问题id" json:"question_id"`
Model
Question *Question `gorm:"foreignKey:QuestionId;references:question_id" json:"question"`
}
func (m *UserCollection) TableName() string {
return "user_collection"
}
func (m *UserCollection) BeforeCreate(tx *gorm.DB) error {
if m.CollectionId == 0 {
m.CollectionId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+38
View File
@@ -0,0 +1,38 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
type UserCoupon struct {
UserCouponId int64 `gorm:"column:user_coupon_id;type:bigint(19);primary_key;comment:主键id" json:"user_coupon_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
CouponId int64 `gorm:"column:coupon_id;type:bigint(19);comment:优惠卷id;NOT NULL" json:"coupon_id"`
UserCouponStatus int `gorm:"column:user_coupon_status;type:tinyint(1);default:0;comment:状态(0:未使用 1:已使用 3:已过期)" json:"user_coupon_status"`
IsWindows int `gorm:"column:is_windows;type:tinyint(1);default:0;comment:是否已弹窗(0:否 1:是)" json:"is_windows"`
CouponUseDate LocalTime `gorm:"column:coupon_use_date;type:datetime;comment:使用时间" json:"coupon_use_date"`
ValidStartTime LocalTime `gorm:"column:valid_start_time;type:datetime;comment:有效使用时间" json:"valid_start_time"`
ValidEndTime LocalTime `gorm:"column:valid_end_time;type:datetime;comment:过期使用时间" json:"valid_end_time"`
Model
Coupon *Coupon `gorm:"foreignKey:CouponId;references:coupon_id" json:"coupon"`
}
func (m *UserCoupon) TableName() string {
return "user_coupon"
}
func (m *UserCoupon) BeforeCreate(tx *gorm.DB) error {
if m.UserCouponId == 0 {
m.UserCouponId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+43
View File
@@ -0,0 +1,43 @@
package model
import (
"gorm.io/gorm"
"hepa-calc-admin-api/global"
"time"
)
// UserInfo 用户表-基础信息
type UserInfo struct {
UserInfoId int64 `gorm:"column:user_info_id;type:bigint(19);primary_key;comment:主键id" json:"user_info_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id" json:"user_id"`
Height string `gorm:"column:height;type:varchar(20);comment:身高(cm" json:"height"`
Weight string `gorm:"column:weight;type:varchar(20);comment:体重(kg" json:"weight"`
NationId int64 `gorm:"column:nation_id;type:bigint(19);comment:民族id" json:"nation_id"`
FamilyHistoryId int64 `gorm:"column:family_history_id;type:bigint(19);comment:家族病史id" json:"family_history_id"`
ProvinceId int `gorm:"column:province_id;type:int(11);comment:省份id" json:"province_id"`
Province string `gorm:"column:province;type:varchar(40);comment:省份" json:"province"`
CityId int `gorm:"column:city_id;type:int(11);comment:城市id" json:"city_id"`
City string `gorm:"column:city;type:varchar(50);comment:城市" json:"city"`
CountyId int `gorm:"column:county_id;type:int(11);comment:区县id" json:"county_id"`
County string `gorm:"column:county;type:varchar(255);comment:区县" json:"county"`
DiseaseClassId int64 `gorm:"column:disease_class_id;type:bigint(19);comment:疾病分类id" json:"disease_class_id"`
Model
}
func (m *UserInfo) TableName() string {
return "user_info"
}
func (m *UserInfo) BeforeCreate(tx *gorm.DB) error {
if m.UserInfoId == 0 {
m.UserInfoId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+87
View File
@@ -0,0 +1,87 @@
package model
import (
"database/sql/driver"
"errors"
"fmt"
"gorm.io/gorm"
"strings"
"time"
)
type Model struct {
CreatedAt LocalTime `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at"`
UpdatedAt LocalTime `gorm:"column:updated_at;type:datetime;comment:修改时间" json:"updated_at"`
}
// LocalTime 自定义数据类型
type LocalTime time.Time
func (t *LocalTime) UnmarshalJSON(data []byte) error {
if string(data) == "null" {
return nil
}
var err error
// 前端接收的时间字符串
str := string(data)
// 去除接收的str收尾多余的"
timeStr := strings.Trim(str, "\"")
t1, err := time.Parse("2006-01-02 15:04:05", timeStr)
*t = LocalTime(t1)
return err
}
func (t LocalTime) MarshalJSON() ([]byte, error) {
formatted := fmt.Sprintf("\"%v\"", time.Time(t).Format("2006-01-02 15:04:05"))
return []byte(formatted), nil
}
func (t LocalTime) Value() (driver.Value, error) {
// MyTime 转换成 time.Time 类型
tTime := time.Time(t)
return tTime.Format("2006-01-02 15:04:05"), nil
}
func (t *LocalTime) Scan(v interface{}) error {
switch vt := v.(type) {
case time.Time:
// 字符串转成 time.Time 类型
*t = LocalTime(vt)
default:
return errors.New("类型处理错误")
}
return nil
}
func (t *LocalTime) String() string {
return fmt.Sprintf("hhh:%s", time.Time(*t).String())
}
func (t *LocalTime) IsEmpty() bool {
return time.Time(*t).IsZero()
}
func (m *Model) BeforeUpdate(tx *gorm.DB) (err error) {
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
func Paginate(page, pageSize int) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
if page <= 0 {
page = 1
}
switch {
case pageSize > 100:
pageSize = 100
case pageSize <= 0:
pageSize = 10
}
offset := (page - 1) * pageSize
return db.Offset(offset).Limit(pageSize)
}
}