stock_in_api_controller.go 262KB

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