stock_in_api_controller.go 276KB

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