stock_in_api_controller.go 255KB

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