stock_in_api_controller.go 274KB

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