stock_in_api_controller.go 234KB

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