stock_in_api_controller.go 212KB

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