stock_in_api_controller.go 236KB

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