his_api_controller.go 101KB

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