1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317 |
- package controllers
-
- import (
- "encoding/json"
- "fmt"
- "reflect"
- "strconv"
- "strings"
- "time"
-
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "github.com/astaxie/beego"
- "github.com/jinzhu/gorm"
- "github.com/mozillazg/go-pinyin"
- )
-
- type StockManagerApiController struct {
- BaseAuthAPIController
- }
-
- func StockManagerApiRegistRouters() {
-
- //入库管理和其他入库管理相关接口
- beego.Router("/api/warehouse/create", &StockManagerApiController{}, "post:CreateWarehouse")
- beego.Router("/api/warehouse/list", &StockManagerApiController{}, "get:GetWarehouseList")
- beego.Router("/api/warehouse/delete", &StockManagerApiController{}, "post:DeleteWarehouse")
- beego.Router("/api/warehouseinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseInfo")
- beego.Router("/api/warehouseinfo/list", &StockManagerApiController{}, "get:GetWarehouseInfoList")
- beego.Router("/api/warehouse/edit", &StockManagerApiController{}, "post:EditWarehouse")
-
- //退货管理和其他退货管理相关接口
- beego.Router("/api/salesreturn/create", &StockManagerApiController{}, "post:CreateSalesReturn")
- beego.Router("/api/salesreturn/delete", &StockManagerApiController{}, "post:DeleteSalesReturn")
- beego.Router("/api/salesreturninfo/delete", &StockManagerApiController{}, "post:DeleteSalesReturnInfo")
- beego.Router("/api/salesreturninfo/list", &StockManagerApiController{}, "get:GetSalesReturnInfoList")
- beego.Router("/api/salesreturn/list", &StockManagerApiController{}, "get:GetSalesReturnList")
- beego.Router("/api/salesreturn/edit", &StockManagerApiController{}, "post:EditReturnInfo")
-
- //出库管理和其他出库管理相关接口
- beego.Router("/api/warehouseout/create", &StockManagerApiController{}, "post:CreateWarehouseOut")
- beego.Router("/api/warehouseout/delete", &StockManagerApiController{}, "post:DeleteWarehouseOut")
- beego.Router("/api/warehouseoutinfo/delete", &StockManagerApiController{}, "post:DeleteWarehouseOutInfo")
- beego.Router("/api/warehouseout/list", &StockManagerApiController{}, "get:GetWarehouseOutList")
- beego.Router("/api/warehouseout/edit", &StockManagerApiController{}, "post:EditWarehouseOut")
- beego.Router("/api/warehouseout/info", &StockManagerApiController{}, "get:GetWarehouseOutInfoList")
-
- //出库退库管理和其他出库退库管理相关接口
- beego.Router("/api/cancelstock/create", &StockManagerApiController{}, "post:CreateCancelStock")
- beego.Router("/api/cancelstock/list", &StockManagerApiController{}, "get:GetCancelStockList")
- beego.Router("/api/cancelstock/info", &StockManagerApiController{}, "get:GetCancelStockInfoList")
- beego.Router("/api/cancelstock/delete", &StockManagerApiController{}, "post:DeleteCancelStock")
- beego.Router("/api/cancelstockinfo/delete", &StockManagerApiController{}, "post:DeleteCancelStockInfo")
- beego.Router("/api/cancelstockinfo/edit", &StockManagerApiController{}, "post:EditCancelStock")
- beego.Router("/api/cancelstockinfo/config", &StockManagerApiController{}, "get:GetCancelStockConfig")
-
- //库存相关全局配置
- beego.Router("/api/stock/config", &StockManagerApiController{}, "get:GetAllConfig")
- beego.Router("/api/return/config", &StockManagerApiController{}, "get:GetAllSalesReturnConfig")
-
- //库存查询
- beego.Router("/api/stock/query", &StockManagerApiController{}, "get:GetQueryInfo")
-
- beego.Router("/api/stock/detail", &StockManagerApiController{}, "get:GetDetailInfo")
-
- beego.Router("/api/warehouseout/user", &StockManagerApiController{}, "get:GetUserDetailInfo")
-
- beego.Router("/api/warehouseout/postsearchstock", &StockManagerApiController{}, "Get:PostSearchStock")
-
- beego.Router("/api/warehouseout/getoutstocktotalcount", &StockManagerApiController{}, "Get:GetOutStockTotalCount")
-
- beego.Router("/api/good/postgoodinformation", &StockManagerApiController{}, "Post:AddGoodInformation")
-
- beego.Router("/api/good/postdruginformation", &StockManagerApiController{}, "Post:AddDrugInformation")
-
- beego.Router("/api/good/initializtion", &StockManagerApiController{}, "Get:GetInitializtion")
-
- beego.Router("/api/good/getwarehouseorderinfolist", &StockManagerApiController{}, "Get:GetWarehouseOrderInfolist")
-
- beego.Router("/api/good/postsearchgoodlist", &StockManagerApiController{}, "Get:PostSearchGoodList")
-
- beego.Router("/api/good/getallstocklist", &StockManagerApiController{}, "Get:GetAllStockList")
-
- beego.Router("/api/stock/getstocklistbyid", &StockManagerApiController{}, "Get:GetStockListById")
- beego.Router("/api/stock/getstockoutlist", &StockManagerApiController{}, "Get:GetStockOutList")
-
- beego.Router("/api/good/getstockdrugcount", &StockManagerApiController{}, "Get:GetStockDrugCount")
-
- beego.Router("/api/good/getorderdetialbyorderid", &StockManagerApiController{}, "Get:GetOrderDetialByOrderId")
- beego.Router("/api/good/getorderdetaibyid", &StockManagerApiController{}, "Get:GetOrderDetailById")
- beego.Router("/api/good/getsingleoutorderdetail", &StockManagerApiController{}, "Get:GetSingleOutOrderDetail")
- beego.Router("/api/stock/getexportstocklist", &StockManagerApiController{}, "Get:GetExprotStockList")
- beego.Router("/api/stock/getoutexprotlist", &StockManagerApiController{}, "Get:GetOutExprotList")
- beego.Router("/api/stock/getsinglecancelorder", &StockManagerApiController{}, "Get:GetSingleCancelOrder")
- beego.Router("/api/stock/getcancelstockorderprint", &StockManagerApiController{}, "Get:GetCancelStockOrderPrint")
- beego.Router("/api/stock/getstockbatchnumber", &StockManagerApiController{}, "Get:GetStockBatchNumber")
-
- beego.Router("/api/stock/getstockflow", &StockManagerApiController{}, "Get:GetStockFlow")
-
- beego.Router("/api/cancel/getcancelexportlist", &StockManagerApiController{}, "Get:GetCancelExportList")
-
- //耗材调价
- beego.Router("/api/stock/postsearchgoodwarehouselist", &StockManagerApiController{}, "Get:GetSearchGoodWarehouseList")
- beego.Router("/api/stock/saveadjustprice", &StockManagerApiController{}, "Post:SaveAdjuestPrice")
- beego.Router("/api/stock/getallstockprice", &StockManagerApiController{}, "Get:GetAllStockPrice")
- beego.Router("/api/stock/savecheckedprice", &StockManagerApiController{}, "Get:SaveCheckPrice")
- beego.Router("/api/stock/getadjustpriceinfo", &StockManagerApiController{}, "Get:GetAdjustPriceById")
- beego.Router("/api/stock/savereportstock", &StockManagerApiController{}, "Post:SaveReportStock")
- beego.Router("/api/stock/getreportstocklist", &StockManagerApiController{}, "Get:GetReportStockList")
- beego.Router("/api/stock/savecheckdamage", &StockManagerApiController{}, "Get:SaveCheckDamage")
- beego.Router("/api/stock/saveinventory", &StockManagerApiController{}, "Post:SaveInventory")
- beego.Router("/api/stock/getinventorylist", &StockManagerApiController{}, "Get:GetInventorylist")
- beego.Router("/api/stock/savecheckinventory", &StockManagerApiController{}, "Get:SaveCheckInventory")
- beego.Router("/api/stock/getmodifypriceDetail", &StockManagerApiController{}, "Get:GetModifyPriceDetail")
- beego.Router("/api/stock/updatestockprice", &StockManagerApiController{}, "Get:UpdateStockPrice")
- beego.Router("/api/stock/deletestockprice", &StockManagerApiController{}, "Get:DeleteStockPrice")
- beego.Router("/api/stock/getstockdamagedetal", &StockManagerApiController{}, "Get:GetStockDamageDetail")
- beego.Router("/api/sotck/modifyprice", &StockManagerApiController{}, "Get:ModifyPrice")
- beego.Router("/api/stock/deletestockdamage", &StockManagerApiController{}, "Get:DeleteDamage")
- beego.Router("/api/stock/getstockdamagebyid", &StockManagerApiController{}, "Get:GetStockDamageById")
- beego.Router("api/sotck/getinventorydetail", &StockManagerApiController{}, "Get:GetInventoryDetail")
- beego.Router("/api/stock/modifyinventory", &StockManagerApiController{}, "Get:ModifyInventory")
- beego.Router("/api/stock/deleteinventory", &StockManagerApiController{}, "Get:DeleteInventory")
- beego.Router("/api/stock/getinventorydetaillist", &StockManagerApiController{}, "Get:GetInventoryDetailList")
- beego.Router("/api/stock/getinventoryprintlist", &StockManagerApiController{}, "Get:GetInventoryPrintList")
- beego.Router("/api/stock/getinventorydetailprintlist", &StockManagerApiController{}, "Get:GetInventoryDetailPrintList")
- beego.Router("/api/drug/deletedrugprice", &StockManagerApiController{}, "Get:DeleteDrugPrice")
- beego.Router("/api/stock/getgoodwarehouselist", &StockManagerApiController{}, "Get:GetGoodWarehouseList")
- beego.Router("/api/stock/proofinventory", &StockManagerApiController{}, "Get:ProofInventory")
- beego.Router("/api/stock/getwarehousetotal", &StockManagerApiController{}, "Get:GetWarehouseTotal")
- beego.Router("/api/stock/getgoodinventorywarehouselist", &StockManagerApiController{}, "Get:GetGoodInventoryWarehouseList")
- beego.Router("/api/stock/savestockinentorylist", &StockManagerApiController{}, "Post:SaveStockInventoryList")
- beego.Router("/api/sotck/getdamagedetailbygoodid", &StockManagerApiController{}, "Get:GetDamageDetailByGoodId")
- beego.Router("/api/stock/getinventoryexportlist", &StockManagerApiController{}, "Get:GetInventoryExportList")
-
- //处理历史数据
- beego.Router("/api/stock/updatecancelstockorder", &StockManagerApiController{}, "Get:UpdateCancelStockOrder")
-
- beego.Router("/api/stock/getdrugdetailsummary", &StockManagerApiController{}, "Get:GetDrugDetailSummary")
- beego.Router("/api/stock/getgooddetialsummary", &StockManagerApiController{}, "Get:GetGoodDetailSummary")
-
- //库存优化接口
- beego.Router("/api/stock/checkwarehouseout", &StockManagerApiController{}, "Get:CheckWarehouseOut")
- beego.Router("/api/stock/returncheckwarehouseout", &StockManagerApiController{}, "Get:ReturnCheckWarehouseOut")
- beego.Router("/api/stock/tocheckwarehouseinfo", &StockManagerApiController{}, "Get:CheckWarehouseInfo")
- beego.Router("/api/stock/returncheckwarehouseinfo", &StockManagerApiController{}, "Get:ReturnCheckWarehouseInfo")
- beego.Router("/api/stock/checkstockwarehouseinfo", &StockManagerApiController{}, "Get:CheckStockWarehouseInfo")
- beego.Router("/api/stock/checkreturnstockwarehouseinfo", &StockManagerApiController{}, "Get:CheckReturnStockWarehouseInfo")
- beego.Router("/api/stock/getprintlist", &StockManagerApiController{}, "Get:GetPrintList")
-
- beego.Router("/api/stock/getwarehouseinfolist", &StockManagerApiController{}, "Get:GetInvetoryWarehouseInfoList")
-
- //结算成功后调用操作库存相关接口
- beego.Router("/api/settle/stock", &StockManagerApiController{}, "Get:HandleSettleStock")
- beego.Router("/api/settle/cancelstock", &StockManagerApiController{}, "Get:HandleRefundStock")
-
- beego.Router("/api/stock/getnewgoodwarehouseinfo", &StockManagerApiController{}, "Get:GetNewGoodWarehouseInfo")
- beego.Router("/api/stock/getnewwarehouseoutinfolist", &StockManagerApiController{}, "Get:GetNewWarehouseOutInfoList")
-
- beego.Router("/api/stock/getstockfloworderlist", &StockManagerApiController{}, "Get:GetStockFlowOrderList")
-
- beego.Router("/api/stock/getgoodpatientname", &StockManagerApiController{}, "Get:GetGoodPatientName")
-
- beego.Router("/api/drug/updatebasedruglisbyuserorgid", &StockManagerApiController{}, "Get:UpdateBaseDrugListByUserOrgID")
-
- beego.Router("/api/good/updategoodinfobyuserorgid", &StockManagerApiController{}, "Get:UpdateGoodInfoByUserOrgId")
-
- beego.Router("/api/good/getgoodstockinventorylist", &StockManagerApiController{}, "Get:GetGoodStockInventoryList")
-
- beego.Router("/api/good/getstockinventoryprintlist", &StockManagerApiController{}, "Get:GetStockInventoryPrintList")
-
- beego.Router("/api/good/getstockinventoymodeprintlist", &StockManagerApiController{}, "Get:GetStockInventoryModePrintList")
-
- }
- func (c *StockManagerApiController) HandleRefundStock() {
- order_id, _ := c.GetInt64("order_id", 0)
- order, _ := service.GetHisOrderByIDThree(order_id)
- if order.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
- houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
- var goods []*models.DialysisBeforePrepareGoods
- var newGoods []*models.NewDialysisBeforePrepareGoods
- var infos []*models.HisDoctorAdviceInfo
-
- for _, info := range orders {
- if info.AdviceId > 0 && info.ProjectId == 0 {
- infos = append(infos, &info.HisDoctorAdviceInfo)
- }
- if info.ProjectId > 0 && info.AdviceId == 0 {
- if info.HisPrescriptionProject.Type == 3 {
- var good models.DialysisBeforePrepareGoods
- var newGood models.NewDialysisBeforePrepareGoods
- good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
- good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
- count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
- good.Count = int64(count)
- good.StorehouseId = houseConfig.StorehouseOutInfo
- good.ProjectId = info.HisPrescriptionProject.ID
- goods = append(goods, &good)
-
- newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
- newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
- count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
- newGood.Count = int64(count2)
- newGood.StorehouseId = houseConfig.StorehouseOutInfo
- newGood.ProjectId = info.HisPrescriptionProject.ID
- newGoods = append(newGoods, &newGood)
- }
- }
- }
- for _, item := range infos {
- //service.HisDrugsDelivery(item.UserOrgId, order.Creator, item)
- service.DrugAutoAddCancelInfo(item, order.Creator)
-
- }
-
- }
- func (c *StockManagerApiController) HandleSettleStock() {
- order_id, _ := c.GetInt64("order_id", 0)
- order, _ := service.GetHisOrderByID(order_id)
- if order.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- orders, _ := service.GetHisOrderDetailByNumberTwo(order.Number, order.UserOrgId)
- houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
- var goods []*models.DialysisBeforePrepareGoods
- var newGoods []*models.NewDialysisBeforePrepareGoods
- var infos []*models.HisDoctorAdviceInfo
-
- for _, info := range orders {
- if info.AdviceId > 0 && info.ProjectId == 0 {
- infos = append(infos, &info.HisDoctorAdviceInfo)
- }
- if info.ProjectId > 0 && info.AdviceId == 0 {
- if info.HisPrescriptionProject.Type == 3 {
- var good models.DialysisBeforePrepareGoods
- var newGood models.NewDialysisBeforePrepareGoods
- good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
- good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
- count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
- good.Count = int64(count)
- good.StorehouseId = houseConfig.StorehouseOutInfo
- good.ProjectId = info.HisPrescriptionProject.ID
- goods = append(goods, &good)
-
- newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
- newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
- count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
- newGood.Count = int64(count2)
- newGood.StorehouseId = houseConfig.StorehouseOutInfo
- newGood.ProjectId = info.HisPrescriptionProject.ID
- newGoods = append(newGoods, &newGood)
- }
- }
- }
- service.ConsumablesDeliveryTotal(order.UserOrgId, order.PatientId, order.SettleAccountsDate, goods, newGoods, order.Creator)
- for _, item := range infos {
- service.HisDrugsDelivery(item.UserOrgId, order.Creator, item)
- }
- }
-
- func (c *StockManagerApiController) CreateWarehouse() {
-
- warehousing_time := c.GetString("warehousing_time")
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- warehousing_info_id, _ := c.GetInt64("warehousing_info_id")
- ctime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- // 开始外部循环的事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindNewAllWarehouseTotal(adminUserInfo.CurrentOrgId, tx)
- total = total + 1
- warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
- warehousing := models.Warehousing{
- WarehousingOrder: warehousing_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehousingTime: warehousingDate.Unix(),
- Type: types,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
- if warehousing_info_id == 0 {
-
- service.AddNewSigleWarehouse(&warehousing, tx)
- }
- if warehousing_info_id > 0 {
-
- service.UpdateNewWarehouse(warehousing_info_id, storehouse_id, tx)
- }
- info, _ := service.FindNewLastWarehousingSix(adminUserInfo.CurrentOrgId, tx)
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingInfo []*models.WarehousingInfo
-
- if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["stockIn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
- utils.ErrorLog("warehousing_count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
-
- total := float64(warehousing_count) * price
-
- if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
- utils.ErrorLog("packing_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
-
- var productDates int64
- var expiryDates int64
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
-
- }
-
- number, _ := items["number"].(string)
-
- remark, _ := items["remark"].(string)
-
- manufacturer := int64(items["manufacturer"].(float64))
- dealer := int64(items["dealer"].(float64))
-
- license_number, _ := items["license_number"].(string)
-
- register_number, _ := items["register_number"].(string)
-
- good_code, _ := items["good_code"].(string)
- //入库单表格
- warehouseInfo := &models.WarehousingInfo{
- ID: id,
- WarehousingOrder: warehousing.WarehousingOrder,
- WarehousingId: info.ID,
- GoodId: good_id,
- Number: number,
- GoodTypeId: good_type_id,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- WarehousingCount: warehousing_count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: warehousingDate.Unix(),
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- StockCount: 0,
- Dealer: dealer,
- LicenseNumber: license_number,
- PackingPrice: packing_price,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- RegisterNumber: register_number,
- GoodCode: good_code,
- }
- warehousingInfo = append(warehousingInfo, warehouseInfo)
-
- }
- }
- }
-
- for _, item := range warehousingInfo {
- if item.ID == 0 {
- service.CreatedNewWarehouseingDetail(item, tx)
- }
- if item.ID > 0 {
-
- service.UpdateNewWarehouseDetail(item, item.ID, tx)
- }
-
- }
-
- //查询入库数据
- list, _ := service.GetNewGoodWarehouseInfoById(info.ID, info.OrgId, tx)
-
- tx.Commit()
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "入库成功",
- "warehousing_order": warehousing_order,
- "info": info,
- "list": list,
- "dealerList": dealerList,
- "manufacturerList": manufacturerList,
- })
-
- }
- func (c *StockManagerApiController) GetWarehouseList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
- storehouse_id, _ := c.GetInt64("storehouse_id")
- check_type, _ := c.GetInt64("check_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- var ids []int64
- var goodids []int64
- //查询商品名称
- if len(keywords) > 0 {
- //查询商品名称
- list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
- for _, item := range list {
- goodids = append(goodids, item.ID)
- //入库详情但里面查询
- }
- if len(goodids) > 0 {
- info, _ := service.GetWarehoureOrderInfoByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId, storehouse_id)
- for _, it := range info {
- ids = append(ids, it.WarehousingId)
- }
- }
- }
- warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids, storehouse_id, check_type)
- fmt.Println("ottal--------", total)
- houselist, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseList,
- "total": total,
- "houselist": houselist,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockManagerApiController) GetWarehouseInfoList() {
-
- id := c.GetString("id")
- idArray := strings.Split(id, ",")
- warehousing, err := service.FindWarehousingByIdOne(idArray)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- var ids []int64
-
- for _, item := range warehousing {
- ids = append(ids, item.ID)
- }
-
- warehousingInfo, err := service.FindWarehousingInfoByIdOne(ids)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "info": warehousingInfo,
- "warehousing": warehousing,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockManagerApiController) EditWarehouse() {
-
- // 开始外部循环的事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- warehousing_time := c.GetString("warehousing_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehouse, _ := service.FindNewWarehousingById(id, tx)
-
- warehousing := models.Warehousing{
- WarehousingOrder: warehouse.WarehousingOrder,
- OrgId: adminUserInfo.CurrentOrgId,
- Modifier: adminUserInfo.AdminUser.Id,
- Mtime: mtime,
- Status: 1,
- WarehousingTime: warehousingDate.Unix(),
- Type: warehouse.Type,
- StorehouseId: storehouse_id,
- }
-
- service.EditNewWarehousing(warehousing, tx)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingInfo []*models.WarehousingInfo
- var upDateWarehousingInfo []*models.WarehousingInfo
- if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["stockIn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
- utils.ErrorLog("warehousing_count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
- total := float64(warehousing_count) * price
- if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
- utils.ErrorLog("packing_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
- var productDates int64
- var expiryDates int64
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
- }
-
- }
-
- number, _ := items["number"].(string)
-
- remark, _ := items["remark"].(string)
-
- manufacturer := int64(items["manufacturer"].(float64))
- dealer := int64(items["dealer"].(float64))
- license_number, _ := items["license_number"].(string)
- register_number, _ := items["register_number"].(string)
- good_code, _ := items["good_code"].(string)
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if id == 0 {
- warehouseInfo := &models.WarehousingInfo{
- WarehousingOrder: warehouse.WarehousingOrder,
- WarehousingId: warehouse.ID,
- GoodId: good_id,
- Number: number,
- GoodTypeId: good_type_id,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- WarehousingCount: warehousing_count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- Dealer: dealer,
- StockCount: warehousing_count,
- LicenseNumber: license_number,
- PackingPrice: packing_price,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- RegisterNumber: register_number,
- GoodCode: good_code,
- }
- warehousingInfo = append(warehousingInfo, warehouseInfo)
-
- } else {
-
- warehouseInfo := &models.WarehousingInfo{
- ID: id,
- WarehousingOrder: warehouse.WarehousingOrder,
- WarehousingId: warehouse.ID,
- GoodId: good_id,
- Number: number,
- GoodTypeId: good_type_id,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- WarehousingCount: warehousing_count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- Dealer: dealer,
- LicenseNumber: license_number,
- PackingPrice: packing_price,
- StorehouseId: storehouse_id,
- RegisterNumber: register_number,
- GoodCode: good_code,
- }
- upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
-
- }
- }
- }
- }
- var errs error
- if len(warehousingInfo) > 0 {
-
- errs = service.CreateNewWarehousingInfo(warehousingInfo, tx)
- }
-
- if len(upDateWarehousingInfo) > 0 {
- for _, item := range upDateWarehousingInfo {
- if item.ID > 0 {
- service.UpdateNewWarehouseInfoByGoodIdOne(item, item.ID, tx)
- }
-
- }
- }
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- list, _ := service.GetNewAllStockInList(id, adminUserInfo.CurrentOrgId, tx)
- tx.Commit()
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "编辑成功",
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- })
-
- }
- func (c *StockManagerApiController) DeleteWarehouse() {
- ids := c.GetString("ids")
- if len(ids) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- idArray := strings.Split(ids, ",")
- err := service.DeleteWarehouse(idArray)
- //删除流水
- service.DeleteStockFlow(idArray)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (c *StockManagerApiController) DeleteWarehouseInfo() {
- id, _ := c.GetInt64("id", 0)
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- err := service.UpDateWarehouseStatus(id)
- service.UpdatedStockFlowById(id)
- //查询入库记录
- info, _ := service.GetWarehouseInfoByIdTwenty(id, orgId)
- //查询该机构默认仓库
- storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
- //查询剩余库存
- goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, orgId)
- var sum_count int64
- var sum_in_count int64
- for _, item := range goodList {
- sum_count += item.StockCount
- sum_in_count += item.WarehousingCount
- }
- service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
-
- func (c *StockManagerApiController) CreateSalesReturn() {
- dealer_id, _ := c.GetInt64("dealer_id", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- sales_return_time := c.GetString("time")
- types, _ := c.GetInt64("type", 0)
-
- salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
- ctime := time.Now().Unix()
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
- total = total + 1
- orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- salesReturn := models.SalesReturn{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: salesReturnDate.Unix(),
- Dealer: dealer_id,
- Manufacturer: manufacturer_id,
- Type: types,
- }
-
- service.AddSigleSalesReturn(&salesReturn)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var salesReturnInfos []*models.SalesReturnInfo
-
- if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["salesReturn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
- return_count, _ := items["return_count"].(string)
- if len(return_count) == 0 {
- utils.ErrorLog("len(return_count) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
-
- return
- }
-
- count, _ := strconv.ParseInt(return_count, 10, 64)
- price, _ := strconv.ParseFloat(items["price"].(string), 10)
- total := float64(count) * price
-
- salesReturnInfo := &models.SalesReturnInfo{
- OrderNumber: salesReturn.OrderNumber,
- SalesReturnId: salesReturn.ID,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Price: price,
- Total: total,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
-
- salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
-
- }
- }
- }
- errs := service.CreateSalesReturnInfo(salesReturnInfos)
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "退货成功",
- })
-
- }
- func (c *StockManagerApiController) GetSalesReturnList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": returnList,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
- func (this *StockManagerApiController) DeleteSalesReturn() {
- ids := this.GetString("ids")
-
- if len(ids) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- err := service.DeleteSalesReturn(idArray)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (this *StockManagerApiController) DeleteSalesReturnInfo() {
- id, _ := this.GetInt64("id", 0)
- fmt.Println(id)
- if id == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- err := service.UpDateSaleReturnStatus(id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
- func (this *StockManagerApiController) GetSalesReturnInfoList() {
- id, _ := this.GetInt64("id", 0)
- list, _ := service.FindAllSalesReturnInfoById(id)
- salesReturn, _ := service.FindAllSalesReturnById(id)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "salesReturn": salesReturn,
- })
-
- }
- func (c *StockManagerApiController) EditReturnInfo() {
- return_time := c.GetString("return_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
- dealer_id, _ := c.GetInt64("dealer_id", 0)
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- salesReturns, _ := service.FindSalesReturnById(id)
-
- sales := models.SalesReturn{
- ID: salesReturns.ID,
- Mtime: mtime,
- ReturnTime: returnDate.Unix(),
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
-
- service.EditSaleReturn(sales)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var returnInfos []*models.SalesReturnInfo
- var upDateReturnInfos []*models.SalesReturnInfo
-
- if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["salesReturn"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- if id == 0 {
- returnInfo := &models.SalesReturnInfo{
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: sales.OrderNumber,
- SalesReturnId: sales.ID,
- Mtime: time.Now().Unix(),
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
- returnInfos = append(returnInfos, returnInfo)
-
- } else {
- returnInfo := &models.SalesReturnInfo{
- ID: id,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: sales.OrderNumber,
- SalesReturnId: sales.ID,
- Mtime: time.Now().Unix(),
- Type: types,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- }
- upDateReturnInfos = append(upDateReturnInfos, returnInfo)
- }
- }
- }
- }
- var errs error
- if len(returnInfos) > 0 {
- errs = service.CreateSalesReturnInfo(returnInfos)
- }
-
- if len(upDateReturnInfos) > 0 {
- for _, item := range upDateReturnInfos {
- errs = service.UpDateSalesReturnInfo(item)
- }
- }
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "编辑成功",
- })
-
- }
-
- func (c *StockManagerApiController) CreateWarehouseOut() {
-
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- warehouseOut_id, _ := c.GetInt64("warehouseOut_id")
-
- ctime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehousing_out_time := c.GetString("warehousing_out_time")
- warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
-
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehouseOutTime: warehousingOutDate.Unix(),
- Type: types,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- // 开始外部循环的事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- if warehouseOut_id == 0 {
- //查询是否生成出库单
- warehouseOutObj, _ := service.FindStockOutByIsSysOne(adminUserInfo.CurrentOrgId, 0, operation_time, warehousing_out_order, tx)
-
- if warehouseOutObj.ID == 0 {
- service.AddSigleWarehouseOut(&warehouseOut, tx)
- }
-
- }
-
- if warehouseOut_id > 0 {
- service.UpdateSingleWarehoseOut(warehouseOut_id, storehouse_id, tx)
- }
-
- var warehousingOutInfo []*models.WarehouseOutInfo
-
- if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["stockOut"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- total_one := float64(count) * price
- remark := items["remark"].(string)
-
- manufacturer := int64(items["manufacturer"].(float64))
-
- dealer := int64(items["dealer"].(float64))
- number := items["number"].(string)
-
- expiry_date := items["expiry_date"].(string)
-
- warehouse_info_id := int64(items["warehouse_info_id"].(float64))
-
- admin_user_id := int64(items["admin_user_id"].(float64))
-
- if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
- utils.ErrorLog("buy_price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
-
- stock_count := items["stock_count"].(string)
-
- register_number := items["register_number"].(string)
-
- class_type := items["class_type"].(string)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var expiryDate int64
- if len(expiry_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiryDate = theTime.Unix()
- }
-
- product_date := items["product_date"].(string)
-
- var productDate int64
- if len(product_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", product_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- productDate = theTime.Unix()
- }
- license_number := items["license_number"].(string)
-
- patient_id := int64(items["patient_id"].(float64))
-
- warehouseOutInfo := &models.WarehouseOutInfo{
- ID: id,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Price: price,
- TotalPrice: total_one,
- Status: 1,
- Ctime: ctime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- Number: number,
- ExpiryDate: expiryDate,
- ProductDate: productDate,
- Dealer: dealer,
- LicenseNumber: license_number,
- WarehouseInfotId: warehouse_info_id,
- StorehouseId: storehouse_id,
- AdminUserId: admin_user_id,
- BuyPrice: buy_price,
- StockCount: stock_count,
- IsCheck: 2,
- RegisterNumber: register_number,
- SysRecordTime: warehouseOut.WarehouseOutTime,
- PatientId: patient_id,
- ClassType: class_type,
- }
- warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
-
- }
- }
- }
-
- goodWarehouseOut, _ := service.GetLastGoodWarehouseOutTwentyOne(adminUserInfo.CurrentOrgId, tx)
-
- if len(warehousingOutInfo) > 0 {
- for _, it := range warehousingOutInfo {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: goodWarehouseOut.ID,
- WarehouseInfotId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: it.Remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: it.Manufacturer,
- Dealer: it.Dealer,
- IsSys: 0,
- SysRecordTime: it.SysRecordTime,
- GoodTypeId: it.GoodTypeId,
- GoodId: it.GoodId,
- ExpiryDate: it.ExpiryDate,
- ProductDate: it.ProductDate,
- Number: it.Number,
- Price: it.Price,
- LicenseNumber: it.LicenseNumber,
- SupplyWarehouseId: 0,
- StorehouseId: storehouse_id,
- AdminUserId: it.AdminUserId,
- BuyPrice: it.BuyPrice,
- StockCount: it.StockCount,
- Count: it.Count,
- IsCheck: 2,
- RegisterNumber: it.RegisterNumber,
- PatientId: it.PatientId,
- ClassType: it.ClassType,
- }
- if it.ID == 0 {
-
- //查询改耗材是否出库
- outInfo, _ := service.GetGoodsIsExsit(it.GoodId, it.SysRecordTime, it.OrgId, goodWarehouseOut.ID, tx)
- if outInfo.ID == 0 {
- service.AddSigleWarehouseOutInfo(warehouseOutInfo, tx)
- }
-
- }
- if it.ID > 0 {
- service.ModifyWarehouseOutInfo(it.ID, warehouseOutInfo, tx)
- }
- }
- }
-
- appId := adminUserInfo.CurrentAppId
-
- warehouseOutInfoList, _ := service.GetLastGoodWarehouseOutInfo(adminUserInfo.CurrentOrgId, goodWarehouseOut.ID, tx)
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- doctorList, _ := service.GetAllDoctorListSix(adminUserInfo.CurrentOrgId, appId)
- tx.Commit()
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "good_name": "",
- "specification_name": "",
- "warehouseOut": goodWarehouseOut,
- "warehouseOutInfoList": warehouseOutInfoList,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "doctorList": doctorList,
- })
- return
- }
- func (c *StockManagerApiController) GetWarehouseOutList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
- storehouse_id, _ := c.GetInt64("storehouse_id")
- way_type, _ := c.GetInt64("way_type")
- check_type, _ := c.GetInt64("check_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- var ids []int64
- var goodids []int64
- if len(keywords) > 0 {
- //查询商品名称
- list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
- for _, item := range list {
- goodids = append(goodids, item.ID)
- }
-
- if len(goodids) > 0 {
- //出库详情但里面查询
- info, _ := service.GetWarehoureOrderOutByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId, storehouse_id)
- for _, it := range info {
- ids = append(ids, it.WarehouseOutId)
- }
- }
-
- }
- warehouseOutList, total, err := service.FindAllWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids, storehouse_id, way_type, check_type)
- houselist, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- patients, _ := service.GetAllpatient(adminUserInfo.CurrentOrgId)
- fmt.Println(err)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseOutList,
- "total": total,
- "houselist": houselist,
- "patients": patients,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockManagerApiController) DeleteWarehouseOut() {
- ids := c.GetString("ids")
-
- if len(ids) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
-
- err := service.DeleteWarehouseOut(idArray)
- //list, _ := service.GetWarehouseOutInfoByIds(idArray)
- //for _, item := range list {
- // //添加库存
- // service.UpdateWarehouseInfoById(item.WarehouseInfotId, item.Count)
- // //添加库存
- // //查询该机构默认仓库
- // storeConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- // //查询剩余库存
- // goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, item.OrgId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, item := range goodList {
- // sum_count += item.StockCount
- // sum_in_count += item.WarehousingCount
- // }
- // service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
- //}
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
- id, _ := this.GetInt64("id", 0)
- fmt.Println(id)
- if id == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- err := service.UpDateWarehouseOutStatus(id)
- //添加库存
- //out, _ := service.GetWarhouseOutById(id)
- //
- //service.UpdateWareInfoById(out.WarehouseInfotId, out.Count)
- //
- ////查询该机构默认仓库
- //storeConfig, _ := service.GetAllStoreHouseConfig(out.OrgId)
- ////查询剩余库存
- //goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, out.GoodId, out.OrgId)
- //var sum_count int64
- //var sum_in_count int64
- //for _, item := range goodList {
- // sum_count += item.StockCount
- // sum_in_count += item.WarehousingCount
- //}
- //service.UpdateGoodByGoodId(out.GoodId, sum_count, sum_in_count, out.OrgId)
- //
- //
- //service.UpdateStockFlowWarehouseOutById(id)
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
- func (c *StockManagerApiController) GetWarehouseOutInfoList() {
- id, _ := c.GetInt64("id", 0)
- warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
- warehouseOut, _ := service.FindWareHouseOutByIdOne(id)
- adminUserInfo := c.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- wareoutList, _ := service.GetWareOutInfoById(id, orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseOutInfo,
- "info": warehouseOut,
- "wareoutList": wareoutList,
- })
-
- }
- func (c *StockManagerApiController) EditWarehouseOut() {
-
- warehouse_out_time := c.GetString("warehouse_out_time")
- id, _ := c.GetInt64("id", 0)
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
-
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- // 开始外部循环的事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- warehouseOut, _ := service.FindWareHouseOutById(id, tx)
-
- tempWarehouseOut := models.WarehouseOut{
- ID: warehouseOut.ID,
- Mtime: mtime,
- WarehouseOutTime: warehouseOutDate.Unix(),
- StorehouseId: storehouse_id,
- }
-
- service.EditWarehouseOut(tempWarehouseOut, tx)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var warehousingOutInfo []*models.WarehouseOutInfo
- var upDateWarehouseOutInfos []*models.WarehouseOutInfo
-
- if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
- thisStockOut, _ := dataBody["stockOut"].([]interface{})
- if len(thisStockOut) > 0 {
- for _, item := range thisStockOut {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
-
- total := float64(count) * price
- remark := items["remark"].(string)
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
-
- manufacturer := int64(items["manufacturer"].(float64))
-
- dealer := int64(items["dealer"].(float64))
-
- number := items["number"].(string)
-
- license_number := items["license_number"].(string)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- expiry_date := items["expiry_date"].(string)
-
- var expiryDate int64
- if len(expiry_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiryDate = theTime.Unix()
- }
-
- product_date := items["product_date"].(string)
-
- warehouse_info_id := int64(items["warehouse_info_id"].(float64))
-
- admin_user_id := int64(items["admin_user_id"].(float64))
-
- //if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
- // utils.ErrorLog("buy_price")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- //}
- //buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
-
- stock_count := items["stock_count"].(string)
-
- register_number := items["register_number"].(string)
-
- patient_id := int64(items["patient_id"].(float64))
-
- class_type := items["class_type"].(string)
-
- var productDate int64
- if len(product_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", product_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- productDate = theTime.Unix()
- }
-
- if id == 0 {
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: warehouseOut.WarehouseOutTime,
- Mtime: time.Now().Unix(),
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- IsSys: 0,
- SysRecordTime: warehouseOut.WarehouseOutTime,
- Number: number,
- ExpiryDate: expiryDate,
- ProductDate: productDate,
- Dealer: dealer,
- Manufacturer: manufacturer,
- LicenseNumber: license_number,
- ConsumableType: 1,
- WarehouseInfotId: warehouse_info_id,
- StorehouseId: storehouse_id,
- AdminUserId: admin_user_id,
- StockCount: stock_count,
- RegisterNumber: register_number,
- PatientId: patient_id,
- ClassType: class_type,
- }
- warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
-
- } else {
- if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
- utils.ErrorLog("is_sys")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- is_sys := int64(items["is_sys"].(float64))
-
- if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
- utils.ErrorLog("sys_record_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- sys_record_time := int64(items["sys_record_time"].(float64))
-
- warehouseOutInfo := &models.WarehouseOutInfo{
- ID: id,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Price: price,
- TotalPrice: total,
- Status: 1,
- Ctime: warehouseOut.WarehouseOutTime,
- Remark: remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Mtime: time.Now().Unix(),
- Type: types,
- Manufacturer: manufacturer,
- IsSys: is_sys,
- SysRecordTime: sys_record_time,
- Number: number,
- ExpiryDate: expiryDate,
- ProductDate: productDate,
- Dealer: dealer,
- LicenseNumber: license_number,
- ConsumableType: 2,
- WarehouseInfotId: warehouse_info_id,
- StorehouseId: storehouse_id,
- AdminUserId: admin_user_id,
- StockCount: stock_count,
- RegisterNumber: register_number,
- PatientId: patient_id,
- ClassType: class_type,
- }
- upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
- }
- }
- }
- }
-
- var errs error
-
- //新增出库
- if len(warehousingOutInfo) > 0 {
-
- warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- for _, item := range warehousingOutInfo {
- //查询改耗材是否出库
- outInfo, _ := service.GetGoodsIsExsit(item.GoodId, item.SysRecordTime, item.OrgId, item.WarehouseOutId, tx)
- if outInfo.ID == 0 {
- service.AddSigleWarehouseOutInfo(item, tx)
- }
-
- }
- }
-
- if len(upDateWarehouseOutInfos) > 0 {
- for _, item := range upDateWarehouseOutInfos {
- if item.ID > 0 {
- service.UpDateWarehouseOutInfo(item, tx)
- }
-
- }
- }
-
- tx.Commit()
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- })
-
- }
-
- func (c *StockManagerApiController) CreateCancelStock() {
-
- cancel_stock_time := c.GetString("time")
- types, _ := c.GetInt64("type", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- cancel_stock_id, _ := c.GetInt64("cancel_stock_id")
- cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- ctime := time.Now().Unix()
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllCancelStockTotal(adminUserInfo.CurrentOrgId)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.CancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- ReturnTime: cancelStockDate.Unix(),
- Type: types,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
- if cancel_stock_id == 0 {
- service.AddSigleCancelStock(&cancelStock)
- } else {
- service.UpdateSigleCancelStock(cancel_stock_id, storehouse_id)
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var cancelStockInfos []*models.CancelStockInfo
- if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
- thisStockIn, _ := dataBody["cancelStock"].([]interface{})
- if len(thisStockIn) > 0 {
- for _, item := range thisStockIn {
- items := item.(map[string]interface{})
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- return_count, _ := items["return_count"].(string)
- if len(return_count) == 0 {
- utils.ErrorLog("len(return_count) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
-
- return
- }
-
- count, _ := strconv.ParseInt(return_count, 10, 64)
-
- number := items["number"].(string)
-
- register_account := items["register_account"].(string)
-
- manufacturer, _ := items["manufacturer"].(string)
-
- dealer, _ := items["dealer"].(string)
-
- warehouse_info_id := int64(items["warehouse_info_id"].(float64))
-
- var expiryDates int64
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
- }
-
- var productDates int64
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
-
- }
- }
-
- remark := items["remark"].(string)
-
- retail_prices := items["price"].(string)
- price, _ := strconv.ParseFloat(retail_prices, 64)
- cancelStockInfo := &models.CancelStockInfo{
- ID: id,
- OrderNumber: cancelStock.OrderNumber,
- CancelStockId: cancelStock.ID,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: types,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Number: number,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- RegisterAccount: register_account,
- Remark: remark,
- Price: price,
- WarehouseInfoId: warehouse_info_id,
- StorehouseId: storehouse_id,
- IsCheck: 2,
- }
- cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
-
- }
- }
- }
- lastCancelStock, _ := service.GetLastCancelStockById(adminUserInfo.CurrentOrgId)
- for _, item := range cancelStockInfos {
- item.CancelStockId = lastCancelStock.ID
- if item.ID == 0 {
- service.CreateCancelStockInfoOne(item)
- }
- if item.ID > 0 {
- service.ModifyCancelStockInfo(item.ID, item)
- }
- }
-
- list, _ := service.GetCancelStockInfo(lastCancelStock.ID, adminUserInfo.CurrentOrgId)
-
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
-
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
-
- // storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseId, item.OrgId)
- // goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- // info, _ := service.GetWarehoureOrderStockOutFlow(item.GoodId, item.OrgId, item.WarehouseInfoId, storehouse_id)
- // if item.Count > info.Count {
- // service.UpdateCancelInfo(item.CancelStockId)
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "good_name": goodObj.GoodName,
- // "specification_name": goodObj.SpecificationName,
- // "storehouse_name": storehouse.StorehouseName,
- // })
- // return
- // }
- //
- // //查询该批次入库的值
- // infolist, _ := service.GetWarehouseInfoByIdSeven(item.WarehouseInfoId)
- //
- // if item.Count > infolist.WarehousingCount {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "4",
- // "good_name": goodObj.GoodName,
- // "specification_name": goodObj.SpecificationName,
- // "storehouse_name": storehouse.StorehouseName,
- // })
- // return
- // }
- //
- // if item.Count <= infolist.WarehousingCount {
- // _, msgerrkonde := service.GetCancelStockDetailByOrderNumber(orderNumber, adminUserInfo.CurrentOrgId)
- // if msgerrkonde == gorm.ErrRecordNotFound {
- // service.AddSigleCancelStock(&cancelStock)
- // }
- // listcancel, _ := service.GetLastCancelStockById(adminUserInfo.CurrentOrgId)
- //
- // item.CancelStockId = listcancel.ID
- // errs := service.CreateCancelStockInfoOne(item)
- // list, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- //
- // var manufacturer_id int64
- //
- // for _, items := range list {
- // if item.Manufacturer == items.ManufacturerName {
- // manufacturer_id = items.ID
- // }
- // }
- // flow := models.VmStockFlow{
- // WarehousingId: 0,
- // GoodId: item.GoodId,
- // Number: item.Number,
- // LicenseNumber: "",
- // Count: item.Count,
- // UserOrgId: adminUserInfo.CurrentOrgId,
- // PatientId: 0,
- // SystemTime: time.Now().Unix(),
- // ConsumableType: 4,
- // IsSys: 0,
- // WarehousingOrder: "",
- // WarehouseOutId: 0,
- // WarehouseOutOrderNumber: "",
- // IsEdit: 0,
- // CancelStockId: cancelStock.ID,
- // CancelOrderNumber: cancelStock.OrderNumber,
- // Manufacturer: manufacturer_id,
- // Dealer: 0,
- // Creator: adminUserInfo.AdminUser.Id,
- // UpdateCreator: 0,
- // Status: 1,
- // Ctime: time.Now().Unix(),
- // Mtime: 0,
- // Price: item.Price,
- // WarehousingDetailId: 0,
- // WarehouseOutDetailId: 0,
- // CancelOutDetailId: 0,
- // ProductDate: item.ProductDate,
- // ExpireDate: item.ExpiryDate,
- // StorehouseId: item.StorehouseId,
- // }
- // cancelStockInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
- // flow.CancelStockId = cancelStockInfo.CancelStockId
- // flow.CancelOutDetailId = cancelStockInfo.ID
- // service.CreateStockFlowOne(flow)
- // if errs != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
- // return
- // }
- //
- // //查询该批次的剩余库存
- // wareouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
- // if (wareouseinfo.StockCount + item.Count) > wareouseinfo.WarehousingCount {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "5",
- // "good_name": goodObj.GoodName,
- // "specification_name": goodObj.SpecificationName,
- // "storehouse_name": storehouse.StorehouseName,
- // })
- // return
- // }
- // //更改入库数量
- // errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
- //
- // storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- // //查询剩余库存
- // goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range goodList {
- // sum_count += it.StockCount
- // sum_in_count += it.WarehousingCount
- // }
- // service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, adminUserInfo.CurrentOrgId)
- //
- // if err != nil {
- // utils.ErrorLog(err.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // }
- //}
-
- c.ServeSuccessJSON(map[string]interface{}{
- "cancelStock": lastCancelStock,
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- })
- return
-
- }
- func (c *StockManagerApiController) GetCancelStockInfoList() {
- id, _ := c.GetInt64("id", 0)
-
- cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
- info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
- manufacturerList, _ := service.GetAllManufacturerList(c.GetAdminUserInfo().CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(c.GetAdminUserInfo().CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": cancelStockInfoList,
- "info": info,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- })
-
- }
- func (c *StockManagerApiController) GetCancelStockList() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- types, _ := c.GetInt64("type", 0)
- keywords := c.GetString("keywords")
- storehouse_id, _ := c.GetInt64("storehouse_id")
- check_type, _ := c.GetInt64("check_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- returnList, total, err := service.FindAllCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, storehouse_id, check_type)
- houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": returnList,
- "total": total,
- "houseList": houseList,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
- func (this *StockManagerApiController) DeleteCancelStock() {
- ids := this.GetString("ids")
-
- if len(ids) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- idArray := strings.Split(ids, ",")
- ////获取
- //list, _ := service.GetCancelWarehosueInfo(idArray)
- //for _, item := range list {
- // info, _ := service.GetCancelStockById(item.WarehouseInfoId)
- // warehousingInfo := models.WarehousingInfo{
- // StockCount: info.Count,
- // }
- // //扣减库存
- // service.ModefyWarehouseInfoNight(warehousingInfo, info.WarehouseInfoId)
- //
- // //查询该机构默认仓库
- // storeConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
- // //查询剩余库存
- // goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, item.OrgId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, item := range goodList {
- // sum_count += item.StockCount
- // sum_in_count += item.WarehousingCount
- // }
- // service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
- //
- // //删除流水
- // service.UpdatedStockFlowByCancelId(info.ID, info.GoodId)
- //}
- //获取
- err := service.DeleteCancelStock(idArray)
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- }
- func (this *StockManagerApiController) DeleteCancelStockInfo() {
- id, _ := this.GetInt64("id", 0)
- //fmt.Println(id)
- if id == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ////改变库存
- //info, _ := service.GetCancelStockById(id)
- //
- //warehousingInfo := models.WarehousingInfo{
- // StockCount: info.Count,
- //}
- ////扣减库存
- //service.ModefyWarehouseInfoNight(warehousingInfo, info.WarehouseInfoId)
- //
- ////查询该机构默认仓库
- //storeConfig, _ := service.GetAllStoreHouseConfig(info.OrgId)
- ////查询剩余库存
- //goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, info.OrgId)
- //var sum_count int64
- //var sum_in_count int64
- //for _, item := range goodList {
- // sum_count += item.StockCount
- // sum_in_count += item.WarehousingCount
- //}
- //service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
-
- //删除详情
- err := service.UpDateCancleStockStatus(id)
- //删除流水
- //err = service.UpdatedStockFlowByCancelId(id, info.GoodId)
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
-
- }
- func (c *StockManagerApiController) EditCancelStock() {
- cancel_time := c.GetString("cancel_time")
- id, _ := c.GetInt64("id", 0)
- storehouse_id, _ := c.GetInt64("storehouse_id")
- if id == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ctime := time.Now().Unix()
- mtime := time.Now().Unix()
- adminUserInfo := c.GetAdminUserInfo()
-
- cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
-
- tempCancelStock := models.CancelStock{
- ID: cancelStock.ID,
- Mtime: mtime,
- ReturnTime: cancelDate.Unix(),
- StorehouseId: storehouse_id,
- }
-
- service.EditCancelStock(tempCancelStock)
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var cancelStockInfos []*models.CancelStockInfo
- var upDateCancelStockInfos []*models.CancelStockInfo
- var stockFlow []*models.VmStockFlow
- if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
- thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
- if len(thisCancelStock) > 0 {
- for _, item := range thisCancelStock {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- id := int64(items["id"].(float64))
- number := items["number"].(string)
-
- register_account := items["register_account"].(string)
-
- manufacturer, _ := items["manufacturer"].(string)
-
- dealer, _ := items["dealer"].(string)
-
- remark := items["remark"].(string)
-
- var productDates int64
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
- productDates = 0
- } else {
- if len(items["product_date"].(string)) == 0 {
- productDates = 0
-
- } else {
- productDate, _ := items["product_date"].(string)
- product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
- productDates = product_date.Unix()
-
- }
-
- }
- var expiryDates int64
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
- expiryDates = 0
- } else {
- if len(items["expiry_date"].(string)) == 0 {
- expiryDates = 0
-
- } else {
- expiryDate, _ := items["expiry_date"].(string)
- expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
- expiryDates = expiry_date.Unix()
-
- }
-
- }
-
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
- utils.ErrorLog("price")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- price, _ := strconv.ParseFloat(items["price"].(string), 64)
-
- warehouse_info_id := int64(items["warehouse_info_id"].(float64))
- if id == 0 {
- cancelStockInfo := &models.CancelStockInfo{
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: cancelStock.OrderNumber,
- CancelStockId: cancelStock.ID,
- Mtime: time.Now().Unix(),
- Number: number,
- RegisterAccount: register_account,
- Manufacturer: manufacturer,
- Dealer: dealer,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- Remark: remark,
- Price: price,
- WarehouseInfoId: warehouse_info_id,
- StorehouseId: storehouse_id,
- }
- cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
-
- flow := &models.VmStockFlow{
- WarehousingId: 0,
- GoodId: good_id,
- Number: number,
- LicenseNumber: "",
- Count: count,
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: 0,
- SystemTime: time.Now().Unix(),
- ConsumableType: 4,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 2,
- CancelStockId: cancelStock.ID,
- CancelOrderNumber: cancelStock.OrderNumber,
- Manufacturer: 0,
- Dealer: 0,
- Creator: adminUserInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: price,
- WarehousingDetailId: warehouse_info_id,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ProductDate: productDates,
- ExpireDate: expiryDates,
- StorehouseId: storehouse_id,
- }
-
- stockFlow = append(stockFlow, flow)
-
- } else {
- cancelStockInfo := &models.CancelStockInfo{
- ID: id,
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- Status: 1,
- Ctime: ctime,
- OrgId: adminUserInfo.CurrentOrgId,
- OrderNumber: cancelStock.OrderNumber,
- CancelStockId: cancelStock.ID,
- Mtime: time.Now().Unix(),
- Number: number,
- RegisterAccount: register_account,
- Manufacturer: manufacturer,
- Dealer: dealer,
- ProductDate: productDates,
- ExpiryDate: expiryDates,
- Remark: remark,
- Price: price,
- WarehouseInfoId: warehouse_info_id,
- StorehouseId: storehouse_id,
- }
- upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
-
- list, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
-
- var manufacuture_id int64
- for _, it := range list {
- if it.ManufacturerName == manufacturer {
- manufacuture_id = it.ID
- }
- }
-
- flow := &models.VmStockFlow{
- WarehousingId: 0,
- GoodId: good_id,
- Number: number,
- LicenseNumber: "",
- Count: count,
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: 0,
- SystemTime: time.Now().Unix(),
- ConsumableType: 4,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 2,
- CancelStockId: cancelStock.ID,
- CancelOrderNumber: cancelStock.OrderNumber,
- Manufacturer: manufacuture_id,
- Dealer: 0,
- Creator: adminUserInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: price,
- WarehousingDetailId: warehouse_info_id,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ProductDate: productDates,
- ExpireDate: expiryDates,
- StorehouseId: storehouse_id,
- }
-
- stockFlow = append(stockFlow, flow)
- }
- }
- }
- }
- var errs error
- for _, item := range cancelStockInfos {
- service.CreateCancelStockInfoOne(item)
- }
- if len(upDateCancelStockInfos) > 0 {
- for _, item := range upDateCancelStockInfos {
- service.ModifyCancelStockInfo(item.ID, item)
- }
- }
- //判断是否更改了仓库
- //if storehouse_id == cancelStock.ID {
- //
- // if len(cancelStockInfos) > 0 {
- //
- // for _, item := range cancelStockInfos {
- // //统计该耗材的出库数量
- // info, _ := service.GetWarehoureOrderStockOutFlow(item.GoodId, item.OrgId, item.WarehouseInfoId, storehouse_id)
- // storeObj, _ := service.FindStoreHouseByStorehouseId(storehouse_id, item.OrgId)
- // if item.Count > info.Count {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "storehouse_name": storeObj.StorehouseName,
- // })
- // return
- // }
- // //查询该批次入库的值
- // infolist, _ := service.GetWarehouseInfoByIdSix(item.WarehouseInfoId, storehouse_id)
- //
- // if item.Count > infolist.WarehousingCount {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "4",
- // "storehouse_name": storeObj.StorehouseName,
- // })
- // return
- // }
- //
- // if item.Count <= infolist.WarehousingCount {
- //
- // errs := service.CreateCancelStockInfo(cancelStockInfos)
- //
- // if errs != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
- // return
- // }
- //
- // //更改入库数量
- // errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
- //
- // //查询该机构默认仓库
- // storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- // //查询剩余库存
- // goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range goodList {
- // sum_count += it.StockCount
- // sum_in_count += it.WarehousingCount
- // }
- // service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, adminUserInfo.CurrentOrgId)
- //
- // break
- // }
- //
- // }
- //
- // if len(stockFlow) > 0 {
- // for _, itemcancel := range stockFlow {
- // //查询是否存在
- // stockInfo, errcode := service.IsExsitStockFlow(itemcancel.GoodId, itemcancel.CancelOrderNumber)
- // if errcode == gorm.ErrRecordNotFound {
- // service.CreateStockFlowSix(itemcancel)
- // } else {
- // flow := models.VmStockFlow{
- // Count: itemcancel.Count,
- // Manufacturer: itemcancel.Manufacturer,
- // Dealer: itemcancel.Dealer,
- // Price: itemcancel.Price,
- // ProductDate: itemcancel.ProductDate,
- // ExpireDate: itemcancel.ExpireDate,
- // StorehouseId: itemcancel.StorehouseId,
- // }
- // service.UpdateStockFlowThree(stockInfo.ID, flow)
- // }
- // }
- // }
- // }
- //
- // if len(upDateCancelStockInfos) > 0 {
- // for _, item := range upDateCancelStockInfos {
- //
- // var all_total int64
- // //获取该批次最后一套退库记录
- // info, _ := service.GetLastCancelInfo(item.WarehouseInfoId, item.GoodId)
- // //查询该批次总的退库数量
- // list, _ := service.GetAllCancelInfoById(item.WarehouseInfoId, item.GoodId)
- // for _, it := range list {
- // all_total += it.Count
- // }
- //
- // //比较退库库数量和最后一次退库库数据大小
- // //退库(加)
- // if item.Count > info.Count {
- // var total = item.Count - info.Count
- // errs = service.UpDateCancelStockInfo(item)
- //
- // warehouseinfo, _ := service.GetWarehouseInfoByIdSix(item.WarehouseInfoId, storehouse_id)
- // storeObj, _ := service.FindStoreHouseByStorehouseId(storehouse_id, item.OrgId)
- //
- // // 总退库数量大于入库数据
- // if all_total > warehouseinfo.StockCount {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "5",
- // "storehouse_name": storeObj.StorehouseName,
- // })
- // return
- // }
- // parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total)
- //
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- // break
- // }
- // }
- // //(减)
- // if item.Count < info.Count {
- // errs = service.UpDateCancelStockInfo(item)
- //
- // var total_count = info.Count - item.Count
- //
- // parseDateErr := service.UpdateWareInfoByIdSix(item.WarehouseInfoId, total_count)
- //
- // if parseDateErr != nil {
- // utils.ErrorLog(errs.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- // return
- // }
- //
- // }
- // if item.Count == info.Count {
- // errs = service.UpDateCancelStockInfo(item)
- //
- // }
- //
- // //查询该机构默认仓库
- // storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- // //查询剩余库存
- // goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
- // var sum_count int64
- // var sum_in_count int64
- // for _, it := range goodList {
- // sum_count += it.StockCount
- // sum_in_count += it.WarehousingCount
- // }
- // service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, adminUserInfo.CurrentOrgId)
- // }
- // }
- //
- // if len(stockFlow) > 0 {
- // for _, itemcancel := range stockFlow {
- //
- // //查询是否存在
- // stockInfo, errcode := service.IsExsitStockFlow(itemcancel.GoodId, itemcancel.CancelOrderNumber)
- // if errcode == gorm.ErrRecordNotFound {
- //
- // } else {
- // flow := models.VmStockFlow{
- // Count: itemcancel.Count,
- // Manufacturer: itemcancel.Manufacturer,
- // Dealer: itemcancel.Dealer,
- // Price: itemcancel.Price,
- // LicenseNumber: itemcancel.LicenseNumber,
- // Number: itemcancel.Number,
- // ExpireDate: itemcancel.ExpireDate,
- // ProductDate: itemcancel.ProductDate,
- // StorehouseId: itemcancel.StorehouseId,
- // }
- // service.UpdateStockFlowThree(stockInfo.ID, flow)
- // }
- // }
- // }
- //
- //}
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- })
-
- }
- func (this *StockManagerApiController) GetCancelStockConfig() {
- types, _ := this.GetInt64("type", 0)
- adminUserInfo := this.GetAdminUserInfo()
- warehouseOutInfoList, _ := service.FindAllWarehouseOutInfo(adminUserInfo.CurrentOrgId, types)
- this.ServeSuccessJSON(map[string]interface{}{
- "warehouseOutInfoList": warehouseOutInfoList,
- })
- }
-
- func (c *StockManagerApiController) GetQueryInfo() {
- page, _ := c.GetInt64("page", -1)
- limit, _ := c.GetInt64("limit", -1)
- keyword := c.GetString("keyword")
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- type_name, _ := c.GetInt64("type_name")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- adminUserInfo := c.GetAdminUserInfo()
- list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, startTime, endTime, type_name)
- info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
-
- infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId, "")
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "info": info,
- "infomationList": infomationList,
- "orgid": adminUserInfo.CurrentOrgId,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- func (c *StockManagerApiController) SearchWarehouse() {
- keywords := c.GetString("keywords")
- adminUserInfo := c.GetAdminUserInfo()
- warehouseList, total, err := service.FindAllWarehouseByKeyword(adminUserInfo.CurrentOrgId, 1, 10, keywords)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseList,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockManagerApiController) GetAllConfig() {
- adminUserInfo := c.GetAdminUserInfo()
- manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
- dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
- goodType, _ := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
- goodInfo, _ := service.FindAllGoodInfoTwo(adminUserInfo.CurrentOrgId)
-
- //获取所有仓库看列表
- list, _ := service.GetAllStoreHouseListThree(adminUserInfo.CurrentOrgId)
- //获取仓库配置列表
- configList, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- appId := c.GetAdminUserInfo().CurrentAppId
- doctorList, _ := service.GetAllDoctorListSix(adminUserInfo.CurrentOrgId, appId)
-
- patients, _ := service.GetAllpatientTwenty(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "manufacturer": manufacturer,
- "dealer": dealer,
- "goodType": goodType,
- "goodInfo": goodInfo,
- "list": list,
- "configlist": configList,
- "doctorList": doctorList,
- "patients": patients,
- })
- }
- func (this *StockManagerApiController) GetAllSalesReturnConfig() {
- types, _ := this.GetInt64("type", 0)
- adminUserInfo := this.GetAdminUserInfo()
- warehouseInfoList, _ := service.FindAllWarehouseInfo(adminUserInfo.CurrentOrgId, types)
- this.ServeSuccessJSON(map[string]interface{}{
- "warehouseInfoList": warehouseInfoList,
- })
- }
-
- func (this *StockManagerApiController) GetDetailInfo() {
-
- page, _ := this.GetInt64("page", 0)
- limit, _ := this.GetInt64("limit", 0)
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- types, _ := this.GetInt64("type", 0)
-
- keywords := this.GetString("keywords")
- manufacturer, _ := this.GetInt64("manufacturer", 0)
- order_type, _ := this.GetInt64("order_type", 0)
- dealer, _ := this.GetInt64("dealer", 0)
-
- storehouse_id, _ := this.GetInt64("storehouse_id")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- adminUserInfo := this.GetAdminUserInfo()
-
- var list []*models.WarehousingInfo
- var list1 []*models.WarehouseOutInfo
- var list2 []*models.SalesReturnInfo
- var list3 []*models.CancelStockInfo
-
- var total int64
- var err error
- var total_price float64
- houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- patientsList, _ := service.GetAllpatient(adminUserInfo.CurrentOrgId)
- if types == 1 {
- list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
- _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "total_price": total_price,
- "houseList": houseList,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "patientsList": patientsList,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- } else if types == 2 {
- list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
- _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list1,
- "total": total,
- "total_price": total_price,
- "houseList": houseList,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "patientsList": patientsList,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- } else if types == 3 {
- list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list2,
- "total": total,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "patientsList": patientsList,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- } else if types == 4 {
- list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
- listGroup, err := service.FindeCancelGroup(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer, storehouse_id)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list3,
- "total": total,
- "listgroup": listGroup,
- "houseList": houseList,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "patientsList": patientsList,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- }
-
- func (this *StockManagerApiController) GetUserDetailInfo() {
- order_id, _ := this.GetInt64("id")
- if order_id <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := this.GetAdminUserInfo()
- userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": userDetails,
- "total": total,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
-
- func (this *StockManagerApiController) PostSearchStock() {
-
- keyword := this.GetString("keyword")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- stock, err := service.PostSearchStock(keyword, orgId)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "stock": stock,
- })
- }
-
- func (this *StockManagerApiController) GetOutStockTotalCount() {
-
- warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
- adminUserInfo := this.GetAdminUserInfo()
- stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "stockCount": stockCount,
- })
- }
-
- func (this *StockManagerApiController) AddGoodInformation() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- return
- }
- utils.ErrorLog("%v", dataBody)
- var goods []*models.GoodInfo
- var total_goods []interface{}
- tempGoods := dataBody["goods"].([]interface{})
-
- total_goods = tempGoods
- for index, goodMap := range tempGoods {
- goodNameM := goodMap.(map[string]interface{})
-
- var good models.GoodInfo
-
- if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- return
- }
-
- good_name, _ := goodNameM["good_name"].(string)
- if len(good_name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.GoodName = good_name
-
- // 获取数据字典数据
- var good_kind_id int64
- var name = "耗材种类"
- config, _ := service.GetDrugDataConfig(0, name)
-
- good_kind := goodNameM["good_kind"].(string)
-
- if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- if len(good_kind) != 0 {
- _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
- lastConfig, _ := service.GetLastDicConfig(config.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: config.ID,
- Module: "system",
- OrgId: orgId,
- Name: good_kind,
- FieldName: "",
- Value: lastConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUserInfo.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- if errcodegoodkind == gorm.ErrRecordNotFound {
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
- for _, it := range dataConfig {
- if good_kind == it.Name {
- fmt.Println(it.Name)
- good_kind_id = int64(it.Value)
- }
- }
- good.GoodKind = good_kind_id
-
- good_type := goodNameM["type_name"].(string)
- if len(good_type) == 0 {
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材类型不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- if len(good_type) != 0 {
- _, errcodegoodtype := service.GetGoodType(good_type, orgId)
- if errcodegoodtype == gorm.ErrRecordNotFound {
- goodsType := models.GoodsType{
- TypeName: good_type,
- Remark: "",
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Creater: adminUserInfo.AdminUser.Id,
- Modifier: 0,
- OrgId: adminUserInfo.CurrentOrgId,
- Status: 1,
- Type: 0,
- Number: 0,
- OutStock: 0,
- StockAttribute: 1,
- }
- service.CreatedGoodType(&goodsType)
- }
- }
-
- goodType, _ := service.GetAllGoodType(orgId)
- var good_type_id int64
- for _, it := range goodType {
- if good_type == it.TypeName {
- good_type_id = it.ID
- }
- }
- good.GoodTypeId = good_type_id
-
- medical_insurance_level := goodNameM["medical_insurance_level"].(string)
- if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var medical_insurance_id int64
- var medicalInsurance = "医保等级"
- medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
-
- if len(medical_insurance_level) != 0 {
- _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
- if errcodemedicalInsurance == gorm.ErrRecordNotFound {
- mediConfigOne, _ := service.GetLastDicConfig(medicalInsuranceDataConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: medicalInsuranceDataConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: medical_insurance_level,
- FieldName: "",
- Value: mediConfigOne.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUserInfo.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
- for _, it := range medicalInsuranceList {
- if medical_insurance_level == it.Name {
- medical_insurance_id = int64(it.Value)
- }
- }
- good.MedicalInsuranceLevel = medical_insurance_id
-
- if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- return
- }
- specification_name := goodNameM["specification_name"].(string)
- if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.SpecificationName = specification_name
-
- var manufacturer_id int64
- manufacturer := goodNameM["manufacturer"].(string)
- if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- if len(manufacturer) != 0 {
- _, errcodes := service.GetManufacturerName(orgId, manufacturer)
- manu := models.Manufacturer{
- ManufacturerName: manufacturer,
- Status: 1,
- OrgId: orgId,
- Creater: adminUserInfo.AdminUser.Id,
- }
- if errcodes == gorm.ErrRecordNotFound {
-
- service.CreateManufacturer(&manu)
-
- }
- }
-
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- for _, it := range manufacturerList {
- if manufacturer == it.ManufacturerName {
- manufacturer_id = it.ID
- }
- }
-
- good.Manufacturer = manufacturer_id
-
- if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
- utils.ErrorLog("unit_id")
- return
- }
-
- unit_id := int64(goodNameM["unit_id"].(float64))
- if unit_id <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.GoodUnit = unit_id
-
- default_count := int64(goodNameM["default_count"].(float64))
- if default_count == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "默认单次用量不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.DefaultCount = default_count
-
- default_count_unit := goodNameM["default_count_unit"].(string)
- if len(default_count_unit) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "默认单次用量单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.DefaultCountUnit = default_count_unit
-
- retail_prices := goodNameM["retail_price"].(string)
- retail_price, _ := strconv.ParseFloat(retail_prices, 64)
-
- if retail_price <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的价格不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.RetailPrice = retail_price
-
- buy_prices := goodNameM["buy_price"].(string)
- buy_price, _ := strconv.ParseFloat(buy_prices, 64)
-
- if buy_price <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.BuyPrice = buy_price
-
- if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
- utils.ErrorLog("stock_warn_count")
- return
- }
-
- stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
- if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- good.StockWarnCount = stock_warn_count
-
- var dealer_id int64
- dealerName := goodNameM["dealer"].(string)
-
- fmt.Println("经销商", dealerName)
- dealer := models.Dealer{
- OrgId: orgId,
- Status: 1,
- DealerName: dealerName,
- Creater: adminUserInfo.AdminUser.Id,
- Ctime: time.Now().Unix(),
- }
- if len(dealerName) != 0 {
- _, errcodedealer := service.GetDealerByName(orgId, dealerName)
-
- if errcodedealer == gorm.ErrRecordNotFound {
- service.CreateDealer(&dealer)
- }
- }
-
- dealerList, _ := service.GetAllDealerList(orgId)
- for _, it := range dealerList {
- if dealerName == it.DealerName {
- dealer_id = it.ID
- }
- }
-
- good.Dealer = dealer_id
- if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
- utils.ErrorLog("pinyin")
- return
- }
- pinyin := goodNameM["pinyin"].(string)
-
- good.Pinyin = pinyin
-
- if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
- utils.ErrorLog("wubi")
- return
- }
- wubi := goodNameM["wubi"].(string)
-
- good.Wubi = wubi
-
- if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
- utils.ErrorLog("social_security_directory_code")
- return
- }
- social_security_directory_code := goodNameM["social_security_directory_code"].(string)
-
- good.SocialSecurityDirectoryCode = social_security_directory_code
-
- if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
- utils.ErrorLog("is_special_diseases")
- return
- }
-
- is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
- good.IsSpecialDiseases = is_special_diseases
-
- if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
- utils.ErrorLog("is_record")
- return
- }
-
- is_record := int64(goodNameM["is_record"].(float64))
- good.IsRecord = is_record
-
- if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
- utils.ErrorLog("good_status")
- return
- }
- good_status := goodNameM["good_status"].(string)
- good.GoodStatus = good_status
-
- if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
- utils.ErrorLog("medical_insurance_number")
- return
- }
- medical_insurance_number := goodNameM["medical_insurance_number"].(string)
- good.MedicalInsuranceNumber = medical_insurance_number
-
- if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
- utils.ErrorLog("production_type")
- return
- }
- production_type := goodNameM["production_type"].(string)
- good.ProductionType = production_type
-
- if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
- utils.ErrorLog("remark")
- return
- }
- remark := goodNameM["remark"].(string)
- good.Remark = remark
-
- statistics_category := goodNameM["statistics_category"].(string)
-
- var categoryName = "统计分类"
- var statistic_id int64
- drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
-
- if len(statistics_category) != 0 {
- _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
-
- if errcodecagegory == gorm.ErrRecordNotFound {
- dicConfigThree, _ := service.GetLastDicConfig(drugDataConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: drugDataConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: statistics_category,
- FieldName: "",
- Value: dicConfigThree.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUserInfo.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
-
- for _, it := range parentDataConfig {
- if statistics_category == it.Name {
- statistic_id = int64(it.Value)
- }
- }
-
- good.StatisticsCategory = statistic_id
-
- special_medical := goodNameM["special_medical"].(string)
- good.SpecialMedical = special_medical
-
- packing_unit := goodNameM["good_unit"].(string)
- good.PackingUnit = packing_unit
-
- number := goodNameM["number"].(string)
- good.Number = number
-
- register_number := goodNameM["register_number"].(string)
- good.RegisterNumber = register_number
-
- goods = append(goods, &good)
-
- }
-
- export_time := time.Now().Unix()
- errLogs, _ := service.FindPatientExportLogTwo(this.GetAdminUserInfo().CurrentOrgId, export_time)
- if len(goods) > 0 {
-
- for _, item := range goods {
- hans := item.GoodName // 要转换的汉字字符串
- // 创建一个拼音转换器
- p := pinyin.NewArgs()
-
- // 将汉字转为拼音
- pinyinSlice := pinyin.Pinyin(hans, p)
-
- // 输出拼音
- fmt.Println("Pinyin:", pinyinSlice)
-
- // 获取首字母
- firstLetter := ""
- for _, py := range pinyinSlice {
- if len(py) > 0 {
- firstLetter += string(py[0][0])
- }
- }
-
- item.FirstLetter = firstLetter
- goodInfo := models.GoodInfo{
- GoodName: item.GoodName,
- SpecificationName: item.SpecificationName,
- GoodKind: item.GoodKind,
- GoodTypeId: item.GoodTypeId,
- Dealer: item.Dealer,
- GoodUnit: item.GoodUnit,
- IsRecord: item.IsRecord,
- IsSpecialDiseases: item.IsSpecialDiseases,
- Manufacturer: item.Manufacturer,
- Pinyin: item.Pinyin,
- GoodStatus: item.GoodStatus,
- ProductionType: item.ProductionType,
- Remark: item.Remark,
- RetailPrice: item.RetailPrice,
- SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
- SpecialMedical: item.SpecialMedical,
- Wubi: item.Wubi,
- StockWarnCount: item.StockWarnCount,
- MedicalInsuranceLevel: item.MedicalInsuranceLevel,
- OrgId: orgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- StatisticsCategory: item.StatisticsCategory,
- GoodCode: item.GoodCode,
- BuyPrice: item.BuyPrice,
- MedicalInsuranceNumber: item.MedicalInsuranceNumber,
- IsUser: 2,
- PackingUnit: item.PackingUnit,
- PackingPrice: item.RetailPrice,
- IsWarehouse: 1,
- DefaultCount: item.DefaultCount,
- DefaultCountUnit: item.DefaultCountUnit,
- FirstLetter: item.FirstLetter,
- RegisterNumber: item.RegisterNumber,
- Number: item.Number,
- }
-
- //查询同种耗材名称同种类型同种规格的耗材是否存在
- _, errcodegood := service.GetGoodsInformaitonIsExist(item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
-
- if errcodegood == gorm.ErrRecordNotFound {
- service.CreateGoodsInfomation(&goodInfo)
- } else if errcodegood == nil {
- service.UpdateGoodsInformation(&goodInfo, item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
- }
-
- log := models.ExportLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_goods)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(goods)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_goods),
- "success_num": len(goods),
- "fail_num": int64(len(errLogs)),
- })
- }
- } else {
- log := models.ExportLog{
- LogType: 5,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_goods)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(goods)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_goods),
- "success_num": len(goods),
- "fail_num": int64(len(errLogs)),
- })
- }
- }
-
- func (this *StockManagerApiController) AddDrugInformation() {
- adminUser := this.GetAdminUserInfo()
- orgId := adminUser.CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- return
- }
- utils.ErrorLog("%v", dataBody)
- var drugList []*models.BaseDrugLib
- var total_goods []interface{}
- tempDrugs := dataBody["drugs"].([]interface{})
-
- total_goods = tempDrugs
- for index, drugMap := range tempDrugs {
-
- goodNameM := drugMap.(map[string]interface{})
- var drug models.BaseDrugLib
- if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
- utils.ErrorLog("drug_name")
- return
- }
-
- drug_name, _ := goodNameM["drug_name"].(string)
- if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DrugName = drug_name
-
- dose_unit := goodNameM["dose_unit"].(string)
- drug.DoseUnit = dose_unit
-
- if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
- utils.ErrorLog("min_number")
- return
- }
- min_number, _ := goodNameM["min_number"].(string)
- minNumber, _ := strconv.ParseInt(min_number, 10, 64)
- if len(min_number) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.MinNumber = minNumber
-
- min_unit := goodNameM["min_unit"].(string)
- if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.MinUnit = min_unit
-
- max_unit_id := goodNameM["max_unit"].(string)
- if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.MaxUnit = max_unit_id
-
- max_unit := goodNameM["max_unit"].(string)
- if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.MaxUnit = max_unit
-
- drug_type := goodNameM["drug_type"].(string)
- if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var drug_type_id int64
- var drugType = "药品类型"
-
- drugconfig, _ := service.GetDrugDataConfig(0, drugType)
- if len(drug_type) != 0 {
- _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
- if errcodes == gorm.ErrRecordNotFound {
- //获取该型号最后一条数据型号
- config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
-
- dataconfig := models.DictDataconfig{
- ParentId: drugconfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_type,
- FieldName: "",
- Value: config.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
- for _, it := range drugTypeList {
- if drug_type == it.Name {
- drug_type_id = int64(it.Value)
- }
- }
-
- drug.DrugType = drug_type_id
-
- drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
- if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DrugStockLimit = drug_stock_limit
-
- drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
- if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DrugOriginPlace = drug_origin_place
-
- drug_dosage_form := goodNameM["drug_dosage_form"].(string)
-
- if len(drug_dosage_form) == 0 {
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var drug_dosage = "药品剂型"
- var drug_dosage_form_id int64
- drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
- if len(drug_dosage_form) != 0 {
- _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
- if errcodess == gorm.ErrRecordNotFound {
- configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: drugDosageconfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_dosage_form,
- FieldName: "",
- Value: configOne.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
- for _, it := range drugDosageList {
- if drug_dosage_form == it.Name {
- drug_dosage_form_id = int64(it.Value)
- }
- }
-
- drug.DrugDosageForm = drug_dosage_form_id
-
- retail_prices := goodNameM["retail_price"].(string)
- retail_price, _ := strconv.ParseFloat(retail_prices, 64)
-
- if retail_price <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.RetailPrice = retail_price
-
- last_prices := goodNameM["last_price"].(string)
- last_price, _ := strconv.ParseFloat(last_prices, 64)
- if last_price <= 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.LastPrice = last_price
-
- drug_classify := goodNameM["drug_classify"].(string)
-
- if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- var drugClassify = "药物分类"
- var drug_classify_id int64
- drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
-
- if len(drug_classify) != 0 {
- _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
- if errcodesClass == gorm.ErrRecordNotFound {
- drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: drugClassifyConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_classify,
- FieldName: "",
- Value: drugClassConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
- for _, it := range drugClassList {
- if drug_classify == it.Name {
- drug_classify_id = int64(it.Value)
- }
- }
-
- drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
- drug_dose := goodNameM["drug_dose"].(string)
-
- if len(drug_dose) == 0 {
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
- drug.DrugDose = drugDoses
-
- var units = "单位"
- var unit_id int64
-
- drugDoseUnit := goodNameM["drug_dose_unit"].(string)
-
- if len(drugDoseUnit) == 0 {
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- dataConfig, _ := service.GetDataConfigIsExist(0, units)
- if len(drugDoseUnit) != 0 {
- _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
- if errcodedataconfig == gorm.ErrRecordNotFound {
- childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
- dataconfig := models.Dataconfig{
- ParentId: dataConfig.ID,
- Module: "hemodialysis",
- OrgId: orgId,
- Name: drugDoseUnit,
- FieldName: "",
- Value: childConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- FieldType: 0,
- }
- service.CreateDataConfig(&dataconfig)
- }
- }
- list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
- for _, it := range list {
- if drugDoseUnit == it.Name {
- unit_id = int64(it.Value)
- }
- }
- drug.DrugDoseUnit = unit_id
-
- manufacturer := goodNameM["manufacturer"].(string)
- if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- if len(manufacturer) != 0 {
- _, errcodema := service.GetManufacturerName(orgId, manufacturer)
- if errcodema == gorm.ErrRecordNotFound {
- manufactur := models.Manufacturer{
- OrgId: orgId,
- Status: 1,
- ManufacturerName: manufacturer,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- }
- service.CreateManufacturer(&manufactur)
- }
- }
-
- var manufacturer_id int64
-
- manufacturList, _ := service.GetAllManufacturerList(orgId)
- for _, it := range manufacturList {
- if manufacturer == it.ManufacturerName {
- manufacturer_id = it.ID
- }
- }
-
- drug.Manufacturer = manufacturer_id
-
- dealer := goodNameM["dealer"].(string)
- if len(dealer) != 0 {
- _, errcodesdealer := service.GetDealerByName(orgId, dealer)
- if errcodesdealer == gorm.ErrRecordNotFound {
- dealerconfig := models.Dealer{
- DealerName: dealer,
- Status: 1,
- OrgId: orgId,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- }
- service.CreateDealer(&dealerconfig)
- }
- }
-
- var dealer_id int64
- dealerList, _ := service.GetAllDealerList(orgId)
- for _, it := range dealerList {
- if dealer == it.DealerName {
- dealer_id = it.ID
- }
- }
- drug.Dealer = dealer_id
-
- delivery_way := goodNameM["delivery_way"].(string)
- if len(delivery_way) == 0 {
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认给药途径不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DeliveryWay = delivery_way
-
- execution_frequency := goodNameM["execution_frequency"].(string)
-
- if len(execution_frequency) == 0 {
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.ExecutionFrequency = execution_frequency
-
- prescribing_number := goodNameM["prescribing_number"].(float64)
-
- if prescribing_number == 0 {
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认开药数量不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- drug.PrescribingNumber = prescribing_number
-
- prescribing_number_unit := goodNameM["prescribing_number_unit"].(string)
-
- if len(prescribing_number_unit) == 0 {
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认开药数量单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.PrescribingNumberUnit = prescribing_number_unit
-
- drug_day := goodNameM["drug_day"].(string)
-
- if len(drug_day) == 0 {
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的天数不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.DrugDay = drug_day
-
- lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
-
- drug.LmtUsedFlag = lmt_used_flags
-
- if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
- utils.ErrorLog("drug_alias")
- return
- }
-
- drug_alias, _ := goodNameM["drug_alias"].(string)
-
- drug.DrugAlias = drug_alias
-
- drug_category := goodNameM["drug_category"].(string)
-
- var drugCategory = "药品类别"
- var drug_category_id int64
-
- drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
-
- if len(drug_category) != 0 {
- _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
- if drugcategoryerrcodes == gorm.ErrRecordNotFound {
- drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: drugCategoryConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: drug_category,
- FieldName: "",
- Value: drugCategoryConfigSix.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
- for _, it := range drugCategoryList {
- if drug_category == it.Name {
- drug_category_id = int64(it.Value)
- }
- }
-
- drug.DrugCategory = drug_category_id
-
- statistics_category := goodNameM["statistics_category"].(string)
-
- var statisticsCategory = "统计分类"
- var statistics_category_id int64
-
- statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
- if len(statistics_category) != 0 {
- _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
- if errcodestatistc == gorm.ErrRecordNotFound {
- staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: statistcConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: statistics_category,
- FieldName: "",
- Value: staConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
-
- }
-
- statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
- for _, it := range statisticsCategoryList {
- if statistics_category == it.Name {
- statistics_category_id = int64(it.Value)
- }
- }
- drug.StatisticsCategory = statistics_category_id
-
- hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
- drug.HospApprFlag = hosp_appr_flag
- medical_insurance_number := goodNameM["medical_insurance_number"].(string)
- drug.MedicalInsuranceNumber = medical_insurance_number
-
- pharmacology_category := goodNameM["pharmacology_category"].(string)
-
- var pharmacology = "药理分类"
- var pharmacology_category_id int64
- pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
- if len(pharmacology_category) != 0 {
- _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
- if errcodespharmacology == gorm.ErrRecordNotFound {
- dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
- dataconfig := models.DictDataconfig{
- ParentId: pharmacologyConfig.ID,
- Module: "system",
- OrgId: orgId,
- Name: pharmacology_category,
- FieldName: "",
- Value: dicConfig.Value + 1,
- CreatedTime: "",
- UpdatedTime: "",
- CreateUserId: adminUser.AdminUser.Id,
- Status: 1,
- Remark: "",
- DeleteIdSystem: 0,
- Title: "",
- Content: "",
- Order: 0,
- Code: "",
- }
- service.CreatedDicConfig(&dataconfig)
- }
- }
-
- pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
- for _, it := range pharmacologyList {
- if pharmacology_category == it.Name {
- pharmacology_category_id = int64(it.Value)
- }
- }
- drug.PharmacologyCategory = pharmacology_category_id
-
- code := goodNameM["code"].(string)
- drug.Code = code
- is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
- drug.IsSpecialDiseases = is_special_diseases
- is_record := int64(goodNameM["is_record"].(float64))
- drug.IsRecord = is_record
- prescription_mark := int64(goodNameM["prescription_mark"].(float64))
- drug.PrescriptionMark = prescription_mark
- social_security_directory_code := goodNameM["social_security_directory_code"].(string)
- drug.SocialSecurityDirectoryCode = social_security_directory_code
- record_date := goodNameM["record_date"].(string)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- drug.RecordDate = theTime.Unix()
- drug_remark := goodNameM["drug_remark"].(string)
- drug.DrugRemark = drug_remark
- drug_status := goodNameM["drug_status"].(string)
- drug.DrugStatus = drug_status
- limit_remark := goodNameM["limit_remark"].(string)
- drug.LimitRemark = limit_remark
- min_prices := goodNameM["min_price"].(string)
- min_price, _ := strconv.ParseFloat(min_prices, 64)
- drug.MinPrice = min_price
- dose := goodNameM["dose"].(string)
-
- //is_self_drug := int64(goodNameM["is_self_drug"].(float64))
- //
- //drug.IsSelfDrug = is_self_drug
-
- if len(dose) < 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- drug.Dose = dose
-
- if len(dose) < 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: time.Now().Unix(),
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- drugList = append(drugList, &drug)
- }
- export_time := time.Now().Unix()
- errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
-
- if len(drugList) > 0 {
- for _, item := range drugList {
- hans := item.DrugName // 要转换的汉字字符串
- // 创建一个拼音转换器
- p := pinyin.NewArgs()
-
- // 将汉字转为拼音
- pinyinSlice := pinyin.Pinyin(hans, p)
-
- // 输出拼音
- fmt.Println("Pinyin:", pinyinSlice)
-
- // 获取首字母
- firstLetter := ""
- for _, py := range pinyinSlice {
- if len(py) > 0 {
- firstLetter += string(py[0][0])
- }
- }
-
- item.FirstLetter = firstLetter
- item.Pinyin = firstLetter
- goodInfo := models.BaseDrugLib{
- DrugName: item.DrugName,
- DrugAlias: item.DrugAlias,
- DrugSpec: item.DrugSpec,
- DrugType: item.DrugType,
- DrugStockLimit: item.DrugStockLimit,
- DrugOriginPlace: item.DrugOriginPlace,
- DrugDosageForm: item.DrugDosageForm,
- MedicalInsuranceLevel: item.MedicalInsuranceLevel,
- MaxUnit: item.MaxUnit,
- MinUnit: item.MinUnit,
- UnitMatrixing: item.UnitMatrixing,
- RetailPrice: item.RetailPrice,
- LastPrice: item.LastPrice,
- DrugClassify: item.DrugClassify,
- Manufacturer: item.Manufacturer,
- Dealer: item.Dealer,
- OrgId: orgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Pinyin: item.Pinyin,
- Wubi: item.Wubi,
- DrugAliasPinyin: item.DrugAliasPinyin,
- DrugAliasWubi: item.DrugAliasWubi,
- DrugControl: item.DrugControl,
- Number: item.Number,
- HospApprFlag: item.HospApprFlag,
- MedicalInsuranceNumber: item.MedicalInsuranceNumber,
- PharmacologyCategory: item.PharmacologyCategory,
- StatisticsCategory: item.StatisticsCategory,
- Code: item.Code,
- IsSpecialDiseases: item.IsSpecialDiseases,
- IsRecord: item.IsRecord,
- PrescriptionMark: item.PrescriptionMark,
- SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
- RecordDate: item.RecordDate,
- DrugRemark: item.DrugRemark,
- DrugStatus: item.DrugStatus,
- LimitRemark: item.LimitRemark,
- DrugCategory: item.DrugCategory,
- DrugDose: item.DrugDose,
- SingleDose: item.DrugDose,
- DrugDoseUnit: item.DrugDoseUnit,
- LmtUsedFlag: item.LmtUsedFlag,
- DrugDay: item.DrugDay,
- DeliveryWay: item.DeliveryWay,
- ExecutionFrequency: item.ExecutionFrequency,
- DoseUnit: item.DoseUnit,
- Dose: item.Dose,
- MinNumber: item.MinNumber,
- IsUse: 2,
- MinPrice: item.MinPrice,
- PrescribingNumber: item.PrescribingNumber,
- PrescribingNumberUnit: item.PrescribingNumberUnit,
- FirstLetter: item.FirstLetter,
- IsSelfDrug: item.IsSelfDrug,
- }
-
- //查询同种药品同种规格是否存在
- _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.DoseUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
-
- if drugerror == gorm.ErrRecordNotFound {
- service.CreateDrugsInfomation(&goodInfo)
- } else if drugerror == nil {
- service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
- }
- log := models.ExportLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_goods)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(drugList)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_goods),
- "success_num": len(drugList),
- "fail_num": int64(len(errLogs)),
- })
- }
- } else {
- log := models.ExportLog{
- LogType: 4,
- UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_goods)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(drugList)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_goods),
- "success_num": len(drugList),
- "fail_num": int64(len(errLogs)),
- })
- }
-
- }
-
- func (this *StockManagerApiController) GetInitializtion() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- var drugCategory = "药品类别"
- var drugType = "药品类型"
- var drugDosageForm = "药品剂型"
- var medicalInsuranceLevel = "医保等级"
- var drugControl = "开药控制"
- var drugClassify = "药物分类"
- var statisticsCategory = "统计分类"
- var pharmacologyCategory = "药理分类"
- var goodKind = "耗材种类"
- var tubeColor = "试管颜色"
- var costClassify = "费用类别"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
-
- drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
- drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
-
- drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
- drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
-
- medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
- medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
-
- drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
- drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
-
- drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
- drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
-
- statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
- statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
-
- pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
- pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
-
- goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
- goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
-
- tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
- tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
-
- costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
- costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "drugCategoryList": drugCategoryList,
- "drugTypeList": drugTypeList,
- "drugDosageFormList": drugDosageFormList,
- "medicalInsuranceLevelList": medicalInsuranceLevelList,
- "drugControlList": drugControlList,
- "drugClassifyList": drugClassifyList,
- "statisticsCategoryList": statisticsCategoryList,
- "pharmacologyCategoryList": pharmacologyCategoryList,
- "goodKindList": goodKindList,
- "tubeColorList": tubeColorList,
- "costClassifyList": costClassifyList,
- })
- }
-
- func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- list, _ := service.GetWarehouseOrderInfoList(orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) PostSearchGoodList() {
-
- keyword := this.GetString("keyword")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- storehouse_id, _ := this.GetInt64("storehouse_id")
- list, _ := service.GetSearchGoodListSix(keyword, orgId, storehouse_id)
-
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- })
- }
-
- func (this *StockManagerApiController) GetAllStockList() {
-
- page, _ := this.GetInt64("page", -1)
- limit, _ := this.GetInt64("limit", -1)
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- types, _ := this.GetInt64("type", 0)
- keywords := this.GetString("keywords")
- good_id, _ := this.GetInt64("good_id")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
-
- list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId, good_id, storehouse_id)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "manufacturerList": manufacturerList,
- })
- }
-
- func (this *StockManagerApiController) GetStockListById() {
-
- id, _ := this.GetInt64("id")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- start_first_time := this.GetString("start_first_time")
- end_first_time := this.GetString("end_first_time")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- var startFistTime int64
- if len(start_first_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_first_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startFistTime = theTime.Unix()
- }
- var endFirstTime int64
- if len(end_first_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_first_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endFirstTime = theTime.Unix()
- }
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- list, total, _ := service.GetStockListById(id, orgId, limit, page, startTime, endTime, startFistTime, endFirstTime)
- houseList, _ := service.GetAllStoreHouseList(orgId)
- good, _ := service.GetGoodInformationByGoodId(id)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "manufacturerList": manufacturerList,
- "houseList": houseList,
- "good": good,
- })
-
- }
-
- func (this *StockManagerApiController) GetStockOutList() {
-
- id, _ := this.GetInt64("id")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- is_sys, _ := this.GetInt64("is_sys")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "outList": outList,
- "total": total,
- })
- }
-
- func (this *StockManagerApiController) GetStockDrugCount() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- fmt.Println(orgId)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
- outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
- autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
- totalCount, _ := service.GetCancelOutTotalCount(startTime, endTime, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "count": count,
- "outList": outList,
- "autoCount": autoCount,
- "totalCount": totalCount,
- })
- }
-
- func (this *StockManagerApiController) GetOrderDetialByOrderId() {
-
- ids := this.GetString("id")
-
- idsArray := strings.Split(ids, ",")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
- list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
- stockFlowListGroup, _ := service.GetOrderDetailStockFlowByStorehouseById(idsArray, orgId)
- stockFlowList, _ := service.GetOrderDetailStockFlow(idsArray, orgId)
- //获取耗材退库数据
- cancelInfolist, _ := service.GetOrderStockFlow(idsArray, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "order": order,
- "stockFlowList": stockFlowList,
- "stockFlowListGroup": stockFlowListGroup,
- "cancelInfolist": cancelInfolist,
- })
- }
-
- func (this *StockManagerApiController) GetOrderDetailById() {
-
- id, _ := this.GetInt64("id")
- good_id, _ := this.GetInt64("good_id")
- record_time, _ := this.GetInt64("record_time")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- //自动出库
- userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
-
- //手动出库
- info, _ := service.GetWarehouseOutInfoById(id, good_id)
-
- //出库数据
- stockFlowList, err := service.GetStockFlowBatchNumberOne(id, good_id)
-
- //退库数据
- cancelInfo, err := service.GetStockFlowCancelInfo(id, good_id)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": userDetails,
- "total": total,
- "info": info,
- "stockFlowList": stockFlowList,
- "cancelInfo": cancelInfo,
- })
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (this *StockManagerApiController) GetSingleOutOrderDetail() {
- id, _ := this.GetInt64("id", 0)
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- warehouseOutInfo, _ := service.GetOrderDetialByOrderId(id, orgId)
- out, _ := service.GetGoodWarehouseOutById(id, orgId)
- storelist, _ := service.GetAllStoreHouseList(orgId)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- goodType, _ := service.GetAllGoodType(orgId)
- appId := this.GetAdminUserInfo().CurrentAppId
- doctorlist, _ := service.GetAllDoctorListSix(orgId, appId)
- patients, _ := service.GetAllpatientTwenty(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": warehouseOutInfo,
- "dealerList": dealerList,
- "manufacturerList": manufacturerList,
- "goodType": goodType,
- "out": out,
- "storelist": storelist,
- "doctorlist": doctorlist,
- "patients": patients,
- })
- }
-
- func (this *StockManagerApiController) GetExprotStockList() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- idArray := this.GetString("id")
- ids := strings.Split(idArray, ",")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- list, _ := service.GetExprotStockListTwenty(orgId, ids, startTime, endTime, storehouse_id)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) GetOutExprotList() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- idArray := this.GetString("id")
- ids := strings.Split(idArray, ",")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- list, _ := service.GetOutExprotList(orgId, ids, startTime, endTime)
- outCount, _ := service.GetOutStockTotalCountOne(startTime, endTime, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "count": outCount,
- })
- }
-
- func (this *StockManagerApiController) GetSingleCancelOrder() {
-
- id, _ := this.GetInt64("id")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- order, _ := service.GetSingleCancelOrder(id, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": order,
- })
- }
-
- func (this *StockManagerApiController) GetCancelStockOrderPrint() {
- id := this.GetString("id")
- idStr := strings.Split(id, ",")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetCancelStockOrderPrintOne(idStr, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) GetStockBatchNumber() {
-
- id, _ := this.GetInt64("id")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetStockBatchNumber(id, orgId)
- lastWarehouseInfoTwo, _ := service.GetLastWarehouseInfoTwo(id, storehouse_id, orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "lastWarehouseInfoTwo": lastWarehouseInfoTwo,
- })
- }
-
- func (this *StockManagerApiController) GetStockFlow() {
-
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- good_id, _ := this.GetInt64("good_id")
- consumable_type, _ := this.GetInt64("is_sys")
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- list, total, _ := service.GetStockFlowList(limit, page, consumable_type, orgId, startTime, endTime, good_id)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- good, _ := service.GetGoodInformationByGoodId(good_id)
- houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
- patients, _ := service.GetAllPatientListSix(adminUserInfo.CurrentOrgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "manufacturerList": manufacturerList,
- "good": good,
- "houseList": houseList,
- "patients": patients,
- })
- }
-
- func (this *StockManagerApiController) GetCancelExportList() {
-
- adminUserInfo := this.GetAdminUserInfo()
- orgId := adminUserInfo.CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- idArray := this.GetString("order_id")
- fmt.Println("232323232323232232", idArray)
- ids := strings.Split(idArray, ",")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- list, _ := service.GetCancelExportList(startTime, endTime, ids, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) GetSearchGoodWarehouseList() {
-
- keyword := this.GetString("keyword")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetSearchGoodWarehouseList(keyword, orgId, storehouse_id)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- })
- }
-
- func (this *StockManagerApiController) SaveAdjuestPrice() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- tableData, _ := dataBody["tableData"].([]interface{})
- if len(tableData) > 0 {
- for _, item := range tableData {
- items := item.(map[string]interface{})
-
- if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_name := items["good_name"].(string)
-
- if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
- utils.ErrorLog("packing_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
-
- if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
- utils.ErrorLog("warehousing_order")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_order := items["warehousing_order"].(string)
-
- if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
- utils.ErrorLog("license_number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- license_number := items["license_number"].(string)
-
- if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
- utils.ErrorLog("dealer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- dealer := items["dealer"].(string)
-
- if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
- utils.ErrorLog("manufacturer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- manufacturer := items["manufacturer"].(string)
-
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- specification_name := items["specification_name"].(string)
-
- if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
- utils.ErrorLog("remark")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- remark := items["remark"].(string)
-
- if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
- utils.ErrorLog("warehousing_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_unit := items["warehousing_unit"].(string)
-
- if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
- utils.ErrorLog("buy_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
- utils.ErrorLog("count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- count := int64(items["count"].(float64))
-
- if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
- utils.ErrorLog("new_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var startTime int64
- start_time := items["start_time"].(string)
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- orgId := this.GetAdminUserInfo().CurrentOrgId
- adjustprice := models.XtStockAdjustPrice{
- GoodName: good_name,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- Count: count,
- BuyPrice: buy_price,
- PackingPrice: packing_price,
- NewPrice: new_price,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Remark: remark,
- GoodId: good_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehousing_order,
- LicenseNumber: license_number,
- StartTime: startTime,
- Creater: this.GetAdminUserInfo().AdminUser.Id,
- CheckerStatus: 2,
- }
-
- service.CreateAdjustPrice(&adjustprice)
- }
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功!",
- })
- }
-
- func (this *StockManagerApiController) GetAllStockPrice() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- orgId := this.GetAdminUserInfo().CurrentOrgId
- keyword := this.GetString("keyword")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- list, total, _ := service.GetAllStockPrice(orgId, startTime, endTime, keyword, limit, page)
- doctor, _ := service.GetAllDoctorThree(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "doctor": doctor,
- "total": total,
- })
- }
-
- func (this *StockManagerApiController) SaveCheckPrice() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- idstr := this.GetString("ids")
- ids := strings.Split(idstr, ",")
- check_time := this.GetString("check_time")
- var checkTime int64
- if len(check_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- checkTime = theTime.Unix()
- }
- checker, _ := this.GetInt64("checker")
- adjustPrice := models.XtStockAdjustPrice{
- Checker: checker,
- CheckerStatus: 1,
- CheckerTime: checkTime,
- }
- err = service.UpdateAdjustPrice(ids, adjustPrice)
- fmt.Println(err)
-
- list, _ := service.GetAdjustCheckPriceList(ids)
- fmt.Println("list2333223323232323232323", list)
- for _, item := range list {
- info := models.GoodInfo{
- PackingPrice: item.NewPrice,
- BuyPrice: item.NewPrice,
- }
- err = service.UpdateAdjustCheckPrice(&info, item.GoodId)
- fmt.Println(err)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "adjustPrice": adjustPrice,
- })
- }
-
- func (this *StockManagerApiController) GetAdjustPriceById() {
-
- ids := this.GetString("ids")
- fmt.Println("ids23232233223233232", ids)
- splitIds := strings.Split(ids, ",")
- list, _ := service.GetAdjustPricebyIdOne(splitIds)
- fmt.Println("list2322322323", list)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) SaveReportStock() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- tableData, _ := dataBody["tableData"].([]interface{})
- if len(tableData) > 0 {
- for _, item := range tableData {
- items := item.(map[string]interface{})
-
- if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_name := items["good_name"].(string)
-
- if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
- utils.ErrorLog("packing_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
-
- if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
- utils.ErrorLog("warehousing_order")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_order := items["warehousing_order"].(string)
-
- if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
- utils.ErrorLog("license_number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- license_number := items["license_number"].(string)
-
- if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
- utils.ErrorLog("dealer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- dealer := items["dealer"].(string)
-
- if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
- utils.ErrorLog("manufacturer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- manufacturer := items["manufacturer"].(string)
-
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- specification_name := items["specification_name"].(string)
-
- if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
- utils.ErrorLog("remark")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- remark := items["remark"].(string)
-
- if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
- utils.ErrorLog("warehousing_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_unit := items["warehousing_unit"].(string)
-
- if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
- utils.ErrorLog("buy_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
- utils.ErrorLog("count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- count := int64(items["count"].(float64))
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var startTime int64
- start_time := items["start_time"].(string)
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- utils.ErrorLog("number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- number := items["number"].(string)
-
- if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
- utils.ErrorLog("warehousing_info_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_info_id := int64(items["warehousing_info_id"].(float64))
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
- utils.ErrorLog("expiry_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiry_date := int64(items["expiry_date"].(float64))
-
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
- utils.ErrorLog("product_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- product_date := int64(items["product_date"].(float64))
- orgId := this.GetAdminUserInfo().CurrentOrgId
- Creater := this.GetAdminUserInfo().AdminUser.Id
-
- if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
- utils.ErrorLog("total")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- total := int64(items["total"].(float64))
-
- if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
- utils.ErrorLog("good_origin_place")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_origin_place := items["good_origin_place"].(string)
- reportPrice := models.XtStockReportPrice{
- GoodName: good_name,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- Count: count,
- BuyPrice: buy_price,
- PackingPrice: packing_price,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Remark: remark,
- GoodId: good_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehousing_order,
- LicenseNumber: license_number,
- StartTime: startTime,
- Creater: Creater,
- Checker: 0,
- CheckerStatus: 2,
- CheckerTime: 0,
- Number: number,
- WarehousingInfoId: warehousing_info_id,
- ExpiryDate: expiry_date,
- ProductDate: product_date,
- Total: total,
- GoodOriginPlace: good_origin_place,
- }
- err := service.CreateReportPrice(&reportPrice)
- fmt.Println(err)
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功!",
- })
- }
-
- func (this *StockManagerApiController) GetReportStockList() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- fmt.Println("开始时间", startTime)
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
-
- }
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- keyword := this.GetString("keyword")
- list, total, _ := service.GetStockDamagedList(orgId, keyword, page, limit, startTime, endTime, storehouse_id)
- damageList, _ := service.GetStockDamagedCount(orgId)
- doctorlist, _ := service.GetAllDoctorThree(orgId)
- houseList, _ := service.GetAllStoreHouseList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "doctorlist": doctorlist,
- "damageList": damageList,
- "houseList": houseList,
- })
- }
-
- func (this *StockManagerApiController) SaveCheckDamage() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- idstr := this.GetString("ids")
- ids := strings.Split(idstr, ",")
- check_time := this.GetString("check_time")
- var checkTime int64
- if len(check_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- checkTime = theTime.Unix()
- }
- checker, _ := this.GetInt64("checker")
- reportprice := models.XtStockReportPrice{
- Checker: checker,
- CheckerStatus: 1,
- CheckerTime: checkTime,
- }
- err := service.UpdateCheckDamage(ids, reportprice)
- fmt.Println(err)
-
- //获取当前核对的数据
- list, _ := service.GetCheckDamageList(ids)
-
- ctime := time.Now().Unix()
- adminUserInfo := this.GetAdminUserInfo()
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehouseOutTime: ctime,
- Type: 1,
- }
-
- _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
-
- if errcodes == gorm.ErrRecordNotFound {
- service.AddSigleWarehouseOutOne(&warehouseOut)
-
- }
- out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- var manufacturer_id int64
- var dealer_id int64
-
- for _, item := range list {
- for _, it := range manufacturerList {
- if item.Manufacturer == it.ManufacturerName {
- manufacturer_id = it.ID
- }
- }
- for _, its := range dealerList {
- if item.Dealer == its.DealerName {
- dealer_id = its.ID
- }
- }
- goodinfo, _ := service.GetGoodInformationByGoodId(item.GoodId)
- //插入出库单
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- GoodId: item.GoodId,
- Count: item.Count,
- Price: item.PackingPrice,
- Status: 1,
- Ctime: ctime,
- Remark: item.Remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 2,
- Manufacturer: manufacturer_id,
- Number: item.Number,
- ExpiryDate: item.ExpiryDate,
- ProductDate: item.ProductDate,
- Dealer: dealer_id,
- LicenseNumber: item.LicenseNumber,
- GoodTypeId: goodinfo.GoodTypeId,
- }
- errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
- fmt.Println("", errOne)
-
- //更改库存
- info, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
-
- warehousingInfo := models.WarehousingInfo{
- StockCount: info.StockCount - item.Count,
- }
- errOne = service.UpdateGoodWarehouseInfo(item.WarehousingInfoId, warehousingInfo)
- fmt.Println(errOne)
- flow := models.VmStockFlow{
- WarehousingId: 0,
- GoodId: item.GoodId,
- Number: item.Number,
- LicenseNumber: item.LicenseNumber,
- Count: item.Count,
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: 0,
- SystemTime: time.Now().Unix(),
- ConsumableType: 5,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: out.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: 0,
- CancelOrderNumber: "",
- Manufacturer: 0,
- Dealer: 0,
- Creator: adminUserInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: item.PackingPrice,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ProductDate: item.ProductDate,
- ExpireDate: item.ExpiryDate,
- }
- service.CreateStockFlowOne(flow)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "reportPrice": reportprice,
- })
- }
-
- func (this *StockManagerApiController) SaveInventory() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- tableData, _ := dataBody["tableData"].([]interface{})
- if len(tableData) > 0 {
- for _, item := range tableData {
- items := item.(map[string]interface{})
-
- if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_name := items["good_name"].(string)
-
- if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
- utils.ErrorLog("packing_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
-
- if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
- utils.ErrorLog("warehousing_order")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_order := items["warehousing_order"].(string)
-
- if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
- utils.ErrorLog("license_number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- license_number := items["license_number"].(string)
-
- if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
- utils.ErrorLog("dealer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- dealer := items["dealer"].(string)
-
- if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
- utils.ErrorLog("manufacturer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- manufacturer := items["manufacturer"].(string)
-
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- specification_name := items["specification_name"].(string)
-
- if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
- utils.ErrorLog("remark")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- remark := items["remark"].(string)
-
- if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
- utils.ErrorLog("warehousing_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_unit := items["warehousing_unit"].(string)
-
- if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
- utils.ErrorLog("buy_price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
- utils.ErrorLog("count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- count := int64(items["count"].(float64))
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var startTime int64
- start_time := items["start_time"].(string)
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
- utils.ErrorLog("total")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- total := int64(items["total"].(float64))
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
- utils.ErrorLog("expiry_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiry_date := int64(items["expiry_date"].(float64))
-
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
- utils.ErrorLog("product_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- product_date := int64(items["product_date"].(float64))
-
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- utils.ErrorLog("number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- number := items["number"].(string)
-
- if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
- utils.ErrorLog("warehousing_info_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- warehousing_info_id := int64(items["warehousing_info_id"].(float64))
-
- if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
- utils.ErrorLog("good_origin_place")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_origin_place := items["good_origin_place"].(string)
- orgId := this.GetAdminUserInfo().CurrentOrgId
- Creater := this.GetAdminUserInfo().AdminUser.Id
-
- inventory := models.XtStockInventory{
- GoodName: good_name,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- Count: count,
- BuyPrice: buy_price,
- PackingPrice: packing_price,
- NewPrice: 0,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Remark: remark,
- GoodId: good_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehousing_order,
- LicenseNumber: license_number,
- StartTime: startTime,
- Creater: Creater,
- Checker: 0,
- CheckerStatus: 2,
- CheckerTime: 0,
- Total: total,
- ExpireDate: expiry_date,
- ProductDate: product_date,
- Number: number,
- WarehousingInfoId: warehousing_info_id,
- GoodOriginPlace: good_origin_place,
- }
- err = service.CreateInentory(inventory)
- fmt.Println(err)
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功!",
- })
- }
-
- func (this *StockManagerApiController) GetInventorylist() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- keyword := this.GetString("keyword")
- inventory_status, _ := this.GetInt64("inventory_status")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- fmt.Println("开始时间", startTime)
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
-
- }
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, total, _ := service.GetInventorylist(startTime, endTime, page, limit, inventory_status, keyword, orgId)
- doctorlist, _ := service.GetAllDoctorThree(orgId)
-
- houseList, _ := service.GetAllStoreHouseList(orgId)
- houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "doctorlist": doctorlist,
- "houseList": houseList,
- "houseConfig": houseConfig,
- })
- }
-
- func (this *StockManagerApiController) SaveCheckInventory() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- idstr := this.GetString("ids")
- ids := strings.Split(idstr, ",")
- check_time := this.GetString("check_time")
- var checkTime int64
- if len(check_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- checkTime = theTime.Unix()
- }
- checker, _ := this.GetInt64("checker")
- inventory := models.XtStockInventory{
- Checker: checker,
- CheckerStatus: 1,
- CheckerTime: checkTime,
- }
- adminUserInfo := this.GetAdminUserInfo()
- err = service.UpdateCheckInventory(ids, inventory)
- manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
- dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
- var manufactuer_id int64
- var dealer_id int64
- //查询耗材信息
- list, _ := service.GetInventoryDetailById(ids)
- for _, item := range list {
- for _, it := range manufacturerList {
- if item.Manufacturer == it.ManufacturerName {
- manufactuer_id = it.ID
- }
- }
-
- for _, its := range dealerList {
- if item.Dealer == its.DealerName {
- dealer_id = its.ID
- }
- }
- //查寻该批次的库存量
- list, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
-
- //查询该耗材最后1条批次
- info, _ := service.GetLastWarehouseInfo(item.GoodId)
- good, _ := service.GetGoodInformationByGoodId(item.GoodId)
- fmt.Println("总共", item.Count)
- fmt.Println("数据", list.StockCount)
- //盘点盘点库存和et实际库存的大小
- // 如果盘点库存大于实际库存,怎需要入库
- if item.Count > list.StockCount {
-
- ctime := time.Now().Unix()
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
- total = total + 1
- warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
- warehousing := models.Warehousing{
- WarehousingOrder: warehousing_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: ctime,
- Status: 1,
- WarehousingTime: ctime,
- Type: 1,
- }
- service.AddSigleWarehouse(&warehousing)
-
- //获取最
- //入库单表格
- warehouseInfo := models.WarehousingInfo{
- WarehousingOrder: warehousing.WarehousingOrder,
- WarehousingId: warehousing.ID,
- GoodId: item.GoodId,
- Number: info.Number,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- WarehousingCount: item.Count - list.StockCount,
- Price: info.Price,
- Status: 1,
- Ctime: ctime,
- Remark: item.Remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: manufactuer_id,
- StockCount: item.Count - list.StockCount,
- Dealer: dealer_id,
- LicenseNumber: info.LicenseNumber,
- WarehouseInfoId: item.WarehousingInfoId,
- GoodTypeId: good.GoodTypeId,
- }
-
- flow := models.VmStockFlow{
- WarehousingOrder: warehousing.WarehousingOrder,
- WarehousingId: warehousing.ID,
- GoodId: item.GoodId,
- Number: info.Number,
- ProductDate: info.ProductDate,
- ExpireDate: info.ExpiryDate,
- Count: item.Count - list.StockCount,
- Price: item.BuyPrice,
- Status: 1,
- Ctime: ctime,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Manufacturer: info.Manufacturer,
- Dealer: info.Dealer,
- LicenseNumber: info.LicenseNumber,
- IsEdit: 1,
- Creator: adminUserInfo.AdminUser.Id,
- SystemTime: operation_time,
- ConsumableType: 1,
- WarehousingDetailId: warehouseInfo.ID,
- }
-
- service.CreateWarehouseInfo(warehouseInfo)
- service.CreateStockFlowOne(flow)
-
- }
-
- //如果盘点库存小于实际库存,需要出库
- if item.Count < list.StockCount {
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
- creater := adminUserInfo.AdminUser.Id
-
- //查询最早的1条批次
- warehouseInfo, _ := service.GetFirstWarehouseInfo(item.GoodId)
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: adminUserInfo.CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: time.Now().Unix(),
- Type: 1,
- }
- err = service.CreateWarehouseOut(warehouseOut)
- fmt.Println(err)
- out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
- WarehouseOutId: out.ID,
- GoodId: warehouseInfo.GoodId,
- Count: list.StockCount - item.Count,
- Price: warehouseInfo.Price,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: item.Remark,
- OrgId: adminUserInfo.CurrentOrgId,
- Type: 1,
- Manufacturer: manufactuer_id,
- Number: warehouseInfo.Number,
- ExpiryDate: warehouseInfo.ExpiryDate,
- ProductDate: warehouseInfo.ProductDate,
- Dealer: dealer_id,
- LicenseNumber: warehouseInfo.LicenseNumber,
- GoodTypeId: good.GoodTypeId,
- SysRecordTime: time.Now().Unix(),
- }
-
- stockFlow := models.VmStockFlow{
- WarehousingId: item.WarehousingInfoId,
- GoodId: warehouseInfo.GoodId,
- Number: warehouseInfo.Number,
- LicenseNumber: warehouseInfo.LicenseNumber,
- Count: list.StockCount - item.Count,
- UserOrgId: warehouseInfo.OrgId,
- PatientId: 0,
- SystemTime: time.Now().Unix(),
- ConsumableType: 2,
- IsSys: 2,
- WarehousingOrder: "",
- WarehouseOutId: out.ID,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- IsEdit: 1,
- CancelStockId: 0,
- CancelOrderNumber: "",
- Manufacturer: manufactuer_id,
- Dealer: dealer_id,
- Creator: adminUserInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: warehouseInfo.Price,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: out.ID,
- CancelOutDetailId: 0,
- ProductDate: warehouseInfo.ProductDate,
- ExpireDate: warehouseInfo.ExpiryDate,
- }
- errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
- fmt.Println(errOne)
- //创建出库明细
- service.CreateStockFlowOne(stockFlow)
-
- //更改库存
- warehousingInfos := models.WarehousingInfo{
- StockCount: item.Count,
- }
- service.UpdateStockOut(item.WarehousingInfoId, warehousingInfos)
-
- }
- }
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "inventory": inventory,
- })
- }
-
- func (this *StockManagerApiController) GetModifyPriceDetail() {
-
- id, _ := this.GetInt64("id")
-
- detail, _ := service.GetModifyPriceDetail(id)
- this.ServeSuccessJSON(map[string]interface{}{
- "detail": detail,
- })
- }
-
- func (this *StockManagerApiController) UpdateStockPrice() {
-
- id, _ := this.GetInt64("id")
- newPrice := this.GetString("new_price")
- new_price, _ := strconv.ParseFloat(newPrice, 64)
- good_name := this.GetString("good_name")
- packingPrice := this.GetString("packing_price")
- packing_price, _ := strconv.ParseFloat(packingPrice, 64)
- remark := this.GetString("remark")
- good_id, _ := this.GetInt64("good_id")
- manufacturer := this.GetString("manufacturer")
- dealer := this.GetString("dealer")
- adjust := models.XtStockAdjustPrice{
- NewPrice: new_price,
- GoodName: good_name,
- PackingPrice: packing_price,
- Remark: remark,
- GoodId: good_id,
- Manufacturer: manufacturer,
- Dealer: dealer,
- }
- err := service.UpdateStockPrice(adjust, id)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "adjust": adjust,
- })
- }
-
- func (this *StockManagerApiController) DeleteStockPrice() {
-
- id, _ := this.GetInt64("id")
- err := service.DeleteStockPrice(id)
- fmt.Println(err)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *StockManagerApiController) GetStockDamageDetail() {
-
- id, _ := this.GetInt64("id")
- detail, err := service.GetStockDamageDetail(id)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "detail": detail,
- })
- }
-
- func (this *StockManagerApiController) ModifyPrice() {
-
- count, _ := this.GetInt64("count")
- id, _ := this.GetInt64("id")
- good_name := this.GetString("good_name")
- specification_name := this.GetString("specification_name")
- number := this.GetString("number")
- warehousing_unit := this.GetString("warehousing_unit")
- buyPrice := this.GetString("buy_price")
- buy_price, _ := strconv.ParseFloat(buyPrice, 64)
- packingPrice := this.GetString("packing_price")
- packing_price, _ := strconv.ParseFloat(packingPrice, 64)
- good_origin_place := this.GetString("good_origin_place")
- manufacturer := this.GetString("manufacturer")
- dealer := this.GetString("dealer")
- total, _ := this.GetInt64("total")
- remark := this.GetString("remark")
- warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
- good_id, _ := this.GetInt64("good_id")
- adjust := models.XtStockReportPrice{
- Count: count,
- SpecificationName: specification_name,
- Number: number,
- GoodName: good_name,
- WarehousingUnit: warehousing_unit,
- BuyPrice: buy_price,
- PackingPrice: packing_price,
- GoodOriginPlace: good_origin_place,
- Manufacturer: manufacturer,
- Dealer: dealer,
- Total: total,
- Remark: remark,
- WarehousingInfoId: warehousing_info_id,
- GoodId: good_id,
- }
- err := service.ModifyPrice(id, adjust)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "adjust": adjust,
- })
- }
-
- func (this *StockManagerApiController) DeleteDamage() {
-
- id, _ := this.GetInt64("id")
- err := service.DeleteDamage(id)
- fmt.Println(err)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *StockManagerApiController) GetStockDamageById() {
- ids := this.GetString("ids")
-
- splitIds := strings.Split(ids, ",")
- list, _ := service.GetStockDamageById(splitIds)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) GetInventoryDetail() {
- id, _ := this.GetInt64("id")
- detail, _ := service.GetInventoryDetail(id)
- this.ServeSuccessJSON(map[string]interface{}{
- "detail": detail,
- })
- }
-
- func (this *StockManagerApiController) ModifyInventory() {
- id, _ := this.GetInt64("id")
- good_id, _ := this.GetInt64("good_id")
- good_name := this.GetString("good_name")
- specification_name := this.GetString("specification_name")
- number := this.GetString("number")
- warehousing_unit := this.GetString("warehousing_unit")
- buyPrice := this.GetString("buy_price")
- buy_price, _ := strconv.ParseFloat(buyPrice, 64)
- packingPrice := this.GetString("packing_price")
- packing_price, _ := strconv.ParseFloat(packingPrice, 64)
- total, _ := this.GetInt64("total")
- good_origin_place := this.GetString("good_origin_place")
- license_number := this.GetString("license_number")
- dealer := this.GetString("dealer")
- manufacturer := this.GetString("manufacturer")
- count, _ := this.GetInt64("count")
- remark := this.GetString("remark")
- inventory := models.XtStockInventory{
- GoodId: good_id,
- GoodName: good_name,
- SpecificationName: specification_name,
- Number: number,
- WarehousingUnit: warehousing_unit,
- BuyPrice: buy_price,
- PackingPrice: packing_price,
- Total: total,
- GoodOriginPlace: good_origin_place,
- LicenseNumber: license_number,
- Dealer: dealer,
- Manufacturer: manufacturer,
- Count: count,
- Remark: remark,
- }
- err := service.ModifyInventory(id, inventory)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "inventory": inventory,
- })
- }
-
- func (this *StockManagerApiController) DeleteInventory() {
- id, _ := this.GetInt64("id")
- err := service.DeleteInventory(id)
- fmt.Println(err)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *StockManagerApiController) GetInventoryDetailList() {
- keyword := this.GetString("keyword")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- appId := this.GetAdminUserInfo().CurrentAppId
- storehouse_id, _ := this.GetInt64("storehouse_id")
- houseList, _ := service.GetAllStoreHouseList(orgId)
- list, total, _ := service.GetInventoryDetailList(keyword, limit, page, orgId, storehouse_id)
- doclist, _ := service.GetAllDoctorListSix(orgId, appId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "houseList": houseList,
- "doclist": doclist,
- })
- }
-
- func (this *StockManagerApiController) GetInventoryPrintList() {
-
- ids := this.GetString("ids")
- splitIds := strings.Split(ids, ",")
- list, _ := service.GetInventoryPrintList(splitIds)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) GetInventoryDetailPrintList() {
- ids := this.GetString("ids")
- splitIds := strings.Split(ids, ",")
- list, _ := service.GetInventoryDetailPrintList(splitIds)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) DeleteDrugPrice() {
-
- id, _ := this.GetInt64("id")
- err := service.DeleteDrugPrice(id)
- fmt.Println(err)
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
-
- func (this *StockManagerApiController) GetGoodWarehouseList() {
-
- id, _ := this.GetInt64("id")
- list, _ := service.GetGoodWarehouseList(id)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) ProofInventory() {
-
- id, _ := this.GetInt64("id")
- good_id, _ := this.GetInt64("good_id")
- warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
- proof_count, _ := this.GetInt64("proof_count")
- total, _ := this.GetInt64("total")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- creater := this.GetAdminUserInfo().AdminUser.Id
-
- info := models.WarehousingInfo{
- GoodId: good_id,
- StockCount: proof_count,
- }
- err := service.UpdateProofInventory(warehousing_info_id, info)
- inventory := models.XtStockInventory{
- Total: proof_count,
- }
- err = service.UpdateStockInventory(inventory, id)
- fmt.Println(err)
- record := models.XtStockCorrectRecord{
- GoodId: good_id,
- OrdCount: total,
- WarehousingInfoId: warehousing_info_id,
- NewCount: proof_count,
- UserOrgId: orgId,
- Status: 1,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- }
- service.CeateStockCorrectRecord(record)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": info,
- })
- }
-
- func (this *StockManagerApiController) GetWarehouseTotal() {
-
- id, _ := this.GetInt64("id")
- list, _ := service.GetWarehouseTotal(id)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) GetGoodInventoryWarehouseList() {
-
- id, _ := this.GetInt64("id")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- list, _ := service.GetGoodInventoryWarehouseList(id, storehouse_id)
- orgId := this.GetAdminUserInfo().CurrentOrgId
- fmt.Println(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *StockManagerApiController) SaveStockInventoryList() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
-
- tableData, _ := dataBody["tableData"].([]interface{})
- if len(tableData) > 0 {
- for _, item := range tableData {
- items := item.(map[string]interface{})
- good_name := items["good_name"].(string)
- if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- specification_name := items["specification_name"].(string)
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_unit := items["warehousing_unit"].(string)
- if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
- utils.ErrorLog("warehousing_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- stock_count := int64(items["stock_count"].(float64))
- if items["stock_count"] == nil || reflect.TypeOf(items["stock_count"]).String() != "float64" {
- utils.ErrorLog("stock_count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- price := items["price"].(float64)
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "float64" {
- utils.ErrorLog("price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- manufacturer_name := items["manufacturer_name"].(string)
- if items["manufacturer_name"] == nil || reflect.TypeOf(items["manufacturer_name"]).String() != "string" {
- utils.ErrorLog("manufacturer_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- good_id := int64(items["good_id"].(float64))
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- manufacturer := int64(items["manufacturer"].(float64))
- if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "float64" {
- utils.ErrorLog("manufacturer")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_order := items["warehousing_order"].(string)
- if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
- utils.ErrorLog("warehousing_order")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- number := items["number"].(string)
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- utils.ErrorLog("number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- id := int64(items["id"].(float64))
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
- utils.ErrorLog("expiry_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiry_date := int64(items["expiry_date"].(float64))
-
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
- utils.ErrorLog("product_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- product_date := int64(items["product_date"].(float64))
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- adminId := this.GetAdminUserInfo().AdminUser.Id
-
- stock_type := int64(items["type"].(float64))
- if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
- utils.ErrorLog("type")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- last_stock_count := int64(items["last_stock_count"].(float64))
- if items["last_stock_count"] == nil || reflect.TypeOf(items["last_stock_count"]).String() != "float64" {
- utils.ErrorLog("last_stock_count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- storehouse_id := int64(items["storehouse_id"].(float64))
- if items["storehouse_id"] == nil || reflect.TypeOf(items["storehouse_id"]).String() != "float64" {
- utils.ErrorLog("storehouse_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var total_count int64
- var inventory_type int64
-
- if stock_count > last_stock_count {
- total_count = stock_count - last_stock_count
- inventory_type = 11
- }
- if stock_count < last_stock_count {
- total_count = last_stock_count - stock_count
- inventory_type = 10
- }
-
- creater := this.GetAdminUserInfo().AdminUser.Id
- inventory := models.XtStockInventory{
- GoodName: good_name,
- SpecificationName: specification_name,
- WarehousingUnit: warehousing_unit,
- Count: total_count,
- BuyPrice: price,
- PackingPrice: price,
- NewPrice: 0,
- Manufacturer: manufacturer_name,
- Dealer: "",
- Remark: "",
- GoodId: good_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehousing_order,
- LicenseNumber: number,
- StartTime: time.Now().Unix(),
- Creater: adminId,
- Checker: 0,
- CheckerStatus: 0,
- CheckerTime: 0,
- Total: 0,
- Number: number,
- WarehousingInfoId: id,
- ExpireDate: expiry_date,
- ProductDate: product_date,
- GoodOriginPlace: "",
- Type: 10,
- InventoryType: stock_type,
- LastStockCount: last_stock_count,
- StockCount: stock_count,
- StorehouseId: storehouse_id,
- }
- service.CreateInentory(inventory)
-
- stockFlow := models.VmStockFlow{
- WarehousingId: 0,
- GoodId: good_id,
- Number: number,
- LicenseNumber: "",
- Count: total_count,
- UserOrgId: orgId,
- PatientId: 0,
- SystemTime: 0,
- ConsumableType: inventory_type,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: warehousing_order,
- IsEdit: 0,
- CancelStockId: 0,
- CancelOrderNumber: "",
- Manufacturer: manufacturer,
- Dealer: 0,
- Creator: creater,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: price,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ProductDate: product_date,
- ExpireDate: expiry_date,
- ReturnCount: 0,
- StorehouseId: storehouse_id,
- }
-
- info := models.WarehousingInfo{
- StockCount: last_stock_count,
- WarehousingCount: last_stock_count,
- }
-
- warehosueinfos, _ := service.GetWarehouseInfoByIdNight(id)
- //如果当前的盘点后的数量大于当前库存数量,则新增库存
- if last_stock_count > warehosueinfos.StockCount && last_stock_count <= warehosueinfos.WarehousingCount {
- //更改库存
- service.UpdatedWarehousingInfo(info, id)
- }
-
- if last_stock_count > warehosueinfos.StockCount && last_stock_count > warehosueinfos.WarehousingCount {
-
- //更改库存
- service.UpdatedWarehousingInfoSix(info, id)
- }
- //如果当前的盘点后的数量大于当前库存数量,则扣减库存
- if last_stock_count < warehosueinfos.StockCount {
-
- //更改库存
- service.UpdatedWarehousingInfo(info, id)
- }
- //查询该机构默认仓库
- storeConfig, _ := service.GetAllStoreHouseConfig(warehosueinfos.OrgId)
- goodListOne, _ := service.GetSumGoodList(orgId, storeConfig.StorehouseOutInfo, good_id)
- var flush_count int64
- for _, it := range goodListOne {
- flush_count += it.StockCount
- }
-
- if stock_count != last_stock_count {
- stockFlow.OverCount = flush_count
- service.CreateStockFlowOne(stockFlow)
- }
-
- //查询已审核单据的剩余库存
- goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, good_id, warehosueinfos.OrgId)
- var sum_count int64
- var sum_in_count int64
- for _, item := range goodList {
- sum_count += item.StockCount
- sum_in_count += item.WarehousingCount
- }
- service.UpdateGoodByGoodId(good_id, sum_count, sum_in_count, warehosueinfos.OrgId)
-
- service.UpdateSumGood(orgId, storeConfig.StorehouseOutInfo, good_id, flush_count)
- this.ServeSuccessJSON(map[string]interface{}{
- "inventory": inventory,
- })
- }
- }
-
- newTableData, _ := dataBody["newTableData"].([]interface{})
- if len(newTableData) > 0 {
- for _, item := range newTableData {
- items := item.(map[string]interface{})
- good_name := items["good_name"].(string)
- if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
- utils.ErrorLog("good_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- specification_name := items["specification_name"].(string)
- if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
- utils.ErrorLog("specification_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_unit := items["warehousing_unit"].(string)
- if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
- utils.ErrorLog("warehousing_unit")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_count := int64(items["warehousing_count"].(float64))
- if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "float64" {
- utils.ErrorLog("warehousing_count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- stock_count := int64(items["stock_count"].(float64))
- if items["stock_count"] == nil || reflect.TypeOf(items["stock_count"]).String() != "float64" {
- utils.ErrorLog("stock_count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- price := items["price"].(float64)
- if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "float64" {
- utils.ErrorLog("price")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- manufacturer_name := items["manufacturer_name"].(string)
- if items["manufacturer_name"] == nil || reflect.TypeOf(items["manufacturer_name"]).String() != "string" {
- utils.ErrorLog("manufacturer_name")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- good_id := int64(items["good_id"].(float64))
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- warehousing_order := items["warehousing_order"].(string)
- if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
- utils.ErrorLog("warehousing_order")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- number := items["number"].(string)
- if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
- utils.ErrorLog("number")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- id := int64(items["id"].(float64))
- if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
- utils.ErrorLog("id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
- utils.ErrorLog("expiry_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- expiry_date := int64(items["expiry_date"].(float64))
-
- if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
- utils.ErrorLog("product_date")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- product_date := int64(items["product_date"].(float64))
-
- stock_type := int64(items["type"].(float64))
- if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
- utils.ErrorLog("type")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- last_stock_count := int64(items["last_stock_count"].(float64))
- if items["last_stock_count"] == nil || reflect.TypeOf(items["last_stock_count"]).String() != "float64" {
- utils.ErrorLog("last_stock_count")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- storehouse_id := int64(items["storehouse_id"].(float64))
- if items["storehouse_id"] == nil || reflect.TypeOf(items["storehouse_id"]).String() != "float64" {
- utils.ErrorLog("storehouse_id")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- creater := this.GetAdminUserInfo().AdminUser.Id
-
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
-
- user_org_id := this.GetAdminUserInfo().CurrentOrgId
-
- goodStockInventory := models.XtGoodStockInventoryList{
- GoodId: good_id,
- WarehousingOrder: warehousing_order,
- InCount: warehousing_count,
- BatchNumber: number,
- Price: price,
- BeforCount: stock_count,
- AfterCount: last_stock_count,
- Reason: stock_type,
- Creater: creater,
- RecordDate: recordDate.Unix(),
- UserOrgId: user_org_id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- WarehouseInfoId: id,
- SpecificationName: specification_name,
- ManufacturerName: manufacturer_name,
- GoodName: good_name,
- ExpiryDate: expiry_date,
- ProductDate: product_date,
- StorehouseId: storehouse_id,
- MaxUnit: warehousing_unit,
- Status: 1,
- }
-
- //查询今日该耗材是否有记录
-
- goodStock, _ := service.GetGoodStockInventoryByRecordate(good_id, recordDate.Unix(), user_org_id)
-
- if goodStock.ID == 0 {
-
- service.CreateGoodStockInventoryList(goodStockInventory)
- }
-
- if goodStock.ID > 0 {
- goodStockInventory.ID = goodStock.ID
-
- service.SaveGoodStockInventoryList(goodStockInventory)
- }
-
- }
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功!",
- })
- }
-
- func (this *StockManagerApiController) GetDamageDetailByGoodId() {
-
- good_id, _ := this.GetInt64("good_id")
- warehousing_order := this.GetString("warehousing_order")
- inventory_type, _ := this.GetInt64("type")
- list, _ := service.GetDamageDetailByGoodId(good_id, warehousing_order, inventory_type)
- orgId := this.GetAdminUserInfo().CurrentOrgId
- damageList, _ := service.GetStockDamagedCountOne(orgId, warehousing_order, inventory_type)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "damageList": damageList,
- })
- }
-
- func (this *StockManagerApiController) GetInventoryExportList() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- list, _ := service.GetInventoryExportList(orgId)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- })
- }
-
- func (this *StockManagerApiController) UpdateCancelStockOrder() {
-
- type_id, _ := this.GetInt64("type_id")
- //获取目前在使用的机构ID
- list, _ := service.GetOrgIdList()
-
- //耗材
- if type_id == 1 {
- for _, item := range list {
- //查询该机构的所有耗材
- goodList, _ := service.GetAllGoodList(item.OrgId)
-
- for _, it := range goodList {
- //查询该耗材的入库总数
- info, _ := service.GetStockCountWarehouseInfoById(it.ID)
- var total int64
- for _, its := range info {
- total += its.StockCount
- }
- //更新库存
- service.ModifyGoodAddInformationSeven(it.ID, total, it.OrgId)
- }
- }
- }
-
- //药品
- if type_id == 2 {
-
- for _, item := range list {
- fmt.Println(item)
- //查询该机构的所有药品
- drugList, _ := service.GetAllBaseDrugStockList(4)
- for _, it := range drugList {
- //查询该药品的入库总数
- info, _ := service.GetDrugStockCountWarehoseInfoById(it.ID)
- var sum_count int64
- for _, its := range info {
- if its.MaxUnit == it.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * it.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateModifyDrugInfoById(it.ID, sum_count, it.OrgId)
- }
-
- }
- }
- }
-
- func (this *StockManagerApiController) GetDrugDetailSummary() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
-
- end_time := this.GetString("end_time")
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- fmt.Println("开始时间", startTime)
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- keyword := this.GetString("keyword")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, total, err := service.GetDrugDetailSummary(startTime, endTime, keyword, limit, page, orgId)
- druglist, _, _ := service.GetDrugDetailSummaryOne(startTime, endTime, keyword, limit, page, orgId)
-
- patients, _ := service.GetAllpatient(orgId)
- var drugType = "药品类型"
- drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
- drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
- for _, item := range list {
- for _, it := range druglist {
- if item.DrugId == it.DrugId {
- item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
- }
- }
- }
- drug, _ := service.GetAllDrugSummary(orgId)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "drug": drug,
- "drugTypeList": drugTypeList,
- "patients": patients,
- })
- }
- }
-
- func (this *StockManagerApiController) GetGoodDetailSummary() {
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
-
- end_time := this.GetString("end_time")
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
-
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- keyword := this.GetString("keyword")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, total, err := service.GetGoodDetailSummary(startTime, endTime, keyword, limit, page, orgId)
-
- goodlist, _, _ := service.GetGoodDetailSummaryOne(startTime, endTime, keyword, limit, page, orgId)
- for _, item := range list {
- for _, it := range goodlist {
- if item.ProjectId == it.ProjectId {
- item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
- }
- }
- }
-
- information, _ := service.GeAllGoodInformation(orgId)
- patients, _ := service.GetAllpatient(orgId)
- goodType, _ := service.GetAllGoodType(orgId)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "good": information,
- "patients": patients,
- "goodType": goodType,
- })
- }
- }
-
- func (this *StockManagerApiController) CheckWarehouseOut() {
-
- id, _ := this.GetInt64("id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- // 开始外部循环的事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- warehouseOut, _ := service.GetNewWarehouseById(id, tx)
-
- //查询已保存的单据
- warehousingOutInfo, _ := service.GetNewWarehouseOutById(id, orgId, tx)
-
- ////出库逻辑
- for _, item := range warehousingOutInfo {
- // 查询该耗材是否有库存
- warehouseOne, _ := service.FindNewWarehousingInfoTen(item.GoodId, item.StorehouseId, tx)
-
- storehouse, _ := service.FindNewStoreHouseByStorehouseId(item.StorehouseId, item.OrgId, tx)
-
- // 如果出库数量大于该批次剩余库存数量
- if item.Count > warehouseOne.StockCount {
- goodObj, _ := service.GetNewGoodInformationByGoodId(item.GoodId, tx)
- tx.Rollback()
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- "storehose_name": storehouse.StorehouseName,
- })
- return
- }
-
- }
- for _, item := range warehousingOutInfo {
-
- creater := this.GetAdminUserInfo().AdminUser.Id
-
- //出库
- err := service.ConsumablesNewDeliveryThirty(orgId, item.SysRecordTime, item, &warehouseOut, item.Count, creater, tx)
-
- if err != nil {
- tx.Rollback()
- return
- }
-
- goodList, _ := service.GetNewSumGoodList(orgId, item.StorehouseId, item.GoodId, tx)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
- service.UpdateNewSumGood(orgId, item.StorehouseId, item.GoodId, flush_count, tx)
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- //查询默认仓库
- storeHouseConfig, _ := service.GetNewAllStoreHouseConfig(orgId, tx)
- stockList, _ := service.GetNewStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId, tx)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库扣减库存
- service.UpdateNewGoodInfoReduceSumCount(item.GoodId, total_count, orgId, tx)
-
- }
-
- //审核单据
- err := service.UpdatedNewWarehouseOut(id, tx)
-
- tx.Commit()
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "good_name": "",
- "specification_name": "",
- "storehose_name": "",
- })
- }
-
- }
-
- func (this *StockManagerApiController) ReturnCheckWarehouseOut() {
-
- id, _ := this.GetInt64("id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- // 开始外部循环的事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
- // 查询出库数据
- list, err := service.GetNewWarehouseOutById(id, orgId, tx)
- for _, item := range list {
- //回退库存
- service.UpdateaNewGoodWarehouseInfo(item.Count, item.GoodId, item.OrgId, item.WarehouseInfotId, tx)
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetNewAllStoreHouseConfig(orgId, tx)
-
- stockList, _ := service.GetNewStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId, tx)
-
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库扣减库存
- service.UpdateNewGoodInfoReduceSumCount(item.GoodId, total_count, orgId, tx)
-
- goodList, _ := service.GetNewSumGoodList(orgId, item.StorehouseId, item.GoodId, tx)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
- service.UpdateNewSumGood(orgId, item.StorehouseId, item.GoodId, flush_count, tx)
-
- //扣减出库数据
- service.ModifyNewReduceGoodSumCount(item.StorehouseId, item.Count, orgId, item.GoodId, tx)
-
- }
- //删除流水,改变审核状态
- service.ModifyNewGoodWarehouseOut(id, tx)
-
- tx.Commit()
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "list",
- })
- }
- }
-
- func (this *StockManagerApiController) CheckWarehouseInfo() {
-
- warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- Creator := this.GetAdminUserInfo().AdminUser.Id
-
- // 开始外部循环的事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetNewAllStoreHouseConfig(orgId, tx)
-
- checker := this.GetAdminUserInfo().AdminUser.Id
- //更改审核状态
- err := service.UpdateNewCheckWarehouseInfo(warehousing_info_id, checker, tx)
- if err == nil {
- list, _ := service.GetNewWarehouseInfoList(warehousing_info_id, orgId, tx)
-
- for _, item := range list {
- service.UpdateNewWarehouseInfoByIdListThree(item.WarehousingCount, item.ID, tx)
-
- //查询该耗材剩余库存库
- stockList, _ := service.GetNewStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId, tx)
- var total_count int64
- var sum_in_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- sum_in_count += it.WarehousingCount
- }
- //基础库插入数据
- service.UpdateNewGoodInfoAddSumCount(item.GoodId, total_count, orgId, sum_in_count, tx)
-
- //查询该仓库是否有数据
- _, errcode := service.GetNewGoodStockCount(orgId, item.StorehouseId, item.GoodId, tx)
-
- goodList, _ := service.GetNewSumGoodList(orgId, item.StorehouseId, item.GoodId, tx)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
- stockFlow := models.VmStockFlow{
- WarehousingId: item.WarehousingId,
- GoodId: item.GoodId,
- Number: item.Number,
- LicenseNumber: item.LicenseNumber,
- Count: item.WarehousingCount,
- UserOrgId: item.OrgId,
- PatientId: 0,
- SystemTime: 0,
- ConsumableType: 1,
- IsSys: 1,
- WarehousingOrder: item.WarehousingOrder,
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 1,
- CancelStockId: 0,
- CancelOrderNumber: "",
- Manufacturer: item.Manufacturer,
- Dealer: item.Dealer,
- Creator: Creator,
- UpdateCreator: 0,
- Status: 1,
- Ctime: item.Ctime,
- Mtime: 0,
- Price: item.PackingPrice,
- WarehousingDetailId: item.ID,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ProductDate: item.ProductDate,
- ExpireDate: item.ExpiryDate,
- SupplyWarehouseId: item.SupplyWarehouseId,
- StorehouseId: item.StorehouseId,
- AdminUserId: 0,
- BuyPrice: item.Price,
- StockCount: "",
- BatchNumberCount: item.WarehousingCount,
- IsCheck: 1,
- OverCount: flush_count,
- OperateTime: time.Now().Unix(),
- GoodCode: item.GoodCode,
- }
- //创建出库流水
- service.CreateNewStockFlowOne(stockFlow, tx)
-
- if errcode == gorm.ErrRecordNotFound {
-
- goodCount := models.XtGoodStockCount{
- UserOrgId: orgId,
- GoodId: item.GoodId,
- StorehouseId: item.StorehouseId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- StockInCount: item.WarehousingCount,
- StockOutCount: 0,
- StockCancelCount: 0,
- FlushCount: flush_count,
- StockActOutCount: 0,
- }
- service.CreateNewGoodCount(goodCount, tx)
- }
- if errcode == nil {
- service.UpdateNewGoodStockCount(orgId, item.StorehouseId, item.GoodId, item.WarehousingCount, flush_count, tx)
- }
- }
- }
-
- tx.Commit()
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "list",
- })
- }
- }
-
- func (this *StockManagerApiController) ReturnCheckWarehouseInfo() {
-
- warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- // 开始外部循环的事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
-
- //查询入库数据
- list, _ := service.GetNewWarehouseInfoList(warehousing_info_id, orgId, tx)
- for _, item := range list {
- //查询该耗材 是否有出库数据
- outlist, _ := service.GetNewWarehouseOutByWarehouseInfoId(item.ID, item.GoodId, item.OrgId, tx)
-
- if len(outlist) > 0 {
- tx.Rollback()
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCheckGoodParamWrong)
- return
- }
- }
-
- err := service.UpdateNewWarehouseInfoMap(list, warehousing_info_id, orgId, tx)
- tx.Commit()
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "反审核成功!",
- })
- return
- }
-
- }
-
- func (this *StockManagerApiController) CheckStockWarehouseInfo() {
-
- cancel_stock_id, _ := this.GetInt64("cancel_stock_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetCancelStockInfoListById(cancel_stock_id, orgId)
- creater := this.GetAdminUserInfo().AdminUser.Id
-
- manufacturerlist, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- var manufacturer_id int64
- var cancel_total_count int64
- var out_total_count int64
- var dealer_id int64
- for _, item := range list {
-
- //查询该药品该批次的出库数量是否满足退库需求
- outList, _ := service.GetWarehouseOutList(item.OrgId, item.GoodId, item.WarehouseInfoId)
- for _, it := range outList {
- out_total_count += it.Count
- }
- warehouseList, _ := service.GetCancelWarehouseList(item.OrgId, item.GoodId, item.WarehouseInfoId)
- for _, it := range warehouseList {
- cancel_total_count += it.Count
- }
- if cancel_total_count > out_total_count {
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- }
- }
-
- cancelStock := models.CancelStock{
- IsCheck: 1,
- }
- service.CheckCancelStock(cancelStock, cancel_stock_id, orgId)
-
- //回退库存
- cancellist, _ := service.GetCancelStockInfoById(cancel_stock_id, orgId)
- for _, item := range cancellist {
- for _, items := range manufacturerlist {
- if item.Manufacturer == items.ManufacturerName {
- manufacturer_id = items.ID
- }
- }
- for _, it := range dealerList {
- if item.Dealer == it.DealerName {
- dealer_id = it.ID
- }
- }
- //回退库存
- service.UpdateCancelStockNumber(item.Count, item.WarehouseInfoId, orgId)
- //更新基础库库存
- service.UpdateGoodSumCount(item.Count, item.GoodId, orgId)
- goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
- //退库数量增加
- service.UpdateSumAddCancelCount(orgId, item.GoodId, item.StorehouseId, item.Count)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- stockFlow := models.VmStockFlow{
- ID: 0,
- WarehousingId: item.WarehouseInfoId,
- GoodId: item.GoodId,
- Number: item.Number,
- LicenseNumber: "",
- Count: item.Count,
- UserOrgId: item.OrgId,
- PatientId: item.PatientId,
- SystemTime: item.RecordDate,
- ConsumableType: 4,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: cancel_stock_id,
- CancelOrderNumber: item.OrderNumber,
- Manufacturer: manufacturer_id,
- Dealer: dealer_id,
- Creator: creater,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: item.Price,
- WarehousingDetailId: item.WarehouseInfoId,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: item.ID,
- ProductDate: item.ProductDate,
- ExpireDate: item.ExpiryDate,
- ReturnCount: 0,
- ProjectId: 0,
- SupplyWarehouseId: 0,
- SupplyCancelOutId: 0,
- SupplyWarehouseDetailInfo: 0,
- StorehouseId: item.StorehouseId,
- SecondWarehouseInfoId: 0,
- AdminUserId: 0,
- BuyPrice: item.Price,
- StockCount: "",
- OverCount: flush_count,
- }
- //创建流水
- service.CreateStockFlowOne(stockFlow)
- //更新剩余库存
- errs := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
-
- //出库数量减少
- service.ModifyAddGoodSumCount(item.StorehouseId, item.Count, orgId, item.GoodId)
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "手动退库更新剩余出库失败",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "good_name": "",
- "specification_name": "",
- })
- return
- }
-
- func (this *StockManagerApiController) CheckReturnStockWarehouseInfo() {
-
- cancel_stock_id, _ := this.GetInt64("cancel_stock_id")
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- cancelStock := models.CancelStock{
- IsCheck: 2,
- }
- list, _ := service.GetCancelStockInfoListById(cancel_stock_id, orgId)
- creater := this.GetAdminUserInfo().AdminUser.Id
- for _, item := range list {
- //回退库存
- service.UpdateStockNumberWarehouseInfo(item.WarehouseInfoId, item.GoodId, item.OrgId, item.Count)
-
- service.UpdateStockWarehouseInfoStockFlow(item.ID, orgId, item.GoodId)
-
- //退库数量增加
- service.UpdateSumReduceCancelCount(orgId, item.GoodId, item.StorehouseId, item.Count)
-
- goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
- errs := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
-
- //出库数量增加
- service.UpdateSumAddOutCount(orgId, item.GoodId, item.StorehouseId, item.Count)
-
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "手动退库反审核更新剩余出库失败",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- }
- err := service.UpdateStockWarehouseInfo(cancel_stock_id, orgId, cancelStock)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "反审核成功!",
- })
- return
- }
- }
-
- func (this *StockManagerApiController) GetPrintList() {
-
- storehouse_id, _ := this.GetInt64("storehouse_id")
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- good_name := this.GetString("good_name")
- ids := this.GetString("ids")
- idSplit := strings.Split(ids, ",")
- fmt.Println(storehouse_id, good_name)
- orgId := this.GetAdminUserInfo().CurrentOrgId
- houseList, _ := service.GetAllStoreHouseList(orgId)
- list, total, _ := service.GetInventoryDetailPrintMapList(good_name, limit, page, orgId, storehouse_id, idSplit)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "houseList": houseList,
- })
- }
-
- func (this *StockManagerApiController) GetInvetoryWarehouseInfoList() {
-
- storehouse_id, _ := this.GetInt64("storehouse_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetInvetoryWarehouseInfoList(orgId, storehouse_id)
- var info []*models.WarehousingInfo
- if orgId == 10571 {
- for _, item := range list {
- if strings.ContainsAny(item.GoodInfo.GoodStatus, "收费") {
- info = append(info, item)
- }
- }
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": info,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- })
- } else {
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "info": info,
- })
- }
-
- }
-
- func (this *StockManagerApiController) GetNewGoodWarehouseInfo() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
-
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- storehouse_id, _ := this.GetInt64("storehouse_id")
-
- keywords := this.GetString("keywords")
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- var goodids []int64
- //查询商品名称
- if len(keywords) > 0 {
- //查询商品名称
- list, _ := service.GetGoodInforByGoodName(keywords, orgId)
- for _, item := range list {
- goodids = append(goodids, item.ID)
- //入库详情但里面查询
- }
- }
-
- list, _ := service.GetNewGoodWarehouseInfo(startTime, endTime, orgId, goodids, storehouse_id)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- storeHouseList, _ := service.GetAllStoreHouseList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "storeHouseList": storeHouseList,
- })
- }
-
- func (this *StockManagerApiController) GetNewWarehouseOutInfoList() {
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := this.GetString("start_time")
- end_time := this.GetString("end_time")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
-
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- storehouse_id, _ := this.GetInt64("storehouse_id")
-
- keywords := this.GetString("keyword")
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- var goodids []int64
- //查询商品名称
- if len(keywords) > 0 {
- //查询商品名称
- list, _ := service.GetGoodInforByGoodName(keywords, orgId)
- for _, item := range list {
- goodids = append(goodids, item.ID)
- //入库详情但里面查询
- }
- }
-
- list, _ := service.GetNewWarehouseOutInfoList(startTime, endTime, orgId, goodids, storehouse_id)
-
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- dealerList, _ := service.GetAllDealerList(orgId)
- storeHouseList, _ := service.GetAllStoreHouseList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- "dealerList": dealerList,
- "storeHouseList": storeHouseList,
- })
- }
-
- func (this *StockManagerApiController) GetStockFlowOrderList() {
-
- good_id, _ := this.GetInt64("good_id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetStockFlowOrderList(good_id, orgId)
- for index, _ := range list {
- if list[index].ConsumableType == 3 || list[index].ConsumableType == 2 || list[index].ConsumableType == 11 || list[index].ConsumableType == 12 || list[index].ConsumableType == 15 {
- var count int64
-
- if index == 0 {
- count = list[index].FlushOverCount - list[index].Count
- service.UpdateOverCount(list[index+1].ID, count)
- }
-
- if index >= 1 {
- lastStockFlow, _ := service.GetLastOverCount(list[index-1].ID)
- count = lastStockFlow.FlushOverCount - list[index].Count
- service.UpdateOverCount(list[index].ID, count)
- }
-
- }
- if list[index].ConsumableType == 7 || list[index].ConsumableType == 4 || list[index].ConsumableType == 1 || list[index].ConsumableType == 10 || list[index].ConsumableType == 13 {
- if index == 0 {
- var count int64
- count = list[index].FlushOverCount + list[index].Count
- service.UpdateOverCount(list[index+1].ID, count)
- }
-
- if index >= 1 {
- var count int64
- lastStockFlow, _ := service.GetLastOverCount(list[index-1].ID)
- count = lastStockFlow.FlushOverCount + list[index].Count
- service.UpdateOverCount(list[index].ID, count)
- }
-
- }
-
- }
- }
-
- func (this *StockManagerApiController) GetGoodPatientName() {
-
- good_id, _ := this.GetInt64("good_id")
-
- sys_record_time, _ := this.GetInt64("sys_record_time")
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- projectList, _ := service.GetGoodProjectList(good_id, sys_record_time, orgId)
-
- outList, _ := service.GetWarehouseOutListBySysrecordTime(good_id, sys_record_time, orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "projectList": projectList,
- "outList": outList,
- })
- }
-
- func (this *StockManagerApiController) UpdateBaseDrugListByUserOrgID() {
-
- //orgId := this.GetAdminUserInfo().CurrentOrgId
-
- //list, _ := service.GetAllBaseDrugList(orgId)
- //
-
- //for _, item := range list {
- // var sum_in_count int64
- // var sum_out_count int64
- // var flush_out_count int64
- // //var str = ""
- // //str = item.Dose + item.DoseUnit + "*" + strconv.FormatInt(item.MinNumber, 10) + item.MinUnit + "/" + item.MaxUnit
- // //service.UpdateBaseDrugById(item.ID, str)
- // //
- // //drug_dosage_form_str := service.GetDosageFormListById(item.DrugDosageForm, orgId)
- // //service.UpdateDosageFormListById(drug_dosage_form_str, item.ID)
- //
- // warehouseinfo, _ := service.GetDrugWarehouseInfoByItemId(item.ID)
- // if len(warehouseinfo) > 0 {
- // for _, it := range warehouseinfo {
- // if item.MaxUnit == it.MaxUnit && item.MaxUnit != item.MinUnit {
- // it.WarehousingCount = it.WarehousingCount * item.MinNumber
- // }
- //
- // if item.MaxUnit == it.MinUnit && item.MaxUnit != item.MinUnit {
- // it.WarehousingCount = it.WarehousingCount
- // }
- //
- // if item.MaxUnit == it.MinUnit && item.MaxUnit == item.MinUnit {
- // it.WarehousingCount = it.WarehousingCount
- // }
- //
- // sum_in_count += it.WarehousingCount
- // }
- //
- // }
- // //
- // outList, _ := service.GetDrugWarehosueOutInfoByItemId(item.ID)
- // if len(outList) > 0 {
- // for _, it := range outList {
- // if item.MaxUnit == it.CountUnit && item.MaxUnit != item.MinUnit {
- // it.Count = it.Count * item.MinNumber
- // }
- //
- // if item.MaxUnit == it.CountUnit && item.MaxUnit != item.MinUnit {
- // it.Count = it.Count
- // }
- //
- // if item.MaxUnit == it.CountUnit && item.MaxUnit == item.MinUnit {
- // it.Count = it.Count
- // }
- //
- // sum_out_count += it.Count
- // }
- // }
- //
- // flush_out_count = sum_in_count - sum_out_count
- // fmt.Println("sum_in_count+++++++++++++", sum_in_count)
- // fmt.Println("sum_out_count++++++++++++++", sum_out_count)
- // fmt.Println("flushi_out_count===========", flush_out_count)
- //
- // service.UpdateBaseDrugByIdCountTwo(item.ID, flush_out_count)
- //}
-
- //info, _ := service.GetDrugAllInfo(orgId)
-
- //info, _ := service.GetDrugOutAllInfo(orgId)
- //
- //for _, item := range info {
- //
- // //dealer, _ := service.GetDealerById(item.Dealer)
- //
- // manufacturer, _ := service.GetManufactureById(item.Manufacturer)
- //
- // service.UpdateDealerManufacturerOne(item.ID, manufacturer.ManufacturerName)
- //}
-
- drugList, _ := service.GetAllBaseDrugListTwentyOne(10215)
-
- for _, item := range drugList {
- var drug_spec = item.Dose + item.DoseUnit + "*" + strconv.FormatInt(item.MinNumber, 10) + item.MinUnit + "/" + item.MaxUnit
-
- service.UpdateBaseDrugList(item.ID, drug_spec)
- }
-
- }
-
- func (this *StockManagerApiController) UpdateGoodInfoByUserOrgId() {
-
- //orgId := this.GetAdminUserInfo().CurrentOrgId
-
- //info, _ := service.GetAllWareHouseOutByUserOrg(10633)
- //
- //if len(info) > 0 {
- // for _, item := range info {
- //
- // //dealer, _ := service.GetDealerById(item.Dealer)
- //
- // //manufacturer, _ := service.GetManufactureById(item.Manufacturer)
- //
- // //service.UpdateGoodInfoByUserOrgIdTwo(item.ID, dealer.DealerName)
- // }
- //}
- goodList, _ := service.GetAllGoodList(10633)
-
- for _, item := range goodList {
- service.UpdateStockFlowByList(item.ID, item.PackingPrice)
- //service.UpdateWarehouseOutInfoByPrice(item.ID, item.PackingPrice)
-
- //outList, _ := service.GetWarehosueOutInfoByPrice(item.ID, 10633)
- //
- //for _, it := range outList {
- // //service.UpdateWarehouseOut(it.ID, item.PackingPrice)
- //
- // service.UpdateStockFlowByList(it.GoodId, item.PackingPrice)
- //}
-
- //good_type_name := service.GetAllGoodTypeName(item.GoodTypeId, orgId)
- //
- //service.UpdateGoodTypeName(item.ID, good_type_name)
- }
-
- //
- //for _, item := range goodList {
- //
- // var sum_in_count int64
- // var sum_out_count int64
- // var flush_out_count int64
- // infor, _ := service.GetAllWarehouseSumInCount(item.ID)
- //
- // for _, item := range infor {
- // sum_in_count += item.WarehousingCount
- // }
- //
- // outInfo, _ := service.GetAllWarehouseSumOutCount(item.ID)
- //
- // for _, item := range outInfo {
- // sum_out_count += item.Count
- // }
- //
- // flush_out_count = sum_in_count - sum_out_count
- //
- // service.UpdateGoodInfoByIdOne(item.ID, flush_out_count)
- //}
-
- }
-
- func (this *StockManagerApiController) GetGoodStockInventoryList() {
-
- keyword := this.GetString("keyword")
-
- limit, _ := this.GetInt64("limit")
-
- page, _ := this.GetInt64("page")
-
- storehouse_id, _ := this.GetInt64("storehouse_id")
-
- start_time := this.GetString("start_time")
-
- end_time := this.GetString("end_time")
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
- appId := this.GetAdminUserInfo().CurrentAppId
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
-
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- list, total, _ := service.GetGoodStockInventoryList(keyword, limit, page, storehouse_id, startTime, endTime, orgId)
- doclist, _ := service.GetAllDoctorListSix(orgId, appId)
-
- storeHouseList, _ := service.GetAllStoreHouseList(orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "storeHouseList": storeHouseList,
- "doclist": doclist,
- })
- }
-
- func (this *StockManagerApiController) GetStockInventoryPrintList() {
-
- storehouse_id, _ := this.GetInt64("storehouse_id")
-
- keyword := this.GetString("keyword")
-
- limit, _ := this.GetInt64("limit")
-
- page, _ := this.GetInt64("page")
-
- ids := this.GetString("ids")
-
- p_ids_arr := strings.Split(ids, ",")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- appId := this.GetAdminUserInfo().CurrentAppId
- list, total, _ := service.GetStockInventoryPrintList(storehouse_id, keyword, limit, page, p_ids_arr, orgId)
-
- doclist, _ := service.GetAllDoctorListSix(orgId, appId)
-
- storeHouseList, _ := service.GetAllStoreHouseList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- "storeHouseList": storeHouseList,
- "doclist": doclist,
- })
- }
-
- func (this *StockManagerApiController) GetStockInventoryModePrintList() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- start_time := this.GetString("start_time")
-
- end_time := this.GetString("end_time")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
-
- }
-
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- goodInfo, _ := service.FindAllGoodInfoThree(orgId)
-
- //获取所有入库数量
-
- list, _ := service.GetInventoryExportList(orgId)
-
- infoList, _ := service.GetGoodWarehouseInfoList(startTime, endTime, orgId)
-
- outinfo, _ := service.GetGoodWarhouseOutList(startTime, endTime, orgId)
-
- //获取盘盈的数据
- flowProList, _ := service.GetGoodStockFlowProList(startTime, endTime, orgId)
-
- //获取盘亏的数据
- flowNoProList, _ := service.GetGoodStockFlowNoProList(startTime, endTime, orgId)
-
- //获取盘点退库
- CancelFlowList, _ := service.GetCancelStockFlowList(startTime, endTime, orgId)
-
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
-
- //获取期初结余数量
- warehouseinfo, _ := service.GetLastMonthCount(startTime, orgId)
-
- //期出结余出库数量
- warehouseOutInfo, _ := service.GetLastMonthOverCount(startTime, orgId)
-
- cancelInfo, _ := service.GetLastCancelMonthCount(startTime, orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "infoList": infoList,
- "outinfo": outinfo,
- "flowProList": flowProList,
- "flowNoProList": flowNoProList,
- "manufacturerList": manufacturerList,
- "goodInfo": goodInfo,
- "warehouseinfo": warehouseinfo,
- "warehouseOutInfo": warehouseOutInfo,
- "cancelInfo": cancelInfo,
- "CancelFlowList": CancelFlowList,
- })
-
- }
|