stock_in_api_controller.go 192KB

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