stock_in_api_controller.go 273KB

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