12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093 |
- package controllers
- import (
- "Cold_Api/Nats/NatsServer"
- "Cold_Api/conf"
- "Cold_Api/controllers/lib"
- "Cold_Api/models/Account"
- "Cold_Api/models/Company"
- "Cold_Api/models/Device"
- "Cold_Api/models/System"
- "Cold_Api/models/Warning"
- "encoding/json"
- "fmt"
- "github.com/beego/beego/v2/adapter/orm"
- "github.com/beego/beego/v2/core/logs"
- beego "github.com/beego/beego/v2/server/web"
- uuid "github.com/satori/go.uuid"
- "github.com/shopspring/decimal"
- "github.com/xuri/excelize/v2"
- "math"
- "os"
- "strconv"
- "strings"
- "time"
- )
- type UserController struct {
- beego.Controller
- Admin_r Account.Admin // 登陆的用户
- T_pid int // 公司id
- }
- func (c *UserController) Prepare() {
- GetCookie := c.Ctx.GetCookie("User_tokey")
- GetString := c.GetString("User_tokey")
- User_tokey := GetCookie
- if len(User_tokey) == 0 {
- User_tokey = GetString
- }
- if Account.Admin_r == nil {
- return
- }
- c.Admin_r = *Account.Admin_r
- T_pid := c.Admin_r.T_pid
- EntryPid, _ := Account.Redis_Tokey_T_pid_Get(User_tokey)
- if EntryPid > 0 {
- T_pid = EntryPid
- }
- c.T_pid = T_pid
- }
- // 获取微信二维码 ( 扫描后 ,Nats 自动绑定在 Admin->T_wx )
- func (c *UserController) User_WxQRCode() {
- T_name := c.GetString("T_name")
- WxQRCode_str, _ := NatsServer.Wx_GenerateQRCode("-|" + lib.AesEncryptCBC(c.Admin_r.T_uuid+"/"+T_name, "0123456789012345") + "|- @宝智达冷链 微信公众号通知")
- WxQRCode_str = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + WxQRCode_str
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: WxQRCode_str}
- c.ServeJSON()
- return
- }
- // 用户绑定的公司列表
- func (c *UserController) Company_Tree() {
- var r_jsons lib.R_JSONS
- T_name := c.GetString("T_name")
- r_jsons.Data = Account.Read_Company_Tree(c.Admin_r, T_name)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *UserController) Company_Transport_List() {
- var r_jsons lib.R_JSONS
- T_name := c.GetString("T_name")
- r_jsons.Data = Account.Read_Transport_Company_List(T_name)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 所有公司树
- func (c *UserController) Company_List() {
- var r_jsons lib.R_JSONS
- T_name := c.GetString("T_name")
- r_jsons.Data = Account.Read_Company_List(T_name)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *UserController) Company_Get() {
- var r_jsons lib.R_JSONS
- Company_r, err := Account.Read_Company_ById(c.T_pid)
- if err != nil {
- logs.Warning(lib.FuncName(), "获取公司信息失败", err)
- }
- r_jsons.Data = Account.CompanyToCompany_R(Company_r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *UserController) Company_Add() {
- T_mid, _ := c.GetInt("T_mid")
- T_name := c.GetString("T_name")
- T_plan := c.GetString("T_plan")
- T_data := c.GetString("T_data")
- T_v3d := c.GetString("T_v3d")
- T_type, _ := c.GetInt("T_type")
- var_ := Account.Company{
- T_mid: T_mid,
- T_name: T_name,
- T_State: 1,
- T_plan: T_plan,
- T_data: T_data,
- T_v3d: T_v3d,
- T_warning: 1,
- T_type: T_type,
- }
- id, err := Account.Add_Company(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- if c.Admin_r.T_pids != "*" {
- T_pids := []int{int(id)}
- if err = Account.Add_Company_bind(c.Admin_r, T_pids); err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "公司绑定失败"}
- c.ServeJSON()
- return
- }
- }
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "公司管理", "添加", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: id}
- c.ServeJSON()
- return
- }
- func (c *UserController) Company_Edit() {
- Id, Id_err := c.GetInt("Id")
- if Id_err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- Company_r, err := Account.Read_Company_ById(Id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- T_name := c.GetString("T_name")
- T_type, _ := c.GetInt("T_type")
- if len(T_name) > 0 {
- Company_r.T_name = T_name
- }
- if T_type > 0 {
- Company_r.T_type = T_type
- }
- is := Account.Update_Company(Company_r, "T_name", "T_type")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "公司管理", "修改", Company_r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 数字孪生
- func (c *UserController) Company_DigitalTwin() {
- Id, Id_err := c.GetInt("Id")
- if Id_err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- Company_r, err := Account.Read_Company_ById(Id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- T_plan := c.GetString("T_plan")
- T_data := c.GetString("T_data")
- T_v3d := c.GetString("T_v3d")
- T_warning, _ := c.GetInt("T_warning")
- Company_r.T_plan = T_plan
- Company_r.T_data = T_data
- Company_r.T_v3d = T_v3d
- Company_r.T_warning = T_warning
- is := Account.Update_Company(Company_r, "T_plan", "T_data", "T_v3d", "T_warning")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "公司管理", "修改数字孪生", Company_r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 充值
- func (c *UserController) Company_Pay() {
- Id, Id_err := c.GetInt("Id")
- if Id_err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- Company_r, err := Account.Read_Company_ById(Id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- T_balance, _ := c.GetFloat("T_balance")
- T_money64, _ := decimal.NewFromFloat(float64(Company_r.T_money) + T_balance).Round(2).Float64()
- Company_r.T_money = float32(T_money64)
- is := Account.Update_Company(Company_r, "T_money")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "充值失败!"}
- c.ServeJSON()
- return
- }
- // 添加充值记录
- bill := Company.CompanyBill{
- T_pid: Company_r.Id,
- T_type: "充值",
- T_project: "充值",
- T_bill: "充值",
- T_charging: float32(T_balance),
- T_balance: float32(T_money64),
- }
- _, err = Company.Add_CompanyBill(bill)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "充值失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "公司管理", "充值", Company_r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 报警统计
- func (c *UserController) Company_Warning() {
- Id, Id_err := c.GetInt("Id")
- if Id_err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- Company_r, err := Account.Read_Company_ById(Id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- T_warning, _ := c.GetInt("T_warning")
- if T_warning > 0 {
- Company_r.T_warning = T_warning
- }
- is := Account.Update_Company(Company_r, "T_warning")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "公司管理", "修改报警统计", Company_r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) Company_Del() {
- Id, Id_err := c.GetInt("Id")
- if Id_err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- Company_r, err := Account.Read_Company_ById(Id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- ids := Account.ReadCompanyIds_T_path(Company_r.T_path)
- if cnt := Account.Read_Admin_Num_ByT_pid(ids); cnt > 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "有关联用户,禁止删除!"}
- c.ServeJSON()
- return
- }
- o := orm.NewOrm()
- o.Begin()
- for _, id := range ids {
- if is := Account.Delete_Company(o, id); !is {
- o.Rollback()
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
- c.ServeJSON()
- return
- }
- if err = Account.Delete_Company_bind_T_pids(o, id); err != nil {
- o.Rollback()
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
- c.ServeJSON()
- return
- }
- }
- o.Commit()
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "公司管理", "删除", Company_r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 进入公司
- func (c *UserController) Company_Entry() {
- GetCookie := c.Ctx.GetCookie("User_tokey")
- GetString := c.GetString("User_tokey")
- User_tokey := GetCookie
- if len(User_tokey) == 0 {
- User_tokey = GetString
- }
- T_pid, _ := c.GetInt("T_pid")
- // 操作pid
- company_r, err := Account.Read_Company_ById(T_pid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
- c.ServeJSON()
- return
- }
- visit := false
- if c.Admin_r.T_pid > 0 && strings.Contains(company_r.T_path, fmt.Sprintf("/%d/", c.Admin_r.T_pid)) {
- visit = true
- }
- if c.Admin_r.T_pid == 0 {
- if c.Admin_r.T_pids == "*" {
- visit = true
- } else {
- pids := lib.SplitStringToIntIds(c.Admin_r.T_pids, "P")
- if len(pids) > 0 {
- list := Account.ReadCompanyIds_T_pids(pids)
- for _, v := range list {
- if T_pid == v {
- visit = true
- break
- }
- }
- }
- }
- }
- if !visit {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有权限!"}
- c.ServeJSON()
- return
- }
- Account.Redis_Tokey_T_pid_Set(User_tokey, T_pid)
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "公司管理", "进入公司", T_pid)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 记账扣费
- func (c *UserController) Company_Charging() {
- Id, Id_err := c.GetInt("Id")
- if Id_err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- Company_r, err := Account.Read_Company_ById(Id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- T_Charging, _ := c.GetInt("T_Charging")
- Company_r.T_Charging = T_Charging
- is := Account.Update_Company(Company_r, "T_Charging")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "充值失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "公司管理", "记账扣费", Company_r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 检查 Tokey 是否过期
- // 用户管理
- func (c *UserController) User_List() {
- var r_jsons lib.R_JSONS
- 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")
- Account.Read_Power_All_Map()
- r_jsons.Data, r_jsons.Num = Account.Read_Admin_List(c.T_pid, T_name, page, page_z)
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *UserController) User_Get() {
- T_uuid := c.GetString("T_uuid")
- if len(T_uuid) < 8 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- admin_r, err := Account.Read_Admin_ByUuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Account.AdminToAdmin_R(admin_r)}
- c.ServeJSON()
- return
- }
- func (c *UserController) User_Info() {
- type User_ struct {
- User Account.Admin_R
- //Power Account.Power // 权限
- //Menu map[string]Account.Menu_R // 菜单
- //Menu []Account.Menu // 菜单
- }
- Admin_r := User_{}
- Admin_r.User = Account.AdminToAdmin_R(c.Admin_r)
- //Admin_r.Power, _ = Account.Read_Power_ById(admin_r.T_power)
- //Admin_r.Menu = Account.Read_Menu_Tree(Power.T_menu, T_pid)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Admin_r}
- c.ServeJSON()
- return
- }
- func (c *UserController) User_Post() {
- admin_r := c.Admin_r
- T_name := c.GetString("T_name")
- T_pass := c.GetString("T_pass")
- T_phone := c.GetString("T_phone")
- T_mail := c.GetString("T_mail")
- T_wx := c.GetString("T_wx")
- if len(T_pass) < 8 && len(T_pass) > 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "密码异常!"}
- c.ServeJSON()
- return
- }
- if len(T_name) > 0 {
- admin_r.T_name = T_name
- }
- if len(T_pass) >= 8 {
- admin_r.T_pass = T_pass
- }
- if len(T_phone) > 0 {
- admin_r.T_phone = T_phone
- }
- if len(T_mail) > 0 {
- admin_r.T_mail = T_mail
- }
- if len(T_wx) > 0 {
- if T_wx == "-" {
- T_wx = ""
- }
- admin_r.T_wx = T_wx
- }
- is := Account.Update_Admin(admin_r, "T_name", "T_pass", "T_phone", "T_mail", "T_wx")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- admin_r.T_pass = "******"
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "用户管理", "修改个人信息", admin_r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) User_Add() {
- T_power, _ := c.GetInt("T_power")
- T_name := c.GetString("T_name")
- T_user := c.GetString("T_user")
- T_pass := c.GetString("T_pass")
- T_phone := c.GetString("T_phone")
- T_mail := c.GetString("T_mail")
- T_wx := c.GetString("T_wx")
- T_uuid := uuid.NewV4().String()
- var_ := Account.Admin{
- T_uuid: T_uuid,
- T_pid: c.T_pid,
- T_name: T_name,
- T_user: T_user,
- T_phone: T_phone,
- T_mail: T_mail,
- T_wx: T_wx,
- T_pass: T_pass,
- T_power: T_power,
- T_State: 1,
- }
- if len(T_pass) < 8 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "密码异常!"}
- c.ServeJSON()
- return
- }
- _, err := Account.Read_Admin_T_user(T_user)
- if err == nil {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "账户重复!"}
- c.ServeJSON()
- return
- }
- _, err = Account.Add_Admin(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- var_.T_pass = "******"
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "用户管理", "添加", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) User_Edit() {
- T_uuid := c.GetString("T_uuid")
- if len(T_uuid) < 8 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- r, err := Account.Read_Admin_ByUuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- T_power, T_power_err := c.GetInt("T_power")
- T_name := c.GetString("T_name")
- T_pass := c.GetString("T_pass")
- T_phone := c.GetString("T_phone")
- T_mail := c.GetString("T_mail")
- if T_power_err == nil {
- r.T_power = T_power
- }
- if len(T_pass) < 8 && len(T_pass) > 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "密码异常!"}
- c.ServeJSON()
- return
- }
- if len(T_name) > 0 {
- r.T_name = T_name
- }
- if len(T_pass) >= 8 {
- r.T_pass = T_pass
- }
- if len(T_phone) > 0 {
- r.T_phone = T_phone
- }
- if len(T_mail) > 0 {
- r.T_mail = T_mail
- }
- is := Account.Update_Admin(r, "T_power", "T_pid", "T_name", "T_pass", "T_phone", "T_mail")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- if len(T_name) > 0 {
- if is = Company.Update_CompanyNotice_Bind_By_T_uuid(T_uuid, T_name); !is {
- logs.Info("修改用户 => 修改用户关联报警通知失败", T_uuid, T_name)
- }
- }
- r.T_pass = "******"
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "用户管理", "编辑", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) User_Del() {
- T_uuid := c.GetString("T_uuid")
- if len(T_uuid) <= 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- admin_r_lod, err := Account.Read_Admin_ByUuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- if is := Account.Delete_Admin(admin_r_lod); !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
- c.ServeJSON()
- return
- }
- if is := Company.Delete_CompanyNotice_Bind_By_T_uuid(T_uuid); !is {
- logs.Info("删除用户 => 删除用户关联报警通知失败", T_uuid)
- }
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "用户管理", "删除", T_uuid)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 管理员
- func (c *UserController) User_Home() {
- // 报警标识
- //设备管理-设备报警 callthepolice
- //公司管理-设备报警 companyCallthepolice
- //T_warning_sign := c.GetString("T_warning_sign")
- power, err := Account.Read_Power_ById(c.Admin_r.T_power)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取菜单失败"}
- c.ServeJSON()
- return
- }
- ret := Account.Read_Menu_Bind_List(power.Id, power.T_menu, c.T_pid)
- var T_warning_sign string
- for _, v := range ret.MenuPermission {
- if v == Warning.CompanyCallthepolice {
- T_warning_sign = Warning.CompanyCallthepolice
- break
- }
- if v == Warning.Callthepolice {
- T_warning_sign = Warning.Callthepolice
- }
- }
- // 验证登录
- admin_r := c.Admin_r
- type NoticeRecord struct {
- Sms int // 短信
- Phone int // 电话
- }
- type Info struct {
- T_name string // 姓名
- T_pids string // 内部用户绑定的公司id
- T_pid int // 公司id
- T_Days int // 服务天数
- Admin []Account.Admin_ // 专属管理员
- WarningSign string // 报警标识
- WarningNum int64 // 报警数量
- UntreatedWarningNum int64 // 未处理报警数量
- NewsNum int64 // 消息数量
- WorkOrderNum int64 // 工单数量
- WarningRate float32 // 设备报警率
- UntreatedWorkOrderNum int64 // 未处理工单数量
- Balance float32 // 余额
- NoticeRecord NoticeRecord // 通知记录
- CompanyKey string
- CompanyName string
- }
- var info Info
- info.T_name = admin_r.T_name
- info.T_pid = admin_r.T_pid
- var Company_r Account.Company
- if c.T_pid > 0 {
- Company_r, err = Account.Read_Company_ById(c.T_pid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- info.CompanyKey = Company_r.T_key
- info.CompanyName = Company_r.T_name
- }
- if admin_r.T_pid > 0 {
- info.WarningSign = T_warning_sign
- bindSN, err := Account.Read_UserDevice_List(c.Admin_r)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
- c.ServeJSON()
- return
- }
- power, _ := Account.Read_Power_ById(admin_r.T_power)
- company, _ := Account.Read_Company_ById(admin_r.T_pid)
- info.T_Days = lib.GetDiffDays(time.Now(), company.CreateTime)
- AdminList := Account.Read_Admin_List_T_pids(admin_r.T_pid)
- var Admin_ []Account.Admin_
- for _, v := range AdminList {
- Admin_ = append(Admin_, Account.Admin_RToAdmin_(v))
- }
- info.Admin = Admin_
- T_pids := []int{}
- // 拥有公司管理-设备报警权限 统计公司及其所有子公司的今日报警数量、未处理报警数量、我的消息数量
- if T_warning_sign == Warning.CompanyCallthepolice {
- T_pids = Account.ReadCompanyIds_T_path(Company_r.T_path)
- info.WarningNum = Warning.Read_Warning_ALL_T_State_Count(0, T_pids, 1, bindSN, power.T_warning, true)
- info.UntreatedWarningNum = Warning.Read_Warning_ALL_T_State_Count(0, T_pids, 3, bindSN, power.T_warning, false)
- info.NewsNum = Warning.Read_Warning_ALL_T_State_Count(0, T_pids, 1, bindSN, "T1003|T1002|", false)
- }
- // 拥有设备管理-设备报警权限 统计本公司今日报警数量、未处理报警数量、我的消息数量
- if T_warning_sign == Warning.Callthepolice {
- info.WarningNum = Warning.Read_Warning_ALL_T_State_Count(admin_r.T_pid, T_pids, 1, bindSN, power.T_warning, true)
- info.UntreatedWarningNum = Warning.Read_Warning_ALL_T_State_Count(admin_r.T_pid, T_pids, 3, bindSN, power.T_warning, false)
- info.NewsNum = Warning.Read_Warning_ALL_T_State_Count(admin_r.T_pid, T_pids, 1, bindSN, "T1003|T1002|", false)
- }
- info.Balance = company.T_money
- info.NoticeRecord.Sms = Warning.Get_WarningSandNum_CurrentMonth(admin_r.T_pid, 1)
- info.NoticeRecord.Phone = Warning.Get_WarningSandNum_CurrentMonth(admin_r.T_pid, 2)
- }
- if admin_r.T_pid == 0 {
- if len(admin_r.T_pids) > 0 && admin_r.T_pids != "*" {
- info.T_pids = admin_r.T_pids
- info.WarningRate = Warning.Read_WarningRate_Yesterday(admin_r.T_uuid)
- }
- info.WorkOrderNum, info.UntreatedWorkOrderNum = NatsServer.Read_WorkOrderT_State_Count(admin_r.T_pids)
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: info}
- c.ServeJSON()
- return
- }
- // 内部用户管理
- func (c *UserController) Admin_List() {
- var r_jsons lib.R_JSONS
- 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")
- if c.Admin_r.T_pid > 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "无权查看!"}
- c.ServeJSON()
- return
- }
- T_bind_company, _ := c.GetInt("T_bind_company") // 管理员绑定公司 0-全部 1-绑定公司
- Account.Read_Power_All_Map()
- userList, num := Account.Read_Admin_List(0, T_name, page, page_z)
- r_jsons.Data, r_jsons.Num = userList, num
- // 过滤已绑定公司列表
- if T_bind_company == 1 {
- var adminList []Account.Admin_R
- for _, v := range userList {
- if len(v.T_pids) == 0 || v.T_pids == "*" {
- continue
- }
- adminList = append(adminList, v)
- }
- r_jsons.Data = adminList
- }
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *UserController) Admin_Get() {
- T_uuid := c.GetString("T_uuid")
- if len(T_uuid) < 8 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- admin_r, err := Account.Read_Admin_ByUuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Account.AdminToAdmin_R(admin_r)}
- c.ServeJSON()
- return
- }
- func (c *UserController) Admin_Add() {
- T_power, _ := c.GetInt("T_power")
- T_name := c.GetString("T_name")
- T_user := c.GetString("T_user")
- T_pass := c.GetString("T_pass")
- T_phone := c.GetString("T_phone")
- T_mail := c.GetString("T_mail")
- T_wx := c.GetString("T_wx")
- var_ := Account.Admin{
- T_uuid: uuid.NewV4().String(),
- T_pid: 0,
- T_name: T_name,
- T_user: T_user,
- T_phone: T_phone,
- T_mail: T_mail,
- T_wx: T_wx,
- T_pass: T_pass,
- T_power: T_power,
- T_State: 1,
- }
- if len(T_pass) < 8 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "密码异常!"}
- c.ServeJSON()
- return
- }
- _, err := Account.Read_Admin_T_user(T_user)
- if err == nil {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "账户重复!"}
- c.ServeJSON()
- return
- }
- _, err = Account.Add_Admin(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- var_.T_pass = "******"
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "内部用户管理", "添加", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) Admin_Edit() {
- T_uuid := c.GetString("T_uuid")
- if len(T_uuid) < 8 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- r, err := Account.Read_Admin_ByUuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- T_power, T_power_err := c.GetInt("T_power")
- T_name := c.GetString("T_name")
- T_pass := c.GetString("T_pass")
- T_phone := c.GetString("T_phone")
- T_mail := c.GetString("T_mail")
- T_wx := c.GetString("T_wx")
- if T_power_err == nil {
- r.T_power = T_power
- }
- if len(T_pass) < 8 && len(T_pass) > 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "密码异常!"}
- c.ServeJSON()
- return
- }
- if len(T_name) > 0 {
- r.T_name = T_name
- }
- if len(T_pass) >= 8 {
- r.T_pass = T_pass
- }
- if len(T_phone) > 0 {
- r.T_phone = T_phone
- }
- if len(T_mail) > 0 {
- r.T_mail = T_mail
- }
- if len(T_wx) > 0 {
- r.T_wx = T_wx
- }
- is := Account.Update_Admin(r, "T_power", "T_name", "T_pass", "T_phone", "T_mail", "T_wx")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- if len(T_name) > 0 {
- if is = Company.Update_CompanyNotice_Bind_By_T_uuid(T_uuid, "内管-"+T_name); !is {
- logs.Info("修改内部用户 => 修改内部用户关联报警通知失败", T_uuid, T_name)
- }
- }
- r.T_pass = "********"
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "内部用户管理", "修改", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) Admin_Del() {
- T_uuid := c.GetString("T_uuid")
- if len(T_uuid) <= 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- admin_r_lod, err := Account.Read_Admin_ByUuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- if admin_r_lod.Id == 1 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "无权删除!"}
- c.ServeJSON()
- return
- }
- if is := Account.Delete_Admin(admin_r_lod); !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
- c.ServeJSON()
- return
- }
- if is := Company.Delete_CompanyNotice_Bind_By_T_uuid(T_uuid); !is {
- logs.Info("删除内部用户 => 删除内部用户关联报警通知失败", T_uuid)
- }
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "内部用户管理", "删除", T_uuid)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 报警通知的用户列表
- func (c *UserController) User_Notice_List() {
- T_name := c.GetString("T_name")
- type R_JSONS struct {
- //必须的大写开头
- AdminList []Account.Admin_R
- UserList []Account.Admin_R
- }
- var AdminList, UserList []Account.Admin_R
- var r_jsons R_JSONS
- // 操作pid
- company_r, err := Account.Read_Company_ById(c.T_pid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
- c.ServeJSON()
- return
- }
- T_pids := []int{}
- for _, v := range strings.Split(strings.Trim(company_r.T_path, "/"), "/") {
- pid, _ := strconv.Atoi(v)
- T_pids = append(T_pids, pid)
- }
- // 绑定公司id的内部用户列表
- AdminList = Account.Read_Admin_List_T_pids(c.T_pid)
- // 绑定公司id的公司用户列表
- //r_jsons.UserList = Account.Read_Admin_List_T_pid(c.T_pid)
- // 绑定上级公司用户列表
- UserList = Account.Read_Parent_Admin_List(T_pids)
- if len(T_name) > 0 {
- for _, v := range AdminList {
- if strings.Contains(v.T_name, T_name) {
- r_jsons.AdminList = append(r_jsons.AdminList, v)
- }
- }
- for _, v := range UserList {
- if strings.Contains(v.T_name, T_name) {
- r_jsons.UserList = append(r_jsons.UserList, v)
- }
- }
- } else {
- r_jsons.AdminList = AdminList
- r_jsons.UserList = UserList
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 管理员绑定公司
- func (c *UserController) AdminCompanyBind_List() {
- var r_jsons lib.R_JSONS
- T_uuid := c.GetString("T_uuid")
- if len(T_uuid) < 8 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- r, err := Account.Read_Admin_ByUuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- r_jsons.Data = Account.Read_Company_List_ByT_pids(r.T_pids)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *UserController) AdminCompanyBind_Add() {
- T_uuid := c.GetString("T_uuid")
- if len(T_uuid) < 8 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- T_pid, _ := c.GetInt("T_pid")
- if T_pid == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_pid Err!"}
- c.ServeJSON()
- return
- }
- r, err := Account.Read_Admin_ByUuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- if r.T_pids == "*" {
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- Company_r, err := Account.Read_Company_ById(T_pid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_pid Err!"}
- c.ServeJSON()
- return
- }
- T_pids := Account.ReadCompanyIds_T_path(Company_r.T_path)
- if err = Account.Add_Company_bind(r, T_pids); err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "公司绑定失败"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs(c.Admin_r.T_uuid, "内部用户管理", "公司绑定添加", T_uuid+"-"+strconv.Itoa(T_pid))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) AdminCompanyBind_Del() {
- T_uuid := c.GetString("T_uuid")
- if len(T_uuid) < 8 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- T_pid, _ := c.GetInt("T_pid")
- if T_pid == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_pid Err!"}
- c.ServeJSON()
- return
- }
- r, err := Account.Read_Admin_ByUuid(T_uuid)
- Company_r, err := Account.Read_Company_ById(T_pid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_pid Err!"}
- c.ServeJSON()
- return
- }
- T_pids := Account.ReadCompanyIds_T_path(Company_r.T_path)
- if len(T_pids) == 0 {
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- if err = Account.Delete_Company_bind(r, T_pids); err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "公司绑定失败"}
- c.ServeJSON()
- return
- }
- if is := Company.Delete_CompanyNotice_Bind_By_T_uuid_T_pid(T_uuid, T_pids); !is {
- logs.Info("删除内部用户公司绑定 => 删除内部用户绑定的公司关联报警通知失败", T_uuid)
- }
- System.Add_UserLogs(c.Admin_r.T_uuid, "内部用户管理", "公司绑定删除", T_uuid+"-"+strconv.Itoa(T_pid))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 权限管理
- func (c *UserController) Power_List() {
- var r_jsons lib.R_JSONS
- page, _ := c.GetInt("page")
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- Name := c.GetString("T_name")
- r_jsons.Data, r_jsons.Num = Account.Read_Power_List(Name, page, page_z)
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 添加用户 权限选择列表
- func (c *UserController) Power_List_All() {
- r, err := Account.Read_Power_ById(c.Admin_r.T_power)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- var r_jsons lib.R_JSONS
- r_jsons.Data = Account.Read_Power_List_ALL_User(r.T_select)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *UserController) Power_Get() {
- type Data struct {
- Power Account.Power_
- Menu []Account.Menu
- Menu_checked []int
- Select []Account.Power_R
- Warning []Warning.WarningType_R
- }
- var data Data
- id, id_err := c.GetInt("T_id")
- if id_err != nil || id == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- power, err := Account.Read_Power_ById(id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- data.Power = Account.PowerToPower_(power)
- data.Menu, data.Menu_checked = Account.Read_Menu_List_All()
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_menu Err!"}
- c.ServeJSON()
- return
- }
- if power.T_menu != "*" {
- data.Menu_checked = lib.SplitStringToIntIds(power.T_menu, "M")
- }
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_menu Err!"}
- c.ServeJSON()
- return
- }
- data.Select = Account.Read_Power_List_ALL_T_select(power.T_select)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_select Err!"}
- c.ServeJSON()
- return
- }
- data.Warning = Warning.Read_WarningType_All_Power_T_Warning(power.T_warning)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_warning Err!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: data}
- c.ServeJSON()
- return
- }
- func (c *UserController) Power_Add() {
- T_name := c.GetString("T_name")
- T_select := c.GetString("T_select")
- T_warning := c.GetString("T_warning")
- T_menu := c.GetString("T_menu")
- var_ := Account.Power{
- T_name: T_name,
- T_select: T_select,
- T_warning: T_warning,
- T_menu: T_menu,
- T_State: 1,
- }
- _, err := Account.Add_Power(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "权限管理", "添加", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) Power_Edit() {
- Id, Id_err := c.GetInt("T_id")
- if Id_err != nil || Id == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- if Id == 1 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "无权修改!"}
- c.ServeJSON()
- return
- }
- r, err := Account.Read_Power_ById(Id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- T_name := c.GetString("T_name")
- T_select := c.GetString("T_select")
- T_warning := c.GetString("T_warning")
- T_menu := c.GetString("T_menu")
- if len(T_name) > 0 {
- r.T_name = T_name
- }
- if len(T_select) > 0 {
- r.T_select = T_select
- }
- if len(T_warning) > 0 {
- r.T_warning = T_warning
- }
- if len(T_menu) > 0 {
- r.T_menu = T_menu
- }
- is := Account.Update_Power(r, "T_name", "T_select", "T_warning", "T_menu")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(c.Admin_r.T_uuid, "权限管理", "修改", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) Power_Del() {
- id, id_err := c.GetInt("T_id")
- if id_err != nil || id == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- r, err := Account.Read_Power_ById(id)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- if cnt := Account.Read_Admin_Num_ByT_power(id); cnt > 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "有关联用户,禁止删除!"}
- c.ServeJSON()
- return
- }
- is := Account.Delete_Power(r)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "删除失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs(c.Admin_r.T_uuid, "权限管理", "删除", strconv.Itoa(id))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 菜单列表
- func (c *UserController) User_Menu_List() {
- type R_JSONS struct {
- //必须的大写开头
- Data interface{}
- Permission interface{}
- }
- var r_jsons R_JSONS
- power, err := Account.Read_Power_ById(c.Admin_r.T_power)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取菜单失败"}
- c.ServeJSON()
- return
- }
- //logs.Info("登录用户 菜单 pid 为:", c.T_pid)
- ret := Account.Read_Menu_Bind_List(power.Id, power.T_menu, c.T_pid)
- r_jsons.Data = ret.Menu
- r_jsons.Permission = ret.Permission
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 权限菜单列表
- func (c *UserController) Menu_List_All() {
- var r_jsons lib.R_JSONS
- r_jsons.Data, _ = Account.Read_Menu_List_All()
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *UserController) Menu_Excel() {
- filename := fmt.Sprintf("冷链3.0菜单")
- 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", "Menu")
- f.SetRowHeight("Sheet1", 1, 30)
- f.MergeCell("Sheet1", "H1", "M1")
- f.SetRowStyle("Sheet1", 1, 1, Style1)
- f.SetCellValue("Sheet1", "H1", "API")
- f.SetRowHeight("Sheet1", 1, 30)
- f.SetCellStyle("Sheet1", "A2", "G2", Style2)
- f.SetRowHeight("Sheet1", 2, 25)
- // 这里设置表头
- f.SetCellValue("Sheet1", "A2", "ID")
- f.SetCellValue("Sheet1", "B2", "t_mid")
- f.SetCellValue("Sheet1", "C2", "t_name")
- f.SetCellValue("Sheet1", "D2", "t_permission")
- f.SetCellValue("Sheet1", "E2", "t_sort")
- f.SetCellValue("Sheet1", "F2", "t_pid")
- f.SetCellValue("Sheet1", "G2", "t_icon")
- f.SetCellValue("Sheet1", "H2", "ID")
- f.SetCellValue("Sheet1", "I2", "t__menu__id")
- f.SetCellValue("Sheet1", "J2", "t_name")
- f.SetCellValue("Sheet1", "K2", "t_uri")
- f.SetCellValue("Sheet1", "L2", "t_method")
- f.SetCellValue("Sheet1", "M2", "t_enable")
- // 设置列宽
- f.SetColWidth("Sheet1", "A", "M", 15)
- line := 2
- menu := Account.Read_Menu_All()
- for _, m := range menu {
- Menu_Call(f, m, line)
- }
- Style11, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 10, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "top", Color: "000000", Style: 1},
- },
- })
- Style22, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 10, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- },
- })
- Style33, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 10, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "right", Color: "000000", Style: 1},
- },
- })
- Style44, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 10, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "bottom", Color: "000000", Style: 1},
- },
- })
- //// 循环写入数据
- for _, v := range menu {
- line1 := line
- line = Menu_Call(f, v, line)
- f.SetCellStyle("Sheet1", fmt.Sprintf("A%d", line1), fmt.Sprintf("M%d", line1), Style11)
- f.SetCellStyle("Sheet1", fmt.Sprintf("A%d", line), fmt.Sprintf("A%d", line), Style22)
- f.SetCellStyle("Sheet1", fmt.Sprintf("M%d", line), fmt.Sprintf("M%d", line), Style33)
- f.SetCellStyle("Sheet1", fmt.Sprintf("A%d", line), fmt.Sprintf("M%d", line), Style44)
- }
- 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 Menu_Call(f *excelize.File, v Account.Menu, line int) int {
- line++
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), v.Id)
- f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_mid)
- f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_name)
- f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_permission)
- f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_sort)
- f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_pid)
- f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_icon)
- apiList := Account.Read_API_List_ByMenuId(v.Id)
- for _, api := range apiList {
- f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), api.Id)
- f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), api.T_Menu_Id)
- f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), api.T_name)
- f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), api.T_uri)
- f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), api.T_method)
- f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), api.T_enable)
- line++
- }
- return line
- }
- // 流量池
- func (c *UserController) Flow_Pool() {
- var r_jsons lib.R_JSONS
- r_jsons.Data, _ = lib.Yidong_group_data_margin()
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 账单下载
- func (c *UserController) CompanyBill_Excel() {
- T_month := c.GetString("T_month")
- _, 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]
- company, _ := Account.Read_Company_ById(c.Admin_r.T_pid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
- c.ServeJSON()
- return
- }
- filename := fmt.Sprintf("%s%s年%s月账单", company.T_name, 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", "G2", 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.SetCellValue("Sheet1", "G2", "时间")
- // 设置列宽
- f.SetColWidth("Sheet1", "A", "A", 10)
- f.SetColWidth("Sheet1", "B", "B", 50)
- f.SetColWidth("Sheet1", "C", "C", 15)
- f.SetColWidth("Sheet1", "D", "D", 12)
- f.SetColWidth("Sheet1", "E", "E", 15)
- f.SetColWidth("Sheet1", "F", "F", 15)
- f.SetColWidth("Sheet1", "G", "G", 20)
- line := 2
- CompanyBill_List, err := Company.Read_CompanyBill_List(c.Admin_r.T_pid, T_month)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
- c.ServeJSON()
- return
- }
- // 循环写入数据
- for i, v := range CompanyBill_List {
- line++
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
- f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_project)
- f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_bill)
- f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_type)
- f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_charging)
- f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_balance)
- f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.CreateTime.Format("2006-01-02"))
- }
- 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("G%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) WxPay_QRCode() {
- if c.Admin_r.T_pid == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "非公司用户不能充值"}
- c.ServeJSON()
- return
- }
- Total, _ := c.GetFloat("Total")
- Title := "冷链3.0-" + c.Admin_r.T_user
- res, err := lib.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_ := Company.CompanyPayOrder{
- T_pid: c.Admin_r.T_pid,
- T_type: "微信",
- T_title: Title,
- T_total: Total,
- T_order_no: res.OrderNo,
- T_remark: c.Admin_r.T_uuid,
- }
- _, err = Company.Add_CompanyPayOrder(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) WxPay_Notify() {
- type RequestBody struct {
- TradeNo string
- Status string
- }
- type JSON struct {
- Code int
- Message string
- }
- buf := make([]byte, 1024)
- n, _ := c.Ctx.Request.Body.Read(buf)
- logs.Info("Body================ ", string(buf[0:n]))
- //解密
- adc_str, _ := lib.AesDeCrypt(buf[0:n], []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()
- }
- payOrder, err := Company.Get_CompanyPayOrder_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:支付失败(其他原因,如银行返回失败)
- payOrder.T_status = body.Status
- err = Company.Update_CompanyPayOrder(payOrder, "T_status")
- if err != nil {
- c.Data["json"] = JSON{Code: 202, Message: "更新状态失败!"}
- c.ServeJSON()
- return
- }
- // 添加充值记录
- // 余额加上充值金额
- if body.Status == "SUCCESS" {
- Company_r, err := Account.Read_Company_ById(payOrder.T_pid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id Err!"}
- c.ServeJSON()
- return
- }
- T_money64, _ := decimal.NewFromFloat(float64(Company_r.T_money) + payOrder.T_total).Round(2).Float64()
- Company_r.T_money = float32(T_money64)
- is := Account.Update_Company(Company_r, "T_money")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "充值失败!"}
- c.ServeJSON()
- return
- }
- }
- c.Data["json"] = JSON{Code: 200, Message: "成功"}
- c.ServeJSON()
- return
- }
- // 获取微信支付订单状态
- func (c *UserController) WxPay_GetOrderState() {
- OrderNo := c.GetString("OrderNo")
- payOrder, err := Company.Get_CompanyPayOrder_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: payOrder}
- c.ServeJSON()
- return
- }
- // 设备分类绑定
- func (c *UserController) UserDeviceBind_List() {
- var r_jsons lib.R_JSONS
- 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")
- T_uuid := c.GetString("T_uuid")
- admin_r, err := Account.Read_Admin_ByUuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- bindSN, err := Account.Read_UserDevice_List(admin_r)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
- c.ServeJSON()
- return
- }
- if len(bindSN) == 0 {
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- r_jsons.Data, r_jsons.Num = Device.Read_Device_List(&c.Admin_r, bindSN, c.T_pid, T_name, "", "", -1, page, page_z)
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *UserController) UserDeviceUnbind_List() {
- var r_jsons lib.R_JSONS
- 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")
- T_uuid := c.GetString("T_uuid")
- admin_r, err := Account.Read_Admin_ByUuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- bindSN, err := Account.Read_UserDevice_List(admin_r)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
- c.ServeJSON()
- return
- }
- r_jsons.Data, r_jsons.Num = Device.Read_User_Unbind_Device_List(&c.Admin_r, bindSN, c.T_pid, T_name, page, page_z)
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *UserController) UserDeviceBind_Add() {
- T_sn := c.GetString("T_sn")
- T_uuid := c.GetString("T_uuid")
- T_oneHey, _ := c.GetInt("T_oneKey") // 一键绑定
- if T_oneHey == 1 {
- admin_r, err := Account.Read_Admin_ByUuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- bindSN, err := Account.Read_UserDevice_List(admin_r)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
- c.ServeJSON()
- return
- }
- Unbind_Device_List, _ := Device.Read_User_Unbind_Device_List(&c.Admin_r, bindSN, c.T_pid, "", 0, 9999)
- var UserDeviceList []Account.UserDevice
- for _, r := range Unbind_Device_List {
- UserDeviceList = append(UserDeviceList, Account.UserDevice{T_sn: r.T_sn, T_uuid: T_uuid})
- }
- if _, err = Account.Add_UserDevice_Multi(T_uuid, UserDeviceList); err != nil {
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "绑定失败"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs(c.Admin_r.T_uuid, "用户管理", "一键绑定主机操作", T_uuid+"-"+T_sn)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- if len(T_uuid) == 0 || len(T_sn) == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
- c.ServeJSON()
- return
- }
- if len(T_uuid) < 8 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- device, err := Device.Read_Device_ByT_sn(T_sn)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"}
- c.ServeJSON()
- return
- }
- admin_r, err := Account.Read_Admin_ByUuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- if admin_r.T_pid != device.T_pid {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_pid Err!"}
- c.ServeJSON()
- return
- }
- userdievice, err := Account.Read_UserDevice_ByT_uuid_T_sn(T_uuid, T_sn)
- if userdievice.Id > 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "重复绑定!"}
- c.ServeJSON()
- return
- }
- if _, err = Account.Add_UserDevice(Account.UserDevice{T_sn: T_sn, T_uuid: T_uuid}); err != nil {
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "绑定失败"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs(c.Admin_r.T_uuid, "用户管理", "绑定主机操作", T_uuid+"-"+T_sn)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- func (c *UserController) UserDeviceBind_Del() {
- T_sn := c.GetString("T_sn")
- T_uuid := c.GetString("T_uuid")
- if len(T_uuid) == 0 || len(T_sn) == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn T_id T_class_id Err!"}
- c.ServeJSON()
- return
- }
- if len(T_uuid) < 8 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- device, err := Device.Read_Device_ByT_sn(T_sn)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_sn Err!"}
- c.ServeJSON()
- return
- }
- admin_r, err := Account.Read_Admin_ByUuid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid Err!"}
- c.ServeJSON()
- return
- }
- if admin_r.T_pid != device.T_pid {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_pid Err!"}
- c.ServeJSON()
- return
- }
- userdievice, err := Account.Read_UserDevice_ByT_uuid_T_sn(T_uuid, T_sn)
- if err != nil {
- if err.Error() == orm.ErrNoRows.Error() {
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "解绑失败!"}
- c.ServeJSON()
- return
- }
- if err = Account.Delete_UserDevice(Account.UserDevice{Id: userdievice.Id, T_sn: T_sn, T_uuid: T_uuid}); err != nil {
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "删除失败"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs(c.Admin_r.T_uuid, "用户管理", "解绑主机操作", T_uuid+"-"+T_sn)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
|