his_api_controller.go 101KB

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