stock_in_api_controller.go 252KB

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