stock_in_api_controller.go 256KB

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