12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643 |
- package service
-
- import (
- "Xcx_New/models"
- "fmt"
- "github.com/jinzhu/gorm"
- "strconv"
- "strings"
- "time"
- )
-
- 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 FindAllDealerList(orgId int64, page int64, limit 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)
- 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 FindAllManufacturerList(orgId int64, page int64, limit 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)
- 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,
- }).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) (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)
- } else {
- if is_use > 0 {
- if is_use == 1 {
- 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)
- }
- }
-
- 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 = readDb.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 = readDb.Model(&models.GoodInfo{}).Where("org_id = ? AND status = 1", 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 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 AddSigleWarehouse(warehouse *models.Warehousing) error {
- err := writeDb.Create(&warehouse).Error
- return err
-
- }
-
- func AddSigleDrugWarehouse(warehouse *models.DrugWarehouse) error {
- err := writeDb.Create(&warehouse).Error
- 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) 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)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- }
- 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) 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)
- }
- 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 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) 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)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- }
- return
- }
-
- 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 := XTReadDB().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 {
-
- err := XTWriteDB().Create(&flow).Error
- 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 FindFirstWarehousingInfoByStock(good_id int64, good_type_id int64) (info models.WarehousingInfo, err error) {
- 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
- return info, err
- }
-
- func FindFirstWarehousingInfoByStockTwo(good_id int64, good_type_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)
- }
- err = db.Select("sum(x.stock_count) as count").Scan(&info).Error
- return info, err
- }
-
- //药品先进先出,找出最先入库的批次
-
- func FindLastDrugWarehousingInfoByID(drug_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) ", drug_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) (list []*models.Warehousing, total int64, err error) {
- 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)
- }
-
- db = db.Count(&total)
- offset := (page - 1) * limit
- err = db.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) (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)
- }
- err = db.Find(&info).Error
- return info, err
- }
-
- func GetWarehoureOrderOutByGoodId(good_id []int64, startime int64, endtime int64, orgid 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)
- }
- 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"`
- }
-
- 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"`
- Drug *Drug `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
- }
-
- 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"`
- 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 float64 `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"`
- }
-
- 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) (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)
- }
- 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.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,t.manufacturer,t.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 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 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 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 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("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"`
- }
-
- 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).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 AddSigleWarehouseOut(warehouseOut *models.WarehouseOut) error {
- err := writeDb.Create(&warehouseOut).Error
- return err
-
- }
-
- func AddSigleDrugWarehouseOut(warehouseOut *models.DrugWarehouseOut) error {
- err := writeDb.Create(&warehouseOut).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) (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.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 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) (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)
- }
- 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 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"`
- }
-
- 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 AddSigleCancelStock(cancelStock *models.CancelStock) error {
- err := writeDb.Create(&cancelStock).Error
- return err
-
- }
-
- func AddSigleDrugCancelStock(cancelStock *models.DrugCancelStock) error {
- err := writeDb.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) 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)
- }
- thisSQL += strings.Join(insertParams, ", ")
- err = utx.Exec(thisSQL, insertData...).Error
- if err != nil {
- utx.Rollback()
- return
- }
- }
- utx.Commit()
- }
- return
-
- }
-
- 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 := readDb.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 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 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 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
- }
- 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 FindWareHouseOutById(id int64) (*models.WarehouseOut, error) {
- warehouseOut := &models.WarehouseOut{}
- err := readDb.Model(&models.WarehouseOut{}).Where("id = ? AND status = 1", id).First(&warehouseOut).Error
- 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 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 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 GetDrugWarehouseOrder(id int64) (models.DrugWarehouseInfo, error) {
-
- info := models.DrugWarehouseInfo{}
- err = XTReadDB().Model(&info).Where("id = ?", 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}).Error
-
- }
-
- func EditDrugWarehousing(warehouse models.DrugWarehouse) {
- err = readDb.Model(&models.DrugWarehouse{}).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}).Error
-
- }
- func FindAllWarehouse(org_id int64, types int64) (list []*models.Warehousing, err error) {
- err = readDb.Model(&models.Warehousing{}).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 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
- }
- 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
- }
- 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 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 UpDateWarehouseInfoByStockDelete(id int64,count int64) (err error) {
- // err = DB.Model(&models.WarehousingInfo{}).Where("id = ?",info.ID).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
- // 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) {
- err = readDb.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}).Error
- }
-
- 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}).Error
- }
-
- func UpDateWarehouseOutInfo(info *models.WarehouseOutInfo) (err error) {
- err = writeDb.Save(&info).Error
- return err
- }
-
- func UpDateDrugWarehouseOutInfo(info *models.DrugWarehouseOutInfo) (err error) {
- err = writeDb.Save(&info).Error
- return err
- }
-
- func FindAllCancelList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (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("xt_manufacturer.manufacturer_name LIKE ? OR sgj_user_admin_role.user_name LIKE ? OR xt_cancel_stock.order_number LIKE ?", likeKey, 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)
- }
- 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) (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("xt_manufacturer.manufacturer_name LIKE ? OR sgj_user_admin_role.user_name LIKE ? OR xt_drug_cancel_stock.order_number LIKE ?", likeKey, 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)
- }
- 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 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
- }
- ut.Commit()
- return
- }
-
- 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
- }
- 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 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 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}).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}).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.CancelStock{}).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) (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", 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.Joins("join xt_manufacturer on xt_manufacturer.id = xt_warehouse.manufacturer")
- //db = db.Where(" sgj_user_admin_role.user_name LIKE ?", likeKey).Group("xt_warehouse_info.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)
- }
-
- 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.ctime desc").Find(&list).Error
- return
- }
-
- func GetStockInDetailTotal(orgId int64, startTime int64, endTime int64, keywords string, manufacturer int64, order_type int64, dealer 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)
- }
- 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) (list []*models.WarehouseOutInfo, total int64, err error) {
- 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 ? OR xt_good_information.specification_name LIKE ?", 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)
- }
-
- db = db.Preload("WarehouseOut", "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.ctime desc").Find(&list).Error
- return
- }
-
- func GetStockOutDetailTotal(orgId int64, startTime int64, endTime int64, keywords string, manufacturer int64, order_type int64, dealer 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)
- }
-
- 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 ?", 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 FindCancelDetailList(orgId int64, page int64, limit int64, startTime int64, endTime int64, keywords string, manufacturer int64, order_type int64, dealer 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 ?", 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)
- }
-
- 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.ctime 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 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 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}).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 AddSigleWarehouseOutInfo(info *models.WarehouseOutInfo) error {
-
- err := writeDb.Create(&info).Error
- 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 {
- ut := writeDb.Begin()
- err := ut.Create(&info).Error
- if err != nil {
- ut.Rollback()
- return err
- }
- ut.Commit()
- 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 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)", orgid).
- Preload("GoodInfo", "org_id = ? and status = 1", 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}).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", orgid).Find(&goodInfo).Error
-
- } else {
- err = XTReadDB().Where("org_id = ? and status = 1 AND good_name like ?", 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 float64, maxunit string, unival 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 dosage = ? and max_unit = ? and unval = ? and min_unit=? and packing_unit = ? and status =1 and org_id = ?", drugname, dosage, maxunit, unival, 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, "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) {
- err = readDb.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}).Error
-
- }
-
- 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 GetAllDealerList(orgid int64) (list []*models.Dealer, err error) {
-
- err = XTReadDB().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 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 ", orgid)
- if len(keywords) > 0 {
- likekey := "%" + keywords + "%"
- err = db.Where("(drug_name LIKE ?)", likekey).Find(&drug).Error
- } else {
- err = db.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", 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.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 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}).Error
- return err
- }
-
- func UpDateWarehouseInfoByStockDelete(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 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 FindGoodInfoByIdTwo(id int64) (goodInfo models.GoodInfo, err error) {
- err = readDb.Model(&models.GoodInfo{}).Where("id = ? AND status = 1", id).First(&goodInfo).Error
- return
- }
-
- 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) (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)
- }
-
- err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Preload("StWarehousingInfo", "status= 1 and org_id =? and ctime>=? and ctime<=?", orgid, startime, endtime).Preload("CancelStockInfo", "status= 1 and org_id =? and ctime>=? and ctime<=?", orgid, startime, endtime).Find(&info).Error
- return info, total, err
- }
-
- func GetStockListById(good_id int64, orgid int64, limit int64, page int64, startime int64, endtime 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)
- }
-
- 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,t.manufacturer,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.min_unit,t.buy_price").Joins("left join xt_good_information as t on t.id = x.good_id").Count(&total).Offset(offset).Limit(limit).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 startime > 0 {
- 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, startime).Scan(&autoMatic).Error
- } else {
- 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 `status` = 1) as b GROUP BY good_id", orgid).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 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, endtime).Scan(&autoMatic).Error
- } else {
- 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 `status` = 1) as b GROUP BY good_id", orgid).Scan(&autoMatic).Error
- }
-
- return autoMatic, 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,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_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").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")
- fmt.Println(table)
- 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,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_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.warehouse_out_id,x.good_id").Order("x.ctime desc").Scan(&out).Error
- return out, 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 = ? ", 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 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 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")
- fmt.Println(table)
- if orgid > 0 {
- db = db.Where("x.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,t.good_name,t.specification_name,t.min_number,t.packing_price,t.min_unit,t.packing_unit,t.manufacturer,t.dealer").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) (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)
- }
-
- err = db.Find(&info).Error
- return info, err
- }
-
- func GetDrugWarehouseOrderDetailTwo(ids []int64, orgid int64, startime int64, endtime 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)
- }
-
- err = db.Find(&info).Error
- return info, err
- }
-
- func GetDrugTotalCount(drugid int64, orgid int64) (info models.VmDrugWarehouseInfo, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
- 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,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 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) (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)
- }
- 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).Group("number").Find(&info).Error
- return info, err
- }
-
- func GetWarehouseOutInfoById(id int64, goodid int64) (info []*models.WarehouseOutInfo, err error) {
-
- err = XTReadDB().Model(&info).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")
- 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
- //err = XTReadDB().Model(&stock).Where("warehouse_out_id = ? and good_id = ? and status = 1", id, goodid).Find(&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) (out []*models.StDrugWarehouseInfo, err error) {
-
- db := XTReadDB().Table("xt_drug_warehouse_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.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").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 GetLastGoodInformationByGoodId(goodid int64, warehouse_info_id int64, orgid 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) (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)
- }
-
- 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) (info models.WarehousingInfo, err error) {
- err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND status = 1 and id<>?", good_id, id).Order("ctime").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 {
-
- err := XTWriteDB().Create(&flow).Error
- return err
- }
-
- func UpdatedStockFlow(flow models.VmStockFlow) error {
- err := XTWriteDB().Save(&flow).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", 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 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) (*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 = ?", 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 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)
- 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 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).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) 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}).Error
- 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)
- 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")
- }
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").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 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 = ?", 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 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 UpdateDrugWarehouseInfo(info *models.XtDrugWarehouseInfo, id int64) error {
-
- //err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_max_number": info.StockMaxNumber}).Error
- //return err
- 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 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 GetLastCancelStockInfo(id int64) (models.DrugCancelStockInfo, error) {
-
- info := models.DrugCancelStockInfo{}
-
- err := XTReadDB().Where("id = ? and status = 1", id).Find(&info).Error
- return info, err
- }
-
- func UpdatedDrugInfo(id int64, count int64) (err error) {
-
- err = writeDb.Model(&models.DrugWarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
- return err
- }
-
- func UpdatedDrugInfoOne(id int64, count int64) (err error) {
-
- err = writeDb.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) 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) 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 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 CreateWarehouseInfo(info models.WarehousingInfo) error {
-
- err := XTReadDB().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 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 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}).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 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 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 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) (info []*models.BloodWarehouseInfo, err error) {
-
- db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 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)
- }
- 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,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 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.start_time>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.end_time<=?", 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 GetWarehouseInfoById(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 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) (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")
- 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 = ? or r.user_name like ?", keyword, likeKey)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- 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").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
- }
|