stock_in_api_controller.go 272KB

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