his_api_controller.go 102KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875
  1. package controllers
  2. import (
  3. "archive/zip"
  4. "bytes"
  5. "encoding/json"
  6. "fmt"
  7. "gdyb/enums"
  8. "gdyb/models"
  9. "gdyb/service"
  10. "gdyb/utils"
  11. "github.com/astaxie/beego"
  12. "github.com/jinzhu/gorm"
  13. "github.com/shopspring/decimal"
  14. "io"
  15. "io/ioutil"
  16. "math/rand"
  17. "net/http"
  18. "os"
  19. "path/filepath"
  20. "strconv"
  21. "strings"
  22. "syscall"
  23. "time"
  24. "unsafe"
  25. )
  26. type HisApiController struct {
  27. BaseAuthAPIController
  28. }
  29. func HisManagerApiRegistRouters() {
  30. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  31. beego.Router("/api/diag/upload", &HisApiController{}, "get:GetUploadDiag")
  32. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  33. beego.Router("/api/settle/get", &HisApiController{}, "get:GetSettleInfo")
  34. //beego.Router("/api/upload/get", &HisApiController{}, "get:Sel")
  35. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  36. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  37. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  38. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  39. beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  40. beego.Router("/api/refundnumber/post", &HisApiController{}, "get:RefundNumber")
  41. beego.Router("/api/refunddetail/post", &HisApiController{}, "get:RefundDetail")
  42. beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment")
  43. beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord")
  44. beego.Router("/api/patient/info", &HisApiController{}, "get:GetHisPatientInfo")
  45. beego.Router("/api/org/info", &HisApiController{}, "get:GetOrgInfo")
  46. }
  47. func (c *HisApiController) GetOrgInfo() {
  48. miConfig, _ := service.FindMedicalInsuranceInfo(9919)
  49. service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "")
  50. }
  51. func (c *HisApiController) GetHisPatientInfo() {
  52. medical_insurance_card := c.GetString("medical_insurance_card")
  53. id_card_type, _ := c.GetInt64("id_card_type")
  54. id_card := c.GetString("id_card")
  55. adminInfo := c.GetAdminUserInfo()
  56. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  57. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  58. appRole, _ := service.GetAppRole(adminInfo.CurrentOrgId)
  59. IdCardNo := ""
  60. if id_card_type == 1 {
  61. IdCardNo = medical_insurance_card
  62. } else if id_card_type == 2 {
  63. IdCardNo = id_card
  64. }
  65. if config.IsOpen == 1 {
  66. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  67. resp, requestErr := http.Get(api)
  68. if requestErr != nil {
  69. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  70. return
  71. }
  72. defer resp.Body.Close()
  73. body, ioErr := ioutil.ReadAll(resp.Body)
  74. if ioErr != nil {
  75. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  76. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  77. return
  78. }
  79. var respJSON map[string]interface{}
  80. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  81. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  82. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  83. return
  84. }
  85. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  86. userJSONBytes, _ := json.Marshal(userJSON)
  87. var res ResultTwo
  88. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  89. utils.ErrorLog("解析失败:%v", err)
  90. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  91. return
  92. }
  93. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  94. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  95. infoStr := string(Iinfos)
  96. idetinfoStr := string(Idetinfos)
  97. if res.Infcode == 0 {
  98. his := models.VMHisPatient{
  99. Status: 1,
  100. Ctime: time.Now().Unix(),
  101. Mtime: time.Now().Unix(),
  102. PsnNo: res.Output.Baseinfo.PsnNo,
  103. PsnCertType: res.Output.Baseinfo.PsnCertType,
  104. Certno: res.Output.Baseinfo.Certno,
  105. PsnName: res.Output.Baseinfo.PsnName,
  106. Gend: res.Output.Baseinfo.Gend,
  107. Naty: res.Output.Baseinfo.Naty,
  108. Brdy: res.Output.Baseinfo.Brdy,
  109. Age: res.Output.Baseinfo.Age,
  110. Iinfo: infoStr,
  111. Idetinfo: idetinfoStr,
  112. UserOrgId: adminInfo.CurrentOrgId,
  113. IsReturn: 1,
  114. IdCardType: id_card_type,
  115. }
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "info": his,
  118. })
  119. } else {
  120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  121. return
  122. }
  123. }
  124. }
  125. func (c *HisApiController) Sscard() {
  126. id_card_type, _ := c.GetInt64("id_card_type")
  127. adminUser := c.GetAdminUserInfo()
  128. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  129. r := CardInit()
  130. fmt.Println(r)
  131. //if r == 0 {
  132. switch id_card_type {
  133. case 1:
  134. basStr, err := GetBasBaseInfo()
  135. if err != nil {
  136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  137. return
  138. } else {
  139. fmt.Println(basStr)
  140. bas := strings.Split(basStr, "|")
  141. basNumber := bas[1]
  142. //basNumber := bas[2]
  143. card_sn := bas[3]
  144. appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  145. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + basNumber + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10) + "&card_sn=" + card_sn
  146. resp, requestErr := http.Get(api)
  147. if requestErr != nil {
  148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  149. return
  150. }
  151. defer resp.Body.Close()
  152. body, ioErr := ioutil.ReadAll(resp.Body)
  153. if ioErr != nil {
  154. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  156. return
  157. }
  158. var respJSON map[string]interface{}
  159. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  160. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  162. return
  163. }
  164. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  165. userJSONBytes, _ := json.Marshal(userJSON)
  166. var res ResultTwo
  167. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  168. utils.ErrorLog("解析失败:%v", err)
  169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  170. return
  171. }
  172. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  173. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  174. infoStr := string(Iinfos)
  175. idetinfoStr := string(Idetinfos)
  176. if res.Infcode == 0 {
  177. his := models.VMHisPatient{
  178. Status: 1,
  179. Ctime: time.Now().Unix(),
  180. Mtime: time.Now().Unix(),
  181. PsnNo: res.Output.Baseinfo.PsnNo,
  182. PsnCertType: res.Output.Baseinfo.PsnCertType,
  183. Certno: res.Output.Baseinfo.Certno,
  184. PsnName: res.Output.Baseinfo.PsnName,
  185. Gend: res.Output.Baseinfo.Gend,
  186. Naty: res.Output.Baseinfo.Naty,
  187. Brdy: res.Output.Baseinfo.Brdy,
  188. Age: res.Output.Baseinfo.Age,
  189. Iinfo: infoStr,
  190. Idetinfo: idetinfoStr,
  191. UserOrgId: adminUser.CurrentOrgId,
  192. IsReturn: 1,
  193. IdCardType: id_card_type,
  194. }
  195. patient, err := service.GetPatientByNumber(basNumber, adminUser.CurrentOrgId)
  196. if err == gorm.ErrRecordNotFound {
  197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  198. return
  199. } else if err != nil {
  200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  201. return
  202. } else {
  203. c.ServeSuccessJSON(map[string]interface{}{
  204. "patient": patient,
  205. "his": his,
  206. "number": basNumber,
  207. })
  208. }
  209. } else {
  210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  211. return
  212. }
  213. }
  214. break
  215. case 2:
  216. ////SFZStr, err := GetSFZBaseInfo()
  217. //if err != nil {
  218. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  219. // return
  220. //
  221. //} else {
  222. //
  223. // id_card_str := strings.Split(SFZStr, "^")
  224. // id_card_number := id_card_str[0]
  225. //appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  226. //
  227. //api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + id_card_number + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
  228. //resp, requestErr := http.Get(api)
  229. //if requestErr != nil {
  230. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  231. // return
  232. //}
  233. //defer resp.Body.Close()
  234. //body, ioErr := ioutil.ReadAll(resp.Body)
  235. //if ioErr != nil {
  236. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  237. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  238. // return
  239. //}
  240. //var respJSON map[string]interface{}
  241. //
  242. //if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  243. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  244. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. // return
  246. //}
  247. //
  248. //userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  249. //userJSONBytes, _ := json.Marshal(userJSON)
  250. //var res ResultTwo
  251. //if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  252. // utils.ErrorLog("解析失败:%v", err)
  253. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  254. // return
  255. //}
  256. //Iinfos, _ := json.Marshal(res.Output.Iinfo)
  257. //Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  258. //infoStr := string(Iinfos)
  259. //idetinfoStr := string(Idetinfos)
  260. //
  261. //if res.Infcode == 0 {
  262. // his := models.VMHisPatient{
  263. // Status: 1,
  264. // Ctime: time.Now().Unix(),
  265. // Mtime: time.Now().Unix(),
  266. // PsnNo: res.Output.Baseinfo.PsnNo,
  267. // PsnCertType: res.Output.Baseinfo.PsnCertType,
  268. // Certno: res.Output.Baseinfo.Certno,
  269. // PsnName: res.Output.Baseinfo.PsnName,
  270. // Gend: res.Output.Baseinfo.Gend,
  271. // Naty: res.Output.Baseinfo.Naty,
  272. // Brdy: res.Output.Baseinfo.Brdy,
  273. // Age: res.Output.Baseinfo.Age,
  274. // Iinfo: infoStr,
  275. // Idetinfo: idetinfoStr,
  276. // UserOrgId: adminUser.CurrentOrgId,
  277. // IsReturn: 1,
  278. // IdCardType: id_card_type,
  279. // }
  280. // patient, err := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  281. // if err == gorm.ErrRecordNotFound {
  282. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  283. // return
  284. //
  285. // } else if err != nil {
  286. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  287. // return
  288. //
  289. // } else {
  290. // c.ServeSuccessJSON(map[string]interface{}{
  291. // "patient": patient,
  292. // "number": id_card_number,
  293. // })
  294. // }
  295. //}
  296. break
  297. case 3:
  298. break
  299. }
  300. }
  301. func GetBasBaseInfo() (jsonStr string, err error) {
  302. handle, err := syscall.LoadLibrary("SSCard.dll")
  303. if err != nil {
  304. fmt.Printf("Error: %s\n", err)
  305. return "", err
  306. }
  307. defer syscall.FreeLibrary(handle)
  308. str := make([]byte, 256)
  309. str1 := make([]byte, 256)
  310. add, err := syscall.GetProcAddress(handle, "ReadCardBas")
  311. if err != nil {
  312. fmt.Printf("Error: %s\n", err)
  313. return "", err
  314. }
  315. ret, _, _ := syscall.Syscall(add, (uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  316. if err != nil {
  317. fmt.Printf("Error: %s\n", err)
  318. }
  319. fmt.Println("> Add(4,5)的结果为:", ret)
  320. //return nil
  321. //
  322. //handle := syscall.NewLazyDLL("SSCard.dll")
  323. //ReadCardBas := handle.NewProc("ReadCardBas")
  324. //
  325. //var str2 [1024]C.char
  326. //var str3 [1024]C.char
  327. //
  328. //
  329. //
  330. ////sssssswwwww
  331. ////a := 256
  332. //
  333. //r, _, _ := ReadCardBas.Call(&str2, 1024, &str3, 1024)
  334. //fmt.Println(r)
  335. ////p := (*byte)(unsafe.Pointer(r))
  336. // define a slice to fill with the p string
  337. //data := make([]byte, 0)
  338. // loop until find '\0'
  339. //if *p != 0 {
  340. //
  341. // //data = append(data, *p) // append 1 byte
  342. // //r += unsafe.Sizeof(byte(0)) // move r to next byte
  343. // //p = (*byte)(unsafe.Pointer(r)) // get the byte value
  344. //} else {
  345. // return "", nil
  346. //
  347. //}
  348. return "", nil
  349. }
  350. //func GetSFZBaseInfo() (jsonStr string, err error) {
  351. // //handle := syscall.MustLoadDLL("SSCard.dll")
  352. //
  353. // str := make([]byte, 256)
  354. // str1 := make([]byte, 256)
  355. // r, _, _ := ReadIDCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  356. //
  357. // fmt.Println(r)
  358. // return string(str), nil
  359. //}
  360. //func GetQRBaseInfo() (jsonStr string, err error) {
  361. // handle := syscall.LoadDLL("SSCard.dll")
  362. // ReadCardBas := handle.FindProc("GetQRBase")
  363. //
  364. // str := make([]byte, 256)
  365. // str1 := make([]byte, 256)
  366. // r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  367. //
  368. // fmt.Println(string(str))
  369. // fmt.Println(r)
  370. // return string(str), nil
  371. //}
  372. func CardInit() int {
  373. DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  374. add := DllTestDef.MustFindProc("Init")
  375. ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  376. if err != nil {
  377. fmt.Println("SSCard的运算结果为:", ret)
  378. }
  379. result := int(ret)
  380. return result
  381. }
  382. //func CardInit() int {
  383. // ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  384. // if err != nil {
  385. // fmt.Println("SSCard的运算结果为:", ret)
  386. // }
  387. // fmt.Println(err)
  388. // result := int(ret)
  389. // return result
  390. //}
  391. func IntPtr(n int) uintptr {
  392. return uintptr(n)
  393. }
  394. func StrPtr(s string) uintptr {
  395. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  396. }
  397. type ResultTwo struct {
  398. ErrMsg string `json:"err_msg"`
  399. InfRefmsgid string `json:"inf_refmsgid"`
  400. Infcode int64 `json:"infcode"`
  401. Output struct {
  402. Baseinfo struct {
  403. Age float64 `json:"age"`
  404. Brdy string `json:"brdy"`
  405. Certno string `json:"certno"`
  406. Gend string `json:"gend"`
  407. Naty string `json:"naty"`
  408. PsnCertType string `json:"psn_cert_type"`
  409. PsnName string `json:"psn_name"`
  410. PsnNo string `json:"psn_no"`
  411. } `json:"baseinfo"`
  412. Idetinfo []interface{} `json:"idetinfo"`
  413. Iinfo []struct {
  414. Balc int64 `json:"balc"`
  415. CvlservFlag string `json:"cvlserv_flag"`
  416. EmpName string `json:"emp_name"`
  417. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  418. Insutype string `json:"insutype"`
  419. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  420. PausInsuDate interface{} `json:"paus_insu_date"`
  421. PsnInsuDate string `json:"psn_insu_date"`
  422. PsnInsuStas string `json:"psn_insu_stas"`
  423. PsnType string `json:"psn_type"`
  424. } `json:"insuinfo"`
  425. } `json:"output"`
  426. RefmsgTime string `json:"refmsg_time"`
  427. RespondTime string `json:"respond_time"`
  428. Signtype interface{} `json:"signtype"`
  429. WarnInfo interface{} `json:"warn_info"`
  430. }
  431. type ResultThree struct {
  432. Cainfo interface{} `json:"cainfo"`
  433. ErrMsg string `json:"err_msg"`
  434. InfRefmsgid string `json:"inf_refmsgid"`
  435. Infcode int64 `json:"infcode"`
  436. Output struct {
  437. Data struct {
  438. IptOtpNo string `json:"ipt_otp_no"`
  439. MdtrtID string `json:"mdtrt_id"`
  440. PsnNo string `json:"psn_no"`
  441. } `json:"data"`
  442. } `json:"output"`
  443. RefmsgTime string `json:"refmsg_time"`
  444. RespondTime string `json:"respond_time"`
  445. Signtype interface{} `json:"signtype"`
  446. WarnMsg interface{} `json:"warn_msg"`
  447. }
  448. type ResultFour struct {
  449. Cainfo string `json:"cainfo"`
  450. ErrMsg string `json:"err_msg"`
  451. InfRefmsgid string `json:"inf_refmsgid"`
  452. Infcode int64 `json:"infcode"`
  453. Output struct {
  454. Result []struct {
  455. BasMednFlag string `json:"bas_medn_flag"`
  456. ChldMedcFlag string `json:"chld_medc_flag"`
  457. ChrgitmLv string `json:"chrgitm_lv"`
  458. Cnt float64 `json:"cnt"`
  459. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  460. DrtReimFlag string `json:"drt_reim_flag"`
  461. FeedetlSn string `json:"feedetl_sn"`
  462. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  463. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  464. InscpScpAmt float64 `json:"inscp_scp_amt"`
  465. ListSpItemFlag string `json:"list_sp_item_flag"`
  466. LmtUsedFlag string `json:"lmt_used_flag"`
  467. MedChrgitmType string `json:"med_chrgitm_type"`
  468. Memo string `json:"memo"`
  469. OverlmtAmt float64 `json:"overlmt_amt"`
  470. PreselfpayAmt float64 `json:"preselfpay_amt"`
  471. Pric float64 `json:"pric"`
  472. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  473. SelfpayProp float64 `json:"selfpay_prop"`
  474. } `json:"result"`
  475. } `json:"output"`
  476. RefmsgTime string `json:"refmsg_time"`
  477. RespondTime string `json:"respond_time"`
  478. Signtype string `json:"signtype"`
  479. WarnMsg string `json:"warn_msg"`
  480. }
  481. type ResultFive struct {
  482. Insutype string `json:"insutype"`
  483. }
  484. type ResultSix struct {
  485. Cainfo interface{} `json:"cainfo"`
  486. ErrMsg string `json:"err_msg"`
  487. InfRefmsgid string `json:"inf_refmsgid"`
  488. Infcode int64 `json:"infcode"`
  489. Output struct {
  490. } `json:"output"`
  491. RefmsgTime string `json:"refmsg_time"`
  492. RespondTime string `json:"respond_time"`
  493. Signtype interface{} `json:"signtype"`
  494. WarnMsg interface{} `json:"warn_msg"`
  495. }
  496. type ResultSeven struct {
  497. Cainfo string `json:"cainfo"`
  498. ErrMsg string `json:"err_msg"`
  499. InfRefmsgid string `json:"inf_refmsgid"`
  500. Infcode int64 `json:"infcode"`
  501. Output struct {
  502. Setldetail []interface{} `json:"setldetail"`
  503. Setlinfo struct {
  504. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  505. AcctPay float64 `json:"acct_pay"`
  506. ActPayDedc float64 `json:"act_pay_dedc"`
  507. Age float64 `json:"age"`
  508. Balc float64 `json:"balc"`
  509. Brdy string `json:"brdy"`
  510. Certno string `json:"certno"`
  511. ClrOptins string `json:"clr_optins"`
  512. ClrType string `json:"clr_type"`
  513. ClrWay string `json:"clr_way"`
  514. CvlservFlag string `json:"cvlserv_flag"`
  515. CvlservPay float64 `json:"cvlserv_pay"`
  516. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  517. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  518. Gend string `json:"gend"`
  519. HifesPay float64 `json:"hifes_pay"`
  520. HifmiPay float64 `json:"hifmi_pay"`
  521. HifpPay float64 `json:"hifp_pay"`
  522. HospPartAmt float64 `json:"hosp_part_amt"`
  523. InscpScpAmt float64 `json:"inscp_scp_amt"`
  524. Insutype string `json:"insutype"`
  525. MafPay float64 `json:"maf_pay"`
  526. MdtrtCertType string `json:"mdtrt_cert_type"`
  527. HifobPay float64 `json:"hifob_pay"`
  528. MdtrtID string `json:"mdtrt_id"`
  529. MedType string `json:"med_type"`
  530. MedfeeSumamt float64 `json:"medfee_sumamt"`
  531. MedinsSetlID string `json:"medins_setl_id"`
  532. Naty string `json:"naty"`
  533. OthPay float64 `json:"oth_pay"`
  534. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  535. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  536. PreselfpayAmt float64 `json:"preselfpay_amt"`
  537. PsnCashPay float64 `json:"psn_cash_pay"`
  538. PsnCertType string `json:"psn_cert_type"`
  539. PsnName string `json:"psn_name"`
  540. PsnNo string `json:"psn_no"`
  541. PsnPartAmt float64 `json:"psn_part_amt"`
  542. PsnType string `json:"psn_type"`
  543. SetlID string `json:"setl_id"`
  544. SetlTime string `json:"setl_time"`
  545. } `json:"setlinfo"`
  546. } `json:"output"`
  547. RefmsgTime string `json:"refmsg_time"`
  548. RespondTime string `json:"respond_time"`
  549. Signtype interface{} `json:"signtype"`
  550. WarnMsg interface{} `json:"warn_msg"`
  551. }
  552. type ResultEight struct {
  553. Cainfo string `json:"cainfo"`
  554. ErrMsg string `json:"err_msg"`
  555. InfRefmsgid string `json:"inf_refmsgid"`
  556. Infcode int64 `json:"infcode"`
  557. Output struct {
  558. Stmtinfo struct {
  559. SetlOptins string `json:"setl_optins"`
  560. StmtRslt string `json:"stmt_rslt"`
  561. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  562. } `json:"stmtinfo"`
  563. } `json:"output"`
  564. RefmsgTime string `json:"refmsg_time"`
  565. RespondTime string `json:"respond_time"`
  566. Signtype interface{} `json:"signtype"`
  567. WarnMsg interface{} `json:"warn_msg"`
  568. }
  569. type ResultNine struct {
  570. Cainfo string `json:"cainfo"`
  571. ErrMsg string `json:"err_msg"`
  572. InfRefmsgid string `json:"inf_refmsgid"`
  573. Infcode int64 `json:"infcode"`
  574. Output struct {
  575. FileQuryNo string `json:"file_qury_no"`
  576. } `json:"output"`
  577. RefmsgTime string `json:"refmsg_time"`
  578. RespondTime string `json:"respond_time"`
  579. Signtype interface{} `json:"signtype"`
  580. WarnMsg interface{} `json:"warn_msg"`
  581. }
  582. type ResultTen struct {
  583. Cainfo string `json:"cainfo"`
  584. ErrMsg string `json:"err_msg"`
  585. InfRefmsgid string `json:"inf_refmsgid"`
  586. Infcode int64 `json:"infcode"`
  587. Output struct {
  588. DldEndtime string `json:"dld_endtime"`
  589. FileQuryNo string `json:"file_qury_no"`
  590. Filename string `json:"filename"`
  591. } `json:"output"`
  592. RefmsgTime string `json:"refmsg_time"`
  593. RespondTime string `json:"respond_time"`
  594. Signtype interface{} `json:"signtype"`
  595. WarnMsg interface{} `json:"warn_msg"`
  596. }
  597. type ResultEleven struct {
  598. Cainfo string `json:"cainfo"`
  599. ErrMsg string `json:"err_msg"`
  600. InfRefmsgid string `json:"inf_refmsgid"`
  601. Infcode int64 `json:"infcode"`
  602. Output struct {
  603. Setlinfo struct {
  604. FixmedinsName string `json:"fixmedins_name"`
  605. FixmedinsCode string `json:"fixmedins_code"`
  606. PsnNo string `json:"psn_no"`
  607. PsnName string `json:"psn_name"`
  608. HifobPay float64 `json:"hifob_pay"`
  609. Gend string `json:"gend"`
  610. Brdy string `json:"brdy"`
  611. PsnCertType string `json:"psn_cert_type"`
  612. PsnType string `json:"psn_type"`
  613. EmpName string `json:"emp_name"`
  614. Certno string `json:"certno"`
  615. Insutype string `json:"insutype"`
  616. MedfeeSumamt float64 `json:"medfee_sumamt"`
  617. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  618. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  619. PreselfpayAmt float64 `json:"preselfpay_amt"`
  620. InscpScpAmt float64 `json:"inscp_scp_amt"`
  621. ActPayDedc float64 `json:"act_pay_dedc"`
  622. HifpPay float64 `json:"hifp_pay"`
  623. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  624. CvlservPay float64 `json:"cvlserv_pay"`
  625. HifesPay float64 `json:"hifes_pay"`
  626. HifmiPay float64 `json:"hifmi_pay"`
  627. MafPay float64 `json:"maf_pay"`
  628. OthPay float64 `json:"oth_pay"`
  629. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  630. PsnPay float64 `json:"psn_pay"`
  631. AcctPay float64 `json:"acct_pay"`
  632. CashPayamt float64 `json:"cash_payamt"`
  633. Balc float64 `json:"balc"`
  634. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  635. MedinsSetlId string `json:"medins_setl_id"`
  636. RefdSetlFlag string `json:"refd_setl_flag"`
  637. SetlTime string `json:"setl_time"`
  638. MedType string `json:"med_type"`
  639. HospLv string `json:"hosp_lv"`
  640. } `json:"setlinfo"`
  641. } `json:"output"`
  642. RefmsgTime string `json:"refmsg_time"`
  643. RespondTime string `json:"respond_time"`
  644. Signtype interface{} `json:"signtype"`
  645. WarnMsg interface{} `json:"warn_msg"`
  646. }
  647. type ResultTwelve struct {
  648. Cainfo string `json:"cainfo"`
  649. ErrMsg string `json:"err_msg"`
  650. InfRefmsgid string `json:"inf_refmsgid"`
  651. Infcode int64 `json:"infcode"`
  652. Output struct {
  653. MdtrtId string `json:"mdtrt_id"`
  654. ChrgBchno string `json:"chrg_bchno"`
  655. PsnNo string `json:"psn_no"`
  656. } `json:"output"`
  657. RefmsgTime string `json:"refmsg_time"`
  658. RespondTime string `json:"respond_time"`
  659. Signtype interface{} `json:"signtype"`
  660. WarnMsg interface{} `json:"warn_msg"`
  661. }
  662. type Custom struct {
  663. DetItemFeeSumamt string
  664. Cut string
  665. FeedetlSn string
  666. Price string
  667. MedListCodg string
  668. Type int64
  669. AdviceId int64
  670. ProjectId int64
  671. ItemId int64
  672. }
  673. //获取个人信息----挂号-----上传就诊信息
  674. func (c *HisApiController) GetRegisterInfo() {
  675. id, _ := c.GetInt64("id")
  676. record_time := c.GetString("record_time")
  677. settlementValue, _ := c.GetInt64("settlement_value")
  678. medical_insurance_card := c.GetString("medical_insurance_card")
  679. name := c.GetString("name")
  680. id_card_type, _ := c.GetInt64("id_card_type")
  681. certificates, _ := c.GetInt64("certificates")
  682. medical_care, _ := c.GetInt64("medical_care")
  683. birthday := c.GetString("birthday")
  684. age, _ := c.GetInt64("age")
  685. id_card := c.GetString("id_card")
  686. register_type, _ := c.GetInt64("register")
  687. doctor, _ := c.GetInt64("doctor")
  688. department, _ := c.GetInt64("department")
  689. gender, _ := c.GetInt64("sex")
  690. phone := c.GetString("phone")
  691. registration_fee, _ := c.GetFloat("registration_fee")
  692. medical_expenses, _ := c.GetFloat("medical_expenses")
  693. social_type, _ := c.GetInt64("social_type")
  694. admin_user_id, _ := c.GetInt64("admin_user_id")
  695. diagnosis_id, _ := c.GetInt64("diagnosis")
  696. sick_type, _ := c.GetInt64("sick_type")
  697. reg_type := c.GetString("p_type")
  698. timeLayout := "2006-01-02"
  699. loc, _ := time.LoadLocation("Local")
  700. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  701. birthUnix := birthdays.Unix()
  702. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  703. if err != nil {
  704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  705. return
  706. }
  707. recordDateTime := theTime.Unix()
  708. adminInfo := c.GetAdminUserInfo()
  709. var patient service.Patients
  710. if id == 0 {
  711. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  712. } else {
  713. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  714. }
  715. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  716. if patientPrescription.ID == 0 {
  717. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  718. }
  719. //adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  720. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  721. sickConfig, _ := service.FindSickById(sick_type)
  722. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  723. if patient.ID == 0 {
  724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  725. return
  726. }
  727. if len(patient.IdCardNo) == 0 {
  728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  729. return
  730. }
  731. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  732. if config.IsOpen == 1 {
  733. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  734. resp, requestErr := http.Get(api)
  735. if requestErr != nil {
  736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  737. return
  738. }
  739. defer resp.Body.Close()
  740. body, ioErr := ioutil.ReadAll(resp.Body)
  741. if ioErr != nil {
  742. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  744. return
  745. }
  746. var respJSON map[string]interface{}
  747. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  748. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  750. return
  751. }
  752. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  753. userJSONBytes, _ := json.Marshal(userJSON)
  754. var res ResultTwo
  755. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  756. utils.ErrorLog("解析失败:%v", err)
  757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  758. return
  759. }
  760. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  761. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  762. infoStr := string(Iinfos)
  763. idetinfoStr := string(Idetinfos)
  764. if res.Infcode == 0 {
  765. his := models.VMHisPatient{
  766. Name: name,
  767. Gender: gender,
  768. Birthday: birthUnix,
  769. MedicalTreatmentType: medical_care,
  770. IdType: certificates,
  771. IdCardNo: id_card,
  772. BalanceAccountsType: settlementValue,
  773. SocialType: social_type,
  774. MedicalInsuranceNumber: medical_insurance_card,
  775. RegisterType: register_type,
  776. RegisterCost: registration_fee,
  777. TreatmentCost: medical_expenses,
  778. Status: 1,
  779. Ctime: time.Now().Unix(),
  780. Mtime: time.Now().Unix(),
  781. PsnNo: res.Output.Baseinfo.PsnNo,
  782. PsnCertType: res.Output.Baseinfo.PsnCertType,
  783. Certno: res.Output.Baseinfo.Certno,
  784. PsnName: res.Output.Baseinfo.PsnName,
  785. Gend: res.Output.Baseinfo.Gend,
  786. Naty: res.Output.Baseinfo.Naty,
  787. Brdy: res.Output.Baseinfo.Brdy,
  788. Age: res.Output.Baseinfo.Age,
  789. Iinfo: infoStr,
  790. Idetinfo: idetinfoStr,
  791. PatientId: patient.ID,
  792. RecordDate: theTime.Unix(),
  793. UserOrgId: adminInfo.CurrentOrgId,
  794. AdminUserId: admin_user_id,
  795. IsReturn: 1,
  796. IdCardType: id_card_type,
  797. Doctor: doctor,
  798. Departments: department,
  799. }
  800. timestamp := time.Now().Unix()
  801. tempTime := time.Unix(timestamp, 0)
  802. timeFormat := tempTime.Format("20060102150405")
  803. chrgBchno := rand.Intn(100000) + 10000
  804. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  805. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  806. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  807. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  808. IdCardNo := ""
  809. if id_card_type == 1 {
  810. IdCardNo = medical_insurance_card
  811. } else {
  812. IdCardNo = patient.IdCardNo
  813. }
  814. if count <= 0 {
  815. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + IdCardNo + "&insutype=" +
  816. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  817. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  818. "&dept=" + department.Name + "&fixmedins_code=" + miConfig.Code + "&dept_code=" + department.Number + "&doctor_id=" + doctor_id + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
  819. resp, requestErr := http.Get(api)
  820. if requestErr != nil {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  822. return
  823. }
  824. defer resp.Body.Close()
  825. body, ioErr := ioutil.ReadAll(resp.Body)
  826. if ioErr != nil {
  827. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  829. return
  830. }
  831. var respJSON map[string]interface{}
  832. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  833. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  835. return
  836. }
  837. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  838. userJSONBytes, _ := json.Marshal(respJSON)
  839. var res ResultThree
  840. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  841. utils.ErrorLog("解析失败:%v", err)
  842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  843. return
  844. }
  845. if res.Infcode == -1 {
  846. adminUser := c.GetAdminUserInfo()
  847. errlog := &models.HisOrderError{
  848. UserOrgId: adminUser.CurrentOrgId,
  849. Ctime: time.Now().Unix(),
  850. Mtime: time.Now().Unix(),
  851. ErrMsg: res.ErrMsg,
  852. Status: 1,
  853. PatientId: id,
  854. RecordTime: recordDateTime,
  855. Stage: 2,
  856. }
  857. service.CreateErrMsgLog(errlog)
  858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  859. return
  860. }
  861. his.Number = res.Output.Data.MdtrtID
  862. his.PsnNo = res.Output.Data.PsnNo
  863. his.IptOtpNo = res.Output.Data.IptOtpNo
  864. his.IdCardNo = patient.IdCardNo
  865. his.PhoneNumber = patient.Phone
  866. his.UserOrgId = adminInfo.CurrentOrgId
  867. his.Ctime = time.Now().Unix()
  868. his.Mtime = time.Now().Unix()
  869. his.Status = 1
  870. err := service.CreateHisPatientTwo(&his)
  871. if err == nil {
  872. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  873. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  874. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + reg_type + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  875. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  876. resp2, requestErr2 := http.Get(api2)
  877. if requestErr2 != nil {
  878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  879. return
  880. }
  881. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  882. if ioErr2 != nil {
  883. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  885. return
  886. }
  887. var respJSON2 map[string]interface{}
  888. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  889. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  891. return
  892. }
  893. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  894. userJSONBytes2, _ := json.Marshal(respJSON2)
  895. var res2 ResultSix
  896. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  897. utils.ErrorLog("解析失败:%v", err)
  898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  899. return
  900. }
  901. if res2.Infcode == -1 {
  902. adminUser := c.GetAdminUserInfo()
  903. errlog := &models.HisOrderError{
  904. UserOrgId: adminUser.CurrentOrgId,
  905. Ctime: time.Now().Unix(),
  906. Mtime: time.Now().Unix(),
  907. ErrMsg: res2.ErrMsg,
  908. Status: 1,
  909. PatientId: id,
  910. RecordTime: recordDateTime,
  911. Stage: 3,
  912. }
  913. service.CreateErrMsgLog(errlog)
  914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  915. return
  916. }
  917. c.ServeSuccessJSON(map[string]interface{}{
  918. "his_info": his,
  919. })
  920. } else {
  921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  922. return
  923. }
  924. } else {
  925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  926. return
  927. }
  928. } else {
  929. adminUser := c.GetAdminUserInfo()
  930. errlog := &models.HisOrderError{
  931. UserOrgId: adminUser.CurrentOrgId,
  932. Ctime: time.Now().Unix(),
  933. Mtime: time.Now().Unix(),
  934. ErrMsg: res.ErrMsg,
  935. Status: 1,
  936. PatientId: id,
  937. RecordTime: recordDateTime,
  938. Stage: 1,
  939. }
  940. service.CreateErrMsgLog(errlog)
  941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  942. return
  943. }
  944. } else {
  945. timeStr := time.Now().Format("2006-01-02")
  946. timeArr := strings.Split(timeStr, "-")
  947. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  948. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  949. var hisPatient models.XtHisPatient
  950. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  951. hisPatient = models.XtHisPatient{
  952. Name: name,
  953. Age: age,
  954. Gender: gender,
  955. Birthday: birthUnix,
  956. Phone: phone,
  957. MedicalTreatmentType: medical_care,
  958. IdType: certificates,
  959. IdCardNo: id_card,
  960. BalanceAccountsType: settlementValue,
  961. SocialType: social_type,
  962. MedicalInsuranceNumber: medical_insurance_card,
  963. RegisterType: register_type,
  964. RegisterCost: registration_fee,
  965. TreatmentCost: medical_expenses,
  966. AdminUserId: admin_user_id,
  967. UserOrgId: adminInfo.CurrentOrgId,
  968. Status: 1,
  969. RecordDate: recordDateTime,
  970. IsReturn: 1,
  971. PatientId: patient.ID,
  972. Ctime: time.Now().Unix(),
  973. Mtime: time.Now().Unix(),
  974. Number: str,
  975. }
  976. service.CreateHisPatient(&hisPatient)
  977. }
  978. c.ServeSuccessJSON(map[string]interface{}{
  979. "his_info": hisPatient,
  980. })
  981. }
  982. }
  983. //上传明细----结算
  984. func (c *HisApiController) GetUploadInfo() {
  985. id, _ := c.GetInt64("id")
  986. record_time := c.GetString("record_time")
  987. pay_way, _ := c.GetInt64("pay_way")
  988. pay_price, _ := c.GetFloat("pay_price")
  989. pay_card_no := c.GetString("pay_card_no")
  990. discount_price, _ := c.GetFloat("discount_price")
  991. preferential_price, _ := c.GetFloat("preferential_price")
  992. reality_price, _ := c.GetFloat("reality_price")
  993. found_price, _ := c.GetFloat("found_price")
  994. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  995. private_price, _ := c.GetFloat("private_price")
  996. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  997. admin_user_id, _ := c.GetInt64("admin_user_id")
  998. timeLayout := "2006-01-02"
  999. loc, _ := time.LoadLocation("Local")
  1000. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1001. if err != nil {
  1002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1003. return
  1004. }
  1005. recordDateTime := theTime.Unix()
  1006. adminUser := c.GetAdminUserInfo()
  1007. var prescriptions []*models.HisPrescription
  1008. var start_time int64
  1009. var end_time int64
  1010. data := make(map[string]interface{})
  1011. if settle_accounts_type == 1 { //日结
  1012. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1013. data["pre"] = prescriptions
  1014. } else { //月结
  1015. start_time_str := c.GetString("start_time")
  1016. end_time_str := c.GetString("end_time")
  1017. timeLayout := "2006-01-02"
  1018. loc, _ := time.LoadLocation("Local")
  1019. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1020. if err != nil {
  1021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1022. return
  1023. }
  1024. recordStartTime := theStartTime.Unix()
  1025. start_time = recordStartTime
  1026. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1027. if err != nil {
  1028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1029. return
  1030. }
  1031. recordEndTime := theEndTime.Unix()
  1032. end_time = recordEndTime
  1033. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1034. data["pre"] = prescriptions
  1035. }
  1036. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1037. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1038. timestamp := time.Now().Unix()
  1039. tempTime := time.Unix(timestamp, 0)
  1040. timeFormat := tempTime.Format("20060102150405")
  1041. chrgBchno := rand.Intn(100000) + 10000
  1042. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1043. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1044. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1045. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1046. strconv.FormatInt(his.PatientId, 10)
  1047. client := &http.Client{}
  1048. data["psn_no"] = his.PsnNo
  1049. data["mdtrt_id"] = his.Number
  1050. data["chrg_bchno"] = chrg_bchno
  1051. data["org_name"] = miConfig.OrgName
  1052. data["doctor"] = roles.UserName
  1053. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1054. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1055. data["fixmedins_code"] = miConfig.Code
  1056. data["dept_code"] = department.Number
  1057. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1058. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1059. data["secret_key"] = miConfig.SecretKey
  1060. var ids []int64
  1061. for _, item := range prescriptions {
  1062. ids = append(ids, item.ID)
  1063. }
  1064. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1065. if config.IsOpen == 1 { //对接了医保,走医保流程
  1066. bytesData, _ := json.Marshal(data)
  1067. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1068. resp, _ := client.Do(req)
  1069. defer resp.Body.Close()
  1070. body, ioErr := ioutil.ReadAll(resp.Body)
  1071. if ioErr != nil {
  1072. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1074. return
  1075. }
  1076. var respJSON map[string]interface{}
  1077. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1078. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1080. return
  1081. }
  1082. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1083. userJSONBytes, _ := json.Marshal(respJSON)
  1084. var res ResultFour
  1085. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1086. utils.ErrorLog("解析失败:%v", err)
  1087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1088. return
  1089. }
  1090. if res.Infcode == 0 {
  1091. order := &models.HisOrder{
  1092. UserOrgId: adminUser.CurrentOrgId,
  1093. HisPatientId: his.ID,
  1094. PatientId: his.PatientId,
  1095. SettleAccountsDate: recordDateTime,
  1096. Ctime: time.Now().Unix(),
  1097. Mtime: time.Now().Unix(),
  1098. Status: 1,
  1099. Number: chrg_bchno,
  1100. Infcode: res.Infcode,
  1101. WarnMsg: res.WarnMsg,
  1102. Cainfo: res.Cainfo,
  1103. ErrMsg: res.ErrMsg,
  1104. RespondTime: res.RefmsgTime,
  1105. InfRefmsgid: res.InfRefmsgid,
  1106. OrderStatus: 1,
  1107. PayWay: pay_way,
  1108. PayPrice: pay_price,
  1109. PayCardNo: pay_card_no,
  1110. DiscountPrice: discount_price,
  1111. PreferentialPrice: preferential_price,
  1112. RealityPrice: reality_price,
  1113. FoundPrice: found_price,
  1114. MedicalInsurancePrice: medical_insurance_price,
  1115. PrivatePrice: private_price,
  1116. IsMedicineInsurance: 1,
  1117. SettleType: settle_accounts_type,
  1118. SettleStartTime: start_time,
  1119. SettleEndTime: end_time,
  1120. Creator: roles.ID,
  1121. Modify: roles.ID,
  1122. }
  1123. err = service.CreateOrder(order)
  1124. if err != nil {
  1125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1126. return
  1127. }
  1128. for _, item := range res.Output.Result {
  1129. temp := strings.Split(item.FeedetlSn, "-")
  1130. var advice_id int64 = 0
  1131. var project_id int64 = 0
  1132. var types int64 = 0
  1133. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1134. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1135. if temp[1] == "1" {
  1136. advice_id = id
  1137. project_id = 0
  1138. } else if temp[1] == "2" {
  1139. advice_id = 0
  1140. project_id = id
  1141. }
  1142. info := &models.HisOrderInfo{
  1143. OrderNumber: order.Number,
  1144. FeedetlSn: item.FeedetlSn,
  1145. UploadDate: time.Now().Unix(),
  1146. AdviceId: advice_id,
  1147. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1148. Cnt: item.Cnt,
  1149. Pric: float64(item.Pric),
  1150. PatientId: his.PatientId,
  1151. PricUplmtAmt: item.PricUplmtAmt,
  1152. SelfpayProp: item.SelfpayProp,
  1153. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1154. OverlmtAmt: item.OverlmtAmt,
  1155. PreselfpayAmt: item.PreselfpayAmt,
  1156. BasMednFlag: item.BasMednFlag,
  1157. MedChrgitmType: item.MedChrgitmType,
  1158. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1159. Status: 1,
  1160. Memo: item.Memo,
  1161. Mtime: time.Now().Unix(),
  1162. InscpScpAmt: item.InscpScpAmt,
  1163. DrtReimFlag: item.DrtReimFlag,
  1164. Ctime: time.Now().Unix(),
  1165. ListSpItemFlag: item.ListSpItemFlag,
  1166. ChldMedcFlag: item.ChldMedcFlag,
  1167. LmtUsedFlag: item.LmtUsedFlag,
  1168. ChrgitmLv: item.ChrgitmLv,
  1169. UserOrgId: adminUser.CurrentOrgId,
  1170. HisPatientId: his.ID,
  1171. OrderId: order.ID,
  1172. ProjectId: project_id,
  1173. Type: types,
  1174. }
  1175. service.CreateOrderInfo(info)
  1176. }
  1177. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1178. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1179. var total float64
  1180. for _, item := range prescriptions {
  1181. if item.Type == 1 { //药品
  1182. for _, subItem := range item.HisDoctorAdviceInfo {
  1183. total = total + (subItem.Price * subItem.PrescribingNumber)
  1184. }
  1185. }
  1186. if item.Type == 2 { //项目
  1187. for _, subItem := range item.HisPrescriptionProject {
  1188. total = total + (subItem.Price * float64(subItem.Count))
  1189. }
  1190. }
  1191. }
  1192. for _, item := range prescriptions {
  1193. for _, subItem := range item.HisAdditionalCharge {
  1194. total = total + (subItem.Price * float64(subItem.Count))
  1195. }
  1196. }
  1197. allTotal := fmt.Sprintf("%.2f", total)
  1198. if res.Infcode == 0 {
  1199. var rf []*ResultFive
  1200. json.Unmarshal([]byte(his.Iinfo), &rf)
  1201. psn_no := his.PsnNo
  1202. mdtrt_id := his.Number
  1203. chrg_bchno := chrg_bchno
  1204. cert_no := his.Certno
  1205. insutype := rf[0].Insutype
  1206. if his.IdCardType == 1 {
  1207. cert_no = his.MedicalInsuranceNumber
  1208. } else {
  1209. cert_no = his.Certno
  1210. }
  1211. api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" +
  1212. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1213. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  1214. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  1215. resp, requestErr := http.Get(api)
  1216. if requestErr != nil {
  1217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1218. return
  1219. }
  1220. defer resp.Body.Close()
  1221. body, ioErr := ioutil.ReadAll(resp.Body)
  1222. if ioErr != nil {
  1223. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1225. return
  1226. }
  1227. var respJSON map[string]interface{}
  1228. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1229. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1231. return
  1232. }
  1233. fmt.Println(respJSON)
  1234. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1235. userJSONBytes, _ := json.Marshal(respJSON)
  1236. var res ResultSeven
  1237. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1238. utils.ErrorLog("解析失败:%v", err)
  1239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1240. return
  1241. }
  1242. if res.Infcode == -1 {
  1243. errlog := &models.HisOrderError{
  1244. UserOrgId: adminUser.CurrentOrgId,
  1245. Ctime: time.Now().Unix(),
  1246. Mtime: time.Now().Unix(),
  1247. Number: chrg_bchno,
  1248. ErrMsg: res.ErrMsg,
  1249. Status: 1,
  1250. PatientId: id,
  1251. RecordTime: recordDateTime,
  1252. Stage: 6,
  1253. }
  1254. service.CreateErrMsgLog(errlog)
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1256. return
  1257. } else {
  1258. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1259. order.OrderStatus = 1
  1260. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1261. order.SetlId = res.Output.Setlinfo.SetlID
  1262. order.PsnNo = res.Output.Setlinfo.PsnNo
  1263. order.PsnName = res.Output.Setlinfo.PsnName
  1264. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1265. order.Certno = res.Output.Setlinfo.Certno
  1266. order.Gend = res.Output.Setlinfo.Gend
  1267. order.Naty = res.Output.Setlinfo.Naty
  1268. order.Age = res.Output.Setlinfo.Age
  1269. order.Insutype = res.Output.Setlinfo.Insutype
  1270. order.PsnType = res.Output.Setlinfo.PsnType
  1271. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1272. order.SetlTime = res.Output.Setlinfo.SetlTime
  1273. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1274. order.MedType = res.Output.Setlinfo.MedType
  1275. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1276. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1277. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1278. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1279. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1280. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1281. order.HifpPay = res.Output.Setlinfo.HifpPay
  1282. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1283. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1284. order.HifesPay = res.Output.Setlinfo.HifesPay
  1285. order.HifobPay = res.Output.Setlinfo.HifobPay
  1286. order.MafPay = res.Output.Setlinfo.MafPay
  1287. order.OthPay = res.Output.Setlinfo.OthPay
  1288. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1289. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1290. order.AcctPay = res.Output.Setlinfo.AcctPay
  1291. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1292. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1293. order.Balc = res.Output.Setlinfo.Balc
  1294. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1295. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1296. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1297. order.ClrWay = res.Output.Setlinfo.ClrWay
  1298. order.Creator = order.Creator
  1299. order.Modify = roles.ID
  1300. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1301. detailStr := string(setlDetail)
  1302. order.SetlDetail = detailStr
  1303. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1304. err = service.UpDateOrder(order)
  1305. //订单确认
  1306. result := service.Gdyb6201(miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, order)
  1307. var dat map[string]interface{}
  1308. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1309. userJSONBytes, _ := json.Marshal(dat)
  1310. var res ResultTwelve
  1311. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1312. utils.ErrorLog("解析失败:%v", err)
  1313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1314. return
  1315. }
  1316. if res.Infcode == 0 {
  1317. if err == nil {
  1318. c.ServeSuccessJSON(map[string]interface{}{
  1319. "msg": "预结算成功",
  1320. })
  1321. } else {
  1322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  1323. return
  1324. }
  1325. } else {
  1326. adminUser := c.GetAdminUserInfo()
  1327. errlog := &models.HisOrderError{
  1328. UserOrgId: adminUser.CurrentOrgId,
  1329. Ctime: time.Now().Unix(),
  1330. Mtime: time.Now().Unix(),
  1331. ErrMsg: res.ErrMsg,
  1332. Status: 1,
  1333. PatientId: id,
  1334. RecordTime: recordDateTime,
  1335. Stage: 7,
  1336. }
  1337. service.CreateErrMsgLog(errlog)
  1338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1339. }
  1340. } else {
  1341. fmt.Println(err)
  1342. }
  1343. }
  1344. } else {
  1345. adminUser := c.GetAdminUserInfo()
  1346. errlog := &models.HisOrderError{
  1347. UserOrgId: adminUser.CurrentOrgId,
  1348. Ctime: time.Now().Unix(),
  1349. Mtime: time.Now().Unix(),
  1350. ErrMsg: res.ErrMsg,
  1351. Status: 1,
  1352. PatientId: id,
  1353. RecordTime: recordDateTime,
  1354. Stage: 4,
  1355. }
  1356. service.CreateErrMsgLog(errlog)
  1357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1358. return
  1359. }
  1360. } else {
  1361. adminUser := c.GetAdminUserInfo()
  1362. errlog := &models.HisOrderError{
  1363. UserOrgId: adminUser.CurrentOrgId,
  1364. Ctime: time.Now().Unix(),
  1365. Mtime: time.Now().Unix(),
  1366. ErrMsg: res.ErrMsg,
  1367. Status: 1,
  1368. PatientId: id,
  1369. RecordTime: recordDateTime,
  1370. Stage: 4,
  1371. }
  1372. service.CreateErrMsgLog(errlog)
  1373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  1374. return
  1375. }
  1376. }
  1377. }
  1378. func (c *HisApiController) GetSettleInfo() {
  1379. id, _ := c.GetInt64("id")
  1380. record_time := c.GetString("record_time")
  1381. //pay_way, _ := c.GetInt64("pay_way")
  1382. //pay_price, _ := c.GetFloat("pay_price")
  1383. //pay_card_no := c.GetString("pay_card_no")
  1384. //discount_price, _ := c.GetFloat("discount_price")
  1385. //preferential_price, _ := c.GetFloat("preferential_price")
  1386. //reality_price, _ := c.GetFloat("reality_price")
  1387. //found_price, _ := c.GetFloat("found_price")
  1388. //medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1389. //private_price, _ := c.GetFloat("private_price")
  1390. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1391. admin_user_id, _ := c.GetInt64("admin_user_id")
  1392. timeLayout := "2006-01-02"
  1393. loc, _ := time.LoadLocation("Local")
  1394. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1395. if err != nil {
  1396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1397. return
  1398. }
  1399. recordDateTime := theTime.Unix()
  1400. adminUser := c.GetAdminUserInfo()
  1401. var prescriptions []*models.HisPrescription
  1402. //var start_time int64
  1403. //var end_time int64
  1404. data := make(map[string]interface{})
  1405. if settle_accounts_type == 1 { //日结
  1406. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1407. data["pre"] = prescriptions
  1408. } else { //月结
  1409. start_time_str := c.GetString("start_time")
  1410. end_time_str := c.GetString("end_time")
  1411. timeLayout := "2006-01-02"
  1412. loc, _ := time.LoadLocation("Local")
  1413. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1414. if err != nil {
  1415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1416. return
  1417. }
  1418. recordStartTime := theStartTime.Unix()
  1419. //start_time = recordStartTime
  1420. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1421. if err != nil {
  1422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1423. return
  1424. }
  1425. recordEndTime := theEndTime.Unix()
  1426. //end_time = recordEndTime
  1427. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1428. data["pre"] = prescriptions
  1429. }
  1430. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1431. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1432. timestamp := time.Now().Unix()
  1433. tempTime := time.Unix(timestamp, 0)
  1434. timeFormat := tempTime.Format("20060102150405")
  1435. chrgBchno := rand.Intn(100000) + 10000
  1436. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1437. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1438. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1439. strconv.FormatInt(his.PatientId, 10)
  1440. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1441. if config.IsOpen == 1 { //对接了医保,走医保流程
  1442. var total float64
  1443. for _, item := range prescriptions {
  1444. if item.Type == 1 { //药品
  1445. for _, subItem := range item.HisDoctorAdviceInfo {
  1446. total = total + (subItem.Price * subItem.PrescribingNumber)
  1447. }
  1448. }
  1449. if item.Type == 2 { //项目
  1450. for _, subItem := range item.HisPrescriptionProject {
  1451. total = total + (subItem.Price * float64(subItem.Count))
  1452. }
  1453. }
  1454. }
  1455. for _, item := range prescriptions {
  1456. for _, subItem := range item.HisAdditionalCharge {
  1457. total = total + (subItem.Price * float64(subItem.Count))
  1458. }
  1459. }
  1460. allTotal := fmt.Sprintf("%.2f", total)
  1461. var rf []*ResultFive
  1462. json.Unmarshal([]byte(his.Iinfo), &rf)
  1463. psn_no := his.PsnNo
  1464. mdtrt_id := his.Number
  1465. chrg_bchno := chrg_bchno
  1466. cert_no := his.Certno
  1467. insutype := rf[0].Insutype
  1468. if his.IdCardType == 1 {
  1469. cert_no = his.MedicalInsuranceNumber
  1470. } else {
  1471. cert_no = his.Certno
  1472. }
  1473. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1474. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1475. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  1476. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  1477. resp, requestErr := http.Get(api)
  1478. if requestErr != nil {
  1479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1480. return
  1481. }
  1482. defer resp.Body.Close()
  1483. body, ioErr := ioutil.ReadAll(resp.Body)
  1484. if ioErr != nil {
  1485. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1487. return
  1488. }
  1489. var respJSON map[string]interface{}
  1490. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1491. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1493. return
  1494. }
  1495. fmt.Println(respJSON)
  1496. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1497. userJSONBytes, _ := json.Marshal(respJSON)
  1498. var res ResultSeven
  1499. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1500. utils.ErrorLog("解析失败:%v", err)
  1501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1502. return
  1503. }
  1504. if res.Infcode == -1 {
  1505. errlog := &models.HisOrderError{
  1506. UserOrgId: adminUser.CurrentOrgId,
  1507. Ctime: time.Now().Unix(),
  1508. Mtime: time.Now().Unix(),
  1509. Number: chrg_bchno,
  1510. ErrMsg: res.ErrMsg,
  1511. Status: 1,
  1512. PatientId: id,
  1513. RecordTime: recordDateTime,
  1514. Stage: 6,
  1515. }
  1516. service.CreateErrMsgLog(errlog)
  1517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1518. return
  1519. } else {
  1520. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1521. order.OrderStatus = 2
  1522. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1523. order.SetlId = res.Output.Setlinfo.SetlID
  1524. order.PsnNo = res.Output.Setlinfo.PsnNo
  1525. order.PsnName = res.Output.Setlinfo.PsnName
  1526. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1527. order.Certno = res.Output.Setlinfo.Certno
  1528. order.Gend = res.Output.Setlinfo.Gend
  1529. order.Naty = res.Output.Setlinfo.Naty
  1530. order.Age = res.Output.Setlinfo.Age
  1531. order.Insutype = res.Output.Setlinfo.Insutype
  1532. order.PsnType = res.Output.Setlinfo.PsnType
  1533. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1534. order.SetlTime = res.Output.Setlinfo.SetlTime
  1535. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1536. order.MedType = res.Output.Setlinfo.MedType
  1537. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1538. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1539. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1540. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1541. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1542. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1543. order.HifpPay = res.Output.Setlinfo.HifpPay
  1544. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1545. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1546. order.HifesPay = res.Output.Setlinfo.HifesPay
  1547. order.HifobPay = res.Output.Setlinfo.HifobPay
  1548. order.MafPay = res.Output.Setlinfo.MafPay
  1549. order.OthPay = res.Output.Setlinfo.OthPay
  1550. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1551. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1552. order.AcctPay = res.Output.Setlinfo.AcctPay
  1553. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1554. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1555. order.Balc = res.Output.Setlinfo.Balc
  1556. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1557. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1558. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1559. order.ClrWay = res.Output.Setlinfo.ClrWay
  1560. order.Creator = order.Creator
  1561. order.Modify = roles.ID
  1562. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1563. detailStr := string(setlDetail)
  1564. order.SetlDetail = detailStr
  1565. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1566. err = service.UpDateOrder(order)
  1567. if err == nil {
  1568. c.ServeSuccessJSON(map[string]interface{}{
  1569. "msg": "结算成功",
  1570. })
  1571. } else {
  1572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1573. return
  1574. }
  1575. }
  1576. }
  1577. }
  1578. //退款
  1579. func (c *HisApiController) Refund() {
  1580. order_id, _ := c.GetInt64("order_id")
  1581. number := c.GetString("number")
  1582. record_time := c.GetString("record_time")
  1583. patient_id, _ := c.GetInt64("patient_id")
  1584. timeLayout := "2006-01-02"
  1585. loc, _ := time.LoadLocation("Local")
  1586. adminUser := c.GetAdminUserInfo()
  1587. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1588. fmt.Println(err)
  1589. if err != nil {
  1590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1591. return
  1592. }
  1593. recordDateTime := theTime.Unix()
  1594. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1595. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1596. var order models.HisOrder
  1597. order, _ = service.GetHisOrderByID(order_id)
  1598. if order.ID == 0 {
  1599. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  1600. }
  1601. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1602. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1603. if config.IsOpen == 1 { //对接了医保,走医保流程
  1604. api := "http://127.0.0.1:9532/" + "gdyb/nine?psn_no=" + his.PsnNo +
  1605. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&setl_id=" + order.SetlId + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1606. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1607. resp, requestErr := http.Get(api)
  1608. if requestErr != nil {
  1609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1610. return
  1611. }
  1612. body, ioErr := ioutil.ReadAll(resp.Body)
  1613. if ioErr != nil {
  1614. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1616. return
  1617. }
  1618. var respJSON map[string]interface{}
  1619. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1620. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1622. return
  1623. }
  1624. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1625. userJSONBytes, _ := json.Marshal(respJSON)
  1626. fmt.Println(respJSON)
  1627. fmt.Println(userJSONBytes)
  1628. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  1629. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1630. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1631. resp2, requestErr2 := http.Get(api2)
  1632. if requestErr2 != nil {
  1633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1634. return
  1635. }
  1636. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1637. if ioErr2 != nil {
  1638. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1640. return
  1641. }
  1642. var respJSON2 map[string]interface{}
  1643. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1644. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1646. return
  1647. }
  1648. //api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  1649. // "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1650. // "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1651. //resp3, requestErr3 := http.Get(api3)
  1652. //if requestErr3 != nil {
  1653. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1654. // return
  1655. //}
  1656. //
  1657. //body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  1658. //if ioErr3 != nil {
  1659. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  1660. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1661. // return
  1662. //}
  1663. //var respJSON3 map[string]interface{}
  1664. //if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  1665. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1666. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1667. // return
  1668. //}
  1669. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1670. //service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1671. if err == nil {
  1672. c.ServeSuccessJSON(map[string]interface{}{
  1673. "msg": "退费成功",
  1674. })
  1675. } else {
  1676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1677. return
  1678. }
  1679. } else {
  1680. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1681. if err == nil {
  1682. c.ServeSuccessJSON(map[string]interface{}{
  1683. "msg": "退费成功",
  1684. })
  1685. } else {
  1686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1687. return
  1688. }
  1689. }
  1690. }
  1691. func (c *HisApiController) RefundNumber() {
  1692. record_time := c.GetString("record_time")
  1693. patient_id, _ := c.GetInt64("patient_id")
  1694. timeLayout := "2006-01-02"
  1695. loc, _ := time.LoadLocation("Local")
  1696. adminUser := c.GetAdminUserInfo()
  1697. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1698. fmt.Println(err)
  1699. if err != nil {
  1700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1701. return
  1702. }
  1703. recordDateTime := theTime.Unix()
  1704. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1705. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1706. //order, _ := service.GetHisOrderByID(order_id)
  1707. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1708. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1709. if config.IsOpen == 1 { //对接了医保,走医保流程
  1710. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  1711. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1712. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1713. resp3, requestErr3 := http.Get(api3)
  1714. if requestErr3 != nil {
  1715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1716. return
  1717. }
  1718. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  1719. if ioErr3 != nil {
  1720. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  1721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1722. return
  1723. }
  1724. var respJSON3 map[string]interface{}
  1725. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  1726. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1728. return
  1729. }
  1730. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1731. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1732. if err == nil {
  1733. c.ServeSuccessJSON(map[string]interface{}{
  1734. "msg": "退费成功",
  1735. })
  1736. } else {
  1737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1738. return
  1739. }
  1740. } else {
  1741. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1742. //if err == nil {
  1743. // c.ServeSuccessJSON(map[string]interface{}{
  1744. // "msg": "退费成功",
  1745. // })
  1746. //} else {
  1747. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1748. // return
  1749. //}
  1750. }
  1751. }
  1752. func (c *HisApiController) RefundDetail() {
  1753. order_id, _ := c.GetInt64("order_id")
  1754. number := c.GetString("number")
  1755. record_time := c.GetString("record_time")
  1756. patient_id, _ := c.GetInt64("patient_id")
  1757. timeLayout := "2006-01-02"
  1758. loc, _ := time.LoadLocation("Local")
  1759. adminUser := c.GetAdminUserInfo()
  1760. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1761. fmt.Println(err)
  1762. if err != nil {
  1763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1764. return
  1765. }
  1766. recordDateTime := theTime.Unix()
  1767. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1768. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1769. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1770. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1771. var order models.HisOrder
  1772. order, _ = service.GetHisOrderByID(order_id)
  1773. if order.ID == 0 {
  1774. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  1775. }
  1776. if config.IsOpen == 1 { //对接了医保,走医保流程
  1777. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  1778. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1779. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1780. resp2, requestErr2 := http.Get(api2)
  1781. if requestErr2 != nil {
  1782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1783. return
  1784. }
  1785. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1786. if ioErr2 != nil {
  1787. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1789. return
  1790. }
  1791. var respJSON2 map[string]interface{}
  1792. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1793. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1795. return
  1796. }
  1797. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1798. if err == nil {
  1799. c.ServeSuccessJSON(map[string]interface{}{
  1800. "msg": "退费成功",
  1801. })
  1802. } else {
  1803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1804. return
  1805. }
  1806. } else {
  1807. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1808. if err == nil {
  1809. c.ServeSuccessJSON(map[string]interface{}{
  1810. "msg": "退费成功",
  1811. })
  1812. } else {
  1813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1814. return
  1815. }
  1816. }
  1817. }
  1818. //对账
  1819. func (c *HisApiController) GetCheckAccount() {
  1820. start_time := c.GetString("start_time")
  1821. end_time := c.GetString("end_time")
  1822. insutype := c.GetString("insutype")
  1823. clr_type := c.GetString("clr_type")
  1824. admin_user_id, _ := c.GetInt64("admin_user_id")
  1825. adminUser := c.GetAdminUserInfo()
  1826. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1827. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1828. timeLayout := "2006-01-02"
  1829. loc, _ := time.LoadLocation("Local")
  1830. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1831. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1832. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  1833. decimal.DivisionPrecision = 2
  1834. var medfee_sumamt float64
  1835. var acct_pay float64
  1836. var fund_pay_sumamt float64
  1837. fixmedins_setl_cnt := int64(len(orders))
  1838. for _, item := range orders {
  1839. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  1840. acct_pay, _ = decimal.NewFromFloat(acct_pay).Add(decimal.NewFromFloat(item.AcctPay)).Float64()
  1841. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  1842. }
  1843. var user_name string
  1844. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1845. if role.ID == 0 {
  1846. user_name = "xxx"
  1847. } else {
  1848. user_name = role.UserName
  1849. }
  1850. if config.IsOpen == 1 {
  1851. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  1852. "insutype=" + insutype +
  1853. "&clr_type=" + clr_type +
  1854. "&setl_optins=" + miConfig.OrgName +
  1855. "&stmt_begndate=" + start_time +
  1856. "&stm_enddate=" + end_time +
  1857. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  1858. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  1859. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  1860. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  1861. "&fixmedins_code=" + miConfig.Code +
  1862. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  1863. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  1864. "&secret_key=" + miConfig.SecretKey +
  1865. "&org_name=" + miConfig.OrgName +
  1866. "&doctor=" + user_name
  1867. fmt.Println(api)
  1868. resp, requestErr := http.Get(api)
  1869. if requestErr != nil {
  1870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1871. return
  1872. }
  1873. body, ioErr := ioutil.ReadAll(resp.Body)
  1874. fmt.Println(body)
  1875. if ioErr != nil {
  1876. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1878. return
  1879. }
  1880. var respJSON map[string]interface{}
  1881. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1882. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1884. return
  1885. }
  1886. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1887. userJSONBytes, _ := json.Marshal(respJSON)
  1888. var res ResultEight
  1889. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1890. utils.ErrorLog("解析失败:%v", err)
  1891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1892. return
  1893. }
  1894. if res.Infcode == 0 {
  1895. c.ServeSuccessJSON(map[string]interface{}{
  1896. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  1897. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  1898. })
  1899. } else {
  1900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1901. }
  1902. }
  1903. }
  1904. //对账明细
  1905. func (c *HisApiController) GetCheckDetailAccount() {
  1906. start_time := c.GetString("start_time")
  1907. end_time := c.GetString("end_time")
  1908. admin_user_id, _ := c.GetInt64("admin_user_id")
  1909. adminUser := c.GetAdminUserInfo()
  1910. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1911. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1912. timeLayout := "2006-01-02"
  1913. loc, _ := time.LoadLocation("Local")
  1914. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1915. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1916. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  1917. Mkdir(miConfig.OrgName)
  1918. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  1919. file_name := file + ".txt"
  1920. zip_name := file + ".zip"
  1921. zip_path := miConfig.OrgName + "/" + zip_name
  1922. file_path := miConfig.OrgName + "/" + file_name
  1923. decimal.DivisionPrecision = 2
  1924. var medfee_sumamt float64
  1925. var psn_cash_pay float64
  1926. var fund_pay_sumamt float64
  1927. fixmedins_setl_cnt := int64(len(orders))
  1928. for _, item := range orders {
  1929. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  1930. psn_cash_pay, _ = decimal.NewFromFloat(psn_cash_pay).Add(decimal.NewFromFloat(item.PsnCashPay)).Float64()
  1931. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  1932. }
  1933. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  1934. defer f.Close()
  1935. if err != nil {
  1936. fmt.Println(err.Error())
  1937. } else {
  1938. for _, item := range orders {
  1939. var refd_setl_flag string
  1940. if item.OrderStatus == 2 {
  1941. refd_setl_flag = "0"
  1942. }
  1943. if item.OrderStatus == 3 {
  1944. refd_setl_flag = "1"
  1945. }
  1946. var str string
  1947. str = item.SetlId + " " +
  1948. item.MdtrtId + " " +
  1949. item.PsnNo + " " +
  1950. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  1951. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  1952. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n"
  1953. _, err = f.Write([]byte(str))
  1954. }
  1955. }
  1956. Zip(file_path, zip_path)
  1957. fmt.Println(ReadFile(zip_path))
  1958. fmt.Println(string(ReadFile(zip_path)))
  1959. if config.IsOpen == 1 {
  1960. var user_name string
  1961. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1962. if role.ID == 0 {
  1963. user_name = "管理员"
  1964. } else {
  1965. user_name = role.UserName
  1966. }
  1967. baseParams := models.BaseParams{
  1968. SecretKey: miConfig.SecretKey,
  1969. FixmedinsCode: miConfig.Code,
  1970. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1971. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1972. OrgName: miConfig.OrgName,
  1973. Doctor: user_name,
  1974. }
  1975. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  1976. var dat map[string]interface{}
  1977. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1978. fmt.Println(dat)
  1979. } else {
  1980. fmt.Println(err)
  1981. }
  1982. userJSONBytes, _ := json.Marshal(dat)
  1983. var res ResultNine
  1984. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1985. utils.ErrorLog("解析失败:%v", err)
  1986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1987. return
  1988. }
  1989. if res.Infcode == 0 {
  1990. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  1991. "file_qury_no=" + res.Output.FileQuryNo +
  1992. "&setl_optins=" + miConfig.OrgName +
  1993. "&stmt_begndate=" + start_time +
  1994. "&stm_enddate=" + end_time +
  1995. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  1996. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  1997. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  1998. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  1999. "&fixmedins_code=" + miConfig.Code +
  2000. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2001. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2002. "&secret_key=" + miConfig.SecretKey +
  2003. "&org_name=" + miConfig.OrgName +
  2004. "&doctor=" + user_name
  2005. resp, requestErr := http.Get(api)
  2006. if requestErr != nil {
  2007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2008. return
  2009. }
  2010. body, ioErr := ioutil.ReadAll(resp.Body)
  2011. if ioErr != nil {
  2012. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2014. return
  2015. }
  2016. var respJSON map[string]interface{}
  2017. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2018. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2020. return
  2021. }
  2022. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2023. userJSONBytes, _ := json.Marshal(respJSON)
  2024. var res ResultTen
  2025. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2026. utils.ErrorLog("解析失败:%v", err)
  2027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2028. return
  2029. }
  2030. if res.Infcode == 0 {
  2031. service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
  2032. c.ServeSuccessJSON(map[string]interface{}{
  2033. "msg": "明细对账成功",
  2034. })
  2035. }
  2036. } else {
  2037. }
  2038. }
  2039. }
  2040. func (c *HisApiController) GetSettleAccounts() {
  2041. //id, _ := c.GetInt64("id")
  2042. //record_time := c.GetString("record_time")
  2043. order_id, _ := c.GetInt64("order_id")
  2044. admin_user_id, _ := c.GetInt64("admin_user_id")
  2045. //timeLayout := "2006-01-02"
  2046. //loc, _ := time.LoadLocation("Local")
  2047. //
  2048. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2049. //if err != nil {
  2050. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2051. // return
  2052. //}
  2053. //recordDateTime := theTime.Unix()
  2054. adminUser := c.GetAdminUserInfo()
  2055. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2056. order, _ := service.GetHisOrderByID(order_id)
  2057. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  2058. var bedCostTotal float64 = 0 //床位总费
  2059. var bedCostSelfTotal float64 = 0 //床位自费
  2060. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  2061. var operationCostTotal float64 = 0 //手术费
  2062. var operationCostSelfTotal float64 = 0 //手术费
  2063. var operationCostPartSelfTotal float64 = 0 //手术费
  2064. var otherCostTotal float64 = 0 //其他费用
  2065. var otherCostSelfTotal float64 = 0 //其他费用
  2066. var otherCostPartSelfTotal float64 = 0 //其他费用
  2067. var materialCostTotal float64 = 0 //材料费
  2068. var materialCostSelfTotal float64 = 0 //材料费
  2069. var materialCostPartSelfTotal float64 = 0 //材料费
  2070. var westernMedicineCostTotal float64 = 0 //西药费
  2071. var westernMedicineCostSelfTotal float64 = 0 //西药费
  2072. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  2073. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  2074. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  2075. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  2076. var checkCostTotal float64 = 0 //检查费
  2077. var checkCostSelfTotal float64 = 0 //检查费
  2078. var checkCostPartSelfTotal float64 = 0 //检查费
  2079. var laboratoryCostTotal float64 = 0 //化验费
  2080. var laboratoryCostSelfTotal float64 = 0 //化验费
  2081. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  2082. var treatCostTotal float64 = 0 //治疗费用
  2083. var treatCostSelfTotal float64 = 0 //治疗费用
  2084. var treatCostPartSelfTotal float64 = 0 //治疗费用
  2085. decimal.DivisionPrecision = 2
  2086. for _, item := range orderInfos {
  2087. if item.MedChrgitmType == "01" { //床位费
  2088. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2089. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2090. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2091. }
  2092. if item.MedChrgitmType == "03" { //检查费
  2093. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2094. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2095. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2096. }
  2097. if item.MedChrgitmType == "04" { //化验费
  2098. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2099. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2100. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2101. }
  2102. if item.MedChrgitmType == "05" { //治疗费
  2103. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2104. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2105. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2106. }
  2107. if item.MedChrgitmType == "06" { //手术费
  2108. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2109. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2110. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2111. }
  2112. if item.MedChrgitmType == "08" { //材料费
  2113. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2114. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2115. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2116. }
  2117. if item.MedChrgitmType == "09" { //西药费
  2118. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2119. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2120. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2121. }
  2122. if item.MedChrgitmType == "11" { //中成费
  2123. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2124. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2125. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2126. }
  2127. if item.MedChrgitmType == "14" { //其他费
  2128. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2129. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2130. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2131. }
  2132. }
  2133. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2134. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2135. var user_name string
  2136. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2137. if role.ID == 0 {
  2138. user_name = "管理员"
  2139. } else {
  2140. user_name = role.UserName
  2141. }
  2142. baseParams := models.BaseParams{
  2143. SecretKey: miConfig.SecretKey,
  2144. FixmedinsCode: miConfig.Code,
  2145. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2146. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2147. OrgName: miConfig.OrgName,
  2148. Doctor: user_name,
  2149. }
  2150. businessParams := models.BusinessParams{
  2151. PsnNo: order.PsnNo,
  2152. MdtrtId: order.MdtrtId,
  2153. SetlId: order.SetlId,
  2154. }
  2155. if config.IsOpen == 1 {
  2156. result := service.Gdyb5203(baseParams, businessParams)
  2157. var dat map[string]interface{}
  2158. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2159. fmt.Println(dat)
  2160. } else {
  2161. fmt.Println(err)
  2162. }
  2163. userJSONBytes, _ := json.Marshal(dat)
  2164. var res ResultEleven
  2165. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2166. utils.ErrorLog("解析失败:%v", err)
  2167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2168. return
  2169. }
  2170. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2171. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  2172. if res.Infcode == 0 {
  2173. c.ServeSuccessJSON(map[string]interface{}{
  2174. "charge_admin": charge_admin,
  2175. "printor_admin": printor_admin,
  2176. "info": res.Output.Setlinfo,
  2177. "bedCostTotal": bedCostTotal,
  2178. "bedCostSelfTotal": bedCostSelfTotal,
  2179. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  2180. "operationCostTotal": operationCostTotal,
  2181. "operationCostSelfTotal": operationCostSelfTotal,
  2182. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  2183. "otherCostTotal": otherCostTotal,
  2184. "otherCostSelfTotal": otherCostSelfTotal,
  2185. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  2186. "materialCostTotal": materialCostTotal,
  2187. "materialCostSelfTotal": materialCostSelfTotal,
  2188. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  2189. "westernMedicineCostTotal": westernMedicineCostTotal,
  2190. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  2191. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  2192. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  2193. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  2194. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  2195. "checkCostTotal": checkCostTotal,
  2196. "checkCostSelfTotal": checkCostSelfTotal,
  2197. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  2198. "laboratoryCostTotal": laboratoryCostTotal,
  2199. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  2200. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  2201. "treatCostTotal": treatCostTotal,
  2202. "treatCostSelfTotal": treatCostSelfTotal,
  2203. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  2204. })
  2205. }
  2206. }
  2207. }
  2208. func (c *HisApiController) GetCode() {
  2209. name := c.GetString("name")
  2210. codg := c.GetString("codg")
  2211. adminUser := c.GetAdminUserInfo()
  2212. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2213. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2214. var user_name string
  2215. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2216. if role.ID == 0 {
  2217. user_name = "xxx"
  2218. } else {
  2219. user_name = role.UserName
  2220. }
  2221. baseParams := &models.BaseParams{
  2222. SecretKey: miConfig.SecretKey,
  2223. FixmedinsCode: miConfig.Code,
  2224. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2225. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2226. OrgName: miConfig.OrgName,
  2227. Doctor: user_name,
  2228. }
  2229. if config.IsOpen == 1 {
  2230. result := service.Gdyb3301(baseParams, name, codg)
  2231. var dat map[string]interface{}
  2232. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2233. fmt.Println(dat)
  2234. } else {
  2235. fmt.Println(err)
  2236. }
  2237. }
  2238. }
  2239. func (c *HisApiController) CheckTreatment() {
  2240. patient_id, _ := c.GetInt64("patient_id", 0)
  2241. record_time := c.GetString("record_time")
  2242. insutype := c.GetString("insutype")
  2243. timeLayout := "2006-01-02"
  2244. loc, _ := time.LoadLocation("Local")
  2245. adminUser := c.GetAdminUserInfo()
  2246. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2247. fmt.Println(err)
  2248. if err != nil {
  2249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2250. return
  2251. }
  2252. recordDateTime := theTime.Unix()
  2253. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2254. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2255. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2256. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2257. var user_name string
  2258. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2259. if role.ID == 0 {
  2260. user_name = "xxx"
  2261. } else {
  2262. user_name = role.UserName
  2263. }
  2264. baseParams := models.BaseParams{
  2265. SecretKey: miConfig.SecretKey,
  2266. FixmedinsCode: miConfig.Code,
  2267. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2268. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2269. OrgName: miConfig.OrgName,
  2270. Doctor: user_name,
  2271. }
  2272. if config.IsOpen == 1 {
  2273. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  2274. var dat map[string]interface{}
  2275. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2276. fmt.Println(dat)
  2277. } else {
  2278. fmt.Println(err)
  2279. }
  2280. }
  2281. }
  2282. func (c *HisApiController) PutRecord() {
  2283. id, _ := c.GetInt64("id")
  2284. record_time := c.GetString("record_time")
  2285. timeLayout := "2006-01-02"
  2286. loc, _ := time.LoadLocation("Local")
  2287. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2288. if err != nil {
  2289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2290. return
  2291. }
  2292. recordDateTime := theTime.Unix()
  2293. adminInfo := c.GetAdminUserInfo()
  2294. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  2295. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2296. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2297. fmt.Println(miConfig.SecretKey)
  2298. if patient == nil {
  2299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2300. return
  2301. }
  2302. if len(patient.IdCardNo) == 0 {
  2303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  2304. return
  2305. }
  2306. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  2307. if config.IsOpen == 1 {
  2308. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2309. resp, requestErr := http.Get(api)
  2310. if requestErr != nil {
  2311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2312. return
  2313. }
  2314. defer resp.Body.Close()
  2315. body, ioErr := ioutil.ReadAll(resp.Body)
  2316. if ioErr != nil {
  2317. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2319. return
  2320. }
  2321. var respJSON map[string]interface{}
  2322. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2323. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2325. return
  2326. }
  2327. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2328. userJSONBytes, _ := json.Marshal(userJSON)
  2329. var res ResultTwo
  2330. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2331. utils.ErrorLog("解析失败:%v", err)
  2332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2333. return
  2334. }
  2335. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  2336. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  2337. infoStr := string(Iinfos)
  2338. idetinfoStr := string(Idetinfos)
  2339. if res.Infcode == 0 {
  2340. his := models.VMHisPatient{
  2341. Status: 1,
  2342. Ctime: time.Now().Unix(),
  2343. Mtime: time.Now().Unix(),
  2344. PsnNo: res.Output.Baseinfo.PsnNo,
  2345. PsnCertType: res.Output.Baseinfo.PsnCertType,
  2346. Certno: res.Output.Baseinfo.Certno,
  2347. PsnName: res.Output.Baseinfo.PsnName,
  2348. Gend: res.Output.Baseinfo.Gend,
  2349. Naty: res.Output.Baseinfo.Naty,
  2350. Brdy: res.Output.Baseinfo.Brdy,
  2351. Age: res.Output.Baseinfo.Age,
  2352. Iinfo: infoStr,
  2353. Idetinfo: idetinfoStr,
  2354. PatientId: patient.ID,
  2355. RecordDate: theTime.Unix(),
  2356. UserOrgId: adminInfo.CurrentOrgId,
  2357. AdminUserId: adminInfo.AdminUser.Id,
  2358. IsReturn: 1,
  2359. }
  2360. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  2361. result := service.Gdyb2503(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  2362. result2 := service.Gdyb5301(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  2363. var dat map[string]interface{}
  2364. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2365. fmt.Println(dat)
  2366. } else {
  2367. fmt.Println(err)
  2368. }
  2369. var dat2 map[string]interface{}
  2370. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  2371. fmt.Println(dat2)
  2372. } else {
  2373. fmt.Println(err)
  2374. }
  2375. } else {
  2376. adminUser := c.GetAdminUserInfo()
  2377. errlog := &models.HisOrderError{
  2378. UserOrgId: adminUser.CurrentOrgId,
  2379. Ctime: time.Now().Unix(),
  2380. Mtime: time.Now().Unix(),
  2381. ErrMsg: res.ErrMsg,
  2382. Status: 1,
  2383. PatientId: id,
  2384. RecordTime: recordDateTime,
  2385. Stage: 1,
  2386. }
  2387. service.CreateErrMsgLog(errlog)
  2388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  2389. return
  2390. }
  2391. }
  2392. }
  2393. func (c *HisApiController) GetUploadDiag() {
  2394. id, _ := c.GetInt64("id")
  2395. record_time := c.GetString("record_time")
  2396. diagnosis_id, _ := c.GetInt64("diagnosis")
  2397. sick_type, _ := c.GetInt64("sick_type")
  2398. reg_type, _ := c.GetInt64("reg_type")
  2399. timeLayout := "2006-01-02"
  2400. loc, _ := time.LoadLocation("Local")
  2401. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2402. if err != nil {
  2403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2404. return
  2405. }
  2406. var patientPrescription models.HisPrescriptionInfo
  2407. recordDateTime := theTime.Unix()
  2408. adminInfo := c.GetAdminUserInfo()
  2409. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2410. if patientPrescription.ID == 0 {
  2411. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2412. }
  2413. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2414. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  2415. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2416. sickConfig, _ := service.FindSickById(sick_type)
  2417. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2418. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  2419. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  2420. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + strconv.FormatInt(reg_type, 10) + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  2421. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  2422. resp2, requestErr2 := http.Get(api2)
  2423. if requestErr2 != nil {
  2424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2425. return
  2426. }
  2427. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2428. if ioErr2 != nil {
  2429. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2431. return
  2432. }
  2433. var respJSON2 map[string]interface{}
  2434. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2435. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2437. return
  2438. }
  2439. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2440. userJSONBytes2, _ := json.Marshal(respJSON2)
  2441. var res2 ResultSix
  2442. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  2443. utils.ErrorLog("解析失败:%v", err)
  2444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2445. return
  2446. }
  2447. if res2.Infcode == -1 {
  2448. adminUser := c.GetAdminUserInfo()
  2449. errlog := &models.HisOrderError{
  2450. UserOrgId: adminUser.CurrentOrgId,
  2451. Ctime: time.Now().Unix(),
  2452. Mtime: time.Now().Unix(),
  2453. ErrMsg: res2.ErrMsg,
  2454. Status: 1,
  2455. PatientId: id,
  2456. RecordTime: recordDateTime,
  2457. Stage: 3,
  2458. }
  2459. service.CreateErrMsgLog(errlog)
  2460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  2461. return
  2462. }
  2463. c.ServeSuccessJSON(map[string]interface{}{
  2464. "msg": "上传成功",
  2465. })
  2466. }
  2467. func PathExists(path string) (bool, error) {
  2468. _, err := os.Stat(path)
  2469. if err == nil {
  2470. return true, nil
  2471. }
  2472. if os.IsNotExist(err) {
  2473. return false, nil
  2474. }
  2475. return false, err
  2476. }
  2477. //创建文件夹
  2478. func Mkdir(dir string) {
  2479. // 创建文件夹
  2480. exist, err := PathExists(dir)
  2481. if err != nil {
  2482. fmt.Println(err.Error())
  2483. } else {
  2484. if exist {
  2485. fmt.Println(dir + "文件夹已存在!")
  2486. } else {
  2487. // 文件夹名称,权限
  2488. err := os.Mkdir(dir, os.ModePerm)
  2489. if err != nil {
  2490. fmt.Println(dir+"文件夹创建失败:", err.Error())
  2491. } else {
  2492. fmt.Println(dir + "文件夹创建成功!")
  2493. }
  2494. }
  2495. }
  2496. }
  2497. //压缩文件
  2498. func Zip(srcFile string, destZip string) error {
  2499. zipfile, err := os.Create(destZip)
  2500. if err != nil {
  2501. return err
  2502. }
  2503. defer zipfile.Close()
  2504. archive := zip.NewWriter(zipfile)
  2505. defer archive.Close()
  2506. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  2507. if err != nil {
  2508. return err
  2509. }
  2510. header, err := zip.FileInfoHeader(info)
  2511. if err != nil {
  2512. return err
  2513. }
  2514. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  2515. // header.Name = path
  2516. if info.IsDir() {
  2517. header.Name += "/"
  2518. } else {
  2519. header.Method = zip.Deflate
  2520. }
  2521. writer, err := archive.CreateHeader(header)
  2522. if err != nil {
  2523. return err
  2524. }
  2525. if !info.IsDir() {
  2526. file, err := os.Open(path)
  2527. if err != nil {
  2528. return err
  2529. }
  2530. defer file.Close()
  2531. _, err = io.Copy(writer, file)
  2532. }
  2533. return err
  2534. })
  2535. return err
  2536. }
  2537. func ReadFile(filePath string) []byte {
  2538. f, err := os.Open(filePath)
  2539. if err != nil {
  2540. fmt.Println("read file fail", err)
  2541. return nil
  2542. }
  2543. defer f.Close()
  2544. fd, err := ioutil.ReadAll(f)
  2545. if err != nil {
  2546. fmt.Println("read to fd fail", err)
  2547. return nil
  2548. }
  2549. return fd
  2550. }
  2551. func RemoveRepeatedCode(arr []string) (newArr []string) {
  2552. newArr = make([]string, 0)
  2553. for i := 0; i < len(arr); i++ {
  2554. repeat := false
  2555. for j := i + 1; j < len(arr); j++ {
  2556. if arr[i] == arr[j] {
  2557. repeat = true
  2558. break
  2559. }
  2560. }
  2561. if !repeat {
  2562. newArr = append(newArr, arr[i])
  2563. }
  2564. }
  2565. return
  2566. }
  2567. //func ShowMessage1(caption, text string, style uintptr) (result int) {
  2568. // user32, _ := syscall.LoadLibrary("SSCard.dll")
  2569. // messageBox, _ := syscall.GetProcAddress(user32, "MessageBoxW")
  2570. // defer syscall.FreeLibrary(user32)
  2571. //
  2572. // ret, _, _ := syscall.Syscall9(messageBox,
  2573. // 4,
  2574. // 0,
  2575. // StrPtr(text),
  2576. // StrPtr(caption),
  2577. // style,
  2578. // 0, 0, 0, 0, 0)
  2579. // result = int(ret)
  2580. // return
  2581. //}
  2582. func StrPtr3(s string) uintptr {
  2583. return uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(s)))
  2584. }