stock_in_api_controller.go 273KB

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