新增发送短信
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
type LogSms struct {
|
||||
}
|
||||
|
||||
// GetLogSmsById 获取短信数据-短信id
|
||||
func (r *LogSms) GetLogSmsById(hospitalId int64) (m *model.LogSms, err error) {
|
||||
err = global.Db.First(&m, hospitalId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (r *LogSms) GetLogSmsListByPhone(phone int64) (m []*model.LogSms, err error) {
|
||||
err = global.Db.Where("phone = ?", phone).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddLogSms 新增短信
|
||||
func (r *LogSms) AddLogSms(tx *gorm.DB, model *model.LogSms) (*model.LogSms, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// AddLogSmsUnTransaction 新增短信-无事物
|
||||
func (r *LogSms) AddLogSmsUnTransaction(model *model.LogSms) (*model.LogSms, error) {
|
||||
if err := global.Db.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetLogSmsList 获取短信列表
|
||||
func (r *LogSms) GetLogSmsList(maps interface{}) (m []*model.LogSms, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteLogSmsById 删除短信-短信id
|
||||
func (r *LogSms) DeleteLogSmsById(tx *gorm.DB, logId int64) error {
|
||||
if err := tx.Delete(&model.LogSms{}, logId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// LogSms 日志-短信发送表
|
||||
type LogSms struct {
|
||||
LogId int64 `gorm:"column:log_id;type:bigint(19);primary_key;comment:主键id" json:"log_id"`
|
||||
Type int `gorm:"column:type;type:tinyint(1);comment:类型(1:短信 2:邮件);NOT NULL" json:"type"`
|
||||
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(1:发送成功 2:发送失败)" json:"status"`
|
||||
Phone string `gorm:"column:phone;type:varchar(20);comment:手机号" json:"phone"`
|
||||
TemplateCode string `gorm:"column:template_code;type:varchar(20);comment:模版code" json:"template_code"`
|
||||
ThirdCode string `gorm:"column:third_code;type:varchar(100);comment:第三方编码" json:"third_code"`
|
||||
SceneDesc string `gorm:"column:scene_desc;type:varchar(255);comment:场景描述" json:"scene_desc"`
|
||||
Remarks string `gorm:"column:remarks;type:varchar(255);comment:备注" json:"remarks"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *LogSms) TableName() string {
|
||||
return "gdxz_log_sms"
|
||||
}
|
||||
|
||||
func (m *LogSms) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.LogId == 0 {
|
||||
m.LogId = 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
|
||||
}
|
||||
Reference in New Issue
Block a user