stock_in_api_controller.go 271KB

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