stock_in_api_controller.go 275KB

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