stock_in_api_controller.go 261KB

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