stock_in_api_controller.go 276KB

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