stock_in_api_controller.go 211KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499
  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. }
  110. func (c *StockManagerApiController) CreateWarehouse() {
  111. warehousing_time := c.GetString("warehousing_time")
  112. types, _ := c.GetInt64("type", 0)
  113. ctime := time.Now().Unix()
  114. adminUserInfo := c.GetAdminUserInfo()
  115. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  116. if parseDateErr != nil {
  117. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  119. return
  120. }
  121. timeStr := time.Now().Format("2006-01-02")
  122. timeArr := strings.Split(timeStr, "-")
  123. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  124. total = total + 1
  125. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  126. operation_time := time.Now().Unix()
  127. creater := adminUserInfo.AdminUser.Id
  128. warehousing := models.Warehousing{
  129. WarehousingOrder: warehousing_order,
  130. OperationTime: operation_time,
  131. OrgId: adminUserInfo.CurrentOrgId,
  132. Creater: creater,
  133. Ctime: ctime,
  134. Status: 1,
  135. WarehousingTime: warehousingDate.Unix(),
  136. Type: types,
  137. }
  138. service.AddSigleWarehouse(&warehousing)
  139. dataBody := make(map[string]interface{}, 0)
  140. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  141. if err != nil {
  142. utils.ErrorLog(err.Error())
  143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  144. return
  145. }
  146. var warehousingInfo []*models.WarehousingInfo
  147. var stockFlow []*models.VmStockFlow
  148. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  149. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  150. if len(thisStockIn) > 0 {
  151. for _, item := range thisStockIn {
  152. items := item.(map[string]interface{})
  153. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  154. utils.ErrorLog("good_id")
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  156. return
  157. }
  158. good_id := int64(items["good_id"].(float64))
  159. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  160. utils.ErrorLog("good_type_id")
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  162. return
  163. }
  164. good_type_id := int64(items["good_type_id"].(float64))
  165. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  166. utils.ErrorLog("warehousing_count")
  167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. return
  169. }
  170. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  171. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  172. utils.ErrorLog("price")
  173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. return
  175. }
  176. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  177. total := float64(warehousing_count) * price
  178. var productDates int64
  179. var expiryDates int64
  180. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  181. expiryDates = 0
  182. } else {
  183. if len(items["expiry_date"].(string)) == 0 {
  184. expiryDates = 0
  185. } else {
  186. expiryDate, _ := items["expiry_date"].(string)
  187. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  188. expiryDates = expiry_date.Unix()
  189. }
  190. }
  191. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  192. productDates = 0
  193. } else {
  194. if len(items["product_date"].(string)) == 0 {
  195. productDates = 0
  196. } else {
  197. productDate, _ := items["product_date"].(string)
  198. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  199. productDates = product_date.Unix()
  200. }
  201. }
  202. number, _ := items["number"].(string)
  203. remark, _ := items["remark"].(string)
  204. manufacturer := int64(items["manufacturer"].(float64))
  205. dealer := int64(items["dealer"].(float64))
  206. license_number, _ := items["license_number"].(string)
  207. //入库单表格
  208. warehouseInfo := &models.WarehousingInfo{
  209. WarehousingOrder: warehousing.WarehousingOrder,
  210. WarehousingId: warehousing.ID,
  211. GoodId: good_id,
  212. Number: number,
  213. GoodTypeId: good_type_id,
  214. ProductDate: productDates,
  215. ExpiryDate: expiryDates,
  216. WarehousingCount: warehousing_count,
  217. Price: price,
  218. TotalPrice: total,
  219. Status: 1,
  220. Ctime: ctime,
  221. Remark: remark,
  222. OrgId: adminUserInfo.CurrentOrgId,
  223. Type: types,
  224. Manufacturer: manufacturer,
  225. StockCount: warehousing_count,
  226. Dealer: dealer,
  227. LicenseNumber: license_number,
  228. }
  229. warehousingInfo = append(warehousingInfo, warehouseInfo)
  230. flow := &models.VmStockFlow{
  231. WarehousingOrder: warehousing.WarehousingOrder,
  232. WarehousingId: warehousing.ID,
  233. GoodId: good_id,
  234. Number: number,
  235. ProductDate: productDates,
  236. ExpireDate: expiryDates,
  237. Count: warehousing_count,
  238. Price: price,
  239. Status: 1,
  240. Ctime: ctime,
  241. UserOrgId: adminUserInfo.CurrentOrgId,
  242. Manufacturer: manufacturer,
  243. Dealer: dealer,
  244. LicenseNumber: license_number,
  245. IsEdit: 1,
  246. Creator: adminUserInfo.AdminUser.Id,
  247. SystemTime: operation_time,
  248. ConsumableType: 1,
  249. WarehousingDetailId: warehouseInfo.ID,
  250. }
  251. stockFlow = append(stockFlow, flow)
  252. }
  253. }
  254. }
  255. //入库单创建成功
  256. errs := service.CreateWarehousingInfo(warehousingInfo)
  257. //创建入库单流水
  258. service.CreateStockFlow(stockFlow)
  259. info, _ := service.FindLastWarehousingInfo(warehousing.WarehousingOrder)
  260. for _, item := range warehousingInfo {
  261. goodInfo, _ := service.GetGoodInformationByGoodId(item.GoodId)
  262. str := strconv.FormatInt(item.WarehousingCount, 10)
  263. minFloat, _ := strconv.ParseFloat(str, 64)
  264. good := models.GoodInfo{
  265. Total: minFloat + goodInfo.Total,
  266. }
  267. //更该库存
  268. parseDateErr := service.UpdateGoodInfoList(good, goodInfo.ID)
  269. break
  270. fmt.Println(parseDateErr)
  271. }
  272. if errs != nil {
  273. utils.ErrorLog(errs.Error())
  274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  275. return
  276. }
  277. c.ServeSuccessJSON(map[string]interface{}{
  278. "msg": "入库成功",
  279. "warehousing_order": warehousing_order,
  280. "info": info,
  281. })
  282. }
  283. func (c *StockManagerApiController) GetWarehouseList() {
  284. page, _ := c.GetInt64("page", -1)
  285. limit, _ := c.GetInt64("limit", -1)
  286. start_time := c.GetString("start_time")
  287. end_time := c.GetString("end_time")
  288. types, _ := c.GetInt64("type", 0)
  289. keywords := c.GetString("keywords")
  290. timeLayout := "2006-01-02"
  291. loc, _ := time.LoadLocation("Local")
  292. var startTime int64
  293. if len(start_time) > 0 {
  294. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  295. if err != nil {
  296. fmt.Println(err)
  297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  298. return
  299. }
  300. startTime = theTime.Unix()
  301. }
  302. var endTime int64
  303. if len(end_time) > 0 {
  304. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  305. if err != nil {
  306. utils.ErrorLog(err.Error())
  307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  308. return
  309. }
  310. endTime = theTime.Unix()
  311. }
  312. adminUserInfo := c.GetAdminUserInfo()
  313. var ids []int64
  314. var goodids []int64
  315. //查询商品名称
  316. if len(keywords) > 0 {
  317. //查询商品名称
  318. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  319. for _, item := range list {
  320. goodids = append(goodids, item.ID)
  321. //入库详情但里面查询
  322. }
  323. if len(goodids) > 0 {
  324. info, _ := service.GetWarehoureOrderInfoByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
  325. for _, it := range info {
  326. ids = append(ids, it.WarehousingId)
  327. }
  328. }
  329. }
  330. warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  331. if err == nil {
  332. c.ServeSuccessJSON(map[string]interface{}{
  333. "list": warehouseList,
  334. "total": total,
  335. })
  336. } else {
  337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  338. }
  339. }
  340. func (c *StockManagerApiController) GetWarehouseInfoList() {
  341. id := c.GetString("id")
  342. idArray := strings.Split(id, ",")
  343. warehousing, err := service.FindWarehousingByIdOne(idArray)
  344. if err != nil {
  345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  346. return
  347. }
  348. var ids []int64
  349. for _, item := range warehousing {
  350. ids = append(ids, item.ID)
  351. }
  352. warehousingInfo, err := service.FindWarehousingInfoByIdOne(ids)
  353. if err == nil {
  354. c.ServeSuccessJSON(map[string]interface{}{
  355. "info": warehousingInfo,
  356. "warehousing": warehousing,
  357. })
  358. } else {
  359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  360. }
  361. }
  362. func (c *StockManagerApiController) EditWarehouse() {
  363. warehousing_time := c.GetString("warehousing_time")
  364. id, _ := c.GetInt64("id", 0)
  365. types, _ := c.GetInt64("type", 0)
  366. if id == 0 {
  367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  368. return
  369. }
  370. ctime := time.Now().Unix()
  371. mtime := time.Now().Unix()
  372. adminUserInfo := c.GetAdminUserInfo()
  373. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  374. if parseDateErr != nil {
  375. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  377. return
  378. }
  379. warehouse, _ := service.FindWarehousingById(id)
  380. warehousing := models.Warehousing{
  381. WarehousingOrder: warehouse.WarehousingOrder,
  382. OrgId: adminUserInfo.CurrentOrgId,
  383. Modifier: adminUserInfo.AdminUser.Id,
  384. Mtime: mtime,
  385. Status: 1,
  386. WarehousingTime: warehousingDate.Unix(),
  387. Type: warehouse.Type,
  388. }
  389. service.EditWarehousing(warehousing)
  390. dataBody := make(map[string]interface{}, 0)
  391. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  392. if err != nil {
  393. utils.ErrorLog(err.Error())
  394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  395. return
  396. }
  397. var warehousingInfo []*models.WarehousingInfo
  398. var upDateWarehousingInfo []*models.WarehousingInfo
  399. var stockFlow []*models.VmStockFlow
  400. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  401. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  402. if len(thisStockIn) > 0 {
  403. for _, item := range thisStockIn {
  404. items := item.(map[string]interface{})
  405. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  406. utils.ErrorLog("good_id")
  407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  408. return
  409. }
  410. good_id := int64(items["good_id"].(float64))
  411. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  412. utils.ErrorLog("good_type_id")
  413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  414. return
  415. }
  416. good_type_id := int64(items["good_type_id"].(float64))
  417. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  418. utils.ErrorLog("warehousing_count")
  419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  420. return
  421. }
  422. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  423. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  424. utils.ErrorLog("price")
  425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  426. return
  427. }
  428. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  429. total := float64(warehousing_count) * price
  430. var productDates int64
  431. var expiryDates int64
  432. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  433. expiryDates = 0
  434. } else {
  435. if len(items["expiry_date"].(string)) == 0 {
  436. expiryDates = 0
  437. } else {
  438. expiryDate, _ := items["expiry_date"].(string)
  439. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  440. expiryDates = expiry_date.Unix()
  441. }
  442. }
  443. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  444. productDates = 0
  445. } else {
  446. if len(items["product_date"].(string)) == 0 {
  447. productDates = 0
  448. } else {
  449. productDate, _ := items["product_date"].(string)
  450. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  451. productDates = product_date.Unix()
  452. }
  453. }
  454. number, _ := items["number"].(string)
  455. remark, _ := items["remark"].(string)
  456. manufacturer := int64(items["manufacturer"].(float64))
  457. dealer := int64(items["dealer"].(float64))
  458. license_number, _ := items["license_number"].(string)
  459. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  460. utils.ErrorLog("id")
  461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  462. return
  463. }
  464. id := int64(items["id"].(float64))
  465. if id == 0 {
  466. warehouseInfo := &models.WarehousingInfo{
  467. WarehousingOrder: warehouse.WarehousingOrder,
  468. WarehousingId: warehouse.ID,
  469. GoodId: good_id,
  470. Number: number,
  471. GoodTypeId: good_type_id,
  472. ProductDate: productDates,
  473. ExpiryDate: expiryDates,
  474. WarehousingCount: warehousing_count,
  475. Price: price,
  476. TotalPrice: total,
  477. Status: 1,
  478. Ctime: ctime,
  479. Remark: remark,
  480. OrgId: adminUserInfo.CurrentOrgId,
  481. Type: types,
  482. Manufacturer: manufacturer,
  483. Dealer: dealer,
  484. StockCount: warehousing_count,
  485. LicenseNumber: license_number,
  486. }
  487. warehousingInfo = append(warehousingInfo, warehouseInfo)
  488. } else {
  489. warehouseInfo := &models.WarehousingInfo{
  490. ID: id,
  491. WarehousingOrder: warehouse.WarehousingOrder,
  492. WarehousingId: warehouse.ID,
  493. GoodId: good_id,
  494. Number: number,
  495. GoodTypeId: good_type_id,
  496. ProductDate: productDates,
  497. ExpiryDate: expiryDates,
  498. WarehousingCount: warehousing_count,
  499. Price: price,
  500. TotalPrice: total,
  501. Status: 1,
  502. Ctime: ctime,
  503. Remark: remark,
  504. OrgId: adminUserInfo.CurrentOrgId,
  505. Type: types,
  506. Manufacturer: manufacturer,
  507. Dealer: dealer,
  508. LicenseNumber: license_number,
  509. }
  510. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  511. flow := &models.VmStockFlow{
  512. WarehousingOrder: warehousing.WarehousingOrder,
  513. WarehousingId: id,
  514. GoodId: good_id,
  515. Number: number,
  516. ProductDate: productDates,
  517. ExpireDate: expiryDates,
  518. Count: warehousing_count,
  519. Price: price,
  520. Status: 1,
  521. Ctime: ctime,
  522. UserOrgId: adminUserInfo.CurrentOrgId,
  523. Manufacturer: manufacturer,
  524. Dealer: dealer,
  525. LicenseNumber: license_number,
  526. IsEdit: 2,
  527. Creator: adminUserInfo.AdminUser.Id,
  528. SystemTime: ctime,
  529. ConsumableType: 1,
  530. WarehousingDetailId: warehouseInfo.ID,
  531. }
  532. stockFlow = append(stockFlow, flow)
  533. }
  534. }
  535. }
  536. }
  537. var errs error
  538. if len(warehousingInfo) > 0 {
  539. errs = service.CreateWarehousingInfo(warehousingInfo)
  540. for _, its := range warehousingInfo {
  541. //查询
  542. info, _ := service.GetLastGoodWarehouseInfo(its.GoodId)
  543. flows := models.VmStockFlow{
  544. WarehousingOrder: info.WarehousingOrder,
  545. WarehousingId: info.ID,
  546. GoodId: info.GoodId,
  547. Number: info.Number,
  548. ProductDate: info.ProductDate,
  549. ExpireDate: info.ExpiryDate,
  550. Count: info.WarehousingCount,
  551. Price: info.Price,
  552. Status: 1,
  553. Ctime: ctime,
  554. UserOrgId: adminUserInfo.CurrentOrgId,
  555. Manufacturer: info.Manufacturer,
  556. Dealer: info.Dealer,
  557. LicenseNumber: info.LicenseNumber,
  558. IsEdit: 1,
  559. Creator: adminUserInfo.AdminUser.Id,
  560. SystemTime: ctime,
  561. ConsumableType: 1,
  562. WarehousingDetailId: info.ID,
  563. }
  564. _, errcodescode := service.GetGoodStockFlowInfo(info.ID, info.GoodId)
  565. if errcodescode == gorm.ErrRecordNotFound {
  566. service.CreateStockFlowOne(flows)
  567. }
  568. //改变库存
  569. good, _ := service.GetLastInfoMationById(info.GoodId)
  570. warhouseCount := strconv.FormatInt(info.WarehousingCount, 10)
  571. total, _ := strconv.ParseFloat(warhouseCount, 64)
  572. goodInfo := models.GoodInfo{
  573. Total: good.Total + total,
  574. }
  575. errcodescode = service.UpdateGoodInfoMation(info.GoodId, goodInfo)
  576. fmt.Println(errcodescode)
  577. }
  578. }
  579. if len(upDateWarehousingInfo) > 0 {
  580. for _, item := range upDateWarehousingInfo {
  581. var total int64
  582. //获取该批次该型号的库存
  583. info, _ := service.GetLastWarehousingByIdOne(item.ID, item.GoodId)
  584. //增加库存
  585. if item.WarehousingCount > info.WarehousingCount {
  586. total = item.WarehousingCount - info.WarehousingCount
  587. goodinfo := models.WarehousingInfo{
  588. WarehousingCount: item.WarehousingCount,
  589. StockCount: info.StockCount + total,
  590. }
  591. service.UpdateWarehouseInfoByGoodId(goodinfo, item.ID)
  592. flowStock := models.VmStockFlow{
  593. Count: item.WarehousingCount,
  594. }
  595. service.UpdatedStockFlowByGoodId(item.WarehousingId, item.GoodId, flowStock)
  596. //改变库存
  597. good, _ := service.GetLastInfoMationById(info.GoodId)
  598. warhouseCount := strconv.FormatInt(total, 10)
  599. all_total, _ := strconv.ParseFloat(warhouseCount, 64)
  600. goodInfo := models.GoodInfo{
  601. Total: good.Total + all_total,
  602. }
  603. service.UpdateGoodInfoMation(info.GoodId, goodInfo)
  604. }
  605. if item.WarehousingCount < info.WarehousingCount {
  606. total = info.WarehousingCount - item.WarehousingCount
  607. goodinfo := models.WarehousingInfo{
  608. WarehousingCount: item.WarehousingCount,
  609. StockCount: info.StockCount - total,
  610. }
  611. service.UpdateWarehouseInfoByGoodId(goodinfo, item.ID)
  612. //改变库存
  613. good, _ := service.GetLastInfoMationById(info.GoodId)
  614. warhouseCount := strconv.FormatInt(total, 10)
  615. all_total, _ := strconv.ParseFloat(warhouseCount, 64)
  616. goodInfo := models.GoodInfo{
  617. Total: good.Total - all_total,
  618. }
  619. service.UpdateGoodInfoMation(info.GoodId, goodInfo)
  620. }
  621. if item.WarehousingCount == info.WarehousingCount {
  622. goodinfo := models.WarehousingInfo{
  623. WarehousingCount: item.WarehousingCount,
  624. StockCount: info.StockCount,
  625. Price: item.Price,
  626. Manufacturer: item.Manufacturer,
  627. Number: item.Number,
  628. ProductDate: item.ProductDate,
  629. ExpiryDate: item.ExpiryDate,
  630. LicenseNumber: item.LicenseNumber,
  631. Dealer: item.Dealer,
  632. Remark: item.Remark,
  633. }
  634. service.UpdateWarehouseInfoByGoodIdOne(goodinfo, item.ID)
  635. }
  636. }
  637. }
  638. if len(stockFlow) > 0 {
  639. for _, item := range stockFlow {
  640. flow := models.VmStockFlow{
  641. Count: item.Count,
  642. }
  643. parseDateErr := service.UpdateStockFlow(flow, item.GoodId, item.WarehousingId)
  644. fmt.Println(parseDateErr)
  645. }
  646. }
  647. if errs != nil {
  648. utils.ErrorLog(errs.Error())
  649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  650. return
  651. }
  652. c.ServeSuccessJSON(map[string]interface{}{
  653. "msg": "编辑成功",
  654. })
  655. }
  656. func (c *StockManagerApiController) DeleteWarehouse() {
  657. ids := c.GetString("ids")
  658. if len(ids) == 0 {
  659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  660. return
  661. }
  662. idArray := strings.Split(ids, ",")
  663. err := service.DeleteWarehouse(idArray)
  664. if err != nil {
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  666. } else {
  667. c.ServeSuccessJSON(map[string]interface{}{
  668. "msg": "删除成功",
  669. })
  670. }
  671. }
  672. func (c *StockManagerApiController) DeleteWarehouseInfo() {
  673. id, _ := c.GetInt64("id", 0)
  674. if id == 0 {
  675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  676. return
  677. }
  678. err := service.UpDateWarehouseStatus(id)
  679. if err != nil {
  680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  681. } else {
  682. c.ServeSuccessJSON(map[string]interface{}{
  683. "msg": "删除成功",
  684. })
  685. }
  686. }
  687. func (c *StockManagerApiController) CreateSalesReturn() {
  688. dealer_id, _ := c.GetInt64("dealer_id", 0)
  689. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  690. sales_return_time := c.GetString("time")
  691. types, _ := c.GetInt64("type", 0)
  692. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  693. if parseDateErr != nil {
  694. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  696. return
  697. }
  698. adminUserInfo := c.GetAdminUserInfo()
  699. operation_time := time.Now().Unix()
  700. creater := adminUserInfo.AdminUser.Id
  701. ctime := time.Now().Unix()
  702. timeStr := time.Now().Format("2006-01-02")
  703. timeArr := strings.Split(timeStr, "-")
  704. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  705. total = total + 1
  706. orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  707. salesReturn := models.SalesReturn{
  708. OrderNumber: orderNumber,
  709. OperaTime: operation_time,
  710. OrgId: adminUserInfo.CurrentOrgId,
  711. Creater: creater,
  712. Ctime: ctime,
  713. Status: 1,
  714. ReturnTime: salesReturnDate.Unix(),
  715. Dealer: dealer_id,
  716. Manufacturer: manufacturer_id,
  717. Type: types,
  718. }
  719. service.AddSigleSalesReturn(&salesReturn)
  720. dataBody := make(map[string]interface{}, 0)
  721. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  722. if err != nil {
  723. utils.ErrorLog(err.Error())
  724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  725. return
  726. }
  727. var salesReturnInfos []*models.SalesReturnInfo
  728. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  729. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  730. if len(thisStockIn) > 0 {
  731. for _, item := range thisStockIn {
  732. items := item.(map[string]interface{})
  733. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  734. utils.ErrorLog("good_id")
  735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  736. return
  737. }
  738. good_id := int64(items["good_id"].(float64))
  739. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  740. utils.ErrorLog("good_type_id")
  741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  742. return
  743. }
  744. good_type_id := int64(items["good_type_id"].(float64))
  745. return_count, _ := items["return_count"].(string)
  746. if len(return_count) == 0 {
  747. utils.ErrorLog("len(return_count) == 0")
  748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  749. return
  750. }
  751. count, _ := strconv.ParseInt(return_count, 10, 64)
  752. price, _ := strconv.ParseFloat(items["price"].(string), 10)
  753. total := float64(count) * price
  754. salesReturnInfo := &models.SalesReturnInfo{
  755. OrderNumber: salesReturn.OrderNumber,
  756. SalesReturnId: salesReturn.ID,
  757. GoodId: good_id,
  758. GoodTypeId: good_type_id,
  759. Count: count,
  760. Price: price,
  761. Total: total,
  762. Status: 1,
  763. Ctime: ctime,
  764. OrgId: adminUserInfo.CurrentOrgId,
  765. Type: types,
  766. Manufacturer: manufacturer_id,
  767. Dealer: dealer_id,
  768. }
  769. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  770. }
  771. }
  772. }
  773. errs := service.CreateSalesReturnInfo(salesReturnInfos)
  774. if errs != nil {
  775. utils.ErrorLog(errs.Error())
  776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  777. return
  778. }
  779. c.ServeSuccessJSON(map[string]interface{}{
  780. "msg": "退货成功",
  781. })
  782. }
  783. func (c *StockManagerApiController) GetSalesReturnList() {
  784. page, _ := c.GetInt64("page", -1)
  785. limit, _ := c.GetInt64("limit", -1)
  786. start_time := c.GetString("start_time")
  787. end_time := c.GetString("end_time")
  788. types, _ := c.GetInt64("type", 0)
  789. keywords := c.GetString("keywords")
  790. timeLayout := "2006-01-02"
  791. loc, _ := time.LoadLocation("Local")
  792. var startTime int64
  793. if len(start_time) > 0 {
  794. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  795. if err != nil {
  796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  797. return
  798. }
  799. startTime = theTime.Unix()
  800. }
  801. var endTime int64
  802. if len(end_time) > 0 {
  803. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  804. if err != nil {
  805. utils.ErrorLog(err.Error())
  806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  807. return
  808. }
  809. endTime = theTime.Unix()
  810. }
  811. adminUserInfo := c.GetAdminUserInfo()
  812. returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  813. if err == nil {
  814. c.ServeSuccessJSON(map[string]interface{}{
  815. "list": returnList,
  816. "total": total,
  817. })
  818. } else {
  819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  820. }
  821. }
  822. func (this *StockManagerApiController) DeleteSalesReturn() {
  823. ids := this.GetString("ids")
  824. if len(ids) == 0 {
  825. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  826. return
  827. }
  828. idArray := strings.Split(ids, ",")
  829. err := service.DeleteSalesReturn(idArray)
  830. if err != nil {
  831. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  832. } else {
  833. this.ServeSuccessJSON(map[string]interface{}{
  834. "msg": "删除成功",
  835. })
  836. }
  837. }
  838. func (this *StockManagerApiController) DeleteSalesReturnInfo() {
  839. id, _ := this.GetInt64("id", 0)
  840. fmt.Println(id)
  841. if id == 0 {
  842. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  843. return
  844. }
  845. err := service.UpDateSaleReturnStatus(id)
  846. if err != nil {
  847. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  848. } else {
  849. this.ServeSuccessJSON(map[string]interface{}{
  850. "msg": "删除成功",
  851. })
  852. }
  853. }
  854. func (this *StockManagerApiController) GetSalesReturnInfoList() {
  855. id, _ := this.GetInt64("id", 0)
  856. list, _ := service.FindAllSalesReturnInfoById(id)
  857. salesReturn, _ := service.FindAllSalesReturnById(id)
  858. this.ServeSuccessJSON(map[string]interface{}{
  859. "list": list,
  860. "salesReturn": salesReturn,
  861. })
  862. }
  863. func (c *StockManagerApiController) EditReturnInfo() {
  864. return_time := c.GetString("return_time")
  865. id, _ := c.GetInt64("id", 0)
  866. types, _ := c.GetInt64("type", 0)
  867. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  868. dealer_id, _ := c.GetInt64("dealer_id", 0)
  869. if id == 0 {
  870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  871. return
  872. }
  873. ctime := time.Now().Unix()
  874. mtime := time.Now().Unix()
  875. adminUserInfo := c.GetAdminUserInfo()
  876. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  877. if parseDateErr != nil {
  878. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  880. return
  881. }
  882. salesReturns, _ := service.FindSalesReturnById(id)
  883. sales := models.SalesReturn{
  884. ID: salesReturns.ID,
  885. Mtime: mtime,
  886. ReturnTime: returnDate.Unix(),
  887. Manufacturer: manufacturer_id,
  888. Dealer: dealer_id,
  889. }
  890. service.EditSaleReturn(sales)
  891. dataBody := make(map[string]interface{}, 0)
  892. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  893. if err != nil {
  894. utils.ErrorLog(err.Error())
  895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  896. return
  897. }
  898. var returnInfos []*models.SalesReturnInfo
  899. var upDateReturnInfos []*models.SalesReturnInfo
  900. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  901. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  902. if len(thisStockIn) > 0 {
  903. for _, item := range thisStockIn {
  904. items := item.(map[string]interface{})
  905. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  906. utils.ErrorLog("good_id")
  907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  908. return
  909. }
  910. good_id := int64(items["good_id"].(float64))
  911. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  912. utils.ErrorLog("good_type_id")
  913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  914. return
  915. }
  916. good_type_id := int64(items["good_type_id"].(float64))
  917. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  918. utils.ErrorLog("count")
  919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  920. return
  921. }
  922. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  923. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  924. utils.ErrorLog("id")
  925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  926. return
  927. }
  928. id := int64(items["id"].(float64))
  929. if id == 0 {
  930. returnInfo := &models.SalesReturnInfo{
  931. GoodId: good_id,
  932. GoodTypeId: good_type_id,
  933. Count: count,
  934. Status: 1,
  935. Ctime: ctime,
  936. OrgId: adminUserInfo.CurrentOrgId,
  937. OrderNumber: sales.OrderNumber,
  938. SalesReturnId: sales.ID,
  939. Mtime: time.Now().Unix(),
  940. Type: types,
  941. Manufacturer: manufacturer_id,
  942. Dealer: dealer_id,
  943. }
  944. returnInfos = append(returnInfos, returnInfo)
  945. } else {
  946. returnInfo := &models.SalesReturnInfo{
  947. ID: id,
  948. GoodId: good_id,
  949. GoodTypeId: good_type_id,
  950. Count: count,
  951. Status: 1,
  952. Ctime: ctime,
  953. OrgId: adminUserInfo.CurrentOrgId,
  954. OrderNumber: sales.OrderNumber,
  955. SalesReturnId: sales.ID,
  956. Mtime: time.Now().Unix(),
  957. Type: types,
  958. Manufacturer: manufacturer_id,
  959. Dealer: dealer_id,
  960. }
  961. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  962. }
  963. }
  964. }
  965. }
  966. var errs error
  967. if len(returnInfos) > 0 {
  968. errs = service.CreateSalesReturnInfo(returnInfos)
  969. }
  970. if len(upDateReturnInfos) > 0 {
  971. for _, item := range upDateReturnInfos {
  972. errs = service.UpDateSalesReturnInfo(item)
  973. }
  974. }
  975. if errs != nil {
  976. utils.ErrorLog(errs.Error())
  977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  978. return
  979. }
  980. c.ServeSuccessJSON(map[string]interface{}{
  981. "msg": "编辑成功",
  982. })
  983. }
  984. func (c *StockManagerApiController) CreateWarehouseOut() {
  985. types, _ := c.GetInt64("type", 0)
  986. ctime := time.Now().Unix()
  987. adminUserInfo := c.GetAdminUserInfo()
  988. warehousing_out_time := c.GetString("warehousing_out_time")
  989. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  990. if parseDateErr != nil {
  991. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  993. return
  994. }
  995. timeStr := time.Now().Format("2006-01-02")
  996. timeArr := strings.Split(timeStr, "-")
  997. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  998. total = total + 1
  999. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1000. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1001. number = number + total
  1002. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1003. operation_time := time.Now().Unix()
  1004. creater := adminUserInfo.AdminUser.Id
  1005. warehouseOut := models.WarehouseOut{
  1006. WarehouseOutOrderNumber: warehousing_out_order,
  1007. OperationTime: operation_time,
  1008. OrgId: adminUserInfo.CurrentOrgId,
  1009. Creater: creater,
  1010. Ctime: ctime,
  1011. Status: 1,
  1012. WarehouseOutTime: warehousingOutDate.Unix(),
  1013. Type: types,
  1014. }
  1015. dataBody := make(map[string]interface{}, 0)
  1016. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1017. if err != nil {
  1018. utils.ErrorLog(err.Error())
  1019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1020. return
  1021. }
  1022. var warehousingOutInfo []*models.WarehouseOutInfo
  1023. var beforePrepares []*models.DialysisBeforePrepareGoods
  1024. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  1025. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1026. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  1027. if len(thisStockIn) > 0 {
  1028. for _, item := range thisStockIn {
  1029. items := item.(map[string]interface{})
  1030. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1031. utils.ErrorLog("good_id")
  1032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1033. return
  1034. }
  1035. good_id := int64(items["good_id"].(float64))
  1036. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1037. utils.ErrorLog("good_type_id")
  1038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1039. return
  1040. }
  1041. good_type_id := int64(items["good_type_id"].(float64))
  1042. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1043. utils.ErrorLog("count")
  1044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1045. return
  1046. }
  1047. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1048. utils.ErrorLog("price")
  1049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1050. return
  1051. }
  1052. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1053. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1054. total := float64(count) * price
  1055. remark := items["remark"].(string)
  1056. manufacturer := int64(items["manufacturer"].(float64))
  1057. dealer := int64(items["dealer"].(float64))
  1058. number := items["number"].(string)
  1059. expiry_date := items["expiry_date"].(string)
  1060. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1061. timeLayout := "2006-01-02"
  1062. loc, _ := time.LoadLocation("Local")
  1063. var expiryDate int64
  1064. if len(expiry_date) > 0 {
  1065. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1066. if err != nil {
  1067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1068. return
  1069. }
  1070. expiryDate = theTime.Unix()
  1071. }
  1072. product_date := items["product_date"].(string)
  1073. var productDate int64
  1074. if len(product_date) > 0 {
  1075. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1076. if err != nil {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. productDate = theTime.Unix()
  1081. }
  1082. license_number := items["license_number"].(string)
  1083. warehouseOutInfo := &models.WarehouseOutInfo{
  1084. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1085. WarehouseOutId: warehouseOut.ID,
  1086. GoodId: good_id,
  1087. GoodTypeId: good_type_id,
  1088. Count: count,
  1089. Price: price,
  1090. TotalPrice: total,
  1091. Status: 1,
  1092. Ctime: ctime,
  1093. Remark: remark,
  1094. OrgId: adminUserInfo.CurrentOrgId,
  1095. Type: types,
  1096. Manufacturer: manufacturer,
  1097. Number: number,
  1098. ExpiryDate: expiryDate,
  1099. ProductDate: productDate,
  1100. Dealer: dealer,
  1101. LicenseNumber: license_number,
  1102. WarehouseInfotId: warehouse_info_id,
  1103. }
  1104. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1105. prepareGoods := &models.DialysisBeforePrepareGoods{
  1106. GoodTypeId: good_type_id,
  1107. GoodId: good_id,
  1108. Count: count,
  1109. }
  1110. beforePrepares = append(beforePrepares, prepareGoods)
  1111. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  1112. GoodTypeId: good_type_id,
  1113. GoodId: good_id,
  1114. Count: count,
  1115. }
  1116. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  1117. }
  1118. }
  1119. }
  1120. //出库逻辑
  1121. for _, item := range warehousingOutInfo {
  1122. // 查询该耗材是否有库存
  1123. warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId)
  1124. fmt.Println("hhh2333223223", item.GoodId, item.Count, warehouseOne.StockCount)
  1125. // 如果出库数量大于该批次剩余库存数量
  1126. if item.Count > warehouseOne.StockCount {
  1127. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  1128. c.ServeSuccessJSON(map[string]interface{}{
  1129. "msg": "1",
  1130. "good_name": goodObj.GoodName,
  1131. "specification_name": goodObj.SpecificationName,
  1132. })
  1133. return
  1134. }
  1135. }
  1136. for _, it := range warehousingOutInfo {
  1137. //查询是否生成出库单
  1138. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  1139. if errcodes == gorm.ErrRecordNotFound {
  1140. service.AddSigleWarehouseOut(&warehouseOut)
  1141. }
  1142. //出库逻辑
  1143. parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), it, &warehouseOut, it.Count, creater)
  1144. if parseDateErr != nil {
  1145. utils.ErrorLog(parseDateErr.Error())
  1146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1147. return
  1148. }
  1149. c.ServeSuccessJSON(map[string]interface{}{
  1150. "msg": "2",
  1151. "good_name": "",
  1152. "specification_name": "",
  1153. })
  1154. }
  1155. }
  1156. func (c *StockManagerApiController) GetWarehouseOutList() {
  1157. page, _ := c.GetInt64("page", -1)
  1158. limit, _ := c.GetInt64("limit", -1)
  1159. start_time := c.GetString("start_time")
  1160. end_time := c.GetString("end_time")
  1161. types, _ := c.GetInt64("type", 0)
  1162. keywords := c.GetString("keywords")
  1163. timeLayout := "2006-01-02"
  1164. loc, _ := time.LoadLocation("Local")
  1165. var startTime int64
  1166. if len(start_time) > 0 {
  1167. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1168. if err != nil {
  1169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1170. return
  1171. }
  1172. startTime = theTime.Unix()
  1173. }
  1174. var endTime int64
  1175. if len(end_time) > 0 {
  1176. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1177. if err != nil {
  1178. utils.ErrorLog(err.Error())
  1179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1180. return
  1181. }
  1182. endTime = theTime.Unix()
  1183. }
  1184. adminUserInfo := c.GetAdminUserInfo()
  1185. var ids []int64
  1186. var goodids []int64
  1187. if len(keywords) > 0 {
  1188. //查询商品名称
  1189. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  1190. for _, item := range list {
  1191. goodids = append(goodids, item.ID)
  1192. }
  1193. if len(goodids) > 0 {
  1194. //出库详情但里面查询
  1195. info, _ := service.GetWarehoureOrderOutByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
  1196. for _, it := range info {
  1197. ids = append(ids, it.WarehouseOutId)
  1198. }
  1199. }
  1200. }
  1201. warehouseOutList, total, err := service.FindAllWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  1202. fmt.Println(err)
  1203. if err == nil {
  1204. c.ServeSuccessJSON(map[string]interface{}{
  1205. "list": warehouseOutList,
  1206. "total": total,
  1207. })
  1208. } else {
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1210. }
  1211. }
  1212. func (c *StockManagerApiController) DeleteWarehouseOut() {
  1213. ids := c.GetString("ids")
  1214. if len(ids) == 0 {
  1215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1216. return
  1217. }
  1218. idArray := strings.Split(ids, ",")
  1219. err := service.DeleteWarehouseOut(idArray)
  1220. if err != nil {
  1221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1222. } else {
  1223. c.ServeSuccessJSON(map[string]interface{}{
  1224. "msg": "删除成功",
  1225. })
  1226. }
  1227. }
  1228. func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
  1229. id, _ := this.GetInt64("id", 0)
  1230. fmt.Println(id)
  1231. if id == 0 {
  1232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1233. return
  1234. }
  1235. err := service.UpDateWarehouseOutStatus(id)
  1236. if err != nil {
  1237. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1238. } else {
  1239. this.ServeSuccessJSON(map[string]interface{}{
  1240. "msg": "删除成功",
  1241. })
  1242. }
  1243. }
  1244. func (c *StockManagerApiController) GetWarehouseOutInfoList() {
  1245. id, _ := c.GetInt64("id", 0)
  1246. warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
  1247. warehouseOut, _ := service.FindWareHouseOutById(id)
  1248. adminUserInfo := c.GetAdminUserInfo()
  1249. orgId := adminUserInfo.CurrentOrgId
  1250. wareoutList, _ := service.GetWareOutInfoById(id, orgId)
  1251. c.ServeSuccessJSON(map[string]interface{}{
  1252. "list": warehouseOutInfo,
  1253. "info": warehouseOut,
  1254. "wareoutList": wareoutList,
  1255. })
  1256. }
  1257. func (c *StockManagerApiController) EditWarehouseOut() {
  1258. warehouse_out_time := c.GetString("warehouse_out_time")
  1259. id, _ := c.GetInt64("id", 0)
  1260. types, _ := c.GetInt64("type", 0)
  1261. if id == 0 {
  1262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1263. return
  1264. }
  1265. ctime := time.Now().Unix()
  1266. mtime := time.Now().Unix()
  1267. adminUserInfo := c.GetAdminUserInfo()
  1268. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1269. if parseDateErr != nil {
  1270. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1272. return
  1273. }
  1274. warehouseOut, _ := service.FindWareHouseOutById(id)
  1275. tempWarehouseOut := models.WarehouseOut{
  1276. ID: warehouseOut.ID,
  1277. Mtime: mtime,
  1278. WarehouseOutTime: warehouseOutDate.Unix(),
  1279. }
  1280. service.EditWarehouseOut(tempWarehouseOut)
  1281. dataBody := make(map[string]interface{}, 0)
  1282. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1283. if err != nil {
  1284. utils.ErrorLog(err.Error())
  1285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1286. return
  1287. }
  1288. var warehousingOutInfo []*models.WarehouseOutInfo
  1289. var upDateWarehouseOutInfos []*models.WarehouseOutInfo
  1290. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1291. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1292. if len(thisStockOut) > 0 {
  1293. for _, item := range thisStockOut {
  1294. items := item.(map[string]interface{})
  1295. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1296. utils.ErrorLog("good_id")
  1297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1298. return
  1299. }
  1300. good_id := int64(items["good_id"].(float64))
  1301. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1302. utils.ErrorLog("good_type_id")
  1303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1304. return
  1305. }
  1306. good_type_id := int64(items["good_type_id"].(float64))
  1307. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1308. utils.ErrorLog("count")
  1309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1310. return
  1311. }
  1312. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1313. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1314. utils.ErrorLog("price")
  1315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1316. return
  1317. }
  1318. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1319. total := float64(count) * price
  1320. remark := items["remark"].(string)
  1321. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1322. utils.ErrorLog("id")
  1323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1324. return
  1325. }
  1326. id := int64(items["id"].(float64))
  1327. manufacturer := int64(items["manufacturer"].(float64))
  1328. dealer := int64(items["dealer"].(float64))
  1329. number := items["number"].(string)
  1330. license_number := items["license_number"].(string)
  1331. timeLayout := "2006-01-02"
  1332. loc, _ := time.LoadLocation("Local")
  1333. expiry_date := items["expiry_date"].(string)
  1334. var expiryDate int64
  1335. if len(expiry_date) > 0 {
  1336. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1337. if err != nil {
  1338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1339. return
  1340. }
  1341. expiryDate = theTime.Unix()
  1342. }
  1343. product_date := items["product_date"].(string)
  1344. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1345. var productDate int64
  1346. if len(product_date) > 0 {
  1347. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1348. if err != nil {
  1349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1350. return
  1351. }
  1352. productDate = theTime.Unix()
  1353. }
  1354. if id == 0 {
  1355. warehouseOutInfo := &models.WarehouseOutInfo{
  1356. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1357. WarehouseOutId: warehouseOut.ID,
  1358. GoodId: good_id,
  1359. GoodTypeId: good_type_id,
  1360. Count: count,
  1361. Price: price,
  1362. TotalPrice: total,
  1363. Status: 1,
  1364. Ctime: ctime,
  1365. Remark: remark,
  1366. OrgId: adminUserInfo.CurrentOrgId,
  1367. Type: types,
  1368. IsSys: 0,
  1369. SysRecordTime: 0,
  1370. Number: number,
  1371. ExpiryDate: expiryDate,
  1372. ProductDate: productDate,
  1373. Dealer: dealer,
  1374. Manufacturer: manufacturer,
  1375. LicenseNumber: license_number,
  1376. ConsumableType: 1,
  1377. WarehouseInfotId: warehouse_info_id,
  1378. }
  1379. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1380. } else {
  1381. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1382. utils.ErrorLog("is_sys")
  1383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1384. return
  1385. }
  1386. is_sys := int64(items["is_sys"].(float64))
  1387. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1388. utils.ErrorLog("sys_record_time")
  1389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1390. return
  1391. }
  1392. sys_record_time := int64(items["sys_record_time"].(float64))
  1393. warehouseOutInfo := &models.WarehouseOutInfo{
  1394. ID: id,
  1395. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1396. WarehouseOutId: warehouseOut.ID,
  1397. GoodId: good_id,
  1398. GoodTypeId: good_type_id,
  1399. Count: count,
  1400. Price: price,
  1401. TotalPrice: total,
  1402. Status: 1,
  1403. Ctime: ctime,
  1404. Remark: remark,
  1405. OrgId: adminUserInfo.CurrentOrgId,
  1406. Mtime: time.Now().Unix(),
  1407. Type: types,
  1408. Manufacturer: manufacturer,
  1409. IsSys: is_sys,
  1410. SysRecordTime: sys_record_time,
  1411. Number: number,
  1412. ExpiryDate: expiryDate,
  1413. ProductDate: productDate,
  1414. Dealer: dealer,
  1415. LicenseNumber: license_number,
  1416. ConsumableType: 2,
  1417. WarehouseInfotId: warehouse_info_id,
  1418. }
  1419. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1420. }
  1421. }
  1422. }
  1423. }
  1424. var errs error
  1425. //新增出库
  1426. if len(warehousingOutInfo) > 0 {
  1427. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1428. if parseDateErr != nil {
  1429. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  1430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1431. return
  1432. }
  1433. creater := adminUserInfo.AdminUser.Id
  1434. for _, item := range warehousingOutInfo {
  1435. // 查询该耗材是否有库存
  1436. warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId)
  1437. // 如果出库数量大于该批次剩余库存数量
  1438. if item.Count > warehouseOne.StockCount {
  1439. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  1440. c.ServeSuccessJSON(map[string]interface{}{
  1441. "msg": "7",
  1442. "good_name": goodObj.GoodName,
  1443. "specification_name": goodObj.SpecificationName,
  1444. })
  1445. return
  1446. } else {
  1447. warehouseOut, _ := service.GetWarehouseById(id)
  1448. //出库逻辑
  1449. parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
  1450. if parseDateErr != nil {
  1451. utils.ErrorLog(parseDateErr.Error())
  1452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1453. return
  1454. }
  1455. }
  1456. }
  1457. }
  1458. if len(upDateWarehouseOutInfos) > 0 {
  1459. for _, item := range upDateWarehouseOutInfos {
  1460. //1.查询该耗材该批次的最后一次出库记录
  1461. lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId)
  1462. // 退库的库存和该耗材该批次最后一次出库数量进行比较
  1463. //如果退库数量大于 最后一次批次的数量(要么要进行出库)
  1464. if item.Count > lastGood.Count {
  1465. //查询该耗材是否还有库存
  1466. warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId)
  1467. //无库存
  1468. if warehouseinfo.StockCount <= 0 {
  1469. c.ServeSuccessJSON(map[string]interface{}{
  1470. "msg": "5",
  1471. })
  1472. return
  1473. }
  1474. //有库存,进行出库,调用出库接口
  1475. if warehouseinfo.StockCount > 0 {
  1476. var total int64
  1477. var stock_cout int64
  1478. var total_count int64
  1479. //计算和最后一次出库数据的差
  1480. total = item.Count - lastGood.Count
  1481. //获取该耗材该批次的剩余库存量
  1482. info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1483. //判断该批次的剩余库存 和出库的库存进行比较
  1484. //如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
  1485. if item.Count > info.StockCount {
  1486. //计算出库和该批次相差的库存
  1487. total_count = item.Count - info.StockCount
  1488. //清空本批次次库存
  1489. service.DeleteWarehouseInfo(item.WarehouseInfotId)
  1490. //调用出库逻辑
  1491. parseDateErr := service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
  1492. if parseDateErr != nil {
  1493. utils.ErrorLog(errs.Error())
  1494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1495. return
  1496. }
  1497. c.ServeSuccessJSON(map[string]interface{}{
  1498. "msg": "1",
  1499. })
  1500. }
  1501. //如果出库的库存小于或等于于该批次的剩余库存,那么需要该批次出库
  1502. if item.Count <= info.StockCount {
  1503. stock_cout = lastGood.Count + total
  1504. fmt.Println(stock_cout)
  1505. //扣减库存
  1506. warehouse := models.WarehousingInfo{
  1507. StockCount: info.StockCount - total,
  1508. }
  1509. errs := service.UpdateWarehousingInfo(warehouse, info.ID)
  1510. warehouseOutInfo := &models.WarehouseOutInfo{
  1511. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1512. WarehouseOutId: id,
  1513. WarehouseInfotId: item.WarehouseInfotId,
  1514. Status: 1,
  1515. Ctime: time.Now().Unix(),
  1516. Remark: item.Remark,
  1517. OrgId: item.OrgId,
  1518. Type: 1,
  1519. Manufacturer: item.Manufacturer,
  1520. Dealer: item.Dealer,
  1521. IsSys: 0,
  1522. SysRecordTime: item.SysRecordTime,
  1523. GoodTypeId: item.GoodTypeId,
  1524. GoodId: item.GoodId,
  1525. ExpiryDate: item.ExpiryDate,
  1526. ProductDate: item.ProductDate,
  1527. Number: item.Number,
  1528. Price: item.Price,
  1529. LicenseNumber: item.LicenseNumber,
  1530. Count: item.Count,
  1531. ConsumableType: 2,
  1532. }
  1533. //查询是否存在
  1534. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1535. if errcode == gorm.ErrRecordNotFound {
  1536. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1537. if errOne != nil {
  1538. utils.ErrorLog(errs.Error())
  1539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1540. return
  1541. }
  1542. c.ServeSuccessJSON(map[string]interface{}{
  1543. "msg": "1",
  1544. })
  1545. return
  1546. } else if errcode == nil {
  1547. service.UpDateWarehouseOutInfo(item)
  1548. c.ServeSuccessJSON(map[string]interface{}{
  1549. "msg": "1",
  1550. })
  1551. return
  1552. }
  1553. }
  1554. }
  1555. }
  1556. var last_count int64
  1557. var all_total int64
  1558. var stock_total int64
  1559. //如果退库数量小于最后一次批次的数量(要么要进行退库)
  1560. if item.Count < lastGood.Count {
  1561. //退库数量和最后一次出库数据进行计算
  1562. last_count = lastGood.Count - item.Count
  1563. //获取该耗材该批次的剩余库存量
  1564. infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1565. //退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
  1566. all_total = last_count + infoInfo.StockCount
  1567. //如果库存大于总数量,则退回到这个批次
  1568. if infoInfo.WarehousingCount > all_total {
  1569. stock_total = last_count + infoInfo.StockCount
  1570. //退回该批次,计算数量
  1571. warehousingInfoOne := models.WarehousingInfo{
  1572. StockCount: stock_total,
  1573. ID: item.WarehouseInfotId,
  1574. OrgId: item.OrgId,
  1575. }
  1576. parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
  1577. fmt.Println("parseDateErr", parseDateErr)
  1578. //插入一条新纪录
  1579. warehouseOutInfoThree := &models.WarehouseOutInfo{
  1580. WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
  1581. WarehouseOutId: id,
  1582. WarehouseInfotId: item.WarehouseInfotId,
  1583. Status: 1,
  1584. Ctime: time.Now().Unix(),
  1585. Remark: item.Remark,
  1586. OrgId: item.OrgId,
  1587. Type: 1,
  1588. Manufacturer: item.Manufacturer,
  1589. Dealer: item.Dealer,
  1590. IsSys: 0,
  1591. GoodTypeId: item.GoodTypeId,
  1592. GoodId: item.GoodId,
  1593. ExpiryDate: item.ExpiryDate,
  1594. ProductDate: item.ProductDate,
  1595. Number: item.Number,
  1596. Price: item.Price,
  1597. LicenseNumber: item.LicenseNumber,
  1598. ConsumableType: 2,
  1599. Count: item.Count,
  1600. }
  1601. //查询是否存在
  1602. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1603. if errcode == gorm.ErrRecordNotFound {
  1604. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfoThree)
  1605. if errOne != nil {
  1606. utils.ErrorLog(errs.Error())
  1607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1608. return
  1609. }
  1610. c.ServeSuccessJSON(map[string]interface{}{
  1611. "msg": "1",
  1612. })
  1613. return
  1614. } else if errcode == nil {
  1615. service.UpDateWarehouseOutInfo(item)
  1616. return
  1617. }
  1618. }
  1619. //如果库存小于总数量,则报错提醒,该批次的退库数据大于入库数据了无法退库,则需要退库到另一个批次
  1620. if infoInfo.WarehousingCount < all_total {
  1621. c.ServeSuccessJSON(map[string]interface{}{
  1622. "msg": "6",
  1623. })
  1624. return
  1625. }
  1626. }
  1627. if item.Count == lastGood.Count {
  1628. errs = service.UpDateWarehouseOutInfo(item)
  1629. if errs != nil {
  1630. utils.ErrorLog(errs.Error())
  1631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1632. return
  1633. }
  1634. c.ServeSuccessJSON(map[string]interface{}{
  1635. "msg": "1",
  1636. })
  1637. return
  1638. }
  1639. }
  1640. }
  1641. if errs != nil {
  1642. utils.ErrorLog(errs.Error())
  1643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1644. return
  1645. }
  1646. c.ServeSuccessJSON(map[string]interface{}{
  1647. "msg": "1",
  1648. })
  1649. }
  1650. func (c *StockManagerApiController) CreateCancelStock() {
  1651. cancel_stock_time := c.GetString("time")
  1652. types, _ := c.GetInt64("type", 0)
  1653. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1654. if parseDateErr != nil {
  1655. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1657. return
  1658. }
  1659. adminUserInfo := c.GetAdminUserInfo()
  1660. operation_time := time.Now().Unix()
  1661. creater := adminUserInfo.AdminUser.Id
  1662. ctime := time.Now().Unix()
  1663. timeStr := time.Now().Format("2006-01-02")
  1664. timeArr := strings.Split(timeStr, "-")
  1665. total, _ := service.FindAllCancelStockTotal(adminUserInfo.CurrentOrgId)
  1666. total = total + 1
  1667. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1668. cancelStock := models.CancelStock{
  1669. OrderNumber: orderNumber,
  1670. OperaTime: operation_time,
  1671. OrgId: adminUserInfo.CurrentOrgId,
  1672. Creater: creater,
  1673. Ctime: ctime,
  1674. Status: 1,
  1675. ReturnTime: cancelStockDate.Unix(),
  1676. Type: types,
  1677. }
  1678. dataBody := make(map[string]interface{}, 0)
  1679. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1680. if err != nil {
  1681. utils.ErrorLog(err.Error())
  1682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1683. return
  1684. }
  1685. var cancelStockInfos []*models.CancelStockInfo
  1686. var stockFLow []*models.VmStockFlow
  1687. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1688. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1689. if len(thisStockIn) > 0 {
  1690. for _, item := range thisStockIn {
  1691. items := item.(map[string]interface{})
  1692. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1693. utils.ErrorLog("good_id")
  1694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1695. return
  1696. }
  1697. good_id := int64(items["good_id"].(float64))
  1698. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1699. utils.ErrorLog("good_type_id")
  1700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1701. return
  1702. }
  1703. good_type_id := int64(items["good_type_id"].(float64))
  1704. return_count, _ := items["return_count"].(string)
  1705. if len(return_count) == 0 {
  1706. utils.ErrorLog("len(return_count) == 0")
  1707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1708. return
  1709. }
  1710. count, _ := strconv.ParseInt(return_count, 10, 64)
  1711. number := items["number"].(string)
  1712. register_account := items["register_account"].(string)
  1713. manufacturer, _ := items["manufacturer"].(string)
  1714. dealer, _ := items["dealer"].(string)
  1715. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1716. var expiryDates int64
  1717. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1718. expiryDates = 0
  1719. } else {
  1720. if len(items["expiry_date"].(string)) == 0 {
  1721. expiryDates = 0
  1722. } else {
  1723. expiryDate, _ := items["expiry_date"].(string)
  1724. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1725. expiryDates = expiry_date.Unix()
  1726. }
  1727. }
  1728. var productDates int64
  1729. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1730. productDates = 0
  1731. } else {
  1732. if len(items["product_date"].(string)) == 0 {
  1733. productDates = 0
  1734. } else {
  1735. productDate, _ := items["product_date"].(string)
  1736. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1737. productDates = product_date.Unix()
  1738. }
  1739. }
  1740. remark := items["remark"].(string)
  1741. retail_prices := items["price"].(string)
  1742. price, _ := strconv.ParseFloat(retail_prices, 64)
  1743. cancelStockInfo := &models.CancelStockInfo{
  1744. OrderNumber: cancelStock.OrderNumber,
  1745. CancelStockId: cancelStock.ID,
  1746. GoodId: good_id,
  1747. GoodTypeId: good_type_id,
  1748. Count: count,
  1749. Status: 1,
  1750. Ctime: ctime,
  1751. OrgId: adminUserInfo.CurrentOrgId,
  1752. Type: types,
  1753. Manufacturer: manufacturer,
  1754. Dealer: dealer,
  1755. Number: number,
  1756. ProductDate: productDates,
  1757. ExpiryDate: expiryDates,
  1758. RegisterAccount: register_account,
  1759. Remark: remark,
  1760. Price: price,
  1761. WarehouseInfoId: warehouse_info_id,
  1762. }
  1763. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1764. flow := &models.VmStockFlow{
  1765. WarehousingId: 0,
  1766. GoodId: good_id,
  1767. Number: number,
  1768. LicenseNumber: "",
  1769. Count: count,
  1770. UserOrgId: adminUserInfo.CurrentOrgId,
  1771. PatientId: 0,
  1772. SystemTime: time.Now().Unix(),
  1773. ConsumableType: 4,
  1774. IsSys: 0,
  1775. WarehousingOrder: "",
  1776. WarehouseOutId: 0,
  1777. WarehouseOutOrderNumber: "",
  1778. IsEdit: 0,
  1779. CancelStockId: cancelStock.ID,
  1780. CancelOrderNumber: cancelStock.OrderNumber,
  1781. Manufacturer: 0,
  1782. Dealer: 0,
  1783. Creator: adminUserInfo.AdminUser.Id,
  1784. UpdateCreator: 0,
  1785. Status: 1,
  1786. Ctime: time.Now().Unix(),
  1787. Mtime: 0,
  1788. Price: price,
  1789. WarehousingDetailId: 0,
  1790. WarehouseOutDetailId: 0,
  1791. CancelOutDetailId: 0,
  1792. ProductDate: productDates,
  1793. ExpireDate: expiryDates,
  1794. }
  1795. stockFLow = append(stockFLow, flow)
  1796. }
  1797. }
  1798. }
  1799. for _, item := range cancelStockInfos {
  1800. //统计该批次耗材的出库数量
  1801. info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId, item.WarehouseInfoId)
  1802. fmt.Println("2333223323322332233223322323", item.Count, info.Count)
  1803. if item.Count > info.Count {
  1804. service.UpdateCancelInfo(item.CancelStockId)
  1805. c.ServeSuccessJSON(map[string]interface{}{
  1806. "msg": "2",
  1807. })
  1808. return
  1809. }
  1810. //查询该批次入库的值
  1811. infolist, _ := service.GetWarehouseInfoByIdSeven(item.WarehouseInfoId)
  1812. if item.Count > infolist.WarehousingCount {
  1813. c.ServeSuccessJSON(map[string]interface{}{
  1814. "msg": "4",
  1815. })
  1816. return
  1817. }
  1818. if item.Count <= infolist.WarehousingCount {
  1819. _, msgerrkonde := service.GetCancelStockDetailByOrderNumber(orderNumber, adminUserInfo.CurrentOrgId)
  1820. if msgerrkonde == gorm.ErrRecordNotFound {
  1821. service.AddSigleCancelStock(&cancelStock)
  1822. }
  1823. listcancel, _ := service.GetLastCancelStockById(adminUserInfo.CurrentOrgId)
  1824. for _, it := range cancelStockInfos {
  1825. it.CancelStockId = listcancel.ID
  1826. }
  1827. errs := service.CreateCancelStockInfo(cancelStockInfos)
  1828. if len(stockFLow) > 0 {
  1829. service.CreateStockFlow(stockFLow)
  1830. }
  1831. if errs != nil {
  1832. utils.ErrorLog(errs.Error())
  1833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1834. return
  1835. }
  1836. //查询该批次的剩余库存
  1837. wareouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  1838. if (wareouseinfo.StockCount + item.Count) > wareouseinfo.WarehousingCount {
  1839. c.ServeSuccessJSON(map[string]interface{}{
  1840. "msg": "5",
  1841. })
  1842. return
  1843. }
  1844. //更改入库数量
  1845. errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  1846. break
  1847. }
  1848. }
  1849. c.ServeSuccessJSON(map[string]interface{}{
  1850. "msg": "3",
  1851. })
  1852. return
  1853. }
  1854. func (c *StockManagerApiController) GetCancelStockInfoList() {
  1855. id, _ := c.GetInt64("id", 0)
  1856. cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
  1857. info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1858. manufacturerList, _ := service.GetAllManufacturerList(c.GetAdminUserInfo().CurrentOrgId)
  1859. dealerList, _ := service.GetAllDealerList(c.GetAdminUserInfo().CurrentOrgId)
  1860. c.ServeSuccessJSON(map[string]interface{}{
  1861. "list": cancelStockInfoList,
  1862. "info": info,
  1863. "manufacturerList": manufacturerList,
  1864. "dealerList": dealerList,
  1865. })
  1866. }
  1867. func (c *StockManagerApiController) GetCancelStockList() {
  1868. page, _ := c.GetInt64("page", -1)
  1869. limit, _ := c.GetInt64("limit", -1)
  1870. start_time := c.GetString("start_time")
  1871. end_time := c.GetString("end_time")
  1872. types, _ := c.GetInt64("type", 0)
  1873. keywords := c.GetString("keywords")
  1874. timeLayout := "2006-01-02"
  1875. loc, _ := time.LoadLocation("Local")
  1876. var startTime int64
  1877. if len(start_time) > 0 {
  1878. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1879. if err != nil {
  1880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1881. return
  1882. }
  1883. startTime = theTime.Unix()
  1884. }
  1885. var endTime int64
  1886. if len(end_time) > 0 {
  1887. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1888. if err != nil {
  1889. utils.ErrorLog(err.Error())
  1890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1891. return
  1892. }
  1893. endTime = theTime.Unix()
  1894. }
  1895. adminUserInfo := c.GetAdminUserInfo()
  1896. returnList, total, err := service.FindAllCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1897. if err == nil {
  1898. c.ServeSuccessJSON(map[string]interface{}{
  1899. "list": returnList,
  1900. "total": total,
  1901. })
  1902. } else {
  1903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1904. }
  1905. }
  1906. func (this *StockManagerApiController) DeleteCancelStock() {
  1907. ids := this.GetString("ids")
  1908. if len(ids) == 0 {
  1909. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1910. return
  1911. }
  1912. idArray := strings.Split(ids, ",")
  1913. err := service.DeleteCancelStock(idArray)
  1914. if err != nil {
  1915. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1916. } else {
  1917. this.ServeSuccessJSON(map[string]interface{}{
  1918. "msg": "删除成功",
  1919. })
  1920. }
  1921. }
  1922. func (this *StockManagerApiController) DeleteCancelStockInfo() {
  1923. id, _ := this.GetInt64("id", 0)
  1924. fmt.Println(id)
  1925. if id == 0 {
  1926. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1927. return
  1928. }
  1929. err := service.UpDateCancleStockStatus(id)
  1930. if err != nil {
  1931. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1932. } else {
  1933. this.ServeSuccessJSON(map[string]interface{}{
  1934. "msg": "删除成功",
  1935. })
  1936. }
  1937. }
  1938. func (c *StockManagerApiController) EditCancelStock() {
  1939. cancel_time := c.GetString("cancel_time")
  1940. id, _ := c.GetInt64("id", 0)
  1941. if id == 0 {
  1942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1943. return
  1944. }
  1945. ctime := time.Now().Unix()
  1946. mtime := time.Now().Unix()
  1947. adminUserInfo := c.GetAdminUserInfo()
  1948. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  1949. if parseDateErr != nil {
  1950. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  1951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1952. return
  1953. }
  1954. cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1955. tempCancelStock := models.CancelStock{
  1956. ID: cancelStock.ID,
  1957. Mtime: mtime,
  1958. ReturnTime: cancelDate.Unix(),
  1959. }
  1960. service.EditCancelStock(tempCancelStock)
  1961. dataBody := make(map[string]interface{}, 0)
  1962. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1963. if err != nil {
  1964. utils.ErrorLog(err.Error())
  1965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1966. return
  1967. }
  1968. var cancelStockInfos []*models.CancelStockInfo
  1969. var upDateCancelStockInfos []*models.CancelStockInfo
  1970. var stockFlow []*models.VmStockFlow
  1971. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1972. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  1973. if len(thisCancelStock) > 0 {
  1974. for _, item := range thisCancelStock {
  1975. items := item.(map[string]interface{})
  1976. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1977. utils.ErrorLog("good_id")
  1978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1979. return
  1980. }
  1981. good_id := int64(items["good_id"].(float64))
  1982. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1983. utils.ErrorLog("good_type_id")
  1984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1985. return
  1986. }
  1987. good_type_id := int64(items["good_type_id"].(float64))
  1988. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1989. utils.ErrorLog("count")
  1990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1991. return
  1992. }
  1993. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1994. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1995. utils.ErrorLog("id")
  1996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1997. return
  1998. }
  1999. id := int64(items["id"].(float64))
  2000. number := items["number"].(string)
  2001. register_account := items["register_account"].(string)
  2002. manufacturer, _ := items["manufacturer"].(string)
  2003. dealer, _ := items["dealer"].(string)
  2004. remark := items["remark"].(string)
  2005. var productDates int64
  2006. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  2007. productDates = 0
  2008. } else {
  2009. if len(items["product_date"].(string)) == 0 {
  2010. productDates = 0
  2011. } else {
  2012. productDate, _ := items["product_date"].(string)
  2013. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  2014. productDates = product_date.Unix()
  2015. }
  2016. }
  2017. var expiryDates int64
  2018. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  2019. expiryDates = 0
  2020. } else {
  2021. if len(items["expiry_date"].(string)) == 0 {
  2022. expiryDates = 0
  2023. } else {
  2024. expiryDate, _ := items["expiry_date"].(string)
  2025. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  2026. expiryDates = expiry_date.Unix()
  2027. }
  2028. }
  2029. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2030. utils.ErrorLog("price")
  2031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2032. return
  2033. }
  2034. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2035. if id == 0 {
  2036. cancelStockInfo := &models.CancelStockInfo{
  2037. GoodId: good_id,
  2038. GoodTypeId: good_type_id,
  2039. Count: count,
  2040. Status: 1,
  2041. Ctime: ctime,
  2042. OrgId: adminUserInfo.CurrentOrgId,
  2043. OrderNumber: cancelStock.OrderNumber,
  2044. CancelStockId: cancelStock.ID,
  2045. Mtime: time.Now().Unix(),
  2046. Number: number,
  2047. RegisterAccount: register_account,
  2048. Manufacturer: manufacturer,
  2049. Dealer: dealer,
  2050. ProductDate: productDates,
  2051. ExpiryDate: expiryDates,
  2052. Remark: remark,
  2053. Price: price,
  2054. }
  2055. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  2056. flow := &models.VmStockFlow{
  2057. WarehousingId: 0,
  2058. GoodId: good_id,
  2059. Number: number,
  2060. LicenseNumber: "",
  2061. Count: count,
  2062. UserOrgId: adminUserInfo.CurrentOrgId,
  2063. PatientId: 0,
  2064. SystemTime: time.Now().Unix(),
  2065. ConsumableType: 4,
  2066. IsSys: 0,
  2067. WarehousingOrder: "",
  2068. WarehouseOutId: 0,
  2069. WarehouseOutOrderNumber: "",
  2070. IsEdit: 2,
  2071. CancelStockId: cancelStock.ID,
  2072. CancelOrderNumber: cancelStock.OrderNumber,
  2073. Manufacturer: 0,
  2074. Dealer: 0,
  2075. Creator: adminUserInfo.AdminUser.Id,
  2076. UpdateCreator: 0,
  2077. Status: 1,
  2078. Ctime: time.Now().Unix(),
  2079. Mtime: 0,
  2080. Price: price,
  2081. WarehousingDetailId: 0,
  2082. WarehouseOutDetailId: 0,
  2083. CancelOutDetailId: 0,
  2084. ProductDate: productDates,
  2085. ExpireDate: expiryDates,
  2086. }
  2087. stockFlow = append(stockFlow, flow)
  2088. } else {
  2089. cancelStockInfo := &models.CancelStockInfo{
  2090. ID: id,
  2091. GoodId: good_id,
  2092. GoodTypeId: good_type_id,
  2093. Count: count,
  2094. Status: 1,
  2095. Ctime: ctime,
  2096. OrgId: adminUserInfo.CurrentOrgId,
  2097. OrderNumber: cancelStock.OrderNumber,
  2098. CancelStockId: cancelStock.ID,
  2099. Mtime: time.Now().Unix(),
  2100. Number: number,
  2101. RegisterAccount: register_account,
  2102. Manufacturer: manufacturer,
  2103. Dealer: dealer,
  2104. ProductDate: productDates,
  2105. ExpiryDate: expiryDates,
  2106. Remark: remark,
  2107. Price: price,
  2108. }
  2109. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  2110. flow := &models.VmStockFlow{
  2111. WarehousingId: 0,
  2112. GoodId: good_id,
  2113. Number: number,
  2114. LicenseNumber: "",
  2115. Count: count,
  2116. UserOrgId: adminUserInfo.CurrentOrgId,
  2117. PatientId: 0,
  2118. SystemTime: time.Now().Unix(),
  2119. ConsumableType: 4,
  2120. IsSys: 0,
  2121. WarehousingOrder: "",
  2122. WarehouseOutId: 0,
  2123. WarehouseOutOrderNumber: "",
  2124. IsEdit: 2,
  2125. CancelStockId: cancelStock.ID,
  2126. CancelOrderNumber: cancelStock.OrderNumber,
  2127. Manufacturer: 0,
  2128. Dealer: 0,
  2129. Creator: adminUserInfo.AdminUser.Id,
  2130. UpdateCreator: 0,
  2131. Status: 1,
  2132. Ctime: time.Now().Unix(),
  2133. Mtime: 0,
  2134. Price: price,
  2135. WarehousingDetailId: 0,
  2136. WarehouseOutDetailId: 0,
  2137. CancelOutDetailId: 0,
  2138. ProductDate: productDates,
  2139. ExpireDate: expiryDates,
  2140. }
  2141. stockFlow = append(stockFlow, flow)
  2142. }
  2143. }
  2144. }
  2145. }
  2146. var errs error
  2147. fmt.Println("出库22322333223", cancelStockInfos)
  2148. fmt.Println("更新23232323232323233", upDateCancelStockInfos)
  2149. if len(cancelStockInfos) > 0 {
  2150. for _, item := range cancelStockInfos {
  2151. //统计该耗材的出库数量
  2152. info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId, item.WarehouseInfoId)
  2153. if item.Count > info.Count {
  2154. c.ServeSuccessJSON(map[string]interface{}{
  2155. "msg": "2",
  2156. })
  2157. return
  2158. }
  2159. //查询该批次入库的值
  2160. infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2161. if item.Count > infolist.WarehousingCount {
  2162. c.ServeSuccessJSON(map[string]interface{}{
  2163. "msg": "4",
  2164. })
  2165. return
  2166. }
  2167. if item.Count <= infolist.WarehousingCount {
  2168. errs := service.CreateCancelStockInfo(cancelStockInfos)
  2169. if len(stockFlow) > 0 {
  2170. service.CreateStockFlow(stockFlow)
  2171. }
  2172. if errs != nil {
  2173. utils.ErrorLog(errs.Error())
  2174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  2175. return
  2176. }
  2177. //更改入库数量
  2178. errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
  2179. break
  2180. }
  2181. }
  2182. }
  2183. if len(upDateCancelStockInfos) > 0 {
  2184. for _, item := range upDateCancelStockInfos {
  2185. //获取该批次最后一套出库记录
  2186. info, _ := service.GetLastCancelInfo(item.WarehouseInfoId, item.GoodId)
  2187. fmt.Println("info232332322332233223", info.Count, item.Count)
  2188. //比较出库数量和最后一次出库数据大小
  2189. //退库(加)
  2190. if item.Count < info.Count {
  2191. var total = info.Count - item.Count
  2192. errs = service.UpDateCancelStockInfo(item)
  2193. service.CreateStockFlow(stockFlow)
  2194. warehouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2195. if (warehouseinfo.StockCount + total) > warehouseinfo.StockCount {
  2196. c.ServeSuccessJSON(map[string]interface{}{
  2197. "msg": "5",
  2198. })
  2199. return
  2200. }
  2201. parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total)
  2202. if parseDateErr != nil {
  2203. utils.ErrorLog(errs.Error())
  2204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2205. break
  2206. }
  2207. }
  2208. //(减)
  2209. if item.Count > info.Count {
  2210. errs = service.UpDateCancelStockInfo(item)
  2211. service.CreateStockFlow(stockFlow)
  2212. //查询该批次入库的值
  2213. infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
  2214. if item.Count > infolist.WarehousingCount {
  2215. c.ServeSuccessJSON(map[string]interface{}{
  2216. "msg": "4",
  2217. })
  2218. return
  2219. }
  2220. if item.Count <= infolist.WarehousingCount {
  2221. var total_count = info.Count - item.Count
  2222. parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total_count)
  2223. if parseDateErr != nil {
  2224. utils.ErrorLog(errs.Error())
  2225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2226. return
  2227. }
  2228. }
  2229. }
  2230. }
  2231. if errs != nil {
  2232. utils.ErrorLog(errs.Error())
  2233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2234. return
  2235. }
  2236. c.ServeSuccessJSON(map[string]interface{}{
  2237. "msg": "3",
  2238. })
  2239. }
  2240. if errs != nil {
  2241. utils.ErrorLog(errs.Error())
  2242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2243. return
  2244. }
  2245. c.ServeSuccessJSON(map[string]interface{}{
  2246. "msg": "3",
  2247. })
  2248. }
  2249. func (this *StockManagerApiController) GetCancelStockConfig() {
  2250. types, _ := this.GetInt64("type", 0)
  2251. adminUserInfo := this.GetAdminUserInfo()
  2252. warehouseOutInfoList, _ := service.FindAllWarehouseOutInfo(adminUserInfo.CurrentOrgId, types)
  2253. this.ServeSuccessJSON(map[string]interface{}{
  2254. "warehouseOutInfoList": warehouseOutInfoList,
  2255. })
  2256. }
  2257. func (c *StockManagerApiController) GetQueryInfo() {
  2258. page, _ := c.GetInt64("page", -1)
  2259. limit, _ := c.GetInt64("limit", -1)
  2260. keyword := c.GetString("keyword")
  2261. start_time := c.GetString("start_time")
  2262. end_time := c.GetString("end_time")
  2263. type_name, _ := c.GetInt64("type_name")
  2264. timeLayout := "2006-01-02"
  2265. loc, _ := time.LoadLocation("Local")
  2266. var startTime int64
  2267. if len(start_time) > 0 {
  2268. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2269. if err != nil {
  2270. fmt.Println(err)
  2271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2272. return
  2273. }
  2274. startTime = theTime.Unix()
  2275. }
  2276. var endTime int64
  2277. if len(end_time) > 0 {
  2278. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2279. if err != nil {
  2280. utils.ErrorLog(err.Error())
  2281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2282. return
  2283. }
  2284. endTime = theTime.Unix()
  2285. }
  2286. adminUserInfo := c.GetAdminUserInfo()
  2287. list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, startTime, endTime, type_name)
  2288. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  2289. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId, "")
  2290. if err == nil {
  2291. c.ServeSuccessJSON(map[string]interface{}{
  2292. "list": list,
  2293. "total": total,
  2294. "info": info,
  2295. "infomationList": infomationList,
  2296. "orgid": adminUserInfo.CurrentOrgId,
  2297. })
  2298. } else {
  2299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2300. }
  2301. }
  2302. func (c *StockManagerApiController) SearchWarehouse() {
  2303. keywords := c.GetString("keywords")
  2304. adminUserInfo := c.GetAdminUserInfo()
  2305. warehouseList, total, err := service.FindAllWarehouseByKeyword(adminUserInfo.CurrentOrgId, 1, 10, keywords)
  2306. if err == nil {
  2307. c.ServeSuccessJSON(map[string]interface{}{
  2308. "list": warehouseList,
  2309. "total": total,
  2310. })
  2311. } else {
  2312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2313. }
  2314. }
  2315. func (c *StockManagerApiController) GetAllConfig() {
  2316. adminUserInfo := c.GetAdminUserInfo()
  2317. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  2318. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  2319. goodType, _ := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  2320. goodInfo, _ := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
  2321. c.ServeSuccessJSON(map[string]interface{}{
  2322. "manufacturer": manufacturer,
  2323. "dealer": dealer,
  2324. "goodType": goodType,
  2325. "goodInfo": goodInfo,
  2326. })
  2327. }
  2328. func (this *StockManagerApiController) GetAllSalesReturnConfig() {
  2329. types, _ := this.GetInt64("type", 0)
  2330. adminUserInfo := this.GetAdminUserInfo()
  2331. warehouseInfoList, _ := service.FindAllWarehouseInfo(adminUserInfo.CurrentOrgId, types)
  2332. this.ServeSuccessJSON(map[string]interface{}{
  2333. "warehouseInfoList": warehouseInfoList,
  2334. })
  2335. }
  2336. func (this *StockManagerApiController) GetDetailInfo() {
  2337. page, _ := this.GetInt64("page", 0)
  2338. limit, _ := this.GetInt64("limit", 0)
  2339. start_time := this.GetString("start_time")
  2340. end_time := this.GetString("end_time")
  2341. types, _ := this.GetInt64("type", 0)
  2342. keywords := this.GetString("keywords")
  2343. manufacturer, _ := this.GetInt64("manufacturer", 0)
  2344. order_type, _ := this.GetInt64("order_type", 0)
  2345. dealer, _ := this.GetInt64("dealer", 0)
  2346. timeLayout := "2006-01-02"
  2347. loc, _ := time.LoadLocation("Local")
  2348. var startTime int64
  2349. if len(start_time) > 0 {
  2350. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2351. if err != nil {
  2352. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2353. return
  2354. }
  2355. startTime = theTime.Unix()
  2356. }
  2357. var endTime int64
  2358. if len(end_time) > 0 {
  2359. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2360. if err != nil {
  2361. utils.ErrorLog(err.Error())
  2362. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2363. return
  2364. }
  2365. endTime = theTime.Unix()
  2366. }
  2367. adminUserInfo := this.GetAdminUserInfo()
  2368. var list []*models.WarehousingInfo
  2369. var list1 []*models.WarehouseOutInfo
  2370. var list2 []*models.SalesReturnInfo
  2371. var list3 []*models.CancelStockInfo
  2372. var total int64
  2373. var err error
  2374. var total_price float64
  2375. if types == 1 {
  2376. list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2377. _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2378. if err == nil {
  2379. this.ServeSuccessJSON(map[string]interface{}{
  2380. "list": list,
  2381. "total": total,
  2382. "total_price": total_price,
  2383. })
  2384. } else {
  2385. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2386. }
  2387. } else if types == 2 {
  2388. list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2389. _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2390. if err == nil {
  2391. this.ServeSuccessJSON(map[string]interface{}{
  2392. "list": list1,
  2393. "total": total,
  2394. "total_price": total_price,
  2395. })
  2396. } else {
  2397. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2398. }
  2399. } else if types == 3 {
  2400. list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2401. if err == nil {
  2402. this.ServeSuccessJSON(map[string]interface{}{
  2403. "list": list2,
  2404. "total": total,
  2405. })
  2406. } else {
  2407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2408. }
  2409. } else if types == 4 {
  2410. list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2411. listGroup, err := service.FindeCancelGroup(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2412. if err == nil {
  2413. this.ServeSuccessJSON(map[string]interface{}{
  2414. "list": list3,
  2415. "total": total,
  2416. "listgroup": listGroup,
  2417. })
  2418. } else {
  2419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2420. }
  2421. }
  2422. }
  2423. func (this *StockManagerApiController) GetUserDetailInfo() {
  2424. order_id, _ := this.GetInt64("id")
  2425. if order_id <= 0 {
  2426. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2427. return
  2428. }
  2429. adminUserInfo := this.GetAdminUserInfo()
  2430. userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  2431. if err == nil {
  2432. this.ServeSuccessJSON(map[string]interface{}{
  2433. "list": userDetails,
  2434. "total": total,
  2435. })
  2436. } else {
  2437. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2438. return
  2439. }
  2440. }
  2441. func (this *StockManagerApiController) PostSearchStock() {
  2442. keyword := this.GetString("keyword")
  2443. adminUserInfo := this.GetAdminUserInfo()
  2444. orgId := adminUserInfo.CurrentOrgId
  2445. stock, err := service.PostSearchStock(keyword, orgId)
  2446. if err != nil {
  2447. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2448. }
  2449. this.ServeSuccessJSON(map[string]interface{}{
  2450. "stock": stock,
  2451. })
  2452. }
  2453. func (this *StockManagerApiController) GetOutStockTotalCount() {
  2454. warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
  2455. adminUserInfo := this.GetAdminUserInfo()
  2456. stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
  2457. if err != nil {
  2458. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2459. }
  2460. this.ServeSuccessJSON(map[string]interface{}{
  2461. "stockCount": stockCount,
  2462. })
  2463. }
  2464. func (this *StockManagerApiController) AddGoodInformation() {
  2465. adminUserInfo := this.GetAdminUserInfo()
  2466. orgId := adminUserInfo.CurrentOrgId
  2467. dataBody := make(map[string]interface{}, 0)
  2468. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2469. if err != nil {
  2470. utils.ErrorLog(err.Error())
  2471. return
  2472. }
  2473. utils.ErrorLog("%v", dataBody)
  2474. var goods []*models.GoodInfo
  2475. var total_goods []interface{}
  2476. tempGoods := dataBody["goods"].([]interface{})
  2477. total_goods = tempGoods
  2478. for index, goodMap := range tempGoods {
  2479. goodNameM := goodMap.(map[string]interface{})
  2480. var good models.GoodInfo
  2481. if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
  2482. utils.ErrorLog("good_name")
  2483. return
  2484. }
  2485. good_name, _ := goodNameM["good_name"].(string)
  2486. if len(good_name) == 0 { //名字为空则生成一条导入错误日志
  2487. err_log := models.ExportErrLog{
  2488. LogType: 5,
  2489. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2490. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
  2491. Status: 1,
  2492. CreateTime: time.Now().Unix(),
  2493. UpdateTime: time.Now().Unix(),
  2494. ExportTime: time.Now().Unix(),
  2495. }
  2496. service.CreateExportErrLog(&err_log)
  2497. continue
  2498. }
  2499. good.GoodName = good_name
  2500. // 获取数据字典数据
  2501. var good_kind_id int64
  2502. var name = "耗材种类"
  2503. config, _ := service.GetDrugDataConfig(0, name)
  2504. good_kind := goodNameM["good_kind"].(string)
  2505. if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
  2506. err_log := models.ExportErrLog{
  2507. LogType: 5,
  2508. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2509. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
  2510. Status: 1,
  2511. CreateTime: time.Now().Unix(),
  2512. UpdateTime: time.Now().Unix(),
  2513. ExportTime: time.Now().Unix(),
  2514. }
  2515. service.CreateExportErrLog(&err_log)
  2516. continue
  2517. }
  2518. if len(good_kind) != 0 {
  2519. _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
  2520. lastConfig, _ := service.GetLastDicConfig(config.ID, orgId)
  2521. dataconfig := models.DictDataconfig{
  2522. ParentId: config.ID,
  2523. Module: "system",
  2524. OrgId: orgId,
  2525. Name: good_kind,
  2526. FieldName: "",
  2527. Value: lastConfig.Value + 1,
  2528. CreatedTime: "",
  2529. UpdatedTime: "",
  2530. CreateUserId: adminUserInfo.AdminUser.Id,
  2531. Status: 1,
  2532. Remark: "",
  2533. DeleteIdSystem: 0,
  2534. Title: "",
  2535. Content: "",
  2536. Order: 0,
  2537. Code: "",
  2538. }
  2539. if errcodegoodkind == gorm.ErrRecordNotFound {
  2540. service.CreatedDicConfig(&dataconfig)
  2541. }
  2542. }
  2543. dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
  2544. for _, it := range dataConfig {
  2545. if good_kind == it.Name {
  2546. fmt.Println(it.Name)
  2547. good_kind_id = int64(it.Value)
  2548. }
  2549. }
  2550. good.GoodKind = good_kind_id
  2551. good_type := goodNameM["type_name"].(string)
  2552. if len(good_type) == 0 {
  2553. err_log := models.ExportErrLog{
  2554. LogType: 5,
  2555. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2556. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材类型不能为空",
  2557. Status: 1,
  2558. CreateTime: time.Now().Unix(),
  2559. UpdateTime: time.Now().Unix(),
  2560. ExportTime: time.Now().Unix(),
  2561. }
  2562. service.CreateExportErrLog(&err_log)
  2563. continue
  2564. }
  2565. if len(good_type) != 0 {
  2566. _, errcodegoodtype := service.GetGoodType(good_type, orgId)
  2567. if errcodegoodtype == gorm.ErrRecordNotFound {
  2568. goodsType := models.GoodsType{
  2569. TypeName: good_type,
  2570. Remark: "",
  2571. Ctime: time.Now().Unix(),
  2572. Mtime: 0,
  2573. Creater: adminUserInfo.AdminUser.Id,
  2574. Modifier: 0,
  2575. OrgId: adminUserInfo.CurrentOrgId,
  2576. Status: 1,
  2577. Type: 0,
  2578. Number: 0,
  2579. OutStock: 0,
  2580. StockAttribute: 1,
  2581. }
  2582. service.CreatedGoodType(&goodsType)
  2583. }
  2584. }
  2585. goodType, _ := service.GetAllGoodType(orgId)
  2586. var good_type_id int64
  2587. for _, it := range goodType {
  2588. if good_type == it.TypeName {
  2589. good_type_id = it.ID
  2590. }
  2591. }
  2592. good.GoodTypeId = good_type_id
  2593. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  2594. if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
  2595. err_log := models.ExportErrLog{
  2596. LogType: 5,
  2597. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2598. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  2599. Status: 1,
  2600. CreateTime: time.Now().Unix(),
  2601. UpdateTime: time.Now().Unix(),
  2602. ExportTime: time.Now().Unix(),
  2603. }
  2604. service.CreateExportErrLog(&err_log)
  2605. continue
  2606. }
  2607. var medical_insurance_id int64
  2608. var medicalInsurance = "医保等级"
  2609. medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
  2610. if len(medical_insurance_level) != 0 {
  2611. _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
  2612. if errcodemedicalInsurance == gorm.ErrRecordNotFound {
  2613. mediConfigOne, _ := service.GetLastDicConfig(medicalInsuranceDataConfig.ID, orgId)
  2614. dataconfig := models.DictDataconfig{
  2615. ParentId: medicalInsuranceDataConfig.ID,
  2616. Module: "system",
  2617. OrgId: orgId,
  2618. Name: medical_insurance_level,
  2619. FieldName: "",
  2620. Value: mediConfigOne.Value + 1,
  2621. CreatedTime: "",
  2622. UpdatedTime: "",
  2623. CreateUserId: adminUserInfo.AdminUser.Id,
  2624. Status: 1,
  2625. Remark: "",
  2626. DeleteIdSystem: 0,
  2627. Title: "",
  2628. Content: "",
  2629. Order: 0,
  2630. Code: "",
  2631. }
  2632. service.CreatedDicConfig(&dataconfig)
  2633. }
  2634. }
  2635. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
  2636. for _, it := range medicalInsuranceList {
  2637. if medical_insurance_level == it.Name {
  2638. medical_insurance_id = int64(it.Value)
  2639. }
  2640. }
  2641. good.MedicalInsuranceLevel = medical_insurance_id
  2642. if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
  2643. utils.ErrorLog("specification_name")
  2644. return
  2645. }
  2646. specification_name := goodNameM["specification_name"].(string)
  2647. if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
  2648. err_log := models.ExportErrLog{
  2649. LogType: 5,
  2650. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2651. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
  2652. Status: 1,
  2653. CreateTime: time.Now().Unix(),
  2654. UpdateTime: time.Now().Unix(),
  2655. ExportTime: time.Now().Unix(),
  2656. }
  2657. service.CreateExportErrLog(&err_log)
  2658. continue
  2659. }
  2660. good.SpecificationName = specification_name
  2661. var manufacturer_id int64
  2662. manufacturer := goodNameM["manufacturer"].(string)
  2663. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  2664. err_log := models.ExportErrLog{
  2665. LogType: 5,
  2666. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2667. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
  2668. Status: 1,
  2669. CreateTime: time.Now().Unix(),
  2670. UpdateTime: time.Now().Unix(),
  2671. ExportTime: time.Now().Unix(),
  2672. }
  2673. service.CreateExportErrLog(&err_log)
  2674. continue
  2675. }
  2676. if len(manufacturer) != 0 {
  2677. _, errcodes := service.GetManufacturerName(orgId, manufacturer)
  2678. manu := models.Manufacturer{
  2679. ManufacturerName: manufacturer,
  2680. Status: 1,
  2681. OrgId: orgId,
  2682. Creater: adminUserInfo.AdminUser.Id,
  2683. }
  2684. if errcodes == gorm.ErrRecordNotFound {
  2685. service.CreateManufacturer(&manu)
  2686. }
  2687. }
  2688. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2689. for _, it := range manufacturerList {
  2690. if manufacturer == it.ManufacturerName {
  2691. manufacturer_id = it.ID
  2692. }
  2693. }
  2694. good.Manufacturer = manufacturer_id
  2695. if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
  2696. utils.ErrorLog("unit_id")
  2697. return
  2698. }
  2699. unit_id := int64(goodNameM["unit_id"].(float64))
  2700. if unit_id <= 0 { //名字为空则生成一条导入错误日志
  2701. err_log := models.ExportErrLog{
  2702. LogType: 5,
  2703. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2704. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
  2705. Status: 1,
  2706. CreateTime: time.Now().Unix(),
  2707. UpdateTime: time.Now().Unix(),
  2708. ExportTime: time.Now().Unix(),
  2709. }
  2710. service.CreateExportErrLog(&err_log)
  2711. continue
  2712. }
  2713. good.GoodUnit = unit_id
  2714. retail_prices := goodNameM["retail_price"].(string)
  2715. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  2716. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  2717. err_log := models.ExportErrLog{
  2718. LogType: 5,
  2719. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2720. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的价格不能为空",
  2721. Status: 1,
  2722. CreateTime: time.Now().Unix(),
  2723. UpdateTime: time.Now().Unix(),
  2724. ExportTime: time.Now().Unix(),
  2725. }
  2726. service.CreateExportErrLog(&err_log)
  2727. continue
  2728. }
  2729. good.RetailPrice = retail_price
  2730. if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
  2731. utils.ErrorLog("stock_warn_count")
  2732. return
  2733. }
  2734. stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
  2735. if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
  2736. err_log := models.ExportErrLog{
  2737. LogType: 5,
  2738. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2739. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
  2740. Status: 1,
  2741. CreateTime: time.Now().Unix(),
  2742. UpdateTime: time.Now().Unix(),
  2743. ExportTime: time.Now().Unix(),
  2744. }
  2745. service.CreateExportErrLog(&err_log)
  2746. continue
  2747. }
  2748. good.StockWarnCount = stock_warn_count
  2749. var dealer_id int64
  2750. dealerName := goodNameM["dealer"].(string)
  2751. fmt.Println("经销商", dealerName)
  2752. dealer := models.Dealer{
  2753. OrgId: orgId,
  2754. Status: 1,
  2755. DealerName: dealerName,
  2756. Creater: adminUserInfo.AdminUser.Id,
  2757. Ctime: time.Now().Unix(),
  2758. }
  2759. if len(dealerName) != 0 {
  2760. _, errcodedealer := service.GetDealerByName(orgId, dealerName)
  2761. if errcodedealer == gorm.ErrRecordNotFound {
  2762. service.CreateDealer(&dealer)
  2763. }
  2764. }
  2765. dealerList, _ := service.GetAllDealerList(orgId)
  2766. for _, it := range dealerList {
  2767. if dealerName == it.DealerName {
  2768. dealer_id = it.ID
  2769. }
  2770. }
  2771. good.Dealer = dealer_id
  2772. if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
  2773. utils.ErrorLog("pinyin")
  2774. return
  2775. }
  2776. pinyin := goodNameM["pinyin"].(string)
  2777. good.Pinyin = pinyin
  2778. if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
  2779. utils.ErrorLog("wubi")
  2780. return
  2781. }
  2782. wubi := goodNameM["wubi"].(string)
  2783. good.Wubi = wubi
  2784. buy_prices := goodNameM["buy_price"].(string)
  2785. buy_price, _ := strconv.ParseFloat(buy_prices, 64)
  2786. good.BuyPrice = buy_price
  2787. if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
  2788. utils.ErrorLog("social_security_directory_code")
  2789. return
  2790. }
  2791. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  2792. good.SocialSecurityDirectoryCode = social_security_directory_code
  2793. if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
  2794. utils.ErrorLog("is_special_diseases")
  2795. return
  2796. }
  2797. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  2798. good.IsSpecialDiseases = is_special_diseases
  2799. if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
  2800. utils.ErrorLog("is_record")
  2801. return
  2802. }
  2803. is_record := int64(goodNameM["is_record"].(float64))
  2804. good.IsRecord = is_record
  2805. if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
  2806. utils.ErrorLog("good_status")
  2807. return
  2808. }
  2809. good_status := goodNameM["good_status"].(string)
  2810. good.GoodStatus = good_status
  2811. if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
  2812. utils.ErrorLog("medical_insurance_number")
  2813. return
  2814. }
  2815. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  2816. good.MedicalInsuranceNumber = medical_insurance_number
  2817. if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
  2818. utils.ErrorLog("production_type")
  2819. return
  2820. }
  2821. production_type := goodNameM["production_type"].(string)
  2822. good.ProductionType = production_type
  2823. if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
  2824. utils.ErrorLog("remark")
  2825. return
  2826. }
  2827. remark := goodNameM["remark"].(string)
  2828. good.Remark = remark
  2829. statistics_category := goodNameM["statistics_category"].(string)
  2830. var categoryName = "统计分类"
  2831. var statistic_id int64
  2832. drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
  2833. if len(statistics_category) != 0 {
  2834. _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
  2835. if errcodecagegory == gorm.ErrRecordNotFound {
  2836. dicConfigThree, _ := service.GetLastDicConfig(drugDataConfig.ID, orgId)
  2837. dataconfig := models.DictDataconfig{
  2838. ParentId: drugDataConfig.ID,
  2839. Module: "system",
  2840. OrgId: orgId,
  2841. Name: statistics_category,
  2842. FieldName: "",
  2843. Value: dicConfigThree.Value + 1,
  2844. CreatedTime: "",
  2845. UpdatedTime: "",
  2846. CreateUserId: adminUserInfo.AdminUser.Id,
  2847. Status: 1,
  2848. Remark: "",
  2849. DeleteIdSystem: 0,
  2850. Title: "",
  2851. Content: "",
  2852. Order: 0,
  2853. Code: "",
  2854. }
  2855. service.CreatedDicConfig(&dataconfig)
  2856. }
  2857. }
  2858. parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
  2859. for _, it := range parentDataConfig {
  2860. if statistics_category == it.Name {
  2861. statistic_id = int64(it.Value)
  2862. }
  2863. }
  2864. good.StatisticsCategory = statistic_id
  2865. special_medical := goodNameM["special_medical"].(string)
  2866. good.SpecialMedical = special_medical
  2867. goods = append(goods, &good)
  2868. }
  2869. export_time := time.Now().Unix()
  2870. errLogs, _ := service.FindPatientExportLogTwo(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2871. if len(goods) > 0 {
  2872. for _, item := range goods {
  2873. goodInfo := models.GoodInfo{
  2874. GoodName: item.GoodName,
  2875. SpecificationName: item.SpecificationName,
  2876. GoodKind: item.GoodKind,
  2877. GoodTypeId: item.GoodTypeId,
  2878. Dealer: item.Dealer,
  2879. GoodUnit: item.GoodUnit,
  2880. IsRecord: item.IsRecord,
  2881. IsSpecialDiseases: item.IsSpecialDiseases,
  2882. Manufacturer: item.Manufacturer,
  2883. Pinyin: item.Pinyin,
  2884. GoodStatus: item.GoodStatus,
  2885. ProductionType: item.ProductionType,
  2886. Remark: item.Remark,
  2887. RetailPrice: item.RetailPrice,
  2888. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  2889. SpecialMedical: item.SpecialMedical,
  2890. Wubi: item.Wubi,
  2891. StockWarnCount: item.StockWarnCount,
  2892. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  2893. OrgId: orgId,
  2894. Status: 1,
  2895. Ctime: time.Now().Unix(),
  2896. StatisticsCategory: item.StatisticsCategory,
  2897. GoodCode: item.GoodCode,
  2898. BuyPrice: item.BuyPrice,
  2899. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  2900. }
  2901. //查询同种耗材名称同种类型同种规格的耗材是否存在
  2902. _, errcodegood := service.GetGoodsInformaitonIsExist(item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2903. if errcodegood == gorm.ErrRecordNotFound {
  2904. service.CreateGoodsInfomation(&goodInfo)
  2905. } else if errcodegood == nil {
  2906. service.UpdateGoodsInformation(&goodInfo, item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2907. }
  2908. log := models.ExportLog{
  2909. LogType: 5,
  2910. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2911. TotalNum: int64(len(total_goods)),
  2912. FailNum: int64(len(errLogs)),
  2913. SuccessNum: int64(len(goods)),
  2914. CreateTime: time.Now().Unix(),
  2915. UpdateTime: time.Now().Unix(),
  2916. ExportTime: export_time,
  2917. Status: 1,
  2918. }
  2919. service.CreateExportLog(&log)
  2920. this.ServeSuccessJSON(map[string]interface{}{
  2921. "msg": "导入成功",
  2922. "total_num": len(total_goods),
  2923. "success_num": len(goods),
  2924. "fail_num": int64(len(errLogs)),
  2925. })
  2926. }
  2927. } else {
  2928. log := models.ExportLog{
  2929. LogType: 5,
  2930. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2931. TotalNum: int64(len(total_goods)),
  2932. FailNum: int64(len(errLogs)),
  2933. SuccessNum: int64(len(goods)),
  2934. CreateTime: time.Now().Unix(),
  2935. UpdateTime: time.Now().Unix(),
  2936. ExportTime: export_time,
  2937. Status: 1,
  2938. }
  2939. service.CreateExportLog(&log)
  2940. this.ServeSuccessJSON(map[string]interface{}{
  2941. "msg": "导入成功",
  2942. "total_num": len(total_goods),
  2943. "success_num": len(goods),
  2944. "fail_num": int64(len(errLogs)),
  2945. })
  2946. }
  2947. }
  2948. func (this *StockManagerApiController) AddDrugInformation() {
  2949. adminUser := this.GetAdminUserInfo()
  2950. orgId := adminUser.CurrentOrgId
  2951. dataBody := make(map[string]interface{}, 0)
  2952. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2953. if err != nil {
  2954. utils.ErrorLog(err.Error())
  2955. return
  2956. }
  2957. utils.ErrorLog("%v", dataBody)
  2958. var drugList []*models.BaseDrugLib
  2959. var total_goods []interface{}
  2960. tempDrugs := dataBody["drugs"].([]interface{})
  2961. total_goods = tempDrugs
  2962. for index, drugMap := range tempDrugs {
  2963. goodNameM := drugMap.(map[string]interface{})
  2964. var drug models.BaseDrugLib
  2965. if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
  2966. utils.ErrorLog("drug_name")
  2967. return
  2968. }
  2969. drug_name, _ := goodNameM["drug_name"].(string)
  2970. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2971. err_log := models.ExportErrLog{
  2972. LogType: 4,
  2973. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2974. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
  2975. Status: 1,
  2976. CreateTime: time.Now().Unix(),
  2977. UpdateTime: time.Now().Unix(),
  2978. ExportTime: time.Now().Unix(),
  2979. }
  2980. service.CreateExportErrLog(&err_log)
  2981. continue
  2982. }
  2983. drug.DrugName = drug_name
  2984. if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
  2985. utils.ErrorLog("min_number")
  2986. return
  2987. }
  2988. min_number, _ := goodNameM["min_number"].(string)
  2989. minNumber, _ := strconv.ParseInt(min_number, 10, 64)
  2990. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2991. err_log := models.ExportErrLog{
  2992. LogType: 4,
  2993. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2994. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
  2995. Status: 1,
  2996. CreateTime: time.Now().Unix(),
  2997. UpdateTime: time.Now().Unix(),
  2998. ExportTime: time.Now().Unix(),
  2999. }
  3000. service.CreateExportErrLog(&err_log)
  3001. continue
  3002. }
  3003. drug.MinNumber = minNumber
  3004. min_unit := goodNameM["min_unit"].(string)
  3005. if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
  3006. err_log := models.ExportErrLog{
  3007. LogType: 4,
  3008. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3009. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
  3010. Status: 1,
  3011. CreateTime: time.Now().Unix(),
  3012. UpdateTime: time.Now().Unix(),
  3013. ExportTime: time.Now().Unix(),
  3014. }
  3015. service.CreateExportErrLog(&err_log)
  3016. continue
  3017. }
  3018. drug.MinUnit = min_unit
  3019. dose := goodNameM["dose"].(float64)
  3020. if dose < 0 { //名字为空则生成一条导入错误日志
  3021. err_log := models.ExportErrLog{
  3022. LogType: 4,
  3023. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3024. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  3025. Status: 1,
  3026. CreateTime: time.Now().Unix(),
  3027. UpdateTime: time.Now().Unix(),
  3028. ExportTime: time.Now().Unix(),
  3029. }
  3030. service.CreateExportErrLog(&err_log)
  3031. continue
  3032. }
  3033. drug.Dose = dose
  3034. max_unit_id := goodNameM["max_unit"].(string)
  3035. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  3036. err_log := models.ExportErrLog{
  3037. LogType: 4,
  3038. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3039. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  3040. Status: 1,
  3041. CreateTime: time.Now().Unix(),
  3042. UpdateTime: time.Now().Unix(),
  3043. ExportTime: time.Now().Unix(),
  3044. }
  3045. service.CreateExportErrLog(&err_log)
  3046. continue
  3047. }
  3048. drug.MaxUnit = max_unit_id
  3049. max_unit := goodNameM["max_unit"].(string)
  3050. if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
  3051. err_log := models.ExportErrLog{
  3052. LogType: 4,
  3053. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3054. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
  3055. Status: 1,
  3056. CreateTime: time.Now().Unix(),
  3057. UpdateTime: time.Now().Unix(),
  3058. ExportTime: time.Now().Unix(),
  3059. }
  3060. service.CreateExportErrLog(&err_log)
  3061. continue
  3062. }
  3063. drug.MaxUnit = max_unit
  3064. delivery_way := goodNameM["delivery_way"].(string)
  3065. if len(delivery_way) == 0 { //名字为空则生成一条导入错误日志
  3066. err_log := models.ExportErrLog{
  3067. LogType: 4,
  3068. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3069. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认给药途径不能为空",
  3070. Status: 1,
  3071. CreateTime: time.Now().Unix(),
  3072. UpdateTime: time.Now().Unix(),
  3073. ExportTime: time.Now().Unix(),
  3074. }
  3075. service.CreateExportErrLog(&err_log)
  3076. continue
  3077. }
  3078. drug.DeliveryWay = delivery_way
  3079. execution_frequency := goodNameM["execution_frequency"].(string)
  3080. if len(execution_frequency) == 0 { //名字为空则生成一条导入错误日志
  3081. err_log := models.ExportErrLog{
  3082. LogType: 4,
  3083. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3084. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  3085. Status: 1,
  3086. CreateTime: time.Now().Unix(),
  3087. UpdateTime: time.Now().Unix(),
  3088. ExportTime: time.Now().Unix(),
  3089. }
  3090. service.CreateExportErrLog(&err_log)
  3091. continue
  3092. }
  3093. drug.ExecutionFrequency = execution_frequency
  3094. drug_day := goodNameM["drug_day"].(string)
  3095. if len(drug_day) == 0 { //名字为空则生成一条导入错误日志
  3096. err_log := models.ExportErrLog{
  3097. LogType: 4,
  3098. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3099. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  3100. Status: 1,
  3101. CreateTime: time.Now().Unix(),
  3102. UpdateTime: time.Now().Unix(),
  3103. ExportTime: time.Now().Unix(),
  3104. }
  3105. service.CreateExportErrLog(&err_log)
  3106. continue
  3107. }
  3108. drug.DrugDay = drug_day
  3109. drug_type := goodNameM["drug_type"].(string)
  3110. if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
  3111. err_log := models.ExportErrLog{
  3112. LogType: 4,
  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. var drug_type_id int64
  3124. var drugType = "药品类型"
  3125. drugconfig, _ := service.GetDrugDataConfig(0, drugType)
  3126. if len(drug_type) != 0 {
  3127. _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
  3128. if errcodes == gorm.ErrRecordNotFound {
  3129. //获取该型号最后一条数据型号
  3130. config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
  3131. dataconfig := models.DictDataconfig{
  3132. ParentId: drugconfig.ID,
  3133. Module: "system",
  3134. OrgId: orgId,
  3135. Name: drug_type,
  3136. FieldName: "",
  3137. Value: config.Value + 1,
  3138. CreatedTime: "",
  3139. UpdatedTime: "",
  3140. CreateUserId: adminUser.AdminUser.Id,
  3141. Status: 1,
  3142. Remark: "",
  3143. DeleteIdSystem: 0,
  3144. Title: "",
  3145. Content: "",
  3146. Order: 0,
  3147. Code: "",
  3148. }
  3149. service.CreatedDicConfig(&dataconfig)
  3150. }
  3151. }
  3152. drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
  3153. for _, it := range drugTypeList {
  3154. if drug_type == it.Name {
  3155. drug_type_id = int64(it.Value)
  3156. }
  3157. }
  3158. drug.DrugType = drug_type_id
  3159. drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
  3160. if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
  3161. err_log := models.ExportErrLog{
  3162. LogType: 4,
  3163. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3164. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
  3165. Status: 1,
  3166. CreateTime: time.Now().Unix(),
  3167. UpdateTime: time.Now().Unix(),
  3168. ExportTime: time.Now().Unix(),
  3169. }
  3170. service.CreateExportErrLog(&err_log)
  3171. continue
  3172. }
  3173. drug.DrugStockLimit = drug_stock_limit
  3174. drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
  3175. if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
  3176. err_log := models.ExportErrLog{
  3177. LogType: 4,
  3178. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3179. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
  3180. Status: 1,
  3181. CreateTime: time.Now().Unix(),
  3182. UpdateTime: time.Now().Unix(),
  3183. ExportTime: time.Now().Unix(),
  3184. }
  3185. service.CreateExportErrLog(&err_log)
  3186. continue
  3187. }
  3188. drug.DrugOriginPlace = drug_origin_place
  3189. drug_dosage_form := goodNameM["drug_dosage_form"].(string)
  3190. if len(drug_dosage_form) == 0 {
  3191. err_log := models.ExportErrLog{
  3192. LogType: 4,
  3193. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3194. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
  3195. Status: 1,
  3196. CreateTime: time.Now().Unix(),
  3197. UpdateTime: time.Now().Unix(),
  3198. ExportTime: time.Now().Unix(),
  3199. }
  3200. service.CreateExportErrLog(&err_log)
  3201. continue
  3202. }
  3203. var drug_dosage = "药品剂型"
  3204. var drug_dosage_form_id int64
  3205. drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
  3206. if len(drug_dosage_form) != 0 {
  3207. _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
  3208. if errcodess == gorm.ErrRecordNotFound {
  3209. configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
  3210. dataconfig := models.DictDataconfig{
  3211. ParentId: drugDosageconfig.ID,
  3212. Module: "system",
  3213. OrgId: orgId,
  3214. Name: drug_dosage_form,
  3215. FieldName: "",
  3216. Value: configOne.Value + 1,
  3217. CreatedTime: "",
  3218. UpdatedTime: "",
  3219. CreateUserId: adminUser.AdminUser.Id,
  3220. Status: 1,
  3221. Remark: "",
  3222. DeleteIdSystem: 0,
  3223. Title: "",
  3224. Content: "",
  3225. Order: 0,
  3226. Code: "",
  3227. }
  3228. service.CreatedDicConfig(&dataconfig)
  3229. }
  3230. }
  3231. drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
  3232. for _, it := range drugDosageList {
  3233. if drug_dosage_form == it.Name {
  3234. drug_dosage_form_id = int64(it.Value)
  3235. }
  3236. }
  3237. drug.DrugDosageForm = drug_dosage_form_id
  3238. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  3239. var medical_insurance_level_id int64
  3240. if len(medical_insurance_level) == 0 { //名字为空则生成一条导入错误日志
  3241. err_log := models.ExportErrLog{
  3242. LogType: 4,
  3243. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3244. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  3245. Status: 1,
  3246. CreateTime: time.Now().Unix(),
  3247. UpdateTime: time.Now().Unix(),
  3248. ExportTime: time.Now().Unix(),
  3249. }
  3250. service.CreateExportErrLog(&err_log)
  3251. continue
  3252. }
  3253. var medicalInsuranceName = "医保等级"
  3254. medicalInsuranceConfig, _ := service.GetDrugDataConfig(0, medicalInsuranceName)
  3255. if len(medical_insurance_level) != 0 {
  3256. _, errcodemedical := service.IsExistDicConfig(medicalInsuranceConfig.ID, medical_insurance_level, orgId)
  3257. if errcodemedical == gorm.ErrRecordNotFound {
  3258. medConfig, _ := service.GetLastDicConfig(medicalInsuranceConfig.ID, orgId)
  3259. dataconfig := models.DictDataconfig{
  3260. ParentId: medicalInsuranceConfig.ID,
  3261. Module: "system",
  3262. OrgId: orgId,
  3263. Name: medical_insurance_level,
  3264. FieldName: "",
  3265. Value: medConfig.Value + 1,
  3266. CreatedTime: "",
  3267. UpdatedTime: "",
  3268. CreateUserId: adminUser.AdminUser.Id,
  3269. Status: 1,
  3270. Remark: "",
  3271. DeleteIdSystem: 0,
  3272. Title: "",
  3273. Content: "",
  3274. Order: 0,
  3275. Code: "",
  3276. }
  3277. service.CreatedDicConfig(&dataconfig)
  3278. }
  3279. }
  3280. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceConfig.ID, orgId)
  3281. for _, it := range medicalInsuranceList {
  3282. if medical_insurance_level == it.Name {
  3283. medical_insurance_level_id = int64(it.Value)
  3284. }
  3285. }
  3286. drug.MedicalInsuranceLevel = medical_insurance_level_id
  3287. unit_matrixing := goodNameM["unit_matrixing"].(string)
  3288. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  3289. err_log := models.ExportErrLog{
  3290. LogType: 4,
  3291. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3292. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位换算不能为空",
  3293. Status: 1,
  3294. CreateTime: time.Now().Unix(),
  3295. UpdateTime: time.Now().Unix(),
  3296. ExportTime: time.Now().Unix(),
  3297. }
  3298. service.CreateExportErrLog(&err_log)
  3299. continue
  3300. }
  3301. drug.UnitMatrixing = unit_matrixing
  3302. retail_prices := goodNameM["retail_price"].(string)
  3303. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  3304. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  3305. err_log := models.ExportErrLog{
  3306. LogType: 4,
  3307. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3308. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
  3309. Status: 1,
  3310. CreateTime: time.Now().Unix(),
  3311. UpdateTime: time.Now().Unix(),
  3312. ExportTime: time.Now().Unix(),
  3313. }
  3314. service.CreateExportErrLog(&err_log)
  3315. continue
  3316. }
  3317. drug.RetailPrice = retail_price
  3318. packing_prices := goodNameM["packing_price"].(string)
  3319. packing_price, _ := strconv.ParseFloat(packing_prices, 64)
  3320. if packing_price <= 0 { //名字为空则生成一条导入错误日志
  3321. err_log := models.ExportErrLog{
  3322. LogType: 4,
  3323. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3324. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装零售价不能为空",
  3325. Status: 1,
  3326. CreateTime: time.Now().Unix(),
  3327. UpdateTime: time.Now().Unix(),
  3328. ExportTime: time.Now().Unix(),
  3329. }
  3330. service.CreateExportErrLog(&err_log)
  3331. continue
  3332. }
  3333. drug.RetailPrice = retail_price
  3334. last_prices := goodNameM["last_price"].(string)
  3335. last_price, _ := strconv.ParseFloat(last_prices, 64)
  3336. if last_price <= 0 { //名字为空则生成一条导入错误日志
  3337. err_log := models.ExportErrLog{
  3338. LogType: 4,
  3339. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3340. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
  3341. Status: 1,
  3342. CreateTime: time.Now().Unix(),
  3343. UpdateTime: time.Now().Unix(),
  3344. ExportTime: time.Now().Unix(),
  3345. }
  3346. service.CreateExportErrLog(&err_log)
  3347. continue
  3348. }
  3349. drug.LastPrice = last_price
  3350. drug_classify := goodNameM["drug_classify"].(string)
  3351. if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
  3352. err_log := models.ExportErrLog{
  3353. LogType: 4,
  3354. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3355. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
  3356. Status: 1,
  3357. CreateTime: time.Now().Unix(),
  3358. UpdateTime: time.Now().Unix(),
  3359. ExportTime: time.Now().Unix(),
  3360. }
  3361. service.CreateExportErrLog(&err_log)
  3362. continue
  3363. }
  3364. var drugClassify = "药物分类"
  3365. var drug_classify_id int64
  3366. drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
  3367. if len(drug_classify) != 0 {
  3368. _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
  3369. if errcodesClass == gorm.ErrRecordNotFound {
  3370. drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
  3371. dataconfig := models.DictDataconfig{
  3372. ParentId: drugClassifyConfig.ID,
  3373. Module: "system",
  3374. OrgId: orgId,
  3375. Name: drug_classify,
  3376. FieldName: "",
  3377. Value: drugClassConfig.Value + 1,
  3378. CreatedTime: "",
  3379. UpdatedTime: "",
  3380. CreateUserId: adminUser.AdminUser.Id,
  3381. Status: 1,
  3382. Remark: "",
  3383. DeleteIdSystem: 0,
  3384. Title: "",
  3385. Content: "",
  3386. Order: 0,
  3387. Code: "",
  3388. }
  3389. service.CreatedDicConfig(&dataconfig)
  3390. }
  3391. }
  3392. drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
  3393. for _, it := range drugClassList {
  3394. if drug_classify == it.Name {
  3395. drug_classify_id = int64(it.Value)
  3396. }
  3397. }
  3398. drug_dose := goodNameM["drug_dose"].(string)
  3399. if len(drug_dose) == 0 {
  3400. err_log := models.ExportErrLog{
  3401. LogType: 4,
  3402. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3403. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
  3404. Status: 1,
  3405. CreateTime: time.Now().Unix(),
  3406. UpdateTime: time.Now().Unix(),
  3407. ExportTime: time.Now().Unix(),
  3408. }
  3409. service.CreateExportErrLog(&err_log)
  3410. continue
  3411. }
  3412. drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
  3413. drug.DrugDose = drugDoses
  3414. var units = "单位"
  3415. var unit_id int64
  3416. drugDoseUnit := goodNameM["drug_dose_unit"].(string)
  3417. if len(drugDoseUnit) == 0 {
  3418. err_log := models.ExportErrLog{
  3419. LogType: 4,
  3420. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3421. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
  3422. Status: 1,
  3423. CreateTime: time.Now().Unix(),
  3424. UpdateTime: time.Now().Unix(),
  3425. ExportTime: time.Now().Unix(),
  3426. }
  3427. service.CreateExportErrLog(&err_log)
  3428. continue
  3429. }
  3430. dataConfig, _ := service.GetDataConfigIsExist(0, units)
  3431. if len(drugDoseUnit) != 0 {
  3432. _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
  3433. if errcodedataconfig == gorm.ErrRecordNotFound {
  3434. childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
  3435. dataconfig := models.Dataconfig{
  3436. ParentId: dataConfig.ID,
  3437. Module: "hemodialysis",
  3438. OrgId: orgId,
  3439. Name: drugDoseUnit,
  3440. FieldName: "",
  3441. Value: childConfig.Value + 1,
  3442. CreatedTime: "",
  3443. UpdatedTime: "",
  3444. CreateUserId: adminUser.AdminUser.Id,
  3445. Status: 1,
  3446. Remark: "",
  3447. DeleteIdSystem: 0,
  3448. Title: "",
  3449. Content: "",
  3450. Order: 0,
  3451. Code: "",
  3452. FieldType: 0,
  3453. }
  3454. service.CreateDataConfig(&dataconfig)
  3455. }
  3456. }
  3457. list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
  3458. for _, it := range list {
  3459. if drugDoseUnit == it.Name {
  3460. unit_id = int64(it.Value)
  3461. }
  3462. }
  3463. drug.DrugDoseUnit = unit_id
  3464. drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
  3465. manufacturer := goodNameM["manufacturer"].(string)
  3466. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  3467. err_log := models.ExportErrLog{
  3468. LogType: 4,
  3469. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3470. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
  3471. Status: 1,
  3472. CreateTime: time.Now().Unix(),
  3473. UpdateTime: time.Now().Unix(),
  3474. ExportTime: time.Now().Unix(),
  3475. }
  3476. service.CreateExportErrLog(&err_log)
  3477. continue
  3478. }
  3479. if len(manufacturer) != 0 {
  3480. _, errcodema := service.GetManufacturerName(orgId, manufacturer)
  3481. if errcodema == gorm.ErrRecordNotFound {
  3482. manufactur := models.Manufacturer{
  3483. OrgId: orgId,
  3484. Status: 1,
  3485. ManufacturerName: manufacturer,
  3486. Ctime: time.Now().Unix(),
  3487. Creater: adminUser.AdminUser.Id,
  3488. }
  3489. service.CreateManufacturer(&manufactur)
  3490. }
  3491. }
  3492. var manufacturer_id int64
  3493. manufacturList, _ := service.GetAllManufacturerList(orgId)
  3494. for _, it := range manufacturList {
  3495. if manufacturer == it.ManufacturerName {
  3496. manufacturer_id = it.ID
  3497. }
  3498. }
  3499. drug.Manufacturer = manufacturer_id
  3500. dealer := goodNameM["dealer"].(string)
  3501. if len(dealer) != 0 {
  3502. _, errcodesdealer := service.GetDealerByName(orgId, dealer)
  3503. if errcodesdealer == gorm.ErrRecordNotFound {
  3504. dealerconfig := models.Dealer{
  3505. DealerName: dealer,
  3506. Status: 1,
  3507. OrgId: orgId,
  3508. Ctime: time.Now().Unix(),
  3509. Creater: adminUser.AdminUser.Id,
  3510. }
  3511. service.CreateDealer(&dealerconfig)
  3512. }
  3513. }
  3514. var dealer_id int64
  3515. dealerList, _ := service.GetAllDealerList(orgId)
  3516. for _, it := range dealerList {
  3517. if dealer == it.DealerName {
  3518. dealer_id = it.ID
  3519. }
  3520. }
  3521. drug.Dealer = dealer_id
  3522. lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
  3523. drug.LmtUsedFlag = lmt_used_flags
  3524. if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
  3525. utils.ErrorLog("drug_alias")
  3526. return
  3527. }
  3528. drug_alias, _ := goodNameM["drug_alias"].(string)
  3529. drug.DrugAlias = drug_alias
  3530. drug_category := goodNameM["drug_category"].(string)
  3531. var drugCategory = "药品类别"
  3532. var drug_category_id int64
  3533. drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
  3534. if len(drug_category) != 0 {
  3535. _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
  3536. if drugcategoryerrcodes == gorm.ErrRecordNotFound {
  3537. drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
  3538. dataconfig := models.DictDataconfig{
  3539. ParentId: drugCategoryConfig.ID,
  3540. Module: "system",
  3541. OrgId: orgId,
  3542. Name: drug_category,
  3543. FieldName: "",
  3544. Value: drugCategoryConfigSix.Value + 1,
  3545. CreatedTime: "",
  3546. UpdatedTime: "",
  3547. CreateUserId: adminUser.AdminUser.Id,
  3548. Status: 1,
  3549. Remark: "",
  3550. DeleteIdSystem: 0,
  3551. Title: "",
  3552. Content: "",
  3553. Order: 0,
  3554. Code: "",
  3555. }
  3556. service.CreatedDicConfig(&dataconfig)
  3557. }
  3558. }
  3559. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
  3560. fmt.Println("drugCategoryList", drugCategoryList)
  3561. for _, it := range drugCategoryList {
  3562. if drug_category == it.Name {
  3563. drug_category_id = int64(it.Value)
  3564. }
  3565. }
  3566. drug.DrugCategory = drug_category_id
  3567. statistics_category := goodNameM["statistics_category"].(string)
  3568. var statisticsCategory = "统计分类"
  3569. var statistics_category_id int64
  3570. statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3571. if len(statistics_category) != 0 {
  3572. _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
  3573. if errcodestatistc == gorm.ErrRecordNotFound {
  3574. staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
  3575. dataconfig := models.DictDataconfig{
  3576. ParentId: statistcConfig.ID,
  3577. Module: "system",
  3578. OrgId: orgId,
  3579. Name: statistics_category,
  3580. FieldName: "",
  3581. Value: staConfig.Value + 1,
  3582. CreatedTime: "",
  3583. UpdatedTime: "",
  3584. CreateUserId: adminUser.AdminUser.Id,
  3585. Status: 1,
  3586. Remark: "",
  3587. DeleteIdSystem: 0,
  3588. Title: "",
  3589. Content: "",
  3590. Order: 0,
  3591. Code: "",
  3592. }
  3593. service.CreatedDicConfig(&dataconfig)
  3594. }
  3595. }
  3596. statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
  3597. for _, it := range statisticsCategoryList {
  3598. if statistics_category == it.Name {
  3599. statistics_category_id = int64(it.Value)
  3600. }
  3601. }
  3602. drug.StatisticsCategory = statistics_category_id
  3603. number := goodNameM["number"].(string)
  3604. drug.Number = number
  3605. hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
  3606. drug.HospApprFlag = hosp_appr_flag
  3607. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  3608. drug.MedicalInsuranceNumber = medical_insurance_number
  3609. pharmacology_category := goodNameM["pharmacology_category"].(string)
  3610. var pharmacology = "药理分类"
  3611. var pharmacology_category_id int64
  3612. pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
  3613. if len(pharmacology_category) != 0 {
  3614. _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
  3615. if errcodespharmacology == gorm.ErrRecordNotFound {
  3616. dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
  3617. dataconfig := models.DictDataconfig{
  3618. ParentId: pharmacologyConfig.ID,
  3619. Module: "system",
  3620. OrgId: orgId,
  3621. Name: pharmacology_category,
  3622. FieldName: "",
  3623. Value: dicConfig.Value + 1,
  3624. CreatedTime: "",
  3625. UpdatedTime: "",
  3626. CreateUserId: adminUser.AdminUser.Id,
  3627. Status: 1,
  3628. Remark: "",
  3629. DeleteIdSystem: 0,
  3630. Title: "",
  3631. Content: "",
  3632. Order: 0,
  3633. Code: "",
  3634. }
  3635. service.CreatedDicConfig(&dataconfig)
  3636. }
  3637. }
  3638. pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
  3639. for _, it := range pharmacologyList {
  3640. if pharmacology_category == it.Name {
  3641. pharmacology_category_id = int64(it.Value)
  3642. }
  3643. }
  3644. drug.PharmacologyCategory = pharmacology_category_id
  3645. code := goodNameM["code"].(string)
  3646. drug.Code = code
  3647. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  3648. drug.IsSpecialDiseases = is_special_diseases
  3649. is_record := int64(goodNameM["is_record"].(float64))
  3650. drug.IsRecord = is_record
  3651. prescription_mark := int64(goodNameM["prescription_mark"].(float64))
  3652. drug.PrescriptionMark = prescription_mark
  3653. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  3654. drug.SocialSecurityDirectoryCode = social_security_directory_code
  3655. record_date := goodNameM["record_date"].(string)
  3656. timeLayout := "2006-01-02"
  3657. loc, _ := time.LoadLocation("Local")
  3658. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3659. drug.RecordDate = theTime.Unix()
  3660. drug_remark := goodNameM["drug_remark"].(string)
  3661. drug.DrugRemark = drug_remark
  3662. drug_status := goodNameM["drug_status"].(string)
  3663. drug.DrugStatus = drug_status
  3664. limit_remark := goodNameM["limit_remark"].(string)
  3665. drug.LimitRemark = limit_remark
  3666. drug_control := goodNameM["drug_control"].(string)
  3667. var drugControl = "开药控制"
  3668. var drug_control_id int64
  3669. drugContorlConfig, _ := service.GetDrugDataConfig(0, drugControl)
  3670. if len(drug_control) != 0 {
  3671. _, errcodesdrugcontrol := service.IsExistDicConfig(drugContorlConfig.ID, drug_control, orgId)
  3672. if errcodesdrugcontrol == gorm.ErrRecordNotFound {
  3673. drugContorlConfigOne, _ := service.GetLastDicConfig(drugContorlConfig.ID, orgId)
  3674. dataconfig := models.DictDataconfig{
  3675. ParentId: drugContorlConfig.ID,
  3676. Module: "system",
  3677. OrgId: orgId,
  3678. Name: drug_control,
  3679. FieldName: "",
  3680. Value: drugContorlConfigOne.Value + 1,
  3681. CreatedTime: "",
  3682. UpdatedTime: "",
  3683. CreateUserId: adminUser.AdminUser.Id,
  3684. Status: 1,
  3685. Remark: "",
  3686. DeleteIdSystem: 0,
  3687. Title: "",
  3688. Content: "",
  3689. Order: 0,
  3690. Code: "",
  3691. }
  3692. service.CreatedDicConfig(&dataconfig)
  3693. }
  3694. }
  3695. drugContorlList, _ := service.GetParentDataConfig(drugContorlConfig.ID, orgId)
  3696. for _, it := range drugContorlList {
  3697. if drug_control == it.Name {
  3698. drug_control_id = int64(it.Value)
  3699. }
  3700. }
  3701. drug.DrugControl = drug_control_id
  3702. drugList = append(drugList, &drug)
  3703. }
  3704. export_time := time.Now().Unix()
  3705. errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3706. if len(drugList) > 0 {
  3707. for _, item := range drugList {
  3708. goodInfo := models.BaseDrugLib{
  3709. DrugName: item.DrugName,
  3710. DrugAlias: item.DrugAlias,
  3711. DrugSpec: item.DrugSpec,
  3712. DrugType: item.DrugType,
  3713. DrugStockLimit: item.DrugStockLimit,
  3714. DrugOriginPlace: item.DrugOriginPlace,
  3715. DrugDosageForm: item.DrugDosageForm,
  3716. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  3717. MaxUnit: item.MaxUnit,
  3718. MinUnit: item.MinUnit,
  3719. UnitMatrixing: item.UnitMatrixing,
  3720. RetailPrice: item.RetailPrice,
  3721. LastPrice: item.LastPrice,
  3722. DrugClassify: item.DrugClassify,
  3723. Manufacturer: item.Manufacturer,
  3724. Dealer: item.Dealer,
  3725. OrgId: orgId,
  3726. Status: 1,
  3727. Ctime: time.Now().Unix(),
  3728. Pinyin: item.Pinyin,
  3729. Wubi: item.Wubi,
  3730. DrugAliasPinyin: item.DrugAliasPinyin,
  3731. DrugAliasWubi: item.DrugAliasWubi,
  3732. DrugControl: item.DrugControl,
  3733. Number: item.Number,
  3734. HospApprFlag: item.HospApprFlag,
  3735. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  3736. PharmacologyCategory: item.PharmacologyCategory,
  3737. StatisticsCategory: item.StatisticsCategory,
  3738. Code: item.Code,
  3739. IsSpecialDiseases: item.IsSpecialDiseases,
  3740. IsRecord: item.IsRecord,
  3741. PrescriptionMark: item.PrescriptionMark,
  3742. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3743. RecordDate: item.RecordDate,
  3744. DrugRemark: item.DrugRemark,
  3745. DrugStatus: item.DrugStatus,
  3746. LimitRemark: item.LimitRemark,
  3747. DrugCategory: item.DrugCategory,
  3748. DrugDose: item.DrugDose,
  3749. DrugDoseUnit: item.DrugDoseUnit,
  3750. LmtUsedFlag: item.LmtUsedFlag,
  3751. DrugDay: item.DrugDay,
  3752. DeliveryWay: item.DeliveryWay,
  3753. ExecutionFrequency: item.ExecutionFrequency,
  3754. DoseUnit: item.DoseUnit,
  3755. }
  3756. //查询同种药品同种规格是否存在
  3757. _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.MaxUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
  3758. if drugerror == gorm.ErrRecordNotFound {
  3759. service.CreateDrugsInfomation(&goodInfo)
  3760. } else if drugerror == nil {
  3761. service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
  3762. }
  3763. log := models.ExportLog{
  3764. LogType: 4,
  3765. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3766. TotalNum: int64(len(total_goods)),
  3767. FailNum: int64(len(errLogs)),
  3768. SuccessNum: int64(len(drugList)),
  3769. CreateTime: time.Now().Unix(),
  3770. UpdateTime: time.Now().Unix(),
  3771. ExportTime: export_time,
  3772. Status: 1,
  3773. }
  3774. service.CreateExportLog(&log)
  3775. this.ServeSuccessJSON(map[string]interface{}{
  3776. "msg": "导入成功",
  3777. "total_num": len(total_goods),
  3778. "success_num": len(drugList),
  3779. "fail_num": int64(len(errLogs)),
  3780. })
  3781. }
  3782. } else {
  3783. log := models.ExportLog{
  3784. LogType: 4,
  3785. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3786. TotalNum: int64(len(total_goods)),
  3787. FailNum: int64(len(errLogs)),
  3788. SuccessNum: int64(len(drugList)),
  3789. CreateTime: time.Now().Unix(),
  3790. UpdateTime: time.Now().Unix(),
  3791. ExportTime: export_time,
  3792. Status: 1,
  3793. }
  3794. service.CreateExportLog(&log)
  3795. this.ServeSuccessJSON(map[string]interface{}{
  3796. "msg": "导入成功",
  3797. "total_num": len(total_goods),
  3798. "success_num": len(drugList),
  3799. "fail_num": int64(len(errLogs)),
  3800. })
  3801. }
  3802. }
  3803. func (this *StockManagerApiController) GetInitializtion() {
  3804. orgId := this.GetAdminUserInfo().CurrentOrgId
  3805. var drugCategory = "药品类别"
  3806. var drugType = "药品类型"
  3807. var drugDosageForm = "药品剂型"
  3808. var medicalInsuranceLevel = "医保等级"
  3809. var drugControl = "开药控制"
  3810. var drugClassify = "药物分类"
  3811. var statisticsCategory = "统计分类"
  3812. var pharmacologyCategory = "药理分类"
  3813. var goodKind = "耗材种类"
  3814. var tubeColor = "试管颜色"
  3815. var costClassify = "费用类别"
  3816. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3817. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3818. drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
  3819. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
  3820. drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
  3821. drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
  3822. medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
  3823. medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
  3824. drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
  3825. drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
  3826. drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
  3827. drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
  3828. statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3829. statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
  3830. pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
  3831. pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
  3832. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  3833. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
  3834. tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
  3835. tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
  3836. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  3837. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
  3838. this.ServeSuccessJSON(map[string]interface{}{
  3839. "drugCategoryList": drugCategoryList,
  3840. "drugTypeList": drugTypeList,
  3841. "drugDosageFormList": drugDosageFormList,
  3842. "medicalInsuranceLevelList": medicalInsuranceLevelList,
  3843. "drugControlList": drugControlList,
  3844. "drugClassifyList": drugClassifyList,
  3845. "statisticsCategoryList": statisticsCategoryList,
  3846. "pharmacologyCategoryList": pharmacologyCategoryList,
  3847. "goodKindList": goodKindList,
  3848. "tubeColorList": tubeColorList,
  3849. "costClassifyList": costClassifyList,
  3850. })
  3851. }
  3852. func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
  3853. adminUserInfo := this.GetAdminUserInfo()
  3854. orgId := adminUserInfo.CurrentOrgId
  3855. list, _ := service.GetWarehouseOrderInfoList(orgId)
  3856. this.ServeSuccessJSON(map[string]interface{}{
  3857. "list": list,
  3858. })
  3859. }
  3860. func (this *StockManagerApiController) PostSearchGoodList() {
  3861. keyword := this.GetString("keyword")
  3862. adminUserInfo := this.GetAdminUserInfo()
  3863. orgId := adminUserInfo.CurrentOrgId
  3864. list, _ := service.GetSearchGoodList(keyword, orgId)
  3865. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3866. dealerList, _ := service.GetAllDealerList(orgId)
  3867. this.ServeSuccessJSON(map[string]interface{}{
  3868. "list": list,
  3869. "manufacturerList": manufacturerList,
  3870. "dealerList": dealerList,
  3871. })
  3872. }
  3873. func (this *StockManagerApiController) GetAllStockList() {
  3874. page, _ := this.GetInt64("page", -1)
  3875. limit, _ := this.GetInt64("limit", -1)
  3876. start_time := this.GetString("start_time")
  3877. end_time := this.GetString("end_time")
  3878. types, _ := this.GetInt64("type", 0)
  3879. keywords := this.GetString("keywords")
  3880. timeLayout := "2006-01-02"
  3881. loc, _ := time.LoadLocation("Local")
  3882. var startTime int64
  3883. if len(start_time) > 0 {
  3884. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3885. if err != nil {
  3886. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3887. return
  3888. }
  3889. startTime = theTime.Unix()
  3890. }
  3891. var endTime int64
  3892. if len(end_time) > 0 {
  3893. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3894. if err != nil {
  3895. utils.ErrorLog(err.Error())
  3896. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3897. return
  3898. }
  3899. endTime = theTime.Unix()
  3900. }
  3901. adminUserInfo := this.GetAdminUserInfo()
  3902. orgId := adminUserInfo.CurrentOrgId
  3903. list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId)
  3904. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3905. this.ServeSuccessJSON(map[string]interface{}{
  3906. "list": list,
  3907. "total": total,
  3908. "manufacturerList": manufacturerList,
  3909. })
  3910. }
  3911. func (this *StockManagerApiController) GetStockListById() {
  3912. id, _ := this.GetInt64("id")
  3913. adminUserInfo := this.GetAdminUserInfo()
  3914. orgId := adminUserInfo.CurrentOrgId
  3915. limit, _ := this.GetInt64("limit")
  3916. page, _ := this.GetInt64("page")
  3917. timeLayout := "2006-01-02"
  3918. loc, _ := time.LoadLocation("Local")
  3919. start_time := this.GetString("start_time")
  3920. end_time := this.GetString("end_time")
  3921. var startTime int64
  3922. if len(start_time) > 0 {
  3923. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3924. if err != nil {
  3925. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3926. return
  3927. }
  3928. startTime = theTime.Unix()
  3929. }
  3930. var endTime int64
  3931. if len(end_time) > 0 {
  3932. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3933. if err != nil {
  3934. utils.ErrorLog(err.Error())
  3935. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3936. return
  3937. }
  3938. endTime = theTime.Unix()
  3939. }
  3940. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3941. list, total, _ := service.GetStockListById(id, orgId, limit, page, startTime, endTime)
  3942. this.ServeSuccessJSON(map[string]interface{}{
  3943. "list": list,
  3944. "total": total,
  3945. "manufacturerList": manufacturerList,
  3946. })
  3947. }
  3948. func (this *StockManagerApiController) GetStockOutList() {
  3949. id, _ := this.GetInt64("id")
  3950. adminUserInfo := this.GetAdminUserInfo()
  3951. orgId := adminUserInfo.CurrentOrgId
  3952. limit, _ := this.GetInt64("limit")
  3953. page, _ := this.GetInt64("page")
  3954. timeLayout := "2006-01-02"
  3955. loc, _ := time.LoadLocation("Local")
  3956. start_time := this.GetString("start_time")
  3957. end_time := this.GetString("end_time")
  3958. is_sys, _ := this.GetInt64("is_sys")
  3959. var startTime int64
  3960. if len(start_time) > 0 {
  3961. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3962. if err != nil {
  3963. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3964. return
  3965. }
  3966. startTime = theTime.Unix()
  3967. }
  3968. var endTime int64
  3969. if len(end_time) > 0 {
  3970. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3971. if err != nil {
  3972. utils.ErrorLog(err.Error())
  3973. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3974. return
  3975. }
  3976. endTime = theTime.Unix()
  3977. }
  3978. outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
  3979. this.ServeSuccessJSON(map[string]interface{}{
  3980. "outList": outList,
  3981. "total": total,
  3982. })
  3983. }
  3984. func (this *StockManagerApiController) GetStockDrugCount() {
  3985. adminUserInfo := this.GetAdminUserInfo()
  3986. orgId := adminUserInfo.CurrentOrgId
  3987. fmt.Println(orgId)
  3988. timeLayout := "2006-01-02"
  3989. loc, _ := time.LoadLocation("Local")
  3990. start_time := this.GetString("start_time")
  3991. end_time := this.GetString("end_time")
  3992. var startTime int64
  3993. if len(start_time) > 0 {
  3994. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3995. if err != nil {
  3996. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3997. return
  3998. }
  3999. startTime = theTime.Unix()
  4000. }
  4001. var endTime int64
  4002. if len(end_time) > 0 {
  4003. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4004. if err != nil {
  4005. utils.ErrorLog(err.Error())
  4006. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4007. return
  4008. }
  4009. endTime = theTime.Unix()
  4010. }
  4011. count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
  4012. outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
  4013. autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
  4014. totalCount, _ := service.GetCancelOutTotalCount(startTime, endTime, orgId)
  4015. this.ServeSuccessJSON(map[string]interface{}{
  4016. "count": count,
  4017. "outList": outList,
  4018. "autoCount": autoCount,
  4019. "totalCount": totalCount,
  4020. })
  4021. }
  4022. func (this *StockManagerApiController) GetOrderDetialByOrderId() {
  4023. ids := this.GetString("id")
  4024. idsArray := strings.Split(ids, ",")
  4025. orgId := this.GetAdminUserInfo().CurrentOrgId
  4026. list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
  4027. this.ServeSuccessJSON(map[string]interface{}{
  4028. "list": list,
  4029. })
  4030. }
  4031. func (this *StockManagerApiController) GetOrderDetailById() {
  4032. id, _ := this.GetInt64("id")
  4033. good_id, _ := this.GetInt64("good_id")
  4034. record_time, _ := this.GetInt64("record_time")
  4035. orgId := this.GetAdminUserInfo().CurrentOrgId
  4036. //自动出库
  4037. userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
  4038. //手动出库
  4039. info, _ := service.GetWarehouseOutInfoById(id, good_id)
  4040. stockFlowList, err := service.GetStockFlowBatchNumberOne(id, good_id)
  4041. if err == nil {
  4042. this.ServeSuccessJSON(map[string]interface{}{
  4043. "list": userDetails,
  4044. "total": total,
  4045. "info": info,
  4046. "stockFlowList": stockFlowList,
  4047. })
  4048. } else {
  4049. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4050. return
  4051. }
  4052. }
  4053. func (this *StockManagerApiController) GetSingleOutOrderDetail() {
  4054. id, _ := this.GetInt64("id", 0)
  4055. orgId := this.GetAdminUserInfo().CurrentOrgId
  4056. warehouseOutInfo, _ := service.GetOrderDetialByOrderId(id, orgId)
  4057. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4058. dealerList, _ := service.GetAllDealerList(orgId)
  4059. goodType, _ := service.GetAllGoodType(orgId)
  4060. this.ServeSuccessJSON(map[string]interface{}{
  4061. "list": warehouseOutInfo,
  4062. "dealerList": dealerList,
  4063. "manufacturerList": manufacturerList,
  4064. "goodType": goodType,
  4065. })
  4066. }
  4067. func (this *StockManagerApiController) GetExprotStockList() {
  4068. adminUserInfo := this.GetAdminUserInfo()
  4069. orgId := adminUserInfo.CurrentOrgId
  4070. timeLayout := "2006-01-02"
  4071. loc, _ := time.LoadLocation("Local")
  4072. start_time := this.GetString("start_time")
  4073. end_time := this.GetString("end_time")
  4074. idArray := this.GetString("id")
  4075. ids := strings.Split(idArray, ",")
  4076. var startTime int64
  4077. if len(start_time) > 0 {
  4078. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4079. if err != nil {
  4080. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4081. return
  4082. }
  4083. startTime = theTime.Unix()
  4084. }
  4085. var endTime int64
  4086. if len(end_time) > 0 {
  4087. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4088. if err != nil {
  4089. utils.ErrorLog(err.Error())
  4090. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4091. return
  4092. }
  4093. endTime = theTime.Unix()
  4094. }
  4095. fmt.Println("ids2222222222222222", ids)
  4096. list, _ := service.GetExprotStockList(orgId, ids, startTime, endTime)
  4097. this.ServeSuccessJSON(map[string]interface{}{
  4098. "list": list,
  4099. })
  4100. }
  4101. func (this *StockManagerApiController) GetOutExprotList() {
  4102. adminUserInfo := this.GetAdminUserInfo()
  4103. orgId := adminUserInfo.CurrentOrgId
  4104. timeLayout := "2006-01-02"
  4105. loc, _ := time.LoadLocation("Local")
  4106. start_time := this.GetString("start_time")
  4107. end_time := this.GetString("end_time")
  4108. idArray := this.GetString("id")
  4109. ids := strings.Split(idArray, ",")
  4110. fmt.Println("ids2222222222", ids)
  4111. var startTime int64
  4112. if len(start_time) > 0 {
  4113. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4114. if err != nil {
  4115. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4116. return
  4117. }
  4118. startTime = theTime.Unix()
  4119. }
  4120. var endTime int64
  4121. if len(end_time) > 0 {
  4122. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4123. if err != nil {
  4124. utils.ErrorLog(err.Error())
  4125. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4126. return
  4127. }
  4128. endTime = theTime.Unix()
  4129. }
  4130. list, _ := service.GetOutExprotList(orgId, ids, startTime, endTime)
  4131. outCount, _ := service.GetOutStockTotalCountOne(startTime, endTime, orgId)
  4132. this.ServeSuccessJSON(map[string]interface{}{
  4133. "list": list,
  4134. "count": outCount,
  4135. })
  4136. }
  4137. func (this *StockManagerApiController) GetSingleCancelOrder() {
  4138. id, _ := this.GetInt64("id")
  4139. adminUserInfo := this.GetAdminUserInfo()
  4140. orgId := adminUserInfo.CurrentOrgId
  4141. order, _ := service.GetSingleCancelOrder(id, orgId)
  4142. this.ServeSuccessJSON(map[string]interface{}{
  4143. "list": order,
  4144. })
  4145. }
  4146. func (this *StockManagerApiController) GetCancelStockOrderPrint() {
  4147. id := this.GetString("id")
  4148. idStr := strings.Split(id, ",")
  4149. orgId := this.GetAdminUserInfo().CurrentOrgId
  4150. list, _ := service.GetCancelStockOrderPrintOne(idStr, orgId)
  4151. this.ServeSuccessJSON(map[string]interface{}{
  4152. "list": list,
  4153. })
  4154. }
  4155. func (this *StockManagerApiController) GetStockBatchNumber() {
  4156. id, _ := this.GetInt64("id")
  4157. orgId := this.GetAdminUserInfo().CurrentOrgId
  4158. list, _ := service.GetStockBatchNumber(id, orgId)
  4159. this.ServeSuccessJSON(map[string]interface{}{
  4160. "list": list,
  4161. })
  4162. }
  4163. func (this *StockManagerApiController) GetStockFlow() {
  4164. limit, _ := this.GetInt64("limit")
  4165. page, _ := this.GetInt64("page")
  4166. good_id, _ := this.GetInt64("good_id")
  4167. consumable_type, _ := this.GetInt64("is_sys")
  4168. adminUserInfo := this.GetAdminUserInfo()
  4169. orgId := adminUserInfo.CurrentOrgId
  4170. timeLayout := "2006-01-02"
  4171. loc, _ := time.LoadLocation("Local")
  4172. start_time := this.GetString("start_time")
  4173. end_time := this.GetString("end_time")
  4174. var startTime int64
  4175. if len(start_time) > 0 {
  4176. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4177. if err != nil {
  4178. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4179. return
  4180. }
  4181. startTime = theTime.Unix()
  4182. }
  4183. var endTime int64
  4184. if len(end_time) > 0 {
  4185. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4186. if err != nil {
  4187. utils.ErrorLog(err.Error())
  4188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4189. return
  4190. }
  4191. endTime = theTime.Unix()
  4192. }
  4193. list, total, _ := service.GetStockFlowList(limit, page, consumable_type, orgId, startTime, endTime, good_id)
  4194. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4195. this.ServeSuccessJSON(map[string]interface{}{
  4196. "list": list,
  4197. "total": total,
  4198. "manufacturerList": manufacturerList,
  4199. })
  4200. }
  4201. func (this *StockManagerApiController) GetCancelExportList() {
  4202. adminUserInfo := this.GetAdminUserInfo()
  4203. orgId := adminUserInfo.CurrentOrgId
  4204. timeLayout := "2006-01-02"
  4205. loc, _ := time.LoadLocation("Local")
  4206. start_time := this.GetString("start_time")
  4207. end_time := this.GetString("end_time")
  4208. idArray := this.GetString("order_id")
  4209. fmt.Println("232323232323232232", idArray)
  4210. ids := strings.Split(idArray, ",")
  4211. var startTime int64
  4212. if len(start_time) > 0 {
  4213. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4214. if err != nil {
  4215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4216. return
  4217. }
  4218. startTime = theTime.Unix()
  4219. }
  4220. var endTime int64
  4221. if len(end_time) > 0 {
  4222. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4223. if err != nil {
  4224. utils.ErrorLog(err.Error())
  4225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4226. return
  4227. }
  4228. endTime = theTime.Unix()
  4229. }
  4230. list, _ := service.GetCancelExportList(startTime, endTime, ids, orgId)
  4231. this.ServeSuccessJSON(map[string]interface{}{
  4232. "list": list,
  4233. })
  4234. }
  4235. func (this *StockManagerApiController) GetSearchGoodWarehouseList() {
  4236. keyword := this.GetString("keyword")
  4237. orgId := this.GetAdminUserInfo().CurrentOrgId
  4238. list, _ := service.GetSearchGoodWarehouseList(keyword, orgId)
  4239. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  4240. dealerList, _ := service.GetAllDealerList(orgId)
  4241. this.ServeSuccessJSON(map[string]interface{}{
  4242. "list": list,
  4243. "manufacturerList": manufacturerList,
  4244. "dealerList": dealerList,
  4245. })
  4246. }
  4247. func (this *StockManagerApiController) SaveAdjuestPrice() {
  4248. timeLayout := "2006-01-02"
  4249. loc, _ := time.LoadLocation("Local")
  4250. dataBody := make(map[string]interface{}, 0)
  4251. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4252. if err != nil {
  4253. utils.ErrorLog(err.Error())
  4254. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4255. return
  4256. }
  4257. tableData, _ := dataBody["tableData"].([]interface{})
  4258. if len(tableData) > 0 {
  4259. for _, item := range tableData {
  4260. items := item.(map[string]interface{})
  4261. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4262. utils.ErrorLog("good_name")
  4263. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4264. return
  4265. }
  4266. good_name := items["good_name"].(string)
  4267. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4268. utils.ErrorLog("good_name")
  4269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4270. return
  4271. }
  4272. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4273. utils.ErrorLog("packing_price")
  4274. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4275. return
  4276. }
  4277. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4278. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4279. utils.ErrorLog("warehousing_order")
  4280. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4281. return
  4282. }
  4283. warehousing_order := items["warehousing_order"].(string)
  4284. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4285. utils.ErrorLog("license_number")
  4286. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4287. return
  4288. }
  4289. license_number := items["license_number"].(string)
  4290. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4291. utils.ErrorLog("dealer")
  4292. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4293. return
  4294. }
  4295. dealer := items["dealer"].(string)
  4296. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4297. utils.ErrorLog("manufacturer")
  4298. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4299. return
  4300. }
  4301. manufacturer := items["manufacturer"].(string)
  4302. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4303. utils.ErrorLog("specification_name")
  4304. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4305. return
  4306. }
  4307. specification_name := items["specification_name"].(string)
  4308. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4309. utils.ErrorLog("remark")
  4310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4311. return
  4312. }
  4313. remark := items["remark"].(string)
  4314. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4315. utils.ErrorLog("warehousing_unit")
  4316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4317. return
  4318. }
  4319. warehousing_unit := items["warehousing_unit"].(string)
  4320. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4321. utils.ErrorLog("buy_price")
  4322. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4323. return
  4324. }
  4325. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4326. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4327. utils.ErrorLog("count")
  4328. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4329. return
  4330. }
  4331. count := int64(items["count"].(float64))
  4332. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  4333. utils.ErrorLog("new_price")
  4334. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4335. return
  4336. }
  4337. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  4338. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4339. utils.ErrorLog("good_id")
  4340. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4341. return
  4342. }
  4343. good_id := int64(items["good_id"].(float64))
  4344. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4345. utils.ErrorLog("start_time")
  4346. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4347. return
  4348. }
  4349. var startTime int64
  4350. start_time := items["start_time"].(string)
  4351. if len(start_time) > 0 {
  4352. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4353. if err != nil {
  4354. fmt.Println(err)
  4355. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4356. return
  4357. }
  4358. startTime = theTime.Unix()
  4359. }
  4360. orgId := this.GetAdminUserInfo().CurrentOrgId
  4361. adjustprice := models.XtStockAdjustPrice{
  4362. GoodName: good_name,
  4363. SpecificationName: specification_name,
  4364. WarehousingUnit: warehousing_unit,
  4365. Count: count,
  4366. BuyPrice: buy_price,
  4367. PackingPrice: packing_price,
  4368. NewPrice: new_price,
  4369. Manufacturer: manufacturer,
  4370. Dealer: dealer,
  4371. Remark: remark,
  4372. GoodId: good_id,
  4373. UserOrgId: orgId,
  4374. Ctime: time.Now().Unix(),
  4375. Mtime: 0,
  4376. Status: 1,
  4377. WarehousingOrder: warehousing_order,
  4378. LicenseNumber: license_number,
  4379. StartTime: startTime,
  4380. Creater: this.GetAdminUserInfo().AdminUser.Id,
  4381. CheckerStatus: 2,
  4382. }
  4383. service.CreateAdjustPrice(&adjustprice)
  4384. }
  4385. }
  4386. this.ServeSuccessJSON(map[string]interface{}{
  4387. "msg": "保存成功!",
  4388. })
  4389. }
  4390. func (this *StockManagerApiController) GetAllStockPrice() {
  4391. timeLayout := "2006-01-02"
  4392. loc, _ := time.LoadLocation("Local")
  4393. dataBody := make(map[string]interface{}, 0)
  4394. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4395. fmt.Println(err)
  4396. orgId := this.GetAdminUserInfo().CurrentOrgId
  4397. keyword := this.GetString("keyword")
  4398. start_time := this.GetString("start_time")
  4399. end_time := this.GetString("end_time")
  4400. limit, _ := this.GetInt64("limit")
  4401. page, _ := this.GetInt64("page")
  4402. var startTime int64
  4403. if len(start_time) > 0 {
  4404. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4405. if err != nil {
  4406. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4407. return
  4408. }
  4409. startTime = theTime.Unix()
  4410. }
  4411. var endTime int64
  4412. if len(end_time) > 0 {
  4413. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4414. if err != nil {
  4415. utils.ErrorLog(err.Error())
  4416. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4417. return
  4418. }
  4419. endTime = theTime.Unix()
  4420. }
  4421. list, total, _ := service.GetAllStockPrice(orgId, startTime, endTime, keyword, limit, page)
  4422. doctor, _ := service.GetAllDoctorThree(orgId)
  4423. this.ServeSuccessJSON(map[string]interface{}{
  4424. "list": list,
  4425. "doctor": doctor,
  4426. "total": total,
  4427. })
  4428. }
  4429. func (this *StockManagerApiController) SaveCheckPrice() {
  4430. timeLayout := "2006-01-02"
  4431. loc, _ := time.LoadLocation("Local")
  4432. dataBody := make(map[string]interface{}, 0)
  4433. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4434. fmt.Println(err)
  4435. idstr := this.GetString("ids")
  4436. ids := strings.Split(idstr, ",")
  4437. check_time := this.GetString("check_time")
  4438. var checkTime int64
  4439. if len(check_time) > 0 {
  4440. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  4441. if err != nil {
  4442. fmt.Println(err)
  4443. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4444. return
  4445. }
  4446. checkTime = theTime.Unix()
  4447. }
  4448. checker, _ := this.GetInt64("checker")
  4449. adjustPrice := models.XtStockAdjustPrice{
  4450. Checker: checker,
  4451. CheckerStatus: 1,
  4452. CheckerTime: checkTime,
  4453. }
  4454. err = service.UpdateAdjustPrice(ids, adjustPrice)
  4455. fmt.Println(err)
  4456. list, _ := service.GetAdjustCheckPriceList(ids)
  4457. fmt.Println("list2333223323232323232323", list)
  4458. for _, item := range list {
  4459. info := models.GoodInfo{
  4460. PackingPrice: item.NewPrice,
  4461. BuyPrice: item.NewPrice,
  4462. }
  4463. err = service.UpdateAdjustCheckPrice(&info, item.GoodId)
  4464. fmt.Println(err)
  4465. }
  4466. this.ServeSuccessJSON(map[string]interface{}{
  4467. "adjustPrice": adjustPrice,
  4468. })
  4469. }
  4470. func (this *StockManagerApiController) GetAdjustPriceById() {
  4471. ids := this.GetString("ids")
  4472. fmt.Println("ids23232233223233232", ids)
  4473. splitIds := strings.Split(ids, ",")
  4474. list, _ := service.GetAdjustPricebyIdOne(splitIds)
  4475. fmt.Println("list2322322323", list)
  4476. this.ServeSuccessJSON(map[string]interface{}{
  4477. "list": list,
  4478. })
  4479. }
  4480. func (this *StockManagerApiController) SaveReportStock() {
  4481. timeLayout := "2006-01-02"
  4482. loc, _ := time.LoadLocation("Local")
  4483. dataBody := make(map[string]interface{}, 0)
  4484. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4485. if err != nil {
  4486. utils.ErrorLog(err.Error())
  4487. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4488. return
  4489. }
  4490. tableData, _ := dataBody["tableData"].([]interface{})
  4491. if len(tableData) > 0 {
  4492. for _, item := range tableData {
  4493. items := item.(map[string]interface{})
  4494. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4495. utils.ErrorLog("good_name")
  4496. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4497. return
  4498. }
  4499. good_name := items["good_name"].(string)
  4500. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4501. utils.ErrorLog("good_name")
  4502. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4503. return
  4504. }
  4505. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4506. utils.ErrorLog("packing_price")
  4507. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4508. return
  4509. }
  4510. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4511. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4512. utils.ErrorLog("warehousing_order")
  4513. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4514. return
  4515. }
  4516. warehousing_order := items["warehousing_order"].(string)
  4517. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4518. utils.ErrorLog("license_number")
  4519. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4520. return
  4521. }
  4522. license_number := items["license_number"].(string)
  4523. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4524. utils.ErrorLog("dealer")
  4525. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4526. return
  4527. }
  4528. dealer := items["dealer"].(string)
  4529. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4530. utils.ErrorLog("manufacturer")
  4531. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4532. return
  4533. }
  4534. manufacturer := items["manufacturer"].(string)
  4535. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4536. utils.ErrorLog("specification_name")
  4537. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4538. return
  4539. }
  4540. specification_name := items["specification_name"].(string)
  4541. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4542. utils.ErrorLog("remark")
  4543. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4544. return
  4545. }
  4546. remark := items["remark"].(string)
  4547. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4548. utils.ErrorLog("warehousing_unit")
  4549. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4550. return
  4551. }
  4552. warehousing_unit := items["warehousing_unit"].(string)
  4553. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4554. utils.ErrorLog("buy_price")
  4555. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4556. return
  4557. }
  4558. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4559. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4560. utils.ErrorLog("count")
  4561. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4562. return
  4563. }
  4564. count := int64(items["count"].(float64))
  4565. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4566. utils.ErrorLog("good_id")
  4567. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4568. return
  4569. }
  4570. good_id := int64(items["good_id"].(float64))
  4571. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4572. utils.ErrorLog("start_time")
  4573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4574. return
  4575. }
  4576. var startTime int64
  4577. start_time := items["start_time"].(string)
  4578. if len(start_time) > 0 {
  4579. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4580. if err != nil {
  4581. fmt.Println(err)
  4582. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4583. return
  4584. }
  4585. startTime = theTime.Unix()
  4586. }
  4587. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  4588. utils.ErrorLog("number")
  4589. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4590. return
  4591. }
  4592. number := items["number"].(string)
  4593. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  4594. utils.ErrorLog("warehousing_info_id")
  4595. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4596. return
  4597. }
  4598. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  4599. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  4600. utils.ErrorLog("expiry_date")
  4601. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4602. return
  4603. }
  4604. expiry_date := int64(items["expiry_date"].(float64))
  4605. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  4606. utils.ErrorLog("product_date")
  4607. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4608. return
  4609. }
  4610. product_date := int64(items["product_date"].(float64))
  4611. orgId := this.GetAdminUserInfo().CurrentOrgId
  4612. Creater := this.GetAdminUserInfo().AdminUser.Id
  4613. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  4614. utils.ErrorLog("total")
  4615. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4616. return
  4617. }
  4618. total := int64(items["total"].(float64))
  4619. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  4620. utils.ErrorLog("good_origin_place")
  4621. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4622. return
  4623. }
  4624. good_origin_place := items["good_origin_place"].(string)
  4625. reportPrice := models.XtStockReportPrice{
  4626. GoodName: good_name,
  4627. SpecificationName: specification_name,
  4628. WarehousingUnit: warehousing_unit,
  4629. Count: count,
  4630. BuyPrice: buy_price,
  4631. PackingPrice: packing_price,
  4632. Manufacturer: manufacturer,
  4633. Dealer: dealer,
  4634. Remark: remark,
  4635. GoodId: good_id,
  4636. UserOrgId: orgId,
  4637. Ctime: time.Now().Unix(),
  4638. Mtime: 0,
  4639. Status: 1,
  4640. WarehousingOrder: warehousing_order,
  4641. LicenseNumber: license_number,
  4642. StartTime: startTime,
  4643. Creater: Creater,
  4644. Checker: 0,
  4645. CheckerStatus: 2,
  4646. CheckerTime: 0,
  4647. Number: number,
  4648. WarehousingInfoId: warehousing_info_id,
  4649. ExpiryDate: expiry_date,
  4650. ProductDate: product_date,
  4651. Total: total,
  4652. GoodOriginPlace: good_origin_place,
  4653. }
  4654. err := service.CreateReportPrice(&reportPrice)
  4655. fmt.Println(err)
  4656. }
  4657. }
  4658. this.ServeSuccessJSON(map[string]interface{}{
  4659. "msg": "保存成功!",
  4660. })
  4661. }
  4662. func (this *StockManagerApiController) GetReportStockList() {
  4663. timeLayout := "2006-01-02"
  4664. loc, _ := time.LoadLocation("Local")
  4665. start_time := this.GetString("start_time")
  4666. end_time := this.GetString("end_time")
  4667. page, _ := this.GetInt64("page")
  4668. limit, _ := this.GetInt64("limit")
  4669. var startTime int64
  4670. if len(start_time) > 0 {
  4671. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4672. if err != nil {
  4673. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4674. return
  4675. }
  4676. startTime = theTime.Unix()
  4677. fmt.Println("开始时间", startTime)
  4678. }
  4679. var endTime int64
  4680. if len(end_time) > 0 {
  4681. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4682. if err != nil {
  4683. utils.ErrorLog(err.Error())
  4684. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4685. return
  4686. }
  4687. endTime = theTime.Unix()
  4688. }
  4689. orgId := this.GetAdminUserInfo().CurrentOrgId
  4690. keyword := this.GetString("keyword")
  4691. fmt.Println("startTime", startTime, "endTime", endTime)
  4692. //list, total, _ := service.GetReportStockList(startTime, endTime, orgId, keyword, page, limit)
  4693. list, total, _ := service.GetStockDamagedList(orgId, keyword, page, limit, startTime, endTime)
  4694. damageList, _ := service.GetStockDamagedCount(orgId)
  4695. doctorlist, _ := service.GetAllDoctorThree(orgId)
  4696. this.ServeSuccessJSON(map[string]interface{}{
  4697. "list": list,
  4698. "total": total,
  4699. "doctorlist": doctorlist,
  4700. "damageList": damageList,
  4701. })
  4702. }
  4703. func (this *StockManagerApiController) SaveCheckDamage() {
  4704. timeLayout := "2006-01-02"
  4705. loc, _ := time.LoadLocation("Local")
  4706. idstr := this.GetString("ids")
  4707. ids := strings.Split(idstr, ",")
  4708. check_time := this.GetString("check_time")
  4709. var checkTime int64
  4710. if len(check_time) > 0 {
  4711. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  4712. if err != nil {
  4713. fmt.Println(err)
  4714. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4715. return
  4716. }
  4717. checkTime = theTime.Unix()
  4718. }
  4719. checker, _ := this.GetInt64("checker")
  4720. reportprice := models.XtStockReportPrice{
  4721. Checker: checker,
  4722. CheckerStatus: 1,
  4723. CheckerTime: checkTime,
  4724. }
  4725. err := service.UpdateCheckDamage(ids, reportprice)
  4726. fmt.Println(err)
  4727. //获取当前核对的数据
  4728. list, _ := service.GetCheckDamageList(ids)
  4729. ctime := time.Now().Unix()
  4730. adminUserInfo := this.GetAdminUserInfo()
  4731. timeStr := time.Now().Format("2006-01-02")
  4732. timeArr := strings.Split(timeStr, "-")
  4733. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  4734. total = total + 1
  4735. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4736. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4737. number = number + total
  4738. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4739. operation_time := time.Now().Unix()
  4740. creater := adminUserInfo.AdminUser.Id
  4741. warehouseOut := models.WarehouseOut{
  4742. WarehouseOutOrderNumber: warehousing_out_order,
  4743. OperationTime: operation_time,
  4744. OrgId: adminUserInfo.CurrentOrgId,
  4745. Creater: creater,
  4746. Ctime: ctime,
  4747. Status: 1,
  4748. WarehouseOutTime: ctime,
  4749. Type: 1,
  4750. }
  4751. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  4752. if errcodes == gorm.ErrRecordNotFound {
  4753. service.AddSigleWarehouseOut(&warehouseOut)
  4754. }
  4755. out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
  4756. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  4757. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  4758. var manufacturer_id int64
  4759. var dealer_id int64
  4760. for _, item := range list {
  4761. for _, it := range manufacturerList {
  4762. if item.Manufacturer == it.ManufacturerName {
  4763. manufacturer_id = it.ID
  4764. }
  4765. }
  4766. for _, its := range dealerList {
  4767. if item.Dealer == its.DealerName {
  4768. dealer_id = its.ID
  4769. }
  4770. }
  4771. goodinfo, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4772. //插入出库单
  4773. warehouseOutInfo := &models.WarehouseOutInfo{
  4774. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4775. WarehouseOutId: out.ID,
  4776. GoodId: item.GoodId,
  4777. Count: item.Count,
  4778. Price: item.PackingPrice,
  4779. Status: 1,
  4780. Ctime: ctime,
  4781. Remark: item.Remark,
  4782. OrgId: adminUserInfo.CurrentOrgId,
  4783. Type: 2,
  4784. Manufacturer: manufacturer_id,
  4785. Number: item.Number,
  4786. ExpiryDate: item.ExpiryDate,
  4787. ProductDate: item.ProductDate,
  4788. Dealer: dealer_id,
  4789. LicenseNumber: item.LicenseNumber,
  4790. GoodTypeId: goodinfo.GoodTypeId,
  4791. }
  4792. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4793. fmt.Println("99999999999999", errOne)
  4794. //更改库存
  4795. info, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  4796. warehousingInfo := models.WarehousingInfo{
  4797. StockCount: info.StockCount - item.Count,
  4798. }
  4799. errOne = service.UpdateGoodWarehouseInfo(item.WarehousingInfoId, warehousingInfo)
  4800. fmt.Println(errOne)
  4801. flow := models.VmStockFlow{
  4802. WarehousingId: 0,
  4803. GoodId: item.GoodId,
  4804. Number: item.Number,
  4805. LicenseNumber: item.LicenseNumber,
  4806. Count: item.Count,
  4807. UserOrgId: adminUserInfo.CurrentOrgId,
  4808. PatientId: 0,
  4809. SystemTime: time.Now().Unix(),
  4810. ConsumableType: 5,
  4811. IsSys: 0,
  4812. WarehousingOrder: "",
  4813. WarehouseOutId: out.ID,
  4814. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4815. IsEdit: 0,
  4816. CancelStockId: 0,
  4817. CancelOrderNumber: "",
  4818. Manufacturer: 0,
  4819. Dealer: 0,
  4820. Creator: adminUserInfo.AdminUser.Id,
  4821. UpdateCreator: 0,
  4822. Status: 1,
  4823. Ctime: time.Now().Unix(),
  4824. Mtime: 0,
  4825. Price: item.PackingPrice,
  4826. WarehousingDetailId: 0,
  4827. WarehouseOutDetailId: 0,
  4828. CancelOutDetailId: 0,
  4829. ProductDate: item.ProductDate,
  4830. ExpireDate: item.ExpiryDate,
  4831. }
  4832. service.CreateStockFlowOne(flow)
  4833. }
  4834. this.ServeSuccessJSON(map[string]interface{}{
  4835. "reportPrice": reportprice,
  4836. })
  4837. }
  4838. func (this *StockManagerApiController) SaveInventory() {
  4839. timeLayout := "2006-01-02"
  4840. loc, _ := time.LoadLocation("Local")
  4841. dataBody := make(map[string]interface{}, 0)
  4842. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4843. if err != nil {
  4844. utils.ErrorLog(err.Error())
  4845. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4846. return
  4847. }
  4848. tableData, _ := dataBody["tableData"].([]interface{})
  4849. if len(tableData) > 0 {
  4850. for _, item := range tableData {
  4851. items := item.(map[string]interface{})
  4852. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4853. utils.ErrorLog("good_name")
  4854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4855. return
  4856. }
  4857. good_name := items["good_name"].(string)
  4858. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  4859. utils.ErrorLog("good_name")
  4860. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4861. return
  4862. }
  4863. if items["packing_price"] == nil || reflect.TypeOf(items["packing_price"]).String() != "string" {
  4864. utils.ErrorLog("packing_price")
  4865. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4866. return
  4867. }
  4868. packing_price, _ := strconv.ParseFloat(items["packing_price"].(string), 64)
  4869. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  4870. utils.ErrorLog("warehousing_order")
  4871. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4872. return
  4873. }
  4874. warehousing_order := items["warehousing_order"].(string)
  4875. if items["license_number"] == nil || reflect.TypeOf(items["license_number"]).String() != "string" {
  4876. utils.ErrorLog("license_number")
  4877. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4878. return
  4879. }
  4880. license_number := items["license_number"].(string)
  4881. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  4882. utils.ErrorLog("dealer")
  4883. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4884. return
  4885. }
  4886. dealer := items["dealer"].(string)
  4887. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  4888. utils.ErrorLog("manufacturer")
  4889. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4890. return
  4891. }
  4892. manufacturer := items["manufacturer"].(string)
  4893. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  4894. utils.ErrorLog("specification_name")
  4895. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4896. return
  4897. }
  4898. specification_name := items["specification_name"].(string)
  4899. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  4900. utils.ErrorLog("remark")
  4901. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4902. return
  4903. }
  4904. remark := items["remark"].(string)
  4905. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  4906. utils.ErrorLog("warehousing_unit")
  4907. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4908. return
  4909. }
  4910. warehousing_unit := items["warehousing_unit"].(string)
  4911. if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
  4912. utils.ErrorLog("buy_price")
  4913. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4914. return
  4915. }
  4916. buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
  4917. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  4918. utils.ErrorLog("count")
  4919. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4920. return
  4921. }
  4922. count := int64(items["count"].(float64))
  4923. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4924. utils.ErrorLog("good_id")
  4925. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4926. return
  4927. }
  4928. good_id := int64(items["good_id"].(float64))
  4929. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  4930. utils.ErrorLog("start_time")
  4931. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4932. return
  4933. }
  4934. var startTime int64
  4935. start_time := items["start_time"].(string)
  4936. if len(start_time) > 0 {
  4937. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4938. if err != nil {
  4939. fmt.Println(err)
  4940. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4941. return
  4942. }
  4943. startTime = theTime.Unix()
  4944. }
  4945. if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "float64" {
  4946. utils.ErrorLog("total")
  4947. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4948. return
  4949. }
  4950. total := int64(items["total"].(float64))
  4951. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  4952. utils.ErrorLog("expiry_date")
  4953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4954. return
  4955. }
  4956. expiry_date := int64(items["expiry_date"].(float64))
  4957. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  4958. utils.ErrorLog("product_date")
  4959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4960. return
  4961. }
  4962. product_date := int64(items["product_date"].(float64))
  4963. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  4964. utils.ErrorLog("number")
  4965. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4966. return
  4967. }
  4968. number := items["number"].(string)
  4969. if items["warehousing_info_id"] == nil || reflect.TypeOf(items["warehousing_info_id"]).String() != "float64" {
  4970. utils.ErrorLog("warehousing_info_id")
  4971. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4972. return
  4973. }
  4974. warehousing_info_id := int64(items["warehousing_info_id"].(float64))
  4975. if items["good_origin_place"] == nil || reflect.TypeOf(items["good_origin_place"]).String() != "string" {
  4976. utils.ErrorLog("good_origin_place")
  4977. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4978. return
  4979. }
  4980. good_origin_place := items["good_origin_place"].(string)
  4981. orgId := this.GetAdminUserInfo().CurrentOrgId
  4982. Creater := this.GetAdminUserInfo().AdminUser.Id
  4983. inventory := models.XtStockInventory{
  4984. GoodName: good_name,
  4985. SpecificationName: specification_name,
  4986. WarehousingUnit: warehousing_unit,
  4987. Count: count,
  4988. BuyPrice: buy_price,
  4989. PackingPrice: packing_price,
  4990. NewPrice: 0,
  4991. Manufacturer: manufacturer,
  4992. Dealer: dealer,
  4993. Remark: remark,
  4994. GoodId: good_id,
  4995. UserOrgId: orgId,
  4996. Ctime: time.Now().Unix(),
  4997. Mtime: 0,
  4998. Status: 1,
  4999. WarehousingOrder: warehousing_order,
  5000. LicenseNumber: license_number,
  5001. StartTime: startTime,
  5002. Creater: Creater,
  5003. Checker: 0,
  5004. CheckerStatus: 2,
  5005. CheckerTime: 0,
  5006. Total: total,
  5007. ExpireDate: expiry_date,
  5008. ProductDate: product_date,
  5009. Number: number,
  5010. WarehousingInfoId: warehousing_info_id,
  5011. GoodOriginPlace: good_origin_place,
  5012. }
  5013. err = service.CreateInentory(inventory)
  5014. fmt.Println(err)
  5015. }
  5016. }
  5017. this.ServeSuccessJSON(map[string]interface{}{
  5018. "msg": "保存成功!",
  5019. })
  5020. }
  5021. func (this *StockManagerApiController) GetInventorylist() {
  5022. timeLayout := "2006-01-02"
  5023. loc, _ := time.LoadLocation("Local")
  5024. start_time := this.GetString("start_time")
  5025. end_time := this.GetString("end_time")
  5026. page, _ := this.GetInt64("page")
  5027. limit, _ := this.GetInt64("limit")
  5028. keyword := this.GetString("keyword")
  5029. inventory_status, _ := this.GetInt64("inventory_status")
  5030. var startTime int64
  5031. if len(start_time) > 0 {
  5032. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5033. if err != nil {
  5034. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5035. return
  5036. }
  5037. startTime = theTime.Unix()
  5038. fmt.Println("开始时间", startTime)
  5039. }
  5040. var endTime int64
  5041. if len(end_time) > 0 {
  5042. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5043. if err != nil {
  5044. utils.ErrorLog(err.Error())
  5045. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5046. return
  5047. }
  5048. endTime = theTime.Unix()
  5049. }
  5050. orgId := this.GetAdminUserInfo().CurrentOrgId
  5051. list, total, _ := service.GetInventorylist(startTime, endTime, page, limit, inventory_status, keyword, orgId)
  5052. doctorlist, _ := service.GetAllDoctorThree(orgId)
  5053. this.ServeSuccessJSON(map[string]interface{}{
  5054. "list": list,
  5055. "total": total,
  5056. "doctorlist": doctorlist,
  5057. })
  5058. }
  5059. func (this *StockManagerApiController) SaveCheckInventory() {
  5060. timeLayout := "2006-01-02"
  5061. loc, _ := time.LoadLocation("Local")
  5062. dataBody := make(map[string]interface{}, 0)
  5063. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5064. fmt.Println(err)
  5065. idstr := this.GetString("ids")
  5066. ids := strings.Split(idstr, ",")
  5067. check_time := this.GetString("check_time")
  5068. var checkTime int64
  5069. if len(check_time) > 0 {
  5070. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  5071. if err != nil {
  5072. fmt.Println(err)
  5073. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5074. return
  5075. }
  5076. checkTime = theTime.Unix()
  5077. }
  5078. checker, _ := this.GetInt64("checker")
  5079. inventory := models.XtStockInventory{
  5080. Checker: checker,
  5081. CheckerStatus: 1,
  5082. CheckerTime: checkTime,
  5083. }
  5084. adminUserInfo := this.GetAdminUserInfo()
  5085. err = service.UpdateCheckInventory(ids, inventory)
  5086. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  5087. dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
  5088. var manufactuer_id int64
  5089. var dealer_id int64
  5090. //查询耗材信息
  5091. list, _ := service.GetInventoryDetailById(ids)
  5092. for _, item := range list {
  5093. for _, it := range manufacturerList {
  5094. if item.Manufacturer == it.ManufacturerName {
  5095. manufactuer_id = it.ID
  5096. }
  5097. }
  5098. for _, its := range dealerList {
  5099. if item.Dealer == its.DealerName {
  5100. dealer_id = its.ID
  5101. }
  5102. }
  5103. //查寻该批次的库存量
  5104. list, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
  5105. //查询该耗材最后1条批次
  5106. info, _ := service.GetLastWarehouseInfo(item.GoodId)
  5107. good, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5108. fmt.Println("总共", item.Count)
  5109. fmt.Println("数据", list.StockCount)
  5110. //盘点盘点库存和et实际库存的大小
  5111. // 如果盘点库存大于实际库存,怎需要入库
  5112. if item.Count > list.StockCount {
  5113. ctime := time.Now().Unix()
  5114. timeStr := time.Now().Format("2006-01-02")
  5115. timeArr := strings.Split(timeStr, "-")
  5116. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  5117. total = total + 1
  5118. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5119. operation_time := time.Now().Unix()
  5120. creater := adminUserInfo.AdminUser.Id
  5121. warehousing := models.Warehousing{
  5122. WarehousingOrder: warehousing_order,
  5123. OperationTime: operation_time,
  5124. OrgId: adminUserInfo.CurrentOrgId,
  5125. Creater: creater,
  5126. Ctime: ctime,
  5127. Status: 1,
  5128. WarehousingTime: ctime,
  5129. Type: 1,
  5130. }
  5131. service.AddSigleWarehouse(&warehousing)
  5132. //获取最
  5133. //入库单表格
  5134. warehouseInfo := models.WarehousingInfo{
  5135. WarehousingOrder: warehousing.WarehousingOrder,
  5136. WarehousingId: warehousing.ID,
  5137. GoodId: item.GoodId,
  5138. Number: info.Number,
  5139. ProductDate: info.ProductDate,
  5140. ExpiryDate: info.ExpiryDate,
  5141. WarehousingCount: item.Count - list.StockCount,
  5142. Price: info.Price,
  5143. Status: 1,
  5144. Ctime: ctime,
  5145. Remark: item.Remark,
  5146. OrgId: adminUserInfo.CurrentOrgId,
  5147. Type: 1,
  5148. Manufacturer: manufactuer_id,
  5149. StockCount: item.Count - list.StockCount,
  5150. Dealer: dealer_id,
  5151. LicenseNumber: info.LicenseNumber,
  5152. WarehouseInfoId: item.WarehousingInfoId,
  5153. GoodTypeId: good.GoodTypeId,
  5154. }
  5155. flow := models.VmStockFlow{
  5156. WarehousingOrder: warehousing.WarehousingOrder,
  5157. WarehousingId: warehousing.ID,
  5158. GoodId: item.GoodId,
  5159. Number: info.Number,
  5160. ProductDate: info.ProductDate,
  5161. ExpireDate: info.ExpiryDate,
  5162. Count: item.Count - list.StockCount,
  5163. Price: item.BuyPrice,
  5164. Status: 1,
  5165. Ctime: ctime,
  5166. UserOrgId: adminUserInfo.CurrentOrgId,
  5167. Manufacturer: info.Manufacturer,
  5168. Dealer: info.Dealer,
  5169. LicenseNumber: info.LicenseNumber,
  5170. IsEdit: 1,
  5171. Creator: adminUserInfo.AdminUser.Id,
  5172. SystemTime: operation_time,
  5173. ConsumableType: 1,
  5174. WarehousingDetailId: warehouseInfo.ID,
  5175. }
  5176. service.CreateWarehouseInfo(warehouseInfo)
  5177. service.CreateStockFlowOne(flow)
  5178. }
  5179. //如果盘点库存小于实际库存,需要出库
  5180. if item.Count < list.StockCount {
  5181. timeStr := time.Now().Format("2006-01-02")
  5182. timeArr := strings.Split(timeStr, "-")
  5183. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  5184. total = total + 1
  5185. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5186. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5187. number = number + total
  5188. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5189. operation_time := time.Now().Unix()
  5190. creater := adminUserInfo.AdminUser.Id
  5191. //查询最早的1条批次
  5192. warehouseInfo, _ := service.GetFirstWarehouseInfo(item.GoodId)
  5193. warehouseOut := models.WarehouseOut{
  5194. WarehouseOutOrderNumber: warehousing_out_order,
  5195. OperationTime: operation_time,
  5196. OrgId: adminUserInfo.CurrentOrgId,
  5197. Creater: creater,
  5198. Ctime: time.Now().Unix(),
  5199. Status: 1,
  5200. WarehouseOutTime: time.Now().Unix(),
  5201. Type: 1,
  5202. }
  5203. err = service.CreateWarehouseOut(warehouseOut)
  5204. fmt.Println(err)
  5205. out, _ := service.GetLastGoodWarehouseOut(adminUserInfo.CurrentOrgId)
  5206. warehouseOutInfo := &models.WarehouseOutInfo{
  5207. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  5208. WarehouseOutId: out.ID,
  5209. GoodId: warehouseInfo.GoodId,
  5210. Count: list.StockCount - item.Count,
  5211. Price: warehouseInfo.Price,
  5212. Status: 1,
  5213. Ctime: time.Now().Unix(),
  5214. Remark: item.Remark,
  5215. OrgId: adminUserInfo.CurrentOrgId,
  5216. Type: 1,
  5217. Manufacturer: manufactuer_id,
  5218. Number: warehouseInfo.Number,
  5219. ExpiryDate: warehouseInfo.ExpiryDate,
  5220. ProductDate: warehouseInfo.ProductDate,
  5221. Dealer: dealer_id,
  5222. LicenseNumber: warehouseInfo.LicenseNumber,
  5223. GoodTypeId: good.GoodTypeId,
  5224. }
  5225. stockFlow := models.VmStockFlow{
  5226. WarehousingId: item.WarehousingInfoId,
  5227. GoodId: warehouseInfo.GoodId,
  5228. Number: warehouseInfo.Number,
  5229. LicenseNumber: warehouseInfo.LicenseNumber,
  5230. Count: list.StockCount - item.Count,
  5231. UserOrgId: warehouseInfo.OrgId,
  5232. PatientId: 0,
  5233. SystemTime: 0,
  5234. ConsumableType: 2,
  5235. IsSys: 2,
  5236. WarehousingOrder: "",
  5237. WarehouseOutId: out.ID,
  5238. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5239. IsEdit: 1,
  5240. CancelStockId: 0,
  5241. CancelOrderNumber: "",
  5242. Manufacturer: manufactuer_id,
  5243. Dealer: dealer_id,
  5244. Creator: adminUserInfo.AdminUser.Id,
  5245. UpdateCreator: 0,
  5246. Status: 1,
  5247. Ctime: time.Now().Unix(),
  5248. Mtime: 0,
  5249. Price: warehouseInfo.Price,
  5250. WarehousingDetailId: 0,
  5251. WarehouseOutDetailId: out.ID,
  5252. CancelOutDetailId: 0,
  5253. ProductDate: warehouseInfo.ProductDate,
  5254. ExpireDate: warehouseInfo.ExpiryDate,
  5255. }
  5256. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5257. fmt.Println(errOne)
  5258. //创建出库明细
  5259. service.CreateStockFlowOne(stockFlow)
  5260. //更改库存
  5261. warehousingInfos := models.WarehousingInfo{
  5262. StockCount: item.Count,
  5263. }
  5264. service.UpdateStockOut(item.WarehousingInfoId, warehousingInfos)
  5265. }
  5266. }
  5267. fmt.Println(err)
  5268. this.ServeSuccessJSON(map[string]interface{}{
  5269. "inventory": inventory,
  5270. })
  5271. }
  5272. func (this *StockManagerApiController) GetModifyPriceDetail() {
  5273. id, _ := this.GetInt64("id")
  5274. detail, _ := service.GetModifyPriceDetail(id)
  5275. this.ServeSuccessJSON(map[string]interface{}{
  5276. "detail": detail,
  5277. })
  5278. }
  5279. func (this *StockManagerApiController) UpdateStockPrice() {
  5280. id, _ := this.GetInt64("id")
  5281. newPrice := this.GetString("new_price")
  5282. new_price, _ := strconv.ParseFloat(newPrice, 64)
  5283. good_name := this.GetString("good_name")
  5284. packingPrice := this.GetString("packing_price")
  5285. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5286. remark := this.GetString("remark")
  5287. good_id, _ := this.GetInt64("good_id")
  5288. manufacturer := this.GetString("manufacturer")
  5289. dealer := this.GetString("dealer")
  5290. adjust := models.XtStockAdjustPrice{
  5291. NewPrice: new_price,
  5292. GoodName: good_name,
  5293. PackingPrice: packing_price,
  5294. Remark: remark,
  5295. GoodId: good_id,
  5296. Manufacturer: manufacturer,
  5297. Dealer: dealer,
  5298. }
  5299. err := service.UpdateStockPrice(adjust, id)
  5300. fmt.Println(err)
  5301. this.ServeSuccessJSON(map[string]interface{}{
  5302. "adjust": adjust,
  5303. })
  5304. }
  5305. func (this *StockManagerApiController) DeleteStockPrice() {
  5306. id, _ := this.GetInt64("id")
  5307. err := service.DeleteStockPrice(id)
  5308. fmt.Println(err)
  5309. returnData := make(map[string]interface{}, 0)
  5310. returnData["msg"] = "ok"
  5311. this.ServeSuccessJSON(returnData)
  5312. return
  5313. }
  5314. func (this *StockManagerApiController) GetStockDamageDetail() {
  5315. id, _ := this.GetInt64("id")
  5316. detail, err := service.GetStockDamageDetail(id)
  5317. fmt.Println(err)
  5318. this.ServeSuccessJSON(map[string]interface{}{
  5319. "detail": detail,
  5320. })
  5321. }
  5322. func (this *StockManagerApiController) ModifyPrice() {
  5323. count, _ := this.GetInt64("count")
  5324. id, _ := this.GetInt64("id")
  5325. good_name := this.GetString("good_name")
  5326. specification_name := this.GetString("specification_name")
  5327. number := this.GetString("number")
  5328. warehousing_unit := this.GetString("warehousing_unit")
  5329. buyPrice := this.GetString("buy_price")
  5330. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5331. packingPrice := this.GetString("packing_price")
  5332. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5333. good_origin_place := this.GetString("good_origin_place")
  5334. manufacturer := this.GetString("manufacturer")
  5335. dealer := this.GetString("dealer")
  5336. total, _ := this.GetInt64("total")
  5337. remark := this.GetString("remark")
  5338. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5339. good_id, _ := this.GetInt64("good_id")
  5340. adjust := models.XtStockReportPrice{
  5341. Count: count,
  5342. SpecificationName: specification_name,
  5343. Number: number,
  5344. GoodName: good_name,
  5345. WarehousingUnit: warehousing_unit,
  5346. BuyPrice: buy_price,
  5347. PackingPrice: packing_price,
  5348. GoodOriginPlace: good_origin_place,
  5349. Manufacturer: manufacturer,
  5350. Dealer: dealer,
  5351. Total: total,
  5352. Remark: remark,
  5353. WarehousingInfoId: warehousing_info_id,
  5354. GoodId: good_id,
  5355. }
  5356. err := service.ModifyPrice(id, adjust)
  5357. fmt.Println(err)
  5358. this.ServeSuccessJSON(map[string]interface{}{
  5359. "adjust": adjust,
  5360. })
  5361. }
  5362. func (this *StockManagerApiController) DeleteDamage() {
  5363. id, _ := this.GetInt64("id")
  5364. err := service.DeleteDamage(id)
  5365. fmt.Println(err)
  5366. returnData := make(map[string]interface{}, 0)
  5367. returnData["msg"] = "ok"
  5368. this.ServeSuccessJSON(returnData)
  5369. return
  5370. }
  5371. func (this *StockManagerApiController) GetStockDamageById() {
  5372. ids := this.GetString("ids")
  5373. splitIds := strings.Split(ids, ",")
  5374. list, _ := service.GetStockDamageById(splitIds)
  5375. this.ServeSuccessJSON(map[string]interface{}{
  5376. "list": list,
  5377. })
  5378. }
  5379. func (this *StockManagerApiController) GetInventoryDetail() {
  5380. id, _ := this.GetInt64("id")
  5381. detail, _ := service.GetInventoryDetail(id)
  5382. this.ServeSuccessJSON(map[string]interface{}{
  5383. "detail": detail,
  5384. })
  5385. }
  5386. func (this *StockManagerApiController) ModifyInventory() {
  5387. id, _ := this.GetInt64("id")
  5388. good_id, _ := this.GetInt64("good_id")
  5389. good_name := this.GetString("good_name")
  5390. specification_name := this.GetString("specification_name")
  5391. number := this.GetString("number")
  5392. warehousing_unit := this.GetString("warehousing_unit")
  5393. buyPrice := this.GetString("buy_price")
  5394. buy_price, _ := strconv.ParseFloat(buyPrice, 64)
  5395. packingPrice := this.GetString("packing_price")
  5396. packing_price, _ := strconv.ParseFloat(packingPrice, 64)
  5397. total, _ := this.GetInt64("total")
  5398. good_origin_place := this.GetString("good_origin_place")
  5399. license_number := this.GetString("license_number")
  5400. dealer := this.GetString("dealer")
  5401. manufacturer := this.GetString("manufacturer")
  5402. count, _ := this.GetInt64("count")
  5403. remark := this.GetString("remark")
  5404. inventory := models.XtStockInventory{
  5405. GoodId: good_id,
  5406. GoodName: good_name,
  5407. SpecificationName: specification_name,
  5408. Number: number,
  5409. WarehousingUnit: warehousing_unit,
  5410. BuyPrice: buy_price,
  5411. PackingPrice: packing_price,
  5412. Total: total,
  5413. GoodOriginPlace: good_origin_place,
  5414. LicenseNumber: license_number,
  5415. Dealer: dealer,
  5416. Manufacturer: manufacturer,
  5417. Count: count,
  5418. Remark: remark,
  5419. }
  5420. err := service.ModifyInventory(id, inventory)
  5421. fmt.Println(err)
  5422. this.ServeSuccessJSON(map[string]interface{}{
  5423. "inventory": inventory,
  5424. })
  5425. }
  5426. func (this *StockManagerApiController) DeleteInventory() {
  5427. id, _ := this.GetInt64("id")
  5428. err := service.DeleteInventory(id)
  5429. fmt.Println(err)
  5430. returnData := make(map[string]interface{}, 0)
  5431. returnData["msg"] = "ok"
  5432. this.ServeSuccessJSON(returnData)
  5433. return
  5434. }
  5435. func (this *StockManagerApiController) GetInventoryDetailList() {
  5436. keyword := this.GetString("keyword")
  5437. limit, _ := this.GetInt64("limit")
  5438. page, _ := this.GetInt64("page")
  5439. orgId := this.GetAdminUserInfo().CurrentOrgId
  5440. list, total, _ := service.GetInventoryDetailList(keyword, limit, page, orgId)
  5441. this.ServeSuccessJSON(map[string]interface{}{
  5442. "list": list,
  5443. "total": total,
  5444. })
  5445. }
  5446. func (this *StockManagerApiController) GetInventoryPrintList() {
  5447. ids := this.GetString("ids")
  5448. splitIds := strings.Split(ids, ",")
  5449. list, _ := service.GetInventoryPrintList(splitIds)
  5450. this.ServeSuccessJSON(map[string]interface{}{
  5451. "list": list,
  5452. })
  5453. }
  5454. func (this *StockManagerApiController) GetInventoryDetailPrintList() {
  5455. ids := this.GetString("ids")
  5456. splitIds := strings.Split(ids, ",")
  5457. list, _ := service.GetInventoryDetailPrintList(splitIds)
  5458. this.ServeSuccessJSON(map[string]interface{}{
  5459. "list": list,
  5460. })
  5461. }
  5462. func (this *StockManagerApiController) DeleteDrugPrice() {
  5463. id, _ := this.GetInt64("id")
  5464. err := service.DeleteDrugPrice(id)
  5465. fmt.Println(err)
  5466. returnData := make(map[string]interface{}, 0)
  5467. returnData["msg"] = "ok"
  5468. this.ServeSuccessJSON(returnData)
  5469. return
  5470. }
  5471. func (this *StockManagerApiController) GetGoodWarehouseList() {
  5472. id, _ := this.GetInt64("id")
  5473. list, _ := service.GetGoodWarehouseList(id)
  5474. this.ServeSuccessJSON(map[string]interface{}{
  5475. "list": list,
  5476. })
  5477. }
  5478. func (this *StockManagerApiController) ProofInventory() {
  5479. id, _ := this.GetInt64("id")
  5480. good_id, _ := this.GetInt64("good_id")
  5481. warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
  5482. proof_count, _ := this.GetInt64("proof_count")
  5483. total, _ := this.GetInt64("total")
  5484. orgId := this.GetAdminUserInfo().CurrentOrgId
  5485. creater := this.GetAdminUserInfo().AdminUser.Id
  5486. info := models.WarehousingInfo{
  5487. GoodId: good_id,
  5488. StockCount: proof_count,
  5489. }
  5490. err := service.UpdateProofInventory(warehousing_info_id, info)
  5491. inventory := models.XtStockInventory{
  5492. Total: proof_count,
  5493. }
  5494. err = service.UpdateStockInventory(inventory, id)
  5495. fmt.Println(err)
  5496. record := models.XtStockCorrectRecord{
  5497. GoodId: good_id,
  5498. OrdCount: total,
  5499. WarehousingInfoId: warehousing_info_id,
  5500. NewCount: proof_count,
  5501. UserOrgId: orgId,
  5502. Status: 1,
  5503. Creater: creater,
  5504. Ctime: time.Now().Unix(),
  5505. Mtime: 0,
  5506. }
  5507. service.CeateStockCorrectRecord(record)
  5508. this.ServeSuccessJSON(map[string]interface{}{
  5509. "list": info,
  5510. })
  5511. }
  5512. func (this *StockManagerApiController) GetWarehouseTotal() {
  5513. id, _ := this.GetInt64("id")
  5514. list, _ := service.GetWarehouseTotal(id)
  5515. this.ServeSuccessJSON(map[string]interface{}{
  5516. "list": list,
  5517. })
  5518. }
  5519. func (this *StockManagerApiController) GetGoodInventoryWarehouseList() {
  5520. id, _ := this.GetInt64("id")
  5521. list, _ := service.GetGoodInventoryWarehouseList(id)
  5522. orgId := this.GetAdminUserInfo().CurrentOrgId
  5523. fmt.Println(orgId)
  5524. this.ServeSuccessJSON(map[string]interface{}{
  5525. "list": list,
  5526. })
  5527. }
  5528. func (this *StockManagerApiController) SaveStockInventoryList() {
  5529. dataBody := make(map[string]interface{}, 0)
  5530. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5531. fmt.Println(err)
  5532. tableData, _ := dataBody["tableData"].([]interface{})
  5533. if len(tableData) > 0 {
  5534. for _, item := range tableData {
  5535. items := item.(map[string]interface{})
  5536. good_name := items["good_name"].(string)
  5537. if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
  5538. utils.ErrorLog("good_name")
  5539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5540. return
  5541. }
  5542. specification_name := items["specification_name"].(string)
  5543. if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  5544. utils.ErrorLog("specification_name")
  5545. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5546. return
  5547. }
  5548. warehousing_unit := items["warehousing_unit"].(string)
  5549. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  5550. utils.ErrorLog("warehousing_unit")
  5551. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5552. return
  5553. }
  5554. stock_count := int64(items["stock_count"].(float64))
  5555. if items["stock_count"] == nil || reflect.TypeOf(items["stock_count"]).String() != "float64" {
  5556. utils.ErrorLog("stock_count")
  5557. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5558. return
  5559. }
  5560. price := items["price"].(float64)
  5561. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "float64" {
  5562. utils.ErrorLog("price")
  5563. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5564. return
  5565. }
  5566. manufacturer_name := items["manufacturer_name"].(string)
  5567. if items["manufacturer_name"] == nil || reflect.TypeOf(items["manufacturer_name"]).String() != "string" {
  5568. utils.ErrorLog("manufacturer_name")
  5569. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5570. return
  5571. }
  5572. good_id := int64(items["good_id"].(float64))
  5573. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5574. utils.ErrorLog("good_id")
  5575. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5576. return
  5577. }
  5578. manufacturer := int64(items["manufacturer"].(float64))
  5579. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "float64" {
  5580. utils.ErrorLog("manufacturer")
  5581. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5582. return
  5583. }
  5584. warehousing_order := items["warehousing_order"].(string)
  5585. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  5586. utils.ErrorLog("warehousing_order")
  5587. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5588. return
  5589. }
  5590. number := items["number"].(string)
  5591. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5592. utils.ErrorLog("number")
  5593. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5594. return
  5595. }
  5596. id := int64(items["id"].(float64))
  5597. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5598. utils.ErrorLog("id")
  5599. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5600. return
  5601. }
  5602. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
  5603. utils.ErrorLog("expiry_date")
  5604. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5605. return
  5606. }
  5607. expiry_date := int64(items["expiry_date"].(float64))
  5608. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
  5609. utils.ErrorLog("product_date")
  5610. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5611. return
  5612. }
  5613. product_date := int64(items["product_date"].(float64))
  5614. orgId := this.GetAdminUserInfo().CurrentOrgId
  5615. adminId := this.GetAdminUserInfo().AdminUser.Id
  5616. stock_type := int64(items["type"].(float64))
  5617. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5618. utils.ErrorLog("type")
  5619. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5620. return
  5621. }
  5622. last_stock_count := int64(items["last_stock_count"].(float64))
  5623. if items["last_stock_count"] == nil || reflect.TypeOf(items["last_stock_count"]).String() != "float64" {
  5624. utils.ErrorLog("last_stock_count")
  5625. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5626. return
  5627. }
  5628. var total_count int64
  5629. var inventory_type int64
  5630. fmt.Println("盘点前", stock_count)
  5631. fmt.Println("盘点后", last_stock_count)
  5632. if stock_count > last_stock_count {
  5633. total_count = stock_count - last_stock_count
  5634. inventory_type = 11
  5635. }
  5636. if stock_count < last_stock_count {
  5637. total_count = last_stock_count - stock_count
  5638. inventory_type = 10
  5639. }
  5640. creater := this.GetAdminUserInfo().AdminUser.Id
  5641. inventory := models.XtStockInventory{
  5642. GoodName: good_name,
  5643. SpecificationName: specification_name,
  5644. WarehousingUnit: warehousing_unit,
  5645. Count: total_count,
  5646. BuyPrice: price,
  5647. PackingPrice: price,
  5648. NewPrice: 0,
  5649. Manufacturer: manufacturer_name,
  5650. Dealer: "",
  5651. Remark: "",
  5652. GoodId: good_id,
  5653. UserOrgId: orgId,
  5654. Ctime: time.Now().Unix(),
  5655. Mtime: 0,
  5656. Status: 1,
  5657. WarehousingOrder: warehousing_order,
  5658. LicenseNumber: number,
  5659. StartTime: time.Now().Unix(),
  5660. Creater: adminId,
  5661. Checker: 0,
  5662. CheckerStatus: 0,
  5663. CheckerTime: 0,
  5664. Total: 0,
  5665. Number: number,
  5666. WarehousingInfoId: id,
  5667. ExpireDate: expiry_date,
  5668. ProductDate: product_date,
  5669. GoodOriginPlace: "",
  5670. Type: 10,
  5671. InventoryType: stock_type,
  5672. LastStockCount: last_stock_count,
  5673. StockCount: stock_count,
  5674. }
  5675. service.CreateInentory(inventory)
  5676. stockFlow := models.VmStockFlow{
  5677. WarehousingId: 0,
  5678. GoodId: good_id,
  5679. Number: number,
  5680. LicenseNumber: "",
  5681. Count: total_count,
  5682. UserOrgId: orgId,
  5683. PatientId: 0,
  5684. SystemTime: 0,
  5685. ConsumableType: inventory_type,
  5686. IsSys: 0,
  5687. WarehousingOrder: "",
  5688. WarehouseOutId: 0,
  5689. WarehouseOutOrderNumber: warehousing_order,
  5690. IsEdit: 0,
  5691. CancelStockId: 0,
  5692. CancelOrderNumber: "",
  5693. Manufacturer: manufacturer,
  5694. Dealer: 0,
  5695. Creator: creater,
  5696. UpdateCreator: 0,
  5697. Status: 1,
  5698. Ctime: time.Now().Unix(),
  5699. Mtime: 0,
  5700. Price: price,
  5701. WarehousingDetailId: 0,
  5702. WarehouseOutDetailId: 0,
  5703. CancelOutDetailId: 0,
  5704. ProductDate: product_date,
  5705. ExpireDate: expiry_date,
  5706. ReturnCount: 0,
  5707. }
  5708. info := models.WarehousingInfo{
  5709. StockCount: last_stock_count,
  5710. }
  5711. //更改库存
  5712. service.UpdatedWarehousingInfo(info, id)
  5713. if stock_count != last_stock_count {
  5714. service.CreateStockFlowOne(stockFlow)
  5715. }
  5716. this.ServeSuccessJSON(map[string]interface{}{
  5717. "inventory": inventory,
  5718. })
  5719. }
  5720. }
  5721. }
  5722. func (this *StockManagerApiController) GetDamageDetailByGoodId() {
  5723. good_id, _ := this.GetInt64("good_id")
  5724. warehousing_order := this.GetString("warehousing_order")
  5725. inventory_type, _ := this.GetInt64("type")
  5726. fmt.Println("inventory_type23232323223322332", inventory_type)
  5727. list, _ := service.GetDamageDetailByGoodId(good_id, warehousing_order, inventory_type)
  5728. orgId := this.GetAdminUserInfo().CurrentOrgId
  5729. damageList, _ := service.GetStockDamagedCountOne(orgId, warehousing_order, inventory_type)
  5730. this.ServeSuccessJSON(map[string]interface{}{
  5731. "list": list,
  5732. "damageList": damageList,
  5733. })
  5734. }