sz_his_api_controller.go 43KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  1. package sz
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "gdyb/controllers"
  6. "gdyb/enums"
  7. "gdyb/models"
  8. "gdyb/service"
  9. "gdyb/utils"
  10. "github.com/astaxie/beego"
  11. "math"
  12. "math/rand"
  13. "strconv"
  14. "strings"
  15. "syscall"
  16. "time"
  17. "unsafe"
  18. )
  19. type Result struct {
  20. Transtime string `json:"transTime"`
  21. Transtype string `json:"transType"`
  22. Transreturncode string `json:"transReturnCode"`
  23. Transreturnmessage string `json:"transReturnMessage"`
  24. Transversion string `json:"transVersion"`
  25. Serialnumber string `json:"serialNumber"`
  26. Cardarea string `json:"cardArea"`
  27. Hospitalcode string `json:"hospitalCode"`
  28. Operatorcode string `json:"operatorCode"`
  29. Operatorname string `json:"operatorName"`
  30. Operatorpass string `json:"operatorPass"`
  31. Transbody struct {
  32. Akc190 string `json:"akc190"`
  33. Listsize int `json:"listsize"`
  34. Outputlist []struct {
  35. Aae072 string `json:"aae072"`
  36. Bkc369 string `json:"bkc369"`
  37. Bkf500 string `json:"bkf500"`
  38. Aka111 string `json:"aka111"`
  39. Ake001 string `json:"ake001"`
  40. Ake002 string `json:"ake002"`
  41. Bkm017 string `json:"bkm017"`
  42. Ake005 string `json:"ake005"`
  43. Ake006 string `json:"ake006"`
  44. Akc225 float64 `json:"akc225"`
  45. Akc226 float64 `json:"akc226"`
  46. Akc264 float64 `json:"akc264"`
  47. Aka065 string `json:"aka065"`
  48. Cka319 float64 `json:"cka319"`
  49. Akc268 float64 `json:"akc268"`
  50. } `json:"outputlist"`
  51. } `json:"transBody"`
  52. Verifycode string `json:"verifyCode"`
  53. Extenddeviceid string `json:"extendDeviceId"`
  54. Transchannel string `json:"transChannel"`
  55. Extenduserid string `json:"extendUserId"`
  56. Extendserialnumber string `json:"extendSerialNumber"`
  57. Caz055 string `json:"caz055"`
  58. Aae501 string `json:"aae501"`
  59. }
  60. type ResultTwo struct {
  61. Transtime string `json:"transTime"`
  62. Transtype string `json:"transType"`
  63. Transreturncode string `json:"transReturnCode"`
  64. Transreturnmessage string `json:"transReturnMessage"`
  65. Transversion string `json:"transVersion"`
  66. Serialnumber string `json:"serialNumber"`
  67. Cardarea string `json:"cardArea"`
  68. Hospitalcode string `json:"hospitalCode"`
  69. Operatorcode string `json:"operatorCode"`
  70. Operatorname string `json:"operatorName"`
  71. Operatorpass string `json:"operatorPass"`
  72. Transbody struct {
  73. Ckc618 string `json:"ckc618"`
  74. Akc264 float64 `json:"akc264"`
  75. Akb068 float64 `json:"akb068"`
  76. Akb066 float64 `json:"akb066"`
  77. Akb067 float64 `json:"akb067"`
  78. Aae240 float64 `json:"aae240"`
  79. Outputlist1 []struct {
  80. Aka111 string `json:"aka111"`
  81. Bka058 int `json:"bka058"`
  82. } `json:"outputlist1"`
  83. Outputlist2 []struct {
  84. Aaa036 string `json:"aaa036"`
  85. Aae019 int `json:"aae019"`
  86. } `json:"outputlist2"`
  87. Outputlist3 []interface{} `json:"outputlist3"`
  88. } `json:"transBody"`
  89. Verifycode string `json:"verifyCode"`
  90. Extenddeviceid string `json:"extendDeviceId"`
  91. Transchannel string `json:"transChannel"`
  92. Extenduserid string `json:"extendUserId"`
  93. Extendserialnumber string `json:"extendSerialNumber"`
  94. Caz055 string `json:"caz055"`
  95. Aae501 string `json:"aae501"`
  96. }
  97. type ResultThree struct {
  98. Transtime string `json:"transTime"`
  99. Transtype string `json:"transType"`
  100. Transreturncode string `json:"transReturnCode"`
  101. Transreturnmessage string `json:"transReturnMessage"`
  102. Transversion string `json:"transVersion"`
  103. Serialnumber string `json:"serialNumber"`
  104. Cardarea string `json:"cardArea"`
  105. Hospitalcode string `json:"hospitalCode"`
  106. Operatorcode string `json:"operatorCode"`
  107. Operatorname string `json:"operatorName"`
  108. Operatorpass string `json:"operatorPass"`
  109. Transbody struct {
  110. Baz700 string `json:"baz700"`
  111. Ckc618 string `json:"ckc618"`
  112. } `json:"transBody"`
  113. Verifycode string `json:"verifyCode"`
  114. Extenddeviceid string `json:"extendDeviceId"`
  115. Transchannel string `json:"transChannel"`
  116. Extenduserid string `json:"extendUserId"`
  117. Extendserialnumber string `json:"extendSerialNumber"`
  118. Caz055 string `json:"caz055"`
  119. Aae501 string `json:"aae501"`
  120. }
  121. type ResultFour struct {
  122. Transtime string `json:"transTime"`
  123. Transtype string `json:"transType"`
  124. Transreturncode string `json:"transReturnCode"`
  125. Transreturnmessage string `json:"transReturnMessage"`
  126. Transversion string `json:"transVersion"`
  127. Serialnumber string `json:"serialNumber"`
  128. Cardarea string `json:"cardArea"`
  129. Hospitalcode string `json:"hospitalCode"`
  130. Operatorcode string `json:"operatorCode"`
  131. Operatorname string `json:"operatorName"`
  132. Operatorpass string `json:"operatorPass"`
  133. Transbody struct {
  134. Akc190 string `json:"akc190"`
  135. Akc194 int `json:"akc194"`
  136. Bae917 int64 `json:"bae917"`
  137. Aka018 string `json:"aka018"`
  138. Aka030 string `json:"aka030"`
  139. Ckc618 string `json:"ckc618"`
  140. Akc264 int `json:"akc264"`
  141. Akb068 int `json:"akb068"`
  142. Akb066 int `json:"akb066"`
  143. Akb067 int `json:"akb067"`
  144. Cke298 float64 `json:"cke298"`
  145. Aae240 float64 `json:"aae240"`
  146. Outputlist2 []struct {
  147. Aka111 string `json:"aka111"`
  148. Bka058 int `json:"bka058"`
  149. } `json:"outputlist2"`
  150. Outputlist3 []struct {
  151. Aaa036 string `json:"aaa036"`
  152. Aae019 int `json:"aae019"`
  153. } `json:"outputlist3"`
  154. } `json:"transBody"`
  155. Verifycode string `json:"verifyCode"`
  156. Extenddeviceid string `json:"extendDeviceId"`
  157. Transchannel string `json:"transChannel"`
  158. Extenduserid string `json:"extendUserId"`
  159. Extendserialnumber string `json:"extendSerialNumber"`
  160. Caz055 string `json:"caz055"`
  161. Aae501 string `json:"aae501"`
  162. }
  163. type SZHisApiController struct {
  164. controllers.BaseAuthAPIController
  165. }
  166. func SZHisManagerApiRegistRouters() {
  167. //挂号
  168. beego.Router("/sz/api/register/get", &SZHisApiController{}, "get:GetRegisterInfo")
  169. //上传明细,预结算
  170. beego.Router("/sz/api/upload/get", &SZHisApiController{}, "get:GetUploadInfo")
  171. //结算
  172. beego.Router("/sz/api/settle/get", &SZHisApiController{}, "get:GetSettleInfo")
  173. //退费
  174. beego.Router("/sz/api/refund/get", &SZHisApiController{}, "get:Refund")
  175. beego.Router("/sz/api/monthrefund/get", &SZHisApiController{}, "get:MonthRefund")
  176. //查询交易
  177. beego.Router("/sz/api/settle/query", &SZHisApiController{}, "get:GetSettleAccounts")
  178. }
  179. func IntPtr(n int) uintptr {
  180. return uintptr(n)
  181. }
  182. func StrPtr(s string) uintptr {
  183. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  184. }
  185. type Custom struct {
  186. DetItemFeeSumamt string
  187. Cut string
  188. FeedetlSn string
  189. Price string
  190. MedListCodg string
  191. Type int64
  192. AdviceId int64
  193. ProjectId int64
  194. ItemId int64
  195. }
  196. //获取读卡信息 -- 门诊挂号
  197. func (c *SZHisApiController) GetRegisterInfo() {
  198. adminInfo := c.GetAdminUserInfo()
  199. admin_user_id, _ := c.GetInt64("admin_user_id")
  200. patient_id, _ := c.GetInt64("id")
  201. record_time := c.GetString("record_time")
  202. settlementValue, _ := c.GetInt64("settlement_value")
  203. medical_insurance_card := c.GetString("medical_insurance_card")
  204. name := c.GetString("name")
  205. id_card_type, _ := c.GetInt64("id_card_type")
  206. certificates, _ := c.GetInt64("certificates")
  207. medical_care, _ := c.GetInt64("medical_care")
  208. birthday := c.GetString("birthday")
  209. id_card := c.GetString("id_card")
  210. register_type, _ := c.GetInt64("register")
  211. doctor, _ := c.GetInt64("doctor")
  212. department, _ := c.GetInt64("department")
  213. gender, _ := c.GetInt64("sex")
  214. registration_fee, _ := c.GetFloat("registration_fee")
  215. medical_expenses, _ := c.GetFloat("medical_expenses")
  216. social_type, _ := c.GetInt64("social_type")
  217. is_yidi, _ := c.GetInt64("is_yidi")
  218. timeLayout := "2006-01-02"
  219. loc, _ := time.LoadLocation("Local")
  220. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  221. birthUnix := birthdays.Unix()
  222. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  223. if err != nil {
  224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  225. return
  226. }
  227. var patient service.Patients
  228. if patient_id == 0 {
  229. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  230. } else {
  231. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  232. }
  233. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  234. if patient.ID == 0 {
  235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  236. return
  237. }
  238. if len(patient.IdCardNo) == 0 {
  239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  240. return
  241. }
  242. adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  243. var doctor_name string
  244. var doctor_code string
  245. if adminRole.ID == 0 {
  246. doctor_name = "黄亦轩"
  247. doctor_code = "1001"
  248. } else {
  249. doctor_name = adminRole.UserName
  250. doctor_code = strconv.FormatInt(admin_user_id, 10)
  251. }
  252. month := time.Unix(1557042972, 0).Format("1")
  253. year := time.Now().Format("2006")
  254. month = time.Now().Format("01")
  255. day := time.Now().Format("02")
  256. //流水号
  257. //
  258. //number := miConfig.Code + year + month + day +
  259. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  260. number := miConfig.Code + year + month + day + "1122334"
  261. //number := miConfig.Code +year + month + day + strconv.FormatInt(patient_id, 10)
  262. other_number := year + month + day + strconv.FormatInt(patient_id, 10)
  263. //verifyCode := ReadCardGetCode(number)
  264. //1.判断读卡类型
  265. //2.读卡 获取交易验证码,医疗证号,发卡地区行政区划代码
  266. //yiliao_number, id_card_number, err, ret4 := ReadBasCardGetNumber(number)
  267. verifyCode := "000000|8eddd7f22d32b866ac01fd75499c2991"
  268. yiliao_number := "%GAAFSAKSXSUKKWDKHDAD?;07734724145330238292?"
  269. id_card_number := "142729195704031523"
  270. ret4 := 0
  271. is_yidi = 1
  272. if err != nil {
  273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  274. return
  275. }
  276. if ret4 == 0 { //本地卡流程
  277. if is_yidi == 1 { //本地就医流程
  278. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  279. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  280. if tempPatient.ID == patient_id {
  281. //挂号
  282. resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, other_number)
  283. his := models.VMHisPatient{
  284. Name: name,
  285. Gender: gender,
  286. Birthday: birthUnix,
  287. MedicalTreatmentType: medical_care,
  288. IdType: certificates,
  289. IdCardNo: id_card,
  290. BalanceAccountsType: settlementValue,
  291. SocialType: social_type,
  292. MedicalInsuranceNumber: medical_insurance_card,
  293. RegisterType: register_type,
  294. RegisterCost: registration_fee,
  295. TreatmentCost: medical_expenses,
  296. Status: 1,
  297. Ctime: time.Now().Unix(),
  298. Mtime: time.Now().Unix(),
  299. Iinfo: resp_result,
  300. PatientId: patient.ID,
  301. RecordDate: theTime.Unix(),
  302. UserOrgId: adminInfo.CurrentOrgId,
  303. AdminUserId: admin_user_id,
  304. IsReturn: 1,
  305. IdCardType: id_card_type,
  306. Doctor: doctor,
  307. Departments: department,
  308. YiliaoNumber: yiliao_number,
  309. MzNumber: number,
  310. }
  311. service.CreateHisPatientTwo(&his)
  312. } else {
  313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  314. return
  315. }
  316. } else { //异地就医流程
  317. //异地走鉴权流程
  318. //authResult := CardAuth(number)
  319. //fmt.Println(authResult)
  320. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  321. if tempPatient.ID == patient_id {
  322. resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, other_number)
  323. his := models.VMHisPatient{
  324. Name: name,
  325. Gender: gender,
  326. Birthday: birthUnix,
  327. MedicalTreatmentType: medical_care,
  328. IdType: certificates,
  329. IdCardNo: id_card,
  330. BalanceAccountsType: settlementValue,
  331. SocialType: social_type,
  332. MedicalInsuranceNumber: medical_insurance_card,
  333. RegisterType: register_type,
  334. RegisterCost: registration_fee,
  335. TreatmentCost: medical_expenses,
  336. Status: 1,
  337. Ctime: time.Now().Unix(),
  338. Mtime: time.Now().Unix(),
  339. Iinfo: resp_result,
  340. PatientId: patient.ID,
  341. RecordDate: theTime.Unix(),
  342. UserOrgId: adminInfo.CurrentOrgId,
  343. AdminUserId: admin_user_id,
  344. IsReturn: 1,
  345. IdCardType: id_card_type,
  346. Doctor: doctor,
  347. Departments: department,
  348. }
  349. service.CreateHisPatientTwo(&his)
  350. }
  351. }
  352. } else if ret4 == -24 || ret4 == -2201 || ret4 == -2203 || ret4 == -27272 { //异地卡流程
  353. //readCardBasResult := ReadCardBasHSM(number)
  354. //fmt.Println(readCardBasResult)
  355. //是否异地就医,是的话走鉴权流程,不是的话走门诊挂号
  356. if is_yidi == 1 { //1本地就医
  357. resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, other_number)
  358. his := models.VMHisPatient{
  359. Name: name,
  360. Gender: gender,
  361. Birthday: birthUnix,
  362. MedicalTreatmentType: medical_care,
  363. IdType: certificates,
  364. IdCardNo: id_card,
  365. BalanceAccountsType: settlementValue,
  366. SocialType: social_type,
  367. MedicalInsuranceNumber: medical_insurance_card,
  368. RegisterType: register_type,
  369. RegisterCost: registration_fee,
  370. TreatmentCost: medical_expenses,
  371. Status: 1,
  372. Ctime: time.Now().Unix(),
  373. Mtime: time.Now().Unix(),
  374. Iinfo: resp_result,
  375. PatientId: patient.ID,
  376. RecordDate: theTime.Unix(),
  377. UserOrgId: adminInfo.CurrentOrgId,
  378. AdminUserId: admin_user_id,
  379. IsReturn: 1,
  380. IdCardType: id_card_type,
  381. Doctor: doctor,
  382. Departments: department,
  383. }
  384. service.CreateHisPatientTwo(&his)
  385. } else { //异地就医需要走鉴权流程
  386. //authResult := CardAuth(number)
  387. //fmt.Println(authResult)
  388. resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, other_number)
  389. his := models.VMHisPatient{
  390. Name: name,
  391. Gender: gender,
  392. Birthday: birthUnix,
  393. MedicalTreatmentType: medical_care,
  394. IdType: certificates,
  395. IdCardNo: id_card,
  396. BalanceAccountsType: settlementValue,
  397. SocialType: social_type,
  398. MedicalInsuranceNumber: medical_insurance_card,
  399. RegisterType: register_type,
  400. RegisterCost: registration_fee,
  401. TreatmentCost: medical_expenses,
  402. Status: 1,
  403. Ctime: time.Now().Unix(),
  404. Mtime: time.Now().Unix(),
  405. Iinfo: resp_result,
  406. PatientId: patient.ID,
  407. RecordDate: theTime.Unix(),
  408. UserOrgId: adminInfo.CurrentOrgId,
  409. AdminUserId: admin_user_id,
  410. IsReturn: 1,
  411. IdCardType: id_card_type,
  412. Doctor: doctor,
  413. Departments: department,
  414. }
  415. service.CreateHisPatientTwo(&his)
  416. }
  417. }
  418. }
  419. //上传明细----预结算----确认订单
  420. func (c *SZHisApiController) GetUploadInfo() {
  421. patient_id, _ := c.GetInt64("id")
  422. record_time := c.GetString("record_time")
  423. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  424. admin_user_id, _ := c.GetInt64("admin_user_id")
  425. timestamp := time.Now().Unix()
  426. tempTime := time.Unix(timestamp, 0)
  427. timeFormat := tempTime.Format("20060102150405")
  428. chrgBchno := rand.Intn(10000) + 1000
  429. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  430. //miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  431. month := time.Unix(1557042972, 0).Format("1")
  432. year := time.Now().Format("2006")
  433. month = time.Now().Format("01")
  434. day := time.Now().Format("02")
  435. timeLayout := "2006-01-02"
  436. loc, _ := time.LoadLocation("Local")
  437. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  438. if err != nil {
  439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  440. return
  441. }
  442. recordDateTime := theTime.Unix()
  443. adminUser := c.GetAdminUserInfo()
  444. var prescriptions []*models.HisPrescription
  445. var start_time int64
  446. var end_time int64
  447. if settle_accounts_type == 1 { //日结
  448. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  449. } else { //月结
  450. start_time_str := c.GetString("start_time")
  451. end_time_str := c.GetString("end_time")
  452. timeLayout := "2006-01-02"
  453. loc, _ := time.LoadLocation("Local")
  454. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  455. if err != nil {
  456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  457. return
  458. }
  459. recordStartTime := theStartTime.Unix()
  460. start_time = recordStartTime
  461. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  462. if err != nil {
  463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  464. return
  465. }
  466. recordEndTime := theEndTime.Unix()
  467. end_time = recordEndTime
  468. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  469. }
  470. var ids []int64
  471. for _, item := range prescriptions {
  472. ids = append(ids, item.ID)
  473. }
  474. adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  475. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  476. number := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  477. var doctor_name string
  478. var doctor_code string
  479. if adminRole.ID == 0 {
  480. doctor_name = "黄亦轩"
  481. doctor_code = "1001"
  482. } else {
  483. doctor_name = adminRole.UserName
  484. doctor_code = strconv.FormatInt(admin_user_id, 10)
  485. }
  486. //verifyCode := ReadCardGetCode("FY001" + "|" + number + "|" + miConfig.Code)
  487. verifyCode := "000000|5d8f3a9447aa0fe836513f5686f2649e"
  488. var customs []*models.CustomDetail
  489. for _, item := range prescriptions {
  490. if item.Type == 1 { //药品
  491. for _, subItem := range item.HisDoctorAdviceInfo {
  492. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 {
  493. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber), 64)
  494. price, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price), 64)
  495. cus := &models.CustomDetail{
  496. PrescriptionNumber: chrg_bchno,
  497. OrderType: "1",
  498. ChargeSerialNumber: subItem.FeedetlSn,
  499. Code: subItem.BaseDrugLib.MedicalInsuranceNumber,
  500. CodeName: subItem.BaseDrugLib.DrugName,
  501. Flag: "1",
  502. Price: price,
  503. Count: subItem.PrescribingNumber,
  504. ChargeOrderDate: year + month + day,
  505. DoctorCode: doctor_code,
  506. Total: detItemFeeSumamt,
  507. DoseCode: "",
  508. Spec: strconv.FormatFloat(subItem.DrugSpec, 'E', -1, 64) + subItem.DrugSpecUnit,
  509. }
  510. customs = append(customs, cus)
  511. }
  512. }
  513. }
  514. if item.Type == 2 { //项目
  515. for _, subItem := range item.HisPrescriptionProject {
  516. if len(subItem.HisProject.MedicalCode) > 0 {
  517. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  518. count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  519. cus := &models.CustomDetail{
  520. PrescriptionNumber: chrg_bchno,
  521. OrderType: "1",
  522. ChargeSerialNumber: subItem.FeedetlSn,
  523. Code: subItem.HisProject.MedicalCode,
  524. CodeName: subItem.HisProject.ProjectName,
  525. Flag: "1",
  526. Price: subItem.Price,
  527. Count: count,
  528. ChargeOrderDate: year + month + day,
  529. DoctorCode: doctor_code,
  530. Total: detItemFeeSumamt,
  531. DoseCode: "",
  532. Spec: "",
  533. }
  534. customs = append(customs, cus)
  535. }
  536. }
  537. }
  538. for _, subItem := range item.HisAdditionalCharge {
  539. if len(subItem.XtHisAddtionConfig.Code) > 0 {
  540. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  541. count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  542. cus := &models.CustomDetail{
  543. PrescriptionNumber: chrg_bchno,
  544. OrderType: "1",
  545. ChargeSerialNumber: subItem.FeedetlSn,
  546. Code: subItem.XtHisAddtionConfig.Code,
  547. CodeName: subItem.XtHisAddtionConfig.Name,
  548. Flag: "1",
  549. Price: subItem.Price,
  550. Count: count,
  551. ChargeOrderDate: year + month + day,
  552. DoctorCode: doctor_code,
  553. Total: detItemFeeSumamt,
  554. DoseCode: "",
  555. Spec: "",
  556. }
  557. customs = append(customs, cus)
  558. }
  559. }
  560. }
  561. var pagesize int = 50
  562. var start int = 1
  563. var stop int
  564. var pagecount int
  565. var curpage int
  566. var isSuccess bool = true
  567. //总页数,向上取整,注意除之前要先转换类型为float64
  568. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  569. var ress []*Result
  570. for curpage = 1; curpage <= pagecount; curpage++ {
  571. if curpage == 1 {
  572. start = 1
  573. } else {
  574. start = (curpage-1)*pagesize + 1
  575. }
  576. stop = curpage * pagesize
  577. if stop > len(customs) {
  578. stop = len(customs)
  579. }
  580. result := service.SzybFY001(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, number)
  581. fmt.Println(result)
  582. var dat map[string]interface{}
  583. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  584. fmt.Println(dat)
  585. } else {
  586. fmt.Println(err)
  587. }
  588. userJSONBytes, _ := json.Marshal(dat)
  589. var res Result
  590. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  591. utils.ErrorLog("解析失败:%v", err)
  592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  593. return
  594. }
  595. if res.Transreturncode == "00000000" {
  596. ress = append(ress, &res)
  597. } else {
  598. isSuccess = false
  599. //预结算报错
  600. errlog := &models.HisOrderError{
  601. UserOrgId: adminUser.CurrentOrgId,
  602. Ctime: time.Now().Unix(),
  603. Mtime: time.Now().Unix(),
  604. Number: chrg_bchno,
  605. ErrMsg: res.Transreturnmessage,
  606. Status: 1,
  607. PatientId: patient_id,
  608. RecordTime: recordDateTime,
  609. Stage: 10,
  610. }
  611. service.CreateErrMsgLog(errlog)
  612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  613. return
  614. }
  615. //设置变量,根据变量的值来判断上传是否成功
  616. }
  617. if isSuccess == true {
  618. order := &models.HisOrder{
  619. UserOrgId: adminUser.CurrentOrgId,
  620. HisPatientId: 0,
  621. PatientId: patient_id,
  622. SettleAccountsDate: recordDateTime,
  623. Ctime: time.Now().Unix(),
  624. Mtime: time.Now().Unix(),
  625. Status: 1,
  626. Number: chrg_bchno,
  627. Infcode: 0,
  628. WarnMsg: "",
  629. Cainfo: "",
  630. ErrMsg: "",
  631. RespondTime: "",
  632. InfRefmsgid: "",
  633. OrderStatus: 1,
  634. IsMedicineInsurance: 1,
  635. SettleType: settle_accounts_type,
  636. SettleStartTime: start_time,
  637. SettleEndTime: end_time,
  638. Creator: admin_user_id,
  639. Modify: admin_user_id,
  640. }
  641. err = service.CreateOrder(order)
  642. if err != nil {
  643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  644. return
  645. }
  646. for _, subItem := range ress {
  647. for _, item := range subItem.Transbody.Outputlist {
  648. temp := strings.Split(item.Aae072, "-")
  649. var advice_id int64 = 0
  650. var project_id int64 = 0
  651. var types int64 = 0
  652. id, _ := strconv.ParseInt(temp[2], 10, 64)
  653. types, _ = strconv.ParseInt(temp[1], 10, 64)
  654. if temp[1] == "1" {
  655. advice_id = id
  656. project_id = 0
  657. } else if temp[1] == "2" {
  658. advice_id = 0
  659. project_id = id
  660. }
  661. info := &models.HisOrderInfo{
  662. OrderNumber: order.Number,
  663. FeedetlSn: item.Aae072,
  664. UploadDate: time.Now().Unix(),
  665. AdviceId: advice_id,
  666. DetItemFeeSumamt: item.Akc264,
  667. Cnt: item.Akc226,
  668. Pric: float64(item.Akc225),
  669. PatientId: patient_id,
  670. Status: 1,
  671. ChrgitmLv: item.Aka065,
  672. Mtime: time.Now().Unix(),
  673. Ctime: time.Now().Unix(),
  674. UserOrgId: adminUser.CurrentOrgId,
  675. OrderId: order.ID,
  676. ProjectId: project_id,
  677. Type: types,
  678. OverPricPsnPay: item.Akc268,
  679. AllowReimburse: item.Cka319,
  680. }
  681. service.CreateOrderInfo(info)
  682. }
  683. }
  684. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  685. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patient_id, chrg_bchno, recordDateTime)
  686. var total float64
  687. for _, item := range prescriptions {
  688. if item.Type == 1 { //药品
  689. for _, subItem := range item.HisDoctorAdviceInfo {
  690. total = total + (subItem.Price * subItem.PrescribingNumber)
  691. }
  692. }
  693. if item.Type == 2 { //项目
  694. for _, subItem := range item.HisPrescriptionProject {
  695. total = total + (subItem.Price * float64(subItem.Count))
  696. }
  697. }
  698. }
  699. for _, item := range prescriptions {
  700. for _, subItem := range item.HisAdditionalCharge {
  701. total = total + (subItem.Price * float64(subItem.Count))
  702. }
  703. }
  704. //verifyCode := ReadCardGetCode("FY004" + "|" + number + "|" + miConfig.Code)
  705. result_two := service.SzybFY004(doctor_name, doctor_code, miConfig.Code, total, verifyCode, number)
  706. var dat map[string]interface{}
  707. if err := json.Unmarshal([]byte(result_two), &dat); err == nil {
  708. fmt.Println(dat)
  709. } else {
  710. fmt.Println(err)
  711. }
  712. userJSONBytes, _ := json.Marshal(dat)
  713. var res ResultTwo
  714. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  715. utils.ErrorLog("解析失败:%v", err)
  716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  717. return
  718. }
  719. if res.Transreturncode == "00000000" {
  720. c.ServeSuccessJSON(map[string]interface{}{
  721. "msg": "预结算成功",
  722. })
  723. } else {
  724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  725. return
  726. }
  727. } else {
  728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  729. return
  730. }
  731. }
  732. //结算
  733. func (c *SZHisApiController) GetSettleInfo() {
  734. patient_id, _ := c.GetInt64("id")
  735. order_id, _ := c.GetInt64("order_id")
  736. record_time := c.GetString("record_time")
  737. pay_way, _ := c.GetInt64("pay_way")
  738. pay_price, _ := c.GetFloat("pay_price")
  739. pay_card_no := c.GetString("pay_card_no")
  740. discount_price, _ := c.GetFloat("discount_price")
  741. preferential_price, _ := c.GetFloat("preferential_price")
  742. reality_price, _ := c.GetFloat("reality_price")
  743. found_price, _ := c.GetFloat("found_price")
  744. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  745. private_price, _ := c.GetFloat("private_price")
  746. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  747. admin_user_id, _ := c.GetInt64("admin_user_id")
  748. timeLayout := "2006-01-02"
  749. loc, _ := time.LoadLocation("Local")
  750. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  751. if err != nil {
  752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  753. return
  754. }
  755. recordDateTime := theTime.Unix()
  756. adminUser := c.GetAdminUserInfo()
  757. var prescriptions []*models.HisPrescription
  758. data := make(map[string]interface{})
  759. if settle_accounts_type == 1 { //日结
  760. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  761. data["pre"] = prescriptions
  762. } else { //月结
  763. start_time_str := c.GetString("start_time")
  764. end_time_str := c.GetString("end_time")
  765. timeLayout := "2006-01-02"
  766. loc, _ := time.LoadLocation("Local")
  767. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  768. if err != nil {
  769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  770. return
  771. }
  772. recordStartTime := theStartTime.Unix()
  773. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  774. if err != nil {
  775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  776. return
  777. }
  778. recordEndTime := theEndTime.Unix()
  779. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  780. data["pre"] = prescriptions
  781. }
  782. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  783. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  784. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  785. strconv.FormatInt(his.PatientId, 10)
  786. order_src, _ := service.GetHisOrderByID(order_id)
  787. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  788. if config.IsOpen == 1 { //对接了医保,走医保流程
  789. var total float64
  790. for _, item := range prescriptions {
  791. if item.Type == 1 { //药品
  792. for _, subItem := range item.HisDoctorAdviceInfo {
  793. total = total + (subItem.Price * subItem.PrescribingNumber)
  794. }
  795. }
  796. if item.Type == 2 { //项目
  797. for _, subItem := range item.HisPrescriptionProject {
  798. total = total + (subItem.Price * float64(subItem.Count))
  799. }
  800. }
  801. }
  802. for _, item := range prescriptions {
  803. for _, subItem := range item.HisAdditionalCharge {
  804. total = total + (subItem.Price * float64(subItem.Count))
  805. }
  806. }
  807. //结算流程
  808. var doctor_name string
  809. var doctor_code string
  810. if roles.ID == 0 {
  811. doctor_name = "黄亦轩"
  812. doctor_code = "1001"
  813. } else {
  814. doctor_name = roles.UserName
  815. doctor_code = strconv.FormatInt(admin_user_id, 10)
  816. }
  817. month := time.Unix(1557042972, 0).Format("1")
  818. year := time.Now().Format("2006")
  819. month = time.Now().Format("01")
  820. day := time.Now().Format("02")
  821. //流水号
  822. number := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  823. //verifyCode := ReadCardGetCode("FY005" + "|" + number + "|" + miConfig.Code)
  824. verifyCode := "000000|e57597afc5bb4f2bc6132710ff8b2899"
  825. result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, "", total, his.YiliaoNumber, verifyCode, number)
  826. var dat map[string]interface{}
  827. if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  828. fmt.Println(dat)
  829. } else {
  830. fmt.Println(err)
  831. }
  832. userJSONBytes, _ := json.Marshal(dat)
  833. var res ResultTwo
  834. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  835. utils.ErrorLog("解析失败:%v", err)
  836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  837. return
  838. }
  839. if res.Transreturncode == "00000000" {
  840. order_src.OrderStatus = 2
  841. order_src.PayWay = pay_way
  842. order_src.PayPrice = pay_price
  843. order_src.PayCardNo = pay_card_no
  844. order_src.DiscountPrice = discount_price
  845. order_src.PreferentialPrice = preferential_price
  846. order_src.RealityPrice = reality_price
  847. order_src.FoundPrice = found_price
  848. order_src.MedicalInsurancePrice = medical_insurance_price
  849. order_src.PrivatePrice = private_price
  850. order_src.Creator = order_src.Creator
  851. order_src.Modify = roles.ID
  852. order_src.MedfeeSumamt = res.Transbody.Akc264
  853. order_src.SetlId = res.Transbody.Ckc618
  854. order_src.FundPaySumamt = res.Transbody.Akb068
  855. order_src.AcctPay = res.Transbody.Akb066
  856. order_src.PsnCashPay = res.Transbody.Akb067
  857. order_src.PsnPartAmt = res.Transbody.Akb067
  858. order_src.AccountPrice = res.Transbody.Aae240
  859. order_src.OrgSetlNumber = number
  860. setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  861. detailStrOne := string(setlDetailOne)
  862. order_src.SzChargeInfo = detailStrOne
  863. setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  864. detailStrTwo := string(setlDetailTwo)
  865. order_src.SzProjectInfo = detailStrTwo
  866. setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  867. detailStrThree := string(setlDetailThree)
  868. order_src.SzMedicineInsuranceInfo = detailStrThree
  869. err = service.UpdataOrderStatusTwo(order_src.Number, adminUser.CurrentOrgId)
  870. err = service.UpDateOrder(order_src)
  871. c.ServeSuccessJSON(map[string]interface{}{
  872. "msg": "结算成功",
  873. })
  874. } else {
  875. }
  876. }
  877. }
  878. //当月退费
  879. func (c *SZHisApiController) Refund() {
  880. order_id, _ := c.GetInt64("order_id")
  881. record_time := c.GetString("record_time")
  882. patient_id, _ := c.GetInt64("patient_id")
  883. admin_user_id, _ := c.GetInt64("admin_user_id")
  884. timeLayout := "2006-01-02"
  885. loc, _ := time.LoadLocation("Local")
  886. adminUser := c.GetAdminUserInfo()
  887. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  888. fmt.Println(err)
  889. if err != nil {
  890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  891. return
  892. }
  893. recordDateTime := theTime.Unix()
  894. var order models.HisOrder
  895. order, _ = service.GetHisOrderByID(order_id)
  896. if order.ID == 0 {
  897. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  898. }
  899. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  900. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  901. //结算流程
  902. var doctor_name string
  903. var doctor_code string
  904. if roles.ID == 0 {
  905. doctor_name = "黄亦轩"
  906. doctor_code = "1001"
  907. } else {
  908. doctor_name = roles.UserName
  909. doctor_code = strconv.FormatInt(admin_user_id, 10)
  910. }
  911. //month := time.Unix(1557042972, 0).Format("1")
  912. //year := time.Now().Format("2006")
  913. //month = time.Now().Format("01")
  914. //day := time.Now().Format("02")
  915. //流水号
  916. //number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  917. //verifyCode := ReadCardGetCode("JY002" + "|" + number_two + "|" + miConfig.Code)
  918. verifyCode := "000000|1f94f1cbbb032e0c9ef8f1cd648e0689"
  919. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  920. if config.IsOpen == 1 { //对接了医保,走医保流程
  921. result := service.SzybJY002(doctor_name, doctor_code, miConfig.Code, order.OrgSetlNumber, order.MzNumber, verifyCode)
  922. fmt.Println(result)
  923. var dat map[string]interface{}
  924. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  925. fmt.Println(dat)
  926. } else {
  927. fmt.Println(err)
  928. }
  929. userJSONBytes, _ := json.Marshal(dat)
  930. var res ResultThree
  931. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  932. utils.ErrorLog("解析失败:%v", err)
  933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  934. return
  935. }
  936. if res.Transreturncode == "00000000" {
  937. c.ServeSuccessJSON(map[string]interface{}{
  938. "msg": "退费成功",
  939. })
  940. } else {
  941. }
  942. }
  943. }
  944. //跨月退费
  945. func (c *SZHisApiController) MonthRefund() {
  946. order_id, _ := c.GetInt64("order_id")
  947. record_time := c.GetString("record_time")
  948. patient_id, _ := c.GetInt64("patient_id")
  949. admin_user_id, _ := c.GetInt64("admin_user_id")
  950. timeLayout := "2006-01-02"
  951. loc, _ := time.LoadLocation("Local")
  952. adminUser := c.GetAdminUserInfo()
  953. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  954. fmt.Println(err)
  955. if err != nil {
  956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  957. return
  958. }
  959. recordDateTime := theTime.Unix()
  960. var order models.HisOrder
  961. order, _ = service.GetHisOrderByID(order_id)
  962. if order.ID == 0 {
  963. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  964. }
  965. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  966. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  967. //结算流程
  968. var doctor_name string
  969. var doctor_code string
  970. if roles.ID == 0 {
  971. doctor_name = "黄亦轩"
  972. doctor_code = "1001"
  973. } else {
  974. doctor_name = roles.UserName
  975. doctor_code = strconv.FormatInt(admin_user_id, 10)
  976. }
  977. month := time.Unix(1557042972, 0).Format("1")
  978. year := time.Now().Format("2006")
  979. month = time.Now().Format("01")
  980. day := time.Now().Format("02")
  981. //流水号
  982. number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  983. //verifyCode := ReadCardGetCode("JY002" + "|" + number_two + "|" + miConfig.Code)
  984. fmt.Println(number_two)
  985. verifyCode := "000000|a33205bcba1658c0406f71294073887d"
  986. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  987. if config.IsOpen == 1 { //对接了医保,走医保流程
  988. result := service.SzybJY003(doctor_name, doctor_code, miConfig.Code, order.OrgSetlNumber, order.MzNumber, verifyCode)
  989. fmt.Println(result)
  990. var dat map[string]interface{}
  991. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  992. fmt.Println(dat)
  993. } else {
  994. fmt.Println(err)
  995. }
  996. userJSONBytes, _ := json.Marshal(dat)
  997. var res ResultThree
  998. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  999. utils.ErrorLog("解析失败:%v", err)
  1000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1001. return
  1002. }
  1003. if res.Transreturncode == "00000000" {
  1004. c.ServeSuccessJSON(map[string]interface{}{
  1005. "msg": "退费成功",
  1006. })
  1007. } else {
  1008. }
  1009. }
  1010. }
  1011. //查询
  1012. func (c *SZHisApiController) GetSettleAccounts() {
  1013. order_id, _ := c.GetInt64("order_id")
  1014. record_time := c.GetString("record_time")
  1015. patient_id, _ := c.GetInt64("patient_id")
  1016. admin_user_id, _ := c.GetInt64("admin_user_id")
  1017. timeLayout := "2006-01-02"
  1018. loc, _ := time.LoadLocation("Local")
  1019. adminUser := c.GetAdminUserInfo()
  1020. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1021. fmt.Println(err)
  1022. if err != nil {
  1023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1024. return
  1025. }
  1026. recordDateTime := theTime.Unix()
  1027. var order models.HisOrder
  1028. order, _ = service.GetHisOrderByID(order_id)
  1029. if order.ID == 0 {
  1030. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  1031. }
  1032. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1033. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1034. //结算流程
  1035. var doctor_name string
  1036. var doctor_code string
  1037. if roles.ID == 0 {
  1038. doctor_name = "黄亦轩"
  1039. doctor_code = "1001"
  1040. } else {
  1041. doctor_name = roles.UserName
  1042. doctor_code = strconv.FormatInt(admin_user_id, 10)
  1043. }
  1044. month := time.Unix(1557042972, 0).Format("1")
  1045. year := time.Now().Format("2006")
  1046. month = time.Now().Format("01")
  1047. day := time.Now().Format("02")
  1048. //流水号
  1049. number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  1050. fmt.Println(number_two)
  1051. //verifyCode := ReadCardGetCode("JY001" + "|" + number_two + "|" + miConfig.Code)
  1052. verifyCode := "000000|2d27e121885fde08cccbeae7d206efd5"
  1053. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1054. if config.IsOpen == 1 { //对接了医保,走医保流程
  1055. result := service.SzybJY001(doctor_name, doctor_code, miConfig.Code, order.OrgSetlNumber, order.MzNumber, verifyCode)
  1056. fmt.Println(result)
  1057. var dat map[string]interface{}
  1058. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1059. fmt.Println(dat)
  1060. } else {
  1061. fmt.Println(err)
  1062. }
  1063. userJSONBytes, _ := json.Marshal(dat)
  1064. var res ResultFour
  1065. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1066. utils.ErrorLog("解析失败:%v", err)
  1067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1068. return
  1069. }
  1070. if res.Transreturncode == "00000000" {
  1071. c.ServeSuccessJSON(map[string]interface{}{})
  1072. } else {
  1073. }
  1074. }
  1075. }
  1076. //获取verifyCode
  1077. //func ReadCardGetCode(request string) string {
  1078. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  1079. // readCards := DllDef2.MustFindProc("iVerifyCode")
  1080. // str := request
  1081. // str3 := make([]byte, 256)
  1082. // ret4, _, _ := readCards.Call(StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  1083. // fmt.Println(":", string(str3))
  1084. //
  1085. // if ret4 == 0 {
  1086. // result := string(str3)
  1087. // fmt.Println(result)
  1088. // result_arr := strings.Split(result, "|")
  1089. // verifyCode := result_arr[0] + "|" + result_arr[1]
  1090. //
  1091. // return verifyCode
  1092. //
  1093. // }
  1094. // return ""
  1095. //}
  1096. //
  1097. ////读卡
  1098. //func ReadBasCardGetNumber(request string) (string, string, error, int64) {
  1099. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  1100. // readCards := DllDef2.MustFindProc("iReadCardBas")
  1101. // str := request
  1102. // var err error
  1103. // var ret4 int64
  1104. //
  1105. // str3 := make([]byte, 256)
  1106. // ret4, _, err = readCards.Call(IntPtr(3), StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  1107. // fmt.Println(":", string(str3))
  1108. //
  1109. // if ret4 == 0 {
  1110. // result := string(str3)
  1111. // fmt.Println(result)
  1112. // result_arr := strings.Split(result, "|")
  1113. // //医疗证号
  1114. // yiliao_number := result_arr[12]
  1115. //
  1116. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  1117. // id_card_number := result_arr[1]
  1118. // return yiliao_number, id_card_number, err, ret4
  1119. //
  1120. // }
  1121. // return "", "", err, ret4
  1122. //}
  1123. //
  1124. ////iReadCardBas_HSM_Step1 ---- 1903 iCardInnerAuthentication --- iReadCardBas_HSM_Step2
  1125. //func ReadCardBasHSM(number string) string {
  1126. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  1127. // readCards := DllDef2.MustFindProc("iReadCardBas_HSM_Step1")
  1128. // str := make([]byte, 256)
  1129. // ret, _, _ := readCards.Call(IntPtr(3), (uintptr)(unsafe.Pointer(&str[0])))
  1130. // fmt.Println(":", string(str))
  1131. //
  1132. // result_arr := strings.Split(string(str), "|")
  1133. //
  1134. // if ret == 0 {
  1135. // readCards := DllDef2.MustFindProc("iCardInnerAuthentication")
  1136. // str2 := make([]byte, 256)
  1137. // str3 := "" + "|" + "" + "|" + "440300" + "|" + "" + "|" + "" + "|" + result_arr[1] + "|" + result_arr[2] + "|" + result_arr[3] + "|" + result_arr[4] + "|" + result_arr[5] + "|" + "" + "|" + "" + "|"
  1138. // ret2, _, _ := readCards.Call(StrPtr(str3), (uintptr)(unsafe.Pointer(&str2[0])))
  1139. // fmt.Println(":", string(str2))
  1140. //
  1141. // if ret2 == 0 {
  1142. // result_arr := strings.Split(string(str2), "|")
  1143. //
  1144. // if result_arr[2] == "0" {
  1145. // readCards := DllDef2.MustFindProc("iReadCardBas_HSM_Step2")
  1146. // str4 := result_arr[4] + "|" + result_arr[5]
  1147. // str5 := make([]byte, 256)
  1148. // ret3, _, _ := readCards.Call(StrPtr(str4), StrPtr(number), (uintptr)(unsafe.Pointer(&str5[0])))
  1149. //
  1150. // if ret3 == 0 {
  1151. // return string(str5)
  1152. //
  1153. // } else {
  1154. // return ""
  1155. // }
  1156. // } else {
  1157. // return ""
  1158. // }
  1159. // }
  1160. // return ""
  1161. // }
  1162. // return ""
  1163. //
  1164. //}
  1165. //
  1166. ////1904卡鉴权
  1167. //func CardAuth(request string) string {
  1168. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  1169. // readCards := DllDef2.MustFindProc("iCardAuthentication")
  1170. // str := request
  1171. // str3 := make([]byte, 256)
  1172. // ret4, _, _ := readCards.Call(StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  1173. // fmt.Println(":", string(str3))
  1174. //
  1175. // if ret4 == 0 {
  1176. // return string(str3)
  1177. // }
  1178. // return ""
  1179. //}