stock_in_api_controller.go 253KB

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