stock_in_api_controller.go 270KB

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