drug_stock_api_contorller.go 142KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "reflect"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type StockDrugApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func DrugStockManagerApiRegistRouters() {
  20. //入库管理和其他入库管理相关接口
  21. beego.Router("/api/drugwarehouse/create", &StockDrugApiController{}, "post:CreateDrugWarehouse")
  22. beego.Router("/api/drugwarehouse/list", &StockDrugApiController{}, "get:GetDrugWarehouseList")
  23. beego.Router("/api/drugwarehouse/delete", &StockDrugApiController{}, "post:DeleteDrugWarehouse")
  24. beego.Router("/api/drugwarehouseinfo/delete", &StockDrugApiController{}, "post:DeleteDrugWarehouseInfo")
  25. beego.Router("/api/drugwarehouseinfo/list", &StockDrugApiController{}, "get:GetDrugWarehouseInfoList")
  26. beego.Router("/api/drugwarehouse/edit", &StockDrugApiController{}, "post:EditDrugWarehouse")
  27. //退货管理和其他退货管理相关接口
  28. beego.Router("/api/drugsalesreturn/create", &StockDrugApiController{}, "post:CreateDrugSalesReturn")
  29. beego.Router("/api/drugsalesreturn/delete", &StockDrugApiController{}, "post:DeleteDrugSalesReturn")
  30. beego.Router("/api/drugsalesreturninfo/delete", &StockDrugApiController{}, "post:DeleteDrugSalesReturnInfo")
  31. beego.Router("/api/drugsalesreturninfo/list", &StockDrugApiController{}, "get:GetDrugSalesReturnInfoList")
  32. beego.Router("/api/drugsalesreturn/list", &StockDrugApiController{}, "get:GetDrugSalesReturnList")
  33. beego.Router("/api/drugsalesreturn/edit", &StockDrugApiController{}, "post:EditDrugReturnInfo")
  34. //出库管理和其他出库管理相关接口
  35. beego.Router("/api/drugwarehouseout/create", &StockDrugApiController{}, "post:CreateDrugWarehouseOut")
  36. beego.Router("/api/drugwarehouseout/delete", &StockDrugApiController{}, "post:DeleteDrugWarehouseOut")
  37. beego.Router("/api/drugwarehouseoutinfo/delete", &StockDrugApiController{}, "post:DeleteDrugWarehouseOutInfo")
  38. beego.Router("/api/drugwarehouseout/list", &StockDrugApiController{}, "get:GetDrugWarehouseOutList")
  39. beego.Router("/api/drugwarehouseout/edit", &StockDrugApiController{}, "post:EditDrugWarehouseOut")
  40. beego.Router("/api/drugwarehouseout/info", &StockDrugApiController{}, "get:GetDrugWarehouseOutInfoList")
  41. //出库退库管理和其他出库退库管理相关接口
  42. beego.Router("/api/drugcancelstock/create", &StockDrugApiController{}, "post:CreateDrugCancelStock")
  43. beego.Router("/api/drugcancelstock/list", &StockDrugApiController{}, "get:GetDrugCancelStockList")
  44. beego.Router("/api/drugcancelstock/info", &StockDrugApiController{}, "get:GetDrugCancelStockInfoList")
  45. beego.Router("/api/drugcancelstock/delete", &StockDrugApiController{}, "post:DeleteDrugCancelStock")
  46. beego.Router("/api/drugcancelstockinfo/delete", &StockDrugApiController{}, "post:DeleteDrugCancelStockInfo")
  47. beego.Router("/api/drugcancelstockinfo/edit", &StockDrugApiController{}, "post:EditDrugCancelStock")
  48. ////库存相关全局配置
  49. beego.Router("/api/drugstock/config", &StockDrugApiController{}, "get:GetAllConfig")
  50. //beego.Router("/api/drugreturn/config", &StockDrugApiController{}, "get:GetAllSalesReturnConfig")
  51. //
  52. ////库存查询
  53. beego.Router("/api/drugstock/query", &StockDrugApiController{}, "get:GetDrugQueryInfo")
  54. //
  55. //beego.Router("/api/drugstock/detail", &StockDrugApiController{}, "get:GetDetailInfo")
  56. //
  57. beego.Router("/api/drugwarehouseout/user", &StockDrugApiController{}, "get:GetUserDetailInfo")
  58. beego.Router("/api/drugstock/get", &StockDrugApiController{}, "get:GetAllDrugStock")
  59. beego.Router("/api/drug/getcanceldrugorderprint", &StockDrugApiController{}, "get:GetCancelDrugOrderPrint")
  60. beego.Router("/api/drug/drugcancelexportlist", &StockDrugApiController{}, "get:GetDrugCancelExportList")
  61. beego.Router("/api/drug/getdrugwarehouseinfoprint", &StockDrugApiController{}, "get:GetDrugWarehouseInfoPrint")
  62. beego.Router("/api/drug/getdrugoutorderprint", &StockDrugApiController{}, "get:GetDrugOutOrderPrint")
  63. beego.Router("/api/drugstock/config/list", &StockDrugApiController{}, "get:GetConfigList")
  64. beego.Router("/api/drug/checkwarehouseinginfo", &StockDrugApiController{}, "get:CheckWarehousingInfo")
  65. beego.Router("/api/drug/returncheckwarehouseinginfo", &StockDrugApiController{}, "get:ReturnCheckWarehouseingInfo")
  66. beego.Router("/api/drug/tocheckdrugout", &StockDrugApiController{}, "get:CheckDrugOut")
  67. beego.Router("/api/drug/toreturncheck", &StockDrugApiController{}, "get:ToReturnCheck")
  68. beego.Router("/api/drug/checkcanceldrugstock", &StockDrugApiController{}, "get:CheckCancelDrugStock")
  69. beego.Router("/api/drug/returndrugcancelstock", &StockDrugApiController{}, "get:ReturnDrugCancelStock")
  70. }
  71. func (c *StockDrugApiController) CreateDrugWarehouse() {
  72. warehousing_time := c.GetString("warehousing_time")
  73. types, _ := c.GetInt64("type", 0)
  74. storehouse_id, _ := c.GetInt64("storehouse_id")
  75. warehousing_id, _ := c.GetInt64("warehousing_id")
  76. ctime := time.Now().Unix()
  77. adminUserInfo := c.GetAdminUserInfo()
  78. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  79. if parseDateErr != nil {
  80. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  81. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  82. return
  83. }
  84. timeStr := time.Now().Format("2006-01-02")
  85. timeArr := strings.Split(timeStr, "-")
  86. total, _ := service.FindAllWarehouseTotalOne(adminUserInfo.CurrentOrgId)
  87. total = total + 1
  88. warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  89. operation_time := time.Now().Unix()
  90. creater := adminUserInfo.AdminUser.Id
  91. warehousing := models.DrugWarehouse{
  92. WarehousingOrder: warehousing_order,
  93. OperationTime: operation_time,
  94. OrgId: adminUserInfo.CurrentOrgId,
  95. Creater: creater,
  96. Ctime: ctime,
  97. Status: 1,
  98. WarehousingTime: warehousingDate.Unix(),
  99. Type: types,
  100. StorehouseId: storehouse_id,
  101. IsCheck: 2,
  102. }
  103. if warehousing_id == 0 {
  104. service.AddSigleDrugWarehouse(&warehousing)
  105. }
  106. if warehousing_id > 0 {
  107. service.UpdateSigleDrugWarehouse(warehousing_id, storehouse_id)
  108. }
  109. info, _ := service.FindLastWarehousingSeven(adminUserInfo.CurrentOrgId)
  110. dataBody := make(map[string]interface{}, 0)
  111. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  112. if err != nil {
  113. utils.ErrorLog(err.Error())
  114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  115. return
  116. }
  117. var warehousingInfo []*models.DrugWarehouseInfo
  118. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  119. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  120. if len(thisStockIn) > 0 {
  121. for _, item := range thisStockIn {
  122. items := item.(map[string]interface{})
  123. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  124. utils.ErrorLog("id")
  125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  126. return
  127. }
  128. id := int64(items["id"].(float64))
  129. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  130. utils.ErrorLog("drug_id")
  131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  132. return
  133. }
  134. drug_id := int64(items["drug_id"].(float64))
  135. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  136. utils.ErrorLog("warehousing_count")
  137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  138. return
  139. }
  140. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  141. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  142. utils.ErrorLog("last_price")
  143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  144. return
  145. }
  146. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  147. total := float64(warehousing_count) * last_price
  148. retail_price_total := float64(warehousing_count) * last_price
  149. var productDates int64
  150. var expiryDates int64
  151. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  152. expiryDates = 0
  153. } else {
  154. if len(items["expiry_date"].(string)) == 0 {
  155. expiryDates = 0
  156. } else {
  157. expiryDate, _ := items["expiry_date"].(string)
  158. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  159. expiryDates = expiry_date.Unix()
  160. }
  161. }
  162. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  163. productDates = 0
  164. } else {
  165. if len(items["product_date"].(string)) == 0 {
  166. productDates = 0
  167. } else {
  168. productDate, _ := items["product_date"].(string)
  169. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  170. productDates = product_date.Unix()
  171. }
  172. }
  173. number, _ := items["number"].(string)
  174. batch_number, _ := items["batch_number"].(string)
  175. if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
  176. utils.ErrorLog("max_unit")
  177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  178. return
  179. }
  180. max_unit, _ := items["max_unit"].(string)
  181. if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
  182. utils.ErrorLog("min_unit")
  183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  184. return
  185. }
  186. min_unit, _ := items["min_unit"].(string)
  187. var remark string
  188. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  189. remark = ""
  190. } else {
  191. remark = items["remark"].(string)
  192. }
  193. manufacturer := int64(items["manufacturer"].(float64))
  194. dealer := int64(items["dealer"].(float64))
  195. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  196. utils.ErrorLog("retail_price")
  197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  198. return
  199. }
  200. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  201. warehouseInfo := &models.DrugWarehouseInfo{
  202. ID: id,
  203. WarehousingOrder: warehousing.WarehousingOrder,
  204. WarehousingId: info.ID,
  205. DrugId: drug_id,
  206. Number: number,
  207. ProductDate: productDates,
  208. ExpiryDate: expiryDates,
  209. WarehousingCount: warehousing_count,
  210. Price: last_price,
  211. TotalPrice: total,
  212. Status: 1,
  213. Ctime: ctime,
  214. Remark: remark,
  215. OrgId: adminUserInfo.CurrentOrgId,
  216. Type: types,
  217. Manufacturer: manufacturer,
  218. Dealer: dealer,
  219. StockMaxNumber: 0,
  220. RetailTotalPrice: retail_price_total,
  221. BatchNumber: batch_number,
  222. MaxUnit: max_unit,
  223. MinUnit: min_unit,
  224. RetailPrice: retail_price,
  225. StorehouseId: storehouse_id,
  226. IsCheck: 2,
  227. StockMinNumber: 0,
  228. }
  229. fmt.Println(warehouseInfo)
  230. warehousingInfo = append(warehousingInfo, warehouseInfo)
  231. }
  232. }
  233. }
  234. for _, item := range warehousingInfo {
  235. if item.ID == 0 {
  236. service.CreatedWarehouseing(item)
  237. }
  238. if item.ID > 0 {
  239. service.UpdateWarehouseing(item)
  240. }
  241. }
  242. list, _ := service.FindDrugWarehouseInfoListById(info.ID, adminUserInfo.CurrentOrgId)
  243. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  244. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  245. var drugType = "药品类型"
  246. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  247. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminUserInfo.CurrentOrgId)
  248. c.ServeSuccessJSON(map[string]interface{}{
  249. "msg": "入库成功",
  250. "warehousing_order": warehousing_order,
  251. "info": info,
  252. "list": list,
  253. "manufacturerList": manufacturerList,
  254. "dealerList": dealerList,
  255. "drugTypeList": drugTypeList,
  256. })
  257. }
  258. func (c *StockDrugApiController) GetDrugWarehouseList() {
  259. page, _ := c.GetInt64("page", -1)
  260. limit, _ := c.GetInt64("limit", -1)
  261. start_time := c.GetString("start_time")
  262. end_time := c.GetString("end_time")
  263. types, _ := c.GetInt64("type", 0)
  264. keywords := c.GetString("keywords")
  265. storehouse_id, _ := c.GetInt64("storehouse_id")
  266. check_type, _ := c.GetInt64("check_type")
  267. timeLayout := "2006-01-02"
  268. loc, _ := time.LoadLocation("Local")
  269. var startTime int64
  270. if len(start_time) > 0 {
  271. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  272. if err != nil {
  273. fmt.Println(err)
  274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  275. return
  276. }
  277. startTime = theTime.Unix()
  278. }
  279. var endTime int64
  280. if len(end_time) > 0 {
  281. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  282. if err != nil {
  283. utils.ErrorLog(err.Error())
  284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  285. return
  286. }
  287. endTime = theTime.Unix()
  288. }
  289. adminUserInfo := c.GetAdminUserInfo()
  290. //按药品名称搜索
  291. var ids []int64
  292. var idArray []int64
  293. list, _ := service.GetDrugNameByKeyword(keywords, adminUserInfo.CurrentOrgId)
  294. for _, item := range list {
  295. ids = append(ids, item.ID)
  296. }
  297. //查找入库单详情
  298. if len(ids) > 0 {
  299. info, _ := service.GetDrugWarehouseOrderDetailTwo(ids, adminUserInfo.CurrentOrgId, startTime, endTime, storehouse_id)
  300. for _, it := range info {
  301. idArray = append(idArray, it.WarehousingId)
  302. }
  303. }
  304. warehouseList, total, err := service.FindAllDrugWarehousingListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, idArray, storehouse_id, check_type)
  305. houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  306. if err == nil {
  307. c.ServeSuccessJSON(map[string]interface{}{
  308. "list": warehouseList,
  309. "total": total,
  310. "houseList": houseList,
  311. })
  312. } else {
  313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  314. }
  315. }
  316. func (c *StockDrugApiController) GetDrugWarehouseInfoList() {
  317. id, _ := c.GetInt64("id", 0)
  318. if id <= 0 {
  319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  320. return
  321. }
  322. admin := c.GetAdminUserInfo()
  323. warehousing, err := service.FindDrugWarehousingById(id, admin.CurrentOrgId)
  324. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  325. dealerList, _ := service.GetAllDealerList(admin.CurrentOrgId)
  326. if err != nil {
  327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  328. return
  329. }
  330. if warehousing.ID <= 0 {
  331. return
  332. }
  333. warehousingInfo, err := service.FindDrugWarehousingInfoByIdThree(id, admin.CurrentOrgId)
  334. list, _ := service.GetAllStoreHouseListThree(admin.CurrentOrgId)
  335. if err == nil {
  336. c.ServeSuccessJSON(map[string]interface{}{
  337. "info": warehousingInfo,
  338. "warehousing": warehousing,
  339. "manufacturerList": manufacturerList,
  340. "dealerList": dealerList,
  341. "list": list,
  342. })
  343. } else {
  344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  345. }
  346. }
  347. func (c *StockDrugApiController) EditDrugWarehouse() {
  348. warehousing_time := c.GetString("warehousing_time")
  349. id, _ := c.GetInt64("id", 0)
  350. types, _ := c.GetInt64("type", 0)
  351. storehouse_id, _ := c.GetInt64("storehouse_id")
  352. if id == 0 {
  353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  354. return
  355. }
  356. ctime := time.Now().Unix()
  357. mtime := time.Now().Unix()
  358. adminUserInfo := c.GetAdminUserInfo()
  359. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  360. if parseDateErr != nil {
  361. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  363. return
  364. }
  365. warehouse, _ := service.FindDrugWarehousingById(id, adminUserInfo.CurrentOrgId)
  366. warehousing := models.DrugWarehouse{
  367. WarehousingOrder: warehouse.WarehousingOrder,
  368. OrgId: adminUserInfo.CurrentOrgId,
  369. Modifier: adminUserInfo.AdminUser.Id,
  370. Mtime: mtime,
  371. Status: 1,
  372. WarehousingTime: warehousingDate.Unix(),
  373. Type: warehouse.Type,
  374. StorehouseId: storehouse_id,
  375. }
  376. service.EditDrugWarehousingOne(warehousing, id)
  377. dataBody := make(map[string]interface{}, 0)
  378. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  379. if err != nil {
  380. utils.ErrorLog(err.Error())
  381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  382. return
  383. }
  384. var warehousingInfo []*models.DrugWarehouseInfo
  385. var upDateWarehousingInfo []*models.DrugWarehouseInfo
  386. var drugFlow []*models.DrugFlow
  387. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  388. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  389. if len(thisStockIn) > 0 {
  390. for _, item := range thisStockIn {
  391. items := item.(map[string]interface{})
  392. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  393. utils.ErrorLog("drug_id")
  394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  395. return
  396. }
  397. drug_id := int64(items["drug_id"].(float64))
  398. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  399. utils.ErrorLog("warehousing_count")
  400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  401. return
  402. }
  403. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  404. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  405. utils.ErrorLog("price")
  406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  407. return
  408. }
  409. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  410. total := float64(warehousing_count) * price
  411. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  412. utils.ErrorLog("last_price")
  413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  414. return
  415. }
  416. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  417. retail_price_total := float64(warehousing_count) * last_price
  418. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  419. var productDates int64
  420. var expiryDates int64
  421. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  422. expiryDates = 0
  423. } else {
  424. if len(items["expiry_date"].(string)) == 0 {
  425. expiryDates = 0
  426. } else {
  427. expiryDate, _ := items["expiry_date"].(string)
  428. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  429. expiryDates = expiry_date.Unix()
  430. }
  431. }
  432. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  433. productDates = 0
  434. } else {
  435. if len(items["product_date"].(string)) == 0 {
  436. productDates = 0
  437. } else {
  438. productDate, _ := items["product_date"].(string)
  439. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  440. productDates = product_date.Unix()
  441. }
  442. }
  443. number, _ := items["number"].(string)
  444. batch_number, _ := items["batch_number"].(string)
  445. max_unit, _ := items["max_unit"].(string)
  446. min_unit, _ := items["min_unit"].(string)
  447. var remark string
  448. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  449. remark = ""
  450. } else {
  451. remark = items["remark"].(string)
  452. }
  453. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  454. utils.ErrorLog("id")
  455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  456. return
  457. }
  458. id := int64(items["id"].(float64))
  459. manufacturer := int64(items["manufacturer"].(float64))
  460. dealer := int64(items["dealer"].(float64))
  461. medical, _ := service.GetBaseDrugMedical(drug_id)
  462. if id == 0 {
  463. warehouseInfo := &models.DrugWarehouseInfo{
  464. WarehousingOrder: warehouse.WarehousingOrder,
  465. WarehousingId: warehouse.ID,
  466. DrugId: drug_id,
  467. Number: number,
  468. ProductDate: productDates,
  469. ExpiryDate: expiryDates,
  470. WarehousingCount: warehousing_count,
  471. Price: price,
  472. TotalPrice: total,
  473. Status: 1,
  474. Ctime: ctime,
  475. Remark: remark,
  476. OrgId: adminUserInfo.CurrentOrgId,
  477. Type: types,
  478. Manufacturer: manufacturer,
  479. Dealer: dealer,
  480. RetailPrice: retail_price,
  481. RetailTotalPrice: retail_price_total,
  482. BatchNumber: batch_number,
  483. MaxUnit: max_unit,
  484. MinUnit: min_unit,
  485. StockMaxNumber: 0,
  486. StorehouseId: storehouse_id,
  487. StockMinNumber: 0,
  488. }
  489. warehousingInfo = append(warehousingInfo, warehouseInfo)
  490. } else {
  491. warehouseInfo := &models.DrugWarehouseInfo{
  492. ID: id,
  493. WarehousingOrder: warehouse.WarehousingOrder,
  494. WarehousingId: warehouse.ID,
  495. DrugId: drug_id,
  496. Number: number,
  497. ProductDate: productDates,
  498. ExpiryDate: expiryDates,
  499. WarehousingCount: warehousing_count,
  500. Price: price,
  501. TotalPrice: total,
  502. Status: 1,
  503. Ctime: ctime,
  504. Remark: remark,
  505. OrgId: adminUserInfo.CurrentOrgId,
  506. Type: types,
  507. Manufacturer: manufacturer,
  508. Dealer: dealer,
  509. RetailPrice: retail_price,
  510. RetailTotalPrice: retail_price_total,
  511. MaxUnit: max_unit,
  512. MinUnit: min_unit,
  513. BatchNumber: batch_number,
  514. StorehouseId: storehouse_id,
  515. }
  516. if medical.MaxUnit == medical.MinUnit {
  517. warehouseInfo.StockMaxNumber = warehousing_count
  518. warehouseInfo.StockMinNumber = 0
  519. warehouseInfo.MaxUnit = min_unit
  520. }
  521. if medical.MinUnit != medical.MaxUnit {
  522. if max_unit == medical.MaxUnit {
  523. warehouseInfo.StockMaxNumber = warehousing_count
  524. warehouseInfo.StockMinNumber = 0
  525. warehouseInfo.MaxUnit = max_unit
  526. warehouseInfo.MinUnit = medical.MinUnit
  527. }
  528. if max_unit == medical.MinUnit {
  529. warehouseInfo.StockMaxNumber = 0
  530. warehouseInfo.StockMinNumber = warehousing_count
  531. warehouseInfo.MaxUnit = medical.MinUnit
  532. warehouseInfo.MinUnit = medical.MinUnit
  533. }
  534. }
  535. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  536. drugflow := &models.DrugFlow{
  537. WarehousingOrder: warehousing.WarehousingOrder,
  538. WarehousingId: warehouse.ID,
  539. DrugId: drug_id,
  540. Number: number,
  541. ProductDate: productDates,
  542. ExpireDate: expiryDates,
  543. Count: warehousing_count,
  544. Price: last_price,
  545. Status: 1,
  546. Ctime: ctime,
  547. UserOrgId: adminUserInfo.CurrentOrgId,
  548. Manufacturer: manufacturer,
  549. Dealer: dealer,
  550. BatchNumber: batch_number,
  551. MaxUnit: max_unit,
  552. MinUnit: min_unit,
  553. ConsumableType: 1,
  554. IsEdit: 1,
  555. Creator: adminUserInfo.AdminUser.Id,
  556. IsSys: 0,
  557. WarehousingDetailId: id,
  558. StorehouseId: storehouse_id,
  559. }
  560. if max_unit == min_unit {
  561. drugflow.MaxUnit = min_unit
  562. }
  563. drugFlow = append(drugFlow, drugflow)
  564. }
  565. }
  566. }
  567. }
  568. var errs error
  569. if len(warehousingInfo) > 0 {
  570. errs = service.CreateDrugWarehousingInfo(warehousingInfo)
  571. }
  572. if len(upDateWarehousingInfo) > 0 {
  573. for _, item := range upDateWarehousingInfo {
  574. service.UpdateDrugWarehouseInfoTwenty(item.ID, item)
  575. }
  576. }
  577. if errs != nil {
  578. utils.ErrorLog(errs.Error())
  579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  580. return
  581. }
  582. list, _ := service.GetDrugWarehouseInfoList(id, adminUserInfo.CurrentOrgId)
  583. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  584. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  585. var drugType = "药品类型"
  586. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  587. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminUserInfo.CurrentOrgId)
  588. c.ServeSuccessJSON(map[string]interface{}{
  589. "msg": "编辑成功",
  590. "list": list,
  591. "manufacturerList": manufacturerList,
  592. "dealerList": dealerList,
  593. "drugTypeList": drugTypeList,
  594. })
  595. }
  596. func (c *StockDrugApiController) DeleteDrugWarehouse() {
  597. ids := c.GetString("ids")
  598. if len(ids) == 0 {
  599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  600. return
  601. }
  602. idArray := strings.Split(ids, ",")
  603. orgId := c.GetAdminUserInfo().CurrentOrgId
  604. err := service.DeleteDrugWarehouse(idArray)
  605. list, _ := service.GetLastDrugwarehouseInfoByIdTwenty(idArray, orgId)
  606. for _, it := range list {
  607. //查询默认仓库
  608. houseConfig, _ := service.GetAllStoreHouseConfig(it.OrgId)
  609. //查询默认仓库剩余多少库存
  610. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, it.OrgId, it.DrugId)
  611. var sum_count int64
  612. var sum_in_count int64
  613. for _, it := range list {
  614. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  615. if it.MaxUnit == baseDrug.MaxUnit {
  616. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  617. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  618. }
  619. sum_count += it.StockMaxNumber + it.StockMinNumber
  620. sum_in_count += it.WarehousingCount
  621. }
  622. service.UpdateMedicalSumCount(it.DrugId, sum_count, sum_in_count, it.OrgId)
  623. }
  624. if err != nil {
  625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  626. } else {
  627. c.ServeSuccessJSON(map[string]interface{}{
  628. "msg": "删除成功",
  629. })
  630. }
  631. }
  632. func (c *StockDrugApiController) DeleteDrugWarehouseInfo() {
  633. id, _ := c.GetInt64("id", 0)
  634. if id == 0 {
  635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  636. return
  637. }
  638. err := service.UpDateDrugWarehouseStatus(id)
  639. service.UpdateDrugFlowById(id)
  640. var sum_total int64
  641. list, _ := service.GetDrugWarehouseInfoByIdTwenty(id)
  642. medical, _ := service.GetBaseDrugMedical(list.DrugId)
  643. sum_total += list.StockMaxNumber*medical.MinNumber + list.StockMinNumber
  644. storeConfig, _ := service.GetAllStoreHouseConfig(list.OrgId)
  645. if storeConfig.DrugStorehouseInfo == list.StorehouseId {
  646. service.ModifyDrugReduceInformationTwo(list.DrugId, sum_total, list.OrgId)
  647. }
  648. if err != nil {
  649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  650. } else {
  651. c.ServeSuccessJSON(map[string]interface{}{
  652. "msg": "删除成功",
  653. })
  654. }
  655. }
  656. func (c *StockDrugApiController) CreateDrugSalesReturn() {
  657. dealer_id, _ := c.GetInt64("dealer_id", 0)
  658. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  659. sales_return_time := c.GetString("time")
  660. types, _ := c.GetInt64("type", 0)
  661. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  662. if parseDateErr != nil {
  663. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  665. return
  666. }
  667. adminUserInfo := c.GetAdminUserInfo()
  668. operation_time := time.Now().Unix()
  669. creater := adminUserInfo.AdminUser.Id
  670. ctime := time.Now().Unix()
  671. timeStr := time.Now().Format("2006-01-02")
  672. timeArr := strings.Split(timeStr, "-")
  673. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  674. total = total + 1
  675. orderNumber := "YPTHD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  676. salesReturn := models.DrugSalesReturn{
  677. OrderNumber: orderNumber,
  678. OperaTime: operation_time,
  679. OrgId: adminUserInfo.CurrentOrgId,
  680. Creater: creater,
  681. Ctime: ctime,
  682. Status: 1,
  683. ReturnTime: salesReturnDate.Unix(),
  684. Dealer: dealer_id,
  685. Manufacturer: manufacturer_id,
  686. Type: types,
  687. }
  688. service.AddSigleDrugSalesReturn(&salesReturn)
  689. dataBody := make(map[string]interface{}, 0)
  690. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  691. if err != nil {
  692. utils.ErrorLog(err.Error())
  693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  694. return
  695. }
  696. var salesReturnInfos []*models.DrugSalesReturnInfo
  697. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  698. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  699. if len(thisStockIn) > 0 {
  700. for _, item := range thisStockIn {
  701. items := item.(map[string]interface{})
  702. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  703. utils.ErrorLog("drug_id")
  704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  705. return
  706. }
  707. drug_id := int64(items["drug_id"].(float64))
  708. return_count, _ := items["return_count"].(string)
  709. if len(return_count) == 0 {
  710. utils.ErrorLog("len(return_count) == 0")
  711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  712. return
  713. }
  714. count, _ := strconv.ParseInt(return_count, 10, 64)
  715. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  716. utils.ErrorLog("price")
  717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  718. return
  719. }
  720. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  721. total := float64(count) * price
  722. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  723. utils.ErrorLog("retail_price")
  724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  725. return
  726. }
  727. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  728. retail_price_total := float64(count) * retail_price
  729. salesReturnInfo := &models.DrugSalesReturnInfo{
  730. OrderNumber: salesReturn.OrderNumber,
  731. SalesReturnId: salesReturn.ID,
  732. DrugId: drug_id,
  733. Count: count,
  734. Price: price,
  735. Total: total,
  736. Status: 1,
  737. Ctime: ctime,
  738. OrgId: adminUserInfo.CurrentOrgId,
  739. Type: types,
  740. Manufacturer: manufacturer_id,
  741. Dealer: dealer_id,
  742. RetailPrice: retail_price,
  743. RetailTotalPrice: retail_price_total,
  744. }
  745. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  746. }
  747. }
  748. }
  749. errs := service.CreateDrugSalesReturnInfo(salesReturnInfos)
  750. if errs != nil {
  751. utils.ErrorLog(errs.Error())
  752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateReturnFail)
  753. return
  754. }
  755. c.ServeSuccessJSON(map[string]interface{}{
  756. "msg": "退货成功",
  757. })
  758. }
  759. func (c *StockDrugApiController) GetDrugSalesReturnList() {
  760. page, _ := c.GetInt64("page", -1)
  761. limit, _ := c.GetInt64("limit", -1)
  762. start_time := c.GetString("start_time")
  763. end_time := c.GetString("end_time")
  764. types, _ := c.GetInt64("type", 0)
  765. keywords := c.GetString("keywords")
  766. timeLayout := "2006-01-02"
  767. loc, _ := time.LoadLocation("Local")
  768. var startTime int64
  769. if len(start_time) > 0 {
  770. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  771. if err != nil {
  772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  773. return
  774. }
  775. startTime = theTime.Unix()
  776. }
  777. var endTime int64
  778. if len(end_time) > 0 {
  779. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  780. if err != nil {
  781. utils.ErrorLog(err.Error())
  782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  783. return
  784. }
  785. endTime = theTime.Unix()
  786. }
  787. adminUserInfo := c.GetAdminUserInfo()
  788. returnList, total, err := service.FindAllDrugReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  789. if err == nil {
  790. c.ServeSuccessJSON(map[string]interface{}{
  791. "list": returnList,
  792. "total": total,
  793. })
  794. } else {
  795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  796. }
  797. }
  798. func (this *StockDrugApiController) DeleteDrugSalesReturn() {
  799. ids := this.GetString("ids")
  800. if len(ids) == 0 {
  801. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  802. return
  803. }
  804. idArray := strings.Split(ids, ",")
  805. err := service.DeleteDrugSalesReturn(idArray)
  806. if err != nil {
  807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  808. } else {
  809. this.ServeSuccessJSON(map[string]interface{}{
  810. "msg": "删除成功",
  811. })
  812. }
  813. }
  814. func (this *StockDrugApiController) DeleteDrugSalesReturnInfo() {
  815. id, _ := this.GetInt64("id", 0)
  816. fmt.Println(id)
  817. if id == 0 {
  818. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  819. return
  820. }
  821. err := service.UpDateDrugSaleReturnStatus(id)
  822. if err != nil {
  823. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  824. } else {
  825. this.ServeSuccessJSON(map[string]interface{}{
  826. "msg": "删除成功",
  827. })
  828. }
  829. }
  830. func (this *StockDrugApiController) GetDrugSalesReturnInfoList() {
  831. id, _ := this.GetInt64("id", 0)
  832. adminUserInfo := this.GetAdminUserInfo()
  833. list, _ := service.FindAllDrugSalesReturnInfoById(id, adminUserInfo.CurrentOrgId)
  834. salesReturn, _ := service.FindAllDrugSalesReturnById(id, adminUserInfo.CurrentOrgId)
  835. this.ServeSuccessJSON(map[string]interface{}{
  836. "list": list,
  837. "salesReturn": salesReturn,
  838. })
  839. }
  840. func (c *StockDrugApiController) EditDrugReturnInfo() {
  841. return_time := c.GetString("return_time")
  842. id, _ := c.GetInt64("id", 0)
  843. types, _ := c.GetInt64("type", 0)
  844. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  845. dealer_id, _ := c.GetInt64("dealer_id", 0)
  846. if id == 0 {
  847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  848. return
  849. }
  850. ctime := time.Now().Unix()
  851. mtime := time.Now().Unix()
  852. adminUserInfo := c.GetAdminUserInfo()
  853. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  854. if parseDateErr != nil {
  855. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. return
  858. }
  859. salesReturns, _ := service.FindDrugSalesReturnById(id)
  860. sales := models.DrugSalesReturn{
  861. ID: salesReturns.ID,
  862. Mtime: mtime,
  863. ReturnTime: returnDate.Unix(),
  864. Manufacturer: manufacturer_id,
  865. Dealer: dealer_id,
  866. }
  867. service.EditDrugSaleReturn(sales)
  868. dataBody := make(map[string]interface{}, 0)
  869. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  870. if err != nil {
  871. utils.ErrorLog(err.Error())
  872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  873. return
  874. }
  875. var returnInfos []*models.DrugSalesReturnInfo
  876. var upDateReturnInfos []*models.DrugSalesReturnInfo
  877. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  878. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  879. if len(thisStockIn) > 0 {
  880. for _, item := range thisStockIn {
  881. items := item.(map[string]interface{})
  882. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  883. utils.ErrorLog("drug_id")
  884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  885. return
  886. }
  887. drug_id := int64(items["drug_id"].(float64))
  888. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  889. utils.ErrorLog("count")
  890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  891. return
  892. }
  893. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  894. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  895. utils.ErrorLog("id")
  896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  897. return
  898. }
  899. id := int64(items["id"].(float64))
  900. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  901. utils.ErrorLog("price")
  902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  903. return
  904. }
  905. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  906. total := float64(count) * price
  907. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  908. utils.ErrorLog("retail_price")
  909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  910. return
  911. }
  912. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  913. retail_price_total := float64(count) * retail_price
  914. if id == 0 {
  915. returnInfo := &models.DrugSalesReturnInfo{
  916. DrugId: drug_id,
  917. Count: count,
  918. Status: 1,
  919. Ctime: ctime,
  920. OrgId: adminUserInfo.CurrentOrgId,
  921. OrderNumber: sales.OrderNumber,
  922. SalesReturnId: sales.ID,
  923. Mtime: time.Now().Unix(),
  924. Type: types,
  925. Manufacturer: manufacturer_id,
  926. Dealer: dealer_id,
  927. RetailPrice: retail_price,
  928. RetailTotalPrice: retail_price_total,
  929. Total: total,
  930. Price: price,
  931. }
  932. returnInfos = append(returnInfos, returnInfo)
  933. } else {
  934. returnInfo := &models.DrugSalesReturnInfo{
  935. ID: id,
  936. DrugId: drug_id,
  937. Count: count,
  938. Status: 1,
  939. Ctime: ctime,
  940. OrgId: adminUserInfo.CurrentOrgId,
  941. OrderNumber: sales.OrderNumber,
  942. SalesReturnId: sales.ID,
  943. Mtime: time.Now().Unix(),
  944. Type: types,
  945. Manufacturer: manufacturer_id,
  946. Dealer: dealer_id,
  947. RetailPrice: retail_price,
  948. RetailTotalPrice: retail_price_total,
  949. Total: total,
  950. Price: price,
  951. }
  952. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  953. }
  954. }
  955. }
  956. }
  957. var errs error
  958. if len(returnInfos) > 0 {
  959. errs = service.CreateDrugSalesReturnInfo(returnInfos)
  960. }
  961. if len(upDateReturnInfos) > 0 {
  962. for _, item := range upDateReturnInfos {
  963. errs = service.UpDateDrugSalesReturnInfo(item)
  964. }
  965. }
  966. if errs != nil {
  967. utils.ErrorLog(errs.Error())
  968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateReturnFail)
  969. return
  970. }
  971. c.ServeSuccessJSON(map[string]interface{}{
  972. "msg": "编辑成功",
  973. })
  974. }
  975. func (c *StockDrugApiController) CreateDrugWarehouseOut() {
  976. types, _ := c.GetInt64("type", 0)
  977. storehouse_id, _ := c.GetInt64("storehouse_id")
  978. warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
  979. ctime := time.Now().Unix()
  980. adminUserInfo := c.GetAdminUserInfo()
  981. warehousing_out_time := c.GetString("warehousing_out_time")
  982. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  983. if parseDateErr != nil {
  984. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  986. return
  987. }
  988. timeStr := time.Now().Format("2006-01-02")
  989. timeArr := strings.Split(timeStr, "-")
  990. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  991. total = total + 1
  992. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  993. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  994. number = number + total
  995. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  996. operation_time := time.Now().Unix()
  997. creater := adminUserInfo.AdminUser.Id
  998. //创建一个出库单
  999. warehouseOut := models.DrugWarehouseOut{
  1000. WarehouseOutOrderNumber: warehousing_out_order,
  1001. OperationTime: operation_time,
  1002. OrgId: adminUserInfo.CurrentOrgId,
  1003. Creater: creater,
  1004. Ctime: ctime,
  1005. Status: 1,
  1006. WarehouseOutTime: warehousingOutDate.Unix(),
  1007. Type: types,
  1008. StorehouseId: storehouse_id,
  1009. IsCheck: 2,
  1010. }
  1011. fmt.Println("warehouse_out_id232323322323232323233223", warehouse_out_id)
  1012. if warehouse_out_id == 0 {
  1013. service.AddSigleDrugWarehouseOut(&warehouseOut)
  1014. }
  1015. if warehouse_out_id > 0 {
  1016. service.UpdateSingleDrugWarehouseOut(warehouse_out_id, storehouse_id)
  1017. }
  1018. lastWarehouseOut, _ := service.GetDrugLastWarehouseOut(adminUserInfo.CurrentOrgId)
  1019. dataBody := make(map[string]interface{}, 0)
  1020. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1021. if err != nil {
  1022. utils.ErrorLog(err.Error())
  1023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1024. return
  1025. }
  1026. //出库单详情
  1027. var warehousingOutInfo []*models.DrugWarehouseOutInfo
  1028. //把前端的参数加工为出库单详情
  1029. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1030. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  1031. if len(thisStockIn) > 0 {
  1032. for _, item := range thisStockIn {
  1033. items := item.(map[string]interface{})
  1034. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1035. utils.ErrorLog("drug_id")
  1036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1037. return
  1038. }
  1039. drug_id := int64(items["drug_id"].(float64))
  1040. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1041. utils.ErrorLog("count")
  1042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1043. return
  1044. }
  1045. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1046. utils.ErrorLog("price")
  1047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1048. return
  1049. }
  1050. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1051. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1052. total := float64(count) * price
  1053. retail_price_total := float64(count) * price
  1054. remark := items["remark"].(string)
  1055. max_unit := items["max_unit"].(string)
  1056. dealer := int64(items["dealer"].(float64))
  1057. manufacturer := int64(items["manufacturer"].(float64))
  1058. number := items["number"].(string)
  1059. batch_number := items["batch_number"].(string)
  1060. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1061. var productDates int64
  1062. var expiryDates int64
  1063. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1064. expiryDates = 0
  1065. } else {
  1066. if len(items["expiry_date"].(string)) == 0 {
  1067. expiryDates = 0
  1068. } else {
  1069. expiryDate, _ := items["expiry_date"].(string)
  1070. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1071. expiryDates = expiry_date.Unix()
  1072. }
  1073. }
  1074. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1075. productDates = 0
  1076. } else {
  1077. if len(items["product_date"].(string)) == 0 {
  1078. productDates = 0
  1079. } else {
  1080. productDate, _ := items["product_date"].(string)
  1081. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1082. productDates = product_date.Unix()
  1083. }
  1084. }
  1085. admin_user_id := int64(items["admin_user_id"].(float64))
  1086. //if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1087. // utils.ErrorLog("last_price")
  1088. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1089. // return
  1090. //}
  1091. //last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1092. stock_count, _ := items["stock_count"].(string)
  1093. id := int64(items["id"].(float64))
  1094. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1095. ID: id,
  1096. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1097. WarehouseOutId: lastWarehouseOut.ID,
  1098. DrugId: drug_id,
  1099. Count: count,
  1100. Price: price,
  1101. TotalPrice: total,
  1102. Status: 1,
  1103. Ctime: ctime,
  1104. Remark: remark,
  1105. OrgId: adminUserInfo.CurrentOrgId,
  1106. Type: types,
  1107. Manufacturer: manufacturer,
  1108. Dealer: dealer,
  1109. RetailPrice: price,
  1110. RetailTotalPrice: retail_price_total,
  1111. CountUnit: max_unit,
  1112. ExpiryDate: expiryDates,
  1113. ProductDate: productDates,
  1114. Number: number,
  1115. BatchNumber: batch_number,
  1116. IsSys: 0,
  1117. WarehouseInfoId: warehouse_info_id,
  1118. StorehouseId: storehouse_id,
  1119. AdminUserId: admin_user_id,
  1120. StockCount: stock_count,
  1121. IsCheck: 2,
  1122. }
  1123. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1124. }
  1125. }
  1126. }
  1127. //var total_count int64 //总库存
  1128. //var prescribing_number_total int64 //出库数据
  1129. //调用出库逻辑
  1130. for _, item := range warehousingOutInfo {
  1131. if item.ID == 0 {
  1132. errOne := service.AddSigleDrugWarehouseOutInfo(item)
  1133. fmt.Println(errOne)
  1134. }
  1135. if item.ID > 0 {
  1136. service.UpdatedDrugWarehouseInfo(item, item.ID)
  1137. }
  1138. }
  1139. list, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  1140. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  1141. warehousingOutInfoList, _ := service.GetDrugWarehouseOutListById(lastWarehouseOut.ID, adminUserInfo.CurrentOrgId)
  1142. var drugType = "药品类型"
  1143. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1144. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminUserInfo.CurrentOrgId)
  1145. c.ServeSuccessJSON(map[string]interface{}{
  1146. "msg": "2",
  1147. "drug_name": "",
  1148. "dose": "",
  1149. "dose_unit": "",
  1150. "min_number": "",
  1151. "min_unit": "",
  1152. "max_unit": "",
  1153. "dealerList": list,
  1154. "manufacturerList": manufacturerList,
  1155. "warehousingOutInfo": warehousingOutInfoList,
  1156. "warehouseOut": lastWarehouseOut,
  1157. "drugTypeList": drugTypeList,
  1158. })
  1159. return
  1160. }
  1161. func (c *StockDrugApiController) GetDrugWarehouseOutList() {
  1162. page, _ := c.GetInt64("page", -1)
  1163. limit, _ := c.GetInt64("limit", -1)
  1164. start_time := c.GetString("start_time")
  1165. end_time := c.GetString("end_time")
  1166. types, _ := c.GetInt64("type", 0)
  1167. keywords := c.GetString("keywords")
  1168. storehouse_id, _ := c.GetInt64("storehouse_id")
  1169. way_type, _ := c.GetInt64("way_type")
  1170. check_type, _ := c.GetInt64("check_type")
  1171. timeLayout := "2006-01-02"
  1172. loc, _ := time.LoadLocation("Local")
  1173. var startTime int64
  1174. if len(start_time) > 0 {
  1175. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1176. if err != nil {
  1177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1178. return
  1179. }
  1180. startTime = theTime.Unix()
  1181. }
  1182. var endTime int64
  1183. if len(end_time) > 0 {
  1184. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1185. if err != nil {
  1186. utils.ErrorLog(err.Error())
  1187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1188. return
  1189. }
  1190. endTime = theTime.Unix()
  1191. }
  1192. adminUserInfo := c.GetAdminUserInfo()
  1193. var ids []int64
  1194. var goodids []int64
  1195. if len(keywords) > 0 {
  1196. //查询商品名称
  1197. list, _ := service.GetDrugNameByKeyword(keywords, adminUserInfo.CurrentOrgId)
  1198. for _, item := range list {
  1199. goodids = append(goodids, item.ID)
  1200. }
  1201. if len(goodids) > 0 {
  1202. //出库详情但里面查询
  1203. info, _ := service.GetDrugWarehouseOrderDetail(goodids, adminUserInfo.CurrentOrgId, startTime, endTime, storehouse_id)
  1204. for _, it := range info {
  1205. ids = append(ids, it.WarehouseOutId)
  1206. }
  1207. }
  1208. }
  1209. warehouseOutList, total, err := service.FindAllDrugWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids, storehouse_id, way_type, check_type)
  1210. fmt.Println("warehouseOutList232332323232323", warehouseOutList)
  1211. houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  1212. fmt.Println(err)
  1213. if err == nil {
  1214. c.ServeSuccessJSON(map[string]interface{}{
  1215. "list": warehouseOutList,
  1216. "total": total,
  1217. "houseList": houseList,
  1218. })
  1219. } else {
  1220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1221. }
  1222. }
  1223. func (c *StockDrugApiController) DeleteDrugWarehouseOut() {
  1224. ids := c.GetString("ids")
  1225. if len(ids) == 0 {
  1226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1227. return
  1228. }
  1229. idArray := strings.Split(ids, ",")
  1230. err := service.DeleteDrugWarehouseOut(idArray)
  1231. //list, _ := service.GetDrugWarhouseOutByIds(idArray)
  1232. //for _, item := range list {
  1233. // medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1234. // if item.CountUnit == medical.MaxUnit {
  1235. //
  1236. // service.UpdateDrugInfoByIds(item.WarehouseInfoId, item.Count)
  1237. //
  1238. // }
  1239. // if medical.MaxUnit != medical.MinUnit && item.CountUnit == medical.MinUnit {
  1240. // service.UpdateDrugInfoByIdsOne(item.WarehouseInfoId, item.Count)
  1241. // }
  1242. //
  1243. // //查询默认仓库
  1244. // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
  1245. // //查询默认仓库剩余多少库存
  1246. // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
  1247. // var sum_count int64
  1248. // var sum_in_count int64
  1249. // for _, it := range list {
  1250. // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  1251. // if it.MaxUnit == baseDrug.MaxUnit {
  1252. // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  1253. // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  1254. // }
  1255. // sum_count += it.StockMaxNumber + it.StockMinNumber
  1256. // sum_in_count += it.WarehousingCount
  1257. // }
  1258. // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
  1259. //}
  1260. if err != nil {
  1261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1262. } else {
  1263. c.ServeSuccessJSON(map[string]interface{}{
  1264. "msg": "删除成功",
  1265. })
  1266. }
  1267. }
  1268. func (this *StockDrugApiController) DeleteDrugWarehouseOutInfo() {
  1269. id, _ := this.GetInt64("id", 0)
  1270. if id == 0 {
  1271. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1272. return
  1273. }
  1274. ////查询详情
  1275. //info, _ := service.GetDrugWarehosueOutInfo(id)
  1276. //
  1277. ////查询默认仓库
  1278. //houseConfig, _ := service.GetAllStoreHouseConfig(info.OrgId)
  1279. ////查询默认仓库剩余多少库存
  1280. //list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, info.OrgId, info.DrugId)
  1281. //
  1282. //for _, it := range list {
  1283. //
  1284. // //查询默认仓库
  1285. // houseConfig, _ := service.GetAllStoreHouseConfig(it.OrgId)
  1286. // //查询默认仓库剩余多少库存
  1287. // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, it.OrgId, it.DrugId)
  1288. // var sum_count int64
  1289. // var sum_in_count int64
  1290. // for _, it := range list {
  1291. // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  1292. // if it.MaxUnit == baseDrug.MaxUnit {
  1293. // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  1294. // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  1295. // }
  1296. // sum_count += it.StockMaxNumber + it.StockMinNumber
  1297. // sum_in_count += it.WarehousingCount
  1298. // }
  1299. // service.UpdateMedicalSumCount(it.DrugId, sum_count, sum_in_count, it.OrgId)
  1300. //
  1301. //}
  1302. //删除流水
  1303. //service.DeleteDrugWarehouseOutInfoById(info.ID)
  1304. err := service.UpDateDrugWarehouseOutStatus(id)
  1305. if err != nil {
  1306. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1307. } else {
  1308. this.ServeSuccessJSON(map[string]interface{}{
  1309. "msg": "删除成功",
  1310. })
  1311. }
  1312. }
  1313. func (c *StockDrugApiController) GetDrugWarehouseOutInfoList() {
  1314. id, _ := c.GetInt64("id", 0)
  1315. adminInfo := c.GetAdminUserInfo()
  1316. warehouseOutInfo, _ := service.FindDrugWarehouseOutInfoById(id, adminInfo.CurrentOrgId)
  1317. warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminInfo.CurrentOrgId)
  1318. manulist, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1319. dealerList, _ := service.GetAllDealerList(adminInfo.CurrentOrgId)
  1320. houstList, _ := service.GetAllStoreHouseList(adminInfo.CurrentOrgId)
  1321. appId := c.GetAdminUserInfo().CurrentAppId
  1322. doctorList, _ := service.GetAllDoctorListSix(adminInfo.CurrentOrgId, appId)
  1323. c.ServeSuccessJSON(map[string]interface{}{
  1324. "list": warehouseOutInfo,
  1325. "info": warehouseOut,
  1326. "manulist": manulist,
  1327. "dealerList": dealerList,
  1328. "houstList": houstList,
  1329. "doctorList": doctorList,
  1330. })
  1331. }
  1332. func (c *StockDrugApiController) EditDrugWarehouseOut() {
  1333. warehouse_out_time := c.GetString("warehouse_out_time")
  1334. id, _ := c.GetInt64("id", 0)
  1335. types, _ := c.GetInt64("type", 0)
  1336. storehouse_id, _ := c.GetInt64("storehouse_id")
  1337. if id == 0 {
  1338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1339. return
  1340. }
  1341. ctime := time.Now().Unix()
  1342. mtime := time.Now().Unix()
  1343. adminUserInfo := c.GetAdminUserInfo()
  1344. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1345. if parseDateErr != nil {
  1346. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1347. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1348. return
  1349. }
  1350. warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminUserInfo.CurrentOrgId)
  1351. tempWarehouseOut := models.DrugWarehouseOut{
  1352. ID: warehouseOut.ID,
  1353. Mtime: mtime,
  1354. WarehouseOutTime: warehouseOutDate.Unix(),
  1355. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1356. StorehouseId: storehouse_id,
  1357. }
  1358. service.EditDrugWarehouseOut(tempWarehouseOut)
  1359. dataBody := make(map[string]interface{}, 0)
  1360. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1361. if err != nil {
  1362. utils.ErrorLog(err.Error())
  1363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1364. return
  1365. }
  1366. var warehousingOutInfo []*models.DrugWarehouseOutInfo
  1367. var upDateWarehouseOutInfos []*models.DrugWarehouseOutInfo
  1368. var drugFlow []*models.DrugFlow
  1369. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1370. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1371. if len(thisStockOut) > 0 {
  1372. for _, item := range thisStockOut {
  1373. items := item.(map[string]interface{})
  1374. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1375. utils.ErrorLog("drug_id")
  1376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1377. return
  1378. }
  1379. drug_id := int64(items["drug_id"].(float64))
  1380. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1381. utils.ErrorLog("count")
  1382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1383. return
  1384. }
  1385. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1386. count_unit, _ := items["count_unit"].(string)
  1387. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1388. utils.ErrorLog("price")
  1389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1390. return
  1391. }
  1392. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1393. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1394. utils.ErrorLog("retail_price")
  1395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1396. return
  1397. }
  1398. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1399. total := float64(count) * price
  1400. retail_price_total := float64(count) * retail_price
  1401. remark := items["remark"].(string)
  1402. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1403. utils.ErrorLog("id")
  1404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1405. return
  1406. }
  1407. id := int64(items["id"].(float64))
  1408. dealer := int64(items["dealer"].(float64))
  1409. manufacturer := int64(items["manufacturer"].(float64))
  1410. batch_number := items["batch_number"].(string)
  1411. number := items["number"].(string)
  1412. max_unit := items["count_unit"].(string)
  1413. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1414. var productDates int64
  1415. var expiryDates int64
  1416. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1417. expiryDates = 0
  1418. } else {
  1419. if len(items["expiry_date"].(string)) == 0 {
  1420. expiryDates = 0
  1421. } else {
  1422. expiryDate, _ := items["expiry_date"].(string)
  1423. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1424. expiryDates = expiry_date.Unix()
  1425. }
  1426. }
  1427. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1428. productDates = 0
  1429. } else {
  1430. if len(items["product_date"].(string)) == 0 {
  1431. productDates = 0
  1432. } else {
  1433. productDate, _ := items["product_date"].(string)
  1434. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1435. productDates = product_date.Unix()
  1436. }
  1437. }
  1438. admin_user_id := int64(items["admin_user_id"].(float64))
  1439. //if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1440. // utils.ErrorLog("last_price")
  1441. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1442. // return
  1443. //}
  1444. //last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1445. stock_count, _ := items["stock_count"].(string)
  1446. if id == 0 {
  1447. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1448. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1449. WarehouseOutId: warehouseOut.ID,
  1450. DrugId: drug_id,
  1451. Count: count,
  1452. Price: price,
  1453. TotalPrice: total,
  1454. Status: 1,
  1455. Ctime: ctime,
  1456. Remark: remark,
  1457. OrgId: adminUserInfo.CurrentOrgId,
  1458. Type: types,
  1459. Manufacturer: manufacturer,
  1460. Dealer: dealer,
  1461. IsSys: 0,
  1462. SysRecordTime: 0,
  1463. RetailPrice: retail_price,
  1464. RetailTotalPrice: retail_price_total,
  1465. BatchNumber: batch_number,
  1466. Number: number,
  1467. ProductDate: productDates,
  1468. ExpiryDate: expiryDates,
  1469. CountUnit: count_unit,
  1470. WarehouseInfoId: warehouse_info_id,
  1471. StorehouseId: storehouse_id,
  1472. AdminUserId: admin_user_id,
  1473. StockCount: stock_count,
  1474. }
  1475. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1476. drugflow := &models.DrugFlow{
  1477. WarehousingOrder: "",
  1478. WarehousingId: 0,
  1479. DrugId: drug_id,
  1480. Number: number,
  1481. ProductDate: productDates,
  1482. ExpireDate: expiryDates,
  1483. Count: count,
  1484. Price: price,
  1485. Status: 1,
  1486. Ctime: ctime,
  1487. UserOrgId: adminUserInfo.CurrentOrgId,
  1488. Manufacturer: manufacturer,
  1489. Dealer: dealer,
  1490. BatchNumber: batch_number,
  1491. MaxUnit: max_unit,
  1492. ConsumableType: 1,
  1493. IsEdit: 1,
  1494. Creator: adminUserInfo.AdminUser.Id,
  1495. IsSys: 0,
  1496. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1497. WarehouseOutId: id,
  1498. StorehouseId: storehouse_id,
  1499. AdminUserId: admin_user_id,
  1500. StockCount: stock_count,
  1501. }
  1502. drugFlow = append(drugFlow, drugflow)
  1503. } else {
  1504. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1505. utils.ErrorLog("is_sys")
  1506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1507. return
  1508. }
  1509. is_sys := int64(items["is_sys"].(float64))
  1510. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1511. utils.ErrorLog("sys_record_time")
  1512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1513. return
  1514. }
  1515. sys_record_time := int64(items["sys_record_time"].(float64))
  1516. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1517. ID: id,
  1518. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1519. WarehouseOutId: warehouseOut.ID,
  1520. DrugId: drug_id,
  1521. Count: count,
  1522. Price: price,
  1523. TotalPrice: total,
  1524. Status: 1,
  1525. Ctime: ctime,
  1526. Remark: remark,
  1527. OrgId: adminUserInfo.CurrentOrgId,
  1528. Mtime: time.Now().Unix(),
  1529. Type: types,
  1530. Manufacturer: manufacturer,
  1531. Dealer: dealer,
  1532. IsSys: is_sys,
  1533. SysRecordTime: sys_record_time,
  1534. RetailPrice: retail_price,
  1535. RetailTotalPrice: retail_price_total,
  1536. BatchNumber: batch_number,
  1537. Number: number,
  1538. ProductDate: productDates,
  1539. ExpiryDate: expiryDates,
  1540. CountUnit: count_unit,
  1541. WarehouseInfoId: warehouse_info_id,
  1542. StorehouseId: storehouse_id,
  1543. AdminUserId: admin_user_id,
  1544. StockCount: stock_count,
  1545. }
  1546. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1547. drugflow := &models.DrugFlow{
  1548. WarehousingOrder: "",
  1549. WarehousingId: 0,
  1550. DrugId: drug_id,
  1551. Number: number,
  1552. ProductDate: productDates,
  1553. ExpireDate: expiryDates,
  1554. Count: count,
  1555. Price: price,
  1556. Status: 1,
  1557. Ctime: ctime,
  1558. UserOrgId: adminUserInfo.CurrentOrgId,
  1559. Manufacturer: manufacturer,
  1560. Dealer: dealer,
  1561. BatchNumber: batch_number,
  1562. MaxUnit: max_unit,
  1563. ConsumableType: 1,
  1564. IsEdit: 1,
  1565. Creator: adminUserInfo.AdminUser.Id,
  1566. IsSys: 0,
  1567. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1568. WarehouseOutId: warehouseOut.ID,
  1569. StorehouseId: storehouse_id,
  1570. AdminUserId: admin_user_id,
  1571. StockCount: stock_count,
  1572. }
  1573. drugFlow = append(drugFlow, drugflow)
  1574. }
  1575. }
  1576. }
  1577. }
  1578. var errs error
  1579. if len(warehousingOutInfo) > 0 {
  1580. //var total_count int64
  1581. //var prescribing_number_total int64
  1582. //调用出库逻辑
  1583. for _, item := range warehousingOutInfo {
  1584. errOnes := service.AddSigleDrugWarehouseOutInfo(item)
  1585. fmt.Println("errone", errOnes)
  1586. ////获取药品库存
  1587. //info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId, storehouse_id)
  1588. ////查询改药品信息
  1589. //medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1590. ////判断单位是否相等
  1591. //if medical.MaxUnit == item.CountUnit {
  1592. // //转化为最小单位
  1593. // total_count = info.Count * medical.MinNumber
  1594. // prescribing_number_total = item.Count * medical.MinNumber
  1595. //}
  1596. //if medical.MinUnit == item.CountUnit {
  1597. // total_count = info.Count
  1598. // prescribing_number_total = item.Count
  1599. //}
  1600. //
  1601. ////判断单位
  1602. //if total_count == 0 {
  1603. // goodObj, _ := service.GetDrugByGoodId(item.DrugId)
  1604. // c.ServeSuccessJSON(map[string]interface{}{
  1605. // "msg": "1",
  1606. // "drug_name": goodObj.DrugName,
  1607. // "dose": goodObj.Dose,
  1608. // "dose_unit": goodObj.DoseUnit,
  1609. // "min_number": goodObj.MinNumber,
  1610. // "min_unit": goodObj.MinUnit,
  1611. // "max_unit": goodObj.MaxUnit,
  1612. // })
  1613. // return
  1614. //}
  1615. //if prescribing_number_total > total_count {
  1616. //
  1617. // goodObj, _ := service.GetDrugByGoodId(item.DrugId)
  1618. // c.ServeSuccessJSON(map[string]interface{}{
  1619. // "msg": "1",
  1620. // "drug_name": goodObj.DrugName,
  1621. // "dose": goodObj.Dose,
  1622. // "dose_unit": goodObj.DoseUnit,
  1623. // "min_number": goodObj.MinNumber,
  1624. // "min_unit": goodObj.MinUnit,
  1625. // "max_unit": goodObj.MaxUnit,
  1626. // })
  1627. // return
  1628. //} else {
  1629. //
  1630. // // 出库流程
  1631. // // 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
  1632. // drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
  1633. // if drup.ID > 0 {
  1634. // prescribingNumber := item.Count
  1635. // service.AutoDrugDeliverInfoTwentyOne(item.OrgId, prescribingNumber, &tempWarehouseOut, &drup, item)
  1636. // }
  1637. //}
  1638. }
  1639. }
  1640. if len(upDateWarehouseOutInfos) > 0 {
  1641. for _, item := range upDateWarehouseOutInfos {
  1642. service.UpdatedDrugWarehouseInfo(item, item.ID)
  1643. ////获取药品库存
  1644. //info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId, storehouse_id)
  1645. ////查询改药品信息
  1646. //medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1647. ////查询最后一次出库记录
  1648. //outInfo, _ := service.GetLastDrugWarehouseOutInfo(item.DrugId, item.WarehouseOutId, item.OrgId)
  1649. //var min_number int64 //最后一次出库数量
  1650. //var max_number int64 //当前出库数量
  1651. //var all_number int64 //总库存
  1652. //var cha_number int64 //库存差
  1653. //var maxNumber int64
  1654. //var minNumber int64
  1655. //
  1656. //if medical.MaxUnit == outInfo.CountUnit {
  1657. // //转为最小单位
  1658. // min_number = outInfo.Count * medical.MinNumber
  1659. //}
  1660. //
  1661. //if medical.MinUnit == outInfo.CountUnit {
  1662. // min_number = outInfo.Count
  1663. //}
  1664. //
  1665. //if medical.MaxUnit == item.CountUnit {
  1666. // max_number = item.Count * medical.MinNumber
  1667. //}
  1668. //
  1669. //if medical.MinUnit == item.CountUnit {
  1670. // max_number = item.Count
  1671. //}
  1672. //
  1673. //all_number = info.Count*medical.MinNumber + info.StockMinNumber
  1674. //
  1675. ////比较当前出库数量 小于等于 最后一次出库数量,则需要退库
  1676. //if max_number <= min_number {
  1677. // errs = service.UpDateDrugWarehouseOutInfo(item)
  1678. // flow := models.DrugFlow{
  1679. // Count: max_number,
  1680. // ExpireDate: item.ExpiryDate,
  1681. // ProductDate: item.ProductDate,
  1682. // Price: item.Price,
  1683. // Manufacturer: item.Manufacturer,
  1684. // Dealer: item.Dealer,
  1685. // Number: item.Number,
  1686. // WarehouseOutId: item.WarehouseOutId,
  1687. // StorehouseId: item.StorehouseId,
  1688. // AdminUserId: item.AdminUserId,
  1689. // StockCount: item.StockCount,
  1690. // }
  1691. // service.UpdateDrugFlowSix(item.WarehouseOutId, item.DrugId, item.WarehouseOutOrderNumber, flow)
  1692. // cha_number = min_number - max_number
  1693. //
  1694. // if item.CountUnit == medical.MaxUnit {
  1695. // maxNumber = cha_number / medical.MinNumber
  1696. //
  1697. // parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId, outInfo.WarehouseInfoId)
  1698. //
  1699. // if parseDateErr != nil {
  1700. // utils.ErrorLog(errs.Error())
  1701. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1702. // return
  1703. // }
  1704. //
  1705. // c.ServeSuccessJSON(map[string]interface{}{
  1706. // "msg": "2",
  1707. // "drug_name": "",
  1708. // "dose": "",
  1709. // "dose_unit": "",
  1710. // "min_number": "",
  1711. // "min_unit": "",
  1712. // "max_unit": "",
  1713. // })
  1714. // minNumber = cha_number % medical.MinNumber
  1715. // if minNumber < 0 {
  1716. // minNumber = 0
  1717. // }
  1718. // parseDateErr = service.UpdateWarehouseInfoOne(minNumber, item.DrugId, item.OrgId, outInfo.WarehouseInfoId)
  1719. //
  1720. // if parseDateErr != nil {
  1721. // utils.ErrorLog(errs.Error())
  1722. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1723. // return
  1724. // }
  1725. //
  1726. // c.ServeSuccessJSON(map[string]interface{}{
  1727. // "msg": "2",
  1728. // "drug_name": "",
  1729. // "dose": "",
  1730. // "dose_unit": "",
  1731. // "min_number": "",
  1732. // "min_unit": "",
  1733. // "max_unit": "",
  1734. // })
  1735. // }
  1736. // if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1737. // parseDateErr := service.UpdateWarehouseInfoOne(cha_number, item.DrugId, item.OrgId, outInfo.WarehouseInfoId)
  1738. //
  1739. // if parseDateErr != nil {
  1740. // utils.ErrorLog(errs.Error())
  1741. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1742. // return
  1743. // }
  1744. //
  1745. // c.ServeSuccessJSON(map[string]interface{}{
  1746. // "msg": "2",
  1747. // "drug_name": "",
  1748. // "dose": "",
  1749. // "dose_unit": "",
  1750. // "min_number": "",
  1751. // "min_unit": "",
  1752. // "max_unit": "",
  1753. // })
  1754. // }
  1755. //
  1756. //}
  1757. ////比较当前出库数量 大于 最后一次出库数量,则需要出库
  1758. //if max_number > min_number {
  1759. //
  1760. // cha_number = max_number - min_number
  1761. // //如果总库存大于差,正常出库
  1762. // if all_number > cha_number {
  1763. //
  1764. // errs = service.UpDateDrugWarehouseOutInfo(item)
  1765. // flow := models.DrugFlow{
  1766. // Count: max_number,
  1767. // ExpireDate: item.ExpiryDate,
  1768. // ProductDate: item.ProductDate,
  1769. // Price: item.Price,
  1770. // Manufacturer: item.Manufacturer,
  1771. // Dealer: item.Dealer,
  1772. // Number: item.Number,
  1773. // StorehouseId: item.StorehouseId,
  1774. // AdminUserId: item.AdminUserId,
  1775. // }
  1776. // service.UpdateDrugFlowSix(item.WarehouseOutId, item.DrugId, item.WarehouseOutOrderNumber, flow)
  1777. //
  1778. // service.UpdateWarehouseInfoTwentyFive(cha_number, item.DrugId, item.OrgId, storehouse_id, &medical)
  1779. //
  1780. //
  1781. // }
  1782. //
  1783. // if all_number == cha_number {
  1784. // warehouseInfo := models.XtDrugWarehouseInfo{
  1785. // Number: item.Number,
  1786. // ProductDate: item.ProductDate,
  1787. // ExpiryDate: item.ExpiryDate,
  1788. // Price: item.Price,
  1789. // TotalPrice: item.TotalPrice,
  1790. // Dealer: item.Dealer,
  1791. // Manufacturer: item.Manufacturer,
  1792. // Remark: item.Remark,
  1793. // BatchNumber: item.BatchNumber,
  1794. // MaxUnit: item.CountUnit,
  1795. // StorehouseId: item.StorehouseId,
  1796. // }
  1797. // parseDateErr := service.UpdateDrugWarehouseingInfoSix(item.ID, warehouseInfo)
  1798. //
  1799. // if parseDateErr != nil {
  1800. // utils.ErrorLog(errs.Error())
  1801. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1802. // return
  1803. // }
  1804. // fmt.Println("单位123223232323", item.CountUnit)
  1805. // fmt.Println("单位232232323323232", medical.MaxUnit)
  1806. //
  1807. // errs = service.UpDateDrugWarehouseOutInfo(item)
  1808. // flow := models.DrugFlow{
  1809. // Count: item.Count,
  1810. // ExpireDate: item.ExpiryDate,
  1811. // ProductDate: item.ProductDate,
  1812. // Price: item.Price,
  1813. // Manufacturer: item.Manufacturer,
  1814. // Dealer: item.Dealer,
  1815. // Number: item.Number,
  1816. // StorehouseId: item.StorehouseId,
  1817. // AdminUserId: item.AdminUserId,
  1818. // }
  1819. // service.UpdateDrugFlowSix(item.WarehouseOutId, item.DrugId, item.WarehouseOutOrderNumber, flow)
  1820. // if item.CountUnit == medical.MaxUnit {
  1821. // maxNumber = cha_number / medical.MinNumber
  1822. //
  1823. // parseDateErr := service.UpdateWarehouseInfoTwo(maxNumber, item.DrugId, item.OrgId)
  1824. //
  1825. // fmt.Println("parseDateErr", parseDateErr)
  1826. // if parseDateErr != nil {
  1827. // utils.ErrorLog(errs.Error())
  1828. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1829. // return
  1830. // }
  1831. //
  1832. // c.ServeSuccessJSON(map[string]interface{}{
  1833. // "msg": "2",
  1834. // "drug_name": "",
  1835. // "dose": "",
  1836. // "dose_unit": "",
  1837. // "min_number": "",
  1838. // "min_unit": "",
  1839. // "max_unit": "",
  1840. // })
  1841. // minNumber = cha_number % medical.MinNumber
  1842. // if minNumber < 0 {
  1843. // minNumber = 0
  1844. // }
  1845. // parseDateErr = service.UpdateWarehouseInfoFour(minNumber, item.DrugId, item.OrgId)
  1846. //
  1847. // if parseDateErr != nil {
  1848. // utils.ErrorLog(errs.Error())
  1849. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1850. // return
  1851. // }
  1852. //
  1853. // c.ServeSuccessJSON(map[string]interface{}{
  1854. // "msg": "2",
  1855. // "drug_name": "",
  1856. // "dose": "",
  1857. // "dose_unit": "",
  1858. // "min_number": "",
  1859. // "min_unit": "",
  1860. // "max_unit": "",
  1861. // })
  1862. // }
  1863. // if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1864. // parseDateErr := service.UpdateWarehouseInfoFour(cha_number, item.DrugId, item.OrgId)
  1865. //
  1866. // if parseDateErr != nil {
  1867. // utils.ErrorLog(errs.Error())
  1868. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1869. // return
  1870. // }
  1871. //
  1872. // c.ServeSuccessJSON(map[string]interface{}{
  1873. // "msg": "2",
  1874. // "drug_name": "",
  1875. // "dose": "",
  1876. // "dose_unit": "",
  1877. // "min_number": "",
  1878. // "min_unit": "",
  1879. // "max_unit": "",
  1880. // })
  1881. // }
  1882. //
  1883. // }
  1884. // if all_number < cha_number {
  1885. // goodObj, _ := service.GetDrugByGoodId(item.DrugId)
  1886. // c.ServeSuccessJSON(map[string]interface{}{
  1887. // "msg": "1",
  1888. // "drug_name": goodObj.DrugName,
  1889. // "dose": goodObj.Dose,
  1890. // "dose_unit": goodObj.DoseUnit,
  1891. // "min_number": goodObj.MinNumber,
  1892. // "min_unit": goodObj.MinUnit,
  1893. // "max_unit": goodObj.MaxUnit,
  1894. // })
  1895. // return
  1896. // }
  1897. //}
  1898. //
  1899. ////查询默认仓库
  1900. //houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
  1901. ////查询默认仓库剩余多少库存
  1902. //list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
  1903. //var sum_count int64
  1904. //var sum_in_count int64
  1905. //for _, it := range list {
  1906. // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  1907. // if it.MaxUnit == baseDrug.MaxUnit {
  1908. // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  1909. // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  1910. //
  1911. // }
  1912. // sum_count += it.StockMaxNumber + it.StockMinNumber
  1913. // sum_in_count += it.WarehousingCount
  1914. //}
  1915. //service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
  1916. }
  1917. }
  1918. if errs != nil {
  1919. utils.ErrorLog(errs.Error())
  1920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1921. return
  1922. }
  1923. c.ServeSuccessJSON(map[string]interface{}{
  1924. "msg": "2",
  1925. "drug_name": "",
  1926. "dose": "",
  1927. "dose_unit": "",
  1928. "min_number": "",
  1929. "min_unit": "",
  1930. "max_unit": "",
  1931. })
  1932. }
  1933. func (c *StockDrugApiController) CreateDrugCancelStock() {
  1934. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1935. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1936. cancel_stock_time := c.GetString("time")
  1937. types, _ := c.GetInt64("type", 0)
  1938. storehouse_id, _ := c.GetInt64("storehouse_id")
  1939. cancelstock_id, _ := c.GetInt64("cancelstock_id")
  1940. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1941. if parseDateErr != nil {
  1942. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1944. return
  1945. }
  1946. adminUserInfo := c.GetAdminUserInfo()
  1947. operation_time := time.Now().Unix()
  1948. creater := adminUserInfo.AdminUser.Id
  1949. ctime := time.Now().Unix()
  1950. timeStr := time.Now().Format("2006-01-02")
  1951. timeArr := strings.Split(timeStr, "-")
  1952. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1953. total = total + 1
  1954. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1955. cancelStock := models.DrugCancelStock{
  1956. OrderNumber: orderNumber,
  1957. OperaTime: operation_time,
  1958. OrgId: adminUserInfo.CurrentOrgId,
  1959. Creater: creater,
  1960. Ctime: ctime,
  1961. Status: 1,
  1962. ReturnTime: cancelStockDate.Unix(),
  1963. Dealer: dealer_id,
  1964. Manufacturer: manufacturer_id,
  1965. Type: types,
  1966. StorehouseId: storehouse_id,
  1967. IsCheck: 2,
  1968. }
  1969. if cancelstock_id == 0 {
  1970. service.AddSigleDrugCancelStock(&cancelStock)
  1971. }
  1972. if cancelstock_id > 0 {
  1973. service.UpdateSingleDrugCancelStock(cancelstock_id, storehouse_id)
  1974. }
  1975. cancelLastStock, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1976. dataBody := make(map[string]interface{}, 0)
  1977. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1978. if err != nil {
  1979. utils.ErrorLog(err.Error())
  1980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1981. return
  1982. }
  1983. var cancelStockInfos []*models.DrugCancelStockInfo
  1984. var drugFlow []*models.DrugFlow
  1985. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1986. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1987. if len(thisStockIn) > 0 {
  1988. for _, item := range thisStockIn {
  1989. items := item.(map[string]interface{})
  1990. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1991. utils.ErrorLog("id")
  1992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1993. return
  1994. }
  1995. id := int64(items["id"].(float64))
  1996. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1997. utils.ErrorLog("drug_id")
  1998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1999. return
  2000. }
  2001. drug_id := int64(items["drug_id"].(float64))
  2002. return_count, _ := items["return_count"].(string)
  2003. if len(return_count) == 0 {
  2004. utils.ErrorLog("len(return_count) == 0")
  2005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2006. return
  2007. }
  2008. count, _ := strconv.ParseInt(return_count, 10, 64)
  2009. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2010. utils.ErrorLog("price")
  2011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2012. return
  2013. }
  2014. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2015. total := float64(count) * price
  2016. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  2017. utils.ErrorLog("retail_price")
  2018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2019. return
  2020. }
  2021. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  2022. retail_price_total := float64(count) * retail_price
  2023. register_account, _ := items["register_account"].(string)
  2024. remark, _ := items["remark"].(string)
  2025. var productDates int64
  2026. var expiryDates int64
  2027. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  2028. expiryDates = 0
  2029. } else {
  2030. if len(items["expiry_date"].(string)) == 0 {
  2031. expiryDates = 0
  2032. } else {
  2033. expiryDate, _ := items["expiry_date"].(string)
  2034. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  2035. expiryDates = expiry_date.Unix()
  2036. }
  2037. }
  2038. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  2039. productDates = 0
  2040. } else {
  2041. if len(items["product_date"].(string)) == 0 {
  2042. productDates = 0
  2043. } else {
  2044. productDate, _ := items["product_date"].(string)
  2045. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  2046. productDates = product_date.Unix()
  2047. }
  2048. }
  2049. manufacturer, _ := items["manufacturer"].(string)
  2050. dealer, _ := items["dealer"].(string)
  2051. batch_number := items["batch_number"].(string)
  2052. max_unit := items["max_unit"].(string)
  2053. batch_number_id := int64(items["batch_number_id"].(float64))
  2054. var manufacturer_id int64
  2055. var dealer_id int64
  2056. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  2057. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  2058. for _, item := range manufacturerList {
  2059. if manufacturer == item.ManufacturerName {
  2060. manufacturer_id = item.ID
  2061. }
  2062. }
  2063. for _, item := range dealerList {
  2064. if dealer == item.DealerName {
  2065. dealer_id = item.ID
  2066. }
  2067. }
  2068. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2069. cancelStockInfo := &models.DrugCancelStockInfo{
  2070. ID: id,
  2071. OrderNumber: cancelInfo.OrderNumber,
  2072. CancelStockId: cancelInfo.ID,
  2073. DrugId: drug_id,
  2074. Count: count,
  2075. Status: 1,
  2076. Ctime: ctime,
  2077. OrgId: adminUserInfo.CurrentOrgId,
  2078. Type: types,
  2079. Manufacturer: manufacturer,
  2080. Dealer: dealer,
  2081. Total: total,
  2082. RetailPrice: retail_price,
  2083. RetailTotalPrice: retail_price_total,
  2084. Price: price,
  2085. RegisterAccount: register_account,
  2086. Remark: remark,
  2087. BatchNumber: batch_number,
  2088. MaxUnit: max_unit,
  2089. ProductDate: productDates,
  2090. ExpiryDate: expiryDates,
  2091. BatchNumberId: batch_number_id,
  2092. StorehouseId: storehouse_id,
  2093. IsCheck: 2,
  2094. }
  2095. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  2096. flow := &models.DrugFlow{
  2097. WarehousingId: 0,
  2098. DrugId: drug_id,
  2099. Number: "",
  2100. BatchNumber: batch_number,
  2101. Count: count,
  2102. UserOrgId: adminUserInfo.CurrentOrgId,
  2103. PatientId: 0,
  2104. SystemTime: ctime,
  2105. ConsumableType: 4,
  2106. IsSys: 0,
  2107. WarehousingOrder: "",
  2108. WarehouseOutId: 0,
  2109. WarehouseOutOrderNumber: "",
  2110. IsEdit: 0,
  2111. CancelStockId: cancelStock.ID,
  2112. CancelOrderNumber: cancelStock.OrderNumber,
  2113. Manufacturer: manufacturer_id,
  2114. Dealer: dealer_id,
  2115. Creator: adminUserInfo.AdminUser.Id,
  2116. UpdateCreator: 0,
  2117. Status: 1,
  2118. Ctime: time.Now().Unix(),
  2119. Mtime: 0,
  2120. Price: price,
  2121. WarehousingDetailId: 0,
  2122. WarehouseOutDetailId: 0,
  2123. CancelOutDetailId: 0,
  2124. ExpireDate: expiryDates,
  2125. ProductDate: productDates,
  2126. MaxUnit: max_unit,
  2127. MinUnit: "",
  2128. StorehouseId: storehouse_id,
  2129. }
  2130. drugFlow = append(drugFlow, flow)
  2131. }
  2132. }
  2133. }
  2134. for _, item := range cancelStockInfos {
  2135. if item.ID == 0 {
  2136. service.CreateCancelStockInfoTwo(item)
  2137. }
  2138. if item.ID > 0 {
  2139. service.ModifyDrugCancelStockInfo(item.ID, item)
  2140. }
  2141. }
  2142. list, _ := service.GetLastCancelStockByList(cancelLastStock.ID, adminUserInfo.CurrentOrgId)
  2143. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  2144. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  2145. var drugType = "药品类型"
  2146. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  2147. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminUserInfo.CurrentOrgId)
  2148. c.ServeSuccessJSON(map[string]interface{}{
  2149. "cancelStock": cancelLastStock,
  2150. "cancelLastStock": cancelLastStock,
  2151. "list": list,
  2152. "manufacturerList": manufacturerList,
  2153. "dealerList": dealerList,
  2154. "drugTypeList": drugTypeList,
  2155. "msg": "1",
  2156. })
  2157. //扣减库存逻辑
  2158. //for _, item := range cancelStockInfos {
  2159. //
  2160. // var total_number int64
  2161. // var out_number int64
  2162. // var can_number int64
  2163. // medical, _ := service.GetBaseDrugMedical(item.DrugId)
  2164. // //将当前退库数转为最小单位
  2165. // if item.MaxUnit == medical.MaxUnit {
  2166. // total_number = item.Count * medical.MinNumber
  2167. // }
  2168. // if item.MaxUnit == medical.MinUnit {
  2169. // total_number = item.Count
  2170. // }
  2171. // //查询当前药品退库的批次号的总入库数
  2172. // infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
  2173. // var total_count int64
  2174. // total_count = infoWareInfo.WarehousingCount * medical.MinNumber
  2175. //
  2176. // //查询该批次的出库数量
  2177. // outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
  2178. //
  2179. // //查询该批次总的退库数量
  2180. // canInfo, _ := service.GetCancelDrugStockOutInfo(item.BatchNumberId, item.DrugId)
  2181. //
  2182. // for _, it := range canInfo {
  2183. // if it.MaxUnit == medical.MaxUnit {
  2184. // it.Count = it.Count * medical.MinNumber
  2185. // }
  2186. // if it.MaxUnit == medical.MinUnit {
  2187. // it.Count = it.Count
  2188. // }
  2189. // }
  2190. //
  2191. // for _, it := range canInfo {
  2192. // can_number += it.Count
  2193. // }
  2194. //
  2195. // for _, it := range outInfo {
  2196. // if it.CountUnit == medical.MaxUnit {
  2197. // it.Count = it.Count * medical.MinNumber
  2198. // }
  2199. // if it.CountUnit == medical.MinUnit {
  2200. // it.Count = it.Count
  2201. // }
  2202. // }
  2203. // for _, it := range outInfo {
  2204. // out_number += it.Count
  2205. // }
  2206. //
  2207. // if out_number == 0 {
  2208. // service.UpdateDrugCancel(item.CancelStockId)
  2209. // c.ServeSuccessJSON(map[string]interface{}{
  2210. // "msg": "2",
  2211. // })
  2212. // return
  2213. // }
  2214. // fmt.Println("当前退库数", total_count)
  2215. // fmt.Println("当前批次总库存", total_count)
  2216. // fmt.Println("总出库数", out_number)
  2217. // //判断退库数量是否大于总入库数量
  2218. // if total_number > total_count {
  2219. // service.UpdateDrugCancel(item.CancelStockId)
  2220. // c.ServeSuccessJSON(map[string]interface{}{
  2221. // "msg": "2",
  2222. // })
  2223. // return
  2224. // }
  2225. //
  2226. // //判断总退库数量是否大于出库数量
  2227. //
  2228. // if can_number+total_number > out_number {
  2229. // //清空退库单
  2230. // service.UpdateDrugCancel(item.CancelStockId)
  2231. // c.ServeSuccessJSON(map[string]interface{}{
  2232. // "msg": "2",
  2233. // })
  2234. // return
  2235. // }
  2236. //
  2237. // //正常退库
  2238. // if total_number <= out_number {
  2239. // //创建退库详情
  2240. // errs := service.CreateCancelStockInfoTwo(item)
  2241. // lastInfo, _ := service.GetLastStockInfoThree(item.DrugId)
  2242. // //创建库存明细
  2243. // flows := models.DrugFlow{
  2244. // WarehousingId: 0,
  2245. // DrugId: item.DrugId,
  2246. // Number: "",
  2247. // BatchNumber: item.BatchNumber,
  2248. // Count: item.Count,
  2249. // UserOrgId: adminUserInfo.CurrentOrgId,
  2250. // PatientId: 0,
  2251. // SystemTime: ctime,
  2252. // ConsumableType: 4,
  2253. // IsSys: 0,
  2254. // WarehousingOrder: infoWareInfo.WarehousingOrder,
  2255. // WarehouseOutId: 0,
  2256. // WarehouseOutOrderNumber: "",
  2257. // IsEdit: 0,
  2258. // CancelStockId: cancelStock.ID,
  2259. // CancelOrderNumber: cancelStock.OrderNumber,
  2260. // Manufacturer: manufacturer_id,
  2261. // Dealer: dealer_id,
  2262. // Creator: adminUserInfo.AdminUser.Id,
  2263. // UpdateCreator: 0,
  2264. // Status: 1,
  2265. // Ctime: time.Now().Unix(),
  2266. // Mtime: 0,
  2267. // Price: item.Price,
  2268. // WarehousingDetailId: 0,
  2269. // WarehouseOutDetailId: 0,
  2270. // CancelOutDetailId: lastInfo.ID,
  2271. // ExpireDate: item.ExpiryDate,
  2272. // ProductDate: item.ProductDate,
  2273. // MaxUnit: item.MaxUnit,
  2274. // MinUnit: "",
  2275. // StorehouseId: storehouse_id,
  2276. // }
  2277. // errs = service.CreateDrugFlowOne(flows)
  2278. //
  2279. // var total int64
  2280. //
  2281. // if medical.MaxUnit == item.MaxUnit {
  2282. // total = item.Count
  2283. //
  2284. // warehouseInfo := models.XtDrugWarehouseInfo{
  2285. // StockMaxNumber: total,
  2286. // }
  2287. //
  2288. // errs = service.UpdateDrugWarehouseInfo(&warehouseInfo, item.BatchNumberId)
  2289. // //查询默认仓库
  2290. // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
  2291. // //查询默认仓库剩余多少库存
  2292. // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
  2293. // var sum_count int64
  2294. // var sum_in_count int64
  2295. // for _, it := range list {
  2296. // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2297. // if it.MaxUnit == baseDrug.MaxUnit {
  2298. // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2299. // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2300. // }
  2301. // sum_count += it.StockMaxNumber + it.StockMinNumber
  2302. // sum_in_count += it.WarehousingCount
  2303. // }
  2304. // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
  2305. // if errs != nil {
  2306. // utils.ErrorLog(errs.Error())
  2307. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2308. // return
  2309. // }
  2310. //
  2311. // c.ServeSuccessJSON(map[string]interface{}{
  2312. // "msg": "1",
  2313. // })
  2314. // }
  2315. //
  2316. // if medical.MinUnit == item.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2317. // total = item.Count
  2318. // warehouseInfo := models.XtDrugWarehouseInfo{
  2319. // StockMinNumber: total,
  2320. // }
  2321. //
  2322. // errs = service.UpdateDrugWarehouseInfoOne(&warehouseInfo, item.BatchNumberId)
  2323. // //查询默认仓库
  2324. // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
  2325. // //查询默认仓库剩余多少库存
  2326. // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
  2327. // var sum_count int64
  2328. // var sum_in_count int64
  2329. // for _, it := range list {
  2330. // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2331. // if it.MaxUnit == baseDrug.MaxUnit {
  2332. // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2333. // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2334. // }
  2335. // sum_count += it.StockMaxNumber + it.StockMinNumber
  2336. // sum_in_count += it.WarehousingCount
  2337. // }
  2338. // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
  2339. // if errs != nil {
  2340. // utils.ErrorLog(errs.Error())
  2341. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2342. // return
  2343. // }
  2344. //
  2345. // c.ServeSuccessJSON(map[string]interface{}{
  2346. // "msg": "1",
  2347. // })
  2348. // }
  2349. // }
  2350. //
  2351. //}
  2352. }
  2353. func (c *StockDrugApiController) GetDrugCancelStockInfoList() {
  2354. id, _ := c.GetInt64("id", 0)
  2355. adminUserInfo := c.GetAdminUserInfo()
  2356. cancelStockInfoList, _ := service.FindDrugCancelStockInfoById(id, adminUserInfo.CurrentOrgId)
  2357. info, _ := service.FindCancelDrugById(id, adminUserInfo.CurrentOrgId)
  2358. list, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  2359. c.ServeSuccessJSON(map[string]interface{}{
  2360. "list": cancelStockInfoList,
  2361. "info": info,
  2362. "houselist": list,
  2363. })
  2364. }
  2365. func (c *StockDrugApiController) GetDrugCancelStockList() {
  2366. page, _ := c.GetInt64("page", -1)
  2367. limit, _ := c.GetInt64("limit", -1)
  2368. start_time := c.GetString("start_time")
  2369. end_time := c.GetString("end_time")
  2370. types, _ := c.GetInt64("type", 0)
  2371. keywords := c.GetString("keywords")
  2372. storehouse_id, _ := c.GetInt64("storehouse_id")
  2373. check_type, _ := c.GetInt64("check_type")
  2374. timeLayout := "2006-01-02"
  2375. loc, _ := time.LoadLocation("Local")
  2376. var startTime int64
  2377. if len(start_time) > 0 {
  2378. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2379. if err != nil {
  2380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2381. return
  2382. }
  2383. startTime = theTime.Unix()
  2384. }
  2385. var endTime int64
  2386. if len(end_time) > 0 {
  2387. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2388. if err != nil {
  2389. utils.ErrorLog(err.Error())
  2390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2391. return
  2392. }
  2393. endTime = theTime.Unix()
  2394. }
  2395. adminUserInfo := c.GetAdminUserInfo()
  2396. returnList, total, err := service.FindAllDrugCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, storehouse_id, check_type)
  2397. houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  2398. if err == nil {
  2399. c.ServeSuccessJSON(map[string]interface{}{
  2400. "list": returnList,
  2401. "total": total,
  2402. "houseList": houseList,
  2403. })
  2404. } else {
  2405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2406. }
  2407. }
  2408. func (this *StockDrugApiController) DeleteDrugCancelStock() {
  2409. ids := this.GetString("ids")
  2410. if len(ids) == 0 {
  2411. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2412. return
  2413. }
  2414. idArray := strings.Split(ids, ",")
  2415. ////获取入库数据
  2416. //list, _ := service.GetDrugWareInfoByCancelId(idArray)
  2417. //for _, item := range list {
  2418. // medical, _ := service.GetBaseDrugMedical(item.DrugId)
  2419. // if item.MaxUnit == medical.MaxUnit {
  2420. // //回退库存
  2421. // service.ModifyDrugWarehouseByInfoId(item.BatchNumberId, item.Count)
  2422. //
  2423. // }
  2424. // if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2425. // service.ModifyDrugWarehouseByStockMin(item.BatchNumberId, item.Count)
  2426. // }
  2427. //
  2428. // //查询默认仓库
  2429. // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
  2430. // //查询默认仓库剩余多少库存
  2431. // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
  2432. // var sum_count int64
  2433. // var sum_in_count int64
  2434. // for _, it := range list {
  2435. // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2436. // if it.MaxUnit == baseDrug.MaxUnit {
  2437. // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2438. // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2439. // sum_count += it.StockMaxNumber + it.StockMinNumber
  2440. // sum_in_count += it.WarehousingCount
  2441. // }
  2442. // }
  2443. // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
  2444. //}
  2445. err := service.DeleteDrugCancelStock(idArray)
  2446. if err != nil {
  2447. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2448. } else {
  2449. this.ServeSuccessJSON(map[string]interface{}{
  2450. "msg": "删除成功",
  2451. })
  2452. }
  2453. }
  2454. func (this *StockDrugApiController) DeleteDrugCancelStockInfo() {
  2455. id, _ := this.GetInt64("id", 0)
  2456. if id == 0 {
  2457. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2458. return
  2459. }
  2460. ////查询
  2461. //cancelinfo, _ := service.GetDrugCancelById(id)
  2462. //
  2463. //drug, _ := service.GetBaseDrugMedical(cancelinfo.DrugId)
  2464. //if drug.MaxUnit == cancelinfo.MaxUnit {
  2465. // service.ModeFyDrugWareseInfo(cancelinfo.BatchNumberId, cancelinfo.Count)
  2466. //
  2467. //}
  2468. //if drug.MinUnit == cancelinfo.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2469. // service.ModeFyDrugWarehouseMin(cancelinfo.BatchNumberId, cancelinfo.Count)
  2470. //}
  2471. //
  2472. err := service.UpDateDrugCancleStockStatus(id)
  2473. //删除流水
  2474. // service.UpDateDrugCancelStockById(cancelinfo.ID)
  2475. //查询默认仓库
  2476. //houseConfig, _ := service.GetAllStoreHouseConfig(cancelinfo.OrgId)
  2477. ////查询默认仓库剩余多少库存
  2478. //list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, cancelinfo.OrgId, cancelinfo.DrugId)
  2479. //var sum_count int64
  2480. //var sum_in_count int64
  2481. //for _, it := range list {
  2482. // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2483. // if it.MaxUnit == baseDrug.MaxUnit {
  2484. // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2485. // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2486. // }
  2487. // sum_count += it.StockMaxNumber + it.StockMinNumber
  2488. // sum_in_count += it.WarehousingCount
  2489. //}
  2490. //service.UpdateMedicalSumCount(cancelinfo.DrugId, sum_count, sum_in_count, cancelinfo.OrgId)
  2491. if err != nil {
  2492. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2493. } else {
  2494. this.ServeSuccessJSON(map[string]interface{}{
  2495. "msg": "删除成功",
  2496. })
  2497. }
  2498. }
  2499. func (c *StockDrugApiController) EditDrugCancelStock() {
  2500. cancel_time := c.GetString("cancel_time")
  2501. id, _ := c.GetInt64("id", 0)
  2502. types, _ := c.GetInt64("type", 0)
  2503. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  2504. dealer_id, _ := c.GetInt64("dealer_id", 0)
  2505. storehouse_id, _ := c.GetInt64("storehouse_id")
  2506. if id == 0 {
  2507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2508. return
  2509. }
  2510. ctime := time.Now().Unix()
  2511. mtime := time.Now().Unix()
  2512. adminUserInfo := c.GetAdminUserInfo()
  2513. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  2514. if parseDateErr != nil {
  2515. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  2516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2517. return
  2518. }
  2519. cancelStock, _ := service.FindDrugCancelStockById(id)
  2520. tempCancelStock := models.DrugCancelStock{
  2521. ID: cancelStock.ID,
  2522. Mtime: mtime,
  2523. ReturnTime: cancelDate.Unix(),
  2524. Manufacturer: manufacturer_id,
  2525. Dealer: dealer_id,
  2526. StorehouseId: storehouse_id,
  2527. IsCheck: 1,
  2528. }
  2529. service.EditDrugCancelStock(tempCancelStock)
  2530. dataBody := make(map[string]interface{}, 0)
  2531. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2532. if err != nil {
  2533. utils.ErrorLog(err.Error())
  2534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2535. return
  2536. }
  2537. var cancelStockInfos []*models.DrugCancelStockInfo
  2538. var upDateCancelStockInfos []*models.DrugCancelStockInfo
  2539. var drugFlow []*models.DrugFlow
  2540. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  2541. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  2542. if len(thisCancelStock) > 0 {
  2543. for _, item := range thisCancelStock {
  2544. items := item.(map[string]interface{})
  2545. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  2546. utils.ErrorLog("drug_id")
  2547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2548. return
  2549. }
  2550. drug_id := int64(items["drug_id"].(float64))
  2551. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2552. utils.ErrorLog("count")
  2553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2554. return
  2555. }
  2556. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2557. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2558. utils.ErrorLog("price")
  2559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2560. return
  2561. }
  2562. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2563. total := float64(count) * price
  2564. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  2565. utils.ErrorLog("retail_price")
  2566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2567. return
  2568. }
  2569. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  2570. retail_price_total := float64(count) * retail_price
  2571. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2572. utils.ErrorLog("id")
  2573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2574. return
  2575. }
  2576. id := int64(items["id"].(float64))
  2577. max_unit := items["max_unit"].(string)
  2578. batch_number := items["batch_number"].(string)
  2579. register_account := items["register_account"].(string)
  2580. remark := items["remark"].(string)
  2581. manufacturer := items["manufacturer"].(string)
  2582. dealer := items["dealer"].(string)
  2583. var productDates int64
  2584. var expiryDates int64
  2585. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  2586. expiryDates = 0
  2587. } else {
  2588. if len(items["expiry_date"].(string)) == 0 {
  2589. expiryDates = 0
  2590. } else {
  2591. expiryDate, _ := items["expiry_date"].(string)
  2592. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  2593. expiryDates = expiry_date.Unix()
  2594. }
  2595. }
  2596. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  2597. productDates = 0
  2598. } else {
  2599. if len(items["product_date"].(string)) == 0 {
  2600. productDates = 0
  2601. } else {
  2602. productDate, _ := items["product_date"].(string)
  2603. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  2604. productDates = product_date.Unix()
  2605. }
  2606. }
  2607. batch_number_id := int64(items["batch_number_id"].(float64))
  2608. if id == 0 {
  2609. cancelStockInfo := &models.DrugCancelStockInfo{
  2610. DrugId: drug_id,
  2611. Count: count,
  2612. Status: 1,
  2613. Ctime: ctime,
  2614. OrgId: adminUserInfo.CurrentOrgId,
  2615. OrderNumber: cancelStock.OrderNumber,
  2616. CancelStockId: cancelStock.ID,
  2617. Mtime: time.Now().Unix(),
  2618. Type: types,
  2619. RetailPrice: retail_price,
  2620. RetailTotalPrice: retail_price_total,
  2621. Price: price,
  2622. Total: total,
  2623. Manufacturer: manufacturer,
  2624. Dealer: dealer,
  2625. RegisterAccount: register_account,
  2626. MaxUnit: max_unit,
  2627. BatchNumber: batch_number,
  2628. Remark: remark,
  2629. ProductDate: productDates,
  2630. ExpiryDate: expiryDates,
  2631. BatchNumberId: batch_number_id,
  2632. StorehouseId: storehouse_id,
  2633. }
  2634. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  2635. } else {
  2636. cancelStockInfo := &models.DrugCancelStockInfo{
  2637. ID: id,
  2638. DrugId: drug_id,
  2639. Count: count,
  2640. Status: 1,
  2641. Ctime: ctime,
  2642. OrgId: adminUserInfo.CurrentOrgId,
  2643. OrderNumber: cancelStock.OrderNumber,
  2644. CancelStockId: cancelStock.ID,
  2645. Mtime: time.Now().Unix(),
  2646. Type: types,
  2647. RetailPrice: retail_price,
  2648. RetailTotalPrice: retail_price_total,
  2649. Price: price,
  2650. Total: total,
  2651. Manufacturer: manufacturer,
  2652. Dealer: dealer,
  2653. RegisterAccount: register_account,
  2654. MaxUnit: max_unit,
  2655. BatchNumber: batch_number,
  2656. Remark: remark,
  2657. ProductDate: productDates,
  2658. ExpiryDate: expiryDates,
  2659. BatchNumberId: batch_number_id,
  2660. StorehouseId: storehouse_id,
  2661. }
  2662. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  2663. }
  2664. flow := &models.DrugFlow{
  2665. WarehousingId: 0,
  2666. DrugId: drug_id,
  2667. Number: "",
  2668. BatchNumber: batch_number,
  2669. Count: count,
  2670. UserOrgId: adminUserInfo.CurrentOrgId,
  2671. PatientId: 0,
  2672. SystemTime: time.Now().Unix(),
  2673. ConsumableType: 4,
  2674. IsSys: 0,
  2675. WarehousingOrder: "",
  2676. WarehouseOutId: 0,
  2677. WarehouseOutOrderNumber: "",
  2678. IsEdit: 0,
  2679. CancelStockId: cancelStock.ID,
  2680. CancelOrderNumber: cancelStock.OrderNumber,
  2681. Manufacturer: 0,
  2682. Dealer: 0,
  2683. Creator: adminUserInfo.AdminUser.Id,
  2684. UpdateCreator: adminUserInfo.AdminUser.Id,
  2685. Status: 1,
  2686. Ctime: time.Now().Unix(),
  2687. Mtime: 0,
  2688. Price: price,
  2689. WarehousingDetailId: 0,
  2690. WarehouseOutDetailId: 0,
  2691. CancelOutDetailId: 0,
  2692. ExpireDate: expiryDates,
  2693. ProductDate: productDates,
  2694. MaxUnit: max_unit,
  2695. MinUnit: "",
  2696. StorehouseId: storehouse_id,
  2697. }
  2698. drugFlow = append(drugFlow, flow)
  2699. }
  2700. }
  2701. }
  2702. if len(cancelStockInfos) > 0 {
  2703. service.CreateDrugCancelStockInfo(cancelStockInfos)
  2704. }
  2705. if len(upDateCancelStockInfos) > 0 {
  2706. for _, item := range upDateCancelStockInfos {
  2707. service.UpDateDrugCancelStockInfo(item)
  2708. }
  2709. }
  2710. //var errs error
  2711. //if len(cancelStockInfos) > 0 {
  2712. //
  2713. // //扣减库存逻辑
  2714. // for _, item := range cancelStockInfos {
  2715. // medical, _ := service.GetBaseDrugMedical(item.DrugId)
  2716. // //查询当前药品退库的批次号的总入库数
  2717. // infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
  2718. //
  2719. // var total_count int64
  2720. // var cancel_count int64
  2721. // var out_count int64
  2722. // total_count = infoWareInfo.StockMaxNumber*medical.MinNumber + infoWareInfo.StockMinNumber
  2723. // //转化为最小单位
  2724. // var total_number int64
  2725. // if item.MaxUnit == medical.MaxUnit {
  2726. // total_number = item.Count * medical.MinNumber
  2727. // }
  2728. // if item.MaxUnit == medical.MinUnit {
  2729. // total_number = item.Count
  2730. // }
  2731. //
  2732. // //统计该批次的总出库数
  2733. // outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
  2734. // for _, item := range outInfo {
  2735. // if item.CountUnit == medical.MaxUnit {
  2736. // item.Count = item.Count * medical.MinNumber
  2737. // }
  2738. // if item.CountUnit == medical.MinUnit {
  2739. // item.Count = item.Count
  2740. // }
  2741. // }
  2742. //
  2743. // for _, item := range outInfo {
  2744. // out_count += item.Count
  2745. // }
  2746. //
  2747. // //判断退库数量是否大于出库数量
  2748. // cancelInfo, _ := service.GetCancelDrugStockOutInfo(item.BatchNumberId, item.DrugId)
  2749. // for _, item := range cancelInfo {
  2750. // if item.MaxUnit == medical.MaxUnit {
  2751. // item.Count = item.Count * medical.MinNumber
  2752. // }
  2753. // if item.MaxUnit == medical.MinUnit {
  2754. // item.Count = item.Count
  2755. // }
  2756. // }
  2757. //
  2758. // for _, item := range cancelInfo {
  2759. // cancel_count += item.Count
  2760. // }
  2761. //
  2762. // if total_number+cancel_count > out_count {
  2763. // c.ServeSuccessJSON(map[string]interface{}{
  2764. // "msg": "4",
  2765. // })
  2766. // return
  2767. // }
  2768. //
  2769. // //判断退库数量是否大于总入库数量
  2770. // if total_number > total_count {
  2771. // c.ServeSuccessJSON(map[string]interface{}{
  2772. // "msg": "2",
  2773. // })
  2774. // return
  2775. // }
  2776. //
  2777. // //正常退库
  2778. // if total_number <= total_count {
  2779. // //创建退库详情
  2780. // errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
  2781. // //创建库存明细
  2782. // //查询这个药品这个订单是否已存在流水
  2783. // for _, items := range drugFlow {
  2784. // drugwarehouseinfo, _ := service.GetLastDrugCancelStockInfoById(items.DrugId)
  2785. // items.CancelOutDetailId = drugwarehouseinfo.ID
  2786. // _, errsId := service.GetCancelStockId(items.CancelStockId, items.DrugId)
  2787. // if errsId == gorm.ErrRecordNotFound {
  2788. //
  2789. // errs = service.CreateDrugFlowTwo(items)
  2790. // }
  2791. // }
  2792. //
  2793. // //获取该批次最后一条退库详情
  2794. // lastCancel, _ := service.GetLastCancelStockInfo(id)
  2795. // var cancel_number int64
  2796. // if lastCancel.MaxUnit == medical.MaxUnit {
  2797. // cancel_number = lastCancel.Count * medical.MinNumber
  2798. // }
  2799. //
  2800. // if lastCancel.MaxUnit == medical.MinUnit {
  2801. // cancel_number = lastCancel.Count
  2802. // }
  2803. //
  2804. // var total int64
  2805. //
  2806. // if medical.MaxUnit == item.MaxUnit {
  2807. // total = item.Count - cancel_number
  2808. //
  2809. // warehouseInfo := models.XtDrugWarehouseInfo{
  2810. // StockMaxNumber: total,
  2811. // }
  2812. // errs = service.UpdateDrugWarehouseInfo(&warehouseInfo, item.BatchNumberId)
  2813. //
  2814. // if errs != nil {
  2815. // utils.ErrorLog(errs.Error())
  2816. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2817. // return
  2818. // }
  2819. //
  2820. // c.ServeSuccessJSON(map[string]interface{}{
  2821. // "msg": "1",
  2822. // })
  2823. // }
  2824. // if medical.MinUnit == item.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2825. // total = item.Count - cancel_number
  2826. // warehouseInfo := models.XtDrugWarehouseInfo{
  2827. // StockMinNumber: total,
  2828. // }
  2829. //
  2830. // errs = service.UpdateDrugWarehouseInfoOne(&warehouseInfo, item.BatchNumberId)
  2831. //
  2832. // //查询默认仓库
  2833. // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
  2834. // //查询默认仓库剩余多少库存
  2835. // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
  2836. // var sum_count int64
  2837. // var sum_in_count int64
  2838. // for _, it := range list {
  2839. // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2840. // if it.MaxUnit == baseDrug.MaxUnit {
  2841. // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2842. // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2843. // }
  2844. // sum_count += it.StockMaxNumber + it.StockMinNumber
  2845. // sum_in_count += it.WarehousingCount
  2846. // }
  2847. // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
  2848. //
  2849. // if errs != nil {
  2850. // utils.ErrorLog(errs.Error())
  2851. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2852. // return
  2853. // }
  2854. //
  2855. // c.ServeSuccessJSON(map[string]interface{}{
  2856. // "msg": "1",
  2857. // })
  2858. // }
  2859. //
  2860. // }
  2861. //
  2862. // }
  2863. //}
  2864. //if len(drugFlow) > 0 {
  2865. // for _, items := range drugFlow {
  2866. // _, errsId := service.GetCancelStockId(items.CancelStockId, items.DrugId)
  2867. // if errsId == gorm.ErrRecordNotFound {
  2868. // errs = service.CreateDrugFlowTwo(items)
  2869. // }
  2870. // }
  2871. //}
  2872. //
  2873. //if len(upDateCancelStockInfos) > 0 {
  2874. // var total int64
  2875. // var out_count int64
  2876. // var cancel_count int64
  2877. // var now_count int64
  2878. // var all_count int64
  2879. // for _, item := range upDateCancelStockInfos {
  2880. //
  2881. // //查询最后一条退库记录
  2882. // info, _ := service.GetLastCancelStockInfoOne(id, item.DrugId)
  2883. //
  2884. // errs = service.UpDateDrugCancelStockInfo(item)
  2885. //
  2886. // //查询该药品的信息
  2887. // medical, _ := service.GetBaseDrugMedical(item.DrugId)
  2888. // //统计该批次的总出库数
  2889. // outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
  2890. // //查询该批次的总退库数量
  2891. // cancelInfo, _ := service.GetTotalDrugCancelInfo(item.BatchNumberId, item.DrugId, item.ID)
  2892. // for _, item := range outInfo {
  2893. // if item.CountUnit == medical.MaxUnit {
  2894. // item.Count = item.Count * medical.MinNumber
  2895. // }
  2896. // if item.CountUnit == medical.MinUnit {
  2897. // item.Count = item.Count
  2898. // }
  2899. // }
  2900. //
  2901. // for _, item := range outInfo {
  2902. // out_count += item.Count
  2903. // }
  2904. //
  2905. // for _, item := range cancelInfo {
  2906. // if item.MaxUnit == medical.MaxUnit {
  2907. // item.Count = item.Count * medical.MinNumber
  2908. // }
  2909. // if item.MaxUnit == medical.MinUnit {
  2910. // item.Count = item.Count
  2911. // }
  2912. // }
  2913. //
  2914. // for _, item := range cancelInfo {
  2915. // cancel_count += item.Count
  2916. // }
  2917. //
  2918. // fmt.Println("out_count232233332232323223", out_count)
  2919. //
  2920. // if item.MaxUnit == medical.MaxUnit {
  2921. // now_count = item.Count * medical.MinNumber
  2922. // }
  2923. // if item.MaxUnit == medical.MinUnit {
  2924. // now_count = item.Count
  2925. // }
  2926. // fmt.Println("hhhhhh2323322323", now_count+cancel_count)
  2927. // //总退库批次
  2928. // all_count = now_count + cancel_count
  2929. //
  2930. // //该批次的总出库数小与退库数报错返回
  2931. // if all_count > out_count {
  2932. // c.ServeSuccessJSON(map[string]interface{}{
  2933. // "msg": "4",
  2934. // })
  2935. // return
  2936. // }
  2937. //
  2938. // if item.MaxUnit == medical.MaxUnit {
  2939. // //更新库存
  2940. // total = item.Count - info.Count
  2941. // parseDateErr := service.UpdatedDrugInfo(item.BatchNumberId, total)
  2942. // fmt.Println("parseDateErr", parseDateErr)
  2943. //
  2944. // flow := models.DrugFlow{
  2945. // Count: item.Count,
  2946. // }
  2947. // service.UpdatedDrugFlow(info.CancelStockId, item.DrugId, flow)
  2948. // }
  2949. //
  2950. // if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2951. // item.Count = item.Count
  2952. // total = item.Count - info.Count
  2953. // service.UpdatedDrugInfoOne(item.BatchNumberId, total)
  2954. //
  2955. // flow := models.DrugFlow{
  2956. // Count: item.Count,
  2957. // }
  2958. // service.UpdatedDrugFlow(info.CancelStockId, item.DrugId, flow)
  2959. // }
  2960. //
  2961. // //查询默认仓库
  2962. // houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
  2963. // //查询默认仓库剩余多少库存
  2964. // list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
  2965. // var sum_count int64
  2966. // var sum_in_count int64
  2967. // for _, it := range list {
  2968. // baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2969. // if it.MaxUnit == baseDrug.MaxUnit {
  2970. // it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2971. // it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2972. // sum_count += it.StockMaxNumber + it.StockMinNumber
  2973. // sum_in_count += it.WarehousingCount
  2974. // }
  2975. // }
  2976. // service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
  2977. //
  2978. // }
  2979. //}
  2980. //if errs != nil {
  2981. // utils.ErrorLog(errs.Error())
  2982. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateCancelStockFail)
  2983. // return
  2984. //}
  2985. c.ServeSuccessJSON(map[string]interface{}{
  2986. "msg": "1",
  2987. })
  2988. }
  2989. func (c *StockDrugApiController) GetAllConfig() {
  2990. adminUserInfo := c.GetAdminUserInfo()
  2991. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  2992. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  2993. stockIns, _ := service.FindStockInNumber(adminUserInfo.CurrentOrgId)
  2994. drugs, _ := service.GetDrugs(adminUserInfo.CurrentOrgId)
  2995. list, _ := service.GetAllStoreHouseListThree(adminUserInfo.CurrentOrgId)
  2996. configlist, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2997. appId := c.GetAdminUserInfo().CurrentAppId
  2998. doctorList, _ := service.GetAllDoctorListSix(adminUserInfo.CurrentOrgId, appId)
  2999. c.ServeSuccessJSON(map[string]interface{}{
  3000. "manufacturer": manufacturer,
  3001. "dealer": dealer,
  3002. "drugs": drugs,
  3003. "numbers": stockIns,
  3004. "list": list,
  3005. "configlist": configlist,
  3006. "doctorList": doctorList,
  3007. })
  3008. }
  3009. func (c *StockDrugApiController) GetAllDrugStock() {
  3010. adminUserInfo := c.GetAdminUserInfo()
  3011. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  3012. dealer_id, _ := c.GetInt64("dealer_id", 0)
  3013. drugs, err := service.FindAllDrugByManufactureId(manufacturer_id, dealer_id, adminUserInfo.CurrentOrgId)
  3014. if err == nil {
  3015. c.ServeSuccessJSON(map[string]interface{}{
  3016. "drugs": drugs,
  3017. })
  3018. } else {
  3019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3020. }
  3021. }
  3022. func (c *StockDrugApiController) GetDrugQueryInfo() {
  3023. page, _ := c.GetInt64("page", -1)
  3024. limit, _ := c.GetInt64("limit", -1)
  3025. keyword := c.GetString("keyword")
  3026. drug_category, _ := c.GetInt64("drug_category")
  3027. start_time := c.GetString("start_time")
  3028. end_time := c.GetString("end_time")
  3029. timeLayout := "2006-01-02"
  3030. loc, _ := time.LoadLocation("Local")
  3031. var startTime int64
  3032. if len(start_time) > 0 {
  3033. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3034. if err != nil {
  3035. fmt.Println(err)
  3036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3037. return
  3038. }
  3039. startTime = theTime.Unix()
  3040. }
  3041. var endTime int64
  3042. if len(end_time) > 0 {
  3043. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3044. if err != nil {
  3045. utils.ErrorLog(err.Error())
  3046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3047. return
  3048. }
  3049. endTime = theTime.Unix()
  3050. }
  3051. adminUserInfo := c.GetAdminUserInfo()
  3052. list, total, err := service.FindAllDrugStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, drug_category, startTime, endTime)
  3053. if err == nil {
  3054. c.ServeSuccessJSON(map[string]interface{}{
  3055. "list": list,
  3056. "total": total,
  3057. })
  3058. } else {
  3059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3060. }
  3061. }
  3062. func (this *StockDrugApiController) GetUserDetailInfo() {
  3063. order_id, _ := this.GetInt64("id")
  3064. if order_id <= 0 {
  3065. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3066. return
  3067. }
  3068. adminUserInfo := this.GetAdminUserInfo()
  3069. userDetails, err, total := service.FindDrugStockUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  3070. if err == nil {
  3071. this.ServeSuccessJSON(map[string]interface{}{
  3072. "list": userDetails,
  3073. "total": total,
  3074. })
  3075. } else {
  3076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3077. return
  3078. }
  3079. }
  3080. func (this *StockDrugApiController) GetCancelDrugOrderPrint() {
  3081. orderId := this.GetString("order_id")
  3082. ids := strings.Split(orderId, ",")
  3083. orgId := this.GetAdminUserInfo().CurrentOrgId
  3084. list, _ := service.GetCancelDrugOrderPrint(ids, orgId)
  3085. this.ServeSuccessJSON(map[string]interface{}{
  3086. "list": list,
  3087. })
  3088. }
  3089. func (this *StockDrugApiController) GetDrugCancelExportList() {
  3090. orderId := this.GetString("order_id")
  3091. ids := strings.Split(orderId, ",")
  3092. orgId := this.GetAdminUserInfo().CurrentOrgId
  3093. list, _ := service.GetDrugCancelExportList(ids, orgId)
  3094. this.ServeSuccessJSON(map[string]interface{}{
  3095. "list": list,
  3096. })
  3097. }
  3098. func (c *StockDrugApiController) GetDrugWarehouseInfoPrint() {
  3099. start_time := c.GetString("start_time")
  3100. end_time := c.GetString("end_time")
  3101. order_type, _ := c.GetInt64("order_type")
  3102. timeLayout := "2006-01-02"
  3103. loc, _ := time.LoadLocation("Local")
  3104. var startTime int64
  3105. if len(start_time) > 0 {
  3106. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3107. if err != nil {
  3108. fmt.Println(err)
  3109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3110. return
  3111. }
  3112. startTime = theTime.Unix()
  3113. }
  3114. var endTime int64
  3115. if len(end_time) > 0 {
  3116. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3117. if err != nil {
  3118. utils.ErrorLog(err.Error())
  3119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3120. return
  3121. }
  3122. endTime = theTime.Unix()
  3123. }
  3124. adminUserInfo := c.GetAdminUserInfo()
  3125. orgId := adminUserInfo.CurrentOrgId
  3126. if order_type == 1 {
  3127. list, err := service.GetDrugWarehouseInfoPrint(startTime, endTime, orgId)
  3128. if err == nil {
  3129. c.ServeSuccessJSON(map[string]interface{}{
  3130. "list": list,
  3131. })
  3132. return
  3133. }
  3134. }
  3135. }
  3136. func (c *StockDrugApiController) GetDrugOutOrderPrint() {
  3137. start_time := c.GetString("start_time")
  3138. end_time := c.GetString("end_time")
  3139. order_type, _ := c.GetInt64("order_type")
  3140. timeLayout := "2006-01-02"
  3141. loc, _ := time.LoadLocation("Local")
  3142. var startTime int64
  3143. if len(start_time) > 0 {
  3144. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3145. if err != nil {
  3146. fmt.Println(err)
  3147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3148. return
  3149. }
  3150. startTime = theTime.Unix()
  3151. }
  3152. var endTime int64
  3153. if len(end_time) > 0 {
  3154. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3155. if err != nil {
  3156. utils.ErrorLog(err.Error())
  3157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3158. return
  3159. }
  3160. endTime = theTime.Unix()
  3161. }
  3162. adminUserInfo := c.GetAdminUserInfo()
  3163. orgId := adminUserInfo.CurrentOrgId
  3164. if order_type == 2 {
  3165. list, err := service.GetDrugOutOrderInfoPrintList(startTime, endTime, orgId)
  3166. if err == nil {
  3167. c.ServeSuccessJSON(map[string]interface{}{
  3168. "list": list,
  3169. })
  3170. return
  3171. }
  3172. }
  3173. }
  3174. func (c *StockDrugApiController) GetConfigList() {
  3175. adminUserInfo := c.GetAdminUserInfo()
  3176. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  3177. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  3178. stockIns, _ := service.FindStockInNumber(adminUserInfo.CurrentOrgId)
  3179. list, _ := service.GetAllStoreHouseListThree(adminUserInfo.CurrentOrgId)
  3180. configlist, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  3181. appId := c.GetAdminUserInfo().CurrentAppId
  3182. doctorList, _ := service.GetAllDoctorListSix(adminUserInfo.CurrentOrgId, appId)
  3183. c.ServeSuccessJSON(map[string]interface{}{
  3184. "manufacturer": manufacturer,
  3185. "dealer": dealer,
  3186. "numbers": stockIns,
  3187. "list": list,
  3188. "configlist": configlist,
  3189. "doctorList": doctorList,
  3190. })
  3191. }
  3192. func (c *StockDrugApiController) CheckWarehousingInfo() {
  3193. warehousing_id, _ := c.GetInt64("warehousing_id")
  3194. orgId := c.GetAdminUserInfo().CurrentOrgId
  3195. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3196. //更改核对状态
  3197. err := service.CheckWarehousingInfo(warehousing_id, orgId)
  3198. if err == nil {
  3199. list, _ := service.GetWarehousingInfoByList(warehousing_id, orgId)
  3200. for _, item := range list {
  3201. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  3202. if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3203. //新增库存
  3204. service.AddDrugWarehouseStockMaxNumber(item.WarehousingCount, item.ID)
  3205. }
  3206. if item.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3207. //新增库存
  3208. service.AddDrugWarehouseStockMaxNumber(item.WarehousingCount, item.ID)
  3209. }
  3210. if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3211. //新增库存
  3212. service.AddDrugWarehouseStockMinNumber(item.WarehousingCount, item.ID)
  3213. }
  3214. Creator := c.GetAdminUserInfo().AdminUser.Id
  3215. flow := &models.DrugFlow{
  3216. WarehousingId: 0,
  3217. DrugId: item.DrugId,
  3218. Number: item.Number,
  3219. BatchNumber: item.BatchNumber,
  3220. Count: item.WarehousingCount,
  3221. UserOrgId: item.OrgId,
  3222. PatientId: 0,
  3223. SystemTime: time.Now().Unix(),
  3224. ConsumableType: 1,
  3225. IsSys: 0,
  3226. WarehousingOrder: item.WarehousingOrder,
  3227. WarehouseOutId: 0,
  3228. WarehouseOutOrderNumber: "",
  3229. IsEdit: 0,
  3230. CancelStockId: 0,
  3231. CancelOrderNumber: "",
  3232. Manufacturer: 0,
  3233. Dealer: 0,
  3234. Creator: Creator,
  3235. UpdateCreator: Creator,
  3236. Status: 1,
  3237. Ctime: time.Now().Unix(),
  3238. Mtime: 0,
  3239. Price: item.Price,
  3240. WarehousingDetailId: item.ID,
  3241. WarehouseOutDetailId: 0,
  3242. CancelOutDetailId: 0,
  3243. ExpireDate: item.ExpiryDate,
  3244. ProductDate: item.ProductDate,
  3245. MaxUnit: item.MaxUnit,
  3246. MinUnit: item.MinUnit,
  3247. StorehouseId: item.StorehouseId,
  3248. }
  3249. service.CreateDrugFlowTwo(flow)
  3250. //查询默认仓库
  3251. //查询默认仓库剩余多少库存
  3252. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
  3253. var sum_count int64
  3254. var sum_in_count int64
  3255. for _, it := range list {
  3256. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  3257. if it.MaxUnit == baseDrug.MaxUnit {
  3258. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  3259. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  3260. }
  3261. sum_count += it.StockMaxNumber + it.StockMinNumber
  3262. sum_in_count += it.WarehousingCount
  3263. }
  3264. service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
  3265. drugInfolist, _ := service.GetDrugSumCountByStorehouseId(item.StorehouseId, item.OrgId, item.DrugId)
  3266. var total_count int64 // 入库总数量
  3267. var over_count int64 //剩余库存
  3268. for _, it := range drugInfolist {
  3269. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  3270. if it.MaxUnit == baseDrug.MaxUnit {
  3271. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  3272. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  3273. }
  3274. }
  3275. for _, it := range drugInfolist {
  3276. total_count += it.WarehousingCount
  3277. over_count += it.StockMaxNumber + it.StockMinNumber
  3278. }
  3279. fmt.Println("over_countwoowoowowow", over_count)
  3280. //查询该仓库是否有默认数据
  3281. _, errcode := service.GetDrugStockCount(item.StorehouseId, item.DrugId, item.OrgId)
  3282. if errcode == gorm.ErrRecordNotFound {
  3283. drugStock := models.XtDrugStockCount{
  3284. UserOrgId: item.OrgId,
  3285. StorehouseId: item.StorehouseId,
  3286. SumInCount: total_count,
  3287. SumOutCount: 0,
  3288. SumCancelCount: 0,
  3289. DrugId: item.DrugId,
  3290. Ctime: time.Now().Unix(),
  3291. Mtime: 0,
  3292. Status: 1,
  3293. FlushCount: over_count,
  3294. SumActOutCount: 0,
  3295. }
  3296. service.CreateDrugStockSum(drugStock)
  3297. } else if errcode == nil {
  3298. service.UpdateDrugStockSum(item.StorehouseId, item.DrugId, item.OrgId, total_count, over_count)
  3299. }
  3300. }
  3301. c.ServeSuccessJSON(map[string]interface{}{
  3302. "list": list,
  3303. })
  3304. }
  3305. }
  3306. func (c *StockDrugApiController) ReturnCheckWarehouseingInfo() {
  3307. warehousing_id, _ := c.GetInt64("warehousing_id")
  3308. orgId := c.GetAdminUserInfo().CurrentOrgId
  3309. list, _ := service.GetWarehousingInfoByList(warehousing_id, orgId)
  3310. for _, item := range list {
  3311. //查询该药品是否有出库数据
  3312. outInfo, _ := service.GetDrugWarehouseOutByWarehouseInfoId(item.ID, item.DrugId, item.OrgId)
  3313. if len(outInfo) > 0 {
  3314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCheckGoodParamWrong)
  3315. return
  3316. }
  3317. }
  3318. for _, item := range list {
  3319. //删除流水
  3320. service.UpdateWarehousingInfoFlow(item.ID, orgId)
  3321. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  3322. if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3323. //新增库存
  3324. service.AddDrugReturnWarehouseStockMaxNumber(item.WarehousingCount, item.ID)
  3325. }
  3326. if item.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3327. //新增库存
  3328. service.AddDrugReturnWarehouseStockMaxNumber(item.WarehousingCount, item.ID)
  3329. }
  3330. if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3331. //新增库存
  3332. service.AddDrugReturnWarehouseStockMinNumber(item.WarehousingCount, item.ID)
  3333. }
  3334. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3335. stockInfoList, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, orgId, item.DrugId)
  3336. var sum_count int64
  3337. var sum_in_count int64
  3338. for _, its := range stockInfoList {
  3339. if its.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3340. sum_count += its.StockMaxNumber * medical.MinNumber
  3341. sum_in_count += its.WarehousingCount * medical.MinNumber
  3342. }
  3343. if its.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3344. sum_count += its.StockMaxNumber
  3345. sum_in_count += its.WarehousingCount
  3346. }
  3347. if its.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3348. sum_count += its.StockMaxNumber
  3349. sum_in_count += its.WarehousingCount
  3350. }
  3351. }
  3352. service.UpdateBaseDrugSumInfo(sum_count, item.DrugId, item.OrgId, sum_in_count)
  3353. var total_count int64
  3354. if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3355. total_count = item.WarehousingCount * medical.MinNumber
  3356. }
  3357. if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3358. total_count = item.WarehousingCount
  3359. }
  3360. if item.MaxUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  3361. total_count = item.WarehousingCount * medical.MinNumber
  3362. }
  3363. drugInfolist, _ := service.GetDrugSumCountByStorehouseId(item.StorehouseId, item.OrgId, item.DrugId)
  3364. var over_count int64 //剩余库存
  3365. for _, it := range drugInfolist {
  3366. if it.MaxUnit == medical.MaxUnit {
  3367. it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
  3368. }
  3369. }
  3370. for _, it := range drugInfolist {
  3371. over_count += it.StockMaxNumber*medical.MinNumber + it.StockMinNumber
  3372. }
  3373. //扣减库存
  3374. service.ReduceDrugStockCount(item.StorehouseId, item.DrugId, item.OrgId, total_count, over_count)
  3375. }
  3376. //更新审核
  3377. err := service.ReturnCheckWarehouseingInfo(warehousing_id, orgId)
  3378. if err == nil {
  3379. c.ServeSuccessJSON(map[string]interface{}{
  3380. "msg": "反审核成功!",
  3381. })
  3382. return
  3383. }
  3384. }
  3385. func (c *StockDrugApiController) CheckDrugOut() {
  3386. warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
  3387. orgId := c.GetAdminUserInfo().CurrentOrgId
  3388. warehousingOutInfoList, _ := service.GetDrugWarehouseOutListById(warehouse_out_id, orgId)
  3389. drugWarehouseOut, _ := service.GetDrugWarehouseOutByLastId(warehouse_out_id)
  3390. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3391. for _, it := range warehousingOutInfoList {
  3392. var total_count int64
  3393. var out_count int64
  3394. //查询剩余库存
  3395. stockInfo, _ := service.GetDrugAllStockInfo(it.StorehouseId, it.OrgId, it.DrugId)
  3396. drup, _ := service.FindBaseDrugLibRecord(it.OrgId, it.DrugId)
  3397. for _, item := range stockInfo {
  3398. if item.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
  3399. item.StockMaxNumber = item.StockMaxNumber * drup.MinNumber
  3400. }
  3401. total_count += item.StockMaxNumber + item.StockMinNumber
  3402. }
  3403. //if it.CountUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
  3404. // it.Count = it.Count * drup.MinNumber
  3405. //}
  3406. //out_count += it.Count
  3407. //出库数量累加
  3408. if it.CountUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
  3409. out_count = it.Count * drup.MinNumber
  3410. }
  3411. if it.CountUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
  3412. out_count = it.Count
  3413. }
  3414. if it.CountUnit == drup.MinUnit && drup.MaxUnit == drup.MinUnit {
  3415. out_count = it.Count
  3416. }
  3417. if out_count > total_count {
  3418. c.ServeSuccessJSON(map[string]interface{}{
  3419. "warehousingOutInfoList": warehousingOutInfoList,
  3420. "drug_name": drup.DrugName,
  3421. "dose": drup.Dose,
  3422. "dose_unit": drup.DoseUnit,
  3423. "min_number": drup.MinNumber,
  3424. "min_unit": drup.MinUnit,
  3425. "max_unit": drup.MaxUnit,
  3426. "msg": 2,
  3427. })
  3428. return
  3429. }
  3430. }
  3431. for _, it := range warehousingOutInfoList {
  3432. drup, _ := service.FindBaseDrugLibRecord(it.OrgId, it.DrugId)
  3433. //出库逻辑
  3434. service.AutoDrugDeliverInfoFourtyOne(orgId, it.Count, &drugWarehouseOut, &drup, it)
  3435. medical, _ := service.GetBaseDrugMedical(it.DrugId)
  3436. //查询剩余库存
  3437. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, it.OrgId, it.DrugId)
  3438. var sum_count int64
  3439. for _, its := range stockInfo {
  3440. if its.MaxUnit == medical.MaxUnit {
  3441. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  3442. }
  3443. sum_count += its.StockMaxNumber + its.StockMinNumber
  3444. }
  3445. service.UpdateBaseDrugSumTwo(it.DrugId, sum_count, it.OrgId)
  3446. ////出库数量累加
  3447. var out_count_one int64
  3448. if it.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3449. out_count_one = it.Count * medical.MinNumber
  3450. }
  3451. if it.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3452. out_count_one = it.Count
  3453. }
  3454. if it.CountUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  3455. out_count_one = it.Count
  3456. }
  3457. fmt.Println("out_count23233232323woede", out_count_one)
  3458. //增加出库数量
  3459. service.AddDrugCount(it.DrugId, it.OrgId, storeHouseConfig.DrugStorehouseOut, out_count_one)
  3460. //查询该药品剩余库存
  3461. infolist, _ := service.FindDrugWarehouseInfoFlushCountByStorehouse(it.DrugId, it.OrgId, storeHouseConfig.DrugStorehouseOut)
  3462. var over_count int64
  3463. for _, its := range infolist {
  3464. over_count += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
  3465. }
  3466. service.UpdateDrugStockCount(it.DrugId, it.OrgId, storeHouseConfig.DrugStorehouseOut, over_count)
  3467. }
  3468. out := models.DrugWarehouseOut{
  3469. IsCheck: 1,
  3470. }
  3471. service.UpdateCheckDrugOut(out, warehouse_out_id)
  3472. info := models.DrugWarehouseOutInfo{
  3473. IsCheck: 1,
  3474. }
  3475. service.UpdateCheckDrugOutInfo(info, warehouse_out_id)
  3476. c.ServeSuccessJSON(map[string]interface{}{
  3477. "warehousingOutInfoList": warehousingOutInfoList,
  3478. "drug_name": "",
  3479. "dose": "",
  3480. "dose_unit": "",
  3481. "min_number": "",
  3482. "min_unit": "",
  3483. "max_unit": "",
  3484. "msg": 1,
  3485. })
  3486. }
  3487. func (c *StockDrugApiController) ToReturnCheck() {
  3488. warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
  3489. out := models.DrugWarehouseOut{
  3490. IsCheck: 2,
  3491. }
  3492. service.UpdateCheckDrugOut(out, warehouse_out_id)
  3493. outInfo := models.DrugWarehouseOutInfo{
  3494. IsCheck: 2,
  3495. }
  3496. service.UpdateCheckDrugOutInfoList(outInfo, warehouse_out_id)
  3497. creater := c.GetAdminUserInfo().AdminUser.Id
  3498. orgId := c.GetAdminUserInfo().CurrentOrgId
  3499. list, _ := service.GetDrugWarehouseOutListById(warehouse_out_id, orgId)
  3500. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3501. //调用出库逻辑
  3502. for _, item := range list {
  3503. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  3504. if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3505. service.UpdateDrugMaxNumber(item.Count, item.WarehouseInfoId)
  3506. var sum_out_count int64
  3507. sum_out_count = item.Count * medical.MinNumber
  3508. service.ModifyReduceDrugInformation(item.DrugId, sum_out_count, item.OrgId)
  3509. drugInfoList, _ := service.FindDrugWarehouseInfoList(item.DrugId, item.OrgId)
  3510. var drug_max_number int64
  3511. var drug_min_number int64
  3512. for _, item := range drugInfoList {
  3513. drug_max_number += item.StockMaxNumber
  3514. drug_min_number += item.StockMinNumber
  3515. }
  3516. drugFlushInfo := models.XtDrugWarehouseFlushInfo{
  3517. DrugMaxNumber: drug_max_number,
  3518. UserOrgId: item.OrgId,
  3519. WarehouseOutId: item.ID,
  3520. Type: 2,
  3521. SystemTime: item.SysRecordTime,
  3522. PatientId: 0,
  3523. Ctime: time.Now().Unix(),
  3524. Mtime: 0,
  3525. BatchNumberId: item.WarehouseInfoId,
  3526. DrugId: item.DrugId,
  3527. Count: item.Count,
  3528. WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
  3529. Creater: creater,
  3530. DrugMinNumber: drug_min_number,
  3531. Unit: item.CountUnit,
  3532. Status: 1,
  3533. }
  3534. service.CreatedDrugFlushInfo(drugFlushInfo)
  3535. service.DeleteDrugOutFlow(item.ID, item.OrgId)
  3536. }
  3537. if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3538. service.UpdateDrugMaxNumber(item.Count, item.WarehouseInfoId)
  3539. var sum_out_count int64
  3540. sum_out_count = item.Count * medical.MinNumber
  3541. service.ModifyReduceDrugInformation(item.DrugId, sum_out_count, item.OrgId)
  3542. service.DeleteDrugOutFlow(item.ID, item.OrgId)
  3543. }
  3544. if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3545. service.UpdateDrugMinNumber(item.Count, item.WarehouseInfoId)
  3546. var sum_out_count int64
  3547. sum_out_count = item.Count
  3548. service.ModifyReduceDrugInformation(item.DrugId, sum_out_count, item.OrgId)
  3549. service.DeleteDrugOutFlow(item.ID, item.OrgId)
  3550. }
  3551. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
  3552. var sum_count int64
  3553. for _, its := range stockInfo {
  3554. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  3555. if its.MaxUnit == baseDrug.MaxUnit {
  3556. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3557. }
  3558. sum_count += its.StockMaxNumber + its.StockMinNumber
  3559. }
  3560. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.OrgId)
  3561. //出库数量累加
  3562. var out_count int64
  3563. if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3564. out_count = item.Count * medical.MinNumber
  3565. }
  3566. if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3567. out_count = item.Count
  3568. }
  3569. if item.CountUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  3570. out_count = item.Count
  3571. }
  3572. //增加出库数量
  3573. service.ReduceDrugCount(item.DrugId, item.OrgId, storeHouseConfig.DrugStorehouseOut, out_count)
  3574. //查询该药品剩余库存
  3575. infolist, _ := service.FindDrugWarehouseInfoFlushCountByStorehouse(item.DrugId, item.OrgId, storeHouseConfig.DrugStorehouseOut)
  3576. var over_count int64
  3577. for _, its := range infolist {
  3578. over_count += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
  3579. }
  3580. service.UpdateDrugStockCount(item.DrugId, item.OrgId, storeHouseConfig.DrugStorehouseOut, over_count)
  3581. }
  3582. c.ServeSuccessJSON(map[string]interface{}{
  3583. "out": out,
  3584. })
  3585. }
  3586. func (c *StockDrugApiController) CheckCancelDrugStock() {
  3587. cancelstock_id, _ := c.GetInt64("cancelstock_id")
  3588. orgId := c.GetAdminUserInfo().CurrentOrgId
  3589. cancelDrugStock, _ := service.GetCancelDrugStock(cancelstock_id, orgId)
  3590. list, _ := service.GetCancelDrugStockList(cancelstock_id, orgId)
  3591. cancelStock := models.DrugCancelStock{
  3592. IsCheck: 1,
  3593. }
  3594. var manufacturer_id int64
  3595. var dealer_id int64
  3596. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3597. dealerList, _ := service.GetAllDealerList(orgId)
  3598. creater := c.GetAdminUserInfo().AdminUser.Id
  3599. //查询退库单据
  3600. cancelList, _ := service.GetDrugCancelCheckByIdTwenty(cancelstock_id, orgId)
  3601. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3602. var cancel_total_count int64
  3603. var out_count int64
  3604. for _, its := range cancelList {
  3605. medical, _ := service.GetBaseDrugMedical(its.DrugId)
  3606. //查询该批次的出库数据
  3607. outList, _ := service.GetDrugWarehouseOutList(its.BatchNumberId, its.DrugId, its.OrgId)
  3608. for _, item := range outList {
  3609. if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3610. out_count += item.Count * medical.MinNumber
  3611. }
  3612. if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3613. out_count += item.Count
  3614. }
  3615. if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3616. out_count += item.Count
  3617. }
  3618. }
  3619. if its.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3620. cancel_total_count += its.Count * medical.MinNumber
  3621. }
  3622. if its.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3623. cancel_total_count += its.Count
  3624. }
  3625. if its.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3626. cancel_total_count += its.Count
  3627. }
  3628. if cancel_total_count > out_count {
  3629. c.ServeSuccessJSON(map[string]interface{}{
  3630. "drug_name": medical.DrugName,
  3631. "dose": medical.Dose,
  3632. "dose_unit": medical.DoseUnit,
  3633. "min_number": medical.MinNumber,
  3634. "min_unit": medical.MinUnit,
  3635. "max_unit": medical.MaxUnit,
  3636. "msg": "2",
  3637. })
  3638. return
  3639. }
  3640. }
  3641. for _, its := range list {
  3642. for _, item := range manufacturerList {
  3643. if its.Manufacturer == item.ManufacturerName {
  3644. manufacturer_id = item.ID
  3645. }
  3646. }
  3647. for _, item := range dealerList {
  3648. if its.Dealer == item.DealerName {
  3649. dealer_id = item.ID
  3650. }
  3651. }
  3652. //查询该批次的退库数量
  3653. drugFlow := models.DrugFlow{
  3654. ID: 0,
  3655. WarehousingId: its.BatchNumberId,
  3656. DrugId: its.DrugId,
  3657. Number: its.Number,
  3658. BatchNumber: "",
  3659. Count: its.Count,
  3660. UserOrgId: its.OrgId,
  3661. PatientId: 0,
  3662. SystemTime: cancelDrugStock.ReturnTime,
  3663. ConsumableType: 4,
  3664. IsSys: 0,
  3665. WarehousingOrder: "",
  3666. WarehouseOutId: 0,
  3667. WarehouseOutOrderNumber: "",
  3668. IsEdit: 0,
  3669. CancelStockId: 0,
  3670. CancelOrderNumber: its.OrderNumber,
  3671. Manufacturer: manufacturer_id,
  3672. Dealer: dealer_id,
  3673. Creator: creater,
  3674. UpdateCreator: 0,
  3675. Status: 1,
  3676. Ctime: time.Now().Unix(),
  3677. Mtime: 0,
  3678. Price: its.Price,
  3679. WarehousingDetailId: its.BatchNumberId,
  3680. WarehouseOutDetailId: 0,
  3681. CancelOutDetailId: its.ID,
  3682. ExpireDate: its.ExpiryDate,
  3683. ProductDate: its.ProductDate,
  3684. MaxUnit: its.MaxUnit,
  3685. MinUnit: "",
  3686. StockMaxNumber: 0,
  3687. StockMinNumber: 0,
  3688. LastStockMaxNumber: 0,
  3689. LastStockMinNumber: 0,
  3690. AdviceId: 0,
  3691. SupplyWarehouseId: 0,
  3692. SupplyCancelOutId: 0,
  3693. SupplyWarehouseDetailInfo: 0,
  3694. StorehouseId: its.StorehouseId,
  3695. SecondWarehouseInfoId: 0,
  3696. AdminUserId: 0,
  3697. LastPrice: 0,
  3698. StockCount: "",
  3699. PharmacyId: 0,
  3700. }
  3701. service.CreateDrugFlowOne(drugFlow)
  3702. medical, _ := service.GetBaseDrugMedical(its.DrugId)
  3703. if its.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3704. var sum_cancel_count int64
  3705. sum_cancel_count += its.Count * medical.MinNumber
  3706. //退库数量增加
  3707. //service.ModifyAddCancelAddInfomation(its.DrugId,sum_cancel_count,its.OrgId,its.StorehouseId)
  3708. //出库数量减少
  3709. service.ModifyAddDrugOutReduceInfomation(its.DrugId, sum_cancel_count, its.OrgId, its.StorehouseId)
  3710. }
  3711. if its.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3712. //退库数量增加
  3713. //service.ModifyAddCancelAddInfomation(its.DrugId,its.Count,its.OrgId,its.StorehouseId)
  3714. //出库数量减少
  3715. service.ModifyAddDrugOutReduceInfomation(its.DrugId, its.Count, its.OrgId, its.StorehouseId)
  3716. }
  3717. if its.MaxUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  3718. //退库数量增加
  3719. //service.ModifyAddCancelAddInfomation(its.DrugId,its.Count,its.OrgId,its.StorehouseId)
  3720. //出库数量减少
  3721. service.ModifyAddDrugOutReduceInfomation(its.DrugId, its.Count, its.OrgId, its.StorehouseId)
  3722. }
  3723. }
  3724. for _, its := range cancelList {
  3725. medical, _ := service.GetBaseDrugMedical(its.DrugId)
  3726. //扣减库存
  3727. if its.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3728. service.ModifyDrugWarehouseInfoStockMaxNumber(its.Count, its.DrugId, its.OrgId, its.BatchNumberId)
  3729. }
  3730. if its.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3731. service.ModifyDrugWarehouseInfoStockMinNumber(its.Count, its.DrugId, its.OrgId, its.BatchNumberId)
  3732. }
  3733. if its.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3734. service.ModifyDrugWarehouseInfoStockMaxNumber(its.Count, its.DrugId, its.OrgId, its.BatchNumberId)
  3735. }
  3736. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, its.OrgId, its.DrugId)
  3737. var sum_count int64
  3738. for _, its := range stockInfo {
  3739. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  3740. if its.MaxUnit == baseDrug.MaxUnit {
  3741. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3742. }
  3743. sum_count += its.StockMaxNumber + its.StockMinNumber
  3744. }
  3745. service.UpdateBaseDrugSumTwo(its.DrugId, sum_count, its.OrgId)
  3746. var cancel_count int64
  3747. if its.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3748. cancel_count = its.Count * medical.MinNumber
  3749. }
  3750. if its.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3751. cancel_count = its.Count
  3752. }
  3753. if its.MaxUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  3754. cancel_count = its.Count * medical.MinNumber
  3755. }
  3756. cancelInfo, _ := service.GetDrugAllStockInfo(its.StorehouseId, its.OrgId, its.DrugId)
  3757. var over_count int64
  3758. for _, its := range cancelInfo {
  3759. if its.MaxUnit == medical.MaxUnit {
  3760. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  3761. }
  3762. over_count += its.StockMaxNumber + its.StockMinNumber
  3763. }
  3764. service.AddCancelSumCount(its.StorehouseId, its.DrugId, its.OrgId, cancel_count, over_count)
  3765. service.ModifyCancelStock(cancelstock_id, cancelStock, orgId)
  3766. }
  3767. //新增库存
  3768. c.ServeSuccessJSON(map[string]interface{}{
  3769. "drug_name": "",
  3770. "dose": "",
  3771. "dose_unit": "",
  3772. "min_number": "",
  3773. "min_unit": "",
  3774. "max_unit": "",
  3775. "msg": "1",
  3776. })
  3777. return
  3778. }
  3779. func (c *StockDrugApiController) ReturnDrugCancelStock() {
  3780. cancelstock_id, _ := c.GetInt64("cancelstock_id")
  3781. orgId := c.GetAdminUserInfo().CurrentOrgId
  3782. drugStock := models.DrugCancelStock{
  3783. IsCheck: 2,
  3784. }
  3785. err := service.ReturnDrugCancelStock(cancelstock_id, drugStock)
  3786. list, err := service.GetDrugCancelStockInfo(cancelstock_id, orgId)
  3787. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3788. for _, item := range list {
  3789. //删除流水
  3790. service.ModifyDrugFlowByCancelId(item.ID, item.DrugId, item.OrgId)
  3791. //扣减库存
  3792. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  3793. if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3794. var sum_cancel_count int64
  3795. sum_cancel_count += item.Count * medical.MinNumber
  3796. service.ModifyDrugMaxNumberWarehouseInfo(item.BatchNumberId, item.Count, item.OrgId)
  3797. //退库数量减少
  3798. //service.ModifyDrugCancelWarehouseInfo(item.DrugId,sum_cancel_count,item.OrgId,item.StorehouseId)
  3799. //出库数量增加
  3800. service.ModifyAddDrugOutAddInfomation(item.DrugId, sum_cancel_count, item.OrgId, item.StorehouseId)
  3801. }
  3802. if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3803. service.ModifyDrugMinNumberWarehouseInfo(item.BatchNumberId, item.Count, item.OrgId)
  3804. //退库数量减少
  3805. //service.ModifyDrugCancelWarehouseInfo(item.DrugId,item.Count,item.OrgId,item.StorehouseId)
  3806. //出库数量增加
  3807. service.ModifyAddDrugOutAddInfomation(item.DrugId, item.Count, item.OrgId, item.StorehouseId)
  3808. }
  3809. if item.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3810. service.ModifyDrugMaxNumberWarehouseInfo(item.BatchNumberId, item.Count, item.OrgId)
  3811. //退库数量减少
  3812. //service.ModifyDrugCancelWarehouseInfo(item.DrugId,item.Count,item.OrgId,item.StorehouseId)
  3813. //出库数量增加
  3814. service.ModifyAddDrugOutAddInfomation(item.DrugId, item.Count, item.OrgId, item.StorehouseId)
  3815. }
  3816. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
  3817. var sum_count int64
  3818. for _, its := range stockInfo {
  3819. if its.MaxUnit == medical.MaxUnit {
  3820. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  3821. }
  3822. sum_count += its.StockMaxNumber + its.StockMinNumber
  3823. }
  3824. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.OrgId)
  3825. var cancel_count int64
  3826. if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3827. cancel_count = item.Count * medical.MinNumber
  3828. }
  3829. if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3830. cancel_count = item.Count
  3831. }
  3832. if item.MaxUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  3833. cancel_count = item.Count * medical.MinNumber
  3834. }
  3835. cancelInfo, _ := service.GetDrugAllStockInfo(item.StorehouseId, item.OrgId, item.DrugId)
  3836. var over_count int64
  3837. for _, its := range cancelInfo {
  3838. if its.MaxUnit == medical.MaxUnit {
  3839. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  3840. }
  3841. over_count += its.StockMaxNumber + its.StockMinNumber
  3842. }
  3843. //退库数量减少,更新剩余库存
  3844. service.ReduceCancelSumCount(item.StorehouseId, item.DrugId, item.OrgId, cancel_count, over_count)
  3845. }
  3846. if err == nil {
  3847. c.ServeSuccessJSON(map[string]interface{}{
  3848. "msg": "反审核成功!",
  3849. })
  3850. return
  3851. }
  3852. }