stock_in_api_controller.go 276KB

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