stock_in_api_controller.go 238KB

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