stock_in_api_controller.go 262KB

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