stock_in_api_controller.go 262KB

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