123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103 |
- 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_user := c.GetString("T_user")
- 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_user) > 0 {
- var admin Account.Admin
- admin, err = Account.Read_Admin_T_user(T_user)
- if err == nil && admin.T_uuid != T_uuid {
- c.Data["json"] = lib.JSONS{Code: 302, Msg: "用户名重复!"}
- c.ServeJSON()
- return
- }
- r.T_user = T_user
- }
- 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_user", "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 {
- logs.Error(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 {
- // logs.Error(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 {
- logs.Error(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 {
- logs.Error(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
- }
|