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