his_api_controller.go 101KB

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