Browse Source

短信记录

庄逸洲 5 years ago
parent
commit
a0d7e4d95a

+ 5 - 0
controllers/sms/router_collector.go View File

@@ -0,0 +1,5 @@
1
+package sms
2
+
3
+func RegisterRouters() {
4
+	SMSCtlRegistRouters()
5
+}

+ 39 - 0
controllers/sms/sms_controller.go View File

@@ -0,0 +1,39 @@
1
+package sms
2
+
3
+import (
4
+	base_ctl "SCRM/controllers"
5
+	"SCRM/enums"
6
+	"SCRM/service/sms_service"
7
+
8
+	"github.com/astaxie/beego"
9
+)
10
+
11
+func SMSCtlRegistRouters() {
12
+	beego.Router("/api/sms/records", &SMSController{}, "get:GetSendRecords")
13
+}
14
+
15
+type SMSController struct {
16
+	base_ctl.BaseAuthAPIController
17
+}
18
+
19
+// /api/sms/records [get]
20
+// @param page:int
21
+func (this *SMSController) GetSendRecords() {
22
+	page, _ := this.GetInt("page")
23
+	if page <= 0 {
24
+		page = 1
25
+	}
26
+
27
+	adminUserInfo := this.GetAdminUserInfo()
28
+	records, total, getRecordErr := sms_service.GetBatchSendRecords(adminUserInfo.CurrentOrgId, page, 10)
29
+	if getRecordErr != nil {
30
+		this.ErrorLog("获取短信批次记录失败:%v", getRecordErr)
31
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
32
+		return
33
+	}
34
+
35
+	this.ServeSuccessJSON(map[string]interface{}{
36
+		"records": records,
37
+		"total":   total,
38
+	})
39
+}

+ 2 - 1
controllers/短信模块临时备注 View File

@@ -1,2 +1,3 @@
1 1
 修改个人信息
2
-权限管理中添加管理员
2
+权限管理中添加管理员
3
+客户管理

+ 77 - 0
models/sms_models.go View File

@@ -0,0 +1,77 @@
1
+package models
2
+
3
+type SMSTemplate struct {
4
+	ID           int64  `gorm:"column:id"`
5
+	TemplateType int8   `gorm:"column:template_type"` // 模板类型 1.默认模板 2.自定义模板
6
+	TemplateID   int64  `gorm:"column:template_id"`   // 短信平台上的模板 id
7
+	MessageType  int8   `gorm:"column:message_type"`  // 短信类型 1.通知短信、2.服务短信 3.验证码短信
8
+	Content      string // 模板内容
9
+	ParamTypes   string `gorm:"column:param_types"` // 模板内容里的参数类型:1,2,3 。参数类型以逗号隔开,位置代表了参数‘{n+1}’,类型暂时有:1.用户名 2.商家简称 3.链接 4.商品名称 5.活动名称 6.验证码。(自定义模板是没有值的,因为它没有参数)
10
+	Autograph    string // 短信签名
11
+	OrgID        int64  `gorm:"column:org_id"` // 模板所属机构(自定义模板才有值)
12
+	Status       int8   // 模板状态 0.无效 1.有效 2.审核中
13
+	CreateTime   int64  `gorm:"column:ctime"` // 创建时间
14
+	ModifyTime   int64  `gorm:"column:mtime"` // 修改时间
15
+}
16
+
17
+func (SMSTemplate) TableName() string {
18
+	return "sgj_patient_sms_template"
19
+}
20
+
21
+type UserSMSFreeLimit struct {
22
+	ID         int64  `gorm:"column:id"`
23
+	OrgID      int64  `gorm:"column:org_id"`      // 机构 ID
24
+	TotalCount int    `gorm:"column:total_count"` // 免费额度,单位:条,下同
25
+	UsedCount  int    `gorm:"column:used_count"`  // 已用额度
26
+	ValidMonth string `gorm:"column:valid_month"` // 生效月份,格式:201804
27
+	Status     int8   // 状态 0.无效 1.有效
28
+	CreateTime int64  `gorm:"column:ctime"` // 创建时间
29
+	ModifyTime int64  `gorm:"column:mtime"` // 修改时间
30
+}
31
+
32
+func (UserSMSFreeLimit) TableName() string {
33
+	return "sgj_patient_user_sms_free_limit"
34
+}
35
+
36
+type SMSBatch struct {
37
+	ID          int64  `gorm:"column:id"`
38
+	OrgID       int64  `gorm:"column:org_id"`          // 机构 ID
39
+	TemplateID  int64  `gorm:"column:sms_template_id"` // 对应短信平台上的模板 ID
40
+	Autograph   string // 短信签名
41
+	Params      string // 模板参数,以“,”隔开
42
+	FullContent string `gorm:"column:full_content"` // 完整短信内容
43
+	Mobiles     string // 接收手机号,以“,”隔开
44
+	SendTime    int64  `gorm:"column:send_time"` // 发送时间
45
+	Status      int8   // 状态: 1.待审核 2.审核未通过 3.未发送 4.已发送 5.发送失败
46
+	CreateTime  int64  `gorm:"column:ctime"` // 创建时间
47
+	ModifyTime  int64  `gorm:"column:mtime"` // 修改时间
48
+}
49
+
50
+func (SMSBatch) TableName() string {
51
+	return "sgj_patient_sms_batch"
52
+}
53
+
54
+type SMSSendStatus struct {
55
+	ID         int64  `gorm:"column:id"`
56
+	BatchID    int64  `gorm:"batch_id"` // 批次 ID,对应 SMSBatch.ID
57
+	Mobile     string // 接收手机号
58
+	Status     int8   // 发送结果状态: 0.失败 1.成功
59
+	Code       string // 短信平台返回的错误码
60
+	Msg        string // 短信平台返回的错误信息
61
+	CreateTime int64  `gorm:"column:ctime"` // 创建时间
62
+	ModifyTime int64  `gorm:"column:mtime"` // 修改时间
63
+}
64
+
65
+func (SMSSendStatus) TableName() string {
66
+	return "sgj_patient_sms_send_status"
67
+}
68
+
69
+// 1.待审核 2.审核未通过 3.未发送 4.已发送 5.发送失败
70
+const (
71
+	SMSBatchStatusInReview   = int8(1)
72
+	SMSBatchStatusUnapproved = int8(2)
73
+	SMSBatchStatusUnsend     = int8(3)
74
+	SMSBatchStatusDidSend    = int8(4)
75
+	SMSBatchStatusSendFailed = int8(5)
76
+	SMSBatchStatusSending    = int8(6)
77
+)

+ 2 - 0
routers/router.go View File

@@ -9,6 +9,7 @@ import (
9 9
 	"SCRM/controllers/members"
10 10
 	"SCRM/controllers/mpwechat"
11 11
 	"SCRM/controllers/role"
12
+	"SCRM/controllers/sms"
12 13
 
13 14
 	"github.com/astaxie/beego"
14 15
 	"github.com/astaxie/beego/plugins/cors"
@@ -31,4 +32,5 @@ func init() {
31 32
 	marketing_tool.RegisterRouters()
32 33
 	article.RegisterRouters()
33 34
 	mpwechat.RegisterRouters()
35
+	sms.RegisterRouters()
34 36
 }

+ 31 - 0
service/sms_service/sms_service.go View File

@@ -0,0 +1,31 @@
1
+package sms_service
2
+
3
+import (
4
+	"SCRM/models"
5
+	"SCRM/service"
6
+)
7
+
8
+func GetBatchSendRecords(orgID int64, page int, count int) ([]*SMSBatchListViewModel, int, error) {
9
+	if count <= 0 {
10
+		return []*SMSBatchListViewModel{}, 0, nil
11
+	}
12
+	var viewModels []*SMSBatchListViewModel = make([]*SMSBatchListViewModel, 0)
13
+	readDB := service.PatientReadDB()
14
+	var total int
15
+	getTotalErr := readDB.Model(&models.SMSBatch{}).Where("org_id = ?", orgID).Count(&total).Error
16
+	if getTotalErr != nil {
17
+		return nil, 0, getTotalErr
18
+	}
19
+
20
+	rows, err := readDB.Raw("SELECT b.full_content, b.status, (SELECT COUNT(id) AS c FROM sgj_patient_sms_send_status WHERE batch_id = b.id) AS total_count, (SELECT COUNT(id) AS c FROM sgj_patient_sms_send_status WHERE batch_id = b.id AND STATUS = '1') AS success_count FROM sgj_patient_sms_batch AS b WHERE b.org_id = ? ORDER BY b.id LIMIT ? OFFSET ?;", orgID, count, (page-1)*count).Rows()
21
+	defer rows.Close()
22
+	if err != nil {
23
+		return nil, 0, err
24
+	}
25
+	for rows.Next() {
26
+		var viewModel SMSBatchListViewModel
27
+		readDB.ScanRows(rows, &viewModel)
28
+		viewModels = append(viewModels, &viewModel)
29
+	}
30
+	return viewModels, total, nil
31
+}

+ 8 - 0
service/sms_service/sms_vms.go View File

@@ -0,0 +1,8 @@
1
+package sms_service
2
+
3
+type SMSBatchListViewModel struct {
4
+	FullContent  string `json:"full_content"`  // 发送内容
5
+	Status       int8   `json:"status"`        // 批次状态 (值同 sms_models 中的 SMSBatchStatuss)
6
+	TotalCount   int    `json:"total_count"`   // 发送人数
7
+	SuccessCount int    `json:"success_count"` // 到达条数
8
+}