| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186 |
- package controllers
- import (
- "FollowUp_Notice/Nats/NatsServer"
- "FollowUp_Notice/conf"
- "FollowUp_Notice/http"
- "FollowUp_Notice/http/submail"
- "FollowUp_Notice/lib"
- "FollowUp_Notice/logs"
- "FollowUp_Notice/models/Account"
- "FollowUp_Notice/models/Illness"
- "FollowUp_Notice/models/Patient"
- "FollowUp_Notice/models/System"
- "encoding/json"
- "fmt"
- beego "github.com/beego/beego/v2/server/web"
- "github.com/robfig/cron/v3"
- "github.com/shopspring/decimal"
- "github.com/xuri/excelize/v2"
- "math"
- "os"
- "strings"
- "time"
- )
- type UserController struct {
- beego.Controller
- User Account.User
- }
- func (c *UserController) Prepare() {
- if Account.User_r != nil {
- c.User = *Account.User_r
- }
- }
- // 验证登录
- func (c *UserController) Login_verification() {
- Admin_user := c.GetString("username")
- Admin_pass := c.GetString("password")
- type JSONS struct {
- //必须的大写开头
- Code int16
- Msg string
- Data interface{} // 泛型
- UserId int
- }
- err, user_r := Account.Read_User_verification(Admin_user, Admin_pass)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "用户名或密码错误!"}
- } else {
- User_tokey := Account.Add_Tokey(user_r.T_uuid)
- c.Ctx.SetCookie("User_tokey", User_tokey, time.Second*60*60)
- c.Data["json"] = JSONS{Code: 200, Msg: "OK!", Data: User_tokey, UserId: user_r.Id}
- System.Add_UserLogs_T(user_r.T_uuid, "用户", "用户登陆", lib.GetUserLoginInfo(c.Ctx))
- }
- c.ServeJSON()
- return
- }
- // --------------------------------------------------------------------------------------------------------------
- // 用户列表
- func (c *UserController) 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_name := c.GetString("T_name")
- R_List, R_cnt := Account.Read_User_List(T_name, 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 *UserController) Get() {
- T_uuid := c.GetString("T_uuid")
- user, err := Account.Read_User_ByT_uuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- var r_jsons lib.R_JSONS
- r_jsons.Data = Account.UserToUser_R(user)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 个人信息
- func (c *UserController) Info() {
- type Info struct {
- 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)
- 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()
- return
- }
- // 添加用户信息
- func (c *UserController) Add() {
- T_user := c.GetString("T_user")
- T_pass := c.GetString("T_pass")
- T_phone := c.GetString("T_phone")
- T_arrears_notice, _ := c.GetInt("T_arrears_notice")
- T_State, _ := c.GetInt("T_State")
- if len(T_user) < 3 {
- c.Data["json"] = lib.JSONS{Code: 207, Msg: "用户名长度不足!"}
- c.ServeJSON()
- return
- }
- if len(T_pass) < 6 {
- 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_arrears_notice: T_arrears_notice,
- T_State: T_State,
- }
- _, err := Account.Add_User(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 209, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- var_.T_pass = "******"
- System.Add_UserLogs_T(c.User.T_uuid, "用户", "新增", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 修改个人信息
- func (c *UserController) Post() {
- T_pass := c.GetString("T_pass")
- user := c.User
- if len(T_pass) > 0 {
- if len(T_pass) < 8 {
- c.Data["json"] = lib.JSONS{Code: 206, Msg: "密码格式不正确!"}
- c.ServeJSON()
- return
- }
- user.T_pass = T_pass
- }
- if err := Account.Update_User(user, "T_pass"); err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(c.User.T_uuid, "用户", "修改登录密码", "")
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 修改用户信息
- func (c *UserController) Edit() {
- T_uuid := c.GetString("T_uuid")
- T_pass := c.GetString("T_pass")
- T_phone := c.GetString("T_phone")
- T_arrears_notice, _ := c.GetInt("T_arrears_notice")
- T_State, _ := c.GetInt("T_State")
- var err error
- var user Account.User
- var cols []string
- if len(T_uuid) > 0 {
- user, err = Account.Read_User_ByT_uuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- }
- if len(T_pass) > 0 {
- if len(T_pass) < 6 {
- c.Data["json"] = lib.JSONS{Code: 206, Msg: "密码格式不正确!"}
- c.ServeJSON()
- return
- }
- user.T_pass = T_pass
- cols = append(cols, "T_pass")
- }
- if len(T_phone) > 0 {
- user.T_phone = T_phone
- cols = append(cols, "T_phone")
- }
- if T_arrears_notice > 0 {
- user.T_arrears_notice = T_arrears_notice
- cols = append(cols, "T_arrears_notice")
- }
- if T_State > 0 {
- user.T_State = T_State
- cols = append(cols, "T_State")
- }
- if err = Account.Update_User(user, cols...); err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- user.T_pass = "******"
- System.Add_UserLogs_T(c.User.T_uuid, "用户", "修改个人信息", user)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 删除用户信息
- func (c *UserController) Del() {
- T_uuid := c.GetString("T_uuid")
- if len(T_uuid) == 0 {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- user, err := Account.Read_User_ByT_uuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- if user.Id == 1 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "禁止删除超级管理员!"}
- c.ServeJSON()
- return
- }
- cnt := Illness.Read_IllnessNotice_Count_ByT_uid(user.Id)
- if cnt > 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "请先删除短信通知模版!"}
- c.ServeJSON()
- return
- }
- if err = Account.Delete_User(user); err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 充值
- func (c *UserController) Pay() {
- T_uuid := c.GetString("T_uuid")
- T_balance, _ := c.GetFloat("T_balance")
- if len(T_uuid) == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- user, err := Account.Read_User_ByT_uuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- T_money64, _ := decimal.NewFromFloat(float64(user.T_money) + T_balance).Round(2).Float64()
- user.T_money = float32(T_money64)
- err = Account.Update_User(user, "T_money")
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "充值失败!"}
- c.ServeJSON()
- return
- }
- // 添加充值记录
- bill := Account.UserBill{
- T_uid: user.Id,
- T_type: Account.Pay,
- T_bill: "充值",
- T_charging: float32(T_balance),
- T_balance: float32(T_money64),
- }
- _, err = Account.Add_UserBill(bill)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "充值失败!"}
- c.ServeJSON()
- return
- }
- user.T_pass = "******"
- System.Add_UserLogs_T(c.User.T_uuid, "用户管理", "充值", user)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 账单下载
- func (c *UserController) Bill() {
- // 分页参数 初始化
- 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_uuid := c.GetString("T_uuid")
- //T_type 1 充值 2扣费
- T_type, _ := c.GetInt("T_type")
- user, err := Account.Read_User_ByT_uuid(T_uuid)
- if err != nil {
- user = c.User
- }
- Bill_List, cnt := Account.Read_UserBill_List(user.Id, "", T_type, page, page_z)
- var r_jsons lib.R_JSONS
- r_jsons.Num = cnt
- r_jsons.Data = Bill_List
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(cnt) / float64(page_z)))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 账单下载
- func (c *UserController) Bill_Excel() {
- T_month := c.GetString("T_month")
- T_uuid := c.GetString("T_uuid")
- user, err := Account.Read_User_ByT_uuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- filename := fmt.Sprintf("%s账单", user.T_user)
- if len(T_month) > 0 {
- _, err := time.Parse("2006-01", T_month)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "日期格式错误!"}
- c.ServeJSON()
- return
- }
- year, month := strings.Split(T_month, "-")[0], strings.Split(T_month, "-")[1]
- filename = fmt.Sprintf("%s%s年%s月账单", c.User.T_user, year, month)
- }
- f := excelize.NewFile()
- Style1, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 16, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
- })
- Style2, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 14, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- })
- f.MergeCell("Sheet1", "A1", "G1")
- f.SetRowStyle("Sheet1", 1, 1, Style1)
- f.SetCellValue("Sheet1", "A1", filename)
- f.SetRowHeight("Sheet1", 1, 30)
- 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", "E2", "余额(元)")
- 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", 15)
- f.SetColWidth("Sheet1", "E", "E", 15)
- f.SetColWidth("Sheet1", "F", "F", 20)
- line := 2
- //T_type 1 充值 2扣费
- Bill_List, _ := Account.Read_UserBill_List(user.Id, T_month, 0, 0, 9999)
- // 循环写入数据
- for i, v := range Bill_List {
- line++
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
- f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_bill)
- f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_type)
- f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_charging)
- f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_balance)
- f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.CreateTime)
- }
- Style4, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 12, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- })
- f.SetCellStyle("Sheet1", "A2", fmt.Sprintf("F%d", line), Style4)
- timeStr := filename + fmt.Sprintf("(%s)", lib.GetRandstring(8, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 0))
- // 保存文件
- if err = f.SaveAs("ofile/" + timeStr + ".xlsx"); err != nil {
- fmt.Println(err)
- }
- var url string
- //// 上传 OSS
- url, is := NatsServer.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+timeStr+".xlsx", "ofile/"+timeStr+".xlsx")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "oss!"}
- c.ServeJSON()
- return
- }
- //删除目录
- err = os.Remove("ofile/" + timeStr + ".xlsx")
- if err != nil {
- fmt.Println(err)
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
- c.ServeJSON()
- return
- }
- // 通知记录
- func (c *UserController) Send() {
- // 分页参数 初始化
- page, _ := c.GetInt("page")
- T_month := c.GetString("T_month")
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- T_uuid := c.GetString("T_uuid")
- user, err := Account.Read_User_ByT_uuid(T_uuid)
- if err != nil {
- user = c.User
- }
- T_patient_uuid := c.GetString("T_patient_uuid")
- T_patient_Id := 0
- if len(T_patient_uuid) > 0 {
- patient, err := Patient.Read_Patient_ByT_uuid(T_patient_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_patient_uuid Err!"}
- c.ServeJSON()
- return
- }
- T_patient_Id = patient.Id
- }
- // 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)
- var r_jsons lib.R_JSONS
- r_jsons.Num = cnt
- r_jsons.Data = send_List
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(cnt) / float64(page_z)))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 通知记录下载
- func (c *UserController) Send_Excel() {
- T_month := c.GetString("T_month")
- T_uuid := c.GetString("T_uuid")
- T_type, _ := c.GetInt("T_type")
- user, err := Account.Read_User_ByT_uuid(T_uuid)
- if err != nil {
- user = c.User
- }
- T_patient_uuid := c.GetString("T_patient_uuid")
- T_patient_Id := 0
- if len(T_patient_uuid) > 0 {
- patient, err := Patient.Read_Patient_ByT_uuid(T_patient_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_patient_uuid Err!"}
- c.ServeJSON()
- return
- }
- T_patient_Id = patient.Id
- }
- 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)
- if len(T_month) > 0 {
- _, err := time.Parse("2006-01", T_month)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "日期格式错误!"}
- c.ServeJSON()
- 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)
- }
- f := excelize.NewFile()
- Style1, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 16, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
- })
- Style2, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 14, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- })
- 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", "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", "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", 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++
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
- f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_phone)
- if v.T_type == 1 {
- T_type_str = "短信"
- }
- if v.T_type == 2 {
- T_type_str = "电话"
- }
- f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), T_type_str)
- 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(
- &excelize.Style{
- Font: &excelize.Font{Size: 12, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- })
- f.SetCellStyle("Sheet1", "A2", fmt.Sprintf("F%d", line), Style4)
- timeStr := filename + fmt.Sprintf("(%s)", lib.GetRandstring(8, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 0))
- // 保存文件
- if err = f.SaveAs("ofile/" + timeStr + ".xlsx"); err != nil {
- fmt.Println(err)
- }
- var url string
- //// 上传 OSS
- url, is := NatsServer.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+timeStr+".xlsx", "ofile/"+timeStr+".xlsx")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "oss!"}
- c.ServeJSON()
- return
- }
- //删除目录
- err = os.Remove("ofile/" + timeStr + ".xlsx")
- if err != nil {
- fmt.Println(err)
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
- c.ServeJSON()
- return
- }
- // 通知记录
- func (c *UserController) Send_Test() {
- // 1 短信 2 电话
- T_type, _ := c.GetInt("T_type")
- T_phone := c.GetString("T_phone")
- if c.User.Id != 1 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- //发送短信通知
- if T_type == 1 {
- res, err := submail.SmsXSend("mDZSZ3", T_phone, "张三", time.Now().AddDate(0, 0, 1).Format("2006年01月02日"))
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "短信发送失败!"}
- c.ServeJSON()
- return
- }
- // 保存短信发送记录
- smsSend := Patient.PatientSend{
- T_uid: c.User.Id,
- T_pid: 0,
- T_phone: T_phone,
- T_type: 1,
- T_id: res.Send_id,
- T_remark: res.Status,
- T_fee: res.Fee,
- T_code: res.Code,
- T_State: 1,
- }
- if res.Status == "error" {
- smsSend.T_State = 0
- }
- _, err = Patient.Add_PatientSend(smsSend)
- if err != nil {
- System.Add_SysLogs_T("复诊通知", "添加短信发送记录失败", smsSend)
- }
- if res.Status == "error" {
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "短信发送失败!"}
- c.ServeJSON()
- return
- }
- }
- if T_type == 2 {
- // 华为语音通知
- //playInfoList := http.GetPlayInfoList(conf.VoiceCall_Template, []string{"某某医院消化内科", "张三", time.Now().AddDate(0, 0, 1).Format("2006/01/02")})
- //res, err := http.VoiceNotifyAPI(conf.VoiceCall_Phone, "+86"+T_phone, playInfoList)
- //if err != nil {
- // c.Data["json"] = lib.JSONS{Code: 202, Msg: "电话通知失败!"}
- // c.ServeJSON()
- // return
- //}
- // 保存短信发送记录
- //send := Patient.PatientSend{
- // T_uid: c.User.Id,
- // T_pid: 0,
- // T_phone: T_phone,
- // T_type: 2,
- // T_id: res.SessionId,
- // T_code: -1,
- // T_State: 0,
- //}
- //
- //_, err = Patient.Add_PatientSend(send)
- //if err != nil {
- // System.Add_SysLogs_T("复诊通知", "添加发送记录失败", send)
- //}
- //
- //if res.Resultcode != "0" {
- // c.Data["json"] = lib.JSONS{Code: 202, Msg: "电话通知失败!"}
- // c.ServeJSON()
- // return
- //}
- res, err := submail.VoiceXSend(T_phone, "某某医院某某科室", "张三", time.Now().AddDate(0, 0, 1).Format("2006年01月02日"))
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "电话通知失败!"}
- c.ServeJSON()
- return
- }
- // 保存短信发送记录
- send := Patient.PatientSend{
- T_uid: c.User.Id,
- T_pid: 0,
- T_phone: T_phone,
- T_type: 2,
- T_id: res.Send_id,
- T_fee: res.Fee,
- T_code: res.Code,
- T_State: 1,
- }
- if res.Status == "error" {
- send.T_State = 0
- }
- _, err = Patient.Add_PatientSend(send)
- if err != nil {
- System.Add_SysLogs_T("复诊通知", "添加语音发送记录失败", send)
- }
- if res.Status == "error" {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "语音通知失败!"}
- c.ServeJSON()
- return
- }
- }
- // 发送满意度调查短信
- if T_type == 3 {
- playInfoList := http.GetSatisfactionPlayInfoList([]string{"张三", "某某医院消化内科"})
- res, err := http.VoiceNotifyAPI(conf.VoiceCall_Phone, "+86"+T_phone, playInfoList)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "电话通知失败!"}
- c.ServeJSON()
- return
- }
- // 保存电话通知发送记录
- send := Patient.PatientSend{
- T_uid: c.User.Id,
- T_pid: 0,
- T_phone: T_phone,
- T_type: 3,
- T_id: res.SessionId,
- T_code: res.Resultcode,
- T_State: 0,
- }
- _, err = Patient.Add_PatientSend(send)
- if err != nil {
- System.Add_SysLogs_T("复诊通知", "添加发送记录失败", send)
- }
- if res.Resultcode != "0" {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "满意度调查失败!"}
- c.ServeJSON()
- return
- }
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 获取微信支付二维码
- func (c *UserController) Get_Weixin_QR_Code() {
- Total, _ := c.GetFloat("Total")
- Title := "复诊通知" + c.User.T_user
- res, err := http.PayTransactionNative(Title, Total)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
- c.ServeJSON()
- return
- }
- if res.Code != 200 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: res.Message}
- c.ServeJSON()
- return
- }
- var_ := Account.UserPayOrder{
- T_uid: c.User.Id,
- T_type: "微信",
- T_title: Title,
- T_total: Total,
- T_order_no: res.OrderNo,
- }
- _, err = Account.Add_UserPayOrder(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: res}
- c.ServeJSON()
- return
- }
- // 微信支付回调
- func (c *UserController) Weixin_Notify() {
- type RequestBody struct {
- TradeNo string
- Status string
- }
- type JSON struct {
- Code int
- Message string
- }
- logs.Info("Body:", string(c.Ctx.Input.RequestBody))
- //解密
- adc_str, err := lib.AesDeCrypt(c.Ctx.Input.RequestBody, []byte(conf.Weixin_PwdKey))
- //adc_str, _ := lib.AesDeCrypt(buf[0:n], []byte(conf.Weixin_PwdKey))
- var body RequestBody
- logs.Info("data================ ", string(adc_str))
- err = json.Unmarshal(adc_str, &body)
- if err != nil {
- c.Data["json"] = JSON{Code: 202, Message: "json.Unmarshal is err:" + err.Error()}
- c.ServeJSON()
- }
- UserPayOrder, err := Account.Get_UserPayOrder_ByT_order_no(body.TradeNo)
- if err != nil {
- c.Data["json"] = JSON{Code: 202, Message: "查询失败!"}
- c.ServeJSON()
- return
- }
- //交易状态
- //SUCCESS:支付成功
- //REFUND:转入退款
- //NOTPAY:未支付
- //CLOSED:已关闭
- //REVOKED:已撤销(付款码支付)
- //USERPAYING:用户支付中(付款码支付)
- //PAYERROR:支付失败(其他原因,如银行返回失败)
- UserPayOrder.T_status = body.Status
- err = Account.Update_UserPayOrder(UserPayOrder, "T_status")
- if err != nil {
- c.Data["json"] = JSON{Code: 202, Message: "更新状态失败!"}
- c.ServeJSON()
- return
- }
- // 添加充值记录
- // 余额加上充值金额
- if body.Status == "SUCCESS" {
- T_money64, _ := decimal.NewFromFloat(float64(c.User.T_money) + UserPayOrder.T_total).Round(2).Float64()
- c.User.T_money = float32(T_money64)
- // 修改用户余额
- err = Account.Update_User(c.User, "T_money")
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "充值失败!"}
- c.ServeJSON()
- return
- }
- // 添加充值记录
- bill := Account.UserBill{
- T_uid: c.User.Id,
- T_type: Account.Pay,
- T_bill: "充值(微信)",
- T_charging: float32(UserPayOrder.T_total),
- T_balance: float32(T_money64),
- }
- _, err = Account.Add_UserBill(bill)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "充值失败!"}
- c.ServeJSON()
- return
- }
- user := c.User
- user.T_pass = "******"
- System.Add_UserLogs_T(c.User.T_uuid, "用户管理", "充值", user)
- }
- c.Data["json"] = JSON{Code: 200, Message: "成功"}
- c.ServeJSON()
- return
- }
- // 获取微信支付订单状态
- func (c *UserController) GetWxOrderState() {
- OrderNo := c.GetString("OrderNo")
- UserPayOrder, err := Account.Get_UserPayOrder_ByT_order_no(OrderNo)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "成功", Data: UserPayOrder}
- c.ServeJSON()
- return
- }
- // 满意度统计
- func (c *UserController) Satisfaction_Stats() {
- list, err := Patient.Read_PatientSatisfaction_ByT_uid(c.User.Id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
- c.ServeJSON()
- return
- }
- type Json struct {
- Count map[string]map[string]int
- Title map[string]string
- }
- countMap := make(map[string]map[string]int)
- for _, v := range list {
- updateCountMap(countMap, "question1", v.T_question1)
- updateCountMap(countMap, "question2", v.T_question2)
- updateCountMap(countMap, "question3", v.T_question3)
- updateCountMap(countMap, "question4", v.T_question4)
- updateCountMap(countMap, "question5", v.T_question5)
- }
- title := make(map[string]string)
- title["question1"] = Patient.Question1
- title["question2"] = Patient.Question2
- title["question3"] = Patient.Question3
- title["question4"] = Patient.Question4
- title["question5"] = Patient.Question5
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Json{Count: countMap, Title: title}}
- c.ServeJSON()
- return
- }
- // 辅助函数:更新选项计数
- func updateCountMap(countMap map[string]map[string]int, question string, value string) {
- if question == "question2" {
- if strings.Contains("12", value) {
- if countMap[question] == nil {
- countMap[question] = map[string]int{
- "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{
- "count": 0,
- "1": 0,
- "2": 0,
- "3": 0,
- }
- }
- countMap[question]["count"]++
- countMap[question][value]++
- }
- }
- }
- // 满意度列表
- func (c *UserController) Satisfaction_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
- }
- Patient.Read_Patient_All_Map(c.User.Id)
- list, cnt := Patient.Read_PatientSatisfaction_List(c.User.Id, page, page_z)
- var r_jsons lib.R_JSONS
- r_jsons.Num = cnt
- r_jsons.Data = list
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(cnt) / float64(page_z)))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 用户定时任务
- func Cron_User() {
- //创建一个定时任务对象
- c := cron.New(cron.WithSeconds())
- //给对象增加定时任务
- //c.AddFunc("0 */1 * * * ?", Cron_User_Money_Bill)
- c.AddFunc("0 0 7 * * *", Cron_User_Money_Bill)
- //启动定时任务
- c.Start()
- defer c.Stop()
- //查询语句,阻塞,让main函数不退出,保持程序运行
- select {}
- }
- // 用户扣费,并生成账单,每天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 电话
- 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)
- 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
- }
- sendMsg := false
- moneyFlag := ""
- var_ := Account.User{Id: user.Id, T_money: user.T_money - float32(money)}
- if user.T_money >= 100 && var_.T_money < 100 {
- sendMsg = true
- moneyFlag = "不足100元"
- } else if user.T_money >= 10 && var_.T_money < 10 {
- sendMsg = true
- moneyFlag = "不足10元"
- } else if user.T_money >= 0 && var_.T_money < 0 {
- sendMsg = true
- moneyFlag = "欠费"
- }
- err := Account.Update_User(var_, "T_money")
- if err != nil {
- System.Add_SysLogs_T("用户扣费", "扣费失败", var_)
- }
- // 添加扣费记录
- bill := Account.UserBill{
- T_uid: user.Id,
- T_type: Account.FeeDeduction,
- T_bill: yesterday + "通知自动扣除",
- T_charging: float32(money),
- T_balance: user.T_money - float32(money),
- }
- _, err = Account.Add_UserBill(bill)
- if err != nil {
- System.Add_SysLogs_T("用户扣费", "添加扣费记录失败", bill)
- }
- if sendMsg {
- _, err = submail.SmsXSendBill(user.T_phone, user.T_user, moneyFlag)
- info := fmt.Sprintf("T_uid:%v, T_phone:%v, T_user:%v, moneyFlag:%v", user.Id, user.T_phone, user.T_user, moneyFlag)
- if err != nil {
- System.Add_SysLogs_T("复诊通知-账单", "短信通知失败", info)
- } else {
- System.Add_SysLogs_T("复诊通知-账单", "短信通知成功", info)
- }
- }
- }
- logs.Info("用户账单扣费统计结束")
- }
|