stock_in_api_controller.go 264KB

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