1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871 |
- package service
-
- import (
- "errors"
- "fmt"
- "strconv"
- "strings"
- "time"
-
- "XT_New/models"
- "github.com/jinzhu/gorm"
- )
-
- func AddSigleDealer(dealer *models.Dealer) (error, *models.Dealer) {
- err := writeDb.Create(&dealer).Error
- return err, dealer
- }
-
- func ModifyDealer(dealer *models.Dealer) error {
- err := writeDb.Model(&models.Dealer{}).Where("id = ? AND status = 1", dealer.ID).Updates(map[string]interface{}{
- "dealer_name": dealer.DealerName,
- "contact": dealer.Contact,
- "contact_phone": dealer.ContactPhone,
- "platform_number": dealer.PlatformNumber,
- "email": dealer.Email,
- "contact_address": dealer.ContactAddress,
- "modifier": dealer.Modifier,
- "mtime": time.Now().Unix(),
- "remark": dealer.Remark,
- "wubi": dealer.WuBi,
- "pinyin": dealer.PinYin,
- }).Error
-
- return err
- }
-
- func FindAllDealerTotal(orgId int64) (total int64) {
- db := readDb.Model(&models.Dealer{})
- db = db.Where("org_id = ? ", orgId).Count(&total)
- return
- }
-
- // 获取经销商的名称
- func FindAllDealerName(orgId int64) (tmp []*models.Dealer, err error) {
- err = readDb.Model(&models.Dealer{}).Where("org_id = ? and status = 1", orgId).Find(&tmp).Error
- return
- }
- func FindAllDealerList(orgId int64, page int64, limit, key int64) (list []*models.Dealer, total int64, err error) {
- offset := (page - 1) * limit
- db := readDb.Model(&models.Dealer{})
- db = db.Where("org_id = ? AND status = 1", orgId)
- if key != 0 {
- db = db.Where("id = ? ", key)
- offset = 0
- limit = 10
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
- return
- }
-
- func DeleteDealerById(id int64) error {
- err := writeDb.Model(&models.Dealer{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
- return err
- }
-
- func FindDealerById(id int64) (*models.Dealer, error) {
- dealer := &models.Dealer{}
- err := readDb.Model(&models.Dealer{}).Where("id = ? AND status = 1", id).First(&dealer).Error
- return dealer, err
- }
-
- func AddSigleManufacturer(manufacturer *models.Manufacturer) (error, *models.Manufacturer) {
- err := writeDb.Create(&manufacturer).Error
- return err, manufacturer
- }
-
- func ModifyManufacturer(manufacturer *models.Manufacturer) error {
- err := writeDb.Model(&models.Manufacturer{}).Where("id = ? AND status = 1", manufacturer.ID).Updates(map[string]interface{}{
- "manufacturer_name": manufacturer.ManufacturerName,
- "contact": manufacturer.Contact,
- "contact_phone": manufacturer.ContactPhone,
- "platform_number": manufacturer.PlatformNumber,
- "email": manufacturer.Email,
- "contact_address": manufacturer.ContactAddress,
- "modifier": manufacturer.Modifier,
- "mtime": time.Now().Unix(),
- "remark": manufacturer.Remark,
- "wubi": manufacturer.WuBi,
- "pinyin": manufacturer.PinYin,
- }).Error
-
- return err
- }
-
- // 获取生产厂商名称
- func FindAllManufacturerName(orgid int64) (tmp []*models.Manufacturer, err error) {
- err = readDb.Model(&models.Manufacturer{}).Where("org_id = ? and status = 1", orgid).Find(&tmp).Error
- return
- }
-
- func FindAllManufacturerList(orgId int64, page int64, limit, key int64) (list []*models.Manufacturer, total int64, err error) {
- offset := (page - 1) * limit
- db := readDb.Model(&models.Manufacturer{})
- db = db.Where("org_id = ? AND status = 1", orgId)
- if key != 0 {
- db = db.Where("id = ?", key)
- offset = 0
- limit = 10
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
- return
- }
-
- func DeleteManufacturerById(id int64) error {
- err := writeDb.Model(&models.Manufacturer{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
- return err
- }
-
- func FindManufacturerById(id int64) (*models.Manufacturer, error) {
- dealer := &models.Manufacturer{}
- err := readDb.Model(&models.Manufacturer{}).Where("id = ? AND status = 1", id).First(&dealer).Error
- return dealer, err
- }
-
- func FindManufacturerTotal(orgId int64) (total int64) {
- db := readDb.Model(&models.Manufacturer{})
- db = db.Where("org_id = ?", orgId).Count(&total)
- return
- }
-
- func FindAllDealer(orgId int64) (dealers []*models.Dealer, err error) {
- err = readDb.Model(&models.Dealer{}).Where("org_id = ? AND status = 1", orgId).Find(&dealers).Error
- return dealers, err
- }
-
- func FindAllManufacturer(orgId int64) (manufacturer []*models.Manufacturer, err error) {
- err = readDb.Model(&models.Manufacturer{}).Where("org_id = ? AND status = 1", orgId).Find(&manufacturer).Error
- return manufacturer, err
- }
-
- func FindAllGoodTypeTotal(orgId int64) (total int64) {
- db := readDb.Model(&models.GoodsType{})
- db = db.Where("org_id = ?", orgId).Count(&total)
- return
- }
-
- func GetGoodsTypeIsExist(orgid int64) (*models.GoodsType, error) {
- goodsType := models.GoodsType{}
- err := XTReadDB().Where("org_id = ? and stock_attribute = 2 and status =1", orgid).Find(&goodsType).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &goodsType, nil
- }
-
- func GetGoodsTypeIsExistOne(orgid int64) (*models.GoodsType, error) {
- goodsType := models.GoodsType{}
- err := XTReadDB().Where("org_id = ? and stock_attribute = 3 and status = 1", orgid).Find(&goodsType).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &goodsType, nil
- }
-
- func AddSigleGoodType(goodType *models.GoodsType) (error, *models.GoodsType) {
- err := writeDb.Create(&goodType).Error
- return err, goodType
-
- }
-
- func ModifyGoodType(goodType *models.GoodsType) (error, *models.GoodsType) {
- err := writeDb.Model(&models.GoodsType{}).Where("id = ? AND status = 1", goodType.ID).Updates(map[string]interface{}{
- "modifier": goodType.Modifier,
- "mtime": time.Now().Unix(),
- "remark": goodType.Remark,
- "type_name": goodType.TypeName,
- "out_stock": goodType.OutStock,
- "stock_attribute": goodType.StockAttribute,
- }).Error
- return err, goodType
-
- }
-
- func FindAllGoodTypeList(orgId int64, page int64, limit int64, keyword string) (list []*models.GoodsType, total int64, err error) {
- offset := (page - 1) * limit
- db := readDb.Model(&models.GoodsType{})
- db = db.Where("org_id=? AND status = 1", orgId)
- if len(keyword) > 0 {
- likeKey := "%" + keyword + "%"
- db = db.Where("type_code LIKE ? OR type_name LIKE ?", likeKey, likeKey)
- }
-
- err = db.Count(&total).Offset(offset).Limit(limit).Order("type desc, number desc,ctime desc").Find(&list).Error
- return
- }
-
- func DeleteGoodTypeById(id int64, operateId int64) error {
- err := writeDb.Model(&models.GoodsType{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0, "modifier": operateId}).Error
- writeDb.Model(&models.GoodInfo{}).Where("good_type_id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0, "modifier": operateId})
- return err
- }
-
- func FindGoodTypeById(id int64) (*models.GoodsType, error) {
- goodType := &models.GoodsType{}
- err := readDb.Model(&models.GoodsType{}).Where("id = ? AND status = 1", id).First(&goodType).Error
- return goodType, err
- }
-
- func FindAllGoodInfoTotal(orgId int64) (total int64) {
- db := readDb.Model(&models.GoodInfo{})
- db = db.Where("org_id = ?", orgId).Count(&total)
- return
- }
-
- func AddSigleGoodInfo(goodInfo *models.GoodInfo) (error, *models.GoodInfo) {
- err := writeDb.Create(&goodInfo).Error
- return err, goodInfo
-
- }
-
- func ModifyGoodInfo(goodInfo *models.GoodInfo) (error, *models.GoodInfo) {
-
- err := writeDb.Model(&models.GoodInfo{}).Where("id = ? AND status = 1", goodInfo.ID).Updates(map[string]interface{}{
- "good_type_id": goodInfo.GoodTypeId,
- "modifier": goodInfo.Modifier,
- "mtime": time.Now().Unix(),
- "remark": goodInfo.Remark,
- "specification_name": goodInfo.SpecificationName,
- "good_unit": goodInfo.GoodUnit,
- "buy_price": goodInfo.BuyPrice,
- "sell_price": goodInfo.SellPrice,
- "manufacturer": goodInfo.Manufacturer,
- "dealer": goodInfo.Dealer,
- "expiry_date_warn_day_count": goodInfo.ExpiryDateWarnDayCount,
- "stock_warn_count": goodInfo.StockWarnCount,
- "is_reuse": goodInfo.IsReuse,
- "good_name": goodInfo.GoodName,
- "pinyin": goodInfo.Pinyin,
- "wubi": goodInfo.Wubi,
- "good_kind": goodInfo.GoodKind,
- "medical_insurance_level": goodInfo.MedicalInsuranceLevel,
- "retail_price": goodInfo.PackingPrice,
- "medical_insurance_number": goodInfo.MedicalInsuranceNumber,
- "is_special_diseases": goodInfo.IsSpecialDiseases,
- "is_record": goodInfo.IsRecord,
- "statistics_category": goodInfo.StatisticsCategory,
- "good_status": goodInfo.GoodStatus,
- "default_count": goodInfo.DefaultCount,
- "sign": goodInfo.Sign,
- "is_default": goodInfo.IsDefault,
- "is_charge_use": goodInfo.IsChargeUse,
- "is_charge_predict": goodInfo.IsChargePredict,
- "is_statistics_work": goodInfo.IsStatisticsWork,
- "sort": goodInfo.Sort,
- "is_doctor_use": goodInfo.IsDoctorUse,
- "agent": goodInfo.Agent,
- "good_number": goodInfo.GoodNumber,
- "social_security_directory_code": goodInfo.SocialSecurityDirectoryCode,
- "special_medical": goodInfo.SpecialMedical,
- "production_type": goodInfo.ProductionType,
- "min_number": goodInfo.MinNumber,
- "packing_unit": goodInfo.PackingUnit,
- "packing_price": goodInfo.PackingPrice,
- "default_count_unit": goodInfo.DefaultCountUnit,
- "min_unit": goodInfo.MinUnit,
- "register_number": goodInfo.RegisterNumber,
- "provinces_code": goodInfo.ProvincesCode,
- "is_user": goodInfo.IsUser,
- "number": goodInfo.Number,
- "is_warehouse": goodInfo.IsWarehouse,
- "bbx01": goodInfo.Bbx01,
- "bby01": goodInfo.Bby01,
- "zuobiao_id": goodInfo.Bbx01,
- "first_letter": goodInfo.FirstLetter,
- "is_show": goodInfo.IsShow,
- "is_zero_flag": goodInfo.IsZeroFlag,
- }).Error
-
- writeDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND org_id = ?", goodInfo.ID, goodInfo.OrgId).Updates(map[string]interface{}{"good_type_id": goodInfo.GoodTypeId})
- writeDb.Model(&models.WarehouseOutInfo{}).Where("good_id = ? AND org_id = ?", goodInfo.ID, goodInfo.OrgId).Updates(map[string]interface{}{"good_type_id": goodInfo.GoodTypeId})
- writeDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND org_id = ?", goodInfo.ID, goodInfo.OrgId).Updates(map[string]interface{}{"good_type_id": goodInfo.GoodTypeId})
- writeDb.Model(&models.DialysisBeforePrepare{}).Where("good_id = ? AND user_org_id = ?", goodInfo.ID, goodInfo.OrgId).Updates(map[string]interface{}{"good_type_id": goodInfo.GoodTypeId})
- writeDb.Model(&models.SalesReturnInfo{}).Where("good_id = ? AND org_id = ?", goodInfo.ID, goodInfo.OrgId).Updates(map[string]interface{}{"good_type_id": goodInfo.GoodTypeId})
- writeDb.Model(&models.CancelStockInfo{}).Where("good_id = ? AND org_id = ?", goodInfo.ID, goodInfo.OrgId).Updates(map[string]interface{}{"good_type_id": goodInfo.GoodTypeId})
- return err, goodInfo
-
- }
-
- func FindGoodInfoList(orgId int64, page int64, limit int64, keyword string, is_use int64, is_charge int64, good_kind int64, is_mark int64, manufacturer int64, is_type int64) (list []*models.GoodInfo, total int64, err error) {
- offset := (page - 1) * limit
- db := readDb.Model(&models.GoodInfo{})
- db = db.Where("org_id = ? AND status = 1", orgId)
- db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgId)
- if len(keyword) > 0 {
- likeKey := "%" + keyword + "%"
- db = db.Where("good_code LIKE ? OR good_name LIKE ?", likeKey, likeKey)
- if is_use > 0 {
- if is_use == 2 {
- db = db.Where("find_in_set('停用',good_status) = 0")
- } else {
- db = db.Where("find_in_set('停用',good_status) > 0")
- }
- }
- if is_charge > 0 {
- if is_charge == 1 {
- db = db.Where("find_in_set('收费',good_status) > 0")
- } else {
- db = db.Where("find_in_set('收费',good_status) = 0")
- }
- }
- if good_kind > 0 {
- db = db.Where(" good_kind = ?", good_kind)
- }
-
- if is_mark > 0 {
- db = db.Where("is_mark = ?", is_mark)
- }
- if manufacturer > 0 {
- db = db.Where("manufacturer = ?", manufacturer)
- }
- if is_type > 0 {
- db = db.Where("good_type_id = ?", is_type)
- }
- } else {
- if is_use > 0 {
- if is_use == 2 {
- db = db.Where("find_in_set('停用',good_status) = 0")
- } else {
- db = db.Where("find_in_set('停用',good_status) > 0")
- }
- }
- if is_charge > 0 {
- if is_charge == 1 {
- db = db.Where("find_in_set('收费',good_status) > 0")
- } else {
- db = db.Where("find_in_set('收费',good_status) = 0")
- }
- }
- if good_kind > 0 {
- db = db.Where(" good_kind = ?", good_kind)
- }
-
- if is_mark > 0 {
- db = db.Where("is_mark = ?", is_mark)
- }
- if manufacturer > 0 {
- db = db.Where("manufacturer = ?", manufacturer)
- }
- if is_type > 0 {
- db = db.Where("good_type_id = ?", is_type)
- }
- }
-
- err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
- return
- }
-
- func DeleteGoodInfoById(id int64, operateId int64) error {
- err := writeDb.Model(&models.GoodInfo{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0, "modifier": operateId}).Error
- return err
- }
-
- func FindGoodInfoByGoodId(id int64) (list []*models.GoodInfo, err error) {
- err = readDb.Model(&models.GoodInfo{}).Where("good_type_id = ? AND status = 1", id).Find(&list).Error
- return list, err
- }
-
- func FindStockOutDetailGoodInfoByGoodId(id int64) (list []*models.AutomaticReduceDetail, err error) {
- err = readDb.Model(&models.AutomaticReduceDetail{}).Where("good_type_id = ? AND status = 1", id).Find(&list).Error
- return list, err
- }
-
- func FindGoodInfoById(id int64) (*models.GoodInfo, error) {
- goodInfo := &models.GoodInfo{}
- err := readDb.Model(&models.GoodInfo{}).Where("id = ? AND status = 1", id).First(&goodInfo).Error
- return goodInfo, err
- }
-
- func FindAllGoodType(org_id int64) (goodType []*models.GoodsType, err error) {
- err = XTReadDB().Model(&models.GoodsType{}).Where("org_id = ? AND status = 1", org_id).Find(&goodType).Error
- return goodType, err
- }
-
- func FindAllGoodTypeOne(org_id int64) (goodType []*models.GoodsType, err error) {
- err = readDb.Model(&models.GoodsType{}).Where("org_id = ? AND status = 1 and out_stock = 1", org_id).Find(&goodType).Error
- return goodType, err
- }
-
- func FindAllGoodInfo(org_id int64) (goodInfo []*models.GoodInfo, err error) {
- err = XTReadDB().Model(&models.GoodInfo{}).Where("org_id = ? AND status = 1 and is_warehouse = 1 and find_in_set('停用',good_status) = 0", org_id).Find(&goodInfo).Error
- return goodInfo, err
- }
-
- func FindAllGoodInfoTwo(org_id int64) (goodInfo []*models.GoodInfo, err error) {
- err = XTReadDB().Model(&models.GoodInfo{}).Where("org_id = ? AND status = 1", org_id).Find(&goodInfo).Error
- return goodInfo, err
- }
-
- func FindAllGoodInfoThree(org_id int64) (goodInfo []*models.XtGoodInformationFourty, err error) {
- err = XTReadDB().Model(&models.XtGoodInformationFourty{}).Where("org_id = ? AND status = 1 and find_in_set('停用',good_status) = 0", org_id).Find(&goodInfo).Error
- return goodInfo, err
- }
-
- func FindAllWarehouseTotal(org_id int64) (total int64, err error) {
- err = readDb.Model(&models.Warehousing{}).Where("org_id = ?", org_id).Count(&total).Error
- return total, err
- }
-
- func FindNewAllWarehouseTotal(org_id int64, tx *gorm.DB) (total int64, err error) {
-
- err = tx.Model(&models.Warehousing{}).Where("org_id = ?", org_id).Count(&total).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return total, err
- }
- }
- return total, err
- }
-
- func FindAllWarehouseTotalOne(org_id int64) (total int64, err error) {
- err = readDb.Model(&models.XtDrugWarehouse{}).Where("org_id = ?", org_id).Count(&total).Error
- return total, err
- }
-
- func FindNewAllWarehouseTotalOne(org_id int64, tx *gorm.DB) (total int64, err error) {
-
- err = tx.Model(&models.XtDrugWarehouse{}).Where("org_id = ?", org_id).Count(&total).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return total, err
- }
- }
- return total, err
- }
-
- func AddSigleWarehouse(warehouse *models.Warehousing) error {
- err := writeDb.Create(&warehouse).Error
- return err
- }
-
- func AddNewSigleWarehouse(warehouse *models.Warehousing, tx *gorm.DB) error {
- err := writeDb.Create(&warehouse).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
- func UpdateWarehouse(id int64, storehouse_id int64) error {
-
- err := XTWriteDB().Model(&models.Warehousing{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"storehouse_id": storehouse_id}).Error
- return err
- }
-
- func UpdateNewWarehouse(id int64, storehouse_id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.Warehousing{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"storehouse_id": storehouse_id}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func AddSigleDrugWarehouse(warehouse *models.DrugWarehouse) error {
- err := writeDb.Create(&warehouse).Error
- return err
-
- }
-
- func AddNewSigleDrugWarehouse(warehouse *models.DrugWarehouse, tx *gorm.DB) error {
-
- err := tx.Create(&warehouse).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
-
- }
-
- func UpdateSigleDrugWarehouse(id int64, storehosue_id int64) error {
- err := XTWriteDB().Model(&models.DrugWarehouse{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"storehouse_id": storehosue_id}).Error
- return err
- }
-
- func UpdateNewSigleDrugWarehouse(id int64, storehosue_id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouse{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"storehouse_id": storehosue_id}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func AddSigleSalesReturn(salesReturn *models.SalesReturn) error {
- err := writeDb.Create(&salesReturn).Error
- return err
-
- }
-
- func AddSigleDrugSalesReturn(salesReturn *models.DrugSalesReturn) error {
- err := writeDb.Create(&salesReturn).Error
- return err
-
- }
-
- func UpDateGoodReturnStatus(ids []string) {
- writeDb.Model(&models.WarehousingInfo{}).Where("id IN (?)", ids).Update(map[string]interface{}{"is_return": 1})
-
- }
-
- func UpDateCanCelStockStatus(ids []string) {
- writeDb.Model(&models.WarehouseOutInfo{}).Where("id IN (?)", ids).Update(map[string]interface{}{"is_cancel": 1})
-
- }
-
- func CreateWarehousingInfo(warehousingInfo []*models.WarehousingInfo) (err error) {
- if len(warehousingInfo) > 0 {
- utx := writeDb.Begin()
- if len(warehousingInfo) > 0 {
- thisSQL := "INSERT INTO xt_warehouse_info (warehousing_id, good_id, good_type_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,stock_count,license_number,packing_price,storehouse_id,good_code) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, info := range warehousingInfo {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, info.WarehousingId)
- insertData = append(insertData, info.GoodId)
- insertData = append(insertData, info.GoodTypeId)
- insertData = append(insertData, info.Number)
- insertData = append(insertData, info.ProductDate)
- insertData = append(insertData, info.ExpiryDate)
- insertData = append(insertData, info.WarehousingCount)
- insertData = append(insertData, info.Price)
- insertData = append(insertData, info.TotalPrice)
- insertData = append(insertData, info.Dealer)
- insertData = append(insertData, info.Manufacturer)
- insertData = append(insertData, info.Remark)
- insertData = append(insertData, info.Ctime)
- insertData = append(insertData, info.Mtime)
- insertData = append(insertData, info.Status)
- insertData = append(insertData, info.OrgId)
- insertData = append(insertData, info.WarehousingOrder)
- insertData = append(insertData, info.Type)
- insertData = append(insertData, info.WarehousingCount)
- insertData = append(insertData, info.LicenseNumber)
- insertData = append(insertData, info.PackingPrice)
- insertData = append(insertData, info.StorehouseId)
- insertData = append(insertData, info.GoodCode)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- }
- return
-
- }
-
- func CreateNewWarehousingInfo(warehousingInfo []*models.WarehousingInfo, tx *gorm.DB) (err error) {
- if len(warehousingInfo) > 0 {
-
- if len(warehousingInfo) > 0 {
- thisSQL := "INSERT INTO xt_warehouse_info (warehousing_id, good_id, good_type_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,stock_count,license_number,packing_price,storehouse_id,good_code) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, info := range warehousingInfo {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, info.WarehousingId)
- insertData = append(insertData, info.GoodId)
- insertData = append(insertData, info.GoodTypeId)
- insertData = append(insertData, info.Number)
- insertData = append(insertData, info.ProductDate)
- insertData = append(insertData, info.ExpiryDate)
- insertData = append(insertData, info.WarehousingCount)
- insertData = append(insertData, info.Price)
- insertData = append(insertData, info.TotalPrice)
- insertData = append(insertData, info.Dealer)
- insertData = append(insertData, info.Manufacturer)
- insertData = append(insertData, info.Remark)
- insertData = append(insertData, info.Ctime)
- insertData = append(insertData, info.Mtime)
- insertData = append(insertData, info.Status)
- insertData = append(insertData, info.OrgId)
- insertData = append(insertData, info.WarehousingOrder)
- insertData = append(insertData, info.Type)
- insertData = append(insertData, info.WarehousingCount)
- insertData = append(insertData, info.LicenseNumber)
- insertData = append(insertData, info.PackingPrice)
- insertData = append(insertData, info.StorehouseId)
- insertData = append(insertData, info.GoodCode)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = tx.Exec(thisSQL, insertData...).Error
- if err != nil {
- tx.Rollback()
- return
- }
- }
- }
- return
-
- }
-
- func CreateDrugWarehousingInfo(warehousingInfo []*models.DrugWarehouseInfo) (err error) {
- if len(warehousingInfo) > 0 {
- utx := writeDb.Begin()
- if len(warehousingInfo) > 0 {
- thisSQL := "INSERT INTO xt_drug_warehouse_info (warehousing_id, drug_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,retail_price,retail_total_price,stock_max_number,max_unit,min_unit,batch_number,stock_min_number,storehouse_id) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, info := range warehousingInfo {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, info.WarehousingId)
- insertData = append(insertData, info.DrugId)
- insertData = append(insertData, info.Number)
- insertData = append(insertData, info.ProductDate)
- insertData = append(insertData, info.ExpiryDate)
- insertData = append(insertData, info.WarehousingCount)
- insertData = append(insertData, info.Price)
- insertData = append(insertData, info.TotalPrice)
- insertData = append(insertData, info.Dealer)
- insertData = append(insertData, info.Manufacturer)
- insertData = append(insertData, info.Remark)
- insertData = append(insertData, info.Ctime)
- insertData = append(insertData, info.Mtime)
- insertData = append(insertData, info.Status)
- insertData = append(insertData, info.OrgId)
- insertData = append(insertData, info.WarehousingOrder)
- insertData = append(insertData, info.Type)
- insertData = append(insertData, info.RetailPrice)
- insertData = append(insertData, info.RetailTotalPrice)
- insertData = append(insertData, info.StockMaxNumber)
- insertData = append(insertData, info.MaxUnit)
- insertData = append(insertData, info.MinUnit)
- insertData = append(insertData, info.BatchNumber)
- insertData = append(insertData, info.StockMinNumber)
- insertData = append(insertData, info.StorehouseId)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- }
- return
- }
-
- func CreateNewDrugWarehousingInfo(warehousingInfo []*models.DrugWarehouseInfo, tx *gorm.DB) (err error) {
- if len(warehousingInfo) > 0 {
-
- if len(warehousingInfo) > 0 {
- thisSQL := "INSERT INTO xt_drug_warehouse_info (warehousing_id, drug_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,retail_price,retail_total_price,stock_max_number,max_unit,min_unit,batch_number,stock_min_number,storehouse_id) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, info := range warehousingInfo {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, info.WarehousingId)
- insertData = append(insertData, info.DrugId)
- insertData = append(insertData, info.Number)
- insertData = append(insertData, info.ProductDate)
- insertData = append(insertData, info.ExpiryDate)
- insertData = append(insertData, info.WarehousingCount)
- insertData = append(insertData, info.Price)
- insertData = append(insertData, info.TotalPrice)
- insertData = append(insertData, info.Dealer)
- insertData = append(insertData, info.Manufacturer)
- insertData = append(insertData, info.Remark)
- insertData = append(insertData, info.Ctime)
- insertData = append(insertData, info.Mtime)
- insertData = append(insertData, info.Status)
- insertData = append(insertData, info.OrgId)
- insertData = append(insertData, info.WarehousingOrder)
- insertData = append(insertData, info.Type)
- insertData = append(insertData, info.RetailPrice)
- insertData = append(insertData, info.RetailTotalPrice)
- insertData = append(insertData, info.StockMaxNumber)
- insertData = append(insertData, info.MaxUnit)
- insertData = append(insertData, info.MinUnit)
- insertData = append(insertData, info.BatchNumber)
- insertData = append(insertData, info.StockMinNumber)
- insertData = append(insertData, info.StorehouseId)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = tx.Exec(thisSQL, insertData...).Error
- if err != nil {
- tx.Rollback()
- return
- }
- }
- }
- return
- }
-
- func CreateDrugWarehousingInfoSix(warehousingInfo []*models.DrugWarehouseInfo) (err error) {
- if len(warehousingInfo) > 0 {
- utx := writeDb.Begin()
- if len(warehousingInfo) > 0 {
- thisSQL := "INSERT INTO xt_drug_warehouse_info (warehousing_id, drug_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,retail_price,retail_total_price,stock_max_number,max_unit,min_unit,batch_number,stock_min_number,supply_warehouse_id,supply_warehouse_detail_info,storehouse_id,is_check) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, info := range warehousingInfo {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, info.WarehousingId)
- insertData = append(insertData, info.DrugId)
- insertData = append(insertData, info.Number)
- insertData = append(insertData, info.ProductDate)
- insertData = append(insertData, info.ExpiryDate)
- insertData = append(insertData, info.WarehousingCount)
- insertData = append(insertData, info.Price)
- insertData = append(insertData, info.TotalPrice)
- insertData = append(insertData, info.Dealer)
- insertData = append(insertData, info.Manufacturer)
- insertData = append(insertData, info.Remark)
- insertData = append(insertData, info.Ctime)
- insertData = append(insertData, info.Mtime)
- insertData = append(insertData, info.Status)
- insertData = append(insertData, info.OrgId)
- insertData = append(insertData, info.WarehousingOrder)
- insertData = append(insertData, info.Type)
- insertData = append(insertData, info.RetailPrice)
- insertData = append(insertData, info.RetailTotalPrice)
- insertData = append(insertData, info.StockMaxNumber)
- insertData = append(insertData, info.MaxUnit)
- insertData = append(insertData, info.MinUnit)
- insertData = append(insertData, info.BatchNumber)
- insertData = append(insertData, info.StockMinNumber)
- insertData = append(insertData, info.SupplyWarehouseId)
- insertData = append(insertData, info.SupplyWarehouseDetailInfo)
- insertData = append(insertData, info.StorehouseId)
- insertData = append(insertData, info.IsCheck)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- }
- return
- }
-
- func UpdateDrugInfo(warehousingInfo []*models.DrugWarehouseInfo) (err error) {
- var total float64
- var min_number int64
- for _, item := range warehousingInfo {
- //查询刚入库耗材的库存
- count, _ := FindDrugWaresingCount(item.DrugId, item.OrgId)
- //更新药品库的总量
- info, _ := FindeDrugInfo(item.DrugId)
-
- min_number = count.StockMaxNumber * info.MinNumber
- str := strconv.FormatInt(min_number, 10)
- minFloat, _ := strconv.ParseFloat(str, 64)
- total = info.Total + minFloat
- lib := models.BaseDrugLib{
- Total: total,
- }
- UpdateBaseDrug(&lib, item.ID)
- }
- return err
- }
-
- func FindDrugWaresingCount(drug_id int64, orgid int64) (models.XtDrugWarehouseInfo, error) {
-
- info := models.XtDrugWarehouseInfo{}
- db := XTReadDB().Table("xt_drug_warehouse_info").Where("status = 1")
- err = db.Select("stock_max_number,drug_id").Where("drug_id = ? and org_id = ? and status =1", drug_id, orgid).Last(&info).Error
- return info, err
- }
-
- func FindeDrugInfo(drug_id int64) (models.BaseDrugLib, error) {
-
- lib := models.BaseDrugLib{}
- err := XTReadDB().Model(&lib).Where("id = ?", drug_id).Find(&lib).Error
- return lib, err
- }
-
- func UpdateBaseDrug(lib *models.BaseDrugLib, id int64) error {
-
- err := XTWriteDB().Model(&lib).Where("id = ?", id).Updates(map[string]interface{}{"total": lib.Total}).Error
- return err
- }
-
- func UpdateBaseDrugOne(lib models.BaseDrugLib, id int64) error {
-
- err := XTWriteDB().Model(&lib).Where("id = ?", id).Updates(map[string]interface{}{"retail_price": lib.RetailPrice, "last_price": lib.LastPrice}).Error
- return err
- }
- func FindeLastWarehouseInfo(id int64) (models.DrugWarehouseInfo, error) {
- info := models.DrugWarehouseInfo{}
- err := XTReadDB().Model(&info).Where("id=? and status = 1", id).Find(&info).Error
- return info, err
- }
-
- func GetLastWarehouseOut(orgid int64) (models.DrugWarehouseOut, error) {
-
- out := models.DrugWarehouseOut{}
- err := XTReadDB().Where("org_id = ? and status = 1", orgid).Last(&out).Error
- return out, err
- }
-
- func CreateDrugFlow(drugflow []*models.DrugFlow) (err error) {
- if len(drugflow) > 0 {
- utx := writeDb.Begin()
- if len(drugflow) > 0 {
- thisSQL := "INSERT INTO xt_drug_flow (warehousing_id, drug_id, number,batch_number,count,user_org_id,patient_id,system_time,consumable_type,is_sys,warehousing_order,warehouse_out_id,warehouse_out_order_number,is_edit,cancel_stock_id,cancel_order_number,manufacturer,dealer,creator,update_creator,status,ctime,mtime,price,warehousing_detail_id,warehouse_out_detail_id,cancel_out_detail_id,expire_date,product_date,max_unit,min_unit,storehouse_id) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, info := range drugflow {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, info.WarehousingId)
- insertData = append(insertData, info.DrugId)
- insertData = append(insertData, info.Number)
- insertData = append(insertData, info.BatchNumber)
- insertData = append(insertData, info.Count)
- insertData = append(insertData, info.UserOrgId)
- insertData = append(insertData, info.PatientId)
- insertData = append(insertData, info.SystemTime)
- insertData = append(insertData, info.ConsumableType)
- insertData = append(insertData, info.IsSys)
- insertData = append(insertData, info.WarehousingOrder)
- insertData = append(insertData, info.WarehouseOutId)
- insertData = append(insertData, info.WarehouseOutOrderNumber)
-
- insertData = append(insertData, info.IsEdit)
- insertData = append(insertData, info.CancelStockId)
- insertData = append(insertData, info.CancelOrderNumber)
- insertData = append(insertData, info.Manufacturer)
- insertData = append(insertData, info.Dealer)
- insertData = append(insertData, info.Creator)
- insertData = append(insertData, info.UpdateCreator)
- insertData = append(insertData, info.Status)
- insertData = append(insertData, info.Ctime)
- insertData = append(insertData, info.Mtime)
- insertData = append(insertData, info.Price)
- insertData = append(insertData, info.WarehousingDetailId)
- insertData = append(insertData, info.WarehouseOutDetailId)
- insertData = append(insertData, info.CancelOutDetailId)
- insertData = append(insertData, info.ExpireDate)
- insertData = append(insertData, info.ProductDate)
- insertData = append(insertData, info.MaxUnit)
- insertData = append(insertData, info.MinUnit)
- insertData = append(insertData, info.StorehouseId)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- }
- return
- }
-
- func GetDrugFlowIsExist(warhouseing int64, drug_id int64) (*models.DrugFlow, error) {
-
- info := models.DrugFlow{}
- err = XTReadDB().Where("warehousing_id = ? and drug_id = ? and status = 1", warhouseing, drug_id).Find(&info).Error
-
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &info, nil
- }
-
- func GetDrugByWarehouseInfo(id int64) (models.XtDrugWarehouseInfo, error) {
-
- info := models.XtDrugWarehouseInfo{}
- err := XTReadDB().Where("id=? and status = 1", id).Find(&info).Error
- return info, err
- }
-
- func UpdateDrugWarehouseingInfo(id int64, info models.XtDrugWarehouseInfo) error {
-
- warehouseInfo := models.XtDrugWarehouseInfo{}
- err := XTWriteDB().Model(&warehouseInfo).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_max_number": info.StockMaxNumber}).Error
- return err
- }
-
- func CreateDrugFlowOne(flow models.DrugFlow) error {
- ut := writeDb.Begin()
- err := ut.Create(&flow).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- ut.Commit()
- return err
- }
-
- func CreateSelfDrugFlowTwo(flow models.XtSelfDrugFlow) error {
- ut := writeDb.Begin()
- err := ut.Create(&flow).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- ut.Commit()
- return err
- }
-
- func CreateNewDrugFlowOne(flow models.DrugFlow, tx *gorm.DB) error {
-
- err := tx.Create(&flow).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpdateDrugFlowSeven(patientid int64, recorddate int64, drugid int64, advice_id int64, id int64) (models.DrugAutomaticReduceDetail, error) {
- detail := models.DrugAutomaticReduceDetail{}
- err := XTWriteDB().Model(&detail).Where("patient_id = ? and record_time = ? and drug_id = ? and status= 1 and advice_id =? ", patientid, recorddate, drugid, advice_id).Updates(map[string]interface{}{"status": 0}).Error
- err = XTWriteDB().Model(&models.DrugWarehouseOutInfo{}).Where("patient_id =? and sys_record_time =? and drug_id = ? and status = 1 and advice_id =?", patientid, recorddate, drugid, advice_id).Updates(map[string]interface{}{"status": 0}).Error
- return detail, err
- }
-
- func UpdateSelfDrugFlowSeven(patientid int64, recorddate int64, drugid int64, advice_id int64, id int64) (models.XtSelfDrugWarehouseOutInfo, error) {
-
- detail := models.XtSelfDrugWarehouseOutInfo{}
- err = XTWriteDB().Model(&models.XtSelfDrugWarehouseOutInfo{}).Where("patient_id =? and sys_record_time =? and drug_id = ? and status = 1 and advice_id =?", patientid, recorddate, drugid, advice_id).Updates(map[string]interface{}{"status": 0}).Error
- return detail, err
- }
-
- func UpdateDrugFlowTens(patientid int64, warehouse_out_number string, drug_id int64, advice_id int64) (models.DrugFlow, error) {
- flow := models.DrugFlow{}
- err := XTWriteDB().Model(&flow).Where("patient_id =? and warehouse_out_order_number = ? and drug_id = ? and status = 1 and advice_id =?", patientid, warehouse_out_number, drug_id, advice_id).Updates(map[string]interface{}{"is_read": 1}).Error
- return flow, err
- }
-
- func UpdateDrugFlowTensOne(patientid int64, warehouse_out_number string, drug_id int64, advice_id int64) (models.XtSelfDrugFlow, error) {
- flow := models.XtSelfDrugFlow{}
- err := XTWriteDB().Model(&flow).Where("patient_id =? and warehouse_out_order_number = ? and drug_id = ? and status = 1 and advice_id =?", patientid, warehouse_out_number, drug_id, advice_id).Updates(map[string]interface{}{"is_read": 1}).Error
- return flow, err
- }
-
- func CreateDrugFlowTwo(flow *models.DrugFlow) error {
- tx := XTWriteDB().Begin()
- err := tx.Create(&flow).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- tx.Commit()
- return err
- }
-
- func CreateNewDrugFlowTwo(flow *models.DrugFlow, tx *gorm.DB) error {
-
- err := tx.Create(&flow).Error
- if err != nil {
- tx.Rollback()
- return err
- }
-
- return err
- }
-
- func FindLastWarehousingInfo(order string) (info models.WarehousingInfo, err error) {
- err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_order = ? AND status = 1", order).Last(&info).Error
-
- return info, err
-
- }
-
- func GetLastWarehousingInfo(goodid int64) (models.WarehousingInfo, error) {
- info := models.WarehousingInfo{}
- err := XTReadDB().Model(&info).Where("good_id = ? and status = 1", goodid).Last(&info).Error
- return info, err
- }
-
- func CreatedWarehouseingDetail(info *models.WarehousingInfo) error {
-
- err := XTWriteDB().Create(&info).Error
- return err
- }
-
- func CreatedNewWarehouseingDetail(info *models.WarehousingInfo, tx *gorm.DB) error {
-
- err := tx.Create(&info).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func FindFirstWarehousingInfoByStock(good_id int64, good_type_id int64, storehouse_id int64) (info models.WarehousingInfo, err error) {
- if storehouse_id == 0 {
- err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND good_type_id = ? AND status = 1 and stock_count > 0", good_id, good_type_id).Order("ctime").First(&info).Error
- }
- if storehouse_id > 0 {
- err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND good_type_id = ? AND status = 1 and stock_count > 0 and storehouse_id =? ", good_id, good_type_id, storehouse_id).Order("ctime").First(&info).Error
- }
-
- return info, err
- }
-
- func FindNewFirstWarehousingInfoByStock(good_id int64, good_type_id int64, storehouse_id int64, tx *gorm.DB) (info models.WarehousingInfo, err error) {
- if storehouse_id == 0 {
- err = tx.Model(&models.WarehousingInfo{}).Where("good_id = ? AND good_type_id = ? AND status = 1 and stock_count > 0", good_id, good_type_id).Order("ctime").First(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- }
- if storehouse_id > 0 {
- err = tx.Model(&models.WarehousingInfo{}).Where("good_id = ? AND good_type_id = ? AND status = 1 and stock_count > 0 and storehouse_id =? ", good_id, good_type_id, storehouse_id).Order("ctime").First(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- }
-
- return info, err
- }
-
- func FindFirstWarehousingInfoByStockTwo(good_id int64, good_type_id int64, storehouse_id int64) (info models.VmWarehousingInfo, err error) {
- db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
- if good_id > 0 {
- db = db.Where("x.good_id = ?", good_id)
- }
- if good_type_id > 0 {
- db = db.Where("x.good_type_id = ?", good_type_id)
- }
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
- err = db.Select("sum(x.stock_count) as count").Scan(&info).Error
- return info, err
- }
-
- func FindWarehousingInfoByIdSeven(id int64) (models.WarehousingInfo, error) {
- info := models.WarehousingInfo{}
- err := XTReadDB().Model(&info).Where("id= ? and status = 1", id).Find(&info).Error
- return info, err
- }
-
- func FindWarehousingInfoTen(goodId int64, storehouse_id int64) (models.WarehousingInfo, error) {
- info := models.WarehousingInfo{}
- var err error
- if storehouse_id == 0 {
- err = XTReadDB().Select(" good_id,sum(stock_count) as stock_count").Where("good_id = ? and status = 1 and is_check = 1", goodId).Find(&info).Error
- }
- if storehouse_id > 0 {
- err = XTReadDB().Select(" good_id,sum(stock_count) as stock_count").Where("good_id = ? and status = 1 and storehouse_id = ? and is_check = 1", goodId, storehouse_id).Find(&info).Error
- }
-
- return info, err
- }
-
- func FindNewWarehousingInfoTen(goodId int64, storehouse_id int64, tx *gorm.DB) (models.WarehousingInfo, error) {
-
- info := models.WarehousingInfo{}
- var err error
- if storehouse_id == 0 {
- err = tx.Select(" good_id,sum(stock_count) as stock_count").Where("good_id = ? and status = 1 and is_check = 1", goodId).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- }
- if storehouse_id > 0 {
- err := tx.Select(" good_id,sum(stock_count) as stock_count").Where("good_id = ? and status = 1 and storehouse_id = ? and is_check = 1", goodId, storehouse_id).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- }
-
- return info, err
- }
-
- //药品先进先出,找出最先入库的批次
-
- func FindLastDrugWarehousingInfoByID(drug_id int64, storehouse_id int64) (info models.XtDrugWarehouseInfo, err error) {
- err = readDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0) and storehouse_id = ? and is_check = 1", drug_id, storehouse_id).Order("ctime").First(&info).Error
- return info, err
- }
-
- func FindLastDrugWarehousingInfoByIDTwo(drug_id int64, storehouse_id int64) (info models.XtDrugWarehouseInfo, err error) {
- err = readDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ? AND status = 1 and storehouse_id = ? and is_check = 1", drug_id, storehouse_id).Order("ctime").Last(&info).Error
- return info, err
- }
-
- func FindNewLastDrugWarehousingInfoByID(drug_id int64, storehouse_id int64, tx *gorm.DB) (info models.XtDrugWarehouseInfo, err error) {
- err = tx.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0) and storehouse_id = ? and is_check = 1", drug_id, storehouse_id).Order("ctime").First(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
-
- return info, err
- }
-
- func FindLastDrugWarehousingInfoByIDSix(drug_id int64, warehouse_out_id int64, is_source int64, storehouse_id int64) (info models.XtDrugWarehouseInfo, err error) {
- if is_source == 1 {
- err = readDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0) and supply_warehouse_id = ? and storehouse_id = ?", drug_id, warehouse_out_id, storehouse_id).Order("ctime").First(&info).Error
- }
-
- if is_source == 2 || is_source == 0 {
- err = readDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0) and storehouse_id = ?", drug_id, storehouse_id).Order("ctime").First(&info).Error
- }
- return info, err
- }
-
- // 出库时先进先出,找出最先入库的批次
- func FindLastWarehousingInfoByID(drug_id int64) (info models.WarehousingInfo, err error) {
- err = readDb.Model(&models.WarehousingInfo{}).Where("drup_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0) ", drug_id).Order("ctime").First(&info).Error
- return info, err
- }
-
- //
- //// 出库时先进先出,找出最先入库的批次
- //func (drug_id int64) (info models.WarehousingInfo, err error) {
- // err = readDb.Model(&models.WarehousingInfo{}).Where("drup_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0) ", drug_id).Order("ctime").First(&info).Error
- // return info, err
- //}
-
- func FindLastDrugWarehousingInfo(order string) (info models.DrugWarehouseInfo, err error) {
- err = readDb.Model(&models.DrugWarehouseInfo{}).Where("warehousing_order = ? AND status = 1", order).Last(&info).Error
-
- return info, err
-
- }
-
- func FindAllWarehousingList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string, ids []int64, storehouse_id int64, check_type int64) (list []*models.Warehousing, total int64, err error) {
- offset := (page - 1) * limit
- db := readDb.Model(&models.Warehousing{})
-
- db = db.Where("xt_warehouse.org_id = ? AND xt_warehouse.status = 1 AND xt_warehouse.type = ?", orgId, types)
-
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
-
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_warehouse.creater")
-
- db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_warehouse.warehousing_order LIKE ? or xt_warehouse.id in(?)", likeKey, likeKey, ids).Group("xt_warehouse.id")
- }
-
- if startTime > 0 {
- db = db.Where("xt_warehouse.operation_time >=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("xt_warehouse.operation_time<= ?", endTime)
- }
- if storehouse_id > 0 {
- db = db.Where("xt_warehouse.storehouse_id = ?", storehouse_id)
- }
-
- if check_type == 0 {
- db = db.Where("xt_warehouse.is_check = 0 or xt_warehouse.is_check = 1 or xt_warehouse.is_check = 2")
- }
- if check_type > 0 {
- db = db.Where("xt_warehouse.is_check = ?", check_type)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Order("xt_warehouse.ctime desc").Find(&list).Error
- return
- }
-
- func GetGoodInforByGoodName(keyword string, orgid int64) (goodInfo []*models.GoodInfo, err error) {
-
- db := XTReadDB().Model(&goodInfo).Where("status = 1")
- if orgid > 0 {
- db = db.Where("org_id = ?", orgid)
- }
- if len(keyword) > 0 {
- likeKey := "%" + keyword + "%"
- db = db.Where("good_name like ?", likeKey)
- }
- err = db.Find(&goodInfo).Error
- return goodInfo, err
-
- }
-
- func GetWarehoureOrderInfoByGoodId(good_id []int64, startime int64, endtime int64, orgid int64, storehouse_id int64) (info []*models.WarehousingInfo, err error) {
-
- db := XTReadDB().Model(&info).Where("status =1")
- if len(good_id) > 0 {
- db = db.Where("good_id in (?)", good_id)
- }
- if startime > 0 {
- db = db.Where("ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("ctime<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("org_id = ?", orgid)
- }
- if storehouse_id > 0 {
- db = db.Where("storehouse_id = ?", storehouse_id)
- }
- err = db.Find(&info).Error
- return info, err
- }
-
- func GetWarehoureOrderOutByGoodId(good_id []int64, startime int64, endtime int64, orgid int64, storehouse_id int64) (info []*models.WarehouseOutInfo, err error) {
-
- db := XTReadDB().Model(&info).Where("status =1")
- if len(good_id) > 0 {
- db = db.Where("good_id in (?)", good_id)
- }
- if startime > 0 {
- db = db.Where("ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("ctime<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("org_id = ?", orgid)
- }
- if storehouse_id > 0 {
- db = db.Where("storehouse_id = ?", storehouse_id)
- }
- err = db.Find(&info).Error
- return info, err
- }
-
- type VMDrugWarehouse struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- WarehousingOrder string `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
- OperationTime int64 `gorm:"column:operation_time" json:"operation_time" form:"operation_time"`
- OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
- Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
- Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
- Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
- Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
- Status int64 `gorm:"column:status" json:"status" form:"status"`
- WarehousingTime int64 `gorm:"column:warehousing_time" json:"warehousing_time" form:"warehousing_time"`
- Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
- Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
- Type int64 `gorm:"column:type" json:"type" form:"type"`
- Manufacturers *models.Manufacturer `gorm:"ForeignKey:Manufacturer;AssociationForeignKey:ID" json:"manufacturers"`
- Dealers *models.Dealer `gorm:"ForeignKey:Dealer;AssociationForeignKey:ID" json:"dealers"`
- SupplyWarehouseId int64 `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
- StorehouseId int64 `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
- IsSys int64 `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
- IsCheck int64 `gorm:"column:is_check" json:"is_check" form:"is_check"`
- Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
- }
-
- func (VMDrugWarehouse) TableName() string {
- return "xt_drug_warehouse"
- }
-
- type VMDrugWarehouseInfo struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- WarehousingId int64 `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
- DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
- Number string `gorm:"column:number" json:"number" form:"number"`
- ProductDate int64 `gorm:"column:product_date" json:"product_date" form:"product_date"`
- ExpiryDate int64 `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
- WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
- Price float64 `gorm:"column:price" json:"price" form:"price"`
- TotalPrice float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
- Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
- Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
- Remark string `gorm:"column:remark" json:"remark" form:"remark"`
- Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
- Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
- Status int64 `gorm:"column:status" json:"status" form:"status"`
- OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
- IsReturn int64 `gorm:"column:is_return" json:"is_return" form:"is_return"`
- WarehousingOrder string `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
- Type int64 `gorm:"column:type" json:"type" form:"type"`
- RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
- RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
- BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
- MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
- MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
- Drug *Drug `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
- SupplyWarehouseId int64 `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
- SupplyWarehouseDetailInfo int64 `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
- StorehouseId int64 `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
- DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
- }
-
- func (VMDrugWarehouseInfo) TableName() string {
- return "xt_drug_warehouse_info"
- }
-
- type Drug struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
- Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
- Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
- DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
- DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
- DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
- DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
- DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
- DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
- DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
- DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
- DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
- MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
- MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
- MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
- UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
- RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
- LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
- DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
- Number string `gorm:"column:number" json:"number" form:"number"`
- DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
- DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
- DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
- MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
- ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
-
- Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
- PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
- StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
- Code string `gorm:"column:code" json:"code" form:"code"`
- IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
- IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
- Agent string `gorm:"column:agent" json:"agent" form:"agent"`
- DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
- LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
- DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
- ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
- SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
- PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
- Label int64 `gorm:"column:label" json:"label" form:"label"`
- Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
- IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
- IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
- IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
- IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
- IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
- Status int64 `gorm:"column:status" json:"status" form:"status"`
- Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
- Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
- OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
- DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
- Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
- DoseCode string `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
- RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
- DrugRemark string `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
- SocialSecurityDirectoryCode string `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
- IsMark int64 `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
- PrescriptionMark int64 `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
- HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
- LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
- Total float64 `gorm:"column:total" json:"total" form:"total"`
- PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
- MinNumber int64 `gorm:"column:min_number" json:"min_number" form:"min_number"`
- Dose string `gorm:"column:dose" json:"dose" form:"dose"`
- DoseUnit string `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
- DrugDay string `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
- MinPrice float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
- IsZeroFlag int64 `gorm:"column:is_zero_flag" json:"is_zero_flag" form:"is_zero_flag"`
- }
-
- func (Drug) TableName() string {
- return "xt_base_drug"
- }
-
- func FindAllDrugWarehousingList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*VMDrugWarehouse, total int64, err error) {
- db := readDb.Model(&VMDrugWarehouse{})
- db = db.Where("xt_drug_warehouse.org_id = ? AND xt_drug_warehouse.status = 1", orgId)
- db = db.Preload("Manufacturers", "status = 1 AND org_id = ?", orgId)
- db = db.Preload("Dealers", "status = 1 AND org_id = ?", orgId)
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_warehouse.creater")
- db = db.Joins("join xt_manufacturer on xt_manufacturer.id = xt_drug_warehouse.manufacturer")
- db = db.Where("xt_manufacturer.manufacturer_name LIKE ? OR sgj_user_admin_role.user_name LIKE ? OR xt_drug_warehouse.warehousing_order LIKE ?", likeKey, likeKey, likeKey).Group("xt_drug_warehouse.id")
- }
- if startTime > 0 {
- db = db.Where("xt_drug_warehouse.operation_time >=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("xt_drug_warehouse.operation_time<= ?", endTime)
- }
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.Offset(offset).Limit(limit).Order("xt_drug_warehouse.ctime desc").Find(&list).Error
- return
- }
-
- func FindAllDrugWarehousingListOne(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string, ids []int64, storehouse_id int64, check_type int64) (list []*VMDrugWarehouse, total int64, err error) {
- db := readDb.Model(&VMDrugWarehouse{})
- db = db.Where("xt_drug_warehouse.org_id = ? AND xt_drug_warehouse.status = 1", orgId)
- db = db.Preload("Manufacturers", "status = 1 AND org_id = ?", orgId)
- db = db.Preload("Dealers", "status = 1 AND org_id = ?", orgId)
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_warehouse.creater")
- db = db.Where(" sgj_user_admin_role.user_name LIKE ? OR xt_drug_warehouse.warehousing_order LIKE ? OR xt_drug_warehouse.id in(?)", likeKey, likeKey, ids).Group("xt_drug_warehouse.id")
- }
- if startTime > 0 {
- db = db.Where("xt_drug_warehouse.operation_time >=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("xt_drug_warehouse.operation_time<= ?", endTime)
- }
- if storehouse_id > 0 {
- db = db.Where("xt_drug_warehouse.storehouse_id = ?", storehouse_id)
- }
- if check_type > 0 {
- db = db.Where("xt_drug_warehouse.is_check = ?", check_type)
- }
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.Offset(offset).Limit(limit).Order("xt_drug_warehouse.ctime desc").Find(&list).Error
- return
- }
-
- func FindWarehousingInfoById(id int64) (list []*models.WarehousingInfo, err error) {
- err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_id = ? AND status = 1", id).Preload("GoodInfo").Find(&list).Error
- return list, err
- }
-
- func FindWarehousingInfoByIdOne(id []int64) (list []*models.WarehousingInfo, err error) {
- err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_id in(?) AND status = 1", id).Preload("GoodInfo").Find(&list).Error
- return list, err
- }
-
- func FindDrugWarehousingInfoById(id int64, org_id int64) (list []*VMDrugWarehouseInfo, err error) {
- err = readDb.Model(&VMDrugWarehouseInfo{}).Preload("Drug", "status = 1 AND org_id = ? AND find_in_set('',drug_status) = 0", org_id).Where("warehousing_id = ? AND status = 1", id).Find(&list).Error
- return list, err
- }
-
- func FindDrugWarehousingInfoByIdThree(id int64, org_id int64) (list []*VMDrugWarehouseInfo, err error) {
- err = readDb.Model(&VMDrugWarehouseInfo{}).Preload("Drug", "status = 1 AND org_id = ?", org_id).Where("warehousing_id = ? AND status = 1", id).Find(&list).Error
- return list, err
- }
-
- func FindDrugWarehousingInfoByIdOne(id []string, org_id int64) (list []*models.StDrugWarehouseInfo, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
- fmt.Println(table)
- if len(id) > 0 {
- db = db.Where("x.warehousing_id in(?)", id)
- }
- if org_id > 0 {
- db = db.Where("x.org_id = ?", org_id)
- }
- err = db.Select("x.id,x.max_unit as limax_unit,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.remark,x.batch_number,x.batch_number,x.manufacturer,x.dealer,t.drug_name,t.last_price,t.dose_unit,t.dose,t.min_number,t.min_unit,t.max_unit,t.drug_type").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&list).Error
- return list, err
- }
-
- func FindWarehousingById(id int64) (warehousing models.Warehousing, err error) {
- err = readDb.Model(&models.Warehousing{}).Where("id = ? AND status = 1 ", id).First(&warehousing).Error
- return warehousing, err
-
- }
-
- func FindNewWarehousingById(id int64, tx *gorm.DB) (warehousing models.Warehousing, err error) {
-
- err = tx.Model(&models.Warehousing{}).Where("id = ? AND status = 1 ", id).First(&warehousing).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return warehousing, err
- }
- }
- return warehousing, err
-
- }
-
- func FindWarehousingByIdOne(id []string) (warehousing []*models.Warehousing, err error) {
- err = readDb.Model(&models.Warehousing{}).Where("id in(?) and status = 1", id).Find(&warehousing).Error
- //err = readDb.Model(&models.Warehousing{}).Where("id = ? AND status = 1 ", id).First(&warehousing).Error
- return warehousing, err
-
- }
-
- func FindDrugWarehousingById(id int64, org_id int64) (warehousing VMDrugWarehouse, err error) {
- err = readDb.Model(&VMDrugWarehouse{}).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Where("id = ? AND status = 1 ", id).First(&warehousing).Error
- return warehousing, err
-
- }
-
- func FindNewDrugWarehousingById(id int64, org_id int64, tx *gorm.DB) (warehousing VMDrugWarehouse, err error) {
-
- err = tx.Model(&VMDrugWarehouse{}).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Where("id = ? AND status = 1 ", id).First(&warehousing).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return warehousing, err
- }
- }
- return warehousing, err
-
- }
-
- func FindDrugWarehousingByIdOne(id []string, org_id int64) (warehousing []*models.DrugWarehouse, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse as x").Where("x.status = 1")
- if len(id) > 0 {
- db = db.Where("x.id in(?)", id)
- }
- if org_id > 0 {
- db = db.Where("x.org_id = ?", org_id)
- }
-
- err = db.Select("x.id,x.warehousing_order,x.operation_time,x.org_id,x.creater,x.ctime,x.modifier,x.warehousing_time").Find(&warehousing).Error
- return warehousing, err
- }
-
- //func FindDrugWarehousingById(id int64) (warehousing models.DrugWarehouse, err error) {
- // err = readDb.Model(&models.DrugWarehouse{}).Where("id = ? AND status = 1 ", id).First(&warehousing).Error
- // return warehousing, err
- //
- //}
-
- func GetInfoByIds(ids []string) (info []*models.WarehousingInfo, err error) {
- err = readDb.Model(&models.WarehousingInfo{}).Preload("Warehousing", "status = 1").Where("id in (?) AND status = 1", ids).Find(&info).Error
- return
- }
-
- func GetWarehousOutInfoByIds(ids []string) (info []*models.WarehouseOutInfo, err error) {
- err = readDb.Model(&models.WarehouseOutInfo{}).Preload("WarehouseOut", "status = 1").Where("id in (?) AND status = 1", ids).Find(&info).Error
- return
- }
-
- func CreateSalesReturnInfo(salesReturnInfo []*models.SalesReturnInfo) (err error) {
- if len(salesReturnInfo) > 0 {
- utx := writeDb.Begin()
- if len(salesReturnInfo) > 0 {
- thisSQL := "INSERT INTO xt_sales_return_info (good_id, sales_return_id, good_type_id, count, price,total,ctime,status,org_id,order_number,type,dealer,manufacturer) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, info := range salesReturnInfo {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, info.GoodId)
- insertData = append(insertData, info.SalesReturnId)
- insertData = append(insertData, info.GoodTypeId)
- insertData = append(insertData, info.Count)
- insertData = append(insertData, info.Price)
- insertData = append(insertData, info.Total)
- insertData = append(insertData, info.Ctime)
- insertData = append(insertData, info.Status)
- insertData = append(insertData, info.OrgId)
- insertData = append(insertData, info.OrderNumber)
- insertData = append(insertData, info.Type)
- insertData = append(insertData, info.Dealer)
- insertData = append(insertData, info.Manufacturer)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- }
- return
-
- }
-
- func CreateDrugSalesReturnInfo(salesReturnInfo []*models.DrugSalesReturnInfo) (err error) {
- if len(salesReturnInfo) > 0 {
- utx := writeDb.Begin()
- if len(salesReturnInfo) > 0 {
- thisSQL := "INSERT INTO xt_drug_sales_return_info (drug_id,sales_return_id, count, price,total,ctime,status,org_id,order_number,type,dealer,manufacturer,retail_price,retail_total_price) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, info := range salesReturnInfo {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, info.DrugId)
- insertData = append(insertData, info.SalesReturnId)
- insertData = append(insertData, info.Count)
- insertData = append(insertData, info.Price)
- insertData = append(insertData, info.Total)
- insertData = append(insertData, info.Ctime)
- insertData = append(insertData, info.Status)
- insertData = append(insertData, info.OrgId)
- insertData = append(insertData, info.OrderNumber)
- insertData = append(insertData, info.Type)
- insertData = append(insertData, info.Dealer)
- insertData = append(insertData, info.Manufacturer)
- insertData = append(insertData, info.RetailPrice)
- insertData = append(insertData, info.RetailTotalPrice)
-
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- }
- return
-
- }
-
- func FindAllSalesReturnTotal(org_id int64) (total int64, err error) {
- err = readDb.Model(&models.SalesReturn{}).Where("org_id = ?", org_id).Count(&total).Error
- return total, err
-
- }
-
- func FindAllCancelStockTotal(org_id int64) (total int64, err error) {
- err = readDb.Model(&models.CancelStock{}).Where("org_id = ?", org_id).Count(&total).Error
- return total, err
-
- }
-
- func FindNewAllCancelStockTotal(org_id int64, tx *gorm.DB) (total int64, err error) {
-
- err = tx.Model(&models.CancelStock{}).Where("org_id = ?", org_id).Count(&total).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return total, err
- }
- }
- return total, err
-
- }
-
- func FindAllDrugCancelStockTotal(org_id int64) (total int64, err error) {
- err = readDb.Model(&models.DrugCancelStock{}).Where("org_id = ?", org_id).Count(&total).Error
- return total, err
- }
-
- func FindNewAllDrugCancelStockTotal(org_id int64, tx *gorm.DB) (total int64, err error) {
-
- err = tx.Model(&models.DrugCancelStock{}).Where("org_id = ?", org_id).Count(&total).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return total, err
- }
- }
-
- return total, err
- }
-
- //func FindAllDrugCancelStockTotalTX(org_id int64,tx *gorm.DB) (total int64, err error) {
- // err = tx.Model(&models.DrugCancelStock{}).Where("org_id = ?", org_id).Count(&total).Error
- // return total, err
- //}
-
- func FindAllReturnList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.SalesReturn, total int64, err error) {
- db := readDb.Model(&models.SalesReturn{})
- db = db.Where("xt_sales_return.org_id = ? AND xt_sales_return.status = 1 AND xt_sales_return.type = ?", orgId, types)
-
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_sales_return.creater")
- db = db.Joins("join xt_manufacturer on xt_manufacturer.id = xt_sales_return.manufacturer")
- db = db.Where("xt_manufacturer.manufacturer_name LIKE ? OR sgj_user_admin_role.user_name LIKE ? OR xt_sales_return.order_number LIKE ?", likeKey, likeKey, likeKey).Group("xt_sales_return.id")
- }
-
- if startTime > 0 {
- db = db.Where("xt_sales_return.opera_time >=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("xt_sales_return.opera_time<= ?", endTime)
- }
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.Offset(offset).Limit(limit).Order("xt_sales_return.ctime desc").Find(&list).Error
- return
- }
-
- func FindAllDrugReturnList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.DrugSalesReturn, total int64, err error) {
- db := readDb.Model(&models.DrugSalesReturn{})
- db = db.Where("xt_drug_sales_return.org_id = ? AND xt_drug_sales_return.status = 1 ", orgId)
-
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_sales_return.creater")
- db = db.Joins("join xt_manufacturer on xt_manufacturer.id = xt_drug_sales_return.manufacturer")
- db = db.Where("xt_manufacturer.manufacturer_name LIKE ? OR sgj_user_admin_role.user_name LIKE ? OR xt_drug_sales_return.order_number LIKE ?", likeKey, likeKey, likeKey).Group("xt_drug_sales_return.id")
- }
-
- if startTime > 0 {
- db = db.Where("xt_drug_sales_return.opera_time >=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("xt_drug_sales_return.opera_time<= ?", endTime)
- }
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.Offset(offset).Limit(limit).Order("xt_drug_sales_return.ctime desc").Find(&list).Error
- return
- }
-
- func FindReturnInfoById(id int64) (list []*models.SalesReturnInfo, err error) {
- err = readDb.Model(&models.SalesReturnInfo{}).Where("sales_return_id = ? AND status = 1", id).Find(&list).Error
- return list, err
- }
-
- func FindCancelStockInfoById(id int64) (list []*models.CancelStockInfo, err error) {
- err = readDb.Model(&models.CancelStockInfo{}).Where("cancel_stock_id = ? AND status = 1", id).Preload("WarehousingInfo", "status = 1").Preload("GoodInfo", "status = 1").Find(&list).Error
- return list, err
- }
-
- type DrugCancelStockInfo struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
- CancelStockId int64 `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
- Count int64 `gorm:"column:count" json:"count" form:"count"`
- Price float64 `gorm:"column:price" json:"price" form:"price"`
- Total float64 `gorm:"column:total" json:"total" form:"total"`
- ProductDate int64 `gorm:"column:product_date" json:"product_date" form:"product_date"`
- ExpiryDate int64 `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
- Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
- Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
- Status int64 `gorm:"column:status" json:"status" form:"status"`
- OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
- OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
- Type int64 `gorm:"column:type" json:"type" form:"type"`
- Dealer string `gorm:"column:dealer" json:"dealer" form:"dealer"`
- Manufacturer string `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
- RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
- RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
- Number string `gorm:"column:number" json:"number" form:"number"`
- RegisterAccount string `gorm:"column:register_account" json:"register_account" form:"register_account"`
- Remark string `gorm:"column:remark" json:"remark" form:"remark"`
- BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
- MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
- Drug *Drug `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
- BatchNumberId int64 `gorm:"column:batch_number_id" json:"batch_number_id" form:"batch_number_id"`
- StorehouseId int64 `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
- DrugWarehouseInfo []*models.XtDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:DrugId" json:"drug_warehouse_info"`
- }
-
- func (DrugCancelStockInfo) TableName() string {
- return "xt_drug_cancel_stock_info"
- }
-
- func FindDrugCancelStockInfoById(id int64, org_id int64) (list []*DrugCancelStockInfo, err error) {
- err = readDb.Model(&DrugCancelStockInfo{}).Preload("Drug", "status = 1 AND org_id = ? ", org_id).Preload("DrugWarehouseInfo", "status = 1 AND org_id = ? ", org_id).Where("cancel_stock_id = ? AND status = 1", id).Find(&list).Error
- return list, err
- }
-
- func FindAllWarehousingInfo(orgId int64, page int64, limit int64, startTime int64, endTime int64) (list []*models.WarehousingInfo, total int64, err error) {
- db := readDb.Model(&models.WarehousingInfo{})
- db = db.Where("org_id = ? AND status = 1", orgId)
- db = db.Preload("Warehousing", "status = 1 AND org_id = ?", orgId)
-
- if startTime > 0 {
- db = db.Where("ctime >=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("ctime<= ?", endTime)
- }
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
- return list, total, err
- }
-
- func FindAllWarehouseOut(org_id int64) (total int64, err error) {
- err = readDb.Model(&models.WarehouseOut{}).Where("org_id = ?", org_id).Count(&total).Error
- return total, err
-
- }
-
- func FindAllDrugWarehouseOut(org_id int64) (total int64, err error) {
-
- err = readDb.Model(&models.DrugWarehouseOut{}).Where("org_id = ?", org_id).Count(&total).Error
- return total, err
-
- }
-
- func FindAllSelfDrugWarehouseOut(org_id int64, tx *gorm.DB) (total int64, err error) {
-
- err = tx.Model(&models.XtSelfDrugWarehouseOut{}).Where("org_id = ?", org_id).Count(&total).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return
- }
- }
- return total, err
-
- }
-
- func AddSigleWarehouseOutOne(warehouseOut *models.WarehouseOut) error {
-
- err := XTWriteDB().Create(&warehouseOut).Error
-
- return err
- }
-
- func AddSigleWarehouseOut(warehouseOut *models.WarehouseOut, tx *gorm.DB) error {
-
- err := tx.Create(&warehouseOut).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func AddNewSigleWarehouseOut(warehouseOut *models.WarehouseOut, tx *gorm.DB) error {
-
- err := tx.Create(&warehouseOut).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpdateSingleWarehoseOut(id int64, storehouse_id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.WarehouseOut{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"storehouse_id": storehouse_id}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func GetDrugWarehouseOutIsExit(org_id int64, is_sys int, record_time int64, warehousing_out_order string) (models.DrugWarehouseOut, error) {
-
- drugWarehouseOut := models.DrugWarehouseOut{}
- err := XTReadDB().Where("is_sys = ? AND status = 1 AND org_id = ? AND warehouse_out_time = ? and warehouse_out_order_number = ?", is_sys, org_id, record_time, warehousing_out_order).Find(&drugWarehouseOut).Error
-
- return drugWarehouseOut, err
- }
-
- func GetNewDrugWarehouseOutIsExit(org_id int64, is_sys int, record_time int64, warehousing_out_order string, tx *gorm.DB) (models.DrugWarehouseOut, error) {
-
- drugWarehouseOut := models.DrugWarehouseOut{}
- err := tx.Where("is_sys = ? AND status = 1 AND org_id = ? AND warehouse_out_time = ? and warehouse_out_order_number = ?", is_sys, org_id, record_time, warehousing_out_order).Find(&drugWarehouseOut).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return drugWarehouseOut, err
- }
- }
-
- return drugWarehouseOut, err
- }
-
- func AddSigleDrugWarehouseOut(warehouseOut *models.DrugWarehouseOut) error {
- err := writeDb.Create(&warehouseOut).Error
- return err
-
- }
-
- func GetSigleDrugWarehouseOutByPatientId(warehousing_time int64, patient_id int64, tx *gorm.DB) (models.XtSelfDrugWarehouse, error) {
-
- selfDrugWarehouse := models.XtSelfDrugWarehouse{}
-
- err := tx.Where("warehousing_time = ? and patient_id = ? and is_sys =1 and status=1", warehousing_time, patient_id).Find(&selfDrugWarehouse).Error
-
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return selfDrugWarehouse, err
- }
- }
-
- return selfDrugWarehouse, err
- }
-
- func AddSelfSigleDrugWarehouseOut(warehouseOut *models.XtSelfDrugWarehouseOut, tx *gorm.DB) error {
-
- err := tx.Create(&warehouseOut).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
-
- }
-
- func AddNewSigleDrugWarehouseOut(warehouseOut *models.DrugWarehouseOut, tx *gorm.DB) error {
-
- err := tx.Create(&warehouseOut).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
-
- }
-
- func UpdateSingleDrugWarehouseOut(id int64, storehouse_id int64) error {
-
- err := XTWriteDB().Model(&models.DrugWarehouseOut{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"storehouse_id": storehouse_id}).Error
- return err
- }
-
- func UpdateNewSingleDrugWarehouseOut(id int64, storehouse_id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouseOut{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"storehouse_id": storehouse_id}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpdateSelfSingleDrugWarehouseOut(id int64, patient_id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.XtSelfDrugWarehouseOut{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"patient_id": patient_id}).Error
- return err
- }
-
- func CreateWarehousingOutInfo(warehouseOutInfo []*models.WarehouseOutInfo) (err error) {
- if len(warehouseOutInfo) > 0 {
- utx := writeDb.Begin()
- if len(warehouseOutInfo) > 0 {
- thisSQL := "INSERT INTO xt_warehouse_out_info (warehouse_out_id, good_id, good_type_id, product_date,expiry_date,count,price,total_price,remark,ctime,status,org_id,warehouse_out_order_number,type,dealer,manufacturer,number,license_number) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, info := range warehouseOutInfo {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, info.WarehouseOutId)
- insertData = append(insertData, info.GoodId)
- insertData = append(insertData, info.GoodTypeId)
- insertData = append(insertData, info.ProductDate)
- insertData = append(insertData, info.ExpiryDate)
- insertData = append(insertData, info.Count)
- insertData = append(insertData, info.Price)
- insertData = append(insertData, info.TotalPrice)
- insertData = append(insertData, info.Remark)
- insertData = append(insertData, info.Ctime)
- insertData = append(insertData, info.Status)
- insertData = append(insertData, info.OrgId)
- insertData = append(insertData, info.WarehouseOutOrderNumber)
- insertData = append(insertData, info.Type)
- insertData = append(insertData, info.Dealer)
- insertData = append(insertData, info.Manufacturer)
- insertData = append(insertData, info.Number)
- insertData = append(insertData, info.LicenseNumber)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- }
- return
-
- }
-
- func CreateDrugWarehousingOutInfo(warehouseOutInfo []*models.DrugWarehouseOutInfo) (err error) {
- if len(warehouseOutInfo) > 0 {
- utx := writeDb.Begin()
- if len(warehouseOutInfo) > 0 {
- thisSQL := "INSERT INTO xt_drug_warehouse_out_info (warehouse_out_id, drug_id, product_date,expiry_date,count,price,total_price,remark,ctime,status,org_id,warehouse_out_order_number,type,dealer,manufacturer,retail_price,retail_total_price,number,batch_number,count_unit) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, info := range warehouseOutInfo {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, info.WarehouseOutId)
- insertData = append(insertData, info.DrugId)
- insertData = append(insertData, info.ProductDate)
- insertData = append(insertData, info.ExpiryDate)
- insertData = append(insertData, info.Count)
- insertData = append(insertData, info.Price)
- insertData = append(insertData, info.TotalPrice)
- insertData = append(insertData, info.Remark)
- insertData = append(insertData, info.Ctime)
- insertData = append(insertData, info.Status)
- insertData = append(insertData, info.OrgId)
- insertData = append(insertData, info.WarehouseOutOrderNumber)
- insertData = append(insertData, info.Type)
- insertData = append(insertData, info.Dealer)
- insertData = append(insertData, info.Manufacturer)
- insertData = append(insertData, info.RetailPrice)
- insertData = append(insertData, info.RetailTotalPrice)
- insertData = append(insertData, info.Number)
- insertData = append(insertData, info.BatchNumber)
- insertData = append(insertData, info.CountUnit)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- }
- return
-
- }
-
- func FindLastWarehousingOutInfo(order string) (info models.WarehouseOutInfo, err error) {
- err = readDb.Model(&models.WarehouseOutInfo{}).Where("warehouse_out_order_number = ? AND status = 1", order).Last(&info).Error
-
- return info, err
-
- }
-
- func FindLastDrugWarehousingOutInfo(order string) (info models.DrugWarehouseOutInfo, err error) {
- err = readDb.Model(&models.DrugWarehouseOutInfo{}).Where("warehouse_out_order_number = ? AND status = 1", order).Last(&info).Error
-
- return info, err
-
- }
-
- func FindAllWarehouseOutList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.WarehouseOut, total int64, err error) {
- db := readDb.Model(&models.WarehouseOut{})
- db = db.Where("xt_warehouse_out.org_id = ? AND xt_warehouse_out.status = 1 AND xt_warehouse_out.type = ?", orgId, types)
-
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_warehouse_out.creater")
- db = db.Joins("join xt_manufacturer on xt_manufacturer.id = xt_warehouse_out.manufacturer")
- db = db.Where("xt_manufacturer.manufacturer_name LIKE ? OR sgj_user_admin_role.user_name LIKE ? OR xt_warehouse_out.warehouse_out_order_number LIKE ?", likeKey, likeKey, likeKey).Group("xt_warehouse_out.id")
- }
-
- if startTime > 0 {
- db = db.Where("xt_warehouse_out.ctime >=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("xt_warehouse_out.ctime<= ?", endTime)
- }
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.Offset(offset).Limit(limit).Order("xt_warehouse_out.ctime desc").Find(&list).Error
- return list, total, err
-
- }
-
- func FindAllWarehouseOutListOne(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string, ids []int64, storehouse_id int64, way_type int64, check_type int64) (list []*models.WarehouseOut, total int64, err error) {
- db := readDb.Model(&models.WarehouseOut{})
- db = db.Where("xt_warehouse_out.org_id = ? AND xt_warehouse_out.status = 1 AND xt_warehouse_out.type = ?", orgId, types)
-
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_warehouse_out.creater")
- db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_warehouse_out.warehouse_out_order_number LIKE ? or xt_warehouse_out.id in(?)", likeKey, likeKey, ids).Group("xt_warehouse_out.id")
- }
-
- if startTime > 0 {
- db = db.Where("xt_warehouse_out.warehouse_out_time >=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("xt_warehouse_out.warehouse_out_time<= ?", endTime)
- }
- if storehouse_id > 0 {
- db = db.Where("xt_warehouse_out.storehouse_id = ?", storehouse_id)
- }
- if way_type == 0 {
- db = db.Where("xt_warehouse_out.is_sys = 0 or xt_warehouse_out.is_sys = 1 or xt_warehouse_out.is_sys = 12 or xt_warehouse_out.is_sys = 5")
- }
- if way_type == 1 {
- db = db.Where("xt_warehouse_out.is_sys = 0")
- }
- if way_type == 2 {
- db = db.Where("xt_warehouse_out.is_sys = 1")
- }
- if way_type == 3 {
- db = db.Where("xt_warehouse_out.is_sys = 12")
- }
- if way_type == 4 {
- db = db.Where("xt_warehouse_out.is_sys = 5")
- }
- if check_type > 0 {
- db = db.Where("xt_warehouse_out.is_check = ?", check_type)
- }
- if check_type == 0 {
- db = db.Where("xt_warehouse_out.is_check = 1 or xt_warehouse_out.is_check = 2")
- }
- db = db.Count(&total)
- offset := (page - 1) * limit
- if orgId == 10191 {
- err = db.Offset(offset).Limit(limit).Order("xt_warehouse_out.warehouse_out_time desc").Find(&list).Error
- } else {
- err = db.Offset(offset).Limit(limit).Order("xt_warehouse_out.ctime desc").Find(&list).Error
- }
-
- return list, total, err
-
- }
-
- func FindAllDrugWarehouseOutList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.DrugWarehouseOut, total int64, err error) {
- db := readDb.Model(&models.DrugWarehouseOut{})
- db = db.Where("xt_drug_warehouse_out.org_id = ? AND xt_drug_warehouse_out.status = 1 ", orgId)
-
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_warehouse_out.creater")
- db = db.Joins("join xt_manufacturer on xt_manufacturer.id = xt_drug_warehouse_out.manufacturer")
-
- db = db.Where("xt_manufacturer.manufacturer_name LIKE ? OR sgj_user_admin_role.user_name LIKE ? OR xt_drug_warehouse_out.warehouse_out_order_number LIKE ?", likeKey, likeKey, likeKey).Group("xt_drug_warehouse_out.id")
- }
-
- if startTime > 0 {
- db = db.Where("xt_drug_warehouse_out.ctime >=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("xt_drug_warehouse_out.ctime<= ?", endTime)
- }
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.Offset(offset).Limit(limit).Order("xt_drug_warehouse_out.ctime desc").Find(&list).Error
- return list, total, err
-
- }
-
- func FindAllDrugWarehouseOutListOne(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string, ids []int64, storehouse_id int64, way_type int64, check_type int64) (list []*models.DrugWarehouseOut, total int64, err error) {
- db := readDb.Model(&models.DrugWarehouseOut{})
- db = db.Where("xt_drug_warehouse_out.org_id = ? AND xt_drug_warehouse_out.status = 1 ", orgId)
-
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_warehouse_out.creater")
-
- db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_drug_warehouse_out.warehouse_out_order_number LIKE ? or xt_drug_warehouse_out.id in(?) ", likeKey, likeKey, ids).Group("xt_drug_warehouse_out.id")
- }
-
- if startTime > 0 {
- db = db.Where("xt_drug_warehouse_out.ctime >=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("xt_drug_warehouse_out.ctime<= ?", endTime)
- }
- if storehouse_id > 0 {
- db = db.Where("xt_drug_warehouse_out.storehouse_id = ?", storehouse_id)
- }
- if check_type > 0 {
- db = db.Where("xt_drug_warehouse_out.is_check = ?", check_type)
- }
-
- if way_type == 0 {
- db = db.Where("xt_drug_warehouse_out.is_sys = 0 || xt_drug_warehouse_out.is_sys = 1 || xt_drug_warehouse_out.is_sys = 12 || xt_drug_warehouse_out.is_sys = 5")
- }
- if way_type == 1 {
- db = db.Where("xt_drug_warehouse_out.is_sys = 0")
- }
- if way_type == 2 {
- db = db.Where("xt_drug_warehouse_out.is_sys = 1")
- }
- if way_type == 3 {
- db = db.Where("xt_drug_warehouse_out.is_sys = 12")
- }
- if way_type == 4 {
- db = db.Where("xt_drug_warehouse_out.is_sys = 15")
- }
- db = db.Count(&total)
- offset := (page - 1) * limit
- if orgId == 10191 {
- err = db.Offset(offset).Limit(limit).Order("xt_drug_warehouse_out.warehouse_out_time desc").Find(&list).Error
- } else {
- err = db.Offset(offset).Limit(limit).Order("xt_drug_warehouse_out.ctime desc").Find(&list).Error
- }
-
- return list, total, err
-
- }
-
- func FindWarehouseOutInfoById(id int64) (list []*models.WarehouseOutInfo, err error) {
- err = readDb.Model(&models.WarehouseOutInfo{}).Where("warehouse_out_id = ? AND status = 1 AND count <> 0 AND good_id <> 0", id).Preload("GoodInfo", "status = 1").Order("good_type_id desc").Find(&list).Error
- return list, err
- }
-
- type DrugWarehouseOutInfo struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
- DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
- WarehousingOutTarget int64 `gorm:"column:warehousing_out_target" json:"warehousing_out_target" form:"warehousing_out_target"`
- Count int64 `gorm:"column:count" json:"count" form:"count"`
- CountUnit string `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
- Price float64 `gorm:"column:price" json:"price" form:"price"`
- TotalPrice float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
- ProductDate int64 `gorm:"column:product_date" json:"product_date" form:"product_date"`
- ExpiryDate int64 `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
- Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
- Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
- Status int64 `gorm:"column:status" json:"status" form:"status"`
- OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
- Remark string `gorm:"column:remark" json:"remark" form:"remark"`
- IsCancel int64 `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
- WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
- Type int64 `gorm:"column:type" json:"type" form:"type"`
- Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
- Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
- IsSys int64 `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
- SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
- RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
- RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
- Number string `gorm:"column:number" json:"number" form:"number"`
- BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
- Drug *Drug `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
- WarehouseInfoId int64 `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
- SupplyCancelOutId int64 `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
- SupplyWarehouseId int64 `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
- AdminUserId int64 `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
- LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
- StockCount string `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
- PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
- ClassType string `gorm:"column:class_type" json:"class_type" form:"class_type"`
- }
-
- func (DrugWarehouseOutInfo) TableName() string {
- return "xt_drug_warehouse_out_info"
- }
-
- func FindDrugWarehouseOutInfoById(id int64, org_id int64) (list []*DrugWarehouseOutInfo, err error) {
- err = readDb.Model(&DrugWarehouseOutInfo{}).Preload("Drug", "status = 1 AND org_id = ?", org_id).Where("warehouse_out_id = ? AND status = 1 ", id).Find(&list).Error
- return list, err
- }
-
- func FindWarehouseInfoByGoodId(good_id int64) (int64, *models.WarehousingInfo) {
- info := &models.WarehousingInfo{}
- type WarehouseInfoCountAmount struct {
- Total int64
- }
- var result WarehouseInfoCountAmount
- readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND status = 1", good_id).Select("sum(warehousing_count) as total").Scan(&result)
- readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND status = 1", good_id).First(info)
-
- return result.Total, info
-
- }
-
- func FindAllSalesReturnCountByGoodId(good_id int64) (int64, error) {
- type SalesReturnCountAmount struct {
- Total int64
- }
- var result SalesReturnCountAmount
- err = readDb.Model(&models.SalesReturnInfo{}).Where("good_id = ? AND status = 1", good_id).Select("sum(count) as total").Scan(&result).Error
- return result.Total, err
- }
-
- func FindAllWarehouseOutInfoByGoodId(good_id int64) (int64, error) {
- type WarehouseOutInfoCountAmount struct {
- Total int64
- }
- var result WarehouseOutInfoCountAmount
- err = readDb.Model(&models.WarehouseOutInfo{}).Where("good_id = ? AND status = 1", good_id).Select("sum(count) as total").Scan(&result).Error
- return result.Total, err
- }
-
- func FindAllCancleStockInfoByGoodId(good_id int64) (int64, error) {
- type CancleStockoCountAmount struct {
- Total int64
- }
- var result CancleStockoCountAmount
- err = readDb.Model(&models.CancelStockInfo{}).Where("good_id = ? AND status = 1", good_id).Select("sum(count) as total").Scan(&result).Error
- return result.Total, err
- }
-
- func FindWarehouseInfoByGoodTypeId(good_type_id int64) (models.WarehousingInfo, error) {
- info := models.WarehousingInfo{}
- err := readDb.Model(&models.WarehousingInfo{}).Where("good_type_id = ? AND status = 1", good_type_id).First(&info).Error
- return info, err
-
- }
-
- func GetCancelStockDetailByOrderNumber(ordernumber string, orgid int64) (*models.CancelStock, error) {
-
- stock := models.CancelStock{}
- err := XTReadDB().Where("order_number = ? and org_id = ? and status = 1", ordernumber, orgid).Find(&stock).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &stock, nil
- }
-
- func GetCancelStockDetailByOrderNumberOne(return_time int64, orgid int64) (*models.CancelStock, error) {
-
- stock := models.CancelStock{}
- err := XTReadDB().Where("return_time = ? and org_id = ? and status = 1", return_time, orgid).Find(&stock).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &stock, nil
- }
-
- func GetNewCancelStockDetailByOrderNumberOne(return_time int64, orgid int64, tx *gorm.DB) (*models.CancelStock, error) {
-
- stock := models.CancelStock{}
- err := tx.Where("return_time = ? and org_id = ? and status = 1", return_time, orgid).Find(&stock).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return &stock, err
- }
- }
- return &stock, err
- }
-
- func AddSigleCancelStock(cancelStock *models.CancelStock) error {
- err := writeDb.Create(&cancelStock).Error
- return err
-
- }
-
- func AddNewSigleCancelStock(cancelStock *models.CancelStock, tx *gorm.DB) error {
-
- err := tx.Create(&cancelStock).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
-
- }
- func UpdateSigleCancelStock(id int64, storehouse_id int64) error {
- err := XTWriteDB().Model(&models.CancelStock{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"storehouse_id": storehouse_id}).Error
- return err
- }
-
- func GetLastCancelStockById(orgid int64) (models.CancelStock, error) {
- stock := models.CancelStock{}
- err := XTReadDB().Where("org_id = ? and status = 1", orgid).Last(&stock).Error
- return stock, err
- }
-
- func GetNewLastCancelStockById(orgid int64, tx *gorm.DB) (models.CancelStock, error) {
- stock := models.CancelStock{}
- err := tx.Where("org_id = ? and status = 1", orgid).Last(&stock).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return stock, err
- }
- }
- return stock, err
- }
-
- func GetLastDrugCancelStockById(orgid int64) (models.DrugCancelStock, error) {
- stock := models.DrugCancelStock{}
- err := XTReadDB().Where("org_id = ? and status = 1", orgid).Last(&stock).Error
- return stock, err
- }
-
- func GetNewLastDrugCancelStockById(orgid int64, tx *gorm.DB) (models.DrugCancelStock, error) {
- stock := models.DrugCancelStock{}
- err := tx.Where("org_id = ? and status = 1", orgid).Last(&stock).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return stock, err
- }
- }
-
- return stock, err
- }
-
- func GetManufactureById(id int64) (models.Manufacturer, error) {
- manufacturer := models.Manufacturer{}
- err := XTReadDB().Model(&manufacturer).Where("id = ? and status = 1", id).Find(&manufacturer).Error
- return manufacturer, err
- }
-
- func GetNewManufactureById(id int64, tx *gorm.DB) (models.Manufacturer, error) {
- manufacturer := models.Manufacturer{}
- err := tx.Model(&manufacturer).Where("id = ? and status = 1", id).Find(&manufacturer).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return manufacturer, err
- }
- }
-
- return manufacturer, err
- }
-
- func GetDealerById(id int64) (models.Dealer, error) {
- dealer := models.Dealer{}
- err := XTReadDB().Model(&dealer).Where("id=? and status = 1", id).Find(&dealer).Error
- return dealer, err
- }
-
- func GetNewDealerById(id int64, tx *gorm.DB) (models.Dealer, error) {
- dealer := models.Dealer{}
- err := tx.Model(&dealer).Where("id=? and status = 1", id).Find(&dealer).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return dealer, err
- }
- }
-
- return dealer, err
- }
-
- func AddSigleDrugCancelStock(cancelStock *models.DrugCancelStock) error {
- err := writeDb.Create(&cancelStock).Error
- return err
- }
-
- func AddNewSigleDrugCancelStock(cancelStock *models.DrugCancelStock, tx *gorm.DB) error {
-
- err := tx.Create(&cancelStock).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpdateSingleDrugCancelStock(id int64, storehouse_id int64) error {
-
- err := XTWriteDB().Model(&models.DrugCancelStock{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"storehouse_id": storehouse_id}).Error
- return err
- }
-
- //func AddSigleDrugCancelStockTX(cancelStock *models.DrugCancelStock,tx *gorm.DB) error {
- // err := tx.Create(&cancelStock).Error
- // return err
- //}
-
- func CreateCancelStockInfo(cancelStockInfo []*models.CancelStockInfo) (err error) {
- if len(cancelStockInfo) > 0 {
- utx := writeDb.Begin()
- if len(cancelStockInfo) > 0 {
- thisSQL := "INSERT INTO xt_cancel_stock_info (good_id, cancel_stock_id, good_type_id, count, price,total,ctime,status,org_id,order_number,type,dealer,manufacturer,number,register_account,remark,product_date,expiry_date,warehouse_info_id,storehouse_id) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, info := range cancelStockInfo {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, info.GoodId)
- insertData = append(insertData, info.CancelStockId)
- insertData = append(insertData, info.GoodTypeId)
- insertData = append(insertData, info.Count)
- insertData = append(insertData, info.Price)
- insertData = append(insertData, info.Total)
- insertData = append(insertData, info.Ctime)
- insertData = append(insertData, info.Status)
- insertData = append(insertData, info.OrgId)
- insertData = append(insertData, info.OrderNumber)
- insertData = append(insertData, info.Type)
- insertData = append(insertData, info.Dealer)
- insertData = append(insertData, info.Manufacturer)
- insertData = append(insertData, info.Number)
- insertData = append(insertData, info.RegisterAccount)
- insertData = append(insertData, info.Remark)
- insertData = append(insertData, info.ProductDate)
- insertData = append(insertData, info.ExpiryDate)
- insertData = append(insertData, info.WarehouseInfoId)
- insertData = append(insertData, info.WarehouseInfoId)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- }
- return
-
- }
-
- func CreateCancelStockInfoTwo(info *models.DrugCancelStockInfo) error {
-
- err := XTWriteDB().Create(&info).Error
- return err
- }
-
- //func CreateCancelStockInfoTwoTX(info *models.DrugCancelStockInfo,tx *gorm.DB) error {
- // err := tx.Create(&info).Error
- // return err
- //}
-
- func GetLastStockInfoThree(drugid int64) (models.DrugCancelStockInfo, error) {
-
- info := models.DrugCancelStockInfo{}
-
- err := XTReadDB().Model(&info).Where("drug_id = ? and status = 1", drugid).Find(&info).Error
- return info, err
- }
-
- //func GetLastStockInfoThreeTX(drugid int64,tx *gorm.DB) (models.DrugCancelStockInfo, error) {
- // info := models.DrugCancelStockInfo{}
- // err := tx.Model(&info).Where("drug_id = ? and status = 1", drugid).Find(&info).Error
- // return info, err
- //}
-
- func CreateCancelStockInfoOne(info *models.CancelStockInfo) error {
-
- err := XTWriteDB().Create(&info).Error
- return err
- }
-
- func CreateNewCancelStockInfoOne(info *models.CancelStockInfo, tx *gorm.DB) error {
-
- err := XTWriteDB().Create(&info).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func GetLastCancelStockInfoByGoodId(goodId int64) (models.CancelStockInfo, error) {
- info := models.CancelStockInfo{}
- err := XTReadDB().Model(&info).Where("good_id = ? and status = 1", goodId).Last(&info).Error
- return info, err
- }
-
- func GetLastNewCancelStockInfoByGoodId(goodId int64, tx *gorm.DB) (models.CancelStockInfo, error) {
- info := models.CancelStockInfo{}
- err := tx.Model(&info).Where("good_id = ? and status = 1", goodId).Last(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
-
- }
- return info, err
- }
-
- func GetLastDrugCancelStockInfoById(drugid int64) (models.DrugCancelStockInfo, error) {
- info := models.DrugCancelStockInfo{}
- err := XTReadDB().Model(&info).Where("drug_id = ? and status = 1", drugid).Last(&info).Error
- return info, err
- }
-
- func CreateDrugCancelStockInfo(cancelStockInfo []*models.DrugCancelStockInfo) (err error) {
- if len(cancelStockInfo) > 0 {
- utx := writeDb.Begin()
- if len(cancelStockInfo) > 0 {
- thisSQL := "INSERT INTO xt_drug_cancel_stock_info (drug_id,cancel_stock_id, count, price,total,ctime,status,org_id,order_number,type,dealer,manufacturer,retail_price,retail_total_price,register_account,batch_number,remark,max_unit,product_date,expiry_date,batch_number_id) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, info := range cancelStockInfo {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, info.DrugId)
- insertData = append(insertData, info.CancelStockId)
- insertData = append(insertData, info.Count)
- insertData = append(insertData, info.Price)
- insertData = append(insertData, info.Total)
- insertData = append(insertData, info.Ctime)
- insertData = append(insertData, info.Status)
- insertData = append(insertData, info.OrgId)
- insertData = append(insertData, info.OrderNumber)
- insertData = append(insertData, info.Type)
- insertData = append(insertData, info.Dealer)
- insertData = append(insertData, info.Manufacturer)
- insertData = append(insertData, info.RetailPrice)
- insertData = append(insertData, info.RetailTotalPrice)
- insertData = append(insertData, info.RegisterAccount)
- insertData = append(insertData, info.BatchNumber)
- insertData = append(insertData, info.Remark)
- insertData = append(insertData, info.MaxUnit)
- insertData = append(insertData, info.ProductDate)
- insertData = append(insertData, info.ExpiryDate)
- insertData = append(insertData, info.BatchNumberId)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- }
- return
-
- }
-
- func FindAllCancelStockList(orgId int64) (list []*models.CancelStock, err error) {
- db := readDb.Model(&models.CancelStock{})
- db = db.Where("org_id = ? AND status = 1", orgId)
- err = db.Order("ctime desc").Find(&list).Error
- return
- }
-
- func FindAllStockOutList(orgId int64, page int64, limit int64, startTime int64, endTime int64) (list []*models.WarehouseOutInfo, total int64, err error) {
-
- db := readDb.Model(&models.WarehousingInfo{})
- db = db.Where("org_id = ? AND status = 1", orgId)
- db = db.Preload("WarehouseOut", "status = 1 AND org_id = ?", orgId)
-
- if startTime > 0 {
- db = db.Where("ctime >=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("ctime<= ?", endTime)
- }
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
-
- return
- }
-
- func FindAllStockInfo(orgId int64, page int64, limit int64, keyword string, startime int64, endtime int64, type_name int64) (list []*models.StockInfo, total int64, err error) {
-
- db := XTReadDB().Model(&models.StockInfo{})
- if startime > 0 {
-
- db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
- return db.Where("org_id = ? AND status = 1 and sys_record_time>=?", orgId, startime)
- })
- }
-
- if startime == 0 || endtime == 0 {
- db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
- return db.Where("org_id = ? AND status = 1", orgId)
- })
- }
-
- if endtime > 0 {
-
- db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
- return db.Where("org_id = ? AND status = 1 and sys_record_time >=? and sys_record_time<=?", orgId, startime, endtime)
- })
- }
-
- db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgId)
- db = db.Group("xt_good_information.id")
- if startime == 0 || endtime == 0 {
- db = db.Preload("QueryWarehousingInfo", func(db *gorm.DB) *gorm.DB {
- return db.Where("org_id = ? AND status = 1", orgId)
- })
- }
-
- if startime > 0 {
- db = db.Preload("QueryWarehousingInfo", func(db *gorm.DB) *gorm.DB {
- return db.Where("org_id = ? AND status = 1 and ctime >= ?", orgId, startime)
- })
- }
-
- if endtime > 0 {
- db = db.Preload("QueryWarehousingInfo", func(db *gorm.DB) *gorm.DB {
- return db.Where("org_id = ? AND status = 1 and ctime>=? and ctime <= ?", orgId, startime, endtime)
- })
- }
-
- db = db.Preload("QuerySalesReturnInfo", "org_id = ? AND status = 1", orgId)
-
- if startime == 0 || endtime == 0 {
- db = db.Preload("QueryCancelStockInfo", "org_id = ? AND status = 1", orgId)
- }
- if startime > 0 {
- db = db.Preload("QueryCancelStockInfo", "org_id = ? AND status = 1 and ctime >=?", orgId, startime)
- }
- if endtime > 0 {
- db = db.Preload("QueryCancelStockInfo", "org_id = ? AND status = 1 and ctime >=? and ctime<=?", orgId, startime, endtime)
- }
-
- db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgId)
-
- if len(keyword) > 0 {
- likeKey := "%" + keyword + "%"
- db = db.Joins("join xt_goods_type on xt_goods_type.id = xt_good_information.good_type_id AND xt_goods_type.org_id = ? AND xt_goods_type.status = 1", orgId)
- db = db.Where("xt_good_information.good_code LIKE ? OR xt_good_information.specification_name LIKE ? OR xt_good_information.good_name LIKE ? OR xt_goods_type.type_name LIKE ?", likeKey, likeKey, likeKey, likeKey).Group("xt_good_information.id")
-
- }
-
- if type_name > 0 {
-
- db = db.Joins("join xt_goods_type on xt_goods_type.id = xt_good_information.good_type_id AND xt_goods_type.org_id = ? AND xt_goods_type.status = 1 and xt_goods_type.id = ?", orgId, type_name)
- }
-
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
- return
- }
-
- func FindWarehouseInfoTotalByGoodId(goodId int64) (total int64, err error) {
- err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND status = 1", goodId).Count(&total).Error
- return
- }
-
- func FindWarehouseOutInfoTotalByGoodId(goodId int64) (total int64, err error) {
- err = readDb.Model(&models.WarehouseOutInfo{}).Where("good_id = ? AND status = 1", goodId).Count(&total).Error
- return
- }
- func UpDateWarehouse(warehouse *models.Warehousing) (err error) {
- err = readDb.Model(&models.Warehousing{}).Where("warehousing_order = ? AND status = 1", warehouse.WarehousingOrder).Update(map[string]interface{}{"operation_time": warehouse.OperationTime, "mtime": warehouse.Mtime, "modifier": warehouse.Modifier}).Error
- return
- }
- func UpDateWarehouseOut(warehouseOut *models.WarehouseOut) (err error) {
- err = readDb.Model(&models.WarehouseOut{}).Where("warehouse_out_order_number = ? AND status = 1", warehouseOut.WarehouseOutOrderNumber).Update(map[string]interface{}{"operation_time": warehouseOut.OperationTime, "mtime": warehouseOut.Mtime, "modifier": warehouseOut.Modifier}).Error
- return
- }
-
- func UpDateWarehouseInfo(warehouseInfo *models.WarehousingInfo) (err error) {
- err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_order = ? AND status = 1", warehouseInfo.WarehousingOrder).Update(map[string]interface{}{"good_type_id": warehouseInfo.GoodTypeId,
- "good_id": warehouseInfo.GoodId,
- "number": warehouseInfo.Number,
- "product_date": warehouseInfo.ProductDate,
- "expiry_date": warehouseInfo.ExpiryDate,
- "warehousing_count": warehouseInfo.WarehousingCount,
- "price": warehouseInfo.Price,
- "total_price": warehouseInfo.TotalPrice,
- "mtime": warehouseInfo.Mtime,
- "remark": warehouseInfo.Remark,
- }).Error
- return
- }
-
- func UpDateWarehouseStatus(id int64) (err error) {
- err = readDb.Model(&models.WarehousingInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
-
- return
- }
-
- func UpdatedStockFlowById(id int64) (err error) {
- err = XTWriteDB().Model(&models.VmStockFlow{}).Where("warehousing_detail_id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return
- }
-
- func UpDateDrugWarehouseStatus(id int64) (err error) {
- err = readDb.Model(&models.DrugWarehouseInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func UpdateDrugFlowById(id int64) (err error) {
- err = XTWriteDB().Model(&models.DrugFlow{}).Where("warehousing_detail_id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func DeleteWarehouse(ids []string) (err error) {
- ut := writeDb.Begin()
- err = ut.Model(&models.Warehousing{}).Where("id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.WarehousingInfo{}).Where("warehousing_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
-
- ut.Commit()
- return
- }
-
- func DeleteStockFlow(ids []string) (err error) {
- ut := writeDb.Begin()
- err = ut.Model(&models.VmStockFlow{}).Where("warehousing_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- return
- }
-
- func DeleteDrugWarehouse(ids []string) (err error) {
- ut := writeDb.Begin()
- err = ut.Model(&models.DrugWarehouse{}).Where("id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.DrugWarehouseInfo{}).Where("warehousing_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
-
- err = ut.Model(&models.DrugFlow{}).Where("warehousing_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- return
- }
-
- func FindWareHouseById(orderNumber string) (*models.Warehousing, error) {
- warehouse := &models.Warehousing{}
- err := readDb.Model(&models.Warehousing{}).Where("warehousing_order = ? AND status = 1", orderNumber).First(&warehouse).Error
- return warehouse, err
- }
-
- func FindWareHouseOutByIdOne(id int64) (*models.WarehouseOut, error) {
- warehouseOut := &models.WarehouseOut{}
- err := XTReadDB().Model(&models.WarehouseOut{}).Where("id = ? AND status = 1", id).First(&warehouseOut).Error
-
- return warehouseOut, err
- }
- func FindWareHouseOutById(id int64, tx *gorm.DB) (*models.WarehouseOut, error) {
- warehouseOut := &models.WarehouseOut{}
- err := tx.Model(&models.WarehouseOut{}).Where("id = ? AND status = 1", id).First(&warehouseOut).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return warehouseOut, err
- }
- }
- return warehouseOut, err
- }
-
- func FindDrugWareHouseOutById(id int64, org_id int64) (*models.DrugWarehouseOut, error) {
- warehouseOut := &models.DrugWarehouseOut{}
- err := readDb.Model(&models.DrugWarehouseOut{}).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ? ", org_id).Where("id = ? AND status = 1", id).First(&warehouseOut).Error
- return warehouseOut, err
- }
-
- func FindNewDrugWareHouseOutById(id int64, org_id int64, tx *gorm.DB) (*models.DrugWarehouseOut, error) {
- warehouseOut := &models.DrugWarehouseOut{}
- err := tx.Model(&models.DrugWarehouseOut{}).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ? ", org_id).Where("id = ? AND status = 1", id).First(&warehouseOut).Error
- if err != nil {
- tx.Rollback()
- return warehouseOut, err
- }
- return warehouseOut, err
- }
-
- func FindWarehouseInfoByOrderNumber(orderNumber string) (info []*models.WarehousingInfo, err error) {
- err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_order = ? AND status = 1", orderNumber).Find(&info).Error
- return
-
- }
-
- func FindWarehouseOutInfoByOrderNumber(orderNumber string) (info []*models.WarehouseOutInfo, err error) {
- err = readDb.Model(&models.WarehouseOutInfo{}).Where("warehouse_out_order_number = ? AND status = 1", orderNumber).Find(&info).Error
- return
-
- }
-
- func DeleteStockInRecordByOrderNumber(orderNumber string, id int64) (err error) {
- err = readDb.Model(&models.WarehousingInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- err = readDb.Model(&models.Warehousing{}).Where("warehousing_order = ? AND status = 1", orderNumber).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func DeleteStockInRecordByReocordId(id int64) (err error) {
- err = readDb.Model(&models.WarehousingInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func FindAllGoodByManufactureId(manufacturer_id int64, dealer_id int64, org_id int64) (goodInfo []*models.GoodInfo, err error) {
- db := readDb.Model(&models.GoodInfo{}).Where("org_id = ? AND status = 1", org_id)
- if manufacturer_id > 0 {
- db = db.Where("manufacturer = ?", manufacturer_id)
- }
- if dealer_id > 0 {
- db = db.Where("dealer = ?", dealer_id)
- }
- err = db.Preload("GoodsType", "status = 1 AND org_id = ?", org_id).Find(&goodInfo).Error
- return goodInfo, err
- }
-
- func FindAllWarehouseByKeyword(orgId int64, page int64, limit int64, keywords string) (list []*models.Warehousing, total int64, err error) {
- db := readDb.Model(&models.Warehousing{})
- likekey := "%" + keywords + "%"
- db = db.Where("org_id = ? AND status = 1 ", orgId)
- db = db.Where("warehousing_order LIKE ? ", likekey)
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
- return
- }
-
- func GetLastWarehousingById(warehousing_id int64, orgid int64) (models.WarehousingInfo, error) {
-
- info := models.WarehousingInfo{}
- err = XTReadDB().Model(&info).Where("warehousing_id = ? and good_id = ? and status = 1", warehousing_id, orgid).Find(&info).Error
- return info, err
- }
-
- func GetLastWarehousingByIdOne(warehousing_id int64, orgid int64) (models.WarehousingInfo, error) {
-
- info := models.WarehousingInfo{}
- err = XTReadDB().Model(&info).Where("id = ? and good_id = ? and status = 1", warehousing_id, orgid).Find(&info).Error
- return info, err
- }
-
- func UpDateWarehousingInfo(info *models.WarehousingInfo) (err error) {
- err = writeDb.Save(&info).Error
- return err
- }
-
- func UpDateDrugWarehousingInfo(info *models.DrugWarehouseInfo) (err error) {
- err = writeDb.Save(&info).Error
- return err
- }
-
- func UpDateDrugWarehousingInfoTwo(id int64, info *models.DrugWarehouseInfo) (err error) {
- err = writeDb.Model(&info).Where("id= ? and status = 1", id).Updates(map[string]interface{}{"number": info.Number, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "price": info.Price, "total_price": info.TotalPrice, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "remark": info.Remark, "batch_number": info.BatchNumber, "max_unit": info.MaxUnit, "min_unit": info.MinUnit, "retail_price": info.RetailPrice, "stock_max_number": info.StockMaxNumber, "stock_min_number": info.StockMinNumber, "storehouse_id": info.StorehouseId}).Error
- return err
- }
-
- func UpDateDrugWarehousingInfoSix(id int64, info *models.DrugWarehouseInfo) (err error) {
- err = writeDb.Model(&info).Where("id= ? and status = 1", id).Updates(map[string]interface{}{"number": info.Number, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "price": info.Price, "total_price": info.TotalPrice, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "remark": info.Remark, "batch_number": info.BatchNumber, "max_unit": info.MaxUnit, "min_unit": info.MinUnit, "retail_price": info.RetailPrice, "storehouse_id": info.StorehouseId}).Error
- return err
- }
-
- func GetDrugWarehouseOrderOne(id int64, drug_id int64) (models.DrugWarehouseInfo, error) {
-
- info := models.DrugWarehouseInfo{}
- err = XTReadDB().Model(&info).Where("warehousing_id = ? and drug_id = ?", id, drug_id).Find(&info).Error
- return info, err
- }
-
- func EditWarehousing(warehouse models.Warehousing) {
-
- err = readDb.Model(&models.Warehousing{}).Where("warehousing_order = ? AND status = 1", warehouse.WarehousingOrder).Update(map[string]interface{}{"mtime": time.Now().Unix(), "warehousing_time": warehouse.WarehousingTime, "modifier": warehouse.Modifier, "dealer": warehouse.Dealer, "manufacturer": warehouse.Manufacturer, "storehouse_id": warehouse.StorehouseId}).Error
-
- }
-
- func EditNewWarehousing(warehouse models.Warehousing, tx *gorm.DB) {
-
- err = tx.Model(&models.Warehousing{}).Where("warehousing_order = ? AND status = 1", warehouse.WarehousingOrder).Update(map[string]interface{}{"mtime": time.Now().Unix(), "warehousing_time": warehouse.WarehousingTime, "modifier": warehouse.Modifier, "dealer": warehouse.Dealer, "manufacturer": warehouse.Manufacturer, "storehouse_id": warehouse.StorehouseId}).Error
-
- if err != nil {
- tx.Rollback()
- return
- }
- return
- }
-
- func FindAllWarehouseInfo(org_id int64, types int64) (list []*models.WarehousingInfoConfig, err error) {
- err = readDb.Model(&models.WarehousingInfoConfig{}).Preload("WarehousingGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND org_id = ?", org_id).Preload("GoodsType", "status = 1 AND org_id = ?", org_id).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id)
- }).Where("org_id = ? AND status = 1 AND type = ?", org_id, types).Find(&list).Error
- return list, err
- }
-
- func DeleteSalesReturn(ids []string) (err error) {
- ut := writeDb.Begin()
- err = ut.Model(&models.SalesReturn{}).Where("id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.SalesReturnInfo{}).Where("sales_return_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- return
- }
-
- func DeleteDrugSalesReturn(ids []string) (err error) {
- ut := writeDb.Begin()
- err = ut.Model(&models.DrugSalesReturn{}).Where("id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.DrugSalesReturnInfo{}).Where("sales_return_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- return
- }
-
- func FindAllSalesReturnInfoById(id int64) (list []*models.SalesReturnInfo, err error) {
- err = readDb.Model(&models.SalesReturnInfo{}).Where("sales_return_id = ? AND status = 1", id).Find(&list).Error
- return
- }
-
- type DrugSalesReturnInfo struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
- SalesReturnId int64 `gorm:"column:sales_return_id" json:"sales_return_id" form:"sales_return_id"`
- Count int64 `gorm:"column:count" json:"count" form:"count"`
- Price float64 `gorm:"column:price" json:"price" form:"price"`
- Total float64 `gorm:"column:total" json:"total" form:"total"`
- ProductDate int64 `gorm:"column:product_date" json:"product_date" form:"product_date"`
- ExpiryDate int64 `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
- Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
- Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
- Status int64 `gorm:"column:status" json:"status" form:"status"`
- OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
- OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
- Type int64 `gorm:"column:type" json:"type" form:"type"`
- Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
- Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
- RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
- RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
- Number string `gorm:"column:number" json:"number" form:"number"`
- Drug *Drug `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
- }
-
- func (DrugSalesReturnInfo) TableName() string {
- return "xt_drug_sales_return_info"
- }
-
- func FindAllDrugSalesReturnInfoById(id int64, org_id int64) (list []*DrugSalesReturnInfo, err error) {
- err = readDb.Model(&DrugSalesReturnInfo{}).Preload("Drug", "status = 1 AND org_id = ?", org_id).Where("sales_return_id = ? AND status = 1 AND org_id = ?", id, org_id).Find(&list).Error
- return
- }
-
- func FindAllSalesReturnById(id int64) (salesReturn models.SalesReturn, err error) {
- err = readDb.Model(&models.SalesReturn{}).Where("id = ? AND status = 1", id).First(&salesReturn).Error
- return
- }
-
- func FindAllDrugSalesReturnById(id int64, org_id int64) (salesReturn models.DrugSalesReturn, err error) {
- err = readDb.Model(&models.DrugSalesReturn{}).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Where("id = ? AND status = 1", id).First(&salesReturn).Error
- return
- }
-
- func UpDateSaleReturnStatus(id int64) (err error) {
- err = readDb.Model(&models.SalesReturnInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func UpDateDrugSaleReturnStatus(id int64) (err error) {
- err = readDb.Model(&models.DrugSalesReturnInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func FindSalesReturnById(id int64) (salesReturn models.SalesReturn, err error) {
- err = readDb.Model(&models.SalesReturn{}).Where("id = ? AND status = 1", id).First(&salesReturn).Error
- return salesReturn, err
-
- }
-
- func FindDrugSalesReturnById(id int64) (salesReturn models.DrugSalesReturn, err error) {
- err = readDb.Model(&models.DrugSalesReturn{}).Where("id = ? AND status = 1", id).First(&salesReturn).Error
- return salesReturn, err
-
- }
-
- func EditSaleReturn(sales models.SalesReturn) {
- err = readDb.Model(&models.SalesReturn{}).Where("id = ? AND status = 1", sales.ID).Update(map[string]interface{}{"mtime": time.Now().Unix(), "return_time": sales.ReturnTime, "dealer": sales.Dealer, "manufacturer": sales.Manufacturer}).Error
-
- }
-
- func EditDrugSaleReturn(sales models.DrugSalesReturn) {
- err = readDb.Model(&models.DrugSalesReturn{}).Where("id = ? AND status = 1", sales.ID).Update(map[string]interface{}{"mtime": time.Now().Unix(), "return_time": sales.ReturnTime, "dealer": sales.Dealer, "manufacturer": sales.Manufacturer}).Error
-
- }
- func UpDateSalesReturnInfo(info *models.SalesReturnInfo) (err error) {
- err = writeDb.Save(&info).Error
- return err
- }
-
- func UpDateDrugSalesReturnInfo(info *models.DrugSalesReturnInfo) (err error) {
- err = writeDb.Save(&info).Error
- return err
- }
-
- func DeleteWarehouseOut(ids []string) (err error) {
- ut := writeDb.Begin()
- err = ut.Model(&models.WarehouseOut{}).Where("id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.WarehouseOutInfo{}).Where("warehouse_out_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
-
- err = ut.Model(&models.VmStockFlow{}).Where("warehouse_out_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- return
- }
-
- func DeleteDrugWarehouseOut(ids []string) (err error) {
- ut := writeDb.Begin()
- err = ut.Model(&models.DrugWarehouseOut{}).Where("id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.DrugWarehouseOutInfo{}).Where("warehouse_out_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
-
- err = ut.Model(&models.DrugFlow{}).Where("warehouse_out_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- return
- }
-
- func UpDateWarehouseOutStatus(id int64) (err error) {
- err = readDb.Model(&models.WarehouseOutInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func UpDateDrugWarehouseInfoByStock(info *models.XtDrugWarehouseInfo) (err error) {
- ut := writeDb.Begin()
- err = ut.Save(&info).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- ut.Commit()
- return err
- }
-
- func UpDateNewDrugWarehouseInfoByStock(info *models.XtDrugWarehouseInfo, tx *gorm.DB) (err error) {
- err = tx.Save(&info).Error
-
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpDateWarehouseInfoByStock(info *models.WarehousingInfo) (err error) {
- ut := writeDb.Begin()
- err = ut.Save(&info).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- ut.Commit()
- return err
- }
-
- func UpDateNewWarehouseInfoByStock(info *models.WarehousingInfo, tx *gorm.DB) (err error) {
-
- err = tx.Save(&info).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpDateDrugWarehouseOutStatus(id int64) (err error) {
- err = readDb.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func EditWarehouseOut(warehouseOut models.WarehouseOut, tx *gorm.DB) {
-
- err = tx.Model(&models.WarehouseOut{}).Where("id = ? AND status = 1", warehouseOut.ID).Update(map[string]interface{}{"mtime": time.Now().Unix(), "warehouse_out_time": warehouseOut.WarehouseOutTime, "dealer": warehouseOut.Dealer, "manufacturer": warehouseOut.Manufacturer, "storehouse_id": warehouseOut.StorehouseId}).Error
-
- if err != nil {
- tx.Rollback()
- return
- }
- return
- }
-
- func EditDrugWarehouseOut(warehouseOut models.DrugWarehouseOut) {
- err = readDb.Model(&models.DrugWarehouseOut{}).Where("id = ? AND status = 1", warehouseOut.ID).Update(map[string]interface{}{"mtime": time.Now().Unix(), "warehouse_out_time": warehouseOut.WarehouseOutTime, "dealer": warehouseOut.Dealer, "manufacturer": warehouseOut.Manufacturer, "storehouse_id": warehouseOut.StorehouseId}).Error
- }
-
- func EditNewDrugWarehouseOut(warehouseOut models.DrugWarehouseOut, tx *gorm.DB) {
-
- err = tx.Model(&models.DrugWarehouseOut{}).Where("id = ? AND status = 1", warehouseOut.ID).Update(map[string]interface{}{"mtime": time.Now().Unix(), "warehouse_out_time": warehouseOut.WarehouseOutTime, "dealer": warehouseOut.Dealer, "manufacturer": warehouseOut.Manufacturer, "storehouse_id": warehouseOut.StorehouseId}).Error
- if err != nil {
- tx.Rollback()
- return
- }
- return
- }
-
- func UpDateWarehouseOutInfo(info *models.WarehouseOutInfo, tx *gorm.DB) (err error) {
- err = tx.Save(&info).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func FindAllCancelList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string, storehouse_id int64, check_type int64) (list []*models.CancelStock, total int64, err error) {
- db := readDb.Model(&models.CancelStock{})
- db = db.Where("xt_cancel_stock.org_id = ? AND xt_cancel_stock.status = 1 AND xt_cancel_stock.type = ?", orgId, types)
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_cancel_stock.creater")
- //db = db.Joins("join xt_manufacturer on xt_manufacturer.id = xt_cancel_stock.manufacturer")
- db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_cancel_stock.order_number LIKE ?", likeKey, likeKey).Group("xt_cancel_stock.id")
- }
-
- if startTime > 0 {
- db = db.Where("xt_cancel_stock.opera_time >=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("xt_cancel_stock.opera_time<= ?", endTime)
- }
- if storehouse_id > 0 {
- db = db.Where("xt_cancel_stock.storehouse_id = ?", storehouse_id)
- }
- if check_type > 0 {
- db = db.Where("xt_cancel_stock.is_check = ?", check_type)
- }
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.Offset(offset).Limit(limit).Order("xt_cancel_stock.ctime desc").Find(&list).Error
- return
- }
-
- func FindAllDrugCancelList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string, storehoue_id int64, check_type int64) (list []*models.DrugCancelStock, total int64, err error) {
- db := readDb.Model(&models.DrugCancelStock{})
- db = db.Where("xt_drug_cancel_stock.org_id = ? AND xt_drug_cancel_stock.status = 1", orgId)
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_cancel_stock.creater")
- //db = db.Joins("join xt_manufacturer on xt_manufacturer.id = xt_drug_cancel_stock.manufacturer")
- db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_drug_cancel_stock.order_number LIKE ?", likeKey, likeKey).Group("xt_drug_cancel_stock.id")
- }
-
- if startTime > 0 {
- db = db.Where("xt_drug_cancel_stock.opera_time >=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("xt_drug_cancel_stock.opera_time<= ?", endTime)
- }
- if storehoue_id > 0 {
- db = db.Where("xt_drug_cancel_stock.storehouse_id = ?", storehoue_id)
- }
- if check_type > 0 {
- db = db.Where("xt_drug_cancel_stock.is_check = ?", check_type)
- }
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.Offset(offset).Limit(limit).Order("xt_drug_cancel_stock.ctime desc").Find(&list).Error
- return
- }
-
- func GetCancelWarehosueInfo(ids []string) (info []*models.CancelStockInfo, err error) {
-
- err = XTReadDB().Where("id IN(?) and status = 1", ids).Find(&info).Error
- return info, err
- }
-
- func DeleteCancelStock(ids []string) (err error) {
- ut := writeDb.Begin()
- err = ut.Model(&models.CancelStock{}).Where("id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.CancelStockInfo{}).Where("cancel_stock_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.VmStockFlow{}).Where("cancel_stock_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- return
- }
-
- func GetDrugWareInfoByCancelId(ids []string) (info []*models.DrugCancelStockInfo, err error) {
- err = XTReadDB().Where("cancel_stock_id IN(?) and status = 1", ids).Find(&info).Error
- return info, err
- }
-
- func DeleteDrugCancelStock(ids []string) (err error) {
- ut := writeDb.Begin()
- err = ut.Model(&models.DrugCancelStock{}).Where("id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.DrugCancelStockInfo{}).Where("cancel_stock_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.Model(&models.DrugFlow{}).Where("cancel_stock_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- return
- }
-
- func UpDateCancleStockStatus(id int64) (err error) {
- err = readDb.Model(&models.CancelStockInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func GetCancelStockById(id int64) (models.CancelStockInfo, error) {
- info := models.CancelStockInfo{}
- err := XTReadDB().Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
- return info, err
- }
-
- func ModefyWarehouseInfoNight(info models.WarehousingInfo, id int64) error {
-
- err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", info.StockCount)).Error
- return err
- }
-
- func UpdatedStockFlowByCancelId(id int64, good_id int64) (err error) {
-
- err = XTWriteDB().Model(&models.VmStockFlow{}).Where("cancel_out_detail_id = ? and status = 1 and good_id = ?", id, good_id).Updates(map[string]interface{}{"status": 0}).Error
- return
- }
-
- func UpDateDrugCancleStockStatus(id int64) (err error) {
- err = readDb.Model(&models.DrugCancelStockInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func UpDateDrugCancelStockById(id int64) (err error) {
-
- err = XTWriteDB().Model(&models.DrugFlow{}).Where("cancel_out_detail_id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return
- }
-
- func EditCancelStock(sales models.CancelStock) {
- err = readDb.Model(&models.CancelStock{}).Where("id = ? AND status = 1", sales.ID).Update(map[string]interface{}{"mtime": time.Now().Unix(), "return_time": sales.ReturnTime, "dealer": sales.Dealer, "manufacturer": sales.Manufacturer, "storehouse_id": sales.StorehouseId}).Error
-
- }
-
- func EditDrugCancelStock(sales models.DrugCancelStock) {
- err = readDb.Model(&models.DrugCancelStock{}).Where("id = ? AND status = 1", sales.ID).Update(map[string]interface{}{"mtime": time.Now().Unix(), "return_time": sales.ReturnTime, "dealer": sales.Dealer, "manufacturer": sales.Manufacturer, "storehouse_id": sales.StorehouseId}).Error
-
- }
-
- func FindCancelStockById(id int64, org_id int64) (cancelStock models.CancelStock, err error) {
- err = readDb.Model(&models.CancelStock{}).Where("id = ? AND status = 1", id).First(&cancelStock).Error
- return cancelStock, err
-
- }
-
- func FindCancelDrugById(id int64, org_id int64) (cancelStock models.DrugCancelStock, err error) {
- err = readDb.Model(&models.DrugCancelStock{}).Where("id = ? AND status = 1", id).First(&cancelStock).Error
- return cancelStock, err
-
- }
-
- func FindDrugCancelStockById(id int64) (cancelStock models.DrugCancelStock, err error) {
- err = readDb.Model(&models.DrugCancelStock{}).Where("id = ? AND status = 1", id).First(&cancelStock).Error
- return cancelStock, err
-
- }
-
- func UpDateCancelStockInfo(info *models.CancelStockInfo) (err error) {
- err = writeDb.Save(&info).Error
- return err
- }
-
- func UpDateDrugCancelStockInfo(info *models.DrugCancelStockInfo) (err error) {
- err = writeDb.Save(&info).Error
- return err
- }
-
- func FindWarehouseOutList(org_id int64, types int64) (list []*models.WarehouseOut, err error) {
- err = readDb.Model(&models.WarehouseOut{}).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ? ", org_id).Where("org_id = ? AND status = 1 AND type = ?", org_id, types).Find(&list).Error
- return list, err
- }
-
- func FindAllWarehouseOutInfo(org_id int64, types int64) (list []*models.WarehousingOutInfoConfig, err error) {
- err = readDb.Model(&models.WarehousingOutInfoConfig{}).Preload("WarehousingGoodInfo", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND org_id = ?", org_id).Preload("GoodsType", "status = 1 AND org_id = ? ", org_id).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id)
- }).Where("org_id = ? AND status = 1 AND type = ?", org_id, types).Find(&list).Error
- return list, err
-
- }
-
- type StockDetailModel struct {
- GoodId int64 `gorm:"good_id" json:"good_id"`
- GoodTypeId int64 `gorm:"good_type_id" json:"good_type_id"`
- WarehousingOrder string `gorm:"warehousing_order" json:"warehousing_order"`
- Price float64 `gorm:"price" json:"price"`
- WarehousingCount int64 `gorm:"warehousing_count" json:"warehousing_count"`
- Type int `gorm:"type" json:"type"`
- Creater int64 `gorm:"creater" json:"creater"`
- WarehousingTime int64 `gorm:"warehousing_time" json:"warehousing_time"`
- Types int64 `gorm:"types" json:"types"`
- }
-
- func FindStockInDetailList(orgId int64, page int64, limit int64, startTime int64, endTime int64, keywords string, manufacturer int64, order_type int64, dealer int64, storehouse_id int64) (list []*models.WarehousingInfo, total int64, err error) {
-
- db := readDb.Model(&models.WarehousingInfo{})
- db = db.Where("xt_warehouse_info.org_id = ? AND xt_warehouse_info.status = 1 AND xt_warehouse_info.is_check = 1", orgId)
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- //db = db.Joins("join xt_warehouse on xt_warehouse.id = xt_warehouse_info.warehousing_id AND ")
- db = db.Joins("join xt_warehouse on xt_warehouse.id = xt_warehouse_info.warehousing_id AND xt_warehouse.warehousing_time >=? AND xt_warehouse.warehousing_time<= ? AND xt_warehouse.status = 1 AND xt_warehouse.org_id = ?", startTime, endTime, orgId)
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_warehouse.creater")
- db = db.Joins("join xt_good_information on xt_good_information.id = xt_warehouse_info.good_id")
-
- db = db.Where(" sgj_user_admin_role.user_name LIKE ? OR xt_warehouse_info.warehousing_order LIKE ? OR xt_good_information.specification_name LIKE ? OR xt_good_information.good_name LIKE ?", likeKey, likeKey, likeKey, likeKey).Group("xt_warehouse_info.id")
- } else {
- db = db.Joins("join xt_warehouse on xt_warehouse.id = xt_warehouse_info.warehousing_id AND xt_warehouse.warehousing_time >=? AND xt_warehouse.warehousing_time<= ? AND xt_warehouse.status = 1 AND xt_warehouse.org_id = ?", startTime, endTime, orgId)
- }
-
- if manufacturer > 0 {
- db = db.Joins("join xt_warehouse as wa on wa.id = xt_warehouse_info.warehousing_id AND wa.manufacturer =?", manufacturer)
- }
-
- if storehouse_id > 0 {
- db = db.Where("xt_warehouse_info.storehouse_id = ?", storehouse_id)
- }
-
- if order_type > 0 {
- db = db.Where("xt_warehouse_info.type = ?", order_type)
- }
-
- db = db.Preload("Warehousing", "status = 1 AND org_id = ?", orgId)
- db = db.Preload("GoodInfo", "status = 1 AND org_id = ?", orgId)
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.Offset(offset).Limit(limit).Order("xt_warehouse_info.id desc").Find(&list).Error
- return
- }
-
- func GetStockInDetailTotal(orgId int64, startTime int64, endTime int64, keywords string, manufacturer int64, order_type int64, dealer int64, storehouse_id int64) (err error, totalPrice float64) {
- db := readDb.Model(&models.WarehousingInfo{})
- db = db.Where("xt_warehouse_info.org_id = ? AND xt_warehouse_info.status = 1", orgId)
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- //db = db.Joins("join xt_warehouse on xt_warehouse.id = xt_warehouse_info.warehousing_id AND ")
- db = db.Joins("join xt_warehouse on xt_warehouse.id = xt_warehouse_info.warehousing_id AND xt_warehouse.warehousing_time >=? AND xt_warehouse.warehousing_time<= ? AND xt_warehouse.status = 1 AND xt_warehouse.org_id = ?", startTime, endTime, orgId)
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_warehouse.creater")
- db = db.Joins("join xt_good_information on xt_good_information.id = xt_warehouse_info.good_id")
- db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_warehouse_info.warehousing_order LIKE ? OR xt_good_information.specification_name LIKE ?", likeKey, likeKey, likeKey).Group("xt_warehouse_info.id")
- } else {
- db = db.Joins("join xt_warehouse on xt_warehouse.id = xt_warehouse_info.warehousing_id AND xt_warehouse.warehousing_time >=? AND xt_warehouse.warehousing_time<= ? AND xt_warehouse.status = 1 AND xt_warehouse.org_id = ?", startTime, endTime, orgId)
- }
- if manufacturer > 0 {
- db = db.Joins("join xt_warehouse as wa on wa.id = xt_warehouse_info.warehousing_id AND wa.manufacturer =?", manufacturer)
- }
- if order_type > 0 {
- db = db.Where("xt_warehouse_info.type = ?", order_type)
- }
- if storehouse_id > 0 {
- db = db.Where("xt_warehouse_info.storehouse_id = ?", storehouse_id)
- }
- type PriceAmount struct {
- Total float64
- }
- var result []PriceAmount
- err = db.Select("total_price as total").Scan(&result).Error
- var total float64
- for _, value := range result {
- total = total + value.Total
- }
- total, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", total), 64)
- return err, total
- }
-
- func FloatRound(f float64, n int) float64 {
- format := "%." + strconv.Itoa(n) + "f"
- res, _ := strconv.ParseFloat(fmt.Sprintf(format, f), 64)
- return res
- }
-
- func FindStockOutDetailList(orgId int64, page int64, limit int64, startTime int64, endTime int64, keywords string, manufacturer int64, order_type int64, dealer int64, storehouse_id int64) (list []*models.WarehouseOutInfo, total int64, err error) {
-
- if orgId == 9671 {
- db := readDb.Model(&models.WarehouseOutInfo{})
- db = db.Where("xt_warehouse_out_info.org_id = ? AND xt_warehouse_out_info.status = 1 AND xt_warehouse_out_info.is_check = 1 AND xt_warehouse_out_info.good_id <> 0 AND xt_warehouse_out_info.count <> 0 AND xt_warehouse_out_info.sys_record_time>=? AND xt_warehouse_out_info.sys_record_time<=?", orgId, startTime, endTime)
-
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Joins("join xt_warehouse_out on xt_warehouse_out.id = xt_warehouse_out_info.warehouse_out_id AND xt_warehouse_out.warehouse_out_time >=? AND xt_warehouse_out.warehouse_out_time<= ? AND xt_warehouse_out.status = 1 AND xt_warehouse_out.org_id = ?", startTime, endTime, orgId)
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_warehouse_out.creater")
- db = db.Joins("join xt_good_information on xt_good_information.id = xt_warehouse_out_info.good_id")
-
- db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_warehouse_out_info.warehouse_out_order_number LIKE ? OR xt_good_information.specification_name LIKE ? OR xt_good_information.good_name LIKE ?", likeKey, likeKey, likeKey, likeKey).Group("xt_warehouse_out_info.id")
- } else {
- db = db.Joins("join xt_warehouse_out on xt_warehouse_out.id = xt_warehouse_out_info.warehouse_out_id AND xt_warehouse_out.warehouse_out_time >=? AND xt_warehouse_out.warehouse_out_time<= ? AND xt_warehouse_out.status = 1 AND xt_warehouse_out.org_id = ?", startTime, endTime, orgId)
- }
-
- if manufacturer > 0 {
- db = db.Joins("join xt_warehouse_out as wa on wa.id = xt_warehouse_out_info.warehouse_out_id AND wa.manufacturer =?", manufacturer)
- }
-
- if order_type > 0 {
- db = db.Where("xt_warehouse_out_info.type = ?", order_type)
- }
-
- if storehouse_id > 0 {
- db = db.Where("xt_warehouse_out_info.storehouse_id = ?", storehouse_id)
- }
-
- db = db.Preload("WarehouseOut", "status = 1 AND org_id = ?", orgId)
- db = db.Preload("WarehousingInfoNight", "status=1 and org_id = ?", orgId)
- db = db.Preload("GoodInfo", "status = 1 AND org_id = ?", orgId)
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.Offset(offset).Limit(limit).Order("xt_warehouse_out_info.id desc").Find(&list).Error
- return
- } else {
- db := readDb.Model(&models.WarehouseOutInfo{})
- db = db.Where("xt_warehouse_out_info.org_id = ? AND xt_warehouse_out_info.status = 1 AND xt_warehouse_out_info.is_check = 1 AND xt_warehouse_out_info.good_id <> 0 AND xt_warehouse_out_info.count <> 0 ", orgId)
-
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Joins("join xt_warehouse_out on xt_warehouse_out.id = xt_warehouse_out_info.warehouse_out_id AND xt_warehouse_out.warehouse_out_time >=? AND xt_warehouse_out.warehouse_out_time<= ? AND xt_warehouse_out.status = 1 AND xt_warehouse_out.org_id = ?", startTime, endTime, orgId)
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_warehouse_out.creater")
- db = db.Joins("join xt_good_information on xt_good_information.id = xt_warehouse_out_info.good_id")
-
- db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_warehouse_out_info.warehouse_out_order_number LIKE ? OR xt_good_information.specification_name LIKE ? OR xt_good_information.good_name LIKE ?", likeKey, likeKey, likeKey, likeKey).Group("xt_warehouse_out_info.id")
- } else {
- db = db.Joins("join xt_warehouse_out on xt_warehouse_out.id = xt_warehouse_out_info.warehouse_out_id AND xt_warehouse_out.warehouse_out_time >=? AND xt_warehouse_out.warehouse_out_time<= ? AND xt_warehouse_out.status = 1 AND xt_warehouse_out.org_id = ?", startTime, endTime, orgId)
- }
-
- if manufacturer > 0 {
- db = db.Joins("join xt_warehouse_out as wa on wa.id = xt_warehouse_out_info.warehouse_out_id AND wa.manufacturer =?", manufacturer)
- }
-
- if order_type > 0 {
- db = db.Where("xt_warehouse_out_info.type = ?", order_type)
- }
-
- if storehouse_id > 0 {
- db = db.Where("xt_warehouse_out_info.storehouse_id = ?", storehouse_id)
- }
-
- db = db.Preload("WarehouseOut", "status = 1 AND org_id = ?", orgId)
- db = db.Preload("WarehousingInfoNight", "status=1 and org_id = ?", orgId)
- db = db.Preload("GoodInfo", "status = 1 AND org_id = ?", orgId)
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.Offset(offset).Limit(limit).Order("xt_warehouse_out_info.id desc").Find(&list).Error
- return
- }
-
- }
-
- func GetStockOutDetailTotal(orgId int64, startTime int64, endTime int64, keywords string, manufacturer int64, order_type int64, dealer int64, storehouse_id int64) (err error, totalPrice float64) {
- db := readDb.Model(&models.WarehouseOutInfo{})
- db = db.Where("xt_warehouse_out_info.org_id = ? AND xt_warehouse_out_info.status = 1 AND xt_warehouse_out_info.good_id <> 0 AND xt_warehouse_out_info.count <> 0", orgId)
-
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Joins("join xt_warehouse_out on xt_warehouse_out.id = xt_warehouse_out_info.warehouse_out_id AND xt_warehouse_out.warehouse_out_time >=? AND xt_warehouse_out.warehouse_out_time<= ? AND xt_warehouse_out.status = 1 AND xt_warehouse_out.org_id = ?", startTime, endTime, orgId)
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_warehouse_out.creater")
- db = db.Joins("join xt_good_information on xt_good_information.id = xt_warehouse_out_info.good_id")
-
- db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_warehouse_out_info.warehouse_out_order_number LIKE ?", likeKey, likeKey).Group("xt_warehouse_out_info.id")
- } else {
- db = db.Joins("join xt_warehouse_out on xt_warehouse_out.id = xt_warehouse_out_info.warehouse_out_id AND xt_warehouse_out.warehouse_out_time >=? AND xt_warehouse_out.warehouse_out_time<= ? AND xt_warehouse_out.status = 1 AND xt_warehouse_out.org_id = ?", startTime, endTime, orgId)
- }
-
- if manufacturer > 0 {
- db = db.Joins("join xt_warehouse_out as wa on wa.id = xt_warehouse_out_info.warehouse_out_id AND wa.manufacturer =?", manufacturer)
- }
-
- if order_type > 0 {
- db = db.Where("xt_warehouse_out_info.type = ?", order_type)
- }
-
- if storehouse_id > 0 {
- db = db.Where("xt_warehouse_out_info.storehouse_id = ?", storehouse_id)
- }
-
- type PriceAmount struct {
- Total float64
- }
- var result []PriceAmount
- err = db.Select("(count * price) as total").Scan(&result).Error
- var total float64
- for _, value := range result {
- total = total + value.Total
- }
- total, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", total), 64)
- fmt.Println(total)
- return err, total
- }
-
- func FindSalesReturnDetailList(orgId int64, page int64, limit int64, startTime int64, endTime int64, keywords string, manufacturer int64, order_type int64, dealer int64) (list []*models.SalesReturnInfo, total int64, err error) {
- db := readDb.Model(&models.SalesReturnInfo{})
- db = db.Where("xt_sales_return_info.org_id = ? AND xt_sales_return_info.status = 1", orgId)
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Joins("join xt_sales_return on xt_sales_return.id = xt_sales_return_info.sales_return_id AND xt_sales_return.return_time >=? AND xt_sales_return.return_time<= ? AND xt_sales_return.status = 1 AND xt_sales_return.org_id = ?", startTime, endTime, orgId)
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_sales_return.creater")
- db = db.Joins("join xt_good_information on xt_good_information.id = xt_sales_return_info.good_id")
-
- db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_sales_return_info.order_number LIKE ? OR xt_good_information.specification_name LIKE ? OR xt_good_information.good_name LIKE ?", likeKey, likeKey, likeKey, likeKey).Group("xt_sales_return_info.id")
- } else {
- db = db.Joins("join xt_sales_return on xt_sales_return.id = xt_sales_return_info.sales_return_id AND xt_sales_return.return_time >=? AND xt_sales_return.return_time<= ? AND xt_sales_return.status = 1 AND xt_sales_return.org_id = ?", startTime, endTime, orgId)
- }
-
- if manufacturer > 0 {
- db = db.Joins("join xt_sales_return as sr on sr.id = xt_sales_return_info.sales_return_id AND sr.manufacturer =?", manufacturer)
- }
-
- if order_type > 0 {
- db = db.Where("xt_sales_return_info.type = ?", order_type)
- }
-
- db = db.Preload("SalesReturn", "status = 1 AND org_id = ?", orgId)
- db = db.Preload("GoodInfo", "status = 1 AND org_id = ?", orgId)
- offset := (page - 1) * limit
- db = db.Count(&total)
-
- err = db.Offset(offset).Limit(limit).Order("xt_sales_return_info.ctime desc").Find(&list).Error
-
- return
- }
-
- func FindeCancelGroup(orgId int64, startTime int64, endTime int64, keywords string, manufacturer int64, order_type int64, dealer int64, storehouse_id int64) (list []*models.CancelStockInfo, err error) {
- db := readDb.Model(&models.CancelStockInfo{})
- db = db.Where("xt_cancel_stock_info.org_id = ? AND xt_cancel_stock_info.status = 1", orgId)
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Joins("join xt_cancel_stock on xt_cancel_stock.id = xt_cancel_stock_info.cancel_stock_id AND xt_cancel_stock.return_time >=? AND xt_cancel_stock.return_time<= ? AND xt_cancel_stock.status = 1 AND xt_cancel_stock.org_id = ?", startTime, endTime, orgId)
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_cancel_stock.creater")
- db = db.Joins("join xt_good_information on xt_good_information.id = xt_cancel_stock_info.good_id")
-
- db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_cancel_stock_info.order_number LIKE ? OR xt_good_information.specification_name LIKE ?", likeKey, likeKey, likeKey).Group("xt_cancel_stock_info.id")
- } else {
- db = db.Joins("join xt_cancel_stock on xt_cancel_stock.id = xt_cancel_stock_info.cancel_stock_id AND xt_cancel_stock.return_time >=? AND xt_cancel_stock.return_time<= ? ", startTime, endTime)
- }
-
- if manufacturer > 0 {
- db = db.Joins("join xt_cancel_stock as cs on cs.id = xt_cancel_stock_info.cancel_stock_id AND cs.manufacturer =?", manufacturer)
- }
-
- if order_type > 0 {
- db = db.Where("xt_cancel_stock_info.type = ?", order_type)
- }
-
- if storehouse_id > 0 {
- db = db.Where("xt_cancel_stock_info.storehouse_id = ?", order_type)
- }
-
- db = db.Preload("CancelStock", "status = 1 AND org_id = ?", orgId)
- db = db.Preload("GoodInfo", "status = 1 AND org_id = ?", orgId)
-
- err = db.Group("xt_cancel_stock_info.good_id").Order("xt_cancel_stock_info.ctime desc").Find(&list).Error
- return
- }
-
- func FindCancelDetailList(orgId int64, page int64, limit int64, startTime int64, endTime int64, keywords string, manufacturer int64, order_type int64, dealer int64, storehouse_id int64) (list []*models.CancelStockInfo, total int64, err error) {
- db := readDb.Model(&models.CancelStockInfo{})
- db = db.Where("xt_cancel_stock_info.org_id = ? AND xt_cancel_stock_info.status = 1", orgId)
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Joins("join xt_cancel_stock on xt_cancel_stock.id = xt_cancel_stock_info.cancel_stock_id AND xt_cancel_stock.return_time >=? AND xt_cancel_stock.return_time<= ? AND xt_cancel_stock.status = 1 AND xt_cancel_stock.org_id = ?", startTime, endTime, orgId)
- db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_cancel_stock.creater")
- db = db.Joins("join xt_good_information on xt_good_information.id = xt_cancel_stock_info.good_id")
-
- db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_cancel_stock_info.order_number LIKE ? OR xt_good_information.specification_name LIKE ? OR xt_good_information.good_name LIKE ?", likeKey, likeKey, likeKey, likeKey).Group("xt_cancel_stock_info.id")
- } else {
- db = db.Joins("join xt_cancel_stock on xt_cancel_stock.id = xt_cancel_stock_info.cancel_stock_id AND xt_cancel_stock.return_time >=? AND xt_cancel_stock.return_time<= ? ", startTime, endTime)
- }
-
- if manufacturer > 0 {
- db = db.Joins("join xt_cancel_stock as cs on cs.id = xt_cancel_stock_info.cancel_stock_id AND cs.manufacturer =?", manufacturer)
- }
-
- if order_type > 0 {
- db = db.Where("xt_cancel_stock_info.type = ?", order_type)
- }
- if storehouse_id > 0 {
- db = db.Where("xt_cancel_stock_info.storehouse_id = ?", storehouse_id)
- }
-
- db = db.Preload("CancelStock", "status = 1 AND org_id = ?", orgId)
- db = db.Preload("GoodInfo", "status = 1 AND org_id = ?", orgId)
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.Offset(offset).Limit(limit).Order("xt_cancel_stock_info.id desc").Find(&list).Error
- return
- }
-
- func FindStockInByDealerId(id int64) (total int64, err error) {
- err = readDb.Model(&models.Warehousing{}).Where("dealer = ? AND status = 1", id).Count(&total).Error
- return
- }
-
- func FindStockInByManufacturerId(id int64) (total int64, err error) {
- err = readDb.Model(&models.Warehousing{}).Where("manufacturer = ? AND status = 1", id).Count(&total).Error
- return
- }
-
- func FindGoodTypeByName(name string, org_id int64) (total int64) {
- readDb.Model(&models.GoodsType{}).Where("org_id = ? AND status = 1 AND type_name = ? ", org_id, name).Count(&total)
- return
- }
- func FindGoodInfoByName(name string, org_id int64, good_type_id int64) (total int64) {
- readDb.Model(&models.GoodInfo{}).Where("org_id = ? AND status = 1 AND specification_name = ? AND good_type_id = ? ", org_id, name, good_type_id).Count(&total)
- return
- }
-
- func FindGoodInfoByNameTwo(name string, org_id int64, good_type_id int64, good_name string) (total int64) {
- readDb.Model(&models.GoodInfo{}).Where("org_id = ? AND status = 1 AND specification_name = ? AND good_type_id = ? and good_name = ?", org_id, name, good_type_id, good_name).Count(&total)
- return
- }
-
- func FindGoodInfoByNameOne(name string, org_id int64, good_type_id int64, id int64, goodname string) (total int64) {
- readDb.Model(&models.GoodInfo{}).Where("org_id = ? AND status = 1 AND specification_name = ? AND good_type_id = ? and id <> ? and good_name = ? ", org_id, name, good_type_id, id, goodname).Count(&total)
- return
- }
-
- func FindAllGoodTypeByType(types int64) (goodType []*models.GoodsType, err error) {
- err = readDb.Model(&models.GoodsType{}).Where("type = ? AND status = 1", types).Find(&goodType).Error
- return goodType, err
- }
-
- func FindWarehouseInfoByGoodType(good_type_id int64, org_id int64) (info []*models.WarehousingInfo, err error) {
- err = readDb.Model(&models.WarehousingInfo{}).Preload("GoodInfo", " org_id = ? AND good_type_id = ? AND status = 1 AND specification_name <> '' ", org_id, good_type_id).Where(" org_id = ? AND good_type_id = ? AND status = 1 ", org_id, good_type_id).Find(&info).Error
- return info, err
-
- }
-
- func FindStockOutByIsSys(org_id int64, is_sys int, record_time int64) (out models.WarehouseOut, err error) {
- err = readDb.Model(&models.WarehouseOut{}).Where("is_sys = ? AND status = 1 AND org_id = ? AND warehouse_out_time = ?", is_sys, org_id, record_time).First(&out).Error
- return
-
- }
-
- func FindStockOutByIsSysOne(org_id int64, is_sys int, record_time int64, warehousing_out_order string, tx *gorm.DB) (out models.WarehouseOut, err error) {
-
- err = tx.Model(&models.WarehouseOut{}).Where("is_sys = ? AND status = 1 AND org_id = ? AND warehouse_out_time = ? and warehouse_out_order_number = ?", is_sys, org_id, record_time, warehousing_out_order).First(&out).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return
- }
- }
- return
-
- }
-
- func FindStockOutByIsSysSix(org_id int64, is_sys int, record_time int64, second_warehouse_id int64) (out models.WarehouseOut, err error) {
- err = readDb.Model(&models.WarehouseOut{}).Where("is_sys = ? AND status = 1 AND org_id = ? AND warehouse_out_time = ? AND second_warehouse_id=?", is_sys, org_id, record_time, second_warehouse_id).First(&out).Error
- return
-
- }
-
- func FindDrugStockOutByIsSys(org_id int64, is_sys int, record_time int64) (out models.DrugWarehouseOut, err error) {
- err = readDb.Model(&models.DrugWarehouseOut{}).Where("is_sys = ? AND status = 1 AND org_id = ? AND warehouse_out_time = ?", is_sys, org_id, record_time).First(&out).Error
- return
-
- }
-
- func FindNewDrugStockOutByIsSys(org_id int64, is_sys int, record_time int64, tx *gorm.DB) (out models.DrugWarehouseOut, err error) {
-
- err = tx.Model(&models.DrugWarehouseOut{}).Where("is_sys = ? AND status = 1 AND org_id = ? AND warehouse_out_time = ?", is_sys, org_id, record_time).First(&out).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return
- }
- }
-
- return
-
- }
-
- func FindDrugSettleStockOutByIsSys(org_id int64, is_sys int, record_time int64) (out models.DrugWarehouseOut, err error) {
- err = readDb.Model(&models.DrugWarehouseOut{}).Where("is_sys = ? AND status = 1 AND org_id = ? AND warehouse_out_time = ?", is_sys, org_id, record_time).First(&out).Error
- return
-
- }
-
- func FindLastStockInInfoRecord(good_id int64, org_id int64) (in models.WarehousingInfo, err error) {
- err = readDb.Model(&models.WarehousingInfo{}).Where("status = 1 AND org_id = ? AND good_id = ?", org_id, good_id).First(&in).Error
- return
- }
-
- func FindLastDrugStockInInfoRecord(drug_id int64, org_id int64) (in models.DrugWarehouseOutInfo, err error) {
- err = readDb.Model(&models.DrugWarehouseInfo{}).Where("status = 1 AND org_id = ? AND drug_id = ?", org_id, drug_id).Last(&in).Error
- return
-
- }
-
- func GetStockInRecoredByGoodId(goodid int64, goodtypeid int64, recordtime int64, patientid int64, orgid int64) (*models.WarehouseOutInfo, error) {
-
- info := models.WarehouseOutInfo{}
-
- err := XTReadDB().Model(&info).Where("good_id = ? and good_type_id = ? and sys_record_time = ? and patient_id = ? and org_id = ? and status = 1", goodid, goodtypeid, recordtime, patientid, orgid).Find(&info).Error
-
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
-
- if err != nil {
- return nil, err
- }
-
- return &info, nil
- }
-
- func GetStockInRecoredByGoodIdOne(goodid int64, goodtypeid int64, recordtime int64, orgid int64) (*models.WarehouseOutInfo, error) {
-
- info := models.WarehouseOutInfo{}
-
- err := XTReadDB().Model(&info).Where("good_id = ? and good_type_id = ? and sys_record_time = ? and org_id = ? and status = 1", goodid, goodtypeid, recordtime, orgid).Find(&info).Error
-
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
-
- if err != nil {
- return nil, err
- }
-
- return &info, nil
- }
-
- func UpdateAutoMaticReduceDetail(goodid int64, goodtypeid int64, recordtime int64, patientid int64, orgid int64, prepare *models.WarehouseOutInfo) error {
-
- err := XTWriteDB().Model(&prepare).Where("good_id = ? and good_type_id = ? and sys_record_time = ? and patient_id = ? and org_id = ? and status =1", goodid, goodtypeid, recordtime, patientid, orgid).Updates(map[string]interface{}{"count": prepare.Count, "over_count": prepare.OverCount}).Error
- return err
- }
-
- func UpdateAutoMaticReduceDetailOne(goodid int64, goodtypeid int64, recordtime int64, orgid int64, prepare *models.WarehouseOutInfo) error {
-
- err := XTWriteDB().Model(&prepare).Where("good_id = ? and good_type_id = ? and sys_record_time = ? and org_id = ? and status =1", goodid, goodtypeid, recordtime, orgid).Updates(map[string]interface{}{"count": prepare.Count}).Error
- return err
- }
-
- func GetGoodsIsExsit(good_id int64, sys_record_time int64, org_id int64, warehouse_out_id int64, tx *gorm.DB) (models.WarehouseOutInfo, error) {
-
- outInfo := models.WarehouseOutInfo{}
- err := tx.Where("good_id = ? and sys_record_time = ? and org_id = ? and is_sys =0 and status = 1 and warehouse_out_id = ?", good_id, sys_record_time, org_id, warehouse_out_id).Find(&outInfo).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return outInfo, err
- }
-
- }
- return outInfo, err
- }
-
- func GetDrugsIsExsit(drug_id int64, sys_record_time int64, org_id int64, warehouse_out_id int64) (models.XtDrugWarehouseOutInfo, error) {
-
- outInfo := models.XtDrugWarehouseOutInfo{}
- err := XTReadDB().Where("drug_id = ? and sys_record_time = ? and org_id = ? and is_sys =0 and status = 1 and warehouse_out_id = ?", drug_id, sys_record_time, org_id, warehouse_out_id).Find(&outInfo).Error
- return outInfo, err
- }
-
- func GetNewDrugsIsExsit(drug_id int64, sys_record_time int64, org_id int64, warehouse_out_id int64, tx *gorm.DB) (models.XtDrugWarehouseOutInfo, error) {
-
- outInfo := models.XtDrugWarehouseOutInfo{}
- err := tx.Where("drug_id = ? and sys_record_time = ? and org_id = ? and is_sys =0 and status = 1 and warehouse_out_id = ?", drug_id, sys_record_time, org_id, warehouse_out_id).Find(&outInfo).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return outInfo, err
- }
- }
- return outInfo, err
- }
-
- func AddSigleWarehouseOutInfoOne(info *models.WarehouseOutInfo) error {
-
- err := XTWriteDB().Create(&info).Error
- return err
-
- }
-
- func AddSigleWarehouseOutInfo(info *models.WarehouseOutInfo, tx *gorm.DB) error {
-
- err := tx.Create(&info).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
-
- }
-
- func AddNewSigleWarehouseOutInfo(info *models.WarehouseOutInfo, tx *gorm.DB) error {
-
- err := tx.Create(&info).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
-
- }
-
- func UpdateStockOut(warehouseinfoid int64, info models.WarehousingInfo) error {
-
- err := XTWriteDB().Model(&info).Where("id=? and status = 1", warehouseinfoid).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
- return err
- }
-
- func AddSigleDrugWarehouseOutInfo(info *models.DrugWarehouseOutInfo) error {
-
- err := writeDb.Create(&info).Error
-
- return err
- }
-
- func AddSelfSigleDrugWarehouseOutInfo(info *models.XtSelfDrugWarehouseOutInfo, tx *gorm.DB) error {
-
- err := tx.Create(&info).Error
-
- if err != nil {
- tx.Rollback()
- return err
- }
-
- return err
- }
-
- func AddNewSigleDrugWarehouseOutInfo(info *models.DrugWarehouseOutInfo, tx *gorm.DB) error {
-
- err := tx.Create(&info).Error
-
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpdateSigleDrugWarehouseOutInfoDetail(id int64, count int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status=1", id).UpdateColumn("count", gorm.Expr("count + ?", count)).Error
-
- err = tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status=1", id).UpdateColumn("over_count", gorm.Expr("over_count - ?", count)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
-
- return err
- }
-
- func UpdateSigleDrugWarehouseOutInfoDetailOne(id int64, count int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"count": count}).Error
-
- return err
- }
-
- func AddSigleAutoReduceRecordInfo(detail *models.AutomaticReduceDetail) error {
- ut := writeDb.Begin()
- err := ut.Create(&detail).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- ut.Commit()
- return err
- }
-
- func AddSigleDrugAutoReduceRecordInfo(detail *models.DrugAutomaticReduceDetail) error {
- err := writeDb.Create(&detail).Error
- return err
-
- }
-
- func GetDrugAutoMaticReduceDetail(drug_id int64, patient_id int64, record_time int64, org_id int64, adivce_id int64, warehouse_info_id int64, tx *gorm.DB) (models.DrugAutomaticReduceDetail, error) {
-
- detail := models.DrugAutomaticReduceDetail{}
- err := tx.Where("drug_id = ? and patient_id =? and record_time =? and org_id = ? and advice_id = ? and warehouse_info_id =?", drug_id, patient_id, record_time, org_id, adivce_id, warehouse_info_id).Find(&detail).Error
-
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return detail, err
- }
- }
- return detail, err
- }
-
- func UpdateNewSingleDrugAutoReduceRecordInfo(id int64, count int64, tx *gorm.DB) error {
-
- err := tx.Model(models.DrugAutomaticReduceDetail{}).Where("id = ? and status =1", id).UpdateColumn("count", gorm.Expr("count + ?", count)).Error
-
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func AddNewSigleDrugAutoReduceRecordInfo(detail *models.DrugAutomaticReduceDetail, tx *gorm.DB) error {
-
- err := tx.Create(&detail).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
-
- }
-
- func FindStockOutInfoByTypeId(org_id int64, good_type_id int64, good_id int64, out_id int64, number string) (out models.WarehouseOutInfo, err error) {
- err = readDb.Model(&models.WarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND good_type_id = ? AND good_id = ? AND is_sys = 1 AND (warehouse_out_id = ? or warehouse_out_order_number = ?)", org_id, good_type_id, good_id, out_id, number).First(&out).Error
- return
- }
-
- func FindStockOutInfoByStock(org_id int64, good_type_id int64, good_id int64, record_date int64, patient_id int64) (out []*models.WarehouseOutInfo, err error) {
- err = readDb.Model(&models.WarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND good_type_id = ? AND good_id = ? AND is_sys = 1 AND sys_record_time = ? AND patient_id = ?", org_id, good_type_id, good_id, record_date, patient_id).Order("ctime desc").Find(&out).Error
- return
- }
-
- func FindStockOutInfoByStockOne(org_id int64, good_type_id int64, good_id int64, record_date int64) (out []*models.WarehouseOutInfo, err error) {
- err = readDb.Model(&models.WarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND good_type_id = ? AND good_id = ? AND is_sys = 1 AND sys_record_time = ?", org_id, good_type_id, good_id, record_date).Order("ctime desc").Find(&out).Error
- return
- }
-
- func FindStockOutInfoByStockTwo(org_id int64, good_type_id int64, good_id int64, record_date int64, patient_id int64) (models.WarehouseOutInfo, error) {
- info := models.WarehouseOutInfo{}
- err = readDb.Model(&info).Where("status = 1 AND org_id = ? AND good_type_id = ? AND good_id = ? AND is_sys = 1 AND sys_record_time = ? and patient_id = ?", org_id, good_type_id, good_id, record_date, patient_id).Order("ctime desc").Find(&info).Error
- return info, err
- }
-
- func FindDrugStockOutInfoByTypeId(org_id int64, drug_id int64, out_id int64, number string) (out models.DrugWarehouseOutInfo, err error) {
- err = readDb.Model(&models.DrugWarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND drug_id = ? AND is_sys = 1 AND (warehouse_out_id = ? or warehouse_out_order_number = ?)", org_id, drug_id, out_id, number).First(&out).Error
- return
- }
-
- func UpdateStockOutInfoCount(org_id int64, id int64) {
- writeDb.Model(&models.WarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND id = ?", org_id, id).UpdateColumn("count", gorm.Expr("count + ?", 1))
-
- }
-
- func FindUserDetailById(org_id int64, id int64) (user []*models.AutomaticReduceDetail, err error, total int64) {
- db := readDb.Model(&models.AutomaticReduceDetail{})
- db = db.Preload("GoodInfo", "org_id = ? AND status = 1", org_id)
- db = db.Preload("GoodsType", "status = 1")
- db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
- db = db.Where("status = 1 AND org_id = ? AND warehouse_out_id = ? AND good_id != 0 AND count <> 0 ", org_id, id)
- db = db.Count(&total)
- err = db.Find(&user).Error
- return
- }
-
- type DrugAutomaticReduceDetail struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
- WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
- PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
- Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
- Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
- Status int64 `gorm:"column:status" json:"status" form:"status"`
- RecordTime int64 `gorm:"column:record_time" json:"record_time" form:"record_time"`
- OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
- DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
- Count int64 `gorm:"column:count" json:"count" form:"count"`
- CountUnit string `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
- Drug *Drug `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
- Patients *models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"user"`
- DrugWarehouseOutInfo []*models.DrugWarehouseOutInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"drugwarehouseoutinfo"`
- }
-
- func (DrugAutomaticReduceDetail) TableName() string {
- return "xt_drug_automatic_reduce_detail"
- }
-
- func FindDrugStockUserDetailById(org_id int64, id int64) (user []*DrugAutomaticReduceDetail, err error, total int64) {
- db := readDb.Model(&DrugAutomaticReduceDetail{})
- db = db.Preload("Drug", "org_id = ? AND status = 1", org_id)
- db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
- db = db.Where("status = 1 AND org_id = ? AND warehouse_out_id = ? AND drug_id != 0", org_id, id)
- db = db.Count(&total)
- err = db.Find(&user).Error
- return
- }
-
- func UpdateStockOutInfoCount2(org_id int64, id int64, count int64) {
- writeDb.Model(&models.WarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND id = ?", org_id, id).UpdateColumn("count", gorm.Expr("count + ?", count))
-
- }
-
- func UpdateDrugStockOutInfoCount2(org_id int64, id int64, count int64) {
- writeDb.Model(&models.DrugWarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND id = ?", org_id, id).UpdateColumn("count", gorm.Expr("count + ?", count))
-
- }
-
- func FindPatientAutomaticReduceRecord(org_id int64, record_time int64, good_id int64, good_type_id int64, patient_id int64) (count int64, err error) {
-
- err = readDb.Model(&models.AutomaticReduceDetail{}).Where("org_id = ?AND status = 1 AND good_id = ? AND good_type_id = ? AND patient_id = ? AND record_time = ? AND count <> 0", org_id, good_id, good_type_id, patient_id, record_time).Count(&count).Error
- return
-
- }
-
- func FindPatientDrugAutomaticReduceRecord(org_id int64, record_time int64, drug_id int64, patient_id int64) (count int64, err error) {
-
- err = readDb.Model(&models.DrugAutomaticReduceDetail{}).Where("org_id = ? AND status = 1 AND drug_id = ? AND patient_id = ? AND record_time = ?", org_id, drug_id, patient_id, record_time).Count(&count).Error
- return
-
- }
-
- type VMWarehousingInfo struct {
- ID int64 `gorm:"column:id" json:"id"`
- WarehousingId int64 `gorm:"column:warehousing_id" json:"warehousing_id"`
- GoodId int64 `gorm:"column:good_id" json:"good_id"`
- GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
- Status int64 `gorm:"column:status" json:"status"`
- OrgId int64 `gorm:"column:org_id" json:"org_id"`
- GoodInfo GoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
- }
-
- func (VMWarehousingInfo) TableName() string {
- return "xt_warehouse_info"
- }
-
- type GoodInfo struct {
- ID int64 `gorm:"column:id" json:"id"`
- SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
- Status int64 `gorm:"column:status" json:"status"`
- OrgId int64 `gorm:"column:org_id" json:"org_id"`
- }
-
- func (GoodInfo) TableName() string {
- return "xt_good_information"
- }
-
- func GetStockInGoodInfo(orgId int64) (stockIn []*VMWarehousingInfo, err error) {
- err = readDb.Model(&VMWarehousingInfo{}).Preload("GoodInfo", "status = 1 AND org_id = ?", orgId).Where("org_id = ? AND status = 1", orgId).Find(&stockIn).Error
- return
- }
-
- func GetAllStockOutUserDetail(patient_id int64, orgId int64, record_time int64) (goodUser []*models.DialysisBeforePrepare, err error) {
- err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND record_date = ? AND status = 1 AND count <> 0 ", patient_id, orgId, record_time).Find(&goodUser).Error
- return
- }
-
- func PostSearchStock(keyword string, orgid int64) (goods []*models.GoodsType, err error) {
-
- likeKey := "%" + keyword + "%"
- db := XTReadDB().Model(&goods)
- if len(keyword) > 0 {
- db = db.Where("type_name like ?", likeKey)
- }
- err = db.Where("org_id = ? and status =1", orgid).Find(&goods).Error
- return goods, err
- }
-
- func GetStockType(orgid int64) (goodstype []*models.GoodsTypeOne, err error) {
- err = XTReadDB().Where("org_id = ? and status = 1 and (stock_attribute = 2 or stock_attribute = 3 or stock_attribute = 4)", orgid).
- Preload("GoodInfo", "org_id = ? and status = 1 and find_in_set('停用',good_status) = 0", orgid).Find(&goodstype).Error
- return goodstype, err
- }
-
- func GetDialyStockOut(orgid int64, recordtime int64, patientId int64) (prepare []*models.XtDialysisBeforePrepare, err error) {
-
- db := XTReadDB().Table("dialysis_before_prepare as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if recordtime > 0 {
- db = db.Where("x.record_date = ?", recordtime)
- }
- if patientId > 0 {
- db = db.Where("x.patient_id = ?", patientId)
- }
- err = db.Select("x.id,x.user_org_id,x.patient_id,x.record_date,x.good_id,x.good_type_id,x.count,x.commdity_code,t.specification_name").Joins("left join xt_good_information as t on t.id = x.good_id and t.org_id = ? and t.status = 1", orgid).Scan(&prepare).Error
- return prepare, err
- }
-
- func GetAutoReduceRecordInfoById(orgid int64, recordtime int64, goodid int64, goodtypeid int64) (*models.XtAutomaticReduceDetail, error) {
-
- detail := models.XtAutomaticReduceDetail{}
- err := XTReadDB().Model(&detail).Where("org_id = ? and record_time = ? and good_id = ? and good_type_id = ? and status =1", orgid, recordtime, goodid, goodtypeid).Find(&detail).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
-
- if err != nil {
- return nil, err
- }
-
- return &detail, nil
- }
-
- func GetOutStockTotalCount(wareouttime int64, orgid int64) (autoMatic []*models.NewXtAutomaticReduceDetail, err error) {
-
- err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time = ? and `status` = 1) as b GROUP BY good_id", orgid, wareouttime).Scan(&autoMatic).Error
-
- return autoMatic, err
-
- }
-
- func GetOutStockTotalCountOne(startime int64, endtime int64, orgid int64) (autoMatic []*models.NewXtAutomaticReduceDetail, err error) {
- err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time >= ? and x.record_time<=? and `status` = 1) as b GROUP BY good_id", orgid, startime, endtime).Scan(&autoMatic).Error
-
- return autoMatic, err
- }
-
- func GetManufacturerName(orgid int64, name string) (*models.Manufacturer, error) {
- var manufacturer models.Manufacturer
- var err error
- err = XTReadDB().Model(&manufacturer).Where("org_id = ? and manufacturer_name = ? and status = 1", orgid, name).Find(&manufacturer).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &manufacturer, nil
- }
-
- func CreateManufacturer(manufacturer *models.Manufacturer) error {
-
- err := XTWriteDB().Create(manufacturer).Error
- return err
- }
-
- func UpdatedManufactur(manufacturer *models.Manufacturer, orgid int64) error {
-
- err := XTWriteDB().Model(&manufacturer).Where("org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"manufacturer_name": manufacturer.ManufacturerName}).Error
- return err
- }
-
- func GetGoodsInformaitonIsExist(goodName string, goodType int64, specificationName string, orgid int64) (*models.GoodInfo, error) {
-
- var good models.GoodInfo
- var err error
- err = XTReadDB().Model(&good).Where("good_name = ? and good_type_id = ? and specification_name = ? and org_id = ? and status = 1", goodName, goodType, specificationName, orgid).Find(&good).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
-
- if err != nil {
- return nil, err
- }
-
- return &good, nil
-
- }
-
- func CreateGoodsInfomation(info *models.GoodInfo) error {
-
- err := XTWriteDB().Create(&info).Error
- return err
- }
-
- func UpdateGoodsInformation(info *models.GoodInfo, goodName string, goodType int64, specificationName string, orgid int64) error {
-
- err := XTWriteDB().Model(&info).Where("good_name = ? and good_type_id = ? and specification_name = ? and org_id = ? and status = 1", goodName, goodType, specificationName, orgid).Updates(map[string]interface{}{"good_name": info.GoodName, "good_type_id": info.GoodTypeId, "medical_insurance_level": info.MedicalInsuranceLevel, "good_kind": info.GoodKind, "specification_name": info.SpecificationName, "manufacturer": info.Manufacturer, "good_unit": info.GoodUnit, "retail_price": info.RetailPrice, "stock_warn_count": info.StockWarnCount, "dealer": info.Dealer, "pinyin": info.Pinyin, "wubi": info.Wubi, "buy_price": info.BuyPrice, "medical_insurance_number": info.MedicalInsuranceNumber, "is_special_diseases": info.IsSpecialDiseases, "is_record": info.IsRecord, "statistics_category": info.StatisticsCategory, "good_status": info.GoodStatus, "social_security_directory_code": info.SocialSecurityDirectoryCode, "production_type": info.ProductionType, "special_medical": info.SpecialMedical, "remark": info.Remark, "number": info.Number, "register_number": info.RegisterNumber}).Error
- return err
- }
-
- func GetCoutWareseOutInfo(startime int64, endtime int64, orgid int64) (houseOutInfo []*models.VmWarehouseOutInfo, err error) {
-
- db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status =1")
- err = db.Select("x.good_id,Sum(x.count) as count,x.remark,x.price,x.org_id").Where("x.ctime >=? and x.ctime<=? and x.org_id = ?", startime, endtime, orgid).Group("x.good_id").Scan(&houseOutInfo).Error
- return houseOutInfo, err
- }
-
- func GetGoodInfomationList(orgid int64, keyword string) (goodInfo []*models.GoodInfo, err error) {
- key := "%" + keyword + "%"
- if len(keyword) == 0 {
- err = XTReadDB().Where("org_id = ? and status = 1 AND find_in_set('停用',good_status) = 0", orgid).Find(&goodInfo).Error
-
- } else {
- err = XTReadDB().Where("org_id = ? and status = 1 AND good_name like ? AND find_in_set('停用',good_status) = 0", orgid, key).Find(&goodInfo).Error
-
- }
- return goodInfo, err
- }
-
- func IsExistDrugByName(drugname string, drugdesc string, orgid int64) (*models.BaseDrugLib, error) {
- var drug models.BaseDrugLib
- var err error
- err = XTReadDB().Model(&drug).Where("drug_name = ? and drug_spec = ? and status =1 and org_id = ?", drugname, drugdesc, orgid).Find(&drug).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &drug, nil
- }
-
- func IsExistDrugByNameOne(drugname string, dosage string, doseunit string, minnumber int64, minunit string, packtunit string, orgid int64) (*models.BaseDrugLib, error) {
- var drug models.BaseDrugLib
- var err error
- err = XTReadDB().Model(&drug).Where("drug_name = ? and dose = ? and dose_unit = ? and min_number = ? and min_unit=? and max_unit = ? and status =1 and org_id = ?", drugname, dosage, doseunit, minnumber, minunit, packtunit, orgid).Find(&drug).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &drug, nil
- }
-
- func CreateDrugsInfomation(info *models.BaseDrugLib) error {
- err := XTWriteDB().Create(&info).Error
- return err
- }
-
- func UpdateDrugsInformation(drug *models.BaseDrugLib, drugName string, drugSpec string, orgid int64) error {
-
- err := XTWriteDB().Model(&drug).Where("drug_name = ? and drug_spec = ? and org_id = ? and status = 1", drugName, drugSpec, orgid).Updates(map[string]interface{}{"drug_name": drug.DrugName, "drug_alias": drug.DrugAlias, "drug_spec": drug.DrugSpec, "drug_type": drug.DrugType, "drug_stock_limit": drug.DrugStockLimit, "drug_origin_place": drug.DrugOriginPlace, "drug_dosage_form": drug.DrugDosageForm, "medical_insurance_level": drug.MedicalInsuranceLevel, "max_unit": drug.MaxUnit, "min_unit": drug.MinUnit, "unit_matrixing": drug.UnitMatrixing, "retail_price": drug.RetailPrice, "last_price": drug.LastPrice, "drug_classify": drug.DrugClassify, "manufacturer": drug.Manufacturer, "dealer": drug.Dealer, "pinyin": drug.Pinyin, "wubi": drug.Wubi, "drug_alias_pinyin": drug.DrugAliasPinyin, "drug_alias_wubi": drug.DrugAliasWubi, "drug_category": drug.DrugCategory, "drug_control": drug.DrugControl, "number": drug.Number, "hosp_appr_flag": drug.HospApprFlag, "medical_insurance_number": drug.MedicalInsuranceNumber, "pharmacology_category": drug.PharmacologyCategory, "statistics_category": drug.StatisticsCategory, "code": drug.Code, "is_special_diseases": drug.IsSpecialDiseases, "is_record": drug.IsRecord, "prescription_mark": drug.PrescriptionMark, "social_security_directory_code": drug.SocialSecurityDirectoryCode, "record_date": drug.RecordDate, "drug_remark": drug.DrugRemark, "drug_status": drug.DrugStatus, "limit_remark": drug.LimitRemark, "drug_dose": drug.DrugDose, "single_dose": drug.DrugDose, "drug_dose_unit": drug.DrugDoseUnit, "lmt_used_flag": drug.LmtUsedFlag, "delivery_way": drug.DeliveryWay, "execution_frequency": drug.ExecutionFrequency, "drug_day": drug.DrugDay}).Error
- return err
- }
-
- func GetProjectByNameIsExsit(projectName string, orgid int64) (*models.HisProject, error) {
-
- var projoect models.HisProject
- var err error
- err = XTReadDB().Model(&projoect).Where("project_name = ? and user_org_id = ? and status =1", projectName, orgid).Find(&projoect).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &projoect, nil
- }
-
- func CreateProjectInfomation(info *models.HisProject) error {
-
- err := XTWriteDB().Create(&info).Error
- return err
- }
-
- func UpdateProjectByName(project *models.HisProject, projectName string, orgid int64) error {
-
- err := XTWriteDB().Model(&project).Where("project_name = ? and user_org_id = ? and status = 1", projectName, orgid).Updates(map[string]interface{}{"project_name": project.ProjectName, "price": project.Price, "unit": project.Unit, "cost_classify": project.CostClassify, "executive_section": project.ExecutiveSection, "medical_coverage": project.MedicalCoverage, "pinyin": project.Pinyin, "wubi": project.Wubi, "statistical_classification": project.StatisticalClassification, "disease_directory": project.DiseaseDirectory, "is_record": project.IsRecord, "medical_code": project.MedicalCode, "tube_color": project.TubeColor, "single_dose": project.SingleDose, "delivery_way": project.DeliveryWay, "execution_frequency": project.ExecutionFrequency, "number_days": project.NumberDays, "total": project.Total, "medical_status": project.MedicalStatus, "category": project.Category, "specail_project": project.SpecailProject, "social_security_directory_code": project.SocialSecurityDirectoryCode, "record_date": project.RecordDate, "remark": project.Remark}).Error
- return err
- }
- func GetWareOutInfoById(warehouseoutid int64, orgid int64) (warehouseinfo []*models.WarehouseOutInfo, err error) {
-
- err = XTReadDB().Model(&warehouseinfo).Where("warehouse_out_id = ? and org_id = ? and status= 1 and is_sys = 0", warehouseoutid, orgid).Find(&warehouseinfo).Error
- return warehouseinfo, err
- }
-
- func EditDrugWarehousingOne(warehouse models.DrugWarehouse, id int64) error {
- err := XTWriteDB().Model(&models.DrugWarehouse{}).Where("warehousing_order = ? AND status = 1 and id = ?", warehouse.WarehousingOrder, id).Update(map[string]interface{}{"mtime": time.Now().Unix(), "warehousing_time": warehouse.WarehousingTime, "modifier": warehouse.Modifier, "dealer": warehouse.Dealer, "manufacturer": warehouse.Manufacturer, "storehouse_id": warehouse.StorehouseId}).Error
- return err
- }
-
- func EditNewDrugWarehousingOne(warehouse models.DrugWarehouse, id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouse{}).Where("warehousing_order = ? AND status = 1 and id = ?", warehouse.WarehousingOrder, id).Update(map[string]interface{}{"mtime": time.Now().Unix(), "warehousing_time": warehouse.WarehousingTime, "modifier": warehouse.Modifier, "dealer": warehouse.Dealer, "manufacturer": warehouse.Manufacturer, "storehouse_id": warehouse.StorehouseId}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func GetAllManufacturerList(orgid int64) (list []*models.Manufacturer, err error) {
-
- err = XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&list).Error
- return list, err
- }
-
- func GetNewAllManufacturerList(orgid int64) (list []*models.BloodManufacturer, err error) {
- err = XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&list).Error
- return list, err
- }
-
- func GetAllDealerList(orgid int64) (list []*models.Dealer, err error) {
-
- err = XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&list).Error
- return list, err
- }
-
- // func GetAllDealerListTX(orgid int64,tx *gorm.DB) (list []*models.Dealer, err error) {
- // err = tx.Where("org_id = ? and status = 1", orgid).Find(&list).Error
- // return list, err
- // }
- func GetDealerByName(orgid int64, name string) (*models.Dealer, error) {
- var dealer models.Dealer
- var err error
- err = XTReadDB().Model(&dealer).Where("org_id = ? and dealer_name = ? and status = 1", orgid, name).Find(&dealer).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &dealer, nil
- }
-
- func CreateDealer(dealer *models.Dealer) error {
-
- err := XTWriteDB().Create(&dealer).Error
- return err
- }
-
- func UpdateDealer(dealer *models.Dealer, orgid int64) error {
-
- err := XTWriteDB().Model(&dealer).Where("org_id = ? and status =1", orgid).Updates(map[string]interface{}{"dealer_name": dealer.DealerName}).Error
- return err
- }
-
- func GetDrugDataConfig(orgid int64, name string) (models.DictDataconfig, error) {
- dataconfig := models.DictDataconfig{}
- err := XTReadDB().Where("org_id = ? and name = ?", orgid, name).Find(&dataconfig).Error
- return dataconfig, err
- }
-
- func GetParentDataConfig(parentid int64, orgid int64) (dataconfig []*models.DictDataconfig, err error) {
-
- err = XTReadDB().Where("parent_id = ? and status =1 and (org_id = ? or org_id = 0)", parentid, orgid).Find(&dataconfig).Error
- return dataconfig, err
- }
-
- func IsExistDicConfig(parentid int64, goodKind string, orgid int64) (*models.DictDataconfig, error) {
-
- var dataconfig models.DictDataconfig
- var err error
- err = XTReadDB().Where("parent_id = ? and status = 1 and name = ? and (org_id = ? or org_id = 0)", parentid, goodKind, orgid).Find(&dataconfig).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &dataconfig, nil
- }
-
- func GetLastDicConfig(parentid int64, orgid int64) (models.DictDataconfig, error) {
-
- dataconfig := models.DictDataconfig{}
- err := XTReadDB().Model(&dataconfig).Where("parent_id = ? and (org_id = ? or org_id = 0) and status = 1", parentid, orgid).Last(&dataconfig).Error
- return dataconfig, err
- }
-
- func CreatedDicConfig(dataconfig *models.DictDataconfig) error {
-
- err := XTWriteDB().Create(&dataconfig).Error
- return err
- }
-
- func UpdatedDicConfig(parentid int64, dataconfig *models.DictDataconfig, orgid int64, goodKind string) error {
-
- err := XTWriteDB().Model(&dataconfig).Where("parent_id = ? and org_id = ? and name = ?", parentid, orgid, goodKind).Updates(map[string]interface{}{"name": dataconfig.Name}).Error
- return err
- }
-
- func GetGoodType(goodName string, orgid int64) (*models.GoodsType, error) {
-
- var goodType models.GoodsType
- var err error
- err = XTReadDB().Where("type_name =? and org_id = ? and status = 1", goodName, orgid).Find(&goodType).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &goodType, nil
- }
-
- func CreatedGoodType(goodsType *models.GoodsType) error {
-
- err := XTWriteDB().Create(&goodsType).Error
- return err
- }
-
- func GetAllGoodType(orgid int64) (goodsType []*models.GoodsType, err error) {
-
- err = XTReadDB().Model(&goodsType).Where("org_id = ? and status = 1", orgid).Find(&goodsType).Error
- return goodsType, err
- }
-
- func GetAllNewGoodType(orgid int64) (goodsType []*models.NewGoodsType, err error) {
-
- err = XTReadDB().Model(&goodsType).Where("org_id = ? and status = 1", orgid).Find(&goodsType).Error
- return goodsType, err
- }
-
- func GetDepartMentByName(name string, orgid int64) (*models.XtHisDepartment, error) {
-
- var department models.XtHisDepartment
- var err error
- err = XTReadDB().Where("name= ? and user_org_id = ? and status = 1", name, orgid).Find(&department).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &department, nil
- }
-
- func GetDataConfigIsExist(orgid int64, name string) (models.Dataconfig, error) {
- dataconfig := models.Dataconfig{}
- err := XTReadDB().Model(&dataconfig).Where("org_id = ? and name = ? and status = 1", orgid, name).Find(&dataconfig).Error
- return dataconfig, err
- }
-
- func GetChildeConfigIsExist(parentid int64, name string, orgid int64) (*models.Dataconfig, error) {
-
- var dataconfig models.Dataconfig
- var err error
- err = XTReadDB().Model(&dataconfig).Where("parent_id = ? and (org_id = ? or org_id = 0) and name = ? and status = 1", parentid, orgid, name).Find(&dataconfig).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &dataconfig, nil
- }
-
- func GetLastChildeConfig(parentid int64, orgid int64) (models.Dataconfig, error) {
-
- dataconfig := models.Dataconfig{}
- err := XTReadDB().Model(&dataconfig).Where("parent_id = ? and (org_id = ? or org_id = 0) and status =1", parentid, orgid).Last(&dataconfig).Error
- return dataconfig, err
- }
-
- func CreateDataConfig(dataconfig *models.Dataconfig) error {
-
- err := XTWriteDB().Create(&dataconfig).Error
- return err
- }
-
- func FindAllDataConfigList(orgid int64, parentId int64) (dataconfig []*models.Dataconfig, err error) {
-
- err = XTReadDB().Model(&dataconfig).Where("(org_id = ? or org_id = 0) and parent_id = ? and status = 1", orgid, parentId).Find(&dataconfig).Error
- return dataconfig, err
- }
-
- func GetWarehouseOrderInfoList(orgid int64) (list []*models.WarehousingInfo, err error) {
-
- err = XTReadDB().Model(&list).Where("org_id = ? and status = 1", orgid).Order("id asc").Group("good_id").Find(&list).Error
- return list, err
- }
-
- func GetSearchDrugList(keywords string, orgid int64) (drug []*models.BaseDrugLib, err error) {
-
- db := XTReadDB().Model(&drug).Where("org_id=? and status=1 and find_in_set('停用',drug_status) = 0", orgid)
- if len(keywords) > 0 {
- likekey := "%" + keywords + "%"
- err = db.Where("(drug_name LIKE ?)", likekey).Preload("DrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Where("org_id=? and status = 1 and warehousing_count <> 0", orgid).Group("id")
- }).Find(&drug).Error
- } else {
- err = db.Preload("DrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Where("org_id=? and status = 1 and warehousing_count <> 0", orgid).Group("id")
- }).Find(&drug).Error
- }
- return
- }
-
- func GetSearchDrugListSix(keywords string, orgid int64, storehouse_id int64) (drug []*models.BaseDrugLib, err error) {
-
- db := XTReadDB().Model(&drug).Where("org_id=? and status=1 and find_in_set('停用',drug_status) = 0", orgid)
-
- if len(keywords) > 0 {
- likekey := "%" + keywords + "%"
- err = db.Where("(drug_name LIKE ?)", likekey).Preload("LastDrugWarehouseInfo", "org_id=? and status = 1 and (stock_max_number > 0 or stock_min_number>0) and storehouse_id = ?", orgid, storehouse_id).Preload("DrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Where("org_id=? and status = 1 and warehousing_count <> 0 and storehouse_id = ?", orgid, storehouse_id).Group("id")
- }).Find(&drug).Error
- } else {
- err = db.Preload("LastDrugWarehouseInfo", "org_id=? and status = 1 and (stock_max_number > 0 or stock_min_number>0) and storehouse_id = ?", orgid, storehouse_id).Preload("DrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Where("org_id=? and status = 1 and warehousing_count <> 0 and storehouse_id = ?", orgid, storehouse_id).Group("id")
- }).Find(&drug).Error
- }
- return
- }
-
- func GetSearchGoodList(keywords string, orgid int64) (good []*models.GoodInfo, err error) {
-
- db := XTReadDB().Model(&good).Where("org_id =? and status = 1 and good_status <> '停用'", orgid)
- if len(keywords) > 0 {
- likekey := "%" + keywords + "%"
- err = db.Where("(good_name Like ?)", likekey).Preload("StWarehousingInfo", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Where("org_id=? and status = 1 and warehousing_count <> 0", orgid)
- }).Find(&good).Error
- } else {
- err = db.Preload("StWarehousingInfo", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Where("org_id=? and status = 1 and warehousing_count <> 0", orgid)
- }).Find(&good).Error
- }
- return
- }
-
- func GetSearchGoodListSix(keywords string, orgid int64, storehouse_id int64) (good []*models.GoodInfoSevenThirty, err error) {
-
- db := XTReadDB().Model(&good).Where("org_id =? and status = 1 AND find_in_set('停用',good_status) = 0", orgid)
- if len(keywords) > 0 {
- likekey := "%" + keywords + "%"
- err = db.Where("(good_name Like ?)", likekey).Preload("LaStWarehousingInfo", "org_id=? and status = 1 and stock_count <> 0 and storehouse_id =?", orgid, storehouse_id).Preload("StWarehousingInfo", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Where("org_id=? and status = 1 and warehousing_count <> 0 and storehouse_id =?", orgid, storehouse_id)
- }).Find(&good).Error
- } else {
- err = db.Preload("LaStWarehousingInfo", "org_id=? and status = 1 and stock_count <> 0 and storehouse_id =?", orgid, storehouse_id).Preload("StWarehousingInfo", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Where("org_id=? and status = 1 and warehousing_count <> 0 and storehouse_id = ?", orgid, storehouse_id)
- }).Find(&good).Error
- }
- return
- }
-
- func CreateAutoReduceRecord(detail *models.BloodAutomaticReduceDetail) error {
- db := writeDb.Begin()
- err := db.Create(&detail).Error
- if err != nil {
- db.Rollback()
- return err
- }
- db.Commit()
- return err
- }
-
- func GetAutoMaticReduceDetail(orgid int64, patient_id int64, recordtime int64, goodid int64, goodtypeid int64) (*models.BloodAutomaticReduceDetail, error) {
-
- var autoreduece models.BloodAutomaticReduceDetail
- var err error
- err = XTReadDB().Model(&autoreduece).Where("org_id = ? and patient_id = ? and status = 1 and record_time = ? and good_id = ? and good_type_id = ? and count<> 0", orgid, patient_id, recordtime, goodid, goodtypeid).Find(&autoreduece).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &autoreduece, nil
- }
-
- func GetAutoMaticReduceDetailTwenty(orgid int64, patient_id int64, recordtime int64, goodid int64, goodtypeid int64) (models.BloodAutomaticReduceDetail, error) {
- auto := models.BloodAutomaticReduceDetail{}
- err = XTReadDB().Model(&auto).Where("org_id = ? and patient_id = ? and status = 1 and record_time = ? and good_id = ? and good_type_id = ? and count>0", orgid, patient_id, recordtime, goodid, goodtypeid).Find(&auto).Error
- return auto, err
- }
-
- func DeleteAutoRedeceDetailTwo(orgid int64, patient_id int64, recordtime int64, goodid int64, goodtypeid int64) error {
-
- detail := models.BloodAutomaticReduceDetail{}
- err := XTWriteDB().Model(&detail).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ? and good_type_id = ?", orgid, patient_id, recordtime, goodid, goodtypeid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
- return err
- }
-
- func GetWarehosueOutByStockFlow(patient_id int64, recrod_date int64, goodid int64) (stockflow []*models.VmStockFlow, err error) {
-
- err = XTReadDB().Where("patient_id = ? and system_time = ? and good_id = ? and consumable_type = 3 and status = 1", patient_id, recrod_date, goodid).Find(&stockflow).Error
- return stockflow, err
- }
-
- func UpdateAutoGood(orgid int64, patient_id int64, recordtime int64, goodid int64, project_id int64, count int64) (err error) {
-
- err = XTWriteDB().Model(models.BloodAutomaticReduceDetail{}).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ?", orgid, patient_id, recordtime, goodid).UpdateColumn("count", gorm.Expr("count - ?", count)).Error
- err = XTWriteDB().Model(models.WarehouseOutInfo{}).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).UpdateColumn("count", gorm.Expr("count - ?", count)).Error
- err = XTWriteDB().Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).UpdateColumn("count", gorm.Expr("count - ?", count)).Error
- return err
- }
-
- func DeleteAutoRedeceDetailTen(orgid int64, patient_id int64, recordtime int64, goodid int64, project_id int64) error {
-
- detail := models.BloodAutomaticReduceDetail{}
- err := XTWriteDB().Model(&detail).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ? ", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
- info := models.WarehouseOutInfo{}
- err = XTWriteDB().Model(&info).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and status = 1 and project_id = ?", orgid, patient_id, recordtime, goodid, project_id).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
- prepare := models.DialysisBeforePrepare{}
- err = XTWriteDB().Model(&prepare).Where("user_org_id = ? and patient_id = ? and record_date = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
- flow := models.VmStockFlow{}
- err = XTWriteDB().Model(&flow).Where("user_org_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1 and project_id = ?", orgid, patient_id, recordtime, goodid, project_id).Updates(map[string]interface{}{"is_read": 1}).Error
- return err
-
- }
-
- func DeleteAutoRedeceDetailTwenty(orgid int64, patient_id int64, recordtime int64, goodid int64, project_id int64) error {
-
- detail := models.BloodAutomaticReduceDetail{}
- err := XTWriteDB().Model(&detail).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ? and project_id = ?", orgid, patient_id, recordtime, goodid, project_id).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
- info := models.WarehouseOutInfo{}
- err = XTWriteDB().Model(&info).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and status = 1 and project_id = ?", orgid, patient_id, recordtime, goodid, project_id).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
- prepare := models.DialysisBeforePrepare{}
- err = XTWriteDB().Model(&prepare).Where("user_org_id = ? and patient_id = ? and record_date = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
- flow := models.VmStockFlow{}
- err = XTWriteDB().Model(&flow).Where("user_org_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1 and project_id = ?", orgid, patient_id, recordtime, goodid, project_id).Updates(map[string]interface{}{"is_read": 1}).Error
- return err
-
- }
-
- func DeleteAutoRedeceDetailTenOne(orgid int64, patient_id int64, recordtime int64, goodid int64, order_id int64) error {
-
- detail := models.BloodAutomaticReduceDetail{}
- err := XTWriteDB().Model(&detail).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ? ", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
- info := models.WarehouseOutInfo{}
- err = XTWriteDB().Model(&info).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and status = 1 and order_id = ?", orgid, patient_id, recordtime, goodid, order_id).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
- prepare := models.DialysisBeforePrepare{}
- err = XTWriteDB().Model(&prepare).Where("user_org_id = ? and patient_id = ? and record_date = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
- flow := models.VmStockFlow{}
- err = XTWriteDB().Model(&flow).Where("user_org_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1 and order_id = ?", orgid, patient_id, recordtime, goodid, order_id).Updates(map[string]interface{}{"is_read": 1}).Error
- return err
-
- }
-
- func UpDateWarehouseInfoByStockDelete(id int64, count int64, patient_id int64, record_time int64, goodid int64) (err error) {
-
- err = writeDb.Model(&models.WarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
- //err = writeDb.Model(&models.VmStockFlow{}).Where("warehousing_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", id, patient_id, record_time, goodid).UpdateColumn("over_count", gorm.Expr("over_count + ?", count)).Error
- return err
- }
-
- func GetCancelStockInfoByPatientId(patientid int64, goodid int64, record_date int64) (info []*models.CancelStockInfo, err error) {
-
- err = XTReadDB().Where("patient_id = ? and good_id = ? and record_date = ? and status = 1", patientid, goodid, record_date).Find(&info).Error
- return info, err
- }
-
- func GetHisPrepscritionByPatientId(patientid int64, goodid int64, record_date int64) (list []*models.HisPrescriptionProject, err error) {
-
- err = XTReadDB().Where("patient_id = ? and project_id = ? and record_date = ? and status = 1", patientid, goodid, record_date).Find(&list).Error
- return list, err
- }
-
- func UpDateWarehouStockFlowByStockDelete(id int64, recordtime int64, good_id int64, count int64, patient_id int64) (err error) {
-
- err = writeDb.Model(&models.VmStockFlow{}).Where("warehousing_id = ? and system_time = ? and good_id = ? and patient_id = ?", id, recordtime, good_id, patient_id).UpdateColumn("count", gorm.Expr("count - ?", count)).Error
- return err
- }
-
- func UpDateWarehouseInfoByStockDeleteOne(id int64, count int64) (err error) {
- err = writeDb.Model(&models.WarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", count)).Error
- return err
- }
-
- func GetAutoDialysisBefor(goodid int64, goodtypeid int64, patientid int64, orgid int64, recorddate int64) (*models.BloodAutomaticReduceDetail, error) {
-
- var autoreduece models.BloodAutomaticReduceDetail
- var err error
- err = XTReadDB().Model(&autoreduece).Where("good_id = ? and good_type_id = ? and patient_id = ? and org_id = ? and status = 1 and record_time = ?", goodid, goodtypeid, patientid, orgid, recorddate).Find(&autoreduece).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &autoreduece, nil
- }
-
- func GetAutoRecordByGoodIdSeven(goodid int64, patientid int64, recorddate int64) (models.WarehouseOutInfoSeven, error) {
- detail := models.WarehouseOutInfoSeven{}
- err := XTReadDB().Select("id,count").Where(" good_id = ? and sys_record_time = ? and patient_id = ? and status = 1", goodid, recorddate, patientid).Find(&detail).Error
- return detail, err
- }
-
- func GetAutoRecordByGoodIdSevenEight(goodid int64, patientid int64, recorddate int64) (detail []*models.WarehouseOutInfoSeven, err error) {
- err = XTReadDB().Select("id,count").Where("good_id = ? and sys_record_time = ? and patient_id = ? and status = 1", goodid, recorddate, patientid).Find(&detail).Error
- return detail, err
- }
-
- func GetHisProjectPrescriptionByPatientId(patientid int64, recorddate int64) (project []*models.HisPrescriptionProject, err error) {
-
- err = XTReadDB().Model(&project).Where("patient_id = ? and record_date = ? and status =1", patientid, recorddate).Find(&project).Error
- return project, err
- }
-
- func GetHisProjectPrescriptionByPatientIdOne(id int64) (models.HisPrescriptionProject, error) {
- project := models.HisPrescriptionProject{}
- err = XTReadDB().Model(&project).Where("id = ? and status =1", id).Find(&project).Error
- return project, err
- }
-
- func GetAllAutoRecordByPatient(patientid int64, recorddate int64) (auto []*models.WarehouseOutInfoNight, err error) {
-
- err = XTReadDB().Select("count,warehouse_info_id,good_id,org_id,sys_record_time,patient_id,project_id,warehouse_info_id,warehouse_out_order_number,storehouse_id,price,dealer,manufacturer,good_type_id,product_date,expiry_date,number,license_number").Where(" patient_id = ? and sys_record_time = ? and status = 1 and is_sys = 1 and count>0", patientid, recorddate).Find(&auto).Error
- return auto, err
-
- }
-
- func ModefyWarehouseInfo(count int64, id int64) error {
-
- err := XTWriteDB().Model(models.WarehousingInfo{}).Where(" id =? and status = 1", id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
- return err
- }
-
- func DeleteAutoWarehouse(patient_id int64, record_time int64) error {
-
- err := XTWriteDB().Model(models.AutomaticReduceDetail{}).Where("patient_id = ? and record_time = ? and status = 1", patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
- err = XTWriteDB().Model(models.DialysisBeforePrepare{}).Where("patient_id = ? and record_date = ? and status = 1", patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
- err = XTWriteDB().Model(models.VmStockFlow{}).Where("patient_id = ? and system_time = ? and status = 1", patient_id, record_time).Updates(map[string]interface{}{"is_read": 1}).Error
- //err = XTWriteDB().Model(models.WarehouseOutInfoNight{}).Where("patient_id = ? and sys_record_time = ? and status = 1", patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
-
- return err
- }
-
- func FindGoodInfoByIdTwo(id int64) (goodInfo models.GoodInfo, err error) {
- err = readDb.Model(&models.GoodInfo{}).Where("id = ? AND status = 1", id).First(&goodInfo).Error
- return
- }
-
- func FindGoodInfoByIdSeven(id int64) (goodInfo models.GoodInfoSeven, err error) {
- err = readDb.Select("id,good_name").Where("id = ? AND status = 1", id).First(&goodInfo).Error
- return
- }
-
- func GetGoodWarehouseInfo(good_id int64) (info []*models.WarehousingInfo, err error) {
-
- err = readDb.Where("good_id = ? and status = 1 and stock_count<>0", good_id).Find(&info).Error
- return info, err
- }
-
- func GetGoodWarehouseInfoSeven(good_id int64) (info []*models.WarehousingInfoSeven, err error) {
-
- err = readDb.Select("stock_count").Where("good_id = ? and status = 1 and stock_count<>0", good_id).Find(&info).Error
- return info, err
- }
-
- func GetGoodWarehouseInfoSevenTen(good_id int64, storehouse_id int64) (info []*models.WarehousingInfoSeven, err error) {
-
- err = readDb.Select("stock_count").Where("good_id = ? and status = 1 and stock_count<>0 and storehouse_id = ?", good_id, storehouse_id).Find(&info).Error
- return info, err
- }
-
- func GetAllStockList(page int64, limit int64, startime int64, endtime int64, good_type int64, keyword string, orgid int64) (info []*models.VmWarehousingInfo, total int64, err error) {
-
- offset := (page - 1) * limit
- db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status= 1")
-
- table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
- fmt.Println(table)
- if startime > 0 {
- db = db.Where("x.ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
-
- likeKey := "%" + keyword + "%"
- if len(likeKey) > 0 {
- db = db.Where("t.good_name like ?", likeKey)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if good_type > 0 {
- db = db.Where("t.good_type_id = ?", good_type)
- }
- err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehousing_unit,x.stock_count,x.price,x.total_price,x.dealer,x.remark,x.ctime,x.is_return,x.warehousing_order,x.type,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.manufacturer").Joins("left join xt_good_information as t on t.id = x.good_id").Group("x.good_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&info).Error
- return info, total, err
- }
-
- func GetAllGoodInfoStockList(page int64, limit int64, startime int64, endtime int64, good_type int64, keyword string, orgid int64, good_id int64, storehouse_id int64) (info []*models.GoodInfo, total int64, err error) {
-
- offset := (page - 1) * limit
- db := XTReadDB().Table("xt_good_information as x").Where("x.status= 1")
-
- likeKey := "%" + keyword + "%"
- if len(likeKey) > 0 {
- db = db.Where("x.good_name like ?", likeKey)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if good_type > 0 {
- db = db.Where("x.good_type_id = ?", good_type)
- }
- if good_id > 0 {
- db = db.Where("x.id = ?", good_id)
- }
-
- err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Preload("StWarehousingInfo", func(db *gorm.DB) *gorm.DB {
- if startime > 0 {
- db = db.Where("ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("ctime<=?", endtime)
- }
- if good_id > 0 {
- db = db.Where("good_id = ?", good_id)
- }
- if storehouse_id > 0 {
- db = db.Where("storehouse_id = ?", storehouse_id)
- }
- return db.Where("status = 1 and is_check = 1")
- }).Preload("WarehousingInfo", func(db *gorm.DB) *gorm.DB {
- if startime > 0 {
- db = db.Where("ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("ctime<=?", endtime)
- }
- if good_id > 0 {
- db = db.Where("good_id = ?", good_id)
- }
- if storehouse_id > 0 {
- db = db.Where("storehouse_id = ?", storehouse_id)
- }
- return db.Where("status = 1").Group("good_id,storehouse_id")
- }).Preload("CancelStockInfo", func(db *gorm.DB) *gorm.DB {
- if startime > 0 {
- db = db.Where("ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("ctime<=?", endtime)
- }
- return db.Where("status = 1")
- }).Find(&info).Error
- return info, total, err
- }
-
- func GetStockListById(good_id int64, orgid int64, limit int64, page int64, startime int64, endtime int64, startfirsttime int64, endfirsttime int64) (info []*models.VmWarehousingInfo, total int64, err error) {
-
- offset := (page - 1) * limit
- db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status= 1 and x.is_check = 1")
- table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
- tables := XTReadDB().Table("xt_stock_flow as f").Where("f.status = 1 and f.consumable_type = 1 and f.user_org_id = ?", orgid)
- fmt.Println(table, tables)
- if startime > 0 {
- db = db.Where("x.ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
- if startfirsttime > 0 {
- db = db.Where("x.expiry_date >=?", startfirsttime)
- }
- if endfirsttime > 0 {
- db = db.Where("x.expiry_date <=?", endfirsttime)
- }
-
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if good_id > 0 {
- db = db.Where("x.good_id = ?", good_id)
- }
- err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehousing_unit,x.stock_count,x.price,x.total_price,x.dealer,x.packing_price,t.manufacturer,x.remark,x.ctime,x.is_return,x.warehousing_order,x.type,x.storehouse_id,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.min_unit,t.buy_price,f.batch_number_count").Joins("left join xt_good_information as t on t.id = x.good_id").Joins("left join xt_stock_flow as f on f.warehousing_detail_id = x.id").Count(&total).Offset(offset).Limit(limit).Group("x.id").Order("x.id desc").Scan(&info).Error
- return info, total, err
-
- }
-
- func GetStockOutList(good_id int64, orgid int64, limit int64, page int64, startime int64, endtime int64, is_sys int64) (info []*models.WarehouseOutInfo, total int64, err error) {
- offset := (page - 1) * limit
-
- db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status= 1")
-
- if startime > 0 {
- db = db.Where("x.ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
-
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if good_id > 0 {
- db = db.Where("x.good_id = ?", good_id)
- }
- if is_sys == 2 {
- db = db.Where("x.is_sys = 1")
- }
- if is_sys == 3 {
- db = db.Where("x.is_sys = 0")
- }
- err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,x.good_type_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.is_sys,x.number,x.dealer,x.manufacturer,x.consumable_type").Offset(offset).Count(&total).Scan(&info).Error
- return info, total, err
- }
-
- func GetStockDrugCount(startime int64, endtime int64, orgid int64) (info []*models.VmWarehouseInfo, err error) {
-
- db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
-
- err = db.Select("sum(x.warehousing_count) as count,sum(x.stock_count) as stock_count,x.good_id").Group("x.good_id").Scan(&info).Error
- return info, err
- }
-
- func GetAutoDiallysisBefor(startime int64, endtime int64, orgid int64) (info []*models.VmWarehouseInfo, err error) {
- db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status = 1")
- if startime > 0 {
- db = db.Where("x.ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
-
- err = db.Select("sum(x.count) as count,x.good_id").Where("is_sys = 0").Group("x.good_id").Scan(&info).Error
- return info, err
- }
-
- func GetOutStockTotalCountFour(startime int64, endtime int64, orgid int64) (autoMatic []*models.NewXtAutomaticReduceDetail, err error) {
-
- if endtime > 0 {
- err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count,x.record_time FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time >= ? and x.record_time <=? and `status` = 1) as b GROUP BY good_id", orgid, startime, endtime).Scan(&autoMatic).Error
- }
- if endtime == 0 {
- err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count,x.record_time FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and `status` = 1) as b GROUP BY good_id", orgid).Scan(&autoMatic).Error
- }
-
- return autoMatic, err
-
- }
-
- func GetGoodWarehouseOutById(id int64, orgid int64) (models.WarehouseOut, error) {
-
- out := models.WarehouseOut{}
- err := XTReadDB().Where("id = ? and org_id = ? and status = 1", id, orgid).Find(&out).Error
- return out, err
- }
-
- func GetOrderDetialByOrderId(id int64, orgid int64) (out []*models.WarehouseOutInfoOne, err error) {
-
- db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
- fmt.Println(table)
- if id > 0 {
- db = db.Where("x.warehouse_out_id = ?", id)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,x.patient_id,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,x.supply_cancel_out_id,x.supply_warehouse_id,x.storehouse_id,x.admin_user_id,x.buy_price,x.stock_count,x.register_number,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id,x.warehouse_info_id").Order("x.ctime desc").Scan(&out).Error
- return out, err
- }
-
- func GetWarehouseOutOrder(id []string, orgid int64) (out []*models.WarehouseOut, err error) {
-
- db := XTReadDB().Table("xt_warehouse_out as x").Where("x.status = 1")
- if len(id) > 0 {
- db = db.Where("x.id in(?)", id)
- }
- if orgid > 0 {
- db = db.Where("x.org_id= ?", orgid)
- }
- err = db.Select("x.id,x.warehouse_out_order_number,x.operation_time,x.creater,x.org_id,x.modifier,x.remark,x.warehouse_out_time,x.dealer,x.manufacturer,x.type").Find(&out).Error
- return out, err
- }
-
- func GetOrderDetialByOrderIdOne(id []string, orgid int64) (out []*models.WarehouseOutInfoOne, err error) {
-
- db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
- tableOne := XTReadDB().Table("xt_warehouse_info as n").Where("n.status = 1")
- fmt.Println(table, tableOne)
- if len(id) > 0 {
- db = db.Where("x.warehouse_out_id in (?)", id)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
-
- err = db.Select("x.id,x.warehouse_out_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,t.social_security_directory_code,x.is_sys,x.sys_record_time,n.number,x.remark,x.license_number,x.storehouse_id,x.admin_user_id,x.buy_price,x.stock_count,x.warehouse_info_id,x.remark,x.patient_id,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit,t.packing_price,x.register_number,x.class_type").Joins("left join xt_warehouse_info as n on n.id=x.warehouse_info_id").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.warehouse_out_id,x.good_id").Order("x.ctime desc").Scan(&out).Error
-
- return out, err
- }
-
- func GetOrderDetailStockFlowByStorehouseById(id []string, orgid int64) (list []*models.VmStockFlow, err error) {
- db := XTReadDB().Model(&list).Where("status = 1 and (consumable_type = 2 or consumable_type = 3 or consumable_type = 15 or consumable_type = 12)")
- if len(id) > 0 {
- db = db.Where("warehouse_out_id in (?)", id)
- }
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- err = db.Group("warehousing_id").Find(&list).Error
- return list, err
- }
-
- func GetOrderDetailStockFlow(id []string, orgid int64) (list []*models.VmStockFlow, err error) {
-
- db := XTReadDB().Model(&list).Where("status = 1 and (consumable_type = 2 or consumable_type = 3 or consumable_type = 15 or consumable_type = 12)")
- if len(id) > 0 {
- db = db.Where("warehouse_out_id in (?)", id)
- }
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&list).Error
- return list, err
- }
-
- func GetOrderStockFlow(id []string, orgid int64) (list []*models.VmStockFlow, err error) {
-
- db := XTReadDB().Model(&list).Where("status = 1 and consumable_type = 7 and patient_id > 0 and count>0")
- if len(id) > 0 {
- db = db.Where("warehouse_out_id in (?)", id)
- }
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- err = db.Preload("WarehousingInfo", "org_id = ? and status = 1", orgid).Find(&list).Error
- return list, err
- }
-
- func GetLastWarehouseOutInfo(ids []string, orgId int64) (info []*models.WarehouseOutInfoSix, err error) {
-
- db := XTReadDB().Model(&info)
- db = db.Preload("GoodInfo", "status = 1")
- err = db.Raw("select * from(SELECT * FROM xt_warehouse_out_info WHERE warehouse_out_id IN(?) AND org_id = ? and status = 1 ORDER BY id DESC LIMIT 1000) a group by good_id", ids, orgId).Find(&info).Error
-
- return info, err
- }
-
- func FindUserDetailByIdOne(good_id int64, record_time int64, org_id int64) (user []*models.AutomaticReduceDetail, err error, total int64) {
- db := readDb.Model(&models.AutomaticReduceDetail{})
- db = db.Preload("GoodInfo", "org_id = ? AND status = 1", org_id)
- db = db.Preload("GoodsType", "status = 1")
- db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
- db = db.Preload("WarehouseOutInfo", "org_id = ? and status = 1 and good_id = ? and sys_record_time = ?", org_id, good_id, record_time)
- db = db.Where("status = 1 AND org_id = ? AND good_id = ? AND record_time = ? and count<> 0 ", org_id, good_id, record_time)
- db = db.Count(&total)
- err = db.Find(&user).Error
-
- return
- }
-
- func GetGoodInformationByGoodId(good_id int64) (models.GoodInfo, error) {
-
- info := models.GoodInfo{}
- err := XTReadDB().Where("id = ? and status = 1", good_id).Find(&info).Error
- return info, err
- }
-
- func GetNewGoodInformationByGoodId(good_id int64, tx *gorm.DB) (models.GoodInfo, error) {
-
- info := models.GoodInfo{}
- err := tx.Where("id = ? and status = 1", good_id).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- return info, err
- }
-
- func GetGoodInformationByGoodIdThirty(good_id int64) (models.GoodInformationThirty, error) {
-
- info := models.GoodInformationThirty{}
- err := XTReadDB().Where("id = ? and status = 1", good_id).Find(&info).Error
- return info, err
- }
-
- func GetNewGoodInformationByGoodIdThirty(good_id int64, tx *gorm.DB) (models.GoodInformationThirty, error) {
-
- info := models.GoodInformationThirty{}
- err := tx.Where("id = ? and status = 1", good_id).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- return info, err
- }
-
- func UpdateGoodInfoList(info models.GoodInfo, id int64) error {
-
- err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"total": info.Total}).Error
- return err
- }
-
- func GetExprotStockList(orgid int64, orderid []string, startime int64, endtime int64) (info []*models.StWarehousingInfo, err error) {
-
- db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
-
- table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
- fmt.Println(table)
-
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if len(orderid) > 0 {
- db = db.Where("x.warehousing_id in(?)", orderid)
- }
- if startime > 0 {
- db = db.Where("x.ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
- err = db.Select("x.id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.dealer,x.manufacturer,x.remark,x.license_number,t.good_name,t.packing_unit,t.specification_name").Joins("left join xt_good_information as t on t.id = x.good_id").Scan(&info).Error
-
- return info, err
- }
-
- func GetExprotStockListTwenty(orgid int64, orderid []string, startime int64, endtime int64, storehouse_id int64) (info []*models.StWarehousingInfo, err error) {
-
- db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
-
- table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
- fmt.Println(table)
-
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if len(orderid) > 0 {
- db = db.Where("x.warehousing_id in(?)", orderid)
- }
- if startime > 0 {
- db = db.Where("x.ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
-
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
-
- err = db.Select("x.id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.dealer,x.manufacturer,x.remark,x.license_number,t.good_name,t.packing_unit,t.specification_name,p.warehousing_time").Joins("left join xt_warehouse as p on p.id =x.warehousing_id").Joins("left join xt_good_information as t on t.id = x.good_id").Scan(&info).Error
-
- return info, err
- }
-
- func GetDrugWarehouOrderInfo(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseOutInfo, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
- fmt.Println(table)
- if startime > 0 {
- db = db.Where("x.ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
-
- err = db.Select("x.drug_id,x.count,x.count_unit,t.max_unit,t.min_unit,t.min_number").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&info).Error
- return info, err
- }
-
- func GetOutExprotList(orgid int64, ids []string, startime int64, endtime int64) (out []*models.WarehouseOutInfoOne, err error) {
-
- db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status =1 ")
- table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
- tableOne := XTReadDB().Table("xt_warehouse_out as p").Where("p.status=1")
- fmt.Println(table, tableOne)
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if orgid > 0 {
- db = db.Where("t.org_id = ?", orgid)
- }
- if orgid > 0 {
- db = db.Where("p.org_id = ?", orgid)
- }
-
- if len(ids) > 0 {
- db = db.Where("x.warehouse_out_id in (?)", ids)
- }
- if startime > 0 {
- db = db.Where("x.ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
-
- err = db.Select("x.id,x.warehouse_out_id,x.good_id,x.good_type_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.remark,x.number,x.license_number,x.warehouse_out_order_number,t.good_name,t.specification_name,t.min_number,t.packing_price,t.min_unit,t.packing_unit,x.manufacturer,x.dealer,p.warehouse_out_time").Joins("left join xt_warehouse_out as p on p.id =x.warehouse_out_id").Joins("left join xt_good_information as t on t.id = x.good_id").Scan(&out).Error
- return out, err
-
- }
-
- func FindeDrugWarehouseOutOrder(ids []string, orgid int64) (info []*models.DrugWarehouseOut, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_out as x").Where("x.status = 1")
- if len(ids) > 0 {
- db = db.Where("x.id in(?)", ids)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
-
- err = db.Select("x.id,x.warehouse_out_order_number,x.operation_time,x.creater,x.org_id,x.modifier,x.remark,x.warehouse_out_time,x.is_sys").Scan(&info).Error
- return info, err
-
- }
-
- func FindeDrugWarehouseOutDetail(ids []string, orgid int64) (info []*models.VmDrugWarehouseOutInfo, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status =1 ")
- table := XTReadDB().Table("x.base_drug as t").Where("t.status = 1")
- fmt.Println(table)
- if len(ids) > 0 {
- db = db.Where("x.warehouse_out_id in(?)", ids)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.count_unit,x.price,x.product_date,x.expiry_date,x.number,x.batch_number,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.drug_name").Joins("left join xt_base_drug as t on t.id =x.drug_id").Scan(&info).Error
- return info, err
- }
-
- func GetDrugNameByKeyword(keyword string, orgid int64) (basedrug []*models.XtBaseDrug, err error) {
-
- db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
- likeKey := "%" + keyword + "%"
- if len(keyword) > 0 {
- db = db.Where("x.drug_name like ?", likeKey)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- err = db.Find(&basedrug).Error
-
- return basedrug, err
-
- }
-
- func GetDrugWarehouseOrderDetail(ids []int64, orgid int64, startime int64, endtime int64, storehouse_id int64) (info []*models.XtDrugWarehouseOutInfo, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
-
- if len(ids) > 0 {
- db = db.Where("x.drug_id in(?)", ids)
- }
-
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("x.ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
-
- err = db.Find(&info).Error
- return info, err
- }
-
- func GetDrugWarehouseOrderDetailTwo(ids []int64, orgid int64, startime int64, endtime int64, storehouse_id int64) (info []*models.XtDrugWarehouseInfo, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
-
- if len(ids) > 0 {
- db = db.Where("x.drug_id in(?)", ids)
- }
-
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("x.ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
-
- if storehouse_id > 0 {
- db = db.Where("storehouse_id = ?", storehouse_id)
- }
-
- err = db.Find(&info).Error
- return info, err
- }
-
- func GetDrugTotalCount(drugid int64, orgid int64, storehouse_id int64) (info models.VmDrugWarehouseInfo, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1 and x.is_check = 1")
- if drugid > 0 {
- db = db.Where("x.drug_id = ?", drugid)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
- err = db.Select("x.drug_id,sum(x.stock_max_number) as count,sum(x.stock_min_number) as stock_min_number,x.max_unit,x.min_unit").Find(&info).Error
- return info, err
- }
-
- func GetDrugTotalCountTwoTwety(drugid int64, orgid int64, storehouse_id int64, tx *gorm.DB) (info models.VmDrugWarehouseInfo, err error) {
-
- db := tx.Table("xt_drug_warehouse_info as x").Where("x.status = 1 and x.is_check = 1")
- if drugid > 0 {
- db = db.Where("x.drug_id = ?", drugid)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
- err = db.Select("x.drug_id,sum(x.stock_max_number) as count,sum(x.stock_min_number) as stock_min_number,x.max_unit,x.min_unit").Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
-
- }
- return info, err
- }
-
- func GetDrugTotalCountTwenty(drugid int64, orgid int64, storehouse_id int64) (info models.VmDrugWarehouseInfo, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1 and x.is_check = 1 ")
- if drugid > 0 {
- db = db.Where("x.drug_id = ?", drugid)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
- err = db.Select("x.drug_id,sum(x.stock_max_number) as count,sum(x.stock_min_number) as stock_min_number,x.max_unit,x.min_unit").Find(&info).Error
- return info, err
- }
-
- func GetDrugTotalCountSwx(id int64, orgid int64) (info models.VmDrugWarehouseInfo, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
- if id > 0 {
- db = db.Where("x.id = ?", id)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- err = db.Select("x.drug_id,sum(x.stock_max_number) as count,sum(x.stock_min_number) as stock_min_number,x.max_unit,x.min_unit").Find(&info).Error
- return info, err
- }
-
- func GetDrugTotalCountOne(drugid int64, orgid int64, id int64) (models.VmDrugWarehouseInfo, error) {
- info := models.VmDrugWarehouseInfo{}
- db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
- if id == 0 {
- db = db.Where("id = ?", id)
- }
- if drugid > 0 {
- db = db.Where("x.drug_id = ?", drugid)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- err = db.Select("x.drug_id,x.stock_max_number,x.stock_min_number,x.max_unit,x.min_unit").Find(&info).Error
- return info, err
- }
-
- func GetDrugTotalCountTwo(drugid int64, storehouse_id int64) (list []*models.VmDrugWarehouseInfo, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_base_drug as d").Where("d.status = 1")
- fmt.Println(table)
- if drugid > 0 {
- db = db.Where("x.drug_id = ?", drugid)
- }
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
- err = db.Select("x.drug_id,x.stock_max_number,x.stock_min_number,d.min_number").Joins("left join xt_base_drug as d on d.id = x.drug_id").Scan(&list).Error
-
- return list, err
- }
-
- func GetDrugByGoodId(drugid int64) (models.BaseDrugLib, error) {
-
- lib := models.BaseDrugLib{}
- err := XTReadDB().Model(&lib).Where("id = ? and status = 1", drugid).Find(&lib).Error
- return lib, err
- }
-
- func GetWarehoureOrderInfoList(goodid int64, orgid int64) (info []*models.WarehousingInfo, err error) {
-
- db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
-
- if goodid > 0 {
- db = db.Where("x.good_id = ?", goodid)
- }
-
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
-
- err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.total_price,x.dealer,x.manufacturer,x.remark,x.is_return,x.warehousing_order,x.warehousing_unit,x.stock_count,x.license_number,x.org_id").Find(&info).Error
- return info, err
- }
-
- func UpdateWarehousingCount(info *models.WarehousingInfo, goodid int64, orgid int64, warehousingId int64) error {
-
- err := XTWriteDB().Model(models.WarehousingInfo{}).Where("good_id = ? and org_id = ? and status = 1 and warehousing_id = ?", goodid, orgid, warehousingId).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
- return err
- }
-
- func GetSingleCancelOrder(id int64, orgid int64) (info []*models.CancelStockInfo, err error) {
-
- err = XTReadDB().Where("cancel_stock_id = ? and status = 1 and org_id = ?", id, orgid).Preload("GoodInfo", "status = 1").Find(&info).Error
- return info, err
- }
-
- func UpdateCancelOut(list []*models.WarehousingInfo, count int64) error {
-
- //遍历循环入库数据
- for i, item := range list {
- //计算每个批次剩余库存与入库数据的差 然后和退库数量比较
- if (item.WarehousingCount - item.StockCount) >= count {
- //如果差距大于退库数量,则直接把退库数量增加到该批次中
- info := models.WarehousingInfo{
- GoodId: item.GoodId,
- OrgId: item.OrgId,
- WarehousingId: item.WarehousingId,
- StockCount: item.StockCount + count,
- }
- err2 := UpdateWarehousingCount(&info, item.GoodId, item.OrgId, item.WarehousingId)
- fmt.Println("2323233232323232323232323232323", err2)
- return err
- }
-
- if (item.WarehousingCount - item.StockCount) < count {
-
- //如果该批次小于退库数量,则先出库该相差数量
- var countOne = item.WarehousingCount - item.StockCount
-
- infoOne := models.WarehousingInfo{
- GoodId: item.GoodId,
- OrgId: item.OrgId,
- WarehousingId: item.WarehousingId,
- StockCount: countOne + item.StockCount,
- }
-
- err := UpdateWarehousingCount(&infoOne, item.GoodId, item.OrgId, item.WarehousingId)
- if err == nil {
- //剩余的出库到第二个批次
- var countTwo = count - countOne
- infos := append(list, list[i+1])
- var idArray []*models.WarehousingInfo
- for _, it := range infos {
- if it.WarehousingId != item.WarehousingId {
- idArray = append(idArray, it)
- }
- }
- //查询更新后的库存
- UpdateCancelOut(idArray, countTwo)
- return err
- } else {
- return err
- }
-
- }
- }
-
- return err
- }
-
- func GetCancelStockOrderPrint(idstr []string) (info []*models.CancelStockInfo, err error) {
-
- if len(idstr) > 0 {
- err = XTReadDB().Model(&info).Where("cancel_stock_id in(?)", idstr).Preload("GoodInfo", "status = 1").Find(&info).Error
- } else {
- err = XTReadDB().Model(&info).Preload("GoodInfo", "status = 1").Find(&info).Error
- }
- return info, err
- }
-
- func GetCancelStockOrderPrintOne(idstr []string, orgid int64) (info []*models.CancelStock, err error) {
-
- if len(idstr) > 0 {
- err = XTReadDB().Model(&info).Where("id in(?)", idstr).
- Preload("XtCancelStockInfo", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Where("org_id=? and status = 1", orgid).Preload("GoodInfo", "status = 1 and org_id = ?", orgid)
- }).Find(&info).Error
- }
- return info, err
- }
-
- func GetCancelOutTotalCount(startime int64, endtime int64, orgid int64) (info []*models.VmCancelStockInfo, err error) {
-
- db := XTReadDB().Table("xt_cancel_stock_info as x").Where("x.status = 1")
-
- if startime > 0 {
- db = db.Where("x.ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime <= ?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- err = db.Select("x.good_id,sum(x.count) as count").Group("x.good_id").Scan(&info).Error
- return info, err
- }
-
- func GetWarehoureOutOrderInfo(goodid int64, orgid int64) (*models.WarehouseOutInfo, error) {
-
- info := models.WarehouseOutInfo{}
- var err error
- err = XTReadDB().Model(&info).Where("good_id = ? and org_id = ? and status = 1", goodid, orgid).Find(&info).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &info, nil
- }
-
- func GetWarehoureOrderInfoCount(goodid int64, orgid int64, id int64) (info models.WarehouseOutInfo, err error) {
-
- db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status =1")
- if goodid > 0 {
- db = db.Where("x.good_id = ?", goodid)
- }
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if id > 0 {
- db = db.Where("x.warehouse_info_id = ?", id)
- }
- err = db.Select("x.good_id,sum(x.count) as count").Scan(&info).Error
- return info, err
- }
-
- func GetWarehoureOrderStockOutFlow(goodid int64, orgid int64, id int64, storehouse_id int64) (info models.VmStockFlow, err error) {
- db := XTReadDB().Table("xt_stock_flow as x").Where("x.status =1 and x.consumable_type = 2 or x.consumable_type = 3")
- if goodid > 0 {
- db = db.Where("x.good_id = ?", goodid)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if id > 0 {
- db = db.Where("x.warehousing_id = ?", id)
- }
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
- err = db.Select("x.good_id,sum(x.count) as count").Scan(&info).Error
- return info, err
- }
-
- func UpdateCancelInfo(id int64) (models.CancelStock, error) {
- stock := models.CancelStock{}
- err := XTWriteDB().Model(&stock).Where("id=? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return stock, err
- }
-
- func GetStockBatchNumber(id int64, orgid int64) (info []*models.WarehousingInfo, err error) {
-
- err = XTReadDB().Model(&info).Where("good_id = ? and org_id = ? and status = 1 and number <> ''", id, orgid).Find(&info).Error
- return info, err
- }
-
- func GetWarehouseOutInfoById(id int64, goodid int64) (info []*models.WarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("warehouse_out_id = ? and good_id = ? and status = 1", id, goodid).Find(&info).Error
- return info, err
- }
-
- func GetStockFlowBatchNumber(id int64, goodid int64) (stock []*models.VmStockFlow, err error) {
-
- err = XTReadDB().Model(&stock).Where("warehouse_out_id = ? and good_id = ? and status = 1", id, goodid).Group("patient_id,number").Find(&stock).Error
- return stock, err
- }
-
- func GetStockFlowBatchNumberOne(id int64, goodid int64) (stock []*models.VmStockFlowOne, err error) {
-
- db := XTReadDB().Table("xt_stock_flow as x").Where("x.status = 1 and x.count > 0 and (x.consumable_type = 3 or x.consumable_type = 2 or x.consumable_type = 15)")
- table := XTReadDB().Table("xt_patients as t").Where("t.status = 1")
- fmt.Println(table)
- tableone := XTReadDB().Table("xt_good_information as o").Where("o.status = 1")
- fmt.Println(tableone)
- if id > 0 {
- db = db.Where("x.warehouse_out_id = ?", id)
- }
- if goodid > 0 {
- db = db.Where("x.good_id = ?", goodid)
- }
-
- err = db.Select("x.id,x.warehousing_id,x.good_id,x.number,x.count,x.patient_id,x.system_time,x.is_sys,x.warehousing_order,x.warehouse_out_id,x.warehouse_out_order_number,x.price,x.product_date,x.expire_date,x.ctime,o.packing_unit,t.name").Joins("left join xt_patients as t on t.id = x.patient_id").Joins("left join xt_good_information as o on o.id = x.good_id").Scan(&stock).Error
- return stock, err
- }
-
- func GetStockFlowCancelInfo(id int64, goodid int64) (stock []*models.VmStockFlowOne, err error) {
- db := XTReadDB().Table("xt_stock_flow as x").Where("x.status = 1 and x.count > 0 and x.consumable_type = 7")
- table := XTReadDB().Table("xt_patients as t").Where("t.status = 1")
- fmt.Println(table)
- tableone := XTReadDB().Table("xt_good_information as o").Where("o.status = 1")
- fmt.Println(tableone)
- if id > 0 {
- db = db.Where("x.warehouse_out_id = ?", id)
- }
- if goodid > 0 {
- db = db.Where("x.good_id = ?", goodid)
- }
-
- err = db.Select("x.id,x.warehousing_id,x.good_id,x.number,x.count,x.patient_id,x.system_time,x.is_sys,x.warehousing_order,x.warehouse_out_id,x.warehouse_out_order_number,x.price,x.product_date,x.expire_date,x.ctime,o.packing_unit,t.name").Joins("left join xt_patients as t on t.id = x.patient_id").Joins("left join xt_good_information as o on o.id = x.good_id").Scan(&stock).Error
- return stock, err
- }
-
- func GetDrugBatchNumber(drug_id int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
-
- err = XTReadDB().Model(&info).Where("drug_id = ? and org_id = ? and status = 1 and batch_number <>''", drug_id, orgid).Find(&info).Error
- return info, err
- }
-
- func ExportDrugList(warehouse_out_id []string, org_id int64) (out []*models.StDrugWarehouseInfo, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status =1 AND x.org_id=?", org_id)
-
- table := XTReadDB().Table("xt_base_drug as b").Where("b.status = 1 and b.org_id = ?", org_id)
-
- tableOne := XTReadDB().Table("xt_drug_warehouse as p").Where("p.status=1 and p.org_id=?", org_id)
- fmt.Println("table", table)
- fmt.Println("tableOne", tableOne)
- if len(warehouse_out_id) > 0 {
- db = db.Where("x.warehousing_id in(?)", warehouse_out_id)
- }
- err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.price,x.dealer,x.manufacturer,x.warehousing_order,x.batch_number,b.dose,b.dose_unit,b.min_number,b.min_unit,b.max_unit,b.drug_name,b.drug_type,p.warehousing_time").Joins("left join xt_drug_warehouse as p on p.id =x.warehousing_id").Joins("left join xt_base_drug as b on b.id = x.drug_id").Scan(&out).Error
- return out, err
- }
-
- func GetExportOutOrderDrugList(warehouse_out_id []string) (out []*models.StDrugWarehouseOutInfo, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_base_drug as b").Where("b.status = 1")
- fmt.Println("table", table)
- if len(warehouse_out_id) > 0 {
- db = db.Where("x.warehouse_out_id in(?)", warehouse_out_id)
- }
- err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.count,x.count_unit,x.price,x.product_date,x.expiry_date,x.warehouse_out_order_number,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.warehouse_info_id,x.number,x.batch_number,x.patient_id,b.dose,b.dose_unit,b.min_number,b.min_unit,b.max_unit,b.drug_name,b.drug_type,b.min_price").Joins("left join xt_base_drug as b on b.id = x.drug_id").Scan(&out).Error
- return out, err
- }
-
- func GetExportOutOrderDrugListOne(warehouse_out_id []string, org_id int64) (out []*models.StDrugWarehouseOutInfo, err error) {
- db := XTReadDB().Table("xt_drug_flow as x").Where("x.status = 1 and x.user_org_id =?", org_id)
- table := XTReadDB().Table("xt_base_drug as b").Where("b.status = 1 and b.org_id = ?", org_id)
- fmt.Println("table", table)
- if len(warehouse_out_id) > 0 {
- db = db.Where("x.warehouse_out_id in(?)", warehouse_out_id)
- }
- err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.count,x.max_unit as count_unit,x.price,x.retail_price,x.product_date,x.expire_date,x.warehouse_out_order_number,x.dealer,x.manufacturer,x.is_sys,x.number,x.batch_number,x.patient_id,x.ctime,x.consumable_type,b.dose,b.dose_unit,b.min_number,b.min_unit,b.max_unit,b.drug_name,b.drug_type,b.min_price").Joins("left join xt_base_drug as b on b.id = x.drug_id").Scan(&out).Error
- return out, err
- }
-
- func GetDrugOutListFlow(warehouse_out_id []string, orgid int64) (info []*models.XtDrugWarehouseOutInfo, err error) {
-
- db := XTReadDB().Model(&info).Where("status = 1")
- if len(warehouse_out_id) > 0 {
- db = db.Where("warehouse_out_id in(?)", warehouse_out_id)
- }
- if orgid > 0 {
- db = db.Where("org_id = ?", orgid)
- }
- err = db.Find(&info).Error
- return info, err
- }
-
- func GetDrugWarehouseOut(warehouse_out_id []string) (out []*models.StDrugWarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("warehouse_out_id in(?)", warehouse_out_id).Find(&out).Error
- return out, err
- }
-
- func GetDrugWarehouseOutTenty(warehouse_out_id []string, orgid int64) (out []*models.DrugWarehouseOutTwenty, err error) {
-
- err = XTReadDB().Where("id in(?)", warehouse_out_id).Preload("DrugWarehouseOutInfoTenty", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Where("org_id=? and status = 1", orgid).Preload("BaseDrugLib", "status = 1 and org_id = ?", orgid).Preload("DrugWarehouseInfo", "status = 1 and org_id = ?", orgid)
- }).Find(&out).Error
-
- return out, err
- }
-
- func GetLastGoodInformationByGoodId(goodid int64, warehouse_info_id int64, orgid_id int64) (models.WarehouseOutInfo, error) {
-
- info := models.WarehouseOutInfo{}
- err := XTReadDB().Where("good_id = ? and warehouse_info_id= ? and status =1", goodid, warehouse_info_id).Last(&info).Error
- return info, err
- }
-
- func GetTotalCountByGoodId(goodid int64, storehouse_id int64) (models.WarehousingInfo, error) {
-
- info := models.WarehousingInfo{}
-
- db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
- if goodid > 0 {
- db = db.Where("x.good_id = ?", goodid)
- }
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
-
- err := db.Select("x.good_id,sum(x.stock_count) as stock_count").Scan(&info).Error
- return info, err
- }
-
- func GetLastGoodCountById(goodid int64, warehouse_info_id int64) (models.WarehousingInfo, error) {
-
- info := models.WarehousingInfo{}
-
- err := XTReadDB().Where("good_id = ? and id= ? and status = 1", goodid, warehouse_info_id).First(&info).Error
- return info, err
- }
-
- func UpdateWarehousingInfo(info models.WarehousingInfo, id int64) error {
-
- err = XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
- return err
- }
-
- func FindFirstWarehousingInfoByGoodId(good_id int64, id int64, storehouse_id int64) (info models.WarehousingInfo, err error) {
- if storehouse_id == 0 {
- err = readDb.Where("good_id = ? AND status = 1 and stock_count > 0", good_id).Order("ctime asc").First(&info).Error
- }
- if storehouse_id > 0 {
- err = readDb.Where("good_id = ? AND status = 1 and stock_count > 0 and storehouse_id=?", good_id, storehouse_id).Order("ctime asc").First(&info).Error
- }
- return info, err
- }
-
- func CreateStockFlow(warehousingInfo []*models.VmStockFlow) (err error) {
- if len(warehousingInfo) > 0 {
- utx := writeDb.Begin()
- if len(warehousingInfo) > 0 {
- thisSQL := "INSERT INTO xt_stock_flow (warehousing_id, good_id, number, license_number, count,user_org_id,patient_id,system_time,consumable_type,is_sys,warehousing_order,warehouse_out_id,warehouse_out_order_number,is_edit,cancel_stock_id,cancel_order_number,manufacturer,dealer,creator,update_creator,status,ctime,mtime,price,warehousing_detail_id,warehouse_out_detail_id,cancel_out_detail_id,expire_date,product_date) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, info := range warehousingInfo {
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
- insertData = append(insertData, info.WarehousingId)
- insertData = append(insertData, info.GoodId)
- insertData = append(insertData, info.Number)
- insertData = append(insertData, info.LicenseNumber)
- insertData = append(insertData, info.Count)
- insertData = append(insertData, info.UserOrgId)
- insertData = append(insertData, info.PatientId)
- insertData = append(insertData, info.SystemTime)
- insertData = append(insertData, info.ConsumableType)
- insertData = append(insertData, info.IsSys)
- insertData = append(insertData, info.WarehousingOrder)
- insertData = append(insertData, info.WarehouseOutId)
- insertData = append(insertData, info.WarehouseOutOrderNumber)
- insertData = append(insertData, info.IsEdit)
- insertData = append(insertData, info.CancelStockId)
- insertData = append(insertData, info.CancelOrderNumber)
- insertData = append(insertData, info.Manufacturer)
- insertData = append(insertData, info.Dealer)
- insertData = append(insertData, info.Creator)
- insertData = append(insertData, info.UpdateCreator)
- insertData = append(insertData, info.Status)
- insertData = append(insertData, info.Ctime)
- insertData = append(insertData, info.Mtime)
- insertData = append(insertData, info.Price)
- insertData = append(insertData, info.WarehousingDetailId)
- insertData = append(insertData, info.WarehouseOutDetailId)
- insertData = append(insertData, info.CancelOutDetailId)
- insertData = append(insertData, info.ExpireDate)
- insertData = append(insertData, info.ProductDate)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- }
- return
-
- }
-
- func CreateStockFlowOne(flow models.VmStockFlow) error {
- utx := XTWriteDB().Begin()
- err := utx.Create(&flow).Error
- if err != nil {
- utx.Rollback()
- return err
- }
- utx.Commit()
- return err
- }
-
- func CreateNewStockFlowOne(flow models.VmStockFlow, tx *gorm.DB) error {
-
- err := tx.Create(&flow).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func CreateStockFlowSix(flow *models.VmStockFlow) error {
-
- err := XTWriteDB().Create(&flow).Error
- return err
- }
-
- func UpdatedStockFlow(flow models.VmStockFlow) error {
- err := XTWriteDB().Save(&flow).Error
- return err
- }
-
- func UpdatedStockFlowOne(flow models.VmStockFlow, warehousing_id int64, patient_id int64, record_time int64, good_id int64) error {
-
- err = XTWriteDB().Model(&flow).Where("warehousing_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", warehousing_id, patient_id, record_time, good_id).Updates(map[string]interface{}{"number": flow.Number, "license_number": flow.LicenseNumber, "count": flow.Count, "expire_date": flow.ExpireDate, "product_date": flow.ProductDate, "price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer, "over_count": flow.OverCount}).Error
- return err
- }
-
- func UpdatedStockFlowFive(flow models.VmStockFlow, warehouse_out_id int64, patient_id int64, record_time int64, good_id int64) error {
-
- err = XTWriteDB().Model(&flow).Where("warehouse_out_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", warehouse_out_id, patient_id, record_time, good_id).Updates(map[string]interface{}{"number": flow.Number, "license_number": flow.LicenseNumber, "count": flow.Count, "expire_date": flow.ExpireDate, "product_date": flow.ProductDate, "price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer, "over_count": flow.OverCount}).Error
- return err
- }
-
- func GetStockFlowIsExsit(warehousing_id int64, patient_id int64, record_time int64, good_id int64) (*models.VmStockFlow, error) {
-
- stock := models.VmStockFlow{}
- var err error
- err = XTReadDB().Model(&stock).Where("warehousing_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1 and is_read = 0", warehousing_id, patient_id, record_time, good_id).Find(&stock).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &stock, nil
- }
-
- func GetStockFlowIsBatchNumber(warehousing_id int64, patient_id int64, record_time int64, good_id int64) (flow []*models.VmStockFlow, err error) {
-
- err = XTReadDB().Where("patient_id = ? and system_time = ? and good_id = ? and status = 1 and consumable_type = 3", patient_id, record_time, good_id).Find(&flow).Error
- return flow, nil
- }
-
- func GetStockFlowIsBatchNumberSix(patient_id int64, record_time int64, good_id int64, project_id int64) (flow []*models.VmStockFlow, err error) {
-
- err = XTReadDB().Where("patient_id = ? and system_time = ? and good_id = ? and status = 1 and consumable_type = 3 and project_id = ?", patient_id, record_time, good_id, project_id).Find(&flow).Error
- return flow, nil
- }
-
- func GetNewStockFlowIsBatchNumberSix(patient_id int64, record_time int64, good_id int64, project_id int64, tx *gorm.DB) (flow []*models.VmStockFlow, err error) {
-
- err = tx.Where("patient_id = ? and system_time = ? and good_id = ? and status = 1 and consumable_type = 3 and project_id = ?", patient_id, record_time, good_id, project_id).Find(&flow).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return flow, nil
- }
- }
- return flow, nil
- }
-
- func GetStockFlowIsBatchNumberSixty(patient_id int64, record_time int64, good_id int64, project_id int64) (flow []*models.WarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("patient_id = ? and sys_record_time = ? and good_id = ? and status = 1 and project_id = ?", patient_id, record_time, good_id, project_id).Find(&flow).Error
- return flow, nil
- }
-
- func GetNewStockFlowIsBatchNumberSixty(patient_id int64, record_time int64, good_id int64, project_id int64, tx *gorm.DB) (flow []*models.WarehouseOutInfo, err error) {
-
- err = tx.Where("patient_id = ? and sys_record_time = ? and good_id = ? and status = 1 and project_id = ?", patient_id, record_time, good_id, project_id).Find(&flow).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return flow, nil
- }
- }
- return flow, nil
- }
-
- func GetStockFlowIsBatchNumberSeventy(patient_id int64, record_time int64, good_id int64, project_id int64) (flow []*models.AutomaticReduceDetail, err error) {
-
- err = XTReadDB().Where("patient_id = ? and record_time = ? and good_id = ? and status = 1 and project_id = ?", patient_id, record_time, good_id, project_id).Find(&flow).Error
- return flow, nil
- }
-
- func GetNewStockFlowIsBatchNumberSeventy(patient_id int64, record_time int64, good_id int64, project_id int64, tx *gorm.DB) (flow []*models.AutomaticReduceDetail, err error) {
-
- err = tx.Where("patient_id = ? and record_time = ? and good_id = ? and status = 1 and project_id = ?", patient_id, record_time, good_id, project_id).Find(&flow).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return flow, err
- }
- }
- return flow, err
- }
-
- func GetStockFlowIsBatchNumberTwo(patient_id int64, record_time int64, good_id int64) (flow []*models.WarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("patient_id = ? and sys_record_time = ? and good_id = ? and status = 1 ", patient_id, record_time, good_id).Find(&flow).Error
- return flow, nil
- }
-
- func GetStockFlowIsBatchNumberThree(patient_id int64, record_time int64, good_id int64) (flow []*models.VmStockFlow, err error) {
-
- err = XTReadDB().Where("patient_id = ? and system_time = ? and good_id = ? and status = 1 and consumable_type =7", patient_id, record_time, good_id).Find(&flow).Error
- return flow, nil
- }
-
- func GetStockFlowIsBatchNumberFour(patient_id int64, record_time int64, good_id int64, project_id int64) (flow []*models.VmStockFlow, err error) {
-
- err = XTReadDB().Where("patient_id = ? and system_time = ? and good_id = ? and status = 1 and consumable_type =7 and project_id = ?", patient_id, record_time, good_id, project_id).Find(&flow).Error
- return flow, nil
- }
-
- func GetNewStockFlowIsBatchNumberFour(patient_id int64, record_time int64, good_id int64, project_id int64, tx *gorm.DB) (flow []*models.VmStockFlow, err error) {
-
- err = tx.Where("patient_id = ? and system_time = ? and good_id = ? and status = 1 and consumable_type =7 and project_id = ?", patient_id, record_time, good_id, project_id).Find(&flow).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return flow, nil
- }
-
- }
- return flow, nil
- }
-
- func GetStockFlowIsBatchNumberFourty(patient_id int64, record_time int64, good_id int64, project_id int64) (flow []*models.VmStockFlow, err error) {
-
- err = XTReadDB().Where("patient_id = ? and system_time = ? and good_id = ? and status = 1 and consumable_type =7 and project_id = ?", patient_id, record_time, good_id, project_id).Find(&flow).Error
- return flow, nil
- }
-
- func GetWarehouseOutInfoIsExist(id int64) (*models.WarehouseOutInfo, error) {
-
- info := models.WarehouseOutInfo{}
- var err error
- err = XTReadDB().Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &info, nil
- }
-
- func GetWarehouseOutInfoIsExistOne(good_id int64, patient_id int64, record_time int64, project_id int64) (*models.WarehouseOutInfo, error) {
-
- info := models.WarehouseOutInfo{}
- var err error
- err = XTReadDB().Model(&info).Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ? and is_sys=1", good_id, record_time, patient_id).Find(&info).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &info, nil
- }
-
- func GetWarehouseOutInfoIsExistTwo(good_id int64, patient_id int64, record_time int64, project_id int64) (models.WarehouseOutInfo, error) {
- info := models.WarehouseOutInfo{}
- err := XTReadDB().Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ? and is_sys=1", good_id, record_time, patient_id).Find(&info).Error
- return info, err
- }
-
- func GetStockFlowList(limit int64, page int64, consumable_type int64, orgId int64, startTime int64, endTime int64, good_id int64) (flow []*models.VmStockFlow, total int64, err error) {
-
- offset := (page - 1) * limit
- db := XTReadDB().Model(&flow).Where("status = 1 and count > 0")
- if consumable_type > 0 {
- //入库
- if consumable_type == 1 {
- db = db.Where("consumable_type = ?", consumable_type)
- }
- //2 手动出库
- if consumable_type == 2 {
-
- db = db.Where(" consumable_type = ? and is_sys = 0", consumable_type)
- }
-
- //3.自动出库
- if consumable_type == 3 {
- db = db.Where(" consumable_type = ? and is_sys = 1", consumable_type)
- }
-
- //4.手动退库
- if consumable_type == 4 {
- db = db.Where(" consumable_type = ?", consumable_type)
- }
- //自动退库
- if consumable_type == 7 {
- db = db.Where(" consumable_type = ?", consumable_type)
- }
-
- if consumable_type == 10 {
- db = db.Where(" consumable_type = ?", consumable_type)
- }
- if consumable_type == 11 {
- db = db.Where(" consumable_type = ?", consumable_type)
- }
-
- if consumable_type == 12 {
- db = db.Where(" consumable_type = ?", consumable_type)
- }
-
- if consumable_type == 13 {
- db = db.Where(" consumable_type = ?", consumable_type)
- }
- if consumable_type == 15 {
- db = db.Where(" consumable_type = ?", consumable_type)
- }
- }
- if orgId > 0 {
- db = db.Where("user_org_id = ?", orgId)
- }
-
- if startTime > 0 {
- db = db.Where("ctime >= ?", startTime)
- }
-
- if endTime > 0 {
- db = db.Where("ctime<=?", endTime)
- }
-
- if good_id > 0 {
- db = db.Where("good_id = ?", good_id)
- }
-
- err = db.Count(&total).Offset(offset).Limit(limit).Order("id desc").Find(&flow).Error
-
- return flow, total, err
- }
-
- func GetLastGoodListByPatientId(recordtime int64, patientid int64, goodid int64, goodtypeid int64) (models.AutomaticReduceDetail, error) {
-
- detail := models.AutomaticReduceDetail{}
-
- err := XTReadDB().Model(&detail).Where("record_time = ? and patient_id = ? and good_id = ? and good_type_id = ? and status = 1", recordtime, patientid, goodid, goodtypeid).Last(&detail).Error
- return detail, err
- }
-
- func GetLastGoodListByPatientIdOne(recordtime int64, patientid int64, goodid int64, goodtypeid int64) (models.WarehouseOutInfo, error) {
-
- detail := models.WarehouseOutInfo{}
-
- err := XTReadDB().Model(&detail).Where("sys_record_time = ? and patient_id = ? and good_id = ? and good_type_id = ? and status = 1", recordtime, patientid, goodid, goodtypeid).Last(&detail).Error
- return detail, err
- }
-
- func UpdatedWarehouseOutInfo(info *models.WarehouseOutInfo, good_id int64, patient_id int64, record_time int64, project_id int64) error {
-
- outInfo := models.WarehouseOutInfo{}
- err := XTWriteDB().Model(&outInfo).Where("good_id = ? and patient_id = ? and sys_record_time =? and status = 1", good_id, patient_id, record_time).Updates(map[string]interface{}{"warehouse_out_id": info.WarehouseOutId, "WarehouseOutOrderNumber": info.WarehouseOutOrderNumber, "sys_record_time": info.SysRecordTime, "good_type_id": info.GoodTypeId, "patient_id": info.PatientId, "consumable_type": info.ConsumableType, "count": info.Count, "price": info.Price, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "number": info.Number, "license_number": info.LicenseNumber, "over_count": info.OverCount}).Error
- return err
- }
-
- func UpdatedNewWarehouseOutInfo(info *models.WarehouseOutInfo, good_id int64, patient_id int64, record_time int64, project_id int64, tx *gorm.DB) error {
-
- outInfo := models.WarehouseOutInfo{}
- err := tx.Model(&outInfo).Where("good_id = ? and patient_id = ? and sys_record_time =? and status = 1", good_id, patient_id, record_time).Updates(map[string]interface{}{"warehouse_out_id": info.WarehouseOutId, "WarehouseOutOrderNumber": info.WarehouseOutOrderNumber, "sys_record_time": info.SysRecordTime, "good_type_id": info.GoodTypeId, "patient_id": info.PatientId, "consumable_type": info.ConsumableType, "count": info.Count, "price": info.Price, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "number": info.Number, "license_number": info.LicenseNumber, "over_count": info.OverCount}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpdatedWarehouseOutInfoSix(info *models.WarehouseOutInfo, good_id int64, patient_id int64, record_time int64, project_id int64, warehouse_info_id int64) error {
-
- outInfo := models.WarehouseOutInfo{}
- err := XTWriteDB().Model(&outInfo).Where("good_id = ? and patient_id = ? and sys_record_time =? and status = 1 and project_id = ? and warehouse_info_id =? ", good_id, patient_id, record_time, project_id, warehouse_info_id).Updates(map[string]interface{}{"warehouse_out_id": info.WarehouseOutId, "WarehouseOutOrderNumber": info.WarehouseOutOrderNumber, "sys_record_time": info.SysRecordTime, "good_type_id": info.GoodTypeId, "patient_id": info.PatientId, "consumable_type": info.ConsumableType, "count": info.Count, "price": info.Price, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "number": info.Number, "license_number": info.LicenseNumber, "over_count": info.OverCount}).Error
- return err
- }
-
- func UpdatedNewWarehouseOutInfoSix(info *models.WarehouseOutInfo, good_id int64, patient_id int64, record_time int64, project_id int64, warehouse_info_id int64, tx *gorm.DB) error {
-
- outInfo := models.WarehouseOutInfo{}
- err := tx.Model(&outInfo).Where("good_id = ? and patient_id = ? and sys_record_time =? and status = 1 and project_id = ? and warehouse_info_id =? ", good_id, patient_id, record_time, project_id, warehouse_info_id).Updates(map[string]interface{}{"warehouse_out_id": info.WarehouseOutId, "WarehouseOutOrderNumber": info.WarehouseOutOrderNumber, "sys_record_time": info.SysRecordTime, "good_type_id": info.GoodTypeId, "patient_id": info.PatientId, "consumable_type": info.ConsumableType, "count": info.Count, "price": info.Price, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "number": info.Number, "license_number": info.LicenseNumber, "over_count": info.OverCount}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func GetLastWarehouOutInfoByPatientId(orgid int64, patient_id int64, record_time int64, goodid int64, good_type_id int64) (models.WarehouseOutInfo, error) {
-
- info := models.WarehouseOutInfo{}
-
- err = XTReadDB().Model(&info).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and good_type_id = ? and status = 1", orgid, patient_id, record_time, goodid, good_type_id).Last(&info).Error
- return info, err
- }
-
- func GetLastStockOut(id int64) (models.WarehousingInfo, error) {
-
- info := models.WarehousingInfo{}
-
- err := XTReadDB().Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
- return info, err
- }
-
- func GetStockGoodCount(good_id int64) (models.WarehousingInfo, error) {
- info := models.WarehousingInfo{}
- db := XTReadDB().Model(&info)
- if good_id > 0 {
- db = db.Where("good_id = ? and status = 1", good_id)
- }
- err := db.Select("sum(stock_count) as stock_count").Find(&info).Error
- return info, err
- }
-
- func GetDrugFlow(drugid int64, orgid int64, limit int64, page int64, startTime int64, endTime int64, stock_type int64) (drug_flow []*models.DrugFlow, total int64, err error) {
-
- offset := (page - 1) * limit
- db := XTReadDB().Model(drug_flow).Where("status = 1")
- if drugid > 0 {
- db = db.Where("drug_id = ?", drugid)
- }
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
- if startTime > 0 {
- db = db.Where("ctime >=? ", startTime)
- }
- if endTime > 0 {
- db = db.Where("ctime<=?", endTime)
- }
- if stock_type > 0 {
-
- //手动入库
- if stock_type == 1 {
- db = db.Where("consumable_type = 1")
- }
-
- //手动出库
- if stock_type == 2 {
- db = db.Where("consumable_type = 2 and is_sys = 0")
- }
-
- //自动出库
- if stock_type == 3 {
- db = db.Where("consumable_type = 3 and is_sys = 1")
- }
- if stock_type == 4 {
- db = db.Where("consumable_type = 4")
- }
- if stock_type == 10 {
- db = db.Where("consumable_type = 10")
- }
- if stock_type == 11 {
- db = db.Where("consumable_type = 11")
- }
-
- if stock_type == 12 {
- db = db.Where("consumable_type = 12")
- }
-
- if stock_type == 13 {
- db = db.Where("consumable_type = 13")
- }
-
- if stock_type == 15 {
- db = db.Where("consumable_type = 15")
- }
-
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Order("id desc").Preload("BaseDrugLib", "status = 1").Preload("DrugWarehouseInfo", "status = 1").Preload("XtDrugWarehouseOutInfo", "status = 1").Find(&drug_flow).Error
- return drug_flow, total, err
- }
-
- func GetDrugWarehouseOutInfoIsExit(drug_id int64, patient_id int64, recordtime int64) (*models.DrugWarehouseOutInfo, error) {
-
- outInfo := models.DrugWarehouseOutInfo{}
- var err error
- err = XTReadDB().Model(&outInfo).Where("drug_id = ? and patient_id = ? and status = 1 and sys_record_time = ?", drug_id, patient_id, recordtime).Find(&outInfo).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &outInfo, nil
- }
-
- func GetDrugWarehouseOutInfoIsExitOne(drug_id int64, patient_id int64, recordtime int64) (outInfo []*models.DrugWarehouseOutInfo, err error) {
-
- err = XTReadDB().Model(&outInfo).Where("drug_id = ? and patient_id = ? and status = 1 and sys_record_time = ?", drug_id, patient_id, recordtime).Find(&outInfo).Error
-
- return outInfo, err
- }
-
- func UpdatedDrugWarehouseOutInfo(info *models.DrugWarehouseOutInfo, drug_id int64, patient_id int64, record_date int64, orgid int64) error {
-
- outInfo := models.DrugWarehouseOutInfo{}
-
- err := XTWriteDB().Model(&outInfo).Where("drug_id = ? and patient_id = ? and sys_record_time = ? and org_id = ?", drug_id, patient_id, record_date, orgid).Updates(map[string]interface{}{"warehouse_out_id": info.WarehouseOutId, "drug_id": info.DrugId, "count": info.Count, "count_unit": info.CountUnit, "price": info.Price, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "mtime": info.Mtime, "ctime": info.Ctime, "org_id": info.OrgId, "warehouse_out_order_number": info.WarehouseOutOrderNumber, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "is_sys": info.IsSys, "sys_record_time": info.SysRecordTime, "warehouse_info_id": info.WarehouseInfoId, "number": info.Number, "batch_number": info.BatchNumber, "patient_id": info.PatientId}).Error
-
- return err
- }
-
- func GetCancelExportList(startime int64, endtime int64, ids []string, orgid int64) (cancle []*models.CancelStockInfo, err error) {
-
- db := XTReadDB().Model(&cancle).Where("status = 1")
- if startime > 0 {
- db = db.Where("ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("ctime <=?", endtime)
- }
- if len(ids) > 0 {
- db = db.Where("cancel_stock_id in(?)", ids)
- }
- if orgid > 0 {
- db = db.Where("org_id = ?", orgid)
- }
- db = db.Preload("GoodInfo", "status =1 and org_id = ?", orgid)
- err = db.Find(&cancle).Error
- return cancle, err
- }
-
- func GetCancelStockDetail(id int64) (info []*models.DrugCancelStockInfo, err error) {
-
- db := XTReadDB().Model(&info)
- if id > 0 {
- db = db.Where("cancel_stock_id = ? and status = 1", id)
- }
- db = db.Preload("BaseDrugLib")
- err = db.Find(&info).Error
- return info, err
- }
-
- func GetDrugWarehouseInfo(id int64) (models.XtDrugWarehouseInfo, error) {
-
- info := models.XtDrugWarehouseInfo{}
-
- db := XTReadDB().Model(&info).Where("status = 1")
- if id > 0 {
- db = db.Where("id = ?", id)
- }
- err := db.Select("drug_id,warehousing_count,stock_max_number,stock_min_number").Find(&info).Error
-
- return info, err
- }
-
- func GetDrugWarehouseInfoOne(id int64) (models.XtDrugWarehouseInfo, error) {
-
- info := models.XtDrugWarehouseInfo{}
-
- err := XTReadDB().Where("status = 1 and id=?", id).Find(&info).Error
-
- return info, err
- }
-
- //func GetDrugWarehouseInfoTX(id int64,tx *gorm.DB) (models.XtDrugWarehouseInfo, error) {
- // info := models.XtDrugWarehouseInfo{}
- // db := tx.Model(&info).Where("status = 1")
- // if id > 0 {
- // db = db.Where("id = ?", id)
- // }
- // err := db.Select("drug_id,warehousing_count,stock_max_number,stock_min_number").Find(&info).Error
- // return info, err
- //}
-
- func GetDrugWarehouseInfoPrescription(drugid int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
-
- err = XTReadDB().Where("drug_id = ? and org_id =? and status = 1", drugid, orgid).Find(&info).Error
- return info, err
- }
-
- func GetDrugWarehouseInfoPrescriptionSeven(drugid int64, orgid int64, storehouse_id int64) (info []*models.DrugWarehouseInfoSeven, err error) {
-
- err = XTReadDB().Select("id,stock_max_number,stock_min_number").Where("drug_id = ? and org_id =? and status = 1 and storehouse_id = ? and is_check = 1", drugid, orgid, storehouse_id).Find(&info).Error
- return info, err
- }
-
- func GetHisAdviceListByDrugId(drugid int64, patient_id int64, advice_date int64) (models.HisDoctorAdviceInfo, error) {
-
- info := models.HisDoctorAdviceInfo{}
- err := XTReadDB().Model(&info).Where("drug_id = ? and patient_id = ? and advice_date = ? and status = 1", drugid, patient_id, advice_date).Find(&info).Error
- return info, err
- }
-
- func GetHisAdviceListByDrugIdTwo(patient_id int64, advice_date int64, orgid int64) (info []*models.HisDoctorAdviceInfo, err error) {
-
- err = XTReadDB().Where("patient_id = ? and advice_date = ? and status = 1 and user_org_id = ?", patient_id, advice_date, orgid).Find(&info).Error
- return info, err
- }
-
- func GetNewHisAdviceListByDrugIdTwo(patient_id int64, advice_date int64, orgid int64, tx *gorm.DB) (info []*models.HisDoctorAdviceInfo, err error) {
-
- err = tx.Where("patient_id = ? and advice_date = ? and status = 1 and user_org_id = ?", patient_id, advice_date, orgid).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
-
- return info, err
- }
-
- func GetLastHisAdvicesList(patient_id int64, advice_date int64, user_org_id int64, tx *gorm.DB) (models.HisDoctorAdviceInfo, error) {
-
- adviceInfo := models.HisDoctorAdviceInfo{}
- err := tx.Where("patient_id = ? and advice_date= ? and user_org_id = ? and status=1", patient_id, advice_date, user_org_id).Last(&adviceInfo).Error
-
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return adviceInfo, err
- }
- }
- return adviceInfo, err
- }
-
- func GetHisAdviceListByDrugIdEight(drugid int64, patient_id int64, advice_date int64, advice_id int64) (models.HisDoctorAdviceInfo, error) {
-
- info := models.HisDoctorAdviceInfo{}
- err := XTReadDB().Model(&info).Where("drug_id = ? and patient_id = ? and advice_date = ? and status = 1 and id =?", drugid, patient_id, advice_date, advice_id).First(&info).Error
- return info, err
- }
-
- func GetHisAdviceListByDrugIdNight(drugid int64, patient_id int64, advice_date int64, advice_id int64) (models.HisDoctorAdviceInfo, error) {
-
- info := models.HisDoctorAdviceInfo{}
- err := XTReadDB().Model(&info).Where("drug_id = ? and patient_id = ? and advice_date = ? and status = 1 and id =?", drugid, patient_id, advice_date, advice_id).Find(&info).Error
- return info, err
- }
-
- func GetLastDrugWarehouseOutByDrugId(drugid int64, patient_id int64, advice_date int64, advice_id int64) (models.DrugAutomaticReduceDetail, error) {
- detail := models.DrugAutomaticReduceDetail{}
- err := XTReadDB().Model(&detail).Where("drug_id = ? and patient_id = ? and record_time = ? and status = 1 and advice_id = ?", drugid, patient_id, advice_date, advice_id).Last(&detail).Error
- return detail, err
- }
-
- func GetWarehouseOutListExport(drug_id int64, patient_id int64, record_date int64, advice_id int64) (out []*models.XtDrugWarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("drug_id = ? and patient_id = ? and sys_record_time = ? and advice_id =? and status =1", drug_id, patient_id, record_date, advice_id).Find(&out).Error
-
- return out, err
- }
-
- func GetLastDrugWarehouseOutByDrugIdTwenty(drugid int64, patient_id int64, advice_date int64, advice_id int64) (out []*models.DrugWarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("advice_id = ? and drug_id = ? and patient_id = ? and sys_record_time = ? and status = 1 and is_check = 1", advice_id, drugid, patient_id, advice_date).Find(&out).Error
- return out, err
- }
-
- func GetLastNewDrugWarehouseOutByDrugIdTwenty(drugid int64, patient_id int64, advice_date int64, advice_id int64, tx *gorm.DB) (out []*models.DrugWarehouseOutInfo, err error) {
-
- err = tx.Where("advice_id = ? and drug_id = ? and patient_id = ? and sys_record_time = ? and status = 1 and is_check = 1", advice_id, drugid, patient_id, advice_date).Find(&out).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return out, err
- }
- }
-
- return out, err
- }
-
- func ModefyDrugByWarehouseInfo(id int64, stock_max_number int64) error {
-
- err := XTWriteDB().Model(models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", stock_max_number)).Error
- return err
- }
-
- func ModefyDrugByWarehouseInfoOne(id int64, stock_min_number int64) error {
-
- err := XTWriteDB().Model(models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", stock_min_number)).Error
- return err
- }
-
- func DeleteDrugAutoWarehouse(drugid int64, patient_id int64, record_time int64) error {
-
- err := XTWriteDB().Model(models.DrugAutomaticReduceDetail{}).Where("drug_id = ? and patient_id = ? and record_time = ? and status = 1", drugid, patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
- err = XTWriteDB().Model(models.DrugWarehouseOutInfo{}).Where("drug_id = ? and patient_id = ? and sys_record_time = ? and status = 1", drugid, patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
- err = XTWriteDB().Model(models.DrugFlow{}).Where("drug_id = ? and patient_id = ? and system_time = ? and status = 1", drugid, patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func DeleteDrugAutoWarehouseSeven(drugid int64, patient_id int64, record_time int64, advice_id int64) error {
-
- err := XTWriteDB().Model(models.DrugAutomaticReduceDetail{}).Where("drug_id = ? and patient_id = ? and record_time = ? and status = 1 and advice_id = ?", drugid, patient_id, record_time, advice_id).Updates(map[string]interface{}{"status": 0}).Error
- err = XTWriteDB().Model(models.DrugFlow{}).Where("drug_id = ? and patient_id = ? and system_time = ? and status = 1 and advice_id = ?", drugid, patient_id, record_time, advice_id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func DeleteNewDrugAutoWarehouseSeven(drugid int64, patient_id int64, record_time int64, advice_id int64) error {
-
- err := XTWriteDB().Model(models.DrugAutomaticReduceDetail{}).Where("drug_id = ? and patient_id = ? and record_time = ? and status = 1", drugid, patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
- err = XTWriteDB().Model(models.DrugFlow{}).Where("drug_id = ? and patient_id = ? and system_time = ? and status = 1 and advice_id = ?", drugid, patient_id, record_time, advice_id).Updates(map[string]interface{}{"status": 0}).Error
-
- return err
- }
-
- func GetDrugWarehouseInfoById(id int64) (models.XtDrugWarehouseInfo, error) {
-
- info := models.XtDrugWarehouseInfo{}
- err := XTReadDB().Model(&info).Where("id=? and status =1", id).Find(&info).Error
- return info, err
- }
-
- func GetDrugWarehouseInfoByIdTwenty(id int64) (models.XtDrugWarehouseInfo, error) {
-
- info := models.XtDrugWarehouseInfo{}
- err := XTReadDB().Model(&info).Where("id=?", id).Find(&info).Error
- return info, err
- }
-
- func UpdateDrugWarehouseInfo(info *models.XtDrugWarehouseInfo, id int64) error {
-
- err = writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", info.StockMaxNumber)).Error
- return err
- }
-
- //func UpdateDrugWarehouseInfoTX(info *models.XtDrugWarehouseInfo, id int64,tx *gorm.DB) error {
- // err = tx.Model(&models.XtDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", info.StockMaxNumber)).Error
- // return err
- //}
-
- func UpdateDrugWarehouseInfoOne(info *models.XtDrugWarehouseInfo, id int64) error {
-
- //err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_min_number": info.StockMaxNumber}).Error
- //return err
-
- err = writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", info.StockMinNumber)).Error
- return err
- }
-
- //func UpdateDrugWarehouseInfoOneTX(info *models.XtDrugWarehouseInfo, id int64,tx *gorm.DB) error {
- // err = tx.Model(&models.XtDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", info.StockMinNumber)).Error
- // return err
- //}
-
- func GetLastCancelStockInfo(id int64) (models.DrugCancelStockInfo, error) {
-
- info := models.DrugCancelStockInfo{}
-
- err := XTReadDB().Where("id = ? and status = 1", id).Find(&info).Error
- return info, err
- }
-
- func GetLastCancelStockInfoOne(id int64, drug_id int64) (models.DrugCancelStockInfo, error) {
-
- info := models.DrugCancelStockInfo{}
-
- err := XTReadDB().Where("cancel_stock_id = ? and drug_id = ? and status = 1", id, drug_id).Find(&info).Error
- return info, err
- }
-
- func UpdatedDrugInfo(id int64, count int64) (err error) {
-
- err = XTWriteDB().Model(&models.XtDrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
- return err
- }
-
- func UpdatedDrugFlow(cancelstockid int64, drug_id int64, flow models.DrugFlow) error {
-
- err := XTWriteDB().Model(&models.DrugFlow{}).Where("cancel_stock_id = ? and drug_id = ? and status = 1", cancelstockid, drug_id).Updates(map[string]interface{}{"count": flow.Count}).Error
- return err
- }
-
- func UpdatedDrugInfoOne(id int64, count int64) (err error) {
-
- err = XTWriteDB().Model(&models.XtDrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
- return err
- }
-
- func UpdateWarehouseInfo(count int64, drugid int64, orgid int64, warehouse_info_id int64) error {
-
- err := writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ? and org_id = ? and status = 1 and id = ?", drugid, orgid, warehouse_info_id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
-
- return err
- }
-
- func UpdateWarehouseInfoTwo(count int64, drugid int64, orgid int64) error {
-
- err := writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ? and org_id = ? and status = 1", drugid, orgid).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number - ?", count)).Error
-
- return err
- }
-
- func UpdateWarehouseInfoOne(count int64, drugid int64, orgid int64, warehouse_info_id int64) error {
-
- err := writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ? and org_id = ? and status = 1 and id = ?", drugid, orgid, warehouse_info_id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
- return err
- }
-
- func UpdateWarehouseInfoFour(count int64, drugid int64, orgid int64) error {
-
- err := writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ? and org_id = ? and status = 1", drugid, orgid).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number - ?", count)).Error
- return err
- }
-
- func GetWarehouseInfoByIdSeven(id int64) (models.WarehousingInfo, error) {
-
- info := models.WarehousingInfo{}
- err := XTReadDB().Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
- return info, err
- }
-
- func GetLastWarehouseInfo(goodid int64) (models.WarehousingInfo, error) {
-
- info := models.WarehousingInfo{}
- err := XTReadDB().Model(&info).Where("good_id = ? and status = 1", goodid).Last(&info).Error
- return info, err
- }
-
- func GetLastWarehouseInfoTwo(goodid int64, storehouse_id int64, user_org_id int64) (info []*models.WarehousingInfo, err error) {
-
- err = XTReadDB().Model(&info).Where("good_id = ? and status = 1 and storehouse_id=? and org_id = ? and stock_count > 0", goodid, storehouse_id, user_org_id).Order("ctime").First(&info).Error
- return info, err
- }
-
- func GetFirstWarehouseInfo(goodid int64) (models.WarehousingInfo, error) {
- info := models.WarehousingInfo{}
- err := XTReadDB().Model(&info).Where("good_id = ? and status = 1", goodid).First(&info).Error
- return info, err
- }
-
- func CreateWarehouseOut(out models.WarehouseOut) error {
-
- err := XTWriteDB().Create(&out).Error
- return err
- }
-
- func GetLastGoodWarehouseOut(orgid int64) (models.WarehouseOut, error) {
- out := models.WarehouseOut{}
- err := XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&out).Error
- return out, err
- }
-
- func CreateWarehouseInfo(info models.WarehousingInfo) error {
-
- err := XTWriteDB().Create(&info).Error
- return err
- }
-
- func UpdateGoodWarehouseInfo(id int64, info models.WarehousingInfo) error {
-
- err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
- return err
- }
-
- func UpdateWareInfoById(id int64, count int64) error {
-
- err = XTWriteDB().Model(&models.WarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
- return err
- }
-
- func UpdateWareInfoByIdSix(id int64, count int64) error {
-
- err = XTWriteDB().Model(&models.WarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", count)).Error
- return err
- }
-
- func GetLastCancelInfo(id int64, goodid int64) (models.CancelStockInfo, error) {
- info := models.CancelStockInfo{}
- err := XTReadDB().Model(&info).Where("warehouse_info_id = ? and good_id = ? and status = 1", id, goodid).Find(&info).Error
- return info, err
- }
-
- func GetLastCancelInfoSix(id int64, goodid int64, storehouse_id int64) (models.CancelStockInfo, error) {
- info := models.CancelStockInfo{}
- err := XTReadDB().Model(&info).Where("warehouse_info_id = ? and good_id = ? and status = 1 and storehouse_id = ?", id, goodid, storehouse_id).Find(&info).Error
- return info, err
- }
-
- func GetAllCancelInfoById(id int64, goodid int64) (info []*models.CancelStockInfo, err error) {
-
- err = XTReadDB().Model(&info).Where("warehouse_info_id in(?) and good_id = ? and status = 1", id, goodid).Find(&info).Error
- return info, err
- }
-
- func GetAllCancelInfoByIdSix(id int64, goodid int64, storehouse_id int64) (info []*models.CancelStockInfo, err error) {
-
- err = XTReadDB().Model(&info).Where("warehouse_info_id in(?) and good_id = ? and status = 1", id, goodid).Find(&info).Error
- return info, err
- }
-
- func UpdateStockFlow(flow models.VmStockFlow, goodid int64, warehousing_id int64) error {
-
- err := XTWriteDB().Model(&flow).Where("good_id = ? and warehousing_id= ? and status = 1", goodid, warehousing_id).Updates(map[string]interface{}{"count": flow.Count}).Error
- return err
- }
-
- func UpdateDrugFlow(flow models.DrugFlow, drugid int64, warehousing_id int64) error {
-
- drugFlow := models.DrugFlow{}
- err := XTWriteDB().Model(&drugFlow).Where("drug_id = ? and warehousing_id= ? and status = 1", drugid, warehousing_id).Updates(map[string]interface{}{"count": flow.Count, "max_unit": flow.MaxUnit, "min_unit": flow.MinUnit, "price": flow.Price, "expire_date": flow.ExpireDate}).Error
- return err
- }
-
- func UpdateDrugFlowNight(flow models.DrugFlow, drugid int64, warehousing_id int64) error {
-
- drugFlow := models.DrugFlow{}
- err := XTWriteDB().Model(&drugFlow).Where("drug_id = ? and warehousing_detail_id= ? and status = 1", drugid, warehousing_id).Updates(map[string]interface{}{"count": flow.Count, "max_unit": flow.MaxUnit, "min_unit": flow.MinUnit, "price": flow.Price, "expire_date": flow.ExpireDate}).Error
- return err
- }
-
- func UpdateDrugCancel(id int64) (models.DrugCancelStock, error) {
-
- stock := models.DrugCancelStock{}
-
- err := XTWriteDB().Model(&stock).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return stock, err
- }
-
- //func UpdateDrugCancelTX(id int64,tx *gorm.DB) (models.DrugCancelStock, error) {
- // stock := models.DrugCancelStock{}
- // err := tx.Model(&stock).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- // return stock, err
- //}
-
- func GetDrugWarehouseOutInfo(warehouse_info_id int64, drug_id int64) (info []*models.DrugWarehouseOutInfo, err error) {
-
- db := XTReadDB().Model(&info)
- if warehouse_info_id > 0 {
- db = db.Where("warehouse_info_id = ?", warehouse_info_id)
- }
- if drug_id > 0 {
- db = db.Where("drug_id = ? and status =1", drug_id)
- }
-
- err = db.Find(&info).Error
- return info, err
- }
-
- //func GetDrugWarehouseOutInfoTX(warehouse_info_id int64, drug_id int64,tx *gorm.DB) (info []*models.DrugWarehouseOutInfo, err error) {
- // db := tx.Model(&info)
- // if warehouse_info_id > 0 {
- // db = db.Where("warehouse_info_id = ?", warehouse_info_id)
- // }
- // if drug_id > 0 {
- // db = db.Where("drug_id = ? and status =1", drug_id)
- // }
- // err = db.Find(&info).Error
- // return info, err
- //}
-
- func GetCancelDrugStockOutInfo(warehouse_info_id int64, drug_id int64) (info []*models.DrugCancelStockInfo, err error) {
-
- err = XTReadDB().Model(&info).Where("batch_number_id =? and drug_id = ? and status = 1", warehouse_info_id, drug_id).Find(&info).Error
- return info, err
- }
-
- //func GetCancelDrugStockOutInfoTX(warehouse_info_id int64, drug_id int64,tx *gorm.DB) (info []*models.DrugCancelStockInfo, err error) {
- // err = tx.Model(&info).Where("batch_number_id =? and drug_id = ? and status = 1", warehouse_info_id, drug_id).Find(&info).Error
- // return info, err
- //}
-
- func GetTemplateSummary(orgid int64) (config []*models.Dataconfig, err error) {
-
- err = XTReadDB().Model(&config).Where("module='template_summary' and parent_id=? and org_id in (?)", 0, orgid).Find(&config).Error
- return config, err
-
- }
-
- func GetTemplatePlan(orgid int64) (config []*models.Dataconfig, err error) {
-
- err = XTReadDB().Model(&config).Where("module='template_plan' and parent_id=? and org_id in (?)", 0, orgid).Find(&config).Error
- return config, err
- }
-
- func GetSearchGoodWarehouseList(keyword string, orgid int64, storehouse_id int64) (info []*models.BloodWarehouseInfo, err error) {
-
- db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1 and x.is_check = 1")
- table := XTReadDB().Table("xt_goood_information as t").Where("t.status")
- fmt.Println(table)
- likeKey := "%" + keyword + "%"
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
- err = db.Group("x.good_id").Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.total_price,t.dealer,x.remark,x.warehousing_order,x.warehousing_unit,x.stock_count,x.license_number,x.warehousing_unit,x.storehouse_id,t.good_name,t.specification_name,t.manufacturer,t.packing_price,t.id as good_id,t.packing_unit,t.buy_price").Joins("left join xt_good_information as t on t.id = x.good_id").Where("t.good_name like ? and t.org_id = ?", likeKey, orgid).Order("x.ctime desc").Scan(&info).Error
- return info, err
- }
-
- func CreateAdjustPrice(adjustPrice *models.XtStockAdjustPrice) error {
-
- err := XTWriteDB().Create(&adjustPrice).Error
- return err
- }
-
- func GetAllStockPrice(orgid int64, startime int64, endtime int64, keyword string, limit int64, page int64) (list []*models.VmStockAdjustPrice, total int64, err error) {
- likeKey := "%" + keyword + "%"
- offset := (page - 1) * limit
- db := XTReadDB().Table("xt_stock_adjust_price as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
- tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
- fmt.Println(table, tab)
- if startime > 0 {
- db = db.Where("x.start_time>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.start_time<=?", endtime)
- }
- if len(keyword) > 0 {
- db = db.Where("x.warehousing_order = ? or r.user_name like ?", keyword, likeKey)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.id").Select("x.id,x.good_name,x.specification_name,x.warehousing_unit,x.count,x.buy_price,x.packing_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.good_id,x.warehousing_order,x.license_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,t.packing_unit").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.creater").Joins("left join xt_good_information as t on t.id =x.good_id").Count(&total).Offset(offset).Limit(limit).Scan(&list).Error
- return list, total, err
- }
-
- func UpdateAdjustPrice(ids []string, info models.XtStockAdjustPrice) error {
-
- err := XTWriteDB().Model(&info).Where("id in(?)", ids).Updates(map[string]interface{}{"checker": info.Checker, "checker_status": info.CheckerStatus, "checker_time": info.CheckerTime}).Error
- return err
- }
-
- func UpdateAdjustCheckPrice(info *models.GoodInfo, id int64) error {
-
- err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"packing_price": info.PackingPrice, "buy_price": info.BuyPrice}).Error
- return err
- }
-
- func GetAdjustCheckPriceList(ids []string) (info []*models.XtStockAdjustPrice, err error) {
-
- err = XTReadDB().Where("id in(?)", ids).Find(&info).Error
- return info, err
- }
-
- func GetAdjustPricebyIdOne(ids []string) (adjust []*models.XtStockAdjustPrice, err error) {
-
- err = XTReadDB().Where("id in(?) and status = 1", ids).Find(&adjust).Error
- return adjust, err
- }
-
- func CreateReportPrice(price *models.XtStockReportPrice) error {
-
- err := XTWriteDB().Create(&price).Error
- return err
- }
-
- func GetReportStockList(startime int64, endtime int64, orgid int64, keyword string, page int64, limit int64) (adjust []*models.VmStockAdjustPrice, total int64, err error) {
- likeKey := "%" + keyword + "%"
- offset := (page - 1) * limit
- db := XTReadDB().Table("xt_stock_report_price as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
- tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
- fmt.Println(table, tab)
- if startime > 0 {
- db = db.Where("x.ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
- if len(keyword) > 0 {
- db = db.Where("x.warehousing_order like ? or r.user_name like ?", likeKey, likeKey)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.id").Select("x.id,x.good_name,x.specification_name,x.warehousing_unit,x.count,x.buy_price,x.packing_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.good_id,x.warehousing_order,x.license_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,t.packing_unit,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.creater").Joins("left join xt_good_information as t on t.id =x.good_id").Count(&total).Offset(offset).Limit(limit).Scan(&adjust).Error
- return adjust, total, err
- }
-
- func GetStockDamagedList(orgid int64, keyword string, page int64, limit int64, startime int64, endtime int64, storehouse_id int64) (adjust []*models.VmStockInventory, total int64, err error) {
- likeKey := "%" + keyword + "%"
- offset := (page - 1) * limit
- db := XTReadDB().Table("xt_stock_inventory as x").Where("x.status = 1 and x.inventory_type = 4")
- table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
- tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
- fmt.Println(table, tab)
-
- if len(keyword) > 0 {
- db = db.Where("x.warehousing_order like ? or r.user_name like ?", likeKey, likeKey)
- }
-
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("x.ctime >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime <=?", endtime)
- }
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
-
- err = db.Group("x.good_id").Select("x.ctime,x.id,x.good_name,x.specification_name,x.warehousing_unit,x.count,x.buy_price,x.packing_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.good_id,x.warehousing_order,x.license_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.total,x.number,x.storehouse_id,t.packing_unit,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.creater").Joins("left join xt_good_information as t on t.id =x.good_id").Count(&total).Offset(offset).Limit(limit).Scan(&adjust).Error
- return adjust, total, err
-
- }
-
- func GetStockDamagedCountOne(orgid int64, keyword string, inventory_type int64) (adjust []*models.VmStockInventory, err error) {
-
- db := XTReadDB().Table("xt_stock_inventory as x").Where("x.status = 1")
- if inventory_type == 0 {
- db = db.Where("x.inventory_type = 4")
- }
- if inventory_type > 0 {
- db = db.Where("x.inventory_type = ?", inventory_type)
- }
- if len(keyword) > 0 {
- likeKey := "%" + keyword + "%"
- db = db.Where("x.warehousing_order like ?", likeKey)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.good_id").Select("x.id,x.good_name,x.specification_name,x.warehousing_unit,sum(x.count) as count,x.buy_price,x.packing_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.good_id,x.warehousing_order,x.license_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.total,x.number").Scan(&adjust).Error
- return adjust, err
- }
-
- func GetStockDamagedCount(orgid int64) (adjust []*models.VmStockInventory, err error) {
-
- db := XTReadDB().Table("xt_stock_inventory as x").Where("x.status = 1 and inventory_type = 4 ")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- err = db.Group("x.good_id").Select("x.id,x.good_name,x.specification_name,x.warehousing_unit,sum(x.count) as count,x.buy_price,x.packing_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.good_id,x.warehousing_order,x.license_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.total,x.number").Scan(&adjust).Error
- return adjust, err
- }
-
- func UpdateCheckDamage(ids []string, reportPrice models.XtStockReportPrice) error {
-
- err := XTWriteDB().Model(&reportPrice).Where("id in(?) and status = 1", ids).Updates(map[string]interface{}{"checker": reportPrice.Checker, "checker_time": reportPrice.CheckerTime, "checker_status": reportPrice.CheckerStatus}).Error
- return err
- }
-
- func GetCheckDamageList(ids []string) (report []*models.XtStockReportPrice, err error) {
-
- err = XTReadDB().Model(&report).Where("id in(?) and status= 1", ids).Find(&report).Error
- return report, err
- }
-
- func CreateInentory(inventory models.XtStockInventory) error {
-
- err = XTWriteDB().Create(&inventory).Error
- return err
- }
-
- func GetInventorylist(startime int64, endtime int64, page int64, limit int64, inventory_status int64, keyword string, orgid int64) (adjust []*models.VmStockAdjustPrice, total int64, err error) {
-
- likeKey := "%" + keyword + "%"
- offset := (page - 1) * limit
- db := XTReadDB().Table("xt_stock_inventory as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
- tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
- fmt.Println(table, tab)
- if startime > 0 {
- db = db.Where("x.ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.ctime<=?", endtime)
- }
- if len(keyword) > 0 {
- db = db.Where("x.warehousing_order like ? or r.user_name like ?", likeKey, likeKey)
- }
-
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if inventory_status > 0 {
- db = db.Where("checker_status = ?", inventory_status)
- }
- err = db.Group("x.id").Select("x.id,x.good_name,x.specification_name,x.warehousing_unit,x.count,x.buy_price,x.packing_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.good_id,x.warehousing_order,x.license_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.total,x.number,t.packing_unit,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.creater").Joins("left join xt_good_information as t on t.id =x.good_id").Count(&total).Offset(offset).Limit(limit).Scan(&adjust).Error
- return adjust, total, err
- }
-
- func UpdateCheckInventory(ids []string, info models.XtStockInventory) error {
- err := XTWriteDB().Model(&info).Where("id in(?)", ids).Updates(map[string]interface{}{"checker": info.Checker, "checker_status": info.CheckerStatus, "checker_time": info.CheckerTime}).Error
- return err
- }
-
- func GetModifyPriceDetail(id int64) (models.XtStockAdjustPrice, error) {
-
- info := models.XtStockAdjustPrice{}
- err := XTReadDB().Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
- return info, err
- }
-
- func GetInventoryDetailById(id []string) (list []*models.XtStockInventory, err error) {
-
- err = XTReadDB().Model(&list).Where("id in(?) and status = 1", id).Find(&list).Error
- return list, err
- }
-
- func GetWarehouseInfoByIdNight(id int64) (models.WarehousingInfo, error) {
-
- info := models.WarehousingInfo{}
- err := XTReadDB().Where("id = ? and status = 1", id).Find(&info).Error
- return info, err
- }
-
- func GetWarehouseInfoById(id int64) (models.WarehousingInfo, error) {
-
- info := models.WarehousingInfo{}
- //err :=XTReadDB().Model(&info).Where("id = ? or warehouse_info_id and status = 1", id).Find(&info).Error
- //return info, err
-
- db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
- if id > 0 {
- db = db.Where("x.id = ? or x.warehouse_info_id = ?", id, id)
- }
- err := db.Select("sum(x.warehousing_count) as warehousing_count,sum(x.stock_count) as stock_count").Scan(&info).Error
- return info, err
- }
-
- func GetWarehouseInfoByIdTen(id int64, storehouse_id int64) (models.WarehousingInfo, error) {
-
- info := models.WarehousingInfo{}
-
- db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
- if id > 0 {
- db = db.Where("x.id = ? or x.warehouse_info_id = ?", id, id)
- }
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
- err := db.Select("sum(x.warehousing_count) as warehousing_count,sum(x.stock_count) as stock_count").Scan(&info).Error
- return info, err
- }
-
- func UpdateStockPrice(info models.XtStockAdjustPrice, id int64) error {
-
- err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"new_price": info.NewPrice, "good_name": info.GoodName, "packing_price": info.PackingPrice, "good_id": info.GoodId, "remark": info.Remark, "manufacturer": info.Manufacturer, "dealer": info.Dealer}).Error
- return err
- }
-
- func DeleteStockPrice(id int64) error {
- info := models.XtStockAdjustPrice{}
- err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetStockDamageDetail(id int64) (models.XtStockReportPrice, error) {
- report := models.XtStockReportPrice{}
- err := XTReadDB().Model(&report).Where("id=? and status = 1", id).Find(&report).Error
- return report, err
- }
-
- func ModifyPrice(id int64, info models.XtStockReportPrice) error {
-
- err := XTWriteDB().Model(&info).Where("id = ?", id).Updates(map[string]interface{}{"count": info.Count, "specification_name": info.SpecificationName, "good_name": info.GoodName, "number": info.Number, "warehousing_unit": info.WarehousingUnit, "buy_price": info.BuyPrice, "packing_price": info.PackingPrice, "good_origin_place": info.GoodOriginPlace, "manufacturer": info.Manufacturer, "dealer": info.Dealer, "total": info.Total, "remark": info.Remark, "warehousing_info_id": info.WarehousingInfoId, "good_id": info.GoodId}).Error
- return err
- }
-
- func DeleteDamage(id int64) error {
- adjust := models.XtStockReportPrice{}
- err := XTWriteDB().Model(&adjust).Where("id=? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetStockDamageById(ids []string) (adjust []*models.XtStockReportPrice, err error) {
-
- err = XTReadDB().Where("id in(?) and status = 1", ids).Find(&adjust).Error
- return adjust, err
- }
-
- func GetInventoryDetail(id int64) (models.XtStockInventory, error) {
-
- inventory := models.XtStockInventory{}
- err := XTReadDB().Model(&inventory).Where("id=? and status = 1", id).Find(&inventory).Error
- return inventory, err
- }
-
- func ModifyInventory(id int64, inventory models.XtStockInventory) error {
-
- err := XTWriteDB().Model(&inventory).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"good_id": inventory.GoodId, "good_name": inventory.GoodName, "specification_name": inventory.SpecificationName, "number": inventory.Number, "warehousing_unit": inventory.WarehousingUnit, "buy_price": inventory.BuyPrice, "packing_price": inventory.PackingPrice, "total": inventory.Total, "good_origin_place": inventory.GoodOriginPlace, "license_number": inventory.LicenseNumber, "dealer": inventory.Dealer, "manufacturer": inventory.Dealer, "count": inventory.Count, "remark": inventory.Remark}).Error
- return err
- }
-
- func DeleteInventory(id int64) error {
-
- inventory := models.XtStockInventory{}
- err := XTWriteDB().Model(&inventory).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetInventoryDetailList(keyword string, limit int64, page int64, orgid int64, storehouse_id int64) (list []*models.VmStockInventory, total int64, err error) {
-
- likeKey := "%" + keyword + "%"
- offset := (page - 1) * limit
- db := XTReadDB().Table("xt_stock_inventory as x").Where("x.status = 1 and x.type = 10")
- table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
- tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
- fmt.Println(table, tab)
- if len(keyword) > 0 {
- db = db.Where("x.good_name like ?", likeKey)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
- err = db.Select("x.id,x.good_name,x.specification_name,x.warehousing_unit,x.count,x.buy_price,x.packing_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.good_id,x.warehousing_order,x.license_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.total,x.number,x.expire_date,x.product_date,t.packing_unit,x.last_stock_count,x.type,x.inventory_type,x.stock_count,x.storehouse_id,x.ctime").Joins("left join sgj_users.sgj_user_admin_role as r on r.id = x.creater").Joins("left join xt_good_information as t on t.id =x.good_id").Count(&total).Offset(offset).Limit(limit).Order("x.id desc").Scan(&list).Error
- return list, total, err
- }
-
- func GetInventoryDetailPrintMapList(keyword string, limit int64, page int64, orgid int64, storehouse_id int64, ids []string) (list []*models.VmStockInventory, total int64, err error) {
-
- likeKey := "%" + keyword + "%"
- offset := (page - 1) * limit
- db := XTReadDB().Table("xt_stock_inventory as x").Where("x.status = 1 and x.type = 10")
- table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
- tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
- fmt.Println(table, tab)
- if len(keyword) > 0 {
- db = db.Where("x.good_name like ?", likeKey)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if storehouse_id > 0 {
- db = db.Where("x.storehouse_id = ?", storehouse_id)
- }
- if len(ids) > 0 {
- db = db.Where("x.id in(?)", ids)
- }
- err = db.Select("x.id,x.good_name,x.specification_name,x.warehousing_unit,x.count,x.buy_price,x.packing_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.good_id,x.warehousing_order,x.license_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.total,x.number,x.expire_date,x.product_date,t.packing_unit,x.last_stock_count,x.type,x.inventory_type,x.stock_count,x.storehouse_id").Joins("left join sgj_users.sgj_user_admin_role as r on r.id = x.creater").Joins("left join xt_good_information as t on t.id =x.good_id").Count(&total).Offset(offset).Limit(limit).Scan(&list).Error
- return list, total, err
- }
-
- func GetInventoryPrintList(ids []string) (list []*models.XtStockInventory, err error) {
-
- err = XTReadDB().Where("id in(?) and status = 1", ids).Find(&list).Error
- return list, err
- }
-
- func GetInventoryDetailPrintList(ids []string) (list []*models.XtStockInventory, err error) {
-
- err = XTReadDB().Where("id in(?) and status = 1", ids).Find(&list).Error
- return list, err
- }
-
- func DeleteDrugPrice(id int64) error {
-
- info := models.XtDrugAdjustPrice{}
- err := XTReadDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetGoodWarehouseList(goodid int64) (models.WarehousingInfo, error) {
-
- info := models.WarehousingInfo{}
- db := XTReadDB().Model(&info).Where("status = 1")
- if goodid > 0 {
- db = db.Where("good_id = ?", goodid)
- }
- err := db.Select("good_id,sum(stock_count) as stock_count").Find(&info).Error
- return info, err
- }
-
- func UpdateProofInventory(id int64, info models.WarehousingInfo) error {
-
- err := XTWriteDB().Model(&info).Where("id=? and status = 1", id).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
- return err
- }
-
- func UpdateStockInventory(inventory models.XtStockInventory, id int64) error {
-
- err := XTWriteDB().Model(&inventory).Where("id= ? and status = 1", id).Updates(map[string]interface{}{"total": inventory.Total}).Error
- return err
- }
-
- func CeateStockCorrectRecord(record models.XtStockCorrectRecord) error {
-
- err := XTWriteDB().Create(&record).Error
- return err
- }
-
- func GetWarehouseTotal(id int64) (models.WarehousingInfo, error) {
- info := models.WarehousingInfo{}
- //err :=XTReadDB()()()()().Where("id=? and status = 1", id).Find(&info).Error
- //return info, err
-
- db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
- if id > 0 {
- db = db.Where("x.id = ? or x.warehouse_info_id = ?", id, id)
- }
- err := db.Select("sum(x.stock_count) as stock_count").Scan(&info).Error
- return info, err
- }
-
- func GetCurrentWarehosueInfo(id int64) (info []*models.DrugWarehouseInfo, err error) {
-
- err = XTReadDB().Model(&info).Where("id=? or warehousing_info_id = ? ", id, id).Find(&info).Error
- return info, err
- }
-
- func GetCurrentWarehosueInfoOne(id int64) (models.DrugWarehouseInfo, error) {
-
- info := models.DrugWarehouseInfo{}
- err := XTReadDB().Model(&info).Where("id=?", id).Find(&info).Error
- return info, err
- }
-
- func ModifyDrugWarehouseInfo(info *models.DrugWarehouseInfo, id int64) error {
-
- err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_max_number": info.StockMaxNumber, "stock_min_number": info.StockMinNumber, "max_unit": info.MaxUnit, "min_unit": info.MinUnit}).Error
- return err
- }
-
- func ModifyDrugWarehouseInfoSix(info *models.DrugWarehouseInfo, id int64) error {
-
- err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"warehousing_count": info.WarehousingCount, "stock_max_number": info.StockMaxNumber, "stock_min_number": info.StockMinNumber, "max_unit": info.MaxUnit, "min_unit": info.MinUnit}).Error
- return err
- }
-
- func GetGoodInventoryWarehouseList(id int64, storehouse_id int64) (info []*models.WarehousingInfo, err error) {
-
- err = XTReadDB().Model(&info).Where("good_id = ? and status = 1 and storehouse_id=? and is_check= 1 and stock_count>0", id, storehouse_id).Preload("GoodInfo", "status = 1").Find(&info).Error
- return info, err
- }
-
- func UpdatedWarehousingInfo(info models.WarehousingInfo, id int64) error {
- err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
- return err
- }
-
- func UpdatedWarehousingInfoSix(info models.WarehousingInfo, id int64) error {
- err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_count": info.StockCount, "warehousing_count": info.WarehousingCount}).Error
- return err
- }
-
- func GetDamageDetailByGoodId(good_id int64, keyword string, inventory_type int64) (list []*models.XtStockInventory, err error) {
-
- db := XTReadDB().Model(&list).Where(" status = 1")
- if good_id > 0 {
- db = db.Where("good_id = ?", good_id)
- }
- if len(keyword) > 0 {
- likeKey := "%" + keyword + "%"
- db = db.Where("warehousing_order like ?", likeKey)
- }
- if inventory_type > 0 {
- db = db.Where("inventory_type = ?", inventory_type)
- }
- if inventory_type == 0 {
- db = db.Where("inventory_type = 4")
- }
- err = db.Find(&list).Error
-
- return list, err
- }
-
- func GetCancelStockId(cancelstock_id int64, drug_id int64) (*models.DrugFlow, error) {
- flow := models.DrugFlow{}
- err := XTReadDB().Where("cancel_stock_id = ? and drug_id = ?", cancelstock_id, drug_id).Find(&flow).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &flow, nil
- }
-
- func GetTotalDrugCancelInfo(batchNumber_id int64, drug_id int64, id int64) (info []*models.DrugCancelStockInfo, err error) {
-
- err = XTReadDB().Where("batch_number_id = ? and drug_id = ? and status = 1 and id<>?", batchNumber_id, drug_id, id).Find(&info).Error
- return info, err
- }
-
- func GetLastDrugWarehouseInfo(drugid int64) (models.XtDrugWarehouseInfo, error) {
- info := models.XtDrugWarehouseInfo{}
- err := XTReadDB().Where("drug_id = ? and status =1", drugid).Last(&info).Error
- return info, err
- }
-
- func GetLastGoodWarehouseInfo(goodid int64) (models.WarehousingInfo, error) {
-
- info := models.WarehousingInfo{}
- err := XTReadDB().Where("good_id =? and status = 1", goodid).Find(&info).Error
- return info, err
- }
-
- func GetGoodStockFlowInfo(warehouseid int64, goodid int64) (*models.VmStockFlow, error) {
-
- flow := models.VmStockFlow{}
- err := XTReadDB().Where("warehousing_detail_id = ? and good_id = ? and status = 1", warehouseid, goodid).Find(&flow).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &flow, nil
- }
-
- func GetLastInfoMationById(id int64) (models.GoodInfo, error) {
- info := models.GoodInfo{}
- err := XTReadDB().Where("id =? and status = 1", id).Find(&info).Error
- return info, err
- }
-
- func UpdateGoodInfoMation(goodid int64, info models.GoodInfo) error {
-
- err := XTWriteDB().Model(&info).Where("id =? and status = 1", goodid).Updates(map[string]interface{}{"total": info.Total}).Error
- return err
- }
-
- func UpdateWarehouseInfoByGoodId(info models.WarehousingInfo, id int64) error {
-
- err := XTWriteDB().Model(&info).Where("id =? and status = 1", id).Updates(map[string]interface{}{"warehousing_count": info.WarehousingCount, "stock_count": info.StockCount}).Error
- return err
- }
-
- func UpdateWarehouseInfoByGoodIdOne(info *models.WarehousingInfo, id int64) error {
-
- err := XTWriteDB().Model(&info).Where("id =? and status = 1", id).Updates(map[string]interface{}{"warehousing_count": info.WarehousingCount, "stock_count": info.StockCount, "price": info.Price, "number": info.Number, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "license_number": info.LicenseNumber, "manufacturer": info.Manufacturer, "dealer": info.Dealer, "remark": info.Remark, "packing_price": info.PackingPrice, "storehouse_id": info.StorehouseId, "register_number": info.RegisterNumber, "good_id": info.GoodId, "good_code": info.GoodCode}).Error
- return err
- }
-
- func UpdateNewWarehouseInfoByGoodIdOne(info *models.WarehousingInfo, id int64, tx *gorm.DB) error {
-
- err := tx.Model(&info).Where("id =? and status = 1", id).Updates(map[string]interface{}{"warehousing_count": info.WarehousingCount, "stock_count": info.StockCount, "price": info.Price, "number": info.Number, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "license_number": info.LicenseNumber, "manufacturer": info.Manufacturer, "dealer": info.Dealer, "remark": info.Remark, "packing_price": info.PackingPrice, "storehouse_id": info.StorehouseId, "register_number": info.RegisterNumber, "good_id": info.GoodId, "good_code": info.GoodCode}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpdatedStockFlowByGoodId(warehousing_id int64, good_id int64, flow models.VmStockFlow) error {
-
- err := XTWriteDB().Model(&flow).Where("warehousing_id = ? and good_id = ? and status = 1", warehousing_id, good_id).Updates(map[string]interface{}{"count": flow.Count}).Error
- return err
- }
-
- func UpdatedStockFlowByGoodIdOne(warehousing_id int64, good_id int64, flow models.VmStockFlow) error {
-
- err := XTWriteDB().Model(&flow).Where("warehousing_id = ? and good_id = ? and status = 1", warehousing_id, good_id).Updates(map[string]interface{}{"count": flow.Count, "number": flow.Number, "product_date": flow.ProductDate, "expire_date": flow.ExpireDate, "Price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer, "license_number": flow.LicenseNumber, "storehouse_id": flow.StorehouseId, "register_number": flow.RegisterNumber}).Error
- return err
- }
-
- func UpdateStockFlowByDetailId(flow models.VmStockFlow, wareoutdetailid int64) error {
- err := XTWriteDB().Model(&flow).Where("warehouse_out_detail_id = ? and status = 1", wareoutdetailid).Updates(map[string]interface{}{"count": flow.Count, "number": flow.Number, "product_date": flow.ProductDate, "expire_date": flow.ExpireDate, "Price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer, "license_number": flow.LicenseNumber, "price": flow.Price, "storehouse_id": flow.StorehouseId, "admin_user_id": flow.AdminUserId, "stock_count": flow.StockCount, "register_number": flow.RegisterNumber}).Error
- return err
- }
-
- func UpdatedGoodInfo(info models.GoodInfo, goodid int64) error {
- err := XTWriteDB().Model(&info).Where("id = ? and status = 1", goodid).Updates(map[string]interface{}{"manufacturer": info.Manufacturer, "dealer": info.Dealer}).Error
- return err
- }
-
- func GetInventoryExportList(orgid int64) (info []*models.PatientWarehouseInfo, err error) {
-
- if orgid == 10653 {
- db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1 and x.warehousing_count>0 and x.stock_count>0")
- table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
- fmt.Println(table)
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- err = db.Select("x.id,x.good_id,x.number,x.number,x.product_date,x.expiry_date,x.warehousing_unit,x.dealer,x.manufacturer,t.good_name,t.specification_name,t.packing_unit,t.remark").Joins("left join xt_good_information as t on t.id = x.good_id").Group("x.good_id,x.number").Scan(&info).Error
- return info, err
- } else {
- db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1 and x.warehousing_count>0")
- table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
- fmt.Println(table)
- if orgid > 0 {
- db = db.Where("x.org_id = ?", orgid)
- }
- err = db.Select("x.id,x.good_id,x.number,x.number,x.product_date,x.expiry_date,x.warehousing_unit,x.dealer,x.manufacturer,t.good_name,t.specification_name,t.packing_unit,t.remark").Joins("left join xt_good_information as t on t.id = x.good_id").Group("x.good_id,x.number").Scan(&info).Error
- return info, err
- }
-
- }
-
- func UpdateDrugWarehouseingInfoSix(id int64, info models.XtDrugWarehouseInfo) error {
-
- warehouseInfo := models.XtDrugWarehouseInfo{}
- err := XTWriteDB().Model(&warehouseInfo).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"number": info.Number, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "price": info.Price, "total_price": info.TotalPrice, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "remark": info.Remark, "batch_number": info.BatchNumber, "max_unit": info.MaxUnit, "storehouse_id": info.StorehouseId}).Error
- return err
- }
-
- func CreatedCancelStock(info models.DrugCancelStockInfo) error {
-
- err := XTWriteDB().Create(&info).Error
- return err
- }
-
- func CreatedNewCancelStock(info models.DrugCancelStockInfo, tx *gorm.DB) error {
-
- err := tx.Create(&info).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func IsExsitStockFlow(goodid int64, cancel_order_number string) (*models.VmStockFlow, error) {
- flow := models.VmStockFlow{}
- err := XTReadDB().Where("good_id = ? and cancel_order_number = ? and status = 1", goodid, cancel_order_number).Find(&flow).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &flow, nil
- }
-
- func UpdateStockFlowTwo(id int64, flow models.VmStockFlow) error {
-
- err := XTWriteDB().Model(&flow).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"count": flow.Count}).Error
- return err
- }
-
- func UpdateStockFlowThree(id int64, flow models.VmStockFlow) error {
-
- err := XTWriteDB().Model(&flow).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"count": flow.Count, "manufacturer": flow.Count, "dealer": flow.Dealer, "number": flow.Number, "license_number": flow.LicenseNumber, "price": flow.Price, "product_date": flow.ProductDate, "expire_date": flow.ExpireDate, "storehouse_id": flow.StorehouseId}).Error
- return err
- }
-
- func GetLastWarehouseOutInfoById(drugid int64) (models.DrugWarehouseOutInfo, error) {
-
- flow := models.DrugWarehouseOutInfo{}
- err := XTReadDB().Where("drug_id = ? and status = 1", drugid).Last(&flow).Error
- return flow, err
- }
-
- func GetLastNewWarehouseOutInfoById(drugid int64, tx *gorm.DB) (models.DrugWarehouseOutInfo, error) {
-
- flow := models.DrugWarehouseOutInfo{}
- err := tx.Where("drug_id = ? and status = 1", drugid).Last(&flow).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return flow, err
- }
- }
- return flow, err
- }
-
- func GetLastWarehoseByGoodId(goodid int64, patient_id int64, record_date int64) (models.WarehouseOutInfo, error) {
-
- info := models.WarehouseOutInfo{}
- err := XTReadDB().Model(&info).Where("good_id = ? and patient_id = ? and sys_record_time = ? and status = 1", goodid, patient_id, record_date).First(&info).Error
-
- return info, err
- }
-
- func ModifyDrugWarehouseOutInfo(info models.DrugWarehouseOutInfo, drugid int64, patientid int64, sys_record_time int64) error {
-
- err := XTWriteDB().Model(&info).Where("drug_id = ? and patient_id = ? and sys_record_time = ? and status = 1", drugid, patientid, sys_record_time).Updates(map[string]interface{}{"count": info.Count, "count_unit": info.CountUnit}).Error
- return err
- }
-
- func ModifyDrugWarehouseOutInfoOne(info models.DrugWarehouseOutInfo, drugid int64, patientid int64, sys_record_time int64, warehouse_info_id int64) error {
-
- err := XTWriteDB().Model(&info).Where("drug_id = ? and patient_id = ? and sys_record_time = ? and status = 1 and warehouse_info_id = ?", drugid, patientid, sys_record_time, warehouse_info_id).Updates(map[string]interface{}{"count": info.Count, "count_unit": info.CountUnit}).Error
- return err
- }
-
- func GetDrugWarehouseOutInfoByWarehosueId(drugid int64, patientid int64, recorddate int64, warehosueinfoid int64) (*models.DrugWarehouseOutInfo, error) {
- info := models.DrugWarehouseOutInfo{}
- err := XTReadDB().Model(&info).Where("drug_id = ? and patient_id = ? and sys_record_time = ? and warehouse_info_id = ? and status = 1", drugid, patientid, recorddate, warehosueinfoid).Find(&info).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &info, nil
- }
-
- func GetDrugFlowRecord(warehouse_out_order_number string, drugid int64, patientid int64) (*models.DrugFlow, error) {
-
- drugFlow := models.DrugFlow{}
-
- err := XTReadDB().Where("warehouse_out_order_number = ? and drug_id =? and patient_id = ? and status = 1", warehouse_out_order_number, drugid, patientid).Find(&drugFlow).Error
-
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &drugFlow, nil
- }
-
- func ModifyDrugFlow(flow models.DrugFlow, warehouse_out_order_number string, drugid int64, patient_id int64) error {
-
- err := XTWriteDB().Model(&flow).Where("warehouse_out_order_number = ? and drug_id = ? and patient_id = ? and status = 1", warehouse_out_order_number, drugid, patient_id).Updates(map[string]interface{}{"count": flow.Count, "max_unit": flow.MaxUnit}).Error
- return err
- }
-
- func ModifyDrugFlowOne(flow models.DrugFlow, warehouse_out_order_number string, drugid int64, patient_id int64, warehousing_detail_id int64) error {
-
- err := XTWriteDB().Model(&flow).Where("warehouse_out_order_number = ? and drug_id = ? and patient_id = ? and status = 1 and warehousing_detail_id = ?", warehouse_out_order_number, drugid, patient_id, warehousing_detail_id).Updates(map[string]interface{}{"count": flow.Count, "max_unit": flow.MaxUnit}).Error
- return err
- }
-
- func GetDrugAutoReduceRecordOne(drugid int64, patientid int64, recorddate int64) (detail []*models.DrugAutomaticReduceDetail, err error) {
-
- err = XTReadDB().Model(&detail).Where("drug_id = ? and patient_id = ? and record_time = ? and status = 1", drugid, patientid, recorddate).Find(&detail).Error
-
- return detail, err
- }
-
- func GetDrugAutoReduceRecord(drugid int64, patientid int64, recorddate int64) (*models.DrugAutomaticReduceDetail, error) {
-
- detail := models.DrugAutomaticReduceDetail{}
-
- err := XTReadDB().Model(&detail).Where("drug_id = ? and patient_id = ? and record_time = ? and status = 1", drugid, patientid, recorddate).Find(&detail).Error
-
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &detail, nil
- }
-
- func ModifyAutoMaticReduce(auto models.DrugAutomaticReduceDetail, patientid int64, recordate int64, drugid int64) error {
-
- err := XTWriteDB().Model(&auto).Where("patient_id = ? and record_time = ? and drug_id = ? and status = 1", patientid, recordate, drugid).Updates(map[string]interface{}{"count": auto.Count, "count_unit": auto.CountUnit}).Error
- return err
- }
-
- func ModifyAutoMaticReduceOne(auto models.DrugAutomaticReduceDetail, patientid int64, recordate int64, drugid int64, warehouse_info_id int64) error {
-
- err := XTWriteDB().Model(&auto).Where("patient_id = ? and record_time = ? and drug_id = ? and status = 1 and warehouse_info_id = ?", patientid, recordate, drugid, warehouse_info_id).Updates(map[string]interface{}{"count": auto.Count, "count_unit": auto.CountUnit}).Error
- return err
- }
-
- func ModifyDrugWarehouse(id int64, stock_max_number int64, stock_min_number int64) (models.DrugWarehouseInfo, error) {
-
- info := models.DrugWarehouseInfo{}
-
- err = XTWriteDB().Model(&info).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", stock_max_number)).Error
- err = XTWriteDB().Model(&info).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", stock_min_number)).Error
- return info, err
- }
-
- func ModeifyDrugWarehosueInfo(id int64, stock_max_number int64) error {
-
- err := XTWriteDB().Model(models.DrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", stock_max_number)).Error
- return err
- }
-
- func ModeFyStockMinById(id int64, stock_min_number int64) error {
- info := models.DrugWarehouseInfo{}
- err = XTWriteDB().Model(&info).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", stock_min_number)).Error
- return err
- }
-
- func GetDrugCancelById(id int64) (models.DrugCancelStockInfo, error) {
-
- info := models.DrugCancelStockInfo{}
- err := XTReadDB().Where("id = ? and status = 1", id).Find(&info).Error
- return info, err
- }
-
- func ModeFyDrugWareseInfo(id int64, stock_max_number int64) error {
- info := models.DrugWarehouseInfo{}
- err = XTWriteDB().Model(&info).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number - ?", stock_max_number)).Error
- return err
- }
-
- func ModeFyDrugWarehouseMin(id int64, stock_min_number int64) error {
- info := models.DrugWarehouseInfo{}
- err = XTWriteDB().Model(&info).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number - ?", stock_min_number)).Error
- return err
- }
-
- func GetAllHisDoctorAdviceById(drugid int64, patient_id int64, advicedate int64, orgid int64) (advice []*models.HisDoctorAdviceInfo, err error) {
-
- err = XTReadDB().Where("drug_id = ? and patient_id = ? and advice_date = ? and execution_state = 1 and status = 1 and user_org_id = ?", drugid, patient_id, advicedate, orgid).Find(&advice).Error
- return advice, err
- }
-
- func GetAllHisDoctorAdviceByIdOne(drugid int64, patient_id int64, advicedate int64, orgid int64, tx *gorm.DB) (advice []*models.HisDoctorAdviceInfo, err error) {
-
- err = tx.Where("drug_id = ? and patient_id = ? and advice_date = ? and execution_state = 1 and status = 1 and user_org_id = ?", drugid, patient_id, advicedate, orgid).Find(&advice).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return advice, err
- }
- }
- return advice, err
- }
-
- func GetAllDrugFlowById(drugid int64, patient_id int64, advicedate int64, orgid int64) (info []*models.DrugWarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("drug_id = ? and patient_id = ? and sys_record_time = ? and org_id = ? and status = 1", drugid, patient_id, advicedate, orgid).Find(&info).Error
- return info, err
- }
-
- func GetAllDrugFlowByIdOne(drugid int64, patient_id int64, advicedate int64, orgid int64, tx *gorm.DB) (info []*models.DrugWarehouseOutInfo, err error) {
-
- err = tx.Where("drug_id = ? and patient_id = ? and sys_record_time = ? and org_id = ? and status = 1", drugid, patient_id, advicedate, orgid).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- return info, err
- }
-
- // 耗材加库存
- func ModifyGoodAddInformation(good_id int64, sum_count int64, orgid int64) (models.GoodInfo, error) {
-
- info := models.GoodInfo{}
-
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", good_id, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count + ?", sum_count)).Error
- return info, err
- }
-
- func ModifyGoodAddInformationSix(good_id int64, sum_count int64, orgid int64) (models.GoodInfo, error) {
-
- info := models.GoodInfo{}
-
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", good_id, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count + ?", sum_count)).Error
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", good_id, orgid).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count + ?", sum_count)).Error
- return info, err
- }
-
- func ModifyGoodReduceInformation(good_id int64, sum_count int64, orgid int64) (models.GoodInfo, error) {
-
- info := models.GoodInfo{}
-
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", good_id, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count - ?", sum_count)).Error
- return info, err
- }
-
- func ModifyGoodReduceInformationTwo(good_id int64, sum_count int64, orgid int64) (models.GoodInfo, error) {
-
- info := models.GoodInfo{}
-
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", good_id, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count - ?", sum_count)).Error
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", good_id, orgid).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count - ?", sum_count)).Error
- return info, err
- }
-
- func ModifyGoodReduceInformationSix(good_id int64, sum_count int64, orgid int64, retail_price float64) (models.GoodInfo, error) {
-
- info := models.GoodInfo{}
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", good_id, orgid).Update(map[string]interface{}{"batch_retai_price": retail_price}).Error
- return info, err
- }
-
- func GetWarehousingByIdList(ids []string, orgid int64) (info []*models.WarehousingInfo, err error) {
-
- err = XTReadDB().Model(&info).Where("warehousing_id in(?) and org_id = ? and status = 1", ids, orgid).Find(&info).Error
- return info, err
- }
-
- func GetWarehousingByIdListTwenty(ids []string, orgid int64) (info []*models.WarehousingInfo, err error) {
-
- err = XTReadDB().Model(&info).Where("warehousing_id in(?) and org_id = ?", ids, orgid).Find(&info).Error
- return info, err
- }
-
- func GetWarehouseInfoByIdSix(id int64, orgid int64) (models.WarehousingInfo, error) {
-
- info := models.WarehousingInfo{}
- err := XTReadDB().Model(&info).Where("id = ? and status= 1 and org_id = ?", id, orgid).Find(&info).Error
- return info, err
- }
-
- func GetWarehouseInfoByIdTwenty(id int64, orgid int64) (models.WarehousingInfo, error) {
-
- info := models.WarehousingInfo{}
- err := XTReadDB().Model(&info).Where("id = ? and org_id = ?", id, orgid).Find(&info).Error
- return info, err
- }
-
- // 药品加库存
- func ModifyDrugAddInformation(drug_id int64, sum_count int64, orgid int64) (models.BaseDrugLib, error) {
-
- info := models.BaseDrugLib{}
-
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", drug_id, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count + ?", sum_count)).Error
- return info, err
- }
-
- func ModifyDrugAddInformationTwo(drug_id int64, sum_count int64, orgid int64) (models.BaseDrugLib, error) {
-
- info := models.BaseDrugLib{}
-
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", drug_id, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count + ?", sum_count)).Error
-
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", drug_id, orgid).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count + ?", sum_count)).Error
- return info, err
- }
-
- func ModifyDrugReduceInformation(drug_id int64, sum_count int64, orgid int64) (models.BaseDrugLib, error) {
-
- info := models.BaseDrugLib{}
-
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", drug_id, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count - ?", sum_count)).Error
- return info, err
- }
-
- func ModifyDrugReduceInformationTwo(drug_id int64, sum_count int64, orgid int64) (models.BaseDrugLib, error) {
- info := models.BaseDrugLib{}
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", drug_id, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count - ?", sum_count)).Error
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", drug_id, orgid).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count - ?", sum_count)).Error
- return info, err
- }
-
- func ModifyDrugReduceInformationSix(drug_id int64, sum_count int64, orgid int64, batch_retai_price float64) (models.BaseDrugLib, error) {
-
- info := models.BaseDrugLib{}
-
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", drug_id, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count - ?", sum_count)).Error
- err = XTWriteDB().Model(&info).Where("id=? and org_id = ? and status = 1", drug_id, orgid).Update(map[string]interface{}{"batch_retai_price": batch_retai_price}).Error
-
- return info, err
- }
-
- func GetLastDrugwarehouseInfoById(ids []string, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
-
- err = XTReadDB().Where("warehousing_id in(?) and org_id = ? and status = 1", ids, orgid).Find(&info).Error
- return info, err
- }
-
- func GetLastDrugwarehouseInfoByIdTwenty(ids []string, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
-
- err = XTReadDB().Where("warehousing_id in(?) and org_id = ?", ids, orgid).Find(&info).Error
- return info, err
- }
-
- func GetWarhouseOutById(id int64) (models.WarehouseOutInfo, error) {
- info := models.WarehouseOutInfo{}
- err := XTReadDB().Where("id = ? and status = 1", id).Find(&info).Error
- return info, err
- }
-
- func FindeGoodWareHouseOutInfo(id int64, storehouse_id int64, orgid int64) (out []*models.WarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("warehouse_out_id = ? and storehouse_id =? and org_id = ?", id, storehouse_id, orgid).Find(&out).Error
- return out, err
- }
-
- func ModifyWarehouseInfo(id int64, count int64) (models.WarehousingInfo, error) {
- info := models.WarehousingInfo{}
- err = XTWriteDB().Model(&info).Where("id = ? and status = 1", id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
- return info, err
- }
-
- func GetOrgIdList() (template []*models.VMGobalTemplate, err error) {
-
- err = XTReadDB().Where("status = 1").Find(&template).Error
- return template, err
- }
-
- func GetAllGoodList(orgid int64) (good []*models.GoodInfo, err error) {
-
- err = XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&good).Error
-
- return good, err
- }
-
- func GetMobileGoodList(org_id int64) (list []*models.GoodInformationThirty, err error) {
-
- err = XTReadDB().Where("org_id = ? and status =1", org_id).Find(&list).Error
-
- return list, err
- }
-
- func GetAllMobileProjectList(orgid int64) (project []*models.HisProject, err error) {
-
- err = XTReadDB().Where("user_org_id =? and status =1", orgid).Find(&project).Error
-
- return project, err
- }
-
- func ModifyGoodAddInformationSeven(good_id int64, sum_count int64, orgid int64) (models.GoodInfo, error) {
-
- info := models.GoodInfo{}
-
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", good_id, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
-
- return info, err
- }
-
- func GetStockCountWarehouseInfoById(good_id int64) (info []*models.WarehousingInfo, err error) {
-
- db := XTReadDB().Where("status = 1")
- if good_id > 0 {
- db = db.Where("good_id = ?", good_id)
- }
- err = db.Find(&info).Error
- return info, err
- }
-
- func GetDrugStockCountWarehoseInfoById(drug_id int64) (info []*models.DrugWarehouseInfo, err error) {
-
- db := XTReadDB().Model(&info).Where("status = 1")
- if drug_id > 0 {
- db = db.Where("drug_id = ?", drug_id)
- }
- err = db.Find(&info).Error
- return info, err
- }
-
- func UpdateModifyDrugInfoById(drug_id int64, sum_count int64, orgid int64) (models.BaseDrugLib, error) {
- lib := models.BaseDrugLib{}
- err := XTWriteDB().Model(&lib).Where("id = ? and org_id = ? and status = 1", drug_id, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
- return lib, err
- }
-
- func GetWarehouseBySecondWarehouseId(is_sys int64, sencond_wahouse_id int64, orgid int64, record_date int64) (*models.Warehousing, error) {
- info := models.Warehousing{}
- err := XTReadDB().Where("is_sys= ? and second_warehouse_id=? and status = 1 and org_id = ? and warehousing_time = ?", is_sys, sencond_wahouse_id, orgid, record_date).Find(&info).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &info, nil
- }
-
- func GetLastWarehouseById(is_sys int64, sencond_wahouse_id int64, orgid int64, record_date int64) (models.Warehousing, error) {
-
- info := models.Warehousing{}
- err := XTReadDB().Where("is_sys = ? and second_warehouse_id=? and status = 1 and org_id = ? and warehousing_time = ?", is_sys, sencond_wahouse_id, orgid, record_date).Last(&info).Error
- return info, err
- }
-
- func GetDrugWarehouseBySyS(orgid int64, is_sys int64, sencond_wahouse_id int64, record_date int64) (*models.DrugWarehouseOut, error) {
-
- out := models.DrugWarehouseOut{}
- err := XTReadDB().Where("org_id = ? and is_sys = ? and second_warehouse_id = ? and warehouse_out_time = ? and status = 1", orgid, is_sys, sencond_wahouse_id, record_date).Find(&out).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &out, nil
- }
-
- func GetLastDrugWarehouseOutById(is_sys int64, sencond_wahouse_id int64, orgid int64, record_date int64) (models.DrugWarehouseOut, error) {
- info := models.DrugWarehouseOut{}
- err := XTReadDB().Where("is_sys = ? and second_warehouse_id = ? and status = 1 and org_id =? and warehouse_out_time = ?", is_sys, sencond_wahouse_id, orgid, record_date).Last(&info).Error
- return info, err
- }
-
- func GetDrugWarehouseingBySys(is_sys int64, second_warehouse_id int64, orgid int64, record_date int64) (*models.DrugWarehouse, error) {
-
- info := models.DrugWarehouse{}
- err := XTReadDB().Where("is_sys = ? and second_warehouse_id = ? and status = 1 and org_id = ? and warehousing_time = ?", is_sys, second_warehouse_id, orgid, record_date).Find(&info).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &info, nil
- }
-
- func CreateDrugWaresing(warehouse models.DrugWarehouse) error {
- err := XTWriteDB().Create(&warehouse).Error
- return err
- }
-
- func GetLastDrugWarehouseBySys(is_sys int64, second_warehouse_id int64, orgid int64, record_date int64) (models.DrugWarehouse, error) {
-
- info := models.DrugWarehouse{}
- err := XTReadDB().Where("is_sys = ? and second_warehouse_id = ? and status = 1 and org_id = ? and warehousing_time = ?", is_sys, second_warehouse_id, orgid, record_date).Last(&info).Error
- return info, err
- }
-
- func ModifyGoodReduceInformationTwenty(good_id int64, waresing_count int64, sum_count int64, orgid int64) (models.GoodInfo, error) {
-
- info := models.GoodInfo{}
-
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", good_id, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count - ?", sum_count)).Error
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", good_id, orgid).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count - ?", waresing_count)).Error
- return info, err
- }
-
- func ModifyGoodReduceInformationTwentyOne(good_id int64, waresing_count int64, sum_count int64, orgid int64) (models.GoodInfo, error) {
-
- info := models.GoodInfo{}
-
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", good_id, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count + ?", sum_count)).Error
- err = XTWriteDB().Model(&info).Where("id = ? and org_id = ? and status = 1", good_id, orgid).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count + ?", waresing_count)).Error
- return info, err
- }
-
- func UpdateMedicalSumCount(drug_id int64, sum_count int64, sum_in_count int64, orgid int64) error {
- tx := XTWriteDB().Begin()
- err := tx.Model(&models.BaseDrugLib{}).Where("id = ? and org_id = ? and status = 1", drug_id, orgid).Update(map[string]interface{}{"sum_count": sum_count, "sum_in_count": sum_in_count}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- tx.Commit()
- return err
- }
-
- func UpdateNewMedicalSumCount(drug_id int64, sum_count int64, sum_in_count int64, orgid int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.BaseDrugLib{}).Where("id = ? and org_id = ? and status = 1", drug_id, orgid).Update(map[string]interface{}{"sum_count": sum_count, "sum_in_count": sum_in_count}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpdateMedicalSumCountOne(drug_id int64, sum_count int64, orgid int64) error {
- tx := XTWriteDB().Begin()
- err := tx.Model(&models.BaseDrugLib{}).Where("id = ? and org_id = ? and status = 1", drug_id, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- tx.Commit()
- return err
- }
-
- //func UpdateMedicalSumCountTX(drug_id int64, sum_count int64, sum_in_count int64, orgid int64,tx *gorm.DB) error {
- // err := tx.Model(&models.BaseDrugLib{}).Where("id = ? and org_id = ? and status = 1", drug_id, orgid).Update(map[string]interface{}{"sum_count": sum_count, "sum_in_count": sum_in_count}).Error
- // return err
- //}
-
- func UpdateGoodByGoodId(good_id int64, sum_count int64, sum_in_count int64, orgid int64) error {
- err := XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", good_id, orgid).Update(map[string]interface{}{"sum_count": sum_count, "sum_in_count": sum_in_count}).Error
- return err
- }
-
- func GetDrugDetailSummary(startime int64, endtime int64, keyword string, limit int64, page int64, orgid int64) (adviceinfo []*models.BloodHisDoctorAdviceInfo, total int64, err error) {
-
- db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_base_drug as x d")
- fmt.Println(table)
- if startime > 0 {
- db = db.Where("x.advice_date >= ?", startime)
- }
-
- if endtime > 0 {
- db = db.Where("x.advice_date <= ?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
-
- if len(keyword) > 0 {
- likeKey := "%" + keyword + "%"
- db = db.Select("x.patient_id,x.user_org_id,x.id,x.advice_date,x.advice_date,x.prescribing_number_unit,x.drug_id,x.prescribing_number").Joins("left join sgj_xt.xt_base_drug as d on d.id = x.drug_id").Where("d.drug_name like ?", likeKey)
- }
-
- offset := (page - 1) * limit
- err = db.Count(&total).Offset(offset).Limit(limit).Order("x.created_time desc").Group("x.drug_id").Scan(&adviceinfo).Error
- return adviceinfo, total, err
- }
-
- func GetDrugDetailSummaryOne(startime int64, endtime int64, keyword string, limit int64, page int64, orgid int64) (adviceinfo []*models.BloodHisDoctorAdviceInfo, total int64, err error) {
-
- db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
- table := XTReadDB().Table("xt_base_drug as x d")
- fmt.Println(table)
- if startime > 0 {
- db = db.Where("x.advice_date >= ?", startime)
- }
-
- if endtime > 0 {
- db = db.Where("x.advice_date <= ?", endtime)
- }
-
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
-
- if len(keyword) > 0 {
- likeKey := "%" + keyword + "%"
- db = db.Select("x.patient_id,x.user_org_id,x.id,x.advice_date,x.advice_date,x.prescribing_number_unit,x.drug_id,x.prescribing_number").Joins("left join sgj_xt.xt_base_drug as d on d.id = x.drug_id").Where("d.drug_name like ?", likeKey)
- }
-
- err = db.Order("x.created_time desc").Scan(&adviceinfo).Error
- return adviceinfo, total, err
- }
-
- func GetAllDrugSummary(orgid int64) (drug []*models.BaseDrugLib, err error) {
-
- err = XTReadDB().Where("org_id = ? and status = 1 and is_user = 1", orgid).Find(&drug).Error
- return drug, err
- }
-
- func GetGoodDetailSummary(startime int64, endtime int64, keyword string, limit int64, page int64, orgid int64) (project []*models.BloodHisPrescriptionProject, total int64, err error) {
-
- db := XTReadDB().Table("his_prescription_project as x").Where("x.status = 1 and x.type = 3")
- table := XTReadDB().Table("xt_good_information as d")
- fmt.Println(table)
- if startime > 0 {
- db = db.Where("x.record_date >= ?", startime)
- }
-
- if endtime > 0 {
- db = db.Where("x.record_date <= ?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
-
- if len(keyword) > 0 {
- likeKey := "%" + keyword + "%"
- db = db.Select("x.id,x.project_id,x.user_org_id,x.patient_id,x.record_date,x.count").Joins("left join xt_good_information as d on d.id = x.project_id").Where("d.good_name like ?", likeKey).Group("d.id")
- }
-
- offset := (page - 1) * limit
- err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Group("x.project_id").Scan(&project).Error
- return project, total, err
- }
-
- func GetGoodDetailSummaryOne(startime int64, endtime int64, keyword string, limit int64, page int64, orgid int64) (project []*models.BloodHisPrescriptionProject, total int64, err error) {
-
- db := XTReadDB().Table("his_prescription_project as x").Where("x.status = 1 and x.type = 3")
- table := XTReadDB().Table("xt_good_information as d")
- fmt.Println(table)
- if startime > 0 {
- db = db.Where("x.record_date >= ?", startime)
- }
-
- if endtime > 0 {
- db = db.Where("x.record_date <= ?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
-
- if len(keyword) > 0 {
- likeKey := "%" + keyword + "%"
- db = db.Select("x.id,x.project_id,x.user_org_id,x.patient_id,x.record_date,x.count").Joins("left join xt_good_information as d on d.id = x.project_id").Where("d.good_name like ? ", likeKey).Group("d.id")
- }
-
- err = db.Order("x.ctime desc").Group("x.id").Scan(&project).Error
- return project, total, err
- }
-
- func GeAllGoodInformation(orgid int64) (good []*models.GoodInfo, err error) {
-
- err = XTReadDB().Where("org_id =? and status = 1 and is_user = 1", orgid).Find(&good).Error
- return good, err
- }
-
- func GetStockSettingIsExsit(orgid int64) (*models.XtStockSetting, error) {
-
- setting := models.XtStockSetting{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&setting).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &setting, nil
- }
-
- func CreateStockSetting(setting models.XtStockSetting) error {
-
- err := XTWriteDB().Create(&setting).Error
-
- return err
- }
-
- func UpdateStockSetting(orgid int64, setting models.XtStockSetting) error {
-
- err := XTWriteDB().Model(&models.XtStockSetting{}).Where("user_org_id = ? and status = 1", orgid).Update(map[string]interface{}{"is_type": setting.IsType}).Error
- return err
- }
-
- func FindStockSettingById(orgid int64) (models.XtStockSetting, error) {
-
- setting := models.XtStockSetting{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&setting).Error
- return setting, err
- }
-
- func GetAutoStockOutById(good_id int64, record_date int64, orgid int64, patient_id int64) (models.BloodAutomaticReduceDetail, error) {
-
- detail := models.BloodAutomaticReduceDetail{}
- err := XTReadDB().Where("good_id = ? and record_time = ? and org_id = ? and status = 1 and patient_id = ?", good_id, record_date, orgid, patient_id).Find(&detail).Error
- return detail, err
- }
-
- func GetAutoWarehouseOutList(good_id int64, record_date int64, orgid int64, patient_id int64) (models.WarehouseOutInfoNight, error) {
-
- detail := models.WarehouseOutInfoNight{}
- err := XTReadDB().Where("good_id = ? and sys_record_time = ? and org_id = ? and status = 1 and patient_id = ?", good_id, record_date, orgid, patient_id).Find(&detail).Error
- return detail, err
- }
-
- func GetAdviceConfig(orgid int64) (*models.XtAdviceSetting, error) {
-
- setting := models.XtAdviceSetting{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&setting).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &setting, nil
- }
-
- func CreateAdviceSetting(setting models.XtAdviceSetting) error {
-
- err := XTWriteDB().Create(&setting).Error
- return err
- }
-
- func UpdateAdviceSetting(orgid int64, setting models.XtAdviceSetting) error {
-
- err := XTWriteDB().Model(&setting).Where("user_org_id = ? and status = 1", orgid).Update(map[string]interface{}{"is_advice_open": setting.IsAdviceOpen, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func FindAdviceSettingById(orgid int64) (models.XtAdviceSetting, error) {
- setting := models.XtAdviceSetting{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&setting).Error
- return setting, err
- }
-
- func GetPrescriptionConfig(orgid int64) (*models.XtPrescriptionConfig, error) {
-
- config := models.XtPrescriptionConfig{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &config, nil
- }
-
- func CreatePrescriptionConfig(prescriptionConfig models.XtPrescriptionConfig) error {
-
- err := XTWriteDB().Create(&prescriptionConfig).Error
- return err
- }
-
- func UpdatePrescriptionConfig(orgid int64, config models.XtPrescriptionConfig) error {
-
- err := XTWriteDB().Model(&config).Where("user_org_id = ? and status = 1", orgid).Update(map[string]interface{}{"is_open": config.IsOpen, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func FindPrescriptionConfigById(orgid int64) (models.XtPrescriptionConfig, error) {
- config := models.XtPrescriptionConfig{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
-
- return config, err
- }
-
- func UpdateWarehouseInfoTwentyFive(maxNumber int64, drugid int64, orgID int64, storehouse_id int64, drup *models.XtBaseDrug) (err error) {
-
- var deliver_number int64 = 0
- var stock_number int64 = 0
-
- deliver_number = maxNumber
- // 根据先进先出原则,查询最先入库的批次,进行出库
- // 如果没有对应的库存,则报错
- //开启事物
-
- warehouse, err := FindLastDrugWarehousingInfoByID(drugid, storehouse_id)
-
- if err != nil {
- return err
- }
-
- // 将该批次的剩余库存数量转换为拆零数量
- stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
-
- // 当库存数量大于或等于出库数量的话,则正常出库该批次
- if stock_number >= deliver_number {
-
- var maxNumber int64 = 0
- var minNumber int64 = 0
- var stock_max_number int64 = 0
- stock_max_number = warehouse.StockMaxNumber
-
- maxNumber = deliver_number / drup.MinNumber
- minNumber = deliver_number % drup.MinNumber
-
- if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
- minNumber = maxNumber
- }
-
- if drup.MaxUnit != drup.MinUnit {
- if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
- return errors.New("库存数量不足")
- }
- }
-
- warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
-
- if warehouse.StockMaxNumber < 0 {
- warehouse.StockMaxNumber = 0
- }
- if warehouse.StockMinNumber < 0 {
- warehouse.StockMinNumber = 0
- }
-
- warehouse.Mtime = time.Now().Unix()
-
- if warehouse.StockMinNumber < minNumber {
-
- warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
- warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
- } else {
- if minNumber > 0 {
- if minNumber == 1 && maxNumber == 1 && drup.MaxUnit != drup.MinUnit {
- warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
- } else {
- warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
- }
- }
-
- if minNumber == 0 && maxNumber != 1 {
- warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
- }
-
- }
-
- if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
- warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
- if warehouse.StockMinNumber == 0 {
- warehouse.StockMaxNumber = stock_max_number
- }
- }
-
- if drup.MaxUnit != drup.MinUnit {
- if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
- return errors.New("库存数量不足")
- }
- }
- if warehouse.StockMinNumber <= 0 {
- warehouse.StockMinNumber = 0
- }
-
- errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
- fmt.Println(errThree)
-
- //查询默认仓库
- houseConfig, _ := GetAllStoreHouseConfig(orgID)
- //查询默认仓库剩余多少库存
- list, _ := GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgID, warehouse.DrugId)
- var sum_count int64
- var sum_in_count int64
- for _, it := range list {
- baseDrug, _ := GetBaseDrugMedical(it.DrugId)
- if it.MaxUnit == baseDrug.MaxUnit {
- it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- sum_count += it.StockMaxNumber + it.StockMinNumber
- sum_in_count += it.WarehousingCount
- }
- }
- UpdateMedicalSumCount(warehouse.DrugId, sum_count, sum_in_count, orgID)
-
- return nil
-
- } else {
-
- warehouse.StockMaxNumber = 0
- warehouse.StockMinNumber = 0
- warehouse.Mtime = time.Now().Unix()
-
- errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
- fmt.Println(errThree)
-
- //查询默认仓库
- houseConfig, _ := GetAllStoreHouseConfig(orgID)
- //查询默认仓库剩余多少库存
- list, _ := GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgID, warehouse.DrugId)
- var sum_count int64
- var sum_in_count int64
- for _, it := range list {
- baseDrug, _ := GetBaseDrugMedical(it.DrugId)
- if it.MaxUnit == baseDrug.MaxUnit {
- it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- sum_count += it.StockMaxNumber + it.StockMinNumber
- sum_in_count += it.WarehousingCount
- }
- }
- UpdateMedicalSumCount(warehouse.DrugId, sum_count, sum_in_count, orgID)
- if errThree != nil {
- return errThree
- }
- // 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
- prescribingNumber_two_temp := deliver_number - stock_number
-
- UpdateWarehouseInfoTwentyFive(prescribingNumber_two_temp, drugid, orgID, storehouse_id, drup)
- }
- return
- }
-
- func UpdateWarehouseInfoTentyFour(count int64, id int64) error {
-
- err := writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("id = ? status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number - ?", count)).Error
-
- return err
- }
-
- func UpdateWarehouseInfoTentyThree(count int64, id int64) error {
-
- err := writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("id = ? status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number - ?", count)).Error
-
- return err
- }
-
- func GetDrugOpenConfig(orgid int64) (*models.DrugOutConfig, error) {
-
- config := models.DrugOutConfig{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &config, nil
- }
-
- func GetDrugOpenConfigOne(orgid int64) (models.DrugOutConfig, error) {
-
- config := models.DrugOutConfig{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).First(&config).Error
-
- return config, err
- }
-
- func FindXTHisRecordByOrgIdSix(org_id int64) (models.XtHisConfig, error) {
-
- config := models.XtHisConfig{}
- err = readDb.Model(&models.XtHisConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&config).Error
- return config, err
- }
-
- func CreateDrugOutConfig(config models.DrugOutConfig) error {
-
- err := XTWriteDB().Create(&config).Error
- return err
- }
-
- func UpdateDrugOutConfig(orgid int64, drug_out_open int64) error {
-
- err := XTWriteDB().Model(&models.DrugOutConfig{}).Where("user_org_id = ? and status = 1", orgid).Update(map[string]interface{}{"is_open": drug_out_open}).Error
- return err
- }
-
- func FindDrugOutConfigById(orgid int64) (models.DrugOutConfig, error) {
-
- config := models.DrugOutConfig{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
- return config, err
- }
-
- func FindeDrugSettleConfigById(orgid int64) (models.HisSettleStockConfig, error) {
- config := models.HisSettleStockConfig{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
- return config, err
- }
-
- func UpdatedWarehouseOut(id int64) error {
-
- err := XTWriteDB().Model(&models.WarehouseOut{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
- err = XTWriteDB().Model(&models.WarehouseOutInfo{}).Where("warehouse_out_id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
- return err
- }
-
- func UpdatedNewWarehouseOut(id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.WarehouseOut{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.WarehouseOutInfo{}).Where("warehouse_out_id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpdatedSigleWarehouseOutInfo(id int64, info *models.WarehouseOutInfo) error {
-
- tx := XTWriteDB().Begin()
- err := tx.Model(&models.WarehouseOutInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"warehouse_info_id": info.WarehouseInfotId}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- tx.Commit()
- return err
-
- }
-
- func UpdatedNewSigleWarehouseOutInfo(id int64, info *models.WarehouseOutInfo, tx *gorm.DB) error {
-
- err := tx.Model(&models.WarehouseOutInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"warehouse_info_id": info.WarehouseInfotId}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
-
- }
-
- func GetLastGoodWarehouseOutInfo(orgid int64, id int64, tx *gorm.DB) (info []*models.WarehouseOutInfo, err error) {
-
- err = tx.Where("org_id = ? and status = 1 and warehouse_out_id = ?", orgid, id).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
- return tx.Where("org_id=? and status = 1", orgid).Preload("GoodsType", "status = 1")
- }).Find(&info).Error
-
- if err != nil {
- tx.Rollback()
- return info, err
- }
- return info, err
- }
-
- func GetLastGoodWarehouseOutInfoById(orgid int64) (models.WarehouseOutInfo, error) {
- info := models.WarehouseOutInfo{}
- err := XTReadDB().Where("org_id = ? and status = 1", orgid).Last(&info).Error
- return info, err
- }
-
- func ModifyWarehouseOutInfo(id int64, info *models.WarehouseOutInfo, tx *gorm.DB) error {
-
- err := tx.Model(&models.WarehouseOutInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"good_id": info.GoodId, "good_type_id": info.GoodTypeId, "count": info.Count, "price": info.Price, "total_price": info.TotalPrice, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "remark": info.Remark, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "number": info.Number, "license_number": info.LicenseNumber, "storehouse_id": info.StorehouseId, "admin_user_id": info.AdminUserId, "buy_price": info.BuyPrice, "stock_count": info.StockCount, "register_number": info.RegisterNumber}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpdateWarehouseOutFlow(info models.VmStockFlow, id int64) error {
-
- err := XTWriteDB().Model(&models.VmStockFlow{}).Where("warehouse_out_detail_id = ? and status = 1", id).Update(map[string]interface{}{"good_id": info.GoodId, "number": info.Number, "license_number": info.LicenseNumber, "count": info.Count, "manufacturer": info.Manufacturer, "dealer": info.Dealer, "price": info.Price, "expire_date": info.ExpireDate, "product_date": info.ProductDate, "storehouse_id": info.StorehouseId, "admin_user_id": info.AdminUserId, "buy_price": info.BuyPrice, "stock_count": info.StockCount}).Error
- return err
- }
-
- func GetLastGoodWarehouseOutTwenty(orgid int64) (models.WarehouseOut, error) {
- out := models.WarehouseOut{}
- err := XTReadDB().Where("org_id = ? and status = 1", orgid).Last(&out).Error
- return out, err
- }
-
- func GetLastGoodWarehouseOutTwentyOne(orgid int64, tx *gorm.DB) (models.WarehouseOut, error) {
- out := models.WarehouseOut{}
- err := tx.Where("org_id = ? and status = 1", orgid).Last(&out).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return out, err
- }
- }
- return out, err
- }
-
- func UpdateaGoodWarehouseInfo(count int64, good_id int64, orgid int64, warehouse_info_id int64) error {
-
- ut := writeDb.Begin()
- err := ut.Model(&models.WarehousingInfo{}).Where("good_id = ? and org_id = ? and status = 1 and id = ?", good_id, orgid, warehouse_info_id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- ut.Commit()
- return err
-
- }
-
- func UpdateaNewGoodWarehouseInfo(count int64, good_id int64, orgid int64, warehouse_info_id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.WarehousingInfo{}).Where("good_id = ? and org_id = ? and status = 1 and id = ?", good_id, orgid, warehouse_info_id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
-
- }
-
- func ModifyGoodWarehouseOut(id int64) error {
- ut := writeDb.Begin()
- err := ut.Model(&models.WarehouseOut{}).Where("id = ? and status =1", id).Update(map[string]interface{}{"is_check": 2}).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- err = ut.Model(&models.WarehouseOutInfo{}).Where("warehouse_out_id in(?) and status = 1", id).Update(map[string]interface{}{"is_check": 2}).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- err = ut.Model(&models.VmStockFlow{}).Where("warehouse_out_id in(?) and status = 1", id).Update(map[string]interface{}{"status": 0, "is_check": 2}).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- err = ut.Model(&models.XtWarehouseFlushInfo{}).Where("warehouse_out_id in(?) and status = 1", id).Update(map[string]interface{}{"status": 0}).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- ut.Commit()
- return err
- }
-
- func ModifyNewGoodWarehouseOut(id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.WarehouseOut{}).Where("id = ? and status =1", id).Update(map[string]interface{}{"is_check": 2}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.WarehouseOutInfo{}).Where("warehouse_out_id in(?) and status = 1", id).Update(map[string]interface{}{"is_check": 2}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.VmStockFlow{}).Where("warehouse_out_id in(?) and status = 1", id).Update(map[string]interface{}{"status": 0, "is_check": 2}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.XtWarehouseFlushInfo{}).Where("warehouse_out_id in(?) and status = 1", id).Update(map[string]interface{}{"status": 0}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func GetGoodWarehouseInfoById(waresing_id int64, orgid int64) (info []*models.VmWarehousingInfoSix, err error) {
-
- err = XTReadDB().Where("org_id = ? and status = 1 and warehousing_id = ?", orgid, waresing_id).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
- return XTReadDB().Where("org_id=? and status = 1", orgid).Preload("GoodsType", "status = 1")
- }).Find(&info).Error
- return info, err
- }
-
- func GetNewGoodWarehouseInfoById(waresing_id int64, orgid int64, tx *gorm.DB) (info []*models.VmWarehousingInfoSix, err error) {
-
- err = tx.Where("org_id = ? and status = 1 and warehousing_id = ?", orgid, waresing_id).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
- return tx.Where("org_id=? and status = 1", orgid).Preload("GoodsType", "status = 1")
- }).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- return info, err
- }
-
- func FindLastWarehousing(order string) (info models.Warehousing, err error) {
- err = readDb.Model(&models.Warehousing{}).Where("warehousing_order = ? AND status = 1", order).Last(&info).Error
-
- return info, err
-
- }
-
- func UpdateWarehouseDetail(info *models.WarehousingInfo, id int64) error {
-
- err := XTWriteDB().Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"good_id": info.GoodId, "good_type_id": info.GoodTypeId, "number": info.Number, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "warehousing_count": info.WarehousingCount, "warehousing_unit": info.WarehousingUnit, "price": info.Price, "total_price": info.TotalPrice, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "remark": info.Remark, "license_number": info.LicenseNumber, "packing_price": info.PackingPrice, "register_number": info.RegisterNumber, "storehouse_id": info.StorehouseId, "good_code": info.GoodCode}).Error
- return err
- }
-
- func UpdateNewWarehouseDetail(info *models.WarehousingInfo, id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"good_id": info.GoodId, "good_type_id": info.GoodTypeId, "number": info.Number, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "warehousing_count": info.WarehousingCount, "warehousing_unit": info.WarehousingUnit, "price": info.Price, "total_price": info.TotalPrice, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "remark": info.Remark, "license_number": info.LicenseNumber, "packing_price": info.PackingPrice, "register_number": info.RegisterNumber, "storehouse_id": info.StorehouseId, "good_code": info.GoodCode}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpdateCheckWarehouseInfo(id int64, checker int64) error {
-
- tx := XTWriteDB().Begin()
- err := tx.Model(&models.Warehousing{}).Where("id =? and status = 1", id).Update(map[string]interface{}{"is_check": 1, "checker": checker}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- tx.Commit()
- return err
- }
-
- func UpdateNewCheckWarehouseInfo(id int64, checker int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.Warehousing{}).Where("id =? and status = 1", id).Update(map[string]interface{}{"is_check": 1, "checker": checker}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func GetWarehouseInfoList(id int64, orgid int64) (info []*models.WarehousingInfo, err error) {
-
- err = XTReadDB().Where("warehousing_id = ? and org_id = ? and status = 1", id, orgid).Find(&info).Error
- return info, err
- }
-
- func GetNewWarehouseInfoList(id int64, orgid int64, tx *gorm.DB) (info []*models.WarehousingInfo, err error) {
-
- err = tx.Where("warehousing_id = ? and org_id = ? and status = 1", id, orgid).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- return info, err
- }
-
- func UpdateWarehouseInfoByIdListThree(count int64, id int64) error {
-
- tx := XTWriteDB().Begin()
- err := tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"stock_count": count}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- tx.Commit()
- return err
- }
-
- func UpdateNewWarehouseInfoByIdListThree(count int64, id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"stock_count": count}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func FindLastWarehousingSix(org_id int64) (info models.Warehousing, err error) {
- err = readDb.Model(&models.Warehousing{}).Where("org_id = ? AND status = 1", org_id).Last(&info).Error
-
- return info, err
-
- }
-
- func FindNewLastWarehousingSix(org_id int64, tx *gorm.DB) (info models.Warehousing, err error) {
-
- err = tx.Model(&models.Warehousing{}).Where("org_id = ? AND status = 1", org_id).Last(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- return info, err
-
- }
-
- func FindLastWarehousingSeven(org_id int64) (info models.DrugWarehouse, err error) {
- err = readDb.Model(&models.DrugWarehouse{}).Where("org_id = ? AND status = 1", org_id).Last(&info).Error
-
- return info, err
-
- }
-
- func FindNewLastWarehousingSeven(org_id int64, tx *gorm.DB) (info models.DrugWarehouse, err error) {
-
- err = tx.Model(&models.DrugWarehouse{}).Where("org_id = ? AND status = 1", org_id).Last(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- return info, err
-
- }
-
- func FindDrugWarehouseInfoListById(id int64, orgid int64) (info []*models.DrugWarehouseInfoTwenty, err error) {
-
- err = XTReadDB().Where("warehousing_id = ? and org_id = ? and status = 1", id, orgid).Preload("BaseDrugLib", "status = 1 and org_id =?", orgid).Find(&info).Error
- return info, err
- }
-
- func FindNewDrugWarehouseInfoListById(id int64, orgid int64, tx *gorm.DB) (info []*models.DrugWarehouseInfoTwenty, err error) {
-
- err = tx.Where("warehousing_id = ? and org_id = ? and status = 1", id, orgid).Preload("BaseDrugLib", "status = 1 and org_id =?", orgid).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- return info, err
- }
-
- func CreatedWarehouseing(info *models.DrugWarehouseInfo) error {
-
- err := XTWriteDB().Create(&info).Error
- return err
- }
-
- func CreatedNewWarehouseing(info *models.DrugWarehouseInfo, tx *gorm.DB) error {
-
- err := tx.Create(&info).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpdateWarehouseing(info *models.DrugWarehouseInfo) error {
-
- err := XTWriteDB().Save(&info).Error
- return err
- }
-
- func UpdateNewWarehouseing(info *models.DrugWarehouseInfo, tx *gorm.DB) error {
-
- err := tx.Save(&info).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func CheckWarehousingInfo(id int64, orgid int64, checker int64) error {
- tx := XTWriteDB().Begin()
- err := tx.Model(&models.DrugWarehouse{}).Where("id = ? and org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"is_check": 1, "checker": checker}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- tx.Commit()
- return err
- }
-
- func CheckNewWarehousingInfo(id int64, orgid int64, checker int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouse{}).Where("id = ? and org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"is_check": 1, "checker": checker}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func GetWarehousingInfoByList(id int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
-
- err = XTReadDB().Where("warehousing_id = ? and org_id = ? and status = 1", id, orgid).Find(&info).Error
- return info, err
- }
-
- func GetNewWarehousingInfoByList(id int64, orgid int64, tx *gorm.DB) (info []*models.DrugWarehouseInfo, err error) {
-
- err = tx.Where("warehousing_id = ? and org_id = ? and status = 1", id, orgid).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- return info, err
- }
-
- func AddDrugWarehouseStockMaxNumber(count int64, id int64) error {
- tx := XTWriteDB().Begin()
- err := tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- tx.Commit()
- return err
- }
-
- func AddNewDrugWarehouseStockMaxNumber(count int64, id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
-
- return err
- }
-
- func UpdateWarehousingInfoFlow(id int64, orgid int64) error {
- tx := XTWriteDB().Begin()
- err := tx.Model(&models.DrugFlow{}).Where("warehousing_detail_id = ? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"status": 0}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- tx.Commit()
- return err
- }
-
- func UpdateNewWarehousingInfoFlow(id int64, orgid int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugFlow{}).Where("warehousing_detail_id = ? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"status": 0}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func AddDrugWarehouseStockMinNumber(count int64, id int64) error {
- tx := XTWriteDB().Begin()
- err := XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
- tx.Commit()
- return err
- }
-
- func AddNewDrugWarehouseStockMinNumber(count int64, id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func ReturnCheckWarehouseingInfo(id int64, orgid int64) error {
- tx := XTWriteDB().Begin()
- err := XTWriteDB().Model(&models.DrugWarehouse{}).Where("id = ? and status = 1 and org_id = ?", id, orgid).Update(map[string]interface{}{"is_check": 2}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("warehousing_id = ? and status = 1 and org_id = ?", id, orgid).Update(map[string]interface{}{"is_check": 2}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- tx.Commit()
- return err
- }
-
- func ReturnNewCheckWarehouseingInfo(id int64, orgid int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouse{}).Where("id = ? and status = 1 and org_id = ?", id, orgid).Update(map[string]interface{}{"is_check": 2}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.DrugWarehouseInfo{}).Where("warehousing_id = ? and status = 1 and org_id = ?", id, orgid).Update(map[string]interface{}{"is_check": 2}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func AddDrugReturnWarehouseStockMaxNumber(count int64, id int64) error {
- tx := XTWriteDB().Begin()
- err := tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number - ?", count)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 2}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- tx.Commit()
- return err
- }
-
- func AddNewDrugReturnWarehouseStockMaxNumber(count int64, id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number - ?", count)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 2}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func AddDrugReturnWarehouseStockMinNumber(count int64, id int64) error {
- tx := XTWriteDB().Begin()
- err := tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number - ?", count)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 2}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- tx.Commit()
- return err
- }
-
- func AddNewDrugReturnWarehouseStockMinNumber(count int64, id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number - ?", count)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 2}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpdateDrugWarehouseInfoTwenty(id int64, info *models.DrugWarehouseInfo) error {
-
- err := XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"drug_id": info.DrugId, "number": info.Number, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "warehousing_count": info.WarehousingCount, "price": info.Price, "total_price": info.TotalPrice, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "remark": info.Remark, "retail_price": info.RetailPrice, "max_unit": info.MaxUnit, "min_unit": info.MinUnit, "drug_code": info.DrugCode, "batch_number": info.BatchNumber}).Error
- return err
- }
-
- func UpdateNewDrugWarehouseInfoTwenty(id int64, info *models.DrugWarehouseInfo, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"drug_id": info.DrugId, "number": info.Number, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "warehousing_count": info.WarehousingCount, "price": info.Price, "total_price": info.TotalPrice, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "remark": info.Remark, "retail_price": info.RetailPrice, "max_unit": info.MaxUnit, "min_unit": info.MinUnit, "drug_code": info.DrugCode, "batch_number": info.BatchNumber}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpdatedDrugWarehouseInfo(info *models.DrugWarehouseOutInfo, id int64) error {
-
- err := XTWriteDB().Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"drug_id": info.DrugId, "count": info.Count, "count_unit": info.CountUnit, "price": info.Price, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "remark": info.Remark, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "retail_price": info.RetailPrice, "retail_total_price": info.RetailTotalPrice, "number": info.Number, "batch_number": info.BatchNumber, "admin_user_id": info.AdminUserId, "last_price": info.LastPrice, "stock_count": info.StockCount, "storehouse_id": info.StorehouseId, "patient_id": info.PatientId, "class_type": info.ClassType}).Error
- return err
- }
-
- func UpdatedNewDrugWarehouseInfo(info *models.DrugWarehouseOutInfo, id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"drug_id": info.DrugId, "count": info.Count, "count_unit": info.CountUnit, "price": info.Price, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "remark": info.Remark, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "retail_price": info.RetailPrice, "retail_total_price": info.RetailTotalPrice, "number": info.Number, "batch_number": info.BatchNumber, "admin_user_id": info.AdminUserId, "last_price": info.LastPrice, "stock_count": info.StockCount, "storehouse_id": info.StorehouseId, "patient_id": info.PatientId, "class_type": info.ClassType}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpdatedSelfDrugWarehouseInfo(info *models.XtSelfDrugWarehouseOutInfo, id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.XtSelfDrugWarehouseOutInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"drug_id": info.DrugId, "count": info.Count, "count_unit": info.CountUnit, "price": info.Price, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "remark": info.Remark, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "retail_price": info.RetailPrice, "retail_total_price": info.RetailTotalPrice, "number": info.Number, "batch_number": info.BatchNumber, "admin_user_id": info.AdminUserId, "last_price": info.LastPrice, "stock_count": info.StockCount, "storehouse_id": info.StorehouseId, "patient_id": info.PatientId, "class_type": info.ClassType}).Error
- if err != gorm.ErrRecordNotFound {
- return err
- }
- return err
- }
-
- func GetDrugLastWarehouseOut(orgid int64) (models.DrugWarehouseOut, error) {
- out := models.DrugWarehouseOut{}
- err := XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&out).Error
- return out, err
- }
-
- func GetNewDrugLastWarehouseOut(orgid int64, tx *gorm.DB) (models.DrugWarehouseOut, error) {
- out := models.DrugWarehouseOut{}
- err := tx.Where("org_id = ? and status = 1", orgid).Find(&out).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return out, err
- }
- }
- return out, err
- }
-
- func GetSelfDrugLastWarehouseOut(orgid int64, tx *gorm.DB) (models.XtSelfDrugWarehouseOut, error) {
- out := models.XtSelfDrugWarehouseOut{}
- err := tx.Where("org_id = ? and status = 1", orgid).Find(&out).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return out, err
- }
-
- }
- return out, err
- }
-
- func GetSelfDrugLastWarehouseOutOne(id int64, tx *gorm.DB) (models.XtSelfDrugWarehouseOut, error) {
- out := models.XtSelfDrugWarehouseOut{}
- err := tx.Where("id = ? and status = 1", id).Find(&out).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return out, err
- }
-
- }
- return out, err
- }
-
- func GetDrugWarehouseOutListById(warehouse_out_id int64, orgId int64) (info []*models.DrugWarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("warehouse_out_id = ? and org_id =? and status = 1", warehouse_out_id, orgId).Preload("BaseDrugLib", "status=1").Find(&info).Error
- return info, err
- }
-
- func GetNewDrugWarehouseOutListById(warehouse_out_id int64, orgId int64, tx *gorm.DB) (info []*models.DrugWarehouseOutInfo, err error) {
-
- err = tx.Where("warehouse_out_id = ? and org_id =? and status = 1", warehouse_out_id, orgId).Preload("BaseDrugLib", "status=1").Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- return info, err
- }
-
- func UpdateCheckDrugOut(out models.DrugWarehouseOut, id int64) error {
- tx := XTWriteDB().Begin()
- err := tx.Model(&models.DrugWarehouseOut{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": out.IsCheck}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.DrugWarehouseOutInfo{}).Where("warehouse_out_id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- tx.Commit()
- return err
- }
-
- func UpdateNewCheckDrugOut(out models.DrugWarehouseOut, id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouseOut{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": out.IsCheck}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.DrugWarehouseOutInfo{}).Where("warehouse_out_id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- tx.Commit()
- return err
- }
-
- func UpdateCheckDrugOutInfoList(info models.DrugWarehouseOutInfo, warehouse_out_id int64) error {
-
- err := XTWriteDB().Model(&models.DrugWarehouseOutInfo{}).Where("warehouse_out_id = ? and status = 1", warehouse_out_id).Update(map[string]interface{}{"is_check": info.IsCheck}).Error
- return err
- }
-
- func UpdateNewCheckDrugOutInfoList(info models.DrugWarehouseOutInfo, warehouse_out_id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouseOutInfo{}).Where("warehouse_out_id = ? and status = 1", warehouse_out_id).Update(map[string]interface{}{"is_check": info.IsCheck}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func GetDrugWarehouseOutByLastId(id int64) (models.DrugWarehouseOut, error) {
- out := models.DrugWarehouseOut{}
- err := XTReadDB().Where("id = ? and status = 1", id).Find(&out).Error
- return out, err
- }
-
- func GetNewDrugWarehouseOutByLastId(id int64, tx *gorm.DB) (models.DrugWarehouseOut, error) {
- out := models.DrugWarehouseOut{}
- err := tx.Where("id = ? and status = 1", id).Find(&out).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return out, err
- }
- }
- return out, err
- }
-
- func UpdateDrugMaxNumber(count int64, id int64) error {
- err := XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
- return err
- }
-
- func UpdateNewDrugMaxNumber(count int64, id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return err
- }
- }
- return err
- }
-
- func UpdateDrugMinNumber(count int64, id int64) error {
- err := XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
- return err
- }
-
- func UpdateNewDrugMinNumber(count int64, id int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func DeleteDrugOutFlow(id int64, orgid int64) error {
-
- err := XTWriteDB().Model(models.DrugFlow{}).Where("warehouse_out_detail_id = ? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func DeleteNewDrugOutFlow(id int64, orgid int64, tx *gorm.DB) error {
-
- err := tx.Model(models.DrugFlow{}).Where("warehouse_out_detail_id = ? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"status": 0}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func GetWarehouseOutByWarehouseInfoId(warehouse_info_id int64, good_id int64, orgid int64) (outInfo []*models.WarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("warehouse_info_id = ? and good_id = ? and org_id = ? and is_check = 1 and status = 1", warehouse_info_id, good_id, orgid).Find(&outInfo).Error
- return outInfo, err
- }
-
- func GetNewWarehouseOutByWarehouseInfoId(warehouse_info_id int64, good_id int64, orgid int64, tx *gorm.DB) (outInfo []*models.WarehouseOutInfo, err error) {
-
- err = tx.Where("warehouse_info_id = ? and good_id = ? and org_id = ? and is_check = 1 and status = 1", warehouse_info_id, good_id, orgid).Find(&outInfo).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return outInfo, err
- }
- }
- return outInfo, err
- }
-
- func GetDrugWarehouseOutByWarehouseInfoId(warehouse_info_id int64, drug_id int64, orgid int64) (outInfo []*models.DrugWarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("warehouse_info_id = ? and drug_id = ? and org_id = ? and is_check = 1 and status = 1", warehouse_info_id, drug_id, orgid).Find(&outInfo).Error
- return outInfo, err
- }
-
- func GetNewDrugWarehouseOutByWarehouseInfoId(warehouse_info_id int64, drug_id int64, orgid int64, tx *gorm.DB) (outInfo []*models.DrugWarehouseOutInfo, err error) {
-
- err = tx.Where("warehouse_info_id = ? and drug_id = ? and org_id = ? and is_check = 1 and status = 1", warehouse_info_id, drug_id, orgid).Find(&outInfo).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return outInfo, err
- }
- }
- return outInfo, err
- }
-
- func GetAllStockInList(id int64, orgid int64) (info []*models.VmWarehousingInfoSix, err error) {
-
- err = XTReadDB().Where("warehousing_id = ? and org_id = ? and status = 1", id, orgid).Preload("GoodInfo", "status = 1 and org_id =?", orgid).Find(&info).Error
- return info, err
- }
-
- func GetNewAllStockInList(id int64, orgid int64, tx *gorm.DB) (info []*models.VmWarehousingInfoSix, err error) {
-
- err = tx.Where("warehousing_id = ? and org_id = ? and status = 1", id, orgid).Preload("GoodInfo", "status = 1 and org_id =?", orgid).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- return info, err
- }
-
- func GetDrugWarehouseInfoList(id int64, orgid int64) (info []*models.DrugWarehouseInfoTwenty, err error) {
-
- err = XTReadDB().Where("warehousing_id = ? and org_id = ? and status = 1", id, orgid).Preload("BaseDrugLib", "org_id = ? and status = 1", orgid).Find(&info).Error
-
- return info, err
- }
-
- func GetNewDrugWarehouseInfoList(id int64, orgid int64, tx *gorm.DB) (info []*models.DrugWarehouseInfoTwenty, err error) {
-
- err = tx.Where("warehousing_id = ? and org_id = ? and status = 1", id, orgid).Preload("BaseDrugLib", "org_id = ? and status = 1", orgid).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
-
- return info, err
- }
-
- func GetStockCountByGoodId(goodid int64, storehouse_id int64, orgId int64) (info []*models.WarehousingInfo, err error) {
-
- err = XTReadDB().Where("good_id = ? and storehouse_id = ? and org_id = ? and status = 1 and is_check = 1", goodid, storehouse_id, orgId).Find(&info).Error
- return info, err
- }
-
- func GetNewStockCountByGoodId(goodid int64, storehouse_id int64, orgId int64, tx *gorm.DB) (info []*models.WarehousingInfo, err error) {
-
- err = tx.Where("good_id = ? and storehouse_id = ? and org_id = ? and status = 1 and is_check = 1", goodid, storehouse_id, orgId).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- return info, err
- }
-
- func UpdateGoodInfoSumCount(goodid int64, sum_count int64, orgid int64) error {
-
- err = XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", goodid, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count + ?", sum_count)).Error
- err := XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", goodid, orgid).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count + ?", sum_count)).Error
- return err
- }
-
- func UpdateGoodInfoSumCountSix(goodid int64, sum_count int64, orgid int64) error {
-
- err := XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", goodid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
- return err
- }
-
- func UpdateGoodInfoReduceSumCount(goodid int64, sum_count int64, orgid int64) error {
-
- err = XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", goodid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
- return err
-
- }
-
- func UpdateNewGoodInfoReduceSumCount(goodid int64, sum_count int64, orgid int64, tx *gorm.DB) error {
-
- err = tx.Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", goodid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
-
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return err
- }
- }
- return err
-
- }
-
- func UpdateGoodInfoAddSumCount(goodid int64, sum_count int64, orgid int64, sum_in_count int64) error {
-
- err := XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", goodid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
-
- err = XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", goodid, orgid).Update(map[string]interface{}{"sum_in_count": sum_in_count}).Error
-
- return err
- }
-
- func UpdateNewGoodInfoAddSumCount(goodid int64, sum_count int64, orgid int64, sum_in_count int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", goodid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
-
- err = tx.Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", goodid, orgid).Update(map[string]interface{}{"sum_in_count": sum_in_count}).Error
-
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func GetCancelStockInfo(id int64, orgid int64) (stock []*models.CancelStockInfo, err error) {
-
- err = XTReadDB().Where("cancel_stock_id = ? and org_id = ? and status = 1", id, orgid).Preload("GoodInfo", "status = 1 and org_id = ?", orgid).Preload("WarehousingInfo", "status = 1 and org_id = ?", orgid).Find(&stock).Error
- return stock, err
- }
-
- func ModifyCancelStockInfo(id int64, info *models.CancelStockInfo) error {
-
- err := XTWriteDB().Model(&models.CancelStockInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"good_id": info.GoodId, "good_type_id": info.GoodTypeId, "count": info.Count, "price": info.Price, "total": info.Total, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "number": info.Number, "register_account": info.RegisterAccount, "remark": info.Remark, "storehouse_id": info.StorehouseId}).Error
- return err
- }
-
- func GetCancelStockInfoListById(cancel_stock_id int64, orgid int64) (info []*models.CancelStockInfo, err error) {
-
- err = XTReadDB().Where("cancel_stock_id = ? and org_id = ? and status = 1", cancel_stock_id, orgid).Find(&info).Error
- return info, err
- }
-
- func GetWarehouseOutList(orgId int64, goodId int64, warehouseInfoId int64) (info []*models.WarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("org_id = ? and good_id = ? and warehouse_info_id = ? and status = 1", orgId, goodId, warehouseInfoId).Find(&info).Error
- return info, err
- }
-
- func GetCancelWarehouseList(orgId int64, goodId int64, warehouseInfoId int64) (info []*models.CancelStockInfo, err error) {
-
- err = XTReadDB().Where("org_id = ? and good_id = ? and warehouse_info_id = ? and status = 1", orgId, goodId, warehouseInfoId).Find(&info).Error
- return info, err
- }
-
- func CheckCancelStock(stock models.CancelStock, cancel_stock_id int64, orgid int64) error {
-
- err := XTWriteDB().Model(&models.CancelStock{}).Where("id = ? and status = 1 and org_id = ?", cancel_stock_id, orgid).Update(map[string]interface{}{"is_check": 1}).Error
-
- err = XTWriteDB().Model(&models.CancelStockInfo{}).Where("cancel_stock_id = ? and status = 1 and org_id = ?", cancel_stock_id, orgid).Update(map[string]interface{}{"is_check": 1}).Error
-
- return err
- }
-
- func GetCancelStockInfoById(cancel_stock_id int64, orgid int64) (info []*models.CancelStockInfo, err error) {
-
- err = XTReadDB().Where("cancel_stock_id = ? and org_id = ? and status = 1 and is_check = 1", cancel_stock_id, orgid).Find(&info).Error
- return info, err
- }
-
- func UpdateCancelStockNumber(stock_count int64, warehouse_info_id int64, orgid int64) error {
-
- err := XTWriteDB().Model(&models.WarehousingInfo{}).Where("id = ? and org_id = ? and status = 1", warehouse_info_id, orgid).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", stock_count)).Error
-
- return err
- }
-
- func UpdateGoodSumCount(sum_count int64, good_id int64, orgid int64) error {
-
- err := XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", good_id, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count + ?", sum_count)).Error
-
- return err
- }
-
- func UpdateStockWarehouseInfo(cancel_stock_id int64, orgid int64, stock models.CancelStock) error {
-
- err := XTWriteDB().Model(&models.CancelStock{}).Where("id = ? and org_id = ? and status = 1", cancel_stock_id, orgid).Update(map[string]interface{}{"is_check": 2}).Error
-
- err = XTWriteDB().Model(&models.CancelStockInfo{}).Where("cancel_stock_id = ? and org_id = ? and status = 1", cancel_stock_id, orgid).Update(map[string]interface{}{"is_check": 2}).Error
-
- return err
- }
-
- func UpdateStockWarehouseInfoStockFlow(id int64, orgid int64, goodid int64) error {
-
- err = XTWriteDB().Model(&models.VmStockFlow{}).Where("cancel_out_detail_id = ? and user_org_id = ? and status = 1 and good_id =?", id, orgid, goodid).Update(map[string]interface{}{"status": 0}).Error
-
- return err
- }
-
- func UpdateStockNumberWarehouseInfo(warehouse_info_id int64, good_id int64, org_id int64, stock_count int64) error {
-
- err := XTWriteDB().Model(&models.WarehousingInfo{}).Where("id = ? and good_id = ? and org_id = ? and status = 1", warehouse_info_id, good_id, org_id).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", stock_count)).Error
-
- err = XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and status = 1 and org_id = ?", good_id, org_id).UpdateColumn("sum_count", gorm.Expr("sum_count - ?", stock_count)).Error
-
- return err
- }
-
- func UpdateDrugSumCount(drugid int64, sum_count int64, sum_in_count int64, orgid int64) error {
-
- err := XTWriteDB().Model(&models.BaseDrugLib{}).Where("id = ? and org_id = ?", drugid, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count + ?", sum_count)).Error
- err = XTWriteDB().Model(&models.BaseDrugLib{}).Where("id = ? and org_id = ?", drugid, orgid).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count + ?", sum_in_count)).Error
- return err
- }
-
- func GetDrugStockWarehouseInfo(id int64, orgid int64, storehouse_id int64) (info []*models.DrugWarehouseInfo, err error) {
-
- err = XTReadDB().Where("id = ? and org_id = ? and status = 1 and is_check = 1 and storehouse_id = ?", id, orgid, storehouse_id).Find(&info).Error
- return info, err
- }
-
- func UpdateBaseDrugSum(drugid int64, orgid int64, sum_count int64, sum_in_count int64) error {
-
- err := XTWriteDB().Model(&models.BaseDrugLib{}).Where("id = ? and org_id = ? and status = 1", drugid, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count + ?", sum_count)).Error
- err = XTWriteDB().Model(&models.BaseDrugLib{}).Where("id = ? and org_id = ? and status = 1", drugid, orgid).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count + ?", sum_in_count)).Error
- return err
- }
-
- func GetDrugAllStockInfo(storehouse_id int64, orgid int64, drugid int64) (info []*models.DrugWarehouseInfo, err error) {
-
- err = XTReadDB().Where("storehouse_id = ? and org_id = ? and status = 1 and drug_id = ? and is_check = 1", storehouse_id, orgid, drugid).Find(&info).Error
- return info, err
- }
-
- func GetSelfDrugAllStockInfoOne(patient_id int64, orgid int64, drugid int64) (info []*models.XtSelfDrugWarehouseInfo, err error) {
-
- err = XTReadDB().Where("patient_id = ? and org_id = ? and status = 1 and drug_id = ? and is_check = 1", patient_id, orgid, drugid).Find(&info).Error
- return info, err
- }
-
- func GetNewDrugAllStockInfo(storehouse_id int64, orgid int64, drugid int64, tx *gorm.DB) (info []*models.DrugWarehouseInfo, err error) {
-
- err = tx.Where("storehouse_id = ? and org_id = ? and status = 1 and drug_id = ? and is_check = 1", storehouse_id, orgid, drugid).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
-
- }
- return info, err
- }
-
- func UpdateBaseDrugSumInfo(sum_count int64, drugid int64, orgid int64, sum_in_count int64) error {
-
- err := XTWriteDB().Model(&models.BaseDrugLib{}).Where("id = ? and status = 1 and org_id = ?", drugid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
-
- err = XTWriteDB().Model(&models.BaseDrugLib{}).Where("id = ? and status = 1 and org_id = ?", drugid, orgid).Update(map[string]interface{}{"sum_in_count": sum_in_count}).Error
- return err
- }
-
- func UpdateNewBaseDrugSumInfo(sum_count int64, drugid int64, orgid int64, sum_in_count int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.BaseDrugLib{}).Where("id = ? and status = 1 and org_id = ?", drugid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return err
- }
- }
-
- err = tx.Model(&models.BaseDrugLib{}).Where("id = ? and status = 1 and org_id = ?", drugid, orgid).Update(map[string]interface{}{"sum_in_count": sum_in_count}).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return err
- }
- }
- return err
- }
-
- func UpdateBaseDrugSumTwo(drugid int64, sum_count int64, orgid int64) error {
-
- err = writeDb.Model(&models.BaseDrugLib{}).Where("id = ? and org_id = ? and status = 1", drugid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
-
- return err
- }
-
- func UpdateNewBaseDrugSumTwo(drugid int64, sum_count int64, orgid int64, tx *gorm.DB) error {
-
- err = tx.Model(&models.BaseDrugLib{}).Where("id = ? and org_id = ? and status = 1", drugid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
-
- if err != nil {
-
- tx.Rollback()
- return err
- }
- return err
- }
-
- func GetLastCancelStockByList(id int64, orgid int64) (info []*models.DrugCancelStockInfo, err error) {
-
- err = XTReadDB().Where("cancel_stock_id = ? and org_id = ? and status = 1", id, orgid).Preload("DrugWarehouseInfo", "status = 1 and org_id = ?", orgid).Preload("BaseDrugLib", "status = 1 and org_id = ?", orgid).Find(&info).Error
- return info, err
- }
-
- func GetCancelDrugStockList(cancel_stock_id int64, orgid int64) (info []*models.DrugCancelStockInfo, err error) {
-
- err = XTReadDB().Where("cancel_stock_id = ? and org_id = ? and status = 1", cancel_stock_id, orgid).Find(&info).Error
- return info, err
- }
-
- func ModifyCancelStock(cancel_stock_id int64, stock models.DrugCancelStock, orgid int64) error {
-
- err := XTWriteDB().Model(&models.DrugCancelStock{}).Where("id = ? and org_id = ? and status = 1", cancel_stock_id, orgid).Update(map[string]interface{}{"is_check": 1}).Error
- err = XTWriteDB().Model(&models.DrugCancelStockInfo{}).Where("cancel_stock_id = ? and org_id = ? and status = 1", cancel_stock_id, orgid).Update(map[string]interface{}{"is_check": 1}).Error
- return err
- }
-
- func GetCancelDrugStock(cancel_stock_id int64, orgid int64) (models.DrugCancelStock, error) {
- stock := models.DrugCancelStock{}
- err := XTReadDB().Where("id = ? and org_id = ? and status = 1", cancel_stock_id, orgid).Find(&stock).Error
- return stock, err
- }
-
- func GetDrugCancelCheckById(cancel_stock_id int64, orgid int64) (stock []*models.DrugCancelStockInfo, err error) {
-
- err = XTReadDB().Where("cancel_stock_id = ? and org_id = ? and status = 1 and is_check = 1", cancel_stock_id, orgid).Find(&stock).Error
- return stock, err
- }
-
- func GetDrugCancelCheckByIdTwenty(cancel_stock_id int64, orgid int64) (stock []*models.DrugCancelStockInfo, err error) {
-
- err = XTReadDB().Where("cancel_stock_id = ? and org_id = ? and status = 1 ", cancel_stock_id, orgid).Find(&stock).Error
- return stock, err
- }
-
- func GetDrugWarehouseOutList(batch_number_id int64, drugId int64, orgid int64) (info []*models.DrugWarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("warehouse_info_id = ? and drug_id = ? and org_id = ? and status = 1", batch_number_id, drugId, orgid).Find(&info).Error
- return info, err
- }
-
- func ModifyDrugWarehouseInfoStockMaxNumber(count int64, drugid int64, orgid int64, id int64) error {
-
- err = XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("id = ? and org_id = ? and drug_id = ? and status = 1", id, orgid, drugid).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
- return err
- }
-
- func ModifyNewDrugWarehouseInfoStockMaxNumber(count int64, drugid int64, orgid int64, id int64, tx *gorm.DB) error {
-
- err = tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and org_id = ? and drug_id = ? and status = 1", id, orgid, drugid).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func ModifyDrugWarehouseInfoStockMinNumber(count int64, drugid int64, orgid int64, id int64) error {
-
- err = XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("id = ? and org_id = ? and drug_id = ? and status = 1", id, orgid, drugid).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
- return err
- }
-
- func ModifyNewDrugWarehouseInfoStockMinNumber(count int64, drugid int64, orgid int64, id int64, tx *gorm.DB) error {
-
- err = tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and org_id = ? and drug_id = ? and status = 1", id, orgid, drugid).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func ModifyDrugCancelStockInfo(id int64, info *models.DrugCancelStockInfo) error {
-
- err := XTWriteDB().Model(&models.DrugCancelStockInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"drug_id": info.DrugId, "count": info.Count, "price": info.Price, "total": info.Total, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "retail_price": info.RetailPrice, "retail_total_price": info.RetailTotalPrice, "number": info.Number, "register_account": info.RegisterAccount, "remark": info.Remark, "batch_number": info.BatchNumber, "max_unit": info.MaxUnit, "batch_number_id": info.BatchNumberId, "storehouse_id": info.StorehouseId}).Error
- return err
- }
-
- func ReturnDrugCancelStock(cancelstock_id int64, stock models.DrugCancelStock) error {
-
- err := XTWriteDB().Model(&models.DrugCancelStock{}).Where("id = ? and status = 1", cancelstock_id).Update(map[string]interface{}{"is_check": 2}).Error
- err = XTWriteDB().Model(&models.DrugCancelStockInfo{}).Where("cancel_stock_id = ? and status = 1", cancelstock_id).Update(map[string]interface{}{"is_check": 2}).Error
- return err
- }
-
- func GetDrugCancelStockInfo(cancelstock_id int64, orgid int64) (info []*models.DrugCancelStockInfo, err error) {
-
- err = XTReadDB().Where("cancel_stock_id = ? and org_id = ? and status = 1", cancelstock_id, orgid).Find(&info).Error
- return info, err
- }
-
- func ModifyDrugFlowByCancelId(cancelstock_id int64, drugId int64, orgid int64) error {
- err := XTWriteDB().Model(&models.DrugFlow{}).Where("cancel_out_detail_id = ? and drug_id = ? and user_org_id = ? and status = 1", cancelstock_id, drugId, orgid).Update(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func ModifyDrugMaxNumberWarehouseInfo(id int64, count int64, orgid int64) error {
-
- err := XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("id = ? and org_id = ? and status = 1", id, orgid).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number - ?", count)).Error
-
- return err
-
- }
-
- func ModifyDrugMinNumberWarehouseInfo(id int64, count int64, orgid int64) error {
-
- err := XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("id = ? and org_id = ? and status = 1", id, orgid).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number - ?", count)).Error
- return err
- }
-
- func GetDrugInfoSix(id int64, orgid int64) (models.DrugWarehouseInfo, error) {
-
- info := models.DrugWarehouseInfo{}
- err := XTReadDB().Where("id = ? and org_id = ? and status = 1 and is_check = 1", id, orgid).Find(&info).Error
- return info, err
- }
-
- func GetSelfDrugInfoSix(id int64, orgid int64) (models.XtSelfDrugWarehouseInfo, error) {
-
- info := models.XtSelfDrugWarehouseInfo{}
- err := XTReadDB().Where("id = ? and org_id = ? and status = 1 and is_check = 1", id, orgid).Find(&info).Error
- return info, err
- }
-
- func GetPrintList(storehouse_id int64, good_name string, orgid int64, limit int64, page int64) (storeinventory []*models.XtStockInventory, err error) {
-
- db := XTReadDB().Model(&storeinventory).Where("status = 1")
-
- if storehouse_id > 0 {
- db = db.Where("storehouse_id = ?", storehouse_id)
- }
- if orgid > 0 {
- db = db.Where("user_org_id = ?", orgid)
- }
-
- err = XTReadDB().Preload("GoodInfo", "status = 1 and org_id = ?", orgid).Preload("WarehousingInfo", "status = 1 and org_id=?", orgid).Find(&storeinventory).Error
- return storeinventory, err
- }
-
- func GetGoodDialysisOutInfo(orgid int64, patient_id int64, sys_record_time int64, good_id int64) (models.AutomaticReduceDetail, error) {
-
- detail := models.AutomaticReduceDetail{}
- err := XTReadDB().Where("org_id =? and patient_id = ? and record_time = ? and good_id = ? and status= 1", orgid, patient_id, sys_record_time, good_id).Find(&detail).Error
- return detail, err
- }
-
- func GetGoodDialysisOutInfoSix(orgid int64, patient_id int64, sys_record_time int64, good_id int64) (models.WarehouseOutInfo, error) {
-
- detail := models.WarehouseOutInfo{}
- err := XTReadDB().Where("org_id =? and patient_id = ? and sys_record_time = ? and good_id = ? and status= 1", orgid, patient_id, sys_record_time, good_id).Find(&detail).Error
- return detail, err
- }
-
- func GetGoodSumCount(storehouse_id int64, good_id int64, orgid int64) (models.XtGoodStockCount, error) {
-
- stock := models.XtGoodStockCount{}
- err := XTReadDB().Where("storehouse_id = ? and good_id = ? and user_org_id = ? and status = 1", storehouse_id, good_id, orgid).Find(&stock).Error
- return stock, err
- }
-
- func CreateGoodStockCount(stock models.XtGoodStockCount) error {
-
- err := XTWriteDB().Create(&stock).Error
- return err
- }
-
- func AddGoodSumInCount(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
-
- err := XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count + ?", count)).Error
-
- return err
- }
-
- func ReduceGoodSumInCount(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
-
- ut := XTWriteDB().Begin()
-
- err := ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count - ?", count)).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- ut.Commit()
- return err
- }
-
- func UpdateGoodFlushCount(storehouse_id int64, good_id int64, user_org_id int64, flush_count int64) error {
-
- err := XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id =?", storehouse_id, user_org_id, good_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
-
- return err
- }
-
- func UpdateNewGoodFlushCount(storehouse_id int64, good_id int64, user_org_id int64, flush_count int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id =?", storehouse_id, user_org_id, good_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func CreateDrugStock(stock models.XtDrugStockCount) error {
-
- err := XTWriteDB().Create(&stock).Error
- return err
- }
-
- func UpdateDrugCount(storehouse_id int64, user_org_id int64, drug_id int64, sum_in_count int64, flush_count int64) error {
-
- ut := XTWriteDB().Begin()
- err := ut.Model(&models.XtDrugStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and drug_id =?", storehouse_id, user_org_id, drug_id).Update(map[string]interface{}{"sum_in_count": sum_in_count}).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- err = ut.Model(&models.XtDrugStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and drug_id =?", storehouse_id, user_org_id, drug_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
- if err != nil {
- ut.Rollback()
- return err
- }
-
- ut.Commit()
- return err
- }
-
- func UpdateDrugCountOne(storehouse_id int64, user_org_id int64, drug_id int64, flush_count int64) error {
-
- ut := XTWriteDB().Begin()
- err = ut.Model(&models.XtDrugStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and drug_id =?", storehouse_id, user_org_id, drug_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
- if err != nil {
- ut.Rollback()
- return err
- }
-
- ut.Commit()
- return err
- }
-
- func AddDrugSumOutCount(storehouse_id int64, sum_out_count int64, user_org_id int64, drug_id int64) error {
-
- ut := XTWriteDB().Begin()
- err := ut.Model(&models.XtDrugStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and drug_id =?", storehouse_id, user_org_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count + ?", sum_out_count)).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- err = ut.Model(&models.XtDrugStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and drug_id =?", storehouse_id, user_org_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count + ?", sum_out_count)).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- ut.Commit()
- return err
- }
-
- func ReduceDrugSumOut(storehouse_id int64, user_org_id int64, drug_id int64, sum_out_count int64) error {
- ut := XTWriteDB().Begin()
- err := ut.Model(&models.XtDrugStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and drug_id =?", storehouse_id, user_org_id, drug_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count + ?", sum_out_count)).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- ut.Commit()
- return err
- }
-
- func AddGoodSumOutCount(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
- ut := XTWriteDB().Begin()
- err := ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count + ?", count)).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- err = ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count + ?", count)).Error
- if err != nil {
- ut.Rollback()
- return err
- }
-
- ut.Commit()
- return err
- }
-
- func ReduceGoodSumOutCount(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
- ut := XTWriteDB().Begin()
- err := ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count - ?", count)).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- err = ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count - ?", count)).Error
- if err != nil {
- ut.Rollback()
- return err
- }
-
- ut.Commit()
- return err
- }
-
- func GetInvetoryWarehouseInfoList(orgid int64, storehouse_id int64) (info []*models.WarehousingInfo, err error) {
-
- if orgid == 10191 || orgid == 10138 || orgid == 10278 {
- err = XTReadDB().Model(&info).Where("status = 1 and storehouse_id=? and is_check= 1 and org_id = ?", storehouse_id, orgid).Preload("GoodInfo", "status = 1").Order("good_id").Find(&info).Error
- return info, err
- } else {
- err = XTReadDB().Model(&info).Where("status = 1 and storehouse_id=? and is_check= 1 and org_id = ? and stock_count >0", storehouse_id, orgid).Preload("GoodInfo", "status = 1").Order("good_id").Find(&info).Error
- return info, err
- }
-
- }
-
- func GetSettleOpenConfig(user_org_id int64) (*models.HisSettleStockConfig, error) {
-
- config := models.HisSettleStockConfig{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&config).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &config, nil
- }
-
- func CreateSettleOpenConfig(config models.HisSettleStockConfig) error {
-
- err := XTWriteDB().Create(&config).Error
- return err
- }
-
- func UpdateSettleOpenConfig(id int64, config models.HisSettleStockConfig) error {
-
- err := XTWriteDB().Model(&models.HisSettleStockConfig{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_open": config.IsOpen}).Error
- return err
- }
-
- func UpdateDrugStockAutomaticReduceRecordOne(orgid int64, is_open int64) (models.DrugStockConfig, error) {
-
- config := models.DrugStockConfig{}
- err := XTWriteDB().Model(&config).Where("org_id = ? and status = 1", orgid).Update(map[string]interface{}{"is_open": is_open}).Error
- return config, err
- }
-
- func UpdatePharyConfig(orgid int64, is_open int64) (models.PharmacyConfig, error) {
-
- stockConfig := models.PharmacyConfig{}
-
- err := XTWriteDB().Model(&stockConfig).Where("user_org_id = ? and status = 1", orgid).Update(map[string]interface{}{"is_open": is_open}).Error
-
- return stockConfig, err
- }
-
- func UpdateSettleOpenConfigOne(id int64, is_open int64) error {
-
- err := XTWriteDB().Model(&models.HisSettleStockConfig{}).Where("user_org_id = ? and status = 1", id).Update(map[string]interface{}{"is_open": is_open}).Error
- return err
- }
-
- func UpdateSettleOpenConfigTwo(id int64, is_open int64) error {
-
- err := XTWriteDB().Model(&models.HisSettleStockConfig{}).Where("user_org_id = ? and status = 1", id).Update(map[string]interface{}{"is_open": is_open}).Error
- return err
- }
-
- func GetSettleOpenConfigByOrgId(user_org_id int64) (models.HisSettleStockConfig, error) {
-
- config := models.HisSettleStockConfig{}
- err = XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&config).Error
- return config, nil
- }
-
- func GetGoodInformationByGoodIdOne(good_id int64) (models.GoodInformationFourty, error) {
-
- info := models.GoodInformationFourty{}
- err := XTReadDB().Where("id = ? and status = 1", good_id).Find(&info).Error
- return info, err
- }
-
- func GetHisDocById(id int64, orgid int64) (models.HisDoctorAdvice, error) {
-
- advice := models.HisDoctorAdvice{}
- err := XTReadDB().Where("id = ? and user_org_id= ? and status = 1", id, orgid).Find(&advice).Error
- return advice, err
- }
-
- func GetBloodDocById(id int64, orgid int64) (models.DoctorAdvice, error) {
-
- advice := models.DoctorAdvice{}
- err := XTReadDB().Where("id = ? and user_org_id= ? and status = 1", id, orgid).Find(&advice).Error
- return advice, err
- }
-
- func FindAllSettleWarehouseOut(org_id int64, warehouse_out_time int64, is_sys int64) (models.WarehouseOut, error) {
-
- out := models.WarehouseOut{}
- err = readDb.Model(&models.WarehouseOut{}).Where("org_id = ? and status = 1 and warehouse_out_time = ? and is_sys = ?", org_id, warehouse_out_time, is_sys).Find(&out).Error
- return out, err
-
- }
-
- func GetGoodOutOpenConfig(user_org_id int64) (*models.XtGoodOutConfig, error) {
-
- config := models.XtGoodOutConfig{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&config).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &config, nil
- }
-
- func CreateGoodOutOpenConfig(good models.XtGoodOutConfig) error {
-
- err := XTWriteDB().Create(&good).Error
- return err
- }
-
- func UpdateGoodOutOpenConfig(id int64, good models.XtGoodOutConfig) error {
-
- err := XTWriteDB().Model(&good).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"is_open": good.IsOpen}).Error
- return err
- }
-
- func FindGoodOutConfigById(user_org_id int64) (models.XtGoodOutConfig, error) {
-
- config := models.XtGoodOutConfig{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&config).Error
- return config, err
- }
-
- func UpdateGoodAutoConfig(user_org_id int64) error {
-
- gobalConfig := models.GobalConfig{}
- err := XTWriteDB().Model(&gobalConfig).Where("org_id = ? and status = 1", user_org_id).Updates(map[string]interface{}{"is_open": 2}).Error
- return err
- }
-
- func UpdateGoodOutConfig(user_org_id int64) error {
-
- config := models.XtGoodOutConfig{}
- err := XTWriteDB().Model(&config).Where("user_org_id = ? and status = 1", user_org_id).Updates(map[string]interface{}{"is_open": 2}).Error
- return err
- }
-
- func GetHisGoodList(patient_id int64, record_date int64, orgid int64) (info []*models.GoodHisPrescriptionProject, err error) {
-
- err = XTReadDB().Where("patient_id = ? and record_date = ? and status = 1 and user_org_id = ? AND type = 3", patient_id, record_date, orgid).Find(&info).Error
- return info, err
- }
-
- func GetLastGoodWarehouseOutInfoByProjectId(good_id int64, patient_id int64, sys_record_time int64, project_id int64) (good []*models.WarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("good_id = ? and patient_id = ? and sys_record_time = ? and project_id = ? and status = 1", good_id, patient_id, sys_record_time, project_id).Find(&good).Error
- return good, err
- }
-
- func ModifyGoodWarehouseInfo(good_id int64, warehouse_info_id int64, orgid int64, count int64) error {
-
- err = XTWriteDB().Model(&models.WarehousingInfo{}).Where("id = ? and org_id = ? and good_id = ? and status = 1", warehouse_info_id, orgid, good_id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
- return err
- }
-
- func DeleteGoodWarehouseOutInfo(good_id int64, sys_record_time int64, org_id int64, project_id int64) error {
-
- err := XTWriteDB().Model(&models.WarehouseOutInfo{}).Where("good_id = ? and sys_record_time = ? and org_id = ? and project_id = ? and status=1", good_id, sys_record_time, org_id, project_id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func DeleteGoodFlow(good_id int64, sys_record_time int64, org_id int64, project_id int64) error {
-
- err := XTWriteDB().Model(&models.VmStockFlow{}).Where("good_id = ? and system_time = ? and user_org_id = ? and project_id = ? and status=1", good_id, sys_record_time, org_id, project_id).Updates(map[string]interface{}{"status": 0, "is_read": 1}).Error
- return err
- }
-
- func FindPrescriptionWarehouseOut(org_id int64, warehouse_out_time int64) (models.WarehouseOut, error) {
-
- out := models.WarehouseOut{}
- err = readDb.Model(&models.WarehouseOut{}).Where("org_id = ? and status = 1 and warehouse_out_time = ? and is_sys=1", org_id, warehouse_out_time).Find(&out).Error
- return out, err
-
- }
-
- func FindNewPrescriptionWarehouseOut(org_id int64, warehouse_out_time int64, tx *gorm.DB) (models.WarehouseOut, error) {
-
- out := models.WarehouseOut{}
- err = tx.Model(&models.WarehouseOut{}).Where("org_id = ? and status = 1 and warehouse_out_time = ? and is_sys=1", org_id, warehouse_out_time).Find(&out).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return out, err
- }
-
- }
- return out, err
-
- }
-
- func FindLastPrescriptionWarehouseOut(org_id int64, warehouse_out_time int64) (models.WarehouseOut, error) {
-
- out := models.WarehouseOut{}
- err = readDb.Model(&models.WarehouseOut{}).Where("org_id = ? and status = 1 and warehouse_out_time = ? and is_sys=1", org_id, warehouse_out_time).Last(&out).Error
- return out, err
-
- }
-
- func FindNewLastPrescriptionWarehouseOut(org_id int64, warehouse_out_time int64, tx *gorm.DB) (models.WarehouseOut, error) {
-
- out := models.WarehouseOut{}
- err = tx.Model(&models.WarehouseOut{}).Where("org_id = ? and status = 1 and warehouse_out_time = ? and is_sys=1", org_id, warehouse_out_time).Last(&out).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return out, err
- }
- }
- return out, err
-
- }
-
- func GetGoodTypeObj(goodid int64, org_id int64) (models.GoodsType, error) {
-
- goodsType := models.GoodsType{}
- err := XTReadDB().Where("good_id = ? and org_id = ? and status = 1", goodid, org_id).Find(&goodsType).Error
- return goodsType, err
- }
-
- func GetAllGoodTypeName(good_type_id int64, org_id int64) (good_type_name string) {
-
- goodsTypeList, _ := GetAllGoodType(org_id)
- for _, item := range goodsTypeList {
- if good_type_id == item.ID {
- good_type_name = item.TypeName
- }
- }
- return good_type_name
- }
-
- func UpdateGoodTypeName(good_id int64, good_type_name string) (models.GoodInformation, error) {
-
- information := models.GoodInformation{}
-
- err := XTWriteDB().Model(&information).Where("id = ? and status =1", good_id).Updates(map[string]interface{}{"good_type_name": good_type_name}).Error
- return information, err
- }
-
- func GetSencondeGoodWarehouseInfo(good_id int64, org_id int64) (info []*models.WarehousingInfo, err error) {
-
- err = XTReadDB().Where("good_id = ? and org_id= ? and status= 1 and is_check = 1", good_id, org_id).Find(&info).Error
- return info, err
- }
-
- func UpdateGoodSumCountSeven(sum_count int64, good_id int64, orgid int64) error {
- ut := writeDb.Begin()
- err := ut.Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", good_id, orgid).Updates(map[string]interface{}{"sum_count": sum_count}).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- ut.Commit()
- return err
- }
-
- func UpdateNewGoodSumCountSeven(sum_count int64, good_id int64, orgid int64, tx *gorm.DB) error {
-
- err := tx.Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", good_id, orgid).Updates(map[string]interface{}{"sum_count": sum_count}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func GetWarehouseOutInfoIsExistOTwo(good_id int64, patient_id int64, record_time int64, project_id int64) (*models.WarehouseOutInfo, error) {
-
- info := models.WarehouseOutInfo{}
- var err error
- err = XTReadDB().Model(&info).Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ? and project_id = ?", good_id, record_time, patient_id, project_id).Find(&info).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &info, nil
- }
-
- func GetWarehouseOutInfoIsExistThree(good_id int64, patient_id int64, record_time int64, project_id int64) (models.WarehouseOutInfo, error) {
- info := models.WarehouseOutInfo{}
- err := XTReadDB().Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ? and project_id = ?", good_id, record_time, patient_id, project_id).Find(&info).Error
- return info, err
- }
-
- func GetNewWarehouseOutInfoIsExistThree(good_id int64, patient_id int64, record_time int64, project_id int64, tx *gorm.DB) (models.WarehouseOutInfo, error) {
- info := models.WarehouseOutInfo{}
- err := tx.Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ? and project_id = ?", good_id, record_time, patient_id, project_id).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- return info, err
- }
-
- func GetWarehouseOutInfoIsExistTen(good_id int64, patient_id int64, record_time int64, project_id int64, warehouse_info_id int64) (models.WarehouseOutInfo, error) {
- info := models.WarehouseOutInfo{}
- err := XTReadDB().Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ? and project_id = ? and warehouse_info_id = ?", good_id, record_time, patient_id, project_id, warehouse_info_id).Find(&info).Error
- return info, err
- }
-
- func GetNewWarehouseOutInfoIsExistTen(good_id int64, patient_id int64, record_time int64, project_id int64, warehouse_info_id int64, tx *gorm.DB) (models.WarehouseOutInfo, error) {
- info := models.WarehouseOutInfo{}
- err := tx.Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ? and project_id = ? and warehouse_info_id = ?", good_id, record_time, patient_id, project_id, warehouse_info_id).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return info, err
- }
- }
- return info, err
- }
-
- func GetNewWarehouseOutInfoIsExistSix(good_id int64, patient_id int64, record_time int64, project_id int64, warehouse_info_id int64) (*models.WarehouseOutInfo, error) {
-
- info := models.WarehouseOutInfo{}
- var err error
- err = XTReadDB().Model(&info).Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ? and project_id = ? and warehouse_info_id = ?", good_id, record_time, patient_id, project_id, warehouse_info_id).Find(&info).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &info, nil
- }
-
- func GetNewNewWarehouseOutInfoIsExistSix(good_id int64, patient_id int64, record_time int64, project_id int64, warehouse_info_id int64, tx *gorm.DB) (*models.WarehouseOutInfo, error) {
-
- info := models.WarehouseOutInfo{}
- var err error
- err = tx.Model(&info).Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ? and project_id = ? and warehouse_info_id = ?", good_id, record_time, patient_id, project_id, warehouse_info_id).Find(&info).Error
- if err != gorm.ErrRecordNotFound {
- if err != nil {
- tx.Rollback()
- return &info, err
- }
-
- }
- return &info, err
- }
-
- func GetNewGoodWarehouseInfo(startime int64, endtime int64, orgid int64, good_id []int64, storehouse_id int64) (info []*models.GoodWarehousingInfo, err error) {
-
- db := XTReadDB().Model(&info).Where("status = 1")
-
- if startime > 0 {
- db = db.Where("ctime>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("ctime<=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("org_id = ?", orgid)
- }
- if len(good_id) > 0 {
- db = db.Where("good_id in(?)", good_id)
- }
- if storehouse_id > 0 {
- db = db.Where("storehouse_id = ?", storehouse_id)
- }
- err = db.Preload("GoodInfo", "org_id = ? and status= 1", orgid).Find(&info).Error
- return info, err
- }
-
- func GetNewWarehouseOutInfoList(start_time int64, end_time int64, orgid int64, good_id []int64, storehouse_id int64) (info []*models.WarehouseOutInfoNight, err error) {
-
- db := XTReadDB().Model(&info).Where("status= 1")
-
- if start_time > 0 {
- db = db.Where("ctime>=?", start_time)
- }
- if end_time > 0 {
- db = db.Where("ctime <=?", end_time)
- }
-
- if orgid > 0 {
- db = db.Where("org_id = ?", orgid)
- }
- if len(good_id) > 0 {
- db = db.Where("good_id in(?)", good_id)
- }
- if storehouse_id > 0 {
- db = db.Where("storehouse_id = ?", storehouse_id)
- }
- err = db.Preload("GoodInfo", "org_id = ? and status = 1", orgid).Find(&info).Error
- return info, err
- }
-
- func GetGoodOutOpenConfigOne(user_org_id int64) (models.XtGoodOutConfig, error) {
-
- config := models.XtGoodOutConfig{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&config).Error
- return config, err
- }
-
- func UpdateDeleteAutoGood(good_id int64, record_date int64, patient_id int64) error {
-
- err := XTWriteDB().Model(&models.AutomaticReduceDetail{}).Where("good_id = ? and record_time = ? and patient_id = ?", good_id, record_date, patient_id).Updates(map[string]interface{}{"status": 1}).Error
-
- err = XTWriteDB().Model(&models.DialysisBeforePrepare{}).Where("good_id = ? and record_date = ? and patient_id = ?", good_id, record_date, patient_id).Updates(map[string]interface{}{"status": 1}).Error
- return err
- }
-
- func UpdateWarehouseInfoMap(list []*models.WarehousingInfo, warehousing_info_id int64, orgId int64) error {
-
- tx := XTWriteDB().Begin()
-
- for _, item := range list {
-
- err := tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", item.ID).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", item.WarehousingCount)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", item.ID).Update(map[string]interface{}{"is_check": 2}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
-
- err = tx.Model(models.VmStockFlow{}).Where("warehousing_detail_id = ?", item.ID).Update(map[string]interface{}{"status": 0, "is_check": 2}).Error
-
- if err != nil {
- tx.Rollback()
- return err
- }
-
- var goodList []*models.WarehousingInfo
- err = tx.Where("org_id = ? and storehouse_id = ? and good_id = ? and status =1 and is_check = 1", orgId, item.StorehouseId, item.GoodId).Find(&goodList).Error
-
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- err = tx.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and good_id = ? and storehouse_id = ? and status = 1", item.OrgId, item.GoodId, item.StorehouseId).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count - ?", item.WarehousingCount)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and good_id = ? and storehouse_id = ? and status = 1", item.OrgId, item.GoodId, item.StorehouseId).Update(map[string]interface{}{"flush_count": flush_count}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
-
- storeHouseConfig := models.XtStorehouseConfig{}
- err = tx.Where("user_org_id = ? and status = 1", orgId).First(&storeHouseConfig).Error
-
- var stockList []*models.WarehousingInfo
- //查询该耗材剩余多少库存
- err = tx.Where("good_id = ? and storehouse_id = ? and org_id = ? and status = 1 and is_check = 1", item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId).Find(&stockList).Error
-
- var sum_count int64
- var sum_in_count int64
- for _, it := range stockList {
- sum_count += it.StockCount
- sum_in_count += it.WarehousingCount
- }
-
- err = tx.Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", item.GoodId, orgId).Update(map[string]interface{}{"sum_count": sum_count}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", item.GoodId, orgId).Update(map[string]interface{}{"sum_in_count": sum_in_count}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
-
- }
- err := tx.Model(&models.Warehousing{}).Where("id = ? and status = 1", warehousing_info_id).Update(map[string]interface{}{"is_check": 2}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.WarehousingInfo{}).Where("warehousing_id = ? and status = 1", warehousing_info_id).Update(map[string]interface{}{"is_check": 2}).Error
- tx.Commit()
- return err
-
- }
-
- func UpdateNewWarehouseInfoMap(list []*models.WarehousingInfo, warehousing_info_id int64, orgId int64, tx *gorm.DB) error {
-
- for _, item := range list {
-
- err := tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", item.ID).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", item.WarehousingCount)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", item.ID).Update(map[string]interface{}{"is_check": 2}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
-
- err = tx.Model(models.VmStockFlow{}).Where("warehousing_detail_id = ?", item.ID).Update(map[string]interface{}{"status": 0, "is_check": 2}).Error
-
- if err != nil {
- tx.Rollback()
- return err
- }
-
- var goodList []*models.WarehousingInfo
- err = tx.Where("org_id = ? and storehouse_id = ? and good_id = ? and status =1 and is_check = 1", orgId, item.StorehouseId, item.GoodId).Find(&goodList).Error
-
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- err = tx.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and good_id = ? and storehouse_id = ? and status = 1", item.OrgId, item.GoodId, item.StorehouseId).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count - ?", item.WarehousingCount)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and good_id = ? and storehouse_id = ? and status = 1", item.OrgId, item.GoodId, item.StorehouseId).Update(map[string]interface{}{"flush_count": flush_count}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
-
- storeHouseConfig := models.XtStorehouseConfig{}
- err = tx.Where("user_org_id = ? and status = 1", orgId).First(&storeHouseConfig).Error
-
- var stockList []*models.WarehousingInfo
- //查询该耗材剩余多少库存
- err = tx.Where("good_id = ? and storehouse_id = ? and org_id = ? and status = 1 and is_check = 1", item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId).Find(&stockList).Error
-
- var sum_count int64
- var sum_in_count int64
- for _, it := range stockList {
- sum_count += it.StockCount
- sum_in_count += it.WarehousingCount
- }
-
- err = tx.Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", item.GoodId, orgId).Update(map[string]interface{}{"sum_count": sum_count}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", item.GoodId, orgId).Update(map[string]interface{}{"sum_in_count": sum_in_count}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
-
- }
- err := tx.Model(&models.Warehousing{}).Where("id = ? and status = 1", warehousing_info_id).Update(map[string]interface{}{"is_check": 2}).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- err = tx.Model(&models.WarehousingInfo{}).Where("warehousing_id = ? and status = 1", warehousing_info_id).Update(map[string]interface{}{"is_check": 2}).Error
-
- return err
-
- }
-
- func FindFirstWarehousingInfoByStockThree(good_id int64, storehouse_id int64) (info models.WarehousingInfo, err error) {
- if storehouse_id == 0 {
- err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND status = 1 and stock_count > 0", good_id).Order("ctime").First(&info).Error
- }
- if storehouse_id > 0 {
- err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND status = 1 and stock_count > 0 and storehouse_id =? ", good_id, storehouse_id).Order("ctime").First(&info).Error
- }
-
- return info, err
- }
-
- func FindFirstWarehousingInfoByStockFour(good_id int64, storehouse_id int64) (info models.WarehousingInfo, err error) {
-
- err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND status = 1 and storehouse_id =? ", good_id, storehouse_id).Order("ctime").Last(&info).Error
-
- return info, err
- }
-
- func GetHisPrescriptionNumberList(project_id int64, record_date int64, orgid int64, patient_id int64) (list []*models.HisPrescriptionProject, err error) {
-
- err = readDb.Where("project_id = ? and record_date =? and user_org_id =? and status =1 and patient_id = ?", project_id, record_date, orgid, patient_id).Find(&list).Error
-
- return list, err
- }
-
- func GetWarehouseOutnfoByProjectId(project_id int64, record_date int64, orgid int64, patient_id int64) (infor []*models.WarehouseOutInfo, err error) {
-
- err = readDb.Where("good_id =? and sys_record_time = ? and org_id = ? and patient_id = ? and status=1", project_id, record_date, orgid, patient_id).Find(&infor).Error
- return infor, err
- }
-
- func UpdateWarehouseInfoByPatientId(project_id int64, record_date int64, orgid int64, patient_id int64) (models.WarehouseOutInfo, error) {
-
- info := models.WarehouseOutInfo{}
- err := XTWriteDB().Model(&info).Where("good_id = ? and sys_record_time = ? and org_id = ? and status =1 and patient_id = ?", project_id, record_date, orgid, patient_id).Updates(map[string]interface{}{"status": 0}).Error
- return info, err
- }
-
- func UpdateWarehouseInfoByProject(good_id int64, id int64, user_org_id int64, count int64) (models.WarehousingInfo, error) {
-
- info := models.WarehousingInfo{}
-
- err := XTWriteDB().Where("id = ? and good_id = ? and org_id = ? and status= 1", id, good_id, user_org_id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
-
- return info, err
- }
-
- func GetHisPrescripionProjectList(good_id int64, user_org_id int64) (list []*models.HisPrescriptionProjectTemplate, err error) {
-
- err = XTReadDB().Where("project_id=? and status=1 and type =3 and user_org_id=?", good_id, user_org_id).Find(&list).Error
-
- return list, err
- }
-
- func GetHisPrescripionProjectListOne(good_id int64, user_org_id int64) (list []*models.HisPrescriptionProjectTemplate, err error) {
-
- err = XTReadDB().Where("project_id=? and status=1 and type =2 and user_org_id=?", good_id, user_org_id).Find(&list).Error
-
- return list, err
- }
-
- func UpdateHisPrescriptionProjectList(id int64, price float64) (models.HisPrescriptionProjectTemplateL, error) {
-
- templateL := models.HisPrescriptionProjectTemplateL{}
- err := XTWriteDB().Model(&templateL).Where("id =? and status=1", id).Updates(map[string]interface{}{"price": price}).Error
- return templateL, err
- }
-
- func ModifyNewGoodWarehouseInfoStockMinNumber(count int64, goodid int64, orgid int64, id int64, tx *gorm.DB) error {
-
- err = tx.Model(&models.WarehousingInfo{}).Where("id = ? and org_id = ? and good_id = ? and status = 1", id, orgid, goodid).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func GetDrugInvetoryByDrugId(user_org_id int64, drug_id int64) (info []*models.XtDrugWarehouseInfo, err error) {
-
- err = XTReadDB().Where("org_id = ? and drug_id = ? and status=1", user_org_id, drug_id).Preload("XtBaseDrug", "org_id = ? and status=1", user_org_id).Order("id desc").Find(&info).Error
-
- return info, err
- }
-
- func UpdateNewDrugWarehouseInfoById(id int64, last_stock_max_number int64, last_stock_min_number int64) error {
-
- err := XTWriteDB().Model(&models.XtDrugWarehouseInfo{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"stock_max_number": last_stock_max_number, "stock_min_number": last_stock_min_number}).Error
-
- return err
- }
-
- func GeteSelfPrescriptionOpen(user_org_id int64) (models.XtSelfDrugInfoConfig, error) {
-
- drugInfoConfig := models.XtSelfDrugInfoConfig{}
- err := XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&drugInfoConfig).Error
-
- return drugInfoConfig, err
- }
-
- func CreaterSelfConfig(infoConfig models.XtSelfDrugInfoConfig) error {
-
- err := XTWriteDB().Create(&infoConfig).Error
-
- return err
- }
-
- func SaveSelfConfig(infoConfig models.XtSelfDrugInfoConfig) error {
-
- err := XTWriteDB().Save(&infoConfig).Error
-
- return err
- }
-
- func GetSelfPrescriptionOutOpen(user_org_id int64) (models.XtSelfDrugOutConfig, error) {
-
- drugOutConfig := models.XtSelfDrugOutConfig{}
-
- err := XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&drugOutConfig).Error
-
- return drugOutConfig, err
- }
-
- func CreateSelfDrugOutConfig(config models.XtSelfDrugOutConfig) error {
-
- err := XTWriteDB().Create(&config).Error
-
- return err
- }
-
- func UpdateSelfDrugOutConfig(config models.XtSelfDrugOutConfig) error {
-
- err := XTWriteDB().Save(&config).Error
-
- return err
- }
-
- func CreateSelfDrugFlowOne(flow models.XtSelfDrugFlow, tx *gorm.DB) error {
-
- err := tx.Create(&flow).Error
- if err != nil {
- tx.Rollback()
- return err
- }
- return err
- }
-
- func UpdateWarehouseOutInfoByPrice(good_id int64, packing_price float64) error {
-
- err = XTWriteDB().Model(&models.WarehousingInfo{}).Where("good_id =? and status =1 and is_check=1", good_id).Updates(map[string]interface{}{"packing_price": packing_price}).Error
-
- return err
- }
-
- func GetWarehosueOutInfoByPrice(good_id int64, org_id int64) (out []*models.WarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("good_id = ? and org_id = ? and status=1 and price =0", good_id, org_id).Find(&out).Error
-
- return out, err
- }
-
- func UpdateWarehouseOut(good_id int64, packing_price float64) error {
-
- err := XTWriteDB().Model(&models.WarehouseOutInfo{}).Where("id = ? and status=1", good_id).Updates(map[string]interface{}{"price": packing_price}).Error
-
- return err
- }
-
- func UpdateStockFlowByList(good_id int64, packing_price float64) error {
-
- err := XTWriteDB().Model(models.VmStockFlow{}).Where("good_id = ? and user_org_id = 10633 and status=1", good_id).Updates(map[string]interface{}{"price": packing_price}).Error
-
- return err
- }
-
- func GetGoodStockInventoryByRecordate(good_id int64, record_date int64, user_org_id int64) (models.XtGoodStockInventoryList, error) {
-
- goodStockInventoryList := models.XtGoodStockInventoryList{}
- err := XTReadDB().Where("good_id = ? and record_date = ? and user_org_id = ? and status=1", good_id, record_date, user_org_id).Find(&goodStockInventoryList).Error
- return goodStockInventoryList, err
- }
-
- func CreateGoodStockInventoryList(list models.XtGoodStockInventoryList) error {
-
- err := XTWriteDB().Create(&list).Error
-
- return err
- }
-
- func SaveGoodStockInventoryList(list models.XtGoodStockInventoryList) error {
-
- err := XTWriteDB().Save(&list).Error
-
- return err
- }
-
- func GetGoodStockInventoryList(keyword string, limit int64, page int64, storehouse_id int64, startTime int64, endTime int64, orgId int64) (list []*models.XtGoodStockInventoryList, total int64, err error) {
-
- likeKey := "%" + keyword + "%"
- offset := (page - 1) * limit
-
- db := XTReadDB().Model(&models.XtGoodStockInventoryList{}).Where("status=1")
-
- if storehouse_id > 0 {
-
- db = db.Where("storehouse_id = ?", storehouse_id)
- }
-
- if startTime > 0 {
- db = db.Where("record_date >=?", startTime)
- }
-
- if endTime > 0 {
- db = db.Where("record_date<=?", endTime)
- }
-
- if len(keyword) > 0 {
- db = db.Where("good_name like ? or specification_name like ?", likeKey, likeKey)
- }
- if orgId > 0 {
- db = db.Where("user_org_id = ?", orgId)
- }
-
- err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&list).Error
-
- return list, total, err
- }
-
- func GetDrugStockInventoryList(drug_id int64, record_date int64, user_org_id int64) (models.XtDrugStockInventoryList, error) {
-
- drugStockInventoryList := models.XtDrugStockInventoryList{}
-
- err := XTReadDB().Where("drug_id = ? and record_date = ? and user_org_id = ? and status=1", drug_id, record_date, user_org_id).Find(&drugStockInventoryList).Error
-
- return drugStockInventoryList, err
- }
-
- func CreatedDrugStockInventory(list models.XtDrugStockInventoryList) error {
-
- err := XTWriteDB().Create(&list).Error
-
- return err
- }
-
- func SaveDrugStockInventory(list models.XtDrugStockInventoryList) error {
-
- err := XTWriteDB().Save(&list).Error
-
- return err
- }
-
- func GetStockInventoryPrintList(storehouse_id int64, keyword string, limit int64, page int64, ids []string, orgId int64) (list []*models.XtGoodStockInventoryList, total int64, err error) {
-
- db := XTReadDB().Model(&list).Where("status=1")
- likeKey := "%" + keyword + "%"
- offset := (page - 1) * limit
- if storehouse_id > 0 {
- db = db.Where("storehouse_id = ?", storehouse_id)
- }
- if len(keyword) > 0 {
- db = db.Where("good_name like ?", likeKey)
- }
- if orgId > 0 {
- db = db.Where("user_org_id = ?", orgId)
- }
-
- if len(ids) > 0 {
- db = db.Where("id in(?)", ids)
- }
-
- err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&list).Error
-
- return list, total, err
- }
-
- func GetGoodWarehouseInfoList(startTime int64, endTime int64, orgId int64) (info []*models.WarehousingInfo, err error) {
-
- db := XTReadDB().Model(&info).Where("status=1 and is_check=1")
-
- if startTime > 0 {
- db = db.Where("ctime>=?", startTime)
- }
-
- if endTime > 0 {
- db = db.Where("ctime<=?", endTime)
- }
-
- if orgId > 0 {
- db = db.Where("org_id = ?", orgId)
- }
-
- err = db.Find(&info).Error
-
- return info, err
- }
-
- func GetGoodWarhouseOutList(startTime int64, endTime int64, orgId int64) (outinfo []*models.WarehouseOutInfo, err error) {
-
- db := XTReadDB().Model(&outinfo).Where("status=1 and is_check =1")
-
- if startTime > 0 {
- db = db.Where("ctime>=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("ctime<=?", endTime)
- }
-
- if orgId > 0 {
- db = db.Where("org_id = ?", orgId)
- }
-
- err = db.Find(&outinfo).Error
-
- return outinfo, err
- }
-
- func GetGoodStockFlowProList(startTime int64, endTime int64, orgId int64) (flow []*models.VmStockFlow, err error) {
-
- db := XTReadDB().Model(&flow).Where("status=1 and consumable_type = 10")
-
- if startTime > 0 {
- db = db.Where("ctime>=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("ctime<=?", endTime)
- }
- if orgId > 0 {
- db = db.Where("user_org_id = ?", orgId)
- }
- err = db.Find(&flow).Error
-
- return flow, err
- }
-
- func GetGoodStockFlowNoProList(startTime int64, endTime int64, orgId int64) (flow []*models.VmStockFlow, err error) {
-
- db := XTReadDB().Model(&flow).Where("status=1 and consumable_type = 11")
-
- if startTime > 0 {
- db = db.Where("ctime>=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("ctime<=?", endTime)
- }
- if orgId > 0 {
- db = db.Where("user_org_id = ?", orgId)
- }
- err = db.Find(&flow).Error
-
- return flow, err
- }
-
- func GetCancelStockFlowList(startTime int64, endTime int64, orgId int64) (flow []*models.VmStockFlow, err error) {
-
- db := XTReadDB().Model(&flow).Where("status=1 and consumable_type = 7")
-
- if startTime > 0 {
- db = db.Where("ctime>=?", startTime)
- }
- if endTime > 0 {
- db = db.Where("ctime<=?", endTime)
- }
- if orgId > 0 {
- db = db.Where("user_org_id = ?", orgId)
- }
- err = db.Find(&flow).Error
-
- return flow, err
- }
-
- func GetLastMonthCount(startTime int64, orgId int64) (flow []*models.VmStockFlow, err error) {
-
- db := XTReadDB().Model(&flow).Where("status=1 and (consumable_type = 1 or consumable_type = 10)")
-
- if startTime > 0 {
- db = db.Where("ctime <?", startTime)
- }
- if orgId > 0 {
- db = db.Where("user_org_id = ?", orgId)
- }
- err = db.Find(&flow).Error
-
- return flow, err
- }
-
- func GetLastMonthOverCount(startTime int64, orgId int64) (flow []*models.VmStockFlow, err error) {
-
- db := XTReadDB().Model(&flow).Where("status=1 and (consumable_type = 2 or consumable_type=3 or consumable_type=11)")
-
- if startTime > 0 {
- db = db.Where("ctime <?", startTime)
- }
- if orgId > 0 {
- db = db.Where("user_org_id = ?", orgId)
- }
- err = db.Find(&flow).Error
-
- return flow, err
- }
-
- func GetLastCancelMonthCount(startTime int64, orgId int64) (flow []*models.VmStockFlow, err error) {
-
- db := XTReadDB().Model(&flow).Where("status=1 and (consumable_type = 7)")
-
- if startTime > 0 {
- db = db.Where("ctime <?", startTime)
- }
- if orgId > 0 {
- db = db.Where("user_org_id = ?", orgId)
- }
- err = db.Find(&flow).Error
-
- return flow, err
- }
-
- func GetDrugCodeOpen(user_org_id int64) (models.XtDrugCodeOpen, error) {
-
- drugCodeOpen := models.XtDrugCodeOpen{}
-
- err := XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&drugCodeOpen).Error
-
- return drugCodeOpen, err
- }
-
- func CreateDrugOpen(open models.XtDrugCodeOpen) error {
-
- err := XTWriteDB().Create(&open).Error
-
- return err
- }
-
- func SaveDrugOpen(open models.XtDrugCodeOpen) error {
-
- err := XTWriteDB().Save(&open).Error
-
- return err
- }
-
- func GetHisDrugCodeQuery(orgId int64, start_time int64, end_time int64, limit int64, page int64, is_sale int64) (list []*models.HisDoctorAdviceInfo, total int64, err error) {
-
- db := XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("status=1")
-
- if orgId > 0 {
- db = db.Where("user_org_id=?", orgId)
- }
- if start_time > 0 {
- db = db.Where("advice_date >= ?", start_time)
- }
-
- if end_time > 0 {
- db = db.Where("advice_date<=?", end_time)
- }
-
- offset := (page - 1) * limit
-
- if is_sale == 1 {
- db = db.Where("is_upload = 1")
- }
- if is_sale == 2 {
- db = db.Where("is_upload = 2 or is_upload =0")
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&list).Error
- fmt.Println("totla====================", total)
- return list, total, err
- }
-
- func GetDrugWarehouseOutInfoByDrugCode(drug_id int64, patient_id int64, advice_date int64, user_org_id int64) (outinfo []*models.XtDrugWarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("drug_id = ? and patient_id = ? and sys_record_time =? and org_id = ? and status =1", drug_id, patient_id, advice_date, user_org_id).Find(&outinfo).Error
-
- return outinfo, err
- }
|