stock_in_api_controller.go 262KB

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