This commit is contained in:
2023-11-02 04:34:46 +08:00
commit c4548fe498
369 changed files with 40208 additions and 0 deletions

15
model/common/article.go Normal file
View File

@@ -0,0 +1,15 @@
package common
import "miniapp/global"
type Article struct {
global.GVA_MODEL
Title string `json:"title" form:"title" gorm:"column:title;comment:标题;type:varchar(255);size:255;"`
Content string `json:"content" form:"content" gorm:"column:content;comment:内容;type:longtext;"`
CoverImg string `json:"cover_img" form:"coverImg" gorm:"column:cover_img;comment:封面图;type:varchar(255);size:255;"`
ReadingNum int `json:"reading_num" form:"reading_num" gorm:"column:reading_num;comment:阅读量;type:int;size:10;"`
}
func (Article) TableName() string {
return "articles"
}

12
model/common/banner.go Normal file
View File

@@ -0,0 +1,12 @@
package common
import (
"miniapp/global"
)
type Banner struct {
global.GVA_MODEL
ImgUrl string `json:"imgUrl" gorm:"type:varchar(255) comment '图片地址'"`
Link string `json:"link" gorm:"type:varchar(255) comment '跳转链接'"`
Status int `json:"status" gorm:"type:tinyint(1) comment '是否显示 0-不显示 1-显示'"`
}

View File

@@ -0,0 +1,16 @@
package constant
// LoginType 自定义登录类型
type LoginType string
// 登录类型
const (
LoginTypeWeChatMiniApp LoginType = "wechat_mini_app" // 微信小程序登录
LoginTypeSms LoginType = "sms" // 短信验证码登录
LoginTypePassword LoginType = "password" // 密码登录
)
// String 转换为字符串
func (t LoginType) String() string {
return string(t)
}

View File

@@ -0,0 +1,133 @@
package constant
import "fmt"
// PaymentType 支付方式
type PaymentType int
const (
PaymentTypeNone PaymentType = iota // 未知 0
PaymentTypeWeChatMiniApp // 微信小程序 1
PaymentTypeWeChatH5 // 微信H5 2
PaymentTypeWeChatAPP // 微信APP 3
PaymentTypeExchangeCode // 兑换码白嫖 4
)
// 支付渠道描述
var paymentTypeMap = map[PaymentType]string{
PaymentTypeNone: "未知",
PaymentTypeWeChatMiniApp: "微信小程序",
PaymentTypeWeChatH5: "微信H5",
PaymentTypeWeChatAPP: "微信APP",
PaymentTypeExchangeCode: "兑换码",
}
// 处理为看得懂的状态
func (pt PaymentType) String() string {
if str, ok := paymentTypeMap[pt]; ok {
return str
}
return fmt.Sprintf("未知状态(%d)", pt)
}
// MarshalJSON JSON序列化的时候转换为中文
func (pt PaymentType) MarshalJSON() ([]byte, error) {
return []byte(`"` + pt.String() + `"`), nil
}
// =====================================================================================================================
type PayStatus int
const (
PayStatusNot PayStatus = iota // 未支付
PayStatusSuccess // 支付成功
PayStatusFail // 支付失败
PayStatusRefunded // 已退款
)
var payStatusMap = map[PayStatus]string{
PayStatusNot: "未支付",
PayStatusSuccess: "支付成功",
PayStatusFail: "支付失败",
PayStatusRefunded: "已退款",
}
// 处理为看得懂的状态
func (ps PayStatus) String() string {
if str, ok := payStatusMap[ps]; ok {
return str
}
return fmt.Sprintf("未知状态(%d)", ps)
}
// MarshalJSON JSON序列化的时候转换为中文
func (ps PayStatus) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%s"`, ps.String())), nil
}
// =====================================================================================================================
type OrderStatus int
const (
OrderStatusWait OrderStatus = iota // 待支付 0
OrderStatusUsing // 生效中 1
OrderStatusFailure // 已失效 2
OrderStatusApplicationRefund // 已申请退款 3
OrderStatusRefunding // 退款中 4
OrderStatusRefunded // 已退款 5
OrderStatusCanceled // 已取消 6
OrderStatusEnd // 已完成 7
)
var orderStatusMap = map[OrderStatus]string{
OrderStatusWait: "待支付",
OrderStatusUsing: "生效中",
OrderStatusFailure: "已失效",
OrderStatusApplicationRefund: "已申请退款",
OrderStatusRefunding: "退款中",
OrderStatusRefunded: "已退款",
OrderStatusCanceled: "已取消",
OrderStatusEnd: "已完成",
}
// 处理为看得懂的状态
func (os OrderStatus) String() string {
if str, ok := orderStatusMap[os]; ok {
return str
}
return fmt.Sprintf("未知状态(%d)", os)
}
// MarshalJSON JSON序列化的时候转换为中文
func (os OrderStatus) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%s"`, os.String())), nil
}
// =====================================================================================================================
type OrderServiceType int
const (
OrderServiceTypeProduct OrderServiceType = iota + 1 // 普通商品
OrderServiceTypeActivity // 活动
)
var orderServiceTypeMap = map[OrderServiceType]string{
OrderServiceTypeProduct: "服务",
OrderServiceTypeActivity: "活动",
}
// 处理为看得懂的状态
func (os OrderServiceType) String() string {
if str, ok := orderServiceTypeMap[os]; ok {
return str
}
return fmt.Sprintf("未知状态(%d)", os)
}
// MarshalJSON JSON序列化的时候转换为中文
func (os OrderServiceType) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%s"`, os.String())), nil
}

View File

@@ -0,0 +1,8 @@
package constant
const (
OAuth2RedisKey = "oauth:token:" // Token缓存前缀
OAuth2UserCacheKey = "oauth:user:" // 用户缓存前缀
ApiAntiShakeKey = "api:antishake:" // 防抖锁
WeChatSessionKey = "wechat:session:" // 小程序用户SessionKey前缀
)

View File

@@ -0,0 +1,88 @@
package constant
import (
"fmt"
)
// UserStatus 用户状态
type UserStatus string
const (
UserStatusActive UserStatus = "NORMAL" // 用户状态正常
UserStatusDisabled UserStatus = "DISABLE" // 已禁用用户
)
// 状态对应的描述
var userStatusMap = map[UserStatus]string{
UserStatusActive: "正常",
UserStatusDisabled: "已禁用",
}
// 处理为看得懂的状态
func (s UserStatus) String() string {
if str, ok := userStatusMap[s]; ok {
return str
}
return string(s)
}
// =====================================================================================================================
// UserSex 性别
type UserSex int
const (
UserSexNone UserSex = iota // 不知道是啥
UserSexMale // 男
UserSexFemale // 女
UserSexOther // 其他性别
)
// 状态对应的描述
var userSexMap = map[UserSex]string{
UserSexNone: "无性别",
UserSexMale: "男",
UserSexFemale: "女",
UserSexOther: "其他",
}
// FromString 中文取性别
func (s UserSex) FromString(sex string) UserSex {
result := UserSexNone
for key, value := range userSexMap {
if sex == value {
result = key
break
}
}
return result
}
// 处理为看得懂的状态
func (s UserSex) String() string {
if str, ok := userSexMap[s]; ok {
return str
}
//return strconv.Itoa(int(s))
return fmt.Sprintf("UserSex(%d)", int(s))
}
// MarshalJSON JSON序列化的时候转换为中文
func (s UserSex) MarshalJSON() ([]byte, error) {
return []byte(`"` + s.String() + `"`), nil
}
// =====================================================================================================================
// UserIdentity 用户身份
type UserIdentity string
const (
UserIdentityAdmin UserIdentity = "admin" // 管理员
UserIdentityUser UserIdentity = "user" // 普通用户
)
// String implements the Stringer interface.
func (t UserIdentity) String() string {
return string(t)
}

16
model/common/hospital.go Normal file
View File

@@ -0,0 +1,16 @@
package common
import "miniapp/global"
type Hospital struct {
global.GVA_MODEL
Name string `json:"name" form:"name" gorm:"comment:医院名称;"`
Addr string `json:"addr" form:"addr" gorm:"comment:医院地址;"`
Phone string `json:"phone" form:"phone" gorm:"comment:医院电话;"`
Notes []Notes `json:"notes" form:"notes" gorm:"many2many:hospital_notes;comment:注意事项;"`
Todos []Todos `json:"todos" form:"todos" gorm:"many2many:hospital_todos;comment:任务列表;"`
}
func (h Hospital) TableName() string {
return "sys_hospital"
}

13
model/common/notes.go Normal file
View File

@@ -0,0 +1,13 @@
package common
import "miniapp/global"
type Notes struct {
global.GVA_MODEL
Content string `json:"content" form:"content" gorm:"comment:注意事项内容;"`
NotesTime string `json:"notes_time" form:"notes_time" gorm:"comment:注意事项时间;"` //手术前、手术后、术中
}
func (n Notes) TableName() string {
return "sys_notes"
}

View File

@@ -0,0 +1,28 @@
package request
// PageInfo Paging common input parameter structure
type PageInfo struct {
Page int `json:"page" form:"page"` // 页码
PageSize int `json:"pageSize" form:"pageSize"` // 每页大小
Keyword string `json:"keyword" form:"keyword"` //关键字
}
// GetById Find by id structure
type GetById struct {
ID int `json:"id" form:"id"` // 主键ID
}
func (r *GetById) Uint() uint {
return uint(r.ID)
}
type IdsReq struct {
Ids []int `json:"ids" form:"ids"`
}
// GetAuthorityId Get role by id structure
type GetAuthorityId struct {
AuthorityId int `json:"authorityId" form:"authorityId"` // 角色ID
}
type Empty struct{}

View File

@@ -0,0 +1,8 @@
package response
type PageResult struct {
List interface{} `json:"list"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
}

View File

@@ -0,0 +1,55 @@
package response
import (
"net/http"
"github.com/gin-gonic/gin"
)
type Response struct {
Code int `json:"code"`
Data interface{} `json:"data"`
Msg string `json:"msg"`
}
const (
ERROR = 7
SUCCESS = 0
)
func Result(code int, data interface{}, msg string, c *gin.Context) {
// 开始时间
c.JSON(http.StatusOK, Response{
code,
data,
msg,
})
}
func Ok(c *gin.Context) {
Result(SUCCESS, map[string]interface{}{}, "操作成功", c)
}
func OkWithMessage(message string, c *gin.Context) {
Result(SUCCESS, map[string]interface{}{}, message, c)
}
func OkWithData(data interface{}, c *gin.Context) {
Result(SUCCESS, data, "查询成功", c)
}
func OkWithDetailed(data interface{}, message string, c *gin.Context) {
Result(SUCCESS, data, message, c)
}
func Fail(c *gin.Context) {
Result(ERROR, map[string]interface{}{}, "操作失败", c)
}
func FailWithMessage(message string, c *gin.Context) {
Result(ERROR, map[string]interface{}{}, message, c)
}
func FailWithDetailed(data interface{}, message string, c *gin.Context) {
Result(ERROR, data, message, c)
}

13
model/common/todos.go Normal file
View File

@@ -0,0 +1,13 @@
package common
import "miniapp/global"
type Todos struct {
// 任务列表
global.GVA_MODEL
Content string `json:"content" form:"content" gorm:"comment:任务内容;"`
}
func (t Todos) TableName() string {
return "sys_todos"
}

14
model/common/user_todo.go Normal file
View File

@@ -0,0 +1,14 @@
package common
import "miniapp/global"
type UserTodo struct {
global.GVA_MODEL
UserId int `json:"userId" form:"userId" gorm:"comment:用户id;"`
Content string `json:"content" form:"content" gorm:"comment:任务内容;"`
IsFinish int `json:"isFinish" form:"isFinish" gorm:"comment:是否完成;"`
}
func (u UserTodo) TableName() string {
return "t_user_todo"
}