stock_in_api_controller.go 276KB

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