stock_in_api_controller.go 273KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "reflect"
  6. "strconv"
  7. "strings"
  8. "time"
  9. "XT_New/enums"
  10. "XT_New/models"
  11. "XT_New/service"
  12. "XT_New/utils"
  13. "github.com/astaxie/beego"
  14. "github.com/jinzhu/gorm"
  15. "github.com/mozillazg/go-pinyin"
  16. )
  17. type StockManagerApiController struct {
  18. BaseAuthAPIController
  19. }
  20. func StockManagerApiRegistRouters() {
  21. //入库管理和其他入库管理相关接口
  22. beego.Router("/api/warehouse/create", &StockManagerApiController{}, "post:CreateWarehouse")
  23. beego.Router("/api/warehouse/list", &StockManagerApiController{}, "get:GetWarehouseList")
  24. beego.Router("/api/warehouse/delete", &StockManagerApiController{}, "post:DeleteWarehouse")
  25. beego.Router("/api/warehouseinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseInfo")
  26. beego.Router("/api/warehouseinfo/list", &StockManagerApiController{}, "get:GetWarehouseInfoList")
  27. beego.Router("/api/warehouse/edit", &StockManagerApiController{}, "post:EditWarehouse")
  28. //退货管理和其他退货管理相关接口
  29. beego.Router("/api/salesreturn/create", &StockManagerApiController{}, "post:CreateSalesReturn")
  30. beego.Router("/api/salesreturn/delete", &StockManagerApiController{}, "post:DeleteSalesReturn")
  31. beego.Router("/api/salesreturninfo/delete", &StockManagerApiController{}, "post:DeleteSalesReturnInfo")
  32. beego.Router("/api/salesreturninfo/list", &StockManagerApiController{}, "get:GetSalesReturnInfoList")
  33. beego.Router("/api/salesreturn/list", &StockManagerApiController{}, "get:GetSalesReturnList")
  34. beego.Router("/api/salesreturn/edit", &StockManagerApiController{}, "post:EditReturnInfo")
  35. //出库管理和其他出库管理相关接口
  36. beego.Router("/api/warehouseout/create", &StockManagerApiController{}, "post:CreateWarehouseOut")
  37. beego.Router("/api/warehouseout/delete", &StockManagerApiController{}, "post:DeleteWarehouseOut")
  38. beego.Router("/api/warehouseoutinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseOutInfo")
  39. beego.Router("/api/warehouseout/list", &StockManagerApiController{}, "get:GetWarehouseOutList")
  40. beego.Router("/api/warehouseout/edit", &StockManagerApiController{}, "post:EditWarehouseOut")
  41. beego.Router("/api/warehouseout/info", &StockManagerApiController{}, "get:GetWarehouseOutInfoList")
  42. //出库退库管理和其他出库退库管理相关接口
  43. beego.Router("/api/cancelstock/create", &StockManagerApiController{}, "post:CreateCancelStock")
  44. beego.Router("/api/cancelstock/list", &StockManagerApiController{}, "get:GetCancelStockList")
  45. beego.Router("/api/cancelstock/info", &StockManagerApiController{}, "get:GetCancelStockInfoList")
  46. beego.Router("/api/cancelstock/delete", &StockManagerApiController{}, "post:DeleteCancelStock")
  47. beego.Router("/api/cancelstockinfo/delete", &StockManagerApiController{}, "post:DeleteCancelStockInfo")
  48. beego.Router("/api/cancelstockinfo/edit", &StockManagerApiController{}, "post:EditCancelStock")
  49. beego.Router("/api/cancelstockinfo/config", &StockManagerApiController{}, "get:GetCancelStockConfig")
  50. //库存相关全局配置
  51. beego.Router("/api/stock/config", &StockManagerApiController{}, "get:GetAllConfig")
  52. beego.Router("/api/return/config", &StockManagerApiController{}, "get:GetAllSalesReturnConfig")
  53. //库存查询
  54. beego.Router("/api/stock/query", &StockManagerApiController{}, "get:GetQueryInfo")
  55. beego.Router("/api/stock/detail", &StockManagerApiController{}, "get:GetDetailInfo")
  56. beego.Router("/api/warehouseout/user", &StockManagerApiController{}, "get:GetUserDetailInfo")
  57. beego.Router("/api/warehouseout/postsearchstock", &StockManagerApiController{}, "Get:PostSearchStock")
  58. beego.Router("/api/warehouseout/getoutstocktotalcount", &StockManagerApiController{}, "Get:GetOutStockTotalCount")
  59. beego.Router("/api/good/postgoodinformation", &StockManagerApiController{}, "Post:AddGoodInformation")
  60. beego.Router("/api/good/postdruginformation", &StockManagerApiController{}, "Post:AddDrugInformation")
  61. beego.Router("/api/good/initializtion", &StockManagerApiController{}, "Get:GetInitializtion")
  62. beego.Router("/api/good/getwarehouseorderinfolist", &StockManagerApiController{}, "Get:GetWarehouseOrderInfolist")
  63. beego.Router("/api/good/postsearchgoodlist", &StockManagerApiController{}, "Get:PostSearchGoodList")
  64. beego.Router("/api/good/getallstocklist", &StockManagerApiController{}, "Get:GetAllStockList")
  65. beego.Router("/api/stock/getstocklistbyid", &StockManagerApiController{}, "Get:GetStockListById")
  66. beego.Router("/api/stock/getstockoutlist", &StockManagerApiController{}, "Get:GetStockOutList")
  67. beego.Router("/api/good/getstockdrugcount", &StockManagerApiController{}, "Get:GetStockDrugCount")
  68. beego.Router("/api/good/getorderdetialbyorderid", &StockManagerApiController{}, "Get:GetOrderDetialByOrderId")
  69. beego.Router("/api/good/getorderdetaibyid", &StockManagerApiController{}, "Get:GetOrderDetailById")
  70. beego.Router("/api/good/getsingleoutorderdetail", &StockManagerApiController{}, "Get:GetSingleOutOrderDetail")
  71. beego.Router("/api/stock/getexportstocklist", &StockManagerApiController{}, "Get:GetExprotStockList")
  72. beego.Router("/api/stock/getoutexprotlist", &StockManagerApiController{}, "Get:GetOutExprotList")
  73. beego.Router("/api/stock/getsinglecancelorder", &StockManagerApiController{}, "Get:GetSingleCancelOrder")
  74. beego.Router("/api/stock/getcancelstockorderprint", &StockManagerApiController{}, "Get:GetCancelStockOrderPrint")
  75. beego.Router("/api/stock/getstockbatchnumber", &StockManagerApiController{}, "Get:GetStockBatchNumber")
  76. beego.Router("/api/stock/getstockflow", &StockManagerApiController{}, "Get:GetStockFlow")
  77. beego.Router("/api/cancel/getcancelexportlist", &StockManagerApiController{}, "Get:GetCancelExportList")
  78. //耗材调价
  79. beego.Router("/api/stock/postsearchgoodwarehouselist", &StockManagerApiController{}, "Get:GetSearchGoodWarehouseList")
  80. beego.Router("/api/stock/saveadjustprice", &StockManagerApiController{}, "Post:SaveAdjuestPrice")
  81. beego.Router("/api/stock/getallstockprice", &StockManagerApiController{}, "Get:GetAllStockPrice")
  82. beego.Router("/api/stock/savecheckedprice", &StockManagerApiController{}, "Get:SaveCheckPrice")
  83. beego.Router("/api/stock/getadjustpriceinfo", &StockManagerApiController{}, "Get:GetAdjustPriceById")
  84. beego.Router("/api/stock/savereportstock", &StockManagerApiController{}, "Post:SaveReportStock")
  85. beego.Router("/api/stock/getreportstocklist", &StockManagerApiController{}, "Get:GetReportStockList")
  86. beego.Router("/api/stock/savecheckdamage", &StockManagerApiController{}, "Get:SaveCheckDamage")
  87. beego.Router("/api/stock/saveinventory", &StockManagerApiController{}, "Post:SaveInventory")
  88. beego.Router("/api/stock/getinventorylist", &StockManagerApiController{}, "Get:GetInventorylist")
  89. beego.Router("/api/stock/savecheckinventory", &StockManagerApiController{}, "Get:SaveCheckInventory")
  90. beego.Router("/api/stock/getmodifypriceDetail", &StockManagerApiController{}, "Get:GetModifyPriceDetail")
  91. beego.Router("/api/stock/updatestockprice", &StockManagerApiController{}, "Get:UpdateStockPrice")
  92. beego.Router("/api/stock/deletestockprice", &StockManagerApiController{}, "Get:DeleteStockPrice")
  93. beego.Router("/api/stock/getstockdamagedetal", &StockManagerApiController{}, "Get:GetStockDamageDetail")
  94. beego.Router("/api/sotck/modifyprice", &StockManagerApiController{}, "Get:ModifyPrice")
  95. beego.Router("/api/stock/deletestockdamage", &StockManagerApiController{}, "Get:DeleteDamage")
  96. beego.Router("/api/stock/getstockdamagebyid", &StockManagerApiController{}, "Get:GetStockDamageById")
  97. beego.Router("api/sotck/getinventorydetail", &StockManagerApiController{}, "Get:GetInventoryDetail")
  98. beego.Router("/api/stock/modifyinventory", &StockManagerApiController{}, "Get:ModifyInventory")
  99. beego.Router("/api/stock/deleteinventory", &StockManagerApiController{}, "Get:DeleteInventory")
  100. beego.Router("/api/stock/getinventorydetaillist", &StockManagerApiController{}, "Get:GetInventoryDetailList")
  101. beego.Router("/api/stock/getinventoryprintlist", &StockManagerApiController{}, "Get:GetInventoryPrintList")
  102. beego.Router("/api/stock/getinventorydetailprintlist", &StockManagerApiController{}, "Get:GetInventoryDetailPrintList")
  103. beego.Router("/api/drug/deletedrugprice", &StockManagerApiController{}, "Get:DeleteDrugPrice")
  104. beego.Router("/api/stock/getgoodwarehouselist", &StockManagerApiController{}, "Get:GetGoodWarehouseList")
  105. beego.Router("/api/stock/proofinventory", &StockManagerApiController{}, "Get:ProofInventory")
  106. beego.Router("/api/stock/getwarehousetotal", &StockManagerApiController{}, "Get:GetWarehouseTotal")
  107. beego.Router("/api/stock/getgoodinventorywarehouselist", &StockManagerApiController{}, "Get:GetGoodInventoryWarehouseList")
  108. beego.Router("/api/stock/savestockinentorylist", &StockManagerApiController{}, "Post:SaveStockInventoryList")
  109. beego.Router("/api/sotck/getdamagedetailbygoodid", &StockManagerApiController{}, "Get:GetDamageDetailByGoodId")
  110. beego.Router("/api/stock/getinventoryexportlist", &StockManagerApiController{}, "Get:GetInventoryExportList")
  111. //处理历史数据
  112. beego.Router("/api/stock/updatecancelstockorder", &StockManagerApiController{}, "Get:UpdateCancelStockOrder")
  113. beego.Router("/api/stock/getdrugdetailsummary", &StockManagerApiController{}, "Get:GetDrugDetailSummary")
  114. beego.Router("/api/stock/getgooddetialsummary", &StockManagerApiController{}, "Get:GetGoodDetailSummary")
  115. //库存优化接口
  116. beego.Router("/api/stock/checkwarehouseout", &StockManagerApiController{}, "Get:CheckWarehouseOut")
  117. beego.Router("/api/stock/returncheckwarehouseout", &StockManagerApiController{}, "Get:ReturnCheckWarehouseOut")
  118. beego.Router("/api/stock/tocheckwarehouseinfo", &StockManagerApiController{}, "Get:CheckWarehouseInfo")
  119. beego.Router("/api/stock/returncheckwarehouseinfo", &StockManagerApiController{}, "Get:ReturnCheckWarehouseInfo")
  120. beego.Router("/api/stock/checkstockwarehouseinfo", &StockManagerApiController{}, "Get:CheckStockWarehouseInfo")
  121. beego.Router("/api/stock/checkreturnstockwarehouseinfo", &StockManagerApiController{}, "Get:CheckReturnStockWarehouseInfo")
  122. beego.Router("/api/stock/getprintlist", &StockManagerApiController{}, "Get:GetPrintList")
  123. beego.Router("/api/stock/getwarehouseinfolist", &StockManagerApiController{}, "Get:GetInvetoryWarehouseInfoList")
  124. //结算成功后调用操作库存相关接口
  125. beego.Router("/api/settle/stock", &StockManagerApiController{}, "Get:HandleSettleStock")
  126. beego.Router("/api/settle/cancelstock", &StockManagerApiController{}, "Get:HandleRefundStock")
  127. beego.Router("/api/stock/getnewgoodwarehouseinfo", &StockManagerApiController{}, "Get:GetNewGoodWarehouseInfo")
  128. beego.Router("/api/stock/getnewwarehouseoutinfolist", &StockManagerApiController{}, "Get:GetNewWarehouseOutInfoList")
  129. beego.Router("/api/stock/getstockfloworderlist", &StockManagerApiController{}, "Get:GetStockFlowOrderList")
  130. beego.Router("/api/stock/getgoodpatientname", &StockManagerApiController{}, "Get:GetGoodPatientName")
  131. beego.Router("/api/drug/updatebasedruglisbyuserorgid", &StockManagerApiController{}, "Get:UpdateBaseDrugListByUserOrgID")
  132. beego.Router("/api/good/updategoodinfobyuserorgid", &StockManagerApiController{}, "Get:UpdateGoodInfoByUserOrgId")
  133. beego.Router("/api/good/getgoodstockinventorylist", &StockManagerApiController{}, "Get:GetGoodStockInventoryList")
  134. beego.Router("/api/good/getstockinventoryprintlist", &StockManagerApiController{}, "Get:GetStockInventoryPrintList")
  135. beego.Router("/api/good/getstockinventoymodeprintlist", &StockManagerApiController{}, "Get:GetStockInventoryModePrintList")
  136. }
  137. func (c *StockManagerApiController) HandleRefundStock() {
  138. order_id, _ := c.GetInt64("order_id", 0)
  139. order, _ := service.GetHisOrderByIDThree(order_id)
  140. if order.ID == 0 {
  141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  142. return
  143. }
  144. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  145. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  146. var goods []*models.DialysisBeforePrepareGoods
  147. var newGoods []*models.NewDialysisBeforePrepareGoods
  148. var infos []*models.HisDoctorAdviceInfo
  149. for _, info := range orders {
  150. if info.AdviceId > 0 && info.ProjectId == 0 {
  151. infos = append(infos, &info.HisDoctorAdviceInfo)
  152. }
  153. if info.ProjectId > 0 && info.AdviceId == 0 {
  154. if info.HisPrescriptionProject.Type == 3 {
  155. var good models.DialysisBeforePrepareGoods
  156. var newGood models.NewDialysisBeforePrepareGoods
  157. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  158. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  159. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  160. good.Count = int64(count)
  161. good.StorehouseId = houseConfig.StorehouseOutInfo
  162. good.ProjectId = info.HisPrescriptionProject.ID
  163. goods = append(goods, &good)
  164. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  165. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  166. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  167. newGood.Count = int64(count2)
  168. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  169. newGood.ProjectId = info.HisPrescriptionProject.ID
  170. newGoods = append(newGoods, &newGood)
  171. }
  172. }
  173. }
  174. for _, item := range infos {
  175. //service.HisDrugsDelivery(item.UserOrgId, order.Creator, item)
  176. service.DrugAutoAddCancelInfo(item, order.Creator)
  177. }
  178. }
  179. func (c *StockManagerApiController) HandleSettleStock() {
  180. order_id, _ := c.GetInt64("order_id", 0)
  181. order, _ := service.GetHisOrderByID(order_id)
  182. if order.ID == 0 {
  183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  184. return
  185. }
  186. orders, _ := service.GetHisOrderDetailByNumberTwo(order.Number, order.UserOrgId)
  187. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  188. var goods []*models.DialysisBeforePrepareGoods
  189. var newGoods []*models.NewDialysisBeforePrepareGoods
  190. var infos []*models.HisDoctorAdviceInfo
  191. for _, info := range orders {
  192. if info.AdviceId > 0 && info.ProjectId == 0 {
  193. infos = append(infos, &info.HisDoctorAdviceInfo)
  194. }
  195. if info.ProjectId > 0 && info.AdviceId == 0 {
  196. if info.HisPrescriptionProject.Type == 3 {
  197. var good models.DialysisBeforePrepareGoods
  198. var newGood models.NewDialysisBeforePrepareGoods
  199. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  200. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  201. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  202. good.Count = int64(count)
  203. good.StorehouseId = houseConfig.StorehouseOutInfo
  204. good.ProjectId = info.HisPrescriptionProject.ID
  205. goods = append(goods, &good)
  206. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  207. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  208. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  209. newGood.Count = int64(count2)
  210. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  211. newGood.ProjectId = info.HisPrescriptionProject.ID
  212. newGoods = append(newGoods, &newGood)
  213. }
  214. }
  215. }
  216. service.ConsumablesDeliveryTotal(order.UserOrgId, order.PatientId, order.SettleAccountsDate, goods, newGoods, order.Creator)
  217. for _, item := range infos {
  218. service.HisDrugsDelivery(item.UserOrgId, order.Creator, item)
  219. }
  220. }
  221. func (c *StockManagerApiController) CreateWarehouse() {
  222. warehousing_time := c.GetString("warehousing_time")
  223. types, _ := c.GetInt64("type", 0)
  224. storehouse_id, _ := c.GetInt64("storehouse_id")
  225. warehousing_info_id, _ := c.GetInt64("warehousing_info_id")
  226. ctime := time.Now().Unix()
  227. adminUserInfo := c.GetAdminUserInfo()
  228. // 开始外部循环的事务
  229. db := service.XTWriteDB()
  230. tx := db.Begin()
  231. // 在函数结束时处理事务回滚
  232. defer func() {
  233. if r := recover(); r != nil {
  234. tx.Rollback()
  235. }
  236. }()
  237. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  238. if parseDateErr != nil {
  239. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  241. return
  242. }
  243. timeStr := time.Now().Format("2006-01-02")
  244. timeArr := strings.Split(timeStr, "-")
  245. total, _ := service.FindNewAllWarehouseTotal(adminUserInfo.CurrentOrgId, tx)
  246. total = total + 1
  247. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  248. operation_time := time.Now().Unix()
  249. creater := adminUserInfo.AdminUser.Id
  250. warehousing := models.Warehousing{
  251. WarehousingOrder: warehousing_order,
  252. OperationTime: operation_time,
  253. OrgId: adminUserInfo.CurrentOrgId,
  254. Creater: creater,
  255. Ctime: ctime,
  256. Status: 1,
  257. WarehousingTime: warehousingDate.Unix(),
  258. Type: types,
  259. StorehouseId: storehouse_id,
  260. IsCheck: 2,
  261. }
  262. if warehousing_info_id == 0 {
  263. service.AddNewSigleWarehouse(&warehousing, tx)
  264. }
  265. if warehousing_info_id > 0 {
  266. service.UpdateNewWarehouse(warehousing_info_id, storehouse_id, tx)
  267. }
  268. info, _ := service.FindNewLastWarehousingSix(adminUserInfo.CurrentOrgId, tx)
  269. dataBody := make(map[string]interface{}, 0)
  270. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  271. if err != nil {
  272. utils.ErrorLog(err.Error())
  273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  274. return
  275. }
  276. var warehousingInfo []*models.WarehousingInfo
  277. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  278. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  279. if len(thisStockIn) > 0 {
  280. for _, item := range thisStockIn {
  281. items := item.(map[string]interface{})
  282. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  283. utils.ErrorLog("id")
  284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  285. return
  286. }
  287. id := int64(items["id"].(float64))
  288. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  289. utils.ErrorLog("good_id")
  290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  291. return
  292. }
  293. good_id := int64(items["good_id"].(float64))
  294. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  295. utils.ErrorLog("good_type_id")
  296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  297. return
  298. }
  299. good_type_id := int64(items["good_type_id"].(float64))
  300. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  301. utils.ErrorLog("warehousing_count")
  302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  303. return
  304. }
  305. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  306. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  307. utils.ErrorLog("price")
  308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  312. total := float64(warehousing_count) * price
  313. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  314. utils.ErrorLog("packing_price")
  315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  316. return
  317. }
  318. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  319. var productDates int64
  320. var expiryDates int64
  321. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  322. expiryDates = 0
  323. } else {
  324. if len(items["expiry_date"].(string)) == 0 {
  325. expiryDates = 0
  326. } else {
  327. expiryDate, _ := items["expiry_date"].(string)
  328. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  329. expiryDates = expiry_date.Unix()
  330. }
  331. }
  332. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  333. productDates = 0
  334. } else {
  335. if len(items["product_date"].(string)) == 0 {
  336. productDates = 0
  337. } else {
  338. productDate, _ := items["product_date"].(string)
  339. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  340. productDates = product_date.Unix()
  341. }
  342. }
  343. number, _ := items["number"].(string)
  344. remark, _ := items["remark"].(string)
  345. manufacturer := int64(items["manufacturer"].(float64))
  346. dealer := int64(items["dealer"].(float64))
  347. license_number, _ := items["license_number"].(string)
  348. register_number, _ := items["register_number"].(string)
  349. good_code, _ := items["good_code"].(string)
  350. //入库单表格
  351. warehouseInfo := &models.WarehousingInfo{
  352. ID: id,
  353. WarehousingOrder: warehousing.WarehousingOrder,
  354. WarehousingId: info.ID,
  355. GoodId: good_id,
  356. Number: number,
  357. GoodTypeId: good_type_id,
  358. ProductDate: productDates,
  359. ExpiryDate: expiryDates,
  360. WarehousingCount: warehousing_count,
  361. Price: price,
  362. TotalPrice: total,
  363. Status: 1,
  364. Ctime: warehousingDate.Unix(),
  365. Remark: remark,
  366. OrgId: adminUserInfo.CurrentOrgId,
  367. Type: types,
  368. Manufacturer: manufacturer,
  369. StockCount: 0,
  370. Dealer: dealer,
  371. LicenseNumber: license_number,
  372. PackingPrice: packing_price,
  373. StorehouseId: storehouse_id,
  374. IsCheck: 2,
  375. RegisterNumber: register_number,
  376. GoodCode: good_code,
  377. }
  378. warehousingInfo = append(warehousingInfo, warehouseInfo)
  379. }
  380. }
  381. }
  382. for _, item := range warehousingInfo {
  383. if item.ID == 0 {
  384. service.CreatedNewWarehouseingDetail(item, tx)
  385. }
  386. if item.ID > 0 {
  387. service.UpdateNewWarehouseDetail(item, item.ID, tx)
  388. }
  389. }
  390. //查询入库数据
  391. list, _ := service.GetNewGoodWarehouseInfoById(info.ID, info.OrgId, tx)
  392. tx.Commit()
  393. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  394. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  395. c.ServeSuccessJSON(map[string]interface{}{
  396. "msg": "入库成功",
  397. "warehousing_order": warehousing_order,
  398. "info": info,
  399. "list": list,
  400. "dealerList": dealerList,
  401. "manufacturerList": manufacturerList,
  402. })
  403. }
  404. func (c *StockManagerApiController) GetWarehouseList() {
  405. page, _ := c.GetInt64("page", -1)
  406. limit, _ := c.GetInt64("limit", -1)
  407. start_time := c.GetString("start_time")
  408. end_time := c.GetString("end_time")
  409. types, _ := c.GetInt64("type", 0)
  410. keywords := c.GetString("keywords")
  411. storehouse_id, _ := c.GetInt64("storehouse_id")
  412. check_type, _ := c.GetInt64("check_type")
  413. timeLayout := "2006-01-02"
  414. loc, _ := time.LoadLocation("Local")
  415. var startTime int64
  416. if len(start_time) > 0 {
  417. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  418. if err != nil {
  419. fmt.Println(err)
  420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  421. return
  422. }
  423. startTime = theTime.Unix()
  424. }
  425. var endTime int64
  426. if len(end_time) > 0 {
  427. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  428. if err != nil {
  429. utils.ErrorLog(err.Error())
  430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  431. return
  432. }
  433. endTime = theTime.Unix()
  434. }
  435. adminUserInfo := c.GetAdminUserInfo()
  436. var ids []int64
  437. var goodids []int64
  438. //查询商品名称
  439. if len(keywords) > 0 {
  440. //查询商品名称
  441. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  442. for _, item := range list {
  443. goodids = append(goodids, item.ID)
  444. //入库详情但里面查询
  445. }
  446. if len(goodids) > 0 {
  447. info, _ := service.GetWarehoureOrderInfoByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId, storehouse_id)
  448. for _, it := range info {
  449. ids = append(ids, it.WarehousingId)
  450. }
  451. }
  452. }
  453. warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids, storehouse_id, check_type)
  454. fmt.Println("ottal--------", total)
  455. houselist, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  456. if err == nil {
  457. c.ServeSuccessJSON(map[string]interface{}{
  458. "list": warehouseList,
  459. "total": total,
  460. "houselist": houselist,
  461. })
  462. } else {
  463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  464. }
  465. }
  466. func (c *StockManagerApiController) GetWarehouseInfoList() {
  467. id := c.GetString("id")
  468. idArray := strings.Split(id, ",")
  469. warehousing, err := service.FindWarehousingByIdOne(idArray)
  470. if err != nil {
  471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  472. return
  473. }
  474. var ids []int64
  475. for _, item := range warehousing {
  476. ids = append(ids, item.ID)
  477. }
  478. warehousingInfo, err := service.FindWarehousingInfoByIdOne(ids)
  479. if err == nil {
  480. c.ServeSuccessJSON(map[string]interface{}{
  481. "info": warehousingInfo,
  482. "warehousing": warehousing,
  483. })
  484. } else {
  485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  486. }
  487. }
  488. func (c *StockManagerApiController) EditWarehouse() {
  489. // 开始外部循环的事务
  490. db := service.XTWriteDB()
  491. tx := db.Begin()
  492. // 在函数结束时处理事务回滚
  493. defer func() {
  494. if r := recover(); r != nil {
  495. tx.Rollback()
  496. }
  497. }()
  498. warehousing_time := c.GetString("warehousing_time")
  499. id, _ := c.GetInt64("id", 0)
  500. types, _ := c.GetInt64("type", 0)
  501. storehouse_id, _ := c.GetInt64("storehouse_id")
  502. if id == 0 {
  503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  504. return
  505. }
  506. ctime := time.Now().Unix()
  507. mtime := time.Now().Unix()
  508. adminUserInfo := c.GetAdminUserInfo()
  509. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  510. if parseDateErr != nil {
  511. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  513. return
  514. }
  515. warehouse, _ := service.FindNewWarehousingById(id, tx)
  516. warehousing := models.Warehousing{
  517. WarehousingOrder: warehouse.WarehousingOrder,
  518. OrgId: adminUserInfo.CurrentOrgId,
  519. Modifier: adminUserInfo.AdminUser.Id,
  520. Mtime: mtime,
  521. Status: 1,
  522. WarehousingTime: warehousingDate.Unix(),
  523. Type: warehouse.Type,
  524. StorehouseId: storehouse_id,
  525. }
  526. service.EditNewWarehousing(warehousing, tx)
  527. dataBody := make(map[string]interface{}, 0)
  528. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  529. if err != nil {
  530. utils.ErrorLog(err.Error())
  531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  532. return
  533. }
  534. var warehousingInfo []*models.WarehousingInfo
  535. var upDateWarehousingInfo []*models.WarehousingInfo
  536. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  537. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  538. if len(thisStockIn) > 0 {
  539. for _, item := range thisStockIn {
  540. items := item.(map[string]interface{})
  541. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  542. utils.ErrorLog("good_id")
  543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  544. return
  545. }
  546. good_id := int64(items["good_id"].(float64))
  547. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  548. utils.ErrorLog("good_type_id")
  549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  550. return
  551. }
  552. good_type_id := int64(items["good_type_id"].(float64))
  553. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  554. utils.ErrorLog("warehousing_count")
  555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  556. return
  557. }
  558. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  559. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  560. utils.ErrorLog("price")
  561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  562. return
  563. }
  564. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  565. total := float64(warehousing_count) * price
  566. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  567. utils.ErrorLog("packing_price")
  568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  569. return
  570. }
  571. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  572. var productDates int64
  573. var expiryDates int64
  574. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  575. expiryDates = 0
  576. } else {
  577. if len(items["expiry_date"].(string)) == 0 {
  578. expiryDates = 0
  579. } else {
  580. expiryDate, _ := items["expiry_date"].(string)
  581. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  582. expiryDates = expiry_date.Unix()
  583. }
  584. }
  585. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  586. productDates = 0
  587. } else {
  588. if len(items["product_date"].(string)) == 0 {
  589. productDates = 0
  590. } else {
  591. productDate, _ := items["product_date"].(string)
  592. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  593. productDates = product_date.Unix()
  594. }
  595. }
  596. number, _ := items["number"].(string)
  597. remark, _ := items["remark"].(string)
  598. manufacturer := int64(items["manufacturer"].(float64))
  599. dealer := int64(items["dealer"].(float64))
  600. license_number, _ := items["license_number"].(string)
  601. register_number, _ := items["register_number"].(string)
  602. good_code, _ := items["good_code"].(string)
  603. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  604. utils.ErrorLog("id")
  605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  606. return
  607. }
  608. id := int64(items["id"].(float64))
  609. if id == 0 {
  610. warehouseInfo := &models.WarehousingInfo{
  611. WarehousingOrder: warehouse.WarehousingOrder,
  612. WarehousingId: warehouse.ID,
  613. GoodId: good_id,
  614. Number: number,
  615. GoodTypeId: good_type_id,
  616. ProductDate: productDates,
  617. ExpiryDate: expiryDates,
  618. WarehousingCount: warehousing_count,
  619. Price: price,
  620. TotalPrice: total,
  621. Status: 1,
  622. Ctime: ctime,
  623. Remark: remark,
  624. OrgId: adminUserInfo.CurrentOrgId,
  625. Type: types,
  626. Manufacturer: manufacturer,
  627. Dealer: dealer,
  628. StockCount: warehousing_count,
  629. LicenseNumber: license_number,
  630. PackingPrice: packing_price,
  631. StorehouseId: storehouse_id,
  632. IsCheck: 2,
  633. RegisterNumber: register_number,
  634. GoodCode: good_code,
  635. }
  636. warehousingInfo = append(warehousingInfo, warehouseInfo)
  637. } else {
  638. warehouseInfo := &models.WarehousingInfo{
  639. ID: id,
  640. WarehousingOrder: warehouse.WarehousingOrder,
  641. WarehousingId: warehouse.ID,
  642. GoodId: good_id,
  643. Number: number,
  644. GoodTypeId: good_type_id,
  645. ProductDate: productDates,
  646. ExpiryDate: expiryDates,
  647. WarehousingCount: warehousing_count,
  648. Price: price,
  649. TotalPrice: total,
  650. Status: 1,
  651. Ctime: ctime,
  652. Remark: remark,
  653. OrgId: adminUserInfo.CurrentOrgId,
  654. Type: types,
  655. Manufacturer: manufacturer,
  656. Dealer: dealer,
  657. LicenseNumber: license_number,
  658. PackingPrice: packing_price,
  659. StorehouseId: storehouse_id,
  660. RegisterNumber: register_number,
  661. GoodCode: good_code,
  662. }
  663. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  664. }
  665. }
  666. }
  667. }
  668. var errs error
  669. if len(warehousingInfo) > 0 {
  670. errs = service.CreateNewWarehousingInfo(warehousingInfo, tx)
  671. }
  672. if len(upDateWarehousingInfo) > 0 {
  673. for _, item := range upDateWarehousingInfo {
  674. if item.ID > 0 {
  675. service.UpdateNewWarehouseInfoByGoodIdOne(item, item.ID, tx)
  676. }
  677. }
  678. }
  679. if errs != nil {
  680. utils.ErrorLog(errs.Error())
  681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  682. return
  683. }
  684. list, _ := service.GetNewAllStockInList(id, adminUserInfo.CurrentOrgId, tx)
  685. tx.Commit()
  686. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  687. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  688. c.ServeSuccessJSON(map[string]interface{}{
  689. "msg": "编辑成功",
  690. "list": list,
  691. "manufacturerList": manufacturerList,
  692. "dealerList": dealerList,
  693. })
  694. }
  695. func (c *StockManagerApiController) DeleteWarehouse() {
  696. ids := c.GetString("ids")
  697. if len(ids) == 0 {
  698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  699. return
  700. }
  701. idArray := strings.Split(ids, ",")
  702. err := service.DeleteWarehouse(idArray)
  703. //删除流水
  704. service.DeleteStockFlow(idArray)
  705. if err != nil {
  706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  707. } else {
  708. c.ServeSuccessJSON(map[string]interface{}{
  709. "msg": "删除成功",
  710. })
  711. }
  712. }
  713. func (c *StockManagerApiController) DeleteWarehouseInfo() {
  714. id, _ := c.GetInt64("id", 0)
  715. if id == 0 {
  716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  717. return
  718. }
  719. orgId := c.GetAdminUserInfo().CurrentOrgId
  720. err := service.UpDateWarehouseStatus(id)
  721. service.UpdatedStockFlowById(id)
  722. //查询入库记录
  723. info, _ := service.GetWarehouseInfoByIdTwenty(id, orgId)
  724. //查询该机构默认仓库
  725. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  726. //查询剩余库存
  727. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, orgId)
  728. var sum_count int64
  729. var sum_in_count int64
  730. for _, item := range goodList {
  731. sum_count += item.StockCount
  732. sum_in_count += item.WarehousingCount
  733. }
  734. service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
  735. if err != nil {
  736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  737. } else {
  738. c.ServeSuccessJSON(map[string]interface{}{
  739. "msg": "删除成功",
  740. })
  741. }
  742. }
  743. func (c *StockManagerApiController) CreateSalesReturn() {
  744. dealer_id, _ := c.GetInt64("dealer_id", 0)
  745. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  746. sales_return_time := c.GetString("time")
  747. types, _ := c.GetInt64("type", 0)
  748. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  749. if parseDateErr != nil {
  750. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  752. return
  753. }
  754. adminUserInfo := c.GetAdminUserInfo()
  755. operation_time := time.Now().Unix()
  756. creater := adminUserInfo.AdminUser.Id
  757. ctime := time.Now().Unix()
  758. timeStr := time.Now().Format("2006-01-02")
  759. timeArr := strings.Split(timeStr, "-")
  760. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  761. total = total + 1
  762. orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  763. salesReturn := models.SalesReturn{
  764. OrderNumber: orderNumber,
  765. OperaTime: operation_time,
  766. OrgId: adminUserInfo.CurrentOrgId,
  767. Creater: creater,
  768. Ctime: ctime,
  769. Status: 1,
  770. ReturnTime: salesReturnDate.Unix(),
  771. Dealer: dealer_id,
  772. Manufacturer: manufacturer_id,
  773. Type: types,
  774. }
  775. service.AddSigleSalesReturn(&salesReturn)
  776. dataBody := make(map[string]interface{}, 0)
  777. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  778. if err != nil {
  779. utils.ErrorLog(err.Error())
  780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  781. return
  782. }
  783. var salesReturnInfos []*models.SalesReturnInfo
  784. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  785. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  786. if len(thisStockIn) > 0 {
  787. for _, item := range thisStockIn {
  788. items := item.(map[string]interface{})
  789. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  790. utils.ErrorLog("good_id")
  791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  792. return
  793. }
  794. good_id := int64(items["good_id"].(float64))
  795. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  796. utils.ErrorLog("good_type_id")
  797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  798. return
  799. }
  800. good_type_id := int64(items["good_type_id"].(float64))
  801. return_count, _ := items["return_count"].(string)
  802. if len(return_count) == 0 {
  803. utils.ErrorLog("len(return_count) == 0")
  804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  805. return
  806. }
  807. count, _ := strconv.ParseInt(return_count, 10, 64)
  808. price, _ := strconv.ParseFloat(items["price"].(string), 10)
  809. total := float64(count) * price
  810. salesReturnInfo := &models.SalesReturnInfo{
  811. OrderNumber: salesReturn.OrderNumber,
  812. SalesReturnId: salesReturn.ID,
  813. GoodId: good_id,
  814. GoodTypeId: good_type_id,
  815. Count: count,
  816. Price: price,
  817. Total: total,
  818. Status: 1,
  819. Ctime: ctime,
  820. OrgId: adminUserInfo.CurrentOrgId,
  821. Type: types,
  822. Manufacturer: manufacturer_id,
  823. Dealer: dealer_id,
  824. }
  825. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  826. }
  827. }
  828. }
  829. errs := service.CreateSalesReturnInfo(salesReturnInfos)
  830. if errs != nil {
  831. utils.ErrorLog(errs.Error())
  832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  833. return
  834. }
  835. c.ServeSuccessJSON(map[string]interface{}{
  836. "msg": "退货成功",
  837. })
  838. }
  839. func (c *StockManagerApiController) GetSalesReturnList() {
  840. page, _ := c.GetInt64("page", -1)
  841. limit, _ := c.GetInt64("limit", -1)
  842. start_time := c.GetString("start_time")
  843. end_time := c.GetString("end_time")
  844. types, _ := c.GetInt64("type", 0)
  845. keywords := c.GetString("keywords")
  846. timeLayout := "2006-01-02"
  847. loc, _ := time.LoadLocation("Local")
  848. var startTime int64
  849. if len(start_time) > 0 {
  850. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  851. if err != nil {
  852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  853. return
  854. }
  855. startTime = theTime.Unix()
  856. }
  857. var endTime int64
  858. if len(end_time) > 0 {
  859. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  860. if err != nil {
  861. utils.ErrorLog(err.Error())
  862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  863. return
  864. }
  865. endTime = theTime.Unix()
  866. }
  867. adminUserInfo := c.GetAdminUserInfo()
  868. returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  869. if err == nil {
  870. c.ServeSuccessJSON(map[string]interface{}{
  871. "list": returnList,
  872. "total": total,
  873. })
  874. } else {
  875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  876. }
  877. }
  878. func (this *StockManagerApiController) DeleteSalesReturn() {
  879. ids := this.GetString("ids")
  880. if len(ids) == 0 {
  881. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  882. return
  883. }
  884. idArray := strings.Split(ids, ",")
  885. err := service.DeleteSalesReturn(idArray)
  886. if err != nil {
  887. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  888. } else {
  889. this.ServeSuccessJSON(map[string]interface{}{
  890. "msg": "删除成功",
  891. })
  892. }
  893. }
  894. func (this *StockManagerApiController) DeleteSalesReturnInfo() {
  895. id, _ := this.GetInt64("id", 0)
  896. fmt.Println(id)
  897. if id == 0 {
  898. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  899. return
  900. }
  901. err := service.UpDateSaleReturnStatus(id)
  902. if err != nil {
  903. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  904. } else {
  905. this.ServeSuccessJSON(map[string]interface{}{
  906. "msg": "删除成功",
  907. })
  908. }
  909. }
  910. func (this *StockManagerApiController) GetSalesReturnInfoList() {
  911. id, _ := this.GetInt64("id", 0)
  912. list, _ := service.FindAllSalesReturnInfoById(id)
  913. salesReturn, _ := service.FindAllSalesReturnById(id)
  914. this.ServeSuccessJSON(map[string]interface{}{
  915. "list": list,
  916. "salesReturn": salesReturn,
  917. })
  918. }
  919. func (c *StockManagerApiController) EditReturnInfo() {
  920. return_time := c.GetString("return_time")
  921. id, _ := c.GetInt64("id", 0)
  922. types, _ := c.GetInt64("type", 0)
  923. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  924. dealer_id, _ := c.GetInt64("dealer_id", 0)
  925. if id == 0 {
  926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  927. return
  928. }
  929. ctime := time.Now().Unix()
  930. mtime := time.Now().Unix()
  931. adminUserInfo := c.GetAdminUserInfo()
  932. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  933. if parseDateErr != nil {
  934. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  936. return
  937. }
  938. salesReturns, _ := service.FindSalesReturnById(id)
  939. sales := models.SalesReturn{
  940. ID: salesReturns.ID,
  941. Mtime: mtime,
  942. ReturnTime: returnDate.Unix(),
  943. Manufacturer: manufacturer_id,
  944. Dealer: dealer_id,
  945. }
  946. service.EditSaleReturn(sales)
  947. dataBody := make(map[string]interface{}, 0)
  948. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  949. if err != nil {
  950. utils.ErrorLog(err.Error())
  951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  952. return
  953. }
  954. var returnInfos []*models.SalesReturnInfo
  955. var upDateReturnInfos []*models.SalesReturnInfo
  956. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  957. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  958. if len(thisStockIn) > 0 {
  959. for _, item := range thisStockIn {
  960. items := item.(map[string]interface{})
  961. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  962. utils.ErrorLog("good_id")
  963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  964. return
  965. }
  966. good_id := int64(items["good_id"].(float64))
  967. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  968. utils.ErrorLog("good_type_id")
  969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  970. return
  971. }
  972. good_type_id := int64(items["good_type_id"].(float64))
  973. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  974. utils.ErrorLog("count")
  975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  976. return
  977. }
  978. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  979. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  980. utils.ErrorLog("id")
  981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  982. return
  983. }
  984. id := int64(items["id"].(float64))
  985. if id == 0 {
  986. returnInfo := &models.SalesReturnInfo{
  987. GoodId: good_id,
  988. GoodTypeId: good_type_id,
  989. Count: count,
  990. Status: 1,
  991. Ctime: ctime,
  992. OrgId: adminUserInfo.CurrentOrgId,
  993. OrderNumber: sales.OrderNumber,
  994. SalesReturnId: sales.ID,
  995. Mtime: time.Now().Unix(),
  996. Type: types,
  997. Manufacturer: manufacturer_id,
  998. Dealer: dealer_id,
  999. }
  1000. returnInfos = append(returnInfos, returnInfo)
  1001. } else {
  1002. returnInfo := &models.SalesReturnInfo{
  1003. ID: id,
  1004. GoodId: good_id,
  1005. GoodTypeId: good_type_id,
  1006. Count: count,
  1007. Status: 1,
  1008. Ctime: ctime,
  1009. OrgId: adminUserInfo.CurrentOrgId,
  1010. OrderNumber: sales.OrderNumber,
  1011. SalesReturnId: sales.ID,
  1012. Mtime: time.Now().Unix(),
  1013. Type: types,
  1014. Manufacturer: manufacturer_id,
  1015. Dealer: dealer_id,
  1016. }
  1017. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  1018. }
  1019. }
  1020. }
  1021. }
  1022. var errs error
  1023. if len(returnInfos) > 0 {
  1024. errs = service.CreateSalesReturnInfo(returnInfos)
  1025. }
  1026. if len(upDateReturnInfos) > 0 {
  1027. for _, item := range upDateReturnInfos {
  1028. errs = service.UpDateSalesReturnInfo(item)
  1029. }
  1030. }
  1031. if errs != nil {
  1032. utils.ErrorLog(errs.Error())
  1033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1034. return
  1035. }
  1036. c.ServeSuccessJSON(map[string]interface{}{
  1037. "msg": "编辑成功",
  1038. })
  1039. }
  1040. func (c *StockManagerApiController) CreateWarehouseOut() {
  1041. types, _ := c.GetInt64("type", 0)
  1042. storehouse_id, _ := c.GetInt64("storehouse_id")
  1043. warehouseOut_id, _ := c.GetInt64("warehouseOut_id")
  1044. ctime := time.Now().Unix()
  1045. adminUserInfo := c.GetAdminUserInfo()
  1046. warehousing_out_time := c.GetString("warehousing_out_time")
  1047. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  1048. if parseDateErr != nil {
  1049. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  1050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1051. return
  1052. }
  1053. timeStr := time.Now().Format("2006-01-02")
  1054. timeArr := strings.Split(timeStr, "-")
  1055. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  1056. total = total + 1
  1057. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1058. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1059. number = number + total
  1060. warehousing_out_order = "CKM" + strconv.FormatInt(number, 10)
  1061. operation_time := time.Now().Unix()
  1062. creater := adminUserInfo.AdminUser.Id
  1063. warehouseOut := models.WarehouseOut{
  1064. WarehouseOutOrderNumber: warehousing_out_order,
  1065. OperationTime: operation_time,
  1066. OrgId: adminUserInfo.CurrentOrgId,
  1067. Creater: creater,
  1068. Ctime: ctime,
  1069. Status: 1,
  1070. WarehouseOutTime: warehousingOutDate.Unix(),
  1071. Type: types,
  1072. StorehouseId: storehouse_id,
  1073. IsCheck: 2,
  1074. }
  1075. dataBody := make(map[string]interface{}, 0)
  1076. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1077. if err != nil {
  1078. utils.ErrorLog(err.Error())
  1079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1080. return
  1081. }
  1082. // 开始外部循环的事务
  1083. db := service.XTWriteDB()
  1084. tx := db.Begin()
  1085. // 在函数结束时处理事务回滚
  1086. defer func() {
  1087. if r := recover(); r != nil {
  1088. tx.Rollback()
  1089. }
  1090. }()
  1091. if warehouseOut_id == 0 {
  1092. //查询是否生成出库单
  1093. warehouseOutObj, _ := service.FindStockOutByIsSysOne(adminUserInfo.CurrentOrgId, 0, warehousingOutDate.Unix(), warehousing_out_order, tx)
  1094. if warehouseOutObj.ID == 0 {
  1095. service.AddSigleWarehouseOut(&warehouseOut, tx)
  1096. }
  1097. }
  1098. if warehouseOut_id > 0 {
  1099. service.UpdateSingleWarehoseOut(warehouseOut_id, storehouse_id, tx)
  1100. }
  1101. var warehousingOutInfo []*models.WarehouseOutInfo
  1102. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1103. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  1104. if len(thisStockIn) > 0 {
  1105. for _, item := range thisStockIn {
  1106. items := item.(map[string]interface{})
  1107. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1108. utils.ErrorLog("id")
  1109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1110. return
  1111. }
  1112. id := int64(items["id"].(float64))
  1113. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1114. utils.ErrorLog("good_id")
  1115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1116. return
  1117. }
  1118. good_id := int64(items["good_id"].(float64))
  1119. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1120. utils.ErrorLog("good_type_id")
  1121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1122. return
  1123. }
  1124. good_type_id := int64(items["good_type_id"].(float64))
  1125. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1126. utils.ErrorLog("count")
  1127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1128. return
  1129. }
  1130. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1131. utils.ErrorLog("price")
  1132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1133. return
  1134. }
  1135. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1136. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1137. total_one := float64(count) * price
  1138. remark := items["remark"].(string)
  1139. manufacturer := int64(items["manufacturer"].(float64))
  1140. dealer := int64(items["dealer"].(float64))
  1141. number := items["number"].(string)
  1142. expiry_date := items["expiry_date"].(string)
  1143. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1144. admin_user_id := int64(items["admin_user_id"].(float64))
  1145. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  1146. utils.ErrorLog("buy_price")
  1147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1148. return
  1149. }
  1150. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  1151. stock_count := items["stock_count"].(string)
  1152. register_number := items["register_number"].(string)
  1153. class_type := items["class_type"].(string)
  1154. timeLayout := "2006-01-02"
  1155. loc, _ := time.LoadLocation("Local")
  1156. var expiryDate int64
  1157. if len(expiry_date) > 0 {
  1158. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1159. if err != nil {
  1160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1161. return
  1162. }
  1163. expiryDate = theTime.Unix()
  1164. }
  1165. product_date := items["product_date"].(string)
  1166. var productDate int64
  1167. if len(product_date) > 0 {
  1168. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", product_date+" 00:00:00", loc)
  1169. if err != nil {
  1170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1171. return
  1172. }
  1173. productDate = theTime.Unix()
  1174. }
  1175. license_number := items["license_number"].(string)
  1176. patient_id := int64(items["patient_id"].(float64))
  1177. warehouseOutInfo := &models.WarehouseOutInfo{
  1178. ID: id,
  1179. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1180. WarehouseOutId: warehouseOut.ID,
  1181. GoodId: good_id,
  1182. GoodTypeId: good_type_id,
  1183. Count: count,
  1184. Price: price,
  1185. TotalPrice: total_one,
  1186. Status: 1,
  1187. Ctime: ctime,
  1188. Remark: remark,
  1189. OrgId: adminUserInfo.CurrentOrgId,
  1190. Type: types,
  1191. Manufacturer: manufacturer,
  1192. Number: number,
  1193. ExpiryDate: expiryDate,
  1194. ProductDate: productDate,
  1195. Dealer: dealer,
  1196. LicenseNumber: license_number,
  1197. WarehouseInfotId: warehouse_info_id,
  1198. StorehouseId: storehouse_id,
  1199. AdminUserId: admin_user_id,
  1200. BuyPrice: buy_price,
  1201. StockCount: stock_count,
  1202. IsCheck: 2,
  1203. RegisterNumber: register_number,
  1204. SysRecordTime: warehouseOut.WarehouseOutTime,
  1205. PatientId: patient_id,
  1206. ClassType: class_type,
  1207. }
  1208. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1209. }
  1210. }
  1211. }
  1212. goodWarehouseOut, _ := service.GetLastGoodWarehouseOutTwentyOne(adminUserInfo.CurrentOrgId, tx)
  1213. if len(warehousingOutInfo) > 0 {
  1214. for _, it := range warehousingOutInfo {
  1215. warehouseOutInfo := &models.WarehouseOutInfo{
  1216. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1217. WarehouseOutId: goodWarehouseOut.ID,
  1218. WarehouseInfotId: 0,
  1219. Status: 1,
  1220. Ctime: time.Now().Unix(),
  1221. Remark: it.Remark,
  1222. OrgId: adminUserInfo.CurrentOrgId,
  1223. Type: 1,
  1224. Manufacturer: it.Manufacturer,
  1225. Dealer: it.Dealer,
  1226. IsSys: 0,
  1227. SysRecordTime: it.SysRecordTime,
  1228. GoodTypeId: it.GoodTypeId,
  1229. GoodId: it.GoodId,
  1230. ExpiryDate: it.ExpiryDate,
  1231. ProductDate: it.ProductDate,
  1232. Number: it.Number,
  1233. Price: it.Price,
  1234. LicenseNumber: it.LicenseNumber,
  1235. SupplyWarehouseId: 0,
  1236. StorehouseId: storehouse_id,
  1237. AdminUserId: it.AdminUserId,
  1238. BuyPrice: it.BuyPrice,
  1239. StockCount: it.StockCount,
  1240. Count: it.Count,
  1241. IsCheck: 2,
  1242. RegisterNumber: it.RegisterNumber,
  1243. PatientId: it.PatientId,
  1244. ClassType: it.ClassType,
  1245. }
  1246. if it.ID == 0 {
  1247. //查询改耗材是否出库
  1248. outInfo, _ := service.GetGoodsIsExsit(it.GoodId, it.SysRecordTime, it.OrgId, goodWarehouseOut.ID, tx)
  1249. if outInfo.ID == 0 {
  1250. service.AddSigleWarehouseOutInfo(warehouseOutInfo, tx)
  1251. }
  1252. }
  1253. if it.ID > 0 {
  1254. service.ModifyWarehouseOutInfo(it.ID, warehouseOutInfo, tx)
  1255. }
  1256. }
  1257. }
  1258. appId := adminUserInfo.CurrentAppId
  1259. warehouseOutInfoList, _ := service.GetLastGoodWarehouseOutInfo(adminUserInfo.CurrentOrgId, goodWarehouseOut.ID, tx)
  1260. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  1261. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  1262. doctorList, _ := service.GetAllDoctorListSix(adminUserInfo.CurrentOrgId, appId)
  1263. tx.Commit()
  1264. c.ServeSuccessJSON(map[string]interface{}{
  1265. "msg": "2",
  1266. "good_name": "",
  1267. "specification_name": "",
  1268. "warehouseOut": goodWarehouseOut,
  1269. "warehouseOutInfoList": warehouseOutInfoList,
  1270. "manufacturerList": manufacturerList,
  1271. "dealerList": dealerList,
  1272. "doctorList": doctorList,
  1273. })
  1274. return
  1275. }
  1276. func (c *StockManagerApiController) GetWarehouseOutList() {
  1277. page, _ := c.GetInt64("page", -1)
  1278. limit, _ := c.GetInt64("limit", -1)
  1279. start_time := c.GetString("start_time")
  1280. end_time := c.GetString("end_time")
  1281. types, _ := c.GetInt64("type", 0)
  1282. keywords := c.GetString("keywords")
  1283. storehouse_id, _ := c.GetInt64("storehouse_id")
  1284. way_type, _ := c.GetInt64("way_type")
  1285. check_type, _ := c.GetInt64("check_type")
  1286. timeLayout := "2006-01-02"
  1287. loc, _ := time.LoadLocation("Local")
  1288. var startTime int64
  1289. if len(start_time) > 0 {
  1290. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1291. if err != nil {
  1292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1293. return
  1294. }
  1295. startTime = theTime.Unix()
  1296. }
  1297. var endTime int64
  1298. if len(end_time) > 0 {
  1299. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1300. if err != nil {
  1301. utils.ErrorLog(err.Error())
  1302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1303. return
  1304. }
  1305. endTime = theTime.Unix()
  1306. }
  1307. adminUserInfo := c.GetAdminUserInfo()
  1308. var ids []int64
  1309. var goodids []int64
  1310. if len(keywords) > 0 {
  1311. //查询商品名称
  1312. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  1313. for _, item := range list {
  1314. goodids = append(goodids, item.ID)
  1315. }
  1316. if len(goodids) > 0 {
  1317. //出库详情但里面查询
  1318. info, _ := service.GetWarehoureOrderOutByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId, storehouse_id)
  1319. for _, it := range info {
  1320. ids = append(ids, it.WarehouseOutId)
  1321. }
  1322. }
  1323. }
  1324. warehouseOutList, total, err := service.FindAllWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids, storehouse_id, way_type, check_type)
  1325. houselist, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  1326. patients, _ := service.GetAllpatient(adminUserInfo.CurrentOrgId)
  1327. fmt.Println(err)
  1328. if err == nil {
  1329. c.ServeSuccessJSON(map[string]interface{}{
  1330. "list": warehouseOutList,
  1331. "total": total,
  1332. "houselist": houselist,
  1333. "patients": patients,
  1334. })
  1335. } else {
  1336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1337. }
  1338. }
  1339. func (c *StockManagerApiController) DeleteWarehouseOut() {
  1340. ids := c.GetString("ids")
  1341. if len(ids) == 0 {
  1342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1343. return
  1344. }
  1345. idArray := strings.Split(ids, ",")
  1346. err := service.DeleteWarehouseOut(idArray)
  1347. //list, _ := service.GetWarehouseOutInfoByIds(idArray)
  1348. //for _, item := range list {
  1349. // //添加库存
  1350. // service.UpdateWarehouseInfoById(item.WarehouseInfotId, item.Count)
  1351. // //添加库存
  1352. // //查询该机构默认仓库
  1353. // storeConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
  1354. // //查询剩余库存
  1355. // goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, item.OrgId)
  1356. // var sum_count int64
  1357. // var sum_in_count int64
  1358. // for _, item := range goodList {
  1359. // sum_count += item.StockCount
  1360. // sum_in_count += item.WarehousingCount
  1361. // }
  1362. // service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
  1363. //}
  1364. if err != nil {
  1365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1366. } else {
  1367. c.ServeSuccessJSON(map[string]interface{}{
  1368. "msg": "删除成功",
  1369. })
  1370. }
  1371. }
  1372. func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
  1373. id, _ := this.GetInt64("id", 0)
  1374. fmt.Println(id)
  1375. if id == 0 {
  1376. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1377. return
  1378. }
  1379. err := service.UpDateWarehouseOutStatus(id)
  1380. //添加库存
  1381. //out, _ := service.GetWarhouseOutById(id)
  1382. //
  1383. //service.UpdateWareInfoById(out.WarehouseInfotId, out.Count)
  1384. //
  1385. ////查询该机构默认仓库
  1386. //storeConfig, _ := service.GetAllStoreHouseConfig(out.OrgId)
  1387. ////查询剩余库存
  1388. //goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, out.GoodId, out.OrgId)
  1389. //var sum_count int64
  1390. //var sum_in_count int64
  1391. //for _, item := range goodList {
  1392. // sum_count += item.StockCount
  1393. // sum_in_count += item.WarehousingCount
  1394. //}
  1395. //service.UpdateGoodByGoodId(out.GoodId, sum_count, sum_in_count, out.OrgId)
  1396. //
  1397. //
  1398. //service.UpdateStockFlowWarehouseOutById(id)
  1399. if err != nil {
  1400. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1401. } else {
  1402. this.ServeSuccessJSON(map[string]interface{}{
  1403. "msg": "删除成功",
  1404. })
  1405. }
  1406. }
  1407. func (c *StockManagerApiController) GetWarehouseOutInfoList() {
  1408. id, _ := c.GetInt64("id", 0)
  1409. warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
  1410. warehouseOut, _ := service.FindWareHouseOutByIdOne(id)
  1411. adminUserInfo := c.GetAdminUserInfo()
  1412. orgId := adminUserInfo.CurrentOrgId
  1413. wareoutList, _ := service.GetWareOutInfoById(id, orgId)
  1414. c.ServeSuccessJSON(map[string]interface{}{
  1415. "list": warehouseOutInfo,
  1416. "info": warehouseOut,
  1417. "wareoutList": wareoutList,
  1418. })
  1419. }
  1420. func (c *StockManagerApiController) EditWarehouseOut() {
  1421. warehouse_out_time := c.GetString("warehouse_out_time")
  1422. id, _ := c.GetInt64("id", 0)
  1423. types, _ := c.GetInt64("type", 0)
  1424. storehouse_id, _ := c.GetInt64("storehouse_id")
  1425. if id == 0 {
  1426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1427. return
  1428. }
  1429. mtime := time.Now().Unix()
  1430. adminUserInfo := c.GetAdminUserInfo()
  1431. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1432. if parseDateErr != nil {
  1433. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1435. return
  1436. }
  1437. // 开始外部循环的事务
  1438. db := service.XTWriteDB()
  1439. tx := db.Begin()
  1440. // 在函数结束时处理事务回滚
  1441. defer func() {
  1442. if r := recover(); r != nil {
  1443. tx.Rollback()
  1444. }
  1445. }()
  1446. warehouseOut, _ := service.FindWareHouseOutById(id, tx)
  1447. tempWarehouseOut := models.WarehouseOut{
  1448. ID: warehouseOut.ID,
  1449. Mtime: mtime,
  1450. WarehouseOutTime: warehouseOutDate.Unix(),
  1451. StorehouseId: storehouse_id,
  1452. }
  1453. service.EditWarehouseOut(tempWarehouseOut, tx)
  1454. dataBody := make(map[string]interface{}, 0)
  1455. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1456. if err != nil {
  1457. utils.ErrorLog(err.Error())
  1458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1459. return
  1460. }
  1461. var warehousingOutInfo []*models.WarehouseOutInfo
  1462. var upDateWarehouseOutInfos []*models.WarehouseOutInfo
  1463. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1464. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1465. if len(thisStockOut) > 0 {
  1466. for _, item := range thisStockOut {
  1467. items := item.(map[string]interface{})
  1468. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1469. utils.ErrorLog("good_id")
  1470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1471. return
  1472. }
  1473. good_id := int64(items["good_id"].(float64))
  1474. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1475. utils.ErrorLog("good_type_id")
  1476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1477. return
  1478. }
  1479. good_type_id := int64(items["good_type_id"].(float64))
  1480. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1481. utils.ErrorLog("count")
  1482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1483. return
  1484. }
  1485. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1486. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1487. utils.ErrorLog("price")
  1488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1489. return
  1490. }
  1491. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1492. total := float64(count) * price
  1493. remark := items["remark"].(string)
  1494. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1495. utils.ErrorLog("id")
  1496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1497. return
  1498. }
  1499. id := int64(items["id"].(float64))
  1500. manufacturer := int64(items["manufacturer"].(float64))
  1501. dealer := int64(items["dealer"].(float64))
  1502. number := items["number"].(string)
  1503. license_number := items["license_number"].(string)
  1504. timeLayout := "2006-01-02"
  1505. loc, _ := time.LoadLocation("Local")
  1506. expiry_date := items["expiry_date"].(string)
  1507. var expiryDate int64
  1508. if len(expiry_date) > 0 {
  1509. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1510. if err != nil {
  1511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1512. return
  1513. }
  1514. expiryDate = theTime.Unix()
  1515. }
  1516. product_date := items["product_date"].(string)
  1517. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1518. admin_user_id := int64(items["admin_user_id"].(float64))
  1519. //if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  1520. // utils.ErrorLog("buy_price")
  1521. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1522. // return
  1523. //}
  1524. //buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  1525. stock_count := items["stock_count"].(string)
  1526. register_number := items["register_number"].(string)
  1527. patient_id := int64(items["patient_id"].(float64))
  1528. class_type := items["class_type"].(string)
  1529. var productDate int64
  1530. if len(product_date) > 0 {
  1531. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", product_date+" 00:00:00", loc)
  1532. if err != nil {
  1533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1534. return
  1535. }
  1536. productDate = theTime.Unix()
  1537. }
  1538. if id == 0 {
  1539. warehouseOutInfo := &models.WarehouseOutInfo{
  1540. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1541. WarehouseOutId: warehouseOut.ID,
  1542. GoodId: good_id,
  1543. GoodTypeId: good_type_id,
  1544. Count: count,
  1545. Price: price,
  1546. TotalPrice: total,
  1547. Status: 1,
  1548. Ctime: warehouseOut.WarehouseOutTime,
  1549. Mtime: time.Now().Unix(),
  1550. Remark: remark,
  1551. OrgId: adminUserInfo.CurrentOrgId,
  1552. Type: types,
  1553. IsSys: 0,
  1554. SysRecordTime: warehouseOut.WarehouseOutTime,
  1555. Number: number,
  1556. ExpiryDate: expiryDate,
  1557. ProductDate: productDate,
  1558. Dealer: dealer,
  1559. Manufacturer: manufacturer,
  1560. LicenseNumber: license_number,
  1561. ConsumableType: 1,
  1562. WarehouseInfotId: warehouse_info_id,
  1563. StorehouseId: storehouse_id,
  1564. AdminUserId: admin_user_id,
  1565. StockCount: stock_count,
  1566. RegisterNumber: register_number,
  1567. PatientId: patient_id,
  1568. ClassType: class_type,
  1569. }
  1570. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1571. } else {
  1572. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1573. utils.ErrorLog("is_sys")
  1574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1575. return
  1576. }
  1577. is_sys := int64(items["is_sys"].(float64))
  1578. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1579. utils.ErrorLog("sys_record_time")
  1580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1581. return
  1582. }
  1583. sys_record_time := int64(items["sys_record_time"].(float64))
  1584. warehouseOutInfo := &models.WarehouseOutInfo{
  1585. ID: id,
  1586. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1587. WarehouseOutId: warehouseOut.ID,
  1588. GoodId: good_id,
  1589. GoodTypeId: good_type_id,
  1590. Count: count,
  1591. Price: price,
  1592. TotalPrice: total,
  1593. Status: 1,
  1594. Ctime: warehouseOut.WarehouseOutTime,
  1595. Remark: remark,
  1596. OrgId: adminUserInfo.CurrentOrgId,
  1597. Mtime: time.Now().Unix(),
  1598. Type: types,
  1599. Manufacturer: manufacturer,
  1600. IsSys: is_sys,
  1601. SysRecordTime: sys_record_time,
  1602. Number: number,
  1603. ExpiryDate: expiryDate,
  1604. ProductDate: productDate,
  1605. Dealer: dealer,
  1606. LicenseNumber: license_number,
  1607. ConsumableType: 2,
  1608. WarehouseInfotId: warehouse_info_id,
  1609. StorehouseId: storehouse_id,
  1610. AdminUserId: admin_user_id,
  1611. StockCount: stock_count,
  1612. RegisterNumber: register_number,
  1613. PatientId: patient_id,
  1614. ClassType: class_type,
  1615. }
  1616. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1617. }
  1618. }
  1619. }
  1620. }
  1621. var errs error
  1622. //新增出库
  1623. if len(warehousingOutInfo) > 0 {
  1624. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1625. if parseDateErr != nil {
  1626. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  1627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1628. return
  1629. }
  1630. for _, item := range warehousingOutInfo {
  1631. //查询改耗材是否出库
  1632. outInfo, _ := service.GetGoodsIsExsit(item.GoodId, item.SysRecordTime, item.OrgId, item.WarehouseOutId, tx)
  1633. if outInfo.ID == 0 {
  1634. service.AddSigleWarehouseOutInfo(item, tx)
  1635. }
  1636. }
  1637. }
  1638. if len(upDateWarehouseOutInfos) > 0 {
  1639. for _, item := range upDateWarehouseOutInfos {
  1640. if item.ID > 0 {
  1641. service.UpDateWarehouseOutInfo(item, tx)
  1642. }
  1643. }
  1644. }
  1645. tx.Commit()
  1646. if errs != nil {
  1647. utils.ErrorLog(errs.Error())
  1648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1649. return
  1650. }
  1651. c.ServeSuccessJSON(map[string]interface{}{
  1652. "msg": "1",
  1653. })
  1654. }
  1655. func (c *StockManagerApiController) CreateCancelStock() {
  1656. cancel_stock_time := c.GetString("time")
  1657. types, _ := c.GetInt64("type", 0)
  1658. storehouse_id, _ := c.GetInt64("storehouse_id")
  1659. cancel_stock_id, _ := c.GetInt64("cancel_stock_id")
  1660. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1661. if parseDateErr != nil {
  1662. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1664. return
  1665. }
  1666. adminUserInfo := c.GetAdminUserInfo()
  1667. operation_time := time.Now().Unix()
  1668. creater := adminUserInfo.AdminUser.Id
  1669. ctime := time.Now().Unix()
  1670. timeStr := time.Now().Format("2006-01-02")
  1671. timeArr := strings.Split(timeStr, "-")
  1672. total, _ := service.FindAllCancelStockTotal(adminUserInfo.CurrentOrgId)
  1673. total = total + 1
  1674. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1675. cancelStock := models.CancelStock{
  1676. OrderNumber: orderNumber,
  1677. OperaTime: operation_time,
  1678. OrgId: adminUserInfo.CurrentOrgId,
  1679. Creater: creater,
  1680. Ctime: ctime,
  1681. Status: 1,
  1682. ReturnTime: cancelStockDate.Unix(),
  1683. Type: types,
  1684. StorehouseId: storehouse_id,
  1685. IsCheck: 2,
  1686. }
  1687. if cancel_stock_id == 0 {
  1688. service.AddSigleCancelStock(&cancelStock)
  1689. } else {
  1690. service.UpdateSigleCancelStock(cancel_stock_id, storehouse_id)
  1691. }
  1692. dataBody := make(map[string]interface{}, 0)
  1693. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1694. if err != nil {
  1695. utils.ErrorLog(err.Error())
  1696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1697. return
  1698. }
  1699. var cancelStockInfos []*models.CancelStockInfo
  1700. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1701. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1702. if len(thisStockIn) > 0 {
  1703. for _, item := range thisStockIn {
  1704. items := item.(map[string]interface{})
  1705. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1706. utils.ErrorLog("id")
  1707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1708. return
  1709. }
  1710. id := int64(items["id"].(float64))
  1711. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1712. utils.ErrorLog("good_id")
  1713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1714. return
  1715. }
  1716. good_id := int64(items["good_id"].(float64))
  1717. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1718. utils.ErrorLog("good_type_id")
  1719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1720. return
  1721. }
  1722. good_type_id := int64(items["good_type_id"].(float64))
  1723. return_count, _ := items["return_count"].(string)
  1724. if len(return_count) == 0 {
  1725. utils.ErrorLog("len(return_count) == 0")
  1726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1727. return
  1728. }
  1729. count, _ := strconv.ParseInt(return_count, 10, 64)
  1730. number := items["number"].(string)
  1731. register_account := items["register_account"].(string)
  1732. manufacturer, _ := items["manufacturer"].(string)
  1733. dealer, _ := items["dealer"].(string)
  1734. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1735. var expiryDates int64
  1736. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1737. expiryDates = 0
  1738. } else {
  1739. if len(items["expiry_date"].(string)) == 0 {
  1740. expiryDates = 0
  1741. } else {
  1742. expiryDate, _ := items["expiry_date"].(string)
  1743. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1744. expiryDates = expiry_date.Unix()
  1745. }
  1746. }
  1747. var productDates int64
  1748. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1749. productDates = 0
  1750. } else {
  1751. if len(items["product_date"].(string)) == 0 {
  1752. productDates = 0
  1753. } else {
  1754. productDate, _ := items["product_date"].(string)
  1755. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1756. productDates = product_date.Unix()
  1757. }
  1758. }
  1759. remark := items["remark"].(string)
  1760. retail_prices := items["price"].(string)
  1761. price, _ := strconv.ParseFloat(retail_prices, 64)
  1762. cancelStockInfo := &models.CancelStockInfo{
  1763. ID: id,
  1764. OrderNumber: cancelStock.OrderNumber,
  1765. CancelStockId: cancelStock.ID,
  1766. GoodId: good_id,
  1767. GoodTypeId: good_type_id,
  1768. Count: count,
  1769. Status: 1,
  1770. Ctime: ctime,
  1771. OrgId: adminUserInfo.CurrentOrgId,
  1772. Type: types,
  1773. Manufacturer: manufacturer,
  1774. Dealer: dealer,
  1775. Number: number,
  1776. ProductDate: productDates,
  1777. ExpiryDate: expiryDates,
  1778. RegisterAccount: register_account,
  1779. Remark: remark,
  1780. Price: price,
  1781. WarehouseInfoId: warehouse_info_id,
  1782. StorehouseId: storehouse_id,
  1783. IsCheck: 2,
  1784. }
  1785. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1786. }
  1787. }
  1788. }
  1789. lastCancelStock, _ := service.GetLastCancelStockById(adminUserInfo.CurrentOrgId)
  1790. for _, item := range cancelStockInfos {
  1791. item.CancelStockId = lastCancelStock.ID
  1792. if item.ID == 0 {
  1793. service.CreateCancelStockInfoOne(item)
  1794. }
  1795. if item.ID > 0 {
  1796. service.ModifyCancelStockInfo(item.ID, item)
  1797. }
  1798. }
  1799. list, _ := service.GetCancelStockInfo(lastCancelStock.ID, adminUserInfo.CurrentOrgId)
  1800. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  1801. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  1802. // storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseId, item.OrgId)
  1803. // goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  1804. // info, _ := service.GetWarehoureOrderStockOutFlow(item.GoodId, item.OrgId, item.WarehouseInfoId, storehouse_id)
  1805. // if item.Count > info.Count {
  1806. // service.UpdateCancelInfo(item.CancelStockId)
  1807. //
  1808. // c.ServeSuccessJSON(map[string]interface{}{
  1809. // "msg": "2",
  1810. // "good_name": goodObj.GoodName,
  1811. // "specification_name": goodObj.SpecificationName,
  1812. // "storehouse_name": storehouse.StorehouseName,
  1813. // })
  1814. // return
  1815. // }
  1816. //
  1817. // //查询该批次入库的值
  1818. // infolist, _ := service.GetWarehouseInfoByIdSeven(item.WarehouseInfoId)
  1819. //
  1820. // if item.Count > infolist.WarehousingCount {
  1821. // c.ServeSuccessJSON(map[string]interface{}{
  1822. // "msg": "4",
  1823. // "good_name": goodObj.GoodName,
  1824. // "specification_name": goodObj.SpecificationName,
  1825. // "storehouse_name": storehouse.StorehouseName,
  1826. // })
  1827. // return
  1828. // }
  1829. //
  1830. // if item.Count <= infolist.WarehousingCount {
  1831. // _, msgerrkonde := service.GetCancelStockDetailByOrderNumber(orderNumber, adminUserInfo.CurrentOrgId)
  1832. // if msgerrkonde == gorm.ErrRecordNotFound {
  1833. // service.AddSigleCancelStock(&cancelStock)
  1834. // }
  1835. // listcancel, _ := service.GetLastCancelStockById(adminUserInfo.CurrentOrgId)
  1836. //
  1837. // item.CancelStockId = listcancel.ID
  1838. // errs := service.CreateCancelStockInfoOne(item)
  1839. // list, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  1840. //
  1841. // var manufacturer_id int64
  1842. //
  1843. // for _, items := range list {
  1844. // if item.Manufacturer == items.ManufacturerName {
  1845. // manufacturer_id = items.ID
  1846. // }
  1847. // }
  1848. // flow := models.VmStockFlow{
  1849. // WarehousingId: 0,
  1850. // GoodId: item.GoodId,
  1851. // Number: item.Number,
  1852. // LicenseNumber: "",
  1853. // Count: item.Count,
  1854. // UserOrgId: adminUserInfo.CurrentOrgId,
  1855. // PatientId: 0,
  1856. // SystemTime: time.Now().Unix(),
  1857. // ConsumableType: 4,
  1858. // IsSys: 0,
  1859. // WarehousingOrder: "",
  1860. // WarehouseOutId: 0,
  1861. // WarehouseOutOrderNumber: "",
  1862. // IsEdit: 0,
  1863. // CancelStockId: cancelStock.ID,
  1864. // CancelOrderNumber: cancelStock.OrderNumber,
  1865. // Manufacturer: manufacturer_id,
  1866. // Dealer: 0,
  1867. // Creator: adminUserInfo.AdminUser.Id,
  1868. // UpdateCreator: 0,
  1869. // Status: 1,
  1870. // Ctime: time.Now().Unix(),
  1871. // Mtime: 0,
  1872. // Price: item.Price,
  1873. // WarehousingDetailId: 0,
  1874. // WarehouseOutDetailId: 0,
  1875. // CancelOutDetailId: 0,
  1876. // ProductDate: item.ProductDate,
  1877. // ExpireDate: item.ExpiryDate,
  1878. // StorehouseId: item.StorehouseId,
  1879. // }
  1880. // cancelStockInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  1881. // flow.CancelStockId = cancelStockInfo.CancelStockId
  1882. // flow.CancelOutDetailId = cancelStockInfo.ID
  1883. // service.CreateStockFlowOne(flow)
  1884. // if errs != nil {
  1885. // utils.ErrorLog(errs.Error())
  1886. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1887. // return
  1888. // }
  1889. //
  1890. // //查询该批次的剩余库存
  1891. // wareouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  1892. // if (wareouseinfo.StockCount + item.Count) > wareouseinfo.WarehousingCount {
  1893. // c.ServeSuccessJSON(map[string]interface{}{
  1894. // "msg": "5",
  1895. // "good_name": goodObj.GoodName,
  1896. // "specification_name": goodObj.SpecificationName,
  1897. // "storehouse_name": storehouse.StorehouseName,
  1898. // })
  1899. // return
  1900. // }
  1901. // //更改入库数量
  1902. // errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  1903. //
  1904. // storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  1905. // //查询剩余库存
  1906. // goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
  1907. // var sum_count int64
  1908. // var sum_in_count int64
  1909. // for _, it := range goodList {
  1910. // sum_count += it.StockCount
  1911. // sum_in_count += it.WarehousingCount
  1912. // }
  1913. // service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, adminUserInfo.CurrentOrgId)
  1914. //
  1915. // if err != nil {
  1916. // utils.ErrorLog(err.Error())
  1917. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1918. // return
  1919. // }
  1920. // }
  1921. //}
  1922. c.ServeSuccessJSON(map[string]interface{}{
  1923. "cancelStock": lastCancelStock,
  1924. "list": list,
  1925. "manufacturerList": manufacturerList,
  1926. "dealerList": dealerList,
  1927. })
  1928. return
  1929. }
  1930. func (c *StockManagerApiController) GetCancelStockInfoList() {
  1931. id, _ := c.GetInt64("id", 0)
  1932. cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
  1933. info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1934. manufacturerList, _ := service.GetAllManufacturerList(c.GetAdminUserInfo().CurrentOrgId)
  1935. dealerList, _ := service.GetAllDealerList(c.GetAdminUserInfo().CurrentOrgId)
  1936. c.ServeSuccessJSON(map[string]interface{}{
  1937. "list": cancelStockInfoList,
  1938. "info": info,
  1939. "manufacturerList": manufacturerList,
  1940. "dealerList": dealerList,
  1941. })
  1942. }
  1943. func (c *StockManagerApiController) GetCancelStockList() {
  1944. page, _ := c.GetInt64("page", -1)
  1945. limit, _ := c.GetInt64("limit", -1)
  1946. start_time := c.GetString("start_time")
  1947. end_time := c.GetString("end_time")
  1948. types, _ := c.GetInt64("type", 0)
  1949. keywords := c.GetString("keywords")
  1950. storehouse_id, _ := c.GetInt64("storehouse_id")
  1951. check_type, _ := c.GetInt64("check_type")
  1952. timeLayout := "2006-01-02"
  1953. loc, _ := time.LoadLocation("Local")
  1954. var startTime int64
  1955. if len(start_time) > 0 {
  1956. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1957. if err != nil {
  1958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1959. return
  1960. }
  1961. startTime = theTime.Unix()
  1962. }
  1963. var endTime int64
  1964. if len(end_time) > 0 {
  1965. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1966. if err != nil {
  1967. utils.ErrorLog(err.Error())
  1968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1969. return
  1970. }
  1971. endTime = theTime.Unix()
  1972. }
  1973. adminUserInfo := c.GetAdminUserInfo()
  1974. returnList, total, err := service.FindAllCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, storehouse_id, check_type)
  1975. houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  1976. if err == nil {
  1977. c.ServeSuccessJSON(map[string]interface{}{
  1978. "list": returnList,
  1979. "total": total,
  1980. "houseList": houseList,
  1981. })
  1982. } else {
  1983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1984. }
  1985. }
  1986. func (this *StockManagerApiController) DeleteCancelStock() {
  1987. ids := this.GetString("ids")
  1988. if len(ids) == 0 {
  1989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1990. return
  1991. }
  1992. idArray := strings.Split(ids, ",")
  1993. ////获取
  1994. //list, _ := service.GetCancelWarehosueInfo(idArray)
  1995. //for _, item := range list {
  1996. // info, _ := service.GetCancelStockById(item.WarehouseInfoId)
  1997. // warehousingInfo := models.WarehousingInfo{
  1998. // StockCount: info.Count,
  1999. // }
  2000. // //扣减库存
  2001. // service.ModefyWarehouseInfoNight(warehousingInfo, info.WarehouseInfoId)
  2002. //
  2003. // //查询该机构默认仓库
  2004. // storeConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
  2005. // //查询剩余库存
  2006. // goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, item.OrgId)
  2007. // var sum_count int64
  2008. // var sum_in_count int64
  2009. // for _, item := range goodList {
  2010. // sum_count += item.StockCount
  2011. // sum_in_count += item.WarehousingCount
  2012. // }
  2013. // service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
  2014. //
  2015. // //删除流水
  2016. // service.UpdatedStockFlowByCancelId(info.ID, info.GoodId)
  2017. //}
  2018. //获取
  2019. err := service.DeleteCancelStock(idArray)
  2020. if err != nil {
  2021. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2022. } else {
  2023. this.ServeSuccessJSON(map[string]interface{}{
  2024. "msg": "删除成功",
  2025. })
  2026. }
  2027. }
  2028. func (this *StockManagerApiController) DeleteCancelStockInfo() {
  2029. id, _ := this.GetInt64("id", 0)
  2030. //fmt.Println(id)
  2031. if id == 0 {
  2032. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2033. return
  2034. }
  2035. ////改变库存
  2036. //info, _ := service.GetCancelStockById(id)
  2037. //
  2038. //warehousingInfo := models.WarehousingInfo{
  2039. // StockCount: info.Count,
  2040. //}
  2041. ////扣减库存
  2042. //service.ModefyWarehouseInfoNight(warehousingInfo, info.WarehouseInfoId)
  2043. //
  2044. ////查询该机构默认仓库
  2045. //storeConfig, _ := service.GetAllStoreHouseConfig(info.OrgId)
  2046. ////查询剩余库存
  2047. //goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, info.OrgId)
  2048. //var sum_count int64
  2049. //var sum_in_count int64
  2050. //for _, item := range goodList {
  2051. // sum_count += item.StockCount
  2052. // sum_in_count += item.WarehousingCount
  2053. //}
  2054. //service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
  2055. //删除详情
  2056. err := service.UpDateCancleStockStatus(id)
  2057. //删除流水
  2058. //err = service.UpdatedStockFlowByCancelId(id, info.GoodId)
  2059. if err != nil {
  2060. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2061. } else {
  2062. this.ServeSuccessJSON(map[string]interface{}{
  2063. "msg": "删除成功",
  2064. })
  2065. }
  2066. }
  2067. func (c *StockManagerApiController) EditCancelStock() {
  2068. cancel_time := c.GetString("cancel_time")
  2069. id, _ := c.GetInt64("id", 0)
  2070. storehouse_id, _ := c.GetInt64("storehouse_id")
  2071. if id == 0 {
  2072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2073. return
  2074. }
  2075. ctime := time.Now().Unix()
  2076. mtime := time.Now().Unix()
  2077. adminUserInfo := c.GetAdminUserInfo()
  2078. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  2079. if parseDateErr != nil {
  2080. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  2081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2082. return
  2083. }
  2084. cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  2085. tempCancelStock := models.CancelStock{
  2086. ID: cancelStock.ID,
  2087. Mtime: mtime,
  2088. ReturnTime: cancelDate.Unix(),
  2089. StorehouseId: storehouse_id,
  2090. }
  2091. service.EditCancelStock(tempCancelStock)
  2092. dataBody := make(map[string]interface{}, 0)
  2093. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2094. if err != nil {
  2095. utils.ErrorLog(err.Error())
  2096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2097. return
  2098. }
  2099. var cancelStockInfos []*models.CancelStockInfo
  2100. var upDateCancelStockInfos []*models.CancelStockInfo
  2101. var stockFlow []*models.VmStockFlow
  2102. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  2103. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  2104. if len(thisCancelStock) > 0 {
  2105. for _, item := range thisCancelStock {
  2106. items := item.(map[string]interface{})
  2107. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2108. utils.ErrorLog("good_id")
  2109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2110. return
  2111. }
  2112. good_id := int64(items["good_id"].(float64))
  2113. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2114. utils.ErrorLog("good_type_id")
  2115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2116. return
  2117. }
  2118. good_type_id := int64(items["good_type_id"].(float64))
  2119. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2120. utils.ErrorLog("count")
  2121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2122. return
  2123. }
  2124. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2125. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2126. utils.ErrorLog("id")
  2127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2128. return
  2129. }
  2130. id := int64(items["id"].(float64))
  2131. number := items["number"].(string)
  2132. register_account := items["register_account"].(string)
  2133. manufacturer, _ := items["manufacturer"].(string)
  2134. dealer, _ := items["dealer"].(string)
  2135. remark := items["remark"].(string)
  2136. var productDates int64
  2137. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  2138. productDates = 0
  2139. } else {
  2140. if len(items["product_date"].(string)) == 0 {
  2141. productDates = 0
  2142. } else {
  2143. productDate, _ := items["product_date"].(string)
  2144. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  2145. productDates = product_date.Unix()
  2146. }
  2147. }
  2148. var expiryDates int64
  2149. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  2150. expiryDates = 0
  2151. } else {
  2152. if len(items["expiry_date"].(string)) == 0 {
  2153. expiryDates = 0
  2154. } else {
  2155. expiryDate, _ := items["expiry_date"].(string)
  2156. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  2157. expiryDates = expiry_date.Unix()
  2158. }
  2159. }
  2160. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2161. utils.ErrorLog("price")
  2162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2163. return
  2164. }
  2165. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2166. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  2167. if id == 0 {
  2168. cancelStockInfo := &models.CancelStockInfo{
  2169. GoodId: good_id,
  2170. GoodTypeId: good_type_id,
  2171. Count: count,
  2172. Status: 1,
  2173. Ctime: ctime,
  2174. OrgId: adminUserInfo.CurrentOrgId,
  2175. OrderNumber: cancelStock.OrderNumber,
  2176. CancelStockId: cancelStock.ID,
  2177. Mtime: time.Now().Unix(),
  2178. Number: number,
  2179. RegisterAccount: register_account,
  2180. Manufacturer: manufacturer,
  2181. Dealer: dealer,
  2182. ProductDate: productDates,
  2183. ExpiryDate: expiryDates,
  2184. Remark: remark,
  2185. Price: price,
  2186. WarehouseInfoId: warehouse_info_id,
  2187. StorehouseId: storehouse_id,
  2188. }
  2189. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  2190. flow := &models.VmStockFlow{
  2191. WarehousingId: 0,
  2192. GoodId: good_id,
  2193. Number: number,
  2194. LicenseNumber: "",
  2195. Count: count,
  2196. UserOrgId: adminUserInfo.CurrentOrgId,
  2197. PatientId: 0,
  2198. SystemTime: time.Now().Unix(),
  2199. ConsumableType: 4,
  2200. IsSys: 0,
  2201. WarehousingOrder: "",
  2202. WarehouseOutId: 0,
  2203. WarehouseOutOrderNumber: "",
  2204. IsEdit: 2,
  2205. CancelStockId: cancelStock.ID,
  2206. CancelOrderNumber: cancelStock.OrderNumber,
  2207. Manufacturer: 0,
  2208. Dealer: 0,
  2209. Creator: adminUserInfo.AdminUser.Id,
  2210. UpdateCreator: 0,
  2211. Status: 1,
  2212. Ctime: time.Now().Unix(),
  2213. Mtime: 0,
  2214. Price: price,
  2215. WarehousingDetailId: warehouse_info_id,
  2216. WarehouseOutDetailId: 0,
  2217. CancelOutDetailId: 0,
  2218. ProductDate: productDates,
  2219. ExpireDate: expiryDates,
  2220. StorehouseId: storehouse_id,
  2221. }
  2222. stockFlow = append(stockFlow, flow)
  2223. } else {
  2224. cancelStockInfo := &models.CancelStockInfo{
  2225. ID: id,
  2226. GoodId: good_id,
  2227. GoodTypeId: good_type_id,
  2228. Count: count,
  2229. Status: 1,
  2230. Ctime: ctime,
  2231. OrgId: adminUserInfo.CurrentOrgId,
  2232. OrderNumber: cancelStock.OrderNumber,
  2233. CancelStockId: cancelStock.ID,
  2234. Mtime: time.Now().Unix(),
  2235. Number: number,
  2236. RegisterAccount: register_account,
  2237. Manufacturer: manufacturer,
  2238. Dealer: dealer,
  2239. ProductDate: productDates,
  2240. ExpiryDate: expiryDates,
  2241. Remark: remark,
  2242. Price: price,
  2243. WarehouseInfoId: warehouse_info_id,
  2244. StorehouseId: storehouse_id,
  2245. }
  2246. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  2247. list, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  2248. var manufacuture_id int64
  2249. for _, it := range list {
  2250. if it.ManufacturerName == manufacturer {
  2251. manufacuture_id = it.ID
  2252. }
  2253. }
  2254. flow := &models.VmStockFlow{
  2255. WarehousingId: 0,
  2256. GoodId: good_id,
  2257. Number: number,
  2258. LicenseNumber: "",
  2259. Count: count,
  2260. UserOrgId: adminUserInfo.CurrentOrgId,
  2261. PatientId: 0,
  2262. SystemTime: time.Now().Unix(),
  2263. ConsumableType: 4,
  2264. IsSys: 0,
  2265. WarehousingOrder: "",
  2266. WarehouseOutId: 0,
  2267. WarehouseOutOrderNumber: "",
  2268. IsEdit: 2,
  2269. CancelStockId: cancelStock.ID,
  2270. CancelOrderNumber: cancelStock.OrderNumber,
  2271. Manufacturer: manufacuture_id,
  2272. Dealer: 0,
  2273. Creator: adminUserInfo.AdminUser.Id,
  2274. UpdateCreator: 0,
  2275. Status: 1,
  2276. Ctime: time.Now().Unix(),
  2277. Mtime: 0,
  2278. Price: price,
  2279. WarehousingDetailId: warehouse_info_id,
  2280. WarehouseOutDetailId: 0,
  2281. CancelOutDetailId: 0,
  2282. ProductDate: productDates,
  2283. ExpireDate: expiryDates,
  2284. StorehouseId: storehouse_id,
  2285. }
  2286. stockFlow = append(stockFlow, flow)
  2287. }
  2288. }
  2289. }
  2290. }
  2291. var errs error
  2292. for _, item := range cancelStockInfos {
  2293. service.CreateCancelStockInfoOne(item)
  2294. }
  2295. if len(upDateCancelStockInfos) > 0 {
  2296. for _, item := range upDateCancelStockInfos {
  2297. service.ModifyCancelStockInfo(item.ID, item)
  2298. }
  2299. }
  2300. //判断是否更改了仓库
  2301. //if storehouse_id == cancelStock.ID {
  2302. //
  2303. // if len(cancelStockInfos) > 0 {
  2304. //
  2305. // for _, item := range cancelStockInfos {
  2306. // //统计该耗材的出库数量
  2307. // info, _ := service.GetWarehoureOrderStockOutFlow(item.GoodId, item.OrgId, item.WarehouseInfoId, storehouse_id)
  2308. // storeObj, _ := service.FindStoreHouseByStorehouseId(storehouse_id, item.OrgId)
  2309. // if item.Count > info.Count {
  2310. // c.ServeSuccessJSON(map[string]interface{}{
  2311. // "msg": "2",
  2312. // "storehouse_name": storeObj.StorehouseName,
  2313. // })
  2314. // return
  2315. // }
  2316. // //查询该批次入库的值
  2317. // infolist, _ := service.GetWarehouseInfoByIdSix(item.WarehouseInfoId, storehouse_id)
  2318. //
  2319. // if item.Count > infolist.WarehousingCount {
  2320. // c.ServeSuccessJSON(map[string]interface{}{
  2321. // "msg": "4",
  2322. // "storehouse_name": storeObj.StorehouseName,
  2323. // })
  2324. // return
  2325. // }
  2326. //
  2327. // if item.Count <= infolist.WarehousingCount {
  2328. //
  2329. // errs := service.CreateCancelStockInfo(cancelStockInfos)
  2330. //
  2331. // if errs != nil {
  2332. // utils.ErrorLog(errs.Error())
  2333. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2334. // return
  2335. // }
  2336. //
  2337. // //更改入库数量
  2338. // errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  2339. //
  2340. // //查询该机构默认仓库
  2341. // storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2342. // //查询剩余库存
  2343. // goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
  2344. // var sum_count int64
  2345. // var sum_in_count int64
  2346. // for _, it := range goodList {
  2347. // sum_count += it.StockCount
  2348. // sum_in_count += it.WarehousingCount
  2349. // }
  2350. // service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, adminUserInfo.CurrentOrgId)
  2351. //
  2352. // break
  2353. // }
  2354. //
  2355. // }
  2356. //
  2357. // if len(stockFlow) > 0 {
  2358. // for _, itemcancel := range stockFlow {
  2359. // //查询是否存在
  2360. // stockInfo, errcode := service.IsExsitStockFlow(itemcancel.GoodId, itemcancel.CancelOrderNumber)
  2361. // if errcode == gorm.ErrRecordNotFound {
  2362. // service.CreateStockFlowSix(itemcancel)
  2363. // } else {
  2364. // flow := models.VmStockFlow{
  2365. // Count: itemcancel.Count,
  2366. // Manufacturer: itemcancel.Manufacturer,
  2367. // Dealer: itemcancel.Dealer,
  2368. // Price: itemcancel.Price,
  2369. // ProductDate: itemcancel.ProductDate,
  2370. // ExpireDate: itemcancel.ExpireDate,
  2371. // StorehouseId: itemcancel.StorehouseId,
  2372. // }
  2373. // service.UpdateStockFlowThree(stockInfo.ID, flow)
  2374. // }
  2375. // }
  2376. // }
  2377. // }
  2378. //
  2379. // if len(upDateCancelStockInfos) > 0 {
  2380. // for _, item := range upDateCancelStockInfos {
  2381. //
  2382. // var all_total int64
  2383. // //获取该批次最后一套退库记录
  2384. // info, _ := service.GetLastCancelInfo(item.WarehouseInfoId, item.GoodId)
  2385. // //查询该批次总的退库数量
  2386. // list, _ := service.GetAllCancelInfoById(item.WarehouseInfoId, item.GoodId)
  2387. // for _, it := range list {
  2388. // all_total += it.Count
  2389. // }
  2390. //
  2391. // //比较退库库数量和最后一次退库库数据大小
  2392. // //退库(加)
  2393. // if item.Count > info.Count {
  2394. // var total = item.Count - info.Count
  2395. // errs = service.UpDateCancelStockInfo(item)
  2396. //
  2397. // warehouseinfo, _ := service.GetWarehouseInfoByIdSix(item.WarehouseInfoId, storehouse_id)
  2398. // storeObj, _ := service.FindStoreHouseByStorehouseId(storehouse_id, item.OrgId)
  2399. //
  2400. // // 总退库数量大于入库数据
  2401. // if all_total > warehouseinfo.StockCount {
  2402. // c.ServeSuccessJSON(map[string]interface{}{
  2403. // "msg": "5",
  2404. // "storehouse_name": storeObj.StorehouseName,
  2405. // })
  2406. // return
  2407. // }
  2408. // parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total)
  2409. //
  2410. // if parseDateErr != nil {
  2411. // utils.ErrorLog(errs.Error())
  2412. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2413. // break
  2414. // }
  2415. // }
  2416. // //(减)
  2417. // if item.Count < info.Count {
  2418. // errs = service.UpDateCancelStockInfo(item)
  2419. //
  2420. // var total_count = info.Count - item.Count
  2421. //
  2422. // parseDateErr := service.UpdateWareInfoByIdSix(item.WarehouseInfoId, total_count)
  2423. //
  2424. // if parseDateErr != nil {
  2425. // utils.ErrorLog(errs.Error())
  2426. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2427. // return
  2428. // }
  2429. //
  2430. // }
  2431. // if item.Count == info.Count {
  2432. // errs = service.UpDateCancelStockInfo(item)
  2433. //
  2434. // }
  2435. //
  2436. // //查询该机构默认仓库
  2437. // storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2438. // //查询剩余库存
  2439. // goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
  2440. // var sum_count int64
  2441. // var sum_in_count int64
  2442. // for _, it := range goodList {
  2443. // sum_count += it.StockCount
  2444. // sum_in_count += it.WarehousingCount
  2445. // }
  2446. // service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, adminUserInfo.CurrentOrgId)
  2447. // }
  2448. // }
  2449. //
  2450. // if len(stockFlow) > 0 {
  2451. // for _, itemcancel := range stockFlow {
  2452. //
  2453. // //查询是否存在
  2454. // stockInfo, errcode := service.IsExsitStockFlow(itemcancel.GoodId, itemcancel.CancelOrderNumber)
  2455. // if errcode == gorm.ErrRecordNotFound {
  2456. //
  2457. // } else {
  2458. // flow := models.VmStockFlow{
  2459. // Count: itemcancel.Count,
  2460. // Manufacturer: itemcancel.Manufacturer,
  2461. // Dealer: itemcancel.Dealer,
  2462. // Price: itemcancel.Price,
  2463. // LicenseNumber: itemcancel.LicenseNumber,
  2464. // Number: itemcancel.Number,
  2465. // ExpireDate: itemcancel.ExpireDate,
  2466. // ProductDate: itemcancel.ProductDate,
  2467. // StorehouseId: itemcancel.StorehouseId,
  2468. // }
  2469. // service.UpdateStockFlowThree(stockInfo.ID, flow)
  2470. // }
  2471. // }
  2472. // }
  2473. //
  2474. //}
  2475. if errs != nil {
  2476. utils.ErrorLog(errs.Error())
  2477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2478. return
  2479. }
  2480. c.ServeSuccessJSON(map[string]interface{}{
  2481. "msg": "3",
  2482. })
  2483. }
  2484. func (this *StockManagerApiController) GetCancelStockConfig() {
  2485. types, _ := this.GetInt64("type", 0)
  2486. adminUserInfo := this.GetAdminUserInfo()
  2487. warehouseOutInfoList, _ := service.FindAllWarehouseOutInfo(adminUserInfo.CurrentOrgId, types)
  2488. this.ServeSuccessJSON(map[string]interface{}{
  2489. "warehouseOutInfoList": warehouseOutInfoList,
  2490. })
  2491. }
  2492. func (c *StockManagerApiController) GetQueryInfo() {
  2493. page, _ := c.GetInt64("page", -1)
  2494. limit, _ := c.GetInt64("limit", -1)
  2495. keyword := c.GetString("keyword")
  2496. start_time := c.GetString("start_time")
  2497. end_time := c.GetString("end_time")
  2498. type_name, _ := c.GetInt64("type_name")
  2499. timeLayout := "2006-01-02"
  2500. loc, _ := time.LoadLocation("Local")
  2501. var startTime int64
  2502. if len(start_time) > 0 {
  2503. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2504. if err != nil {
  2505. fmt.Println(err)
  2506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2507. return
  2508. }
  2509. startTime = theTime.Unix()
  2510. }
  2511. var endTime int64
  2512. if len(end_time) > 0 {
  2513. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2514. if err != nil {
  2515. utils.ErrorLog(err.Error())
  2516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2517. return
  2518. }
  2519. endTime = theTime.Unix()
  2520. }
  2521. adminUserInfo := c.GetAdminUserInfo()
  2522. list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, startTime, endTime, type_name)
  2523. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  2524. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId, "")
  2525. if err == nil {
  2526. c.ServeSuccessJSON(map[string]interface{}{
  2527. "list": list,
  2528. "total": total,
  2529. "info": info,
  2530. "infomationList": infomationList,
  2531. "orgid": adminUserInfo.CurrentOrgId,
  2532. })
  2533. } else {
  2534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2535. }
  2536. }
  2537. func (c *StockManagerApiController) SearchWarehouse() {
  2538. keywords := c.GetString("keywords")
  2539. adminUserInfo := c.GetAdminUserInfo()
  2540. warehouseList, total, err := service.FindAllWarehouseByKeyword(adminUserInfo.CurrentOrgId, 1, 10, keywords)
  2541. if err == nil {
  2542. c.ServeSuccessJSON(map[string]interface{}{
  2543. "list": warehouseList,
  2544. "total": total,
  2545. })
  2546. } else {
  2547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2548. }
  2549. }
  2550. func (c *StockManagerApiController) GetAllConfig() {
  2551. adminUserInfo := c.GetAdminUserInfo()
  2552. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  2553. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  2554. goodType, _ := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  2555. goodInfo, _ := service.FindAllGoodInfoTwo(adminUserInfo.CurrentOrgId)
  2556. //获取所有仓库看列表
  2557. list, _ := service.GetAllStoreHouseListThree(adminUserInfo.CurrentOrgId)
  2558. //获取仓库配置列表
  2559. configList, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2560. appId := c.GetAdminUserInfo().CurrentAppId
  2561. doctorList, _ := service.GetAllDoctorListSix(adminUserInfo.CurrentOrgId, appId)
  2562. patients, _ := service.GetAllpatientTwenty(adminUserInfo.CurrentOrgId)
  2563. c.ServeSuccessJSON(map[string]interface{}{
  2564. "manufacturer": manufacturer,
  2565. "dealer": dealer,
  2566. "goodType": goodType,
  2567. "goodInfo": goodInfo,
  2568. "list": list,
  2569. "configlist": configList,
  2570. "doctorList": doctorList,
  2571. "patients": patients,
  2572. })
  2573. }
  2574. func (this *StockManagerApiController) GetAllSalesReturnConfig() {
  2575. types, _ := this.GetInt64("type", 0)
  2576. adminUserInfo := this.GetAdminUserInfo()
  2577. warehouseInfoList, _ := service.FindAllWarehouseInfo(adminUserInfo.CurrentOrgId, types)
  2578. this.ServeSuccessJSON(map[string]interface{}{
  2579. "warehouseInfoList": warehouseInfoList,
  2580. })
  2581. }
  2582. func (this *StockManagerApiController) GetDetailInfo() {
  2583. page, _ := this.GetInt64("page", 0)
  2584. limit, _ := this.GetInt64("limit", 0)
  2585. start_time := this.GetString("start_time")
  2586. end_time := this.GetString("end_time")
  2587. types, _ := this.GetInt64("type", 0)
  2588. keywords := this.GetString("keywords")
  2589. manufacturer, _ := this.GetInt64("manufacturer", 0)
  2590. order_type, _ := this.GetInt64("order_type", 0)
  2591. dealer, _ := this.GetInt64("dealer", 0)
  2592. storehouse_id, _ := this.GetInt64("storehouse_id")
  2593. good_id, _ := this.GetInt64("good_id")
  2594. order_way, _ := this.GetInt64("order_way")
  2595. timeLayout := "2006-01-02"
  2596. loc, _ := time.LoadLocation("Local")
  2597. var startTime int64
  2598. if len(start_time) > 0 {
  2599. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2600. if err != nil {
  2601. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2602. return
  2603. }
  2604. startTime = theTime.Unix()
  2605. }
  2606. var endTime int64
  2607. if len(end_time) > 0 {
  2608. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2609. if err != nil {
  2610. utils.ErrorLog(err.Error())
  2611. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2612. return
  2613. }
  2614. endTime = theTime.Unix()
  2615. }
  2616. adminUserInfo := this.GetAdminUserInfo()
  2617. var list []*models.WarehousingInfo
  2618. var list1 []*models.WarehouseOutInfo
  2619. var list2 []*models.SalesReturnInfo
  2620. var list3 []*models.CancelStockInfo
  2621. var total int64
  2622. var err error
  2623. var total_price float64
  2624. houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  2625. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  2626. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  2627. patientsList, _ := service.GetAllpatient(adminUserInfo.CurrentOrgId)
  2628. var goodKind = "耗材种类"
  2629. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  2630. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, adminUserInfo.CurrentOrgId)
  2631. if types == 1 {
  2632. list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id, good_id)
  2633. _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id, good_id)
  2634. if err == nil {
  2635. this.ServeSuccessJSON(map[string]interface{}{
  2636. "list": list,
  2637. "total": total,
  2638. "total_price": total_price,
  2639. "houseList": houseList,
  2640. "manufacturerList": manufacturerList,
  2641. "dealerList": dealerList,
  2642. "patientsList": patientsList,
  2643. "goodKindList": goodKindList,
  2644. })
  2645. } else {
  2646. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2647. }
  2648. } else if types == 2 {
  2649. list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id, good_id, order_way)
  2650. _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id, good_id, order_way)
  2651. if err == nil {
  2652. this.ServeSuccessJSON(map[string]interface{}{
  2653. "list": list1,
  2654. "total": total,
  2655. "total_price": total_price,
  2656. "houseList": houseList,
  2657. "manufacturerList": manufacturerList,
  2658. "dealerList": dealerList,
  2659. "patientsList": patientsList,
  2660. "goodKindList": goodKindList,
  2661. })
  2662. } else {
  2663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2664. }
  2665. } else if types == 3 {
  2666. list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2667. if err == nil {
  2668. this.ServeSuccessJSON(map[string]interface{}{
  2669. "list": list2,
  2670. "total": total,
  2671. "manufacturerList": manufacturerList,
  2672. "dealerList": dealerList,
  2673. "patientsList": patientsList,
  2674. "goodKindList": goodKindList,
  2675. })
  2676. } else {
  2677. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2678. }
  2679. } else if types == 4 {
  2680. list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id, good_id)
  2681. listGroup, err := service.FindeCancelGroup(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id, good_id)
  2682. if err == nil {
  2683. this.ServeSuccessJSON(map[string]interface{}{
  2684. "list": list3,
  2685. "total": total,
  2686. "listgroup": listGroup,
  2687. "houseList": houseList,
  2688. "manufacturerList": manufacturerList,
  2689. "dealerList": dealerList,
  2690. "patientsList": patientsList,
  2691. "goodKindList": goodKindList,
  2692. })
  2693. } else {
  2694. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2695. }
  2696. }
  2697. }
  2698. func (this *StockManagerApiController) GetUserDetailInfo() {
  2699. order_id, _ := this.GetInt64("id")
  2700. if order_id <= 0 {
  2701. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2702. return
  2703. }
  2704. adminUserInfo := this.GetAdminUserInfo()
  2705. userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  2706. if err == nil {
  2707. this.ServeSuccessJSON(map[string]interface{}{
  2708. "list": userDetails,
  2709. "total": total,
  2710. })
  2711. } else {
  2712. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2713. return
  2714. }
  2715. }
  2716. func (this *StockManagerApiController) PostSearchStock() {
  2717. keyword := this.GetString("keyword")
  2718. adminUserInfo := this.GetAdminUserInfo()
  2719. orgId := adminUserInfo.CurrentOrgId
  2720. stock, err := service.PostSearchStock(keyword, orgId)
  2721. if err != nil {
  2722. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2723. }
  2724. this.ServeSuccessJSON(map[string]interface{}{
  2725. "stock": stock,
  2726. })
  2727. }
  2728. func (this *StockManagerApiController) GetOutStockTotalCount() {
  2729. warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
  2730. adminUserInfo := this.GetAdminUserInfo()
  2731. stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
  2732. if err != nil {
  2733. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2734. }
  2735. this.ServeSuccessJSON(map[string]interface{}{
  2736. "stockCount": stockCount,
  2737. })
  2738. }
  2739. func (this *StockManagerApiController) AddGoodInformation() {
  2740. adminUserInfo := this.GetAdminUserInfo()
  2741. orgId := adminUserInfo.CurrentOrgId
  2742. dataBody := make(map[string]interface{}, 0)
  2743. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2744. if err != nil {
  2745. utils.ErrorLog(err.Error())
  2746. return
  2747. }
  2748. utils.ErrorLog("%v", dataBody)
  2749. var goods []*models.GoodInfo
  2750. var total_goods []interface{}
  2751. tempGoods := dataBody["goods"].([]interface{})
  2752. total_goods = tempGoods
  2753. for index, goodMap := range tempGoods {
  2754. goodNameM := goodMap.(map[string]interface{})
  2755. var good models.GoodInfo
  2756. if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
  2757. utils.ErrorLog("good_name")
  2758. return
  2759. }
  2760. good_name, _ := goodNameM["good_name"].(string)
  2761. if len(good_name) == 0 { //名字为空则生成一条导入错误日志
  2762. err_log := models.ExportErrLog{
  2763. LogType: 5,
  2764. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2765. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
  2766. Status: 1,
  2767. CreateTime: time.Now().Unix(),
  2768. UpdateTime: time.Now().Unix(),
  2769. ExportTime: time.Now().Unix(),
  2770. }
  2771. service.CreateExportErrLog(&err_log)
  2772. continue
  2773. }
  2774. good.GoodName = good_name
  2775. // 获取数据字典数据
  2776. var good_kind_id int64
  2777. var name = "耗材种类"
  2778. config, _ := service.GetDrugDataConfig(0, name)
  2779. good_kind := goodNameM["good_kind"].(string)
  2780. if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
  2781. err_log := models.ExportErrLog{
  2782. LogType: 5,
  2783. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2784. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
  2785. Status: 1,
  2786. CreateTime: time.Now().Unix(),
  2787. UpdateTime: time.Now().Unix(),
  2788. ExportTime: time.Now().Unix(),
  2789. }
  2790. service.CreateExportErrLog(&err_log)
  2791. continue
  2792. }
  2793. if len(good_kind) != 0 {
  2794. _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
  2795. lastConfig, _ := service.GetLastDicConfig(config.ID, orgId)
  2796. dataconfig := models.DictDataconfig{
  2797. ParentId: config.ID,
  2798. Module: "system",
  2799. OrgId: orgId,
  2800. Name: good_kind,
  2801. FieldName: "",
  2802. Value: lastConfig.Value + 1,
  2803. CreatedTime: "",
  2804. UpdatedTime: "",
  2805. CreateUserId: adminUserInfo.AdminUser.Id,
  2806. Status: 1,
  2807. Remark: "",
  2808. DeleteIdSystem: 0,
  2809. Title: "",
  2810. Content: "",
  2811. Order: 0,
  2812. Code: "",
  2813. }
  2814. if errcodegoodkind == gorm.ErrRecordNotFound {
  2815. service.CreatedDicConfig(&dataconfig)
  2816. }
  2817. }
  2818. dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
  2819. for _, it := range dataConfig {
  2820. if good_kind == it.Name {
  2821. fmt.Println(it.Name)
  2822. good_kind_id = int64(it.Value)
  2823. }
  2824. }
  2825. good.GoodKind = good_kind_id
  2826. good_type := goodNameM["type_name"].(string)
  2827. if len(good_type) == 0 {
  2828. err_log := models.ExportErrLog{
  2829. LogType: 5,
  2830. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2831. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材类型不能为空",
  2832. Status: 1,
  2833. CreateTime: time.Now().Unix(),
  2834. UpdateTime: time.Now().Unix(),
  2835. ExportTime: time.Now().Unix(),
  2836. }
  2837. service.CreateExportErrLog(&err_log)
  2838. continue
  2839. }
  2840. if len(good_type) != 0 {
  2841. _, errcodegoodtype := service.GetGoodType(good_type, orgId)
  2842. if errcodegoodtype == gorm.ErrRecordNotFound {
  2843. goodsType := models.GoodsType{
  2844. TypeName: good_type,
  2845. Remark: "",
  2846. Ctime: time.Now().Unix(),
  2847. Mtime: 0,
  2848. Creater: adminUserInfo.AdminUser.Id,
  2849. Modifier: 0,
  2850. OrgId: adminUserInfo.CurrentOrgId,
  2851. Status: 1,
  2852. Type: 0,
  2853. Number: 0,
  2854. OutStock: 0,
  2855. StockAttribute: 1,
  2856. }
  2857. service.CreatedGoodType(&goodsType)
  2858. }
  2859. }
  2860. goodType, _ := service.GetAllGoodType(orgId)
  2861. var good_type_id int64
  2862. for _, it := range goodType {
  2863. if good_type == it.TypeName {
  2864. good_type_id = it.ID
  2865. }
  2866. }
  2867. good.GoodTypeId = good_type_id
  2868. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  2869. if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
  2870. err_log := models.ExportErrLog{
  2871. LogType: 5,
  2872. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2873. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  2874. Status: 1,
  2875. CreateTime: time.Now().Unix(),
  2876. UpdateTime: time.Now().Unix(),
  2877. ExportTime: time.Now().Unix(),
  2878. }
  2879. service.CreateExportErrLog(&err_log)
  2880. continue
  2881. }
  2882. var medical_insurance_id int64
  2883. var medicalInsurance = "医保等级"
  2884. medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
  2885. if len(medical_insurance_level) != 0 {
  2886. _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
  2887. if errcodemedicalInsurance == gorm.ErrRecordNotFound {
  2888. mediConfigOne, _ := service.GetLastDicConfig(medicalInsuranceDataConfig.ID, orgId)
  2889. dataconfig := models.DictDataconfig{
  2890. ParentId: medicalInsuranceDataConfig.ID,
  2891. Module: "system",
  2892. OrgId: orgId,
  2893. Name: medical_insurance_level,
  2894. FieldName: "",
  2895. Value: mediConfigOne.Value + 1,
  2896. CreatedTime: "",
  2897. UpdatedTime: "",
  2898. CreateUserId: adminUserInfo.AdminUser.Id,
  2899. Status: 1,
  2900. Remark: "",
  2901. DeleteIdSystem: 0,
  2902. Title: "",
  2903. Content: "",
  2904. Order: 0,
  2905. Code: "",
  2906. }
  2907. service.CreatedDicConfig(&dataconfig)
  2908. }
  2909. }
  2910. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
  2911. for _, it := range medicalInsuranceList {
  2912. if medical_insurance_level == it.Name {
  2913. medical_insurance_id = int64(it.Value)
  2914. }
  2915. }
  2916. good.MedicalInsuranceLevel = medical_insurance_id
  2917. if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
  2918. utils.ErrorLog("specification_name")
  2919. return
  2920. }
  2921. specification_name := goodNameM["specification_name"].(string)
  2922. if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
  2923. err_log := models.ExportErrLog{
  2924. LogType: 5,
  2925. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2926. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
  2927. Status: 1,
  2928. CreateTime: time.Now().Unix(),
  2929. UpdateTime: time.Now().Unix(),
  2930. ExportTime: time.Now().Unix(),
  2931. }
  2932. service.CreateExportErrLog(&err_log)
  2933. continue
  2934. }
  2935. good.SpecificationName = specification_name
  2936. var manufacturer_id int64
  2937. manufacturer := goodNameM["manufacturer"].(string)
  2938. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  2939. err_log := models.ExportErrLog{
  2940. LogType: 5,
  2941. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2942. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
  2943. Status: 1,
  2944. CreateTime: time.Now().Unix(),
  2945. UpdateTime: time.Now().Unix(),
  2946. ExportTime: time.Now().Unix(),
  2947. }
  2948. service.CreateExportErrLog(&err_log)
  2949. continue
  2950. }
  2951. if len(manufacturer) != 0 {
  2952. _, errcodes := service.GetManufacturerName(orgId, manufacturer)
  2953. manu := models.Manufacturer{
  2954. ManufacturerName: manufacturer,
  2955. Status: 1,
  2956. OrgId: orgId,
  2957. Creater: adminUserInfo.AdminUser.Id,
  2958. }
  2959. if errcodes == gorm.ErrRecordNotFound {
  2960. service.CreateManufacturer(&manu)
  2961. }
  2962. }
  2963. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2964. for _, it := range manufacturerList {
  2965. if manufacturer == it.ManufacturerName {
  2966. manufacturer_id = it.ID
  2967. }
  2968. }
  2969. good.Manufacturer = manufacturer_id
  2970. if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
  2971. utils.ErrorLog("unit_id")
  2972. return
  2973. }
  2974. unit_id := int64(goodNameM["unit_id"].(float64))
  2975. if unit_id <= 0 { //名字为空则生成一条导入错误日志
  2976. err_log := models.ExportErrLog{
  2977. LogType: 5,
  2978. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2979. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
  2980. Status: 1,
  2981. CreateTime: time.Now().Unix(),
  2982. UpdateTime: time.Now().Unix(),
  2983. ExportTime: time.Now().Unix(),
  2984. }
  2985. service.CreateExportErrLog(&err_log)
  2986. continue
  2987. }
  2988. good.GoodUnit = unit_id
  2989. default_count := int64(goodNameM["default_count"].(float64))
  2990. if default_count == 0 { //名字为空则生成一条导入错误日志
  2991. err_log := models.ExportErrLog{
  2992. LogType: 5,
  2993. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2994. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "默认单次用量不能为空",
  2995. Status: 1,
  2996. CreateTime: time.Now().Unix(),
  2997. UpdateTime: time.Now().Unix(),
  2998. ExportTime: time.Now().Unix(),
  2999. }
  3000. service.CreateExportErrLog(&err_log)
  3001. continue
  3002. }
  3003. good.DefaultCount = default_count
  3004. default_count_unit := goodNameM["default_count_unit"].(string)
  3005. if len(default_count_unit) == 0 { //名字为空则生成一条导入错误日志
  3006. err_log := models.ExportErrLog{
  3007. LogType: 5,
  3008. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3009. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "默认单次用量单位不能为空",
  3010. Status: 1,
  3011. CreateTime: time.Now().Unix(),
  3012. UpdateTime: time.Now().Unix(),
  3013. ExportTime: time.Now().Unix(),
  3014. }
  3015. service.CreateExportErrLog(&err_log)
  3016. continue
  3017. }
  3018. good.DefaultCountUnit = default_count_unit
  3019. retail_prices := goodNameM["retail_price"].(string)
  3020. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  3021. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  3022. err_log := models.ExportErrLog{
  3023. LogType: 5,
  3024. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3025. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的价格不能为空",
  3026. Status: 1,
  3027. CreateTime: time.Now().Unix(),
  3028. UpdateTime: time.Now().Unix(),
  3029. ExportTime: time.Now().Unix(),
  3030. }
  3031. service.CreateExportErrLog(&err_log)
  3032. continue
  3033. }
  3034. good.RetailPrice = retail_price
  3035. buy_prices := goodNameM["buy_price"].(string)
  3036. buy_price, _ := strconv.ParseFloat(buy_prices, 64)
  3037. if buy_price <= 0 { //名字为空则生成一条导入错误日志
  3038. err_log := models.ExportErrLog{
  3039. LogType: 5,
  3040. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3041. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
  3042. Status: 1,
  3043. CreateTime: time.Now().Unix(),
  3044. UpdateTime: time.Now().Unix(),
  3045. ExportTime: time.Now().Unix(),
  3046. }
  3047. service.CreateExportErrLog(&err_log)
  3048. continue
  3049. }
  3050. good.BuyPrice = buy_price
  3051. if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
  3052. utils.ErrorLog("stock_warn_count")
  3053. return
  3054. }
  3055. stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
  3056. if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
  3057. err_log := models.ExportErrLog{
  3058. LogType: 5,
  3059. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3060. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
  3061. Status: 1,
  3062. CreateTime: time.Now().Unix(),
  3063. UpdateTime: time.Now().Unix(),
  3064. ExportTime: time.Now().Unix(),
  3065. }
  3066. service.CreateExportErrLog(&err_log)
  3067. continue
  3068. }
  3069. good.StockWarnCount = stock_warn_count
  3070. var dealer_id int64
  3071. dealerName := goodNameM["dealer"].(string)
  3072. fmt.Println("经销商", dealerName)
  3073. dealer := models.Dealer{
  3074. OrgId: orgId,
  3075. Status: 1,
  3076. DealerName: dealerName,
  3077. Creater: adminUserInfo.AdminUser.Id,
  3078. Ctime: time.Now().Unix(),
  3079. }
  3080. if len(dealerName) != 0 {
  3081. _, errcodedealer := service.GetDealerByName(orgId, dealerName)
  3082. if errcodedealer == gorm.ErrRecordNotFound {
  3083. service.CreateDealer(&dealer)
  3084. }
  3085. }
  3086. dealerList, _ := service.GetAllDealerList(orgId)
  3087. for _, it := range dealerList {
  3088. if dealerName == it.DealerName {
  3089. dealer_id = it.ID
  3090. }
  3091. }
  3092. good.Dealer = dealer_id
  3093. if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
  3094. utils.ErrorLog("pinyin")
  3095. return
  3096. }
  3097. pinyin := goodNameM["pinyin"].(string)
  3098. good.Pinyin = pinyin
  3099. if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
  3100. utils.ErrorLog("wubi")
  3101. return
  3102. }
  3103. wubi := goodNameM["wubi"].(string)
  3104. good.Wubi = wubi
  3105. if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
  3106. utils.ErrorLog("social_security_directory_code")
  3107. return
  3108. }
  3109. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  3110. good.SocialSecurityDirectoryCode = social_security_directory_code
  3111. if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
  3112. utils.ErrorLog("is_special_diseases")
  3113. return
  3114. }
  3115. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  3116. good.IsSpecialDiseases = is_special_diseases
  3117. if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
  3118. utils.ErrorLog("is_record")
  3119. return
  3120. }
  3121. is_record := int64(goodNameM["is_record"].(float64))
  3122. good.IsRecord = is_record
  3123. if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
  3124. utils.ErrorLog("good_status")
  3125. return
  3126. }
  3127. good_status := goodNameM["good_status"].(string)
  3128. good.GoodStatus = good_status
  3129. if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
  3130. utils.ErrorLog("medical_insurance_number")
  3131. return
  3132. }
  3133. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  3134. good.MedicalInsuranceNumber = medical_insurance_number
  3135. if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
  3136. utils.ErrorLog("production_type")
  3137. return
  3138. }
  3139. production_type := goodNameM["production_type"].(string)
  3140. good.ProductionType = production_type
  3141. if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
  3142. utils.ErrorLog("remark")
  3143. return
  3144. }
  3145. remark := goodNameM["remark"].(string)
  3146. good.Remark = remark
  3147. statistics_category := goodNameM["statistics_category"].(string)
  3148. var categoryName = "统计分类"
  3149. var statistic_id int64
  3150. drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
  3151. if len(statistics_category) != 0 {
  3152. _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
  3153. if errcodecagegory == gorm.ErrRecordNotFound {
  3154. dicConfigThree, _ := service.GetLastDicConfig(drugDataConfig.ID, orgId)
  3155. dataconfig := models.DictDataconfig{
  3156. ParentId: drugDataConfig.ID,
  3157. Module: "system",
  3158. OrgId: orgId,
  3159. Name: statistics_category,
  3160. FieldName: "",
  3161. Value: dicConfigThree.Value + 1,
  3162. CreatedTime: "",
  3163. UpdatedTime: "",
  3164. CreateUserId: adminUserInfo.AdminUser.Id,
  3165. Status: 1,
  3166. Remark: "",
  3167. DeleteIdSystem: 0,
  3168. Title: "",
  3169. Content: "",
  3170. Order: 0,
  3171. Code: "",
  3172. }
  3173. service.CreatedDicConfig(&dataconfig)
  3174. }
  3175. }
  3176. parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
  3177. for _, it := range parentDataConfig {
  3178. if statistics_category == it.Name {
  3179. statistic_id = int64(it.Value)
  3180. }
  3181. }
  3182. good.StatisticsCategory = statistic_id
  3183. special_medical := goodNameM["special_medical"].(string)
  3184. good.SpecialMedical = special_medical
  3185. packing_unit := goodNameM["good_unit"].(string)
  3186. good.PackingUnit = packing_unit
  3187. number := goodNameM["number"].(string)
  3188. good.Number = number
  3189. register_number := goodNameM["register_number"].(string)
  3190. good.RegisterNumber = register_number
  3191. goods = append(goods, &good)
  3192. }
  3193. export_time := time.Now().Unix()
  3194. errLogs, _ := service.FindPatientExportLogTwo(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3195. if len(goods) > 0 {
  3196. for _, item := range goods {
  3197. hans := item.GoodName // 要转换的汉字字符串
  3198. // 创建一个拼音转换器
  3199. p := pinyin.NewArgs()
  3200. // 将汉字转为拼音
  3201. pinyinSlice := pinyin.Pinyin(hans, p)
  3202. // 输出拼音
  3203. fmt.Println("Pinyin:", pinyinSlice)
  3204. // 获取首字母
  3205. firstLetter := ""
  3206. for _, py := range pinyinSlice {
  3207. if len(py) > 0 {
  3208. firstLetter += string(py[0][0])
  3209. }
  3210. }
  3211. item.FirstLetter = firstLetter
  3212. goodInfo := models.GoodInfo{
  3213. GoodName: item.GoodName,
  3214. SpecificationName: item.SpecificationName,
  3215. GoodKind: item.GoodKind,
  3216. GoodTypeId: item.GoodTypeId,
  3217. Dealer: item.Dealer,
  3218. GoodUnit: item.GoodUnit,
  3219. IsRecord: item.IsRecord,
  3220. IsSpecialDiseases: item.IsSpecialDiseases,
  3221. Manufacturer: item.Manufacturer,
  3222. Pinyin: item.Pinyin,
  3223. GoodStatus: item.GoodStatus,
  3224. ProductionType: item.ProductionType,
  3225. Remark: item.Remark,
  3226. RetailPrice: item.RetailPrice,
  3227. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3228. SpecialMedical: item.SpecialMedical,
  3229. Wubi: item.Wubi,
  3230. StockWarnCount: item.StockWarnCount,
  3231. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  3232. OrgId: orgId,
  3233. Status: 1,
  3234. Ctime: time.Now().Unix(),
  3235. StatisticsCategory: item.StatisticsCategory,
  3236. GoodCode: item.GoodCode,
  3237. BuyPrice: item.BuyPrice,
  3238. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  3239. IsUser: 2,
  3240. PackingUnit: item.PackingUnit,
  3241. PackingPrice: item.RetailPrice,
  3242. IsWarehouse: 1,
  3243. DefaultCount: item.DefaultCount,
  3244. DefaultCountUnit: item.DefaultCountUnit,
  3245. FirstLetter: item.FirstLetter,
  3246. RegisterNumber: item.RegisterNumber,
  3247. Number: item.Number,
  3248. }
  3249. //查询同种耗材名称同种类型同种规格的耗材是否存在
  3250. _, errcodegood := service.GetGoodsInformaitonIsExist(item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  3251. if errcodegood == gorm.ErrRecordNotFound {
  3252. service.CreateGoodsInfomation(&goodInfo)
  3253. } else if errcodegood == nil {
  3254. service.UpdateGoodsInformation(&goodInfo, item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  3255. }
  3256. log := models.ExportLog{
  3257. LogType: 5,
  3258. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3259. TotalNum: int64(len(total_goods)),
  3260. FailNum: int64(len(errLogs)),
  3261. SuccessNum: int64(len(goods)),
  3262. CreateTime: time.Now().Unix(),
  3263. UpdateTime: time.Now().Unix(),
  3264. ExportTime: export_time,
  3265. Status: 1,
  3266. }
  3267. service.CreateExportLog(&log)
  3268. this.ServeSuccessJSON(map[string]interface{}{
  3269. "msg": "导入成功",
  3270. "total_num": len(total_goods),
  3271. "success_num": len(goods),
  3272. "fail_num": int64(len(errLogs)),
  3273. })
  3274. }
  3275. } else {
  3276. log := models.ExportLog{
  3277. LogType: 5,
  3278. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3279. TotalNum: int64(len(total_goods)),
  3280. FailNum: int64(len(errLogs)),
  3281. SuccessNum: int64(len(goods)),
  3282. CreateTime: time.Now().Unix(),
  3283. UpdateTime: time.Now().Unix(),
  3284. ExportTime: export_time,
  3285. Status: 1,
  3286. }
  3287. service.CreateExportLog(&log)
  3288. this.ServeSuccessJSON(map[string]interface{}{
  3289. "msg": "导入成功",
  3290. "total_num": len(total_goods),
  3291. "success_num": len(goods),
  3292. "fail_num": int64(len(errLogs)),
  3293. })
  3294. }
  3295. }
  3296. func (this *StockManagerApiController) AddDrugInformation() {
  3297. adminUser := this.GetAdminUserInfo()
  3298. orgId := adminUser.CurrentOrgId
  3299. dataBody := make(map[string]interface{}, 0)
  3300. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  3301. if err != nil {
  3302. utils.ErrorLog(err.Error())
  3303. return
  3304. }
  3305. utils.ErrorLog("%v", dataBody)
  3306. var drugList []*models.BaseDrugLib
  3307. var total_goods []interface{}
  3308. tempDrugs := dataBody["drugs"].([]interface{})
  3309. total_goods = tempDrugs
  3310. for index, drugMap := range tempDrugs {
  3311. goodNameM := drugMap.(map[string]interface{})
  3312. var drug models.BaseDrugLib
  3313. if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
  3314. utils.ErrorLog("drug_name")
  3315. return
  3316. }
  3317. drug_name, _ := goodNameM["drug_name"].(string)
  3318. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  3319. err_log := models.ExportErrLog{
  3320. LogType: 4,
  3321. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3322. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
  3323. Status: 1,
  3324. CreateTime: time.Now().Unix(),
  3325. UpdateTime: time.Now().Unix(),
  3326. ExportTime: time.Now().Unix(),
  3327. }
  3328. service.CreateExportErrLog(&err_log)
  3329. continue
  3330. }
  3331. drug.DrugName = drug_name
  3332. dose_unit := goodNameM["dose_unit"].(string)
  3333. drug.DoseUnit = dose_unit
  3334. if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
  3335. utils.ErrorLog("min_number")
  3336. return
  3337. }
  3338. min_number, _ := goodNameM["min_number"].(string)
  3339. minNumber, _ := strconv.ParseInt(min_number, 10, 64)
  3340. if len(min_number) == 0 { //名字为空则生成一条导入错误日志
  3341. err_log := models.ExportErrLog{
  3342. LogType: 4,
  3343. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3344. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
  3345. Status: 1,
  3346. CreateTime: time.Now().Unix(),
  3347. UpdateTime: time.Now().Unix(),
  3348. ExportTime: time.Now().Unix(),
  3349. }
  3350. service.CreateExportErrLog(&err_log)
  3351. continue
  3352. }
  3353. drug.MinNumber = minNumber
  3354. min_unit := goodNameM["min_unit"].(string)
  3355. if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
  3356. err_log := models.ExportErrLog{
  3357. LogType: 4,
  3358. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3359. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
  3360. Status: 1,
  3361. CreateTime: time.Now().Unix(),
  3362. UpdateTime: time.Now().Unix(),
  3363. ExportTime: time.Now().Unix(),
  3364. }
  3365. service.CreateExportErrLog(&err_log)
  3366. continue
  3367. }
  3368. drug.MinUnit = min_unit
  3369. max_unit_id := goodNameM["max_unit"].(string)
  3370. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  3371. err_log := models.ExportErrLog{
  3372. LogType: 4,
  3373. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3374. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  3375. Status: 1,
  3376. CreateTime: time.Now().Unix(),
  3377. UpdateTime: time.Now().Unix(),
  3378. ExportTime: time.Now().Unix(),
  3379. }
  3380. service.CreateExportErrLog(&err_log)
  3381. continue
  3382. }
  3383. drug.MaxUnit = max_unit_id
  3384. max_unit := goodNameM["max_unit"].(string)
  3385. if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
  3386. err_log := models.ExportErrLog{
  3387. LogType: 4,
  3388. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3389. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
  3390. Status: 1,
  3391. CreateTime: time.Now().Unix(),
  3392. UpdateTime: time.Now().Unix(),
  3393. ExportTime: time.Now().Unix(),
  3394. }
  3395. service.CreateExportErrLog(&err_log)
  3396. continue
  3397. }
  3398. drug.MaxUnit = max_unit
  3399. drug_type := goodNameM["drug_type"].(string)
  3400. if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
  3401. err_log := models.ExportErrLog{
  3402. LogType: 4,
  3403. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3404. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
  3405. Status: 1,
  3406. CreateTime: time.Now().Unix(),
  3407. UpdateTime: time.Now().Unix(),
  3408. ExportTime: time.Now().Unix(),
  3409. }
  3410. service.CreateExportErrLog(&err_log)
  3411. continue
  3412. }
  3413. var drug_type_id int64
  3414. var drugType = "药品类型"
  3415. drugconfig, _ := service.GetDrugDataConfig(0, drugType)
  3416. if len(drug_type) != 0 {
  3417. _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
  3418. if errcodes == gorm.ErrRecordNotFound {
  3419. //获取该型号最后一条数据型号
  3420. config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
  3421. dataconfig := models.DictDataconfig{
  3422. ParentId: drugconfig.ID,
  3423. Module: "system",
  3424. OrgId: orgId,
  3425. Name: drug_type,
  3426. FieldName: "",
  3427. Value: config.Value + 1,
  3428. CreatedTime: "",
  3429. UpdatedTime: "",
  3430. CreateUserId: adminUser.AdminUser.Id,
  3431. Status: 1,
  3432. Remark: "",
  3433. DeleteIdSystem: 0,
  3434. Title: "",
  3435. Content: "",
  3436. Order: 0,
  3437. Code: "",
  3438. }
  3439. service.CreatedDicConfig(&dataconfig)
  3440. }
  3441. }
  3442. drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
  3443. for _, it := range drugTypeList {
  3444. if drug_type == it.Name {
  3445. drug_type_id = int64(it.Value)
  3446. }
  3447. }
  3448. drug.DrugType = drug_type_id
  3449. drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
  3450. if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
  3451. err_log := models.ExportErrLog{
  3452. LogType: 4,
  3453. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3454. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
  3455. Status: 1,
  3456. CreateTime: time.Now().Unix(),
  3457. UpdateTime: time.Now().Unix(),
  3458. ExportTime: time.Now().Unix(),
  3459. }
  3460. service.CreateExportErrLog(&err_log)
  3461. continue
  3462. }
  3463. drug.DrugStockLimit = drug_stock_limit
  3464. drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
  3465. if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
  3466. err_log := models.ExportErrLog{
  3467. LogType: 4,
  3468. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3469. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
  3470. Status: 1,
  3471. CreateTime: time.Now().Unix(),
  3472. UpdateTime: time.Now().Unix(),
  3473. ExportTime: time.Now().Unix(),
  3474. }
  3475. service.CreateExportErrLog(&err_log)
  3476. continue
  3477. }
  3478. drug.DrugOriginPlace = drug_origin_place
  3479. drug_dosage_form := goodNameM["drug_dosage_form"].(string)
  3480. if len(drug_dosage_form) == 0 {
  3481. err_log := models.ExportErrLog{
  3482. LogType: 4,
  3483. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3484. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
  3485. Status: 1,
  3486. CreateTime: time.Now().Unix(),
  3487. UpdateTime: time.Now().Unix(),
  3488. ExportTime: time.Now().Unix(),
  3489. }
  3490. service.CreateExportErrLog(&err_log)
  3491. continue
  3492. }
  3493. var drug_dosage = "药品剂型"
  3494. var drug_dosage_form_id int64
  3495. drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
  3496. if len(drug_dosage_form) != 0 {
  3497. _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
  3498. if errcodess == gorm.ErrRecordNotFound {
  3499. configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
  3500. dataconfig := models.DictDataconfig{
  3501. ParentId: drugDosageconfig.ID,
  3502. Module: "system",
  3503. OrgId: orgId,
  3504. Name: drug_dosage_form,
  3505. FieldName: "",
  3506. Value: configOne.Value + 1,
  3507. CreatedTime: "",
  3508. UpdatedTime: "",
  3509. CreateUserId: adminUser.AdminUser.Id,
  3510. Status: 1,
  3511. Remark: "",
  3512. DeleteIdSystem: 0,
  3513. Title: "",
  3514. Content: "",
  3515. Order: 0,
  3516. Code: "",
  3517. }
  3518. service.CreatedDicConfig(&dataconfig)
  3519. }
  3520. }
  3521. drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
  3522. for _, it := range drugDosageList {
  3523. if drug_dosage_form == it.Name {
  3524. drug_dosage_form_id = int64(it.Value)
  3525. }
  3526. }
  3527. drug.DrugDosageForm = drug_dosage_form_id
  3528. retail_prices := goodNameM["retail_price"].(string)
  3529. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  3530. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  3531. err_log := models.ExportErrLog{
  3532. LogType: 4,
  3533. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3534. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
  3535. Status: 1,
  3536. CreateTime: time.Now().Unix(),
  3537. UpdateTime: time.Now().Unix(),
  3538. ExportTime: time.Now().Unix(),
  3539. }
  3540. service.CreateExportErrLog(&err_log)
  3541. continue
  3542. }
  3543. drug.RetailPrice = retail_price
  3544. last_prices := goodNameM["last_price"].(string)
  3545. last_price, _ := strconv.ParseFloat(last_prices, 64)
  3546. if last_price <= 0 { //名字为空则生成一条导入错误日志
  3547. err_log := models.ExportErrLog{
  3548. LogType: 4,
  3549. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3550. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
  3551. Status: 1,
  3552. CreateTime: time.Now().Unix(),
  3553. UpdateTime: time.Now().Unix(),
  3554. ExportTime: time.Now().Unix(),
  3555. }
  3556. service.CreateExportErrLog(&err_log)
  3557. continue
  3558. }
  3559. drug.LastPrice = last_price
  3560. drug_classify := goodNameM["drug_classify"].(string)
  3561. if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
  3562. err_log := models.ExportErrLog{
  3563. LogType: 4,
  3564. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3565. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
  3566. Status: 1,
  3567. CreateTime: time.Now().Unix(),
  3568. UpdateTime: time.Now().Unix(),
  3569. ExportTime: time.Now().Unix(),
  3570. }
  3571. service.CreateExportErrLog(&err_log)
  3572. continue
  3573. }
  3574. var drugClassify = "药物分类"
  3575. var drug_classify_id int64
  3576. drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
  3577. if len(drug_classify) != 0 {
  3578. _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
  3579. if errcodesClass == gorm.ErrRecordNotFound {
  3580. drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
  3581. dataconfig := models.DictDataconfig{
  3582. ParentId: drugClassifyConfig.ID,
  3583. Module: "system",
  3584. OrgId: orgId,
  3585. Name: drug_classify,
  3586. FieldName: "",
  3587. Value: drugClassConfig.Value + 1,
  3588. CreatedTime: "",
  3589. UpdatedTime: "",
  3590. CreateUserId: adminUser.AdminUser.Id,
  3591. Status: 1,
  3592. Remark: "",
  3593. DeleteIdSystem: 0,
  3594. Title: "",
  3595. Content: "",
  3596. Order: 0,
  3597. Code: "",
  3598. }
  3599. service.CreatedDicConfig(&dataconfig)
  3600. }
  3601. }
  3602. drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
  3603. for _, it := range drugClassList {
  3604. if drug_classify == it.Name {
  3605. drug_classify_id = int64(it.Value)
  3606. }
  3607. }
  3608. drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
  3609. drug_dose := goodNameM["drug_dose"].(string)
  3610. if len(drug_dose) == 0 {
  3611. err_log := models.ExportErrLog{
  3612. LogType: 4,
  3613. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3614. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
  3615. Status: 1,
  3616. CreateTime: time.Now().Unix(),
  3617. UpdateTime: time.Now().Unix(),
  3618. ExportTime: time.Now().Unix(),
  3619. }
  3620. service.CreateExportErrLog(&err_log)
  3621. continue
  3622. }
  3623. drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
  3624. drug.DrugDose = drugDoses
  3625. var units = "单位"
  3626. var unit_id int64
  3627. drugDoseUnit := goodNameM["drug_dose_unit"].(string)
  3628. if len(drugDoseUnit) == 0 {
  3629. err_log := models.ExportErrLog{
  3630. LogType: 4,
  3631. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3632. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
  3633. Status: 1,
  3634. CreateTime: time.Now().Unix(),
  3635. UpdateTime: time.Now().Unix(),
  3636. ExportTime: time.Now().Unix(),
  3637. }
  3638. service.CreateExportErrLog(&err_log)
  3639. continue
  3640. }
  3641. dataConfig, _ := service.GetDataConfigIsExist(0, units)
  3642. if len(drugDoseUnit) != 0 {
  3643. _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
  3644. if errcodedataconfig == gorm.ErrRecordNotFound {
  3645. childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
  3646. dataconfig := models.Dataconfig{
  3647. ParentId: dataConfig.ID,
  3648. Module: "hemodialysis",
  3649. OrgId: orgId,
  3650. Name: drugDoseUnit,
  3651. FieldName: "",
  3652. Value: childConfig.Value + 1,
  3653. CreatedTime: "",
  3654. UpdatedTime: "",
  3655. CreateUserId: adminUser.AdminUser.Id,
  3656. Status: 1,
  3657. Remark: "",
  3658. DeleteIdSystem: 0,
  3659. Title: "",
  3660. Content: "",
  3661. Order: 0,
  3662. Code: "",
  3663. FieldType: 0,
  3664. }
  3665. service.CreateDataConfig(&dataconfig)
  3666. }
  3667. }
  3668. list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
  3669. for _, it := range list {
  3670. if drugDoseUnit == it.Name {
  3671. unit_id = int64(it.Value)
  3672. }
  3673. }
  3674. drug.DrugDoseUnit = unit_id
  3675. manufacturer := goodNameM["manufacturer"].(string)
  3676. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  3677. err_log := models.ExportErrLog{
  3678. LogType: 4,
  3679. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3680. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
  3681. Status: 1,
  3682. CreateTime: time.Now().Unix(),
  3683. UpdateTime: time.Now().Unix(),
  3684. ExportTime: time.Now().Unix(),
  3685. }
  3686. service.CreateExportErrLog(&err_log)
  3687. continue
  3688. }
  3689. if len(manufacturer) != 0 {
  3690. _, errcodema := service.GetManufacturerName(orgId, manufacturer)
  3691. if errcodema == gorm.ErrRecordNotFound {
  3692. manufactur := models.Manufacturer{
  3693. OrgId: orgId,
  3694. Status: 1,
  3695. ManufacturerName: manufacturer,
  3696. Ctime: time.Now().Unix(),
  3697. Creater: adminUser.AdminUser.Id,
  3698. }
  3699. service.CreateManufacturer(&manufactur)
  3700. }
  3701. }
  3702. var manufacturer_id int64
  3703. manufacturList, _ := service.GetAllManufacturerList(orgId)
  3704. for _, it := range manufacturList {
  3705. if manufacturer == it.ManufacturerName {
  3706. manufacturer_id = it.ID
  3707. }
  3708. }
  3709. drug.Manufacturer = manufacturer_id
  3710. dealer := goodNameM["dealer"].(string)
  3711. if len(dealer) != 0 {
  3712. _, errcodesdealer := service.GetDealerByName(orgId, dealer)
  3713. if errcodesdealer == gorm.ErrRecordNotFound {
  3714. dealerconfig := models.Dealer{
  3715. DealerName: dealer,
  3716. Status: 1,
  3717. OrgId: orgId,
  3718. Ctime: time.Now().Unix(),
  3719. Creater: adminUser.AdminUser.Id,
  3720. }
  3721. service.CreateDealer(&dealerconfig)
  3722. }
  3723. }
  3724. var dealer_id int64
  3725. dealerList, _ := service.GetAllDealerList(orgId)
  3726. for _, it := range dealerList {
  3727. if dealer == it.DealerName {
  3728. dealer_id = it.ID
  3729. }
  3730. }
  3731. drug.Dealer = dealer_id
  3732. delivery_way := goodNameM["delivery_way"].(string)
  3733. if len(delivery_way) == 0 {
  3734. err_log := models.ExportErrLog{
  3735. LogType: 4,
  3736. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3737. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认给药途径不能为空",
  3738. Status: 1,
  3739. CreateTime: time.Now().Unix(),
  3740. UpdateTime: time.Now().Unix(),
  3741. ExportTime: time.Now().Unix(),
  3742. }
  3743. service.CreateExportErrLog(&err_log)
  3744. continue
  3745. }
  3746. drug.DeliveryWay = delivery_way
  3747. execution_frequency := goodNameM["execution_frequency"].(string)
  3748. if len(execution_frequency) == 0 {
  3749. err_log := models.ExportErrLog{
  3750. LogType: 4,
  3751. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3752. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  3753. Status: 1,
  3754. CreateTime: time.Now().Unix(),
  3755. UpdateTime: time.Now().Unix(),
  3756. ExportTime: time.Now().Unix(),
  3757. }
  3758. service.CreateExportErrLog(&err_log)
  3759. continue
  3760. }
  3761. drug.ExecutionFrequency = execution_frequency
  3762. prescribing_number := goodNameM["prescribing_number"].(float64)
  3763. if prescribing_number == 0 {
  3764. err_log := models.ExportErrLog{
  3765. LogType: 4,
  3766. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3767. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认开药数量不能为空",
  3768. Status: 1,
  3769. CreateTime: time.Now().Unix(),
  3770. UpdateTime: time.Now().Unix(),
  3771. ExportTime: time.Now().Unix(),
  3772. }
  3773. service.CreateExportErrLog(&err_log)
  3774. continue
  3775. }
  3776. drug.PrescribingNumber = prescribing_number
  3777. prescribing_number_unit := goodNameM["prescribing_number_unit"].(string)
  3778. if len(prescribing_number_unit) == 0 {
  3779. err_log := models.ExportErrLog{
  3780. LogType: 4,
  3781. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3782. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认开药数量单位不能为空",
  3783. Status: 1,
  3784. CreateTime: time.Now().Unix(),
  3785. UpdateTime: time.Now().Unix(),
  3786. ExportTime: time.Now().Unix(),
  3787. }
  3788. service.CreateExportErrLog(&err_log)
  3789. continue
  3790. }
  3791. drug.PrescribingNumberUnit = prescribing_number_unit
  3792. drug_day := goodNameM["drug_day"].(string)
  3793. if len(drug_day) == 0 {
  3794. err_log := models.ExportErrLog{
  3795. LogType: 4,
  3796. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3797. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的天数不能为空",
  3798. Status: 1,
  3799. CreateTime: time.Now().Unix(),
  3800. UpdateTime: time.Now().Unix(),
  3801. ExportTime: time.Now().Unix(),
  3802. }
  3803. service.CreateExportErrLog(&err_log)
  3804. continue
  3805. }
  3806. drug.DrugDay = drug_day
  3807. lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
  3808. drug.LmtUsedFlag = lmt_used_flags
  3809. if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
  3810. utils.ErrorLog("drug_alias")
  3811. return
  3812. }
  3813. drug_alias, _ := goodNameM["drug_alias"].(string)
  3814. drug.DrugAlias = drug_alias
  3815. drug_category := goodNameM["drug_category"].(string)
  3816. var drugCategory = "药品类别"
  3817. var drug_category_id int64
  3818. drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
  3819. if len(drug_category) != 0 {
  3820. _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
  3821. if drugcategoryerrcodes == gorm.ErrRecordNotFound {
  3822. drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
  3823. dataconfig := models.DictDataconfig{
  3824. ParentId: drugCategoryConfig.ID,
  3825. Module: "system",
  3826. OrgId: orgId,
  3827. Name: drug_category,
  3828. FieldName: "",
  3829. Value: drugCategoryConfigSix.Value + 1,
  3830. CreatedTime: "",
  3831. UpdatedTime: "",
  3832. CreateUserId: adminUser.AdminUser.Id,
  3833. Status: 1,
  3834. Remark: "",
  3835. DeleteIdSystem: 0,
  3836. Title: "",
  3837. Content: "",
  3838. Order: 0,
  3839. Code: "",
  3840. }
  3841. service.CreatedDicConfig(&dataconfig)
  3842. }
  3843. }
  3844. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
  3845. for _, it := range drugCategoryList {
  3846. if drug_category == it.Name {
  3847. drug_category_id = int64(it.Value)
  3848. }
  3849. }
  3850. drug.DrugCategory = drug_category_id
  3851. statistics_category := goodNameM["statistics_category"].(string)
  3852. var statisticsCategory = "统计分类"
  3853. var statistics_category_id int64
  3854. statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3855. if len(statistics_category) != 0 {
  3856. _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
  3857. if errcodestatistc == gorm.ErrRecordNotFound {
  3858. staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
  3859. dataconfig := models.DictDataconfig{
  3860. ParentId: statistcConfig.ID,
  3861. Module: "system",
  3862. OrgId: orgId,
  3863. Name: statistics_category,
  3864. FieldName: "",
  3865. Value: staConfig.Value + 1,
  3866. CreatedTime: "",
  3867. UpdatedTime: "",
  3868. CreateUserId: adminUser.AdminUser.Id,
  3869. Status: 1,
  3870. Remark: "",
  3871. DeleteIdSystem: 0,
  3872. Title: "",
  3873. Content: "",
  3874. Order: 0,
  3875. Code: "",
  3876. }
  3877. service.CreatedDicConfig(&dataconfig)
  3878. }
  3879. }
  3880. statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
  3881. for _, it := range statisticsCategoryList {
  3882. if statistics_category == it.Name {
  3883. statistics_category_id = int64(it.Value)
  3884. }
  3885. }
  3886. drug.StatisticsCategory = statistics_category_id
  3887. hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
  3888. drug.HospApprFlag = hosp_appr_flag
  3889. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  3890. drug.MedicalInsuranceNumber = medical_insurance_number
  3891. pharmacology_category := goodNameM["pharmacology_category"].(string)
  3892. var pharmacology = "药理分类"
  3893. var pharmacology_category_id int64
  3894. pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
  3895. if len(pharmacology_category) != 0 {
  3896. _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
  3897. if errcodespharmacology == gorm.ErrRecordNotFound {
  3898. dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
  3899. dataconfig := models.DictDataconfig{
  3900. ParentId: pharmacologyConfig.ID,
  3901. Module: "system",
  3902. OrgId: orgId,
  3903. Name: pharmacology_category,
  3904. FieldName: "",
  3905. Value: dicConfig.Value + 1,
  3906. CreatedTime: "",
  3907. UpdatedTime: "",
  3908. CreateUserId: adminUser.AdminUser.Id,
  3909. Status: 1,
  3910. Remark: "",
  3911. DeleteIdSystem: 0,
  3912. Title: "",
  3913. Content: "",
  3914. Order: 0,
  3915. Code: "",
  3916. }
  3917. service.CreatedDicConfig(&dataconfig)
  3918. }
  3919. }
  3920. pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
  3921. for _, it := range pharmacologyList {
  3922. if pharmacology_category == it.Name {
  3923. pharmacology_category_id = int64(it.Value)
  3924. }
  3925. }
  3926. drug.PharmacologyCategory = pharmacology_category_id
  3927. code := goodNameM["code"].(string)
  3928. drug.Code = code
  3929. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  3930. drug.IsSpecialDiseases = is_special_diseases
  3931. is_record := int64(goodNameM["is_record"].(float64))
  3932. drug.IsRecord = is_record
  3933. prescription_mark := int64(goodNameM["prescription_mark"].(float64))
  3934. drug.PrescriptionMark = prescription_mark
  3935. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  3936. drug.SocialSecurityDirectoryCode = social_security_directory_code
  3937. record_date := goodNameM["record_date"].(string)
  3938. timeLayout := "2006-01-02"
  3939. loc, _ := time.LoadLocation("Local")
  3940. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3941. drug.RecordDate = theTime.Unix()
  3942. drug_remark := goodNameM["drug_remark"].(string)
  3943. drug.DrugRemark = drug_remark
  3944. drug_status := goodNameM["drug_status"].(string)
  3945. drug.DrugStatus = drug_status
  3946. limit_remark := goodNameM["limit_remark"].(string)
  3947. drug.LimitRemark = limit_remark
  3948. min_prices := goodNameM["min_price"].(string)
  3949. min_price, _ := strconv.ParseFloat(min_prices, 64)
  3950. drug.MinPrice = min_price
  3951. dose := goodNameM["dose"].(string)
  3952. //is_self_drug := int64(goodNameM["is_self_drug"].(float64))
  3953. //
  3954. //drug.IsSelfDrug = is_self_drug
  3955. if len(dose) < 0 { //名字为空则生成一条导入错误日志
  3956. err_log := models.ExportErrLog{
  3957. LogType: 4,
  3958. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3959. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  3960. Status: 1,
  3961. CreateTime: time.Now().Unix(),
  3962. UpdateTime: time.Now().Unix(),
  3963. ExportTime: time.Now().Unix(),
  3964. }
  3965. service.CreateExportErrLog(&err_log)
  3966. continue
  3967. }
  3968. drug.Dose = dose
  3969. if len(dose) < 0 { //名字为空则生成一条导入错误日志
  3970. err_log := models.ExportErrLog{
  3971. LogType: 4,
  3972. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3973. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  3974. Status: 1,
  3975. CreateTime: time.Now().Unix(),
  3976. UpdateTime: time.Now().Unix(),
  3977. ExportTime: time.Now().Unix(),
  3978. }
  3979. service.CreateExportErrLog(&err_log)
  3980. continue
  3981. }
  3982. drugList = append(drugList, &drug)
  3983. }
  3984. export_time := time.Now().Unix()
  3985. errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3986. if len(drugList) > 0 {
  3987. for _, item := range drugList {
  3988. hans := item.DrugName // 要转换的汉字字符串
  3989. // 创建一个拼音转换器
  3990. p := pinyin.NewArgs()
  3991. // 将汉字转为拼音
  3992. pinyinSlice := pinyin.Pinyin(hans, p)
  3993. // 输出拼音
  3994. fmt.Println("Pinyin:", pinyinSlice)
  3995. // 获取首字母
  3996. firstLetter := ""
  3997. for _, py := range pinyinSlice {
  3998. if len(py) > 0 {
  3999. firstLetter += string(py[0][0])
  4000. }
  4001. }
  4002. item.FirstLetter = firstLetter
  4003. item.Pinyin = firstLetter
  4004. goodInfo := models.BaseDrugLib{
  4005. DrugName: item.DrugName,
  4006. DrugAlias: item.DrugAlias,
  4007. DrugSpec: item.DrugSpec,
  4008. DrugType: item.DrugType,
  4009. DrugStockLimit: item.DrugStockLimit,
  4010. DrugOriginPlace: item.DrugOriginPlace,
  4011. DrugDosageForm: item.DrugDosageForm,
  4012. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  4013. MaxUnit: item.MaxUnit,
  4014. MinUnit: item.MinUnit,
  4015. UnitMatrixing: item.UnitMatrixing,
  4016. RetailPrice: item.RetailPrice,
  4017. LastPrice: item.LastPrice,
  4018. DrugClassify: item.DrugClassify,
  4019. Manufacturer: item.Manufacturer,
  4020. Dealer: item.Dealer,
  4021. OrgId: orgId,
  4022. Status: 1,
  4023. Ctime: time.Now().Unix(),
  4024. Pinyin: item.Pinyin,
  4025. Wubi: item.Wubi,
  4026. DrugAliasPinyin: item.DrugAliasPinyin,
  4027. DrugAliasWubi: item.DrugAliasWubi,
  4028. DrugControl: item.DrugControl,
  4029. Number: item.Number,
  4030. HospApprFlag: item.HospApprFlag,
  4031. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  4032. PharmacologyCategory: item.PharmacologyCategory,
  4033. StatisticsCategory: item.StatisticsCategory,
  4034. Code: item.Code,
  4035. IsSpecialDiseases: item.IsSpecialDiseases,
  4036. IsRecord: item.IsRecord,
  4037. PrescriptionMark: item.PrescriptionMark,
  4038. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  4039. RecordDate: item.RecordDate,
  4040. DrugRemark: item.DrugRemark,
  4041. DrugStatus: item.DrugStatus,
  4042. LimitRemark: item.LimitRemark,
  4043. DrugCategory: item.DrugCategory,
  4044. DrugDose: item.DrugDose,
  4045. SingleDose: item.DrugDose,
  4046. DrugDoseUnit: item.DrugDoseUnit,
  4047. LmtUsedFlag: item.LmtUsedFlag,
  4048. DrugDay: item.DrugDay,
  4049. DeliveryWay: item.DeliveryWay,
  4050. ExecutionFrequency: item.ExecutionFrequency,
  4051. DoseUnit: item.DoseUnit,
  4052. Dose: item.Dose,
  4053. MinNumber: item.MinNumber,
  4054. IsUse: 2,
  4055. MinPrice: item.MinPrice,
  4056. PrescribingNumber: item.PrescribingNumber,
  4057. PrescribingNumberUnit: item.PrescribingNumberUnit,
  4058. FirstLetter: item.FirstLetter,
  4059. IsSelfDrug: item.IsSelfDrug,
  4060. }
  4061. //查询同种药品同种规格是否存在
  4062. _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.DoseUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
  4063. if drugerror == gorm.ErrRecordNotFound {
  4064. service.CreateDrugsInfomation(&goodInfo)
  4065. } else if drugerror == nil {
  4066. service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
  4067. }
  4068. log := models.ExportLog{
  4069. LogType: 4,
  4070. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4071. TotalNum: int64(len(total_goods)),
  4072. FailNum: int64(len(errLogs)),
  4073. SuccessNum: int64(len(drugList)),
  4074. CreateTime: time.Now().Unix(),
  4075. UpdateTime: time.Now().Unix(),
  4076. ExportTime: export_time,
  4077. Status: 1,
  4078. }
  4079. service.CreateExportLog(&log)
  4080. this.ServeSuccessJSON(map[string]interface{}{
  4081. "msg": "导入成功",
  4082. "total_num": len(total_goods),
  4083. "success_num": len(drugList),
  4084. "fail_num": int64(len(errLogs)),
  4085. })
  4086. }
  4087. } else {
  4088. log := models.ExportLog{
  4089. LogType: 4,
  4090. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4091. TotalNum: int64(len(total_goods)),
  4092. FailNum: int64(len(errLogs)),
  4093. SuccessNum: int64(len(drugList)),
  4094. CreateTime: time.Now().Unix(),
  4095. UpdateTime: time.Now().Unix(),
  4096. ExportTime: export_time,
  4097. Status: 1,
  4098. }
  4099. service.CreateExportLog(&log)
  4100. this.ServeSuccessJSON(map[string]interface{}{
  4101. "msg": "导入成功",
  4102. "total_num": len(total_goods),
  4103. "success_num": len(drugList),
  4104. "fail_num": int64(len(errLogs)),
  4105. })
  4106. }
  4107. }
  4108. func (this *StockManagerApiController) GetInitializtion() {
  4109. orgId := this.GetAdminUserInfo().CurrentOrgId
  4110. var drugCategory = "药品类别"
  4111. var drugType = "药品类型"
  4112. var drugDosageForm = "药品剂型"
  4113. var medicalInsuranceLevel = "医保等级"
  4114. var drugControl = "开药控制"
  4115. var drugClassify = "药物分类"
  4116. var statisticsCategory = "统计分类"
  4117. var pharmacologyCategory = "药理分类"
  4118. var goodKind = "耗材种类"
  4119. var tubeColor = "试管颜色"
  4120. var costClassify = "费用类别"
  4121. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  4122. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  4123. drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
  4124. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
  4125. drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
  4126. drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
  4127. medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
  4128. medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
  4129. drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
  4130. drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
  4131. drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
  4132. drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
  4133. statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
  4134. statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
  4135. pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
  4136. pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
  4137. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  4138. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
  4139. tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
  4140. tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
  4141. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  4142. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
  4143. this.ServeSuccessJSON(map[string]interface{}{
  4144. "drugCategoryList": drugCategoryList,
  4145. "drugTypeList": drugTypeList,
  4146. "drugDosageFormList": drugDosageFormList,
  4147. "medicalInsuranceLevelList": medicalInsuranceLevelList,
  4148. "drugControlList": drugControlList,
  4149. "drugClassifyList": drugClassifyList,
  4150. "statisticsCategoryList": statisticsCategoryList,
  4151. "pharmacologyCategoryList": pharmacologyCategoryList,
  4152. "goodKindList": goodKindList,
  4153. "tubeColorList": tubeColorList,
  4154. "costClassifyList": costClassifyList,
  4155. })
  4156. }
  4157. func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
  4158. adminUserInfo := this.GetAdminUserInfo()
  4159. orgId := adminUserInfo.CurrentOrgId
  4160. list, _ := service.GetWarehouseOrderInfoList(orgId)
  4161. this.ServeSuccessJSON(map[string]interface{}{
  4162. "list": list,
  4163. })
  4164. }
  4165. func (this *StockManagerApiController) PostSearchGoodList() {
  4166. keyword := this.GetString("keyword")
  4167. adminUserInfo := this.GetAdminUserInfo()
  4168. orgId := adminUserInfo.CurrentOrgId
  4169. storehouse_id, _ := this.GetInt64("storehouse_id")
  4170. list, _ := service.GetSearchGoodListSix(keyword, orgId, storehouse_id)
  4171. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4172. dealerList, _ := service.GetAllDealerList(orgId)
  4173. this.ServeSuccessJSON(map[string]interface{}{
  4174. "list": list,
  4175. "manufacturerList": manufacturerList,
  4176. "dealerList": dealerList,
  4177. })
  4178. }
  4179. func (this *StockManagerApiController) GetAllStockList() {
  4180. page, _ := this.GetInt64("page", -1)
  4181. limit, _ := this.GetInt64("limit", -1)
  4182. start_time := this.GetString("start_time")
  4183. end_time := this.GetString("end_time")
  4184. types, _ := this.GetInt64("type", 0)
  4185. keywords := this.GetString("keywords")
  4186. good_id, _ := this.GetInt64("good_id")
  4187. storehouse_id, _ := this.GetInt64("storehouse_id")
  4188. timeLayout := "2006-01-02"
  4189. loc, _ := time.LoadLocation("Local")
  4190. var startTime int64
  4191. if len(start_time) > 0 {
  4192. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4193. if err != nil {
  4194. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4195. return
  4196. }
  4197. startTime = theTime.Unix()
  4198. }
  4199. var endTime int64
  4200. if len(end_time) > 0 {
  4201. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4202. if err != nil {
  4203. utils.ErrorLog(err.Error())
  4204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4205. return
  4206. }
  4207. endTime = theTime.Unix()
  4208. }
  4209. adminUserInfo := this.GetAdminUserInfo()
  4210. orgId := adminUserInfo.CurrentOrgId
  4211. list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId, good_id, storehouse_id)
  4212. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4213. this.ServeSuccessJSON(map[string]interface{}{
  4214. "list": list,
  4215. "total": total,
  4216. "manufacturerList": manufacturerList,
  4217. })
  4218. }
  4219. func (this *StockManagerApiController) GetStockListById() {
  4220. id, _ := this.GetInt64("id")
  4221. adminUserInfo := this.GetAdminUserInfo()
  4222. orgId := adminUserInfo.CurrentOrgId
  4223. limit, _ := this.GetInt64("limit")
  4224. page, _ := this.GetInt64("page")
  4225. timeLayout := "2006-01-02"
  4226. loc, _ := time.LoadLocation("Local")
  4227. start_time := this.GetString("start_time")
  4228. end_time := this.GetString("end_time")
  4229. start_first_time := this.GetString("start_first_time")
  4230. end_first_time := this.GetString("end_first_time")
  4231. var startTime int64
  4232. if len(start_time) > 0 {
  4233. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4234. if err != nil {
  4235. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4236. return
  4237. }
  4238. startTime = theTime.Unix()
  4239. }
  4240. var endTime int64
  4241. if len(end_time) > 0 {
  4242. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4243. if err != nil {
  4244. utils.ErrorLog(err.Error())
  4245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4246. return
  4247. }
  4248. endTime = theTime.Unix()
  4249. }
  4250. var startFistTime int64
  4251. if len(start_first_time) > 0 {
  4252. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_first_time+" 00:00:00", loc)
  4253. if err != nil {
  4254. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4255. return
  4256. }
  4257. startFistTime = theTime.Unix()
  4258. }
  4259. var endFirstTime int64
  4260. if len(end_first_time) > 0 {
  4261. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_first_time+" 23:59:59", loc)
  4262. if err != nil {
  4263. utils.ErrorLog(err.Error())
  4264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4265. return
  4266. }
  4267. endFirstTime = theTime.Unix()
  4268. }
  4269. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4270. list, total, _ := service.GetStockListById(id, orgId, limit, page, startTime, endTime, startFistTime, endFirstTime)
  4271. houseList, _ := service.GetAllStoreHouseList(orgId)
  4272. good, _ := service.GetGoodInformationByGoodId(id)
  4273. this.ServeSuccessJSON(map[string]interface{}{
  4274. "list": list,
  4275. "total": total,
  4276. "manufacturerList": manufacturerList,
  4277. "houseList": houseList,
  4278. "good": good,
  4279. })
  4280. }
  4281. func (this *StockManagerApiController) GetStockOutList() {
  4282. id, _ := this.GetInt64("id")
  4283. adminUserInfo := this.GetAdminUserInfo()
  4284. orgId := adminUserInfo.CurrentOrgId
  4285. limit, _ := this.GetInt64("limit")
  4286. page, _ := this.GetInt64("page")
  4287. timeLayout := "2006-01-02"
  4288. loc, _ := time.LoadLocation("Local")
  4289. start_time := this.GetString("start_time")
  4290. end_time := this.GetString("end_time")
  4291. is_sys, _ := this.GetInt64("is_sys")
  4292. var startTime int64
  4293. if len(start_time) > 0 {
  4294. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4295. if err != nil {
  4296. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4297. return
  4298. }
  4299. startTime = theTime.Unix()
  4300. }
  4301. var endTime int64
  4302. if len(end_time) > 0 {
  4303. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4304. if err != nil {
  4305. utils.ErrorLog(err.Error())
  4306. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4307. return
  4308. }
  4309. endTime = theTime.Unix()
  4310. }
  4311. outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
  4312. this.ServeSuccessJSON(map[string]interface{}{
  4313. "outList": outList,
  4314. "total": total,
  4315. })
  4316. }
  4317. func (this *StockManagerApiController) GetStockDrugCount() {
  4318. adminUserInfo := this.GetAdminUserInfo()
  4319. orgId := adminUserInfo.CurrentOrgId
  4320. fmt.Println(orgId)
  4321. timeLayout := "2006-01-02"
  4322. loc, _ := time.LoadLocation("Local")
  4323. start_time := this.GetString("start_time")
  4324. end_time := this.GetString("end_time")
  4325. var startTime int64
  4326. if len(start_time) > 0 {
  4327. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4328. if err != nil {
  4329. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4330. return
  4331. }
  4332. startTime = theTime.Unix()
  4333. }
  4334. var endTime int64
  4335. if len(end_time) > 0 {
  4336. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4337. if err != nil {
  4338. utils.ErrorLog(err.Error())
  4339. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4340. return
  4341. }
  4342. endTime = theTime.Unix()
  4343. }
  4344. count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
  4345. outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
  4346. autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
  4347. totalCount, _ := service.GetCancelOutTotalCount(startTime, endTime, orgId)
  4348. this.ServeSuccessJSON(map[string]interface{}{
  4349. "count": count,
  4350. "outList": outList,
  4351. "autoCount": autoCount,
  4352. "totalCount": totalCount,
  4353. })
  4354. }
  4355. func (this *StockManagerApiController) GetOrderDetialByOrderId() {
  4356. ids := this.GetString("id")
  4357. idsArray := strings.Split(ids, ",")
  4358. orgId := this.GetAdminUserInfo().CurrentOrgId
  4359. order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
  4360. list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
  4361. stockFlowListGroup, _ := service.GetOrderDetailStockFlowByStorehouseById(idsArray, orgId)
  4362. stockFlowList, _ := service.GetOrderDetailStockFlow(idsArray, orgId)
  4363. //获取耗材退库数据
  4364. cancelInfolist, _ := service.GetOrderStockFlow(idsArray, orgId)
  4365. this.ServeSuccessJSON(map[string]interface{}{
  4366. "list": list,
  4367. "order": order,
  4368. "stockFlowList": stockFlowList,
  4369. "stockFlowListGroup": stockFlowListGroup,
  4370. "cancelInfolist": cancelInfolist,
  4371. })
  4372. }
  4373. func (this *StockManagerApiController) GetOrderDetailById() {
  4374. id, _ := this.GetInt64("id")
  4375. good_id, _ := this.GetInt64("good_id")
  4376. record_time, _ := this.GetInt64("record_time")
  4377. orgId := this.GetAdminUserInfo().CurrentOrgId
  4378. //自动出库
  4379. userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
  4380. //手动出库
  4381. info, _ := service.GetWarehouseOutInfoById(id, good_id)
  4382. //出库数据
  4383. stockFlowList, err := service.GetStockFlowBatchNumberOne(id, good_id)
  4384. //退库数据
  4385. cancelInfo, err := service.GetStockFlowCancelInfo(id, good_id)
  4386. if err == nil {
  4387. this.ServeSuccessJSON(map[string]interface{}{
  4388. "list": userDetails,
  4389. "total": total,
  4390. "info": info,
  4391. "stockFlowList": stockFlowList,
  4392. "cancelInfo": cancelInfo,
  4393. })
  4394. } else {
  4395. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4396. return
  4397. }
  4398. }
  4399. func (this *StockManagerApiController) GetSingleOutOrderDetail() {
  4400. id, _ := this.GetInt64("id", 0)
  4401. orgId := this.GetAdminUserInfo().CurrentOrgId
  4402. warehouseOutInfo, _ := service.GetOrderDetialByOrderId(id, orgId)
  4403. out, _ := service.GetGoodWarehouseOutById(id, orgId)
  4404. storelist, _ := service.GetAllStoreHouseList(orgId)
  4405. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4406. dealerList, _ := service.GetAllDealerList(orgId)
  4407. goodType, _ := service.GetAllGoodType(orgId)
  4408. appId := this.GetAdminUserInfo().CurrentAppId
  4409. doctorlist, _ := service.GetAllDoctorListSix(orgId, appId)
  4410. patients, _ := service.GetAllpatientTwenty(orgId)
  4411. this.ServeSuccessJSON(map[string]interface{}{
  4412. "list": warehouseOutInfo,
  4413. "dealerList": dealerList,
  4414. "manufacturerList": manufacturerList,
  4415. "goodType": goodType,
  4416. "out": out,
  4417. "storelist": storelist,
  4418. "doctorlist": doctorlist,
  4419. "patients": patients,
  4420. })
  4421. }
  4422. func (this *StockManagerApiController) GetExprotStockList() {
  4423. adminUserInfo := this.GetAdminUserInfo()
  4424. orgId := adminUserInfo.CurrentOrgId
  4425. timeLayout := "2006-01-02"
  4426. loc, _ := time.LoadLocation("Local")
  4427. start_time := this.GetString("start_time")
  4428. end_time := this.GetString("end_time")
  4429. storehouse_id, _ := this.GetInt64("storehouse_id")
  4430. idArray := this.GetString("id")
  4431. ids := strings.Split(idArray, ",")
  4432. var startTime int64
  4433. if len(start_time) > 0 {
  4434. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4435. if err != nil {
  4436. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4437. return
  4438. }
  4439. startTime = theTime.Unix()
  4440. }
  4441. var endTime int64
  4442. if len(end_time) > 0 {
  4443. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4444. if err != nil {
  4445. utils.ErrorLog(err.Error())
  4446. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4447. return
  4448. }
  4449. endTime = theTime.Unix()
  4450. }
  4451. list, _ := service.GetExprotStockListTwenty(orgId, ids, startTime, endTime, storehouse_id)
  4452. this.ServeSuccessJSON(map[string]interface{}{
  4453. "list": list,
  4454. })
  4455. }
  4456. func (this *StockManagerApiController) GetOutExprotList() {
  4457. adminUserInfo := this.GetAdminUserInfo()
  4458. orgId := adminUserInfo.CurrentOrgId
  4459. timeLayout := "2006-01-02"
  4460. loc, _ := time.LoadLocation("Local")
  4461. start_time := this.GetString("start_time")
  4462. end_time := this.GetString("end_time")
  4463. idArray := this.GetString("id")
  4464. ids := strings.Split(idArray, ",")
  4465. var startTime int64
  4466. if len(start_time) > 0 {
  4467. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4468. if err != nil {
  4469. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4470. return
  4471. }
  4472. startTime = theTime.Unix()
  4473. }
  4474. var endTime int64
  4475. if len(end_time) > 0 {
  4476. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4477. if err != nil {
  4478. utils.ErrorLog(err.Error())
  4479. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4480. return
  4481. }
  4482. endTime = theTime.Unix()
  4483. }
  4484. list, _ := service.GetOutExprotList(orgId, ids, startTime, endTime)
  4485. outCount, _ := service.GetOutStockTotalCountOne(startTime, endTime, orgId)
  4486. this.ServeSuccessJSON(map[string]interface{}{
  4487. "list": list,
  4488. "count": outCount,
  4489. })
  4490. }
  4491. func (this *StockManagerApiController) GetSingleCancelOrder() {
  4492. id, _ := this.GetInt64("id")
  4493. adminUserInfo := this.GetAdminUserInfo()
  4494. orgId := adminUserInfo.CurrentOrgId
  4495. order, _ := service.GetSingleCancelOrder(id, orgId)
  4496. this.ServeSuccessJSON(map[string]interface{}{
  4497. "list": order,
  4498. })
  4499. }
  4500. func (this *StockManagerApiController) GetCancelStockOrderPrint() {
  4501. id := this.GetString("id")
  4502. idStr := strings.Split(id, ",")
  4503. orgId := this.GetAdminUserInfo().CurrentOrgId
  4504. list, _ := service.GetCancelStockOrderPrintOne(idStr, orgId)
  4505. this.ServeSuccessJSON(map[string]interface{}{
  4506. "list": list,
  4507. })
  4508. }
  4509. func (this *StockManagerApiController) GetStockBatchNumber() {
  4510. id, _ := this.GetInt64("id")
  4511. storehouse_id, _ := this.GetInt64("storehouse_id")
  4512. orgId := this.GetAdminUserInfo().CurrentOrgId
  4513. list, _ := service.GetStockBatchNumber(id, orgId)
  4514. lastWarehouseInfoTwo, _ := service.GetLastWarehouseInfoTwo(id, storehouse_id, orgId)
  4515. this.ServeSuccessJSON(map[string]interface{}{
  4516. "list": list,
  4517. "lastWarehouseInfoTwo": lastWarehouseInfoTwo,
  4518. })
  4519. }
  4520. func (this *StockManagerApiController) GetStockFlow() {
  4521. limit, _ := this.GetInt64("limit")
  4522. page, _ := this.GetInt64("page")
  4523. good_id, _ := this.GetInt64("good_id")
  4524. consumable_type, _ := this.GetInt64("is_sys")
  4525. adminUserInfo := this.GetAdminUserInfo()
  4526. orgId := adminUserInfo.CurrentOrgId
  4527. timeLayout := "2006-01-02"
  4528. loc, _ := time.LoadLocation("Local")
  4529. start_time := this.GetString("start_time")
  4530. end_time := this.GetString("end_time")
  4531. var startTime int64
  4532. if len(start_time) > 0 {
  4533. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4534. if err != nil {
  4535. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4536. return
  4537. }
  4538. startTime = theTime.Unix()
  4539. }
  4540. var endTime int64
  4541. if len(end_time) > 0 {
  4542. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4543. if err != nil {
  4544. utils.ErrorLog(err.Error())
  4545. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4546. return
  4547. }
  4548. endTime = theTime.Unix()
  4549. }
  4550. list, total, _ := service.GetStockFlowList(limit, page, consumable_type, orgId, startTime, endTime, good_id)
  4551. //if len(list) > 0 {
  4552. // for _, item := range list {
  4553. // hisPrescription, _ := service.GetHidsDoctorAdvice(item.GoodId, orgId, item.PatientId, item.SystemTime)
  4554. // item.GoodCode = hisPrescription.good
  4555. // }
  4556. //}
  4557. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4558. good, _ := service.GetGoodInformationByGoodId(good_id)
  4559. houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  4560. patients, _ := service.GetAllPatientListSix(adminUserInfo.CurrentOrgId)
  4561. this.ServeSuccessJSON(map[string]interface{}{
  4562. "list": list,
  4563. "total": total,
  4564. "manufacturerList": manufacturerList,
  4565. "good": good,
  4566. "houseList": houseList,
  4567. "patients": patients,
  4568. })
  4569. }
  4570. func (this *StockManagerApiController) GetCancelExportList() {
  4571. adminUserInfo := this.GetAdminUserInfo()
  4572. orgId := adminUserInfo.CurrentOrgId
  4573. timeLayout := "2006-01-02"
  4574. loc, _ := time.LoadLocation("Local")
  4575. start_time := this.GetString("start_time")
  4576. end_time := this.GetString("end_time")
  4577. idArray := this.GetString("order_id")
  4578. fmt.Println("232323232323232232", idArray)
  4579. ids := strings.Split(idArray, ",")
  4580. var startTime int64
  4581. if len(start_time) > 0 {
  4582. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4583. if err != nil {
  4584. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4585. return
  4586. }
  4587. startTime = theTime.Unix()
  4588. }
  4589. var endTime int64
  4590. if len(end_time) > 0 {
  4591. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4592. if err != nil {
  4593. utils.ErrorLog(err.Error())
  4594. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4595. return
  4596. }
  4597. endTime = theTime.Unix()
  4598. }
  4599. list, _ := service.GetCancelExportList(startTime, endTime, ids, orgId)
  4600. this.ServeSuccessJSON(map[string]interface{}{
  4601. "list": list,
  4602. })
  4603. }
  4604. func (this *StockManagerApiController) GetSearchGoodWarehouseList() {
  4605. keyword := this.GetString("keyword")
  4606. storehouse_id, _ := this.GetInt64("storehouse_id")
  4607. orgId := this.GetAdminUserInfo().CurrentOrgId
  4608. list, _ := service.GetSearchGoodWarehouseList(keyword, orgId, storehouse_id)
  4609. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4610. dealerList, _ := service.GetAllDealerList(orgId)
  4611. this.ServeSuccessJSON(map[string]interface{}{
  4612. "list": list,
  4613. "manufacturerList": manufacturerList,
  4614. "dealerList": dealerList,
  4615. })
  4616. }
  4617. func (this *StockManagerApiController) SaveAdjuestPrice() {
  4618. timeLayout := "2006-01-02"
  4619. loc, _ := time.LoadLocation("Local")
  4620. dataBody := make(map[string]interface{}, 0)
  4621. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4622. if err != nil {
  4623. utils.ErrorLog(err.Error())
  4624. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4625. return
  4626. }
  4627. tableData, _ := dataBody["tableData"].([]interface{})
  4628. if len(tableData) > 0 {
  4629. for _, item := range tableData {
  4630. items := item.(map[string]interface{})
  4631. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4632. utils.ErrorLog("good_name")
  4633. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4634. return
  4635. }
  4636. good_name := items["good_name"].(string)
  4637. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4638. utils.ErrorLog("good_name")
  4639. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4640. return
  4641. }
  4642. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4643. utils.ErrorLog("packing_price")
  4644. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4645. return
  4646. }
  4647. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4648. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4649. utils.ErrorLog("warehousing_order")
  4650. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4651. return
  4652. }
  4653. warehousing_order := items["warehousing_order"].(string)
  4654. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4655. utils.ErrorLog("license_number")
  4656. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4657. return
  4658. }
  4659. license_number := items["license_number"].(string)
  4660. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4661. utils.ErrorLog("dealer")
  4662. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4663. return
  4664. }
  4665. dealer := items["dealer"].(string)
  4666. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4667. utils.ErrorLog("manufacturer")
  4668. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4669. return
  4670. }
  4671. manufacturer := items["manufacturer"].(string)
  4672. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4673. utils.ErrorLog("specification_name")
  4674. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4675. return
  4676. }
  4677. specification_name := items["specification_name"].(string)
  4678. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4679. utils.ErrorLog("remark")
  4680. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4681. return
  4682. }
  4683. remark := items["remark"].(string)
  4684. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4685. utils.ErrorLog("warehousing_unit")
  4686. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4687. return
  4688. }
  4689. warehousing_unit := items["warehousing_unit"].(string)
  4690. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4691. utils.ErrorLog("buy_price")
  4692. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4693. return
  4694. }
  4695. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4696. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4697. utils.ErrorLog("count")
  4698. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4699. return
  4700. }
  4701. count := int64(items["count"].(float64))
  4702. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  4703. utils.ErrorLog("new_price")
  4704. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4705. return
  4706. }
  4707. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  4708. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4709. utils.ErrorLog("good_id")
  4710. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4711. return
  4712. }
  4713. good_id := int64(items["good_id"].(float64))
  4714. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4715. utils.ErrorLog("start_time")
  4716. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4717. return
  4718. }
  4719. var startTime int64
  4720. start_time := items["start_time"].(string)
  4721. if len(start_time) > 0 {
  4722. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4723. if err != nil {
  4724. fmt.Println(err)
  4725. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4726. return
  4727. }
  4728. startTime = theTime.Unix()
  4729. }
  4730. orgId := this.GetAdminUserInfo().CurrentOrgId
  4731. adjustprice := models.XtStockAdjustPrice{
  4732. GoodName: good_name,
  4733. SpecificationName: specification_name,
  4734. WarehousingUnit: warehousing_unit,
  4735. Count: count,
  4736. BuyPrice: buy_price,
  4737. PackingPrice: packing_price,
  4738. NewPrice: new_price,
  4739. Manufacturer: manufacturer,
  4740. Dealer: dealer,
  4741. Remark: remark,
  4742. GoodId: good_id,
  4743. UserOrgId: orgId,
  4744. Ctime: time.Now().Unix(),
  4745. Mtime: 0,
  4746. Status: 1,
  4747. WarehousingOrder: warehousing_order,
  4748. LicenseNumber: license_number,
  4749. StartTime: startTime,
  4750. Creater: this.GetAdminUserInfo().AdminUser.Id,
  4751. CheckerStatus: 2,
  4752. }
  4753. service.CreateAdjustPrice(&adjustprice)
  4754. }
  4755. }
  4756. this.ServeSuccessJSON(map[string]interface{}{
  4757. "msg": "保存成功!",
  4758. })
  4759. }
  4760. func (this *StockManagerApiController) GetAllStockPrice() {
  4761. timeLayout := "2006-01-02"
  4762. loc, _ := time.LoadLocation("Local")
  4763. dataBody := make(map[string]interface{}, 0)
  4764. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4765. fmt.Println(err)
  4766. orgId := this.GetAdminUserInfo().CurrentOrgId
  4767. keyword := this.GetString("keyword")
  4768. start_time := this.GetString("start_time")
  4769. end_time := this.GetString("end_time")
  4770. limit, _ := this.GetInt64("limit")
  4771. page, _ := this.GetInt64("page")
  4772. var startTime int64
  4773. if len(start_time) > 0 {
  4774. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4775. if err != nil {
  4776. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4777. return
  4778. }
  4779. startTime = theTime.Unix()
  4780. }
  4781. var endTime int64
  4782. if len(end_time) > 0 {
  4783. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4784. if err != nil {
  4785. utils.ErrorLog(err.Error())
  4786. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4787. return
  4788. }
  4789. endTime = theTime.Unix()
  4790. }
  4791. list, total, _ := service.GetAllStockPrice(orgId, startTime, endTime, keyword, limit, page)
  4792. doctor, _ := service.GetAllDoctorThree(orgId)
  4793. this.ServeSuccessJSON(map[string]interface{}{
  4794. "list": list,
  4795. "doctor": doctor,
  4796. "total": total,
  4797. })
  4798. }
  4799. func (this *StockManagerApiController) SaveCheckPrice() {
  4800. timeLayout := "2006-01-02"
  4801. loc, _ := time.LoadLocation("Local")
  4802. dataBody := make(map[string]interface{}, 0)
  4803. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4804. fmt.Println(err)
  4805. idstr := this.GetString("ids")
  4806. ids := strings.Split(idstr, ",")
  4807. check_time := this.GetString("check_time")
  4808. var checkTime int64
  4809. if len(check_time) > 0 {
  4810. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  4811. if err != nil {
  4812. fmt.Println(err)
  4813. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4814. return
  4815. }
  4816. checkTime = theTime.Unix()
  4817. }
  4818. checker, _ := this.GetInt64("checker")
  4819. adjustPrice := models.XtStockAdjustPrice{
  4820. Checker: checker,
  4821. CheckerStatus: 1,
  4822. CheckerTime: checkTime,
  4823. }
  4824. err = service.UpdateAdjustPrice(ids, adjustPrice)
  4825. fmt.Println(err)
  4826. list, _ := service.GetAdjustCheckPriceList(ids)
  4827. fmt.Println("list2333223323232323232323", list)
  4828. for _, item := range list {
  4829. info := models.GoodInfo{
  4830. PackingPrice: item.NewPrice,
  4831. BuyPrice: item.NewPrice,
  4832. }
  4833. err = service.UpdateAdjustCheckPrice(&info, item.GoodId)
  4834. fmt.Println(err)
  4835. }
  4836. this.ServeSuccessJSON(map[string]interface{}{
  4837. "adjustPrice": adjustPrice,
  4838. })
  4839. }
  4840. func (this *StockManagerApiController) GetAdjustPriceById() {
  4841. ids := this.GetString("ids")
  4842. fmt.Println("ids23232233223233232", ids)
  4843. splitIds := strings.Split(ids, ",")
  4844. list, _ := service.GetAdjustPricebyIdOne(splitIds)
  4845. fmt.Println("list2322322323", list)
  4846. this.ServeSuccessJSON(map[string]interface{}{
  4847. "list": list,
  4848. })
  4849. }
  4850. func (this *StockManagerApiController) SaveReportStock() {
  4851. timeLayout := "2006-01-02"
  4852. loc, _ := time.LoadLocation("Local")
  4853. dataBody := make(map[string]interface{}, 0)
  4854. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4855. if err != nil {
  4856. utils.ErrorLog(err.Error())
  4857. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4858. return
  4859. }
  4860. tableData, _ := dataBody["tableData"].([]interface{})
  4861. if len(tableData) > 0 {
  4862. for _, item := range tableData {
  4863. items := item.(map[string]interface{})
  4864. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4865. utils.ErrorLog("good_name")
  4866. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4867. return
  4868. }
  4869. good_name := items["good_name"].(string)
  4870. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4871. utils.ErrorLog("good_name")
  4872. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4873. return
  4874. }
  4875. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4876. utils.ErrorLog("packing_price")
  4877. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4878. return
  4879. }
  4880. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4881. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4882. utils.ErrorLog("warehousing_order")
  4883. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4884. return
  4885. }
  4886. warehousing_order := items["warehousing_order"].(string)
  4887. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4888. utils.ErrorLog("license_number")
  4889. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4890. return
  4891. }
  4892. license_number := items["license_number"].(string)
  4893. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4894. utils.ErrorLog("dealer")
  4895. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4896. return
  4897. }
  4898. dealer := items["dealer"].(string)
  4899. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4900. utils.ErrorLog("manufacturer")
  4901. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4902. return
  4903. }
  4904. manufacturer := items["manufacturer"].(string)
  4905. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4906. utils.ErrorLog("specification_name")
  4907. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4908. return
  4909. }
  4910. specification_name := items["specification_name"].(string)
  4911. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4912. utils.ErrorLog("remark")
  4913. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4914. return
  4915. }
  4916. remark := items["remark"].(string)
  4917. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4918. utils.ErrorLog("warehousing_unit")
  4919. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4920. return
  4921. }
  4922. warehousing_unit := items["warehousing_unit"].(string)
  4923. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4924. utils.ErrorLog("buy_price")
  4925. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4926. return
  4927. }
  4928. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4929. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4930. utils.ErrorLog("count")
  4931. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4932. return
  4933. }
  4934. count := int64(items["count"].(float64))
  4935. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4936. utils.ErrorLog("good_id")
  4937. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4938. return
  4939. }
  4940. good_id := int64(items["good_id"].(float64))
  4941. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4942. utils.ErrorLog("start_time")
  4943. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4944. return
  4945. }
  4946. var startTime int64
  4947. start_time := items["start_time"].(string)
  4948. if len(start_time) > 0 {
  4949. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4950. if err != nil {
  4951. fmt.Println(err)
  4952. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4953. return
  4954. }
  4955. startTime = theTime.Unix()
  4956. }
  4957. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  4958. utils.ErrorLog("number")
  4959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4960. return
  4961. }
  4962. number := items["number"].(string)
  4963. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  4964. utils.ErrorLog("warehousing_info_id")
  4965. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4966. return
  4967. }
  4968. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  4969. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  4970. utils.ErrorLog("expiry_date")
  4971. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4972. return
  4973. }
  4974. expiry_date := int64(items["expiry_date"].(float64))
  4975. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  4976. utils.ErrorLog("product_date")
  4977. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4978. return
  4979. }
  4980. product_date := int64(items["product_date"].(float64))
  4981. orgId := this.GetAdminUserInfo().CurrentOrgId
  4982. Creater := this.GetAdminUserInfo().AdminUser.Id
  4983. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  4984. utils.ErrorLog("total")
  4985. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4986. return
  4987. }
  4988. total := int64(items["total"].(float64))
  4989. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  4990. utils.ErrorLog("good_origin_place")
  4991. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4992. return
  4993. }
  4994. good_origin_place := items["good_origin_place"].(string)
  4995. reportPrice := models.XtStockReportPrice{
  4996. GoodName: good_name,
  4997. SpecificationName: specification_name,
  4998. WarehousingUnit: warehousing_unit,
  4999. Count: count,
  5000. BuyPrice: buy_price,
  5001. PackingPrice: packing_price,
  5002. Manufacturer: manufacturer,
  5003. Dealer: dealer,
  5004. Remark: remark,
  5005. GoodId: good_id,
  5006. UserOrgId: orgId,
  5007. Ctime: time.Now().Unix(),
  5008. Mtime: 0,
  5009. Status: 1,
  5010. WarehousingOrder: warehousing_order,
  5011. LicenseNumber: license_number,
  5012. StartTime: startTime,
  5013. Creater: Creater,
  5014. Checker: 0,
  5015. CheckerStatus: 2,
  5016. CheckerTime: 0,
  5017. Number: number,
  5018. WarehousingInfoId: warehousing_info_id,
  5019. ExpiryDate: expiry_date,
  5020. ProductDate: product_date,
  5021. Total: total,
  5022. GoodOriginPlace: good_origin_place,
  5023. }
  5024. err := service.CreateReportPrice(&reportPrice)
  5025. fmt.Println(err)
  5026. }
  5027. }
  5028. this.ServeSuccessJSON(map[string]interface{}{
  5029. "msg": "保存成功!",
  5030. })
  5031. }
  5032. func (this *StockManagerApiController) GetReportStockList() {
  5033. timeLayout := "2006-01-02"
  5034. loc, _ := time.LoadLocation("Local")
  5035. start_time := this.GetString("start_time")
  5036. end_time := this.GetString("end_time")
  5037. page, _ := this.GetInt64("page")
  5038. limit, _ := this.GetInt64("limit")
  5039. storehouse_id, _ := this.GetInt64("storehouse_id")
  5040. var startTime int64
  5041. if len(start_time) > 0 {
  5042. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5043. if err != nil {
  5044. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5045. return
  5046. }
  5047. startTime = theTime.Unix()
  5048. fmt.Println("开始时间", startTime)
  5049. }
  5050. var endTime int64
  5051. if len(end_time) > 0 {
  5052. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5053. if err != nil {
  5054. utils.ErrorLog(err.Error())
  5055. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5056. return
  5057. }
  5058. endTime = theTime.Unix()
  5059. }
  5060. orgId := this.GetAdminUserInfo().CurrentOrgId
  5061. keyword := this.GetString("keyword")
  5062. list, total, _ := service.GetStockDamagedList(orgId, keyword, page, limit, startTime, endTime, storehouse_id)
  5063. damageList, _ := service.GetStockDamagedCount(orgId)
  5064. doctorlist, _ := service.GetAllDoctorThree(orgId)
  5065. houseList, _ := service.GetAllStoreHouseList(orgId)
  5066. this.ServeSuccessJSON(map[string]interface{}{
  5067. "list": list,
  5068. "total": total,
  5069. "doctorlist": doctorlist,
  5070. "damageList": damageList,
  5071. "houseList": houseList,
  5072. })
  5073. }
  5074. func (this *StockManagerApiController) SaveCheckDamage() {
  5075. timeLayout := "2006-01-02"
  5076. loc, _ := time.LoadLocation("Local")
  5077. idstr := this.GetString("ids")
  5078. ids := strings.Split(idstr, ",")
  5079. check_time := this.GetString("check_time")
  5080. var checkTime int64
  5081. if len(check_time) > 0 {
  5082. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  5083. if err != nil {
  5084. fmt.Println(err)
  5085. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5086. return
  5087. }
  5088. checkTime = theTime.Unix()
  5089. }
  5090. checker, _ := this.GetInt64("checker")
  5091. reportprice := models.XtStockReportPrice{
  5092. Checker: checker,
  5093. CheckerStatus: 1,
  5094. CheckerTime: checkTime,
  5095. }
  5096. err := service.UpdateCheckDamage(ids, reportprice)
  5097. fmt.Println(err)
  5098. //获取当前核对的数据
  5099. list, _ := service.GetCheckDamageList(ids)
  5100. ctime := time.Now().Unix()
  5101. adminUserInfo := this.GetAdminUserInfo()
  5102. timeStr := time.Now().Format("2006-01-02")
  5103. timeArr := strings.Split(timeStr, "-")
  5104. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  5105. total = total + 1
  5106. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5107. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5108. number = number + total
  5109. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5110. operation_time := time.Now().Unix()
  5111. creater := adminUserInfo.AdminUser.Id
  5112. warehouseOut := models.WarehouseOut{
  5113. WarehouseOutOrderNumber: warehousing_out_order,
  5114. OperationTime: operation_time,
  5115. OrgId: adminUserInfo.CurrentOrgId,
  5116. Creater: creater,
  5117. Ctime: ctime,
  5118. Status: 1,
  5119. WarehouseOutTime: ctime,
  5120. Type: 1,
  5121. }
  5122. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  5123. if errcodes == gorm.ErrRecordNotFound {
  5124. service.AddSigleWarehouseOutOne(&warehouseOut)
  5125. }
  5126. out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
  5127. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  5128. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  5129. var manufacturer_id int64
  5130. var dealer_id int64
  5131. for _, item := range list {
  5132. for _, it := range manufacturerList {
  5133. if item.Manufacturer == it.ManufacturerName {
  5134. manufacturer_id = it.ID
  5135. }
  5136. }
  5137. for _, its := range dealerList {
  5138. if item.Dealer == its.DealerName {
  5139. dealer_id = its.ID
  5140. }
  5141. }
  5142. goodinfo, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5143. //插入出库单
  5144. warehouseOutInfo := &models.WarehouseOutInfo{
  5145. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  5146. WarehouseOutId: out.ID,
  5147. GoodId: item.GoodId,
  5148. Count: item.Count,
  5149. Price: item.PackingPrice,
  5150. Status: 1,
  5151. Ctime: ctime,
  5152. Remark: item.Remark,
  5153. OrgId: adminUserInfo.CurrentOrgId,
  5154. Type: 2,
  5155. Manufacturer: manufacturer_id,
  5156. Number: item.Number,
  5157. ExpiryDate: item.ExpiryDate,
  5158. ProductDate: item.ProductDate,
  5159. Dealer: dealer_id,
  5160. LicenseNumber: item.LicenseNumber,
  5161. GoodTypeId: goodinfo.GoodTypeId,
  5162. }
  5163. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  5164. fmt.Println("", errOne)
  5165. //更改库存
  5166. info, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  5167. warehousingInfo := models.WarehousingInfo{
  5168. StockCount: info.StockCount - item.Count,
  5169. }
  5170. errOne = service.UpdateGoodWarehouseInfo(item.WarehousingInfoId, warehousingInfo)
  5171. fmt.Println(errOne)
  5172. flow := models.VmStockFlow{
  5173. WarehousingId: 0,
  5174. GoodId: item.GoodId,
  5175. Number: item.Number,
  5176. LicenseNumber: item.LicenseNumber,
  5177. Count: item.Count,
  5178. UserOrgId: adminUserInfo.CurrentOrgId,
  5179. PatientId: 0,
  5180. SystemTime: time.Now().Unix(),
  5181. ConsumableType: 5,
  5182. IsSys: 0,
  5183. WarehousingOrder: "",
  5184. WarehouseOutId: out.ID,
  5185. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  5186. IsEdit: 0,
  5187. CancelStockId: 0,
  5188. CancelOrderNumber: "",
  5189. Manufacturer: 0,
  5190. Dealer: 0,
  5191. Creator: adminUserInfo.AdminUser.Id,
  5192. UpdateCreator: 0,
  5193. Status: 1,
  5194. Ctime: time.Now().Unix(),
  5195. Mtime: 0,
  5196. Price: item.PackingPrice,
  5197. WarehousingDetailId: 0,
  5198. WarehouseOutDetailId: 0,
  5199. CancelOutDetailId: 0,
  5200. ProductDate: item.ProductDate,
  5201. ExpireDate: item.ExpiryDate,
  5202. }
  5203. service.CreateStockFlowOne(flow)
  5204. }
  5205. this.ServeSuccessJSON(map[string]interface{}{
  5206. "reportPrice": reportprice,
  5207. })
  5208. }
  5209. func (this *StockManagerApiController) SaveInventory() {
  5210. timeLayout := "2006-01-02"
  5211. loc, _ := time.LoadLocation("Local")
  5212. dataBody := make(map[string]interface{}, 0)
  5213. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5214. if err != nil {
  5215. utils.ErrorLog(err.Error())
  5216. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5217. return
  5218. }
  5219. tableData, _ := dataBody["tableData"].([]interface{})
  5220. if len(tableData) > 0 {
  5221. for _, item := range tableData {
  5222. items := item.(map[string]interface{})
  5223. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5224. utils.ErrorLog("good_name")
  5225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5226. return
  5227. }
  5228. good_name := items["good_name"].(string)
  5229. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5230. utils.ErrorLog("good_name")
  5231. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5232. return
  5233. }
  5234. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  5235. utils.ErrorLog("packing_price")
  5236. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5237. return
  5238. }
  5239. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  5240. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  5241. utils.ErrorLog("warehousing_order")
  5242. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5243. return
  5244. }
  5245. warehousing_order := items["warehousing_order"].(string)
  5246. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  5247. utils.ErrorLog("license_number")
  5248. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5249. return
  5250. }
  5251. license_number := items["license_number"].(string)
  5252. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  5253. utils.ErrorLog("dealer")
  5254. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5255. return
  5256. }
  5257. dealer := items["dealer"].(string)
  5258. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  5259. utils.ErrorLog("manufacturer")
  5260. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5261. return
  5262. }
  5263. manufacturer := items["manufacturer"].(string)
  5264. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  5265. utils.ErrorLog("specification_name")
  5266. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5267. return
  5268. }
  5269. specification_name := items["specification_name"].(string)
  5270. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  5271. utils.ErrorLog("remark")
  5272. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5273. return
  5274. }
  5275. remark := items["remark"].(string)
  5276. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  5277. utils.ErrorLog("warehousing_unit")
  5278. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5279. return
  5280. }
  5281. warehousing_unit := items["warehousing_unit"].(string)
  5282. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  5283. utils.ErrorLog("buy_price")
  5284. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5285. return
  5286. }
  5287. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  5288. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  5289. utils.ErrorLog("count")
  5290. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5291. return
  5292. }
  5293. count := int64(items["count"].(float64))
  5294. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5295. utils.ErrorLog("good_id")
  5296. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5297. return
  5298. }
  5299. good_id := int64(items["good_id"].(float64))
  5300. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  5301. utils.ErrorLog("start_time")
  5302. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5303. return
  5304. }
  5305. var startTime int64
  5306. start_time := items["start_time"].(string)
  5307. if len(start_time) > 0 {
  5308. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5309. if err != nil {
  5310. fmt.Println(err)
  5311. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5312. return
  5313. }
  5314. startTime = theTime.Unix()
  5315. }
  5316. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  5317. utils.ErrorLog("total")
  5318. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5319. return
  5320. }
  5321. total := int64(items["total"].(float64))
  5322. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  5323. utils.ErrorLog("expiry_date")
  5324. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5325. return
  5326. }
  5327. expiry_date := int64(items["expiry_date"].(float64))
  5328. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  5329. utils.ErrorLog("product_date")
  5330. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5331. return
  5332. }
  5333. product_date := int64(items["product_date"].(float64))
  5334. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5335. utils.ErrorLog("number")
  5336. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5337. return
  5338. }
  5339. number := items["number"].(string)
  5340. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  5341. utils.ErrorLog("warehousing_info_id")
  5342. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5343. return
  5344. }
  5345. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  5346. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  5347. utils.ErrorLog("good_origin_place")
  5348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5349. return
  5350. }
  5351. good_origin_place := items["good_origin_place"].(string)
  5352. orgId := this.GetAdminUserInfo().CurrentOrgId
  5353. Creater := this.GetAdminUserInfo().AdminUser.Id
  5354. inventory := models.XtStockInventory{
  5355. GoodName: good_name,
  5356. SpecificationName: specification_name,
  5357. WarehousingUnit: warehousing_unit,
  5358. Count: count,
  5359. BuyPrice: buy_price,
  5360. PackingPrice: packing_price,
  5361. NewPrice: 0,
  5362. Manufacturer: manufacturer,
  5363. Dealer: dealer,
  5364. Remark: remark,
  5365. GoodId: good_id,
  5366. UserOrgId: orgId,
  5367. Ctime: time.Now().Unix(),
  5368. Mtime: 0,
  5369. Status: 1,
  5370. WarehousingOrder: warehousing_order,
  5371. LicenseNumber: license_number,
  5372. StartTime: startTime,
  5373. Creater: Creater,
  5374. Checker: 0,
  5375. CheckerStatus: 2,
  5376. CheckerTime: 0,
  5377. Total: total,
  5378. ExpireDate: expiry_date,
  5379. ProductDate: product_date,
  5380. Number: number,
  5381. WarehousingInfoId: warehousing_info_id,
  5382. GoodOriginPlace: good_origin_place,
  5383. }
  5384. err = service.CreateInentory(inventory)
  5385. fmt.Println(err)
  5386. }
  5387. }
  5388. this.ServeSuccessJSON(map[string]interface{}{
  5389. "msg": "保存成功!",
  5390. })
  5391. }
  5392. func (this *StockManagerApiController) GetInventorylist() {
  5393. timeLayout := "2006-01-02"
  5394. loc, _ := time.LoadLocation("Local")
  5395. start_time := this.GetString("start_time")
  5396. end_time := this.GetString("end_time")
  5397. page, _ := this.GetInt64("page")
  5398. limit, _ := this.GetInt64("limit")
  5399. keyword := this.GetString("keyword")
  5400. inventory_status, _ := this.GetInt64("inventory_status")
  5401. var startTime int64
  5402. if len(start_time) > 0 {
  5403. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5404. if err != nil {
  5405. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5406. return
  5407. }
  5408. startTime = theTime.Unix()
  5409. fmt.Println("开始时间", startTime)
  5410. }
  5411. var endTime int64
  5412. if len(end_time) > 0 {
  5413. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5414. if err != nil {
  5415. utils.ErrorLog(err.Error())
  5416. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5417. return
  5418. }
  5419. endTime = theTime.Unix()
  5420. }
  5421. orgId := this.GetAdminUserInfo().CurrentOrgId
  5422. list, total, _ := service.GetInventorylist(startTime, endTime, page, limit, inventory_status, keyword, orgId)
  5423. doctorlist, _ := service.GetAllDoctorThree(orgId)
  5424. houseList, _ := service.GetAllStoreHouseList(orgId)
  5425. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5426. this.ServeSuccessJSON(map[string]interface{}{
  5427. "list": list,
  5428. "total": total,
  5429. "doctorlist": doctorlist,
  5430. "houseList": houseList,
  5431. "houseConfig": houseConfig,
  5432. })
  5433. }
  5434. func (this *StockManagerApiController) SaveCheckInventory() {
  5435. timeLayout := "2006-01-02"
  5436. loc, _ := time.LoadLocation("Local")
  5437. dataBody := make(map[string]interface{}, 0)
  5438. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5439. fmt.Println(err)
  5440. idstr := this.GetString("ids")
  5441. ids := strings.Split(idstr, ",")
  5442. check_time := this.GetString("check_time")
  5443. var checkTime int64
  5444. if len(check_time) > 0 {
  5445. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  5446. if err != nil {
  5447. fmt.Println(err)
  5448. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5449. return
  5450. }
  5451. checkTime = theTime.Unix()
  5452. }
  5453. checker, _ := this.GetInt64("checker")
  5454. inventory := models.XtStockInventory{
  5455. Checker: checker,
  5456. CheckerStatus: 1,
  5457. CheckerTime: checkTime,
  5458. }
  5459. adminUserInfo := this.GetAdminUserInfo()
  5460. err = service.UpdateCheckInventory(ids, inventory)
  5461. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  5462. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  5463. var manufactuer_id int64
  5464. var dealer_id int64
  5465. //查询耗材信息
  5466. list, _ := service.GetInventoryDetailById(ids)
  5467. for _, item := range list {
  5468. for _, it := range manufacturerList {
  5469. if item.Manufacturer == it.ManufacturerName {
  5470. manufactuer_id = it.ID
  5471. }
  5472. }
  5473. for _, its := range dealerList {
  5474. if item.Dealer == its.DealerName {
  5475. dealer_id = its.ID
  5476. }
  5477. }
  5478. //查寻该批次的库存量
  5479. list, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  5480. //查询该耗材最后1条批次
  5481. info, _ := service.GetLastWarehouseInfo(item.GoodId)
  5482. good, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5483. fmt.Println("总共", item.Count)
  5484. fmt.Println("数据", list.StockCount)
  5485. //盘点盘点库存和et实际库存的大小
  5486. // 如果盘点库存大于实际库存,怎需要入库
  5487. if item.Count > list.StockCount {
  5488. ctime := time.Now().Unix()
  5489. timeStr := time.Now().Format("2006-01-02")
  5490. timeArr := strings.Split(timeStr, "-")
  5491. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  5492. total = total + 1
  5493. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5494. operation_time := time.Now().Unix()
  5495. creater := adminUserInfo.AdminUser.Id
  5496. warehousing := models.Warehousing{
  5497. WarehousingOrder: warehousing_order,
  5498. OperationTime: operation_time,
  5499. OrgId: adminUserInfo.CurrentOrgId,
  5500. Creater: creater,
  5501. Ctime: ctime,
  5502. Status: 1,
  5503. WarehousingTime: ctime,
  5504. Type: 1,
  5505. }
  5506. service.AddSigleWarehouse(&warehousing)
  5507. //获取最
  5508. //入库单表格
  5509. warehouseInfo := models.WarehousingInfo{
  5510. WarehousingOrder: warehousing.WarehousingOrder,
  5511. WarehousingId: warehousing.ID,
  5512. GoodId: item.GoodId,
  5513. Number: info.Number,
  5514. ProductDate: info.ProductDate,
  5515. ExpiryDate: info.ExpiryDate,
  5516. WarehousingCount: item.Count - list.StockCount,
  5517. Price: info.Price,
  5518. Status: 1,
  5519. Ctime: ctime,
  5520. Remark: item.Remark,
  5521. OrgId: adminUserInfo.CurrentOrgId,
  5522. Type: 1,
  5523. Manufacturer: manufactuer_id,
  5524. StockCount: item.Count - list.StockCount,
  5525. Dealer: dealer_id,
  5526. LicenseNumber: info.LicenseNumber,
  5527. WarehouseInfoId: item.WarehousingInfoId,
  5528. GoodTypeId: good.GoodTypeId,
  5529. }
  5530. flow := models.VmStockFlow{
  5531. WarehousingOrder: warehousing.WarehousingOrder,
  5532. WarehousingId: warehousing.ID,
  5533. GoodId: item.GoodId,
  5534. Number: info.Number,
  5535. ProductDate: info.ProductDate,
  5536. ExpireDate: info.ExpiryDate,
  5537. Count: item.Count - list.StockCount,
  5538. Price: item.BuyPrice,
  5539. Status: 1,
  5540. Ctime: ctime,
  5541. UserOrgId: adminUserInfo.CurrentOrgId,
  5542. Manufacturer: info.Manufacturer,
  5543. Dealer: info.Dealer,
  5544. LicenseNumber: info.LicenseNumber,
  5545. IsEdit: 1,
  5546. Creator: adminUserInfo.AdminUser.Id,
  5547. SystemTime: operation_time,
  5548. ConsumableType: 1,
  5549. WarehousingDetailId: warehouseInfo.ID,
  5550. }
  5551. service.CreateWarehouseInfo(warehouseInfo)
  5552. service.CreateStockFlowOne(flow)
  5553. }
  5554. //如果盘点库存小于实际库存,需要出库
  5555. if item.Count < list.StockCount {
  5556. timeStr := time.Now().Format("2006-01-02")
  5557. timeArr := strings.Split(timeStr, "-")
  5558. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  5559. total = total + 1
  5560. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5561. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5562. number = number + total
  5563. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5564. operation_time := time.Now().Unix()
  5565. creater := adminUserInfo.AdminUser.Id
  5566. //查询最早的1条批次
  5567. warehouseInfo, _ := service.GetFirstWarehouseInfo(item.GoodId)
  5568. warehouseOut := models.WarehouseOut{
  5569. WarehouseOutOrderNumber: warehousing_out_order,
  5570. OperationTime: operation_time,
  5571. OrgId: adminUserInfo.CurrentOrgId,
  5572. Creater: creater,
  5573. Ctime: time.Now().Unix(),
  5574. Status: 1,
  5575. WarehouseOutTime: time.Now().Unix(),
  5576. Type: 1,
  5577. }
  5578. err = service.CreateWarehouseOut(warehouseOut)
  5579. fmt.Println(err)
  5580. out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
  5581. warehouseOutInfo := &models.WarehouseOutInfo{
  5582. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  5583. WarehouseOutId: out.ID,
  5584. GoodId: warehouseInfo.GoodId,
  5585. Count: list.StockCount - item.Count,
  5586. Price: warehouseInfo.Price,
  5587. Status: 1,
  5588. Ctime: time.Now().Unix(),
  5589. Remark: item.Remark,
  5590. OrgId: adminUserInfo.CurrentOrgId,
  5591. Type: 1,
  5592. Manufacturer: manufactuer_id,
  5593. Number: warehouseInfo.Number,
  5594. ExpiryDate: warehouseInfo.ExpiryDate,
  5595. ProductDate: warehouseInfo.ProductDate,
  5596. Dealer: dealer_id,
  5597. LicenseNumber: warehouseInfo.LicenseNumber,
  5598. GoodTypeId: good.GoodTypeId,
  5599. SysRecordTime: time.Now().Unix(),
  5600. }
  5601. stockFlow := models.VmStockFlow{
  5602. WarehousingId: item.WarehousingInfoId,
  5603. GoodId: warehouseInfo.GoodId,
  5604. Number: warehouseInfo.Number,
  5605. LicenseNumber: warehouseInfo.LicenseNumber,
  5606. Count: list.StockCount - item.Count,
  5607. UserOrgId: warehouseInfo.OrgId,
  5608. PatientId: 0,
  5609. SystemTime: time.Now().Unix(),
  5610. ConsumableType: 2,
  5611. IsSys: 2,
  5612. WarehousingOrder: "",
  5613. WarehouseOutId: out.ID,
  5614. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5615. IsEdit: 1,
  5616. CancelStockId: 0,
  5617. CancelOrderNumber: "",
  5618. Manufacturer: manufactuer_id,
  5619. Dealer: dealer_id,
  5620. Creator: adminUserInfo.AdminUser.Id,
  5621. UpdateCreator: 0,
  5622. Status: 1,
  5623. Ctime: time.Now().Unix(),
  5624. Mtime: 0,
  5625. Price: warehouseInfo.Price,
  5626. WarehousingDetailId: 0,
  5627. WarehouseOutDetailId: out.ID,
  5628. CancelOutDetailId: 0,
  5629. ProductDate: warehouseInfo.ProductDate,
  5630. ExpireDate: warehouseInfo.ExpiryDate,
  5631. }
  5632. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  5633. fmt.Println(errOne)
  5634. //创建出库明细
  5635. service.CreateStockFlowOne(stockFlow)
  5636. //更改库存
  5637. warehousingInfos := models.WarehousingInfo{
  5638. StockCount: item.Count,
  5639. }
  5640. service.UpdateStockOut(item.WarehousingInfoId, warehousingInfos)
  5641. }
  5642. }
  5643. fmt.Println(err)
  5644. this.ServeSuccessJSON(map[string]interface{}{
  5645. "inventory": inventory,
  5646. })
  5647. }
  5648. func (this *StockManagerApiController) GetModifyPriceDetail() {
  5649. id, _ := this.GetInt64("id")
  5650. detail, _ := service.GetModifyPriceDetail(id)
  5651. this.ServeSuccessJSON(map[string]interface{}{
  5652. "detail": detail,
  5653. })
  5654. }
  5655. func (this *StockManagerApiController) UpdateStockPrice() {
  5656. id, _ := this.GetInt64("id")
  5657. newPrice := this.GetString("new_price")
  5658. new_price, _ := strconv.ParseFloat(newPrice, 64)
  5659. good_name := this.GetString("good_name")
  5660. packingPrice := this.GetString("packing_price")
  5661. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5662. remark := this.GetString("remark")
  5663. good_id, _ := this.GetInt64("good_id")
  5664. manufacturer := this.GetString("manufacturer")
  5665. dealer := this.GetString("dealer")
  5666. adjust := models.XtStockAdjustPrice{
  5667. NewPrice: new_price,
  5668. GoodName: good_name,
  5669. PackingPrice: packing_price,
  5670. Remark: remark,
  5671. GoodId: good_id,
  5672. Manufacturer: manufacturer,
  5673. Dealer: dealer,
  5674. }
  5675. err := service.UpdateStockPrice(adjust, id)
  5676. fmt.Println(err)
  5677. this.ServeSuccessJSON(map[string]interface{}{
  5678. "adjust": adjust,
  5679. })
  5680. }
  5681. func (this *StockManagerApiController) DeleteStockPrice() {
  5682. id, _ := this.GetInt64("id")
  5683. err := service.DeleteStockPrice(id)
  5684. fmt.Println(err)
  5685. returnData := make(map[string]interface{}, 0)
  5686. returnData["msg"] = "ok"
  5687. this.ServeSuccessJSON(returnData)
  5688. return
  5689. }
  5690. func (this *StockManagerApiController) GetStockDamageDetail() {
  5691. id, _ := this.GetInt64("id")
  5692. detail, err := service.GetStockDamageDetail(id)
  5693. fmt.Println(err)
  5694. this.ServeSuccessJSON(map[string]interface{}{
  5695. "detail": detail,
  5696. })
  5697. }
  5698. func (this *StockManagerApiController) ModifyPrice() {
  5699. count, _ := this.GetInt64("count")
  5700. id, _ := this.GetInt64("id")
  5701. good_name := this.GetString("good_name")
  5702. specification_name := this.GetString("specification_name")
  5703. number := this.GetString("number")
  5704. warehousing_unit := this.GetString("warehousing_unit")
  5705. buyPrice := this.GetString("buy_price")
  5706. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5707. packingPrice := this.GetString("packing_price")
  5708. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5709. good_origin_place := this.GetString("good_origin_place")
  5710. manufacturer := this.GetString("manufacturer")
  5711. dealer := this.GetString("dealer")
  5712. total, _ := this.GetInt64("total")
  5713. remark := this.GetString("remark")
  5714. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5715. good_id, _ := this.GetInt64("good_id")
  5716. adjust := models.XtStockReportPrice{
  5717. Count: count,
  5718. SpecificationName: specification_name,
  5719. Number: number,
  5720. GoodName: good_name,
  5721. WarehousingUnit: warehousing_unit,
  5722. BuyPrice: buy_price,
  5723. PackingPrice: packing_price,
  5724. GoodOriginPlace: good_origin_place,
  5725. Manufacturer: manufacturer,
  5726. Dealer: dealer,
  5727. Total: total,
  5728. Remark: remark,
  5729. WarehousingInfoId: warehousing_info_id,
  5730. GoodId: good_id,
  5731. }
  5732. err := service.ModifyPrice(id, adjust)
  5733. fmt.Println(err)
  5734. this.ServeSuccessJSON(map[string]interface{}{
  5735. "adjust": adjust,
  5736. })
  5737. }
  5738. func (this *StockManagerApiController) DeleteDamage() {
  5739. id, _ := this.GetInt64("id")
  5740. err := service.DeleteDamage(id)
  5741. fmt.Println(err)
  5742. returnData := make(map[string]interface{}, 0)
  5743. returnData["msg"] = "ok"
  5744. this.ServeSuccessJSON(returnData)
  5745. return
  5746. }
  5747. func (this *StockManagerApiController) GetStockDamageById() {
  5748. ids := this.GetString("ids")
  5749. splitIds := strings.Split(ids, ",")
  5750. list, _ := service.GetStockDamageById(splitIds)
  5751. this.ServeSuccessJSON(map[string]interface{}{
  5752. "list": list,
  5753. })
  5754. }
  5755. func (this *StockManagerApiController) GetInventoryDetail() {
  5756. id, _ := this.GetInt64("id")
  5757. detail, _ := service.GetInventoryDetail(id)
  5758. this.ServeSuccessJSON(map[string]interface{}{
  5759. "detail": detail,
  5760. })
  5761. }
  5762. func (this *StockManagerApiController) ModifyInventory() {
  5763. id, _ := this.GetInt64("id")
  5764. good_id, _ := this.GetInt64("good_id")
  5765. good_name := this.GetString("good_name")
  5766. specification_name := this.GetString("specification_name")
  5767. number := this.GetString("number")
  5768. warehousing_unit := this.GetString("warehousing_unit")
  5769. buyPrice := this.GetString("buy_price")
  5770. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5771. packingPrice := this.GetString("packing_price")
  5772. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5773. total, _ := this.GetInt64("total")
  5774. good_origin_place := this.GetString("good_origin_place")
  5775. license_number := this.GetString("license_number")
  5776. dealer := this.GetString("dealer")
  5777. manufacturer := this.GetString("manufacturer")
  5778. count, _ := this.GetInt64("count")
  5779. remark := this.GetString("remark")
  5780. inventory := models.XtStockInventory{
  5781. GoodId: good_id,
  5782. GoodName: good_name,
  5783. SpecificationName: specification_name,
  5784. Number: number,
  5785. WarehousingUnit: warehousing_unit,
  5786. BuyPrice: buy_price,
  5787. PackingPrice: packing_price,
  5788. Total: total,
  5789. GoodOriginPlace: good_origin_place,
  5790. LicenseNumber: license_number,
  5791. Dealer: dealer,
  5792. Manufacturer: manufacturer,
  5793. Count: count,
  5794. Remark: remark,
  5795. }
  5796. err := service.ModifyInventory(id, inventory)
  5797. fmt.Println(err)
  5798. this.ServeSuccessJSON(map[string]interface{}{
  5799. "inventory": inventory,
  5800. })
  5801. }
  5802. func (this *StockManagerApiController) DeleteInventory() {
  5803. id, _ := this.GetInt64("id")
  5804. err := service.DeleteInventory(id)
  5805. fmt.Println(err)
  5806. returnData := make(map[string]interface{}, 0)
  5807. returnData["msg"] = "ok"
  5808. this.ServeSuccessJSON(returnData)
  5809. return
  5810. }
  5811. func (this *StockManagerApiController) GetInventoryDetailList() {
  5812. keyword := this.GetString("keyword")
  5813. limit, _ := this.GetInt64("limit")
  5814. page, _ := this.GetInt64("page")
  5815. orgId := this.GetAdminUserInfo().CurrentOrgId
  5816. appId := this.GetAdminUserInfo().CurrentAppId
  5817. storehouse_id, _ := this.GetInt64("storehouse_id")
  5818. houseList, _ := service.GetAllStoreHouseList(orgId)
  5819. list, total, _ := service.GetInventoryDetailList(keyword, limit, page, orgId, storehouse_id)
  5820. doclist, _ := service.GetAllDoctorListSix(orgId, appId)
  5821. this.ServeSuccessJSON(map[string]interface{}{
  5822. "list": list,
  5823. "total": total,
  5824. "houseList": houseList,
  5825. "doclist": doclist,
  5826. })
  5827. }
  5828. func (this *StockManagerApiController) GetInventoryPrintList() {
  5829. ids := this.GetString("ids")
  5830. splitIds := strings.Split(ids, ",")
  5831. list, _ := service.GetInventoryPrintList(splitIds)
  5832. this.ServeSuccessJSON(map[string]interface{}{
  5833. "list": list,
  5834. })
  5835. }
  5836. func (this *StockManagerApiController) GetInventoryDetailPrintList() {
  5837. ids := this.GetString("ids")
  5838. splitIds := strings.Split(ids, ",")
  5839. list, _ := service.GetInventoryDetailPrintList(splitIds)
  5840. this.ServeSuccessJSON(map[string]interface{}{
  5841. "list": list,
  5842. })
  5843. }
  5844. func (this *StockManagerApiController) DeleteDrugPrice() {
  5845. id, _ := this.GetInt64("id")
  5846. err := service.DeleteDrugPrice(id)
  5847. fmt.Println(err)
  5848. returnData := make(map[string]interface{}, 0)
  5849. returnData["msg"] = "ok"
  5850. this.ServeSuccessJSON(returnData)
  5851. return
  5852. }
  5853. func (this *StockManagerApiController) GetGoodWarehouseList() {
  5854. id, _ := this.GetInt64("id")
  5855. list, _ := service.GetGoodWarehouseList(id)
  5856. this.ServeSuccessJSON(map[string]interface{}{
  5857. "list": list,
  5858. })
  5859. }
  5860. func (this *StockManagerApiController) ProofInventory() {
  5861. id, _ := this.GetInt64("id")
  5862. good_id, _ := this.GetInt64("good_id")
  5863. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5864. proof_count, _ := this.GetInt64("proof_count")
  5865. total, _ := this.GetInt64("total")
  5866. orgId := this.GetAdminUserInfo().CurrentOrgId
  5867. creater := this.GetAdminUserInfo().AdminUser.Id
  5868. info := models.WarehousingInfo{
  5869. GoodId: good_id,
  5870. StockCount: proof_count,
  5871. }
  5872. err := service.UpdateProofInventory(warehousing_info_id, info)
  5873. inventory := models.XtStockInventory{
  5874. Total: proof_count,
  5875. }
  5876. err = service.UpdateStockInventory(inventory, id)
  5877. fmt.Println(err)
  5878. record := models.XtStockCorrectRecord{
  5879. GoodId: good_id,
  5880. OrdCount: total,
  5881. WarehousingInfoId: warehousing_info_id,
  5882. NewCount: proof_count,
  5883. UserOrgId: orgId,
  5884. Status: 1,
  5885. Creater: creater,
  5886. Ctime: time.Now().Unix(),
  5887. Mtime: 0,
  5888. }
  5889. service.CeateStockCorrectRecord(record)
  5890. this.ServeSuccessJSON(map[string]interface{}{
  5891. "list": info,
  5892. })
  5893. }
  5894. func (this *StockManagerApiController) GetWarehouseTotal() {
  5895. id, _ := this.GetInt64("id")
  5896. list, _ := service.GetWarehouseTotal(id)
  5897. this.ServeSuccessJSON(map[string]interface{}{
  5898. "list": list,
  5899. })
  5900. }
  5901. func (this *StockManagerApiController) GetGoodInventoryWarehouseList() {
  5902. id, _ := this.GetInt64("id")
  5903. storehouse_id, _ := this.GetInt64("storehouse_id")
  5904. list, _ := service.GetGoodInventoryWarehouseList(id, storehouse_id)
  5905. orgId := this.GetAdminUserInfo().CurrentOrgId
  5906. fmt.Println(orgId)
  5907. this.ServeSuccessJSON(map[string]interface{}{
  5908. "list": list,
  5909. })
  5910. }
  5911. func (this *StockManagerApiController) SaveStockInventoryList() {
  5912. dataBody := make(map[string]interface{}, 0)
  5913. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5914. fmt.Println(err)
  5915. tableData, _ := dataBody["tableData"].([]interface{})
  5916. if len(tableData) > 0 {
  5917. for _, item := range tableData {
  5918. items := item.(map[string]interface{})
  5919. good_name := items["good_name"].(string)
  5920. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5921. utils.ErrorLog("good_name")
  5922. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5923. return
  5924. }
  5925. specification_name := items["specification_name"].(string)
  5926. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  5927. utils.ErrorLog("specification_name")
  5928. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5929. return
  5930. }
  5931. warehousing_unit := items["warehousing_unit"].(string)
  5932. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  5933. utils.ErrorLog("warehousing_unit")
  5934. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5935. return
  5936. }
  5937. stock_count := int64(items["stock_count"].(float64))
  5938. if items["stock_count"] == nil || reflect.TypeOf(items["stock_count"]).String() != "float64" {
  5939. utils.ErrorLog("stock_count")
  5940. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5941. return
  5942. }
  5943. price := items["price"].(float64)
  5944. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "float64" {
  5945. utils.ErrorLog("price")
  5946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5947. return
  5948. }
  5949. manufacturer_name := items["manufacturer_name"].(string)
  5950. if items["manufacturer_name"] == nil || reflect.TypeOf(items["manufacturer_name"]).String() != "string" {
  5951. utils.ErrorLog("manufacturer_name")
  5952. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5953. return
  5954. }
  5955. good_id := int64(items["good_id"].(float64))
  5956. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5957. utils.ErrorLog("good_id")
  5958. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5959. return
  5960. }
  5961. manufacturer := int64(items["manufacturer"].(float64))
  5962. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "float64" {
  5963. utils.ErrorLog("manufacturer")
  5964. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5965. return
  5966. }
  5967. warehousing_order := items["warehousing_order"].(string)
  5968. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  5969. utils.ErrorLog("warehousing_order")
  5970. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5971. return
  5972. }
  5973. number := items["number"].(string)
  5974. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5975. utils.ErrorLog("number")
  5976. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5977. return
  5978. }
  5979. id := int64(items["id"].(float64))
  5980. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5981. utils.ErrorLog("id")
  5982. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5983. return
  5984. }
  5985. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  5986. utils.ErrorLog("expiry_date")
  5987. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5988. return
  5989. }
  5990. expiry_date := int64(items["expiry_date"].(float64))
  5991. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  5992. utils.ErrorLog("product_date")
  5993. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5994. return
  5995. }
  5996. product_date := int64(items["product_date"].(float64))
  5997. orgId := this.GetAdminUserInfo().CurrentOrgId
  5998. adminId := this.GetAdminUserInfo().AdminUser.Id
  5999. stock_type := int64(items["type"].(float64))
  6000. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6001. utils.ErrorLog("type")
  6002. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6003. return
  6004. }
  6005. last_stock_count := int64(items["last_stock_count"].(float64))
  6006. if items["last_stock_count"] == nil || reflect.TypeOf(items["last_stock_count"]).String() != "float64" {
  6007. utils.ErrorLog("last_stock_count")
  6008. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6009. return
  6010. }
  6011. storehouse_id := int64(items["storehouse_id"].(float64))
  6012. if items["storehouse_id"] == nil || reflect.TypeOf(items["storehouse_id"]).String() != "float64" {
  6013. utils.ErrorLog("storehouse_id")
  6014. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6015. return
  6016. }
  6017. var total_count int64
  6018. var inventory_type int64
  6019. if stock_count > last_stock_count {
  6020. total_count = stock_count - last_stock_count
  6021. inventory_type = 11
  6022. }
  6023. if stock_count < last_stock_count {
  6024. total_count = last_stock_count - stock_count
  6025. inventory_type = 10
  6026. }
  6027. creater := this.GetAdminUserInfo().AdminUser.Id
  6028. inventory := models.XtStockInventory{
  6029. GoodName: good_name,
  6030. SpecificationName: specification_name,
  6031. WarehousingUnit: warehousing_unit,
  6032. Count: total_count,
  6033. BuyPrice: price,
  6034. PackingPrice: price,
  6035. NewPrice: 0,
  6036. Manufacturer: manufacturer_name,
  6037. Dealer: "",
  6038. Remark: "",
  6039. GoodId: good_id,
  6040. UserOrgId: orgId,
  6041. Ctime: time.Now().Unix(),
  6042. Mtime: 0,
  6043. Status: 1,
  6044. WarehousingOrder: warehousing_order,
  6045. LicenseNumber: number,
  6046. StartTime: time.Now().Unix(),
  6047. Creater: adminId,
  6048. Checker: 0,
  6049. CheckerStatus: 0,
  6050. CheckerTime: 0,
  6051. Total: 0,
  6052. Number: number,
  6053. WarehousingInfoId: id,
  6054. ExpireDate: expiry_date,
  6055. ProductDate: product_date,
  6056. GoodOriginPlace: "",
  6057. Type: 10,
  6058. InventoryType: stock_type,
  6059. LastStockCount: last_stock_count,
  6060. StockCount: stock_count,
  6061. StorehouseId: storehouse_id,
  6062. }
  6063. service.CreateInentory(inventory)
  6064. stockFlow := models.VmStockFlow{
  6065. WarehousingId: 0,
  6066. GoodId: good_id,
  6067. Number: number,
  6068. LicenseNumber: "",
  6069. Count: total_count,
  6070. UserOrgId: orgId,
  6071. PatientId: 0,
  6072. SystemTime: 0,
  6073. ConsumableType: inventory_type,
  6074. IsSys: 0,
  6075. WarehousingOrder: "",
  6076. WarehouseOutId: 0,
  6077. WarehouseOutOrderNumber: warehousing_order,
  6078. IsEdit: 0,
  6079. CancelStockId: 0,
  6080. CancelOrderNumber: "",
  6081. Manufacturer: manufacturer,
  6082. Dealer: 0,
  6083. Creator: creater,
  6084. UpdateCreator: 0,
  6085. Status: 1,
  6086. Ctime: time.Now().Unix(),
  6087. Mtime: 0,
  6088. Price: price,
  6089. WarehousingDetailId: 0,
  6090. WarehouseOutDetailId: 0,
  6091. CancelOutDetailId: 0,
  6092. ProductDate: product_date,
  6093. ExpireDate: expiry_date,
  6094. ReturnCount: 0,
  6095. StorehouseId: storehouse_id,
  6096. }
  6097. info := models.WarehousingInfo{
  6098. StockCount: last_stock_count,
  6099. WarehousingCount: last_stock_count,
  6100. }
  6101. warehosueinfos, _ := service.GetWarehouseInfoByIdNight(id)
  6102. //如果当前的盘点后的数量大于当前库存数量,则新增库存
  6103. if last_stock_count > warehosueinfos.StockCount && last_stock_count <= warehosueinfos.WarehousingCount {
  6104. //更改库存
  6105. service.UpdatedWarehousingInfo(info, id)
  6106. }
  6107. if last_stock_count > warehosueinfos.StockCount && last_stock_count > warehosueinfos.WarehousingCount {
  6108. //更改库存
  6109. service.UpdatedWarehousingInfoSix(info, id)
  6110. }
  6111. //如果当前的盘点后的数量大于当前库存数量,则扣减库存
  6112. if last_stock_count < warehosueinfos.StockCount {
  6113. //更改库存
  6114. service.UpdatedWarehousingInfo(info, id)
  6115. }
  6116. //查询该机构默认仓库
  6117. storeConfig, _ := service.GetAllStoreHouseConfig(warehosueinfos.OrgId)
  6118. goodListOne, _ := service.GetSumGoodList(orgId, storeConfig.StorehouseOutInfo, good_id)
  6119. var flush_count int64
  6120. for _, it := range goodListOne {
  6121. flush_count += it.StockCount
  6122. }
  6123. if stock_count != last_stock_count {
  6124. stockFlow.OverCount = flush_count
  6125. service.CreateStockFlowOne(stockFlow)
  6126. }
  6127. //查询已审核单据的剩余库存
  6128. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, good_id, warehosueinfos.OrgId)
  6129. var sum_count int64
  6130. var sum_in_count int64
  6131. for _, item := range goodList {
  6132. sum_count += item.StockCount
  6133. sum_in_count += item.WarehousingCount
  6134. }
  6135. service.UpdateGoodByGoodId(good_id, sum_count, sum_in_count, warehosueinfos.OrgId)
  6136. service.UpdateSumGood(orgId, storeConfig.StorehouseOutInfo, good_id, flush_count)
  6137. this.ServeSuccessJSON(map[string]interface{}{
  6138. "inventory": inventory,
  6139. })
  6140. }
  6141. }
  6142. newTableData, _ := dataBody["newTableData"].([]interface{})
  6143. if len(newTableData) > 0 {
  6144. for _, item := range newTableData {
  6145. items := item.(map[string]interface{})
  6146. good_name := items["good_name"].(string)
  6147. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  6148. utils.ErrorLog("good_name")
  6149. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6150. return
  6151. }
  6152. specification_name := items["specification_name"].(string)
  6153. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  6154. utils.ErrorLog("specification_name")
  6155. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6156. return
  6157. }
  6158. warehousing_unit := items["warehousing_unit"].(string)
  6159. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  6160. utils.ErrorLog("warehousing_unit")
  6161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6162. return
  6163. }
  6164. warehousing_count := int64(items["warehousing_count"].(float64))
  6165. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "float64" {
  6166. utils.ErrorLog("warehousing_count")
  6167. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6168. return
  6169. }
  6170. stock_count := int64(items["stock_count"].(float64))
  6171. if items["stock_count"] == nil || reflect.TypeOf(items["stock_count"]).String() != "float64" {
  6172. utils.ErrorLog("stock_count")
  6173. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6174. return
  6175. }
  6176. price := items["price"].(float64)
  6177. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "float64" {
  6178. utils.ErrorLog("price")
  6179. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6180. return
  6181. }
  6182. manufacturer_name := items["manufacturer_name"].(string)
  6183. if items["manufacturer_name"] == nil || reflect.TypeOf(items["manufacturer_name"]).String() != "string" {
  6184. utils.ErrorLog("manufacturer_name")
  6185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6186. return
  6187. }
  6188. good_id := int64(items["good_id"].(float64))
  6189. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6190. utils.ErrorLog("good_id")
  6191. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6192. return
  6193. }
  6194. warehousing_order := items["warehousing_order"].(string)
  6195. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  6196. utils.ErrorLog("warehousing_order")
  6197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6198. return
  6199. }
  6200. number := items["number"].(string)
  6201. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  6202. utils.ErrorLog("number")
  6203. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6204. return
  6205. }
  6206. id := int64(items["id"].(float64))
  6207. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  6208. utils.ErrorLog("id")
  6209. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6210. return
  6211. }
  6212. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  6213. utils.ErrorLog("expiry_date")
  6214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6215. return
  6216. }
  6217. expiry_date := int64(items["expiry_date"].(float64))
  6218. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  6219. utils.ErrorLog("product_date")
  6220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6221. return
  6222. }
  6223. product_date := int64(items["product_date"].(float64))
  6224. stock_type := int64(items["type"].(float64))
  6225. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6226. utils.ErrorLog("type")
  6227. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6228. return
  6229. }
  6230. last_stock_count := int64(items["last_stock_count"].(float64))
  6231. if items["last_stock_count"] == nil || reflect.TypeOf(items["last_stock_count"]).String() != "float64" {
  6232. utils.ErrorLog("last_stock_count")
  6233. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6234. return
  6235. }
  6236. storehouse_id := int64(items["storehouse_id"].(float64))
  6237. if items["storehouse_id"] == nil || reflect.TypeOf(items["storehouse_id"]).String() != "float64" {
  6238. utils.ErrorLog("storehouse_id")
  6239. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6240. return
  6241. }
  6242. creater := this.GetAdminUserInfo().AdminUser.Id
  6243. recordDateStr := time.Now().Format("2006-01-02")
  6244. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6245. user_org_id := this.GetAdminUserInfo().CurrentOrgId
  6246. goodStockInventory := models.XtGoodStockInventoryList{
  6247. GoodId: good_id,
  6248. WarehousingOrder: warehousing_order,
  6249. InCount: warehousing_count,
  6250. BatchNumber: number,
  6251. Price: price,
  6252. BeforCount: stock_count,
  6253. AfterCount: last_stock_count,
  6254. Reason: stock_type,
  6255. Creater: creater,
  6256. RecordDate: recordDate.Unix(),
  6257. UserOrgId: user_org_id,
  6258. Ctime: time.Now().Unix(),
  6259. Mtime: time.Now().Unix(),
  6260. WarehouseInfoId: id,
  6261. SpecificationName: specification_name,
  6262. ManufacturerName: manufacturer_name,
  6263. GoodName: good_name,
  6264. ExpiryDate: expiry_date,
  6265. ProductDate: product_date,
  6266. StorehouseId: storehouse_id,
  6267. MaxUnit: warehousing_unit,
  6268. Status: 1,
  6269. }
  6270. //查询今日该耗材是否有记录
  6271. goodStock, _ := service.GetGoodStockInventoryByRecordate(good_id, recordDate.Unix(), user_org_id)
  6272. if goodStock.ID == 0 {
  6273. service.CreateGoodStockInventoryList(goodStockInventory)
  6274. }
  6275. if goodStock.ID > 0 {
  6276. goodStockInventory.ID = goodStock.ID
  6277. service.SaveGoodStockInventoryList(goodStockInventory)
  6278. }
  6279. }
  6280. }
  6281. this.ServeSuccessJSON(map[string]interface{}{
  6282. "msg": "保存成功!",
  6283. })
  6284. }
  6285. func (this *StockManagerApiController) GetDamageDetailByGoodId() {
  6286. good_id, _ := this.GetInt64("good_id")
  6287. warehousing_order := this.GetString("warehousing_order")
  6288. inventory_type, _ := this.GetInt64("type")
  6289. list, _ := service.GetDamageDetailByGoodId(good_id, warehousing_order, inventory_type)
  6290. orgId := this.GetAdminUserInfo().CurrentOrgId
  6291. damageList, _ := service.GetStockDamagedCountOne(orgId, warehousing_order, inventory_type)
  6292. this.ServeSuccessJSON(map[string]interface{}{
  6293. "list": list,
  6294. "damageList": damageList,
  6295. })
  6296. }
  6297. func (this *StockManagerApiController) GetInventoryExportList() {
  6298. orgId := this.GetAdminUserInfo().CurrentOrgId
  6299. list, _ := service.GetInventoryExportList(orgId)
  6300. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  6301. this.ServeSuccessJSON(map[string]interface{}{
  6302. "list": list,
  6303. "manufacturerList": manufacturerList,
  6304. })
  6305. }
  6306. func (this *StockManagerApiController) UpdateCancelStockOrder() {
  6307. type_id, _ := this.GetInt64("type_id")
  6308. //获取目前在使用的机构ID
  6309. list, _ := service.GetOrgIdList()
  6310. //耗材
  6311. if type_id == 1 {
  6312. for _, item := range list {
  6313. //查询该机构的所有耗材
  6314. goodList, _ := service.GetAllGoodList(item.OrgId)
  6315. for _, it := range goodList {
  6316. //查询该耗材的入库总数
  6317. info, _ := service.GetStockCountWarehouseInfoById(it.ID)
  6318. var total int64
  6319. for _, its := range info {
  6320. total += its.StockCount
  6321. }
  6322. //更新库存
  6323. service.ModifyGoodAddInformationSeven(it.ID, total, it.OrgId)
  6324. }
  6325. }
  6326. }
  6327. //药品
  6328. if type_id == 2 {
  6329. for _, item := range list {
  6330. fmt.Println(item)
  6331. //查询该机构的所有药品
  6332. drugList, _ := service.GetAllBaseDrugStockList(4)
  6333. for _, it := range drugList {
  6334. //查询该药品的入库总数
  6335. info, _ := service.GetDrugStockCountWarehoseInfoById(it.ID)
  6336. var sum_count int64
  6337. for _, its := range info {
  6338. if its.MaxUnit == it.MaxUnit {
  6339. its.StockMaxNumber = its.StockMaxNumber * it.MinNumber
  6340. }
  6341. sum_count += its.StockMaxNumber + its.StockMinNumber
  6342. }
  6343. service.UpdateModifyDrugInfoById(it.ID, sum_count, it.OrgId)
  6344. }
  6345. }
  6346. }
  6347. }
  6348. func (this *StockManagerApiController) GetDrugDetailSummary() {
  6349. timeLayout := "2006-01-02"
  6350. loc, _ := time.LoadLocation("Local")
  6351. start_time := this.GetString("start_time")
  6352. end_time := this.GetString("end_time")
  6353. var startTime int64
  6354. if len(start_time) > 0 {
  6355. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6356. if err != nil {
  6357. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6358. return
  6359. }
  6360. startTime = theTime.Unix()
  6361. fmt.Println("开始时间", startTime)
  6362. }
  6363. var endTime int64
  6364. if len(end_time) > 0 {
  6365. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6366. if err != nil {
  6367. utils.ErrorLog(err.Error())
  6368. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6369. return
  6370. }
  6371. endTime = theTime.Unix()
  6372. }
  6373. keyword := this.GetString("keyword")
  6374. limit, _ := this.GetInt64("limit")
  6375. page, _ := this.GetInt64("page")
  6376. orgId := this.GetAdminUserInfo().CurrentOrgId
  6377. list, total, err := service.GetDrugDetailSummary(startTime, endTime, keyword, limit, page, orgId)
  6378. druglist, _, _ := service.GetDrugDetailSummaryOne(startTime, endTime, keyword, limit, page, orgId)
  6379. patients, _ := service.GetAllpatient(orgId)
  6380. var drugType = "药品类型"
  6381. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  6382. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  6383. for _, item := range list {
  6384. for _, it := range druglist {
  6385. if item.DrugId == it.DrugId {
  6386. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6387. }
  6388. }
  6389. }
  6390. drug, _ := service.GetAllDrugSummary(orgId)
  6391. if err == nil {
  6392. this.ServeSuccessJSON(map[string]interface{}{
  6393. "list": list,
  6394. "total": total,
  6395. "drug": drug,
  6396. "drugTypeList": drugTypeList,
  6397. "patients": patients,
  6398. })
  6399. }
  6400. }
  6401. func (this *StockManagerApiController) GetGoodDetailSummary() {
  6402. timeLayout := "2006-01-02"
  6403. loc, _ := time.LoadLocation("Local")
  6404. start_time := this.GetString("start_time")
  6405. end_time := this.GetString("end_time")
  6406. var startTime int64
  6407. if len(start_time) > 0 {
  6408. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6409. if err != nil {
  6410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6411. return
  6412. }
  6413. startTime = theTime.Unix()
  6414. }
  6415. var endTime int64
  6416. if len(end_time) > 0 {
  6417. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6418. if err != nil {
  6419. utils.ErrorLog(err.Error())
  6420. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6421. return
  6422. }
  6423. endTime = theTime.Unix()
  6424. }
  6425. keyword := this.GetString("keyword")
  6426. limit, _ := this.GetInt64("limit")
  6427. page, _ := this.GetInt64("page")
  6428. orgId := this.GetAdminUserInfo().CurrentOrgId
  6429. list, total, err := service.GetGoodDetailSummary(startTime, endTime, keyword, limit, page, orgId)
  6430. goodlist, _, _ := service.GetGoodDetailSummaryOne(startTime, endTime, keyword, limit, page, orgId)
  6431. for _, item := range list {
  6432. for _, it := range goodlist {
  6433. if item.ProjectId == it.ProjectId {
  6434. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6435. }
  6436. }
  6437. }
  6438. information, _ := service.GeAllGoodInformation(orgId)
  6439. patients, _ := service.GetAllpatient(orgId)
  6440. goodType, _ := service.GetAllGoodType(orgId)
  6441. if err == nil {
  6442. this.ServeSuccessJSON(map[string]interface{}{
  6443. "list": list,
  6444. "total": total,
  6445. "good": information,
  6446. "patients": patients,
  6447. "goodType": goodType,
  6448. })
  6449. }
  6450. }
  6451. func (this *StockManagerApiController) CheckWarehouseOut() {
  6452. id, _ := this.GetInt64("id")
  6453. orgId := this.GetAdminUserInfo().CurrentOrgId
  6454. // 开始外部循环的事务
  6455. db := service.XTWriteDB()
  6456. tx := db.Begin()
  6457. // 在函数结束时处理事务回滚
  6458. defer func() {
  6459. if r := recover(); r != nil {
  6460. tx.Rollback()
  6461. }
  6462. }()
  6463. warehouseOut, _ := service.GetNewWarehouseById(id, tx)
  6464. //查询已保存的单据
  6465. warehousingOutInfo, _ := service.GetNewWarehouseOutById(id, orgId, tx)
  6466. ////出库逻辑
  6467. for _, item := range warehousingOutInfo {
  6468. // 查询该耗材是否有库存
  6469. warehouseOne, _ := service.FindNewWarehousingInfoTen(item.GoodId, item.StorehouseId, tx)
  6470. storehouse, _ := service.FindNewStoreHouseByStorehouseId(item.StorehouseId, item.OrgId, tx)
  6471. // 如果出库数量大于该批次剩余库存数量
  6472. if item.Count > warehouseOne.StockCount {
  6473. goodObj, _ := service.GetNewGoodInformationByGoodId(item.GoodId, tx)
  6474. tx.Rollback()
  6475. this.ServeSuccessJSON(map[string]interface{}{
  6476. "msg": "1",
  6477. "good_name": goodObj.GoodName,
  6478. "specification_name": goodObj.SpecificationName,
  6479. "storehose_name": storehouse.StorehouseName,
  6480. })
  6481. return
  6482. }
  6483. }
  6484. var is_scucess = 2
  6485. for _, item := range warehousingOutInfo {
  6486. creater := this.GetAdminUserInfo().AdminUser.Id
  6487. var now_count = item.Count
  6488. //出库
  6489. err := service.ConsumablesNewDeliveryThirty(orgId, item.SysRecordTime, item, &warehouseOut, item.Count, creater, tx)
  6490. if err != nil {
  6491. tx.Rollback()
  6492. return
  6493. }
  6494. goodList, _ := service.GetNewSumGoodList(orgId, item.StorehouseId, item.GoodId, tx)
  6495. var flush_count int64
  6496. for _, it := range goodList {
  6497. flush_count += it.StockCount
  6498. }
  6499. service.UpdateNewSumGood(orgId, item.StorehouseId, item.GoodId, flush_count, tx)
  6500. orgId := this.GetAdminUserInfo().CurrentOrgId
  6501. //查询默认仓库
  6502. storeHouseConfig, _ := service.GetNewAllStoreHouseConfig(orgId, tx)
  6503. stockList, _ := service.GetNewStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId, tx)
  6504. var total_count int64
  6505. for _, it := range stockList {
  6506. total_count += it.StockCount
  6507. }
  6508. //基础库扣减库存
  6509. service.UpdateNewGoodInfoReduceSumCount(item.GoodId, total_count, orgId, tx)
  6510. var flow_count int64
  6511. flowList, _ := service.GetGoodFlowByWarehouseOutId(item.GoodId, item.OrgId, item.ID, tx)
  6512. if len(flowList) > 0 {
  6513. for _, items := range flowList {
  6514. flow_count += items.Count
  6515. }
  6516. }
  6517. if now_count != flow_count {
  6518. is_scucess = 1
  6519. tx.Rollback()
  6520. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFlow)
  6521. return
  6522. }
  6523. }
  6524. //审核单据
  6525. err := service.UpdatedNewWarehouseOut(id, tx)
  6526. if is_scucess != 1 {
  6527. tx.Commit()
  6528. }
  6529. if err == nil {
  6530. this.ServeSuccessJSON(map[string]interface{}{
  6531. "msg": "2",
  6532. "good_name": "",
  6533. "specification_name": "",
  6534. "storehose_name": "",
  6535. })
  6536. return
  6537. }
  6538. }
  6539. func (this *StockManagerApiController) ReturnCheckWarehouseOut() {
  6540. id, _ := this.GetInt64("id")
  6541. orgId := this.GetAdminUserInfo().CurrentOrgId
  6542. // 开始外部循环的事务
  6543. db := service.XTWriteDB()
  6544. tx := db.Begin()
  6545. // 在函数结束时处理事务回滚
  6546. defer func() {
  6547. if r := recover(); r != nil {
  6548. tx.Rollback()
  6549. }
  6550. }()
  6551. // 查询出库数据
  6552. list, err := service.GetNewWarehouseOutById(id, orgId, tx)
  6553. for _, item := range list {
  6554. service.ModifyGoodOutInfoLog(item.GoodId, item.ID, tx)
  6555. //回退库存
  6556. service.UpdateaNewGoodWarehouseInfo(item.Count, item.GoodId, item.OrgId, item.WarehouseInfotId, tx)
  6557. //查询默认仓库
  6558. storeHouseConfig, _ := service.GetNewAllStoreHouseConfig(orgId, tx)
  6559. stockList, _ := service.GetNewStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId, tx)
  6560. var total_count int64
  6561. for _, it := range stockList {
  6562. total_count += it.StockCount
  6563. }
  6564. //基础库扣减库存
  6565. service.UpdateNewGoodInfoReduceSumCount(item.GoodId, total_count, orgId, tx)
  6566. goodList, _ := service.GetNewSumGoodList(orgId, item.StorehouseId, item.GoodId, tx)
  6567. var flush_count int64
  6568. for _, it := range goodList {
  6569. flush_count += it.StockCount
  6570. }
  6571. service.UpdateNewSumGood(orgId, item.StorehouseId, item.GoodId, flush_count, tx)
  6572. //扣减出库数据
  6573. service.ModifyNewReduceGoodSumCount(item.StorehouseId, item.Count, orgId, item.GoodId, tx)
  6574. }
  6575. //删除流水,改变审核状态
  6576. service.ModifyNewGoodWarehouseOut(id, tx)
  6577. tx.Commit()
  6578. if err == nil {
  6579. this.ServeSuccessJSON(map[string]interface{}{
  6580. "list": "list",
  6581. })
  6582. }
  6583. }
  6584. func (this *StockManagerApiController) CheckWarehouseInfo() {
  6585. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  6586. orgId := this.GetAdminUserInfo().CurrentOrgId
  6587. Creator := this.GetAdminUserInfo().AdminUser.Id
  6588. // 开始外部循环的事务
  6589. db := service.XTWriteDB()
  6590. tx := db.Begin()
  6591. // 在函数结束时处理事务回滚
  6592. defer func() {
  6593. if r := recover(); r != nil {
  6594. tx.Rollback()
  6595. }
  6596. }()
  6597. //查询默认仓库
  6598. storeHouseConfig, _ := service.GetNewAllStoreHouseConfig(orgId, tx)
  6599. checker := this.GetAdminUserInfo().AdminUser.Id
  6600. //更改审核状态
  6601. err := service.UpdateNewCheckWarehouseInfo(warehousing_info_id, checker, tx)
  6602. var is_success = 2
  6603. if err == nil {
  6604. list, _ := service.GetNewWarehouseInfoList(warehousing_info_id, orgId, tx)
  6605. for _, item := range list {
  6606. var now_count = item.WarehousingCount
  6607. service.UpdateNewWarehouseInfoByIdListThree(item.WarehousingCount, item.ID, tx)
  6608. //查询该耗材剩余库存库
  6609. stockList, _ := service.GetNewStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId, tx)
  6610. var total_count int64
  6611. var sum_in_count int64
  6612. for _, it := range stockList {
  6613. total_count += it.StockCount
  6614. sum_in_count += it.WarehousingCount
  6615. }
  6616. //基础库插入数据
  6617. service.UpdateNewGoodInfoAddSumCount(item.GoodId, total_count, orgId, sum_in_count, tx)
  6618. goodList, _ := service.GetNewSumGoodList(orgId, item.StorehouseId, item.GoodId, tx)
  6619. var flush_count int64
  6620. for _, it := range goodList {
  6621. flush_count += it.StockCount
  6622. }
  6623. stockFlow := models.VmStockFlow{
  6624. WarehousingId: item.WarehousingId,
  6625. GoodId: item.GoodId,
  6626. Number: item.Number,
  6627. LicenseNumber: item.LicenseNumber,
  6628. Count: item.WarehousingCount,
  6629. UserOrgId: item.OrgId,
  6630. PatientId: 0,
  6631. SystemTime: 0,
  6632. ConsumableType: 1,
  6633. IsSys: 1,
  6634. WarehousingOrder: item.WarehousingOrder,
  6635. WarehouseOutId: 0,
  6636. WarehouseOutOrderNumber: "",
  6637. IsEdit: 1,
  6638. CancelStockId: 0,
  6639. CancelOrderNumber: "",
  6640. Manufacturer: item.Manufacturer,
  6641. Dealer: item.Dealer,
  6642. Creator: Creator,
  6643. UpdateCreator: 0,
  6644. Ctime: item.Ctime,
  6645. Status: 1,
  6646. Mtime: 0,
  6647. Price: item.PackingPrice,
  6648. WarehousingDetailId: item.ID,
  6649. WarehouseOutDetailId: 0,
  6650. CancelOutDetailId: 0,
  6651. ProductDate: item.ProductDate,
  6652. ExpireDate: item.ExpiryDate,
  6653. SupplyWarehouseId: item.SupplyWarehouseId,
  6654. StorehouseId: item.StorehouseId,
  6655. AdminUserId: 0,
  6656. BuyPrice: item.Price,
  6657. StockCount: "",
  6658. BatchNumberCount: item.WarehousingCount,
  6659. IsCheck: 1,
  6660. OverCount: flush_count,
  6661. OperateTime: time.Now().Unix(),
  6662. GoodCode: item.GoodCode,
  6663. }
  6664. //创建出库流水
  6665. service.CreateNewStockFlowOne(stockFlow, tx)
  6666. infoLog := models.XtGoodWarehouseInfoLog{
  6667. GoodId: item.GoodId,
  6668. WarehouseInfoId: item.ID,
  6669. RecordDate: time.Now().Unix(),
  6670. UserOrgId: item.OrgId,
  6671. Status: 1,
  6672. Ctime: time.Now().Unix(),
  6673. Mtime: time.Now().Unix(),
  6674. }
  6675. service.CreateGoodWarehouseInfoLog(infoLog, tx)
  6676. //查询该仓库是否有数据
  6677. stockCount, _ := service.GetNewGoodStockCount(orgId, item.StorehouseId, item.GoodId, tx)
  6678. if stockCount.ID == 0 {
  6679. goodCount := models.XtGoodStockCount{
  6680. UserOrgId: orgId,
  6681. GoodId: item.GoodId,
  6682. StorehouseId: item.StorehouseId,
  6683. Status: 1,
  6684. Ctime: time.Now().Unix(),
  6685. Mtime: time.Now().Unix(),
  6686. StockInCount: item.WarehousingCount,
  6687. StockOutCount: 0,
  6688. StockCancelCount: 0,
  6689. FlushCount: flush_count,
  6690. StockActOutCount: 0,
  6691. }
  6692. service.CreateNewGoodCount(goodCount, tx)
  6693. }
  6694. if stockCount.ID > 0 {
  6695. service.UpdateNewGoodStockCount(orgId, item.StorehouseId, item.GoodId, item.WarehousingCount, flush_count, tx)
  6696. }
  6697. //查询该耗材的流水数量
  6698. goodFlowList, _ := service.GetInitGoodFlow(orgId, item.GoodId, item.ID, tx)
  6699. var flow_count int64
  6700. if len(goodFlowList) > 0 {
  6701. for _, item := range goodFlowList {
  6702. flow_count += item.Count
  6703. }
  6704. }
  6705. if now_count != flow_count {
  6706. is_success = 1
  6707. tx.Rollback()
  6708. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFlow)
  6709. return
  6710. }
  6711. }
  6712. }
  6713. if is_success != 1 {
  6714. tx.Commit()
  6715. }
  6716. if err == nil {
  6717. this.ServeSuccessJSON(map[string]interface{}{
  6718. "list": "list",
  6719. })
  6720. }
  6721. return
  6722. }
  6723. func (this *StockManagerApiController) ReturnCheckWarehouseInfo() {
  6724. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  6725. orgId := this.GetAdminUserInfo().CurrentOrgId
  6726. // 开始外部循环的事务
  6727. db := service.XTWriteDB()
  6728. tx := db.Begin()
  6729. // 在函数结束时处理事务回滚
  6730. defer func() {
  6731. if r := recover(); r != nil {
  6732. tx.Rollback()
  6733. }
  6734. }()
  6735. //查询入库数据
  6736. list, _ := service.GetNewWarehouseInfoList(warehousing_info_id, orgId, tx)
  6737. for _, item := range list {
  6738. //查询该耗材 是否有出库数据
  6739. outlist, _ := service.GetNewWarehouseOutByWarehouseInfoId(item.ID, item.GoodId, item.OrgId, tx)
  6740. if len(outlist) > 0 {
  6741. tx.Rollback()
  6742. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCheckGoodParamWrong)
  6743. return
  6744. }
  6745. }
  6746. err := service.UpdateNewWarehouseInfoMap(list, warehousing_info_id, orgId, tx)
  6747. tx.Commit()
  6748. if err == nil {
  6749. this.ServeSuccessJSON(map[string]interface{}{
  6750. "msg": "反审核成功!",
  6751. })
  6752. return
  6753. }
  6754. }
  6755. func (this *StockManagerApiController) CheckStockWarehouseInfo() {
  6756. cancel_stock_id, _ := this.GetInt64("cancel_stock_id")
  6757. orgId := this.GetAdminUserInfo().CurrentOrgId
  6758. list, _ := service.GetCancelStockInfoListById(cancel_stock_id, orgId)
  6759. creater := this.GetAdminUserInfo().AdminUser.Id
  6760. manufacturerlist, _ := service.GetAllManufacturerList(orgId)
  6761. dealerList, _ := service.GetAllDealerList(orgId)
  6762. var manufacturer_id int64
  6763. var cancel_total_count int64
  6764. var out_total_count int64
  6765. var dealer_id int64
  6766. for _, item := range list {
  6767. //查询该药品该批次的出库数量是否满足退库需求
  6768. outList, _ := service.GetWarehouseOutList(item.OrgId, item.GoodId, item.WarehouseInfoId)
  6769. for _, it := range outList {
  6770. out_total_count += it.Count
  6771. }
  6772. warehouseList, _ := service.GetCancelWarehouseList(item.OrgId, item.GoodId, item.WarehouseInfoId)
  6773. for _, it := range warehouseList {
  6774. cancel_total_count += it.Count
  6775. }
  6776. if cancel_total_count > out_total_count {
  6777. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6778. this.ServeSuccessJSON(map[string]interface{}{
  6779. "msg": "2",
  6780. "good_name": goodObj.GoodName,
  6781. "specification_name": goodObj.SpecificationName,
  6782. })
  6783. return
  6784. }
  6785. }
  6786. cancelStock := models.CancelStock{
  6787. IsCheck: 1,
  6788. }
  6789. service.CheckCancelStock(cancelStock, cancel_stock_id, orgId)
  6790. //回退库存
  6791. cancellist, _ := service.GetCancelStockInfoById(cancel_stock_id, orgId)
  6792. for _, item := range cancellist {
  6793. for _, items := range manufacturerlist {
  6794. if item.Manufacturer == items.ManufacturerName {
  6795. manufacturer_id = items.ID
  6796. }
  6797. }
  6798. for _, it := range dealerList {
  6799. if item.Dealer == it.DealerName {
  6800. dealer_id = it.ID
  6801. }
  6802. }
  6803. //回退库存
  6804. service.UpdateCancelStockNumber(item.Count, item.WarehouseInfoId, orgId)
  6805. //更新基础库库存
  6806. service.UpdateGoodSumCount(item.Count, item.GoodId, orgId)
  6807. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6808. //退库数量增加
  6809. service.UpdateSumAddCancelCount(orgId, item.GoodId, item.StorehouseId, item.Count)
  6810. var flush_count int64
  6811. for _, it := range goodList {
  6812. flush_count += it.StockCount
  6813. }
  6814. stockFlow := models.VmStockFlow{
  6815. ID: 0,
  6816. WarehousingId: item.WarehouseInfoId,
  6817. GoodId: item.GoodId,
  6818. Number: item.Number,
  6819. LicenseNumber: "",
  6820. Count: item.Count,
  6821. UserOrgId: item.OrgId,
  6822. PatientId: item.PatientId,
  6823. SystemTime: item.RecordDate,
  6824. ConsumableType: 4,
  6825. IsSys: 0,
  6826. WarehousingOrder: "",
  6827. WarehouseOutId: 0,
  6828. WarehouseOutOrderNumber: "",
  6829. IsEdit: 0,
  6830. CancelStockId: cancel_stock_id,
  6831. CancelOrderNumber: item.OrderNumber,
  6832. Manufacturer: manufacturer_id,
  6833. Dealer: dealer_id,
  6834. Creator: creater,
  6835. UpdateCreator: 0,
  6836. Status: 1,
  6837. Ctime: time.Now().Unix(),
  6838. Mtime: 0,
  6839. Price: item.Price,
  6840. WarehousingDetailId: item.WarehouseInfoId,
  6841. WarehouseOutDetailId: 0,
  6842. CancelOutDetailId: item.ID,
  6843. ProductDate: item.ProductDate,
  6844. ExpireDate: item.ExpiryDate,
  6845. ReturnCount: 0,
  6846. ProjectId: 0,
  6847. SupplyWarehouseId: 0,
  6848. SupplyCancelOutId: 0,
  6849. SupplyWarehouseDetailInfo: 0,
  6850. StorehouseId: item.StorehouseId,
  6851. SecondWarehouseInfoId: 0,
  6852. AdminUserId: 0,
  6853. BuyPrice: item.Price,
  6854. StockCount: "",
  6855. OverCount: flush_count,
  6856. }
  6857. //创建流水
  6858. service.CreateStockFlowOne(stockFlow)
  6859. //更新剩余库存
  6860. errs := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
  6861. //出库数量减少
  6862. service.ModifyAddGoodSumCount(item.StorehouseId, item.Count, orgId, item.GoodId)
  6863. if errs != nil {
  6864. goodErrcode := models.XtGoodErrcode{
  6865. UserOrgId: item.OrgId,
  6866. Errcode: "手动退库更新剩余出库失败",
  6867. GoodId: item.GoodId,
  6868. Status: 1,
  6869. Ctime: time.Now().Unix(),
  6870. Mtime: 0,
  6871. Count: 0,
  6872. StockCount: 0,
  6873. Creater: creater,
  6874. BatchNumberId: 0,
  6875. WarehouseOutId: 0,
  6876. }
  6877. service.CreateGoodErrcode(goodErrcode)
  6878. }
  6879. }
  6880. this.ServeSuccessJSON(map[string]interface{}{
  6881. "msg": "1",
  6882. "good_name": "",
  6883. "specification_name": "",
  6884. })
  6885. return
  6886. }
  6887. func (this *StockManagerApiController) CheckReturnStockWarehouseInfo() {
  6888. cancel_stock_id, _ := this.GetInt64("cancel_stock_id")
  6889. orgId := this.GetAdminUserInfo().CurrentOrgId
  6890. cancelStock := models.CancelStock{
  6891. IsCheck: 2,
  6892. }
  6893. list, _ := service.GetCancelStockInfoListById(cancel_stock_id, orgId)
  6894. creater := this.GetAdminUserInfo().AdminUser.Id
  6895. for _, item := range list {
  6896. //回退库存
  6897. service.UpdateStockNumberWarehouseInfo(item.WarehouseInfoId, item.GoodId, item.OrgId, item.Count)
  6898. service.UpdateStockWarehouseInfoStockFlow(item.ID, orgId, item.GoodId)
  6899. //退库数量增加
  6900. service.UpdateSumReduceCancelCount(orgId, item.GoodId, item.StorehouseId, item.Count)
  6901. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6902. var flush_count int64
  6903. for _, it := range goodList {
  6904. flush_count += it.StockCount
  6905. }
  6906. errs := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
  6907. //出库数量增加
  6908. service.UpdateSumAddOutCount(orgId, item.GoodId, item.StorehouseId, item.Count)
  6909. if errs != nil {
  6910. goodErrcode := models.XtGoodErrcode{
  6911. UserOrgId: item.OrgId,
  6912. Errcode: "手动退库反审核更新剩余出库失败",
  6913. GoodId: item.GoodId,
  6914. Status: 1,
  6915. Ctime: time.Now().Unix(),
  6916. Mtime: 0,
  6917. Count: 0,
  6918. StockCount: 0,
  6919. Creater: creater,
  6920. BatchNumberId: 0,
  6921. WarehouseOutId: 0,
  6922. }
  6923. service.CreateGoodErrcode(goodErrcode)
  6924. }
  6925. }
  6926. err := service.UpdateStockWarehouseInfo(cancel_stock_id, orgId, cancelStock)
  6927. if err == nil {
  6928. this.ServeSuccessJSON(map[string]interface{}{
  6929. "msg": "反审核成功!",
  6930. })
  6931. return
  6932. }
  6933. }
  6934. func (this *StockManagerApiController) GetPrintList() {
  6935. storehouse_id, _ := this.GetInt64("storehouse_id")
  6936. limit, _ := this.GetInt64("limit")
  6937. page, _ := this.GetInt64("page")
  6938. good_name := this.GetString("good_name")
  6939. ids := this.GetString("ids")
  6940. idSplit := strings.Split(ids, ",")
  6941. fmt.Println(storehouse_id, good_name)
  6942. orgId := this.GetAdminUserInfo().CurrentOrgId
  6943. houseList, _ := service.GetAllStoreHouseList(orgId)
  6944. list, total, _ := service.GetInventoryDetailPrintMapList(good_name, limit, page, orgId, storehouse_id, idSplit)
  6945. this.ServeSuccessJSON(map[string]interface{}{
  6946. "list": list,
  6947. "total": total,
  6948. "houseList": houseList,
  6949. })
  6950. }
  6951. func (this *StockManagerApiController) GetInvetoryWarehouseInfoList() {
  6952. storehouse_id, _ := this.GetInt64("storehouse_id")
  6953. orgId := this.GetAdminUserInfo().CurrentOrgId
  6954. list, _ := service.GetInvetoryWarehouseInfoList(orgId, storehouse_id)
  6955. var info []*models.WarehousingInfo
  6956. if orgId == 10571 {
  6957. for _, item := range list {
  6958. if strings.ContainsAny(item.GoodInfo.GoodStatus, "收费") {
  6959. info = append(info, item)
  6960. }
  6961. }
  6962. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  6963. dealerList, _ := service.GetAllDealerList(orgId)
  6964. this.ServeSuccessJSON(map[string]interface{}{
  6965. "list": info,
  6966. "manufacturerList": manufacturerList,
  6967. "dealerList": dealerList,
  6968. })
  6969. } else {
  6970. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  6971. dealerList, _ := service.GetAllDealerList(orgId)
  6972. this.ServeSuccessJSON(map[string]interface{}{
  6973. "list": list,
  6974. "manufacturerList": manufacturerList,
  6975. "dealerList": dealerList,
  6976. "info": info,
  6977. })
  6978. }
  6979. }
  6980. func (this *StockManagerApiController) GetNewGoodWarehouseInfo() {
  6981. timeLayout := "2006-01-02"
  6982. loc, _ := time.LoadLocation("Local")
  6983. start_time := this.GetString("start_time")
  6984. end_time := this.GetString("end_time")
  6985. var startTime int64
  6986. if len(start_time) > 0 {
  6987. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6988. if err != nil {
  6989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6990. return
  6991. }
  6992. startTime = theTime.Unix()
  6993. }
  6994. var endTime int64
  6995. if len(end_time) > 0 {
  6996. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6997. if err != nil {
  6998. utils.ErrorLog(err.Error())
  6999. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7000. return
  7001. }
  7002. endTime = theTime.Unix()
  7003. }
  7004. storehouse_id, _ := this.GetInt64("storehouse_id")
  7005. keywords := this.GetString("keywords")
  7006. orgId := this.GetAdminUserInfo().CurrentOrgId
  7007. var goodids []int64
  7008. //查询商品名称
  7009. if len(keywords) > 0 {
  7010. //查询商品名称
  7011. list, _ := service.GetGoodInforByGoodName(keywords, orgId)
  7012. for _, item := range list {
  7013. goodids = append(goodids, item.ID)
  7014. //入库详情但里面查询
  7015. }
  7016. }
  7017. list, _ := service.GetNewGoodWarehouseInfo(startTime, endTime, orgId, goodids, storehouse_id)
  7018. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  7019. dealerList, _ := service.GetAllDealerList(orgId)
  7020. storeHouseList, _ := service.GetAllStoreHouseList(orgId)
  7021. this.ServeSuccessJSON(map[string]interface{}{
  7022. "list": list,
  7023. "manufacturerList": manufacturerList,
  7024. "dealerList": dealerList,
  7025. "storeHouseList": storeHouseList,
  7026. })
  7027. }
  7028. func (this *StockManagerApiController) GetNewWarehouseOutInfoList() {
  7029. timeLayout := "2006-01-02"
  7030. loc, _ := time.LoadLocation("Local")
  7031. start_time := this.GetString("start_time")
  7032. end_time := this.GetString("end_time")
  7033. var startTime int64
  7034. if len(start_time) > 0 {
  7035. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7036. if err != nil {
  7037. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7038. return
  7039. }
  7040. startTime = theTime.Unix()
  7041. }
  7042. var endTime int64
  7043. if len(end_time) > 0 {
  7044. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7045. if err != nil {
  7046. utils.ErrorLog(err.Error())
  7047. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7048. return
  7049. }
  7050. endTime = theTime.Unix()
  7051. }
  7052. storehouse_id, _ := this.GetInt64("storehouse_id")
  7053. keywords := this.GetString("keyword")
  7054. orgId := this.GetAdminUserInfo().CurrentOrgId
  7055. var goodids []int64
  7056. //查询商品名称
  7057. if len(keywords) > 0 {
  7058. //查询商品名称
  7059. list, _ := service.GetGoodInforByGoodName(keywords, orgId)
  7060. for _, item := range list {
  7061. goodids = append(goodids, item.ID)
  7062. //入库详情但里面查询
  7063. }
  7064. }
  7065. list, _ := service.GetNewWarehouseOutInfoList(startTime, endTime, orgId, goodids, storehouse_id)
  7066. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  7067. dealerList, _ := service.GetAllDealerList(orgId)
  7068. storeHouseList, _ := service.GetAllStoreHouseList(orgId)
  7069. this.ServeSuccessJSON(map[string]interface{}{
  7070. "list": list,
  7071. "manufacturerList": manufacturerList,
  7072. "dealerList": dealerList,
  7073. "storeHouseList": storeHouseList,
  7074. })
  7075. }
  7076. func (this *StockManagerApiController) GetStockFlowOrderList() {
  7077. good_id, _ := this.GetInt64("good_id")
  7078. orgId := this.GetAdminUserInfo().CurrentOrgId
  7079. list, _ := service.GetStockFlowOrderList(good_id, orgId)
  7080. for index, _ := range list {
  7081. if list[index].ConsumableType == 3 || list[index].ConsumableType == 2 || list[index].ConsumableType == 11 || list[index].ConsumableType == 12 || list[index].ConsumableType == 15 {
  7082. var count int64
  7083. if index == 0 {
  7084. count = list[index].FlushOverCount - list[index].Count
  7085. service.UpdateOverCount(list[index+1].ID, count)
  7086. }
  7087. if index >= 1 {
  7088. lastStockFlow, _ := service.GetLastOverCount(list[index-1].ID)
  7089. count = lastStockFlow.FlushOverCount - list[index].Count
  7090. service.UpdateOverCount(list[index].ID, count)
  7091. }
  7092. }
  7093. if list[index].ConsumableType == 7 || list[index].ConsumableType == 4 || list[index].ConsumableType == 1 || list[index].ConsumableType == 10 || list[index].ConsumableType == 13 {
  7094. if index == 0 {
  7095. var count int64
  7096. count = list[index].FlushOverCount + list[index].Count
  7097. service.UpdateOverCount(list[index+1].ID, count)
  7098. }
  7099. if index >= 1 {
  7100. var count int64
  7101. lastStockFlow, _ := service.GetLastOverCount(list[index-1].ID)
  7102. count = lastStockFlow.FlushOverCount + list[index].Count
  7103. service.UpdateOverCount(list[index].ID, count)
  7104. }
  7105. }
  7106. }
  7107. }
  7108. func (this *StockManagerApiController) GetGoodPatientName() {
  7109. good_id, _ := this.GetInt64("good_id")
  7110. sys_record_time, _ := this.GetInt64("sys_record_time")
  7111. orgId := this.GetAdminUserInfo().CurrentOrgId
  7112. projectList, _ := service.GetGoodProjectList(good_id, sys_record_time, orgId)
  7113. outList, _ := service.GetWarehouseOutListBySysrecordTime(good_id, sys_record_time, orgId)
  7114. this.ServeSuccessJSON(map[string]interface{}{
  7115. "projectList": projectList,
  7116. "outList": outList,
  7117. })
  7118. }
  7119. func (this *StockManagerApiController) UpdateBaseDrugListByUserOrgID() {
  7120. //orgId := this.GetAdminUserInfo().CurrentOrgId
  7121. //list, _ := service.GetAllBaseDrugList(orgId)
  7122. //
  7123. //for _, item := range list {
  7124. // var sum_in_count int64
  7125. // var sum_out_count int64
  7126. // var flush_out_count int64
  7127. // //var str = ""
  7128. // //str = item.Dose + item.DoseUnit + "*" + strconv.FormatInt(item.MinNumber, 10) + item.MinUnit + "/" + item.MaxUnit
  7129. // //service.UpdateBaseDrugById(item.ID, str)
  7130. // //
  7131. // //drug_dosage_form_str := service.GetDosageFormListById(item.DrugDosageForm, orgId)
  7132. // //service.UpdateDosageFormListById(drug_dosage_form_str, item.ID)
  7133. //
  7134. // warehouseinfo, _ := service.GetDrugWarehouseInfoByItemId(item.ID)
  7135. // if len(warehouseinfo) > 0 {
  7136. // for _, it := range warehouseinfo {
  7137. // if item.MaxUnit == it.MaxUnit && item.MaxUnit != item.MinUnit {
  7138. // it.WarehousingCount = it.WarehousingCount * item.MinNumber
  7139. // }
  7140. //
  7141. // if item.MaxUnit == it.MinUnit && item.MaxUnit != item.MinUnit {
  7142. // it.WarehousingCount = it.WarehousingCount
  7143. // }
  7144. //
  7145. // if item.MaxUnit == it.MinUnit && item.MaxUnit == item.MinUnit {
  7146. // it.WarehousingCount = it.WarehousingCount
  7147. // }
  7148. //
  7149. // sum_in_count += it.WarehousingCount
  7150. // }
  7151. //
  7152. // }
  7153. // //
  7154. // outList, _ := service.GetDrugWarehosueOutInfoByItemId(item.ID)
  7155. // if len(outList) > 0 {
  7156. // for _, it := range outList {
  7157. // if item.MaxUnit == it.CountUnit && item.MaxUnit != item.MinUnit {
  7158. // it.Count = it.Count * item.MinNumber
  7159. // }
  7160. //
  7161. // if item.MaxUnit == it.CountUnit && item.MaxUnit != item.MinUnit {
  7162. // it.Count = it.Count
  7163. // }
  7164. //
  7165. // if item.MaxUnit == it.CountUnit && item.MaxUnit == item.MinUnit {
  7166. // it.Count = it.Count
  7167. // }
  7168. //
  7169. // sum_out_count += it.Count
  7170. // }
  7171. // }
  7172. //
  7173. // flush_out_count = sum_in_count - sum_out_count
  7174. // fmt.Println("sum_in_count+++++++++++++", sum_in_count)
  7175. // fmt.Println("sum_out_count++++++++++++++", sum_out_count)
  7176. // fmt.Println("flushi_out_count===========", flush_out_count)
  7177. //
  7178. // service.UpdateBaseDrugByIdCountTwo(item.ID, flush_out_count)
  7179. //}
  7180. //info, _ := service.GetDrugAllInfo(orgId)
  7181. //info, _ := service.GetDrugOutAllInfo(orgId)
  7182. //
  7183. //for _, item := range info {
  7184. //
  7185. // //dealer, _ := service.GetDealerById(item.Dealer)
  7186. //
  7187. // manufacturer, _ := service.GetManufactureById(item.Manufacturer)
  7188. //
  7189. // service.UpdateDealerManufacturerOne(item.ID, manufacturer.ManufacturerName)
  7190. //}
  7191. drugList, _ := service.GetAllBaseDrugListTwentyOne(10480)
  7192. for _, item := range drugList {
  7193. var drug_spec = item.Dose + item.DoseUnit + "*" + strconv.FormatInt(item.MinNumber, 10) + item.MinUnit + "/" + item.MaxUnit
  7194. service.UpdateBaseDrugList(item.ID, drug_spec)
  7195. }
  7196. }
  7197. func (this *StockManagerApiController) UpdateGoodInfoByUserOrgId() {
  7198. //orgId := this.GetAdminUserInfo().CurrentOrgId
  7199. //info, _ := service.GetAllWareHouseOutByUserOrg(10633)
  7200. //
  7201. //if len(info) > 0 {
  7202. // for _, item := range info {
  7203. //
  7204. // //dealer, _ := service.GetDealerById(item.Dealer)
  7205. //
  7206. // //manufacturer, _ := service.GetManufactureById(item.Manufacturer)
  7207. //
  7208. // //service.UpdateGoodInfoByUserOrgIdTwo(item.ID, dealer.DealerName)
  7209. // }
  7210. //}
  7211. goodList, _ := service.GetAllGoodList(10633)
  7212. for _, item := range goodList {
  7213. service.UpdateStockFlowByList(item.ID, item.PackingPrice)
  7214. //service.UpdateWarehouseOutInfoByPrice(item.ID, item.PackingPrice)
  7215. //outList, _ := service.GetWarehosueOutInfoByPrice(item.ID, 10633)
  7216. //
  7217. //for _, it := range outList {
  7218. // //service.UpdateWarehouseOut(it.ID, item.PackingPrice)
  7219. //
  7220. // service.UpdateStockFlowByList(it.GoodId, item.PackingPrice)
  7221. //}
  7222. //good_type_name := service.GetAllGoodTypeName(item.GoodTypeId, orgId)
  7223. //
  7224. //service.UpdateGoodTypeName(item.ID, good_type_name)
  7225. }
  7226. //
  7227. //for _, item := range goodList {
  7228. //
  7229. // var sum_in_count int64
  7230. // var sum_out_count int64
  7231. // var flush_out_count int64
  7232. // infor, _ := service.GetAllWarehouseSumInCount(item.ID)
  7233. //
  7234. // for _, item := range infor {
  7235. // sum_in_count += item.WarehousingCount
  7236. // }
  7237. //
  7238. // outInfo, _ := service.GetAllWarehouseSumOutCount(item.ID)
  7239. //
  7240. // for _, item := range outInfo {
  7241. // sum_out_count += item.Count
  7242. // }
  7243. //
  7244. // flush_out_count = sum_in_count - sum_out_count
  7245. //
  7246. // service.UpdateGoodInfoByIdOne(item.ID, flush_out_count)
  7247. //}
  7248. }
  7249. func (this *StockManagerApiController) GetGoodStockInventoryList() {
  7250. keyword := this.GetString("keyword")
  7251. limit, _ := this.GetInt64("limit")
  7252. page, _ := this.GetInt64("page")
  7253. storehouse_id, _ := this.GetInt64("storehouse_id")
  7254. start_time := this.GetString("start_time")
  7255. end_time := this.GetString("end_time")
  7256. orgId := this.GetAdminUserInfo().CurrentOrgId
  7257. appId := this.GetAdminUserInfo().CurrentAppId
  7258. timeLayout := "2006-01-02"
  7259. loc, _ := time.LoadLocation("Local")
  7260. var startTime int64
  7261. if len(start_time) > 0 {
  7262. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7263. if err != nil {
  7264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7265. return
  7266. }
  7267. startTime = theTime.Unix()
  7268. }
  7269. var endTime int64
  7270. if len(end_time) > 0 {
  7271. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7272. if err != nil {
  7273. utils.ErrorLog(err.Error())
  7274. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7275. return
  7276. }
  7277. endTime = theTime.Unix()
  7278. }
  7279. list, total, _ := service.GetGoodStockInventoryList(keyword, limit, page, storehouse_id, startTime, endTime, orgId)
  7280. doclist, _ := service.GetAllDoctorListSix(orgId, appId)
  7281. storeHouseList, _ := service.GetAllStoreHouseList(orgId)
  7282. this.ServeSuccessJSON(map[string]interface{}{
  7283. "list": list,
  7284. "total": total,
  7285. "storeHouseList": storeHouseList,
  7286. "doclist": doclist,
  7287. })
  7288. }
  7289. func (this *StockManagerApiController) GetStockInventoryPrintList() {
  7290. storehouse_id, _ := this.GetInt64("storehouse_id")
  7291. keyword := this.GetString("keyword")
  7292. limit, _ := this.GetInt64("limit")
  7293. page, _ := this.GetInt64("page")
  7294. ids := this.GetString("ids")
  7295. p_ids_arr := strings.Split(ids, ",")
  7296. orgId := this.GetAdminUserInfo().CurrentOrgId
  7297. appId := this.GetAdminUserInfo().CurrentAppId
  7298. list, total, _ := service.GetStockInventoryPrintList(storehouse_id, keyword, limit, page, p_ids_arr, orgId)
  7299. doclist, _ := service.GetAllDoctorListSix(orgId, appId)
  7300. storeHouseList, _ := service.GetAllStoreHouseList(orgId)
  7301. this.ServeSuccessJSON(map[string]interface{}{
  7302. "list": list,
  7303. "total": total,
  7304. "storeHouseList": storeHouseList,
  7305. "doclist": doclist,
  7306. })
  7307. }
  7308. func (this *StockManagerApiController) GetStockInventoryModePrintList() {
  7309. orgId := this.GetAdminUserInfo().CurrentOrgId
  7310. start_time := this.GetString("start_time")
  7311. end_time := this.GetString("end_time")
  7312. timeLayout := "2006-01-02"
  7313. loc, _ := time.LoadLocation("Local")
  7314. var startTime int64
  7315. if len(start_time) > 0 {
  7316. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7317. if err != nil {
  7318. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7319. return
  7320. }
  7321. startTime = theTime.Unix()
  7322. }
  7323. var endTime int64
  7324. if len(end_time) > 0 {
  7325. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7326. if err != nil {
  7327. utils.ErrorLog(err.Error())
  7328. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7329. return
  7330. }
  7331. endTime = theTime.Unix()
  7332. }
  7333. goodInfo, _ := service.FindAllGoodInfoThree(orgId)
  7334. //获取所有入库数量
  7335. list, _ := service.GetInventoryExportList(orgId)
  7336. infoList, _ := service.GetGoodWarehouseInfoList(startTime, endTime, orgId)
  7337. outinfo, _ := service.GetGoodWarhouseOutList(startTime, endTime, orgId)
  7338. //获取盘盈的数据
  7339. flowProList, _ := service.GetGoodStockFlowProList(startTime, endTime, orgId)
  7340. //获取盘亏的数据
  7341. flowNoProList, _ := service.GetGoodStockFlowNoProList(startTime, endTime, orgId)
  7342. //获取盘点退库
  7343. CancelFlowList, _ := service.GetCancelStockFlowList(startTime, endTime, orgId)
  7344. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  7345. //获取期初结余数量
  7346. warehouseinfo, _ := service.GetLastMonthCount(startTime, orgId)
  7347. //期出结余出库数量
  7348. warehouseOutInfo, _ := service.GetLastMonthOverCount(startTime, orgId)
  7349. cancelInfo, _ := service.GetLastCancelMonthCount(startTime, orgId)
  7350. this.ServeSuccessJSON(map[string]interface{}{
  7351. "list": list,
  7352. "infoList": infoList,
  7353. "outinfo": outinfo,
  7354. "flowProList": flowProList,
  7355. "flowNoProList": flowNoProList,
  7356. "manufacturerList": manufacturerList,
  7357. "goodInfo": goodInfo,
  7358. "warehouseinfo": warehouseinfo,
  7359. "warehouseOutInfo": warehouseOutInfo,
  7360. "cancelInfo": cancelInfo,
  7361. "CancelFlowList": CancelFlowList,
  7362. })
  7363. }