stock_in_api_controller.go 264KB

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