stock_in_api_controller.go 238KB

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