stock_in_api_controller.go 257KB

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