pharmacy_controller.go 43KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379
  1. package controllers
  2. import (
  3. "fmt"
  4. "math"
  5. "strconv"
  6. "time"
  7. "XT_New/enums"
  8. "XT_New/models"
  9. "XT_New/service"
  10. "XT_New/utils"
  11. "github.com/astaxie/beego"
  12. )
  13. type PharmacyController struct {
  14. BaseAuthAPIController
  15. }
  16. func PharmacyApiRegistRouters() {
  17. beego.Router("/api/pharmacy/ceshili", &PharmacyController{}, "get:Tlili")
  18. beego.Router("/api/pharmacy/todaynumber", &PharmacyController{}, "get:TodayNumber") //查询今天的待发药,已发药人数(
  19. beego.Router("/api/pharmacy/waitingdrug", &PharmacyController{}, "get:WaitingDrug") //获取当天待发药的所有患者(
  20. beego.Router("/api/pharmacy/issueddrugs", &PharmacyController{}, "get:IssuedDrug") //获取当天已发药的所有患者(
  21. beego.Router("/api/pharmacy/getpharmacycontent", &PharmacyController{}, "get:GetPharmacyContent") //获取当天该患者的所有信息(
  22. beego.Router("/api/pharmacy/dispensingmedicine", &PharmacyController{}, "get:DispensingMedicine") //患者发药按钮点击(
  23. beego.Router("/api/pharmacy/drugwithdrawal", &PharmacyController{}, "get:DrugWithdrawal") //退药按钮点击
  24. beego.Router("/api/pharmacy/dispensingdetails", &PharmacyController{}, "get:DispensingDetails") //获取发药明细的患者列表(
  25. beego.Router("/api/pharmacy/prescriptiondetails", &PharmacyController{}, "get:PrescriptionDetails") //发药明细-详情(
  26. beego.Router("/api/pharmacy/dispensemedicine", &PharmacyController{}, "get:DispenseMedicine") //获取当天已发药的药品(
  27. beego.Router("/api/pharmacy/waitingmedicine", &PharmacyController{}, "get:WaitingMedicine") //获取当天待发药的药品(
  28. beego.Router("/api/pharmacy/getpatientswithdrugs", &PharmacyController{}, "get:GetPatientsWithDrugs") //获取当天该药品的所有患者(
  29. beego.Router("/api/pharmacy/medicinedeparture", &PharmacyController{}, "get:MedicineDeparture") //药品发药按钮点击(
  30. beego.Router("/api/pharmacy/getcurrentname", &PharmacyController{}, "get:GetCurrentName") //获取当前登录账号的名字(
  31. beego.Router("/api/pharmacy/getpartitionlist", &PharmacyController{}, "get:GetPartitionList") //获取当前机构的分区列表
  32. beego.Router("/api/pharmacy/routeofadministration", &PharmacyController{}, "get:RouteOfAdministration") //获取当前机构的给药途径
  33. beego.Router("/api/pharmacy/getgoodinventorylist", &PharmacyController{}, "Get:GetGoodInventoryList")
  34. beego.Router("/api/pharmacy/getgoodinventorybygoodid", &PharmacyController{}, "Get:GetGoodInventoryByGoodId")
  35. beego.Router("/api/pharmacy/updateInventoryWarehouseInfo", &PharmacyController{}, "Get:UpdateInventoryWarehouseInfo")
  36. beego.Router("/api/pharmacy/getdrugnewinventoryList", &PharmacyController{}, "Get:GetDrugInventoryList")
  37. beego.Router("/api/pharmacy/getdruginventorybydrugid", &PharmacyController{}, "Get:GetDrugInventoryByDrugId")
  38. beego.Router("/api/pharmacy/updatedruginventorywarehouseinfo", &PharmacyController{}, "Get:UpdateDrugInventoryWarehouseInfo")
  39. beego.Router("/api/pharmacy/changedrugcode", &PharmacyController{}, "Get:ChangeDrugCode")
  40. }
  41. // 测试
  42. func (this *PharmacyController) Tlili() {
  43. var err error
  44. defer func() {
  45. if rec := recover(); rec != nil {
  46. err = fmt.Errorf("程序异常:%v", rec)
  47. }
  48. if err != nil {
  49. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  50. }
  51. }()
  52. var list2 []*models.ReplacementDrugs
  53. list2, err = service.ReplacementDrugs(9675, false)
  54. if err != nil {
  55. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  56. return
  57. }
  58. this.ServeSuccessJSON(map[string]interface{}{
  59. "list": list2,
  60. })
  61. return
  62. }
  63. func (this *PharmacyController) GetCurrentName() {
  64. create := this.GetAdminUserInfo().AdminUser.Id
  65. this.ServeSuccessJSON(map[string]interface{}{
  66. "list": create,
  67. })
  68. return
  69. }
  70. // 查询今天的待发药,已发药人数
  71. func (this *PharmacyController) TodayNumber() {
  72. var err error
  73. defer func() {
  74. if rec := recover(); rec != nil {
  75. err = fmt.Errorf("程序异常:%v", rec)
  76. }
  77. if err != nil {
  78. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  79. }
  80. }()
  81. orgid := this.GetAdminUserInfo().CurrentOrgId
  82. times := this.GetString("time", "")
  83. timeLayout := "2006-01-02"
  84. loc, _ := time.LoadLocation("Local")
  85. var stime, etime int64
  86. if times == "" {
  87. stime, etime = service.GetNowTime()
  88. } else {
  89. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  90. stime = stmp.Unix()
  91. etime = stime + 86399
  92. }
  93. //if orgid != 9671 && orgid != 10188 && orgid != 10217 && orgid != 3877 && orgid != 10164 && orgid != 10480 {
  94. // //查询表里当天的数据
  95. // var wtotal int
  96. // wtotal, err = service.GetTodayPharmacy(stime, etime, orgid, 1)
  97. //
  98. // if err != nil {
  99. // utils.ErrorLog(err.Error())
  100. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  101. // return
  102. // }
  103. //
  104. // var itotal int
  105. // itotal, err = service.GetTodayPharmacy(stime, etime, orgid, 0)
  106. //
  107. // drug, _ := service.GetAllBaseDrugList(orgid)
  108. // if err != nil {
  109. // utils.ErrorLog(err.Error())
  110. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  111. // return
  112. // }
  113. // this.ServeSuccessJSON(map[string]interface{}{
  114. // "wtotal": wtotal,
  115. // "itotal": itotal,
  116. // "drug": drug,
  117. // })
  118. // return
  119. //}
  120. var wtotal int
  121. var itotal int
  122. //查找出库数量
  123. wtotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 1)
  124. itotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 0)
  125. drug, _ := service.GetAllBaseDrugList(orgid)
  126. this.ServeSuccessJSON(map[string]interface{}{
  127. "wtotal": wtotal,
  128. "itotal": itotal,
  129. "drug": drug,
  130. })
  131. return
  132. }
  133. func (this *PharmacyController) IssuedDrug() {
  134. var err error
  135. defer func() {
  136. if rec := recover(); rec != nil {
  137. err = fmt.Errorf("程序异常:%v", rec)
  138. }
  139. if err != nil {
  140. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  141. }
  142. }()
  143. keyword := this.GetString("keyword", "")
  144. fmt.Println(keyword)
  145. times := this.GetString("time", "")
  146. orgid := this.GetAdminUserInfo().CurrentOrgId
  147. shift, err := this.GetInt64("shift", 0) //班次
  148. if err != nil {
  149. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  150. return
  151. }
  152. partition, err := this.GetInt64("partition", 0) //分区
  153. if err != nil {
  154. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  155. return
  156. }
  157. timeLayout := "2006-01-02"
  158. loc, _ := time.LoadLocation("Local")
  159. var stime, etime int64
  160. if times == "" {
  161. stime, etime = service.GetNowTime()
  162. } else {
  163. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  164. stime = stmp.Unix()
  165. etime = stime + 86399
  166. }
  167. //获取排班班次
  168. schedule, _ := service.GetSchedulePatientId(stime, etime, orgid, shift, partition)
  169. var ids []int64
  170. for _, item := range schedule {
  171. ids = append(ids, item.PatientId)
  172. }
  173. list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 1, ids)
  174. var flist []models.TmpPatientOne
  175. if len(list) > 0 {
  176. for _, item := range list {
  177. patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
  178. flist = append(flist, patientlist)
  179. }
  180. }
  181. this.ServeSuccessJSON(map[string]interface{}{
  182. "list": flist,
  183. })
  184. //if orgid != 10164 && orgid == 3877 && orgid != 10188 && orgid != 10217 && orgid != 9671 && orgid != 10387 && orgid != 10375 && orgid != 10480 && orgid == 10344 {
  185. // //查询表里当天的数据
  186. // var flist []*models.TmpPatient
  187. // flist, err = service.GetTodayDrug(stime, etime, orgid, 1, keyword)
  188. // if err != nil {
  189. // utils.ErrorLog(err.Error())
  190. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  191. // return
  192. // }
  193. // listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
  194. // if err != nil {
  195. // utils.ErrorLog(err.Error())
  196. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  197. // return
  198. // }
  199. // this.ServeSuccessJSON(map[string]interface{}{
  200. // "list": listt,
  201. // })
  202. // return
  203. //}
  204. }
  205. func (this *PharmacyController) WaitingDrug() {
  206. var err error
  207. defer func() {
  208. if rec := recover(); rec != nil {
  209. err = fmt.Errorf("程序异常:%v", rec)
  210. }
  211. if err != nil {
  212. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  213. }
  214. }()
  215. keyword := this.GetString("keyword", "")
  216. times := this.GetString("time", "")
  217. shift, err := this.GetInt64("shift", 0) //班次
  218. if err != nil {
  219. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  220. return
  221. }
  222. partition, err := this.GetInt64("partition", 0) //分区
  223. if err != nil {
  224. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  225. return
  226. }
  227. orgid := this.GetAdminUserInfo().CurrentOrgId
  228. timeLayout := "2006-01-02"
  229. loc, _ := time.LoadLocation("Local")
  230. var stime, etime int64
  231. if times == "" {
  232. stime, etime = service.GetNowTime()
  233. } else {
  234. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  235. stime = stmp.Unix()
  236. etime = stime + 86399
  237. }
  238. //if orgid != 9671 && orgid != 10188 && orgid != 10217 && orgid != 3877 && orgid != 10164 && orgid != 10387 && orgid != 10375 && orgid != 10480 && orgid != 10344 {
  239. // //查询表里当天的数据
  240. // var flist []*models.TmpPatient
  241. // flist, err = service.GetTodayDrug(stime, etime, orgid, 0, keyword)
  242. //
  243. // if err != nil {
  244. // utils.ErrorLog(err.Error())
  245. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  246. // return
  247. // }
  248. // listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
  249. //
  250. // if err != nil {
  251. // utils.ErrorLog(err.Error())
  252. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  253. // return
  254. // }
  255. // baseList, _ := service.GetAllBaseDrugListTwo(orgid)
  256. // this.ServeSuccessJSON(map[string]interface{}{
  257. // "list": listt,
  258. // "baseList": baseList,
  259. // })
  260. // return
  261. //}
  262. fmt.Println(keyword)
  263. //当未发药的人数
  264. //获取排班班次
  265. schedule, _ := service.GetSchedulePatientId(stime, etime, orgid, shift, partition)
  266. var ids []int64
  267. for _, item := range schedule {
  268. ids = append(ids, item.PatientId)
  269. }
  270. list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 0, ids)
  271. var flist []models.TmpPatientOne
  272. if len(list) > 0 {
  273. for _, item := range list {
  274. patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
  275. flist = append(flist, patientlist)
  276. }
  277. }
  278. baseList, _ := service.GetAllBaseDrugListTwo(orgid)
  279. this.ServeSuccessJSON(map[string]interface{}{
  280. "list": flist,
  281. "baseList": baseList,
  282. })
  283. return
  284. }
  285. func (this *PharmacyController) GetPharmacyContent() {
  286. var err error
  287. defer func() {
  288. if rec := recover(); rec != nil {
  289. err = fmt.Errorf("程序异常:%v", rec)
  290. }
  291. if err != nil {
  292. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  293. }
  294. }()
  295. patient_id, _ := this.GetInt64("patient_id", 0)
  296. is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
  297. times := this.GetString("time", "")
  298. orgid := this.GetAdminUserInfo().CurrentOrgId
  299. timeLayout := "2006-01-02"
  300. loc, _ := time.LoadLocation("Local")
  301. var stime, etime int64
  302. if times == "" {
  303. stime, etime = service.GetNowTime()
  304. } else {
  305. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  306. stime = stmp.Unix()
  307. etime = stime + 86399
  308. }
  309. var list []*models.PharmacyContent
  310. list, err = service.GetPatientMedication(orgid, patient_id, stime, etime, is_medicine)
  311. baseList, _ := service.GetAllBaseDrugListTwo(orgid)
  312. patients, _ := service.GetPatientByIDOne(orgid, patient_id)
  313. order, _ := service.GetMobiledialysiOrder(orgid, patient_id, stime)
  314. numberList, _ := service.GetAllBedNumberList(orgid)
  315. zoneList, _ := service.GetAllZoneByList(orgid)
  316. appId := this.GetAdminUserInfo().CurrentAppId
  317. adminUserES, _ := service.GetAllAdminUserES(orgid, appId)
  318. allDoctor, _ := service.GetAllDoctor(orgid, appId)
  319. prescriptionListByToDay, _ := service.GetPrescriptionListByToDay(orgid, patient_id, stime)
  320. diagnose, _ := service.FindAllDiagnose(orgid)
  321. if err != nil {
  322. utils.ErrorLog(err.Error())
  323. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  324. return
  325. }
  326. return_value := make(map[string]interface{})
  327. return_value["list"] = list
  328. return_value["baseList"] = baseList
  329. return_value["patients"] = patients
  330. return_value["order"] = order
  331. return_value["numberList"] = numberList
  332. return_value["zoneList"] = zoneList
  333. return_value["adminUserES"] = adminUserES
  334. return_value["doctors"] = allDoctor
  335. return_value["prescription"] = prescriptionListByToDay
  336. return_value["diagnose"] = diagnose
  337. //if is_medicine == 1{发药时间先不展示
  338. // return_value["time"] = time
  339. //}
  340. this.ServeSuccessJSON(return_value)
  341. return
  342. }
  343. // 发药按钮点击
  344. func (this *PharmacyController) DispensingMedicine() {
  345. var err error
  346. defer func() {
  347. if rec := recover(); rec != nil {
  348. err = fmt.Errorf("程序异常:%v", rec)
  349. }
  350. if err != nil {
  351. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  352. }
  353. }()
  354. patient_id, _ := this.GetInt64("patient_id", 0)
  355. times := this.GetString("time", "")
  356. orgid := this.GetAdminUserInfo().CurrentOrgId
  357. creater := this.GetAdminUserInfo().AdminUser.Id
  358. timeLayout := "2006-01-02"
  359. loc, _ := time.LoadLocation("Local")
  360. var stime, etime int64
  361. if times == "" {
  362. stime, etime = service.GetNowTime()
  363. } else {
  364. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  365. stime = stmp.Unix()
  366. etime = stime + 86399
  367. }
  368. tmp_bool := service.IsPharmacyConfig(orgid)
  369. if tmp_bool == true {
  370. advicelist, _ := service.FindeHisAdviceDocAdvice(orgid, patient_id, stime, etime)
  371. if len(advicelist) > 0 {
  372. var total int64
  373. var prescribing_number_total int64
  374. for _, item := range advicelist {
  375. //查询改药品信息
  376. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  377. //如果是药房发药的方式
  378. if medical.IsPharmacy == 1 {
  379. houseConfig, _ := service.GetAllStoreHouseConfig(orgid)
  380. //查询该药品是否有库存
  381. list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  382. //判断单位是否相等
  383. if medical.MaxUnit == item.PrescribingNumberUnit {
  384. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  385. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  386. //转化为最小单位
  387. total = list.Count*medical.MinNumber + list.StockMinNumber
  388. prescribing_number_total = count * medical.MinNumber
  389. }
  390. if medical.MinUnit == item.PrescribingNumberUnit {
  391. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  392. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  393. total = list.Count*medical.MinNumber + list.StockMinNumber
  394. prescribing_number_total = count
  395. }
  396. if medical.IsUse != 1 {
  397. //如果出库数量大于库存数量
  398. if prescribing_number_total > total {
  399. err := fmt.Errorf(service.FindDrugsName(item.DrugId) + "库存不足")
  400. if err != nil {
  401. utils.ErrorLog(err.Error())
  402. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  403. return
  404. }
  405. }
  406. }
  407. }
  408. }
  409. }
  410. }
  411. if orgid != 10480 && orgid != 10188 && orgid != 10217 && orgid != 10164 && orgid != 10666 {
  412. //发药
  413. err = service.DispensingMedicine(orgid, patient_id, stime, etime, creater)
  414. if err != nil {
  415. utils.ErrorLog(err.Error())
  416. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  417. return
  418. }
  419. this.ServeSuccessJSON(map[string]interface{}{
  420. "list": "操作成功",
  421. })
  422. return
  423. }
  424. if orgid == 10480 || orgid == 10188 || orgid == 10217 || orgid == 10164 || orgid == 10666 {
  425. //发药逻辑
  426. service.DispensingMedicineOne(orgid, patient_id, stime, etime, creater)
  427. //针对桑植盛康
  428. if orgid == 10387 || orgid == 3877 {
  429. advicelist, _ := service.FindeHisAdviceDocAdvice(orgid, patient_id, stime, etime)
  430. if len(advicelist) > 0 {
  431. for _, item := range advicelist {
  432. //查询改药品信息
  433. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  434. if medical.IsPharmacy == 1 {
  435. flow, _ := service.GetFlow(item.DrugId, item.AdviceDate, orgid, item.PatientId)
  436. if len(flow) > 0 {
  437. service.UpdateAdviceFlow(item.ID)
  438. }
  439. }
  440. }
  441. }
  442. }
  443. if err != nil {
  444. utils.ErrorLog(err.Error())
  445. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  446. return
  447. }
  448. this.ServeSuccessJSON(map[string]interface{}{
  449. "list": "操作成功",
  450. })
  451. return
  452. }
  453. }
  454. // 退药按钮点击
  455. func (this *PharmacyController) DrugWithdrawal() {
  456. var err error
  457. defer func() {
  458. if rec := recover(); rec != nil {
  459. err = fmt.Errorf("程序异常:%v", rec)
  460. }
  461. if err != nil {
  462. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  463. }
  464. }()
  465. patient_id, _ := this.GetInt64("patient_id", 0)
  466. times := this.GetString("time", "")
  467. orgid := this.GetAdminUserInfo().CurrentOrgId
  468. creater := this.GetAdminUserInfo().AdminUser.Id
  469. timeLayout := "2006-01-02"
  470. loc, _ := time.LoadLocation("Local")
  471. var stime, etime int64
  472. if times == "" {
  473. stime, etime = service.GetNowTime()
  474. } else {
  475. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  476. stime = stmp.Unix()
  477. etime = stime + 86399
  478. }
  479. err = service.DrugWithdrawal(orgid, patient_id, stime, etime, creater)
  480. if err != nil {
  481. utils.ErrorLog(err.Error())
  482. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  483. return
  484. }
  485. this.ServeSuccessJSON(map[string]interface{}{
  486. "list": "操作成功",
  487. })
  488. return
  489. }
  490. // 发药明细列表
  491. func (this *PharmacyController) DispensingDetails() {
  492. var err error
  493. defer func() {
  494. if rec := recover(); rec != nil {
  495. err = fmt.Errorf("程序异常:%v", rec)
  496. }
  497. if err != nil {
  498. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  499. }
  500. }()
  501. keyword := this.GetString("keyword", "") //患者名称
  502. start_time := this.GetString("start_time", "") //开始时间
  503. end_time := this.GetString("end_time", "") //结束时间
  504. page, _ := this.GetInt64("page", 1) //页码
  505. limit, _ := this.GetInt64("limit", 10) //每一页查出来的条数
  506. orgid := this.GetAdminUserInfo().CurrentOrgId
  507. timeLayout := "2006-01-02"
  508. loc, _ := time.LoadLocation("Local")
  509. var stime, etime int64
  510. if start_time == "" {
  511. stime = 1
  512. } else {
  513. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  514. stime = stmp.Unix()
  515. }
  516. if end_time == "" {
  517. _, etime = service.GetNowTime()
  518. } else {
  519. etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  520. etime = etmp.Unix()
  521. }
  522. var dislist []*models.DispensingList
  523. var total int64
  524. dislist, total, err = service.DispensingDetailsList(stime, etime, orgid, page, limit, keyword)
  525. if err != nil {
  526. utils.ErrorLog(err.Error())
  527. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  528. return
  529. }
  530. this.ServeSuccessJSON(map[string]interface{}{
  531. "list": dislist,
  532. "total": total,
  533. })
  534. return
  535. }
  536. // 处方详情
  537. func (this *PharmacyController) PrescriptionDetails() {
  538. var err error
  539. defer func() {
  540. if rec := recover(); rec != nil {
  541. err = fmt.Errorf("程序异常:%v", rec)
  542. }
  543. if err != nil {
  544. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  545. }
  546. }()
  547. //患者姓名
  548. patient_id, _ := this.GetInt64("patient_id", 0)
  549. //发药时间
  550. record_date, _ := this.GetInt64("record_date", 0)
  551. orgid := this.GetAdminUserInfo().CurrentOrgId
  552. if record_date == 0 || patient_id == 0 {
  553. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数不足")
  554. return
  555. }
  556. var list []*models.PrescripDetails
  557. list, err = service.PrescriptionDetails(patient_id, record_date, orgid)
  558. if err != nil {
  559. utils.ErrorLog(err.Error())
  560. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  561. return
  562. }
  563. this.ServeSuccessJSON(map[string]interface{}{
  564. "list": list,
  565. })
  566. return
  567. }
  568. // 已发药品的信息
  569. func (this *PharmacyController) DispenseMedicine() {
  570. var err error
  571. defer func() {
  572. if rec := recover(); rec != nil {
  573. err = fmt.Errorf("程序异常:%v", rec)
  574. }
  575. if err != nil {
  576. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  577. }
  578. }()
  579. keyword := this.GetString("keyword", "")
  580. times := this.GetString("time", "")
  581. orgid := this.GetAdminUserInfo().CurrentOrgId
  582. timeLayout := "2006-01-02"
  583. loc, _ := time.LoadLocation("Local")
  584. deliveryway := this.GetString("deliveryway", "")
  585. var stime, etime int64
  586. if times == "" {
  587. stime, etime = service.GetNowTime()
  588. } else {
  589. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  590. stime = stmp.Unix()
  591. etime = stime + 86399
  592. }
  593. //查询表里当天的数据
  594. var flist []*models.ListOfDrugs
  595. flist, err = service.GetTodayMedicine(stime, etime, orgid, 1, keyword)
  596. if err != nil {
  597. utils.ErrorLog(err.Error())
  598. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  599. return
  600. }
  601. llist, err := service.Administration(deliveryway, orgid, flist)
  602. if err != nil {
  603. utils.ErrorLog(err.Error())
  604. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  605. return
  606. }
  607. this.ServeSuccessJSON(map[string]interface{}{
  608. "list": llist,
  609. })
  610. return
  611. }
  612. // 待发药的药品信息
  613. func (this *PharmacyController) WaitingMedicine() {
  614. var err error
  615. defer func() {
  616. if rec := recover(); rec != nil {
  617. err = fmt.Errorf("程序异常:%v", rec)
  618. }
  619. if err != nil {
  620. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  621. }
  622. }()
  623. keyword := this.GetString("keyword", "")
  624. times := this.GetString("time", "")
  625. orgid := this.GetAdminUserInfo().CurrentOrgId
  626. timeLayout := "2006-01-02"
  627. loc, _ := time.LoadLocation("Local")
  628. deliveryway := this.GetString("deliveryway", "")
  629. var stime, etime int64
  630. if times == "" {
  631. stime, etime = service.GetNowTime()
  632. } else {
  633. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  634. stime = stmp.Unix()
  635. etime = stime + 86399
  636. }
  637. //查询表里当天的数据
  638. var flist []*models.ListOfDrugs
  639. flist, err = service.GetTodayMedicine(stime, etime, orgid, 0, keyword)
  640. if err != nil {
  641. utils.ErrorLog(err.Error())
  642. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  643. return
  644. }
  645. llist, err := service.Administration(deliveryway, orgid, flist)
  646. if err != nil {
  647. utils.ErrorLog(err.Error())
  648. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  649. return
  650. }
  651. this.ServeSuccessJSON(map[string]interface{}{
  652. "list": llist,
  653. })
  654. return
  655. }
  656. // 获取药品的所有患者信息
  657. func (this *PharmacyController) GetPatientsWithDrugs() {
  658. var err error
  659. defer func() {
  660. if rec := recover(); rec != nil {
  661. err = fmt.Errorf("程序异常:%v", rec)
  662. }
  663. if err != nil {
  664. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  665. }
  666. }()
  667. drug_id, _ := this.GetInt64("drug_id", 0)
  668. is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
  669. times := this.GetString("time", "")
  670. orgid := this.GetAdminUserInfo().CurrentOrgId
  671. deliveryway := this.GetString("deliveryway", "")
  672. if deliveryway == "" {
  673. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  674. return
  675. }
  676. shift, err := this.GetInt64("shift", 0) //班次
  677. if err != nil {
  678. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  679. return
  680. }
  681. partition, err := this.GetInt64("partition", 0) //分区
  682. if err != nil {
  683. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  684. return
  685. }
  686. timeLayout := "2006-01-02"
  687. loc, _ := time.LoadLocation("Local")
  688. var stime, etime int64
  689. if times == "" {
  690. stime, etime = service.GetNowTime()
  691. } else {
  692. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  693. stime = stmp.Unix()
  694. etime = stime + 86399
  695. }
  696. var list []*models.PatientInformation
  697. list, err = service.FindMedicationList(orgid, drug_id, stime, etime, is_medicine)
  698. if err != nil {
  699. utils.ErrorLog(err.Error())
  700. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  701. return
  702. }
  703. listll, err := service.PartitionAndLayoutDrug(deliveryway, stime, etime, orgid, shift, partition, list)
  704. if err != nil {
  705. utils.ErrorLog(err.Error())
  706. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  707. return
  708. }
  709. total, err := service.CalculateTheTotalAmount(listll, drug_id)
  710. if err != nil {
  711. utils.ErrorLog(err.Error())
  712. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  713. return
  714. }
  715. this.ServeSuccessJSON(map[string]interface{}{
  716. "list": listll,
  717. "total": total,
  718. })
  719. return
  720. }
  721. // 药品管理发药按钮点击
  722. func (this *PharmacyController) MedicineDeparture() {
  723. var err error
  724. defer func() {
  725. if rec := recover(); rec != nil {
  726. err = fmt.Errorf("程序异常:%v", rec)
  727. }
  728. if err != nil {
  729. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  730. }
  731. }()
  732. creater, _ := this.GetInt64("creater", 0) //领药人
  733. ids := this.GetString("ids", "") //发药的数据
  734. orgid := this.GetAdminUserInfo().CurrentOrgId
  735. if ids == "" {
  736. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数不足")
  737. return
  738. }
  739. err = service.MedicineDeparture(ids, creater, orgid)
  740. if err != nil {
  741. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  742. return
  743. }
  744. this.ServeSuccessJSON(map[string]interface{}{
  745. "list": "修改成功",
  746. })
  747. return
  748. }
  749. func (this *PharmacyController) GetPartitionList() {
  750. var err error
  751. defer func() {
  752. if rec := recover(); rec != nil {
  753. err = fmt.Errorf("程序异常:%v", rec)
  754. }
  755. if err != nil {
  756. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  757. }
  758. }()
  759. orgid := this.GetAdminUserInfo().CurrentOrgId
  760. tmp := []*models.DeviceZone{{ID: 0, Name: "全部分区"}}
  761. list, err := service.GetAllValidDeviceZones02(orgid)
  762. if err != nil {
  763. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  764. return
  765. }
  766. this.ServeSuccessJSON(map[string]interface{}{
  767. "list": append(tmp, list...),
  768. })
  769. return
  770. }
  771. func (this *PharmacyController) RouteOfAdministration() {
  772. var err error
  773. defer func() {
  774. if rec := recover(); rec != nil {
  775. err = fmt.Errorf("程序异常:%v", rec)
  776. }
  777. if err != nil {
  778. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  779. }
  780. }()
  781. orgid := this.GetAdminUserInfo().CurrentOrgId
  782. tmp := []*models.DrugwayDic{{ID: 0, Name: "全部"}}
  783. list, _, err := service.GetDrugWayDics(orgid)
  784. if err != nil {
  785. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  786. return
  787. }
  788. this.ServeSuccessJSON(map[string]interface{}{
  789. "list": append(tmp, list...),
  790. })
  791. return
  792. }
  793. func (this *PharmacyController) GetGoodInventoryList() {
  794. keyword := this.GetString("keywords")
  795. orgId := this.GetAdminUserInfo().CurrentOrgId
  796. list, _ := service.GetGoodInventoryList(keyword, orgId)
  797. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  798. this.ServeSuccessJSON(map[string]interface{}{
  799. "list": list,
  800. "manufacturerList": manufacturerList,
  801. })
  802. return
  803. }
  804. func (this *PharmacyController) GetGoodInventoryByGoodId() {
  805. id, _ := this.GetInt64("id")
  806. infoList, _ := service.GetGoodInventoryByGoodId(id)
  807. this.ServeSuccessJSON(map[string]interface{}{
  808. "infoList": infoList,
  809. })
  810. }
  811. func (this *PharmacyController) UpdateInventoryWarehouseInfo() {
  812. id, _ := this.GetInt64("id")
  813. stock_count, _ := this.GetInt64("stock_count")
  814. last_stock_count, _ := this.GetInt64("last_stock_count")
  815. good_id, _ := this.GetInt64("good_id")
  816. orgId := this.GetAdminUserInfo().CurrentOrgId
  817. storehouse_id, _ := this.GetInt64("storehouse_id")
  818. is_type, _ := this.GetInt64("is_type")
  819. warehouseInfo, _ := service.GetInventoryWarehouseInfo(id)
  820. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(good_id)
  821. manufacturer, _ := service.GetManufactureById(warehouseInfo.Manufacturer)
  822. //更新库存
  823. service.UpdateWarehouseInfoById(last_stock_count, id)
  824. recordDateStr := time.Now().Format("2006-01-02")
  825. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  826. goodListOne, _ := service.GetSumGoodList(orgId, storehouse_id, good_id)
  827. var flush_count int64
  828. for _, it := range goodListOne {
  829. flush_count += it.StockCount
  830. }
  831. //盘盈
  832. if last_stock_count > stock_count {
  833. var total_count int64
  834. total_count = last_stock_count - stock_count
  835. creater := this.GetAdminUserInfo().AdminUser.Id
  836. inventory := models.XtStockInventory{
  837. GoodName: goodInfo.GoodName,
  838. SpecificationName: goodInfo.SpecificationName,
  839. WarehousingUnit: goodInfo.PackingUnit,
  840. Count: total_count,
  841. BuyPrice: goodInfo.BuyPrice,
  842. PackingPrice: goodInfo.PackingPrice,
  843. NewPrice: 0,
  844. Manufacturer: manufacturer.ManufacturerName,
  845. Dealer: "",
  846. Remark: "",
  847. GoodId: good_id,
  848. UserOrgId: orgId,
  849. Ctime: time.Now().Unix(),
  850. Mtime: 0,
  851. Status: 1,
  852. WarehousingOrder: warehouseInfo.WarehousingOrder,
  853. LicenseNumber: warehouseInfo.LicenseNumber,
  854. StartTime: time.Now().Unix(),
  855. Creater: creater,
  856. Checker: 0,
  857. CheckerStatus: 0,
  858. CheckerTime: 0,
  859. Total: 0,
  860. Number: warehouseInfo.Number,
  861. WarehousingInfoId: id,
  862. ExpireDate: warehouseInfo.ExpiryDate,
  863. ProductDate: warehouseInfo.ProductDate,
  864. GoodOriginPlace: "",
  865. Type: 10,
  866. InventoryType: is_type,
  867. LastStockCount: last_stock_count,
  868. StockCount: stock_count,
  869. StorehouseId: storehouse_id,
  870. RecordDate: recordDate.Unix(),
  871. }
  872. service.CreateInentory(inventory)
  873. stockFlow := models.VmStockFlow{
  874. WarehousingId: 0,
  875. GoodId: good_id,
  876. Number: warehouseInfo.Number,
  877. LicenseNumber: "",
  878. Count: total_count,
  879. UserOrgId: orgId,
  880. PatientId: 0,
  881. SystemTime: recordDate.Unix(),
  882. ConsumableType: 10,
  883. IsSys: 0,
  884. WarehousingOrder: warehouseInfo.WarehousingOrder,
  885. WarehouseOutId: 0,
  886. WarehouseOutOrderNumber: "",
  887. IsEdit: 0,
  888. CancelStockId: 0,
  889. CancelOrderNumber: "",
  890. Manufacturer: warehouseInfo.Manufacturer,
  891. Dealer: 0,
  892. Creator: creater,
  893. UpdateCreator: 0,
  894. Status: 1,
  895. Ctime: time.Now().Unix(),
  896. Mtime: 0,
  897. Price: warehouseInfo.Price,
  898. WarehousingDetailId: 0,
  899. WarehouseOutDetailId: 0,
  900. CancelOutDetailId: 0,
  901. ProductDate: warehouseInfo.ProductDate,
  902. ExpireDate: warehouseInfo.ExpiryDate,
  903. ReturnCount: 0,
  904. StorehouseId: storehouse_id,
  905. OverCount: flush_count,
  906. }
  907. service.CreateStockFlowOne(stockFlow)
  908. service.ReduceSumOutCount(good_id, total_count, storehouse_id, orgId)
  909. }
  910. //盘亏
  911. if last_stock_count < stock_count {
  912. var total_count int64
  913. total_count = stock_count - last_stock_count
  914. creater := this.GetAdminUserInfo().AdminUser.Id
  915. inventory := models.XtStockInventory{
  916. GoodName: goodInfo.GoodName,
  917. SpecificationName: goodInfo.SpecificationName,
  918. WarehousingUnit: goodInfo.PackingUnit,
  919. Count: total_count,
  920. BuyPrice: goodInfo.BuyPrice,
  921. PackingPrice: goodInfo.PackingPrice,
  922. NewPrice: 0,
  923. Manufacturer: manufacturer.ManufacturerName,
  924. Dealer: "",
  925. Remark: "",
  926. GoodId: good_id,
  927. UserOrgId: orgId,
  928. Ctime: time.Now().Unix(),
  929. Mtime: 0,
  930. Status: 1,
  931. WarehousingOrder: warehouseInfo.WarehousingOrder,
  932. LicenseNumber: warehouseInfo.LicenseNumber,
  933. StartTime: time.Now().Unix(),
  934. Creater: creater,
  935. Checker: 0,
  936. CheckerStatus: 0,
  937. CheckerTime: 0,
  938. Total: 0,
  939. Number: warehouseInfo.Number,
  940. WarehousingInfoId: id,
  941. ExpireDate: warehouseInfo.ExpiryDate,
  942. ProductDate: warehouseInfo.ProductDate,
  943. GoodOriginPlace: "",
  944. Type: 10,
  945. InventoryType: is_type,
  946. LastStockCount: last_stock_count,
  947. StockCount: stock_count,
  948. StorehouseId: storehouse_id,
  949. RecordDate: recordDate.Unix(),
  950. }
  951. service.CreateInentory(inventory)
  952. stockFlow := models.VmStockFlow{
  953. WarehousingId: 0,
  954. GoodId: good_id,
  955. Number: warehouseInfo.Number,
  956. LicenseNumber: "",
  957. Count: total_count,
  958. UserOrgId: orgId,
  959. PatientId: 0,
  960. SystemTime: recordDate.Unix(),
  961. ConsumableType: 11,
  962. IsSys: 0,
  963. WarehousingOrder: warehouseInfo.WarehousingOrder,
  964. WarehouseOutId: 0,
  965. WarehouseOutOrderNumber: "",
  966. IsEdit: 0,
  967. CancelStockId: 0,
  968. CancelOrderNumber: "",
  969. Manufacturer: warehouseInfo.Manufacturer,
  970. Dealer: 0,
  971. Creator: creater,
  972. UpdateCreator: 0,
  973. Status: 1,
  974. Ctime: time.Now().Unix(),
  975. Mtime: 0,
  976. Price: warehouseInfo.Price,
  977. WarehousingDetailId: 0,
  978. WarehouseOutDetailId: 0,
  979. CancelOutDetailId: 0,
  980. ProductDate: warehouseInfo.ProductDate,
  981. ExpireDate: warehouseInfo.ExpiryDate,
  982. ReturnCount: 0,
  983. StorehouseId: storehouse_id,
  984. OverCount: flush_count,
  985. }
  986. service.CreateStockFlowOne(stockFlow)
  987. service.ReduceSumInCount(good_id, total_count, storehouse_id, orgId)
  988. }
  989. //查询已审核单据的剩余库存
  990. goodList, _ := service.GetGoodSumCountByStoreId(storehouse_id, good_id, orgId)
  991. var sum_count int64
  992. var sum_in_count int64
  993. for _, item := range goodList {
  994. sum_count += item.StockCount
  995. sum_in_count += item.WarehousingCount
  996. }
  997. service.UpdateGoodByGoodId(good_id, sum_count, sum_in_count, orgId)
  998. service.UpdateSumGood(orgId, storehouse_id, good_id, flush_count)
  999. this.ServeSuccessJSON(map[string]interface{}{
  1000. "msg": "msg",
  1001. })
  1002. }
  1003. func (this *PharmacyController) GetDrugInventoryList() {
  1004. keywords := this.GetString("keywords")
  1005. orgId := this.GetAdminUserInfo().CurrentOrgId
  1006. drugList, _ := service.GetDrugNewInventoryList(orgId, keywords)
  1007. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1008. this.ServeSuccessJSON(map[string]interface{}{
  1009. "drugList": drugList,
  1010. "manufacturerList": manufacturerList,
  1011. })
  1012. }
  1013. func (this *PharmacyController) GetDrugInventoryByDrugId() {
  1014. orgId := this.GetAdminUserInfo().CurrentOrgId
  1015. id, _ := this.GetInt64("id")
  1016. infoList, _ := service.GetDrugInvetoryByDrugId(orgId, id)
  1017. this.ServeSuccessJSON(map[string]interface{}{
  1018. "infoList": infoList,
  1019. })
  1020. }
  1021. func (this *PharmacyController) UpdateDrugInventoryWarehouseInfo() {
  1022. id, _ := this.GetInt64("id")
  1023. stock_max_number, _ := this.GetInt64("stock_max_number")
  1024. stock_min_number, _ := this.GetInt64("stock_min_number")
  1025. last_stock_max_number, _ := this.GetInt64("last_stock_max_number")
  1026. last_stock_min_number, _ := this.GetInt64("last_stock_min_number")
  1027. drug_id, _ := this.GetInt64("drug_id")
  1028. storehouse_id, _ := this.GetInt64("storehouse_id")
  1029. is_type, _ := this.GetInt64("is_type")
  1030. specification_name := this.GetString("specification_name")
  1031. orgId := this.GetAdminUserInfo().CurrentOrgId
  1032. base, _ := service.GetBasedrugByIdOne(drug_id, orgId)
  1033. var ord_total int64
  1034. var new_total int64
  1035. var consumable_count int64
  1036. ord_total = stock_max_number*base.MinNumber + stock_min_number
  1037. new_total = last_stock_max_number*base.MinNumber + last_stock_min_number
  1038. //更新入库单
  1039. service.UpdateNewDrugWarehouseInfoById(id, last_stock_max_number, last_stock_min_number)
  1040. //查询默认仓库
  1041. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1042. //查询默认仓库剩余多少库存
  1043. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, drug_id)
  1044. var sum_count int64
  1045. for _, it := range list {
  1046. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  1047. if it.MaxUnit == baseDrug.MaxUnit {
  1048. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  1049. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  1050. }
  1051. sum_count += it.StockMaxNumber + it.StockMinNumber
  1052. }
  1053. //更新剩余库存
  1054. service.UpdateMedicalSumCountOne(drug_id, sum_count, orgId)
  1055. //更新剩余库存
  1056. service.UpdateDrugStockCount(drug_id, orgId, houseConfig.DrugStorehouseOut, sum_count)
  1057. drugWarehouseInfoOne, _ := service.GetDrugWarehouseInfoOne(id)
  1058. manufacturer, _ := service.GetManufactureById(drugWarehouseInfoOne.Manufacturer)
  1059. recordDateStr := time.Now().Format("2006-01-02")
  1060. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1061. //盘亏
  1062. if ord_total > new_total {
  1063. consumable_count = ord_total - new_total
  1064. inventory := models.XtDrugInventory{
  1065. DrugName: base.DrugName,
  1066. SpecificationName: specification_name,
  1067. WarehousingUnit: drugWarehouseInfoOne.MaxUnit,
  1068. Count: consumable_count,
  1069. LastPrice: drugWarehouseInfoOne.Price,
  1070. RetailPrice: drugWarehouseInfoOne.RetailPrice,
  1071. NewPrice: 0,
  1072. Manufacturer: manufacturer.ManufacturerName,
  1073. Dealer: "",
  1074. Remark: "",
  1075. DrugId: drug_id,
  1076. UserOrgId: orgId,
  1077. Ctime: time.Now().Unix(),
  1078. Mtime: 0,
  1079. Status: 1,
  1080. WarehousingOrder: drugWarehouseInfoOne.WarehousingOrder,
  1081. LicenseNumber: "",
  1082. StartTime: recordDate.Unix(),
  1083. Creater: this.GetAdminUserInfo().AdminUser.Id,
  1084. Checker: 0,
  1085. CheckerStatus: 0,
  1086. CheckerTime: 0,
  1087. ExpiryDate: drugWarehouseInfoOne.ExpiryDate,
  1088. ProductDate: drugWarehouseInfoOne.ProductDate,
  1089. Number: "",
  1090. BatchNumber: drugWarehouseInfoOne.BatchNumber,
  1091. Total: "",
  1092. DrugOriginPlace: "",
  1093. WarehouseInfoId: id,
  1094. ProofCount: 0,
  1095. StockMaxNumber: stock_max_number,
  1096. StockMinNumber: stock_min_number,
  1097. MinCount: 0,
  1098. MinUnit: drugWarehouseInfoOne.MinUnit,
  1099. LastStockMaxNumber: last_stock_max_number,
  1100. LastStockMinNumber: last_stock_min_number,
  1101. InventoryType: 11,
  1102. Type: is_type,
  1103. StorehouseId: storehouse_id,
  1104. RecordDate: recordDate.Unix(),
  1105. }
  1106. service.CreateDrugInventory(inventory)
  1107. flow := models.DrugFlow{
  1108. WarehousingId: id,
  1109. DrugId: drug_id,
  1110. Number: "",
  1111. BatchNumber: drugWarehouseInfoOne.BatchNumber,
  1112. Count: consumable_count,
  1113. UserOrgId: orgId,
  1114. PatientId: 0,
  1115. SystemTime: recordDate.Unix(),
  1116. ConsumableType: 11,
  1117. IsSys: 1,
  1118. WarehousingOrder: drugWarehouseInfoOne.WarehousingOrder,
  1119. WarehouseOutId: 0,
  1120. WarehouseOutOrderNumber: "",
  1121. IsEdit: 0,
  1122. CancelStockId: 0,
  1123. CancelOrderNumber: "",
  1124. Manufacturer: manufacturer.ID,
  1125. Dealer: 0,
  1126. Creator: this.GetAdminUserInfo().AdminUser.Id,
  1127. UpdateCreator: 0,
  1128. Status: 1,
  1129. Ctime: time.Now().Unix(),
  1130. Mtime: 0,
  1131. Price: drugWarehouseInfoOne.Price,
  1132. WarehousingDetailId: id,
  1133. WarehouseOutDetailId: 0,
  1134. CancelOutDetailId: 0,
  1135. ExpireDate: drugWarehouseInfoOne.ExpiryDate,
  1136. ProductDate: 0,
  1137. MaxUnit: drugWarehouseInfoOne.MaxUnit,
  1138. MinUnit: drugWarehouseInfoOne.MinUnit,
  1139. StorehouseId: storehouse_id,
  1140. OverCount: sum_count,
  1141. }
  1142. service.CreateDrugFlowOne(flow)
  1143. //添加出库数据
  1144. service.AddDrugWarehouseOut(drug_id, consumable_count, storehouse_id, orgId)
  1145. }
  1146. //盘盈
  1147. if ord_total < new_total {
  1148. consumable_count = new_total - ord_total
  1149. inventory := models.XtDrugInventory{
  1150. DrugName: base.DrugName,
  1151. SpecificationName: specification_name,
  1152. WarehousingUnit: drugWarehouseInfoOne.MaxUnit,
  1153. Count: consumable_count,
  1154. LastPrice: drugWarehouseInfoOne.Price,
  1155. RetailPrice: drugWarehouseInfoOne.RetailPrice,
  1156. NewPrice: 0,
  1157. Manufacturer: manufacturer.ManufacturerName,
  1158. Dealer: "",
  1159. Remark: "",
  1160. DrugId: drug_id,
  1161. UserOrgId: orgId,
  1162. Ctime: time.Now().Unix(),
  1163. Mtime: 0,
  1164. Status: 1,
  1165. WarehousingOrder: drugWarehouseInfoOne.WarehousingOrder,
  1166. LicenseNumber: "",
  1167. StartTime: recordDate.Unix(),
  1168. Creater: this.GetAdminUserInfo().AdminUser.Id,
  1169. Checker: 0,
  1170. CheckerStatus: 0,
  1171. CheckerTime: 0,
  1172. ExpiryDate: drugWarehouseInfoOne.ExpiryDate,
  1173. ProductDate: drugWarehouseInfoOne.ProductDate,
  1174. Number: "",
  1175. BatchNumber: drugWarehouseInfoOne.BatchNumber,
  1176. Total: "",
  1177. DrugOriginPlace: "",
  1178. WarehouseInfoId: id,
  1179. ProofCount: 0,
  1180. StockMaxNumber: stock_max_number,
  1181. StockMinNumber: stock_min_number,
  1182. MinCount: 0,
  1183. MinUnit: drugWarehouseInfoOne.MinUnit,
  1184. LastStockMaxNumber: last_stock_max_number,
  1185. LastStockMinNumber: last_stock_min_number,
  1186. InventoryType: 10,
  1187. Type: is_type,
  1188. StorehouseId: storehouse_id,
  1189. RecordDate: recordDate.Unix(),
  1190. }
  1191. service.CreateDrugInventory(inventory)
  1192. flow := models.DrugFlow{
  1193. WarehousingId: id,
  1194. DrugId: drug_id,
  1195. Number: "",
  1196. BatchNumber: drugWarehouseInfoOne.BatchNumber,
  1197. Count: consumable_count,
  1198. UserOrgId: orgId,
  1199. PatientId: 0,
  1200. SystemTime: recordDate.Unix(),
  1201. ConsumableType: 10,
  1202. IsSys: 1,
  1203. WarehousingOrder: drugWarehouseInfoOne.WarehousingOrder,
  1204. WarehouseOutId: 0,
  1205. WarehouseOutOrderNumber: "",
  1206. IsEdit: 0,
  1207. CancelStockId: 0,
  1208. CancelOrderNumber: "",
  1209. Manufacturer: manufacturer.ID,
  1210. Dealer: 0,
  1211. Creator: this.GetAdminUserInfo().AdminUser.Id,
  1212. UpdateCreator: 0,
  1213. Status: 1,
  1214. Ctime: time.Now().Unix(),
  1215. Mtime: 0,
  1216. Price: drugWarehouseInfoOne.Price,
  1217. WarehousingDetailId: id,
  1218. WarehouseOutDetailId: 0,
  1219. CancelOutDetailId: 0,
  1220. ExpireDate: drugWarehouseInfoOne.ExpiryDate,
  1221. ProductDate: 0,
  1222. MaxUnit: drugWarehouseInfoOne.MaxUnit,
  1223. MinUnit: drugWarehouseInfoOne.MinUnit,
  1224. StorehouseId: storehouse_id,
  1225. OverCount: sum_count,
  1226. }
  1227. service.CreateDrugFlowOne(flow)
  1228. //减少出库数据
  1229. service.ReduceDrugWarehouseOut(drug_id, consumable_count, storehouse_id, orgId)
  1230. }
  1231. this.ServeSuccessJSON(map[string]interface{}{
  1232. "msg": "msg",
  1233. })
  1234. }
  1235. func (this *PharmacyController) ChangeDrugCode() {
  1236. id, _ := this.GetInt64("id")
  1237. orgId := this.GetAdminUserInfo().CurrentOrgId
  1238. data_source, _ := this.GetInt64("data_source")
  1239. drug_code := this.GetString("drug_code")
  1240. fmt.Println("data_source--------------------", data_source)
  1241. if data_source == 1 {
  1242. fmt.Println("HHAHAHAH")
  1243. service.ChangeHisDrugCode(id, drug_code, orgId)
  1244. }
  1245. if data_source == 2 {
  1246. service.ChangeAdivceDrugCode(id, drug_code, orgId)
  1247. }
  1248. this.ServeSuccessJSON(map[string]interface{}{
  1249. "msg": "msg",
  1250. })
  1251. }