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. //
  3917. //drug.IsSelfDrug = is_self_drug
  3918. if len(dose) < 0 { //名字为空则生成一条导入错误日志
  3919. err_log := models.ExportErrLog{
  3920. LogType: 4,
  3921. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3922. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  3923. Status: 1,
  3924. CreateTime: time.Now().Unix(),
  3925. UpdateTime: time.Now().Unix(),
  3926. ExportTime: time.Now().Unix(),
  3927. }
  3928. service.CreateExportErrLog(&err_log)
  3929. continue
  3930. }
  3931. drug.Dose = dose
  3932. if len(dose) < 0 { //名字为空则生成一条导入错误日志
  3933. err_log := models.ExportErrLog{
  3934. LogType: 4,
  3935. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3936. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  3937. Status: 1,
  3938. CreateTime: time.Now().Unix(),
  3939. UpdateTime: time.Now().Unix(),
  3940. ExportTime: time.Now().Unix(),
  3941. }
  3942. service.CreateExportErrLog(&err_log)
  3943. continue
  3944. }
  3945. drugList = append(drugList, &drug)
  3946. }
  3947. export_time := time.Now().Unix()
  3948. errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3949. if len(drugList) > 0 {
  3950. for _, item := range drugList {
  3951. hans := item.DrugName // 要转换的汉字字符串
  3952. // 创建一个拼音转换器
  3953. p := pinyin.NewArgs()
  3954. // 将汉字转为拼音
  3955. pinyinSlice := pinyin.Pinyin(hans, p)
  3956. // 输出拼音
  3957. fmt.Println("Pinyin:", pinyinSlice)
  3958. // 获取首字母
  3959. firstLetter := ""
  3960. for _, py := range pinyinSlice {
  3961. if len(py) > 0 {
  3962. firstLetter += string(py[0][0])
  3963. }
  3964. }
  3965. item.FirstLetter = firstLetter
  3966. item.Pinyin = firstLetter
  3967. goodInfo := models.BaseDrugLib{
  3968. DrugName: item.DrugName,
  3969. DrugAlias: item.DrugAlias,
  3970. DrugSpec: item.DrugSpec,
  3971. DrugType: item.DrugType,
  3972. DrugStockLimit: item.DrugStockLimit,
  3973. DrugOriginPlace: item.DrugOriginPlace,
  3974. DrugDosageForm: item.DrugDosageForm,
  3975. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  3976. MaxUnit: item.MaxUnit,
  3977. MinUnit: item.MinUnit,
  3978. UnitMatrixing: item.UnitMatrixing,
  3979. RetailPrice: item.RetailPrice,
  3980. LastPrice: item.LastPrice,
  3981. DrugClassify: item.DrugClassify,
  3982. Manufacturer: item.Manufacturer,
  3983. Dealer: item.Dealer,
  3984. OrgId: orgId,
  3985. Status: 1,
  3986. Ctime: time.Now().Unix(),
  3987. Pinyin: item.Pinyin,
  3988. Wubi: item.Wubi,
  3989. DrugAliasPinyin: item.DrugAliasPinyin,
  3990. DrugAliasWubi: item.DrugAliasWubi,
  3991. DrugControl: item.DrugControl,
  3992. Number: item.Number,
  3993. HospApprFlag: item.HospApprFlag,
  3994. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  3995. PharmacologyCategory: item.PharmacologyCategory,
  3996. StatisticsCategory: item.StatisticsCategory,
  3997. Code: item.Code,
  3998. IsSpecialDiseases: item.IsSpecialDiseases,
  3999. IsRecord: item.IsRecord,
  4000. PrescriptionMark: item.PrescriptionMark,
  4001. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  4002. RecordDate: item.RecordDate,
  4003. DrugRemark: item.DrugRemark,
  4004. DrugStatus: item.DrugStatus,
  4005. LimitRemark: item.LimitRemark,
  4006. DrugCategory: item.DrugCategory,
  4007. DrugDose: item.DrugDose,
  4008. SingleDose: item.DrugDose,
  4009. DrugDoseUnit: item.DrugDoseUnit,
  4010. LmtUsedFlag: item.LmtUsedFlag,
  4011. DrugDay: item.DrugDay,
  4012. DeliveryWay: item.DeliveryWay,
  4013. ExecutionFrequency: item.ExecutionFrequency,
  4014. DoseUnit: item.DoseUnit,
  4015. Dose: item.Dose,
  4016. MinNumber: item.MinNumber,
  4017. IsUse: 2,
  4018. MinPrice: item.MinPrice,
  4019. PrescribingNumber: item.PrescribingNumber,
  4020. PrescribingNumberUnit: item.PrescribingNumberUnit,
  4021. FirstLetter: item.FirstLetter,
  4022. IsSelfDrug: item.IsSelfDrug,
  4023. }
  4024. //查询同种药品同种规格是否存在
  4025. _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.DoseUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
  4026. if drugerror == gorm.ErrRecordNotFound {
  4027. service.CreateDrugsInfomation(&goodInfo)
  4028. } else if drugerror == nil {
  4029. service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
  4030. }
  4031. log := models.ExportLog{
  4032. LogType: 4,
  4033. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4034. TotalNum: int64(len(total_goods)),
  4035. FailNum: int64(len(errLogs)),
  4036. SuccessNum: int64(len(drugList)),
  4037. CreateTime: time.Now().Unix(),
  4038. UpdateTime: time.Now().Unix(),
  4039. ExportTime: export_time,
  4040. Status: 1,
  4041. }
  4042. service.CreateExportLog(&log)
  4043. this.ServeSuccessJSON(map[string]interface{}{
  4044. "msg": "导入成功",
  4045. "total_num": len(total_goods),
  4046. "success_num": len(drugList),
  4047. "fail_num": int64(len(errLogs)),
  4048. })
  4049. }
  4050. } else {
  4051. log := models.ExportLog{
  4052. LogType: 4,
  4053. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  4054. TotalNum: int64(len(total_goods)),
  4055. FailNum: int64(len(errLogs)),
  4056. SuccessNum: int64(len(drugList)),
  4057. CreateTime: time.Now().Unix(),
  4058. UpdateTime: time.Now().Unix(),
  4059. ExportTime: export_time,
  4060. Status: 1,
  4061. }
  4062. service.CreateExportLog(&log)
  4063. this.ServeSuccessJSON(map[string]interface{}{
  4064. "msg": "导入成功",
  4065. "total_num": len(total_goods),
  4066. "success_num": len(drugList),
  4067. "fail_num": int64(len(errLogs)),
  4068. })
  4069. }
  4070. }
  4071. func (this *StockManagerApiController) GetInitializtion() {
  4072. orgId := this.GetAdminUserInfo().CurrentOrgId
  4073. var drugCategory = "药品类别"
  4074. var drugType = "药品类型"
  4075. var drugDosageForm = "药品剂型"
  4076. var medicalInsuranceLevel = "医保等级"
  4077. var drugControl = "开药控制"
  4078. var drugClassify = "药物分类"
  4079. var statisticsCategory = "统计分类"
  4080. var pharmacologyCategory = "药理分类"
  4081. var goodKind = "耗材种类"
  4082. var tubeColor = "试管颜色"
  4083. var costClassify = "费用类别"
  4084. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  4085. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  4086. drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
  4087. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
  4088. drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
  4089. drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
  4090. medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
  4091. medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
  4092. drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
  4093. drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
  4094. drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
  4095. drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
  4096. statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
  4097. statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
  4098. pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
  4099. pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
  4100. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  4101. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
  4102. tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
  4103. tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
  4104. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  4105. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
  4106. this.ServeSuccessJSON(map[string]interface{}{
  4107. "drugCategoryList": drugCategoryList,
  4108. "drugTypeList": drugTypeList,
  4109. "drugDosageFormList": drugDosageFormList,
  4110. "medicalInsuranceLevelList": medicalInsuranceLevelList,
  4111. "drugControlList": drugControlList,
  4112. "drugClassifyList": drugClassifyList,
  4113. "statisticsCategoryList": statisticsCategoryList,
  4114. "pharmacologyCategoryList": pharmacologyCategoryList,
  4115. "goodKindList": goodKindList,
  4116. "tubeColorList": tubeColorList,
  4117. "costClassifyList": costClassifyList,
  4118. })
  4119. }
  4120. func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
  4121. adminUserInfo := this.GetAdminUserInfo()
  4122. orgId := adminUserInfo.CurrentOrgId
  4123. list, _ := service.GetWarehouseOrderInfoList(orgId)
  4124. this.ServeSuccessJSON(map[string]interface{}{
  4125. "list": list,
  4126. })
  4127. }
  4128. func (this *StockManagerApiController) PostSearchGoodList() {
  4129. keyword := this.GetString("keyword")
  4130. adminUserInfo := this.GetAdminUserInfo()
  4131. orgId := adminUserInfo.CurrentOrgId
  4132. storehouse_id, _ := this.GetInt64("storehouse_id")
  4133. list, _ := service.GetSearchGoodListSix(keyword, orgId, storehouse_id)
  4134. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4135. dealerList, _ := service.GetAllDealerList(orgId)
  4136. this.ServeSuccessJSON(map[string]interface{}{
  4137. "list": list,
  4138. "manufacturerList": manufacturerList,
  4139. "dealerList": dealerList,
  4140. })
  4141. }
  4142. func (this *StockManagerApiController) GetAllStockList() {
  4143. page, _ := this.GetInt64("page", -1)
  4144. limit, _ := this.GetInt64("limit", -1)
  4145. start_time := this.GetString("start_time")
  4146. end_time := this.GetString("end_time")
  4147. types, _ := this.GetInt64("type", 0)
  4148. keywords := this.GetString("keywords")
  4149. good_id, _ := this.GetInt64("good_id")
  4150. storehouse_id, _ := this.GetInt64("storehouse_id")
  4151. timeLayout := "2006-01-02"
  4152. loc, _ := time.LoadLocation("Local")
  4153. var startTime int64
  4154. if len(start_time) > 0 {
  4155. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4156. if err != nil {
  4157. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4158. return
  4159. }
  4160. startTime = theTime.Unix()
  4161. }
  4162. var endTime int64
  4163. if len(end_time) > 0 {
  4164. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4165. if err != nil {
  4166. utils.ErrorLog(err.Error())
  4167. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4168. return
  4169. }
  4170. endTime = theTime.Unix()
  4171. }
  4172. adminUserInfo := this.GetAdminUserInfo()
  4173. orgId := adminUserInfo.CurrentOrgId
  4174. list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId, good_id, storehouse_id)
  4175. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4176. this.ServeSuccessJSON(map[string]interface{}{
  4177. "list": list,
  4178. "total": total,
  4179. "manufacturerList": manufacturerList,
  4180. })
  4181. }
  4182. func (this *StockManagerApiController) GetStockListById() {
  4183. id, _ := this.GetInt64("id")
  4184. adminUserInfo := this.GetAdminUserInfo()
  4185. orgId := adminUserInfo.CurrentOrgId
  4186. limit, _ := this.GetInt64("limit")
  4187. page, _ := this.GetInt64("page")
  4188. timeLayout := "2006-01-02"
  4189. loc, _ := time.LoadLocation("Local")
  4190. start_time := this.GetString("start_time")
  4191. end_time := this.GetString("end_time")
  4192. start_first_time := this.GetString("start_first_time")
  4193. end_first_time := this.GetString("end_first_time")
  4194. var startTime int64
  4195. if len(start_time) > 0 {
  4196. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4197. if err != nil {
  4198. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4199. return
  4200. }
  4201. startTime = theTime.Unix()
  4202. }
  4203. var endTime int64
  4204. if len(end_time) > 0 {
  4205. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4206. if err != nil {
  4207. utils.ErrorLog(err.Error())
  4208. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4209. return
  4210. }
  4211. endTime = theTime.Unix()
  4212. }
  4213. var startFistTime int64
  4214. if len(start_first_time) > 0 {
  4215. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_first_time+" 00:00:00", loc)
  4216. if err != nil {
  4217. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4218. return
  4219. }
  4220. startFistTime = theTime.Unix()
  4221. }
  4222. var endFirstTime int64
  4223. if len(end_first_time) > 0 {
  4224. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_first_time+" 23:59:59", loc)
  4225. if err != nil {
  4226. utils.ErrorLog(err.Error())
  4227. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4228. return
  4229. }
  4230. endFirstTime = theTime.Unix()
  4231. }
  4232. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4233. list, total, _ := service.GetStockListById(id, orgId, limit, page, startTime, endTime, startFistTime, endFirstTime)
  4234. houseList, _ := service.GetAllStoreHouseList(orgId)
  4235. good, _ := service.GetGoodInformationByGoodId(id)
  4236. this.ServeSuccessJSON(map[string]interface{}{
  4237. "list": list,
  4238. "total": total,
  4239. "manufacturerList": manufacturerList,
  4240. "houseList": houseList,
  4241. "good": good,
  4242. })
  4243. }
  4244. func (this *StockManagerApiController) GetStockOutList() {
  4245. id, _ := this.GetInt64("id")
  4246. adminUserInfo := this.GetAdminUserInfo()
  4247. orgId := adminUserInfo.CurrentOrgId
  4248. limit, _ := this.GetInt64("limit")
  4249. page, _ := this.GetInt64("page")
  4250. timeLayout := "2006-01-02"
  4251. loc, _ := time.LoadLocation("Local")
  4252. start_time := this.GetString("start_time")
  4253. end_time := this.GetString("end_time")
  4254. is_sys, _ := this.GetInt64("is_sys")
  4255. var startTime int64
  4256. if len(start_time) > 0 {
  4257. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4258. if err != nil {
  4259. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4260. return
  4261. }
  4262. startTime = theTime.Unix()
  4263. }
  4264. var endTime int64
  4265. if len(end_time) > 0 {
  4266. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4267. if err != nil {
  4268. utils.ErrorLog(err.Error())
  4269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4270. return
  4271. }
  4272. endTime = theTime.Unix()
  4273. }
  4274. outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
  4275. this.ServeSuccessJSON(map[string]interface{}{
  4276. "outList": outList,
  4277. "total": total,
  4278. })
  4279. }
  4280. func (this *StockManagerApiController) GetStockDrugCount() {
  4281. adminUserInfo := this.GetAdminUserInfo()
  4282. orgId := adminUserInfo.CurrentOrgId
  4283. fmt.Println(orgId)
  4284. timeLayout := "2006-01-02"
  4285. loc, _ := time.LoadLocation("Local")
  4286. start_time := this.GetString("start_time")
  4287. end_time := this.GetString("end_time")
  4288. var startTime int64
  4289. if len(start_time) > 0 {
  4290. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4291. if err != nil {
  4292. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4293. return
  4294. }
  4295. startTime = theTime.Unix()
  4296. }
  4297. var endTime int64
  4298. if len(end_time) > 0 {
  4299. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4300. if err != nil {
  4301. utils.ErrorLog(err.Error())
  4302. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4303. return
  4304. }
  4305. endTime = theTime.Unix()
  4306. }
  4307. count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
  4308. outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
  4309. autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
  4310. totalCount, _ := service.GetCancelOutTotalCount(startTime, endTime, orgId)
  4311. this.ServeSuccessJSON(map[string]interface{}{
  4312. "count": count,
  4313. "outList": outList,
  4314. "autoCount": autoCount,
  4315. "totalCount": totalCount,
  4316. })
  4317. }
  4318. func (this *StockManagerApiController) GetOrderDetialByOrderId() {
  4319. ids := this.GetString("id")
  4320. idsArray := strings.Split(ids, ",")
  4321. orgId := this.GetAdminUserInfo().CurrentOrgId
  4322. order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
  4323. list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
  4324. stockFlowListGroup, _ := service.GetOrderDetailStockFlowByStorehouseById(idsArray, orgId)
  4325. stockFlowList, _ := service.GetOrderDetailStockFlow(idsArray, orgId)
  4326. //获取耗材退库数据
  4327. cancelInfolist, _ := service.GetOrderStockFlow(idsArray, orgId)
  4328. this.ServeSuccessJSON(map[string]interface{}{
  4329. "list": list,
  4330. "order": order,
  4331. "stockFlowList": stockFlowList,
  4332. "stockFlowListGroup": stockFlowListGroup,
  4333. "cancelInfolist": cancelInfolist,
  4334. })
  4335. }
  4336. func (this *StockManagerApiController) GetOrderDetailById() {
  4337. id, _ := this.GetInt64("id")
  4338. good_id, _ := this.GetInt64("good_id")
  4339. record_time, _ := this.GetInt64("record_time")
  4340. orgId := this.GetAdminUserInfo().CurrentOrgId
  4341. //自动出库
  4342. userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
  4343. fmt.Println("userDetails00---------", userDetails)
  4344. //手动出库
  4345. info, _ := service.GetWarehouseOutInfoById(id, good_id)
  4346. //出库数据
  4347. stockFlowList, err := service.GetStockFlowBatchNumberOne(id, good_id)
  4348. fmt.Println("stockFlowList", stockFlowList)
  4349. //退库数据
  4350. cancelInfo, err := service.GetStockFlowCancelInfo(id, good_id)
  4351. if err == nil {
  4352. this.ServeSuccessJSON(map[string]interface{}{
  4353. "list": userDetails,
  4354. "total": total,
  4355. "info": info,
  4356. "stockFlowList": stockFlowList,
  4357. "cancelInfo": cancelInfo,
  4358. })
  4359. } else {
  4360. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4361. return
  4362. }
  4363. }
  4364. func (this *StockManagerApiController) GetSingleOutOrderDetail() {
  4365. id, _ := this.GetInt64("id", 0)
  4366. orgId := this.GetAdminUserInfo().CurrentOrgId
  4367. warehouseOutInfo, _ := service.GetOrderDetialByOrderId(id, orgId)
  4368. out, _ := service.GetGoodWarehouseOutById(id, orgId)
  4369. storelist, _ := service.GetAllStoreHouseList(orgId)
  4370. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4371. dealerList, _ := service.GetAllDealerList(orgId)
  4372. goodType, _ := service.GetAllGoodType(orgId)
  4373. appId := this.GetAdminUserInfo().CurrentAppId
  4374. doctorlist, _ := service.GetAllDoctorListSix(orgId, appId)
  4375. patients, _ := service.GetAllpatientTwenty(orgId)
  4376. this.ServeSuccessJSON(map[string]interface{}{
  4377. "list": warehouseOutInfo,
  4378. "dealerList": dealerList,
  4379. "manufacturerList": manufacturerList,
  4380. "goodType": goodType,
  4381. "out": out,
  4382. "storelist": storelist,
  4383. "doctorlist": doctorlist,
  4384. "patients": patients,
  4385. })
  4386. }
  4387. func (this *StockManagerApiController) GetExprotStockList() {
  4388. adminUserInfo := this.GetAdminUserInfo()
  4389. orgId := adminUserInfo.CurrentOrgId
  4390. timeLayout := "2006-01-02"
  4391. loc, _ := time.LoadLocation("Local")
  4392. start_time := this.GetString("start_time")
  4393. end_time := this.GetString("end_time")
  4394. storehouse_id, _ := this.GetInt64("storehouse_id")
  4395. idArray := this.GetString("id")
  4396. ids := strings.Split(idArray, ",")
  4397. var startTime int64
  4398. if len(start_time) > 0 {
  4399. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4400. if err != nil {
  4401. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4402. return
  4403. }
  4404. startTime = theTime.Unix()
  4405. }
  4406. var endTime int64
  4407. if len(end_time) > 0 {
  4408. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4409. if err != nil {
  4410. utils.ErrorLog(err.Error())
  4411. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4412. return
  4413. }
  4414. endTime = theTime.Unix()
  4415. }
  4416. list, _ := service.GetExprotStockListTwenty(orgId, ids, startTime, endTime, storehouse_id)
  4417. this.ServeSuccessJSON(map[string]interface{}{
  4418. "list": list,
  4419. })
  4420. }
  4421. func (this *StockManagerApiController) GetOutExprotList() {
  4422. adminUserInfo := this.GetAdminUserInfo()
  4423. orgId := adminUserInfo.CurrentOrgId
  4424. timeLayout := "2006-01-02"
  4425. loc, _ := time.LoadLocation("Local")
  4426. start_time := this.GetString("start_time")
  4427. end_time := this.GetString("end_time")
  4428. idArray := this.GetString("id")
  4429. ids := strings.Split(idArray, ",")
  4430. var startTime int64
  4431. if len(start_time) > 0 {
  4432. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4433. if err != nil {
  4434. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4435. return
  4436. }
  4437. startTime = theTime.Unix()
  4438. }
  4439. var endTime int64
  4440. if len(end_time) > 0 {
  4441. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4442. if err != nil {
  4443. utils.ErrorLog(err.Error())
  4444. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4445. return
  4446. }
  4447. endTime = theTime.Unix()
  4448. }
  4449. list, _ := service.GetOutExprotList(orgId, ids, startTime, endTime)
  4450. outCount, _ := service.GetOutStockTotalCountOne(startTime, endTime, orgId)
  4451. this.ServeSuccessJSON(map[string]interface{}{
  4452. "list": list,
  4453. "count": outCount,
  4454. })
  4455. }
  4456. func (this *StockManagerApiController) GetSingleCancelOrder() {
  4457. id, _ := this.GetInt64("id")
  4458. adminUserInfo := this.GetAdminUserInfo()
  4459. orgId := adminUserInfo.CurrentOrgId
  4460. order, _ := service.GetSingleCancelOrder(id, orgId)
  4461. this.ServeSuccessJSON(map[string]interface{}{
  4462. "list": order,
  4463. })
  4464. }
  4465. func (this *StockManagerApiController) GetCancelStockOrderPrint() {
  4466. id := this.GetString("id")
  4467. idStr := strings.Split(id, ",")
  4468. orgId := this.GetAdminUserInfo().CurrentOrgId
  4469. list, _ := service.GetCancelStockOrderPrintOne(idStr, orgId)
  4470. this.ServeSuccessJSON(map[string]interface{}{
  4471. "list": list,
  4472. })
  4473. }
  4474. func (this *StockManagerApiController) GetStockBatchNumber() {
  4475. id, _ := this.GetInt64("id")
  4476. storehouse_id, _ := this.GetInt64("storehouse_id")
  4477. orgId := this.GetAdminUserInfo().CurrentOrgId
  4478. list, _ := service.GetStockBatchNumber(id, orgId)
  4479. lastWarehouseInfoTwo, _ := service.GetLastWarehouseInfoTwo(id, storehouse_id, orgId)
  4480. this.ServeSuccessJSON(map[string]interface{}{
  4481. "list": list,
  4482. "lastWarehouseInfoTwo": lastWarehouseInfoTwo,
  4483. })
  4484. }
  4485. func (this *StockManagerApiController) GetStockFlow() {
  4486. limit, _ := this.GetInt64("limit")
  4487. page, _ := this.GetInt64("page")
  4488. good_id, _ := this.GetInt64("good_id")
  4489. consumable_type, _ := this.GetInt64("is_sys")
  4490. adminUserInfo := this.GetAdminUserInfo()
  4491. orgId := adminUserInfo.CurrentOrgId
  4492. timeLayout := "2006-01-02"
  4493. loc, _ := time.LoadLocation("Local")
  4494. start_time := this.GetString("start_time")
  4495. end_time := this.GetString("end_time")
  4496. var startTime int64
  4497. if len(start_time) > 0 {
  4498. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4499. if err != nil {
  4500. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4501. return
  4502. }
  4503. startTime = theTime.Unix()
  4504. }
  4505. var endTime int64
  4506. if len(end_time) > 0 {
  4507. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4508. if err != nil {
  4509. utils.ErrorLog(err.Error())
  4510. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4511. return
  4512. }
  4513. endTime = theTime.Unix()
  4514. }
  4515. list, total, _ := service.GetStockFlowList(limit, page, consumable_type, orgId, startTime, endTime, good_id)
  4516. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4517. good, _ := service.GetGoodInformationByGoodId(good_id)
  4518. houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  4519. patients, _ := service.GetAllPatientListSix(adminUserInfo.CurrentOrgId)
  4520. this.ServeSuccessJSON(map[string]interface{}{
  4521. "list": list,
  4522. "total": total,
  4523. "manufacturerList": manufacturerList,
  4524. "good": good,
  4525. "houseList": houseList,
  4526. "patients": patients,
  4527. })
  4528. }
  4529. func (this *StockManagerApiController) GetCancelExportList() {
  4530. adminUserInfo := this.GetAdminUserInfo()
  4531. orgId := adminUserInfo.CurrentOrgId
  4532. timeLayout := "2006-01-02"
  4533. loc, _ := time.LoadLocation("Local")
  4534. start_time := this.GetString("start_time")
  4535. end_time := this.GetString("end_time")
  4536. idArray := this.GetString("order_id")
  4537. fmt.Println("232323232323232232", idArray)
  4538. ids := strings.Split(idArray, ",")
  4539. var startTime int64
  4540. if len(start_time) > 0 {
  4541. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4542. if err != nil {
  4543. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4544. return
  4545. }
  4546. startTime = theTime.Unix()
  4547. }
  4548. var endTime int64
  4549. if len(end_time) > 0 {
  4550. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4551. if err != nil {
  4552. utils.ErrorLog(err.Error())
  4553. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4554. return
  4555. }
  4556. endTime = theTime.Unix()
  4557. }
  4558. list, _ := service.GetCancelExportList(startTime, endTime, ids, orgId)
  4559. this.ServeSuccessJSON(map[string]interface{}{
  4560. "list": list,
  4561. })
  4562. }
  4563. func (this *StockManagerApiController) GetSearchGoodWarehouseList() {
  4564. keyword := this.GetString("keyword")
  4565. storehouse_id, _ := this.GetInt64("storehouse_id")
  4566. orgId := this.GetAdminUserInfo().CurrentOrgId
  4567. list, _ := service.GetSearchGoodWarehouseList(keyword, orgId, storehouse_id)
  4568. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4569. dealerList, _ := service.GetAllDealerList(orgId)
  4570. this.ServeSuccessJSON(map[string]interface{}{
  4571. "list": list,
  4572. "manufacturerList": manufacturerList,
  4573. "dealerList": dealerList,
  4574. })
  4575. }
  4576. func (this *StockManagerApiController) SaveAdjuestPrice() {
  4577. timeLayout := "2006-01-02"
  4578. loc, _ := time.LoadLocation("Local")
  4579. dataBody := make(map[string]interface{}, 0)
  4580. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4581. if err != nil {
  4582. utils.ErrorLog(err.Error())
  4583. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4584. return
  4585. }
  4586. tableData, _ := dataBody["tableData"].([]interface{})
  4587. if len(tableData) > 0 {
  4588. for _, item := range tableData {
  4589. items := item.(map[string]interface{})
  4590. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4591. utils.ErrorLog("good_name")
  4592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4593. return
  4594. }
  4595. good_name := items["good_name"].(string)
  4596. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4597. utils.ErrorLog("good_name")
  4598. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4599. return
  4600. }
  4601. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4602. utils.ErrorLog("packing_price")
  4603. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4604. return
  4605. }
  4606. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4607. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4608. utils.ErrorLog("warehousing_order")
  4609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4610. return
  4611. }
  4612. warehousing_order := items["warehousing_order"].(string)
  4613. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4614. utils.ErrorLog("license_number")
  4615. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4616. return
  4617. }
  4618. license_number := items["license_number"].(string)
  4619. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4620. utils.ErrorLog("dealer")
  4621. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4622. return
  4623. }
  4624. dealer := items["dealer"].(string)
  4625. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4626. utils.ErrorLog("manufacturer")
  4627. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4628. return
  4629. }
  4630. manufacturer := items["manufacturer"].(string)
  4631. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4632. utils.ErrorLog("specification_name")
  4633. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4634. return
  4635. }
  4636. specification_name := items["specification_name"].(string)
  4637. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4638. utils.ErrorLog("remark")
  4639. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4640. return
  4641. }
  4642. remark := items["remark"].(string)
  4643. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4644. utils.ErrorLog("warehousing_unit")
  4645. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4646. return
  4647. }
  4648. warehousing_unit := items["warehousing_unit"].(string)
  4649. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4650. utils.ErrorLog("buy_price")
  4651. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4652. return
  4653. }
  4654. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4655. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4656. utils.ErrorLog("count")
  4657. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4658. return
  4659. }
  4660. count := int64(items["count"].(float64))
  4661. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  4662. utils.ErrorLog("new_price")
  4663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4664. return
  4665. }
  4666. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  4667. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4668. utils.ErrorLog("good_id")
  4669. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4670. return
  4671. }
  4672. good_id := int64(items["good_id"].(float64))
  4673. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4674. utils.ErrorLog("start_time")
  4675. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4676. return
  4677. }
  4678. var startTime int64
  4679. start_time := items["start_time"].(string)
  4680. if len(start_time) > 0 {
  4681. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4682. if err != nil {
  4683. fmt.Println(err)
  4684. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4685. return
  4686. }
  4687. startTime = theTime.Unix()
  4688. }
  4689. orgId := this.GetAdminUserInfo().CurrentOrgId
  4690. adjustprice := models.XtStockAdjustPrice{
  4691. GoodName: good_name,
  4692. SpecificationName: specification_name,
  4693. WarehousingUnit: warehousing_unit,
  4694. Count: count,
  4695. BuyPrice: buy_price,
  4696. PackingPrice: packing_price,
  4697. NewPrice: new_price,
  4698. Manufacturer: manufacturer,
  4699. Dealer: dealer,
  4700. Remark: remark,
  4701. GoodId: good_id,
  4702. UserOrgId: orgId,
  4703. Ctime: time.Now().Unix(),
  4704. Mtime: 0,
  4705. Status: 1,
  4706. WarehousingOrder: warehousing_order,
  4707. LicenseNumber: license_number,
  4708. StartTime: startTime,
  4709. Creater: this.GetAdminUserInfo().AdminUser.Id,
  4710. CheckerStatus: 2,
  4711. }
  4712. service.CreateAdjustPrice(&adjustprice)
  4713. }
  4714. }
  4715. this.ServeSuccessJSON(map[string]interface{}{
  4716. "msg": "保存成功!",
  4717. })
  4718. }
  4719. func (this *StockManagerApiController) GetAllStockPrice() {
  4720. timeLayout := "2006-01-02"
  4721. loc, _ := time.LoadLocation("Local")
  4722. dataBody := make(map[string]interface{}, 0)
  4723. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4724. fmt.Println(err)
  4725. orgId := this.GetAdminUserInfo().CurrentOrgId
  4726. keyword := this.GetString("keyword")
  4727. start_time := this.GetString("start_time")
  4728. end_time := this.GetString("end_time")
  4729. limit, _ := this.GetInt64("limit")
  4730. page, _ := this.GetInt64("page")
  4731. var startTime int64
  4732. if len(start_time) > 0 {
  4733. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4734. if err != nil {
  4735. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4736. return
  4737. }
  4738. startTime = theTime.Unix()
  4739. }
  4740. var endTime int64
  4741. if len(end_time) > 0 {
  4742. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4743. if err != nil {
  4744. utils.ErrorLog(err.Error())
  4745. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4746. return
  4747. }
  4748. endTime = theTime.Unix()
  4749. }
  4750. list, total, _ := service.GetAllStockPrice(orgId, startTime, endTime, keyword, limit, page)
  4751. doctor, _ := service.GetAllDoctorThree(orgId)
  4752. this.ServeSuccessJSON(map[string]interface{}{
  4753. "list": list,
  4754. "doctor": doctor,
  4755. "total": total,
  4756. })
  4757. }
  4758. func (this *StockManagerApiController) SaveCheckPrice() {
  4759. timeLayout := "2006-01-02"
  4760. loc, _ := time.LoadLocation("Local")
  4761. dataBody := make(map[string]interface{}, 0)
  4762. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4763. fmt.Println(err)
  4764. idstr := this.GetString("ids")
  4765. ids := strings.Split(idstr, ",")
  4766. check_time := this.GetString("check_time")
  4767. var checkTime int64
  4768. if len(check_time) > 0 {
  4769. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  4770. if err != nil {
  4771. fmt.Println(err)
  4772. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4773. return
  4774. }
  4775. checkTime = theTime.Unix()
  4776. }
  4777. checker, _ := this.GetInt64("checker")
  4778. adjustPrice := models.XtStockAdjustPrice{
  4779. Checker: checker,
  4780. CheckerStatus: 1,
  4781. CheckerTime: checkTime,
  4782. }
  4783. err = service.UpdateAdjustPrice(ids, adjustPrice)
  4784. fmt.Println(err)
  4785. list, _ := service.GetAdjustCheckPriceList(ids)
  4786. fmt.Println("list2333223323232323232323", list)
  4787. for _, item := range list {
  4788. info := models.GoodInfo{
  4789. PackingPrice: item.NewPrice,
  4790. BuyPrice: item.NewPrice,
  4791. }
  4792. err = service.UpdateAdjustCheckPrice(&info, item.GoodId)
  4793. fmt.Println(err)
  4794. }
  4795. this.ServeSuccessJSON(map[string]interface{}{
  4796. "adjustPrice": adjustPrice,
  4797. })
  4798. }
  4799. func (this *StockManagerApiController) GetAdjustPriceById() {
  4800. ids := this.GetString("ids")
  4801. fmt.Println("ids23232233223233232", ids)
  4802. splitIds := strings.Split(ids, ",")
  4803. list, _ := service.GetAdjustPricebyIdOne(splitIds)
  4804. fmt.Println("list2322322323", list)
  4805. this.ServeSuccessJSON(map[string]interface{}{
  4806. "list": list,
  4807. })
  4808. }
  4809. func (this *StockManagerApiController) SaveReportStock() {
  4810. timeLayout := "2006-01-02"
  4811. loc, _ := time.LoadLocation("Local")
  4812. dataBody := make(map[string]interface{}, 0)
  4813. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4814. if err != nil {
  4815. utils.ErrorLog(err.Error())
  4816. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4817. return
  4818. }
  4819. tableData, _ := dataBody["tableData"].([]interface{})
  4820. if len(tableData) > 0 {
  4821. for _, item := range tableData {
  4822. items := item.(map[string]interface{})
  4823. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4824. utils.ErrorLog("good_name")
  4825. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4826. return
  4827. }
  4828. good_name := items["good_name"].(string)
  4829. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4830. utils.ErrorLog("good_name")
  4831. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4832. return
  4833. }
  4834. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4835. utils.ErrorLog("packing_price")
  4836. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4837. return
  4838. }
  4839. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4840. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4841. utils.ErrorLog("warehousing_order")
  4842. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4843. return
  4844. }
  4845. warehousing_order := items["warehousing_order"].(string)
  4846. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4847. utils.ErrorLog("license_number")
  4848. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4849. return
  4850. }
  4851. license_number := items["license_number"].(string)
  4852. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4853. utils.ErrorLog("dealer")
  4854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4855. return
  4856. }
  4857. dealer := items["dealer"].(string)
  4858. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4859. utils.ErrorLog("manufacturer")
  4860. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4861. return
  4862. }
  4863. manufacturer := items["manufacturer"].(string)
  4864. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4865. utils.ErrorLog("specification_name")
  4866. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4867. return
  4868. }
  4869. specification_name := items["specification_name"].(string)
  4870. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4871. utils.ErrorLog("remark")
  4872. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4873. return
  4874. }
  4875. remark := items["remark"].(string)
  4876. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4877. utils.ErrorLog("warehousing_unit")
  4878. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4879. return
  4880. }
  4881. warehousing_unit := items["warehousing_unit"].(string)
  4882. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4883. utils.ErrorLog("buy_price")
  4884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4885. return
  4886. }
  4887. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4888. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4889. utils.ErrorLog("count")
  4890. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4891. return
  4892. }
  4893. count := int64(items["count"].(float64))
  4894. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4895. utils.ErrorLog("good_id")
  4896. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4897. return
  4898. }
  4899. good_id := int64(items["good_id"].(float64))
  4900. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4901. utils.ErrorLog("start_time")
  4902. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4903. return
  4904. }
  4905. var startTime int64
  4906. start_time := items["start_time"].(string)
  4907. if len(start_time) > 0 {
  4908. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4909. if err != nil {
  4910. fmt.Println(err)
  4911. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4912. return
  4913. }
  4914. startTime = theTime.Unix()
  4915. }
  4916. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  4917. utils.ErrorLog("number")
  4918. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4919. return
  4920. }
  4921. number := items["number"].(string)
  4922. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  4923. utils.ErrorLog("warehousing_info_id")
  4924. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4925. return
  4926. }
  4927. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  4928. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  4929. utils.ErrorLog("expiry_date")
  4930. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4931. return
  4932. }
  4933. expiry_date := int64(items["expiry_date"].(float64))
  4934. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  4935. utils.ErrorLog("product_date")
  4936. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4937. return
  4938. }
  4939. product_date := int64(items["product_date"].(float64))
  4940. orgId := this.GetAdminUserInfo().CurrentOrgId
  4941. Creater := this.GetAdminUserInfo().AdminUser.Id
  4942. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  4943. utils.ErrorLog("total")
  4944. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4945. return
  4946. }
  4947. total := int64(items["total"].(float64))
  4948. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  4949. utils.ErrorLog("good_origin_place")
  4950. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4951. return
  4952. }
  4953. good_origin_place := items["good_origin_place"].(string)
  4954. reportPrice := models.XtStockReportPrice{
  4955. GoodName: good_name,
  4956. SpecificationName: specification_name,
  4957. WarehousingUnit: warehousing_unit,
  4958. Count: count,
  4959. BuyPrice: buy_price,
  4960. PackingPrice: packing_price,
  4961. Manufacturer: manufacturer,
  4962. Dealer: dealer,
  4963. Remark: remark,
  4964. GoodId: good_id,
  4965. UserOrgId: orgId,
  4966. Ctime: time.Now().Unix(),
  4967. Mtime: 0,
  4968. Status: 1,
  4969. WarehousingOrder: warehousing_order,
  4970. LicenseNumber: license_number,
  4971. StartTime: startTime,
  4972. Creater: Creater,
  4973. Checker: 0,
  4974. CheckerStatus: 2,
  4975. CheckerTime: 0,
  4976. Number: number,
  4977. WarehousingInfoId: warehousing_info_id,
  4978. ExpiryDate: expiry_date,
  4979. ProductDate: product_date,
  4980. Total: total,
  4981. GoodOriginPlace: good_origin_place,
  4982. }
  4983. err := service.CreateReportPrice(&reportPrice)
  4984. fmt.Println(err)
  4985. }
  4986. }
  4987. this.ServeSuccessJSON(map[string]interface{}{
  4988. "msg": "保存成功!",
  4989. })
  4990. }
  4991. func (this *StockManagerApiController) GetReportStockList() {
  4992. timeLayout := "2006-01-02"
  4993. loc, _ := time.LoadLocation("Local")
  4994. start_time := this.GetString("start_time")
  4995. end_time := this.GetString("end_time")
  4996. page, _ := this.GetInt64("page")
  4997. limit, _ := this.GetInt64("limit")
  4998. storehouse_id, _ := this.GetInt64("storehouse_id")
  4999. var startTime int64
  5000. if len(start_time) > 0 {
  5001. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5002. if err != nil {
  5003. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5004. return
  5005. }
  5006. startTime = theTime.Unix()
  5007. fmt.Println("开始时间", startTime)
  5008. }
  5009. var endTime int64
  5010. if len(end_time) > 0 {
  5011. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5012. if err != nil {
  5013. utils.ErrorLog(err.Error())
  5014. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5015. return
  5016. }
  5017. endTime = theTime.Unix()
  5018. }
  5019. orgId := this.GetAdminUserInfo().CurrentOrgId
  5020. keyword := this.GetString("keyword")
  5021. list, total, _ := service.GetStockDamagedList(orgId, keyword, page, limit, startTime, endTime, storehouse_id)
  5022. damageList, _ := service.GetStockDamagedCount(orgId)
  5023. doctorlist, _ := service.GetAllDoctorThree(orgId)
  5024. houseList, _ := service.GetAllStoreHouseList(orgId)
  5025. this.ServeSuccessJSON(map[string]interface{}{
  5026. "list": list,
  5027. "total": total,
  5028. "doctorlist": doctorlist,
  5029. "damageList": damageList,
  5030. "houseList": houseList,
  5031. })
  5032. }
  5033. func (this *StockManagerApiController) SaveCheckDamage() {
  5034. timeLayout := "2006-01-02"
  5035. loc, _ := time.LoadLocation("Local")
  5036. idstr := this.GetString("ids")
  5037. ids := strings.Split(idstr, ",")
  5038. check_time := this.GetString("check_time")
  5039. var checkTime int64
  5040. if len(check_time) > 0 {
  5041. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  5042. if err != nil {
  5043. fmt.Println(err)
  5044. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5045. return
  5046. }
  5047. checkTime = theTime.Unix()
  5048. }
  5049. checker, _ := this.GetInt64("checker")
  5050. reportprice := models.XtStockReportPrice{
  5051. Checker: checker,
  5052. CheckerStatus: 1,
  5053. CheckerTime: checkTime,
  5054. }
  5055. err := service.UpdateCheckDamage(ids, reportprice)
  5056. fmt.Println(err)
  5057. //获取当前核对的数据
  5058. list, _ := service.GetCheckDamageList(ids)
  5059. ctime := time.Now().Unix()
  5060. adminUserInfo := this.GetAdminUserInfo()
  5061. timeStr := time.Now().Format("2006-01-02")
  5062. timeArr := strings.Split(timeStr, "-")
  5063. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  5064. total = total + 1
  5065. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5066. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5067. number = number + total
  5068. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5069. operation_time := time.Now().Unix()
  5070. creater := adminUserInfo.AdminUser.Id
  5071. warehouseOut := models.WarehouseOut{
  5072. WarehouseOutOrderNumber: warehousing_out_order,
  5073. OperationTime: operation_time,
  5074. OrgId: adminUserInfo.CurrentOrgId,
  5075. Creater: creater,
  5076. Ctime: ctime,
  5077. Status: 1,
  5078. WarehouseOutTime: ctime,
  5079. Type: 1,
  5080. }
  5081. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  5082. if errcodes == gorm.ErrRecordNotFound {
  5083. service.AddSigleWarehouseOut(&warehouseOut)
  5084. }
  5085. out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
  5086. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  5087. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  5088. var manufacturer_id int64
  5089. var dealer_id int64
  5090. for _, item := range list {
  5091. for _, it := range manufacturerList {
  5092. if item.Manufacturer == it.ManufacturerName {
  5093. manufacturer_id = it.ID
  5094. }
  5095. }
  5096. for _, its := range dealerList {
  5097. if item.Dealer == its.DealerName {
  5098. dealer_id = its.ID
  5099. }
  5100. }
  5101. goodinfo, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5102. //插入出库单
  5103. warehouseOutInfo := &models.WarehouseOutInfo{
  5104. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  5105. WarehouseOutId: out.ID,
  5106. GoodId: item.GoodId,
  5107. Count: item.Count,
  5108. Price: item.PackingPrice,
  5109. Status: 1,
  5110. Ctime: ctime,
  5111. Remark: item.Remark,
  5112. OrgId: adminUserInfo.CurrentOrgId,
  5113. Type: 2,
  5114. Manufacturer: manufacturer_id,
  5115. Number: item.Number,
  5116. ExpiryDate: item.ExpiryDate,
  5117. ProductDate: item.ProductDate,
  5118. Dealer: dealer_id,
  5119. LicenseNumber: item.LicenseNumber,
  5120. GoodTypeId: goodinfo.GoodTypeId,
  5121. }
  5122. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5123. fmt.Println("99999999999999", errOne)
  5124. //更改库存
  5125. info, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  5126. warehousingInfo := models.WarehousingInfo{
  5127. StockCount: info.StockCount - item.Count,
  5128. }
  5129. errOne = service.UpdateGoodWarehouseInfo(item.WarehousingInfoId, warehousingInfo)
  5130. fmt.Println(errOne)
  5131. flow := models.VmStockFlow{
  5132. WarehousingId: 0,
  5133. GoodId: item.GoodId,
  5134. Number: item.Number,
  5135. LicenseNumber: item.LicenseNumber,
  5136. Count: item.Count,
  5137. UserOrgId: adminUserInfo.CurrentOrgId,
  5138. PatientId: 0,
  5139. SystemTime: time.Now().Unix(),
  5140. ConsumableType: 5,
  5141. IsSys: 0,
  5142. WarehousingOrder: "",
  5143. WarehouseOutId: out.ID,
  5144. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  5145. IsEdit: 0,
  5146. CancelStockId: 0,
  5147. CancelOrderNumber: "",
  5148. Manufacturer: 0,
  5149. Dealer: 0,
  5150. Creator: adminUserInfo.AdminUser.Id,
  5151. UpdateCreator: 0,
  5152. Status: 1,
  5153. Ctime: time.Now().Unix(),
  5154. Mtime: 0,
  5155. Price: item.PackingPrice,
  5156. WarehousingDetailId: 0,
  5157. WarehouseOutDetailId: 0,
  5158. CancelOutDetailId: 0,
  5159. ProductDate: item.ProductDate,
  5160. ExpireDate: item.ExpiryDate,
  5161. }
  5162. service.CreateStockFlowOne(flow)
  5163. }
  5164. this.ServeSuccessJSON(map[string]interface{}{
  5165. "reportPrice": reportprice,
  5166. })
  5167. }
  5168. func (this *StockManagerApiController) SaveInventory() {
  5169. timeLayout := "2006-01-02"
  5170. loc, _ := time.LoadLocation("Local")
  5171. dataBody := make(map[string]interface{}, 0)
  5172. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5173. if err != nil {
  5174. utils.ErrorLog(err.Error())
  5175. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5176. return
  5177. }
  5178. tableData, _ := dataBody["tableData"].([]interface{})
  5179. if len(tableData) > 0 {
  5180. for _, item := range tableData {
  5181. items := item.(map[string]interface{})
  5182. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5183. utils.ErrorLog("good_name")
  5184. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5185. return
  5186. }
  5187. good_name := items["good_name"].(string)
  5188. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5189. utils.ErrorLog("good_name")
  5190. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5191. return
  5192. }
  5193. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  5194. utils.ErrorLog("packing_price")
  5195. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5196. return
  5197. }
  5198. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  5199. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  5200. utils.ErrorLog("warehousing_order")
  5201. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5202. return
  5203. }
  5204. warehousing_order := items["warehousing_order"].(string)
  5205. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  5206. utils.ErrorLog("license_number")
  5207. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5208. return
  5209. }
  5210. license_number := items["license_number"].(string)
  5211. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  5212. utils.ErrorLog("dealer")
  5213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5214. return
  5215. }
  5216. dealer := items["dealer"].(string)
  5217. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  5218. utils.ErrorLog("manufacturer")
  5219. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5220. return
  5221. }
  5222. manufacturer := items["manufacturer"].(string)
  5223. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  5224. utils.ErrorLog("specification_name")
  5225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5226. return
  5227. }
  5228. specification_name := items["specification_name"].(string)
  5229. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  5230. utils.ErrorLog("remark")
  5231. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5232. return
  5233. }
  5234. remark := items["remark"].(string)
  5235. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  5236. utils.ErrorLog("warehousing_unit")
  5237. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5238. return
  5239. }
  5240. warehousing_unit := items["warehousing_unit"].(string)
  5241. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  5242. utils.ErrorLog("buy_price")
  5243. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5244. return
  5245. }
  5246. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  5247. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  5248. utils.ErrorLog("count")
  5249. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5250. return
  5251. }
  5252. count := int64(items["count"].(float64))
  5253. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5254. utils.ErrorLog("good_id")
  5255. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5256. return
  5257. }
  5258. good_id := int64(items["good_id"].(float64))
  5259. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  5260. utils.ErrorLog("start_time")
  5261. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5262. return
  5263. }
  5264. var startTime int64
  5265. start_time := items["start_time"].(string)
  5266. if len(start_time) > 0 {
  5267. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5268. if err != nil {
  5269. fmt.Println(err)
  5270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5271. return
  5272. }
  5273. startTime = theTime.Unix()
  5274. }
  5275. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  5276. utils.ErrorLog("total")
  5277. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5278. return
  5279. }
  5280. total := int64(items["total"].(float64))
  5281. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  5282. utils.ErrorLog("expiry_date")
  5283. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5284. return
  5285. }
  5286. expiry_date := int64(items["expiry_date"].(float64))
  5287. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  5288. utils.ErrorLog("product_date")
  5289. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5290. return
  5291. }
  5292. product_date := int64(items["product_date"].(float64))
  5293. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5294. utils.ErrorLog("number")
  5295. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5296. return
  5297. }
  5298. number := items["number"].(string)
  5299. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  5300. utils.ErrorLog("warehousing_info_id")
  5301. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5302. return
  5303. }
  5304. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  5305. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  5306. utils.ErrorLog("good_origin_place")
  5307. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5308. return
  5309. }
  5310. good_origin_place := items["good_origin_place"].(string)
  5311. orgId := this.GetAdminUserInfo().CurrentOrgId
  5312. Creater := this.GetAdminUserInfo().AdminUser.Id
  5313. inventory := models.XtStockInventory{
  5314. GoodName: good_name,
  5315. SpecificationName: specification_name,
  5316. WarehousingUnit: warehousing_unit,
  5317. Count: count,
  5318. BuyPrice: buy_price,
  5319. PackingPrice: packing_price,
  5320. NewPrice: 0,
  5321. Manufacturer: manufacturer,
  5322. Dealer: dealer,
  5323. Remark: remark,
  5324. GoodId: good_id,
  5325. UserOrgId: orgId,
  5326. Ctime: time.Now().Unix(),
  5327. Mtime: 0,
  5328. Status: 1,
  5329. WarehousingOrder: warehousing_order,
  5330. LicenseNumber: license_number,
  5331. StartTime: startTime,
  5332. Creater: Creater,
  5333. Checker: 0,
  5334. CheckerStatus: 2,
  5335. CheckerTime: 0,
  5336. Total: total,
  5337. ExpireDate: expiry_date,
  5338. ProductDate: product_date,
  5339. Number: number,
  5340. WarehousingInfoId: warehousing_info_id,
  5341. GoodOriginPlace: good_origin_place,
  5342. }
  5343. err = service.CreateInentory(inventory)
  5344. fmt.Println(err)
  5345. }
  5346. }
  5347. this.ServeSuccessJSON(map[string]interface{}{
  5348. "msg": "保存成功!",
  5349. })
  5350. }
  5351. func (this *StockManagerApiController) GetInventorylist() {
  5352. timeLayout := "2006-01-02"
  5353. loc, _ := time.LoadLocation("Local")
  5354. start_time := this.GetString("start_time")
  5355. end_time := this.GetString("end_time")
  5356. page, _ := this.GetInt64("page")
  5357. limit, _ := this.GetInt64("limit")
  5358. keyword := this.GetString("keyword")
  5359. inventory_status, _ := this.GetInt64("inventory_status")
  5360. var startTime int64
  5361. if len(start_time) > 0 {
  5362. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5363. if err != nil {
  5364. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5365. return
  5366. }
  5367. startTime = theTime.Unix()
  5368. fmt.Println("开始时间", startTime)
  5369. }
  5370. var endTime int64
  5371. if len(end_time) > 0 {
  5372. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5373. if err != nil {
  5374. utils.ErrorLog(err.Error())
  5375. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5376. return
  5377. }
  5378. endTime = theTime.Unix()
  5379. }
  5380. orgId := this.GetAdminUserInfo().CurrentOrgId
  5381. list, total, _ := service.GetInventorylist(startTime, endTime, page, limit, inventory_status, keyword, orgId)
  5382. doctorlist, _ := service.GetAllDoctorThree(orgId)
  5383. houseList, _ := service.GetAllStoreHouseList(orgId)
  5384. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5385. this.ServeSuccessJSON(map[string]interface{}{
  5386. "list": list,
  5387. "total": total,
  5388. "doctorlist": doctorlist,
  5389. "houseList": houseList,
  5390. "houseConfig": houseConfig,
  5391. })
  5392. }
  5393. func (this *StockManagerApiController) SaveCheckInventory() {
  5394. timeLayout := "2006-01-02"
  5395. loc, _ := time.LoadLocation("Local")
  5396. dataBody := make(map[string]interface{}, 0)
  5397. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5398. fmt.Println(err)
  5399. idstr := this.GetString("ids")
  5400. ids := strings.Split(idstr, ",")
  5401. check_time := this.GetString("check_time")
  5402. var checkTime int64
  5403. if len(check_time) > 0 {
  5404. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  5405. if err != nil {
  5406. fmt.Println(err)
  5407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5408. return
  5409. }
  5410. checkTime = theTime.Unix()
  5411. }
  5412. checker, _ := this.GetInt64("checker")
  5413. inventory := models.XtStockInventory{
  5414. Checker: checker,
  5415. CheckerStatus: 1,
  5416. CheckerTime: checkTime,
  5417. }
  5418. adminUserInfo := this.GetAdminUserInfo()
  5419. err = service.UpdateCheckInventory(ids, inventory)
  5420. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  5421. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  5422. var manufactuer_id int64
  5423. var dealer_id int64
  5424. //查询耗材信息
  5425. list, _ := service.GetInventoryDetailById(ids)
  5426. for _, item := range list {
  5427. for _, it := range manufacturerList {
  5428. if item.Manufacturer == it.ManufacturerName {
  5429. manufactuer_id = it.ID
  5430. }
  5431. }
  5432. for _, its := range dealerList {
  5433. if item.Dealer == its.DealerName {
  5434. dealer_id = its.ID
  5435. }
  5436. }
  5437. //查寻该批次的库存量
  5438. list, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  5439. //查询该耗材最后1条批次
  5440. info, _ := service.GetLastWarehouseInfo(item.GoodId)
  5441. good, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5442. fmt.Println("总共", item.Count)
  5443. fmt.Println("数据", list.StockCount)
  5444. //盘点盘点库存和et实际库存的大小
  5445. // 如果盘点库存大于实际库存,怎需要入库
  5446. if item.Count > list.StockCount {
  5447. ctime := time.Now().Unix()
  5448. timeStr := time.Now().Format("2006-01-02")
  5449. timeArr := strings.Split(timeStr, "-")
  5450. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  5451. total = total + 1
  5452. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5453. operation_time := time.Now().Unix()
  5454. creater := adminUserInfo.AdminUser.Id
  5455. warehousing := models.Warehousing{
  5456. WarehousingOrder: warehousing_order,
  5457. OperationTime: operation_time,
  5458. OrgId: adminUserInfo.CurrentOrgId,
  5459. Creater: creater,
  5460. Ctime: ctime,
  5461. Status: 1,
  5462. WarehousingTime: ctime,
  5463. Type: 1,
  5464. }
  5465. service.AddSigleWarehouse(&warehousing)
  5466. //获取最
  5467. //入库单表格
  5468. warehouseInfo := models.WarehousingInfo{
  5469. WarehousingOrder: warehousing.WarehousingOrder,
  5470. WarehousingId: warehousing.ID,
  5471. GoodId: item.GoodId,
  5472. Number: info.Number,
  5473. ProductDate: info.ProductDate,
  5474. ExpiryDate: info.ExpiryDate,
  5475. WarehousingCount: item.Count - list.StockCount,
  5476. Price: info.Price,
  5477. Status: 1,
  5478. Ctime: ctime,
  5479. Remark: item.Remark,
  5480. OrgId: adminUserInfo.CurrentOrgId,
  5481. Type: 1,
  5482. Manufacturer: manufactuer_id,
  5483. StockCount: item.Count - list.StockCount,
  5484. Dealer: dealer_id,
  5485. LicenseNumber: info.LicenseNumber,
  5486. WarehouseInfoId: item.WarehousingInfoId,
  5487. GoodTypeId: good.GoodTypeId,
  5488. }
  5489. flow := models.VmStockFlow{
  5490. WarehousingOrder: warehousing.WarehousingOrder,
  5491. WarehousingId: warehousing.ID,
  5492. GoodId: item.GoodId,
  5493. Number: info.Number,
  5494. ProductDate: info.ProductDate,
  5495. ExpireDate: info.ExpiryDate,
  5496. Count: item.Count - list.StockCount,
  5497. Price: item.BuyPrice,
  5498. Status: 1,
  5499. Ctime: ctime,
  5500. UserOrgId: adminUserInfo.CurrentOrgId,
  5501. Manufacturer: info.Manufacturer,
  5502. Dealer: info.Dealer,
  5503. LicenseNumber: info.LicenseNumber,
  5504. IsEdit: 1,
  5505. Creator: adminUserInfo.AdminUser.Id,
  5506. SystemTime: operation_time,
  5507. ConsumableType: 1,
  5508. WarehousingDetailId: warehouseInfo.ID,
  5509. }
  5510. service.CreateWarehouseInfo(warehouseInfo)
  5511. service.CreateStockFlowOne(flow)
  5512. }
  5513. //如果盘点库存小于实际库存,需要出库
  5514. if item.Count < list.StockCount {
  5515. timeStr := time.Now().Format("2006-01-02")
  5516. timeArr := strings.Split(timeStr, "-")
  5517. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  5518. total = total + 1
  5519. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5520. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5521. number = number + total
  5522. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5523. operation_time := time.Now().Unix()
  5524. creater := adminUserInfo.AdminUser.Id
  5525. //查询最早的1条批次
  5526. warehouseInfo, _ := service.GetFirstWarehouseInfo(item.GoodId)
  5527. warehouseOut := models.WarehouseOut{
  5528. WarehouseOutOrderNumber: warehousing_out_order,
  5529. OperationTime: operation_time,
  5530. OrgId: adminUserInfo.CurrentOrgId,
  5531. Creater: creater,
  5532. Ctime: time.Now().Unix(),
  5533. Status: 1,
  5534. WarehouseOutTime: time.Now().Unix(),
  5535. Type: 1,
  5536. }
  5537. err = service.CreateWarehouseOut(warehouseOut)
  5538. fmt.Println(err)
  5539. out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
  5540. warehouseOutInfo := &models.WarehouseOutInfo{
  5541. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  5542. WarehouseOutId: out.ID,
  5543. GoodId: warehouseInfo.GoodId,
  5544. Count: list.StockCount - item.Count,
  5545. Price: warehouseInfo.Price,
  5546. Status: 1,
  5547. Ctime: time.Now().Unix(),
  5548. Remark: item.Remark,
  5549. OrgId: adminUserInfo.CurrentOrgId,
  5550. Type: 1,
  5551. Manufacturer: manufactuer_id,
  5552. Number: warehouseInfo.Number,
  5553. ExpiryDate: warehouseInfo.ExpiryDate,
  5554. ProductDate: warehouseInfo.ProductDate,
  5555. Dealer: dealer_id,
  5556. LicenseNumber: warehouseInfo.LicenseNumber,
  5557. GoodTypeId: good.GoodTypeId,
  5558. SysRecordTime: time.Now().Unix(),
  5559. }
  5560. stockFlow := models.VmStockFlow{
  5561. WarehousingId: item.WarehousingInfoId,
  5562. GoodId: warehouseInfo.GoodId,
  5563. Number: warehouseInfo.Number,
  5564. LicenseNumber: warehouseInfo.LicenseNumber,
  5565. Count: list.StockCount - item.Count,
  5566. UserOrgId: warehouseInfo.OrgId,
  5567. PatientId: 0,
  5568. SystemTime: time.Now().Unix(),
  5569. ConsumableType: 2,
  5570. IsSys: 2,
  5571. WarehousingOrder: "",
  5572. WarehouseOutId: out.ID,
  5573. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5574. IsEdit: 1,
  5575. CancelStockId: 0,
  5576. CancelOrderNumber: "",
  5577. Manufacturer: manufactuer_id,
  5578. Dealer: dealer_id,
  5579. Creator: adminUserInfo.AdminUser.Id,
  5580. UpdateCreator: 0,
  5581. Status: 1,
  5582. Ctime: time.Now().Unix(),
  5583. Mtime: 0,
  5584. Price: warehouseInfo.Price,
  5585. WarehousingDetailId: 0,
  5586. WarehouseOutDetailId: out.ID,
  5587. CancelOutDetailId: 0,
  5588. ProductDate: warehouseInfo.ProductDate,
  5589. ExpireDate: warehouseInfo.ExpiryDate,
  5590. }
  5591. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5592. fmt.Println(errOne)
  5593. //创建出库明细
  5594. service.CreateStockFlowOne(stockFlow)
  5595. //更改库存
  5596. warehousingInfos := models.WarehousingInfo{
  5597. StockCount: item.Count,
  5598. }
  5599. service.UpdateStockOut(item.WarehousingInfoId, warehousingInfos)
  5600. }
  5601. }
  5602. fmt.Println(err)
  5603. this.ServeSuccessJSON(map[string]interface{}{
  5604. "inventory": inventory,
  5605. })
  5606. }
  5607. func (this *StockManagerApiController) GetModifyPriceDetail() {
  5608. id, _ := this.GetInt64("id")
  5609. detail, _ := service.GetModifyPriceDetail(id)
  5610. this.ServeSuccessJSON(map[string]interface{}{
  5611. "detail": detail,
  5612. })
  5613. }
  5614. func (this *StockManagerApiController) UpdateStockPrice() {
  5615. id, _ := this.GetInt64("id")
  5616. newPrice := this.GetString("new_price")
  5617. new_price, _ := strconv.ParseFloat(newPrice, 64)
  5618. good_name := this.GetString("good_name")
  5619. packingPrice := this.GetString("packing_price")
  5620. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5621. remark := this.GetString("remark")
  5622. good_id, _ := this.GetInt64("good_id")
  5623. manufacturer := this.GetString("manufacturer")
  5624. dealer := this.GetString("dealer")
  5625. adjust := models.XtStockAdjustPrice{
  5626. NewPrice: new_price,
  5627. GoodName: good_name,
  5628. PackingPrice: packing_price,
  5629. Remark: remark,
  5630. GoodId: good_id,
  5631. Manufacturer: manufacturer,
  5632. Dealer: dealer,
  5633. }
  5634. err := service.UpdateStockPrice(adjust, id)
  5635. fmt.Println(err)
  5636. this.ServeSuccessJSON(map[string]interface{}{
  5637. "adjust": adjust,
  5638. })
  5639. }
  5640. func (this *StockManagerApiController) DeleteStockPrice() {
  5641. id, _ := this.GetInt64("id")
  5642. err := service.DeleteStockPrice(id)
  5643. fmt.Println(err)
  5644. returnData := make(map[string]interface{}, 0)
  5645. returnData["msg"] = "ok"
  5646. this.ServeSuccessJSON(returnData)
  5647. return
  5648. }
  5649. func (this *StockManagerApiController) GetStockDamageDetail() {
  5650. id, _ := this.GetInt64("id")
  5651. detail, err := service.GetStockDamageDetail(id)
  5652. fmt.Println(err)
  5653. this.ServeSuccessJSON(map[string]interface{}{
  5654. "detail": detail,
  5655. })
  5656. }
  5657. func (this *StockManagerApiController) ModifyPrice() {
  5658. count, _ := this.GetInt64("count")
  5659. id, _ := this.GetInt64("id")
  5660. good_name := this.GetString("good_name")
  5661. specification_name := this.GetString("specification_name")
  5662. number := this.GetString("number")
  5663. warehousing_unit := this.GetString("warehousing_unit")
  5664. buyPrice := this.GetString("buy_price")
  5665. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5666. packingPrice := this.GetString("packing_price")
  5667. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5668. good_origin_place := this.GetString("good_origin_place")
  5669. manufacturer := this.GetString("manufacturer")
  5670. dealer := this.GetString("dealer")
  5671. total, _ := this.GetInt64("total")
  5672. remark := this.GetString("remark")
  5673. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5674. good_id, _ := this.GetInt64("good_id")
  5675. adjust := models.XtStockReportPrice{
  5676. Count: count,
  5677. SpecificationName: specification_name,
  5678. Number: number,
  5679. GoodName: good_name,
  5680. WarehousingUnit: warehousing_unit,
  5681. BuyPrice: buy_price,
  5682. PackingPrice: packing_price,
  5683. GoodOriginPlace: good_origin_place,
  5684. Manufacturer: manufacturer,
  5685. Dealer: dealer,
  5686. Total: total,
  5687. Remark: remark,
  5688. WarehousingInfoId: warehousing_info_id,
  5689. GoodId: good_id,
  5690. }
  5691. err := service.ModifyPrice(id, adjust)
  5692. fmt.Println(err)
  5693. this.ServeSuccessJSON(map[string]interface{}{
  5694. "adjust": adjust,
  5695. })
  5696. }
  5697. func (this *StockManagerApiController) DeleteDamage() {
  5698. id, _ := this.GetInt64("id")
  5699. err := service.DeleteDamage(id)
  5700. fmt.Println(err)
  5701. returnData := make(map[string]interface{}, 0)
  5702. returnData["msg"] = "ok"
  5703. this.ServeSuccessJSON(returnData)
  5704. return
  5705. }
  5706. func (this *StockManagerApiController) GetStockDamageById() {
  5707. ids := this.GetString("ids")
  5708. splitIds := strings.Split(ids, ",")
  5709. list, _ := service.GetStockDamageById(splitIds)
  5710. this.ServeSuccessJSON(map[string]interface{}{
  5711. "list": list,
  5712. })
  5713. }
  5714. func (this *StockManagerApiController) GetInventoryDetail() {
  5715. id, _ := this.GetInt64("id")
  5716. detail, _ := service.GetInventoryDetail(id)
  5717. this.ServeSuccessJSON(map[string]interface{}{
  5718. "detail": detail,
  5719. })
  5720. }
  5721. func (this *StockManagerApiController) ModifyInventory() {
  5722. id, _ := this.GetInt64("id")
  5723. good_id, _ := this.GetInt64("good_id")
  5724. good_name := this.GetString("good_name")
  5725. specification_name := this.GetString("specification_name")
  5726. number := this.GetString("number")
  5727. warehousing_unit := this.GetString("warehousing_unit")
  5728. buyPrice := this.GetString("buy_price")
  5729. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5730. packingPrice := this.GetString("packing_price")
  5731. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5732. total, _ := this.GetInt64("total")
  5733. good_origin_place := this.GetString("good_origin_place")
  5734. license_number := this.GetString("license_number")
  5735. dealer := this.GetString("dealer")
  5736. manufacturer := this.GetString("manufacturer")
  5737. count, _ := this.GetInt64("count")
  5738. remark := this.GetString("remark")
  5739. inventory := models.XtStockInventory{
  5740. GoodId: good_id,
  5741. GoodName: good_name,
  5742. SpecificationName: specification_name,
  5743. Number: number,
  5744. WarehousingUnit: warehousing_unit,
  5745. BuyPrice: buy_price,
  5746. PackingPrice: packing_price,
  5747. Total: total,
  5748. GoodOriginPlace: good_origin_place,
  5749. LicenseNumber: license_number,
  5750. Dealer: dealer,
  5751. Manufacturer: manufacturer,
  5752. Count: count,
  5753. Remark: remark,
  5754. }
  5755. err := service.ModifyInventory(id, inventory)
  5756. fmt.Println(err)
  5757. this.ServeSuccessJSON(map[string]interface{}{
  5758. "inventory": inventory,
  5759. })
  5760. }
  5761. func (this *StockManagerApiController) DeleteInventory() {
  5762. id, _ := this.GetInt64("id")
  5763. err := service.DeleteInventory(id)
  5764. fmt.Println(err)
  5765. returnData := make(map[string]interface{}, 0)
  5766. returnData["msg"] = "ok"
  5767. this.ServeSuccessJSON(returnData)
  5768. return
  5769. }
  5770. func (this *StockManagerApiController) GetInventoryDetailList() {
  5771. keyword := this.GetString("keyword")
  5772. limit, _ := this.GetInt64("limit")
  5773. page, _ := this.GetInt64("page")
  5774. orgId := this.GetAdminUserInfo().CurrentOrgId
  5775. appId := this.GetAdminUserInfo().CurrentAppId
  5776. storehouse_id, _ := this.GetInt64("storehouse_id")
  5777. houseList, _ := service.GetAllStoreHouseList(orgId)
  5778. list, total, _ := service.GetInventoryDetailList(keyword, limit, page, orgId, storehouse_id)
  5779. doclist, _ := service.GetAllDoctorListSix(orgId, appId)
  5780. this.ServeSuccessJSON(map[string]interface{}{
  5781. "list": list,
  5782. "total": total,
  5783. "houseList": houseList,
  5784. "doclist": doclist,
  5785. })
  5786. }
  5787. func (this *StockManagerApiController) GetInventoryPrintList() {
  5788. ids := this.GetString("ids")
  5789. splitIds := strings.Split(ids, ",")
  5790. list, _ := service.GetInventoryPrintList(splitIds)
  5791. this.ServeSuccessJSON(map[string]interface{}{
  5792. "list": list,
  5793. })
  5794. }
  5795. func (this *StockManagerApiController) GetInventoryDetailPrintList() {
  5796. ids := this.GetString("ids")
  5797. splitIds := strings.Split(ids, ",")
  5798. list, _ := service.GetInventoryDetailPrintList(splitIds)
  5799. this.ServeSuccessJSON(map[string]interface{}{
  5800. "list": list,
  5801. })
  5802. }
  5803. func (this *StockManagerApiController) DeleteDrugPrice() {
  5804. id, _ := this.GetInt64("id")
  5805. err := service.DeleteDrugPrice(id)
  5806. fmt.Println(err)
  5807. returnData := make(map[string]interface{}, 0)
  5808. returnData["msg"] = "ok"
  5809. this.ServeSuccessJSON(returnData)
  5810. return
  5811. }
  5812. func (this *StockManagerApiController) GetGoodWarehouseList() {
  5813. id, _ := this.GetInt64("id")
  5814. list, _ := service.GetGoodWarehouseList(id)
  5815. this.ServeSuccessJSON(map[string]interface{}{
  5816. "list": list,
  5817. })
  5818. }
  5819. func (this *StockManagerApiController) ProofInventory() {
  5820. id, _ := this.GetInt64("id")
  5821. good_id, _ := this.GetInt64("good_id")
  5822. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5823. proof_count, _ := this.GetInt64("proof_count")
  5824. total, _ := this.GetInt64("total")
  5825. orgId := this.GetAdminUserInfo().CurrentOrgId
  5826. creater := this.GetAdminUserInfo().AdminUser.Id
  5827. info := models.WarehousingInfo{
  5828. GoodId: good_id,
  5829. StockCount: proof_count,
  5830. }
  5831. err := service.UpdateProofInventory(warehousing_info_id, info)
  5832. inventory := models.XtStockInventory{
  5833. Total: proof_count,
  5834. }
  5835. err = service.UpdateStockInventory(inventory, id)
  5836. fmt.Println(err)
  5837. record := models.XtStockCorrectRecord{
  5838. GoodId: good_id,
  5839. OrdCount: total,
  5840. WarehousingInfoId: warehousing_info_id,
  5841. NewCount: proof_count,
  5842. UserOrgId: orgId,
  5843. Status: 1,
  5844. Creater: creater,
  5845. Ctime: time.Now().Unix(),
  5846. Mtime: 0,
  5847. }
  5848. service.CeateStockCorrectRecord(record)
  5849. this.ServeSuccessJSON(map[string]interface{}{
  5850. "list": info,
  5851. })
  5852. }
  5853. func (this *StockManagerApiController) GetWarehouseTotal() {
  5854. id, _ := this.GetInt64("id")
  5855. list, _ := service.GetWarehouseTotal(id)
  5856. this.ServeSuccessJSON(map[string]interface{}{
  5857. "list": list,
  5858. })
  5859. }
  5860. func (this *StockManagerApiController) GetGoodInventoryWarehouseList() {
  5861. id, _ := this.GetInt64("id")
  5862. storehouse_id, _ := this.GetInt64("storehouse_id")
  5863. list, _ := service.GetGoodInventoryWarehouseList(id, storehouse_id)
  5864. orgId := this.GetAdminUserInfo().CurrentOrgId
  5865. fmt.Println(orgId)
  5866. this.ServeSuccessJSON(map[string]interface{}{
  5867. "list": list,
  5868. })
  5869. }
  5870. func (this *StockManagerApiController) SaveStockInventoryList() {
  5871. dataBody := make(map[string]interface{}, 0)
  5872. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5873. fmt.Println(err)
  5874. tableData, _ := dataBody["tableData"].([]interface{})
  5875. if len(tableData) > 0 {
  5876. for _, item := range tableData {
  5877. items := item.(map[string]interface{})
  5878. good_name := items["good_name"].(string)
  5879. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5880. utils.ErrorLog("good_name")
  5881. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5882. return
  5883. }
  5884. specification_name := items["specification_name"].(string)
  5885. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  5886. utils.ErrorLog("specification_name")
  5887. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5888. return
  5889. }
  5890. warehousing_unit := items["warehousing_unit"].(string)
  5891. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  5892. utils.ErrorLog("warehousing_unit")
  5893. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5894. return
  5895. }
  5896. stock_count := int64(items["stock_count"].(float64))
  5897. if items["stock_count"] == nil || reflect.TypeOf(items["stock_count"]).String() != "float64" {
  5898. utils.ErrorLog("stock_count")
  5899. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5900. return
  5901. }
  5902. price := items["price"].(float64)
  5903. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "float64" {
  5904. utils.ErrorLog("price")
  5905. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5906. return
  5907. }
  5908. manufacturer_name := items["manufacturer_name"].(string)
  5909. if items["manufacturer_name"] == nil || reflect.TypeOf(items["manufacturer_name"]).String() != "string" {
  5910. utils.ErrorLog("manufacturer_name")
  5911. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5912. return
  5913. }
  5914. good_id := int64(items["good_id"].(float64))
  5915. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5916. utils.ErrorLog("good_id")
  5917. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5918. return
  5919. }
  5920. manufacturer := int64(items["manufacturer"].(float64))
  5921. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "float64" {
  5922. utils.ErrorLog("manufacturer")
  5923. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5924. return
  5925. }
  5926. warehousing_order := items["warehousing_order"].(string)
  5927. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  5928. utils.ErrorLog("warehousing_order")
  5929. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5930. return
  5931. }
  5932. number := items["number"].(string)
  5933. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5934. utils.ErrorLog("number")
  5935. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5936. return
  5937. }
  5938. id := int64(items["id"].(float64))
  5939. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5940. utils.ErrorLog("id")
  5941. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5942. return
  5943. }
  5944. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  5945. utils.ErrorLog("expiry_date")
  5946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5947. return
  5948. }
  5949. expiry_date := int64(items["expiry_date"].(float64))
  5950. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  5951. utils.ErrorLog("product_date")
  5952. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5953. return
  5954. }
  5955. product_date := int64(items["product_date"].(float64))
  5956. orgId := this.GetAdminUserInfo().CurrentOrgId
  5957. adminId := this.GetAdminUserInfo().AdminUser.Id
  5958. stock_type := int64(items["type"].(float64))
  5959. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5960. utils.ErrorLog("type")
  5961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5962. return
  5963. }
  5964. last_stock_count := int64(items["last_stock_count"].(float64))
  5965. if items["last_stock_count"] == nil || reflect.TypeOf(items["last_stock_count"]).String() != "float64" {
  5966. utils.ErrorLog("last_stock_count")
  5967. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5968. return
  5969. }
  5970. storehouse_id := int64(items["storehouse_id"].(float64))
  5971. if items["storehouse_id"] == nil || reflect.TypeOf(items["storehouse_id"]).String() != "float64" {
  5972. utils.ErrorLog("storehouse_id")
  5973. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5974. return
  5975. }
  5976. var total_count int64
  5977. var inventory_type int64
  5978. if stock_count > last_stock_count {
  5979. total_count = stock_count - last_stock_count
  5980. inventory_type = 11
  5981. }
  5982. if stock_count < last_stock_count {
  5983. total_count = last_stock_count - stock_count
  5984. inventory_type = 10
  5985. }
  5986. creater := this.GetAdminUserInfo().AdminUser.Id
  5987. inventory := models.XtStockInventory{
  5988. GoodName: good_name,
  5989. SpecificationName: specification_name,
  5990. WarehousingUnit: warehousing_unit,
  5991. Count: total_count,
  5992. BuyPrice: price,
  5993. PackingPrice: price,
  5994. NewPrice: 0,
  5995. Manufacturer: manufacturer_name,
  5996. Dealer: "",
  5997. Remark: "",
  5998. GoodId: good_id,
  5999. UserOrgId: orgId,
  6000. Ctime: time.Now().Unix(),
  6001. Mtime: 0,
  6002. Status: 1,
  6003. WarehousingOrder: warehousing_order,
  6004. LicenseNumber: number,
  6005. StartTime: time.Now().Unix(),
  6006. Creater: adminId,
  6007. Checker: 0,
  6008. CheckerStatus: 0,
  6009. CheckerTime: 0,
  6010. Total: 0,
  6011. Number: number,
  6012. WarehousingInfoId: id,
  6013. ExpireDate: expiry_date,
  6014. ProductDate: product_date,
  6015. GoodOriginPlace: "",
  6016. Type: 10,
  6017. InventoryType: stock_type,
  6018. LastStockCount: last_stock_count,
  6019. StockCount: stock_count,
  6020. StorehouseId: storehouse_id,
  6021. }
  6022. service.CreateInentory(inventory)
  6023. stockFlow := models.VmStockFlow{
  6024. WarehousingId: 0,
  6025. GoodId: good_id,
  6026. Number: number,
  6027. LicenseNumber: "",
  6028. Count: total_count,
  6029. UserOrgId: orgId,
  6030. PatientId: 0,
  6031. SystemTime: 0,
  6032. ConsumableType: inventory_type,
  6033. IsSys: 0,
  6034. WarehousingOrder: "",
  6035. WarehouseOutId: 0,
  6036. WarehouseOutOrderNumber: warehousing_order,
  6037. IsEdit: 0,
  6038. CancelStockId: 0,
  6039. CancelOrderNumber: "",
  6040. Manufacturer: manufacturer,
  6041. Dealer: 0,
  6042. Creator: creater,
  6043. UpdateCreator: 0,
  6044. Status: 1,
  6045. Ctime: time.Now().Unix(),
  6046. Mtime: 0,
  6047. Price: price,
  6048. WarehousingDetailId: 0,
  6049. WarehouseOutDetailId: 0,
  6050. CancelOutDetailId: 0,
  6051. ProductDate: product_date,
  6052. ExpireDate: expiry_date,
  6053. ReturnCount: 0,
  6054. StorehouseId: storehouse_id,
  6055. }
  6056. info := models.WarehousingInfo{
  6057. StockCount: last_stock_count,
  6058. WarehousingCount: last_stock_count,
  6059. }
  6060. warehosueinfos, _ := service.GetWarehouseInfoByIdNight(id)
  6061. //如果当前的盘点后的数量大于当前库存数量,则新增库存
  6062. if last_stock_count > warehosueinfos.StockCount && last_stock_count <= warehosueinfos.WarehousingCount {
  6063. //更改库存
  6064. service.UpdatedWarehousingInfo(info, id)
  6065. }
  6066. if last_stock_count > warehosueinfos.StockCount && last_stock_count > warehosueinfos.WarehousingCount {
  6067. //更改库存
  6068. service.UpdatedWarehousingInfoSix(info, id)
  6069. }
  6070. //如果当前的盘点后的数量大于当前库存数量,则扣减库存
  6071. if last_stock_count < warehosueinfos.StockCount {
  6072. //更改库存
  6073. service.UpdatedWarehousingInfo(info, id)
  6074. }
  6075. //查询该机构默认仓库
  6076. storeConfig, _ := service.GetAllStoreHouseConfig(warehosueinfos.OrgId)
  6077. goodListOne, _ := service.GetSumGoodList(orgId, storeConfig.StorehouseOutInfo, good_id)
  6078. var flush_count int64
  6079. for _, it := range goodListOne {
  6080. flush_count += it.StockCount
  6081. }
  6082. if stock_count != last_stock_count {
  6083. stockFlow.OverCount = flush_count
  6084. service.CreateStockFlowOne(stockFlow)
  6085. }
  6086. //查询已审核单据的剩余库存
  6087. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, good_id, warehosueinfos.OrgId)
  6088. var sum_count int64
  6089. var sum_in_count int64
  6090. for _, item := range goodList {
  6091. sum_count += item.StockCount
  6092. sum_in_count += item.WarehousingCount
  6093. }
  6094. service.UpdateGoodByGoodId(good_id, sum_count, sum_in_count, warehosueinfos.OrgId)
  6095. service.UpdateSumGood(orgId, storeConfig.StorehouseOutInfo, good_id, flush_count)
  6096. this.ServeSuccessJSON(map[string]interface{}{
  6097. "inventory": inventory,
  6098. })
  6099. }
  6100. }
  6101. newTableData, _ := dataBody["newTableData"].([]interface{})
  6102. if len(newTableData) > 0 {
  6103. for _, item := range newTableData {
  6104. items := item.(map[string]interface{})
  6105. good_name := items["good_name"].(string)
  6106. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  6107. utils.ErrorLog("good_name")
  6108. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6109. return
  6110. }
  6111. specification_name := items["specification_name"].(string)
  6112. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  6113. utils.ErrorLog("specification_name")
  6114. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6115. return
  6116. }
  6117. warehousing_unit := items["warehousing_unit"].(string)
  6118. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  6119. utils.ErrorLog("warehousing_unit")
  6120. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6121. return
  6122. }
  6123. warehousing_count := int64(items["warehousing_count"].(float64))
  6124. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "float64" {
  6125. utils.ErrorLog("warehousing_count")
  6126. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6127. return
  6128. }
  6129. stock_count := int64(items["stock_count"].(float64))
  6130. if items["stock_count"] == nil || reflect.TypeOf(items["stock_count"]).String() != "float64" {
  6131. utils.ErrorLog("stock_count")
  6132. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6133. return
  6134. }
  6135. price := items["price"].(float64)
  6136. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "float64" {
  6137. utils.ErrorLog("price")
  6138. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6139. return
  6140. }
  6141. manufacturer_name := items["manufacturer_name"].(string)
  6142. if items["manufacturer_name"] == nil || reflect.TypeOf(items["manufacturer_name"]).String() != "string" {
  6143. utils.ErrorLog("manufacturer_name")
  6144. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6145. return
  6146. }
  6147. good_id := int64(items["good_id"].(float64))
  6148. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6149. utils.ErrorLog("good_id")
  6150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6151. return
  6152. }
  6153. warehousing_order := items["warehousing_order"].(string)
  6154. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  6155. utils.ErrorLog("warehousing_order")
  6156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6157. return
  6158. }
  6159. number := items["number"].(string)
  6160. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  6161. utils.ErrorLog("number")
  6162. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6163. return
  6164. }
  6165. id := int64(items["id"].(float64))
  6166. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  6167. utils.ErrorLog("id")
  6168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6169. return
  6170. }
  6171. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  6172. utils.ErrorLog("expiry_date")
  6173. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6174. return
  6175. }
  6176. expiry_date := int64(items["expiry_date"].(float64))
  6177. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  6178. utils.ErrorLog("product_date")
  6179. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6180. return
  6181. }
  6182. product_date := int64(items["product_date"].(float64))
  6183. stock_type := int64(items["type"].(float64))
  6184. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6185. utils.ErrorLog("type")
  6186. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6187. return
  6188. }
  6189. last_stock_count := int64(items["last_stock_count"].(float64))
  6190. if items["last_stock_count"] == nil || reflect.TypeOf(items["last_stock_count"]).String() != "float64" {
  6191. utils.ErrorLog("last_stock_count")
  6192. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6193. return
  6194. }
  6195. storehouse_id := int64(items["storehouse_id"].(float64))
  6196. if items["storehouse_id"] == nil || reflect.TypeOf(items["storehouse_id"]).String() != "float64" {
  6197. utils.ErrorLog("storehouse_id")
  6198. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6199. return
  6200. }
  6201. creater := this.GetAdminUserInfo().AdminUser.Id
  6202. recordDateStr := time.Now().Format("2006-01-02")
  6203. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6204. user_org_id := this.GetAdminUserInfo().CurrentOrgId
  6205. goodStockInventory := models.XtGoodStockInventoryList{
  6206. GoodId: good_id,
  6207. WarehousingOrder: warehousing_order,
  6208. InCount: warehousing_count,
  6209. BatchNumber: number,
  6210. Price: price,
  6211. BeforCount: stock_count,
  6212. AfterCount: last_stock_count,
  6213. Reason: stock_type,
  6214. Creater: creater,
  6215. RecordDate: recordDate.Unix(),
  6216. UserOrgId: user_org_id,
  6217. Ctime: time.Now().Unix(),
  6218. Mtime: time.Now().Unix(),
  6219. WarehouseInfoId: id,
  6220. SpecificationName: specification_name,
  6221. ManufacturerName: manufacturer_name,
  6222. GoodName: good_name,
  6223. ExpiryDate: expiry_date,
  6224. ProductDate: product_date,
  6225. StorehouseId: storehouse_id,
  6226. MaxUnit: warehousing_unit,
  6227. Status: 1,
  6228. }
  6229. //查询今日该耗材是否有记录
  6230. goodStock, _ := service.GetGoodStockInventoryByRecordate(good_id, recordDate.Unix(), user_org_id)
  6231. if goodStock.ID == 0 {
  6232. service.CreateGoodStockInventoryList(goodStockInventory)
  6233. }
  6234. if goodStock.ID > 0 {
  6235. goodStockInventory.ID = goodStock.ID
  6236. service.SaveGoodStockInventoryList(goodStockInventory)
  6237. }
  6238. }
  6239. }
  6240. this.ServeSuccessJSON(map[string]interface{}{
  6241. "msg": "保存成功!",
  6242. })
  6243. }
  6244. func (this *StockManagerApiController) GetDamageDetailByGoodId() {
  6245. good_id, _ := this.GetInt64("good_id")
  6246. warehousing_order := this.GetString("warehousing_order")
  6247. inventory_type, _ := this.GetInt64("type")
  6248. list, _ := service.GetDamageDetailByGoodId(good_id, warehousing_order, inventory_type)
  6249. orgId := this.GetAdminUserInfo().CurrentOrgId
  6250. damageList, _ := service.GetStockDamagedCountOne(orgId, warehousing_order, inventory_type)
  6251. this.ServeSuccessJSON(map[string]interface{}{
  6252. "list": list,
  6253. "damageList": damageList,
  6254. })
  6255. }
  6256. func (this *StockManagerApiController) GetInventoryExportList() {
  6257. orgId := this.GetAdminUserInfo().CurrentOrgId
  6258. list, _ := service.GetInventoryExportList(orgId)
  6259. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  6260. this.ServeSuccessJSON(map[string]interface{}{
  6261. "list": list,
  6262. "manufacturerList": manufacturerList,
  6263. })
  6264. }
  6265. func (this *StockManagerApiController) UpdateCancelStockOrder() {
  6266. type_id, _ := this.GetInt64("type_id")
  6267. //获取目前在使用的机构ID
  6268. list, _ := service.GetOrgIdList()
  6269. //耗材
  6270. if type_id == 1 {
  6271. for _, item := range list {
  6272. //查询该机构的所有耗材
  6273. goodList, _ := service.GetAllGoodList(item.OrgId)
  6274. for _, it := range goodList {
  6275. //查询该耗材的入库总数
  6276. info, _ := service.GetStockCountWarehouseInfoById(it.ID)
  6277. var total int64
  6278. for _, its := range info {
  6279. total += its.StockCount
  6280. }
  6281. //更新库存
  6282. service.ModifyGoodAddInformationSeven(it.ID, total, it.OrgId)
  6283. }
  6284. }
  6285. }
  6286. //药品
  6287. if type_id == 2 {
  6288. for _, item := range list {
  6289. fmt.Println(item)
  6290. //查询该机构的所有药品
  6291. drugList, _ := service.GetAllBaseDrugStockList(4)
  6292. for _, it := range drugList {
  6293. //查询该药品的入库总数
  6294. info, _ := service.GetDrugStockCountWarehoseInfoById(it.ID)
  6295. var sum_count int64
  6296. for _, its := range info {
  6297. if its.MaxUnit == it.MaxUnit {
  6298. its.StockMaxNumber = its.StockMaxNumber * it.MinNumber
  6299. }
  6300. sum_count += its.StockMaxNumber + its.StockMinNumber
  6301. }
  6302. service.UpdateModifyDrugInfoById(it.ID, sum_count, it.OrgId)
  6303. }
  6304. }
  6305. }
  6306. }
  6307. func (this *StockManagerApiController) GetDrugDetailSummary() {
  6308. timeLayout := "2006-01-02"
  6309. loc, _ := time.LoadLocation("Local")
  6310. start_time := this.GetString("start_time")
  6311. end_time := this.GetString("end_time")
  6312. var startTime int64
  6313. if len(start_time) > 0 {
  6314. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6315. if err != nil {
  6316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6317. return
  6318. }
  6319. startTime = theTime.Unix()
  6320. fmt.Println("开始时间", startTime)
  6321. }
  6322. var endTime int64
  6323. if len(end_time) > 0 {
  6324. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6325. if err != nil {
  6326. utils.ErrorLog(err.Error())
  6327. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6328. return
  6329. }
  6330. endTime = theTime.Unix()
  6331. }
  6332. keyword := this.GetString("keyword")
  6333. limit, _ := this.GetInt64("limit")
  6334. page, _ := this.GetInt64("page")
  6335. orgId := this.GetAdminUserInfo().CurrentOrgId
  6336. list, total, err := service.GetDrugDetailSummary(startTime, endTime, keyword, limit, page, orgId)
  6337. druglist, _, _ := service.GetDrugDetailSummaryOne(startTime, endTime, keyword, limit, page, orgId)
  6338. patients, _ := service.GetAllpatient(orgId)
  6339. var drugType = "药品类型"
  6340. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  6341. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  6342. for _, item := range list {
  6343. for _, it := range druglist {
  6344. if item.DrugId == it.DrugId {
  6345. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6346. }
  6347. }
  6348. }
  6349. drug, _ := service.GetAllDrugSummary(orgId)
  6350. if err == nil {
  6351. this.ServeSuccessJSON(map[string]interface{}{
  6352. "list": list,
  6353. "total": total,
  6354. "drug": drug,
  6355. "drugTypeList": drugTypeList,
  6356. "patients": patients,
  6357. })
  6358. }
  6359. }
  6360. func (this *StockManagerApiController) GetGoodDetailSummary() {
  6361. timeLayout := "2006-01-02"
  6362. loc, _ := time.LoadLocation("Local")
  6363. start_time := this.GetString("start_time")
  6364. end_time := this.GetString("end_time")
  6365. var startTime int64
  6366. if len(start_time) > 0 {
  6367. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6368. if err != nil {
  6369. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6370. return
  6371. }
  6372. startTime = theTime.Unix()
  6373. }
  6374. var endTime int64
  6375. if len(end_time) > 0 {
  6376. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6377. if err != nil {
  6378. utils.ErrorLog(err.Error())
  6379. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6380. return
  6381. }
  6382. endTime = theTime.Unix()
  6383. }
  6384. keyword := this.GetString("keyword")
  6385. limit, _ := this.GetInt64("limit")
  6386. page, _ := this.GetInt64("page")
  6387. orgId := this.GetAdminUserInfo().CurrentOrgId
  6388. list, total, err := service.GetGoodDetailSummary(startTime, endTime, keyword, limit, page, orgId)
  6389. goodlist, _, _ := service.GetGoodDetailSummaryOne(startTime, endTime, keyword, limit, page, orgId)
  6390. for _, item := range list {
  6391. for _, it := range goodlist {
  6392. if item.ProjectId == it.ProjectId {
  6393. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6394. }
  6395. }
  6396. }
  6397. information, _ := service.GeAllGoodInformation(orgId)
  6398. patients, _ := service.GetAllpatient(orgId)
  6399. goodType, _ := service.GetAllGoodType(orgId)
  6400. if err == nil {
  6401. this.ServeSuccessJSON(map[string]interface{}{
  6402. "list": list,
  6403. "total": total,
  6404. "good": information,
  6405. "patients": patients,
  6406. "goodType": goodType,
  6407. })
  6408. }
  6409. }
  6410. func (this *StockManagerApiController) CheckWarehouseOut() {
  6411. id, _ := this.GetInt64("id")
  6412. orgId := this.GetAdminUserInfo().CurrentOrgId
  6413. creater := this.GetAdminUserInfo().AdminUser.Id
  6414. warehouseOut, errcode := service.GetWarehouseById(id)
  6415. if errcode != nil {
  6416. goodErrcode := models.XtGoodErrcode{
  6417. UserOrgId: orgId,
  6418. Errcode: "查询审核出库单报错",
  6419. GoodId: 0,
  6420. Status: 0,
  6421. Ctime: 0,
  6422. Mtime: 0,
  6423. Count: 0,
  6424. StockCount: 0,
  6425. Creater: creater,
  6426. BatchNumberId: 0,
  6427. WarehouseOutId: 0,
  6428. }
  6429. service.CreateGoodErrcode(goodErrcode)
  6430. }
  6431. //查询已保存的单据
  6432. warehousingOutInfo, erroce := service.GetWarehouseOutById(id, orgId)
  6433. if erroce != nil {
  6434. goodErrcode := models.XtGoodErrcode{
  6435. UserOrgId: orgId,
  6436. Errcode: "查询已审核出库详情单报错",
  6437. GoodId: 0,
  6438. Status: 0,
  6439. Ctime: 0,
  6440. Mtime: 0,
  6441. Count: 0,
  6442. StockCount: 0,
  6443. Creater: creater,
  6444. BatchNumberId: 0,
  6445. WarehouseOutId: 0,
  6446. }
  6447. service.CreateGoodErrcode(goodErrcode)
  6448. }
  6449. ////出库逻辑
  6450. for _, item := range warehousingOutInfo {
  6451. // 查询该耗材是否有库存
  6452. warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId, item.StorehouseId)
  6453. storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseId, item.OrgId)
  6454. // 如果出库数量大于该批次剩余库存数量
  6455. if item.Count > warehouseOne.StockCount {
  6456. goodErrcode := models.XtGoodErrcode{
  6457. UserOrgId: orgId,
  6458. Errcode: "出库数量大于该批次剩余库存",
  6459. GoodId: 0,
  6460. Status: 0,
  6461. Ctime: 0,
  6462. Mtime: 0,
  6463. Count: 0,
  6464. StockCount: 0,
  6465. Creater: creater,
  6466. BatchNumberId: warehouseOne.ID,
  6467. WarehouseOutId: item.ID,
  6468. }
  6469. service.CreateGoodErrcode(goodErrcode)
  6470. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6471. this.ServeSuccessJSON(map[string]interface{}{
  6472. "msg": "1",
  6473. "good_name": goodObj.GoodName,
  6474. "specification_name": goodObj.SpecificationName,
  6475. "storehose_name": storehouse.StorehouseName,
  6476. })
  6477. return
  6478. }
  6479. }
  6480. for _, item := range warehousingOutInfo {
  6481. creater := this.GetAdminUserInfo().AdminUser.Id
  6482. //出库
  6483. err := service.ConsumablesDeliveryThirty(orgId, item.SysRecordTime, item, &warehouseOut, item.Count, creater)
  6484. if err != nil {
  6485. goodErrcode := models.XtGoodErrcode{
  6486. UserOrgId: orgId,
  6487. Errcode: "调用出库接口报错",
  6488. GoodId: item.GoodId,
  6489. Status: 1,
  6490. Ctime: time.Now().Unix(),
  6491. Mtime: 0,
  6492. Count: 0,
  6493. StockCount: 0,
  6494. Creater: creater,
  6495. BatchNumberId: 0,
  6496. WarehouseOutId: 0,
  6497. }
  6498. service.CreateGoodErrcode(goodErrcode)
  6499. }
  6500. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6501. var flush_count int64
  6502. for _, it := range goodList {
  6503. flush_count += it.StockCount
  6504. }
  6505. errs := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
  6506. if errs != nil {
  6507. goodErrcode := models.XtGoodErrcode{
  6508. UserOrgId: orgId,
  6509. Errcode: "手动出库更新剩余出库失败",
  6510. GoodId: item.GoodId,
  6511. Status: 1,
  6512. Ctime: time.Now().Unix(),
  6513. Mtime: 0,
  6514. Count: 0,
  6515. StockCount: 0,
  6516. Creater: creater,
  6517. BatchNumberId: 0,
  6518. WarehouseOutId: 0,
  6519. }
  6520. service.CreateGoodErrcode(goodErrcode)
  6521. }
  6522. orgId := this.GetAdminUserInfo().CurrentOrgId
  6523. //查询默认仓库
  6524. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6525. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
  6526. var total_count int64
  6527. for _, it := range stockList {
  6528. total_count += it.StockCount
  6529. }
  6530. //基础库扣减库存
  6531. errsum := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, orgId)
  6532. if errsum != nil {
  6533. goodErrcode := models.XtGoodErrcode{
  6534. UserOrgId: orgId,
  6535. Errcode: "基础库扣减库存报错",
  6536. GoodId: item.GoodId,
  6537. Status: 1,
  6538. Ctime: time.Now().Unix(),
  6539. Mtime: 0,
  6540. Count: 0,
  6541. StockCount: 0,
  6542. Creater: creater,
  6543. BatchNumberId: 0,
  6544. WarehouseOutId: 0,
  6545. }
  6546. service.CreateGoodErrcode(goodErrcode)
  6547. }
  6548. }
  6549. //审核单据
  6550. err := service.UpdatedWarehouseOut(id)
  6551. if err != nil {
  6552. goodErrcode := models.XtGoodErrcode{
  6553. UserOrgId: orgId,
  6554. Errcode: "审核单据报错",
  6555. GoodId: 0,
  6556. Status: 1,
  6557. Ctime: time.Now().Unix(),
  6558. Mtime: 0,
  6559. Count: 0,
  6560. StockCount: 0,
  6561. Creater: creater,
  6562. BatchNumberId: 0,
  6563. WarehouseOutId: 0,
  6564. }
  6565. service.CreateGoodErrcode(goodErrcode)
  6566. }
  6567. if err == nil {
  6568. this.ServeSuccessJSON(map[string]interface{}{
  6569. "msg": "2",
  6570. "good_name": "",
  6571. "specification_name": "",
  6572. "storehose_name": "",
  6573. })
  6574. }
  6575. }
  6576. func (this *StockManagerApiController) ReturnCheckWarehouseOut() {
  6577. id, _ := this.GetInt64("id")
  6578. orgId := this.GetAdminUserInfo().CurrentOrgId
  6579. creater := this.GetAdminUserInfo().AdminUser.Id
  6580. // 查询出库数据
  6581. list, err := service.GetWarehouseOutById(id, orgId)
  6582. if err != nil {
  6583. goodErrcode := models.XtGoodErrcode{
  6584. UserOrgId: orgId,
  6585. Errcode: "反审核查询出库单报错",
  6586. GoodId: 0,
  6587. Status: 1,
  6588. Ctime: time.Now().Unix(),
  6589. Mtime: 0,
  6590. Count: 0,
  6591. StockCount: 0,
  6592. Creater: creater,
  6593. BatchNumberId: 0,
  6594. WarehouseOutId: 0,
  6595. }
  6596. service.CreateGoodErrcode(goodErrcode)
  6597. }
  6598. for _, item := range list {
  6599. //回退库存
  6600. err := service.UpdateaGoodWarehouseInfo(item.Count, item.GoodId, item.OrgId, item.WarehouseInfotId)
  6601. if err != nil {
  6602. goodErrcode := models.XtGoodErrcode{
  6603. UserOrgId: orgId,
  6604. Errcode: "反审核回退库存报错",
  6605. GoodId: 0,
  6606. Status: 1,
  6607. Ctime: time.Now().Unix(),
  6608. Mtime: 0,
  6609. Count: 0,
  6610. StockCount: 0,
  6611. Creater: creater,
  6612. BatchNumberId: 0,
  6613. WarehouseOutId: 0,
  6614. }
  6615. service.CreateGoodErrcode(goodErrcode)
  6616. }
  6617. //查询默认仓库
  6618. storeHouseConfig, errs := service.GetAllStoreHouseConfig(orgId)
  6619. if errs != nil {
  6620. goodErrcode := models.XtGoodErrcode{
  6621. UserOrgId: orgId,
  6622. Errcode: "反审核查询默认仓库报错",
  6623. GoodId: 0,
  6624. Status: 1,
  6625. Ctime: time.Now().Unix(),
  6626. Mtime: 0,
  6627. Count: 0,
  6628. StockCount: 0,
  6629. Creater: creater,
  6630. BatchNumberId: 0,
  6631. WarehouseOutId: 0,
  6632. }
  6633. service.CreateGoodErrcode(goodErrcode)
  6634. }
  6635. stockList, errcodes := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
  6636. if errcodes != nil {
  6637. goodErrcode := models.XtGoodErrcode{
  6638. UserOrgId: orgId,
  6639. Errcode: "反审核查询默认仓库库存报错",
  6640. GoodId: 0,
  6641. Status: 1,
  6642. Ctime: time.Now().Unix(),
  6643. Mtime: 0,
  6644. Count: 0,
  6645. StockCount: 0,
  6646. Creater: creater,
  6647. BatchNumberId: 0,
  6648. WarehouseOutId: 0,
  6649. }
  6650. service.CreateGoodErrcode(goodErrcode)
  6651. }
  6652. var total_count int64
  6653. for _, it := range stockList {
  6654. total_count += it.StockCount
  6655. }
  6656. //基础库扣减库存
  6657. errs = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, orgId)
  6658. if errs != nil {
  6659. goodErrcode := models.XtGoodErrcode{
  6660. UserOrgId: orgId,
  6661. Errcode: "反审核基础库扣减库存报错",
  6662. GoodId: 0,
  6663. Status: 1,
  6664. Ctime: time.Now().Unix(),
  6665. Mtime: 0,
  6666. Count: 0,
  6667. StockCount: 0,
  6668. Creater: creater,
  6669. BatchNumberId: 0,
  6670. WarehouseOutId: 0,
  6671. }
  6672. service.CreateGoodErrcode(goodErrcode)
  6673. }
  6674. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6675. var flush_count int64
  6676. for _, it := range goodList {
  6677. flush_count += it.StockCount
  6678. }
  6679. erros := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
  6680. if erros != nil {
  6681. goodErrcode := models.XtGoodErrcode{
  6682. UserOrgId: orgId,
  6683. Errcode: "手动出库更新剩余库存报错",
  6684. GoodId: 0,
  6685. Status: 1,
  6686. Ctime: time.Now().Unix(),
  6687. Mtime: 0,
  6688. Count: 0,
  6689. StockCount: 0,
  6690. Creater: creater,
  6691. BatchNumberId: 0,
  6692. WarehouseOutId: 0,
  6693. }
  6694. service.CreateGoodErrcode(goodErrcode)
  6695. }
  6696. //扣减出库数据
  6697. errcoeds := service.ModifyReduceGoodSumCount(item.StorehouseId, item.Count, orgId, item.GoodId)
  6698. if errcoeds != nil {
  6699. goodErrcode := models.XtGoodErrcode{
  6700. UserOrgId: orgId,
  6701. Errcode: "反审核扣减出库数据报错",
  6702. GoodId: 0,
  6703. Status: 1,
  6704. Ctime: time.Now().Unix(),
  6705. Mtime: 0,
  6706. Count: 0,
  6707. StockCount: 0,
  6708. Creater: creater,
  6709. BatchNumberId: 0,
  6710. WarehouseOutId: 0,
  6711. }
  6712. service.CreateGoodErrcode(goodErrcode)
  6713. }
  6714. }
  6715. //删除流水,改变审核状态
  6716. errcos := service.ModifyGoodWarehouseOut(id)
  6717. if errcos != nil {
  6718. goodErrcode := models.XtGoodErrcode{
  6719. UserOrgId: orgId,
  6720. Errcode: "反审核删除流水,改变审核状态报错",
  6721. GoodId: 0,
  6722. Status: 1,
  6723. Ctime: time.Now().Unix(),
  6724. Mtime: 0,
  6725. Count: 0,
  6726. StockCount: 0,
  6727. Creater: creater,
  6728. BatchNumberId: 0,
  6729. WarehouseOutId: 0,
  6730. }
  6731. service.CreateGoodErrcode(goodErrcode)
  6732. }
  6733. if err == nil {
  6734. this.ServeSuccessJSON(map[string]interface{}{
  6735. "list": "list",
  6736. })
  6737. }
  6738. }
  6739. func (this *StockManagerApiController) CheckWarehouseInfo() {
  6740. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  6741. orgId := this.GetAdminUserInfo().CurrentOrgId
  6742. Creator := this.GetAdminUserInfo().AdminUser.Id
  6743. //查询默认仓库
  6744. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6745. checker := this.GetAdminUserInfo().AdminUser.Id
  6746. //更改审核状态
  6747. err := service.UpdateCheckWarehouseInfo(warehousing_info_id, checker)
  6748. if err == nil {
  6749. list, _ := service.GetWarehouseInfoList(warehousing_info_id, orgId)
  6750. for _, item := range list {
  6751. service.UpdateWarehouseInfoByIdListThree(item.WarehousingCount, item.ID)
  6752. //查询该耗材剩余库存库
  6753. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
  6754. var total_count int64
  6755. var sum_in_count int64
  6756. for _, it := range stockList {
  6757. total_count += it.StockCount
  6758. sum_in_count += it.WarehousingCount
  6759. }
  6760. //基础库插入数据
  6761. service.UpdateGoodInfoAddSumCount(item.GoodId, total_count, orgId, sum_in_count)
  6762. //查询该仓库是否有数据
  6763. _, errcode := service.GetGoodStockCount(orgId, item.StorehouseId, item.GoodId)
  6764. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6765. var flush_count int64
  6766. for _, it := range goodList {
  6767. flush_count += it.StockCount
  6768. }
  6769. stockFlow := models.VmStockFlow{
  6770. WarehousingId: item.WarehousingId,
  6771. GoodId: item.GoodId,
  6772. Number: item.Number,
  6773. LicenseNumber: item.LicenseNumber,
  6774. Count: item.WarehousingCount,
  6775. UserOrgId: item.OrgId,
  6776. PatientId: 0,
  6777. SystemTime: 0,
  6778. ConsumableType: 1,
  6779. IsSys: 1,
  6780. WarehousingOrder: item.WarehousingOrder,
  6781. WarehouseOutId: 0,
  6782. WarehouseOutOrderNumber: "",
  6783. IsEdit: 1,
  6784. CancelStockId: 0,
  6785. CancelOrderNumber: "",
  6786. Manufacturer: item.Manufacturer,
  6787. Dealer: item.Dealer,
  6788. Creator: Creator,
  6789. UpdateCreator: 0,
  6790. Status: 1,
  6791. Ctime: item.Ctime,
  6792. Mtime: 0,
  6793. Price: item.PackingPrice,
  6794. WarehousingDetailId: item.ID,
  6795. WarehouseOutDetailId: 0,
  6796. CancelOutDetailId: 0,
  6797. ProductDate: item.ProductDate,
  6798. ExpireDate: item.ExpiryDate,
  6799. SupplyWarehouseId: item.SupplyWarehouseId,
  6800. StorehouseId: item.StorehouseId,
  6801. AdminUserId: 0,
  6802. BuyPrice: item.Price,
  6803. StockCount: "",
  6804. BatchNumberCount: item.WarehousingCount,
  6805. IsCheck: 1,
  6806. OverCount: flush_count,
  6807. OperateTime: time.Now().Unix(),
  6808. GoodCode: item.GoodCode,
  6809. }
  6810. //创建出库流水
  6811. service.CreateStockFlowOne(stockFlow)
  6812. if errcode == gorm.ErrRecordNotFound {
  6813. goodCount := models.XtGoodStockCount{
  6814. UserOrgId: orgId,
  6815. GoodId: item.GoodId,
  6816. StorehouseId: item.StorehouseId,
  6817. Status: 1,
  6818. Ctime: time.Now().Unix(),
  6819. Mtime: time.Now().Unix(),
  6820. StockInCount: item.WarehousingCount,
  6821. StockOutCount: 0,
  6822. StockCancelCount: 0,
  6823. FlushCount: flush_count,
  6824. StockActOutCount: 0,
  6825. }
  6826. service.CreateGoodCount(goodCount)
  6827. }
  6828. if errcode == nil {
  6829. service.UpdateGoodStockCount(orgId, item.StorehouseId, item.GoodId, item.WarehousingCount, flush_count)
  6830. }
  6831. }
  6832. }
  6833. if err == nil {
  6834. this.ServeSuccessJSON(map[string]interface{}{
  6835. "list": "list",
  6836. })
  6837. }
  6838. }
  6839. func (this *StockManagerApiController) ReturnCheckWarehouseInfo() {
  6840. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  6841. orgId := this.GetAdminUserInfo().CurrentOrgId
  6842. //查询入库数据
  6843. list, _ := service.GetWarehouseInfoList(warehousing_info_id, orgId)
  6844. for _, item := range list {
  6845. //查询该耗材 是否有出库数据
  6846. outlist, _ := service.GetWarehouseOutByWarehouseInfoId(item.ID, item.GoodId, item.OrgId)
  6847. if len(outlist) > 0 {
  6848. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCheckGoodParamWrong)
  6849. return
  6850. }
  6851. }
  6852. //for _, item := range list {
  6853. //
  6854. // //扣减数量
  6855. // service.UpdateWarehouseInfoByIdListTwo(item.WarehousingCount, item.ID)
  6856. //
  6857. // //删除流水
  6858. // service.UpdateWarehouseInfoFlow(item.ID)
  6859. //
  6860. // goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6861. // var flush_count int64
  6862. // for _, it := range goodList {
  6863. // flush_count += it.StockCount
  6864. // }
  6865. //
  6866. // //扣减数量
  6867. // service.UpdateGoodInCount(item.WarehousingCount, item.OrgId, item.GoodId, item.StorehouseId, flush_count)
  6868. //
  6869. // //查询默认仓库
  6870. // storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6871. // //查询该耗材剩余多少库存
  6872. // stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)
  6873. // var sum_count int64
  6874. // var sum_in_count int64
  6875. // for _, it := range stockList {
  6876. // sum_count += it.StockCount
  6877. // sum_in_count += it.WarehousingCount
  6878. // }
  6879. // service.UpdateGoodInfoAddSumCount(item.GoodId, sum_count, orgId, sum_in_count)
  6880. //}
  6881. //err := service.ReturnCheckWarehouseInfo(warehousing_info_id)
  6882. err := service.UpdateWarehouseInfoMap(list, warehousing_info_id, orgId)
  6883. if err == nil {
  6884. this.ServeSuccessJSON(map[string]interface{}{
  6885. "msg": "反审核成功!",
  6886. })
  6887. return
  6888. }
  6889. }
  6890. func (this *StockManagerApiController) CheckStockWarehouseInfo() {
  6891. cancel_stock_id, _ := this.GetInt64("cancel_stock_id")
  6892. orgId := this.GetAdminUserInfo().CurrentOrgId
  6893. list, _ := service.GetCancelStockInfoListById(cancel_stock_id, orgId)
  6894. creater := this.GetAdminUserInfo().AdminUser.Id
  6895. manufacturerlist, _ := service.GetAllManufacturerList(orgId)
  6896. dealerList, _ := service.GetAllDealerList(orgId)
  6897. var manufacturer_id int64
  6898. var cancel_total_count int64
  6899. var out_total_count int64
  6900. var dealer_id int64
  6901. for _, item := range list {
  6902. //查询该药品该批次的出库数量是否满足退库需求
  6903. outList, _ := service.GetWarehouseOutList(item.OrgId, item.GoodId, item.WarehouseInfoId)
  6904. for _, it := range outList {
  6905. out_total_count += it.Count
  6906. }
  6907. warehouseList, _ := service.GetCancelWarehouseList(item.OrgId, item.GoodId, item.WarehouseInfoId)
  6908. for _, it := range warehouseList {
  6909. cancel_total_count += it.Count
  6910. }
  6911. if cancel_total_count > out_total_count {
  6912. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6913. this.ServeSuccessJSON(map[string]interface{}{
  6914. "msg": "2",
  6915. "good_name": goodObj.GoodName,
  6916. "specification_name": goodObj.SpecificationName,
  6917. })
  6918. return
  6919. }
  6920. }
  6921. cancelStock := models.CancelStock{
  6922. IsCheck: 1,
  6923. }
  6924. service.CheckCancelStock(cancelStock, cancel_stock_id, orgId)
  6925. //回退库存
  6926. cancellist, _ := service.GetCancelStockInfoById(cancel_stock_id, orgId)
  6927. for _, item := range cancellist {
  6928. for _, items := range manufacturerlist {
  6929. if item.Manufacturer == items.ManufacturerName {
  6930. manufacturer_id = items.ID
  6931. }
  6932. }
  6933. for _, it := range dealerList {
  6934. if item.Dealer == it.DealerName {
  6935. dealer_id = it.ID
  6936. }
  6937. }
  6938. //回退库存
  6939. service.UpdateCancelStockNumber(item.Count, item.WarehouseInfoId, orgId)
  6940. //更新基础库库存
  6941. service.UpdateGoodSumCount(item.Count, item.GoodId, orgId)
  6942. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  6943. //退库数量增加
  6944. service.UpdateSumAddCancelCount(orgId, item.GoodId, item.StorehouseId, item.Count)
  6945. var flush_count int64
  6946. for _, it := range goodList {
  6947. flush_count += it.StockCount
  6948. }
  6949. stockFlow := models.VmStockFlow{
  6950. ID: 0,
  6951. WarehousingId: item.WarehouseInfoId,
  6952. GoodId: item.GoodId,
  6953. Number: item.Number,
  6954. LicenseNumber: "",
  6955. Count: item.Count,
  6956. UserOrgId: item.OrgId,
  6957. PatientId: item.PatientId,
  6958. SystemTime: item.RecordDate,
  6959. ConsumableType: 4,
  6960. IsSys: 0,
  6961. WarehousingOrder: "",
  6962. WarehouseOutId: 0,
  6963. WarehouseOutOrderNumber: "",
  6964. IsEdit: 0,
  6965. CancelStockId: cancel_stock_id,
  6966. CancelOrderNumber: item.OrderNumber,
  6967. Manufacturer: manufacturer_id,
  6968. Dealer: dealer_id,
  6969. Creator: creater,
  6970. UpdateCreator: 0,
  6971. Status: 1,
  6972. Ctime: time.Now().Unix(),
  6973. Mtime: 0,
  6974. Price: item.Price,
  6975. WarehousingDetailId: item.WarehouseInfoId,
  6976. WarehouseOutDetailId: 0,
  6977. CancelOutDetailId: item.ID,
  6978. ProductDate: item.ProductDate,
  6979. ExpireDate: item.ExpiryDate,
  6980. ReturnCount: 0,
  6981. ProjectId: 0,
  6982. SupplyWarehouseId: 0,
  6983. SupplyCancelOutId: 0,
  6984. SupplyWarehouseDetailInfo: 0,
  6985. StorehouseId: item.StorehouseId,
  6986. SecondWarehouseInfoId: 0,
  6987. AdminUserId: 0,
  6988. BuyPrice: item.Price,
  6989. StockCount: "",
  6990. OverCount: flush_count,
  6991. }
  6992. //创建流水
  6993. service.CreateStockFlowOne(stockFlow)
  6994. //更新剩余库存
  6995. errs := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
  6996. //出库数量减少
  6997. service.ModifyAddGoodSumCount(item.StorehouseId, item.Count, orgId, item.GoodId)
  6998. if errs != nil {
  6999. goodErrcode := models.XtGoodErrcode{
  7000. UserOrgId: item.OrgId,
  7001. Errcode: "手动退库更新剩余出库失败",
  7002. GoodId: item.GoodId,
  7003. Status: 1,
  7004. Ctime: time.Now().Unix(),
  7005. Mtime: 0,
  7006. Count: 0,
  7007. StockCount: 0,
  7008. Creater: creater,
  7009. BatchNumberId: 0,
  7010. WarehouseOutId: 0,
  7011. }
  7012. service.CreateGoodErrcode(goodErrcode)
  7013. }
  7014. }
  7015. this.ServeSuccessJSON(map[string]interface{}{
  7016. "msg": "1",
  7017. "good_name": "",
  7018. "specification_name": "",
  7019. })
  7020. return
  7021. }
  7022. func (this *StockManagerApiController) CheckReturnStockWarehouseInfo() {
  7023. cancel_stock_id, _ := this.GetInt64("cancel_stock_id")
  7024. orgId := this.GetAdminUserInfo().CurrentOrgId
  7025. cancelStock := models.CancelStock{
  7026. IsCheck: 2,
  7027. }
  7028. list, _ := service.GetCancelStockInfoListById(cancel_stock_id, orgId)
  7029. creater := this.GetAdminUserInfo().AdminUser.Id
  7030. for _, item := range list {
  7031. //回退库存
  7032. service.UpdateStockNumberWarehouseInfo(item.WarehouseInfoId, item.GoodId, item.OrgId, item.Count)
  7033. service.UpdateStockWarehouseInfoStockFlow(item.ID, orgId, item.GoodId)
  7034. //退库数量增加
  7035. service.UpdateSumReduceCancelCount(orgId, item.GoodId, item.StorehouseId, item.Count)
  7036. goodList, _ := service.GetSumGoodList(orgId, item.StorehouseId, item.GoodId)
  7037. var flush_count int64
  7038. for _, it := range goodList {
  7039. flush_count += it.StockCount
  7040. }
  7041. errs := service.UpdateSumGood(orgId, item.StorehouseId, item.GoodId, flush_count)
  7042. //出库数量增加
  7043. service.UpdateSumAddOutCount(orgId, item.GoodId, item.StorehouseId, item.Count)
  7044. if errs != nil {
  7045. goodErrcode := models.XtGoodErrcode{
  7046. UserOrgId: item.OrgId,
  7047. Errcode: "手动退库反审核更新剩余出库失败",
  7048. GoodId: item.GoodId,
  7049. Status: 1,
  7050. Ctime: time.Now().Unix(),
  7051. Mtime: 0,
  7052. Count: 0,
  7053. StockCount: 0,
  7054. Creater: creater,
  7055. BatchNumberId: 0,
  7056. WarehouseOutId: 0,
  7057. }
  7058. service.CreateGoodErrcode(goodErrcode)
  7059. }
  7060. }
  7061. err := service.UpdateStockWarehouseInfo(cancel_stock_id, orgId, cancelStock)
  7062. if err == nil {
  7063. this.ServeSuccessJSON(map[string]interface{}{
  7064. "msg": "反审核成功!",
  7065. })
  7066. return
  7067. }
  7068. }
  7069. func (this *StockManagerApiController) GetPrintList() {
  7070. storehouse_id, _ := this.GetInt64("storehouse_id")
  7071. limit, _ := this.GetInt64("limit")
  7072. page, _ := this.GetInt64("page")
  7073. good_name := this.GetString("good_name")
  7074. ids := this.GetString("ids")
  7075. idSplit := strings.Split(ids, ",")
  7076. fmt.Println(storehouse_id, good_name)
  7077. orgId := this.GetAdminUserInfo().CurrentOrgId
  7078. houseList, _ := service.GetAllStoreHouseList(orgId)
  7079. list, total, _ := service.GetInventoryDetailPrintMapList(good_name, limit, page, orgId, storehouse_id, idSplit)
  7080. this.ServeSuccessJSON(map[string]interface{}{
  7081. "list": list,
  7082. "total": total,
  7083. "houseList": houseList,
  7084. })
  7085. }
  7086. func (this *StockManagerApiController) GetInvetoryWarehouseInfoList() {
  7087. storehouse_id, _ := this.GetInt64("storehouse_id")
  7088. orgId := this.GetAdminUserInfo().CurrentOrgId
  7089. list, _ := service.GetInvetoryWarehouseInfoList(orgId, storehouse_id)
  7090. var info []*models.WarehousingInfo
  7091. if orgId == 10571 {
  7092. for _, item := range list {
  7093. if strings.ContainsAny(item.GoodInfo.GoodStatus, "收费") {
  7094. info = append(info, item)
  7095. }
  7096. }
  7097. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  7098. dealerList, _ := service.GetAllDealerList(orgId)
  7099. this.ServeSuccessJSON(map[string]interface{}{
  7100. "list": info,
  7101. "manufacturerList": manufacturerList,
  7102. "dealerList": dealerList,
  7103. })
  7104. } else {
  7105. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  7106. dealerList, _ := service.GetAllDealerList(orgId)
  7107. this.ServeSuccessJSON(map[string]interface{}{
  7108. "list": list,
  7109. "manufacturerList": manufacturerList,
  7110. "dealerList": dealerList,
  7111. "info": info,
  7112. })
  7113. }
  7114. }
  7115. func (this *StockManagerApiController) GetNewGoodWarehouseInfo() {
  7116. timeLayout := "2006-01-02"
  7117. loc, _ := time.LoadLocation("Local")
  7118. start_time := this.GetString("start_time")
  7119. end_time := this.GetString("end_time")
  7120. var startTime int64
  7121. if len(start_time) > 0 {
  7122. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7123. if err != nil {
  7124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7125. return
  7126. }
  7127. startTime = theTime.Unix()
  7128. }
  7129. var endTime int64
  7130. if len(end_time) > 0 {
  7131. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7132. if err != nil {
  7133. utils.ErrorLog(err.Error())
  7134. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7135. return
  7136. }
  7137. endTime = theTime.Unix()
  7138. }
  7139. storehouse_id, _ := this.GetInt64("storehouse_id")
  7140. keywords := this.GetString("keywords")
  7141. orgId := this.GetAdminUserInfo().CurrentOrgId
  7142. var goodids []int64
  7143. //查询商品名称
  7144. if len(keywords) > 0 {
  7145. //查询商品名称
  7146. list, _ := service.GetGoodInforByGoodName(keywords, orgId)
  7147. for _, item := range list {
  7148. goodids = append(goodids, item.ID)
  7149. //入库详情但里面查询
  7150. }
  7151. }
  7152. list, _ := service.GetNewGoodWarehouseInfo(startTime, endTime, orgId, goodids, storehouse_id)
  7153. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  7154. dealerList, _ := service.GetAllDealerList(orgId)
  7155. storeHouseList, _ := service.GetAllStoreHouseList(orgId)
  7156. this.ServeSuccessJSON(map[string]interface{}{
  7157. "list": list,
  7158. "manufacturerList": manufacturerList,
  7159. "dealerList": dealerList,
  7160. "storeHouseList": storeHouseList,
  7161. })
  7162. }
  7163. func (this *StockManagerApiController) GetNewWarehouseOutInfoList() {
  7164. timeLayout := "2006-01-02"
  7165. loc, _ := time.LoadLocation("Local")
  7166. start_time := this.GetString("start_time")
  7167. end_time := this.GetString("end_time")
  7168. var startTime int64
  7169. if len(start_time) > 0 {
  7170. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7171. if err != nil {
  7172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7173. return
  7174. }
  7175. startTime = theTime.Unix()
  7176. }
  7177. var endTime int64
  7178. if len(end_time) > 0 {
  7179. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7180. if err != nil {
  7181. utils.ErrorLog(err.Error())
  7182. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7183. return
  7184. }
  7185. endTime = theTime.Unix()
  7186. }
  7187. storehouse_id, _ := this.GetInt64("storehouse_id")
  7188. keywords := this.GetString("keyword")
  7189. orgId := this.GetAdminUserInfo().CurrentOrgId
  7190. var goodids []int64
  7191. //查询商品名称
  7192. if len(keywords) > 0 {
  7193. //查询商品名称
  7194. list, _ := service.GetGoodInforByGoodName(keywords, orgId)
  7195. for _, item := range list {
  7196. goodids = append(goodids, item.ID)
  7197. //入库详情但里面查询
  7198. }
  7199. }
  7200. list, _ := service.GetNewWarehouseOutInfoList(startTime, endTime, orgId, goodids, storehouse_id)
  7201. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  7202. dealerList, _ := service.GetAllDealerList(orgId)
  7203. storeHouseList, _ := service.GetAllStoreHouseList(orgId)
  7204. this.ServeSuccessJSON(map[string]interface{}{
  7205. "list": list,
  7206. "manufacturerList": manufacturerList,
  7207. "dealerList": dealerList,
  7208. "storeHouseList": storeHouseList,
  7209. })
  7210. }
  7211. func (this *StockManagerApiController) GetStockFlowOrderList() {
  7212. good_id, _ := this.GetInt64("good_id")
  7213. orgId := this.GetAdminUserInfo().CurrentOrgId
  7214. list, _ := service.GetStockFlowOrderList(good_id, orgId)
  7215. for index, _ := range list {
  7216. if list[index].ConsumableType == 3 || list[index].ConsumableType == 2 || list[index].ConsumableType == 11 || list[index].ConsumableType == 12 || list[index].ConsumableType == 15 {
  7217. var count int64
  7218. if index == 0 {
  7219. count = list[index].FlushOverCount - list[index].Count
  7220. service.UpdateOverCount(list[index+1].ID, count)
  7221. }
  7222. if index >= 1 {
  7223. lastStockFlow, _ := service.GetLastOverCount(list[index-1].ID)
  7224. count = lastStockFlow.FlushOverCount - list[index].Count
  7225. service.UpdateOverCount(list[index].ID, count)
  7226. }
  7227. }
  7228. if list[index].ConsumableType == 7 || list[index].ConsumableType == 4 || list[index].ConsumableType == 1 || list[index].ConsumableType == 10 || list[index].ConsumableType == 13 {
  7229. if index == 0 {
  7230. var count int64
  7231. count = list[index].FlushOverCount + list[index].Count
  7232. service.UpdateOverCount(list[index+1].ID, count)
  7233. }
  7234. if index >= 1 {
  7235. var count int64
  7236. lastStockFlow, _ := service.GetLastOverCount(list[index-1].ID)
  7237. count = lastStockFlow.FlushOverCount + list[index].Count
  7238. service.UpdateOverCount(list[index].ID, count)
  7239. }
  7240. }
  7241. }
  7242. }
  7243. func (this *StockManagerApiController) GetGoodPatientName() {
  7244. good_id, _ := this.GetInt64("good_id")
  7245. sys_record_time, _ := this.GetInt64("sys_record_time")
  7246. orgId := this.GetAdminUserInfo().CurrentOrgId
  7247. projectList, _ := service.GetGoodProjectList(good_id, sys_record_time, orgId)
  7248. outList, _ := service.GetWarehouseOutListBySysrecordTime(good_id, sys_record_time, orgId)
  7249. this.ServeSuccessJSON(map[string]interface{}{
  7250. "projectList": projectList,
  7251. "outList": outList,
  7252. })
  7253. }
  7254. func (this *StockManagerApiController) UpdateBaseDrugListByUserOrgID() {
  7255. //orgId := this.GetAdminUserInfo().CurrentOrgId
  7256. //list, _ := service.GetAllBaseDrugList(orgId)
  7257. //
  7258. //for _, item := range list {
  7259. // var sum_in_count int64
  7260. // var sum_out_count int64
  7261. // var flush_out_count int64
  7262. // //var str = ""
  7263. // //str = item.Dose + item.DoseUnit + "*" + strconv.FormatInt(item.MinNumber, 10) + item.MinUnit + "/" + item.MaxUnit
  7264. // //service.UpdateBaseDrugById(item.ID, str)
  7265. // //
  7266. // //drug_dosage_form_str := service.GetDosageFormListById(item.DrugDosageForm, orgId)
  7267. // //service.UpdateDosageFormListById(drug_dosage_form_str, item.ID)
  7268. //
  7269. // warehouseinfo, _ := service.GetDrugWarehouseInfoByItemId(item.ID)
  7270. // if len(warehouseinfo) > 0 {
  7271. // for _, it := range warehouseinfo {
  7272. // if item.MaxUnit == it.MaxUnit && item.MaxUnit != item.MinUnit {
  7273. // it.WarehousingCount = it.WarehousingCount * item.MinNumber
  7274. // }
  7275. //
  7276. // if item.MaxUnit == it.MinUnit && item.MaxUnit != item.MinUnit {
  7277. // it.WarehousingCount = it.WarehousingCount
  7278. // }
  7279. //
  7280. // if item.MaxUnit == it.MinUnit && item.MaxUnit == item.MinUnit {
  7281. // it.WarehousingCount = it.WarehousingCount
  7282. // }
  7283. //
  7284. // sum_in_count += it.WarehousingCount
  7285. // }
  7286. //
  7287. // }
  7288. // //
  7289. // outList, _ := service.GetDrugWarehosueOutInfoByItemId(item.ID)
  7290. // if len(outList) > 0 {
  7291. // for _, it := range outList {
  7292. // if item.MaxUnit == it.CountUnit && item.MaxUnit != item.MinUnit {
  7293. // it.Count = it.Count * item.MinNumber
  7294. // }
  7295. //
  7296. // if item.MaxUnit == it.CountUnit && item.MaxUnit != item.MinUnit {
  7297. // it.Count = it.Count
  7298. // }
  7299. //
  7300. // if item.MaxUnit == it.CountUnit && item.MaxUnit == item.MinUnit {
  7301. // it.Count = it.Count
  7302. // }
  7303. //
  7304. // sum_out_count += it.Count
  7305. // }
  7306. // }
  7307. //
  7308. // flush_out_count = sum_in_count - sum_out_count
  7309. // fmt.Println("sum_in_count+++++++++++++", sum_in_count)
  7310. // fmt.Println("sum_out_count++++++++++++++", sum_out_count)
  7311. // fmt.Println("flushi_out_count===========", flush_out_count)
  7312. //
  7313. // service.UpdateBaseDrugByIdCountTwo(item.ID, flush_out_count)
  7314. //}
  7315. //info, _ := service.GetDrugAllInfo(orgId)
  7316. //info, _ := service.GetDrugOutAllInfo(orgId)
  7317. //
  7318. //for _, item := range info {
  7319. //
  7320. // //dealer, _ := service.GetDealerById(item.Dealer)
  7321. //
  7322. // manufacturer, _ := service.GetManufactureById(item.Manufacturer)
  7323. //
  7324. // service.UpdateDealerManufacturerOne(item.ID, manufacturer.ManufacturerName)
  7325. //}
  7326. drugList, _ := service.GetAllBaseDrugListTwenty(10644)
  7327. for _, item := range drugList {
  7328. var drug_spec = item.Dose + item.DoseUnit + "*" + strconv.FormatInt(item.MinNumber, 10) + item.MinUnit + "/" + item.MaxUnit
  7329. service.UpdateBaseDrugList(item.ID, drug_spec)
  7330. }
  7331. }
  7332. func (this *StockManagerApiController) UpdateGoodInfoByUserOrgId() {
  7333. //orgId := this.GetAdminUserInfo().CurrentOrgId
  7334. //info, _ := service.GetAllWareHouseOutByUserOrg(10633)
  7335. //
  7336. //if len(info) > 0 {
  7337. // for _, item := range info {
  7338. //
  7339. // //dealer, _ := service.GetDealerById(item.Dealer)
  7340. //
  7341. // //manufacturer, _ := service.GetManufactureById(item.Manufacturer)
  7342. //
  7343. // //service.UpdateGoodInfoByUserOrgIdTwo(item.ID, dealer.DealerName)
  7344. // }
  7345. //}
  7346. goodList, _ := service.GetAllGoodList(10633)
  7347. for _, item := range goodList {
  7348. service.UpdateStockFlowByList(item.ID, item.PackingPrice)
  7349. //service.UpdateWarehouseOutInfoByPrice(item.ID, item.PackingPrice)
  7350. //outList, _ := service.GetWarehosueOutInfoByPrice(item.ID, 10633)
  7351. //
  7352. //for _, it := range outList {
  7353. // //service.UpdateWarehouseOut(it.ID, item.PackingPrice)
  7354. //
  7355. // service.UpdateStockFlowByList(it.GoodId, item.PackingPrice)
  7356. //}
  7357. //good_type_name := service.GetAllGoodTypeName(item.GoodTypeId, orgId)
  7358. //
  7359. //service.UpdateGoodTypeName(item.ID, good_type_name)
  7360. }
  7361. //
  7362. //for _, item := range goodList {
  7363. //
  7364. // var sum_in_count int64
  7365. // var sum_out_count int64
  7366. // var flush_out_count int64
  7367. // infor, _ := service.GetAllWarehouseSumInCount(item.ID)
  7368. //
  7369. // for _, item := range infor {
  7370. // sum_in_count += item.WarehousingCount
  7371. // }
  7372. //
  7373. // outInfo, _ := service.GetAllWarehouseSumOutCount(item.ID)
  7374. //
  7375. // for _, item := range outInfo {
  7376. // sum_out_count += item.Count
  7377. // }
  7378. //
  7379. // flush_out_count = sum_in_count - sum_out_count
  7380. //
  7381. // service.UpdateGoodInfoByIdOne(item.ID, flush_out_count)
  7382. //}
  7383. }
  7384. func (this *StockManagerApiController) GetGoodStockInventoryList() {
  7385. keyword := this.GetString("keyword")
  7386. limit, _ := this.GetInt64("limit")
  7387. page, _ := this.GetInt64("page")
  7388. storehouse_id, _ := this.GetInt64("storehouse_id")
  7389. start_time := this.GetString("start_time")
  7390. end_time := this.GetString("end_time")
  7391. orgId := this.GetAdminUserInfo().CurrentOrgId
  7392. appId := this.GetAdminUserInfo().CurrentAppId
  7393. timeLayout := "2006-01-02"
  7394. loc, _ := time.LoadLocation("Local")
  7395. var startTime int64
  7396. if len(start_time) > 0 {
  7397. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7398. if err != nil {
  7399. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7400. return
  7401. }
  7402. startTime = theTime.Unix()
  7403. }
  7404. var endTime int64
  7405. if len(end_time) > 0 {
  7406. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7407. if err != nil {
  7408. utils.ErrorLog(err.Error())
  7409. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7410. return
  7411. }
  7412. endTime = theTime.Unix()
  7413. }
  7414. list, total, _ := service.GetGoodStockInventoryList(keyword, limit, page, storehouse_id, startTime, endTime, orgId)
  7415. doclist, _ := service.GetAllDoctorListSix(orgId, appId)
  7416. storeHouseList, _ := service.GetAllStoreHouseList(orgId)
  7417. this.ServeSuccessJSON(map[string]interface{}{
  7418. "list": list,
  7419. "total": total,
  7420. "storeHouseList": storeHouseList,
  7421. "doclist": doclist,
  7422. })
  7423. }
  7424. func (this *StockManagerApiController) GetStockInventoryPrintList() {
  7425. storehouse_id, _ := this.GetInt64("storehouse_id")
  7426. keyword := this.GetString("keyword")
  7427. limit, _ := this.GetInt64("limit")
  7428. page, _ := this.GetInt64("page")
  7429. ids := this.GetString("ids")
  7430. p_ids_arr := strings.Split(ids, ",")
  7431. orgId := this.GetAdminUserInfo().CurrentOrgId
  7432. appId := this.GetAdminUserInfo().CurrentAppId
  7433. list, total, _ := service.GetStockInventoryPrintList(storehouse_id, keyword, limit, page, p_ids_arr, orgId)
  7434. doclist, _ := service.GetAllDoctorListSix(orgId, appId)
  7435. storeHouseList, _ := service.GetAllStoreHouseList(orgId)
  7436. this.ServeSuccessJSON(map[string]interface{}{
  7437. "list": list,
  7438. "total": total,
  7439. "storeHouseList": storeHouseList,
  7440. "doclist": doclist,
  7441. })
  7442. }
  7443. func (this *StockManagerApiController) GetStockInventoryModePrintList() {
  7444. orgId := this.GetAdminUserInfo().CurrentOrgId
  7445. start_time := this.GetString("start_time")
  7446. end_time := this.GetString("end_time")
  7447. timeLayout := "2006-01-02"
  7448. loc, _ := time.LoadLocation("Local")
  7449. var startTime int64
  7450. if len(start_time) > 0 {
  7451. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7452. if err != nil {
  7453. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7454. return
  7455. }
  7456. startTime = theTime.Unix()
  7457. }
  7458. var endTime int64
  7459. if len(end_time) > 0 {
  7460. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7461. if err != nil {
  7462. utils.ErrorLog(err.Error())
  7463. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7464. return
  7465. }
  7466. endTime = theTime.Unix()
  7467. }
  7468. goodInfo, _ := service.FindAllGoodInfoThree(orgId)
  7469. //获取所有入库数量
  7470. list, _ := service.GetInventoryExportList(orgId)
  7471. infoList, _ := service.GetGoodWarehouseInfoList(startTime, endTime, orgId)
  7472. outinfo, _ := service.GetGoodWarhouseOutList(startTime, endTime, orgId)
  7473. //获取盘盈的数据
  7474. flowProList, _ := service.GetGoodStockFlowProList(startTime, endTime, orgId)
  7475. //获取盘亏的数据
  7476. flowNoProList, _ := service.GetGoodStockFlowNoProList(startTime, endTime, orgId)
  7477. //获取盘点退库
  7478. CancelFlowList, _ := service.GetCancelStockFlowList(startTime, endTime, orgId)
  7479. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  7480. //获取期初结余数量
  7481. warehouseinfo, _ := service.GetLastMonthCount(startTime, orgId)
  7482. //期出结余出库数量
  7483. warehouseOutInfo, _ := service.GetLastMonthOverCount(startTime, orgId)
  7484. cancelInfo, _ := service.GetLastCancelMonthCount(startTime, orgId)
  7485. this.ServeSuccessJSON(map[string]interface{}{
  7486. "list": list,
  7487. "infoList": infoList,
  7488. "outinfo": outinfo,
  7489. "flowProList": flowProList,
  7490. "flowNoProList": flowNoProList,
  7491. "manufacturerList": manufacturerList,
  7492. "goodInfo": goodInfo,
  7493. "warehouseinfo": warehouseinfo,
  7494. "warehouseOutInfo": warehouseOutInfo,
  7495. "cancelInfo": cancelInfo,
  7496. "CancelFlowList": CancelFlowList,
  7497. })
  7498. }