stock_in_api_controller.go 261KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929
  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. if types == 1 {
  2838. list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2839. _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2840. if err == nil {
  2841. this.ServeSuccessJSON(map[string]interface{}{
  2842. "list": list,
  2843. "total": total,
  2844. "total_price": total_price,
  2845. "houseList": houseList,
  2846. })
  2847. } else {
  2848. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2849. }
  2850. } else if types == 2 {
  2851. list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2852. _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2853. if err == nil {
  2854. this.ServeSuccessJSON(map[string]interface{}{
  2855. "list": list1,
  2856. "total": total,
  2857. "total_price": total_price,
  2858. "houseList": houseList,
  2859. })
  2860. } else {
  2861. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2862. }
  2863. } else if types == 3 {
  2864. list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2865. if err == nil {
  2866. this.ServeSuccessJSON(map[string]interface{}{
  2867. "list": list2,
  2868. "total": total,
  2869. })
  2870. } else {
  2871. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2872. }
  2873. } else if types == 4 {
  2874. list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2875. listGroup, err := service.FindeCancelGroup(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
  2876. if err == nil {
  2877. this.ServeSuccessJSON(map[string]interface{}{
  2878. "list": list3,
  2879. "total": total,
  2880. "listgroup": listGroup,
  2881. "houseList": houseList,
  2882. })
  2883. } else {
  2884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2885. }
  2886. }
  2887. }
  2888. func (this *StockManagerApiController) GetUserDetailInfo() {
  2889. order_id, _ := this.GetInt64("id")
  2890. if order_id <= 0 {
  2891. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2892. return
  2893. }
  2894. adminUserInfo := this.GetAdminUserInfo()
  2895. userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  2896. if err == nil {
  2897. this.ServeSuccessJSON(map[string]interface{}{
  2898. "list": userDetails,
  2899. "total": total,
  2900. })
  2901. } else {
  2902. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2903. return
  2904. }
  2905. }
  2906. func (this *StockManagerApiController) PostSearchStock() {
  2907. keyword := this.GetString("keyword")
  2908. adminUserInfo := this.GetAdminUserInfo()
  2909. orgId := adminUserInfo.CurrentOrgId
  2910. stock, err := service.PostSearchStock(keyword, orgId)
  2911. if err != nil {
  2912. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2913. }
  2914. this.ServeSuccessJSON(map[string]interface{}{
  2915. "stock": stock,
  2916. })
  2917. }
  2918. func (this *StockManagerApiController) GetOutStockTotalCount() {
  2919. warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
  2920. adminUserInfo := this.GetAdminUserInfo()
  2921. stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
  2922. if err != nil {
  2923. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2924. }
  2925. this.ServeSuccessJSON(map[string]interface{}{
  2926. "stockCount": stockCount,
  2927. })
  2928. }
  2929. func (this *StockManagerApiController) AddGoodInformation() {
  2930. adminUserInfo := this.GetAdminUserInfo()
  2931. orgId := adminUserInfo.CurrentOrgId
  2932. dataBody := make(map[string]interface{}, 0)
  2933. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2934. if err != nil {
  2935. utils.ErrorLog(err.Error())
  2936. return
  2937. }
  2938. utils.ErrorLog("%v", dataBody)
  2939. var goods []*models.GoodInfo
  2940. var total_goods []interface{}
  2941. tempGoods := dataBody["goods"].([]interface{})
  2942. total_goods = tempGoods
  2943. for index, goodMap := range tempGoods {
  2944. goodNameM := goodMap.(map[string]interface{})
  2945. var good models.GoodInfo
  2946. if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
  2947. utils.ErrorLog("good_name")
  2948. return
  2949. }
  2950. good_name, _ := goodNameM["good_name"].(string)
  2951. if len(good_name) == 0 { //名字为空则生成一条导入错误日志
  2952. err_log := models.ExportErrLog{
  2953. LogType: 5,
  2954. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2955. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
  2956. Status: 1,
  2957. CreateTime: time.Now().Unix(),
  2958. UpdateTime: time.Now().Unix(),
  2959. ExportTime: time.Now().Unix(),
  2960. }
  2961. service.CreateExportErrLog(&err_log)
  2962. continue
  2963. }
  2964. good.GoodName = good_name
  2965. // 获取数据字典数据
  2966. var good_kind_id int64
  2967. var name = "耗材种类"
  2968. config, _ := service.GetDrugDataConfig(0, name)
  2969. good_kind := goodNameM["good_kind"].(string)
  2970. if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
  2971. err_log := models.ExportErrLog{
  2972. LogType: 5,
  2973. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2974. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
  2975. Status: 1,
  2976. CreateTime: time.Now().Unix(),
  2977. UpdateTime: time.Now().Unix(),
  2978. ExportTime: time.Now().Unix(),
  2979. }
  2980. service.CreateExportErrLog(&err_log)
  2981. continue
  2982. }
  2983. if len(good_kind) != 0 {
  2984. _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
  2985. lastConfig, _ := service.GetLastDicConfig(config.ID, orgId)
  2986. dataconfig := models.DictDataconfig{
  2987. ParentId: config.ID,
  2988. Module: "system",
  2989. OrgId: orgId,
  2990. Name: good_kind,
  2991. FieldName: "",
  2992. Value: lastConfig.Value + 1,
  2993. CreatedTime: "",
  2994. UpdatedTime: "",
  2995. CreateUserId: adminUserInfo.AdminUser.Id,
  2996. Status: 1,
  2997. Remark: "",
  2998. DeleteIdSystem: 0,
  2999. Title: "",
  3000. Content: "",
  3001. Order: 0,
  3002. Code: "",
  3003. }
  3004. if errcodegoodkind == gorm.ErrRecordNotFound {
  3005. service.CreatedDicConfig(&dataconfig)
  3006. }
  3007. }
  3008. dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
  3009. for _, it := range dataConfig {
  3010. if good_kind == it.Name {
  3011. fmt.Println(it.Name)
  3012. good_kind_id = int64(it.Value)
  3013. }
  3014. }
  3015. good.GoodKind = good_kind_id
  3016. good_type := goodNameM["type_name"].(string)
  3017. if len(good_type) == 0 {
  3018. err_log := models.ExportErrLog{
  3019. LogType: 5,
  3020. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3021. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材类型不能为空",
  3022. Status: 1,
  3023. CreateTime: time.Now().Unix(),
  3024. UpdateTime: time.Now().Unix(),
  3025. ExportTime: time.Now().Unix(),
  3026. }
  3027. service.CreateExportErrLog(&err_log)
  3028. continue
  3029. }
  3030. if len(good_type) != 0 {
  3031. _, errcodegoodtype := service.GetGoodType(good_type, orgId)
  3032. if errcodegoodtype == gorm.ErrRecordNotFound {
  3033. goodsType := models.GoodsType{
  3034. TypeName: good_type,
  3035. Remark: "",
  3036. Ctime: time.Now().Unix(),
  3037. Mtime: 0,
  3038. Creater: adminUserInfo.AdminUser.Id,
  3039. Modifier: 0,
  3040. OrgId: adminUserInfo.CurrentOrgId,
  3041. Status: 1,
  3042. Type: 0,
  3043. Number: 0,
  3044. OutStock: 0,
  3045. StockAttribute: 1,
  3046. }
  3047. service.CreatedGoodType(&goodsType)
  3048. }
  3049. }
  3050. goodType, _ := service.GetAllGoodType(orgId)
  3051. var good_type_id int64
  3052. for _, it := range goodType {
  3053. if good_type == it.TypeName {
  3054. good_type_id = it.ID
  3055. }
  3056. }
  3057. good.GoodTypeId = good_type_id
  3058. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  3059. if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
  3060. err_log := models.ExportErrLog{
  3061. LogType: 5,
  3062. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3063. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  3064. Status: 1,
  3065. CreateTime: time.Now().Unix(),
  3066. UpdateTime: time.Now().Unix(),
  3067. ExportTime: time.Now().Unix(),
  3068. }
  3069. service.CreateExportErrLog(&err_log)
  3070. continue
  3071. }
  3072. var medical_insurance_id int64
  3073. var medicalInsurance = "医保等级"
  3074. medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
  3075. if len(medical_insurance_level) != 0 {
  3076. _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
  3077. if errcodemedicalInsurance == gorm.ErrRecordNotFound {
  3078. mediConfigOne, _ := service.GetLastDicConfig(medicalInsuranceDataConfig.ID, orgId)
  3079. dataconfig := models.DictDataconfig{
  3080. ParentId: medicalInsuranceDataConfig.ID,
  3081. Module: "system",
  3082. OrgId: orgId,
  3083. Name: medical_insurance_level,
  3084. FieldName: "",
  3085. Value: mediConfigOne.Value + 1,
  3086. CreatedTime: "",
  3087. UpdatedTime: "",
  3088. CreateUserId: adminUserInfo.AdminUser.Id,
  3089. Status: 1,
  3090. Remark: "",
  3091. DeleteIdSystem: 0,
  3092. Title: "",
  3093. Content: "",
  3094. Order: 0,
  3095. Code: "",
  3096. }
  3097. service.CreatedDicConfig(&dataconfig)
  3098. }
  3099. }
  3100. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
  3101. for _, it := range medicalInsuranceList {
  3102. if medical_insurance_level == it.Name {
  3103. medical_insurance_id = int64(it.Value)
  3104. }
  3105. }
  3106. good.MedicalInsuranceLevel = medical_insurance_id
  3107. if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
  3108. utils.ErrorLog("specification_name")
  3109. return
  3110. }
  3111. specification_name := goodNameM["specification_name"].(string)
  3112. if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
  3113. err_log := models.ExportErrLog{
  3114. LogType: 5,
  3115. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3116. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
  3117. Status: 1,
  3118. CreateTime: time.Now().Unix(),
  3119. UpdateTime: time.Now().Unix(),
  3120. ExportTime: time.Now().Unix(),
  3121. }
  3122. service.CreateExportErrLog(&err_log)
  3123. continue
  3124. }
  3125. good.SpecificationName = specification_name
  3126. var manufacturer_id int64
  3127. manufacturer := goodNameM["manufacturer"].(string)
  3128. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  3129. err_log := models.ExportErrLog{
  3130. LogType: 5,
  3131. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3132. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
  3133. Status: 1,
  3134. CreateTime: time.Now().Unix(),
  3135. UpdateTime: time.Now().Unix(),
  3136. ExportTime: time.Now().Unix(),
  3137. }
  3138. service.CreateExportErrLog(&err_log)
  3139. continue
  3140. }
  3141. if len(manufacturer) != 0 {
  3142. _, errcodes := service.GetManufacturerName(orgId, manufacturer)
  3143. manu := models.Manufacturer{
  3144. ManufacturerName: manufacturer,
  3145. Status: 1,
  3146. OrgId: orgId,
  3147. Creater: adminUserInfo.AdminUser.Id,
  3148. }
  3149. if errcodes == gorm.ErrRecordNotFound {
  3150. service.CreateManufacturer(&manu)
  3151. }
  3152. }
  3153. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3154. for _, it := range manufacturerList {
  3155. if manufacturer == it.ManufacturerName {
  3156. manufacturer_id = it.ID
  3157. }
  3158. }
  3159. good.Manufacturer = manufacturer_id
  3160. if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
  3161. utils.ErrorLog("unit_id")
  3162. return
  3163. }
  3164. unit_id := int64(goodNameM["unit_id"].(float64))
  3165. if unit_id <= 0 { //名字为空则生成一条导入错误日志
  3166. err_log := models.ExportErrLog{
  3167. LogType: 5,
  3168. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3169. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
  3170. Status: 1,
  3171. CreateTime: time.Now().Unix(),
  3172. UpdateTime: time.Now().Unix(),
  3173. ExportTime: time.Now().Unix(),
  3174. }
  3175. service.CreateExportErrLog(&err_log)
  3176. continue
  3177. }
  3178. good.GoodUnit = unit_id
  3179. retail_prices := goodNameM["retail_price"].(string)
  3180. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  3181. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  3182. err_log := models.ExportErrLog{
  3183. LogType: 5,
  3184. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3185. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的价格不能为空",
  3186. Status: 1,
  3187. CreateTime: time.Now().Unix(),
  3188. UpdateTime: time.Now().Unix(),
  3189. ExportTime: time.Now().Unix(),
  3190. }
  3191. service.CreateExportErrLog(&err_log)
  3192. continue
  3193. }
  3194. good.RetailPrice = retail_price
  3195. if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
  3196. utils.ErrorLog("stock_warn_count")
  3197. return
  3198. }
  3199. stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
  3200. if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
  3201. err_log := models.ExportErrLog{
  3202. LogType: 5,
  3203. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3204. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
  3205. Status: 1,
  3206. CreateTime: time.Now().Unix(),
  3207. UpdateTime: time.Now().Unix(),
  3208. ExportTime: time.Now().Unix(),
  3209. }
  3210. service.CreateExportErrLog(&err_log)
  3211. continue
  3212. }
  3213. good.StockWarnCount = stock_warn_count
  3214. var dealer_id int64
  3215. dealerName := goodNameM["dealer"].(string)
  3216. fmt.Println("经销商", dealerName)
  3217. dealer := models.Dealer{
  3218. OrgId: orgId,
  3219. Status: 1,
  3220. DealerName: dealerName,
  3221. Creater: adminUserInfo.AdminUser.Id,
  3222. Ctime: time.Now().Unix(),
  3223. }
  3224. if len(dealerName) != 0 {
  3225. _, errcodedealer := service.GetDealerByName(orgId, dealerName)
  3226. if errcodedealer == gorm.ErrRecordNotFound {
  3227. service.CreateDealer(&dealer)
  3228. }
  3229. }
  3230. dealerList, _ := service.GetAllDealerList(orgId)
  3231. for _, it := range dealerList {
  3232. if dealerName == it.DealerName {
  3233. dealer_id = it.ID
  3234. }
  3235. }
  3236. good.Dealer = dealer_id
  3237. if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
  3238. utils.ErrorLog("pinyin")
  3239. return
  3240. }
  3241. pinyin := goodNameM["pinyin"].(string)
  3242. good.Pinyin = pinyin
  3243. if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
  3244. utils.ErrorLog("wubi")
  3245. return
  3246. }
  3247. wubi := goodNameM["wubi"].(string)
  3248. good.Wubi = wubi
  3249. buy_prices := goodNameM["buy_price"].(string)
  3250. buy_price, _ := strconv.ParseFloat(buy_prices, 64)
  3251. good.BuyPrice = buy_price
  3252. if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
  3253. utils.ErrorLog("social_security_directory_code")
  3254. return
  3255. }
  3256. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  3257. good.SocialSecurityDirectoryCode = social_security_directory_code
  3258. if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
  3259. utils.ErrorLog("is_special_diseases")
  3260. return
  3261. }
  3262. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  3263. good.IsSpecialDiseases = is_special_diseases
  3264. if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
  3265. utils.ErrorLog("is_record")
  3266. return
  3267. }
  3268. is_record := int64(goodNameM["is_record"].(float64))
  3269. good.IsRecord = is_record
  3270. if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
  3271. utils.ErrorLog("good_status")
  3272. return
  3273. }
  3274. good_status := goodNameM["good_status"].(string)
  3275. good.GoodStatus = good_status
  3276. if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
  3277. utils.ErrorLog("medical_insurance_number")
  3278. return
  3279. }
  3280. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  3281. good.MedicalInsuranceNumber = medical_insurance_number
  3282. if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
  3283. utils.ErrorLog("production_type")
  3284. return
  3285. }
  3286. production_type := goodNameM["production_type"].(string)
  3287. good.ProductionType = production_type
  3288. if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
  3289. utils.ErrorLog("remark")
  3290. return
  3291. }
  3292. remark := goodNameM["remark"].(string)
  3293. good.Remark = remark
  3294. statistics_category := goodNameM["statistics_category"].(string)
  3295. var categoryName = "统计分类"
  3296. var statistic_id int64
  3297. drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
  3298. if len(statistics_category) != 0 {
  3299. _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
  3300. if errcodecagegory == gorm.ErrRecordNotFound {
  3301. dicConfigThree, _ := service.GetLastDicConfig(drugDataConfig.ID, orgId)
  3302. dataconfig := models.DictDataconfig{
  3303. ParentId: drugDataConfig.ID,
  3304. Module: "system",
  3305. OrgId: orgId,
  3306. Name: statistics_category,
  3307. FieldName: "",
  3308. Value: dicConfigThree.Value + 1,
  3309. CreatedTime: "",
  3310. UpdatedTime: "",
  3311. CreateUserId: adminUserInfo.AdminUser.Id,
  3312. Status: 1,
  3313. Remark: "",
  3314. DeleteIdSystem: 0,
  3315. Title: "",
  3316. Content: "",
  3317. Order: 0,
  3318. Code: "",
  3319. }
  3320. service.CreatedDicConfig(&dataconfig)
  3321. }
  3322. }
  3323. parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
  3324. for _, it := range parentDataConfig {
  3325. if statistics_category == it.Name {
  3326. statistic_id = int64(it.Value)
  3327. }
  3328. }
  3329. good.StatisticsCategory = statistic_id
  3330. special_medical := goodNameM["special_medical"].(string)
  3331. good.SpecialMedical = special_medical
  3332. packing_unit := goodNameM["good_unit"].(string)
  3333. good.PackingUnit = packing_unit
  3334. goods = append(goods, &good)
  3335. }
  3336. export_time := time.Now().Unix()
  3337. errLogs, _ := service.FindPatientExportLogTwo(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3338. if len(goods) > 0 {
  3339. for _, item := range goods {
  3340. goodInfo := models.GoodInfo{
  3341. GoodName: item.GoodName,
  3342. SpecificationName: item.SpecificationName,
  3343. GoodKind: item.GoodKind,
  3344. GoodTypeId: item.GoodTypeId,
  3345. Dealer: item.Dealer,
  3346. GoodUnit: item.GoodUnit,
  3347. IsRecord: item.IsRecord,
  3348. IsSpecialDiseases: item.IsSpecialDiseases,
  3349. Manufacturer: item.Manufacturer,
  3350. Pinyin: item.Pinyin,
  3351. GoodStatus: item.GoodStatus,
  3352. ProductionType: item.ProductionType,
  3353. Remark: item.Remark,
  3354. RetailPrice: item.RetailPrice,
  3355. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3356. SpecialMedical: item.SpecialMedical,
  3357. Wubi: item.Wubi,
  3358. StockWarnCount: item.StockWarnCount,
  3359. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  3360. OrgId: orgId,
  3361. Status: 1,
  3362. Ctime: time.Now().Unix(),
  3363. StatisticsCategory: item.StatisticsCategory,
  3364. GoodCode: item.GoodCode,
  3365. BuyPrice: item.BuyPrice,
  3366. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  3367. IsUser: 2,
  3368. PackingUnit: item.PackingUnit,
  3369. PackingPrice: item.RetailPrice,
  3370. IsWarehouse: 1,
  3371. }
  3372. //查询同种耗材名称同种类型同种规格的耗材是否存在
  3373. _, errcodegood := service.GetGoodsInformaitonIsExist(item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  3374. if errcodegood == gorm.ErrRecordNotFound {
  3375. service.CreateGoodsInfomation(&goodInfo)
  3376. } else if errcodegood == nil {
  3377. service.UpdateGoodsInformation(&goodInfo, item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  3378. }
  3379. log := models.ExportLog{
  3380. LogType: 5,
  3381. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3382. TotalNum: int64(len(total_goods)),
  3383. FailNum: int64(len(errLogs)),
  3384. SuccessNum: int64(len(goods)),
  3385. CreateTime: time.Now().Unix(),
  3386. UpdateTime: time.Now().Unix(),
  3387. ExportTime: export_time,
  3388. Status: 1,
  3389. }
  3390. service.CreateExportLog(&log)
  3391. this.ServeSuccessJSON(map[string]interface{}{
  3392. "msg": "导入成功",
  3393. "total_num": len(total_goods),
  3394. "success_num": len(goods),
  3395. "fail_num": int64(len(errLogs)),
  3396. })
  3397. }
  3398. } else {
  3399. log := models.ExportLog{
  3400. LogType: 5,
  3401. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3402. TotalNum: int64(len(total_goods)),
  3403. FailNum: int64(len(errLogs)),
  3404. SuccessNum: int64(len(goods)),
  3405. CreateTime: time.Now().Unix(),
  3406. UpdateTime: time.Now().Unix(),
  3407. ExportTime: export_time,
  3408. Status: 1,
  3409. }
  3410. service.CreateExportLog(&log)
  3411. this.ServeSuccessJSON(map[string]interface{}{
  3412. "msg": "导入成功",
  3413. "total_num": len(total_goods),
  3414. "success_num": len(goods),
  3415. "fail_num": int64(len(errLogs)),
  3416. })
  3417. }
  3418. }
  3419. func (this *StockManagerApiController) AddDrugInformation() {
  3420. adminUser := this.GetAdminUserInfo()
  3421. orgId := adminUser.CurrentOrgId
  3422. dataBody := make(map[string]interface{}, 0)
  3423. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  3424. if err != nil {
  3425. utils.ErrorLog(err.Error())
  3426. return
  3427. }
  3428. utils.ErrorLog("%v", dataBody)
  3429. var drugList []*models.BaseDrugLib
  3430. var total_goods []interface{}
  3431. tempDrugs := dataBody["drugs"].([]interface{})
  3432. total_goods = tempDrugs
  3433. for index, drugMap := range tempDrugs {
  3434. goodNameM := drugMap.(map[string]interface{})
  3435. var drug models.BaseDrugLib
  3436. if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
  3437. utils.ErrorLog("drug_name")
  3438. return
  3439. }
  3440. drug_name, _ := goodNameM["drug_name"].(string)
  3441. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  3442. err_log := models.ExportErrLog{
  3443. LogType: 4,
  3444. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3445. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
  3446. Status: 1,
  3447. CreateTime: time.Now().Unix(),
  3448. UpdateTime: time.Now().Unix(),
  3449. ExportTime: time.Now().Unix(),
  3450. }
  3451. service.CreateExportErrLog(&err_log)
  3452. continue
  3453. }
  3454. drug.DrugName = drug_name
  3455. dose_unit := goodNameM["dose_unit"].(string)
  3456. drug.DoseUnit = dose_unit
  3457. if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
  3458. utils.ErrorLog("min_number")
  3459. return
  3460. }
  3461. min_number, _ := goodNameM["min_number"].(string)
  3462. minNumber, _ := strconv.ParseInt(min_number, 10, 64)
  3463. if len(min_number) == 0 { //名字为空则生成一条导入错误日志
  3464. err_log := models.ExportErrLog{
  3465. LogType: 4,
  3466. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3467. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
  3468. Status: 1,
  3469. CreateTime: time.Now().Unix(),
  3470. UpdateTime: time.Now().Unix(),
  3471. ExportTime: time.Now().Unix(),
  3472. }
  3473. service.CreateExportErrLog(&err_log)
  3474. continue
  3475. }
  3476. drug.MinNumber = minNumber
  3477. min_unit := goodNameM["min_unit"].(string)
  3478. if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
  3479. err_log := models.ExportErrLog{
  3480. LogType: 4,
  3481. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3482. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
  3483. Status: 1,
  3484. CreateTime: time.Now().Unix(),
  3485. UpdateTime: time.Now().Unix(),
  3486. ExportTime: time.Now().Unix(),
  3487. }
  3488. service.CreateExportErrLog(&err_log)
  3489. continue
  3490. }
  3491. drug.MinUnit = min_unit
  3492. max_unit_id := goodNameM["max_unit"].(string)
  3493. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  3494. err_log := models.ExportErrLog{
  3495. LogType: 4,
  3496. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3497. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  3498. Status: 1,
  3499. CreateTime: time.Now().Unix(),
  3500. UpdateTime: time.Now().Unix(),
  3501. ExportTime: time.Now().Unix(),
  3502. }
  3503. service.CreateExportErrLog(&err_log)
  3504. continue
  3505. }
  3506. drug.MaxUnit = max_unit_id
  3507. max_unit := goodNameM["max_unit"].(string)
  3508. if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
  3509. err_log := models.ExportErrLog{
  3510. LogType: 4,
  3511. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3512. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
  3513. Status: 1,
  3514. CreateTime: time.Now().Unix(),
  3515. UpdateTime: time.Now().Unix(),
  3516. ExportTime: time.Now().Unix(),
  3517. }
  3518. service.CreateExportErrLog(&err_log)
  3519. continue
  3520. }
  3521. drug.MaxUnit = max_unit
  3522. drug_type := goodNameM["drug_type"].(string)
  3523. if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
  3524. err_log := models.ExportErrLog{
  3525. LogType: 4,
  3526. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3527. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
  3528. Status: 1,
  3529. CreateTime: time.Now().Unix(),
  3530. UpdateTime: time.Now().Unix(),
  3531. ExportTime: time.Now().Unix(),
  3532. }
  3533. service.CreateExportErrLog(&err_log)
  3534. continue
  3535. }
  3536. var drug_type_id int64
  3537. var drugType = "药品类型"
  3538. drugconfig, _ := service.GetDrugDataConfig(0, drugType)
  3539. if len(drug_type) != 0 {
  3540. _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
  3541. if errcodes == gorm.ErrRecordNotFound {
  3542. //获取该型号最后一条数据型号
  3543. config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
  3544. dataconfig := models.DictDataconfig{
  3545. ParentId: drugconfig.ID,
  3546. Module: "system",
  3547. OrgId: orgId,
  3548. Name: drug_type,
  3549. FieldName: "",
  3550. Value: config.Value + 1,
  3551. CreatedTime: "",
  3552. UpdatedTime: "",
  3553. CreateUserId: adminUser.AdminUser.Id,
  3554. Status: 1,
  3555. Remark: "",
  3556. DeleteIdSystem: 0,
  3557. Title: "",
  3558. Content: "",
  3559. Order: 0,
  3560. Code: "",
  3561. }
  3562. service.CreatedDicConfig(&dataconfig)
  3563. }
  3564. }
  3565. drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
  3566. for _, it := range drugTypeList {
  3567. if drug_type == it.Name {
  3568. drug_type_id = int64(it.Value)
  3569. }
  3570. }
  3571. drug.DrugType = drug_type_id
  3572. drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
  3573. if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
  3574. err_log := models.ExportErrLog{
  3575. LogType: 4,
  3576. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3577. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
  3578. Status: 1,
  3579. CreateTime: time.Now().Unix(),
  3580. UpdateTime: time.Now().Unix(),
  3581. ExportTime: time.Now().Unix(),
  3582. }
  3583. service.CreateExportErrLog(&err_log)
  3584. continue
  3585. }
  3586. drug.DrugStockLimit = drug_stock_limit
  3587. drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
  3588. if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
  3589. err_log := models.ExportErrLog{
  3590. LogType: 4,
  3591. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3592. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
  3593. Status: 1,
  3594. CreateTime: time.Now().Unix(),
  3595. UpdateTime: time.Now().Unix(),
  3596. ExportTime: time.Now().Unix(),
  3597. }
  3598. service.CreateExportErrLog(&err_log)
  3599. continue
  3600. }
  3601. drug.DrugOriginPlace = drug_origin_place
  3602. drug_dosage_form := goodNameM["drug_dosage_form"].(string)
  3603. if len(drug_dosage_form) == 0 {
  3604. err_log := models.ExportErrLog{
  3605. LogType: 4,
  3606. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3607. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
  3608. Status: 1,
  3609. CreateTime: time.Now().Unix(),
  3610. UpdateTime: time.Now().Unix(),
  3611. ExportTime: time.Now().Unix(),
  3612. }
  3613. service.CreateExportErrLog(&err_log)
  3614. continue
  3615. }
  3616. var drug_dosage = "药品剂型"
  3617. var drug_dosage_form_id int64
  3618. drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
  3619. if len(drug_dosage_form) != 0 {
  3620. _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
  3621. if errcodess == gorm.ErrRecordNotFound {
  3622. configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
  3623. dataconfig := models.DictDataconfig{
  3624. ParentId: drugDosageconfig.ID,
  3625. Module: "system",
  3626. OrgId: orgId,
  3627. Name: drug_dosage_form,
  3628. FieldName: "",
  3629. Value: configOne.Value + 1,
  3630. CreatedTime: "",
  3631. UpdatedTime: "",
  3632. CreateUserId: adminUser.AdminUser.Id,
  3633. Status: 1,
  3634. Remark: "",
  3635. DeleteIdSystem: 0,
  3636. Title: "",
  3637. Content: "",
  3638. Order: 0,
  3639. Code: "",
  3640. }
  3641. service.CreatedDicConfig(&dataconfig)
  3642. }
  3643. }
  3644. drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
  3645. for _, it := range drugDosageList {
  3646. if drug_dosage_form == it.Name {
  3647. drug_dosage_form_id = int64(it.Value)
  3648. }
  3649. }
  3650. drug.DrugDosageForm = drug_dosage_form_id
  3651. retail_prices := goodNameM["retail_price"].(string)
  3652. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  3653. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  3654. err_log := models.ExportErrLog{
  3655. LogType: 4,
  3656. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3657. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
  3658. Status: 1,
  3659. CreateTime: time.Now().Unix(),
  3660. UpdateTime: time.Now().Unix(),
  3661. ExportTime: time.Now().Unix(),
  3662. }
  3663. service.CreateExportErrLog(&err_log)
  3664. continue
  3665. }
  3666. drug.RetailPrice = retail_price
  3667. last_prices := goodNameM["last_price"].(string)
  3668. last_price, _ := strconv.ParseFloat(last_prices, 64)
  3669. if last_price <= 0 { //名字为空则生成一条导入错误日志
  3670. err_log := models.ExportErrLog{
  3671. LogType: 4,
  3672. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3673. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
  3674. Status: 1,
  3675. CreateTime: time.Now().Unix(),
  3676. UpdateTime: time.Now().Unix(),
  3677. ExportTime: time.Now().Unix(),
  3678. }
  3679. service.CreateExportErrLog(&err_log)
  3680. continue
  3681. }
  3682. drug.LastPrice = last_price
  3683. drug_classify := goodNameM["drug_classify"].(string)
  3684. if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
  3685. err_log := models.ExportErrLog{
  3686. LogType: 4,
  3687. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3688. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
  3689. Status: 1,
  3690. CreateTime: time.Now().Unix(),
  3691. UpdateTime: time.Now().Unix(),
  3692. ExportTime: time.Now().Unix(),
  3693. }
  3694. service.CreateExportErrLog(&err_log)
  3695. continue
  3696. }
  3697. var drugClassify = "药物分类"
  3698. var drug_classify_id int64
  3699. drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
  3700. if len(drug_classify) != 0 {
  3701. _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
  3702. if errcodesClass == gorm.ErrRecordNotFound {
  3703. drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
  3704. dataconfig := models.DictDataconfig{
  3705. ParentId: drugClassifyConfig.ID,
  3706. Module: "system",
  3707. OrgId: orgId,
  3708. Name: drug_classify,
  3709. FieldName: "",
  3710. Value: drugClassConfig.Value + 1,
  3711. CreatedTime: "",
  3712. UpdatedTime: "",
  3713. CreateUserId: adminUser.AdminUser.Id,
  3714. Status: 1,
  3715. Remark: "",
  3716. DeleteIdSystem: 0,
  3717. Title: "",
  3718. Content: "",
  3719. Order: 0,
  3720. Code: "",
  3721. }
  3722. service.CreatedDicConfig(&dataconfig)
  3723. }
  3724. }
  3725. drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
  3726. for _, it := range drugClassList {
  3727. if drug_classify == it.Name {
  3728. drug_classify_id = int64(it.Value)
  3729. }
  3730. }
  3731. drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
  3732. drug_dose := goodNameM["drug_dose"].(string)
  3733. if len(drug_dose) == 0 {
  3734. err_log := models.ExportErrLog{
  3735. LogType: 4,
  3736. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3737. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
  3738. Status: 1,
  3739. CreateTime: time.Now().Unix(),
  3740. UpdateTime: time.Now().Unix(),
  3741. ExportTime: time.Now().Unix(),
  3742. }
  3743. service.CreateExportErrLog(&err_log)
  3744. continue
  3745. }
  3746. drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
  3747. drug.DrugDose = drugDoses
  3748. var units = "单位"
  3749. var unit_id int64
  3750. drugDoseUnit := goodNameM["drug_dose_unit"].(string)
  3751. if len(drugDoseUnit) == 0 {
  3752. err_log := models.ExportErrLog{
  3753. LogType: 4,
  3754. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3755. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
  3756. Status: 1,
  3757. CreateTime: time.Now().Unix(),
  3758. UpdateTime: time.Now().Unix(),
  3759. ExportTime: time.Now().Unix(),
  3760. }
  3761. service.CreateExportErrLog(&err_log)
  3762. continue
  3763. }
  3764. manufacturer := goodNameM["manufacturer"].(string)
  3765. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  3766. err_log := models.ExportErrLog{
  3767. LogType: 4,
  3768. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3769. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
  3770. Status: 1,
  3771. CreateTime: time.Now().Unix(),
  3772. UpdateTime: time.Now().Unix(),
  3773. ExportTime: time.Now().Unix(),
  3774. }
  3775. service.CreateExportErrLog(&err_log)
  3776. continue
  3777. }
  3778. if len(manufacturer) != 0 {
  3779. _, errcodema := service.GetManufacturerName(orgId, manufacturer)
  3780. if errcodema == gorm.ErrRecordNotFound {
  3781. manufactur := models.Manufacturer{
  3782. OrgId: orgId,
  3783. Status: 1,
  3784. ManufacturerName: manufacturer,
  3785. Ctime: time.Now().Unix(),
  3786. Creater: adminUser.AdminUser.Id,
  3787. }
  3788. service.CreateManufacturer(&manufactur)
  3789. }
  3790. }
  3791. var manufacturer_id int64
  3792. manufacturList, _ := service.GetAllManufacturerList(orgId)
  3793. for _, it := range manufacturList {
  3794. if manufacturer == it.ManufacturerName {
  3795. manufacturer_id = it.ID
  3796. }
  3797. }
  3798. drug.Manufacturer = manufacturer_id
  3799. dealer := goodNameM["dealer"].(string)
  3800. if len(dealer) != 0 {
  3801. _, errcodesdealer := service.GetDealerByName(orgId, dealer)
  3802. if errcodesdealer == gorm.ErrRecordNotFound {
  3803. dealerconfig := models.Dealer{
  3804. DealerName: dealer,
  3805. Status: 1,
  3806. OrgId: orgId,
  3807. Ctime: time.Now().Unix(),
  3808. Creater: adminUser.AdminUser.Id,
  3809. }
  3810. service.CreateDealer(&dealerconfig)
  3811. }
  3812. }
  3813. var dealer_id int64
  3814. dealerList, _ := service.GetAllDealerList(orgId)
  3815. for _, it := range dealerList {
  3816. if dealer == it.DealerName {
  3817. dealer_id = it.ID
  3818. }
  3819. }
  3820. drug.Dealer = dealer_id
  3821. delivery_way := goodNameM["delivery_way"].(string)
  3822. drug.DeliveryWay = delivery_way
  3823. execution_frequency := goodNameM["execution_frequency"].(string)
  3824. drug.ExecutionFrequency = execution_frequency
  3825. lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
  3826. drug.LmtUsedFlag = lmt_used_flags
  3827. dataConfig, _ := service.GetDataConfigIsExist(0, units)
  3828. if len(drugDoseUnit) != 0 {
  3829. _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
  3830. if errcodedataconfig == gorm.ErrRecordNotFound {
  3831. childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
  3832. dataconfig := models.Dataconfig{
  3833. ParentId: dataConfig.ID,
  3834. Module: "hemodialysis",
  3835. OrgId: orgId,
  3836. Name: drugDoseUnit,
  3837. FieldName: "",
  3838. Value: childConfig.Value + 1,
  3839. CreatedTime: "",
  3840. UpdatedTime: "",
  3841. CreateUserId: adminUser.AdminUser.Id,
  3842. Status: 1,
  3843. Remark: "",
  3844. DeleteIdSystem: 0,
  3845. Title: "",
  3846. Content: "",
  3847. Order: 0,
  3848. Code: "",
  3849. FieldType: 0,
  3850. }
  3851. service.CreateDataConfig(&dataconfig)
  3852. }
  3853. }
  3854. list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
  3855. for _, it := range list {
  3856. if drugDoseUnit == it.Name {
  3857. unit_id = int64(it.Value)
  3858. }
  3859. }
  3860. drug.DrugDoseUnit = unit_id
  3861. if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
  3862. utils.ErrorLog("drug_alias")
  3863. return
  3864. }
  3865. drug_alias, _ := goodNameM["drug_alias"].(string)
  3866. drug.DrugAlias = drug_alias
  3867. drug_category := goodNameM["drug_category"].(string)
  3868. var drugCategory = "药品类别"
  3869. var drug_category_id int64
  3870. drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
  3871. if len(drug_category) != 0 {
  3872. _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
  3873. if drugcategoryerrcodes == gorm.ErrRecordNotFound {
  3874. drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
  3875. dataconfig := models.DictDataconfig{
  3876. ParentId: drugCategoryConfig.ID,
  3877. Module: "system",
  3878. OrgId: orgId,
  3879. Name: drug_category,
  3880. FieldName: "",
  3881. Value: drugCategoryConfigSix.Value + 1,
  3882. CreatedTime: "",
  3883. UpdatedTime: "",
  3884. CreateUserId: adminUser.AdminUser.Id,
  3885. Status: 1,
  3886. Remark: "",
  3887. DeleteIdSystem: 0,
  3888. Title: "",
  3889. Content: "",
  3890. Order: 0,
  3891. Code: "",
  3892. }
  3893. service.CreatedDicConfig(&dataconfig)
  3894. }
  3895. }
  3896. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
  3897. fmt.Println("drugCategoryList", drugCategoryList)
  3898. for _, it := range drugCategoryList {
  3899. if drug_category == it.Name {
  3900. drug_category_id = int64(it.Value)
  3901. }
  3902. }
  3903. drug.DrugCategory = drug_category_id
  3904. statistics_category := goodNameM["statistics_category"].(string)
  3905. var statisticsCategory = "统计分类"
  3906. var statistics_category_id int64
  3907. statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3908. if len(statistics_category) != 0 {
  3909. _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
  3910. if errcodestatistc == gorm.ErrRecordNotFound {
  3911. staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
  3912. dataconfig := models.DictDataconfig{
  3913. ParentId: statistcConfig.ID,
  3914. Module: "system",
  3915. OrgId: orgId,
  3916. Name: statistics_category,
  3917. FieldName: "",
  3918. Value: staConfig.Value + 1,
  3919. CreatedTime: "",
  3920. UpdatedTime: "",
  3921. CreateUserId: adminUser.AdminUser.Id,
  3922. Status: 1,
  3923. Remark: "",
  3924. DeleteIdSystem: 0,
  3925. Title: "",
  3926. Content: "",
  3927. Order: 0,
  3928. Code: "",
  3929. }
  3930. service.CreatedDicConfig(&dataconfig)
  3931. }
  3932. }
  3933. statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
  3934. for _, it := range statisticsCategoryList {
  3935. if statistics_category == it.Name {
  3936. statistics_category_id = int64(it.Value)
  3937. }
  3938. }
  3939. drug.StatisticsCategory = statistics_category_id
  3940. hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
  3941. drug.HospApprFlag = hosp_appr_flag
  3942. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  3943. drug.MedicalInsuranceNumber = medical_insurance_number
  3944. pharmacology_category := goodNameM["pharmacology_category"].(string)
  3945. var pharmacology = "药理分类"
  3946. var pharmacology_category_id int64
  3947. pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
  3948. if len(pharmacology_category) != 0 {
  3949. _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
  3950. if errcodespharmacology == gorm.ErrRecordNotFound {
  3951. dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
  3952. dataconfig := models.DictDataconfig{
  3953. ParentId: pharmacologyConfig.ID,
  3954. Module: "system",
  3955. OrgId: orgId,
  3956. Name: pharmacology_category,
  3957. FieldName: "",
  3958. Value: dicConfig.Value + 1,
  3959. CreatedTime: "",
  3960. UpdatedTime: "",
  3961. CreateUserId: adminUser.AdminUser.Id,
  3962. Status: 1,
  3963. Remark: "",
  3964. DeleteIdSystem: 0,
  3965. Title: "",
  3966. Content: "",
  3967. Order: 0,
  3968. Code: "",
  3969. }
  3970. service.CreatedDicConfig(&dataconfig)
  3971. }
  3972. }
  3973. pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
  3974. for _, it := range pharmacologyList {
  3975. if pharmacology_category == it.Name {
  3976. pharmacology_category_id = int64(it.Value)
  3977. }
  3978. }
  3979. drug.PharmacologyCategory = pharmacology_category_id
  3980. code := goodNameM["code"].(string)
  3981. drug.Code = code
  3982. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  3983. drug.IsSpecialDiseases = is_special_diseases
  3984. is_record := int64(goodNameM["is_record"].(float64))
  3985. drug.IsRecord = is_record
  3986. prescription_mark := int64(goodNameM["prescription_mark"].(float64))
  3987. drug.PrescriptionMark = prescription_mark
  3988. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  3989. drug.SocialSecurityDirectoryCode = social_security_directory_code
  3990. record_date := goodNameM["record_date"].(string)
  3991. timeLayout := "2006-01-02"
  3992. loc, _ := time.LoadLocation("Local")
  3993. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3994. drug.RecordDate = theTime.Unix()
  3995. drug_remark := goodNameM["drug_remark"].(string)
  3996. drug.DrugRemark = drug_remark
  3997. drug_status := goodNameM["drug_status"].(string)
  3998. drug.DrugStatus = drug_status
  3999. limit_remark := goodNameM["limit_remark"].(string)
  4000. drug.LimitRemark = limit_remark
  4001. min_prices := goodNameM["min_price"].(string)
  4002. min_price, _ := strconv.ParseFloat(min_prices, 64)
  4003. drug.MinPrice = min_price
  4004. dose := goodNameM["dose"].(string)
  4005. //dose, _ := strconv.ParseFloat(doses, 64)
  4006. if len(dose) < 0 { //名字为空则生成一条导入错误日志
  4007. err_log := models.ExportErrLog{
  4008. LogType: 4,
  4009. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4010. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  4011. Status: 1,
  4012. CreateTime: time.Now().Unix(),
  4013. UpdateTime: time.Now().Unix(),
  4014. ExportTime: time.Now().Unix(),
  4015. }
  4016. service.CreateExportErrLog(&err_log)
  4017. continue
  4018. }
  4019. drug.Dose = dose
  4020. if len(dose) < 0 { //名字为空则生成一条导入错误日志
  4021. err_log := models.ExportErrLog{
  4022. LogType: 4,
  4023. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4024. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  4025. Status: 1,
  4026. CreateTime: time.Now().Unix(),
  4027. UpdateTime: time.Now().Unix(),
  4028. ExportTime: time.Now().Unix(),
  4029. }
  4030. service.CreateExportErrLog(&err_log)
  4031. continue
  4032. }
  4033. drugList = append(drugList, &drug)
  4034. }
  4035. export_time := time.Now().Unix()
  4036. errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
  4037. if len(drugList) > 0 {
  4038. for _, item := range drugList {
  4039. fmt.Println("retial2332332233232323223322323", item.DoseUnit)
  4040. goodInfo := models.BaseDrugLib{
  4041. DrugName: item.DrugName,
  4042. DrugAlias: item.DrugAlias,
  4043. DrugSpec: item.DrugSpec,
  4044. DrugType: item.DrugType,
  4045. DrugStockLimit: item.DrugStockLimit,
  4046. DrugOriginPlace: item.DrugOriginPlace,
  4047. DrugDosageForm: item.DrugDosageForm,
  4048. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  4049. MaxUnit: item.MaxUnit,
  4050. MinUnit: item.MinUnit,
  4051. UnitMatrixing: item.UnitMatrixing,
  4052. RetailPrice: item.RetailPrice,
  4053. LastPrice: item.LastPrice,
  4054. DrugClassify: item.DrugClassify,
  4055. Manufacturer: item.Manufacturer,
  4056. Dealer: item.Dealer,
  4057. OrgId: orgId,
  4058. Status: 1,
  4059. Ctime: time.Now().Unix(),
  4060. Pinyin: item.Pinyin,
  4061. Wubi: item.Wubi,
  4062. DrugAliasPinyin: item.DrugAliasPinyin,
  4063. DrugAliasWubi: item.DrugAliasWubi,
  4064. DrugControl: item.DrugControl,
  4065. Number: item.Number,
  4066. HospApprFlag: item.HospApprFlag,
  4067. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  4068. PharmacologyCategory: item.PharmacologyCategory,
  4069. StatisticsCategory: item.StatisticsCategory,
  4070. Code: item.Code,
  4071. IsSpecialDiseases: item.IsSpecialDiseases,
  4072. IsRecord: item.IsRecord,
  4073. PrescriptionMark: item.PrescriptionMark,
  4074. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  4075. RecordDate: item.RecordDate,
  4076. DrugRemark: item.DrugRemark,
  4077. DrugStatus: item.DrugStatus,
  4078. LimitRemark: item.LimitRemark,
  4079. DrugCategory: item.DrugCategory,
  4080. DrugDose: item.DrugDose,
  4081. DrugDoseUnit: item.DrugDoseUnit,
  4082. LmtUsedFlag: item.LmtUsedFlag,
  4083. DrugDay: item.DrugDay,
  4084. DeliveryWay: item.DeliveryWay,
  4085. ExecutionFrequency: item.ExecutionFrequency,
  4086. DoseUnit: item.DoseUnit,
  4087. Dose: item.Dose,
  4088. MinNumber: item.MinNumber,
  4089. IsUse: 2,
  4090. MinPrice: item.MinPrice,
  4091. }
  4092. //查询同种药品同种规格是否存在
  4093. _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.DoseUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
  4094. if drugerror == gorm.ErrRecordNotFound {
  4095. service.CreateDrugsInfomation(&goodInfo)
  4096. } else if drugerror == nil {
  4097. service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
  4098. }
  4099. log := models.ExportLog{
  4100. LogType: 4,
  4101. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4102. TotalNum: int64(len(total_goods)),
  4103. FailNum: int64(len(errLogs)),
  4104. SuccessNum: int64(len(drugList)),
  4105. CreateTime: time.Now().Unix(),
  4106. UpdateTime: time.Now().Unix(),
  4107. ExportTime: export_time,
  4108. Status: 1,
  4109. }
  4110. service.CreateExportLog(&log)
  4111. this.ServeSuccessJSON(map[string]interface{}{
  4112. "msg": "导入成功",
  4113. "total_num": len(total_goods),
  4114. "success_num": len(drugList),
  4115. "fail_num": int64(len(errLogs)),
  4116. })
  4117. }
  4118. } else {
  4119. log := models.ExportLog{
  4120. LogType: 4,
  4121. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4122. TotalNum: int64(len(total_goods)),
  4123. FailNum: int64(len(errLogs)),
  4124. SuccessNum: int64(len(drugList)),
  4125. CreateTime: time.Now().Unix(),
  4126. UpdateTime: time.Now().Unix(),
  4127. ExportTime: export_time,
  4128. Status: 1,
  4129. }
  4130. service.CreateExportLog(&log)
  4131. this.ServeSuccessJSON(map[string]interface{}{
  4132. "msg": "导入成功",
  4133. "total_num": len(total_goods),
  4134. "success_num": len(drugList),
  4135. "fail_num": int64(len(errLogs)),
  4136. })
  4137. }
  4138. }
  4139. func (this *StockManagerApiController) GetInitializtion() {
  4140. orgId := this.GetAdminUserInfo().CurrentOrgId
  4141. var drugCategory = "药品类别"
  4142. var drugType = "药品类型"
  4143. var drugDosageForm = "药品剂型"
  4144. var medicalInsuranceLevel = "医保等级"
  4145. var drugControl = "开药控制"
  4146. var drugClassify = "药物分类"
  4147. var statisticsCategory = "统计分类"
  4148. var pharmacologyCategory = "药理分类"
  4149. var goodKind = "耗材种类"
  4150. var tubeColor = "试管颜色"
  4151. var costClassify = "费用类别"
  4152. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  4153. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  4154. drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
  4155. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
  4156. drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
  4157. drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
  4158. medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
  4159. medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
  4160. drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
  4161. drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
  4162. drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
  4163. drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
  4164. statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
  4165. statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
  4166. pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
  4167. pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
  4168. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  4169. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
  4170. tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
  4171. tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
  4172. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  4173. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
  4174. this.ServeSuccessJSON(map[string]interface{}{
  4175. "drugCategoryList": drugCategoryList,
  4176. "drugTypeList": drugTypeList,
  4177. "drugDosageFormList": drugDosageFormList,
  4178. "medicalInsuranceLevelList": medicalInsuranceLevelList,
  4179. "drugControlList": drugControlList,
  4180. "drugClassifyList": drugClassifyList,
  4181. "statisticsCategoryList": statisticsCategoryList,
  4182. "pharmacologyCategoryList": pharmacologyCategoryList,
  4183. "goodKindList": goodKindList,
  4184. "tubeColorList": tubeColorList,
  4185. "costClassifyList": costClassifyList,
  4186. })
  4187. }
  4188. func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
  4189. adminUserInfo := this.GetAdminUserInfo()
  4190. orgId := adminUserInfo.CurrentOrgId
  4191. list, _ := service.GetWarehouseOrderInfoList(orgId)
  4192. this.ServeSuccessJSON(map[string]interface{}{
  4193. "list": list,
  4194. })
  4195. }
  4196. func (this *StockManagerApiController) PostSearchGoodList() {
  4197. keyword := this.GetString("keyword")
  4198. adminUserInfo := this.GetAdminUserInfo()
  4199. orgId := adminUserInfo.CurrentOrgId
  4200. storehouse_id, _ := this.GetInt64("storehouse_id")
  4201. list, _ := service.GetSearchGoodListSix(keyword, orgId, storehouse_id)
  4202. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4203. dealerList, _ := service.GetAllDealerList(orgId)
  4204. this.ServeSuccessJSON(map[string]interface{}{
  4205. "list": list,
  4206. "manufacturerList": manufacturerList,
  4207. "dealerList": dealerList,
  4208. })
  4209. }
  4210. func (this *StockManagerApiController) GetAllStockList() {
  4211. page, _ := this.GetInt64("page", -1)
  4212. limit, _ := this.GetInt64("limit", -1)
  4213. start_time := this.GetString("start_time")
  4214. end_time := this.GetString("end_time")
  4215. types, _ := this.GetInt64("type", 0)
  4216. keywords := this.GetString("keywords")
  4217. good_id, _ := this.GetInt64("good_id")
  4218. storehouse_id, _ := this.GetInt64("storehouse_id")
  4219. timeLayout := "2006-01-02"
  4220. loc, _ := time.LoadLocation("Local")
  4221. var startTime int64
  4222. if len(start_time) > 0 {
  4223. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4224. if err != nil {
  4225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4226. return
  4227. }
  4228. startTime = theTime.Unix()
  4229. }
  4230. var endTime int64
  4231. if len(end_time) > 0 {
  4232. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4233. if err != nil {
  4234. utils.ErrorLog(err.Error())
  4235. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4236. return
  4237. }
  4238. endTime = theTime.Unix()
  4239. }
  4240. adminUserInfo := this.GetAdminUserInfo()
  4241. orgId := adminUserInfo.CurrentOrgId
  4242. list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId, good_id, storehouse_id)
  4243. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4244. this.ServeSuccessJSON(map[string]interface{}{
  4245. "list": list,
  4246. "total": total,
  4247. "manufacturerList": manufacturerList,
  4248. })
  4249. }
  4250. func (this *StockManagerApiController) GetStockListById() {
  4251. id, _ := this.GetInt64("id")
  4252. adminUserInfo := this.GetAdminUserInfo()
  4253. orgId := adminUserInfo.CurrentOrgId
  4254. limit, _ := this.GetInt64("limit")
  4255. page, _ := this.GetInt64("page")
  4256. timeLayout := "2006-01-02"
  4257. loc, _ := time.LoadLocation("Local")
  4258. start_time := this.GetString("start_time")
  4259. end_time := this.GetString("end_time")
  4260. start_first_time := this.GetString("start_first_time")
  4261. end_first_time := this.GetString("end_first_time")
  4262. var startTime int64
  4263. if len(start_time) > 0 {
  4264. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4265. if err != nil {
  4266. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4267. return
  4268. }
  4269. startTime = theTime.Unix()
  4270. }
  4271. var endTime int64
  4272. if len(end_time) > 0 {
  4273. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4274. if err != nil {
  4275. utils.ErrorLog(err.Error())
  4276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4277. return
  4278. }
  4279. endTime = theTime.Unix()
  4280. }
  4281. var startFistTime int64
  4282. if len(start_first_time) > 0 {
  4283. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_first_time+" 00:00:00", loc)
  4284. if err != nil {
  4285. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4286. return
  4287. }
  4288. startFistTime = theTime.Unix()
  4289. }
  4290. var endFirstTime int64
  4291. if len(end_first_time) > 0 {
  4292. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_first_time+" 23:59:59", loc)
  4293. if err != nil {
  4294. utils.ErrorLog(err.Error())
  4295. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4296. return
  4297. }
  4298. endFirstTime = theTime.Unix()
  4299. }
  4300. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4301. list, total, _ := service.GetStockListById(id, orgId, limit, page, startTime, endTime, startFistTime, endFirstTime)
  4302. houseList, _ := service.GetAllStoreHouseList(orgId)
  4303. good, _ := service.GetGoodInformationByGoodId(id)
  4304. this.ServeSuccessJSON(map[string]interface{}{
  4305. "list": list,
  4306. "total": total,
  4307. "manufacturerList": manufacturerList,
  4308. "houseList": houseList,
  4309. "good": good,
  4310. })
  4311. }
  4312. func (this *StockManagerApiController) GetStockOutList() {
  4313. id, _ := this.GetInt64("id")
  4314. adminUserInfo := this.GetAdminUserInfo()
  4315. orgId := adminUserInfo.CurrentOrgId
  4316. limit, _ := this.GetInt64("limit")
  4317. page, _ := this.GetInt64("page")
  4318. timeLayout := "2006-01-02"
  4319. loc, _ := time.LoadLocation("Local")
  4320. start_time := this.GetString("start_time")
  4321. end_time := this.GetString("end_time")
  4322. is_sys, _ := this.GetInt64("is_sys")
  4323. var startTime int64
  4324. if len(start_time) > 0 {
  4325. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4326. if err != nil {
  4327. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4328. return
  4329. }
  4330. startTime = theTime.Unix()
  4331. }
  4332. var endTime int64
  4333. if len(end_time) > 0 {
  4334. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4335. if err != nil {
  4336. utils.ErrorLog(err.Error())
  4337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4338. return
  4339. }
  4340. endTime = theTime.Unix()
  4341. }
  4342. outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
  4343. this.ServeSuccessJSON(map[string]interface{}{
  4344. "outList": outList,
  4345. "total": total,
  4346. })
  4347. }
  4348. func (this *StockManagerApiController) GetStockDrugCount() {
  4349. adminUserInfo := this.GetAdminUserInfo()
  4350. orgId := adminUserInfo.CurrentOrgId
  4351. fmt.Println(orgId)
  4352. timeLayout := "2006-01-02"
  4353. loc, _ := time.LoadLocation("Local")
  4354. start_time := this.GetString("start_time")
  4355. end_time := this.GetString("end_time")
  4356. var startTime int64
  4357. if len(start_time) > 0 {
  4358. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4359. if err != nil {
  4360. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4361. return
  4362. }
  4363. startTime = theTime.Unix()
  4364. }
  4365. var endTime int64
  4366. if len(end_time) > 0 {
  4367. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4368. if err != nil {
  4369. utils.ErrorLog(err.Error())
  4370. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4371. return
  4372. }
  4373. endTime = theTime.Unix()
  4374. }
  4375. count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
  4376. outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
  4377. autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
  4378. totalCount, _ := service.GetCancelOutTotalCount(startTime, endTime, orgId)
  4379. this.ServeSuccessJSON(map[string]interface{}{
  4380. "count": count,
  4381. "outList": outList,
  4382. "autoCount": autoCount,
  4383. "totalCount": totalCount,
  4384. })
  4385. }
  4386. func (this *StockManagerApiController) GetOrderDetialByOrderId() {
  4387. ids := this.GetString("id")
  4388. idsArray := strings.Split(ids, ",")
  4389. orgId := this.GetAdminUserInfo().CurrentOrgId
  4390. order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
  4391. list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
  4392. stockFlowListGroup, _ := service.GetOrderDetailStockFlowByStorehouseById(idsArray, orgId)
  4393. stockFlowList, _ := service.GetOrderDetailStockFlow(idsArray, orgId)
  4394. //获取耗材退库数据
  4395. cancelInfolist, _ := service.GetOrderStockFlow(idsArray, orgId)
  4396. this.ServeSuccessJSON(map[string]interface{}{
  4397. "list": list,
  4398. "order": order,
  4399. "stockFlowList": stockFlowList,
  4400. "stockFlowListGroup": stockFlowListGroup,
  4401. "cancelInfolist": cancelInfolist,
  4402. })
  4403. }
  4404. func (this *StockManagerApiController) GetOrderDetailById() {
  4405. id, _ := this.GetInt64("id")
  4406. good_id, _ := this.GetInt64("good_id")
  4407. record_time, _ := this.GetInt64("record_time")
  4408. orgId := this.GetAdminUserInfo().CurrentOrgId
  4409. //自动出库
  4410. userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
  4411. //手动出库
  4412. info, _ := service.GetWarehouseOutInfoById(id, good_id)
  4413. //出库数据
  4414. stockFlowList, err := service.GetStockFlowBatchNumberOne(id, good_id)
  4415. //退库数据
  4416. cancelInfo, err := service.GetStockFlowCancelInfo(id, good_id)
  4417. if err == nil {
  4418. this.ServeSuccessJSON(map[string]interface{}{
  4419. "list": userDetails,
  4420. "total": total,
  4421. "info": info,
  4422. "stockFlowList": stockFlowList,
  4423. "cancelInfo": cancelInfo,
  4424. })
  4425. } else {
  4426. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4427. return
  4428. }
  4429. }
  4430. func (this *StockManagerApiController) GetSingleOutOrderDetail() {
  4431. id, _ := this.GetInt64("id", 0)
  4432. orgId := this.GetAdminUserInfo().CurrentOrgId
  4433. warehouseOutInfo, _ := service.GetOrderDetialByOrderId(id, orgId)
  4434. out, _ := service.GetGoodWarehouseOutById(id, orgId)
  4435. storelist, _ := service.GetAllStoreHouseList(orgId)
  4436. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4437. dealerList, _ := service.GetAllDealerList(orgId)
  4438. goodType, _ := service.GetAllGoodType(orgId)
  4439. appId := this.GetAdminUserInfo().CurrentAppId
  4440. doctorlist, _ := service.GetAllDoctorListSix(orgId, appId)
  4441. this.ServeSuccessJSON(map[string]interface{}{
  4442. "list": warehouseOutInfo,
  4443. "dealerList": dealerList,
  4444. "manufacturerList": manufacturerList,
  4445. "goodType": goodType,
  4446. "out": out,
  4447. "storelist": storelist,
  4448. "doctorlist": doctorlist,
  4449. })
  4450. }
  4451. func (this *StockManagerApiController) GetExprotStockList() {
  4452. adminUserInfo := this.GetAdminUserInfo()
  4453. orgId := adminUserInfo.CurrentOrgId
  4454. timeLayout := "2006-01-02"
  4455. loc, _ := time.LoadLocation("Local")
  4456. start_time := this.GetString("start_time")
  4457. end_time := this.GetString("end_time")
  4458. storehouse_id, _ := this.GetInt64("storehouse_id")
  4459. idArray := this.GetString("id")
  4460. ids := strings.Split(idArray, ",")
  4461. var startTime int64
  4462. if len(start_time) > 0 {
  4463. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4464. if err != nil {
  4465. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4466. return
  4467. }
  4468. startTime = theTime.Unix()
  4469. }
  4470. var endTime int64
  4471. if len(end_time) > 0 {
  4472. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4473. if err != nil {
  4474. utils.ErrorLog(err.Error())
  4475. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4476. return
  4477. }
  4478. endTime = theTime.Unix()
  4479. }
  4480. list, _ := service.GetExprotStockListTwenty(orgId, ids, startTime, endTime, storehouse_id)
  4481. this.ServeSuccessJSON(map[string]interface{}{
  4482. "list": list,
  4483. })
  4484. }
  4485. func (this *StockManagerApiController) GetOutExprotList() {
  4486. adminUserInfo := this.GetAdminUserInfo()
  4487. orgId := adminUserInfo.CurrentOrgId
  4488. timeLayout := "2006-01-02"
  4489. loc, _ := time.LoadLocation("Local")
  4490. start_time := this.GetString("start_time")
  4491. end_time := this.GetString("end_time")
  4492. idArray := this.GetString("id")
  4493. ids := strings.Split(idArray, ",")
  4494. fmt.Println("ids2222222222", ids)
  4495. var startTime int64
  4496. if len(start_time) > 0 {
  4497. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4498. if err != nil {
  4499. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4500. return
  4501. }
  4502. startTime = theTime.Unix()
  4503. }
  4504. var endTime int64
  4505. if len(end_time) > 0 {
  4506. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4507. if err != nil {
  4508. utils.ErrorLog(err.Error())
  4509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4510. return
  4511. }
  4512. endTime = theTime.Unix()
  4513. }
  4514. list, _ := service.GetOutExprotList(orgId, ids, startTime, endTime)
  4515. outCount, _ := service.GetOutStockTotalCountOne(startTime, endTime, orgId)
  4516. this.ServeSuccessJSON(map[string]interface{}{
  4517. "list": list,
  4518. "count": outCount,
  4519. })
  4520. }
  4521. func (this *StockManagerApiController) GetSingleCancelOrder() {
  4522. id, _ := this.GetInt64("id")
  4523. adminUserInfo := this.GetAdminUserInfo()
  4524. orgId := adminUserInfo.CurrentOrgId
  4525. order, _ := service.GetSingleCancelOrder(id, orgId)
  4526. this.ServeSuccessJSON(map[string]interface{}{
  4527. "list": order,
  4528. })
  4529. }
  4530. func (this *StockManagerApiController) GetCancelStockOrderPrint() {
  4531. id := this.GetString("id")
  4532. idStr := strings.Split(id, ",")
  4533. orgId := this.GetAdminUserInfo().CurrentOrgId
  4534. list, _ := service.GetCancelStockOrderPrintOne(idStr, orgId)
  4535. this.ServeSuccessJSON(map[string]interface{}{
  4536. "list": list,
  4537. })
  4538. }
  4539. func (this *StockManagerApiController) GetStockBatchNumber() {
  4540. id, _ := this.GetInt64("id")
  4541. orgId := this.GetAdminUserInfo().CurrentOrgId
  4542. list, _ := service.GetStockBatchNumber(id, orgId)
  4543. this.ServeSuccessJSON(map[string]interface{}{
  4544. "list": list,
  4545. })
  4546. }
  4547. func (this *StockManagerApiController) GetStockFlow() {
  4548. limit, _ := this.GetInt64("limit")
  4549. page, _ := this.GetInt64("page")
  4550. good_id, _ := this.GetInt64("good_id")
  4551. consumable_type, _ := this.GetInt64("is_sys")
  4552. adminUserInfo := this.GetAdminUserInfo()
  4553. orgId := adminUserInfo.CurrentOrgId
  4554. timeLayout := "2006-01-02"
  4555. loc, _ := time.LoadLocation("Local")
  4556. start_time := this.GetString("start_time")
  4557. end_time := this.GetString("end_time")
  4558. var startTime int64
  4559. if len(start_time) > 0 {
  4560. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4561. if err != nil {
  4562. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4563. return
  4564. }
  4565. startTime = theTime.Unix()
  4566. }
  4567. var endTime int64
  4568. if len(end_time) > 0 {
  4569. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4570. if err != nil {
  4571. utils.ErrorLog(err.Error())
  4572. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4573. return
  4574. }
  4575. endTime = theTime.Unix()
  4576. }
  4577. list, total, _ := service.GetStockFlowList(limit, page, consumable_type, orgId, startTime, endTime, good_id)
  4578. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4579. good, _ := service.GetGoodInformationByGoodId(good_id)
  4580. houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  4581. patients, _ := service.GetAllPatientListSix(adminUserInfo.CurrentOrgId)
  4582. this.ServeSuccessJSON(map[string]interface{}{
  4583. "list": list,
  4584. "total": total,
  4585. "manufacturerList": manufacturerList,
  4586. "good": good,
  4587. "houseList": houseList,
  4588. "patients": patients,
  4589. })
  4590. }
  4591. func (this *StockManagerApiController) GetCancelExportList() {
  4592. adminUserInfo := this.GetAdminUserInfo()
  4593. orgId := adminUserInfo.CurrentOrgId
  4594. timeLayout := "2006-01-02"
  4595. loc, _ := time.LoadLocation("Local")
  4596. start_time := this.GetString("start_time")
  4597. end_time := this.GetString("end_time")
  4598. idArray := this.GetString("order_id")
  4599. fmt.Println("232323232323232232", idArray)
  4600. ids := strings.Split(idArray, ",")
  4601. var startTime int64
  4602. if len(start_time) > 0 {
  4603. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4604. if err != nil {
  4605. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4606. return
  4607. }
  4608. startTime = theTime.Unix()
  4609. }
  4610. var endTime int64
  4611. if len(end_time) > 0 {
  4612. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4613. if err != nil {
  4614. utils.ErrorLog(err.Error())
  4615. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4616. return
  4617. }
  4618. endTime = theTime.Unix()
  4619. }
  4620. list, _ := service.GetCancelExportList(startTime, endTime, ids, orgId)
  4621. this.ServeSuccessJSON(map[string]interface{}{
  4622. "list": list,
  4623. })
  4624. }
  4625. func (this *StockManagerApiController) GetSearchGoodWarehouseList() {
  4626. keyword := this.GetString("keyword")
  4627. storehouse_id, _ := this.GetInt64("storehouse_id")
  4628. orgId := this.GetAdminUserInfo().CurrentOrgId
  4629. list, _ := service.GetSearchGoodWarehouseList(keyword, orgId, storehouse_id)
  4630. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4631. dealerList, _ := service.GetAllDealerList(orgId)
  4632. this.ServeSuccessJSON(map[string]interface{}{
  4633. "list": list,
  4634. "manufacturerList": manufacturerList,
  4635. "dealerList": dealerList,
  4636. })
  4637. }
  4638. func (this *StockManagerApiController) SaveAdjuestPrice() {
  4639. timeLayout := "2006-01-02"
  4640. loc, _ := time.LoadLocation("Local")
  4641. dataBody := make(map[string]interface{}, 0)
  4642. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4643. if err != nil {
  4644. utils.ErrorLog(err.Error())
  4645. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4646. return
  4647. }
  4648. tableData, _ := dataBody["tableData"].([]interface{})
  4649. if len(tableData) > 0 {
  4650. for _, item := range tableData {
  4651. items := item.(map[string]interface{})
  4652. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4653. utils.ErrorLog("good_name")
  4654. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4655. return
  4656. }
  4657. good_name := items["good_name"].(string)
  4658. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4659. utils.ErrorLog("good_name")
  4660. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4661. return
  4662. }
  4663. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4664. utils.ErrorLog("packing_price")
  4665. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4666. return
  4667. }
  4668. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4669. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4670. utils.ErrorLog("warehousing_order")
  4671. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4672. return
  4673. }
  4674. warehousing_order := items["warehousing_order"].(string)
  4675. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4676. utils.ErrorLog("license_number")
  4677. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4678. return
  4679. }
  4680. license_number := items["license_number"].(string)
  4681. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4682. utils.ErrorLog("dealer")
  4683. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4684. return
  4685. }
  4686. dealer := items["dealer"].(string)
  4687. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4688. utils.ErrorLog("manufacturer")
  4689. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4690. return
  4691. }
  4692. manufacturer := items["manufacturer"].(string)
  4693. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4694. utils.ErrorLog("specification_name")
  4695. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4696. return
  4697. }
  4698. specification_name := items["specification_name"].(string)
  4699. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4700. utils.ErrorLog("remark")
  4701. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4702. return
  4703. }
  4704. remark := items["remark"].(string)
  4705. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4706. utils.ErrorLog("warehousing_unit")
  4707. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4708. return
  4709. }
  4710. warehousing_unit := items["warehousing_unit"].(string)
  4711. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4712. utils.ErrorLog("buy_price")
  4713. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4714. return
  4715. }
  4716. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4717. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4718. utils.ErrorLog("count")
  4719. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4720. return
  4721. }
  4722. count := int64(items["count"].(float64))
  4723. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  4724. utils.ErrorLog("new_price")
  4725. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4726. return
  4727. }
  4728. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  4729. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4730. utils.ErrorLog("good_id")
  4731. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4732. return
  4733. }
  4734. good_id := int64(items["good_id"].(float64))
  4735. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4736. utils.ErrorLog("start_time")
  4737. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4738. return
  4739. }
  4740. var startTime int64
  4741. start_time := items["start_time"].(string)
  4742. if len(start_time) > 0 {
  4743. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4744. if err != nil {
  4745. fmt.Println(err)
  4746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4747. return
  4748. }
  4749. startTime = theTime.Unix()
  4750. }
  4751. orgId := this.GetAdminUserInfo().CurrentOrgId
  4752. adjustprice := models.XtStockAdjustPrice{
  4753. GoodName: good_name,
  4754. SpecificationName: specification_name,
  4755. WarehousingUnit: warehousing_unit,
  4756. Count: count,
  4757. BuyPrice: buy_price,
  4758. PackingPrice: packing_price,
  4759. NewPrice: new_price,
  4760. Manufacturer: manufacturer,
  4761. Dealer: dealer,
  4762. Remark: remark,
  4763. GoodId: good_id,
  4764. UserOrgId: orgId,
  4765. Ctime: time.Now().Unix(),
  4766. Mtime: 0,
  4767. Status: 1,
  4768. WarehousingOrder: warehousing_order,
  4769. LicenseNumber: license_number,
  4770. StartTime: startTime,
  4771. Creater: this.GetAdminUserInfo().AdminUser.Id,
  4772. CheckerStatus: 2,
  4773. }
  4774. service.CreateAdjustPrice(&adjustprice)
  4775. }
  4776. }
  4777. this.ServeSuccessJSON(map[string]interface{}{
  4778. "msg": "保存成功!",
  4779. })
  4780. }
  4781. func (this *StockManagerApiController) GetAllStockPrice() {
  4782. timeLayout := "2006-01-02"
  4783. loc, _ := time.LoadLocation("Local")
  4784. dataBody := make(map[string]interface{}, 0)
  4785. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4786. fmt.Println(err)
  4787. orgId := this.GetAdminUserInfo().CurrentOrgId
  4788. keyword := this.GetString("keyword")
  4789. start_time := this.GetString("start_time")
  4790. end_time := this.GetString("end_time")
  4791. limit, _ := this.GetInt64("limit")
  4792. page, _ := this.GetInt64("page")
  4793. var startTime int64
  4794. if len(start_time) > 0 {
  4795. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4796. if err != nil {
  4797. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4798. return
  4799. }
  4800. startTime = theTime.Unix()
  4801. }
  4802. var endTime int64
  4803. if len(end_time) > 0 {
  4804. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4805. if err != nil {
  4806. utils.ErrorLog(err.Error())
  4807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4808. return
  4809. }
  4810. endTime = theTime.Unix()
  4811. }
  4812. list, total, _ := service.GetAllStockPrice(orgId, startTime, endTime, keyword, limit, page)
  4813. doctor, _ := service.GetAllDoctorThree(orgId)
  4814. this.ServeSuccessJSON(map[string]interface{}{
  4815. "list": list,
  4816. "doctor": doctor,
  4817. "total": total,
  4818. })
  4819. }
  4820. func (this *StockManagerApiController) SaveCheckPrice() {
  4821. timeLayout := "2006-01-02"
  4822. loc, _ := time.LoadLocation("Local")
  4823. dataBody := make(map[string]interface{}, 0)
  4824. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4825. fmt.Println(err)
  4826. idstr := this.GetString("ids")
  4827. ids := strings.Split(idstr, ",")
  4828. check_time := this.GetString("check_time")
  4829. var checkTime int64
  4830. if len(check_time) > 0 {
  4831. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  4832. if err != nil {
  4833. fmt.Println(err)
  4834. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4835. return
  4836. }
  4837. checkTime = theTime.Unix()
  4838. }
  4839. checker, _ := this.GetInt64("checker")
  4840. adjustPrice := models.XtStockAdjustPrice{
  4841. Checker: checker,
  4842. CheckerStatus: 1,
  4843. CheckerTime: checkTime,
  4844. }
  4845. err = service.UpdateAdjustPrice(ids, adjustPrice)
  4846. fmt.Println(err)
  4847. list, _ := service.GetAdjustCheckPriceList(ids)
  4848. fmt.Println("list2333223323232323232323", list)
  4849. for _, item := range list {
  4850. info := models.GoodInfo{
  4851. PackingPrice: item.NewPrice,
  4852. BuyPrice: item.NewPrice,
  4853. }
  4854. err = service.UpdateAdjustCheckPrice(&info, item.GoodId)
  4855. fmt.Println(err)
  4856. }
  4857. this.ServeSuccessJSON(map[string]interface{}{
  4858. "adjustPrice": adjustPrice,
  4859. })
  4860. }
  4861. func (this *StockManagerApiController) GetAdjustPriceById() {
  4862. ids := this.GetString("ids")
  4863. fmt.Println("ids23232233223233232", ids)
  4864. splitIds := strings.Split(ids, ",")
  4865. list, _ := service.GetAdjustPricebyIdOne(splitIds)
  4866. fmt.Println("list2322322323", list)
  4867. this.ServeSuccessJSON(map[string]interface{}{
  4868. "list": list,
  4869. })
  4870. }
  4871. func (this *StockManagerApiController) SaveReportStock() {
  4872. timeLayout := "2006-01-02"
  4873. loc, _ := time.LoadLocation("Local")
  4874. dataBody := make(map[string]interface{}, 0)
  4875. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4876. if err != nil {
  4877. utils.ErrorLog(err.Error())
  4878. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4879. return
  4880. }
  4881. tableData, _ := dataBody["tableData"].([]interface{})
  4882. if len(tableData) > 0 {
  4883. for _, item := range tableData {
  4884. items := item.(map[string]interface{})
  4885. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4886. utils.ErrorLog("good_name")
  4887. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4888. return
  4889. }
  4890. good_name := items["good_name"].(string)
  4891. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4892. utils.ErrorLog("good_name")
  4893. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4894. return
  4895. }
  4896. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4897. utils.ErrorLog("packing_price")
  4898. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4899. return
  4900. }
  4901. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4902. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4903. utils.ErrorLog("warehousing_order")
  4904. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4905. return
  4906. }
  4907. warehousing_order := items["warehousing_order"].(string)
  4908. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4909. utils.ErrorLog("license_number")
  4910. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4911. return
  4912. }
  4913. license_number := items["license_number"].(string)
  4914. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4915. utils.ErrorLog("dealer")
  4916. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4917. return
  4918. }
  4919. dealer := items["dealer"].(string)
  4920. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4921. utils.ErrorLog("manufacturer")
  4922. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4923. return
  4924. }
  4925. manufacturer := items["manufacturer"].(string)
  4926. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4927. utils.ErrorLog("specification_name")
  4928. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4929. return
  4930. }
  4931. specification_name := items["specification_name"].(string)
  4932. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4933. utils.ErrorLog("remark")
  4934. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4935. return
  4936. }
  4937. remark := items["remark"].(string)
  4938. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4939. utils.ErrorLog("warehousing_unit")
  4940. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4941. return
  4942. }
  4943. warehousing_unit := items["warehousing_unit"].(string)
  4944. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4945. utils.ErrorLog("buy_price")
  4946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4947. return
  4948. }
  4949. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4950. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4951. utils.ErrorLog("count")
  4952. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4953. return
  4954. }
  4955. count := int64(items["count"].(float64))
  4956. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4957. utils.ErrorLog("good_id")
  4958. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4959. return
  4960. }
  4961. good_id := int64(items["good_id"].(float64))
  4962. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4963. utils.ErrorLog("start_time")
  4964. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4965. return
  4966. }
  4967. var startTime int64
  4968. start_time := items["start_time"].(string)
  4969. if len(start_time) > 0 {
  4970. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4971. if err != nil {
  4972. fmt.Println(err)
  4973. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4974. return
  4975. }
  4976. startTime = theTime.Unix()
  4977. }
  4978. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  4979. utils.ErrorLog("number")
  4980. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4981. return
  4982. }
  4983. number := items["number"].(string)
  4984. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  4985. utils.ErrorLog("warehousing_info_id")
  4986. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4987. return
  4988. }
  4989. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  4990. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  4991. utils.ErrorLog("expiry_date")
  4992. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4993. return
  4994. }
  4995. expiry_date := int64(items["expiry_date"].(float64))
  4996. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  4997. utils.ErrorLog("product_date")
  4998. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4999. return
  5000. }
  5001. product_date := int64(items["product_date"].(float64))
  5002. orgId := this.GetAdminUserInfo().CurrentOrgId
  5003. Creater := this.GetAdminUserInfo().AdminUser.Id
  5004. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  5005. utils.ErrorLog("total")
  5006. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5007. return
  5008. }
  5009. total := int64(items["total"].(float64))
  5010. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  5011. utils.ErrorLog("good_origin_place")
  5012. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5013. return
  5014. }
  5015. good_origin_place := items["good_origin_place"].(string)
  5016. reportPrice := models.XtStockReportPrice{
  5017. GoodName: good_name,
  5018. SpecificationName: specification_name,
  5019. WarehousingUnit: warehousing_unit,
  5020. Count: count,
  5021. BuyPrice: buy_price,
  5022. PackingPrice: packing_price,
  5023. Manufacturer: manufacturer,
  5024. Dealer: dealer,
  5025. Remark: remark,
  5026. GoodId: good_id,
  5027. UserOrgId: orgId,
  5028. Ctime: time.Now().Unix(),
  5029. Mtime: 0,
  5030. Status: 1,
  5031. WarehousingOrder: warehousing_order,
  5032. LicenseNumber: license_number,
  5033. StartTime: startTime,
  5034. Creater: Creater,
  5035. Checker: 0,
  5036. CheckerStatus: 2,
  5037. CheckerTime: 0,
  5038. Number: number,
  5039. WarehousingInfoId: warehousing_info_id,
  5040. ExpiryDate: expiry_date,
  5041. ProductDate: product_date,
  5042. Total: total,
  5043. GoodOriginPlace: good_origin_place,
  5044. }
  5045. err := service.CreateReportPrice(&reportPrice)
  5046. fmt.Println(err)
  5047. }
  5048. }
  5049. this.ServeSuccessJSON(map[string]interface{}{
  5050. "msg": "保存成功!",
  5051. })
  5052. }
  5053. func (this *StockManagerApiController) GetReportStockList() {
  5054. timeLayout := "2006-01-02"
  5055. loc, _ := time.LoadLocation("Local")
  5056. start_time := this.GetString("start_time")
  5057. end_time := this.GetString("end_time")
  5058. page, _ := this.GetInt64("page")
  5059. limit, _ := this.GetInt64("limit")
  5060. storehouse_id, _ := this.GetInt64("storehouse_id")
  5061. var startTime int64
  5062. if len(start_time) > 0 {
  5063. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5064. if err != nil {
  5065. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5066. return
  5067. }
  5068. startTime = theTime.Unix()
  5069. fmt.Println("开始时间", startTime)
  5070. }
  5071. var endTime int64
  5072. if len(end_time) > 0 {
  5073. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5074. if err != nil {
  5075. utils.ErrorLog(err.Error())
  5076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5077. return
  5078. }
  5079. endTime = theTime.Unix()
  5080. }
  5081. orgId := this.GetAdminUserInfo().CurrentOrgId
  5082. keyword := this.GetString("keyword")
  5083. list, total, _ := service.GetStockDamagedList(orgId, keyword, page, limit, startTime, endTime, storehouse_id)
  5084. damageList, _ := service.GetStockDamagedCount(orgId)
  5085. doctorlist, _ := service.GetAllDoctorThree(orgId)
  5086. houseList, _ := service.GetAllStoreHouseList(orgId)
  5087. this.ServeSuccessJSON(map[string]interface{}{
  5088. "list": list,
  5089. "total": total,
  5090. "doctorlist": doctorlist,
  5091. "damageList": damageList,
  5092. "houseList": houseList,
  5093. })
  5094. }
  5095. func (this *StockManagerApiController) SaveCheckDamage() {
  5096. timeLayout := "2006-01-02"
  5097. loc, _ := time.LoadLocation("Local")
  5098. idstr := this.GetString("ids")
  5099. ids := strings.Split(idstr, ",")
  5100. check_time := this.GetString("check_time")
  5101. var checkTime int64
  5102. if len(check_time) > 0 {
  5103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  5104. if err != nil {
  5105. fmt.Println(err)
  5106. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5107. return
  5108. }
  5109. checkTime = theTime.Unix()
  5110. }
  5111. checker, _ := this.GetInt64("checker")
  5112. reportprice := models.XtStockReportPrice{
  5113. Checker: checker,
  5114. CheckerStatus: 1,
  5115. CheckerTime: checkTime,
  5116. }
  5117. err := service.UpdateCheckDamage(ids, reportprice)
  5118. fmt.Println(err)
  5119. //获取当前核对的数据
  5120. list, _ := service.GetCheckDamageList(ids)
  5121. ctime := time.Now().Unix()
  5122. adminUserInfo := this.GetAdminUserInfo()
  5123. timeStr := time.Now().Format("2006-01-02")
  5124. timeArr := strings.Split(timeStr, "-")
  5125. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  5126. total = total + 1
  5127. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5128. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5129. number = number + total
  5130. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5131. operation_time := time.Now().Unix()
  5132. creater := adminUserInfo.AdminUser.Id
  5133. warehouseOut := models.WarehouseOut{
  5134. WarehouseOutOrderNumber: warehousing_out_order,
  5135. OperationTime: operation_time,
  5136. OrgId: adminUserInfo.CurrentOrgId,
  5137. Creater: creater,
  5138. Ctime: ctime,
  5139. Status: 1,
  5140. WarehouseOutTime: ctime,
  5141. Type: 1,
  5142. }
  5143. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  5144. if errcodes == gorm.ErrRecordNotFound {
  5145. service.AddSigleWarehouseOut(&warehouseOut)
  5146. }
  5147. out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
  5148. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  5149. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  5150. var manufacturer_id int64
  5151. var dealer_id int64
  5152. for _, item := range list {
  5153. for _, it := range manufacturerList {
  5154. if item.Manufacturer == it.ManufacturerName {
  5155. manufacturer_id = it.ID
  5156. }
  5157. }
  5158. for _, its := range dealerList {
  5159. if item.Dealer == its.DealerName {
  5160. dealer_id = its.ID
  5161. }
  5162. }
  5163. goodinfo, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5164. //插入出库单
  5165. warehouseOutInfo := &models.WarehouseOutInfo{
  5166. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  5167. WarehouseOutId: out.ID,
  5168. GoodId: item.GoodId,
  5169. Count: item.Count,
  5170. Price: item.PackingPrice,
  5171. Status: 1,
  5172. Ctime: ctime,
  5173. Remark: item.Remark,
  5174. OrgId: adminUserInfo.CurrentOrgId,
  5175. Type: 2,
  5176. Manufacturer: manufacturer_id,
  5177. Number: item.Number,
  5178. ExpiryDate: item.ExpiryDate,
  5179. ProductDate: item.ProductDate,
  5180. Dealer: dealer_id,
  5181. LicenseNumber: item.LicenseNumber,
  5182. GoodTypeId: goodinfo.GoodTypeId,
  5183. }
  5184. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5185. fmt.Println("99999999999999", errOne)
  5186. //更改库存
  5187. info, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  5188. warehousingInfo := models.WarehousingInfo{
  5189. StockCount: info.StockCount - item.Count,
  5190. }
  5191. errOne = service.UpdateGoodWarehouseInfo(item.WarehousingInfoId, warehousingInfo)
  5192. fmt.Println(errOne)
  5193. flow := models.VmStockFlow{
  5194. WarehousingId: 0,
  5195. GoodId: item.GoodId,
  5196. Number: item.Number,
  5197. LicenseNumber: item.LicenseNumber,
  5198. Count: item.Count,
  5199. UserOrgId: adminUserInfo.CurrentOrgId,
  5200. PatientId: 0,
  5201. SystemTime: time.Now().Unix(),
  5202. ConsumableType: 5,
  5203. IsSys: 0,
  5204. WarehousingOrder: "",
  5205. WarehouseOutId: out.ID,
  5206. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  5207. IsEdit: 0,
  5208. CancelStockId: 0,
  5209. CancelOrderNumber: "",
  5210. Manufacturer: 0,
  5211. Dealer: 0,
  5212. Creator: adminUserInfo.AdminUser.Id,
  5213. UpdateCreator: 0,
  5214. Status: 1,
  5215. Ctime: time.Now().Unix(),
  5216. Mtime: 0,
  5217. Price: item.PackingPrice,
  5218. WarehousingDetailId: 0,
  5219. WarehouseOutDetailId: 0,
  5220. CancelOutDetailId: 0,
  5221. ProductDate: item.ProductDate,
  5222. ExpireDate: item.ExpiryDate,
  5223. }
  5224. service.CreateStockFlowOne(flow)
  5225. }
  5226. this.ServeSuccessJSON(map[string]interface{}{
  5227. "reportPrice": reportprice,
  5228. })
  5229. }
  5230. func (this *StockManagerApiController) SaveInventory() {
  5231. timeLayout := "2006-01-02"
  5232. loc, _ := time.LoadLocation("Local")
  5233. dataBody := make(map[string]interface{}, 0)
  5234. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5235. if err != nil {
  5236. utils.ErrorLog(err.Error())
  5237. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5238. return
  5239. }
  5240. tableData, _ := dataBody["tableData"].([]interface{})
  5241. if len(tableData) > 0 {
  5242. for _, item := range tableData {
  5243. items := item.(map[string]interface{})
  5244. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5245. utils.ErrorLog("good_name")
  5246. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5247. return
  5248. }
  5249. good_name := items["good_name"].(string)
  5250. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5251. utils.ErrorLog("good_name")
  5252. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5253. return
  5254. }
  5255. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  5256. utils.ErrorLog("packing_price")
  5257. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5258. return
  5259. }
  5260. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  5261. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  5262. utils.ErrorLog("warehousing_order")
  5263. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5264. return
  5265. }
  5266. warehousing_order := items["warehousing_order"].(string)
  5267. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  5268. utils.ErrorLog("license_number")
  5269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5270. return
  5271. }
  5272. license_number := items["license_number"].(string)
  5273. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  5274. utils.ErrorLog("dealer")
  5275. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5276. return
  5277. }
  5278. dealer := items["dealer"].(string)
  5279. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  5280. utils.ErrorLog("manufacturer")
  5281. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5282. return
  5283. }
  5284. manufacturer := items["manufacturer"].(string)
  5285. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  5286. utils.ErrorLog("specification_name")
  5287. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5288. return
  5289. }
  5290. specification_name := items["specification_name"].(string)
  5291. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  5292. utils.ErrorLog("remark")
  5293. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5294. return
  5295. }
  5296. remark := items["remark"].(string)
  5297. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  5298. utils.ErrorLog("warehousing_unit")
  5299. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5300. return
  5301. }
  5302. warehousing_unit := items["warehousing_unit"].(string)
  5303. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  5304. utils.ErrorLog("buy_price")
  5305. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5306. return
  5307. }
  5308. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  5309. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  5310. utils.ErrorLog("count")
  5311. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5312. return
  5313. }
  5314. count := int64(items["count"].(float64))
  5315. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5316. utils.ErrorLog("good_id")
  5317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5318. return
  5319. }
  5320. good_id := int64(items["good_id"].(float64))
  5321. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  5322. utils.ErrorLog("start_time")
  5323. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5324. return
  5325. }
  5326. var startTime int64
  5327. start_time := items["start_time"].(string)
  5328. if len(start_time) > 0 {
  5329. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5330. if err != nil {
  5331. fmt.Println(err)
  5332. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5333. return
  5334. }
  5335. startTime = theTime.Unix()
  5336. }
  5337. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  5338. utils.ErrorLog("total")
  5339. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5340. return
  5341. }
  5342. total := int64(items["total"].(float64))
  5343. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  5344. utils.ErrorLog("expiry_date")
  5345. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5346. return
  5347. }
  5348. expiry_date := int64(items["expiry_date"].(float64))
  5349. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  5350. utils.ErrorLog("product_date")
  5351. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5352. return
  5353. }
  5354. product_date := int64(items["product_date"].(float64))
  5355. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5356. utils.ErrorLog("number")
  5357. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5358. return
  5359. }
  5360. number := items["number"].(string)
  5361. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  5362. utils.ErrorLog("warehousing_info_id")
  5363. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5364. return
  5365. }
  5366. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  5367. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  5368. utils.ErrorLog("good_origin_place")
  5369. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5370. return
  5371. }
  5372. good_origin_place := items["good_origin_place"].(string)
  5373. orgId := this.GetAdminUserInfo().CurrentOrgId
  5374. Creater := this.GetAdminUserInfo().AdminUser.Id
  5375. inventory := models.XtStockInventory{
  5376. GoodName: good_name,
  5377. SpecificationName: specification_name,
  5378. WarehousingUnit: warehousing_unit,
  5379. Count: count,
  5380. BuyPrice: buy_price,
  5381. PackingPrice: packing_price,
  5382. NewPrice: 0,
  5383. Manufacturer: manufacturer,
  5384. Dealer: dealer,
  5385. Remark: remark,
  5386. GoodId: good_id,
  5387. UserOrgId: orgId,
  5388. Ctime: time.Now().Unix(),
  5389. Mtime: 0,
  5390. Status: 1,
  5391. WarehousingOrder: warehousing_order,
  5392. LicenseNumber: license_number,
  5393. StartTime: startTime,
  5394. Creater: Creater,
  5395. Checker: 0,
  5396. CheckerStatus: 2,
  5397. CheckerTime: 0,
  5398. Total: total,
  5399. ExpireDate: expiry_date,
  5400. ProductDate: product_date,
  5401. Number: number,
  5402. WarehousingInfoId: warehousing_info_id,
  5403. GoodOriginPlace: good_origin_place,
  5404. }
  5405. err = service.CreateInentory(inventory)
  5406. fmt.Println(err)
  5407. }
  5408. }
  5409. this.ServeSuccessJSON(map[string]interface{}{
  5410. "msg": "保存成功!",
  5411. })
  5412. }
  5413. func (this *StockManagerApiController) GetInventorylist() {
  5414. timeLayout := "2006-01-02"
  5415. loc, _ := time.LoadLocation("Local")
  5416. start_time := this.GetString("start_time")
  5417. end_time := this.GetString("end_time")
  5418. page, _ := this.GetInt64("page")
  5419. limit, _ := this.GetInt64("limit")
  5420. keyword := this.GetString("keyword")
  5421. inventory_status, _ := this.GetInt64("inventory_status")
  5422. var startTime int64
  5423. if len(start_time) > 0 {
  5424. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5425. if err != nil {
  5426. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5427. return
  5428. }
  5429. startTime = theTime.Unix()
  5430. fmt.Println("开始时间", startTime)
  5431. }
  5432. var endTime int64
  5433. if len(end_time) > 0 {
  5434. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5435. if err != nil {
  5436. utils.ErrorLog(err.Error())
  5437. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5438. return
  5439. }
  5440. endTime = theTime.Unix()
  5441. }
  5442. orgId := this.GetAdminUserInfo().CurrentOrgId
  5443. list, total, _ := service.GetInventorylist(startTime, endTime, page, limit, inventory_status, keyword, orgId)
  5444. doctorlist, _ := service.GetAllDoctorThree(orgId)
  5445. houseList, _ := service.GetAllStoreHouseList(orgId)
  5446. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5447. this.ServeSuccessJSON(map[string]interface{}{
  5448. "list": list,
  5449. "total": total,
  5450. "doctorlist": doctorlist,
  5451. "houseList": houseList,
  5452. "houseConfig": houseConfig,
  5453. })
  5454. }
  5455. func (this *StockManagerApiController) SaveCheckInventory() {
  5456. timeLayout := "2006-01-02"
  5457. loc, _ := time.LoadLocation("Local")
  5458. dataBody := make(map[string]interface{}, 0)
  5459. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5460. fmt.Println(err)
  5461. idstr := this.GetString("ids")
  5462. ids := strings.Split(idstr, ",")
  5463. check_time := this.GetString("check_time")
  5464. var checkTime int64
  5465. if len(check_time) > 0 {
  5466. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  5467. if err != nil {
  5468. fmt.Println(err)
  5469. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5470. return
  5471. }
  5472. checkTime = theTime.Unix()
  5473. }
  5474. checker, _ := this.GetInt64("checker")
  5475. inventory := models.XtStockInventory{
  5476. Checker: checker,
  5477. CheckerStatus: 1,
  5478. CheckerTime: checkTime,
  5479. }
  5480. adminUserInfo := this.GetAdminUserInfo()
  5481. err = service.UpdateCheckInventory(ids, inventory)
  5482. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  5483. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  5484. var manufactuer_id int64
  5485. var dealer_id int64
  5486. //查询耗材信息
  5487. list, _ := service.GetInventoryDetailById(ids)
  5488. for _, item := range list {
  5489. for _, it := range manufacturerList {
  5490. if item.Manufacturer == it.ManufacturerName {
  5491. manufactuer_id = it.ID
  5492. }
  5493. }
  5494. for _, its := range dealerList {
  5495. if item.Dealer == its.DealerName {
  5496. dealer_id = its.ID
  5497. }
  5498. }
  5499. //查寻该批次的库存量
  5500. list, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  5501. //查询该耗材最后1条批次
  5502. info, _ := service.GetLastWarehouseInfo(item.GoodId)
  5503. good, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5504. fmt.Println("总共", item.Count)
  5505. fmt.Println("数据", list.StockCount)
  5506. //盘点盘点库存和et实际库存的大小
  5507. // 如果盘点库存大于实际库存,怎需要入库
  5508. if item.Count > list.StockCount {
  5509. ctime := time.Now().Unix()
  5510. timeStr := time.Now().Format("2006-01-02")
  5511. timeArr := strings.Split(timeStr, "-")
  5512. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  5513. total = total + 1
  5514. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5515. operation_time := time.Now().Unix()
  5516. creater := adminUserInfo.AdminUser.Id
  5517. warehousing := models.Warehousing{
  5518. WarehousingOrder: warehousing_order,
  5519. OperationTime: operation_time,
  5520. OrgId: adminUserInfo.CurrentOrgId,
  5521. Creater: creater,
  5522. Ctime: ctime,
  5523. Status: 1,
  5524. WarehousingTime: ctime,
  5525. Type: 1,
  5526. }
  5527. service.AddSigleWarehouse(&warehousing)
  5528. //获取最
  5529. //入库单表格
  5530. warehouseInfo := models.WarehousingInfo{
  5531. WarehousingOrder: warehousing.WarehousingOrder,
  5532. WarehousingId: warehousing.ID,
  5533. GoodId: item.GoodId,
  5534. Number: info.Number,
  5535. ProductDate: info.ProductDate,
  5536. ExpiryDate: info.ExpiryDate,
  5537. WarehousingCount: item.Count - list.StockCount,
  5538. Price: info.Price,
  5539. Status: 1,
  5540. Ctime: ctime,
  5541. Remark: item.Remark,
  5542. OrgId: adminUserInfo.CurrentOrgId,
  5543. Type: 1,
  5544. Manufacturer: manufactuer_id,
  5545. StockCount: item.Count - list.StockCount,
  5546. Dealer: dealer_id,
  5547. LicenseNumber: info.LicenseNumber,
  5548. WarehouseInfoId: item.WarehousingInfoId,
  5549. GoodTypeId: good.GoodTypeId,
  5550. }
  5551. flow := models.VmStockFlow{
  5552. WarehousingOrder: warehousing.WarehousingOrder,
  5553. WarehousingId: warehousing.ID,
  5554. GoodId: item.GoodId,
  5555. Number: info.Number,
  5556. ProductDate: info.ProductDate,
  5557. ExpireDate: info.ExpiryDate,
  5558. Count: item.Count - list.StockCount,
  5559. Price: item.BuyPrice,
  5560. Status: 1,
  5561. Ctime: ctime,
  5562. UserOrgId: adminUserInfo.CurrentOrgId,
  5563. Manufacturer: info.Manufacturer,
  5564. Dealer: info.Dealer,
  5565. LicenseNumber: info.LicenseNumber,
  5566. IsEdit: 1,
  5567. Creator: adminUserInfo.AdminUser.Id,
  5568. SystemTime: operation_time,
  5569. ConsumableType: 1,
  5570. WarehousingDetailId: warehouseInfo.ID,
  5571. }
  5572. service.CreateWarehouseInfo(warehouseInfo)
  5573. service.CreateStockFlowOne(flow)
  5574. }
  5575. //如果盘点库存小于实际库存,需要出库
  5576. if item.Count < list.StockCount {
  5577. timeStr := time.Now().Format("2006-01-02")
  5578. timeArr := strings.Split(timeStr, "-")
  5579. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  5580. total = total + 1
  5581. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5582. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5583. number = number + total
  5584. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5585. operation_time := time.Now().Unix()
  5586. creater := adminUserInfo.AdminUser.Id
  5587. //查询最早的1条批次
  5588. warehouseInfo, _ := service.GetFirstWarehouseInfo(item.GoodId)
  5589. warehouseOut := models.WarehouseOut{
  5590. WarehouseOutOrderNumber: warehousing_out_order,
  5591. OperationTime: operation_time,
  5592. OrgId: adminUserInfo.CurrentOrgId,
  5593. Creater: creater,
  5594. Ctime: time.Now().Unix(),
  5595. Status: 1,
  5596. WarehouseOutTime: time.Now().Unix(),
  5597. Type: 1,
  5598. }
  5599. err = service.CreateWarehouseOut(warehouseOut)
  5600. fmt.Println(err)
  5601. out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
  5602. warehouseOutInfo := &models.WarehouseOutInfo{
  5603. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  5604. WarehouseOutId: out.ID,
  5605. GoodId: warehouseInfo.GoodId,
  5606. Count: list.StockCount - item.Count,
  5607. Price: warehouseInfo.Price,
  5608. Status: 1,
  5609. Ctime: time.Now().Unix(),
  5610. Remark: item.Remark,
  5611. OrgId: adminUserInfo.CurrentOrgId,
  5612. Type: 1,
  5613. Manufacturer: manufactuer_id,
  5614. Number: warehouseInfo.Number,
  5615. ExpiryDate: warehouseInfo.ExpiryDate,
  5616. ProductDate: warehouseInfo.ProductDate,
  5617. Dealer: dealer_id,
  5618. LicenseNumber: warehouseInfo.LicenseNumber,
  5619. GoodTypeId: good.GoodTypeId,
  5620. SysRecordTime: time.Now().Unix(),
  5621. }
  5622. stockFlow := models.VmStockFlow{
  5623. WarehousingId: item.WarehousingInfoId,
  5624. GoodId: warehouseInfo.GoodId,
  5625. Number: warehouseInfo.Number,
  5626. LicenseNumber: warehouseInfo.LicenseNumber,
  5627. Count: list.StockCount - item.Count,
  5628. UserOrgId: warehouseInfo.OrgId,
  5629. PatientId: 0,
  5630. SystemTime: time.Now().Unix(),
  5631. ConsumableType: 2,
  5632. IsSys: 2,
  5633. WarehousingOrder: "",
  5634. WarehouseOutId: out.ID,
  5635. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5636. IsEdit: 1,
  5637. CancelStockId: 0,
  5638. CancelOrderNumber: "",
  5639. Manufacturer: manufactuer_id,
  5640. Dealer: dealer_id,
  5641. Creator: adminUserInfo.AdminUser.Id,
  5642. UpdateCreator: 0,
  5643. Status: 1,
  5644. Ctime: time.Now().Unix(),
  5645. Mtime: 0,
  5646. Price: warehouseInfo.Price,
  5647. WarehousingDetailId: 0,
  5648. WarehouseOutDetailId: out.ID,
  5649. CancelOutDetailId: 0,
  5650. ProductDate: warehouseInfo.ProductDate,
  5651. ExpireDate: warehouseInfo.ExpiryDate,
  5652. }
  5653. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5654. fmt.Println(errOne)
  5655. //创建出库明细
  5656. service.CreateStockFlowOne(stockFlow)
  5657. //更改库存
  5658. warehousingInfos := models.WarehousingInfo{
  5659. StockCount: item.Count,
  5660. }
  5661. service.UpdateStockOut(item.WarehousingInfoId, warehousingInfos)
  5662. }
  5663. }
  5664. fmt.Println(err)
  5665. this.ServeSuccessJSON(map[string]interface{}{
  5666. "inventory": inventory,
  5667. })
  5668. }
  5669. func (this *StockManagerApiController) GetModifyPriceDetail() {
  5670. id, _ := this.GetInt64("id")
  5671. detail, _ := service.GetModifyPriceDetail(id)
  5672. this.ServeSuccessJSON(map[string]interface{}{
  5673. "detail": detail,
  5674. })
  5675. }
  5676. func (this *StockManagerApiController) UpdateStockPrice() {
  5677. id, _ := this.GetInt64("id")
  5678. newPrice := this.GetString("new_price")
  5679. new_price, _ := strconv.ParseFloat(newPrice, 64)
  5680. good_name := this.GetString("good_name")
  5681. packingPrice := this.GetString("packing_price")
  5682. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5683. remark := this.GetString("remark")
  5684. good_id, _ := this.GetInt64("good_id")
  5685. manufacturer := this.GetString("manufacturer")
  5686. dealer := this.GetString("dealer")
  5687. adjust := models.XtStockAdjustPrice{
  5688. NewPrice: new_price,
  5689. GoodName: good_name,
  5690. PackingPrice: packing_price,
  5691. Remark: remark,
  5692. GoodId: good_id,
  5693. Manufacturer: manufacturer,
  5694. Dealer: dealer,
  5695. }
  5696. err := service.UpdateStockPrice(adjust, id)
  5697. fmt.Println(err)
  5698. this.ServeSuccessJSON(map[string]interface{}{
  5699. "adjust": adjust,
  5700. })
  5701. }
  5702. func (this *StockManagerApiController) DeleteStockPrice() {
  5703. id, _ := this.GetInt64("id")
  5704. err := service.DeleteStockPrice(id)
  5705. fmt.Println(err)
  5706. returnData := make(map[string]interface{}, 0)
  5707. returnData["msg"] = "ok"
  5708. this.ServeSuccessJSON(returnData)
  5709. return
  5710. }
  5711. func (this *StockManagerApiController) GetStockDamageDetail() {
  5712. id, _ := this.GetInt64("id")
  5713. detail, err := service.GetStockDamageDetail(id)
  5714. fmt.Println(err)
  5715. this.ServeSuccessJSON(map[string]interface{}{
  5716. "detail": detail,
  5717. })
  5718. }
  5719. func (this *StockManagerApiController) ModifyPrice() {
  5720. count, _ := this.GetInt64("count")
  5721. id, _ := this.GetInt64("id")
  5722. good_name := this.GetString("good_name")
  5723. specification_name := this.GetString("specification_name")
  5724. number := this.GetString("number")
  5725. warehousing_unit := this.GetString("warehousing_unit")
  5726. buyPrice := this.GetString("buy_price")
  5727. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5728. packingPrice := this.GetString("packing_price")
  5729. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5730. good_origin_place := this.GetString("good_origin_place")
  5731. manufacturer := this.GetString("manufacturer")
  5732. dealer := this.GetString("dealer")
  5733. total, _ := this.GetInt64("total")
  5734. remark := this.GetString("remark")
  5735. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5736. good_id, _ := this.GetInt64("good_id")
  5737. adjust := models.XtStockReportPrice{
  5738. Count: count,
  5739. SpecificationName: specification_name,
  5740. Number: number,
  5741. GoodName: good_name,
  5742. WarehousingUnit: warehousing_unit,
  5743. BuyPrice: buy_price,
  5744. PackingPrice: packing_price,
  5745. GoodOriginPlace: good_origin_place,
  5746. Manufacturer: manufacturer,
  5747. Dealer: dealer,
  5748. Total: total,
  5749. Remark: remark,
  5750. WarehousingInfoId: warehousing_info_id,
  5751. GoodId: good_id,
  5752. }
  5753. err := service.ModifyPrice(id, adjust)
  5754. fmt.Println(err)
  5755. this.ServeSuccessJSON(map[string]interface{}{
  5756. "adjust": adjust,
  5757. })
  5758. }
  5759. func (this *StockManagerApiController) DeleteDamage() {
  5760. id, _ := this.GetInt64("id")
  5761. err := service.DeleteDamage(id)
  5762. fmt.Println(err)
  5763. returnData := make(map[string]interface{}, 0)
  5764. returnData["msg"] = "ok"
  5765. this.ServeSuccessJSON(returnData)
  5766. return
  5767. }
  5768. func (this *StockManagerApiController) GetStockDamageById() {
  5769. ids := this.GetString("ids")
  5770. splitIds := strings.Split(ids, ",")
  5771. list, _ := service.GetStockDamageById(splitIds)
  5772. this.ServeSuccessJSON(map[string]interface{}{
  5773. "list": list,
  5774. })
  5775. }
  5776. func (this *StockManagerApiController) GetInventoryDetail() {
  5777. id, _ := this.GetInt64("id")
  5778. detail, _ := service.GetInventoryDetail(id)
  5779. this.ServeSuccessJSON(map[string]interface{}{
  5780. "detail": detail,
  5781. })
  5782. }
  5783. func (this *StockManagerApiController) ModifyInventory() {
  5784. id, _ := this.GetInt64("id")
  5785. good_id, _ := this.GetInt64("good_id")
  5786. good_name := this.GetString("good_name")
  5787. specification_name := this.GetString("specification_name")
  5788. number := this.GetString("number")
  5789. warehousing_unit := this.GetString("warehousing_unit")
  5790. buyPrice := this.GetString("buy_price")
  5791. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5792. packingPrice := this.GetString("packing_price")
  5793. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5794. total, _ := this.GetInt64("total")
  5795. good_origin_place := this.GetString("good_origin_place")
  5796. license_number := this.GetString("license_number")
  5797. dealer := this.GetString("dealer")
  5798. manufacturer := this.GetString("manufacturer")
  5799. count, _ := this.GetInt64("count")
  5800. remark := this.GetString("remark")
  5801. inventory := models.XtStockInventory{
  5802. GoodId: good_id,
  5803. GoodName: good_name,
  5804. SpecificationName: specification_name,
  5805. Number: number,
  5806. WarehousingUnit: warehousing_unit,
  5807. BuyPrice: buy_price,
  5808. PackingPrice: packing_price,
  5809. Total: total,
  5810. GoodOriginPlace: good_origin_place,
  5811. LicenseNumber: license_number,
  5812. Dealer: dealer,
  5813. Manufacturer: manufacturer,
  5814. Count: count,
  5815. Remark: remark,
  5816. }
  5817. err := service.ModifyInventory(id, inventory)
  5818. fmt.Println(err)
  5819. this.ServeSuccessJSON(map[string]interface{}{
  5820. "inventory": inventory,
  5821. })
  5822. }
  5823. func (this *StockManagerApiController) DeleteInventory() {
  5824. id, _ := this.GetInt64("id")
  5825. err := service.DeleteInventory(id)
  5826. fmt.Println(err)
  5827. returnData := make(map[string]interface{}, 0)
  5828. returnData["msg"] = "ok"
  5829. this.ServeSuccessJSON(returnData)
  5830. return
  5831. }
  5832. func (this *StockManagerApiController) GetInventoryDetailList() {
  5833. keyword := this.GetString("keyword")
  5834. limit, _ := this.GetInt64("limit")
  5835. page, _ := this.GetInt64("page")
  5836. orgId := this.GetAdminUserInfo().CurrentOrgId
  5837. storehouse_id, _ := this.GetInt64("storehouse_id")
  5838. houseList, _ := service.GetAllStoreHouseList(orgId)
  5839. list, total, _ := service.GetInventoryDetailList(keyword, limit, page, orgId, storehouse_id)
  5840. this.ServeSuccessJSON(map[string]interface{}{
  5841. "list": list,
  5842. "total": total,
  5843. "houseList": houseList,
  5844. })
  5845. }
  5846. func (this *StockManagerApiController) GetInventoryPrintList() {
  5847. ids := this.GetString("ids")
  5848. splitIds := strings.Split(ids, ",")
  5849. list, _ := service.GetInventoryPrintList(splitIds)
  5850. this.ServeSuccessJSON(map[string]interface{}{
  5851. "list": list,
  5852. })
  5853. }
  5854. func (this *StockManagerApiController) GetInventoryDetailPrintList() {
  5855. ids := this.GetString("ids")
  5856. splitIds := strings.Split(ids, ",")
  5857. list, _ := service.GetInventoryDetailPrintList(splitIds)
  5858. this.ServeSuccessJSON(map[string]interface{}{
  5859. "list": list,
  5860. })
  5861. }
  5862. func (this *StockManagerApiController) DeleteDrugPrice() {
  5863. id, _ := this.GetInt64("id")
  5864. err := service.DeleteDrugPrice(id)
  5865. fmt.Println(err)
  5866. returnData := make(map[string]interface{}, 0)
  5867. returnData["msg"] = "ok"
  5868. this.ServeSuccessJSON(returnData)
  5869. return
  5870. }
  5871. func (this *StockManagerApiController) GetGoodWarehouseList() {
  5872. id, _ := this.GetInt64("id")
  5873. list, _ := service.GetGoodWarehouseList(id)
  5874. this.ServeSuccessJSON(map[string]interface{}{
  5875. "list": list,
  5876. })
  5877. }
  5878. func (this *StockManagerApiController) ProofInventory() {
  5879. id, _ := this.GetInt64("id")
  5880. good_id, _ := this.GetInt64("good_id")
  5881. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5882. proof_count, _ := this.GetInt64("proof_count")
  5883. total, _ := this.GetInt64("total")
  5884. orgId := this.GetAdminUserInfo().CurrentOrgId
  5885. creater := this.GetAdminUserInfo().AdminUser.Id
  5886. info := models.WarehousingInfo{
  5887. GoodId: good_id,
  5888. StockCount: proof_count,
  5889. }
  5890. err := service.UpdateProofInventory(warehousing_info_id, info)
  5891. inventory := models.XtStockInventory{
  5892. Total: proof_count,
  5893. }
  5894. err = service.UpdateStockInventory(inventory, id)
  5895. fmt.Println(err)
  5896. record := models.XtStockCorrectRecord{
  5897. GoodId: good_id,
  5898. OrdCount: total,
  5899. WarehousingInfoId: warehousing_info_id,
  5900. NewCount: proof_count,
  5901. UserOrgId: orgId,
  5902. Status: 1,
  5903. Creater: creater,
  5904. Ctime: time.Now().Unix(),
  5905. Mtime: 0,
  5906. }
  5907. service.CeateStockCorrectRecord(record)
  5908. this.ServeSuccessJSON(map[string]interface{}{
  5909. "list": info,
  5910. })
  5911. }
  5912. func (this *StockManagerApiController) GetWarehouseTotal() {
  5913. id, _ := this.GetInt64("id")
  5914. list, _ := service.GetWarehouseTotal(id)
  5915. this.ServeSuccessJSON(map[string]interface{}{
  5916. "list": list,
  5917. })
  5918. }
  5919. func (this *StockManagerApiController) GetGoodInventoryWarehouseList() {
  5920. id, _ := this.GetInt64("id")
  5921. storehouse_id, _ := this.GetInt64("storehouse_id")
  5922. list, _ := service.GetGoodInventoryWarehouseList(id, storehouse_id)
  5923. orgId := this.GetAdminUserInfo().CurrentOrgId
  5924. fmt.Println(orgId)
  5925. this.ServeSuccessJSON(map[string]interface{}{
  5926. "list": list,
  5927. })
  5928. }
  5929. func (this *StockManagerApiController) SaveStockInventoryList() {
  5930. dataBody := make(map[string]interface{}, 0)
  5931. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5932. fmt.Println(err)
  5933. tableData, _ := dataBody["tableData"].([]interface{})
  5934. if len(tableData) > 0 {
  5935. for _, item := range tableData {
  5936. items := item.(map[string]interface{})
  5937. good_name := items["good_name"].(string)
  5938. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5939. utils.ErrorLog("good_name")
  5940. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5941. return
  5942. }
  5943. specification_name := items["specification_name"].(string)
  5944. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  5945. utils.ErrorLog("specification_name")
  5946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5947. return
  5948. }
  5949. warehousing_unit := items["warehousing_unit"].(string)
  5950. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  5951. utils.ErrorLog("warehousing_unit")
  5952. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5953. return
  5954. }
  5955. stock_count := int64(items["stock_count"].(float64))
  5956. if items["stock_count"] == nil || reflect.TypeOf(items["stock_count"]).String() != "float64" {
  5957. utils.ErrorLog("stock_count")
  5958. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5959. return
  5960. }
  5961. price := items["price"].(float64)
  5962. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "float64" {
  5963. utils.ErrorLog("price")
  5964. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5965. return
  5966. }
  5967. manufacturer_name := items["manufacturer_name"].(string)
  5968. if items["manufacturer_name"] == nil || reflect.TypeOf(items["manufacturer_name"]).String() != "string" {
  5969. utils.ErrorLog("manufacturer_name")
  5970. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5971. return
  5972. }
  5973. good_id := int64(items["good_id"].(float64))
  5974. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5975. utils.ErrorLog("good_id")
  5976. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5977. return
  5978. }
  5979. manufacturer := int64(items["manufacturer"].(float64))
  5980. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "float64" {
  5981. utils.ErrorLog("manufacturer")
  5982. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5983. return
  5984. }
  5985. warehousing_order := items["warehousing_order"].(string)
  5986. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  5987. utils.ErrorLog("warehousing_order")
  5988. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5989. return
  5990. }
  5991. number := items["number"].(string)
  5992. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5993. utils.ErrorLog("number")
  5994. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5995. return
  5996. }
  5997. id := int64(items["id"].(float64))
  5998. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5999. utils.ErrorLog("id")
  6000. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6001. return
  6002. }
  6003. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  6004. utils.ErrorLog("expiry_date")
  6005. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6006. return
  6007. }
  6008. expiry_date := int64(items["expiry_date"].(float64))
  6009. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  6010. utils.ErrorLog("product_date")
  6011. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6012. return
  6013. }
  6014. product_date := int64(items["product_date"].(float64))
  6015. orgId := this.GetAdminUserInfo().CurrentOrgId
  6016. adminId := this.GetAdminUserInfo().AdminUser.Id
  6017. stock_type := int64(items["type"].(float64))
  6018. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6019. utils.ErrorLog("type")
  6020. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6021. return
  6022. }
  6023. last_stock_count := int64(items["last_stock_count"].(float64))
  6024. if items["last_stock_count"] == nil || reflect.TypeOf(items["last_stock_count"]).String() != "float64" {
  6025. utils.ErrorLog("last_stock_count")
  6026. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6027. return
  6028. }
  6029. storehouse_id := int64(items["storehouse_id"].(float64))
  6030. if items["storehouse_id"] == nil || reflect.TypeOf(items["storehouse_id"]).String() != "float64" {
  6031. utils.ErrorLog("storehouse_id")
  6032. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6033. return
  6034. }
  6035. var total_count int64
  6036. var inventory_type int64
  6037. if stock_count > last_stock_count {
  6038. total_count = stock_count - last_stock_count
  6039. inventory_type = 11
  6040. }
  6041. if stock_count < last_stock_count {
  6042. total_count = last_stock_count - stock_count
  6043. inventory_type = 10
  6044. }
  6045. creater := this.GetAdminUserInfo().AdminUser.Id
  6046. inventory := models.XtStockInventory{
  6047. GoodName: good_name,
  6048. SpecificationName: specification_name,
  6049. WarehousingUnit: warehousing_unit,
  6050. Count: total_count,
  6051. BuyPrice: price,
  6052. PackingPrice: price,
  6053. NewPrice: 0,
  6054. Manufacturer: manufacturer_name,
  6055. Dealer: "",
  6056. Remark: "",
  6057. GoodId: good_id,
  6058. UserOrgId: orgId,
  6059. Ctime: time.Now().Unix(),
  6060. Mtime: 0,
  6061. Status: 1,
  6062. WarehousingOrder: warehousing_order,
  6063. LicenseNumber: number,
  6064. StartTime: time.Now().Unix(),
  6065. Creater: adminId,
  6066. Checker: 0,
  6067. CheckerStatus: 0,
  6068. CheckerTime: 0,
  6069. Total: 0,
  6070. Number: number,
  6071. WarehousingInfoId: id,
  6072. ExpireDate: expiry_date,
  6073. ProductDate: product_date,
  6074. GoodOriginPlace: "",
  6075. Type: 10,
  6076. InventoryType: stock_type,
  6077. LastStockCount: last_stock_count,
  6078. StockCount: stock_count,
  6079. StorehouseId: storehouse_id,
  6080. }
  6081. service.CreateInentory(inventory)
  6082. stockFlow := models.VmStockFlow{
  6083. WarehousingId: 0,
  6084. GoodId: good_id,
  6085. Number: number,
  6086. LicenseNumber: "",
  6087. Count: total_count,
  6088. UserOrgId: orgId,
  6089. PatientId: 0,
  6090. SystemTime: 0,
  6091. ConsumableType: inventory_type,
  6092. IsSys: 0,
  6093. WarehousingOrder: "",
  6094. WarehouseOutId: 0,
  6095. WarehouseOutOrderNumber: warehousing_order,
  6096. IsEdit: 0,
  6097. CancelStockId: 0,
  6098. CancelOrderNumber: "",
  6099. Manufacturer: manufacturer,
  6100. Dealer: 0,
  6101. Creator: creater,
  6102. UpdateCreator: 0,
  6103. Status: 1,
  6104. Ctime: time.Now().Unix(),
  6105. Mtime: 0,
  6106. Price: price,
  6107. WarehousingDetailId: 0,
  6108. WarehouseOutDetailId: 0,
  6109. CancelOutDetailId: 0,
  6110. ProductDate: product_date,
  6111. ExpireDate: expiry_date,
  6112. ReturnCount: 0,
  6113. StorehouseId: storehouse_id,
  6114. }
  6115. info := models.WarehousingInfo{
  6116. StockCount: last_stock_count,
  6117. WarehousingCount: last_stock_count,
  6118. }
  6119. warehosueinfos, _ := service.GetWarehouseInfoByIdNight(id)
  6120. //如果当前的盘点后的数量大于当前库存数量,则新增库存
  6121. if last_stock_count > warehosueinfos.StockCount && last_stock_count <= warehosueinfos.WarehousingCount {
  6122. //更改库存
  6123. service.UpdatedWarehousingInfo(info, id)
  6124. }
  6125. if last_stock_count > warehosueinfos.StockCount && last_stock_count > warehosueinfos.WarehousingCount {
  6126. //更改库存
  6127. service.UpdatedWarehousingInfoSix(info, id)
  6128. }
  6129. //如果当前的盘点后的数量大于当前库存数量,则扣减库存
  6130. if last_stock_count < warehosueinfos.StockCount {
  6131. //更改库存
  6132. service.UpdatedWarehousingInfo(info, id)
  6133. }
  6134. if stock_count != last_stock_count {
  6135. service.CreateStockFlowOne(stockFlow)
  6136. }
  6137. //查询该机构默认仓库
  6138. storeConfig, _ := service.GetAllStoreHouseConfig(warehosueinfos.OrgId)
  6139. //查询已审核单据的剩余库存
  6140. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, good_id, warehosueinfos.OrgId)
  6141. var sum_count int64
  6142. var sum_in_count int64
  6143. for _, item := range goodList {
  6144. sum_count += item.StockCount
  6145. sum_in_count += item.WarehousingCount
  6146. }
  6147. service.UpdateGoodByGoodId(good_id, sum_count, sum_in_count, warehosueinfos.OrgId)
  6148. goodListOne, _ := service.GetSumGoodList(orgId, storeConfig.StorehouseOutInfo, good_id)
  6149. var flush_count int64
  6150. for _, it := range goodListOne {
  6151. flush_count += it.StockCount
  6152. }
  6153. service.UpdateSumGood(orgId, storeConfig.StorehouseOutInfo, good_id, flush_count)
  6154. this.ServeSuccessJSON(map[string]interface{}{
  6155. "inventory": inventory,
  6156. })
  6157. }
  6158. }
  6159. }
  6160. func (this *StockManagerApiController) GetDamageDetailByGoodId() {
  6161. good_id, _ := this.GetInt64("good_id")
  6162. warehousing_order := this.GetString("warehousing_order")
  6163. inventory_type, _ := this.GetInt64("type")
  6164. list, _ := service.GetDamageDetailByGoodId(good_id, warehousing_order, inventory_type)
  6165. orgId := this.GetAdminUserInfo().CurrentOrgId
  6166. damageList, _ := service.GetStockDamagedCountOne(orgId, warehousing_order, inventory_type)
  6167. this.ServeSuccessJSON(map[string]interface{}{
  6168. "list": list,
  6169. "damageList": damageList,
  6170. })
  6171. }
  6172. func (this *StockManagerApiController) GetInventoryExportList() {
  6173. orgId := this.GetAdminUserInfo().CurrentOrgId
  6174. list, _ := service.GetInventoryExportList(orgId)
  6175. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  6176. this.ServeSuccessJSON(map[string]interface{}{
  6177. "list": list,
  6178. "manufacturerList": manufacturerList,
  6179. })
  6180. }
  6181. func (this *StockManagerApiController) UpdateCancelStockOrder() {
  6182. type_id, _ := this.GetInt64("type_id")
  6183. //获取目前在使用的机构ID
  6184. list, _ := service.GetOrgIdList()
  6185. //耗材
  6186. if type_id == 1 {
  6187. for _, item := range list {
  6188. //查询该机构的所有耗材
  6189. goodList, _ := service.GetAllGoodList(item.OrgId)
  6190. for _, it := range goodList {
  6191. //查询该耗材的入库总数
  6192. info, _ := service.GetStockCountWarehouseInfoById(it.ID)
  6193. var total int64
  6194. for _, its := range info {
  6195. total += its.StockCount
  6196. }
  6197. //更新库存
  6198. service.ModifyGoodAddInformationSeven(it.ID, total, it.OrgId)
  6199. }
  6200. }
  6201. }
  6202. //药品
  6203. if type_id == 2 {
  6204. for _, item := range list {
  6205. fmt.Println(item)
  6206. //查询该机构的所有药品
  6207. drugList, _ := service.GetAllBaseDrugStockList(4)
  6208. for _, it := range drugList {
  6209. //查询该药品的入库总数
  6210. info, _ := service.GetDrugStockCountWarehoseInfoById(it.ID)
  6211. var sum_count int64
  6212. for _, its := range info {
  6213. if its.MaxUnit == it.MaxUnit {
  6214. its.StockMaxNumber = its.StockMaxNumber * it.MinNumber
  6215. }
  6216. sum_count += its.StockMaxNumber + its.StockMinNumber
  6217. }
  6218. service.UpdateModifyDrugInfoById(it.ID, sum_count, it.OrgId)
  6219. }
  6220. }
  6221. }
  6222. }
  6223. func (this *StockManagerApiController) GetDrugDetailSummary() {
  6224. timeLayout := "2006-01-02"
  6225. loc, _ := time.LoadLocation("Local")
  6226. start_time := this.GetString("start_time")
  6227. end_time := this.GetString("end_time")
  6228. var startTime int64
  6229. if len(start_time) > 0 {
  6230. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6231. if err != nil {
  6232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6233. return
  6234. }
  6235. startTime = theTime.Unix()
  6236. fmt.Println("开始时间", startTime)
  6237. }
  6238. var endTime int64
  6239. if len(end_time) > 0 {
  6240. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6241. if err != nil {
  6242. utils.ErrorLog(err.Error())
  6243. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6244. return
  6245. }
  6246. endTime = theTime.Unix()
  6247. }
  6248. keyword := this.GetString("keyword")
  6249. limit, _ := this.GetInt64("limit")
  6250. page, _ := this.GetInt64("page")
  6251. orgId := this.GetAdminUserInfo().CurrentOrgId
  6252. list, total, err := service.GetDrugDetailSummary(startTime, endTime, keyword, limit, page, orgId)
  6253. druglist, _, _ := service.GetDrugDetailSummaryOne(startTime, endTime, keyword, limit, page, orgId)
  6254. patients, _ := service.GetAllpatient(orgId)
  6255. var drugType = "药品类型"
  6256. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  6257. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  6258. for _, item := range list {
  6259. for _, it := range druglist {
  6260. if item.DrugId == it.DrugId {
  6261. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6262. }
  6263. }
  6264. }
  6265. drug, _ := service.GetAllDrugSummary(orgId)
  6266. if err == nil {
  6267. this.ServeSuccessJSON(map[string]interface{}{
  6268. "list": list,
  6269. "total": total,
  6270. "drug": drug,
  6271. "drugTypeList": drugTypeList,
  6272. "patients": patients,
  6273. })
  6274. }
  6275. }
  6276. func (this *StockManagerApiController) GetGoodDetailSummary() {
  6277. timeLayout := "2006-01-02"
  6278. loc, _ := time.LoadLocation("Local")
  6279. start_time := this.GetString("start_time")
  6280. end_time := this.GetString("end_time")
  6281. var startTime int64
  6282. if len(start_time) > 0 {
  6283. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6284. if err != nil {
  6285. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6286. return
  6287. }
  6288. startTime = theTime.Unix()
  6289. }
  6290. var endTime int64
  6291. if len(end_time) > 0 {
  6292. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6293. if err != nil {
  6294. utils.ErrorLog(err.Error())
  6295. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6296. return
  6297. }
  6298. endTime = theTime.Unix()
  6299. }
  6300. keyword := this.GetString("keyword")
  6301. limit, _ := this.GetInt64("limit")
  6302. page, _ := this.GetInt64("page")
  6303. orgId := this.GetAdminUserInfo().CurrentOrgId
  6304. list, total, err := service.GetGoodDetailSummary(startTime, endTime, keyword, limit, page, orgId)
  6305. goodlist, _, _ := service.GetGoodDetailSummaryOne(startTime, endTime, keyword, limit, page, orgId)
  6306. for _, item := range list {
  6307. for _, it := range goodlist {
  6308. if item.ProjectId == it.ProjectId {
  6309. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6310. }
  6311. }
  6312. }
  6313. information, _ := service.GeAllGoodInformation(orgId)
  6314. patients, _ := service.GetAllpatient(orgId)
  6315. goodType, _ := service.GetAllGoodType(orgId)
  6316. if err == nil {
  6317. this.ServeSuccessJSON(map[string]interface{}{
  6318. "list": list,
  6319. "total": total,
  6320. "good": information,
  6321. "patients": patients,
  6322. "goodType": goodType,
  6323. })
  6324. }
  6325. }
  6326. func (this *StockManagerApiController) CheckWarehouseOut() {
  6327. id, _ := this.GetInt64("id")
  6328. orgId := this.GetAdminUserInfo().CurrentOrgId
  6329. creater := this.GetAdminUserInfo().AdminUser.Id
  6330. warehouseOut, errcode := service.GetWarehouseById(id)
  6331. if errcode != nil {
  6332. goodErrcode := models.XtGoodErrcode{
  6333. UserOrgId: orgId,
  6334. Errcode: "查询审核出库单报错",
  6335. GoodId: 0,
  6336. Status: 0,
  6337. Ctime: 0,
  6338. Mtime: 0,
  6339. Count: 0,
  6340. StockCount: 0,
  6341. Creater: creater,
  6342. BatchNumberId: 0,
  6343. WarehouseOutId: 0,
  6344. }
  6345. service.CreateGoodErrcode(goodErrcode)
  6346. }
  6347. //查询已审核的单据
  6348. warehousingOutInfo, erroce := service.GetWarehouseOutById(id, orgId)
  6349. if erroce != nil {
  6350. goodErrcode := models.XtGoodErrcode{
  6351. UserOrgId: orgId,
  6352. Errcode: "查询已审核出库详情单报错",
  6353. GoodId: 0,
  6354. Status: 0,
  6355. Ctime: 0,
  6356. Mtime: 0,
  6357. Count: 0,
  6358. StockCount: 0,
  6359. Creater: creater,
  6360. BatchNumberId: 0,
  6361. WarehouseOutId: 0,
  6362. }
  6363. service.CreateGoodErrcode(goodErrcode)
  6364. }
  6365. ////出库逻辑
  6366. for _, item := range warehousingOutInfo {
  6367. // 查询该耗材是否有库存
  6368. warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId, item.StorehouseId)
  6369. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseId, item.OrgId)
  6370. // 如果出库数量大于该批次剩余库存数量
  6371. if item.Count > warehouseOne.StockCount {
  6372. goodErrcode := models.XtGoodErrcode{
  6373. UserOrgId: orgId,
  6374. Errcode: "出库数量大于该批次剩余库存",
  6375. GoodId: 0,
  6376. Status: 0,
  6377. Ctime: 0,
  6378. Mtime: 0,
  6379. Count: 0,
  6380. StockCount: 0,
  6381. Creater: creater,
  6382. BatchNumberId: warehouseOne.ID,
  6383. WarehouseOutId: item.ID,
  6384. }
  6385. service.CreateGoodErrcode(goodErrcode)
  6386. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6387. this.ServeSuccessJSON(map[string]interface{}{
  6388. "msg": "1",
  6389. "good_name": goodObj.GoodName,
  6390. "specification_name": goodObj.SpecificationName,
  6391. "storehose_name": storehouse.StorehouseName,
  6392. })
  6393. return
  6394. }
  6395. }
  6396. for _, item := range warehousingOutInfo {
  6397. creater := this.GetAdminUserInfo().AdminUser.Id
  6398. //出库
  6399. err := service.ConsumablesDeliveryThirty(orgId, item.SysRecordTime, item, &warehouseOut, item.Count, creater)
  6400. if err != nil {
  6401. goodErrcode := models.XtGoodErrcode{
  6402. UserOrgId: orgId,
  6403. Errcode: "调用出库接口报错",
  6404. GoodId: item.GoodId,
  6405. Status: 1,
  6406. Ctime: time.Now().Unix(),
  6407. Mtime: 0,
  6408. Count: 0,
  6409. StockCount: 0,
  6410. Creater: creater,
  6411. BatchNumberId: 0,
  6412. WarehouseOutId: 0,
  6413. }
  6414. service.CreateGoodErrcode(goodErrcode)
  6415. }
  6416. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6417. var flush_count int64
  6418. for _, it := range goodList {
  6419. flush_count += it.StockCount
  6420. }
  6421. errs := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
  6422. if errs != nil {
  6423. goodErrcode := models.XtGoodErrcode{
  6424. UserOrgId: orgId,
  6425. Errcode: "手动出库更新剩余出库失败",
  6426. GoodId: item.GoodId,
  6427. Status: 1,
  6428. Ctime: time.Now().Unix(),
  6429. Mtime: 0,
  6430. Count: 0,
  6431. StockCount: 0,
  6432. Creater: creater,
  6433. BatchNumberId: 0,
  6434. WarehouseOutId: 0,
  6435. }
  6436. service.CreateGoodErrcode(goodErrcode)
  6437. }
  6438. orgId := this.GetAdminUserInfo().CurrentOrgId
  6439. //查询默认仓库
  6440. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6441. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
  6442. var total_count int64
  6443. for _, it := range stockList {
  6444. total_count += it.StockCount
  6445. }
  6446. //基础库扣减库存
  6447. errsum := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, orgId)
  6448. if errsum != nil {
  6449. goodErrcode := models.XtGoodErrcode{
  6450. UserOrgId: orgId,
  6451. Errcode: "基础库扣减库存报错",
  6452. GoodId: item.GoodId,
  6453. Status: 1,
  6454. Ctime: time.Now().Unix(),
  6455. Mtime: 0,
  6456. Count: 0,
  6457. StockCount: 0,
  6458. Creater: creater,
  6459. BatchNumberId: 0,
  6460. WarehouseOutId: 0,
  6461. }
  6462. service.CreateGoodErrcode(goodErrcode)
  6463. }
  6464. }
  6465. //审核单据
  6466. err := service.UpdatedWarehouseOut(id)
  6467. if err != nil {
  6468. goodErrcode := models.XtGoodErrcode{
  6469. UserOrgId: orgId,
  6470. Errcode: "审核单据报错",
  6471. GoodId: 0,
  6472. Status: 1,
  6473. Ctime: time.Now().Unix(),
  6474. Mtime: 0,
  6475. Count: 0,
  6476. StockCount: 0,
  6477. Creater: creater,
  6478. BatchNumberId: 0,
  6479. WarehouseOutId: 0,
  6480. }
  6481. service.CreateGoodErrcode(goodErrcode)
  6482. }
  6483. if err == nil {
  6484. this.ServeSuccessJSON(map[string]interface{}{
  6485. "msg": "2",
  6486. "good_name": "",
  6487. "specification_name": "",
  6488. "storehose_name": "",
  6489. })
  6490. }
  6491. }
  6492. func (this *StockManagerApiController) ReturnCheckWarehouseOut() {
  6493. id, _ := this.GetInt64("id")
  6494. orgId := this.GetAdminUserInfo().CurrentOrgId
  6495. creater := this.GetAdminUserInfo().AdminUser.Id
  6496. // 查询出库数据
  6497. list, err := service.GetWarehouseOutById(id, orgId)
  6498. if err != nil {
  6499. goodErrcode := models.XtGoodErrcode{
  6500. UserOrgId: orgId,
  6501. Errcode: "反审核查询出库单报错",
  6502. GoodId: 0,
  6503. Status: 1,
  6504. Ctime: time.Now().Unix(),
  6505. Mtime: 0,
  6506. Count: 0,
  6507. StockCount: 0,
  6508. Creater: creater,
  6509. BatchNumberId: 0,
  6510. WarehouseOutId: 0,
  6511. }
  6512. service.CreateGoodErrcode(goodErrcode)
  6513. }
  6514. for _, item := range list {
  6515. //回退库存
  6516. err := service.UpdateaGoodWarehouseInfo(item.Count, item.GoodId, item.OrgId, item.WarehouseInfotId)
  6517. if err != nil {
  6518. goodErrcode := models.XtGoodErrcode{
  6519. UserOrgId: orgId,
  6520. Errcode: "反审核回退库存报错",
  6521. GoodId: 0,
  6522. Status: 1,
  6523. Ctime: time.Now().Unix(),
  6524. Mtime: 0,
  6525. Count: 0,
  6526. StockCount: 0,
  6527. Creater: creater,
  6528. BatchNumberId: 0,
  6529. WarehouseOutId: 0,
  6530. }
  6531. service.CreateGoodErrcode(goodErrcode)
  6532. }
  6533. //查询默认仓库
  6534. storeHouseConfig, errs := service.GetAllStoreHouseConfig(orgId)
  6535. if errs != nil {
  6536. goodErrcode := models.XtGoodErrcode{
  6537. UserOrgId: orgId,
  6538. Errcode: "反审核查询默认仓库报错",
  6539. GoodId: 0,
  6540. Status: 1,
  6541. Ctime: time.Now().Unix(),
  6542. Mtime: 0,
  6543. Count: 0,
  6544. StockCount: 0,
  6545. Creater: creater,
  6546. BatchNumberId: 0,
  6547. WarehouseOutId: 0,
  6548. }
  6549. service.CreateGoodErrcode(goodErrcode)
  6550. }
  6551. stockList, errcodes := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
  6552. if errcodes != nil {
  6553. goodErrcode := models.XtGoodErrcode{
  6554. UserOrgId: orgId,
  6555. Errcode: "反审核查询默认仓库库存报错",
  6556. GoodId: 0,
  6557. Status: 1,
  6558. Ctime: time.Now().Unix(),
  6559. Mtime: 0,
  6560. Count: 0,
  6561. StockCount: 0,
  6562. Creater: creater,
  6563. BatchNumberId: 0,
  6564. WarehouseOutId: 0,
  6565. }
  6566. service.CreateGoodErrcode(goodErrcode)
  6567. }
  6568. var total_count int64
  6569. for _, it := range stockList {
  6570. total_count += it.StockCount
  6571. }
  6572. //基础库扣减库存
  6573. errs = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, orgId)
  6574. if errs != nil {
  6575. goodErrcode := models.XtGoodErrcode{
  6576. UserOrgId: orgId,
  6577. Errcode: "反审核基础库扣减库存报错",
  6578. GoodId: 0,
  6579. Status: 1,
  6580. Ctime: time.Now().Unix(),
  6581. Mtime: 0,
  6582. Count: 0,
  6583. StockCount: 0,
  6584. Creater: creater,
  6585. BatchNumberId: 0,
  6586. WarehouseOutId: 0,
  6587. }
  6588. service.CreateGoodErrcode(goodErrcode)
  6589. }
  6590. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6591. var flush_count int64
  6592. for _, it := range goodList {
  6593. flush_count += it.StockCount
  6594. }
  6595. erros := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
  6596. if erros != nil {
  6597. goodErrcode := models.XtGoodErrcode{
  6598. UserOrgId: orgId,
  6599. Errcode: "手动出库更新剩余库存报错",
  6600. GoodId: 0,
  6601. Status: 1,
  6602. Ctime: time.Now().Unix(),
  6603. Mtime: 0,
  6604. Count: 0,
  6605. StockCount: 0,
  6606. Creater: creater,
  6607. BatchNumberId: 0,
  6608. WarehouseOutId: 0,
  6609. }
  6610. service.CreateGoodErrcode(goodErrcode)
  6611. }
  6612. //扣减出库数据
  6613. errcoeds := service.ModifyReduceGoodSumCount(item.StorehouseId, item.Count, orgId, item.GoodId)
  6614. if errcoeds != nil {
  6615. goodErrcode := models.XtGoodErrcode{
  6616. UserOrgId: orgId,
  6617. Errcode: "反审核扣减出库数据报错",
  6618. GoodId: 0,
  6619. Status: 1,
  6620. Ctime: time.Now().Unix(),
  6621. Mtime: 0,
  6622. Count: 0,
  6623. StockCount: 0,
  6624. Creater: creater,
  6625. BatchNumberId: 0,
  6626. WarehouseOutId: 0,
  6627. }
  6628. service.CreateGoodErrcode(goodErrcode)
  6629. }
  6630. }
  6631. //删除流水,改变审核状态
  6632. errcos := service.ModifyGoodWarehouseOut(id)
  6633. if errcos != nil {
  6634. goodErrcode := models.XtGoodErrcode{
  6635. UserOrgId: orgId,
  6636. Errcode: "反审核删除流水,改变审核状态报错",
  6637. GoodId: 0,
  6638. Status: 1,
  6639. Ctime: time.Now().Unix(),
  6640. Mtime: 0,
  6641. Count: 0,
  6642. StockCount: 0,
  6643. Creater: creater,
  6644. BatchNumberId: 0,
  6645. WarehouseOutId: 0,
  6646. }
  6647. service.CreateGoodErrcode(goodErrcode)
  6648. }
  6649. if err == nil {
  6650. this.ServeSuccessJSON(map[string]interface{}{
  6651. "list": "list",
  6652. })
  6653. }
  6654. }
  6655. func (this *StockManagerApiController) CheckWarehouseInfo() {
  6656. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  6657. orgId := this.GetAdminUserInfo().CurrentOrgId
  6658. Creator := this.GetAdminUserInfo().AdminUser.Id
  6659. //查询默认仓库
  6660. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6661. checker := this.GetAdminUserInfo().AdminUser.Id
  6662. //更改审核状态
  6663. err := service.UpdateCheckWarehouseInfo(warehousing_info_id, checker)
  6664. if err == nil {
  6665. list, _ := service.GetWarehouseInfoList(warehousing_info_id, orgId)
  6666. for _, item := range list {
  6667. service.UpdateWarehouseInfoByIdListThree(item.WarehousingCount, item.ID)
  6668. //查询该耗材剩余库存库
  6669. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
  6670. var total_count int64
  6671. var sum_in_count int64
  6672. for _, it := range stockList {
  6673. total_count += it.StockCount
  6674. sum_in_count += it.WarehousingCount
  6675. }
  6676. //基础库插入数据
  6677. service.UpdateGoodInfoAddSumCount(item.GoodId, total_count, orgId, sum_in_count)
  6678. //查询该仓库是否有数据
  6679. _, errcode := service.GetGoodStockCount(orgId, item.StorehouseId, item.GoodId)
  6680. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6681. var flush_count int64
  6682. for _, it := range goodList {
  6683. flush_count += it.StockCount
  6684. }
  6685. stockFlow := models.VmStockFlow{
  6686. WarehousingId: item.WarehousingId,
  6687. GoodId: item.GoodId,
  6688. Number: item.Number,
  6689. LicenseNumber: item.LicenseNumber,
  6690. Count: item.WarehousingCount,
  6691. UserOrgId: item.OrgId,
  6692. PatientId: 0,
  6693. SystemTime: 0,
  6694. ConsumableType: 1,
  6695. IsSys: 1,
  6696. WarehousingOrder: item.WarehousingOrder,
  6697. WarehouseOutId: 0,
  6698. WarehouseOutOrderNumber: "",
  6699. IsEdit: 1,
  6700. CancelStockId: 0,
  6701. CancelOrderNumber: "",
  6702. Manufacturer: item.Manufacturer,
  6703. Dealer: item.Dealer,
  6704. Creator: Creator,
  6705. UpdateCreator: 0,
  6706. Status: 1,
  6707. Ctime: time.Now().Unix(),
  6708. Mtime: 0,
  6709. Price: item.PackingPrice,
  6710. WarehousingDetailId: item.ID,
  6711. WarehouseOutDetailId: 0,
  6712. CancelOutDetailId: 0,
  6713. ProductDate: item.ProductDate,
  6714. ExpireDate: item.ExpiryDate,
  6715. SupplyWarehouseId: item.SupplyWarehouseId,
  6716. StorehouseId: item.StorehouseId,
  6717. AdminUserId: 0,
  6718. BuyPrice: item.Price,
  6719. StockCount: "",
  6720. BatchNumberCount: item.WarehousingCount,
  6721. IsCheck: 1,
  6722. OverCount: flush_count,
  6723. }
  6724. //创建出库流水
  6725. service.CreateStockFlowOne(stockFlow)
  6726. if errcode == gorm.ErrRecordNotFound {
  6727. goodCount := models.XtGoodStockCount{
  6728. UserOrgId: orgId,
  6729. GoodId: item.GoodId,
  6730. StorehouseId: item.StorehouseId,
  6731. Status: 1,
  6732. Ctime: time.Now().Unix(),
  6733. Mtime: time.Now().Unix(),
  6734. StockInCount: item.WarehousingCount,
  6735. StockOutCount: 0,
  6736. StockCancelCount: 0,
  6737. FlushCount: flush_count,
  6738. StockActOutCount: 0,
  6739. }
  6740. service.CreateGoodCount(goodCount)
  6741. }
  6742. if errcode == nil {
  6743. service.UpdateGoodStockCount(orgId, item.StorehouseId, item.GoodId, item.WarehousingCount, flush_count)
  6744. }
  6745. }
  6746. }
  6747. if err == nil {
  6748. this.ServeSuccessJSON(map[string]interface{}{
  6749. "list": "list",
  6750. })
  6751. }
  6752. }
  6753. func (this *StockManagerApiController) ReturnCheckWarehouseInfo() {
  6754. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  6755. orgId := this.GetAdminUserInfo().CurrentOrgId
  6756. //查询入库数据
  6757. list, _ := service.GetWarehouseInfoList(warehousing_info_id, orgId)
  6758. for _, item := range list {
  6759. //查询该耗材 是否有出库数据
  6760. outlist, _ := service.GetWarehouseOutByWarehouseInfoId(item.ID, item.GoodId, item.OrgId)
  6761. if len(outlist) > 0 {
  6762. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCheckGoodParamWrong)
  6763. return
  6764. }
  6765. }
  6766. //for _, item := range list {
  6767. //
  6768. // //扣减数量
  6769. // service.UpdateWarehouseInfoByIdListTwo(item.WarehousingCount, item.ID)
  6770. //
  6771. // //删除流水
  6772. // service.UpdateWarehouseInfoFlow(item.ID)
  6773. //
  6774. // goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6775. // var flush_count int64
  6776. // for _, it := range goodList {
  6777. // flush_count += it.StockCount
  6778. // }
  6779. //
  6780. // //扣减数量
  6781. // service.UpdateGoodInCount(item.WarehousingCount, item.OrgId, item.GoodId, item.StorehouseId, flush_count)
  6782. //
  6783. // //查询默认仓库
  6784. // storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6785. // //查询该耗材剩余多少库存
  6786. // stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
  6787. // var sum_count int64
  6788. // var sum_in_count int64
  6789. // for _, it := range stockList {
  6790. // sum_count += it.StockCount
  6791. // sum_in_count += it.WarehousingCount
  6792. // }
  6793. // service.UpdateGoodInfoAddSumCount(item.GoodId, sum_count, orgId, sum_in_count)
  6794. //}
  6795. //err := service.ReturnCheckWarehouseInfo(warehousing_info_id)
  6796. err := service.UpdateWarehouseInfoMap(list, warehousing_info_id, orgId)
  6797. if err == nil {
  6798. this.ServeSuccessJSON(map[string]interface{}{
  6799. "msg": "反审核成功!",
  6800. })
  6801. return
  6802. }
  6803. }
  6804. func (this *StockManagerApiController) CheckStockWarehouseInfo() {
  6805. cancel_stock_id, _ := this.GetInt64("cancel_stock_id")
  6806. orgId := this.GetAdminUserInfo().CurrentOrgId
  6807. list, _ := service.GetCancelStockInfoListById(cancel_stock_id, orgId)
  6808. creater := this.GetAdminUserInfo().AdminUser.Id
  6809. manufacturerlist, _ := service.GetAllManufacturerList(orgId)
  6810. dealerList, _ := service.GetAllDealerList(orgId)
  6811. var manufacturer_id int64
  6812. var cancel_total_count int64
  6813. var out_total_count int64
  6814. var dealer_id int64
  6815. for _, item := range list {
  6816. //查询该药品该批次的出库数量是否满足退库需求
  6817. outList, _ := service.GetWarehouseOutList(item.OrgId, item.GoodId, item.WarehouseInfoId)
  6818. for _, it := range outList {
  6819. out_total_count += it.Count
  6820. }
  6821. warehouseList, _ := service.GetCancelWarehouseList(item.OrgId, item.GoodId, item.WarehouseInfoId)
  6822. for _, it := range warehouseList {
  6823. cancel_total_count += it.Count
  6824. }
  6825. if cancel_total_count > out_total_count {
  6826. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6827. this.ServeSuccessJSON(map[string]interface{}{
  6828. "msg": "2",
  6829. "good_name": goodObj.GoodName,
  6830. "specification_name": goodObj.SpecificationName,
  6831. })
  6832. return
  6833. }
  6834. }
  6835. cancelStock := models.CancelStock{
  6836. IsCheck: 1,
  6837. }
  6838. service.CheckCancelStock(cancelStock, cancel_stock_id, orgId)
  6839. //回退库存
  6840. cancellist, _ := service.GetCancelStockInfoById(cancel_stock_id, orgId)
  6841. for _, item := range cancellist {
  6842. for _, items := range manufacturerlist {
  6843. if item.Manufacturer == items.ManufacturerName {
  6844. manufacturer_id = items.ID
  6845. }
  6846. }
  6847. for _, it := range dealerList {
  6848. if item.Dealer == it.DealerName {
  6849. dealer_id = it.ID
  6850. }
  6851. }
  6852. //回退库存
  6853. service.UpdateCancelStockNumber(item.Count, item.WarehouseInfoId, orgId)
  6854. //更新基础库库存
  6855. service.UpdateGoodSumCount(item.Count, item.GoodId, orgId)
  6856. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6857. //退库数量增加
  6858. service.UpdateSumAddCancelCount(orgId, item.GoodId, item.StorehouseId, item.Count)
  6859. var flush_count int64
  6860. for _, it := range goodList {
  6861. flush_count += it.StockCount
  6862. }
  6863. stockFlow := models.VmStockFlow{
  6864. ID: 0,
  6865. WarehousingId: item.WarehouseInfoId,
  6866. GoodId: item.GoodId,
  6867. Number: item.Number,
  6868. LicenseNumber: "",
  6869. Count: item.Count,
  6870. UserOrgId: item.OrgId,
  6871. PatientId: item.PatientId,
  6872. SystemTime: item.RecordDate,
  6873. ConsumableType: 4,
  6874. IsSys: 0,
  6875. WarehousingOrder: "",
  6876. WarehouseOutId: 0,
  6877. WarehouseOutOrderNumber: "",
  6878. IsEdit: 0,
  6879. CancelStockId: cancel_stock_id,
  6880. CancelOrderNumber: item.OrderNumber,
  6881. Manufacturer: manufacturer_id,
  6882. Dealer: dealer_id,
  6883. Creator: creater,
  6884. UpdateCreator: 0,
  6885. Status: 1,
  6886. Ctime: time.Now().Unix(),
  6887. Mtime: 0,
  6888. Price: item.Price,
  6889. WarehousingDetailId: item.WarehouseInfoId,
  6890. WarehouseOutDetailId: 0,
  6891. CancelOutDetailId: item.ID,
  6892. ProductDate: item.ProductDate,
  6893. ExpireDate: item.ExpiryDate,
  6894. ReturnCount: 0,
  6895. ProjectId: 0,
  6896. SupplyWarehouseId: 0,
  6897. SupplyCancelOutId: 0,
  6898. SupplyWarehouseDetailInfo: 0,
  6899. StorehouseId: item.StorehouseId,
  6900. SecondWarehouseInfoId: 0,
  6901. AdminUserId: 0,
  6902. BuyPrice: item.Price,
  6903. StockCount: "",
  6904. OverCount: flush_count,
  6905. }
  6906. //创建流水
  6907. service.CreateStockFlowOne(stockFlow)
  6908. //更新剩余库存
  6909. errs := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
  6910. //出库数量减少
  6911. service.ModifyAddGoodSumCount(item.StorehouseId, item.Count, orgId, item.GoodId)
  6912. if errs != nil {
  6913. goodErrcode := models.XtGoodErrcode{
  6914. UserOrgId: item.OrgId,
  6915. Errcode: "手动退库更新剩余出库失败",
  6916. GoodId: item.GoodId,
  6917. Status: 1,
  6918. Ctime: time.Now().Unix(),
  6919. Mtime: 0,
  6920. Count: 0,
  6921. StockCount: 0,
  6922. Creater: creater,
  6923. BatchNumberId: 0,
  6924. WarehouseOutId: 0,
  6925. }
  6926. service.CreateGoodErrcode(goodErrcode)
  6927. }
  6928. }
  6929. this.ServeSuccessJSON(map[string]interface{}{
  6930. "msg": "1",
  6931. "good_name": "",
  6932. "specification_name": "",
  6933. })
  6934. return
  6935. }
  6936. func (this *StockManagerApiController) CheckReturnStockWarehouseInfo() {
  6937. cancel_stock_id, _ := this.GetInt64("cancel_stock_id")
  6938. orgId := this.GetAdminUserInfo().CurrentOrgId
  6939. cancelStock := models.CancelStock{
  6940. IsCheck: 2,
  6941. }
  6942. list, _ := service.GetCancelStockInfoListById(cancel_stock_id, orgId)
  6943. creater := this.GetAdminUserInfo().AdminUser.Id
  6944. for _, item := range list {
  6945. //回退库存
  6946. service.UpdateStockNumberWarehouseInfo(item.WarehouseInfoId, item.GoodId, item.OrgId, item.Count)
  6947. service.UpdateStockWarehouseInfoStockFlow(item.ID, orgId, item.GoodId)
  6948. //退库数量增加
  6949. service.UpdateSumReduceCancelCount(orgId, item.GoodId, item.StorehouseId, item.Count)
  6950. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6951. var flush_count int64
  6952. for _, it := range goodList {
  6953. flush_count += it.StockCount
  6954. }
  6955. errs := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
  6956. //出库数量增加
  6957. service.UpdateSumAddOutCount(orgId, item.GoodId, item.StorehouseId, item.Count)
  6958. if errs != nil {
  6959. goodErrcode := models.XtGoodErrcode{
  6960. UserOrgId: item.OrgId,
  6961. Errcode: "手动退库反审核更新剩余出库失败",
  6962. GoodId: item.GoodId,
  6963. Status: 1,
  6964. Ctime: time.Now().Unix(),
  6965. Mtime: 0,
  6966. Count: 0,
  6967. StockCount: 0,
  6968. Creater: creater,
  6969. BatchNumberId: 0,
  6970. WarehouseOutId: 0,
  6971. }
  6972. service.CreateGoodErrcode(goodErrcode)
  6973. }
  6974. }
  6975. err := service.UpdateStockWarehouseInfo(cancel_stock_id, orgId, cancelStock)
  6976. if err == nil {
  6977. this.ServeSuccessJSON(map[string]interface{}{
  6978. "msg": "反审核成功!",
  6979. })
  6980. return
  6981. }
  6982. }
  6983. func (this *StockManagerApiController) GetPrintList() {
  6984. storehouse_id, _ := this.GetInt64("storehouse_id")
  6985. limit, _ := this.GetInt64("limit")
  6986. page, _ := this.GetInt64("page")
  6987. good_name := this.GetString("good_name")
  6988. fmt.Println(storehouse_id, good_name)
  6989. orgId := this.GetAdminUserInfo().CurrentOrgId
  6990. houseList, _ := service.GetAllStoreHouseList(orgId)
  6991. list, total, _ := service.GetInventoryDetailList(good_name, limit, page, orgId, storehouse_id)
  6992. this.ServeSuccessJSON(map[string]interface{}{
  6993. "list": list,
  6994. "total": total,
  6995. "houseList": houseList,
  6996. })
  6997. }
  6998. func (this *StockManagerApiController) GetInvetoryWarehouseInfoList() {
  6999. storehouse_id, _ := this.GetInt64("storehouse_id")
  7000. orgId := this.GetAdminUserInfo().CurrentOrgId
  7001. list, _ := service.GetInvetoryWarehouseInfoList(orgId, storehouse_id)
  7002. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  7003. dealerList, _ := service.GetAllDealerList(orgId)
  7004. this.ServeSuccessJSON(map[string]interface{}{
  7005. "list": list,
  7006. "manufacturerList": manufacturerList,
  7007. "dealerList": dealerList,
  7008. })
  7009. }
  7010. func (this *StockManagerApiController) GetNewGoodWarehouseInfo() {
  7011. timeLayout := "2006-01-02"
  7012. loc, _ := time.LoadLocation("Local")
  7013. start_time := this.GetString("start_time")
  7014. end_time := this.GetString("end_time")
  7015. var startTime int64
  7016. if len(start_time) > 0 {
  7017. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7018. if err != nil {
  7019. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7020. return
  7021. }
  7022. startTime = theTime.Unix()
  7023. }
  7024. var endTime int64
  7025. if len(end_time) > 0 {
  7026. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7027. if err != nil {
  7028. utils.ErrorLog(err.Error())
  7029. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7030. return
  7031. }
  7032. endTime = theTime.Unix()
  7033. }
  7034. storehouse_id, _ := this.GetInt64("storehouse_id")
  7035. keywords := this.GetString("keywords")
  7036. orgId := this.GetAdminUserInfo().CurrentOrgId
  7037. var goodids []int64
  7038. //查询商品名称
  7039. if len(keywords) > 0 {
  7040. //查询商品名称
  7041. list, _ := service.GetGoodInforByGoodName(keywords, orgId)
  7042. for _, item := range list {
  7043. goodids = append(goodids, item.ID)
  7044. //入库详情但里面查询
  7045. }
  7046. }
  7047. list, _ := service.GetNewGoodWarehouseInfo(startTime, endTime, orgId, goodids, storehouse_id)
  7048. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  7049. dealerList, _ := service.GetAllDealerList(orgId)
  7050. storeHouseList, _ := service.GetAllStoreHouseList(orgId)
  7051. this.ServeSuccessJSON(map[string]interface{}{
  7052. "list": list,
  7053. "manufacturerList": manufacturerList,
  7054. "dealerList": dealerList,
  7055. "storeHouseList": storeHouseList,
  7056. })
  7057. }
  7058. func (this *StockManagerApiController) GetNewWarehouseOutInfoList() {
  7059. timeLayout := "2006-01-02"
  7060. loc, _ := time.LoadLocation("Local")
  7061. start_time := this.GetString("start_time")
  7062. end_time := this.GetString("end_time")
  7063. var startTime int64
  7064. if len(start_time) > 0 {
  7065. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7066. if err != nil {
  7067. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7068. return
  7069. }
  7070. startTime = theTime.Unix()
  7071. }
  7072. var endTime int64
  7073. if len(end_time) > 0 {
  7074. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7075. if err != nil {
  7076. utils.ErrorLog(err.Error())
  7077. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7078. return
  7079. }
  7080. endTime = theTime.Unix()
  7081. }
  7082. storehouse_id, _ := this.GetInt64("storehouse_id")
  7083. keywords := this.GetString("keyword")
  7084. orgId := this.GetAdminUserInfo().CurrentOrgId
  7085. var goodids []int64
  7086. //查询商品名称
  7087. if len(keywords) > 0 {
  7088. //查询商品名称
  7089. list, _ := service.GetGoodInforByGoodName(keywords, orgId)
  7090. for _, item := range list {
  7091. goodids = append(goodids, item.ID)
  7092. //入库详情但里面查询
  7093. }
  7094. }
  7095. list, _ := service.GetNewWarehouseOutInfoList(startTime, endTime, orgId, goodids, storehouse_id)
  7096. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  7097. dealerList, _ := service.GetAllDealerList(orgId)
  7098. storeHouseList, _ := service.GetAllStoreHouseList(orgId)
  7099. this.ServeSuccessJSON(map[string]interface{}{
  7100. "list": list,
  7101. "manufacturerList": manufacturerList,
  7102. "dealerList": dealerList,
  7103. "storeHouseList": storeHouseList,
  7104. })
  7105. }