stock_in_api_controller.go 265KB

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