stock_in_api_controller.go 210KB

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