stock_in_api_controller.go 212KB

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