stock_in_api_controller.go 211KB

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