stock_in_api_controller.go 259KB

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