stock_in_api_controller.go 261KB

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