stock_in_api_controller.go 210KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "reflect"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type StockManagerApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func StockManagerApiRegistRouters() {
  20. //入库管理和其他入库管理相关接口
  21. beego.Router("/api/warehouse/create", &StockManagerApiController{}, "post:CreateWarehouse")
  22. beego.Router("/api/warehouse/list", &StockManagerApiController{}, "get:GetWarehouseList")
  23. beego.Router("/api/warehouse/delete", &StockManagerApiController{}, "post:DeleteWarehouse")
  24. beego.Router("/api/warehouseinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseInfo")
  25. beego.Router("/api/warehouseinfo/list", &StockManagerApiController{}, "get:GetWarehouseInfoList")
  26. beego.Router("/api/warehouse/edit", &StockManagerApiController{}, "post:EditWarehouse")
  27. //退货管理和其他退货管理相关接口
  28. beego.Router("/api/salesreturn/create", &StockManagerApiController{}, "post:CreateSalesReturn")
  29. beego.Router("/api/salesreturn/delete", &StockManagerApiController{}, "post:DeleteSalesReturn")
  30. beego.Router("/api/salesreturninfo/delete", &StockManagerApiController{}, "post:DeleteSalesReturnInfo")
  31. beego.Router("/api/salesreturninfo/list", &StockManagerApiController{}, "get:GetSalesReturnInfoList")
  32. beego.Router("/api/salesreturn/list", &StockManagerApiController{}, "get:GetSalesReturnList")
  33. beego.Router("/api/salesreturn/edit", &StockManagerApiController{}, "post:EditReturnInfo")
  34. //出库管理和其他出库管理相关接口
  35. beego.Router("/api/warehouseout/create", &StockManagerApiController{}, "post:CreateWarehouseOut")
  36. beego.Router("/api/warehouseout/delete", &StockManagerApiController{}, "post:DeleteWarehouseOut")
  37. beego.Router("/api/warehouseoutinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseOutInfo")
  38. beego.Router("/api/warehouseout/list", &StockManagerApiController{}, "get:GetWarehouseOutList")
  39. beego.Router("/api/warehouseout/edit", &StockManagerApiController{}, "post:EditWarehouseOut")
  40. beego.Router("/api/warehouseout/info", &StockManagerApiController{}, "get:GetWarehouseOutInfoList")
  41. //出库退库管理和其他出库退库管理相关接口
  42. beego.Router("/api/cancelstock/create", &StockManagerApiController{}, "post:CreateCancelStock")
  43. beego.Router("/api/cancelstock/list", &StockManagerApiController{}, "get:GetCancelStockList")
  44. beego.Router("/api/cancelstock/info", &StockManagerApiController{}, "get:GetCancelStockInfoList")
  45. beego.Router("/api/cancelstock/delete", &StockManagerApiController{}, "post:DeleteCancelStock")
  46. beego.Router("/api/cancelstockinfo/delete", &StockManagerApiController{}, "post:DeleteCancelStockInfo")
  47. beego.Router("/api/cancelstockinfo/edit", &StockManagerApiController{}, "post:EditCancelStock")
  48. beego.Router("/api/cancelstockinfo/config", &StockManagerApiController{}, "get:GetCancelStockConfig")
  49. //库存相关全局配置
  50. beego.Router("/api/stock/config", &StockManagerApiController{}, "get:GetAllConfig")
  51. beego.Router("/api/return/config", &StockManagerApiController{}, "get:GetAllSalesReturnConfig")
  52. //库存查询
  53. beego.Router("/api/stock/query", &StockManagerApiController{}, "get:GetQueryInfo")
  54. beego.Router("/api/stock/detail", &StockManagerApiController{}, "get:GetDetailInfo")
  55. beego.Router("/api/warehouseout/user", &StockManagerApiController{}, "get:GetUserDetailInfo")
  56. beego.Router("/api/warehouseout/postsearchstock", &StockManagerApiController{}, "Get:PostSearchStock")
  57. beego.Router("/api/warehouseout/getoutstocktotalcount", &StockManagerApiController{}, "Get:GetOutStockTotalCount")
  58. beego.Router("/api/good/postgoodinformation", &StockManagerApiController{}, "Post:AddGoodInformation")
  59. beego.Router("/api/good/postdruginformation", &StockManagerApiController{}, "Post:AddDrugInformation")
  60. beego.Router("/api/good/initializtion", &StockManagerApiController{}, "Get:GetInitializtion")
  61. beego.Router("/api/good/getwarehouseorderinfolist", &StockManagerApiController{}, "Get:GetWarehouseOrderInfolist")
  62. beego.Router("/api/good/postsearchgoodlist", &StockManagerApiController{}, "Get:PostSearchGoodList")
  63. beego.Router("/api/good/getallstocklist", &StockManagerApiController{}, "Get:GetAllStockList")
  64. beego.Router("/api/stock/getstocklistbyid", &StockManagerApiController{}, "Get:GetStockListById")
  65. beego.Router("/api/stock/getstockoutlist", &StockManagerApiController{}, "Get:GetStockOutList")
  66. beego.Router("/api/good/getstockdrugcount", &StockManagerApiController{}, "Get:GetStockDrugCount")
  67. beego.Router("/api/good/getorderdetialbyorderid", &StockManagerApiController{}, "Get:GetOrderDetialByOrderId")
  68. beego.Router("/api/good/getorderdetaibyid", &StockManagerApiController{}, "Get:GetOrderDetailById")
  69. beego.Router("/api/good/getsingleoutorderdetail", &StockManagerApiController{}, "Get:GetSingleOutOrderDetail")
  70. beego.Router("/api/stock/getexportstocklist", &StockManagerApiController{}, "Get:GetExprotStockList")
  71. beego.Router("/api/stock/getoutexprotlist", &StockManagerApiController{}, "Get:GetOutExprotList")
  72. beego.Router("/api/stock/getsinglecancelorder", &StockManagerApiController{}, "Get:GetSingleCancelOrder")
  73. beego.Router("/api/stock/getcancelstockorderprint", &StockManagerApiController{}, "Get:GetCancelStockOrderPrint")
  74. beego.Router("/api/stock/getstockbatchnumber", &StockManagerApiController{}, "Get:GetStockBatchNumber")
  75. beego.Router("/api/stock/getstockflow", &StockManagerApiController{}, "Get:GetStockFlow")
  76. beego.Router("/api/cancel/getcancelexportlist", &StockManagerApiController{}, "Get:GetCancelExportList")
  77. //耗材调价
  78. beego.Router("/api/stock/postsearchgoodwarehouselist", &StockManagerApiController{}, "Get:GetSearchGoodWarehouseList")
  79. beego.Router("/api/stock/saveadjustprice", &StockManagerApiController{}, "Post:SaveAdjuestPrice")
  80. beego.Router("/api/stock/getallstockprice", &StockManagerApiController{}, "Get:GetAllStockPrice")
  81. beego.Router("/api/stock/savecheckedprice", &StockManagerApiController{}, "Get:SaveCheckPrice")
  82. beego.Router("/api/stock/getadjustpriceinfo", &StockManagerApiController{}, "Get:GetAdjustPriceById")
  83. beego.Router("/api/stock/savereportstock", &StockManagerApiController{}, "Post:SaveReportStock")
  84. beego.Router("/api/stock/getreportstocklist", &StockManagerApiController{}, "Get:GetReportStockList")
  85. beego.Router("/api/stock/savecheckdamage", &StockManagerApiController{}, "Get:SaveCheckDamage")
  86. beego.Router("/api/stock/saveinventory", &StockManagerApiController{}, "Post:SaveInventory")
  87. beego.Router("/api/stock/getinventorylist", &StockManagerApiController{}, "Get:GetInventorylist")
  88. beego.Router("/api/stock/savecheckinventory", &StockManagerApiController{}, "Get:SaveCheckInventory")
  89. beego.Router("/api/stock/getmodifypriceDetail", &StockManagerApiController{}, "Get:GetModifyPriceDetail")
  90. beego.Router("/api/stock/updatestockprice", &StockManagerApiController{}, "Get:UpdateStockPrice")
  91. beego.Router("/api/stock/deletestockprice", &StockManagerApiController{}, "Get:DeleteStockPrice")
  92. beego.Router("/api/stock/getstockdamagedetal", &StockManagerApiController{}, "Get:GetStockDamageDetail")
  93. beego.Router("/api/sotck/modifyprice", &StockManagerApiController{}, "Get:ModifyPrice")
  94. beego.Router("/api/stock/deletestockdamage", &StockManagerApiController{}, "Get:DeleteDamage")
  95. beego.Router("/api/stock/getstockdamagebyid", &StockManagerApiController{}, "Get:GetStockDamageById")
  96. beego.Router("api/sotck/getinventorydetail", &StockManagerApiController{}, "Get:GetInventoryDetail")
  97. beego.Router("/api/stock/modifyinventory", &StockManagerApiController{}, "Get:ModifyInventory")
  98. beego.Router("/api/stock/deleteinventory", &StockManagerApiController{}, "Get:DeleteInventory")
  99. beego.Router("/api/stock/getinventorydetaillist", &StockManagerApiController{}, "Get:GetInventoryDetailList")
  100. beego.Router("/api/stock/getinventoryprintlist", &StockManagerApiController{}, "Get:GetInventoryPrintList")
  101. beego.Router("/api/stock/getinventorydetailprintlist", &StockManagerApiController{}, "Get:GetInventoryDetailPrintList")
  102. beego.Router("/api/drug/deletedrugprice", &StockManagerApiController{}, "Get:DeleteDrugPrice")
  103. beego.Router("/api/stock/getgoodwarehouselist", &StockManagerApiController{}, "Get:GetGoodWarehouseList")
  104. beego.Router("/api/stock/proofinventory", &StockManagerApiController{}, "Get:ProofInventory")
  105. beego.Router("/api/stock/getwarehousetotal", &StockManagerApiController{}, "Get:GetWarehouseTotal")
  106. beego.Router("/api/stock/getgoodinventorywarehouselist", &StockManagerApiController{}, "Get:GetGoodInventoryWarehouseList")
  107. beego.Router("/api/stock/savestockinentorylist", &StockManagerApiController{}, "Post:SaveStockInventoryList")
  108. beego.Router("/api/sotck/getdamagedetailbygoodid", &StockManagerApiController{}, "Get:GetDamageDetailByGoodId")
  109. }
  110. func (c *StockManagerApiController) CreateWarehouse() {
  111. warehousing_time := c.GetString("warehousing_time")
  112. types, _ := c.GetInt64("type", 0)
  113. ctime := time.Now().Unix()
  114. adminUserInfo := c.GetAdminUserInfo()
  115. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  116. if parseDateErr != nil {
  117. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  119. return
  120. }
  121. timeStr := time.Now().Format("2006-01-02")
  122. timeArr := strings.Split(timeStr, "-")
  123. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  124. total = total + 1
  125. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  126. operation_time := time.Now().Unix()
  127. creater := adminUserInfo.AdminUser.Id
  128. warehousing := models.Warehousing{
  129. WarehousingOrder: warehousing_order,
  130. OperationTime: operation_time,
  131. OrgId: adminUserInfo.CurrentOrgId,
  132. Creater: creater,
  133. Ctime: ctime,
  134. Status: 1,
  135. WarehousingTime: warehousingDate.Unix(),
  136. Type: types,
  137. }
  138. service.AddSigleWarehouse(&warehousing)
  139. dataBody := make(map[string]interface{}, 0)
  140. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  141. if err != nil {
  142. utils.ErrorLog(err.Error())
  143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  144. return
  145. }
  146. var warehousingInfo []*models.WarehousingInfo
  147. var stockFlow []*models.VmStockFlow
  148. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  149. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  150. if len(thisStockIn) > 0 {
  151. for _, item := range thisStockIn {
  152. items := item.(map[string]interface{})
  153. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  154. utils.ErrorLog("good_id")
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  156. return
  157. }
  158. good_id := int64(items["good_id"].(float64))
  159. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  160. utils.ErrorLog("good_type_id")
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  162. return
  163. }
  164. good_type_id := int64(items["good_type_id"].(float64))
  165. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  166. utils.ErrorLog("warehousing_count")
  167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. return
  169. }
  170. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  171. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  172. utils.ErrorLog("price")
  173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. return
  175. }
  176. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  177. total := float64(warehousing_count) * price
  178. var productDates int64
  179. var expiryDates int64
  180. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  181. expiryDates = 0
  182. } else {
  183. if len(items["expiry_date"].(string)) == 0 {
  184. expiryDates = 0
  185. } else {
  186. expiryDate, _ := items["expiry_date"].(string)
  187. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  188. expiryDates = expiry_date.Unix()
  189. }
  190. }
  191. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  192. productDates = 0
  193. } else {
  194. if len(items["product_date"].(string)) == 0 {
  195. productDates = 0
  196. } else {
  197. productDate, _ := items["product_date"].(string)
  198. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  199. productDates = product_date.Unix()
  200. }
  201. }
  202. number, _ := items["number"].(string)
  203. remark, _ := items["remark"].(string)
  204. manufacturer := int64(items["manufacturer"].(float64))
  205. dealer := int64(items["dealer"].(float64))
  206. license_number, _ := items["license_number"].(string)
  207. //入库单表格
  208. warehouseInfo := &models.WarehousingInfo{
  209. WarehousingOrder: warehousing.WarehousingOrder,
  210. WarehousingId: warehousing.ID,
  211. GoodId: good_id,
  212. Number: number,
  213. GoodTypeId: good_type_id,
  214. ProductDate: productDates,
  215. ExpiryDate: expiryDates,
  216. WarehousingCount: warehousing_count,
  217. Price: price,
  218. TotalPrice: total,
  219. Status: 1,
  220. Ctime: ctime,
  221. Remark: remark,
  222. OrgId: adminUserInfo.CurrentOrgId,
  223. Type: types,
  224. Manufacturer: manufacturer,
  225. StockCount: warehousing_count,
  226. Dealer: dealer,
  227. LicenseNumber: license_number,
  228. }
  229. warehousingInfo = append(warehousingInfo, warehouseInfo)
  230. flow := &models.VmStockFlow{
  231. WarehousingOrder: warehousing.WarehousingOrder,
  232. WarehousingId: warehousing.ID,
  233. GoodId: good_id,
  234. Number: number,
  235. ProductDate: productDates,
  236. ExpireDate: expiryDates,
  237. Count: warehousing_count,
  238. Price: price,
  239. Status: 1,
  240. Ctime: ctime,
  241. UserOrgId: adminUserInfo.CurrentOrgId,
  242. Manufacturer: manufacturer,
  243. Dealer: dealer,
  244. LicenseNumber: license_number,
  245. IsEdit: 1,
  246. Creator: adminUserInfo.AdminUser.Id,
  247. SystemTime: operation_time,
  248. ConsumableType: 1,
  249. WarehousingDetailId: warehouseInfo.ID,
  250. }
  251. stockFlow = append(stockFlow, flow)
  252. }
  253. }
  254. }
  255. //入库单创建成功
  256. errs := service.CreateWarehousingInfo(warehousingInfo)
  257. //创建入库单流水
  258. service.CreateStockFlow(stockFlow)
  259. info, _ := service.FindLastWarehousingInfo(warehousing.WarehousingOrder)
  260. for _, item := range warehousingInfo {
  261. goodInfo, _ := service.GetGoodInformationByGoodId(item.GoodId)
  262. str := strconv.FormatInt(item.WarehousingCount, 10)
  263. minFloat, _ := strconv.ParseFloat(str, 64)
  264. good := models.GoodInfo{
  265. Total: minFloat + goodInfo.Total,
  266. }
  267. //更该库存
  268. parseDateErr := service.UpdateGoodInfoList(good, goodInfo.ID)
  269. break
  270. fmt.Println(parseDateErr)
  271. }
  272. if errs != nil {
  273. utils.ErrorLog(errs.Error())
  274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  275. return
  276. }
  277. c.ServeSuccessJSON(map[string]interface{}{
  278. "msg": "入库成功",
  279. "warehousing_order": warehousing_order,
  280. "info": info,
  281. })
  282. }
  283. func (c *StockManagerApiController) GetWarehouseList() {
  284. page, _ := c.GetInt64("page", -1)
  285. limit, _ := c.GetInt64("limit", -1)
  286. start_time := c.GetString("start_time")
  287. end_time := c.GetString("end_time")
  288. types, _ := c.GetInt64("type", 0)
  289. keywords := c.GetString("keywords")
  290. timeLayout := "2006-01-02"
  291. loc, _ := time.LoadLocation("Local")
  292. var startTime int64
  293. if len(start_time) > 0 {
  294. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  295. if err != nil {
  296. fmt.Println(err)
  297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  298. return
  299. }
  300. startTime = theTime.Unix()
  301. }
  302. var endTime int64
  303. if len(end_time) > 0 {
  304. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  305. if err != nil {
  306. utils.ErrorLog(err.Error())
  307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  308. return
  309. }
  310. endTime = theTime.Unix()
  311. }
  312. adminUserInfo := c.GetAdminUserInfo()
  313. var ids []int64
  314. var goodids []int64
  315. //查询商品名称
  316. if len(keywords) > 0 {
  317. //查询商品名称
  318. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  319. for _, item := range list {
  320. goodids = append(goodids, item.ID)
  321. //入库详情但里面查询
  322. }
  323. if len(goodids) > 0 {
  324. info, _ := service.GetWarehoureOrderInfoByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
  325. for _, it := range info {
  326. ids = append(ids, it.WarehousingId)
  327. }
  328. }
  329. }
  330. warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  331. if err == nil {
  332. c.ServeSuccessJSON(map[string]interface{}{
  333. "list": warehouseList,
  334. "total": total,
  335. })
  336. } else {
  337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  338. }
  339. }
  340. func (c *StockManagerApiController) GetWarehouseInfoList() {
  341. id := c.GetString("id")
  342. idArray := strings.Split(id, ",")
  343. warehousing, err := service.FindWarehousingByIdOne(idArray)
  344. if err != nil {
  345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  346. return
  347. }
  348. var ids []int64
  349. for _, item := range warehousing {
  350. ids = append(ids, item.ID)
  351. }
  352. warehousingInfo, err := service.FindWarehousingInfoByIdOne(ids)
  353. if err == nil {
  354. c.ServeSuccessJSON(map[string]interface{}{
  355. "info": warehousingInfo,
  356. "warehousing": warehousing,
  357. })
  358. } else {
  359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  360. }
  361. }
  362. func (c *StockManagerApiController) EditWarehouse() {
  363. warehousing_time := c.GetString("warehousing_time")
  364. id, _ := c.GetInt64("id", 0)
  365. types, _ := c.GetInt64("type", 0)
  366. if id == 0 {
  367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  368. return
  369. }
  370. ctime := time.Now().Unix()
  371. mtime := time.Now().Unix()
  372. adminUserInfo := c.GetAdminUserInfo()
  373. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  374. if parseDateErr != nil {
  375. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  377. return
  378. }
  379. warehouse, _ := service.FindWarehousingById(id)
  380. warehousing := models.Warehousing{
  381. WarehousingOrder: warehouse.WarehousingOrder,
  382. OrgId: adminUserInfo.CurrentOrgId,
  383. Modifier: adminUserInfo.AdminUser.Id,
  384. Mtime: mtime,
  385. Status: 1,
  386. WarehousingTime: warehousingDate.Unix(),
  387. Type: warehouse.Type,
  388. }
  389. service.EditWarehousing(warehousing)
  390. dataBody := make(map[string]interface{}, 0)
  391. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  392. if err != nil {
  393. utils.ErrorLog(err.Error())
  394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  395. return
  396. }
  397. var warehousingInfo []*models.WarehousingInfo
  398. var upDateWarehousingInfo []*models.WarehousingInfo
  399. var stockFlow []*models.VmStockFlow
  400. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  401. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  402. if len(thisStockIn) > 0 {
  403. for _, item := range thisStockIn {
  404. items := item.(map[string]interface{})
  405. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  406. utils.ErrorLog("good_id")
  407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  408. return
  409. }
  410. good_id := int64(items["good_id"].(float64))
  411. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  412. utils.ErrorLog("good_type_id")
  413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  414. return
  415. }
  416. good_type_id := int64(items["good_type_id"].(float64))
  417. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  418. utils.ErrorLog("warehousing_count")
  419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  420. return
  421. }
  422. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  423. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  424. utils.ErrorLog("price")
  425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  426. return
  427. }
  428. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  429. total := float64(warehousing_count) * price
  430. var productDates int64
  431. var expiryDates int64
  432. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  433. expiryDates = 0
  434. } else {
  435. if len(items["expiry_date"].(string)) == 0 {
  436. expiryDates = 0
  437. } else {
  438. expiryDate, _ := items["expiry_date"].(string)
  439. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  440. expiryDates = expiry_date.Unix()
  441. }
  442. }
  443. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  444. productDates = 0
  445. } else {
  446. if len(items["product_date"].(string)) == 0 {
  447. productDates = 0
  448. } else {
  449. productDate, _ := items["product_date"].(string)
  450. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  451. productDates = product_date.Unix()
  452. }
  453. }
  454. number, _ := items["number"].(string)
  455. remark, _ := items["remark"].(string)
  456. manufacturer := int64(items["manufacturer"].(float64))
  457. dealer := int64(items["dealer"].(float64))
  458. license_number, _ := items["license_number"].(string)
  459. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  460. utils.ErrorLog("id")
  461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  462. return
  463. }
  464. id := int64(items["id"].(float64))
  465. if id == 0 {
  466. warehouseInfo := &models.WarehousingInfo{
  467. WarehousingOrder: warehouse.WarehousingOrder,
  468. WarehousingId: warehouse.ID,
  469. GoodId: good_id,
  470. Number: number,
  471. GoodTypeId: good_type_id,
  472. ProductDate: productDates,
  473. ExpiryDate: expiryDates,
  474. WarehousingCount: warehousing_count,
  475. Price: price,
  476. TotalPrice: total,
  477. Status: 1,
  478. Ctime: ctime,
  479. Remark: remark,
  480. OrgId: adminUserInfo.CurrentOrgId,
  481. Type: types,
  482. Manufacturer: manufacturer,
  483. Dealer: dealer,
  484. StockCount: warehousing_count,
  485. LicenseNumber: license_number,
  486. }
  487. warehousingInfo = append(warehousingInfo, warehouseInfo)
  488. } else {
  489. warehouseInfo := &models.WarehousingInfo{
  490. ID: id,
  491. WarehousingOrder: warehouse.WarehousingOrder,
  492. WarehousingId: warehouse.ID,
  493. GoodId: good_id,
  494. Number: number,
  495. GoodTypeId: good_type_id,
  496. ProductDate: productDates,
  497. ExpiryDate: expiryDates,
  498. WarehousingCount: warehousing_count,
  499. Price: price,
  500. TotalPrice: total,
  501. Status: 1,
  502. Ctime: ctime,
  503. Remark: remark,
  504. OrgId: adminUserInfo.CurrentOrgId,
  505. Type: types,
  506. Manufacturer: manufacturer,
  507. Dealer: dealer,
  508. LicenseNumber: license_number,
  509. }
  510. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  511. flow := &models.VmStockFlow{
  512. WarehousingOrder: warehousing.WarehousingOrder,
  513. WarehousingId: id,
  514. GoodId: good_id,
  515. Number: number,
  516. ProductDate: productDates,
  517. ExpireDate: expiryDates,
  518. Count: warehousing_count,
  519. Price: price,
  520. Status: 1,
  521. Ctime: ctime,
  522. UserOrgId: adminUserInfo.CurrentOrgId,
  523. Manufacturer: manufacturer,
  524. Dealer: dealer,
  525. LicenseNumber: license_number,
  526. IsEdit: 2,
  527. Creator: adminUserInfo.AdminUser.Id,
  528. SystemTime: ctime,
  529. ConsumableType: 1,
  530. WarehousingDetailId: warehouseInfo.ID,
  531. }
  532. stockFlow = append(stockFlow, flow)
  533. }
  534. }
  535. }
  536. }
  537. var errs error
  538. if len(warehousingInfo) > 0 {
  539. errs = service.CreateWarehousingInfo(warehousingInfo)
  540. for _, its := range warehousingInfo {
  541. //查询
  542. info, _ := service.GetLastGoodWarehouseInfo(its.GoodId)
  543. flows := models.VmStockFlow{
  544. WarehousingOrder: info.WarehousingOrder,
  545. WarehousingId: info.ID,
  546. GoodId: info.GoodId,
  547. Number: info.Number,
  548. ProductDate: info.ProductDate,
  549. ExpireDate: info.ExpiryDate,
  550. Count: info.WarehousingCount,
  551. Price: info.Price,
  552. Status: 1,
  553. Ctime: ctime,
  554. UserOrgId: adminUserInfo.CurrentOrgId,
  555. Manufacturer: info.Manufacturer,
  556. Dealer: info.Dealer,
  557. LicenseNumber: info.LicenseNumber,
  558. IsEdit: 1,
  559. Creator: adminUserInfo.AdminUser.Id,
  560. SystemTime: ctime,
  561. ConsumableType: 1,
  562. WarehousingDetailId: info.ID,
  563. }
  564. _, errcodescode := service.GetGoodStockFlowInfo(info.ID, info.GoodId)
  565. if errcodescode == gorm.ErrRecordNotFound {
  566. service.CreateStockFlowOne(flows)
  567. }
  568. //改变库存
  569. good, _ := service.GetLastInfoMationById(info.GoodId)
  570. warhouseCount := strconv.FormatInt(info.WarehousingCount, 10)
  571. total, _ := strconv.ParseFloat(warhouseCount, 64)
  572. goodInfo := models.GoodInfo{
  573. Total: good.Total + total,
  574. }
  575. errcodescode = service.UpdateGoodInfoMation(info.GoodId, goodInfo)
  576. fmt.Println(errcodescode)
  577. }
  578. }
  579. if len(upDateWarehousingInfo) > 0 {
  580. for _, item := range upDateWarehousingInfo {
  581. var total int64
  582. //获取该批次该型号的库存
  583. info, _ := service.GetLastWarehousingByIdOne(item.ID, item.GoodId)
  584. //判断 该批次的库存数量 和 编辑库存数量
  585. fmt.Println("库存11111111111111", item.WarehousingCount)
  586. fmt.Println("库存22222222222222", info.WarehousingCount)
  587. //增加库存
  588. if item.WarehousingCount > info.WarehousingCount {
  589. total = item.WarehousingCount - info.WarehousingCount
  590. goodinfo := models.WarehousingInfo{
  591. WarehousingCount: item.WarehousingCount,
  592. StockCount: info.StockCount + total,
  593. }
  594. service.UpdateWarehouseInfoByGoodId(goodinfo, item.ID)
  595. //改变库存
  596. good, _ := service.GetLastInfoMationById(info.GoodId)
  597. warhouseCount := strconv.FormatInt(total, 10)
  598. all_total, _ := strconv.ParseFloat(warhouseCount, 64)
  599. goodInfo := models.GoodInfo{
  600. Total: good.Total + all_total,
  601. }
  602. service.UpdateGoodInfoMation(info.GoodId, goodInfo)
  603. }
  604. if item.WarehousingCount < info.WarehousingCount {
  605. total = info.WarehousingCount - item.WarehousingCount
  606. goodinfo := models.WarehousingInfo{
  607. WarehousingCount: item.WarehousingCount,
  608. StockCount: info.StockCount - total,
  609. }
  610. service.UpdateWarehouseInfoByGoodId(goodinfo, item.ID)
  611. //改变库存
  612. good, _ := service.GetLastInfoMationById(info.GoodId)
  613. warhouseCount := strconv.FormatInt(total, 10)
  614. all_total, _ := strconv.ParseFloat(warhouseCount, 64)
  615. goodInfo := models.GoodInfo{
  616. Total: good.Total - all_total,
  617. }
  618. service.UpdateGoodInfoMation(info.GoodId, goodInfo)
  619. }
  620. if item.WarehousingCount == info.WarehousingCount {
  621. goodinfo := models.WarehousingInfo{
  622. WarehousingCount: item.WarehousingCount,
  623. StockCount: info.StockCount,
  624. Price: item.Price,
  625. }
  626. service.UpdateWarehouseInfoByGoodIdOne(goodinfo, item.ID)
  627. break
  628. }
  629. }
  630. }
  631. if len(stockFlow) > 0 {
  632. for _, item := range stockFlow {
  633. flow := models.VmStockFlow{
  634. Count: item.Count,
  635. }
  636. parseDateErr := service.UpdateStockFlow(flow, item.GoodId, item.WarehousingId)
  637. fmt.Println(parseDateErr)
  638. }
  639. }
  640. if errs != nil {
  641. utils.ErrorLog(errs.Error())
  642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  643. return
  644. }
  645. c.ServeSuccessJSON(map[string]interface{}{
  646. "msg": "编辑成功",
  647. })
  648. }
  649. func (c *StockManagerApiController) DeleteWarehouse() {
  650. ids := c.GetString("ids")
  651. if len(ids) == 0 {
  652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  653. return
  654. }
  655. idArray := strings.Split(ids, ",")
  656. err := service.DeleteWarehouse(idArray)
  657. if err != nil {
  658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  659. } else {
  660. c.ServeSuccessJSON(map[string]interface{}{
  661. "msg": "删除成功",
  662. })
  663. }
  664. }
  665. func (c *StockManagerApiController) DeleteWarehouseInfo() {
  666. id, _ := c.GetInt64("id", 0)
  667. if id == 0 {
  668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  669. return
  670. }
  671. err := service.UpDateWarehouseStatus(id)
  672. if err != nil {
  673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  674. } else {
  675. c.ServeSuccessJSON(map[string]interface{}{
  676. "msg": "删除成功",
  677. })
  678. }
  679. }
  680. func (c *StockManagerApiController) CreateSalesReturn() {
  681. dealer_id, _ := c.GetInt64("dealer_id", 0)
  682. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  683. sales_return_time := c.GetString("time")
  684. types, _ := c.GetInt64("type", 0)
  685. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  686. if parseDateErr != nil {
  687. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  689. return
  690. }
  691. adminUserInfo := c.GetAdminUserInfo()
  692. operation_time := time.Now().Unix()
  693. creater := adminUserInfo.AdminUser.Id
  694. ctime := time.Now().Unix()
  695. timeStr := time.Now().Format("2006-01-02")
  696. timeArr := strings.Split(timeStr, "-")
  697. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  698. total = total + 1
  699. orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  700. salesReturn := models.SalesReturn{
  701. OrderNumber: orderNumber,
  702. OperaTime: operation_time,
  703. OrgId: adminUserInfo.CurrentOrgId,
  704. Creater: creater,
  705. Ctime: ctime,
  706. Status: 1,
  707. ReturnTime: salesReturnDate.Unix(),
  708. Dealer: dealer_id,
  709. Manufacturer: manufacturer_id,
  710. Type: types,
  711. }
  712. service.AddSigleSalesReturn(&salesReturn)
  713. dataBody := make(map[string]interface{}, 0)
  714. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  715. if err != nil {
  716. utils.ErrorLog(err.Error())
  717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  718. return
  719. }
  720. var salesReturnInfos []*models.SalesReturnInfo
  721. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  722. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  723. if len(thisStockIn) > 0 {
  724. for _, item := range thisStockIn {
  725. items := item.(map[string]interface{})
  726. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  727. utils.ErrorLog("good_id")
  728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  729. return
  730. }
  731. good_id := int64(items["good_id"].(float64))
  732. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  733. utils.ErrorLog("good_type_id")
  734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  735. return
  736. }
  737. good_type_id := int64(items["good_type_id"].(float64))
  738. return_count, _ := items["return_count"].(string)
  739. if len(return_count) == 0 {
  740. utils.ErrorLog("len(return_count) == 0")
  741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  742. return
  743. }
  744. count, _ := strconv.ParseInt(return_count, 10, 64)
  745. price, _ := strconv.ParseFloat(items["price"].(string), 10)
  746. total := float64(count) * price
  747. salesReturnInfo := &models.SalesReturnInfo{
  748. OrderNumber: salesReturn.OrderNumber,
  749. SalesReturnId: salesReturn.ID,
  750. GoodId: good_id,
  751. GoodTypeId: good_type_id,
  752. Count: count,
  753. Price: price,
  754. Total: total,
  755. Status: 1,
  756. Ctime: ctime,
  757. OrgId: adminUserInfo.CurrentOrgId,
  758. Type: types,
  759. Manufacturer: manufacturer_id,
  760. Dealer: dealer_id,
  761. }
  762. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  763. }
  764. }
  765. }
  766. errs := service.CreateSalesReturnInfo(salesReturnInfos)
  767. if errs != nil {
  768. utils.ErrorLog(errs.Error())
  769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  770. return
  771. }
  772. c.ServeSuccessJSON(map[string]interface{}{
  773. "msg": "退货成功",
  774. })
  775. }
  776. func (c *StockManagerApiController) GetSalesReturnList() {
  777. page, _ := c.GetInt64("page", -1)
  778. limit, _ := c.GetInt64("limit", -1)
  779. start_time := c.GetString("start_time")
  780. end_time := c.GetString("end_time")
  781. types, _ := c.GetInt64("type", 0)
  782. keywords := c.GetString("keywords")
  783. timeLayout := "2006-01-02"
  784. loc, _ := time.LoadLocation("Local")
  785. var startTime int64
  786. if len(start_time) > 0 {
  787. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  788. if err != nil {
  789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  790. return
  791. }
  792. startTime = theTime.Unix()
  793. }
  794. var endTime int64
  795. if len(end_time) > 0 {
  796. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  797. if err != nil {
  798. utils.ErrorLog(err.Error())
  799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  800. return
  801. }
  802. endTime = theTime.Unix()
  803. }
  804. adminUserInfo := c.GetAdminUserInfo()
  805. returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  806. if err == nil {
  807. c.ServeSuccessJSON(map[string]interface{}{
  808. "list": returnList,
  809. "total": total,
  810. })
  811. } else {
  812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  813. }
  814. }
  815. func (this *StockManagerApiController) DeleteSalesReturn() {
  816. ids := this.GetString("ids")
  817. if len(ids) == 0 {
  818. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  819. return
  820. }
  821. idArray := strings.Split(ids, ",")
  822. err := service.DeleteSalesReturn(idArray)
  823. if err != nil {
  824. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  825. } else {
  826. this.ServeSuccessJSON(map[string]interface{}{
  827. "msg": "删除成功",
  828. })
  829. }
  830. }
  831. func (this *StockManagerApiController) DeleteSalesReturnInfo() {
  832. id, _ := this.GetInt64("id", 0)
  833. fmt.Println(id)
  834. if id == 0 {
  835. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  836. return
  837. }
  838. err := service.UpDateSaleReturnStatus(id)
  839. if err != nil {
  840. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  841. } else {
  842. this.ServeSuccessJSON(map[string]interface{}{
  843. "msg": "删除成功",
  844. })
  845. }
  846. }
  847. func (this *StockManagerApiController) GetSalesReturnInfoList() {
  848. id, _ := this.GetInt64("id", 0)
  849. list, _ := service.FindAllSalesReturnInfoById(id)
  850. salesReturn, _ := service.FindAllSalesReturnById(id)
  851. this.ServeSuccessJSON(map[string]interface{}{
  852. "list": list,
  853. "salesReturn": salesReturn,
  854. })
  855. }
  856. func (c *StockManagerApiController) EditReturnInfo() {
  857. return_time := c.GetString("return_time")
  858. id, _ := c.GetInt64("id", 0)
  859. types, _ := c.GetInt64("type", 0)
  860. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  861. dealer_id, _ := c.GetInt64("dealer_id", 0)
  862. if id == 0 {
  863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  864. return
  865. }
  866. ctime := time.Now().Unix()
  867. mtime := time.Now().Unix()
  868. adminUserInfo := c.GetAdminUserInfo()
  869. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  870. if parseDateErr != nil {
  871. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  873. return
  874. }
  875. salesReturns, _ := service.FindSalesReturnById(id)
  876. sales := models.SalesReturn{
  877. ID: salesReturns.ID,
  878. Mtime: mtime,
  879. ReturnTime: returnDate.Unix(),
  880. Manufacturer: manufacturer_id,
  881. Dealer: dealer_id,
  882. }
  883. service.EditSaleReturn(sales)
  884. dataBody := make(map[string]interface{}, 0)
  885. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  886. if err != nil {
  887. utils.ErrorLog(err.Error())
  888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  889. return
  890. }
  891. var returnInfos []*models.SalesReturnInfo
  892. var upDateReturnInfos []*models.SalesReturnInfo
  893. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  894. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  895. if len(thisStockIn) > 0 {
  896. for _, item := range thisStockIn {
  897. items := item.(map[string]interface{})
  898. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  899. utils.ErrorLog("good_id")
  900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  901. return
  902. }
  903. good_id := int64(items["good_id"].(float64))
  904. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  905. utils.ErrorLog("good_type_id")
  906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  907. return
  908. }
  909. good_type_id := int64(items["good_type_id"].(float64))
  910. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  911. utils.ErrorLog("count")
  912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  913. return
  914. }
  915. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  916. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  917. utils.ErrorLog("id")
  918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  919. return
  920. }
  921. id := int64(items["id"].(float64))
  922. if id == 0 {
  923. returnInfo := &models.SalesReturnInfo{
  924. GoodId: good_id,
  925. GoodTypeId: good_type_id,
  926. Count: count,
  927. Status: 1,
  928. Ctime: ctime,
  929. OrgId: adminUserInfo.CurrentOrgId,
  930. OrderNumber: sales.OrderNumber,
  931. SalesReturnId: sales.ID,
  932. Mtime: time.Now().Unix(),
  933. Type: types,
  934. Manufacturer: manufacturer_id,
  935. Dealer: dealer_id,
  936. }
  937. returnInfos = append(returnInfos, returnInfo)
  938. } else {
  939. returnInfo := &models.SalesReturnInfo{
  940. ID: id,
  941. GoodId: good_id,
  942. GoodTypeId: good_type_id,
  943. Count: count,
  944. Status: 1,
  945. Ctime: ctime,
  946. OrgId: adminUserInfo.CurrentOrgId,
  947. OrderNumber: sales.OrderNumber,
  948. SalesReturnId: sales.ID,
  949. Mtime: time.Now().Unix(),
  950. Type: types,
  951. Manufacturer: manufacturer_id,
  952. Dealer: dealer_id,
  953. }
  954. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  955. }
  956. }
  957. }
  958. }
  959. var errs error
  960. if len(returnInfos) > 0 {
  961. errs = service.CreateSalesReturnInfo(returnInfos)
  962. }
  963. if len(upDateReturnInfos) > 0 {
  964. for _, item := range upDateReturnInfos {
  965. errs = service.UpDateSalesReturnInfo(item)
  966. }
  967. }
  968. if errs != nil {
  969. utils.ErrorLog(errs.Error())
  970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  971. return
  972. }
  973. c.ServeSuccessJSON(map[string]interface{}{
  974. "msg": "编辑成功",
  975. })
  976. }
  977. func (c *StockManagerApiController) CreateWarehouseOut() {
  978. types, _ := c.GetInt64("type", 0)
  979. ctime := time.Now().Unix()
  980. adminUserInfo := c.GetAdminUserInfo()
  981. warehousing_out_time := c.GetString("warehousing_out_time")
  982. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  983. if parseDateErr != nil {
  984. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  986. return
  987. }
  988. timeStr := time.Now().Format("2006-01-02")
  989. timeArr := strings.Split(timeStr, "-")
  990. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  991. total = total + 1
  992. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  993. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  994. number = number + total
  995. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  996. operation_time := time.Now().Unix()
  997. creater := adminUserInfo.AdminUser.Id
  998. warehouseOut := models.WarehouseOut{
  999. WarehouseOutOrderNumber: warehousing_out_order,
  1000. OperationTime: operation_time,
  1001. OrgId: adminUserInfo.CurrentOrgId,
  1002. Creater: creater,
  1003. Ctime: ctime,
  1004. Status: 1,
  1005. WarehouseOutTime: warehousingOutDate.Unix(),
  1006. Type: types,
  1007. }
  1008. dataBody := make(map[string]interface{}, 0)
  1009. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1010. if err != nil {
  1011. utils.ErrorLog(err.Error())
  1012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1013. return
  1014. }
  1015. var warehousingOutInfo []*models.WarehouseOutInfo
  1016. var beforePrepares []*models.DialysisBeforePrepareGoods
  1017. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  1018. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1019. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  1020. if len(thisStockIn) > 0 {
  1021. for _, item := range thisStockIn {
  1022. items := item.(map[string]interface{})
  1023. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1024. utils.ErrorLog("good_id")
  1025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1026. return
  1027. }
  1028. good_id := int64(items["good_id"].(float64))
  1029. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1030. utils.ErrorLog("good_type_id")
  1031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1032. return
  1033. }
  1034. good_type_id := int64(items["good_type_id"].(float64))
  1035. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1036. utils.ErrorLog("count")
  1037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1038. return
  1039. }
  1040. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1041. utils.ErrorLog("price")
  1042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1043. return
  1044. }
  1045. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1046. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1047. total := float64(count) * price
  1048. remark := items["remark"].(string)
  1049. manufacturer := int64(items["manufacturer"].(float64))
  1050. dealer := int64(items["dealer"].(float64))
  1051. number := items["number"].(string)
  1052. expiry_date := items["expiry_date"].(string)
  1053. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1054. timeLayout := "2006-01-02"
  1055. loc, _ := time.LoadLocation("Local")
  1056. var expiryDate int64
  1057. if len(expiry_date) > 0 {
  1058. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1059. if err != nil {
  1060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1061. return
  1062. }
  1063. expiryDate = theTime.Unix()
  1064. }
  1065. product_date := items["product_date"].(string)
  1066. var productDate int64
  1067. if len(product_date) > 0 {
  1068. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1069. if err != nil {
  1070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1071. return
  1072. }
  1073. productDate = theTime.Unix()
  1074. }
  1075. license_number := items["license_number"].(string)
  1076. warehouseOutInfo := &models.WarehouseOutInfo{
  1077. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1078. WarehouseOutId: warehouseOut.ID,
  1079. GoodId: good_id,
  1080. GoodTypeId: good_type_id,
  1081. Count: count,
  1082. Price: price,
  1083. TotalPrice: total,
  1084. Status: 1,
  1085. Ctime: ctime,
  1086. Remark: remark,
  1087. OrgId: adminUserInfo.CurrentOrgId,
  1088. Type: types,
  1089. Manufacturer: manufacturer,
  1090. Number: number,
  1091. ExpiryDate: expiryDate,
  1092. ProductDate: productDate,
  1093. Dealer: dealer,
  1094. LicenseNumber: license_number,
  1095. WarehouseInfotId: warehouse_info_id,
  1096. }
  1097. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1098. prepareGoods := &models.DialysisBeforePrepareGoods{
  1099. GoodTypeId: good_type_id,
  1100. GoodId: good_id,
  1101. Count: count,
  1102. }
  1103. beforePrepares = append(beforePrepares, prepareGoods)
  1104. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  1105. GoodTypeId: good_type_id,
  1106. GoodId: good_id,
  1107. Count: count,
  1108. }
  1109. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  1110. }
  1111. }
  1112. }
  1113. //出库逻辑
  1114. for _, item := range warehousingOutInfo {
  1115. // 查询该耗材是否有库存
  1116. warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId)
  1117. // 如果出库数量大于该批次剩余库存数量
  1118. if item.Count > warehouseOne.StockCount {
  1119. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  1120. c.ServeSuccessJSON(map[string]interface{}{
  1121. "msg": "1",
  1122. "good_name": goodObj.GoodName,
  1123. "specification_name": goodObj.SpecificationName,
  1124. })
  1125. return
  1126. } else {
  1127. //查询是否生成出库单
  1128. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  1129. if errcodes == gorm.ErrRecordNotFound {
  1130. service.AddSigleWarehouseOut(&warehouseOut)
  1131. }
  1132. //出库逻辑
  1133. parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
  1134. if parseDateErr != nil {
  1135. utils.ErrorLog(parseDateErr.Error())
  1136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1137. return
  1138. }
  1139. c.ServeSuccessJSON(map[string]interface{}{
  1140. "msg": "2",
  1141. "good_name": "",
  1142. "specification_name": "",
  1143. })
  1144. }
  1145. }
  1146. }
  1147. func (c *StockManagerApiController) GetWarehouseOutList() {
  1148. page, _ := c.GetInt64("page", -1)
  1149. limit, _ := c.GetInt64("limit", -1)
  1150. start_time := c.GetString("start_time")
  1151. end_time := c.GetString("end_time")
  1152. types, _ := c.GetInt64("type", 0)
  1153. keywords := c.GetString("keywords")
  1154. timeLayout := "2006-01-02"
  1155. loc, _ := time.LoadLocation("Local")
  1156. var startTime int64
  1157. if len(start_time) > 0 {
  1158. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1159. if err != nil {
  1160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1161. return
  1162. }
  1163. startTime = theTime.Unix()
  1164. }
  1165. var endTime int64
  1166. if len(end_time) > 0 {
  1167. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1168. if err != nil {
  1169. utils.ErrorLog(err.Error())
  1170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1171. return
  1172. }
  1173. endTime = theTime.Unix()
  1174. }
  1175. adminUserInfo := c.GetAdminUserInfo()
  1176. var ids []int64
  1177. var goodids []int64
  1178. if len(keywords) > 0 {
  1179. //查询商品名称
  1180. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  1181. for _, item := range list {
  1182. goodids = append(goodids, item.ID)
  1183. }
  1184. if len(goodids) > 0 {
  1185. //出库详情但里面查询
  1186. info, _ := service.GetWarehoureOrderOutByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
  1187. for _, it := range info {
  1188. ids = append(ids, it.WarehouseOutId)
  1189. }
  1190. }
  1191. }
  1192. warehouseOutList, total, err := service.FindAllWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  1193. fmt.Println(err)
  1194. if err == nil {
  1195. c.ServeSuccessJSON(map[string]interface{}{
  1196. "list": warehouseOutList,
  1197. "total": total,
  1198. })
  1199. } else {
  1200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1201. }
  1202. }
  1203. func (c *StockManagerApiController) DeleteWarehouseOut() {
  1204. ids := c.GetString("ids")
  1205. if len(ids) == 0 {
  1206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1207. return
  1208. }
  1209. idArray := strings.Split(ids, ",")
  1210. err := service.DeleteWarehouseOut(idArray)
  1211. if err != nil {
  1212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1213. } else {
  1214. c.ServeSuccessJSON(map[string]interface{}{
  1215. "msg": "删除成功",
  1216. })
  1217. }
  1218. }
  1219. func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
  1220. id, _ := this.GetInt64("id", 0)
  1221. fmt.Println(id)
  1222. if id == 0 {
  1223. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1224. return
  1225. }
  1226. err := service.UpDateWarehouseOutStatus(id)
  1227. if err != nil {
  1228. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1229. } else {
  1230. this.ServeSuccessJSON(map[string]interface{}{
  1231. "msg": "删除成功",
  1232. })
  1233. }
  1234. }
  1235. func (c *StockManagerApiController) GetWarehouseOutInfoList() {
  1236. id, _ := c.GetInt64("id", 0)
  1237. warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
  1238. warehouseOut, _ := service.FindWareHouseOutById(id)
  1239. adminUserInfo := c.GetAdminUserInfo()
  1240. orgId := adminUserInfo.CurrentOrgId
  1241. wareoutList, _ := service.GetWareOutInfoById(id, orgId)
  1242. c.ServeSuccessJSON(map[string]interface{}{
  1243. "list": warehouseOutInfo,
  1244. "info": warehouseOut,
  1245. "wareoutList": wareoutList,
  1246. })
  1247. }
  1248. func (c *StockManagerApiController) EditWarehouseOut() {
  1249. warehouse_out_time := c.GetString("warehouse_out_time")
  1250. id, _ := c.GetInt64("id", 0)
  1251. types, _ := c.GetInt64("type", 0)
  1252. if id == 0 {
  1253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1254. return
  1255. }
  1256. ctime := time.Now().Unix()
  1257. mtime := time.Now().Unix()
  1258. adminUserInfo := c.GetAdminUserInfo()
  1259. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1260. if parseDateErr != nil {
  1261. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1263. return
  1264. }
  1265. warehouseOut, _ := service.FindWareHouseOutById(id)
  1266. tempWarehouseOut := models.WarehouseOut{
  1267. ID: warehouseOut.ID,
  1268. Mtime: mtime,
  1269. WarehouseOutTime: warehouseOutDate.Unix(),
  1270. }
  1271. service.EditWarehouseOut(tempWarehouseOut)
  1272. dataBody := make(map[string]interface{}, 0)
  1273. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1274. if err != nil {
  1275. utils.ErrorLog(err.Error())
  1276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1277. return
  1278. }
  1279. var warehousingOutInfo []*models.WarehouseOutInfo
  1280. var upDateWarehouseOutInfos []*models.WarehouseOutInfo
  1281. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1282. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1283. if len(thisStockOut) > 0 {
  1284. for _, item := range thisStockOut {
  1285. items := item.(map[string]interface{})
  1286. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1287. utils.ErrorLog("good_id")
  1288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1289. return
  1290. }
  1291. good_id := int64(items["good_id"].(float64))
  1292. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1293. utils.ErrorLog("good_type_id")
  1294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1295. return
  1296. }
  1297. good_type_id := int64(items["good_type_id"].(float64))
  1298. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1299. utils.ErrorLog("count")
  1300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1301. return
  1302. }
  1303. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1304. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1305. utils.ErrorLog("price")
  1306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1307. return
  1308. }
  1309. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1310. total := float64(count) * price
  1311. remark := items["remark"].(string)
  1312. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1313. utils.ErrorLog("id")
  1314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1315. return
  1316. }
  1317. id := int64(items["id"].(float64))
  1318. manufacturer := int64(items["manufacturer"].(float64))
  1319. dealer := int64(items["dealer"].(float64))
  1320. number := items["number"].(string)
  1321. license_number := items["license_number"].(string)
  1322. timeLayout := "2006-01-02"
  1323. loc, _ := time.LoadLocation("Local")
  1324. expiry_date := items["expiry_date"].(string)
  1325. var expiryDate int64
  1326. if len(expiry_date) > 0 {
  1327. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1328. if err != nil {
  1329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1330. return
  1331. }
  1332. expiryDate = theTime.Unix()
  1333. }
  1334. product_date := items["product_date"].(string)
  1335. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1336. var productDate int64
  1337. if len(product_date) > 0 {
  1338. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1339. if err != nil {
  1340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1341. return
  1342. }
  1343. productDate = theTime.Unix()
  1344. }
  1345. if id == 0 {
  1346. warehouseOutInfo := &models.WarehouseOutInfo{
  1347. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1348. WarehouseOutId: warehouseOut.ID,
  1349. GoodId: good_id,
  1350. GoodTypeId: good_type_id,
  1351. Count: count,
  1352. Price: price,
  1353. TotalPrice: total,
  1354. Status: 1,
  1355. Ctime: ctime,
  1356. Remark: remark,
  1357. OrgId: adminUserInfo.CurrentOrgId,
  1358. Type: types,
  1359. IsSys: 0,
  1360. SysRecordTime: 0,
  1361. Number: number,
  1362. ExpiryDate: expiryDate,
  1363. ProductDate: productDate,
  1364. Dealer: dealer,
  1365. Manufacturer: manufacturer,
  1366. LicenseNumber: license_number,
  1367. ConsumableType: 1,
  1368. WarehouseInfotId: warehouse_info_id,
  1369. }
  1370. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1371. } else {
  1372. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1373. utils.ErrorLog("is_sys")
  1374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1375. return
  1376. }
  1377. is_sys := int64(items["is_sys"].(float64))
  1378. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1379. utils.ErrorLog("sys_record_time")
  1380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1381. return
  1382. }
  1383. sys_record_time := int64(items["sys_record_time"].(float64))
  1384. warehouseOutInfo := &models.WarehouseOutInfo{
  1385. ID: id,
  1386. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1387. WarehouseOutId: warehouseOut.ID,
  1388. GoodId: good_id,
  1389. GoodTypeId: good_type_id,
  1390. Count: count,
  1391. Price: price,
  1392. TotalPrice: total,
  1393. Status: 1,
  1394. Ctime: ctime,
  1395. Remark: remark,
  1396. OrgId: adminUserInfo.CurrentOrgId,
  1397. Mtime: time.Now().Unix(),
  1398. Type: types,
  1399. Manufacturer: manufacturer,
  1400. IsSys: is_sys,
  1401. SysRecordTime: sys_record_time,
  1402. Number: number,
  1403. ExpiryDate: expiryDate,
  1404. ProductDate: productDate,
  1405. Dealer: dealer,
  1406. LicenseNumber: license_number,
  1407. ConsumableType: 2,
  1408. WarehouseInfotId: warehouse_info_id,
  1409. }
  1410. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1411. }
  1412. }
  1413. }
  1414. }
  1415. var errs error
  1416. //新增出库
  1417. if len(warehousingOutInfo) > 0 {
  1418. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1419. if parseDateErr != nil {
  1420. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  1421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1422. return
  1423. }
  1424. creater := adminUserInfo.AdminUser.Id
  1425. for _, item := range warehousingOutInfo {
  1426. // 查询该耗材是否有库存
  1427. warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId)
  1428. // 如果出库数量大于该批次剩余库存数量
  1429. if item.Count > warehouseOne.StockCount {
  1430. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  1431. c.ServeSuccessJSON(map[string]interface{}{
  1432. "msg": "7",
  1433. "good_name": goodObj.GoodName,
  1434. "specification_name": goodObj.SpecificationName,
  1435. })
  1436. return
  1437. } else {
  1438. warehouseOut, _ := service.GetWarehouseById(id)
  1439. //出库逻辑
  1440. parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
  1441. if parseDateErr != nil {
  1442. utils.ErrorLog(parseDateErr.Error())
  1443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1444. return
  1445. }
  1446. }
  1447. }
  1448. }
  1449. if len(upDateWarehouseOutInfos) > 0 {
  1450. for _, item := range upDateWarehouseOutInfos {
  1451. //1.查询该耗材该批次的最后一次出库记录
  1452. lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId)
  1453. // 退库的库存和该耗材该批次最后一次出库数量进行比较
  1454. //如果退库数量大于 最后一次批次的数量(要么要进行出库)
  1455. if item.Count > lastGood.Count {
  1456. //查询该耗材是否还有库存
  1457. warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId)
  1458. //无库存
  1459. if warehouseinfo.StockCount <= 0 {
  1460. c.ServeSuccessJSON(map[string]interface{}{
  1461. "msg": "5",
  1462. })
  1463. return
  1464. }
  1465. //有库存,进行出库,调用出库接口
  1466. if warehouseinfo.StockCount > 0 {
  1467. var total int64
  1468. var stock_cout int64
  1469. var total_count int64
  1470. //计算和最后一次出库数据的差
  1471. total = item.Count - lastGood.Count
  1472. //获取该耗材该批次的剩余库存量
  1473. info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1474. //判断该批次的剩余库存 和出库的库存进行比较
  1475. //如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
  1476. if item.Count > info.StockCount {
  1477. //计算出库和该批次相差的库存
  1478. total_count = item.Count - info.StockCount
  1479. //清空本批次次库存
  1480. service.DeleteWarehouseInfo(item.WarehouseInfotId)
  1481. //调用出库逻辑
  1482. parseDateErr := service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
  1483. if parseDateErr != nil {
  1484. utils.ErrorLog(errs.Error())
  1485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1486. return
  1487. }
  1488. c.ServeSuccessJSON(map[string]interface{}{
  1489. "msg": "1",
  1490. })
  1491. }
  1492. //如果出库的库存小于或等于于该批次的剩余库存,那么需要该批次出库
  1493. if item.Count <= info.StockCount {
  1494. stock_cout = lastGood.Count + total
  1495. fmt.Println(stock_cout)
  1496. //扣减库存
  1497. warehouse := models.WarehousingInfo{
  1498. StockCount: info.StockCount - total,
  1499. }
  1500. errs := service.UpdateWarehousingInfo(warehouse, info.ID)
  1501. warehouseOutInfo := &models.WarehouseOutInfo{
  1502. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1503. WarehouseOutId: id,
  1504. WarehouseInfotId: item.WarehouseInfotId,
  1505. Status: 1,
  1506. Ctime: time.Now().Unix(),
  1507. Remark: item.Remark,
  1508. OrgId: item.OrgId,
  1509. Type: 1,
  1510. Manufacturer: item.Manufacturer,
  1511. Dealer: item.Dealer,
  1512. IsSys: 0,
  1513. SysRecordTime: item.SysRecordTime,
  1514. GoodTypeId: item.GoodTypeId,
  1515. GoodId: item.GoodId,
  1516. ExpiryDate: item.ExpiryDate,
  1517. ProductDate: item.ProductDate,
  1518. Number: item.Number,
  1519. Price: item.Price,
  1520. LicenseNumber: item.LicenseNumber,
  1521. Count: item.Count,
  1522. ConsumableType: 2,
  1523. }
  1524. //查询是否存在
  1525. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1526. if errcode == gorm.ErrRecordNotFound {
  1527. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1528. if errOne != nil {
  1529. utils.ErrorLog(errs.Error())
  1530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1531. return
  1532. }
  1533. c.ServeSuccessJSON(map[string]interface{}{
  1534. "msg": "1",
  1535. })
  1536. return
  1537. } else if errcode == nil {
  1538. service.UpDateWarehouseOutInfo(item)
  1539. c.ServeSuccessJSON(map[string]interface{}{
  1540. "msg": "1",
  1541. })
  1542. return
  1543. }
  1544. }
  1545. }
  1546. }
  1547. var last_count int64
  1548. var all_total int64
  1549. var stock_total int64
  1550. //如果退库数量小于最后一次批次的数量(要么要进行退库)
  1551. if item.Count < lastGood.Count {
  1552. //退库数量和最后一次出库数据进行计算
  1553. last_count = lastGood.Count - item.Count
  1554. //获取该耗材该批次的剩余库存量
  1555. infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1556. //退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
  1557. all_total = last_count + infoInfo.StockCount
  1558. //如果库存大于总数量,则退回到这个批次
  1559. if infoInfo.WarehousingCount > all_total {
  1560. stock_total = last_count + infoInfo.StockCount
  1561. //退回该批次,计算数量
  1562. warehousingInfoOne := models.WarehousingInfo{
  1563. StockCount: stock_total,
  1564. ID: item.WarehouseInfotId,
  1565. OrgId: item.OrgId,
  1566. }
  1567. parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
  1568. fmt.Println("parseDateErr", parseDateErr)
  1569. //插入一条新纪录
  1570. warehouseOutInfoThree := &models.WarehouseOutInfo{
  1571. WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
  1572. WarehouseOutId: id,
  1573. WarehouseInfotId: item.WarehouseInfotId,
  1574. Status: 1,
  1575. Ctime: time.Now().Unix(),
  1576. Remark: item.Remark,
  1577. OrgId: item.OrgId,
  1578. Type: 1,
  1579. Manufacturer: item.Manufacturer,
  1580. Dealer: item.Dealer,
  1581. IsSys: 0,
  1582. GoodTypeId: item.GoodTypeId,
  1583. GoodId: item.GoodId,
  1584. ExpiryDate: item.ExpiryDate,
  1585. ProductDate: item.ProductDate,
  1586. Number: item.Number,
  1587. Price: item.Price,
  1588. LicenseNumber: item.LicenseNumber,
  1589. ConsumableType: 2,
  1590. Count: item.Count,
  1591. }
  1592. //查询是否存在
  1593. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1594. if errcode == gorm.ErrRecordNotFound {
  1595. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfoThree)
  1596. if errOne != nil {
  1597. utils.ErrorLog(errs.Error())
  1598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1599. return
  1600. }
  1601. c.ServeSuccessJSON(map[string]interface{}{
  1602. "msg": "1",
  1603. })
  1604. return
  1605. } else if errcode == nil {
  1606. service.UpDateWarehouseOutInfo(item)
  1607. return
  1608. }
  1609. }
  1610. //如果库存小于总数量,则报错提醒,该批次的退库数据大于入库数据了无法退库,则需要退库到另一个批次
  1611. if infoInfo.WarehousingCount < all_total {
  1612. c.ServeSuccessJSON(map[string]interface{}{
  1613. "msg": "6",
  1614. })
  1615. return
  1616. }
  1617. }
  1618. if item.Count == lastGood.Count {
  1619. errs = service.UpDateWarehouseOutInfo(item)
  1620. if errs != nil {
  1621. utils.ErrorLog(errs.Error())
  1622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1623. return
  1624. }
  1625. c.ServeSuccessJSON(map[string]interface{}{
  1626. "msg": "1",
  1627. })
  1628. return
  1629. }
  1630. }
  1631. }
  1632. if errs != nil {
  1633. utils.ErrorLog(errs.Error())
  1634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1635. return
  1636. }
  1637. c.ServeSuccessJSON(map[string]interface{}{
  1638. "msg": "1",
  1639. })
  1640. }
  1641. func (c *StockManagerApiController) CreateCancelStock() {
  1642. cancel_stock_time := c.GetString("time")
  1643. types, _ := c.GetInt64("type", 0)
  1644. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1645. if parseDateErr != nil {
  1646. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1648. return
  1649. }
  1650. adminUserInfo := c.GetAdminUserInfo()
  1651. operation_time := time.Now().Unix()
  1652. creater := adminUserInfo.AdminUser.Id
  1653. ctime := time.Now().Unix()
  1654. timeStr := time.Now().Format("2006-01-02")
  1655. timeArr := strings.Split(timeStr, "-")
  1656. total, _ := service.FindAllCancelStockTotal(adminUserInfo.CurrentOrgId)
  1657. total = total + 1
  1658. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1659. cancelStock := models.CancelStock{
  1660. OrderNumber: orderNumber,
  1661. OperaTime: operation_time,
  1662. OrgId: adminUserInfo.CurrentOrgId,
  1663. Creater: creater,
  1664. Ctime: ctime,
  1665. Status: 1,
  1666. ReturnTime: cancelStockDate.Unix(),
  1667. Type: types,
  1668. }
  1669. dataBody := make(map[string]interface{}, 0)
  1670. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1671. if err != nil {
  1672. utils.ErrorLog(err.Error())
  1673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1674. return
  1675. }
  1676. var cancelStockInfos []*models.CancelStockInfo
  1677. var stockFLow []*models.VmStockFlow
  1678. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1679. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1680. if len(thisStockIn) > 0 {
  1681. for _, item := range thisStockIn {
  1682. items := item.(map[string]interface{})
  1683. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1684. utils.ErrorLog("good_id")
  1685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1686. return
  1687. }
  1688. good_id := int64(items["good_id"].(float64))
  1689. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1690. utils.ErrorLog("good_type_id")
  1691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1692. return
  1693. }
  1694. good_type_id := int64(items["good_type_id"].(float64))
  1695. return_count, _ := items["return_count"].(string)
  1696. if len(return_count) == 0 {
  1697. utils.ErrorLog("len(return_count) == 0")
  1698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1699. return
  1700. }
  1701. count, _ := strconv.ParseInt(return_count, 10, 64)
  1702. number := items["number"].(string)
  1703. register_account := items["register_account"].(string)
  1704. manufacturer, _ := items["manufacturer"].(string)
  1705. dealer, _ := items["dealer"].(string)
  1706. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1707. var expiryDates int64
  1708. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1709. expiryDates = 0
  1710. } else {
  1711. if len(items["expiry_date"].(string)) == 0 {
  1712. expiryDates = 0
  1713. } else {
  1714. expiryDate, _ := items["expiry_date"].(string)
  1715. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1716. expiryDates = expiry_date.Unix()
  1717. }
  1718. }
  1719. var productDates int64
  1720. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1721. productDates = 0
  1722. } else {
  1723. if len(items["product_date"].(string)) == 0 {
  1724. productDates = 0
  1725. } else {
  1726. productDate, _ := items["product_date"].(string)
  1727. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1728. productDates = product_date.Unix()
  1729. }
  1730. }
  1731. remark := items["remark"].(string)
  1732. retail_prices := items["price"].(string)
  1733. price, _ := strconv.ParseFloat(retail_prices, 64)
  1734. cancelStockInfo := &models.CancelStockInfo{
  1735. OrderNumber: cancelStock.OrderNumber,
  1736. CancelStockId: cancelStock.ID,
  1737. GoodId: good_id,
  1738. GoodTypeId: good_type_id,
  1739. Count: count,
  1740. Status: 1,
  1741. Ctime: ctime,
  1742. OrgId: adminUserInfo.CurrentOrgId,
  1743. Type: types,
  1744. Manufacturer: manufacturer,
  1745. Dealer: dealer,
  1746. Number: number,
  1747. ProductDate: productDates,
  1748. ExpiryDate: expiryDates,
  1749. RegisterAccount: register_account,
  1750. Remark: remark,
  1751. Price: price,
  1752. WarehouseInfoId: warehouse_info_id,
  1753. }
  1754. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1755. flow := &models.VmStockFlow{
  1756. WarehousingId: 0,
  1757. GoodId: good_id,
  1758. Number: number,
  1759. LicenseNumber: "",
  1760. Count: count,
  1761. UserOrgId: adminUserInfo.CurrentOrgId,
  1762. PatientId: 0,
  1763. SystemTime: time.Now().Unix(),
  1764. ConsumableType: 4,
  1765. IsSys: 0,
  1766. WarehousingOrder: "",
  1767. WarehouseOutId: 0,
  1768. WarehouseOutOrderNumber: "",
  1769. IsEdit: 0,
  1770. CancelStockId: cancelStock.ID,
  1771. CancelOrderNumber: cancelStock.OrderNumber,
  1772. Manufacturer: 0,
  1773. Dealer: 0,
  1774. Creator: adminUserInfo.AdminUser.Id,
  1775. UpdateCreator: 0,
  1776. Status: 1,
  1777. Ctime: time.Now().Unix(),
  1778. Mtime: 0,
  1779. Price: price,
  1780. WarehousingDetailId: 0,
  1781. WarehouseOutDetailId: 0,
  1782. CancelOutDetailId: 0,
  1783. ProductDate: productDates,
  1784. ExpireDate: expiryDates,
  1785. }
  1786. stockFLow = append(stockFLow, flow)
  1787. }
  1788. }
  1789. }
  1790. for _, item := range cancelStockInfos {
  1791. //统计该批次耗材的出库数量
  1792. info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId, item.WarehouseInfoId)
  1793. fmt.Println("2333223323322332233223322323", item.Count, info.Count)
  1794. if item.Count > info.Count {
  1795. service.UpdateCancelInfo(item.CancelStockId)
  1796. c.ServeSuccessJSON(map[string]interface{}{
  1797. "msg": "2",
  1798. })
  1799. return
  1800. }
  1801. //查询该批次入库的值
  1802. infolist, _ := service.GetWarehouseInfoByIdSeven(item.WarehouseInfoId)
  1803. if item.Count > infolist.WarehousingCount {
  1804. c.ServeSuccessJSON(map[string]interface{}{
  1805. "msg": "4",
  1806. })
  1807. return
  1808. }
  1809. if item.Count <= infolist.WarehousingCount {
  1810. _, msgerrkonde := service.GetCancelStockDetailByOrderNumber(orderNumber, adminUserInfo.CurrentOrgId)
  1811. if msgerrkonde == gorm.ErrRecordNotFound {
  1812. service.AddSigleCancelStock(&cancelStock)
  1813. }
  1814. listcancel, _ := service.GetLastCancelStockById(adminUserInfo.CurrentOrgId)
  1815. for _, it := range cancelStockInfos {
  1816. it.CancelStockId = listcancel.ID
  1817. }
  1818. errs := service.CreateCancelStockInfo(cancelStockInfos)
  1819. if len(stockFLow) > 0 {
  1820. service.CreateStockFlow(stockFLow)
  1821. }
  1822. if errs != nil {
  1823. utils.ErrorLog(errs.Error())
  1824. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1825. return
  1826. }
  1827. //查询该批次的剩余库存
  1828. wareouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  1829. if (wareouseinfo.StockCount + item.Count) > wareouseinfo.WarehousingCount {
  1830. c.ServeSuccessJSON(map[string]interface{}{
  1831. "msg": "5",
  1832. })
  1833. return
  1834. }
  1835. //更改入库数量
  1836. errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  1837. break
  1838. }
  1839. }
  1840. c.ServeSuccessJSON(map[string]interface{}{
  1841. "msg": "3",
  1842. })
  1843. return
  1844. }
  1845. func (c *StockManagerApiController) GetCancelStockInfoList() {
  1846. id, _ := c.GetInt64("id", 0)
  1847. cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
  1848. info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1849. manufacturerList, _ := service.GetAllManufacturerList(c.GetAdminUserInfo().CurrentOrgId)
  1850. dealerList, _ := service.GetAllDealerList(c.GetAdminUserInfo().CurrentOrgId)
  1851. c.ServeSuccessJSON(map[string]interface{}{
  1852. "list": cancelStockInfoList,
  1853. "info": info,
  1854. "manufacturerList": manufacturerList,
  1855. "dealerList": dealerList,
  1856. })
  1857. }
  1858. func (c *StockManagerApiController) GetCancelStockList() {
  1859. page, _ := c.GetInt64("page", -1)
  1860. limit, _ := c.GetInt64("limit", -1)
  1861. start_time := c.GetString("start_time")
  1862. end_time := c.GetString("end_time")
  1863. types, _ := c.GetInt64("type", 0)
  1864. keywords := c.GetString("keywords")
  1865. timeLayout := "2006-01-02"
  1866. loc, _ := time.LoadLocation("Local")
  1867. var startTime int64
  1868. if len(start_time) > 0 {
  1869. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1870. if err != nil {
  1871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1872. return
  1873. }
  1874. startTime = theTime.Unix()
  1875. }
  1876. var endTime int64
  1877. if len(end_time) > 0 {
  1878. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1879. if err != nil {
  1880. utils.ErrorLog(err.Error())
  1881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1882. return
  1883. }
  1884. endTime = theTime.Unix()
  1885. }
  1886. adminUserInfo := c.GetAdminUserInfo()
  1887. returnList, total, err := service.FindAllCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1888. if err == nil {
  1889. c.ServeSuccessJSON(map[string]interface{}{
  1890. "list": returnList,
  1891. "total": total,
  1892. })
  1893. } else {
  1894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1895. }
  1896. }
  1897. func (this *StockManagerApiController) DeleteCancelStock() {
  1898. ids := this.GetString("ids")
  1899. if len(ids) == 0 {
  1900. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1901. return
  1902. }
  1903. idArray := strings.Split(ids, ",")
  1904. err := service.DeleteCancelStock(idArray)
  1905. if err != nil {
  1906. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1907. } else {
  1908. this.ServeSuccessJSON(map[string]interface{}{
  1909. "msg": "删除成功",
  1910. })
  1911. }
  1912. }
  1913. func (this *StockManagerApiController) DeleteCancelStockInfo() {
  1914. id, _ := this.GetInt64("id", 0)
  1915. fmt.Println(id)
  1916. if id == 0 {
  1917. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1918. return
  1919. }
  1920. err := service.UpDateCancleStockStatus(id)
  1921. if err != nil {
  1922. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1923. } else {
  1924. this.ServeSuccessJSON(map[string]interface{}{
  1925. "msg": "删除成功",
  1926. })
  1927. }
  1928. }
  1929. func (c *StockManagerApiController) EditCancelStock() {
  1930. cancel_time := c.GetString("cancel_time")
  1931. id, _ := c.GetInt64("id", 0)
  1932. if id == 0 {
  1933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1934. return
  1935. }
  1936. ctime := time.Now().Unix()
  1937. mtime := time.Now().Unix()
  1938. adminUserInfo := c.GetAdminUserInfo()
  1939. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  1940. if parseDateErr != nil {
  1941. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  1942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1943. return
  1944. }
  1945. cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1946. tempCancelStock := models.CancelStock{
  1947. ID: cancelStock.ID,
  1948. Mtime: mtime,
  1949. ReturnTime: cancelDate.Unix(),
  1950. }
  1951. service.EditCancelStock(tempCancelStock)
  1952. dataBody := make(map[string]interface{}, 0)
  1953. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1954. if err != nil {
  1955. utils.ErrorLog(err.Error())
  1956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1957. return
  1958. }
  1959. var cancelStockInfos []*models.CancelStockInfo
  1960. var upDateCancelStockInfos []*models.CancelStockInfo
  1961. var stockFlow []*models.VmStockFlow
  1962. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1963. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  1964. if len(thisCancelStock) > 0 {
  1965. for _, item := range thisCancelStock {
  1966. items := item.(map[string]interface{})
  1967. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1968. utils.ErrorLog("good_id")
  1969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1970. return
  1971. }
  1972. good_id := int64(items["good_id"].(float64))
  1973. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1974. utils.ErrorLog("good_type_id")
  1975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1976. return
  1977. }
  1978. good_type_id := int64(items["good_type_id"].(float64))
  1979. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1980. utils.ErrorLog("count")
  1981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1982. return
  1983. }
  1984. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1985. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1986. utils.ErrorLog("id")
  1987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1988. return
  1989. }
  1990. id := int64(items["id"].(float64))
  1991. number := items["number"].(string)
  1992. register_account := items["register_account"].(string)
  1993. manufacturer, _ := items["manufacturer"].(string)
  1994. dealer, _ := items["dealer"].(string)
  1995. remark := items["remark"].(string)
  1996. var productDates int64
  1997. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1998. productDates = 0
  1999. } else {
  2000. if len(items["product_date"].(string)) == 0 {
  2001. productDates = 0
  2002. } else {
  2003. productDate, _ := items["product_date"].(string)
  2004. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  2005. productDates = product_date.Unix()
  2006. }
  2007. }
  2008. var expiryDates int64
  2009. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  2010. expiryDates = 0
  2011. } else {
  2012. if len(items["expiry_date"].(string)) == 0 {
  2013. expiryDates = 0
  2014. } else {
  2015. expiryDate, _ := items["expiry_date"].(string)
  2016. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  2017. expiryDates = expiry_date.Unix()
  2018. }
  2019. }
  2020. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2021. utils.ErrorLog("price")
  2022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2023. return
  2024. }
  2025. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2026. if id == 0 {
  2027. cancelStockInfo := &models.CancelStockInfo{
  2028. GoodId: good_id,
  2029. GoodTypeId: good_type_id,
  2030. Count: count,
  2031. Status: 1,
  2032. Ctime: ctime,
  2033. OrgId: adminUserInfo.CurrentOrgId,
  2034. OrderNumber: cancelStock.OrderNumber,
  2035. CancelStockId: cancelStock.ID,
  2036. Mtime: time.Now().Unix(),
  2037. Number: number,
  2038. RegisterAccount: register_account,
  2039. Manufacturer: manufacturer,
  2040. Dealer: dealer,
  2041. ProductDate: productDates,
  2042. ExpiryDate: expiryDates,
  2043. Remark: remark,
  2044. Price: price,
  2045. }
  2046. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  2047. flow := &models.VmStockFlow{
  2048. WarehousingId: 0,
  2049. GoodId: good_id,
  2050. Number: number,
  2051. LicenseNumber: "",
  2052. Count: count,
  2053. UserOrgId: adminUserInfo.CurrentOrgId,
  2054. PatientId: 0,
  2055. SystemTime: time.Now().Unix(),
  2056. ConsumableType: 4,
  2057. IsSys: 0,
  2058. WarehousingOrder: "",
  2059. WarehouseOutId: 0,
  2060. WarehouseOutOrderNumber: "",
  2061. IsEdit: 2,
  2062. CancelStockId: cancelStock.ID,
  2063. CancelOrderNumber: cancelStock.OrderNumber,
  2064. Manufacturer: 0,
  2065. Dealer: 0,
  2066. Creator: adminUserInfo.AdminUser.Id,
  2067. UpdateCreator: 0,
  2068. Status: 1,
  2069. Ctime: time.Now().Unix(),
  2070. Mtime: 0,
  2071. Price: price,
  2072. WarehousingDetailId: 0,
  2073. WarehouseOutDetailId: 0,
  2074. CancelOutDetailId: 0,
  2075. ProductDate: productDates,
  2076. ExpireDate: expiryDates,
  2077. }
  2078. stockFlow = append(stockFlow, flow)
  2079. } else {
  2080. cancelStockInfo := &models.CancelStockInfo{
  2081. ID: id,
  2082. GoodId: good_id,
  2083. GoodTypeId: good_type_id,
  2084. Count: count,
  2085. Status: 1,
  2086. Ctime: ctime,
  2087. OrgId: adminUserInfo.CurrentOrgId,
  2088. OrderNumber: cancelStock.OrderNumber,
  2089. CancelStockId: cancelStock.ID,
  2090. Mtime: time.Now().Unix(),
  2091. Number: number,
  2092. RegisterAccount: register_account,
  2093. Manufacturer: manufacturer,
  2094. Dealer: dealer,
  2095. ProductDate: productDates,
  2096. ExpiryDate: expiryDates,
  2097. Remark: remark,
  2098. Price: price,
  2099. }
  2100. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  2101. flow := &models.VmStockFlow{
  2102. WarehousingId: 0,
  2103. GoodId: good_id,
  2104. Number: number,
  2105. LicenseNumber: "",
  2106. Count: count,
  2107. UserOrgId: adminUserInfo.CurrentOrgId,
  2108. PatientId: 0,
  2109. SystemTime: time.Now().Unix(),
  2110. ConsumableType: 4,
  2111. IsSys: 0,
  2112. WarehousingOrder: "",
  2113. WarehouseOutId: 0,
  2114. WarehouseOutOrderNumber: "",
  2115. IsEdit: 2,
  2116. CancelStockId: cancelStock.ID,
  2117. CancelOrderNumber: cancelStock.OrderNumber,
  2118. Manufacturer: 0,
  2119. Dealer: 0,
  2120. Creator: adminUserInfo.AdminUser.Id,
  2121. UpdateCreator: 0,
  2122. Status: 1,
  2123. Ctime: time.Now().Unix(),
  2124. Mtime: 0,
  2125. Price: price,
  2126. WarehousingDetailId: 0,
  2127. WarehouseOutDetailId: 0,
  2128. CancelOutDetailId: 0,
  2129. ProductDate: productDates,
  2130. ExpireDate: expiryDates,
  2131. }
  2132. stockFlow = append(stockFlow, flow)
  2133. }
  2134. }
  2135. }
  2136. }
  2137. var errs error
  2138. fmt.Println("出库22322333223", cancelStockInfos)
  2139. fmt.Println("更新23232323232323233", upDateCancelStockInfos)
  2140. if len(cancelStockInfos) > 0 {
  2141. for _, item := range cancelStockInfos {
  2142. //统计该耗材的出库数量
  2143. info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId, item.WarehouseInfoId)
  2144. if item.Count > info.Count {
  2145. c.ServeSuccessJSON(map[string]interface{}{
  2146. "msg": "2",
  2147. })
  2148. return
  2149. }
  2150. //查询该批次入库的值
  2151. infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2152. if item.Count > infolist.WarehousingCount {
  2153. c.ServeSuccessJSON(map[string]interface{}{
  2154. "msg": "4",
  2155. })
  2156. return
  2157. }
  2158. if item.Count <= infolist.WarehousingCount {
  2159. errs := service.CreateCancelStockInfo(cancelStockInfos)
  2160. if len(stockFlow) > 0 {
  2161. service.CreateStockFlow(stockFlow)
  2162. }
  2163. if errs != nil {
  2164. utils.ErrorLog(errs.Error())
  2165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2166. return
  2167. }
  2168. //更改入库数量
  2169. errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  2170. break
  2171. }
  2172. }
  2173. }
  2174. if len(upDateCancelStockInfos) > 0 {
  2175. for _, item := range upDateCancelStockInfos {
  2176. //获取该批次最后一套出库记录
  2177. info, _ := service.GetLastCancelInfo(item.WarehouseInfoId, item.GoodId)
  2178. fmt.Println("info232332322332233223", info.Count, item.Count)
  2179. //比较出库数量和最后一次出库数据大小
  2180. //退库(加)
  2181. if item.Count < info.Count {
  2182. var total = info.Count - item.Count
  2183. errs = service.UpDateCancelStockInfo(item)
  2184. service.CreateStockFlow(stockFlow)
  2185. warehouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2186. if (warehouseinfo.StockCount + total) > warehouseinfo.StockCount {
  2187. c.ServeSuccessJSON(map[string]interface{}{
  2188. "msg": "5",
  2189. })
  2190. return
  2191. }
  2192. parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total)
  2193. if parseDateErr != nil {
  2194. utils.ErrorLog(errs.Error())
  2195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2196. break
  2197. }
  2198. }
  2199. //(减)
  2200. if item.Count > info.Count {
  2201. errs = service.UpDateCancelStockInfo(item)
  2202. service.CreateStockFlow(stockFlow)
  2203. //查询该批次入库的值
  2204. infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2205. if item.Count > infolist.WarehousingCount {
  2206. c.ServeSuccessJSON(map[string]interface{}{
  2207. "msg": "4",
  2208. })
  2209. return
  2210. }
  2211. if item.Count <= infolist.WarehousingCount {
  2212. var total_count = info.Count - item.Count
  2213. parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total_count)
  2214. if parseDateErr != nil {
  2215. utils.ErrorLog(errs.Error())
  2216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2217. return
  2218. }
  2219. }
  2220. }
  2221. }
  2222. if errs != nil {
  2223. utils.ErrorLog(errs.Error())
  2224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2225. return
  2226. }
  2227. c.ServeSuccessJSON(map[string]interface{}{
  2228. "msg": "3",
  2229. })
  2230. }
  2231. if errs != nil {
  2232. utils.ErrorLog(errs.Error())
  2233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2234. return
  2235. }
  2236. c.ServeSuccessJSON(map[string]interface{}{
  2237. "msg": "3",
  2238. })
  2239. }
  2240. func (this *StockManagerApiController) GetCancelStockConfig() {
  2241. types, _ := this.GetInt64("type", 0)
  2242. adminUserInfo := this.GetAdminUserInfo()
  2243. warehouseOutInfoList, _ := service.FindAllWarehouseOutInfo(adminUserInfo.CurrentOrgId, types)
  2244. this.ServeSuccessJSON(map[string]interface{}{
  2245. "warehouseOutInfoList": warehouseOutInfoList,
  2246. })
  2247. }
  2248. func (c *StockManagerApiController) GetQueryInfo() {
  2249. page, _ := c.GetInt64("page", -1)
  2250. limit, _ := c.GetInt64("limit", -1)
  2251. keyword := c.GetString("keyword")
  2252. start_time := c.GetString("start_time")
  2253. end_time := c.GetString("end_time")
  2254. type_name, _ := c.GetInt64("type_name")
  2255. timeLayout := "2006-01-02"
  2256. loc, _ := time.LoadLocation("Local")
  2257. var startTime int64
  2258. if len(start_time) > 0 {
  2259. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2260. if err != nil {
  2261. fmt.Println(err)
  2262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2263. return
  2264. }
  2265. startTime = theTime.Unix()
  2266. }
  2267. var endTime int64
  2268. if len(end_time) > 0 {
  2269. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2270. if err != nil {
  2271. utils.ErrorLog(err.Error())
  2272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2273. return
  2274. }
  2275. endTime = theTime.Unix()
  2276. }
  2277. adminUserInfo := c.GetAdminUserInfo()
  2278. list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, startTime, endTime, type_name)
  2279. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  2280. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId, "")
  2281. if err == nil {
  2282. c.ServeSuccessJSON(map[string]interface{}{
  2283. "list": list,
  2284. "total": total,
  2285. "info": info,
  2286. "infomationList": infomationList,
  2287. "orgid": adminUserInfo.CurrentOrgId,
  2288. })
  2289. } else {
  2290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2291. }
  2292. }
  2293. func (c *StockManagerApiController) SearchWarehouse() {
  2294. keywords := c.GetString("keywords")
  2295. adminUserInfo := c.GetAdminUserInfo()
  2296. warehouseList, total, err := service.FindAllWarehouseByKeyword(adminUserInfo.CurrentOrgId, 1, 10, keywords)
  2297. if err == nil {
  2298. c.ServeSuccessJSON(map[string]interface{}{
  2299. "list": warehouseList,
  2300. "total": total,
  2301. })
  2302. } else {
  2303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2304. }
  2305. }
  2306. func (c *StockManagerApiController) GetAllConfig() {
  2307. adminUserInfo := c.GetAdminUserInfo()
  2308. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  2309. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  2310. goodType, _ := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  2311. goodInfo, _ := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
  2312. c.ServeSuccessJSON(map[string]interface{}{
  2313. "manufacturer": manufacturer,
  2314. "dealer": dealer,
  2315. "goodType": goodType,
  2316. "goodInfo": goodInfo,
  2317. })
  2318. }
  2319. func (this *StockManagerApiController) GetAllSalesReturnConfig() {
  2320. types, _ := this.GetInt64("type", 0)
  2321. adminUserInfo := this.GetAdminUserInfo()
  2322. warehouseInfoList, _ := service.FindAllWarehouseInfo(adminUserInfo.CurrentOrgId, types)
  2323. this.ServeSuccessJSON(map[string]interface{}{
  2324. "warehouseInfoList": warehouseInfoList,
  2325. })
  2326. }
  2327. func (this *StockManagerApiController) GetDetailInfo() {
  2328. page, _ := this.GetInt64("page", 0)
  2329. limit, _ := this.GetInt64("limit", 0)
  2330. start_time := this.GetString("start_time")
  2331. end_time := this.GetString("end_time")
  2332. types, _ := this.GetInt64("type", 0)
  2333. keywords := this.GetString("keywords")
  2334. manufacturer, _ := this.GetInt64("manufacturer", 0)
  2335. order_type, _ := this.GetInt64("order_type", 0)
  2336. dealer, _ := this.GetInt64("dealer", 0)
  2337. timeLayout := "2006-01-02"
  2338. loc, _ := time.LoadLocation("Local")
  2339. var startTime int64
  2340. if len(start_time) > 0 {
  2341. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2342. if err != nil {
  2343. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2344. return
  2345. }
  2346. startTime = theTime.Unix()
  2347. }
  2348. var endTime int64
  2349. if len(end_time) > 0 {
  2350. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2351. if err != nil {
  2352. utils.ErrorLog(err.Error())
  2353. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2354. return
  2355. }
  2356. endTime = theTime.Unix()
  2357. }
  2358. adminUserInfo := this.GetAdminUserInfo()
  2359. var list []*models.WarehousingInfo
  2360. var list1 []*models.WarehouseOutInfo
  2361. var list2 []*models.SalesReturnInfo
  2362. var list3 []*models.CancelStockInfo
  2363. var total int64
  2364. var err error
  2365. var total_price float64
  2366. if types == 1 {
  2367. list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2368. _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2369. if err == nil {
  2370. this.ServeSuccessJSON(map[string]interface{}{
  2371. "list": list,
  2372. "total": total,
  2373. "total_price": total_price,
  2374. })
  2375. } else {
  2376. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2377. }
  2378. } else if types == 2 {
  2379. list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2380. _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2381. if err == nil {
  2382. this.ServeSuccessJSON(map[string]interface{}{
  2383. "list": list1,
  2384. "total": total,
  2385. "total_price": total_price,
  2386. })
  2387. } else {
  2388. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2389. }
  2390. } else if types == 3 {
  2391. list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2392. if err == nil {
  2393. this.ServeSuccessJSON(map[string]interface{}{
  2394. "list": list2,
  2395. "total": total,
  2396. })
  2397. } else {
  2398. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2399. }
  2400. } else if types == 4 {
  2401. list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2402. listGroup, err := service.FindeCancelGroup(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2403. if err == nil {
  2404. this.ServeSuccessJSON(map[string]interface{}{
  2405. "list": list3,
  2406. "total": total,
  2407. "listgroup": listGroup,
  2408. })
  2409. } else {
  2410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2411. }
  2412. }
  2413. }
  2414. func (this *StockManagerApiController) GetUserDetailInfo() {
  2415. order_id, _ := this.GetInt64("id")
  2416. if order_id <= 0 {
  2417. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2418. return
  2419. }
  2420. adminUserInfo := this.GetAdminUserInfo()
  2421. userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  2422. if err == nil {
  2423. this.ServeSuccessJSON(map[string]interface{}{
  2424. "list": userDetails,
  2425. "total": total,
  2426. })
  2427. } else {
  2428. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2429. return
  2430. }
  2431. }
  2432. func (this *StockManagerApiController) PostSearchStock() {
  2433. keyword := this.GetString("keyword")
  2434. adminUserInfo := this.GetAdminUserInfo()
  2435. orgId := adminUserInfo.CurrentOrgId
  2436. stock, err := service.PostSearchStock(keyword, orgId)
  2437. if err != nil {
  2438. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2439. }
  2440. this.ServeSuccessJSON(map[string]interface{}{
  2441. "stock": stock,
  2442. })
  2443. }
  2444. func (this *StockManagerApiController) GetOutStockTotalCount() {
  2445. warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
  2446. adminUserInfo := this.GetAdminUserInfo()
  2447. stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
  2448. if err != nil {
  2449. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2450. }
  2451. this.ServeSuccessJSON(map[string]interface{}{
  2452. "stockCount": stockCount,
  2453. })
  2454. }
  2455. func (this *StockManagerApiController) AddGoodInformation() {
  2456. adminUserInfo := this.GetAdminUserInfo()
  2457. orgId := adminUserInfo.CurrentOrgId
  2458. dataBody := make(map[string]interface{}, 0)
  2459. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2460. if err != nil {
  2461. utils.ErrorLog(err.Error())
  2462. return
  2463. }
  2464. utils.ErrorLog("%v", dataBody)
  2465. var goods []*models.GoodInfo
  2466. var total_goods []interface{}
  2467. tempGoods := dataBody["goods"].([]interface{})
  2468. total_goods = tempGoods
  2469. for index, goodMap := range tempGoods {
  2470. goodNameM := goodMap.(map[string]interface{})
  2471. var good models.GoodInfo
  2472. if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
  2473. utils.ErrorLog("good_name")
  2474. return
  2475. }
  2476. good_name, _ := goodNameM["good_name"].(string)
  2477. if len(good_name) == 0 { //名字为空则生成一条导入错误日志
  2478. err_log := models.ExportErrLog{
  2479. LogType: 5,
  2480. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2481. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
  2482. Status: 1,
  2483. CreateTime: time.Now().Unix(),
  2484. UpdateTime: time.Now().Unix(),
  2485. ExportTime: time.Now().Unix(),
  2486. }
  2487. service.CreateExportErrLog(&err_log)
  2488. continue
  2489. }
  2490. good.GoodName = good_name
  2491. // 获取数据字典数据
  2492. var good_kind_id int64
  2493. var name = "耗材种类"
  2494. config, _ := service.GetDrugDataConfig(0, name)
  2495. good_kind := goodNameM["good_kind"].(string)
  2496. if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
  2497. err_log := models.ExportErrLog{
  2498. LogType: 5,
  2499. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2500. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
  2501. Status: 1,
  2502. CreateTime: time.Now().Unix(),
  2503. UpdateTime: time.Now().Unix(),
  2504. ExportTime: time.Now().Unix(),
  2505. }
  2506. service.CreateExportErrLog(&err_log)
  2507. continue
  2508. }
  2509. if len(good_kind) != 0 {
  2510. _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
  2511. lastConfig, _ := service.GetLastDicConfig(config.ID, orgId)
  2512. dataconfig := models.DictDataconfig{
  2513. ParentId: config.ID,
  2514. Module: "system",
  2515. OrgId: orgId,
  2516. Name: good_kind,
  2517. FieldName: "",
  2518. Value: lastConfig.Value + 1,
  2519. CreatedTime: "",
  2520. UpdatedTime: "",
  2521. CreateUserId: adminUserInfo.AdminUser.Id,
  2522. Status: 1,
  2523. Remark: "",
  2524. DeleteIdSystem: 0,
  2525. Title: "",
  2526. Content: "",
  2527. Order: 0,
  2528. Code: "",
  2529. }
  2530. if errcodegoodkind == gorm.ErrRecordNotFound {
  2531. service.CreatedDicConfig(&dataconfig)
  2532. }
  2533. }
  2534. dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
  2535. for _, it := range dataConfig {
  2536. if good_kind == it.Name {
  2537. fmt.Println(it.Name)
  2538. good_kind_id = int64(it.Value)
  2539. }
  2540. }
  2541. good.GoodKind = good_kind_id
  2542. good_type := goodNameM["type_name"].(string)
  2543. if len(good_type) == 0 {
  2544. err_log := models.ExportErrLog{
  2545. LogType: 5,
  2546. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2547. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材类型不能为空",
  2548. Status: 1,
  2549. CreateTime: time.Now().Unix(),
  2550. UpdateTime: time.Now().Unix(),
  2551. ExportTime: time.Now().Unix(),
  2552. }
  2553. service.CreateExportErrLog(&err_log)
  2554. continue
  2555. }
  2556. if len(good_type) != 0 {
  2557. _, errcodegoodtype := service.GetGoodType(good_type, orgId)
  2558. if errcodegoodtype == gorm.ErrRecordNotFound {
  2559. goodsType := models.GoodsType{
  2560. TypeName: good_type,
  2561. Remark: "",
  2562. Ctime: time.Now().Unix(),
  2563. Mtime: 0,
  2564. Creater: adminUserInfo.AdminUser.Id,
  2565. Modifier: 0,
  2566. OrgId: adminUserInfo.CurrentOrgId,
  2567. Status: 1,
  2568. Type: 0,
  2569. Number: 0,
  2570. OutStock: 0,
  2571. StockAttribute: 1,
  2572. }
  2573. service.CreatedGoodType(&goodsType)
  2574. }
  2575. }
  2576. goodType, _ := service.GetAllGoodType(orgId)
  2577. var good_type_id int64
  2578. for _, it := range goodType {
  2579. if good_type == it.TypeName {
  2580. good_type_id = it.ID
  2581. }
  2582. }
  2583. good.GoodTypeId = good_type_id
  2584. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  2585. if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
  2586. err_log := models.ExportErrLog{
  2587. LogType: 5,
  2588. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2589. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  2590. Status: 1,
  2591. CreateTime: time.Now().Unix(),
  2592. UpdateTime: time.Now().Unix(),
  2593. ExportTime: time.Now().Unix(),
  2594. }
  2595. service.CreateExportErrLog(&err_log)
  2596. continue
  2597. }
  2598. var medical_insurance_id int64
  2599. var medicalInsurance = "医保等级"
  2600. medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
  2601. if len(medical_insurance_level) != 0 {
  2602. _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
  2603. if errcodemedicalInsurance == gorm.ErrRecordNotFound {
  2604. mediConfigOne, _ := service.GetLastDicConfig(medicalInsuranceDataConfig.ID, orgId)
  2605. dataconfig := models.DictDataconfig{
  2606. ParentId: medicalInsuranceDataConfig.ID,
  2607. Module: "system",
  2608. OrgId: orgId,
  2609. Name: medical_insurance_level,
  2610. FieldName: "",
  2611. Value: mediConfigOne.Value + 1,
  2612. CreatedTime: "",
  2613. UpdatedTime: "",
  2614. CreateUserId: adminUserInfo.AdminUser.Id,
  2615. Status: 1,
  2616. Remark: "",
  2617. DeleteIdSystem: 0,
  2618. Title: "",
  2619. Content: "",
  2620. Order: 0,
  2621. Code: "",
  2622. }
  2623. service.CreatedDicConfig(&dataconfig)
  2624. }
  2625. }
  2626. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
  2627. for _, it := range medicalInsuranceList {
  2628. if medical_insurance_level == it.Name {
  2629. medical_insurance_id = int64(it.Value)
  2630. }
  2631. }
  2632. good.MedicalInsuranceLevel = medical_insurance_id
  2633. if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
  2634. utils.ErrorLog("specification_name")
  2635. return
  2636. }
  2637. specification_name := goodNameM["specification_name"].(string)
  2638. if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
  2639. err_log := models.ExportErrLog{
  2640. LogType: 5,
  2641. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2642. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
  2643. Status: 1,
  2644. CreateTime: time.Now().Unix(),
  2645. UpdateTime: time.Now().Unix(),
  2646. ExportTime: time.Now().Unix(),
  2647. }
  2648. service.CreateExportErrLog(&err_log)
  2649. continue
  2650. }
  2651. good.SpecificationName = specification_name
  2652. var manufacturer_id int64
  2653. manufacturer := goodNameM["manufacturer"].(string)
  2654. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  2655. err_log := models.ExportErrLog{
  2656. LogType: 5,
  2657. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2658. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
  2659. Status: 1,
  2660. CreateTime: time.Now().Unix(),
  2661. UpdateTime: time.Now().Unix(),
  2662. ExportTime: time.Now().Unix(),
  2663. }
  2664. service.CreateExportErrLog(&err_log)
  2665. continue
  2666. }
  2667. if len(manufacturer) != 0 {
  2668. _, errcodes := service.GetManufacturerName(orgId, manufacturer)
  2669. manu := models.Manufacturer{
  2670. ManufacturerName: manufacturer,
  2671. Status: 1,
  2672. OrgId: orgId,
  2673. Creater: adminUserInfo.AdminUser.Id,
  2674. }
  2675. if errcodes == gorm.ErrRecordNotFound {
  2676. service.CreateManufacturer(&manu)
  2677. }
  2678. }
  2679. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2680. for _, it := range manufacturerList {
  2681. if manufacturer == it.ManufacturerName {
  2682. manufacturer_id = it.ID
  2683. }
  2684. }
  2685. good.Manufacturer = manufacturer_id
  2686. if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
  2687. utils.ErrorLog("unit_id")
  2688. return
  2689. }
  2690. unit_id := int64(goodNameM["unit_id"].(float64))
  2691. if unit_id <= 0 { //名字为空则生成一条导入错误日志
  2692. err_log := models.ExportErrLog{
  2693. LogType: 5,
  2694. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2695. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
  2696. Status: 1,
  2697. CreateTime: time.Now().Unix(),
  2698. UpdateTime: time.Now().Unix(),
  2699. ExportTime: time.Now().Unix(),
  2700. }
  2701. service.CreateExportErrLog(&err_log)
  2702. continue
  2703. }
  2704. good.GoodUnit = unit_id
  2705. retail_prices := goodNameM["retail_price"].(string)
  2706. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  2707. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  2708. err_log := models.ExportErrLog{
  2709. LogType: 5,
  2710. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2711. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的价格不能为空",
  2712. Status: 1,
  2713. CreateTime: time.Now().Unix(),
  2714. UpdateTime: time.Now().Unix(),
  2715. ExportTime: time.Now().Unix(),
  2716. }
  2717. service.CreateExportErrLog(&err_log)
  2718. continue
  2719. }
  2720. good.RetailPrice = retail_price
  2721. if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
  2722. utils.ErrorLog("stock_warn_count")
  2723. return
  2724. }
  2725. stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
  2726. if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
  2727. err_log := models.ExportErrLog{
  2728. LogType: 5,
  2729. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2730. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
  2731. Status: 1,
  2732. CreateTime: time.Now().Unix(),
  2733. UpdateTime: time.Now().Unix(),
  2734. ExportTime: time.Now().Unix(),
  2735. }
  2736. service.CreateExportErrLog(&err_log)
  2737. continue
  2738. }
  2739. good.StockWarnCount = stock_warn_count
  2740. var dealer_id int64
  2741. dealerName := goodNameM["dealer"].(string)
  2742. fmt.Println("经销商", dealerName)
  2743. dealer := models.Dealer{
  2744. OrgId: orgId,
  2745. Status: 1,
  2746. DealerName: dealerName,
  2747. Creater: adminUserInfo.AdminUser.Id,
  2748. Ctime: time.Now().Unix(),
  2749. }
  2750. if len(dealerName) != 0 {
  2751. _, errcodedealer := service.GetDealerByName(orgId, dealerName)
  2752. if errcodedealer == gorm.ErrRecordNotFound {
  2753. service.CreateDealer(&dealer)
  2754. }
  2755. }
  2756. dealerList, _ := service.GetAllDealerList(orgId)
  2757. for _, it := range dealerList {
  2758. if dealerName == it.DealerName {
  2759. dealer_id = it.ID
  2760. }
  2761. }
  2762. good.Dealer = dealer_id
  2763. if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
  2764. utils.ErrorLog("pinyin")
  2765. return
  2766. }
  2767. pinyin := goodNameM["pinyin"].(string)
  2768. good.Pinyin = pinyin
  2769. if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
  2770. utils.ErrorLog("wubi")
  2771. return
  2772. }
  2773. wubi := goodNameM["wubi"].(string)
  2774. good.Wubi = wubi
  2775. buy_prices := goodNameM["buy_price"].(string)
  2776. buy_price, _ := strconv.ParseFloat(buy_prices, 64)
  2777. good.BuyPrice = buy_price
  2778. if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
  2779. utils.ErrorLog("social_security_directory_code")
  2780. return
  2781. }
  2782. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  2783. good.SocialSecurityDirectoryCode = social_security_directory_code
  2784. if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
  2785. utils.ErrorLog("is_special_diseases")
  2786. return
  2787. }
  2788. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  2789. good.IsSpecialDiseases = is_special_diseases
  2790. if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
  2791. utils.ErrorLog("is_record")
  2792. return
  2793. }
  2794. is_record := int64(goodNameM["is_record"].(float64))
  2795. good.IsRecord = is_record
  2796. if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
  2797. utils.ErrorLog("good_status")
  2798. return
  2799. }
  2800. good_status := goodNameM["good_status"].(string)
  2801. good.GoodStatus = good_status
  2802. if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
  2803. utils.ErrorLog("medical_insurance_number")
  2804. return
  2805. }
  2806. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  2807. good.MedicalInsuranceNumber = medical_insurance_number
  2808. if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
  2809. utils.ErrorLog("production_type")
  2810. return
  2811. }
  2812. production_type := goodNameM["production_type"].(string)
  2813. good.ProductionType = production_type
  2814. if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
  2815. utils.ErrorLog("remark")
  2816. return
  2817. }
  2818. remark := goodNameM["remark"].(string)
  2819. good.Remark = remark
  2820. statistics_category := goodNameM["statistics_category"].(string)
  2821. var categoryName = "统计分类"
  2822. var statistic_id int64
  2823. drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
  2824. if len(statistics_category) != 0 {
  2825. _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
  2826. if errcodecagegory == gorm.ErrRecordNotFound {
  2827. dicConfigThree, _ := service.GetLastDicConfig(drugDataConfig.ID, orgId)
  2828. dataconfig := models.DictDataconfig{
  2829. ParentId: drugDataConfig.ID,
  2830. Module: "system",
  2831. OrgId: orgId,
  2832. Name: statistics_category,
  2833. FieldName: "",
  2834. Value: dicConfigThree.Value + 1,
  2835. CreatedTime: "",
  2836. UpdatedTime: "",
  2837. CreateUserId: adminUserInfo.AdminUser.Id,
  2838. Status: 1,
  2839. Remark: "",
  2840. DeleteIdSystem: 0,
  2841. Title: "",
  2842. Content: "",
  2843. Order: 0,
  2844. Code: "",
  2845. }
  2846. service.CreatedDicConfig(&dataconfig)
  2847. }
  2848. }
  2849. parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
  2850. for _, it := range parentDataConfig {
  2851. if statistics_category == it.Name {
  2852. statistic_id = int64(it.Value)
  2853. }
  2854. }
  2855. good.StatisticsCategory = statistic_id
  2856. special_medical := goodNameM["special_medical"].(string)
  2857. good.SpecialMedical = special_medical
  2858. goods = append(goods, &good)
  2859. }
  2860. export_time := time.Now().Unix()
  2861. errLogs, _ := service.FindPatientExportLogTwo(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2862. if len(goods) > 0 {
  2863. for _, item := range goods {
  2864. goodInfo := models.GoodInfo{
  2865. GoodName: item.GoodName,
  2866. SpecificationName: item.SpecificationName,
  2867. GoodKind: item.GoodKind,
  2868. GoodTypeId: item.GoodTypeId,
  2869. Dealer: item.Dealer,
  2870. GoodUnit: item.GoodUnit,
  2871. IsRecord: item.IsRecord,
  2872. IsSpecialDiseases: item.IsSpecialDiseases,
  2873. Manufacturer: item.Manufacturer,
  2874. Pinyin: item.Pinyin,
  2875. GoodStatus: item.GoodStatus,
  2876. ProductionType: item.ProductionType,
  2877. Remark: item.Remark,
  2878. RetailPrice: item.RetailPrice,
  2879. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  2880. SpecialMedical: item.SpecialMedical,
  2881. Wubi: item.Wubi,
  2882. StockWarnCount: item.StockWarnCount,
  2883. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  2884. OrgId: orgId,
  2885. Status: 1,
  2886. Ctime: time.Now().Unix(),
  2887. StatisticsCategory: item.StatisticsCategory,
  2888. GoodCode: item.GoodCode,
  2889. BuyPrice: item.BuyPrice,
  2890. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  2891. }
  2892. //查询同种耗材名称同种类型同种规格的耗材是否存在
  2893. _, errcodegood := service.GetGoodsInformaitonIsExist(item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2894. if errcodegood == gorm.ErrRecordNotFound {
  2895. service.CreateGoodsInfomation(&goodInfo)
  2896. } else if errcodegood == nil {
  2897. service.UpdateGoodsInformation(&goodInfo, item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2898. }
  2899. log := models.ExportLog{
  2900. LogType: 5,
  2901. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2902. TotalNum: int64(len(total_goods)),
  2903. FailNum: int64(len(errLogs)),
  2904. SuccessNum: int64(len(goods)),
  2905. CreateTime: time.Now().Unix(),
  2906. UpdateTime: time.Now().Unix(),
  2907. ExportTime: export_time,
  2908. Status: 1,
  2909. }
  2910. service.CreateExportLog(&log)
  2911. this.ServeSuccessJSON(map[string]interface{}{
  2912. "msg": "导入成功",
  2913. "total_num": len(total_goods),
  2914. "success_num": len(goods),
  2915. "fail_num": int64(len(errLogs)),
  2916. })
  2917. }
  2918. } else {
  2919. log := models.ExportLog{
  2920. LogType: 5,
  2921. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2922. TotalNum: int64(len(total_goods)),
  2923. FailNum: int64(len(errLogs)),
  2924. SuccessNum: int64(len(goods)),
  2925. CreateTime: time.Now().Unix(),
  2926. UpdateTime: time.Now().Unix(),
  2927. ExportTime: export_time,
  2928. Status: 1,
  2929. }
  2930. service.CreateExportLog(&log)
  2931. this.ServeSuccessJSON(map[string]interface{}{
  2932. "msg": "导入成功",
  2933. "total_num": len(total_goods),
  2934. "success_num": len(goods),
  2935. "fail_num": int64(len(errLogs)),
  2936. })
  2937. }
  2938. }
  2939. func (this *StockManagerApiController) AddDrugInformation() {
  2940. adminUser := this.GetAdminUserInfo()
  2941. orgId := adminUser.CurrentOrgId
  2942. dataBody := make(map[string]interface{}, 0)
  2943. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2944. if err != nil {
  2945. utils.ErrorLog(err.Error())
  2946. return
  2947. }
  2948. utils.ErrorLog("%v", dataBody)
  2949. var drugList []*models.BaseDrugLib
  2950. var total_goods []interface{}
  2951. tempDrugs := dataBody["drugs"].([]interface{})
  2952. total_goods = tempDrugs
  2953. for index, drugMap := range tempDrugs {
  2954. goodNameM := drugMap.(map[string]interface{})
  2955. var drug models.BaseDrugLib
  2956. if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
  2957. utils.ErrorLog("drug_name")
  2958. return
  2959. }
  2960. drug_name, _ := goodNameM["drug_name"].(string)
  2961. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2962. err_log := models.ExportErrLog{
  2963. LogType: 4,
  2964. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2965. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
  2966. Status: 1,
  2967. CreateTime: time.Now().Unix(),
  2968. UpdateTime: time.Now().Unix(),
  2969. ExportTime: time.Now().Unix(),
  2970. }
  2971. service.CreateExportErrLog(&err_log)
  2972. continue
  2973. }
  2974. drug.DrugName = drug_name
  2975. if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
  2976. utils.ErrorLog("min_number")
  2977. return
  2978. }
  2979. min_number, _ := goodNameM["min_number"].(string)
  2980. minNumber, _ := strconv.ParseInt(min_number, 10, 64)
  2981. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2982. err_log := models.ExportErrLog{
  2983. LogType: 4,
  2984. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2985. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
  2986. Status: 1,
  2987. CreateTime: time.Now().Unix(),
  2988. UpdateTime: time.Now().Unix(),
  2989. ExportTime: time.Now().Unix(),
  2990. }
  2991. service.CreateExportErrLog(&err_log)
  2992. continue
  2993. }
  2994. drug.MinNumber = minNumber
  2995. min_unit := goodNameM["min_unit"].(string)
  2996. if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
  2997. err_log := models.ExportErrLog{
  2998. LogType: 4,
  2999. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3000. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
  3001. Status: 1,
  3002. CreateTime: time.Now().Unix(),
  3003. UpdateTime: time.Now().Unix(),
  3004. ExportTime: time.Now().Unix(),
  3005. }
  3006. service.CreateExportErrLog(&err_log)
  3007. continue
  3008. }
  3009. drug.MinUnit = min_unit
  3010. dose := goodNameM["dose"].(float64)
  3011. if dose < 0 { //名字为空则生成一条导入错误日志
  3012. err_log := models.ExportErrLog{
  3013. LogType: 4,
  3014. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3015. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  3016. Status: 1,
  3017. CreateTime: time.Now().Unix(),
  3018. UpdateTime: time.Now().Unix(),
  3019. ExportTime: time.Now().Unix(),
  3020. }
  3021. service.CreateExportErrLog(&err_log)
  3022. continue
  3023. }
  3024. drug.Dose = dose
  3025. max_unit_id := goodNameM["max_unit"].(string)
  3026. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  3027. err_log := models.ExportErrLog{
  3028. LogType: 4,
  3029. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3030. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  3031. Status: 1,
  3032. CreateTime: time.Now().Unix(),
  3033. UpdateTime: time.Now().Unix(),
  3034. ExportTime: time.Now().Unix(),
  3035. }
  3036. service.CreateExportErrLog(&err_log)
  3037. continue
  3038. }
  3039. drug.MaxUnit = max_unit_id
  3040. max_unit := goodNameM["max_unit"].(string)
  3041. if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
  3042. err_log := models.ExportErrLog{
  3043. LogType: 4,
  3044. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3045. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
  3046. Status: 1,
  3047. CreateTime: time.Now().Unix(),
  3048. UpdateTime: time.Now().Unix(),
  3049. ExportTime: time.Now().Unix(),
  3050. }
  3051. service.CreateExportErrLog(&err_log)
  3052. continue
  3053. }
  3054. drug.MaxUnit = max_unit
  3055. delivery_way := goodNameM["delivery_way"].(string)
  3056. if len(delivery_way) == 0 { //名字为空则生成一条导入错误日志
  3057. err_log := models.ExportErrLog{
  3058. LogType: 4,
  3059. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3060. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认给药途径不能为空",
  3061. Status: 1,
  3062. CreateTime: time.Now().Unix(),
  3063. UpdateTime: time.Now().Unix(),
  3064. ExportTime: time.Now().Unix(),
  3065. }
  3066. service.CreateExportErrLog(&err_log)
  3067. continue
  3068. }
  3069. drug.DeliveryWay = delivery_way
  3070. execution_frequency := goodNameM["execution_frequency"].(string)
  3071. if len(execution_frequency) == 0 { //名字为空则生成一条导入错误日志
  3072. err_log := models.ExportErrLog{
  3073. LogType: 4,
  3074. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3075. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  3076. Status: 1,
  3077. CreateTime: time.Now().Unix(),
  3078. UpdateTime: time.Now().Unix(),
  3079. ExportTime: time.Now().Unix(),
  3080. }
  3081. service.CreateExportErrLog(&err_log)
  3082. continue
  3083. }
  3084. drug.ExecutionFrequency = execution_frequency
  3085. drug_day := goodNameM["drug_day"].(string)
  3086. if len(drug_day) == 0 { //名字为空则生成一条导入错误日志
  3087. err_log := models.ExportErrLog{
  3088. LogType: 4,
  3089. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3090. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  3091. Status: 1,
  3092. CreateTime: time.Now().Unix(),
  3093. UpdateTime: time.Now().Unix(),
  3094. ExportTime: time.Now().Unix(),
  3095. }
  3096. service.CreateExportErrLog(&err_log)
  3097. continue
  3098. }
  3099. drug.DrugDay = drug_day
  3100. drug_type := goodNameM["drug_type"].(string)
  3101. if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
  3102. err_log := models.ExportErrLog{
  3103. LogType: 4,
  3104. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3105. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
  3106. Status: 1,
  3107. CreateTime: time.Now().Unix(),
  3108. UpdateTime: time.Now().Unix(),
  3109. ExportTime: time.Now().Unix(),
  3110. }
  3111. service.CreateExportErrLog(&err_log)
  3112. continue
  3113. }
  3114. var drug_type_id int64
  3115. var drugType = "药品类型"
  3116. drugconfig, _ := service.GetDrugDataConfig(0, drugType)
  3117. if len(drug_type) != 0 {
  3118. _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
  3119. if errcodes == gorm.ErrRecordNotFound {
  3120. //获取该型号最后一条数据型号
  3121. config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
  3122. dataconfig := models.DictDataconfig{
  3123. ParentId: drugconfig.ID,
  3124. Module: "system",
  3125. OrgId: orgId,
  3126. Name: drug_type,
  3127. FieldName: "",
  3128. Value: config.Value + 1,
  3129. CreatedTime: "",
  3130. UpdatedTime: "",
  3131. CreateUserId: adminUser.AdminUser.Id,
  3132. Status: 1,
  3133. Remark: "",
  3134. DeleteIdSystem: 0,
  3135. Title: "",
  3136. Content: "",
  3137. Order: 0,
  3138. Code: "",
  3139. }
  3140. service.CreatedDicConfig(&dataconfig)
  3141. }
  3142. }
  3143. drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
  3144. for _, it := range drugTypeList {
  3145. if drug_type == it.Name {
  3146. drug_type_id = int64(it.Value)
  3147. }
  3148. }
  3149. drug.DrugType = drug_type_id
  3150. drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
  3151. if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
  3152. err_log := models.ExportErrLog{
  3153. LogType: 4,
  3154. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3155. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
  3156. Status: 1,
  3157. CreateTime: time.Now().Unix(),
  3158. UpdateTime: time.Now().Unix(),
  3159. ExportTime: time.Now().Unix(),
  3160. }
  3161. service.CreateExportErrLog(&err_log)
  3162. continue
  3163. }
  3164. drug.DrugStockLimit = drug_stock_limit
  3165. drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
  3166. if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
  3167. err_log := models.ExportErrLog{
  3168. LogType: 4,
  3169. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3170. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
  3171. Status: 1,
  3172. CreateTime: time.Now().Unix(),
  3173. UpdateTime: time.Now().Unix(),
  3174. ExportTime: time.Now().Unix(),
  3175. }
  3176. service.CreateExportErrLog(&err_log)
  3177. continue
  3178. }
  3179. drug.DrugOriginPlace = drug_origin_place
  3180. drug_dosage_form := goodNameM["drug_dosage_form"].(string)
  3181. if len(drug_dosage_form) == 0 {
  3182. err_log := models.ExportErrLog{
  3183. LogType: 4,
  3184. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3185. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
  3186. Status: 1,
  3187. CreateTime: time.Now().Unix(),
  3188. UpdateTime: time.Now().Unix(),
  3189. ExportTime: time.Now().Unix(),
  3190. }
  3191. service.CreateExportErrLog(&err_log)
  3192. continue
  3193. }
  3194. var drug_dosage = "药品剂型"
  3195. var drug_dosage_form_id int64
  3196. drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
  3197. if len(drug_dosage_form) != 0 {
  3198. _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
  3199. if errcodess == gorm.ErrRecordNotFound {
  3200. configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
  3201. dataconfig := models.DictDataconfig{
  3202. ParentId: drugDosageconfig.ID,
  3203. Module: "system",
  3204. OrgId: orgId,
  3205. Name: drug_dosage_form,
  3206. FieldName: "",
  3207. Value: configOne.Value + 1,
  3208. CreatedTime: "",
  3209. UpdatedTime: "",
  3210. CreateUserId: adminUser.AdminUser.Id,
  3211. Status: 1,
  3212. Remark: "",
  3213. DeleteIdSystem: 0,
  3214. Title: "",
  3215. Content: "",
  3216. Order: 0,
  3217. Code: "",
  3218. }
  3219. service.CreatedDicConfig(&dataconfig)
  3220. }
  3221. }
  3222. drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
  3223. for _, it := range drugDosageList {
  3224. if drug_dosage_form == it.Name {
  3225. drug_dosage_form_id = int64(it.Value)
  3226. }
  3227. }
  3228. drug.DrugDosageForm = drug_dosage_form_id
  3229. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  3230. var medical_insurance_level_id int64
  3231. if len(medical_insurance_level) == 0 { //名字为空则生成一条导入错误日志
  3232. err_log := models.ExportErrLog{
  3233. LogType: 4,
  3234. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3235. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  3236. Status: 1,
  3237. CreateTime: time.Now().Unix(),
  3238. UpdateTime: time.Now().Unix(),
  3239. ExportTime: time.Now().Unix(),
  3240. }
  3241. service.CreateExportErrLog(&err_log)
  3242. continue
  3243. }
  3244. var medicalInsuranceName = "医保等级"
  3245. medicalInsuranceConfig, _ := service.GetDrugDataConfig(0, medicalInsuranceName)
  3246. if len(medical_insurance_level) != 0 {
  3247. _, errcodemedical := service.IsExistDicConfig(medicalInsuranceConfig.ID, medical_insurance_level, orgId)
  3248. if errcodemedical == gorm.ErrRecordNotFound {
  3249. medConfig, _ := service.GetLastDicConfig(medicalInsuranceConfig.ID, orgId)
  3250. dataconfig := models.DictDataconfig{
  3251. ParentId: medicalInsuranceConfig.ID,
  3252. Module: "system",
  3253. OrgId: orgId,
  3254. Name: medical_insurance_level,
  3255. FieldName: "",
  3256. Value: medConfig.Value + 1,
  3257. CreatedTime: "",
  3258. UpdatedTime: "",
  3259. CreateUserId: adminUser.AdminUser.Id,
  3260. Status: 1,
  3261. Remark: "",
  3262. DeleteIdSystem: 0,
  3263. Title: "",
  3264. Content: "",
  3265. Order: 0,
  3266. Code: "",
  3267. }
  3268. service.CreatedDicConfig(&dataconfig)
  3269. }
  3270. }
  3271. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceConfig.ID, orgId)
  3272. for _, it := range medicalInsuranceList {
  3273. if medical_insurance_level == it.Name {
  3274. medical_insurance_level_id = int64(it.Value)
  3275. }
  3276. }
  3277. drug.MedicalInsuranceLevel = medical_insurance_level_id
  3278. unit_matrixing := goodNameM["unit_matrixing"].(string)
  3279. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  3280. err_log := models.ExportErrLog{
  3281. LogType: 4,
  3282. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3283. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位换算不能为空",
  3284. Status: 1,
  3285. CreateTime: time.Now().Unix(),
  3286. UpdateTime: time.Now().Unix(),
  3287. ExportTime: time.Now().Unix(),
  3288. }
  3289. service.CreateExportErrLog(&err_log)
  3290. continue
  3291. }
  3292. drug.UnitMatrixing = unit_matrixing
  3293. retail_prices := goodNameM["retail_price"].(string)
  3294. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  3295. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  3296. err_log := models.ExportErrLog{
  3297. LogType: 4,
  3298. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3299. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
  3300. Status: 1,
  3301. CreateTime: time.Now().Unix(),
  3302. UpdateTime: time.Now().Unix(),
  3303. ExportTime: time.Now().Unix(),
  3304. }
  3305. service.CreateExportErrLog(&err_log)
  3306. continue
  3307. }
  3308. drug.RetailPrice = retail_price
  3309. packing_prices := goodNameM["packing_price"].(string)
  3310. packing_price, _ := strconv.ParseFloat(packing_prices, 64)
  3311. if packing_price <= 0 { //名字为空则生成一条导入错误日志
  3312. err_log := models.ExportErrLog{
  3313. LogType: 4,
  3314. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3315. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装零售价不能为空",
  3316. Status: 1,
  3317. CreateTime: time.Now().Unix(),
  3318. UpdateTime: time.Now().Unix(),
  3319. ExportTime: time.Now().Unix(),
  3320. }
  3321. service.CreateExportErrLog(&err_log)
  3322. continue
  3323. }
  3324. drug.RetailPrice = retail_price
  3325. last_prices := goodNameM["last_price"].(string)
  3326. last_price, _ := strconv.ParseFloat(last_prices, 64)
  3327. if last_price <= 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.LastPrice = last_price
  3341. drug_classify := goodNameM["drug_classify"].(string)
  3342. if len(drug_classify) == 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. var drugClassify = "药物分类"
  3356. var drug_classify_id int64
  3357. drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
  3358. if len(drug_classify) != 0 {
  3359. _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
  3360. if errcodesClass == gorm.ErrRecordNotFound {
  3361. drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
  3362. dataconfig := models.DictDataconfig{
  3363. ParentId: drugClassifyConfig.ID,
  3364. Module: "system",
  3365. OrgId: orgId,
  3366. Name: drug_classify,
  3367. FieldName: "",
  3368. Value: drugClassConfig.Value + 1,
  3369. CreatedTime: "",
  3370. UpdatedTime: "",
  3371. CreateUserId: adminUser.AdminUser.Id,
  3372. Status: 1,
  3373. Remark: "",
  3374. DeleteIdSystem: 0,
  3375. Title: "",
  3376. Content: "",
  3377. Order: 0,
  3378. Code: "",
  3379. }
  3380. service.CreatedDicConfig(&dataconfig)
  3381. }
  3382. }
  3383. drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
  3384. for _, it := range drugClassList {
  3385. if drug_classify == it.Name {
  3386. drug_classify_id = int64(it.Value)
  3387. }
  3388. }
  3389. drug_dose := goodNameM["drug_dose"].(string)
  3390. if len(drug_dose) == 0 {
  3391. err_log := models.ExportErrLog{
  3392. LogType: 4,
  3393. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3394. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
  3395. Status: 1,
  3396. CreateTime: time.Now().Unix(),
  3397. UpdateTime: time.Now().Unix(),
  3398. ExportTime: time.Now().Unix(),
  3399. }
  3400. service.CreateExportErrLog(&err_log)
  3401. continue
  3402. }
  3403. drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
  3404. drug.DrugDose = drugDoses
  3405. var units = "单位"
  3406. var unit_id int64
  3407. drugDoseUnit := goodNameM["drug_dose_unit"].(string)
  3408. if len(drugDoseUnit) == 0 {
  3409. err_log := models.ExportErrLog{
  3410. LogType: 4,
  3411. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3412. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
  3413. Status: 1,
  3414. CreateTime: time.Now().Unix(),
  3415. UpdateTime: time.Now().Unix(),
  3416. ExportTime: time.Now().Unix(),
  3417. }
  3418. service.CreateExportErrLog(&err_log)
  3419. continue
  3420. }
  3421. dataConfig, _ := service.GetDataConfigIsExist(0, units)
  3422. if len(drugDoseUnit) != 0 {
  3423. _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
  3424. if errcodedataconfig == gorm.ErrRecordNotFound {
  3425. childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
  3426. dataconfig := models.Dataconfig{
  3427. ParentId: dataConfig.ID,
  3428. Module: "hemodialysis",
  3429. OrgId: orgId,
  3430. Name: drugDoseUnit,
  3431. FieldName: "",
  3432. Value: childConfig.Value + 1,
  3433. CreatedTime: "",
  3434. UpdatedTime: "",
  3435. CreateUserId: adminUser.AdminUser.Id,
  3436. Status: 1,
  3437. Remark: "",
  3438. DeleteIdSystem: 0,
  3439. Title: "",
  3440. Content: "",
  3441. Order: 0,
  3442. Code: "",
  3443. FieldType: 0,
  3444. }
  3445. service.CreateDataConfig(&dataconfig)
  3446. }
  3447. }
  3448. list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
  3449. for _, it := range list {
  3450. if drugDoseUnit == it.Name {
  3451. unit_id = int64(it.Value)
  3452. }
  3453. }
  3454. drug.DrugDoseUnit = unit_id
  3455. drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
  3456. manufacturer := goodNameM["manufacturer"].(string)
  3457. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  3458. err_log := models.ExportErrLog{
  3459. LogType: 4,
  3460. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3461. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
  3462. Status: 1,
  3463. CreateTime: time.Now().Unix(),
  3464. UpdateTime: time.Now().Unix(),
  3465. ExportTime: time.Now().Unix(),
  3466. }
  3467. service.CreateExportErrLog(&err_log)
  3468. continue
  3469. }
  3470. if len(manufacturer) != 0 {
  3471. _, errcodema := service.GetManufacturerName(orgId, manufacturer)
  3472. if errcodema == gorm.ErrRecordNotFound {
  3473. manufactur := models.Manufacturer{
  3474. OrgId: orgId,
  3475. Status: 1,
  3476. ManufacturerName: manufacturer,
  3477. Ctime: time.Now().Unix(),
  3478. Creater: adminUser.AdminUser.Id,
  3479. }
  3480. service.CreateManufacturer(&manufactur)
  3481. }
  3482. }
  3483. var manufacturer_id int64
  3484. manufacturList, _ := service.GetAllManufacturerList(orgId)
  3485. for _, it := range manufacturList {
  3486. if manufacturer == it.ManufacturerName {
  3487. manufacturer_id = it.ID
  3488. }
  3489. }
  3490. drug.Manufacturer = manufacturer_id
  3491. dealer := goodNameM["dealer"].(string)
  3492. if len(dealer) != 0 {
  3493. _, errcodesdealer := service.GetDealerByName(orgId, dealer)
  3494. if errcodesdealer == gorm.ErrRecordNotFound {
  3495. dealerconfig := models.Dealer{
  3496. DealerName: dealer,
  3497. Status: 1,
  3498. OrgId: orgId,
  3499. Ctime: time.Now().Unix(),
  3500. Creater: adminUser.AdminUser.Id,
  3501. }
  3502. service.CreateDealer(&dealerconfig)
  3503. }
  3504. }
  3505. var dealer_id int64
  3506. dealerList, _ := service.GetAllDealerList(orgId)
  3507. for _, it := range dealerList {
  3508. if dealer == it.DealerName {
  3509. dealer_id = it.ID
  3510. }
  3511. }
  3512. drug.Dealer = dealer_id
  3513. lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
  3514. drug.LmtUsedFlag = lmt_used_flags
  3515. if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
  3516. utils.ErrorLog("drug_alias")
  3517. return
  3518. }
  3519. drug_alias, _ := goodNameM["drug_alias"].(string)
  3520. drug.DrugAlias = drug_alias
  3521. drug_category := goodNameM["drug_category"].(string)
  3522. var drugCategory = "药品类别"
  3523. var drug_category_id int64
  3524. drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
  3525. if len(drug_category) != 0 {
  3526. _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
  3527. if drugcategoryerrcodes == gorm.ErrRecordNotFound {
  3528. drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
  3529. dataconfig := models.DictDataconfig{
  3530. ParentId: drugCategoryConfig.ID,
  3531. Module: "system",
  3532. OrgId: orgId,
  3533. Name: drug_category,
  3534. FieldName: "",
  3535. Value: drugCategoryConfigSix.Value + 1,
  3536. CreatedTime: "",
  3537. UpdatedTime: "",
  3538. CreateUserId: adminUser.AdminUser.Id,
  3539. Status: 1,
  3540. Remark: "",
  3541. DeleteIdSystem: 0,
  3542. Title: "",
  3543. Content: "",
  3544. Order: 0,
  3545. Code: "",
  3546. }
  3547. service.CreatedDicConfig(&dataconfig)
  3548. }
  3549. }
  3550. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
  3551. fmt.Println("drugCategoryList", drugCategoryList)
  3552. for _, it := range drugCategoryList {
  3553. if drug_category == it.Name {
  3554. drug_category_id = int64(it.Value)
  3555. }
  3556. }
  3557. drug.DrugCategory = drug_category_id
  3558. statistics_category := goodNameM["statistics_category"].(string)
  3559. var statisticsCategory = "统计分类"
  3560. var statistics_category_id int64
  3561. statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3562. if len(statistics_category) != 0 {
  3563. _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
  3564. if errcodestatistc == gorm.ErrRecordNotFound {
  3565. staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
  3566. dataconfig := models.DictDataconfig{
  3567. ParentId: statistcConfig.ID,
  3568. Module: "system",
  3569. OrgId: orgId,
  3570. Name: statistics_category,
  3571. FieldName: "",
  3572. Value: staConfig.Value + 1,
  3573. CreatedTime: "",
  3574. UpdatedTime: "",
  3575. CreateUserId: adminUser.AdminUser.Id,
  3576. Status: 1,
  3577. Remark: "",
  3578. DeleteIdSystem: 0,
  3579. Title: "",
  3580. Content: "",
  3581. Order: 0,
  3582. Code: "",
  3583. }
  3584. service.CreatedDicConfig(&dataconfig)
  3585. }
  3586. }
  3587. statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
  3588. for _, it := range statisticsCategoryList {
  3589. if statistics_category == it.Name {
  3590. statistics_category_id = int64(it.Value)
  3591. }
  3592. }
  3593. drug.StatisticsCategory = statistics_category_id
  3594. number := goodNameM["number"].(string)
  3595. drug.Number = number
  3596. hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
  3597. drug.HospApprFlag = hosp_appr_flag
  3598. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  3599. drug.MedicalInsuranceNumber = medical_insurance_number
  3600. pharmacology_category := goodNameM["pharmacology_category"].(string)
  3601. var pharmacology = "药理分类"
  3602. var pharmacology_category_id int64
  3603. pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
  3604. if len(pharmacology_category) != 0 {
  3605. _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
  3606. if errcodespharmacology == gorm.ErrRecordNotFound {
  3607. dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
  3608. dataconfig := models.DictDataconfig{
  3609. ParentId: pharmacologyConfig.ID,
  3610. Module: "system",
  3611. OrgId: orgId,
  3612. Name: pharmacology_category,
  3613. FieldName: "",
  3614. Value: dicConfig.Value + 1,
  3615. CreatedTime: "",
  3616. UpdatedTime: "",
  3617. CreateUserId: adminUser.AdminUser.Id,
  3618. Status: 1,
  3619. Remark: "",
  3620. DeleteIdSystem: 0,
  3621. Title: "",
  3622. Content: "",
  3623. Order: 0,
  3624. Code: "",
  3625. }
  3626. service.CreatedDicConfig(&dataconfig)
  3627. }
  3628. }
  3629. pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
  3630. for _, it := range pharmacologyList {
  3631. if pharmacology_category == it.Name {
  3632. pharmacology_category_id = int64(it.Value)
  3633. }
  3634. }
  3635. drug.PharmacologyCategory = pharmacology_category_id
  3636. code := goodNameM["code"].(string)
  3637. drug.Code = code
  3638. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  3639. drug.IsSpecialDiseases = is_special_diseases
  3640. is_record := int64(goodNameM["is_record"].(float64))
  3641. drug.IsRecord = is_record
  3642. prescription_mark := int64(goodNameM["prescription_mark"].(float64))
  3643. drug.PrescriptionMark = prescription_mark
  3644. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  3645. drug.SocialSecurityDirectoryCode = social_security_directory_code
  3646. record_date := goodNameM["record_date"].(string)
  3647. timeLayout := "2006-01-02"
  3648. loc, _ := time.LoadLocation("Local")
  3649. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3650. drug.RecordDate = theTime.Unix()
  3651. drug_remark := goodNameM["drug_remark"].(string)
  3652. drug.DrugRemark = drug_remark
  3653. drug_status := goodNameM["drug_status"].(string)
  3654. drug.DrugStatus = drug_status
  3655. limit_remark := goodNameM["limit_remark"].(string)
  3656. drug.LimitRemark = limit_remark
  3657. drug_control := goodNameM["drug_control"].(string)
  3658. var drugControl = "开药控制"
  3659. var drug_control_id int64
  3660. drugContorlConfig, _ := service.GetDrugDataConfig(0, drugControl)
  3661. if len(drug_control) != 0 {
  3662. _, errcodesdrugcontrol := service.IsExistDicConfig(drugContorlConfig.ID, drug_control, orgId)
  3663. if errcodesdrugcontrol == gorm.ErrRecordNotFound {
  3664. drugContorlConfigOne, _ := service.GetLastDicConfig(drugContorlConfig.ID, orgId)
  3665. dataconfig := models.DictDataconfig{
  3666. ParentId: drugContorlConfig.ID,
  3667. Module: "system",
  3668. OrgId: orgId,
  3669. Name: drug_control,
  3670. FieldName: "",
  3671. Value: drugContorlConfigOne.Value + 1,
  3672. CreatedTime: "",
  3673. UpdatedTime: "",
  3674. CreateUserId: adminUser.AdminUser.Id,
  3675. Status: 1,
  3676. Remark: "",
  3677. DeleteIdSystem: 0,
  3678. Title: "",
  3679. Content: "",
  3680. Order: 0,
  3681. Code: "",
  3682. }
  3683. service.CreatedDicConfig(&dataconfig)
  3684. }
  3685. }
  3686. drugContorlList, _ := service.GetParentDataConfig(drugContorlConfig.ID, orgId)
  3687. for _, it := range drugContorlList {
  3688. if drug_control == it.Name {
  3689. drug_control_id = int64(it.Value)
  3690. }
  3691. }
  3692. drug.DrugControl = drug_control_id
  3693. drugList = append(drugList, &drug)
  3694. }
  3695. export_time := time.Now().Unix()
  3696. errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3697. if len(drugList) > 0 {
  3698. for _, item := range drugList {
  3699. goodInfo := models.BaseDrugLib{
  3700. DrugName: item.DrugName,
  3701. DrugAlias: item.DrugAlias,
  3702. DrugSpec: item.DrugSpec,
  3703. DrugType: item.DrugType,
  3704. DrugStockLimit: item.DrugStockLimit,
  3705. DrugOriginPlace: item.DrugOriginPlace,
  3706. DrugDosageForm: item.DrugDosageForm,
  3707. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  3708. MaxUnit: item.MaxUnit,
  3709. MinUnit: item.MinUnit,
  3710. UnitMatrixing: item.UnitMatrixing,
  3711. RetailPrice: item.RetailPrice,
  3712. LastPrice: item.LastPrice,
  3713. DrugClassify: item.DrugClassify,
  3714. Manufacturer: item.Manufacturer,
  3715. Dealer: item.Dealer,
  3716. OrgId: orgId,
  3717. Status: 1,
  3718. Ctime: time.Now().Unix(),
  3719. Pinyin: item.Pinyin,
  3720. Wubi: item.Wubi,
  3721. DrugAliasPinyin: item.DrugAliasPinyin,
  3722. DrugAliasWubi: item.DrugAliasWubi,
  3723. DrugControl: item.DrugControl,
  3724. Number: item.Number,
  3725. HospApprFlag: item.HospApprFlag,
  3726. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  3727. PharmacologyCategory: item.PharmacologyCategory,
  3728. StatisticsCategory: item.StatisticsCategory,
  3729. Code: item.Code,
  3730. IsSpecialDiseases: item.IsSpecialDiseases,
  3731. IsRecord: item.IsRecord,
  3732. PrescriptionMark: item.PrescriptionMark,
  3733. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3734. RecordDate: item.RecordDate,
  3735. DrugRemark: item.DrugRemark,
  3736. DrugStatus: item.DrugStatus,
  3737. LimitRemark: item.LimitRemark,
  3738. DrugCategory: item.DrugCategory,
  3739. DrugDose: item.DrugDose,
  3740. DrugDoseUnit: item.DrugDoseUnit,
  3741. LmtUsedFlag: item.LmtUsedFlag,
  3742. DrugDay: item.DrugDay,
  3743. DeliveryWay: item.DeliveryWay,
  3744. ExecutionFrequency: item.ExecutionFrequency,
  3745. DoseUnit: item.DoseUnit,
  3746. }
  3747. //查询同种药品同种规格是否存在
  3748. _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.MaxUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
  3749. if drugerror == gorm.ErrRecordNotFound {
  3750. service.CreateDrugsInfomation(&goodInfo)
  3751. } else if drugerror == nil {
  3752. service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
  3753. }
  3754. log := models.ExportLog{
  3755. LogType: 4,
  3756. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3757. TotalNum: int64(len(total_goods)),
  3758. FailNum: int64(len(errLogs)),
  3759. SuccessNum: int64(len(drugList)),
  3760. CreateTime: time.Now().Unix(),
  3761. UpdateTime: time.Now().Unix(),
  3762. ExportTime: export_time,
  3763. Status: 1,
  3764. }
  3765. service.CreateExportLog(&log)
  3766. this.ServeSuccessJSON(map[string]interface{}{
  3767. "msg": "导入成功",
  3768. "total_num": len(total_goods),
  3769. "success_num": len(drugList),
  3770. "fail_num": int64(len(errLogs)),
  3771. })
  3772. }
  3773. } else {
  3774. log := models.ExportLog{
  3775. LogType: 4,
  3776. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3777. TotalNum: int64(len(total_goods)),
  3778. FailNum: int64(len(errLogs)),
  3779. SuccessNum: int64(len(drugList)),
  3780. CreateTime: time.Now().Unix(),
  3781. UpdateTime: time.Now().Unix(),
  3782. ExportTime: export_time,
  3783. Status: 1,
  3784. }
  3785. service.CreateExportLog(&log)
  3786. this.ServeSuccessJSON(map[string]interface{}{
  3787. "msg": "导入成功",
  3788. "total_num": len(total_goods),
  3789. "success_num": len(drugList),
  3790. "fail_num": int64(len(errLogs)),
  3791. })
  3792. }
  3793. }
  3794. func (this *StockManagerApiController) GetInitializtion() {
  3795. orgId := this.GetAdminUserInfo().CurrentOrgId
  3796. var drugCategory = "药品类别"
  3797. var drugType = "药品类型"
  3798. var drugDosageForm = "药品剂型"
  3799. var medicalInsuranceLevel = "医保等级"
  3800. var drugControl = "开药控制"
  3801. var drugClassify = "药物分类"
  3802. var statisticsCategory = "统计分类"
  3803. var pharmacologyCategory = "药理分类"
  3804. var goodKind = "耗材种类"
  3805. var tubeColor = "试管颜色"
  3806. var costClassify = "费用类别"
  3807. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3808. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3809. drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
  3810. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
  3811. drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
  3812. drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
  3813. medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
  3814. medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
  3815. drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
  3816. drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
  3817. drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
  3818. drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
  3819. statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3820. statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
  3821. pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
  3822. pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
  3823. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  3824. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
  3825. tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
  3826. tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
  3827. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  3828. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
  3829. this.ServeSuccessJSON(map[string]interface{}{
  3830. "drugCategoryList": drugCategoryList,
  3831. "drugTypeList": drugTypeList,
  3832. "drugDosageFormList": drugDosageFormList,
  3833. "medicalInsuranceLevelList": medicalInsuranceLevelList,
  3834. "drugControlList": drugControlList,
  3835. "drugClassifyList": drugClassifyList,
  3836. "statisticsCategoryList": statisticsCategoryList,
  3837. "pharmacologyCategoryList": pharmacologyCategoryList,
  3838. "goodKindList": goodKindList,
  3839. "tubeColorList": tubeColorList,
  3840. "costClassifyList": costClassifyList,
  3841. })
  3842. }
  3843. func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
  3844. adminUserInfo := this.GetAdminUserInfo()
  3845. orgId := adminUserInfo.CurrentOrgId
  3846. list, _ := service.GetWarehouseOrderInfoList(orgId)
  3847. this.ServeSuccessJSON(map[string]interface{}{
  3848. "list": list,
  3849. })
  3850. }
  3851. func (this *StockManagerApiController) PostSearchGoodList() {
  3852. keyword := this.GetString("keyword")
  3853. adminUserInfo := this.GetAdminUserInfo()
  3854. orgId := adminUserInfo.CurrentOrgId
  3855. list, _ := service.GetSearchGoodList(keyword, orgId)
  3856. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3857. dealerList, _ := service.GetAllDealerList(orgId)
  3858. this.ServeSuccessJSON(map[string]interface{}{
  3859. "list": list,
  3860. "manufacturerList": manufacturerList,
  3861. "dealerList": dealerList,
  3862. })
  3863. }
  3864. func (this *StockManagerApiController) GetAllStockList() {
  3865. page, _ := this.GetInt64("page", -1)
  3866. limit, _ := this.GetInt64("limit", -1)
  3867. start_time := this.GetString("start_time")
  3868. end_time := this.GetString("end_time")
  3869. types, _ := this.GetInt64("type", 0)
  3870. keywords := this.GetString("keywords")
  3871. timeLayout := "2006-01-02"
  3872. loc, _ := time.LoadLocation("Local")
  3873. var startTime int64
  3874. if len(start_time) > 0 {
  3875. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3876. if err != nil {
  3877. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3878. return
  3879. }
  3880. startTime = theTime.Unix()
  3881. }
  3882. var endTime int64
  3883. if len(end_time) > 0 {
  3884. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3885. if err != nil {
  3886. utils.ErrorLog(err.Error())
  3887. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3888. return
  3889. }
  3890. endTime = theTime.Unix()
  3891. }
  3892. adminUserInfo := this.GetAdminUserInfo()
  3893. orgId := adminUserInfo.CurrentOrgId
  3894. list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId)
  3895. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3896. this.ServeSuccessJSON(map[string]interface{}{
  3897. "list": list,
  3898. "total": total,
  3899. "manufacturerList": manufacturerList,
  3900. })
  3901. }
  3902. func (this *StockManagerApiController) GetStockListById() {
  3903. id, _ := this.GetInt64("id")
  3904. adminUserInfo := this.GetAdminUserInfo()
  3905. orgId := adminUserInfo.CurrentOrgId
  3906. limit, _ := this.GetInt64("limit")
  3907. page, _ := this.GetInt64("page")
  3908. timeLayout := "2006-01-02"
  3909. loc, _ := time.LoadLocation("Local")
  3910. start_time := this.GetString("start_time")
  3911. end_time := this.GetString("end_time")
  3912. var startTime int64
  3913. if len(start_time) > 0 {
  3914. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3915. if err != nil {
  3916. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3917. return
  3918. }
  3919. startTime = theTime.Unix()
  3920. }
  3921. var endTime int64
  3922. if len(end_time) > 0 {
  3923. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3924. if err != nil {
  3925. utils.ErrorLog(err.Error())
  3926. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3927. return
  3928. }
  3929. endTime = theTime.Unix()
  3930. }
  3931. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3932. list, total, _ := service.GetStockListById(id, orgId, limit, page, startTime, endTime)
  3933. this.ServeSuccessJSON(map[string]interface{}{
  3934. "list": list,
  3935. "total": total,
  3936. "manufacturerList": manufacturerList,
  3937. })
  3938. }
  3939. func (this *StockManagerApiController) GetStockOutList() {
  3940. id, _ := this.GetInt64("id")
  3941. adminUserInfo := this.GetAdminUserInfo()
  3942. orgId := adminUserInfo.CurrentOrgId
  3943. limit, _ := this.GetInt64("limit")
  3944. page, _ := this.GetInt64("page")
  3945. timeLayout := "2006-01-02"
  3946. loc, _ := time.LoadLocation("Local")
  3947. start_time := this.GetString("start_time")
  3948. end_time := this.GetString("end_time")
  3949. is_sys, _ := this.GetInt64("is_sys")
  3950. var startTime int64
  3951. if len(start_time) > 0 {
  3952. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3953. if err != nil {
  3954. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3955. return
  3956. }
  3957. startTime = theTime.Unix()
  3958. }
  3959. var endTime int64
  3960. if len(end_time) > 0 {
  3961. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3962. if err != nil {
  3963. utils.ErrorLog(err.Error())
  3964. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3965. return
  3966. }
  3967. endTime = theTime.Unix()
  3968. }
  3969. outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
  3970. this.ServeSuccessJSON(map[string]interface{}{
  3971. "outList": outList,
  3972. "total": total,
  3973. })
  3974. }
  3975. func (this *StockManagerApiController) GetStockDrugCount() {
  3976. adminUserInfo := this.GetAdminUserInfo()
  3977. orgId := adminUserInfo.CurrentOrgId
  3978. fmt.Println(orgId)
  3979. timeLayout := "2006-01-02"
  3980. loc, _ := time.LoadLocation("Local")
  3981. start_time := this.GetString("start_time")
  3982. end_time := this.GetString("end_time")
  3983. var startTime int64
  3984. if len(start_time) > 0 {
  3985. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3986. if err != nil {
  3987. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3988. return
  3989. }
  3990. startTime = theTime.Unix()
  3991. }
  3992. var endTime int64
  3993. if len(end_time) > 0 {
  3994. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3995. if err != nil {
  3996. utils.ErrorLog(err.Error())
  3997. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3998. return
  3999. }
  4000. endTime = theTime.Unix()
  4001. }
  4002. count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
  4003. outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
  4004. autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
  4005. totalCount, _ := service.GetCancelOutTotalCount(startTime, endTime, orgId)
  4006. this.ServeSuccessJSON(map[string]interface{}{
  4007. "count": count,
  4008. "outList": outList,
  4009. "autoCount": autoCount,
  4010. "totalCount": totalCount,
  4011. })
  4012. }
  4013. func (this *StockManagerApiController) GetOrderDetialByOrderId() {
  4014. ids := this.GetString("id")
  4015. idsArray := strings.Split(ids, ",")
  4016. orgId := this.GetAdminUserInfo().CurrentOrgId
  4017. list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
  4018. this.ServeSuccessJSON(map[string]interface{}{
  4019. "list": list,
  4020. })
  4021. }
  4022. func (this *StockManagerApiController) GetOrderDetailById() {
  4023. id, _ := this.GetInt64("id")
  4024. good_id, _ := this.GetInt64("good_id")
  4025. record_time, _ := this.GetInt64("record_time")
  4026. orgId := this.GetAdminUserInfo().CurrentOrgId
  4027. //自动出库
  4028. userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
  4029. //手动出库
  4030. info, _ := service.GetWarehouseOutInfoById(id, good_id)
  4031. stockFlowList, err := service.GetStockFlowBatchNumberOne(id, good_id)
  4032. if err == nil {
  4033. this.ServeSuccessJSON(map[string]interface{}{
  4034. "list": userDetails,
  4035. "total": total,
  4036. "info": info,
  4037. "stockFlowList": stockFlowList,
  4038. })
  4039. } else {
  4040. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4041. return
  4042. }
  4043. }
  4044. func (this *StockManagerApiController) GetSingleOutOrderDetail() {
  4045. id, _ := this.GetInt64("id", 0)
  4046. orgId := this.GetAdminUserInfo().CurrentOrgId
  4047. warehouseOutInfo, _ := service.GetOrderDetialByOrderId(id, orgId)
  4048. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4049. dealerList, _ := service.GetAllDealerList(orgId)
  4050. goodType, _ := service.GetAllGoodType(orgId)
  4051. this.ServeSuccessJSON(map[string]interface{}{
  4052. "list": warehouseOutInfo,
  4053. "dealerList": dealerList,
  4054. "manufacturerList": manufacturerList,
  4055. "goodType": goodType,
  4056. })
  4057. }
  4058. func (this *StockManagerApiController) GetExprotStockList() {
  4059. adminUserInfo := this.GetAdminUserInfo()
  4060. orgId := adminUserInfo.CurrentOrgId
  4061. timeLayout := "2006-01-02"
  4062. loc, _ := time.LoadLocation("Local")
  4063. start_time := this.GetString("start_time")
  4064. end_time := this.GetString("end_time")
  4065. idArray := this.GetString("id")
  4066. ids := strings.Split(idArray, ",")
  4067. var startTime int64
  4068. if len(start_time) > 0 {
  4069. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4070. if err != nil {
  4071. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4072. return
  4073. }
  4074. startTime = theTime.Unix()
  4075. }
  4076. var endTime int64
  4077. if len(end_time) > 0 {
  4078. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4079. if err != nil {
  4080. utils.ErrorLog(err.Error())
  4081. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4082. return
  4083. }
  4084. endTime = theTime.Unix()
  4085. }
  4086. fmt.Println("ids2222222222222222", ids)
  4087. list, _ := service.GetExprotStockList(orgId, ids, startTime, endTime)
  4088. this.ServeSuccessJSON(map[string]interface{}{
  4089. "list": list,
  4090. })
  4091. }
  4092. func (this *StockManagerApiController) GetOutExprotList() {
  4093. adminUserInfo := this.GetAdminUserInfo()
  4094. orgId := adminUserInfo.CurrentOrgId
  4095. timeLayout := "2006-01-02"
  4096. loc, _ := time.LoadLocation("Local")
  4097. start_time := this.GetString("start_time")
  4098. end_time := this.GetString("end_time")
  4099. idArray := this.GetString("id")
  4100. ids := strings.Split(idArray, ",")
  4101. fmt.Println("ids2222222222", ids)
  4102. var startTime int64
  4103. if len(start_time) > 0 {
  4104. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4105. if err != nil {
  4106. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4107. return
  4108. }
  4109. startTime = theTime.Unix()
  4110. }
  4111. var endTime int64
  4112. if len(end_time) > 0 {
  4113. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4114. if err != nil {
  4115. utils.ErrorLog(err.Error())
  4116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4117. return
  4118. }
  4119. endTime = theTime.Unix()
  4120. }
  4121. list, _ := service.GetOutExprotList(orgId, ids, startTime, endTime)
  4122. outCount, _ := service.GetOutStockTotalCountOne(startTime, endTime, orgId)
  4123. this.ServeSuccessJSON(map[string]interface{}{
  4124. "list": list,
  4125. "count": outCount,
  4126. })
  4127. }
  4128. func (this *StockManagerApiController) GetSingleCancelOrder() {
  4129. id, _ := this.GetInt64("id")
  4130. adminUserInfo := this.GetAdminUserInfo()
  4131. orgId := adminUserInfo.CurrentOrgId
  4132. order, _ := service.GetSingleCancelOrder(id, orgId)
  4133. this.ServeSuccessJSON(map[string]interface{}{
  4134. "list": order,
  4135. })
  4136. }
  4137. func (this *StockManagerApiController) GetCancelStockOrderPrint() {
  4138. id := this.GetString("id")
  4139. idStr := strings.Split(id, ",")
  4140. orgId := this.GetAdminUserInfo().CurrentOrgId
  4141. list, _ := service.GetCancelStockOrderPrintOne(idStr, orgId)
  4142. this.ServeSuccessJSON(map[string]interface{}{
  4143. "list": list,
  4144. })
  4145. }
  4146. func (this *StockManagerApiController) GetStockBatchNumber() {
  4147. id, _ := this.GetInt64("id")
  4148. orgId := this.GetAdminUserInfo().CurrentOrgId
  4149. list, _ := service.GetStockBatchNumber(id, orgId)
  4150. this.ServeSuccessJSON(map[string]interface{}{
  4151. "list": list,
  4152. })
  4153. }
  4154. func (this *StockManagerApiController) GetStockFlow() {
  4155. limit, _ := this.GetInt64("limit")
  4156. page, _ := this.GetInt64("page")
  4157. good_id, _ := this.GetInt64("good_id")
  4158. consumable_type, _ := this.GetInt64("is_sys")
  4159. adminUserInfo := this.GetAdminUserInfo()
  4160. orgId := adminUserInfo.CurrentOrgId
  4161. timeLayout := "2006-01-02"
  4162. loc, _ := time.LoadLocation("Local")
  4163. start_time := this.GetString("start_time")
  4164. end_time := this.GetString("end_time")
  4165. var startTime int64
  4166. if len(start_time) > 0 {
  4167. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4168. if err != nil {
  4169. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4170. return
  4171. }
  4172. startTime = theTime.Unix()
  4173. }
  4174. var endTime int64
  4175. if len(end_time) > 0 {
  4176. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4177. if err != nil {
  4178. utils.ErrorLog(err.Error())
  4179. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4180. return
  4181. }
  4182. endTime = theTime.Unix()
  4183. }
  4184. list, total, _ := service.GetStockFlowList(limit, page, consumable_type, orgId, startTime, endTime, good_id)
  4185. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4186. this.ServeSuccessJSON(map[string]interface{}{
  4187. "list": list,
  4188. "total": total,
  4189. "manufacturerList": manufacturerList,
  4190. })
  4191. }
  4192. func (this *StockManagerApiController) GetCancelExportList() {
  4193. adminUserInfo := this.GetAdminUserInfo()
  4194. orgId := adminUserInfo.CurrentOrgId
  4195. timeLayout := "2006-01-02"
  4196. loc, _ := time.LoadLocation("Local")
  4197. start_time := this.GetString("start_time")
  4198. end_time := this.GetString("end_time")
  4199. idArray := this.GetString("order_id")
  4200. fmt.Println("232323232323232232", idArray)
  4201. ids := strings.Split(idArray, ",")
  4202. var startTime int64
  4203. if len(start_time) > 0 {
  4204. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4205. if err != nil {
  4206. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4207. return
  4208. }
  4209. startTime = theTime.Unix()
  4210. }
  4211. var endTime int64
  4212. if len(end_time) > 0 {
  4213. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4214. if err != nil {
  4215. utils.ErrorLog(err.Error())
  4216. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4217. return
  4218. }
  4219. endTime = theTime.Unix()
  4220. }
  4221. list, _ := service.GetCancelExportList(startTime, endTime, ids, orgId)
  4222. this.ServeSuccessJSON(map[string]interface{}{
  4223. "list": list,
  4224. })
  4225. }
  4226. func (this *StockManagerApiController) GetSearchGoodWarehouseList() {
  4227. keyword := this.GetString("keyword")
  4228. orgId := this.GetAdminUserInfo().CurrentOrgId
  4229. list, _ := service.GetSearchGoodWarehouseList(keyword, orgId)
  4230. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4231. dealerList, _ := service.GetAllDealerList(orgId)
  4232. this.ServeSuccessJSON(map[string]interface{}{
  4233. "list": list,
  4234. "manufacturerList": manufacturerList,
  4235. "dealerList": dealerList,
  4236. })
  4237. }
  4238. func (this *StockManagerApiController) SaveAdjuestPrice() {
  4239. timeLayout := "2006-01-02"
  4240. loc, _ := time.LoadLocation("Local")
  4241. dataBody := make(map[string]interface{}, 0)
  4242. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4243. if err != nil {
  4244. utils.ErrorLog(err.Error())
  4245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4246. return
  4247. }
  4248. tableData, _ := dataBody["tableData"].([]interface{})
  4249. if len(tableData) > 0 {
  4250. for _, item := range tableData {
  4251. items := item.(map[string]interface{})
  4252. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4253. utils.ErrorLog("good_name")
  4254. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4255. return
  4256. }
  4257. good_name := items["good_name"].(string)
  4258. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4259. utils.ErrorLog("good_name")
  4260. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4261. return
  4262. }
  4263. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4264. utils.ErrorLog("packing_price")
  4265. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4266. return
  4267. }
  4268. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4269. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4270. utils.ErrorLog("warehousing_order")
  4271. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4272. return
  4273. }
  4274. warehousing_order := items["warehousing_order"].(string)
  4275. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4276. utils.ErrorLog("license_number")
  4277. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4278. return
  4279. }
  4280. license_number := items["license_number"].(string)
  4281. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4282. utils.ErrorLog("dealer")
  4283. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4284. return
  4285. }
  4286. dealer := items["dealer"].(string)
  4287. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4288. utils.ErrorLog("manufacturer")
  4289. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4290. return
  4291. }
  4292. manufacturer := items["manufacturer"].(string)
  4293. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4294. utils.ErrorLog("specification_name")
  4295. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4296. return
  4297. }
  4298. specification_name := items["specification_name"].(string)
  4299. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4300. utils.ErrorLog("remark")
  4301. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4302. return
  4303. }
  4304. remark := items["remark"].(string)
  4305. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4306. utils.ErrorLog("warehousing_unit")
  4307. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4308. return
  4309. }
  4310. warehousing_unit := items["warehousing_unit"].(string)
  4311. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4312. utils.ErrorLog("buy_price")
  4313. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4314. return
  4315. }
  4316. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4317. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4318. utils.ErrorLog("count")
  4319. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4320. return
  4321. }
  4322. count := int64(items["count"].(float64))
  4323. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  4324. utils.ErrorLog("new_price")
  4325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4326. return
  4327. }
  4328. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  4329. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4330. utils.ErrorLog("good_id")
  4331. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4332. return
  4333. }
  4334. good_id := int64(items["good_id"].(float64))
  4335. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4336. utils.ErrorLog("start_time")
  4337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4338. return
  4339. }
  4340. var startTime int64
  4341. start_time := items["start_time"].(string)
  4342. if len(start_time) > 0 {
  4343. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4344. if err != nil {
  4345. fmt.Println(err)
  4346. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4347. return
  4348. }
  4349. startTime = theTime.Unix()
  4350. }
  4351. orgId := this.GetAdminUserInfo().CurrentOrgId
  4352. adjustprice := models.XtStockAdjustPrice{
  4353. GoodName: good_name,
  4354. SpecificationName: specification_name,
  4355. WarehousingUnit: warehousing_unit,
  4356. Count: count,
  4357. BuyPrice: buy_price,
  4358. PackingPrice: packing_price,
  4359. NewPrice: new_price,
  4360. Manufacturer: manufacturer,
  4361. Dealer: dealer,
  4362. Remark: remark,
  4363. GoodId: good_id,
  4364. UserOrgId: orgId,
  4365. Ctime: time.Now().Unix(),
  4366. Mtime: 0,
  4367. Status: 1,
  4368. WarehousingOrder: warehousing_order,
  4369. LicenseNumber: license_number,
  4370. StartTime: startTime,
  4371. Creater: this.GetAdminUserInfo().AdminUser.Id,
  4372. CheckerStatus: 2,
  4373. }
  4374. service.CreateAdjustPrice(&adjustprice)
  4375. }
  4376. }
  4377. this.ServeSuccessJSON(map[string]interface{}{
  4378. "msg": "保存成功!",
  4379. })
  4380. }
  4381. func (this *StockManagerApiController) GetAllStockPrice() {
  4382. timeLayout := "2006-01-02"
  4383. loc, _ := time.LoadLocation("Local")
  4384. dataBody := make(map[string]interface{}, 0)
  4385. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4386. fmt.Println(err)
  4387. orgId := this.GetAdminUserInfo().CurrentOrgId
  4388. keyword := this.GetString("keyword")
  4389. start_time := this.GetString("start_time")
  4390. end_time := this.GetString("end_time")
  4391. limit, _ := this.GetInt64("limit")
  4392. page, _ := this.GetInt64("page")
  4393. var startTime int64
  4394. if len(start_time) > 0 {
  4395. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4396. if err != nil {
  4397. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4398. return
  4399. }
  4400. startTime = theTime.Unix()
  4401. }
  4402. var endTime int64
  4403. if len(end_time) > 0 {
  4404. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4405. if err != nil {
  4406. utils.ErrorLog(err.Error())
  4407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4408. return
  4409. }
  4410. endTime = theTime.Unix()
  4411. }
  4412. list, total, _ := service.GetAllStockPrice(orgId, startTime, endTime, keyword, limit, page)
  4413. doctor, _ := service.GetAllDoctorThree(orgId)
  4414. this.ServeSuccessJSON(map[string]interface{}{
  4415. "list": list,
  4416. "doctor": doctor,
  4417. "total": total,
  4418. })
  4419. }
  4420. func (this *StockManagerApiController) SaveCheckPrice() {
  4421. timeLayout := "2006-01-02"
  4422. loc, _ := time.LoadLocation("Local")
  4423. dataBody := make(map[string]interface{}, 0)
  4424. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4425. fmt.Println(err)
  4426. idstr := this.GetString("ids")
  4427. ids := strings.Split(idstr, ",")
  4428. check_time := this.GetString("check_time")
  4429. var checkTime int64
  4430. if len(check_time) > 0 {
  4431. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  4432. if err != nil {
  4433. fmt.Println(err)
  4434. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4435. return
  4436. }
  4437. checkTime = theTime.Unix()
  4438. }
  4439. checker, _ := this.GetInt64("checker")
  4440. adjustPrice := models.XtStockAdjustPrice{
  4441. Checker: checker,
  4442. CheckerStatus: 1,
  4443. CheckerTime: checkTime,
  4444. }
  4445. err = service.UpdateAdjustPrice(ids, adjustPrice)
  4446. fmt.Println(err)
  4447. list, _ := service.GetAdjustCheckPriceList(ids)
  4448. fmt.Println("list2333223323232323232323", list)
  4449. for _, item := range list {
  4450. info := models.GoodInfo{
  4451. PackingPrice: item.NewPrice,
  4452. BuyPrice: item.NewPrice,
  4453. }
  4454. err = service.UpdateAdjustCheckPrice(&info, item.GoodId)
  4455. fmt.Println(err)
  4456. }
  4457. this.ServeSuccessJSON(map[string]interface{}{
  4458. "adjustPrice": adjustPrice,
  4459. })
  4460. }
  4461. func (this *StockManagerApiController) GetAdjustPriceById() {
  4462. ids := this.GetString("ids")
  4463. fmt.Println("ids23232233223233232", ids)
  4464. splitIds := strings.Split(ids, ",")
  4465. list, _ := service.GetAdjustPricebyIdOne(splitIds)
  4466. fmt.Println("list2322322323", list)
  4467. this.ServeSuccessJSON(map[string]interface{}{
  4468. "list": list,
  4469. })
  4470. }
  4471. func (this *StockManagerApiController) SaveReportStock() {
  4472. timeLayout := "2006-01-02"
  4473. loc, _ := time.LoadLocation("Local")
  4474. dataBody := make(map[string]interface{}, 0)
  4475. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4476. if err != nil {
  4477. utils.ErrorLog(err.Error())
  4478. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4479. return
  4480. }
  4481. tableData, _ := dataBody["tableData"].([]interface{})
  4482. if len(tableData) > 0 {
  4483. for _, item := range tableData {
  4484. items := item.(map[string]interface{})
  4485. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4486. utils.ErrorLog("good_name")
  4487. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4488. return
  4489. }
  4490. good_name := items["good_name"].(string)
  4491. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4492. utils.ErrorLog("good_name")
  4493. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4494. return
  4495. }
  4496. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4497. utils.ErrorLog("packing_price")
  4498. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4499. return
  4500. }
  4501. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4502. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4503. utils.ErrorLog("warehousing_order")
  4504. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4505. return
  4506. }
  4507. warehousing_order := items["warehousing_order"].(string)
  4508. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4509. utils.ErrorLog("license_number")
  4510. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4511. return
  4512. }
  4513. license_number := items["license_number"].(string)
  4514. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4515. utils.ErrorLog("dealer")
  4516. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4517. return
  4518. }
  4519. dealer := items["dealer"].(string)
  4520. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4521. utils.ErrorLog("manufacturer")
  4522. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4523. return
  4524. }
  4525. manufacturer := items["manufacturer"].(string)
  4526. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4527. utils.ErrorLog("specification_name")
  4528. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4529. return
  4530. }
  4531. specification_name := items["specification_name"].(string)
  4532. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4533. utils.ErrorLog("remark")
  4534. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4535. return
  4536. }
  4537. remark := items["remark"].(string)
  4538. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4539. utils.ErrorLog("warehousing_unit")
  4540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4541. return
  4542. }
  4543. warehousing_unit := items["warehousing_unit"].(string)
  4544. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4545. utils.ErrorLog("buy_price")
  4546. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4547. return
  4548. }
  4549. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4550. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4551. utils.ErrorLog("count")
  4552. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4553. return
  4554. }
  4555. count := int64(items["count"].(float64))
  4556. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4557. utils.ErrorLog("good_id")
  4558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4559. return
  4560. }
  4561. good_id := int64(items["good_id"].(float64))
  4562. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4563. utils.ErrorLog("start_time")
  4564. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4565. return
  4566. }
  4567. var startTime int64
  4568. start_time := items["start_time"].(string)
  4569. if len(start_time) > 0 {
  4570. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4571. if err != nil {
  4572. fmt.Println(err)
  4573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4574. return
  4575. }
  4576. startTime = theTime.Unix()
  4577. }
  4578. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  4579. utils.ErrorLog("number")
  4580. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4581. return
  4582. }
  4583. number := items["number"].(string)
  4584. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  4585. utils.ErrorLog("warehousing_info_id")
  4586. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4587. return
  4588. }
  4589. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  4590. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  4591. utils.ErrorLog("expiry_date")
  4592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4593. return
  4594. }
  4595. expiry_date := int64(items["expiry_date"].(float64))
  4596. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  4597. utils.ErrorLog("product_date")
  4598. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4599. return
  4600. }
  4601. product_date := int64(items["product_date"].(float64))
  4602. orgId := this.GetAdminUserInfo().CurrentOrgId
  4603. Creater := this.GetAdminUserInfo().AdminUser.Id
  4604. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  4605. utils.ErrorLog("total")
  4606. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4607. return
  4608. }
  4609. total := int64(items["total"].(float64))
  4610. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  4611. utils.ErrorLog("good_origin_place")
  4612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4613. return
  4614. }
  4615. good_origin_place := items["good_origin_place"].(string)
  4616. reportPrice := models.XtStockReportPrice{
  4617. GoodName: good_name,
  4618. SpecificationName: specification_name,
  4619. WarehousingUnit: warehousing_unit,
  4620. Count: count,
  4621. BuyPrice: buy_price,
  4622. PackingPrice: packing_price,
  4623. Manufacturer: manufacturer,
  4624. Dealer: dealer,
  4625. Remark: remark,
  4626. GoodId: good_id,
  4627. UserOrgId: orgId,
  4628. Ctime: time.Now().Unix(),
  4629. Mtime: 0,
  4630. Status: 1,
  4631. WarehousingOrder: warehousing_order,
  4632. LicenseNumber: license_number,
  4633. StartTime: startTime,
  4634. Creater: Creater,
  4635. Checker: 0,
  4636. CheckerStatus: 2,
  4637. CheckerTime: 0,
  4638. Number: number,
  4639. WarehousingInfoId: warehousing_info_id,
  4640. ExpiryDate: expiry_date,
  4641. ProductDate: product_date,
  4642. Total: total,
  4643. GoodOriginPlace: good_origin_place,
  4644. }
  4645. err := service.CreateReportPrice(&reportPrice)
  4646. fmt.Println(err)
  4647. }
  4648. }
  4649. this.ServeSuccessJSON(map[string]interface{}{
  4650. "msg": "保存成功!",
  4651. })
  4652. }
  4653. func (this *StockManagerApiController) GetReportStockList() {
  4654. timeLayout := "2006-01-02"
  4655. loc, _ := time.LoadLocation("Local")
  4656. start_time := this.GetString("start_time")
  4657. end_time := this.GetString("end_time")
  4658. page, _ := this.GetInt64("page")
  4659. limit, _ := this.GetInt64("limit")
  4660. var startTime int64
  4661. if len(start_time) > 0 {
  4662. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4663. if err != nil {
  4664. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4665. return
  4666. }
  4667. startTime = theTime.Unix()
  4668. fmt.Println("开始时间", startTime)
  4669. }
  4670. var endTime int64
  4671. if len(end_time) > 0 {
  4672. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4673. if err != nil {
  4674. utils.ErrorLog(err.Error())
  4675. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4676. return
  4677. }
  4678. endTime = theTime.Unix()
  4679. }
  4680. orgId := this.GetAdminUserInfo().CurrentOrgId
  4681. keyword := this.GetString("keyword")
  4682. fmt.Println("startTime", startTime, "endTime", endTime)
  4683. //list, total, _ := service.GetReportStockList(startTime, endTime, orgId, keyword, page, limit)
  4684. list, total, _ := service.GetStockDamagedList(orgId, keyword, page, limit)
  4685. damageList, _ := service.GetStockDamagedCount(orgId)
  4686. doctorlist, _ := service.GetAllDoctorThree(orgId)
  4687. this.ServeSuccessJSON(map[string]interface{}{
  4688. "list": list,
  4689. "total": total,
  4690. "doctorlist": doctorlist,
  4691. "damageList": damageList,
  4692. })
  4693. }
  4694. func (this *StockManagerApiController) SaveCheckDamage() {
  4695. timeLayout := "2006-01-02"
  4696. loc, _ := time.LoadLocation("Local")
  4697. idstr := this.GetString("ids")
  4698. ids := strings.Split(idstr, ",")
  4699. check_time := this.GetString("check_time")
  4700. var checkTime int64
  4701. if len(check_time) > 0 {
  4702. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  4703. if err != nil {
  4704. fmt.Println(err)
  4705. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4706. return
  4707. }
  4708. checkTime = theTime.Unix()
  4709. }
  4710. checker, _ := this.GetInt64("checker")
  4711. reportprice := models.XtStockReportPrice{
  4712. Checker: checker,
  4713. CheckerStatus: 1,
  4714. CheckerTime: checkTime,
  4715. }
  4716. err := service.UpdateCheckDamage(ids, reportprice)
  4717. fmt.Println(err)
  4718. //获取当前核对的数据
  4719. list, _ := service.GetCheckDamageList(ids)
  4720. ctime := time.Now().Unix()
  4721. adminUserInfo := this.GetAdminUserInfo()
  4722. timeStr := time.Now().Format("2006-01-02")
  4723. timeArr := strings.Split(timeStr, "-")
  4724. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  4725. total = total + 1
  4726. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4727. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4728. number = number + total
  4729. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4730. operation_time := time.Now().Unix()
  4731. creater := adminUserInfo.AdminUser.Id
  4732. warehouseOut := models.WarehouseOut{
  4733. WarehouseOutOrderNumber: warehousing_out_order,
  4734. OperationTime: operation_time,
  4735. OrgId: adminUserInfo.CurrentOrgId,
  4736. Creater: creater,
  4737. Ctime: ctime,
  4738. Status: 1,
  4739. WarehouseOutTime: ctime,
  4740. Type: 1,
  4741. }
  4742. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  4743. if errcodes == gorm.ErrRecordNotFound {
  4744. service.AddSigleWarehouseOut(&warehouseOut)
  4745. }
  4746. out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
  4747. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  4748. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  4749. var manufacturer_id int64
  4750. var dealer_id int64
  4751. for _, item := range list {
  4752. for _, it := range manufacturerList {
  4753. if item.Manufacturer == it.ManufacturerName {
  4754. manufacturer_id = it.ID
  4755. }
  4756. }
  4757. for _, its := range dealerList {
  4758. if item.Dealer == its.DealerName {
  4759. dealer_id = its.ID
  4760. }
  4761. }
  4762. goodinfo, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4763. //插入出库单
  4764. warehouseOutInfo := &models.WarehouseOutInfo{
  4765. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4766. WarehouseOutId: out.ID,
  4767. GoodId: item.GoodId,
  4768. Count: item.Count,
  4769. Price: item.PackingPrice,
  4770. Status: 1,
  4771. Ctime: ctime,
  4772. Remark: item.Remark,
  4773. OrgId: adminUserInfo.CurrentOrgId,
  4774. Type: 2,
  4775. Manufacturer: manufacturer_id,
  4776. Number: item.Number,
  4777. ExpiryDate: item.ExpiryDate,
  4778. ProductDate: item.ProductDate,
  4779. Dealer: dealer_id,
  4780. LicenseNumber: item.LicenseNumber,
  4781. GoodTypeId: goodinfo.GoodTypeId,
  4782. }
  4783. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4784. fmt.Println("99999999999999", errOne)
  4785. //更改库存
  4786. info, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  4787. warehousingInfo := models.WarehousingInfo{
  4788. StockCount: info.StockCount - item.Count,
  4789. }
  4790. errOne = service.UpdateGoodWarehouseInfo(item.WarehousingInfoId, warehousingInfo)
  4791. fmt.Println(errOne)
  4792. flow := models.VmStockFlow{
  4793. WarehousingId: 0,
  4794. GoodId: item.GoodId,
  4795. Number: item.Number,
  4796. LicenseNumber: item.LicenseNumber,
  4797. Count: item.Count,
  4798. UserOrgId: adminUserInfo.CurrentOrgId,
  4799. PatientId: 0,
  4800. SystemTime: time.Now().Unix(),
  4801. ConsumableType: 5,
  4802. IsSys: 0,
  4803. WarehousingOrder: "",
  4804. WarehouseOutId: out.ID,
  4805. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4806. IsEdit: 0,
  4807. CancelStockId: 0,
  4808. CancelOrderNumber: "",
  4809. Manufacturer: 0,
  4810. Dealer: 0,
  4811. Creator: adminUserInfo.AdminUser.Id,
  4812. UpdateCreator: 0,
  4813. Status: 1,
  4814. Ctime: time.Now().Unix(),
  4815. Mtime: 0,
  4816. Price: item.PackingPrice,
  4817. WarehousingDetailId: 0,
  4818. WarehouseOutDetailId: 0,
  4819. CancelOutDetailId: 0,
  4820. ProductDate: item.ProductDate,
  4821. ExpireDate: item.ExpiryDate,
  4822. }
  4823. service.CreateStockFlowOne(flow)
  4824. }
  4825. this.ServeSuccessJSON(map[string]interface{}{
  4826. "reportPrice": reportprice,
  4827. })
  4828. }
  4829. func (this *StockManagerApiController) SaveInventory() {
  4830. timeLayout := "2006-01-02"
  4831. loc, _ := time.LoadLocation("Local")
  4832. dataBody := make(map[string]interface{}, 0)
  4833. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4834. if err != nil {
  4835. utils.ErrorLog(err.Error())
  4836. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4837. return
  4838. }
  4839. tableData, _ := dataBody["tableData"].([]interface{})
  4840. if len(tableData) > 0 {
  4841. for _, item := range tableData {
  4842. items := item.(map[string]interface{})
  4843. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4844. utils.ErrorLog("good_name")
  4845. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4846. return
  4847. }
  4848. good_name := items["good_name"].(string)
  4849. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4850. utils.ErrorLog("good_name")
  4851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4852. return
  4853. }
  4854. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4855. utils.ErrorLog("packing_price")
  4856. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4857. return
  4858. }
  4859. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4860. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4861. utils.ErrorLog("warehousing_order")
  4862. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4863. return
  4864. }
  4865. warehousing_order := items["warehousing_order"].(string)
  4866. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4867. utils.ErrorLog("license_number")
  4868. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4869. return
  4870. }
  4871. license_number := items["license_number"].(string)
  4872. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4873. utils.ErrorLog("dealer")
  4874. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4875. return
  4876. }
  4877. dealer := items["dealer"].(string)
  4878. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4879. utils.ErrorLog("manufacturer")
  4880. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4881. return
  4882. }
  4883. manufacturer := items["manufacturer"].(string)
  4884. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4885. utils.ErrorLog("specification_name")
  4886. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4887. return
  4888. }
  4889. specification_name := items["specification_name"].(string)
  4890. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4891. utils.ErrorLog("remark")
  4892. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4893. return
  4894. }
  4895. remark := items["remark"].(string)
  4896. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4897. utils.ErrorLog("warehousing_unit")
  4898. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4899. return
  4900. }
  4901. warehousing_unit := items["warehousing_unit"].(string)
  4902. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4903. utils.ErrorLog("buy_price")
  4904. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4905. return
  4906. }
  4907. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4908. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4909. utils.ErrorLog("count")
  4910. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4911. return
  4912. }
  4913. count := int64(items["count"].(float64))
  4914. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4915. utils.ErrorLog("good_id")
  4916. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4917. return
  4918. }
  4919. good_id := int64(items["good_id"].(float64))
  4920. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4921. utils.ErrorLog("start_time")
  4922. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4923. return
  4924. }
  4925. var startTime int64
  4926. start_time := items["start_time"].(string)
  4927. if len(start_time) > 0 {
  4928. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4929. if err != nil {
  4930. fmt.Println(err)
  4931. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4932. return
  4933. }
  4934. startTime = theTime.Unix()
  4935. }
  4936. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  4937. utils.ErrorLog("total")
  4938. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4939. return
  4940. }
  4941. total := int64(items["total"].(float64))
  4942. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  4943. utils.ErrorLog("expiry_date")
  4944. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4945. return
  4946. }
  4947. expiry_date := int64(items["expiry_date"].(float64))
  4948. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  4949. utils.ErrorLog("product_date")
  4950. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4951. return
  4952. }
  4953. product_date := int64(items["product_date"].(float64))
  4954. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  4955. utils.ErrorLog("number")
  4956. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4957. return
  4958. }
  4959. number := items["number"].(string)
  4960. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  4961. utils.ErrorLog("warehousing_info_id")
  4962. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4963. return
  4964. }
  4965. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  4966. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  4967. utils.ErrorLog("good_origin_place")
  4968. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4969. return
  4970. }
  4971. good_origin_place := items["good_origin_place"].(string)
  4972. orgId := this.GetAdminUserInfo().CurrentOrgId
  4973. Creater := this.GetAdminUserInfo().AdminUser.Id
  4974. inventory := models.XtStockInventory{
  4975. GoodName: good_name,
  4976. SpecificationName: specification_name,
  4977. WarehousingUnit: warehousing_unit,
  4978. Count: count,
  4979. BuyPrice: buy_price,
  4980. PackingPrice: packing_price,
  4981. NewPrice: 0,
  4982. Manufacturer: manufacturer,
  4983. Dealer: dealer,
  4984. Remark: remark,
  4985. GoodId: good_id,
  4986. UserOrgId: orgId,
  4987. Ctime: time.Now().Unix(),
  4988. Mtime: 0,
  4989. Status: 1,
  4990. WarehousingOrder: warehousing_order,
  4991. LicenseNumber: license_number,
  4992. StartTime: startTime,
  4993. Creater: Creater,
  4994. Checker: 0,
  4995. CheckerStatus: 2,
  4996. CheckerTime: 0,
  4997. Total: total,
  4998. ExpireDate: expiry_date,
  4999. ProductDate: product_date,
  5000. Number: number,
  5001. WarehousingInfoId: warehousing_info_id,
  5002. GoodOriginPlace: good_origin_place,
  5003. }
  5004. err = service.CreateInentory(inventory)
  5005. fmt.Println(err)
  5006. }
  5007. }
  5008. this.ServeSuccessJSON(map[string]interface{}{
  5009. "msg": "保存成功!",
  5010. })
  5011. }
  5012. func (this *StockManagerApiController) GetInventorylist() {
  5013. timeLayout := "2006-01-02"
  5014. loc, _ := time.LoadLocation("Local")
  5015. start_time := this.GetString("start_time")
  5016. end_time := this.GetString("end_time")
  5017. page, _ := this.GetInt64("page")
  5018. limit, _ := this.GetInt64("limit")
  5019. keyword := this.GetString("keyword")
  5020. inventory_status, _ := this.GetInt64("inventory_status")
  5021. var startTime int64
  5022. if len(start_time) > 0 {
  5023. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5024. if err != nil {
  5025. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5026. return
  5027. }
  5028. startTime = theTime.Unix()
  5029. fmt.Println("开始时间", startTime)
  5030. }
  5031. var endTime int64
  5032. if len(end_time) > 0 {
  5033. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5034. if err != nil {
  5035. utils.ErrorLog(err.Error())
  5036. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5037. return
  5038. }
  5039. endTime = theTime.Unix()
  5040. }
  5041. orgId := this.GetAdminUserInfo().CurrentOrgId
  5042. list, total, _ := service.GetInventorylist(startTime, endTime, page, limit, inventory_status, keyword, orgId)
  5043. doctorlist, _ := service.GetAllDoctorThree(orgId)
  5044. this.ServeSuccessJSON(map[string]interface{}{
  5045. "list": list,
  5046. "total": total,
  5047. "doctorlist": doctorlist,
  5048. })
  5049. }
  5050. func (this *StockManagerApiController) SaveCheckInventory() {
  5051. timeLayout := "2006-01-02"
  5052. loc, _ := time.LoadLocation("Local")
  5053. dataBody := make(map[string]interface{}, 0)
  5054. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5055. fmt.Println(err)
  5056. idstr := this.GetString("ids")
  5057. ids := strings.Split(idstr, ",")
  5058. check_time := this.GetString("check_time")
  5059. var checkTime int64
  5060. if len(check_time) > 0 {
  5061. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  5062. if err != nil {
  5063. fmt.Println(err)
  5064. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5065. return
  5066. }
  5067. checkTime = theTime.Unix()
  5068. }
  5069. checker, _ := this.GetInt64("checker")
  5070. inventory := models.XtStockInventory{
  5071. Checker: checker,
  5072. CheckerStatus: 1,
  5073. CheckerTime: checkTime,
  5074. }
  5075. adminUserInfo := this.GetAdminUserInfo()
  5076. err = service.UpdateCheckInventory(ids, inventory)
  5077. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  5078. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  5079. var manufactuer_id int64
  5080. var dealer_id int64
  5081. //查询耗材信息
  5082. list, _ := service.GetInventoryDetailById(ids)
  5083. for _, item := range list {
  5084. for _, it := range manufacturerList {
  5085. if item.Manufacturer == it.ManufacturerName {
  5086. manufactuer_id = it.ID
  5087. }
  5088. }
  5089. for _, its := range dealerList {
  5090. if item.Dealer == its.DealerName {
  5091. dealer_id = its.ID
  5092. }
  5093. }
  5094. //查寻该批次的库存量
  5095. list, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  5096. //查询该耗材最后1条批次
  5097. info, _ := service.GetLastWarehouseInfo(item.GoodId)
  5098. good, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5099. fmt.Println("总共", item.Count)
  5100. fmt.Println("数据", list.StockCount)
  5101. //盘点盘点库存和et实际库存的大小
  5102. // 如果盘点库存大于实际库存,怎需要入库
  5103. if item.Count > list.StockCount {
  5104. ctime := time.Now().Unix()
  5105. timeStr := time.Now().Format("2006-01-02")
  5106. timeArr := strings.Split(timeStr, "-")
  5107. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  5108. total = total + 1
  5109. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5110. operation_time := time.Now().Unix()
  5111. creater := adminUserInfo.AdminUser.Id
  5112. warehousing := models.Warehousing{
  5113. WarehousingOrder: warehousing_order,
  5114. OperationTime: operation_time,
  5115. OrgId: adminUserInfo.CurrentOrgId,
  5116. Creater: creater,
  5117. Ctime: ctime,
  5118. Status: 1,
  5119. WarehousingTime: ctime,
  5120. Type: 1,
  5121. }
  5122. service.AddSigleWarehouse(&warehousing)
  5123. //获取最
  5124. //入库单表格
  5125. warehouseInfo := models.WarehousingInfo{
  5126. WarehousingOrder: warehousing.WarehousingOrder,
  5127. WarehousingId: warehousing.ID,
  5128. GoodId: item.GoodId,
  5129. Number: info.Number,
  5130. ProductDate: info.ProductDate,
  5131. ExpiryDate: info.ExpiryDate,
  5132. WarehousingCount: item.Count - list.StockCount,
  5133. Price: info.Price,
  5134. Status: 1,
  5135. Ctime: ctime,
  5136. Remark: item.Remark,
  5137. OrgId: adminUserInfo.CurrentOrgId,
  5138. Type: 1,
  5139. Manufacturer: manufactuer_id,
  5140. StockCount: item.Count - list.StockCount,
  5141. Dealer: dealer_id,
  5142. LicenseNumber: info.LicenseNumber,
  5143. WarehouseInfoId: item.WarehousingInfoId,
  5144. GoodTypeId: good.GoodTypeId,
  5145. }
  5146. flow := models.VmStockFlow{
  5147. WarehousingOrder: warehousing.WarehousingOrder,
  5148. WarehousingId: warehousing.ID,
  5149. GoodId: item.GoodId,
  5150. Number: info.Number,
  5151. ProductDate: info.ProductDate,
  5152. ExpireDate: info.ExpiryDate,
  5153. Count: item.Count - list.StockCount,
  5154. Price: item.BuyPrice,
  5155. Status: 1,
  5156. Ctime: ctime,
  5157. UserOrgId: adminUserInfo.CurrentOrgId,
  5158. Manufacturer: info.Manufacturer,
  5159. Dealer: info.Dealer,
  5160. LicenseNumber: info.LicenseNumber,
  5161. IsEdit: 1,
  5162. Creator: adminUserInfo.AdminUser.Id,
  5163. SystemTime: operation_time,
  5164. ConsumableType: 1,
  5165. WarehousingDetailId: warehouseInfo.ID,
  5166. }
  5167. service.CreateWarehouseInfo(warehouseInfo)
  5168. service.CreateStockFlowOne(flow)
  5169. }
  5170. //如果盘点库存小于实际库存,需要出库
  5171. if item.Count < list.StockCount {
  5172. timeStr := time.Now().Format("2006-01-02")
  5173. timeArr := strings.Split(timeStr, "-")
  5174. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  5175. total = total + 1
  5176. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5177. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5178. number = number + total
  5179. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5180. operation_time := time.Now().Unix()
  5181. creater := adminUserInfo.AdminUser.Id
  5182. //查询最早的1条批次
  5183. warehouseInfo, _ := service.GetFirstWarehouseInfo(item.GoodId)
  5184. warehouseOut := models.WarehouseOut{
  5185. WarehouseOutOrderNumber: warehousing_out_order,
  5186. OperationTime: operation_time,
  5187. OrgId: adminUserInfo.CurrentOrgId,
  5188. Creater: creater,
  5189. Ctime: time.Now().Unix(),
  5190. Status: 1,
  5191. WarehouseOutTime: time.Now().Unix(),
  5192. Type: 1,
  5193. }
  5194. err = service.CreateWarehouseOut(warehouseOut)
  5195. fmt.Println(err)
  5196. out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
  5197. warehouseOutInfo := &models.WarehouseOutInfo{
  5198. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  5199. WarehouseOutId: out.ID,
  5200. GoodId: warehouseInfo.GoodId,
  5201. Count: list.StockCount - item.Count,
  5202. Price: warehouseInfo.Price,
  5203. Status: 1,
  5204. Ctime: time.Now().Unix(),
  5205. Remark: item.Remark,
  5206. OrgId: adminUserInfo.CurrentOrgId,
  5207. Type: 1,
  5208. Manufacturer: manufactuer_id,
  5209. Number: warehouseInfo.Number,
  5210. ExpiryDate: warehouseInfo.ExpiryDate,
  5211. ProductDate: warehouseInfo.ProductDate,
  5212. Dealer: dealer_id,
  5213. LicenseNumber: warehouseInfo.LicenseNumber,
  5214. GoodTypeId: good.GoodTypeId,
  5215. }
  5216. stockFlow := models.VmStockFlow{
  5217. WarehousingId: item.WarehousingInfoId,
  5218. GoodId: warehouseInfo.GoodId,
  5219. Number: warehouseInfo.Number,
  5220. LicenseNumber: warehouseInfo.LicenseNumber,
  5221. Count: list.StockCount - item.Count,
  5222. UserOrgId: warehouseInfo.OrgId,
  5223. PatientId: 0,
  5224. SystemTime: 0,
  5225. ConsumableType: 2,
  5226. IsSys: 2,
  5227. WarehousingOrder: "",
  5228. WarehouseOutId: out.ID,
  5229. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5230. IsEdit: 1,
  5231. CancelStockId: 0,
  5232. CancelOrderNumber: "",
  5233. Manufacturer: manufactuer_id,
  5234. Dealer: dealer_id,
  5235. Creator: adminUserInfo.AdminUser.Id,
  5236. UpdateCreator: 0,
  5237. Status: 1,
  5238. Ctime: time.Now().Unix(),
  5239. Mtime: 0,
  5240. Price: warehouseInfo.Price,
  5241. WarehousingDetailId: 0,
  5242. WarehouseOutDetailId: out.ID,
  5243. CancelOutDetailId: 0,
  5244. ProductDate: warehouseInfo.ProductDate,
  5245. ExpireDate: warehouseInfo.ExpiryDate,
  5246. }
  5247. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5248. fmt.Println(errOne)
  5249. //创建出库明细
  5250. service.CreateStockFlowOne(stockFlow)
  5251. //更改库存
  5252. warehousingInfos := models.WarehousingInfo{
  5253. StockCount: item.Count,
  5254. }
  5255. service.UpdateStockOut(item.WarehousingInfoId, warehousingInfos)
  5256. }
  5257. }
  5258. fmt.Println(err)
  5259. this.ServeSuccessJSON(map[string]interface{}{
  5260. "inventory": inventory,
  5261. })
  5262. }
  5263. func (this *StockManagerApiController) GetModifyPriceDetail() {
  5264. id, _ := this.GetInt64("id")
  5265. detail, _ := service.GetModifyPriceDetail(id)
  5266. this.ServeSuccessJSON(map[string]interface{}{
  5267. "detail": detail,
  5268. })
  5269. }
  5270. func (this *StockManagerApiController) UpdateStockPrice() {
  5271. id, _ := this.GetInt64("id")
  5272. newPrice := this.GetString("new_price")
  5273. new_price, _ := strconv.ParseFloat(newPrice, 64)
  5274. good_name := this.GetString("good_name")
  5275. packingPrice := this.GetString("packing_price")
  5276. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5277. remark := this.GetString("remark")
  5278. good_id, _ := this.GetInt64("good_id")
  5279. manufacturer := this.GetString("manufacturer")
  5280. dealer := this.GetString("dealer")
  5281. adjust := models.XtStockAdjustPrice{
  5282. NewPrice: new_price,
  5283. GoodName: good_name,
  5284. PackingPrice: packing_price,
  5285. Remark: remark,
  5286. GoodId: good_id,
  5287. Manufacturer: manufacturer,
  5288. Dealer: dealer,
  5289. }
  5290. err := service.UpdateStockPrice(adjust, id)
  5291. fmt.Println(err)
  5292. this.ServeSuccessJSON(map[string]interface{}{
  5293. "adjust": adjust,
  5294. })
  5295. }
  5296. func (this *StockManagerApiController) DeleteStockPrice() {
  5297. id, _ := this.GetInt64("id")
  5298. err := service.DeleteStockPrice(id)
  5299. fmt.Println(err)
  5300. returnData := make(map[string]interface{}, 0)
  5301. returnData["msg"] = "ok"
  5302. this.ServeSuccessJSON(returnData)
  5303. return
  5304. }
  5305. func (this *StockManagerApiController) GetStockDamageDetail() {
  5306. id, _ := this.GetInt64("id")
  5307. detail, err := service.GetStockDamageDetail(id)
  5308. fmt.Println(err)
  5309. this.ServeSuccessJSON(map[string]interface{}{
  5310. "detail": detail,
  5311. })
  5312. }
  5313. func (this *StockManagerApiController) ModifyPrice() {
  5314. count, _ := this.GetInt64("count")
  5315. id, _ := this.GetInt64("id")
  5316. good_name := this.GetString("good_name")
  5317. specification_name := this.GetString("specification_name")
  5318. number := this.GetString("number")
  5319. warehousing_unit := this.GetString("warehousing_unit")
  5320. buyPrice := this.GetString("buy_price")
  5321. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5322. packingPrice := this.GetString("packing_price")
  5323. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5324. good_origin_place := this.GetString("good_origin_place")
  5325. manufacturer := this.GetString("manufacturer")
  5326. dealer := this.GetString("dealer")
  5327. total, _ := this.GetInt64("total")
  5328. remark := this.GetString("remark")
  5329. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5330. good_id, _ := this.GetInt64("good_id")
  5331. adjust := models.XtStockReportPrice{
  5332. Count: count,
  5333. SpecificationName: specification_name,
  5334. Number: number,
  5335. GoodName: good_name,
  5336. WarehousingUnit: warehousing_unit,
  5337. BuyPrice: buy_price,
  5338. PackingPrice: packing_price,
  5339. GoodOriginPlace: good_origin_place,
  5340. Manufacturer: manufacturer,
  5341. Dealer: dealer,
  5342. Total: total,
  5343. Remark: remark,
  5344. WarehousingInfoId: warehousing_info_id,
  5345. GoodId: good_id,
  5346. }
  5347. err := service.ModifyPrice(id, adjust)
  5348. fmt.Println(err)
  5349. this.ServeSuccessJSON(map[string]interface{}{
  5350. "adjust": adjust,
  5351. })
  5352. }
  5353. func (this *StockManagerApiController) DeleteDamage() {
  5354. id, _ := this.GetInt64("id")
  5355. err := service.DeleteDamage(id)
  5356. fmt.Println(err)
  5357. returnData := make(map[string]interface{}, 0)
  5358. returnData["msg"] = "ok"
  5359. this.ServeSuccessJSON(returnData)
  5360. return
  5361. }
  5362. func (this *StockManagerApiController) GetStockDamageById() {
  5363. ids := this.GetString("ids")
  5364. splitIds := strings.Split(ids, ",")
  5365. list, _ := service.GetStockDamageById(splitIds)
  5366. this.ServeSuccessJSON(map[string]interface{}{
  5367. "list": list,
  5368. })
  5369. }
  5370. func (this *StockManagerApiController) GetInventoryDetail() {
  5371. id, _ := this.GetInt64("id")
  5372. detail, _ := service.GetInventoryDetail(id)
  5373. this.ServeSuccessJSON(map[string]interface{}{
  5374. "detail": detail,
  5375. })
  5376. }
  5377. func (this *StockManagerApiController) ModifyInventory() {
  5378. id, _ := this.GetInt64("id")
  5379. good_id, _ := this.GetInt64("good_id")
  5380. good_name := this.GetString("good_name")
  5381. specification_name := this.GetString("specification_name")
  5382. number := this.GetString("number")
  5383. warehousing_unit := this.GetString("warehousing_unit")
  5384. buyPrice := this.GetString("buy_price")
  5385. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5386. packingPrice := this.GetString("packing_price")
  5387. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5388. total, _ := this.GetInt64("total")
  5389. good_origin_place := this.GetString("good_origin_place")
  5390. license_number := this.GetString("license_number")
  5391. dealer := this.GetString("dealer")
  5392. manufacturer := this.GetString("manufacturer")
  5393. count, _ := this.GetInt64("count")
  5394. remark := this.GetString("remark")
  5395. inventory := models.XtStockInventory{
  5396. GoodId: good_id,
  5397. GoodName: good_name,
  5398. SpecificationName: specification_name,
  5399. Number: number,
  5400. WarehousingUnit: warehousing_unit,
  5401. BuyPrice: buy_price,
  5402. PackingPrice: packing_price,
  5403. Total: total,
  5404. GoodOriginPlace: good_origin_place,
  5405. LicenseNumber: license_number,
  5406. Dealer: dealer,
  5407. Manufacturer: manufacturer,
  5408. Count: count,
  5409. Remark: remark,
  5410. }
  5411. err := service.ModifyInventory(id, inventory)
  5412. fmt.Println(err)
  5413. this.ServeSuccessJSON(map[string]interface{}{
  5414. "inventory": inventory,
  5415. })
  5416. }
  5417. func (this *StockManagerApiController) DeleteInventory() {
  5418. id, _ := this.GetInt64("id")
  5419. err := service.DeleteInventory(id)
  5420. fmt.Println(err)
  5421. returnData := make(map[string]interface{}, 0)
  5422. returnData["msg"] = "ok"
  5423. this.ServeSuccessJSON(returnData)
  5424. return
  5425. }
  5426. func (this *StockManagerApiController) GetInventoryDetailList() {
  5427. keyword := this.GetString("keyword")
  5428. limit, _ := this.GetInt64("limit")
  5429. page, _ := this.GetInt64("page")
  5430. orgId := this.GetAdminUserInfo().CurrentOrgId
  5431. list, total, _ := service.GetInventoryDetailList(keyword, limit, page, orgId)
  5432. this.ServeSuccessJSON(map[string]interface{}{
  5433. "list": list,
  5434. "total": total,
  5435. })
  5436. }
  5437. func (this *StockManagerApiController) GetInventoryPrintList() {
  5438. ids := this.GetString("ids")
  5439. splitIds := strings.Split(ids, ",")
  5440. list, _ := service.GetInventoryPrintList(splitIds)
  5441. this.ServeSuccessJSON(map[string]interface{}{
  5442. "list": list,
  5443. })
  5444. }
  5445. func (this *StockManagerApiController) GetInventoryDetailPrintList() {
  5446. ids := this.GetString("ids")
  5447. splitIds := strings.Split(ids, ",")
  5448. list, _ := service.GetInventoryDetailPrintList(splitIds)
  5449. this.ServeSuccessJSON(map[string]interface{}{
  5450. "list": list,
  5451. })
  5452. }
  5453. func (this *StockManagerApiController) DeleteDrugPrice() {
  5454. id, _ := this.GetInt64("id")
  5455. err := service.DeleteDrugPrice(id)
  5456. fmt.Println(err)
  5457. returnData := make(map[string]interface{}, 0)
  5458. returnData["msg"] = "ok"
  5459. this.ServeSuccessJSON(returnData)
  5460. return
  5461. }
  5462. func (this *StockManagerApiController) GetGoodWarehouseList() {
  5463. id, _ := this.GetInt64("id")
  5464. list, _ := service.GetGoodWarehouseList(id)
  5465. this.ServeSuccessJSON(map[string]interface{}{
  5466. "list": list,
  5467. })
  5468. }
  5469. func (this *StockManagerApiController) ProofInventory() {
  5470. id, _ := this.GetInt64("id")
  5471. good_id, _ := this.GetInt64("good_id")
  5472. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5473. proof_count, _ := this.GetInt64("proof_count")
  5474. total, _ := this.GetInt64("total")
  5475. orgId := this.GetAdminUserInfo().CurrentOrgId
  5476. creater := this.GetAdminUserInfo().AdminUser.Id
  5477. info := models.WarehousingInfo{
  5478. GoodId: good_id,
  5479. StockCount: proof_count,
  5480. }
  5481. err := service.UpdateProofInventory(warehousing_info_id, info)
  5482. inventory := models.XtStockInventory{
  5483. Total: proof_count,
  5484. }
  5485. err = service.UpdateStockInventory(inventory, id)
  5486. fmt.Println(err)
  5487. record := models.XtStockCorrectRecord{
  5488. GoodId: good_id,
  5489. OrdCount: total,
  5490. WarehousingInfoId: warehousing_info_id,
  5491. NewCount: proof_count,
  5492. UserOrgId: orgId,
  5493. Status: 1,
  5494. Creater: creater,
  5495. Ctime: time.Now().Unix(),
  5496. Mtime: 0,
  5497. }
  5498. service.CeateStockCorrectRecord(record)
  5499. this.ServeSuccessJSON(map[string]interface{}{
  5500. "list": info,
  5501. })
  5502. }
  5503. func (this *StockManagerApiController) GetWarehouseTotal() {
  5504. id, _ := this.GetInt64("id")
  5505. list, _ := service.GetWarehouseTotal(id)
  5506. this.ServeSuccessJSON(map[string]interface{}{
  5507. "list": list,
  5508. })
  5509. }
  5510. func (this *StockManagerApiController) GetGoodInventoryWarehouseList() {
  5511. id, _ := this.GetInt64("id")
  5512. list, _ := service.GetGoodInventoryWarehouseList(id)
  5513. orgId := this.GetAdminUserInfo().CurrentOrgId
  5514. fmt.Println(orgId)
  5515. this.ServeSuccessJSON(map[string]interface{}{
  5516. "list": list,
  5517. })
  5518. }
  5519. func (this *StockManagerApiController) SaveStockInventoryList() {
  5520. dataBody := make(map[string]interface{}, 0)
  5521. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5522. fmt.Println(err)
  5523. tableData, _ := dataBody["tableData"].([]interface{})
  5524. if len(tableData) > 0 {
  5525. for _, item := range tableData {
  5526. items := item.(map[string]interface{})
  5527. good_name := items["good_name"].(string)
  5528. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5529. utils.ErrorLog("good_name")
  5530. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5531. return
  5532. }
  5533. specification_name := items["specification_name"].(string)
  5534. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  5535. utils.ErrorLog("specification_name")
  5536. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5537. return
  5538. }
  5539. warehousing_unit := items["warehousing_unit"].(string)
  5540. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  5541. utils.ErrorLog("warehousing_unit")
  5542. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5543. return
  5544. }
  5545. stock_count := int64(items["stock_count"].(float64))
  5546. if items["stock_count"] == nil || reflect.TypeOf(items["stock_count"]).String() != "float64" {
  5547. utils.ErrorLog("stock_count")
  5548. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5549. return
  5550. }
  5551. price := items["price"].(float64)
  5552. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "float64" {
  5553. utils.ErrorLog("price")
  5554. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5555. return
  5556. }
  5557. manufacturer_name := items["manufacturer_name"].(string)
  5558. if items["manufacturer_name"] == nil || reflect.TypeOf(items["manufacturer_name"]).String() != "string" {
  5559. utils.ErrorLog("manufacturer_name")
  5560. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5561. return
  5562. }
  5563. good_id := int64(items["good_id"].(float64))
  5564. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5565. utils.ErrorLog("good_id")
  5566. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5567. return
  5568. }
  5569. manufacturer := int64(items["manufacturer"].(float64))
  5570. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "float64" {
  5571. utils.ErrorLog("manufacturer")
  5572. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5573. return
  5574. }
  5575. warehousing_order := items["warehousing_order"].(string)
  5576. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  5577. utils.ErrorLog("warehousing_order")
  5578. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5579. return
  5580. }
  5581. number := items["number"].(string)
  5582. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5583. utils.ErrorLog("number")
  5584. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5585. return
  5586. }
  5587. id := int64(items["id"].(float64))
  5588. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5589. utils.ErrorLog("id")
  5590. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5591. return
  5592. }
  5593. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  5594. utils.ErrorLog("expiry_date")
  5595. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5596. return
  5597. }
  5598. expiry_date := int64(items["expiry_date"].(float64))
  5599. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  5600. utils.ErrorLog("product_date")
  5601. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5602. return
  5603. }
  5604. product_date := int64(items["product_date"].(float64))
  5605. orgId := this.GetAdminUserInfo().CurrentOrgId
  5606. adminId := this.GetAdminUserInfo().AdminUser.Id
  5607. stock_type := int64(items["type"].(float64))
  5608. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5609. utils.ErrorLog("type")
  5610. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5611. return
  5612. }
  5613. last_stock_count := int64(items["last_stock_count"].(float64))
  5614. if items["last_stock_count"] == nil || reflect.TypeOf(items["last_stock_count"]).String() != "float64" {
  5615. utils.ErrorLog("last_stock_count")
  5616. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5617. return
  5618. }
  5619. var total_count int64
  5620. var inventory_type int64
  5621. fmt.Println("盘点前", stock_count)
  5622. fmt.Println("盘点后", last_stock_count)
  5623. if stock_count > last_stock_count {
  5624. total_count = stock_count - last_stock_count
  5625. inventory_type = 11
  5626. }
  5627. if stock_count < last_stock_count {
  5628. total_count = last_stock_count - stock_count
  5629. inventory_type = 10
  5630. }
  5631. creater := this.GetAdminUserInfo().AdminUser.Id
  5632. inventory := models.XtStockInventory{
  5633. GoodName: good_name,
  5634. SpecificationName: specification_name,
  5635. WarehousingUnit: warehousing_unit,
  5636. Count: total_count,
  5637. BuyPrice: price,
  5638. PackingPrice: price,
  5639. NewPrice: 0,
  5640. Manufacturer: manufacturer_name,
  5641. Dealer: "",
  5642. Remark: "",
  5643. GoodId: good_id,
  5644. UserOrgId: orgId,
  5645. Ctime: time.Now().Unix(),
  5646. Mtime: 0,
  5647. Status: 1,
  5648. WarehousingOrder: warehousing_order,
  5649. LicenseNumber: number,
  5650. StartTime: time.Now().Unix(),
  5651. Creater: adminId,
  5652. Checker: 0,
  5653. CheckerStatus: 0,
  5654. CheckerTime: 0,
  5655. Total: 0,
  5656. Number: number,
  5657. WarehousingInfoId: id,
  5658. ExpireDate: expiry_date,
  5659. ProductDate: product_date,
  5660. GoodOriginPlace: "",
  5661. Type: 10,
  5662. InventoryType: stock_type,
  5663. LastStockCount: last_stock_count,
  5664. StockCount: stock_count,
  5665. }
  5666. service.CreateInentory(inventory)
  5667. stockFlow := models.VmStockFlow{
  5668. WarehousingId: 0,
  5669. GoodId: good_id,
  5670. Number: number,
  5671. LicenseNumber: "",
  5672. Count: total_count,
  5673. UserOrgId: orgId,
  5674. PatientId: 0,
  5675. SystemTime: 0,
  5676. ConsumableType: inventory_type,
  5677. IsSys: 0,
  5678. WarehousingOrder: "",
  5679. WarehouseOutId: 0,
  5680. WarehouseOutOrderNumber: warehousing_order,
  5681. IsEdit: 0,
  5682. CancelStockId: 0,
  5683. CancelOrderNumber: "",
  5684. Manufacturer: manufacturer,
  5685. Dealer: 0,
  5686. Creator: creater,
  5687. UpdateCreator: 0,
  5688. Status: 1,
  5689. Ctime: time.Now().Unix(),
  5690. Mtime: 0,
  5691. Price: price,
  5692. WarehousingDetailId: 0,
  5693. WarehouseOutDetailId: 0,
  5694. CancelOutDetailId: 0,
  5695. ProductDate: product_date,
  5696. ExpireDate: expiry_date,
  5697. ReturnCount: 0,
  5698. }
  5699. info := models.WarehousingInfo{
  5700. StockCount: last_stock_count,
  5701. }
  5702. //更改库存
  5703. service.UpdatedWarehousingInfo(info, id)
  5704. if stock_count != last_stock_count {
  5705. service.CreateStockFlowOne(stockFlow)
  5706. }
  5707. this.ServeSuccessJSON(map[string]interface{}{
  5708. "inventory": inventory,
  5709. })
  5710. }
  5711. }
  5712. }
  5713. func (this *StockManagerApiController) GetDamageDetailByGoodId() {
  5714. good_id, _ := this.GetInt64("good_id")
  5715. list, _ := service.GetDamageDetailByGoodId(good_id)
  5716. orgId := this.GetAdminUserInfo().CurrentOrgId
  5717. damageList, _ := service.GetStockDamagedCount(orgId)
  5718. this.ServeSuccessJSON(map[string]interface{}{
  5719. "list": list,
  5720. "damageList": damageList,
  5721. })
  5722. }