stock_in_api_controller.go 200KB

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