Browse Source

2023-10-12

zoie 1 year ago
parent
commit
5e721ba0b9

+ 11 - 5
README.md

@@ -1,11 +1,17 @@
 # FollowUp_Notice
 
-仓库管理
+### 赛邮云
 
-### 导入线上库
+#### 短信
+多少字算一条短信?
+短信按照 70 字符为一条计费,当超过 70 字符按照每 67 字符分成多条短信计费,最多支持 1000 字符(不论中英文、标点符号都为 1 个字符计算)。仅为计费方式,短信在用户的手机界面上不会被分开,还是显示为一条短信。
+比如,当一条短信长度为 210 字符时,将分成 67 字+ 67 字+ 67 字+ 9 字的 4 条短信来计费,发送到用户那里,是一条 210 字符的长短信。
 
-git config --global url."git@git.baozhida.cn/ERP_libs".insteadOf "http://120.55.48.97:3000/bzd_zeng/BZD_libs"
+#### 语音
+0.09元/分钟
+只要拨打成功就计费,不管用户有没有接听,(接口无法获取用户是否拒接,在赛邮云平台上才能显示失败退费)
 
-### 导入本地库
 
-go mod edit -replace git.baozhida.cn/ERP_libs=/Users/zoie/work/bzd_project/BZD_libs
+### 华为云
+#### 语音
+华为语音通知8008放音收号失败,也视为通话成功

+ 3 - 2
conf/app.conf

@@ -35,14 +35,15 @@ SUBMAIL_Sms_Signature = "f8e63844edd79d5bd2ab4a3d92c3b820"
 SUBMAIL_Voice_Appid = "22184"
 SUBMAIL_Voice_Signature = "c3e29e10daeea889cd72dd6375b4347e"
 SUBMAIL_Sms_Fee = 0.08
-Voice_Project = "vTHhS1"
+SUBMAIL_Voice_Project = "vTHhS1"
+SUBMAIL_VoiceCall_Fee = 0.12
 
 VoiceCall_BaseUrl = "https://rtccall.cn-north-1.myhuaweicloud.cn:443"
 VoiceCall_AppKey = "Zy8539Sa61Iv5fo5iGNWLcV24KI1"
 VoiceCall_AppSecret = "KNZ3OFv8eVF7zO5smbr0160WS4Az"
 VoiceCall_Template = "1101dc0ebc154a5a9e7c4e5f11bfdb41"
 VoiceCall_Phone = "+8651668971369"
-VoiceCall_Fee = 0.12
+VoiceCall_Fee = 0.4
 
 # 满意度调查
 VoiceCall_Satisfaction_Template1 = "756c9d79a36b4dd4a38c7758cc8becc8"

+ 2 - 1
conf/config.go

@@ -37,7 +37,8 @@ var SUBMAIL_Sms_Signature, _ = beego.AppConfig.String("SUBMAIL_Sms_Signature")
 var SUBMAIL_Voice_Appid, _ = beego.AppConfig.String("SUBMAIL_Voice_Appid")
 var SUBMAIL_Voice_Signature, _ = beego.AppConfig.String("SUBMAIL_Voice_Signature")
 var SUBMAIL_Sms_Fee, _ = beego.AppConfig.Float("SUBMAIL_Sms_Fee")
-var Voice_Project, _ = beego.AppConfig.String("Voice_Project")
+var SUBMAIL_Voice_Project, _ = beego.AppConfig.String("SUBMAIL_Voice_Project")
+var SUBMAIL_VoiceCall_Fee, _ = beego.AppConfig.Float("SUBMAIL_VoiceCall_Fee")
 
 var VoiceCall_BaseUrl, _ = beego.AppConfig.String("VoiceCall_BaseUrl")
 var VoiceCall_AppKey, _ = beego.AppConfig.String("VoiceCall_AppKey")

+ 198 - 4
controllers/Illness.go

@@ -2,13 +2,17 @@ package controllers
 
 import (
 	"FollowUp_Notice/conf"
+	"FollowUp_Notice/http/submail"
 	"FollowUp_Notice/lib"
 	"FollowUp_Notice/models/Account"
 	"FollowUp_Notice/models/Illness"
+	"FollowUp_Notice/models/Patient"
 	"FollowUp_Notice/models/System"
 	beego "github.com/beego/beego/v2/server/web"
+	"github.com/robfig/cron/v3"
 	"math"
 	"strconv"
+	"strings"
 )
 
 type IllnessController struct {
@@ -62,7 +66,7 @@ func (c *IllnessController) Illness_Add() {
 
 	Id, err := Illness.Add_Illness(var_)
 	if err != nil {
-		c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败"}
 		c.ServeJSON()
 		return
 	}
@@ -80,7 +84,7 @@ func (c *IllnessController) Illness_Edit() {
 
 	Illness_r, err := Illness.Read_Illness_ById(T_id)
 	if err != nil {
-		c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
 		c.ServeJSON()
 		return
 	}
@@ -91,7 +95,7 @@ func (c *IllnessController) Illness_Edit() {
 	Illness_r.T_sort = T_sort
 
 	if err = Illness.Update_Illness(Illness_r, "T_name", "T_sort"); err != nil {
-		c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败"}
 		c.ServeJSON()
 		return
 	}
@@ -107,7 +111,7 @@ func (c *IllnessController) Illness_Del() {
 	T_id, _ := c.GetInt("T_id")
 	Illness_r, err := Illness.Read_Illness_ById(T_id)
 	if err != nil {
-		c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
 		c.ServeJSON()
 		return
 	}
@@ -124,3 +128,193 @@ func (c *IllnessController) Illness_Del() {
 	c.ServeJSON()
 	return
 }
+
+// 疾病
+func (c *IllnessController) IllnessNotice_List() {
+
+	// 分页参数 初始化
+	page, _ := c.GetInt("page")
+	if page < 1 {
+		page = 1
+	}
+	page_z, _ := c.GetInt("page_z")
+	if page_z < 1 {
+		page_z = conf.Page_size
+	}
+	T_Illness_id, _ := c.GetInt("T_Illness_id")
+
+	// 查询
+	T_name := c.GetString("T_name")
+	T_template_status := c.GetString("T_template_status")
+
+	R_List, R_cnt := Illness.Read_IllnessNotice_List(T_Illness_id, T_name, T_template_status, page, page_z)
+
+	var r_jsons lib.R_JSONS
+	r_jsons.Num = R_cnt
+	r_jsons.Data = R_List
+	r_jsons.Page = page
+	r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
+	c.ServeJSON()
+	return
+}
+func (c *IllnessController) IllnessNotice_Add() {
+
+	T_Illness_id, _ := c.GetInt("T_Illness_id") // 疾病id
+	T_name := c.GetString("T_name")             // 名称
+	T_content := c.GetString("T_content")       // 内容
+	// 向赛邮添加短信模板
+	template_content := strings.Replace(T_content, "{患者名称}", "@var(name)", -1)
+	template_content = strings.Replace(template_content, "{复诊时间}", "@var(time)", -1)
+	temp, err := submail.SmsTemplate_Post(c.User.T_user, template_content)
+	if err != nil || temp.Status != "success" {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "创建短信模板失败"}
+		c.ServeJSON()
+		return
+	}
+	var_ := Illness.IllnessNotice{
+		T_Illness_id:      T_Illness_id,
+		T_name:            T_name,
+		T_content:         T_content,
+		T_State:           1,
+		T_template_id:     temp.Template_id,
+		T_template_status: "1",
+	}
+
+	Id, err := Illness.Add_IllnessNotice(var_)
+	if err != nil {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败"}
+		c.ServeJSON()
+		return
+	}
+
+	System.Add_UserLogs_T(c.User.T_uuid, "疾病通知内容", "添加", var_)
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
+	c.ServeJSON()
+	return
+}
+func (c *IllnessController) IllnessNotice_Edit() {
+	T_id, _ := c.GetInt("T_id")
+	T_name := c.GetString("T_name")       // 名称
+	T_content := c.GetString("T_content") // 内容
+
+	IllnessNotice_r, err := Illness.Read_IllnessNotice_ById(T_id)
+	if err != nil {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
+		c.ServeJSON()
+		return
+	}
+
+	if IllnessNotice_r.T_content != T_content {
+		// 向赛邮添加短信模板
+		template_content := strings.Replace(T_content, "{患者名称}", "@var(name)", -1)
+		template_content = strings.Replace(template_content, "{复诊时间}", "@var(time)", -1)
+		temp, err := submail.SmsTemplate_Put(IllnessNotice_r.T_template_id, c.User.T_user, template_content)
+		if err != nil || temp.Status != "success" {
+			c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改短信模板失败"}
+			c.ServeJSON()
+			return
+		}
+		IllnessNotice_r.T_content = T_content
+		IllnessNotice_r.T_template_status = "1"
+		IllnessNotice_r.T_template_status_description = ""
+		IllnessNotice_r.T_template_reject_reson = ""
+	}
+
+	if len(T_name) > 0 {
+		IllnessNotice_r.T_name = T_name
+	}
+
+	if err = Illness.Update_IllnessNotice(IllnessNotice_r, "T_name", "T_content", "T_template_status", "T_template_status_description", "T_template_reject_reson"); err != nil {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败"}
+		c.ServeJSON()
+		return
+	}
+
+	System.Add_UserLogs_T(c.User.T_uuid, "疾病通知内容", "修改", IllnessNotice_r)
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
+	c.ServeJSON()
+	return
+}
+func (c *IllnessController) IllnessNotice_Del() {
+
+	T_id, _ := c.GetInt("T_id")
+	IllnessNotice_r, err := Illness.Read_IllnessNotice_ById(T_id)
+	if err != nil {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
+		c.ServeJSON()
+		return
+	}
+
+	count, err := Patient.Read_PatientRevisitRecord_Count_ByT_illness_notice(IllnessNotice_r.T_Illness_id)
+	if err != nil {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
+		c.ServeJSON()
+		return
+	}
+	if count > 0 {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "此内容已关联患者通知信息,禁止删除!"}
+		c.ServeJSON()
+		return
+	}
+	// 向赛邮删除短信模板
+	temp, err := submail.SmsTemplate_Delete(IllnessNotice_r.T_template_id)
+	if err != nil || temp.Status != "success" {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除短信模板失败"}
+		c.ServeJSON()
+		return
+	}
+
+	if err = Illness.Delete_IllnessNotice(IllnessNotice_r); err != nil {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
+		c.ServeJSON()
+		return
+	}
+
+	System.Add_UserLogs(c.User.T_uuid, "疾病通知内容", "删除", strconv.Itoa(T_id))
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
+	c.ServeJSON()
+	return
+}
+
+func Cron_Illness() {
+
+	//创建一个定时任务对象
+	c := cron.New(cron.WithSeconds())
+	//给对象增加定时任务
+	c.AddFunc("0 */1 * * * ?", Cron_Illness_IllnessNotice)
+
+	//启动定时任务
+	c.Start()
+	defer c.Stop()
+
+	//查询语句,阻塞,让main函数不退出,保持程序运行
+	select {}
+
+}
+
+// 同步赛邮云的模板审核状态
+func Cron_Illness_IllnessNotice() {
+
+	list, _ := Illness.Read_IllnessNotice_List(0, "", "1", 0, 9999)
+	for _, v := range list {
+		// 查询赛邮审核状态
+		temp, err := submail.SmsTemplate_Get(v.T_template_id)
+		if err != nil || temp.Status != "success" {
+			continue
+		}
+		if temp.Template.Template_status != "1" {
+			var_ := Illness.IllnessNotice{
+				Id:                            v.Id,
+				T_template_status:             temp.Template.Template_status,
+				T_template_status_description: temp.Template.Template_status_description,
+				T_template_reject_reson:       temp.Template.Template_reject_reson,
+			}
+			Illness.Update_IllnessNotice(var_, "T_template_status", "T_template_status_description", "T_template_reject_reson")
+		}
+	}
+}

+ 384 - 104
controllers/Patient.go

@@ -15,6 +15,7 @@ import (
 	"FollowUp_Notice/models/Tag"
 	"encoding/json"
 	"fmt"
+	"github.com/beego/beego/v2/adapter/orm"
 	beego "github.com/beego/beego/v2/server/web"
 	"github.com/robfig/cron/v3"
 	"github.com/signintech/gopdf"
@@ -62,7 +63,7 @@ func (c *PatientController) Patient_List() {
 	// 通知状态 1待通知 2已通知
 	T_notice, _ := c.GetInt("T_notice")
 	// 复诊状态 1正常 2超时
-	T_follow_up, _ := c.GetInt("T_follow_up")
+	//T_follow_up, _ := c.GetInt("T_follow_up")
 	// 年龄排序 1-升序 2降序
 	T_age_sort, _ := c.GetInt("T_age_sort")
 	// 下次复诊时间 1-升序 2降序
@@ -70,7 +71,7 @@ func (c *PatientController) Patient_List() {
 	Tag.Read_Tag_All_Map()
 	Illness.Read_Illness_All_Map()
 	Surgical.Read_Surgical_All_Map()
-	R_List, R_cnt := Patient.Read_Patient_List(c.User.Id, T_number, T_name, T_tag, T_illness, T_surgical, T_notice, T_follow_up, T_age_sort, T_next_time_sort, page, page_z)
+	R_List, R_cnt := Patient.Read_Patient_List(c.User.Id, T_number, T_name, T_tag, T_illness, T_surgical, T_notice, T_age_sort, T_next_time_sort, page, page_z)
 
 	var r_jsons lib.R_JSONS
 	r_jsons.Num = R_cnt
@@ -97,7 +98,6 @@ func (c *PatientController) Patient_Add() {
 	T_notice_message, _ := c.GetInt("T_notice_message")
 	T_notice_interval := c.GetString("T_notice_interval")
 	T_record := c.GetString("T_record")
-
 	var_ := Patient.Patient{
 		T_uid:             c.User.Id,
 		T_number:          T_number,
@@ -110,40 +110,46 @@ func (c *PatientController) Patient_Add() {
 		T_notice_phone:    T_notice_phone,
 		T_notice_message:  T_notice_message,
 		T_notice_interval: T_notice_interval,
-		T_record:          T_record,
-		T_State:           1,
-	}
-	T_record_list := strings.Split(strings.Trim(T_record, "|"), "|")
-	var T_time string  // 复诊时间
-	var T_interval int // 复诊间隔
-	if len(T_record_list) > 0 {
-		temp := T_record_list[len(T_record_list)-1]
-		T_time = strings.Split(temp, ",")[0]
-		T_interval, _ = strconv.Atoi(strings.Split(temp, ",")[1])
-		t, _ := lib.DateStrToTime(T_time)
-		nextTime := t.AddDate(0, 0, T_interval)
-		// 复诊状态 1正常 2超时 3结束
-		var_.T_follow_up = 1
-		if nextTime.Before(time.Now()) {
-			var_.T_follow_up = 2
-		}
-		if T_interval == 0 {
-			var_.T_follow_up = 3
-		}
-		var_.T_next_time = nextTime.Format("2006-01-02")
-		var_.T_notice = 1
+		//T_record:          T_record,
+		T_State: 1,
 	}
-
-	_, err := Patient.Add_Patient(var_)
+	id, err := Patient.Add_Patient(var_)
 	if err != nil {
 		c.Data["json"] = lib.JSONS{Code: 209, Msg: "添加失败!"}
 		c.ServeJSON()
 		return
 	}
 
+	T_record_list := strings.Split(strings.Trim(T_record, "|"), "|")
+	if len(T_record_list) > 0 && len(T_record) > 0 {
+		for _, record := range T_record_list {
+			recordId := lib.To_int(strings.Split(record, ",")[0])
+			date := strings.Split(record, ",")[1]
+			illnessNoticeId := lib.To_int(strings.Split(record, ",")[2])
+			if recordId > 0 {
+				PatientRevisitRecord_Edit(c.User, recordId, illnessNoticeId, date)
+			} else {
+				PatientRevisitRecord_Add(c.User, int(id), illnessNoticeId, date)
+			}
+		}
+
+		// 更新患者通知信息
+		psr, err := Patient.Read_Next_PatientRevisitRecord(int(id))
+		if err == nil {
+			var_.Id = int(id)
+			var_.T_next_time = psr.T_date
+			var_.T_notice = psr.T_notice
+			if err = Patient.Update_Patient(var_, "T_next_time", "T_notice"); err != nil {
+				c.Data["json"] = lib.JSONS{Code: 208, Msg: "添加失败!"}
+				c.ServeJSON()
+				return
+			}
+		}
+	}
+
 	System.Add_UserLogs_T(c.User.T_uuid, "患者", "新增", var_)
 
-	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: id}
 	c.ServeJSON()
 	return
 
@@ -216,34 +222,28 @@ func (c *PatientController) Patient_Edit() {
 		patient.T_notice_interval = T_notice_interval
 		cols = append(cols, "T_notice_interval")
 	}
-	if len(T_record) > 0 {
-		patient.T_record = T_record
-		cols = append(cols, "T_record")
-	}
 	T_record_list := strings.Split(strings.Trim(T_record, "|"), "|")
-	var T_time string  // 复诊时间
-	var T_interval int // 复诊间隔
-	if len(T_record_list) > 0 {
-		temp := T_record_list[len(T_record_list)-1]
-		T_time = strings.Split(temp, ",")[0]
-		T_interval, _ = strconv.Atoi(strings.Split(temp, ",")[1])
-		t, _ := lib.DateStrToTime(T_time)
-		nextTime := t.AddDate(0, 0, T_interval)
-		nextTimeStr := nextTime.Format("2006-01-02")
-		if nextTimeStr != patient.T_next_time {
-			patient.T_follow_up = 1
-			if nextTime.Before(time.Now()) {
-				patient.T_follow_up = 2
+	if len(T_record_list) > 0 && len(T_record) > 0 {
+		for _, record := range T_record_list {
+			recordId := lib.To_int(strings.Split(record, ",")[0])
+			date := strings.Split(record, ",")[1]
+			illnessNoticeId := lib.To_int(strings.Split(record, ",")[2])
+			if recordId > 0 {
+				PatientRevisitRecord_Edit(c.User, recordId, illnessNoticeId, date)
+			} else {
+				PatientRevisitRecord_Add(c.User, patient.Id, illnessNoticeId, date)
 			}
-			if T_interval == 0 {
-				patient.T_follow_up = 3
-			}
-			patient.T_next_time = nextTimeStr
-			patient.T_notice = 1
 		}
+	}
 
+	// 更新患者通知信息
+	psr, err := Patient.Read_Next_PatientRevisitRecord(patient.Id)
+	if err == nil {
+		patient.T_next_time = psr.T_date
+		patient.T_notice = psr.T_notice
+		cols = append(cols, "T_next_time")
+		cols = append(cols, "T_notice")
 	}
-	cols = append(cols, "T_next_time", "T_notice", "T_follow_up")
 
 	if err = Patient.Update_Patient(patient, cols...); err != nil {
 		c.Data["json"] = lib.JSONS{Code: 208, Msg: "修改失败!"}
@@ -292,6 +292,213 @@ func (c *PatientController) Patient_Del() {
 
 }
 
+// 复诊记录
+func (c *PatientController) PatientRevisitRecord_List() {
+
+	// 分页参数 初始化
+	page, _ := c.GetInt("page")
+	if page < 1 {
+		page = 1
+	}
+	page_z, _ := c.GetInt("page_z")
+	if page_z < 1 {
+		page_z = conf.Page_size
+	}
+	T_pid, _ := c.GetInt("T_pid")
+	Illness.Read_IllnessNotice_All_Map()
+	R_List, R_cnt := Patient.Read_PatientRevisitRecord_List(T_pid, page, page_z)
+
+	var r_jsons lib.R_JSONS
+	r_jsons.Num = R_cnt
+	r_jsons.Data = R_List
+	r_jsons.Page = page
+	r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
+	c.ServeJSON()
+	return
+}
+func PatientRevisitRecord_Add(user Account.User, T_pid, T_illnessNotice int, T_date string) (err error) {
+
+	//date, _ := lib.DateStrToTime(T_date)
+	//nowDate := lib.NowDate()
+	// 超过12点,最早只能通知后天的复诊(提前一天)
+	//if time.Now().Hour() >= 12 {
+	//	if nowDate.After(date.AddDate(0, 0, -2)) {
+	//		c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("复诊时间必须大于%s!", nowDate.AddDate(0, 0, 1).Format("2006年01月02日"))}
+	//		c.ServeJSON()
+	//		return
+	//	}
+	//} else {
+	//	// 未超过12点,最早只能通知明天的复诊(提前一天)
+	//	if nowDate.After(date.AddDate(0, 0, -1)) {
+	//		c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("复诊时间必须大于%s!", nowDate.Format("2006年01月02日"))}
+	//		c.ServeJSON()
+	//		return
+	//	}
+	//}
+
+	var_ := Patient.PatientRevisitRecord{
+		T_date:           T_date,
+		T_pid:            T_pid,
+		T_illness_notice: T_illnessNotice,
+		T_notice:         1,
+	}
+
+	//prr, err := Patient.Read_PatientRevisitRecord_ByT_date(T_pid, T_date)
+	//if prr.Id > 0 {
+	//	return errors.New("日期重复")
+	//}
+	_, err = Patient.Add_PatientRevisitRecord(var_)
+	if err != nil {
+		return err
+	}
+
+	System.Add_UserLogs_T(user.T_uuid, "复诊记录", "添加", var_)
+
+	return nil
+}
+func PatientRevisitRecord_Edit(user Account.User, T_id, T_illnessNotice int, T_date string) (err error) {
+
+	PatientRevisitRecord_r, err := Patient.Read_PatientRevisitRecord_ById(T_id)
+	if err != nil {
+		return err
+	}
+
+	//prr, err := Patient.Read_PatientRevisitRecord_ByT_date(PatientRevisitRecord_r.T_pid, T_date)
+	//if prr.Id > 0 && prr.Id != PatientRevisitRecord_r.Id {
+	//	err = errors.New("日期重复")
+	//	return
+	//}
+
+	if PatientRevisitRecord_r.T_illness_notice == T_illnessNotice && PatientRevisitRecord_r.T_date == T_date {
+		return nil
+	}
+
+	// 已通知,禁止修改
+	if PatientRevisitRecord_r.T_notice == 2 {
+		return nil
+	}
+
+	if T_illnessNotice > 0 {
+		PatientRevisitRecord_r.T_illness_notice = T_illnessNotice
+	}
+	if len(T_date) > 0 {
+		PatientRevisitRecord_r.T_date = T_date
+	}
+
+	if err = Patient.Update_PatientRevisitRecord(PatientRevisitRecord_r, "T_illness_notice", "T_date"); err != nil {
+		return
+	}
+
+	//patient, err := Patient.Read_Patient_ById(PatientRevisitRecord_r.T_pid)
+	//if err != nil {
+	//	return
+	//}
+	//psr, err := Patient.Read_Next_PatientRevisitRecord(PatientRevisitRecord_r.T_pid)
+	//if err == nil {
+	//	patient.T_next_time = psr.T_date
+	//	patient.T_notice = psr.T_notice
+	//	if err = Patient.Update_Patient(patient, "T_next_time", "T_notice"); err != nil {
+	//		return
+	//	}
+	//}
+
+	System.Add_UserLogs_T(user.T_uuid, "复诊记录", "修改", PatientRevisitRecord_r)
+
+	return nil
+}
+
+func (c *PatientController) PatientRevisitRecord_Del() {
+
+	T_id, _ := c.GetInt("T_id")
+	if T_id == 0 {
+		c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
+		c.ServeJSON()
+		return
+	}
+	PatientRevisitRecord_r, err := Patient.Read_PatientRevisitRecord_ById(T_id)
+	if err != nil {
+		c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
+		c.ServeJSON()
+		return
+	}
+
+	// 已通知,禁止删除
+	if PatientRevisitRecord_r.T_notice == 2 {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "已通知,禁止删除!"}
+		c.ServeJSON()
+		return
+	}
+
+	if err = Patient.Delete_PatientRevisitRecord(PatientRevisitRecord_r); err != nil {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
+		c.ServeJSON()
+		return
+	}
+
+	patient, err := Patient.Read_Patient_ById(PatientRevisitRecord_r.T_pid)
+	if err != nil {
+		c.Data["json"] = lib.JSONS{Code: 203, Msg: "查询患者信息失败!"}
+		c.ServeJSON()
+		return
+	}
+	count, err := Patient.Read_PatientRevisitRecord_Count_ByT_pid(patient.Id)
+	if err != nil {
+		c.Data["json"] = lib.JSONS{Code: 203, Msg: "查询患者信息失败!"}
+		c.ServeJSON()
+		return
+	}
+
+	// 通知记录为0时,将患者信息复诊时间和通知状态置为空
+	if count == 0 {
+		patient.T_next_time = ""
+		patient.T_notice = 0
+		if err = Patient.Update_Patient(patient, "T_next_time", "T_notice"); err != nil {
+			c.Data["json"] = lib.JSONS{Code: 208, Msg: "修改失败!"}
+			c.ServeJSON()
+			return
+		}
+	}
+
+	psr, err := Patient.Read_Next_PatientRevisitRecord(PatientRevisitRecord_r.T_pid)
+	if err == nil {
+		patient.T_next_time = psr.T_date
+		patient.T_notice = psr.T_notice
+		if err = Patient.Update_Patient(patient, "T_next_time", "T_notice"); err != nil {
+			c.Data["json"] = lib.JSONS{Code: 208, Msg: "修改失败!"}
+			c.ServeJSON()
+			return
+		}
+	}
+	if err == orm.ErrNoRows {
+		psr, err = Patient.Read_Last_PatientRevisitRecord(PatientRevisitRecord_r.T_pid)
+		if err == nil {
+			patient.T_next_time = psr.T_date
+			patient.T_notice = psr.T_notice
+			// 已复诊 - 结束
+			// 未复诊 - 超时
+			// patient.T_follow_up 复诊状态 1正常 2超时 3结束
+			//if psr.T_follow_up == 1 {
+			//	patient.T_follow_up = 3
+			//} else {
+			//	patient.T_follow_up = 2
+			//}
+			if err = Patient.Update_Patient(patient, "T_next_time", "T_notice"); err != nil {
+				c.Data["json"] = lib.JSONS{Code: 208, Msg: "修改失败!"}
+				c.ServeJSON()
+				return
+			}
+		}
+	}
+
+	System.Add_UserLogs(c.User.T_uuid, "复诊记录", "删除", strconv.Itoa(T_id))
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
+	c.ServeJSON()
+	return
+}
+
 // 发送患者满意度调查
 func (c *PatientController) Patient_Send_Satisfaction() {
 	T_pid := c.GetString("T_pid")
@@ -346,6 +553,12 @@ func (c *PatientController) VoiceCall_Status() {
 	// {"eventType":"callout","statusInfo":{"sessionId":"1201_14852_4294967295_20230529072219@callenabler245.huaweicaas.com","timestamp":"2023-05-29 07:22:19","caller":"+8651668971369","called":"+8618086869080"}}
 	logs.Println("VoiceCall RequestBody-", string(c.Ctx.Input.RequestBody))
 
+	//callout:呼出事件
+	//alerting:振铃事件
+	//answer:应答事件
+	//collectInfo:放音收号结果事件
+	//disconnect:挂机事件
+
 	type RequestBody struct {
 		EventType  string `json:"eventType"`
 		StatusInfo struct {
@@ -373,13 +586,23 @@ func (c *PatientController) VoiceCall_Status() {
 		return
 	}
 
+	// 应答时间 向redis存入用户接听时间
+	if body.EventType == "answer" {
+		Patient.Redis_PatientSend_Set(body.StatusInfo.SessionId, body.StatusInfo.Timestamp)
+	}
+
 	if body.EventType == "disconnect" {
-		if body.StatusInfo.StateCode == 0 {
+		sTime, _ := Patient.Redis_PatientSend_Get(body.StatusInfo.SessionId)
+		s_time, _ := lib.TimeStrToTime(sTime)
+		e_time, _ := lib.TimeStrToTime(body.StatusInfo.Timestamp)
+		// 华为语音通知8008放音收号失败,也视为通话成功
+		if body.StatusInfo.StateCode == 0 || body.StatusInfo.StateCode == 8008 {
 			r.T_State = 1
 		}
 		r.T_code = strconv.Itoa(body.StatusInfo.StateCode)
 		r.T_remark = body.StatusInfo.StateDesc
-		err = Patient.Update_PatientSend(r, "T_State", "T_remark", "T_code")
+		r.T_fee = e_time.Sub(s_time).Seconds()
+		err = Patient.Update_PatientSend(r, "T_State", "T_remark", "T_code", "T_fee")
 		if err != nil {
 			c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改发送状态失败!"}
 			c.ServeJSON()
@@ -500,8 +723,8 @@ func (c *PatientController) Patient_Import() {
 		message = 1
 	}
 	// 下次复诊间隔天数
-	T_next_interval := c.GetString("T_next_interval")
-	T_record := time.Now().Format("2006-01-02") + "," + T_next_interval + "|"
+	//T_next_interval := c.GetString("T_next_interval")
+	//T_record := time.Now().Format("2006-01-02") + "," + T_next_interval + "|"
 	var_ := Patient.Patient{
 		T_uid:             c.User.Id,
 		T_number:          T_number,
@@ -514,29 +737,29 @@ func (c *PatientController) Patient_Import() {
 		T_notice_phone:    phone,
 		T_notice_message:  message,
 		T_notice_interval: "1,3",
-		T_record:          T_record,
-		T_State:           1,
-	}
-	T_record_list := strings.Split(strings.Trim(T_record, "|"), "|")
-	var T_time string  // 复诊时间
-	var T_interval int // 复诊间隔
-	if len(T_record_list) > 0 {
-		temp := T_record_list[len(T_record_list)-1]
-		T_time = strings.Split(temp, ",")[0]
-		T_interval, _ = strconv.Atoi(strings.Split(temp, ",")[1])
-		t, _ := lib.DateStrToTime(T_time)
-		nextTime := t.AddDate(0, 0, T_interval)
-		// 复诊状态 1正常 2超时 3结束
-		var_.T_follow_up = 1
-		if nextTime.Before(time.Now()) {
-			var_.T_follow_up = 2
-		}
-		if T_interval == 0 {
-			var_.T_follow_up = 3
-		}
-		var_.T_next_time = nextTime.Format("2006-01-02")
-		var_.T_notice = 1
+		//T_record:          T_record,
+		T_State: 1,
 	}
+	//T_record_list := strings.Split(strings.Trim(T_record, "|"), "|")
+	//var T_time string  // 复诊时间
+	//var T_interval int // 复诊间隔
+	//if len(T_record_list) > 0 {
+	//	temp := T_record_list[len(T_record_list)-1]
+	//	T_time = strings.Split(temp, ",")[0]
+	//	T_interval, _ = strconv.Atoi(strings.Split(temp, ",")[1])
+	//	t, _ := lib.DateStrToTime(T_time)
+	//	nextTime := t.AddDate(0, 0, T_interval)
+	//	// 复诊状态 1正常 2超时 3结束
+	//	var_.T_follow_up = 1
+	//	if nextTime.Before(time.Now()) {
+	//		var_.T_follow_up = 2
+	//	}
+	//	if T_interval == 0 {
+	//		var_.T_follow_up = 3
+	//	}
+	//	var_.T_next_time = nextTime.Format("2006-01-02")
+	//	var_.T_notice = 1
+	//}
 
 	_, err = Patient.Add_Patient(var_)
 	if err != nil {
@@ -809,8 +1032,9 @@ func Cron_Patient() {
 	c := cron.New(cron.WithSeconds())
 	//给对象增加定时任务
 	//c.AddFunc("0 */1 * * * ?", Cron_Patient_ChangeFollowUp)
-	c.AddFunc("@daily", Cron_Patient_ChangeFollowUp) // 修改复诊状态
+	c.AddFunc("@daily", Cron_Patient_ChangeNextTime) // 修改下次复诊时间
 	c.AddFunc("0 0 12 * * *", Cron_Patient_Notice)   // 消息通知
+	//c.AddFunc("0 */1 * * * ?", Cron_Patient_Notice) // 消息通知
 
 	//启动定时任务
 	c.Start()
@@ -821,36 +1045,57 @@ func Cron_Patient() {
 
 }
 
-// 修改患者复诊状态 每晚0点统计
-// 已通知并且下次复诊时间超过当期时间 已过期
-func Cron_Patient_ChangeFollowUp() {
+// 修改患者下次复诊时间
+// 复诊记录有超过今日的,替换为今日后最近一条
+// 复诊记录无超过今日的,替换为今日前最近一条
+func Cron_Patient_ChangeNextTime() {
 
 	T_date := time.Now().Format("2006-01-02")
-	logs.Info("开始处理" + T_date + "患者通知状态")
+	logs.Info("开始处理" + T_date + "下次通知时间")
 	// T_notice 通知状态 1待通知 2已通知
 	// T_follow_up 复诊状态 1正常 2超时
-	list, _ := Patient.Read_Patient_List(0, "", "", 0, 0, 0, 2, 1, 0, 0, 0, 9999)
-	for _, v := range list {
-		nextTime, _ := lib.DateStrToTime(v.T_next_time)
-		if nextTime.Before(time.Now()) {
-			var_ := Patient.Patient{Id: v.Id, T_follow_up: 2}
-			if err := Patient.Update_Patient(var_, "T_follow_up"); err != nil {
-				System.Add_SysLogs_T("复诊状态", "修改失败", var_)
+	list, _ := Patient.Read_Patient_List_Lt_NextTime(0, T_date)
+	for _, patient := range list {
+
+		psr, err := Patient.Read_Next_PatientRevisitRecord(patient.Id)
+		if err == nil {
+			p := Patient.Patient{
+				Id:          patient.Id,
+				T_next_time: psr.T_date,
+				T_notice:    psr.T_notice,
+			}
+
+			if err = Patient.Update_Patient(p, "T_next_time", "T_notice"); err != nil {
+				System.Add_SysLogs_T("复诊状态", "修改失败", p)
+			}
+		}
+		if err == orm.ErrNoRows {
+			psr, err = Patient.Read_Last_PatientRevisitRecord(patient.Id)
+			if err == nil {
+				p := Patient.Patient{
+					Id:          patient.Id,
+					T_next_time: psr.T_date,
+					T_notice:    psr.T_notice,
+				}
+				if psr.T_date == patient.T_next_time {
+					continue
+				}
+				if err = Patient.Update_Patient(p, "T_next_time", "T_notice"); err != nil {
+					System.Add_SysLogs_T("复诊状态", "修改失败", p)
+				}
 			}
 		}
 	}
 }
 
-// 给患者发送消息提醒 每天8点
-// 发送成功将通知状态修改未已通知H
+// 给患者发送消息提醒 每天12
+// 发送成功将通知状态修改为已通知
 func Cron_Patient_Notice() {
 
 	T_date := time.Now().Format("2006-01-02")
 	logs.Info("开始发送" + T_date + "患者通知")
 	// T_notice 通知状态 1待通知 2已通知
-	// T_follow_up 复诊状态 1正常 2超时 3结束
-	now := time.Now()
-	nowDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
+	nowDate := lib.NowDate()
 	userList, _ := Account.Read_User_List("", 0, 9999)
 	for _, user := range userList {
 		// T_arrears_notice 欠费通知 1继续通知  2终止通知
@@ -859,25 +1104,25 @@ func Cron_Patient_Notice() {
 		if (user.T_money <= 0 && user.T_arrears_notice == 2) || user.T_State == 2 {
 			continue
 		}
-		patientList, _ := Patient.Read_Patient_List(user.Id, "", "", 0, 0, 0, 0, 1, 0, 0, 0, 9999)
+		patientList := Patient.Read_Patient_List_For_Notice(user.Id, T_date)
 		for _, v := range patientList {
-			nextTime, _ := lib.DateStrToTime(v.T_next_time)
+			nextTime, _ := lib.DateStrToTime(v.T_date)
 			var success bool
 			// 提前1天
 			if strings.Contains(v.T_notice_interval, "1") && nextTime.AddDate(0, 0, -1) == nowDate {
-				success = Send_Notice(nextTime, user, v)
+				success = Send_Notice(nextTime, user, v, "提前一天")
 			}
 			// 提前2天
 			if strings.Contains(v.T_notice_interval, "2") && nextTime.AddDate(0, 0, -2) == nowDate {
-				success = Send_Notice(nextTime, user, v)
+				success = Send_Notice(nextTime, user, v, "提前两天")
 			}
 			// 提前3天
 			if strings.Contains(v.T_notice_interval, "3") && nextTime.AddDate(0, 0, -3) == nowDate {
-				success = Send_Notice(nextTime, user, v)
+				success = Send_Notice(nextTime, user, v, "提前三天")
 			}
 			// 提前7天
 			if strings.Contains(v.T_notice_interval, "7") && nextTime.AddDate(0, 0, -7) == nowDate {
-				success = Send_Notice(nextTime, user, v)
+				success = Send_Notice(nextTime, user, v, "提前七天")
 			}
 			if success == true {
 				// 通知状态 1待通知 2已通知
@@ -892,11 +1137,29 @@ func Cron_Patient_Notice() {
 }
 
 // 发送通知(短信、电话)
-func Send_Notice(nextTime time.Time, user Account.User_R, patient Patient.Patient_R) (Success bool) {
+func Send_Notice(nextTime time.Time, user Account.User_R, patient Patient.Patient_R2, days string) (Success bool) {
 
+	// 查询复诊记录id
+	revisit_record_r, err := Patient.Read_PatientRevisitRecord_ById(patient.T_patient_revisit_record_id)
+	if err != nil {
+		return false
+	}
+	// 查询疾病通知
+	IllnessNotice_r, err := Illness.Read_IllnessNotice_ById(revisit_record_r.T_illness_notice)
+	if err != nil {
+		return false
+	}
+	// 短信模板审核通过才能发送通知信息
+	if IllnessNotice_r.T_template_status != "2" {
+		return false
+	}
+	T_content := strings.Replace(IllnessNotice_r.T_content, "{患者名称}", patient.T_name, -1)
+	T_content = strings.Replace(T_content, "{复诊时间}", nextTime.Format("2006年01月02日"), -1)
+	T_remark := ""
 	//发送短信通知
 	if patient.T_notice_message == 1 {
-		res, err := submail.SmsXSend(user.T_template_id, patient.T_phone, patient.T_name, nextTime.Format("2006年01月02日"))
+
+		res, err := submail.SmsXSend(IllnessNotice_r.T_template_id, patient.T_phone, patient.T_name, nextTime.Format("2006年01月02日"))
 		if err != nil {
 			System.Add_SysLogs_T("复诊通知", "短信通知失败", patient)
 		}
@@ -912,16 +1175,22 @@ func Send_Notice(nextTime time.Time, user Account.User_R, patient Patient.Patien
 			T_code:   res.Code,
 			T_State:  1,
 		}
+		msg := ""
 		if res.Status == "error" {
 			smsSend.T_State = 0
+			msg = "通知失败"
 		}
 		if res.Status == "success" {
 			Success = true
+			msg = "通知成功"
 		}
 		_, err = Patient.Add_PatientSend(smsSend)
 		if err != nil {
 			System.Add_SysLogs_T("复诊通知", "添加发送记录失败", patient)
 		}
+
+		// 1201_134,2022-07-24,提前三天,电话,通知成功|1201_135,2022-07-24,提前三天,短信,通知成功
+		T_remark += fmt.Sprintf("%s,%s,%s,短信,%s|", res.Send_id, time.Now().Format("2006-01-02"), days, msg)
 	}
 
 	if patient.T_notice_phone == 1 {
@@ -953,12 +1222,13 @@ func Send_Notice(nextTime time.Time, user Account.User_R, patient Patient.Patien
 		//}
 
 		// ----------- 塞班语音通知
-		res, err := submail.VoiceXSend(patient.T_phone, user.T_user, patient.T_name, nextTime.Format("2006年01月02日"))
+		//res, err := submail.VoiceXSend(patient.T_phone, user.T_user, patient.T_name, nextTime.Format("2006年01月02日"))
+		res, err := submail.VoiceSend(patient.T_phone, user.T_user+"提醒您:"+T_content)
 		if err != nil {
 			System.Add_SysLogs_T("复诊通知", "电话通知失败", patient)
 		}
 
-		// 保存短信发送记录
+		// 保存语音发送记录
 		send := Patient.PatientSend{
 			T_uid:    user.Id,
 			T_pid:    patient.Id,
@@ -975,18 +1245,28 @@ func Send_Notice(nextTime time.Time, user Account.User_R, patient Patient.Patien
 		if err != nil {
 			System.Add_SysLogs_T("复诊通知", "添加语音发送记录失败", send)
 		}
+		msg := ""
 		if res.Status == "error" {
 			send.T_State = 0
+			msg = "通知失败"
 		}
 		if res.Status == "success" {
 			Success = true
+			msg = "通知成功"
 		}
 		_, err = Patient.Add_PatientSend(send)
 		if err != nil {
 			System.Add_SysLogs_T("复诊通知", "添加语音发送记录失败", send)
 		}
+		// 1201_134,2022-07-24,提前三天,电话,通知成功|1201_135,2022-07-24,提前三天,短信,通知成功
+		T_remark += fmt.Sprintf("%s,%s,%s,电话,%s|", res.Send_id, time.Now().Format("2006-01-02"), days, msg)
+	}
 
+	if Success == true {
+		revisit_record_r.T_notice = 2
 	}
+	revisit_record_r.T_remark += T_remark
+	Patient.Update_PatientRevisitRecord(revisit_record_r, "T_notice", "T_remark")
 
 	return Success
 }

+ 1 - 1
controllers/Tag.go

@@ -120,7 +120,7 @@ func (c *TagController) Tag_Del() {
 		c.ServeJSON()
 		return
 	}
-	PatientList, _ := Patient.Read_Patient_List(0, "", "", T_id, 0, 0, 0, 0, 0, 0, 0, 9999)
+	PatientList, _ := Patient.Read_Patient_List(0, "", "", T_id, 0, 0, 0, 0, 0, 0, 9999)
 	for _, r := range PatientList {
 		T_tag := strings.Replace(r.T_tag_str, fmt.Sprintf("|%d|", T_id), "", -1)
 		var_ := Patient.Patient{Id: r.Id, T_tag: T_tag}

+ 70 - 37
controllers/User.go

@@ -8,6 +8,7 @@ import (
 	"FollowUp_Notice/lib"
 	"FollowUp_Notice/logs"
 	"FollowUp_Notice/models/Account"
+	"FollowUp_Notice/models/Illness"
 	"FollowUp_Notice/models/Patient"
 	"FollowUp_Notice/models/System"
 	"encoding/json"
@@ -113,18 +114,36 @@ func (c *UserController) Get() {
 
 // 个人信息
 func (c *UserController) Info() {
+
 	type Info struct {
-		User   Account.User_R
-		Notice struct {
-			Sms       int64
-			VoiceCall int64
+		User         Account.User_R
+		UserPayMoney float32
+		Notice       struct {
+			Sms struct {
+				Success int64
+				Fail    int64
+			}
+			VoiceCall struct {
+				Success int64
+				Fail    int64
+			}
+			Satisfaction struct {
+				Success int64
+				Fail    int64
+			}
 		}
 	}
 	month := time.Now().Format("2006-01")
 	var info Info
 	info.User = Account.UserToUser_R(c.User)
-	info.Notice.Sms = Patient.Read_PatientSend_Count_Month(c.User.Id, 0, 1, month)
-	info.Notice.VoiceCall = Patient.Read_PatientSend_Count_Month(c.User.Id, 0, 2, month)
+	UserBill, _ := Account.Read_UserBill_Pay(c.User.Id)
+	info.UserPayMoney = UserBill.T_balance
+	info.Notice.Sms.Success = Patient.Read_PatientSend_Count_Month(c.User.Id, 0, 1, month, 1)
+	info.Notice.Sms.Fail = Patient.Read_PatientSend_Count_Month(c.User.Id, 0, 1, month, 0)
+	info.Notice.VoiceCall.Success = Patient.Read_PatientSend_Count_Month(c.User.Id, 0, 2, month, 1)
+	info.Notice.VoiceCall.Fail = Patient.Read_PatientSend_Count_Month(c.User.Id, 0, 2, month, 0)
+	info.Notice.Satisfaction.Success = Patient.Read_PatientSend_Count_Month(c.User.Id, 0, 3, month, 1)
+	info.Notice.Satisfaction.Fail = Patient.Read_PatientSend_Count_Month(c.User.Id, 0, 3, month, 0)
 
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: info}
 	c.ServeJSON()
@@ -151,23 +170,15 @@ func (c *UserController) Add() {
 		return
 	}
 
-	temp, err := submail.SmsTemplate_Post(T_user)
-	if err != nil || temp.Status != "success" {
-		c.Data["json"] = lib.JSONS{Code: 202, Msg: "创建短信模板失败"}
-		c.ServeJSON()
-		return
-	}
-
 	var_ := Account.User{
 		T_user:           T_user,
 		T_pass:           T_pass,
 		T_phone:          T_phone,
-		T_template_id:    temp.Template_id,
 		T_arrears_notice: T_arrears_notice,
 		T_State:          T_State,
 	}
 
-	_, err = Account.Add_User(var_)
+	_, err := Account.Add_User(var_)
 	if err != nil {
 		c.Data["json"] = lib.JSONS{Code: 209, Msg: "添加失败!"}
 		c.ServeJSON()
@@ -293,9 +304,9 @@ func (c *UserController) Del() {
 		return
 	}
 
-	temp, err := submail.SmsTemplate_Delete(user.T_template_id)
-	if err != nil || temp.Status != "success" {
-		c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除短信模板失败"}
+	cnt := Illness.Read_IllnessNotice_Count_ByT_uid(user.Id)
+	if cnt > 0 {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "请先删除短信通知模版!"}
 		c.ServeJSON()
 		return
 	}
@@ -544,7 +555,7 @@ func (c *UserController) Send() {
 		T_patient_Id = patient.Id
 	}
 
-	// 1 短信 2 电话
+	// 1 短信 2 电话 3 满意度调查
 	T_type, _ := c.GetInt("T_type")
 
 	send_List, cnt := Patient.Read_PatientSend_List(user.Id, T_patient_Id, T_type, T_month, page, page_z)
@@ -582,12 +593,14 @@ func (c *UserController) Send_Excel() {
 		}
 		T_patient_Id = patient.Id
 	}
-	var T_type_str string
+	var T_type_str, unit string
 	if T_type == 1 {
 		T_type_str = "短信"
+		unit = "条"
 	}
 	if T_type == 2 {
 		T_type_str = "电话"
+		unit = "分钟"
 	}
 
 	filename := fmt.Sprintf("%s%s通知记录", user.T_user, T_type_str)
@@ -600,7 +613,7 @@ func (c *UserController) Send_Excel() {
 			return
 		}
 		year, month := strings.Split(T_month, "-")[0], strings.Split(T_month, "-")[1]
-		filename = fmt.Sprintf("%s%s%s年%s月通知记录", user.T_user, T_type_str, year, month)
+		filename = fmt.Sprintf("%s%s年%s月%s通知记录", user.T_user, T_type_str, year, month)
 	}
 
 	f := excelize.NewFile()
@@ -622,28 +635,32 @@ func (c *UserController) Send_Excel() {
 				{Type: "right", Color: "000000", Style: 1},
 			},
 		})
-	f.MergeCell("Sheet1", "A1", "D1")
+	f.MergeCell("Sheet1", "A1", "F1")
 	f.SetRowStyle("Sheet1", 1, 1, Style1)
 	f.SetCellValue("Sheet1", "A1", filename)
 	f.SetRowHeight("Sheet1", 1, 30)
 
-	f.SetCellStyle("Sheet1", "A2", "D2", Style2)
+	f.SetCellStyle("Sheet1", "A2", "F2", Style2)
 	f.SetRowHeight("Sheet1", 2, 25)
 	// 这里设置表头
 	f.SetCellValue("Sheet1", "A2", "编号")
 	f.SetCellValue("Sheet1", "B2", "通知电话")
-	f.SetCellValue("Sheet1", "C2", "通知类型")
-	f.SetCellValue("Sheet1", "D2", "时间")
+	f.SetCellValue("Sheet1", "C2", "通知方式")
+	f.SetCellValue("Sheet1", "D2", "通知状态")
+	f.SetCellValue("Sheet1", "E2", fmt.Sprintf("计费条数(%s)", unit))
+	f.SetCellValue("Sheet1", "F2", "时间")
 	// 设置列宽
 	f.SetColWidth("Sheet1", "A", "A", 10)
 	f.SetColWidth("Sheet1", "B", "B", 15)
 	f.SetColWidth("Sheet1", "C", "C", 12)
-	f.SetColWidth("Sheet1", "D", "D", 30)
+	f.SetColWidth("Sheet1", "D", "D", 12)
+	f.SetColWidth("Sheet1", "E", "E", 15)
+	f.SetColWidth("Sheet1", "F", "F", 30)
 
 	line := 2
 	//T_type 1 充值 2扣费
 	send_List, _ := Patient.Read_PatientSend_List(user.Id, T_patient_Id, T_type, T_month, 0, 9999)
-
+	var T_State_str string
 	// 循环写入数据
 	for i, v := range send_List {
 		line++
@@ -657,7 +674,15 @@ func (c *UserController) Send_Excel() {
 			T_type_str = "电话"
 		}
 		f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), T_type_str)
-		f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.CreateTime)
+		if v.T_State == 1 {
+			T_State_str = "成功"
+		}
+		if v.T_type == 0 {
+			T_State_str = "失败"
+		}
+		f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), T_State_str)
+		f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_fee_num)
+		f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.CreateTime)
 
 	}
 	Style4, _ := f.NewStyle(
@@ -672,7 +697,7 @@ func (c *UserController) Send_Excel() {
 			},
 		})
 
-	f.SetCellStyle("Sheet1", "A2", fmt.Sprintf("D%d", line), Style4)
+	f.SetCellStyle("Sheet1", "A2", fmt.Sprintf("F%d", line), Style4)
 
 	timeStr := filename + fmt.Sprintf("(%s)", lib.GetRandstring(8, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 0))
 	// 保存文件
@@ -1029,21 +1054,25 @@ func updateCountMap(countMap map[string]map[string]int, question string, value s
 		if strings.Contains("12", value) {
 			if countMap[question] == nil {
 				countMap[question] = map[string]int{
-					"1": 0,
-					"2": 0,
+					"count": 0,
+					"1":     0,
+					"2":     0,
 				}
 			}
+			countMap[question]["count"]++
 			countMap[question][value]++
 		}
 	} else {
 		if strings.Contains("123", value) {
 			if countMap[question] == nil {
 				countMap[question] = map[string]int{
-					"1": 0,
-					"2": 0,
-					"3": 0,
+					"count": 0,
+					"1":     0,
+					"2":     0,
+					"3":     0,
 				}
 			}
+			countMap[question]["count"]++
 			countMap[question][value]++
 		}
 	}
@@ -1093,17 +1122,21 @@ func Cron_User() {
 
 }
 
-// 用户扣费,并生成账单,每天2点执行
+// 用户扣费,并生成账单,每天7点执行
 func Cron_User_Money_Bill() {
 
 	yesterday := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
 	logs.Info("开始进行" + yesterday + "用户账单扣费统计")
 	userList, _ := Account.Read_User_List("", 0, 9999)
 	for _, user := range userList {
-		// 1 短信 2 电话
+		// 1 短信(条) 2 电话
+		if user.Id != 2 {
+			continue
+		}
 		smsCount := Patient.Read_PatientSend_Count_Yesterday(user.Id, 0, 1, yesterday)
 		voiceCallCount := Patient.Read_PatientSend_Count_Yesterday(user.Id, 0, 2, yesterday)
-		money := float64(smsCount)*conf.SUBMAIL_Sms_Fee + float64(voiceCallCount)*conf.VoiceCall_Fee
+		satisfactionCount := Patient.Read_PatientSend_Satisfaction_Count_Yesterday(user.Id, 0, yesterday)
+		money := smsCount*conf.SUBMAIL_Sms_Fee + voiceCallCount/0.09*conf.SUBMAIL_VoiceCall_Fee + float64(satisfactionCount)*conf.VoiceCall_Fee
 		if money == 0 {
 			continue
 		}

+ 0 - 231
http/SmsTemplate.go

@@ -1,231 +0,0 @@
-package http
-
-import (
-	"FollowUp_Notice/conf"
-	"FollowUp_Notice/lib"
-	"FollowUp_Notice/logs"
-	"encoding/json"
-	"github.com/go-resty/resty/v2"
-)
-
-type Template struct {
-	Template_id                 string `json:"template_id"`
-	Sms_title                   string `json:"sms_title"`
-	Sms_signature               string `json:"sms_signature"`
-	Sms_content                 string `json:"sms_content"`
-	Add_date                    string `json:"add_date"`
-	Edit_date                   string `json:"edit_date"`
-	Template_status             string `json:"template_status"`
-	Template_status_description string `json:"template_status_description"`
-}
-
-type TemplateRes struct {
-	Status      string   `json:"status"`
-	Template_id string   `json:"template_id"`
-	Template    Template `json:"template"`
-}
-type XSendRes struct {
-	Status  string `json:"status"`
-	Send_id string `json:"send_id"`
-	Fee     int    `json:"fee"`
-}
-
-func SmsTemplate_Get(template_id string) (TemplateRes, error) {
-	// Create a Resty Client
-	client := resty.New()
-
-	resp, err := client.R().
-		SetQueryParams(map[string]string{
-			"appid":       conf.Sms_Appid,
-			"signature":   conf.Sms_Signature,
-			"template_id": template_id,
-		}).
-		Get("https://api-v4.mysubmail.com/sms/template.json")
-
-	if err != nil {
-		return TemplateRes{}, err
-	}
-
-	temp := TemplateRes{}
-	if err = json.Unmarshal(resp.Body(), &temp); err != nil {
-		logs.Error(lib.FuncName(), err)
-		return TemplateRes{}, err
-	}
-	return temp, nil
-}
-
-// 创建模板
-func SmsTemplate_Post(sms_signature string) (TemplateRes, error) {
-	client := resty.New()
-	resp, err := client.R().
-		SetHeader("Content-Type", "application/x-www-form-urlencoded").
-		SetFormData(map[string]string{
-			"appid":         conf.Sms_Appid,
-			"signature":     conf.Sms_Signature,
-			"sms_title":     "复诊通知",
-			"sms_signature": sms_signature,
-			"sms_content":   "敬爱的@var(name),离上一次来我院治疗的复诊时间已到,为了更好关注您的病情,请于@var(time)到我院进行复诊,祝您早日康复!",
-		}).
-		Post("http://api.mysubmail.com/sms/template.json")
-
-	if err != nil {
-		return TemplateRes{}, err
-	}
-
-	temp := TemplateRes{}
-	if err = json.Unmarshal(resp.Body(), &temp); err != nil {
-		logs.Error(lib.FuncName(), err)
-		return TemplateRes{}, err
-	}
-	return temp, nil
-}
-
-// 修改模板
-func SmsTemplate_Put(template_id, sms_signature string) (TemplateRes, error) {
-	client := resty.New()
-	resp, err := client.R().
-		SetHeader("Content-Type", "application/x-www-form-urlencoded").
-		SetFormData(map[string]string{
-			"appid":         conf.Sms_Appid,
-			"signature":     conf.Sms_Signature,
-			"template_id":   template_id,
-			"sms_title":     "复诊通知",
-			"sms_signature": sms_signature,
-			"sms_content":   "敬爱的@var(code),离上一次来我院治疗的复诊时间已到,为了更好关注您的病情,请于明日到我院进行复诊,祝您早日康复!",
-		}).
-		SetResult(&TemplateRes{}).
-		Put("http://api.mysubmail.com/sms/template.json")
-
-	if err != nil {
-		return TemplateRes{}, err
-	}
-
-	temp := TemplateRes{}
-	if err = json.Unmarshal(resp.Body(), &temp); err != nil {
-		logs.Error(lib.FuncName(), err)
-		return TemplateRes{}, err
-	}
-	return temp, nil
-}
-
-func SmsTemplate_Delete(template_id string) (TemplateRes, error) {
-	client := resty.New()
-	resp, err := client.R().
-		SetHeader("Content-Type", "application/x-www-form-urlencoded").
-		SetFormData(map[string]string{
-			"appid":       conf.Sms_Appid,
-			"signature":   conf.Sms_Signature,
-			"template_id": template_id,
-		}).
-		SetResult(&TemplateRes{}).
-		Delete("http://api.mysubmail.com/sms/template.json")
-
-	if err != nil {
-		return TemplateRes{}, err
-	}
-
-	temp := TemplateRes{}
-	if err = json.Unmarshal(resp.Body(), &temp); err != nil {
-		logs.Error(lib.FuncName(), err)
-		return TemplateRes{}, err
-	}
-	return temp, nil
-}
-
-// 批量发送短信
-func SmsMultiSend(template_id, content string) (TemplateRes, error) {
-	client := resty.New()
-	resp, err := client.R().
-		SetHeader("Content-Type", "application/x-www-form-urlencoded").
-		SetFormData(map[string]string{
-			"appid":     conf.Sms_Appid,
-			"signature": conf.Sms_Signature,
-			"content":   content,
-		}).
-		SetResult(&TemplateRes{}).
-		Delete("https://api-v4.mysubmail.com/sms/multisend")
-
-	if err != nil {
-		return TemplateRes{}, err
-	}
-
-	temp := TemplateRes{}
-	if err = json.Unmarshal(resp.Body(), &temp); err != nil {
-		logs.Error(lib.FuncName(), err)
-		return TemplateRes{}, err
-	}
-	return temp, nil
-}
-
-// 短信模板发送
-func SmsXSend(template_id, to, name, time string) (XSendRes, error) {
-
-	type Vars struct {
-		Name string `json:"name"`
-		Time string `json:"time"`
-	}
-
-	vars := Vars{Name: name, Time: time}
-
-	b, _ := json.Marshal(vars)
-
-	client := resty.New()
-	resp, err := client.R().
-		SetHeader("Content-Type", "application/x-www-form-urlencoded").
-		SetFormData(map[string]string{
-			"appid":     conf.Sms_Appid,
-			"signature": conf.Sms_Signature,
-			"to":        to,
-			"project":   template_id,
-			"vars":      string(b),
-		}).
-		SetResult(&XSendRes{}).
-		Post("https://api-v4.mysubmail.com/sms/xsend")
-
-	if err != nil {
-		return XSendRes{}, err
-	}
-
-	temp := XSendRes{}
-	if err = json.Unmarshal(resp.Body(), &temp); err != nil {
-		logs.Error(lib.FuncName(), err)
-		return XSendRes{}, err
-	}
-	return temp, nil
-}
-
-func SmsXSendBill(to, name, moneyFlag string) (XSendRes, error) {
-
-	type Vars struct {
-		Name string `json:"name"`
-		Msg  string `json:"msg"`
-	}
-
-	vars := Vars{Name: name, Msg: moneyFlag}
-
-	b, _ := json.Marshal(vars)
-
-	client := resty.New()
-	resp, err := client.R().
-		SetHeader("Content-Type", "application/x-www-form-urlencoded").
-		SetFormData(map[string]string{
-			"appid":     conf.Sms_Appid,
-			"signature": conf.Sms_Signature,
-			"to":        to,
-			"project":   "LPdPa4",
-			"vars":      string(b),
-		}).
-		SetResult(&XSendRes{}).
-		Post("https://api-v4.mysubmail.com/sms/xsend")
-
-	if err != nil {
-		return XSendRes{}, err
-	}
-
-	temp := XSendRes{}
-	if err = json.Unmarshal(resp.Body(), &temp); err != nil {
-		logs.Error(lib.FuncName(), err)
-		return XSendRes{}, err
-	}
-	return temp, nil
-}

+ 7 - 6
http/submail/SmsTemplate.go

@@ -13,10 +13,11 @@ type Template struct {
 	Sms_title                   string `json:"sms_title"`
 	Sms_signature               string `json:"sms_signature"`
 	Sms_content                 string `json:"sms_content"`
-	Add_date                    string `json:"add_date"`
-	Edit_date                   string `json:"edit_date"`
+	Add_date                    int64  `json:"add_date"`
+	Edit_date                   int64  `json:"edit_date"`
 	Template_status             string `json:"template_status"`
 	Template_status_description string `json:"template_status_description"`
+	Template_reject_reson       string `json:"template_reject_reson"`
 }
 
 type TemplateRes struct {
@@ -57,7 +58,7 @@ func SmsTemplate_Get(template_id string) (TemplateRes, error) {
 }
 
 // 创建模板
-func SmsTemplate_Post(sms_signature string) (TemplateRes, error) {
+func SmsTemplate_Post(sms_signature, sms_content string) (TemplateRes, error) {
 	client := resty.New()
 	resp, err := client.R().
 		SetHeader("Content-Type", "application/x-www-form-urlencoded").
@@ -66,7 +67,7 @@ func SmsTemplate_Post(sms_signature string) (TemplateRes, error) {
 			"signature":     conf.SUBMAIL_Sms_Signature,
 			"sms_title":     "复诊通知",
 			"sms_signature": sms_signature,
-			"sms_content":   "敬爱的@var(name),离上一次来我院治疗的复诊时间已到,为了更好关注您的病情,请于@var(time)到我院进行复诊,祝您早日康复!",
+			"sms_content":   sms_content,
 		}).
 		Post("http://api.mysubmail.com/sms/template.json")
 
@@ -83,7 +84,7 @@ func SmsTemplate_Post(sms_signature string) (TemplateRes, error) {
 }
 
 // 修改模板
-func SmsTemplate_Put(template_id, sms_signature string) (TemplateRes, error) {
+func SmsTemplate_Put(template_id, sms_signature, sms_content string) (TemplateRes, error) {
 	client := resty.New()
 	resp, err := client.R().
 		SetHeader("Content-Type", "application/x-www-form-urlencoded").
@@ -93,7 +94,7 @@ func SmsTemplate_Put(template_id, sms_signature string) (TemplateRes, error) {
 			"template_id":   template_id,
 			"sms_title":     "复诊通知",
 			"sms_signature": sms_signature,
-			"sms_content":   "敬爱的@var(code),离上一次来我院治疗的复诊时间已到,为了更好关注您的病情,请于明日到我院进行复诊,祝您早日康复!",
+			"sms_content":   sms_content,
 		}).
 		SetResult(&TemplateRes{}).
 		Put("http://api.mysubmail.com/sms/template.json")

+ 26 - 1
http/submail/VoiceTemplate.go

@@ -36,7 +36,7 @@ func VoiceXSend(to, hospital, name, date string) (VoiceXSendRes, error) {
 			"appid":     conf.SUBMAIL_Voice_Appid,
 			"signature": conf.SUBMAIL_Voice_Signature,
 			"to":        to,
-			"project":   conf.Voice_Project,
+			"project":   conf.SUBMAIL_Voice_Project,
 			"vars":      string(b),
 		}).
 		SetResult(&VoiceXSendRes{}).
@@ -53,3 +53,28 @@ func VoiceXSend(to, hospital, name, date string) (VoiceXSendRes, error) {
 	}
 	return temp, nil
 }
+func VoiceSend(to, content string) (VoiceXSendRes, error) {
+
+	client := resty.New()
+	resp, err := client.R().
+		SetHeader("Content-Type", "application/x-www-form-urlencoded").
+		SetFormData(map[string]string{
+			"appid":     conf.SUBMAIL_Voice_Appid,
+			"signature": conf.SUBMAIL_Voice_Signature,
+			"to":        to,
+			"content":   content,
+		}).
+		SetResult(&VoiceXSendRes{}).
+		Post("https://api-v4.mysubmail.com/voice/send.json")
+
+	if err != nil {
+		return VoiceXSendRes{}, err
+	}
+
+	temp := VoiceXSendRes{}
+	if err = json.Unmarshal(resp.Body(), &temp); err != nil {
+		logs.Error(lib.FuncName(), err)
+		return VoiceXSendRes{}, err
+	}
+	return temp, nil
+}

+ 6 - 0
lib/libString.go

@@ -57,6 +57,12 @@ func DateStrToTime(T_date string) (time.Time, bool) {
 	return stamp, true
 }
 
+func NowDate() time.Time {
+	now := time.Now()
+	nowDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
+	return nowDate
+}
+
 func MonthStrToTime(T_month string) (time.Time, bool) {
 	stamp, err := time.ParseInLocation("2006-01", T_month, time.Local) // +8
 	if err != nil {

+ 1 - 1
main.go

@@ -63,7 +63,7 @@ func main() {
 
 	go controllers.Cron_User()    // 用户账单统计
 	go controllers.Cron_Patient() // 患者通知信息
-	//go controllers.Cron_Patient_Notice() // 患者通知信息
+	go controllers.Cron_Illness() // 医院疾病
 	beego.Run()
 
 }

+ 4 - 3
models/Account/UserBill.go

@@ -63,11 +63,12 @@ func Add_UserBill(r UserBill) (id int64, err error) {
 	return
 }
 
-func Read_UserBill_newest(T_uuid string) (r UserBill, err error) {
+// 获取用户充值金额
+func Read_UserBill_Pay(T_uid int) (r UserBill, err error) {
 	o := orm.NewOrm()
 	qs := o.QueryTable(new(UserBill))
 	cond := orm.NewCondition()
-	cond = cond.And("T_uuid", T_uuid)
+	cond = cond.And("T_uid", T_uid).And("T_type", "充值")
 	var maps []UserBill
 	_, err = qs.Limit(1, 0).SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&maps)
 	if err != nil {
@@ -75,7 +76,7 @@ func Read_UserBill_newest(T_uuid string) (r UserBill, err error) {
 		return r, err
 	}
 	if len(maps) == 0 {
-		return
+		return r, orm.ErrNoRows
 	}
 	return maps[0], nil
 }

+ 1 - 1
models/Illness/Illness.go

@@ -11,7 +11,7 @@ import (
 	"time"
 )
 
-// 仓库
+// 诊断
 type Illness struct {
 	Id         int       `orm:"column(ID);size(11);auto;pk"`
 	T_name     string    `orm:"size(256);null"`                                        // 名称

+ 207 - 0
models/Illness/IllnessNotice.go

@@ -0,0 +1,207 @@
+package Illness
+
+import (
+	"FollowUp_Notice/lib"
+	"FollowUp_Notice/logs"
+	_ "github.com/astaxie/beego/cache/redis"
+	"github.com/beego/beego/v2/adapter/orm"
+	orm2 "github.com/beego/beego/v2/client/orm"
+	_ "github.com/go-sql-driver/mysql"
+	"strconv"
+	"sync"
+	"time"
+)
+
+// 诊断通知
+type IllnessNotice struct {
+	Id                            int       `orm:"column(ID);size(11);auto;pk"`
+	T_Illness_id                  int       `orm:"size(256);null"`                                        // 名称
+	T_name                        string    `orm:"size(256);null"`                                        // 名称
+	T_content                     string    `orm:"size(1024);null"`                                       // 名称
+	T_State                       int       `orm:"size(2);default(1)"`                                    // 0 删除(伪删除)   1 正常
+	T_template_id                 string    `orm:"size(20);default(0)"`                                   // 短信模版id
+	T_template_status             string    `orm:"size(20);default(0)"`                                   // 赛邮云短信审核状态
+	T_template_status_description string    `orm:"size(1024);null"`                                       // 赛邮云短信审核描述
+	T_template_reject_reson       string    `orm:"size(1024);null"`                                       // 赛邮云短信审核原因
+	CreateTime                    time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
+	UpdateTime                    time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now 每次 model 保存时都会对时间自动更新
+}
+
+func (t *IllnessNotice) TableName() string {
+	return "illness_notice"
+}
+
+var IllnessNotice_list *sync.Map
+
+func init() {
+	//注册模型
+	orm.RegisterModel(new(IllnessNotice))
+	IllnessNotice_list = new(sync.Map)
+
+}
+
+type IllnessNotice_R struct {
+	Id                            int
+	T_Illness_id                  int    // 名称
+	T_name                        string // 名称
+	T_content                     string // 名称
+	T_State                       int    // 0 删除(伪删除)   1 正常
+	T_template_id                 string // 模版id
+	T_template_status             string // 赛邮云审核状态 0-未提交审核 1-正在审核 2-审核通过 3-未通过审核
+	T_template_status_description string // 赛邮云审核描述
+	T_template_reject_reson       string // 赛邮云审核原因
+	CreateTime                    string //auto_now_add 第一次保存时才设置时间
+	UpdateTime                    string //auto_now 每次 model 保存时都会对时间自动更新
+}
+
+func IllnessNoticeToIllnessNotice_R(t IllnessNotice) (r IllnessNotice_R) {
+	r.Id = t.Id
+	r.T_Illness_id = t.T_Illness_id
+	r.T_name = t.T_name
+	r.T_content = t.T_content
+	r.T_State = t.T_State
+	r.T_template_id = t.T_template_id
+	r.T_template_status = t.T_template_status
+	r.T_template_status_description = t.T_template_status_description
+	r.T_template_reject_reson = t.T_template_reject_reson
+	r.CreateTime = t.CreateTime.Format("2006-01-02 15:04:05")
+	r.UpdateTime = t.UpdateTime.Format("2006-01-02 15:04:05")
+	return r
+}
+
+// 添加
+func Add_IllnessNotice(r IllnessNotice) (id int64, err error) {
+	o := orm.NewOrm()
+	id, err = o.Insert(&r)
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+	}
+	return id, err
+}
+
+// 获取 ById
+func Read_IllnessNotice_ById(Id int) (r IllnessNotice, err error) {
+	o := orm.NewOrm()
+	qs := o.QueryTable(new(IllnessNotice))
+	err = qs.Filter("Id", Id).One(&r)
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+	}
+	return
+}
+
+// 修改
+func Update_IllnessNotice(m IllnessNotice, cols ...string) error {
+	o := orm.NewOrm()
+	_, err := o.Update(&m, cols...)
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return err
+	}
+	return nil
+}
+
+// 删除
+func Delete_IllnessNotice(v IllnessNotice) error {
+	o := orm.NewOrm()
+	v.T_State = 0
+	_, err := o.Update(&v, "T_State")
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+	}
+	return err
+}
+
+// 获取列表
+func Read_IllnessNotice_List(T_Illness_id int, T_name, T_template_status string, page, page_z int) (r_ []IllnessNotice_R, cnt int64) {
+	o := orm.NewOrm()
+	// 也可以直接使用 Model 结构体作为表名
+	qs := o.QueryTable(new(IllnessNotice))
+	var offset int64
+	if page <= 1 {
+		offset = 0
+	} else {
+		offset = int64((page - 1) * page_z)
+	}
+
+	// 过滤
+	cond := orm.NewCondition()
+	cond = cond.And("T_State", 1)
+	if T_Illness_id > 0 {
+		cond = cond.And("T_Illness_id", T_Illness_id)
+
+	}
+
+	if len(T_name) > 0 {
+		cond = cond.And("T_name__icontains", T_name)
+	}
+	if len(T_template_status) > 0 {
+		cond = cond.And("T_template_status", T_template_status)
+
+	}
+
+	// 查询
+	var r []IllnessNotice
+	var err error
+	if page_z == 9999 {
+		_, err = qs.SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&r)
+	} else {
+		_, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&r)
+	}
+
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return
+	}
+
+	cnt, err = qs.SetCond((*orm2.Condition)(cond)).Count()
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return
+	}
+
+	for _, v := range r {
+		r_ = append(r_, IllnessNoticeToIllnessNotice_R(v))
+	}
+
+	return r_, cnt
+}
+func Read_IllnessNotice_Count_ByT_uid(T_uid int) (cnt int64) {
+
+	o := orm.NewOrm()
+	var count int64
+	sql := "SELECT count(*) FROM illness_notice left JOIN illness on illness.ID = illness_notice.t__illness_id " +
+		"WHERE t_uid = " + strconv.Itoa(T_uid)
+	err := o.Raw(sql).QueryRow(&count)
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return
+	}
+	return count
+
+}
+
+// 获取疾病
+func Read_IllnessNotice_All_Map() {
+	o := orm.NewOrm()
+	var r []IllnessNotice
+	qs := o.QueryTable(new(IllnessNotice))
+	_, err := qs.All(&r)
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+	}
+
+	for _, v := range r {
+		IllnessNotice_list.Store(v.Id, v.T_name)
+	}
+
+}
+func Read_IllnessNotice_Get(Id int) string {
+	// 有先加入 给全部人发消息
+	v, ok := IllnessNotice_list.Load(Id) /*如果确定是真实的,则存在,否则不存在 */
+	if ok {
+		return v.(string)
+	} else {
+		return ""
+	}
+}

+ 95 - 30
models/Patient/Patient.go

@@ -17,26 +17,26 @@ import (
 
 // 患者
 type Patient struct {
-	Id                int       `orm:"column(ID);size(11);auto;pk"`
-	T_uuid            string    `orm:"size(32);null"`                                         //
-	T_uid             int       `orm:"size(200);null"`                                        // 关联的用户id
-	T_number          string    `orm:"size(256);null"`                                        // 病历号
-	T_name            string    `orm:"size(256);null"`                                        // 姓名
-	T_age             int       `orm:"size(200);null"`                                        // 年轻
-	T_tag             string    `orm:"size(200);null"`                                        // 标签
-	T_illness         int       `orm:"size(200);null"`                                        // 诊断
-	T_surgical        int       `orm:"size(200);null"`                                        // 术式
-	T_phone           string    `orm:"size(256);null"`                                        // 电话号码
-	T_next_time       string    `orm:"size(200);null"`                                        // 下次复诊时间
-	T_notice_phone    int       `orm:"size(200);null"`                                        // 手机 1通知 0不通知
-	T_notice_message  int       `orm:"size(200);null"`                                        // 短信 1通知 0不通知
-	T_notice_interval string    `orm:"size(200);null"`                                        // 0,0,0,0 提前1天,提前2天,提前3天,提前7天
-	T_notice          int       `orm:"size(200);null"`                                        // 通知状态 1待通知 2已通知
-	T_follow_up       int       `orm:"size(200);null"`                                        // 复诊状态 1正常 2超时 3结束
-	T_record          string    `orm:"type(text);null"`                                       // 2022-07-27,15|2022-07-27,15| 时间,间隔天数|
-	T_State           int       `orm:"size(200);default(1)"`                                  // 0删除 1正常
-	CreateTime        time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now 每次 model 保存时都会对时间自动更新
-	UpdateTime        time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now_add 第一次保存时才设置时间
+	Id                int    `orm:"column(ID);size(11);auto;pk"`
+	T_uuid            string `orm:"size(32);null"`  //
+	T_uid             int    `orm:"size(200);null"` // 关联的用户id
+	T_number          string `orm:"size(256);null"` // 病历号
+	T_name            string `orm:"size(256);null"` // 姓名
+	T_age             int    `orm:"size(200);null"` // 年轻
+	T_tag             string `orm:"size(200);null"` // 标签
+	T_illness         int    `orm:"size(200);null"` // 诊断
+	T_surgical        int    `orm:"size(200);null"` // 术式
+	T_phone           string `orm:"size(256);null"` // 电话号码
+	T_next_time       string `orm:"size(200);null"` // 下次复诊时间
+	T_notice_phone    int    `orm:"size(200);null"` // 手机 1通知 0不通知
+	T_notice_message  int    `orm:"size(200);null"` // 短信 1通知 0不通知
+	T_notice_interval string `orm:"size(200);null"` // 0,0,0,0 提前1天,提前2天,提前3天,提前7天
+	T_notice          int    `orm:"size(200);null"` // 通知状态 1待通知 2已通知
+	//T_follow_up           int    `orm:"size(200);null"` // 复诊状态 1正常 2超时 3结束
+	//T_record              string    `orm:"type(text);null"`                                       // 2022-07-27,15|2022-07-27,15| 时间,间隔天数|
+	T_State    int       `orm:"size(200);default(1)"`                                  // 0删除 1正常
+	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now 每次 model 保存时都会对时间自动更新
+	UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now_add 第一次保存时才设置时间
 }
 type Patient_R struct {
 	Id                int
@@ -54,14 +54,29 @@ type Patient_R struct {
 	T_surgical_name   string   // 术式名称
 	T_phone           string   // 电话号码
 	T_next_time       string   // 下次复诊时间
-	T_next_interval   int      // 下次复诊间隔天数
 	T_notice_phone    int      // 手机 1通知 0不通知
 	T_notice_message  int      // 短信 1通知 0不通知
 	T_notice_interval string   // 0,0,0,0 提前1天,提前2天,提前3天,提前7天
 	T_notice          int      // 待通知 已通知
-	T_follow_up       int      // 复诊 超时 结束
-	T_record          string   // 2022-07-27,15|2022-07-27,15| 时间,间隔天数|
-	T_State           int      // 0删除 1正常
+	//T_follow_up           int      // 复诊 超时 结束
+	//T_record              string   // 2022-07-27,15|2022-07-27,15| 时间,间隔天数|
+	T_State int // 0删除 1正常
+}
+
+type Patient_R2 struct {
+	Id                          int    `json:"id"`
+	T_uuid                      string `json:"t_uuid"` //
+	T_uid                       int    `json:"t_uid"`  // 关联的用户id
+	T_name                      string `json:"t_name"`
+	T_phone                     string `json:"t_phone"`                     // 电话号码
+	T_notice_phone              int    `json:"t_notice_phone"`              // 手机 1通知 0不通知
+	T_notice_message            int    `json:"t_notice_message"`            // 短信 1通知 0不通知
+	T_notice_interval           string `json:"t_notice_interval"`           // 0,0,0,0 提前1天,提前2天,提前3天,提前7天
+	T_patient_revisit_record_id int    `json:"t_patient_revisit_record_id"` // 复诊记录id
+	T_date                      string `json:"t_date"`                      // 复诊日期
+	T_pid                       int    `json:"t_pid"`                       // 患者id
+	T_illness_notice            int    `json:"t_illness_notice"`            // 复诊通知内容id
+	T_remark                    string `json:"t_remark"`                    //
 }
 
 func (t *Patient) TableName() string {
@@ -101,8 +116,8 @@ func PatientToPatient_R(r Patient) (m Patient_R) {
 	m.T_notice_message = r.T_notice_message
 	m.T_notice_interval = r.T_notice_interval
 	m.T_notice = r.T_notice
-	m.T_follow_up = r.T_follow_up
-	m.T_record = r.T_record
+	//m.T_follow_up = r.T_follow_up
+	//m.T_record = r.T_record
 	m.T_State = r.T_State
 	return
 }
@@ -176,7 +191,7 @@ func Delete_Patient(v Patient) error {
 }
 
 // 获取列表
-func Read_Patient_List(T_uid int, T_number, T_name string, T_tag, T_illness, T_surgical, T_notice, T_follow_up, T_age_sort, T_next_time_sort, page, page_z int) (r_ []Patient_R, cnt int64) {
+func Read_Patient_List(T_uid int, T_number, T_name string, T_tag, T_illness, T_surgical, T_notice, T_age_sort, T_next_time_sort, page, page_z int) (r_ []Patient_R, cnt int64) {
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
 	qs := o.QueryTable(new(Patient))
@@ -211,9 +226,6 @@ func Read_Patient_List(T_uid int, T_number, T_name string, T_tag, T_illness, T_s
 	if T_notice > 0 {
 		cond = cond.And("T_notice", T_notice)
 	}
-	if T_follow_up > 0 {
-		cond = cond.And("T_follow_up", T_follow_up)
-	}
 	var order []string
 	if T_age_sort == 1 {
 		order = append(order, "T_age")
@@ -254,6 +266,59 @@ func Read_Patient_List(T_uid int, T_number, T_name string, T_tag, T_illness, T_s
 	return r_, cnt
 }
 
+func Read_Patient_List_Lt_NextTime(T_uid int, T_next_time string) (r_ []Patient_R, cnt int64) {
+	o := orm.NewOrm()
+	// 也可以直接使用 Model 结构体作为表名
+	qs := o.QueryTable(new(Patient))
+
+	// 过滤
+	cond := orm.NewCondition()
+	cond = cond.And("T_State__gt", 0)
+	if T_uid > 0 {
+		cond = cond.And("T_uid", T_uid)
+	}
+
+	if len(T_next_time) > 0 {
+		cond = cond.And("T_next_time__lte", T_next_time)
+	}
+
+	// 查询
+	var r []Patient
+	var err error
+	_, err = qs.SetCond((*orm2.Condition)(cond)).All(&r)
+
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return
+	}
+
+	cnt, err = qs.SetCond((*orm2.Condition)(cond)).Count()
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return
+	}
+
+	for _, v := range r {
+		r_ = append(r_, PatientToPatient_R(v))
+	}
+
+	return r_, cnt
+}
+
+// 患者通知列表
+func Read_Patient_List_For_Notice(T_uid int, nowTime string) (r_ []Patient_R2) {
+	o := orm.NewOrm()
+	sql := "SELECT p.ID as id,t_uid,t_name,t_phone,t_notice_phone,t_notice_message,t_notice_interval," +
+		"prr.ID as t_patient_revisit_record_id,t_date,t_illness_notice,t_remark" +
+		" from patient p INNER JOIN patient_revisit_record prr ON p.id = prr.t_pid  WHERE p.t__state > 0 AND p.t_uid = ? AND prr.t_date > '" + nowTime + "'"
+	_, err := o.Raw(sql, T_uid).QueryRows(&r_)
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+	}
+
+	return r_
+}
+
 func Read_Patient_All_Map(T_uid int) {
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名

+ 255 - 0
models/Patient/PatientRevisitRecord.go

@@ -0,0 +1,255 @@
+package Patient
+
+import (
+	"FollowUp_Notice/lib"
+	"FollowUp_Notice/logs"
+	"FollowUp_Notice/models/Illness"
+	_ "github.com/astaxie/beego/cache/redis"
+	"github.com/beego/beego/v2/adapter/orm"
+	orm2 "github.com/beego/beego/v2/client/orm"
+	_ "github.com/go-sql-driver/mysql"
+	"strings"
+	"time"
+)
+
+// 患者满意度
+type PatientRevisitRecord struct {
+	Id               int       `orm:"column(ID);size(11);auto;pk"`
+	T_date           string    `orm:"size(256);null"`                                        // 复诊日期
+	T_pid            int       `orm:"index;size(100);null"`                                  // 患者id
+	T_illness_notice int       `orm:"size(100);null"`                                        // 复诊通知内容id
+	T_notice         int       `orm:"size(200);null"`                                        // 通知状态 1 待通知 2已通知
+	T_remark         string    `orm:"type(text);null"`                                       // 1201_134,2022-07-24,提前三天,电话,通知成功|1201_135,2022-07-24,提前三天,短信,通知成功
+	CreateTime       time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
+	UpdateTime       time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now_add 第一次保存时才设置时间
+}
+
+func (t *PatientRevisitRecord) TableName() string {
+	return "patient_revisit_record" // 数据库名称   // ************** 替换 FormulaList **************
+}
+
+func init() {
+	//注册模型
+	orm.RegisterModel(new(PatientRevisitRecord))
+}
+
+type RevisitRecordRemark_R struct {
+	T_id           string // 通知id
+	T_date         string // 通知时间
+	T_advance_days string // 提前天数
+	T_type         string // 通知类型
+	T_status       string // 通知状态
+}
+
+type PatientRevisitRecord_R struct {
+	Id                    int
+	T_date                string                  // 复诊日期
+	T_pid                 int                     // 用户id
+	T_illness_notice      int                     // 复诊通知内容id
+	T_illness_notice_name string                  // 复诊通知内容名称
+	T_notice              int                     // 状态 1-已通知 2-未通知
+	T_remark              []RevisitRecordRemark_R // 2022-07-24 提前三天 已通知,2022-07-26 提前一天 已通知
+	CreateTime            string                  //auto_now_add 第一次保存时才设置时间
+	UpdateTime            string                  //auto_now 每次 model 保存时都会对时间自动更新
+}
+
+func PatientRevisitRecordToRemitRemark(T_remark string) (r []RevisitRecordRemark_R) {
+
+	if len(T_remark) == 0 {
+		return
+	}
+
+	remarkList := strings.Split(strings.Trim(T_remark, "|"), "|")
+
+	for _, v := range remarkList {
+
+		remark := strings.Split(v, ",")
+
+		r = append(r, RevisitRecordRemark_R{
+			T_id:           remark[0],
+			T_date:         remark[1],
+			T_advance_days: remark[2],
+			T_type:         remark[3],
+			T_status:       remark[4],
+		})
+	}
+	return r
+}
+
+func PatientRevisitRecordToPatientRevisitRecord_R(t PatientRevisitRecord) (r PatientRevisitRecord_R) {
+	r.Id = t.Id
+	r.T_date = t.T_date
+	r.T_pid = t.T_pid
+	r.T_illness_notice = t.T_illness_notice
+	r.T_illness_notice_name = Illness.Read_IllnessNotice_Get(t.T_illness_notice)
+	r.T_notice = t.T_notice
+	r.T_remark = PatientRevisitRecordToRemitRemark(t.T_remark)
+	r.CreateTime = t.CreateTime.Format("2006-01-02 15:04:05")
+	r.UpdateTime = t.UpdateTime.Format("2006-01-02 15:04:05")
+	return r
+}
+
+// 添加
+func Add_PatientRevisitRecord(r PatientRevisitRecord) (id int64, err error) {
+	o := orm.NewOrm()
+	id, err = o.Insert(&r)
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+	}
+	return id, err
+}
+
+// 获取 ById
+func Read_PatientRevisitRecord_ById(Id int) (r PatientRevisitRecord, err error) {
+	o := orm.NewOrm()
+	qs := o.QueryTable(new(PatientRevisitRecord))
+	err = qs.Filter("Id", Id).One(&r)
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+	}
+	return
+}
+
+// 获取 ById
+func Read_PatientRevisitRecord_ByT_date(T_pid int, T_date string) (r PatientRevisitRecord, err error) {
+	o := orm.NewOrm()
+	qs := o.QueryTable(new(PatientRevisitRecord))
+	err = qs.Filter("T_pid", T_pid).Filter("T_date", T_date).One(&r)
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+	}
+	return
+}
+
+// 修改
+func Update_PatientRevisitRecord(m PatientRevisitRecord, cols ...string) error {
+	o := orm.NewOrm()
+	_, err := o.Update(&m, cols...)
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return err
+	}
+	return nil
+}
+
+// 删除
+func Delete_PatientRevisitRecord(v PatientRevisitRecord) error {
+	o := orm.NewOrm()
+	_, err := o.Delete(&v)
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+	}
+	return err
+}
+
+// 获取列表
+func Read_PatientRevisitRecord_List(T_pid int, page, page_z int) (r_ []PatientRevisitRecord_R, cnt int64) {
+	o := orm.NewOrm()
+	// 也可以直接使用 Model 结构体作为表名
+	qs := o.QueryTable(new(PatientRevisitRecord))
+	var offset int64
+	if page <= 1 {
+		offset = 0
+	} else {
+		offset = int64((page - 1) * page_z)
+	}
+
+	// 过滤
+	cond := orm.NewCondition()
+	cond = cond.And("T_pid", T_pid)
+
+	// 查询
+	var r []PatientRevisitRecord
+	var err error
+	if page_z == 9999 {
+		_, err = qs.SetCond((*orm2.Condition)(cond)).OrderBy("T_date").All(&r)
+	} else {
+		_, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy("T_date").All(&r)
+	}
+
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return
+	}
+
+	cnt, err = qs.SetCond((*orm2.Condition)(cond)).Count()
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return
+	}
+
+	for _, v := range r {
+		r_ = append(r_, PatientRevisitRecordToPatientRevisitRecord_R(v))
+	}
+
+	return r_, cnt
+}
+
+// 获取下次复诊时间(今天之后)
+func Read_Next_PatientRevisitRecord(T_pid int) (r_ PatientRevisitRecord_R, err error) {
+	o := orm.NewOrm()
+	// 也可以直接使用 Model 结构体作为表名
+	qs := o.QueryTable(new(PatientRevisitRecord))
+	// 过滤
+	cond := orm.NewCondition()
+	cond = cond.And("T_pid", T_pid).And("T_date__gt", lib.NowDate())
+
+	// 查询
+	var r []PatientRevisitRecord
+	_, err = qs.Limit(1, 0).SetCond((*orm2.Condition)(cond)).OrderBy("T_date").All(&r)
+	if err != nil {
+		return
+	}
+	if len(r) == 0 {
+		return r_, orm.ErrNoRows
+	}
+
+	return PatientRevisitRecordToPatientRevisitRecord_R(r[0]), nil
+}
+
+// 获取上次复诊时间(今天之前)
+func Read_Last_PatientRevisitRecord(T_pid int) (r_ PatientRevisitRecord_R, err error) {
+	o := orm.NewOrm()
+	// 也可以直接使用 Model 结构体作为表名
+	qs := o.QueryTable(new(PatientRevisitRecord))
+	// 过滤
+	cond := orm.NewCondition()
+	cond = cond.And("T_pid", T_pid).And("T_date__lte", lib.NowDate())
+
+	// 查询
+	var r []PatientRevisitRecord
+	_, err = qs.Limit(1, 0).SetCond((*orm2.Condition)(cond)).OrderBy("-T_date").All(&r)
+	if err != nil {
+		return
+	}
+	if len(r) == 0 {
+		return r_, orm.ErrNoRows
+	}
+
+	return PatientRevisitRecordToPatientRevisitRecord_R(r[0]), nil
+}
+
+func Read_PatientRevisitRecord_Count_ByT_illness_notice(T_illness_notice int) (count int64, err error) {
+	o := orm.NewOrm()
+	// 也可以直接使用 Model 结构体作为表名
+	qs := o.QueryTable(new(PatientRevisitRecord))
+	// 过滤
+	count, err = qs.Filter("T_illness_notice", T_illness_notice).Count()
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return
+	}
+	return
+}
+func Read_PatientRevisitRecord_Count_ByT_pid(T_pid int) (count int64, err error) {
+	o := orm.NewOrm()
+	// 也可以直接使用 Model 结构体作为表名
+	qs := o.QueryTable(new(PatientRevisitRecord))
+	// 过滤
+	count, err = qs.Filter("T_pid", T_pid).Count()
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return
+	}
+	return
+}

+ 96 - 4
models/Patient/PatientSend.go

@@ -1,8 +1,11 @@
 package Patient
 
 import (
+	"FollowUp_Notice/conf"
 	"FollowUp_Notice/lib"
 	"fmt"
+	"github.com/astaxie/beego/cache"
+	_ "github.com/astaxie/beego/cache/redis"
 	"github.com/astaxie/beego/logs"
 	"github.com/beego/beego/v2/adapter/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
@@ -32,7 +35,8 @@ type PatientSend_R struct {
 	T_id       string
 	T_code     string
 	T_remark   string // 备注
-	T_State    int
+	T_State    int    // 0失败 1正常
+	T_fee_num  int    // 计费条数 赛邮云 短信 T_fee 电话 T_fee/0.09
 	CreateTime string //auto_now_add 第一次保存时才设置时间
 }
 
@@ -40,11 +44,51 @@ func (t *PatientSend) TableName() string {
 	return "patient_send" // 数据库名称   // ************** 替换 FormulaList **************
 }
 
+var redisCache_PatientSend cache.Cache
+
 func init() {
 	//注册模型
 	orm.RegisterModel(new(PatientSend))
+	config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
+		"redis_PatientSend", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
+	fmt.Println(config)
+	var err error
+	redisCache_PatientSend, err = cache.NewCache("redis", config)
+	if err != nil || redisCache_PatientSend == nil {
+		errMsg := "failed to init redis"
+		logs.Error(errMsg, err)
+	}
+}
+
+// ---------------- Redis -------------------
+func Redis_PatientSend_Set(key string, r string) (err error) {
+	err = redisCache_PatientSend.Put(key, r, 10*time.Minute)
+	if err != nil {
+		logs.Error("set key:", key, ",value:", r, err)
+	}
+	return
+}
+
+func Redis_PatientSend_Get(key string) (r string, is bool) {
+	if redisCache_PatientSend.IsExist(key) {
+		//println("找到key:",key)
+		v := redisCache_PatientSend.Get(key)
+		value := string(v.([]byte))
+		Redis_PatientSend_Set(key, value)
+		return value, true
+	}
+	//println("没有 找到key:",key)
+	return "", false
+}
 
+func Redis_PatientSend_DelK(key string) (err error) {
+	err = redisCache_PatientSend.Delete(key)
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+	}
+	return
 }
+
 func PatientSendToPatientSend_R(r PatientSend) (m PatientSend_R) {
 	m.Id = r.Id
 	m.T_pid = r.T_pid
@@ -54,6 +98,12 @@ func PatientSendToPatientSend_R(r PatientSend) (m PatientSend_R) {
 	m.T_code = r.T_code
 	m.T_remark = r.T_remark
 	m.T_State = r.T_State
+	if r.T_type == 1 {
+		m.T_fee_num = int(r.T_fee)
+	}
+	if r.T_type == 2 {
+		m.T_fee_num = int(r.T_fee / 0.09)
+	}
 	m.CreateTime = r.CreateTime.Format("2006-01-02 15:04:05")
 
 	return
@@ -147,7 +197,7 @@ func Read_PatientSend_List(T_uid, T_pid, T_type int, T_date string, page, page_z
 }
 
 // 获取列表
-func Read_PatientSend_Count_Yesterday(T_uid, T_pid, T_type int, date string) (cnt int64) {
+func Read_PatientSend_Count_Yesterday(T_uid, T_pid, T_type int, date string) (cnt float64) {
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
 	qs := o.QueryTable(new(PatientSend))
@@ -170,6 +220,48 @@ func Read_PatientSend_Count_Yesterday(T_uid, T_pid, T_type int, date string) (cn
 		cond = cond.And("CreateTime__gte", date+" 00:00:00").And("CreateTime__lte", date+" 23:59:59")
 	}
 
+	type result struct {
+		Total float64 `json:"total"`
+	}
+	var res []result
+	_, err := qs.SetCond((*orm2.Condition)(cond)).Aggregate("sum(t_fee) as total").All(&res)
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return
+	}
+
+	//cnt, err := qs.SetCond((*orm2.Condition)(cond)).Count()
+	//var total float64
+	//_, err := qs.SetCond((*orm2.Condition)(cond)).Aggregate("sum(t_fee) as total").All(&total)
+	//if err != nil {
+	//	logs.Error(lib.FuncName(), err)
+	//	return
+	//}
+
+	return res[0].Total
+}
+
+func Read_PatientSend_Satisfaction_Count_Yesterday(T_uid, T_pid int, date string) (cnt int64) {
+	o := orm.NewOrm()
+	// 也可以直接使用 Model 结构体作为表名
+	qs := o.QueryTable(new(PatientSend))
+
+	// 过滤
+	cond := orm.NewCondition()
+	cond = cond.And("T_type", 3)
+	cond = cond.AndCond(cond.Or("T_State", 1).Or("T_code", "8008"))
+
+	if T_uid > 0 {
+		cond = cond.And("T_uid", T_uid)
+	}
+	if T_pid > 0 {
+		cond = cond.And("T_pid", T_pid)
+	}
+
+	if len(date) > 0 {
+		cond = cond.And("CreateTime__gte", date+" 00:00:00").And("CreateTime__lte", date+" 23:59:59")
+	}
+
 	cnt, err := qs.SetCond((*orm2.Condition)(cond)).Count()
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
@@ -180,14 +272,14 @@ func Read_PatientSend_Count_Yesterday(T_uid, T_pid, T_type int, date string) (cn
 }
 
 // 获取列表
-func Read_PatientSend_Count_Month(T_uid, T_pid, T_type int, month string) (cnt int64) {
+func Read_PatientSend_Count_Month(T_uid, T_pid, T_type int, month string, T_State int) (cnt int64) {
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
 	qs := o.QueryTable(new(PatientSend))
 
 	// 过滤
 	cond := orm.NewCondition()
-
+	cond = cond.And("T_State", T_State)
 	if T_uid > 0 {
 		cond = cond.And("T_uid", T_uid)
 	}

+ 1 - 1
models/Surgical/Surgical.go

@@ -12,7 +12,7 @@ import (
 	_ "github.com/go-sql-driver/mysql"
 )
 
-// 仓库
+// 术式
 type Surgical struct {
 	Id         int       `orm:"column(ID);size(11);auto;pk"`
 	T_uid      int       `orm:"size(200);default(1)"`                                  // 关联的用户id

+ 8 - 1
routers/Illness.go

@@ -14,5 +14,12 @@ func init() {
 		beego.NSRouter("/Del", &controllers.IllnessController{}, "*:Illness_Del"),   // 删除疾病
 	)
 
-	beego.AddNamespace(illness)
+	illnessNotice := beego.NewNamespace("/IllnessNotice",
+		beego.NSRouter("/List", &controllers.IllnessController{}, "*:IllnessNotice_List"), // 疾病内容列表
+		beego.NSRouter("/Add", &controllers.IllnessController{}, "*:IllnessNotice_Add"),   // 获取疾病内容
+		beego.NSRouter("/Edit", &controllers.IllnessController{}, "*:IllnessNotice_Edit"), // 添加疾病内容
+		beego.NSRouter("/Del", &controllers.IllnessController{}, "*:IllnessNotice_Del"),   // 删除疾病内容
+	)
+
+	beego.AddNamespace(illness, illnessNotice)
 }

+ 7 - 2
routers/Patient.go

@@ -7,7 +7,7 @@ import (
 
 func init() {
 
-	illness := beego.NewNamespace("/Patient",
+	patient := beego.NewNamespace("/Patient",
 		beego.NSRouter("/List", &controllers.PatientController{}, "*:Patient_List"),                           // 患者列表
 		beego.NSRouter("/Add", &controllers.PatientController{}, "*:Patient_Add"),                             // 获取患者
 		beego.NSRouter("/Edit", &controllers.PatientController{}, "*:Patient_Edit"),                           // 添加患者
@@ -18,5 +18,10 @@ func init() {
 		beego.NSRouter("/Send_Satisfaction", &controllers.PatientController{}, "*:Patient_Send_Satisfaction"), // 删除患者
 	)
 
-	beego.AddNamespace(illness)
+	patientRevisitRecord := beego.NewNamespace("/PatientRevisitRecord",
+		beego.NSRouter("/List", &controllers.PatientController{}, "*:PatientRevisitRecord_List"), // 患者复诊记录列表
+		beego.NSRouter("/Del", &controllers.PatientController{}, "*:PatientRevisitRecord_Del"),   // 删除患者复诊记录
+	)
+
+	beego.AddNamespace(patient, patientRevisitRecord)
 }

BIN
static/fonts/MiSans-Medium.ttf


BIN
static/fonts/iconfont.eot


File diff suppressed because it is too large
+ 44 - 0
static/fonts/iconfont.svg


BIN
static/fonts/iconfont.ttf


BIN
static/fonts/iconfont.woff


BIN
static/导入患者模板.xlsx


Some files were not shown because too many files changed in this diff