stock_in_api_controller.go 147KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591
  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. func (c *StockManagerApiController) CreateWarehouse() {
  79. warehousing_time := c.GetString("warehousing_time")
  80. types, _ := c.GetInt64("type", 0)
  81. ctime := time.Now().Unix()
  82. adminUserInfo := c.GetAdminUserInfo()
  83. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  84. if parseDateErr != nil {
  85. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  86. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  87. return
  88. }
  89. timeStr := time.Now().Format("2006-01-02")
  90. timeArr := strings.Split(timeStr, "-")
  91. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  92. total = total + 1
  93. warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  94. operation_time := time.Now().Unix()
  95. creater := adminUserInfo.AdminUser.Id
  96. warehousing := models.Warehousing{
  97. WarehousingOrder: warehousing_order,
  98. OperationTime: operation_time,
  99. OrgId: adminUserInfo.CurrentOrgId,
  100. Creater: creater,
  101. Ctime: ctime,
  102. Status: 1,
  103. WarehousingTime: warehousingDate.Unix(),
  104. Type: types,
  105. }
  106. service.AddSigleWarehouse(&warehousing)
  107. dataBody := make(map[string]interface{}, 0)
  108. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  109. if err != nil {
  110. utils.ErrorLog(err.Error())
  111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  112. return
  113. }
  114. var warehousingInfo []*models.WarehousingInfo
  115. var stockFlow []*models.VmStockFlow
  116. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  117. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  118. if len(thisStockIn) > 0 {
  119. for _, item := range thisStockIn {
  120. items := item.(map[string]interface{})
  121. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  122. utils.ErrorLog("good_id")
  123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  124. return
  125. }
  126. good_id := int64(items["good_id"].(float64))
  127. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  128. utils.ErrorLog("good_type_id")
  129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  130. return
  131. }
  132. good_type_id := int64(items["good_type_id"].(float64))
  133. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  134. utils.ErrorLog("warehousing_count")
  135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  136. return
  137. }
  138. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  139. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  140. utils.ErrorLog("price")
  141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  142. return
  143. }
  144. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  145. total := float64(warehousing_count) * price
  146. var productDates int64
  147. var expiryDates int64
  148. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  149. expiryDates = 0
  150. } else {
  151. if len(items["expiry_date"].(string)) == 0 {
  152. expiryDates = 0
  153. } else {
  154. expiryDate, _ := items["expiry_date"].(string)
  155. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  156. expiryDates = expiry_date.Unix()
  157. }
  158. }
  159. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  160. productDates = 0
  161. } else {
  162. if len(items["product_date"].(string)) == 0 {
  163. productDates = 0
  164. } else {
  165. productDate, _ := items["product_date"].(string)
  166. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  167. productDates = product_date.Unix()
  168. }
  169. }
  170. number, _ := items["number"].(string)
  171. remark, _ := items["remark"].(string)
  172. manufacturer := int64(items["manufacturer"].(float64))
  173. dealer := int64(items["dealer"].(float64))
  174. license_number, _ := items["license_number"].(string)
  175. //入库单表格
  176. warehouseInfo := &models.WarehousingInfo{
  177. WarehousingOrder: warehousing.WarehousingOrder,
  178. WarehousingId: warehousing.ID,
  179. GoodId: good_id,
  180. Number: number,
  181. GoodTypeId: good_type_id,
  182. ProductDate: productDates,
  183. ExpiryDate: expiryDates,
  184. WarehousingCount: warehousing_count,
  185. Price: price,
  186. TotalPrice: total,
  187. Status: 1,
  188. Ctime: ctime,
  189. Remark: remark,
  190. OrgId: adminUserInfo.CurrentOrgId,
  191. Type: types,
  192. Manufacturer: manufacturer,
  193. StockCount: warehousing_count,
  194. Dealer: dealer,
  195. LicenseNumber: license_number,
  196. }
  197. warehousingInfo = append(warehousingInfo, warehouseInfo)
  198. flow := &models.VmStockFlow{
  199. WarehousingOrder: warehousing.WarehousingOrder,
  200. WarehousingId: warehousing.ID,
  201. GoodId: good_id,
  202. Number: number,
  203. ProductDate: productDates,
  204. ExpireDate: expiryDates,
  205. Count: warehousing_count,
  206. Price: price,
  207. Status: 1,
  208. Ctime: ctime,
  209. UserOrgId: adminUserInfo.CurrentOrgId,
  210. Manufacturer: manufacturer,
  211. Dealer: dealer,
  212. LicenseNumber: license_number,
  213. IsEdit: 1,
  214. Creator: adminUserInfo.AdminUser.Id,
  215. SystemTime: operation_time,
  216. ConsumableType: 1,
  217. WarehousingDetailId: warehouseInfo.ID,
  218. }
  219. stockFlow = append(stockFlow, flow)
  220. }
  221. }
  222. }
  223. //入库单创建成功
  224. errs := service.CreateWarehousingInfo(warehousingInfo)
  225. //创建入库单流水
  226. service.CreateStockFlow(stockFlow)
  227. info, _ := service.FindLastWarehousingInfo(warehousing.WarehousingOrder)
  228. if errs != nil {
  229. utils.ErrorLog(errs.Error())
  230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  231. return
  232. }
  233. c.ServeSuccessJSON(map[string]interface{}{
  234. "msg": "入库成功",
  235. "warehousing_order": warehousing_order,
  236. "info": info,
  237. })
  238. }
  239. func (c *StockManagerApiController) GetWarehouseList() {
  240. page, _ := c.GetInt64("page", -1)
  241. limit, _ := c.GetInt64("limit", -1)
  242. start_time := c.GetString("start_time")
  243. end_time := c.GetString("end_time")
  244. types, _ := c.GetInt64("type", 0)
  245. keywords := c.GetString("keywords")
  246. timeLayout := "2006-01-02"
  247. loc, _ := time.LoadLocation("Local")
  248. var startTime int64
  249. if len(start_time) > 0 {
  250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  251. if err != nil {
  252. fmt.Println(err)
  253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  254. return
  255. }
  256. startTime = theTime.Unix()
  257. }
  258. var endTime int64
  259. if len(end_time) > 0 {
  260. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  261. if err != nil {
  262. utils.ErrorLog(err.Error())
  263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  264. return
  265. }
  266. endTime = theTime.Unix()
  267. }
  268. adminUserInfo := c.GetAdminUserInfo()
  269. var ids []int64
  270. var goodids []int64
  271. //查询商品名称
  272. if len(keywords) > 0 {
  273. //查询商品名称
  274. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  275. for _, item := range list {
  276. goodids = append(goodids, item.ID)
  277. //入库详情但里面查询
  278. }
  279. if len(goodids) > 0 {
  280. info, _ := service.GetWarehoureOrderInfoByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
  281. for _, it := range info {
  282. ids = append(ids, it.WarehousingId)
  283. }
  284. }
  285. }
  286. warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  287. if err == nil {
  288. c.ServeSuccessJSON(map[string]interface{}{
  289. "list": warehouseList,
  290. "total": total,
  291. })
  292. } else {
  293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  294. }
  295. }
  296. func (c *StockManagerApiController) GetWarehouseInfoList() {
  297. id := c.GetString("id")
  298. idArray := strings.Split(id, ",")
  299. warehousing, err := service.FindWarehousingByIdOne(idArray)
  300. if err != nil {
  301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  302. return
  303. }
  304. var ids []int64
  305. for _, item := range warehousing {
  306. ids = append(ids, item.ID)
  307. }
  308. warehousingInfo, err := service.FindWarehousingInfoByIdOne(ids)
  309. if err == nil {
  310. c.ServeSuccessJSON(map[string]interface{}{
  311. "info": warehousingInfo,
  312. "warehousing": warehousing,
  313. })
  314. } else {
  315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  316. }
  317. }
  318. func (c *StockManagerApiController) EditWarehouse() {
  319. warehousing_time := c.GetString("warehousing_time")
  320. id, _ := c.GetInt64("id", 0)
  321. types, _ := c.GetInt64("type", 0)
  322. if id == 0 {
  323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  324. return
  325. }
  326. ctime := time.Now().Unix()
  327. mtime := time.Now().Unix()
  328. adminUserInfo := c.GetAdminUserInfo()
  329. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  330. if parseDateErr != nil {
  331. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  333. return
  334. }
  335. warehouse, _ := service.FindWarehousingById(id)
  336. warehousing := models.Warehousing{
  337. WarehousingOrder: warehouse.WarehousingOrder,
  338. OrgId: adminUserInfo.CurrentOrgId,
  339. Modifier: adminUserInfo.AdminUser.Id,
  340. Mtime: mtime,
  341. Status: 1,
  342. WarehousingTime: warehousingDate.Unix(),
  343. Type: warehouse.Type,
  344. }
  345. service.EditWarehousing(warehousing)
  346. dataBody := make(map[string]interface{}, 0)
  347. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  348. if err != nil {
  349. utils.ErrorLog(err.Error())
  350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  351. return
  352. }
  353. var warehousingInfo []*models.WarehousingInfo
  354. var upDateWarehousingInfo []*models.WarehousingInfo
  355. var stockFlow []*models.VmStockFlow
  356. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  357. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  358. if len(thisStockIn) > 0 {
  359. for _, item := range thisStockIn {
  360. items := item.(map[string]interface{})
  361. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  362. utils.ErrorLog("good_id")
  363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  364. return
  365. }
  366. good_id := int64(items["good_id"].(float64))
  367. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  368. utils.ErrorLog("good_type_id")
  369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  370. return
  371. }
  372. good_type_id := int64(items["good_type_id"].(float64))
  373. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  374. utils.ErrorLog("warehousing_count")
  375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  376. return
  377. }
  378. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  379. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  380. utils.ErrorLog("price")
  381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  382. return
  383. }
  384. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  385. total := float64(warehousing_count) * price
  386. var productDates int64
  387. var expiryDates int64
  388. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  389. expiryDates = 0
  390. } else {
  391. if len(items["expiry_date"].(string)) == 0 {
  392. expiryDates = 0
  393. } else {
  394. expiryDate, _ := items["expiry_date"].(string)
  395. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  396. expiryDates = expiry_date.Unix()
  397. }
  398. }
  399. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  400. productDates = 0
  401. } else {
  402. if len(items["product_date"].(string)) == 0 {
  403. productDates = 0
  404. } else {
  405. productDate, _ := items["product_date"].(string)
  406. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  407. productDates = product_date.Unix()
  408. }
  409. }
  410. number, _ := items["number"].(string)
  411. remark, _ := items["remark"].(string)
  412. manufacturer := int64(items["manufacturer"].(float64))
  413. dealer := int64(items["dealer"].(float64))
  414. license_number, _ := items["license_number"].(string)
  415. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  416. utils.ErrorLog("id")
  417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  418. return
  419. }
  420. id := int64(items["id"].(float64))
  421. if id == 0 {
  422. warehouseInfo := &models.WarehousingInfo{
  423. WarehousingOrder: warehouse.WarehousingOrder,
  424. WarehousingId: warehouse.ID,
  425. GoodId: good_id,
  426. Number: number,
  427. GoodTypeId: good_type_id,
  428. ProductDate: productDates,
  429. ExpiryDate: expiryDates,
  430. WarehousingCount: warehousing_count,
  431. Price: price,
  432. TotalPrice: total,
  433. Status: 1,
  434. Ctime: ctime,
  435. Remark: remark,
  436. OrgId: adminUserInfo.CurrentOrgId,
  437. Type: types,
  438. Manufacturer: manufacturer,
  439. Dealer: dealer,
  440. StockCount: warehousing_count,
  441. LicenseNumber: license_number,
  442. }
  443. warehousingInfo = append(warehousingInfo, warehouseInfo)
  444. flow := &models.VmStockFlow{
  445. WarehousingOrder: warehousing.WarehousingOrder,
  446. WarehousingId: warehousing.ID,
  447. GoodId: good_id,
  448. Number: number,
  449. ProductDate: productDates,
  450. ExpireDate: expiryDates,
  451. Count: warehousing_count,
  452. Price: price,
  453. Status: 1,
  454. Ctime: ctime,
  455. UserOrgId: adminUserInfo.CurrentOrgId,
  456. Manufacturer: manufacturer,
  457. Dealer: dealer,
  458. LicenseNumber: license_number,
  459. IsEdit: 1,
  460. Creator: adminUserInfo.AdminUser.Id,
  461. SystemTime: ctime,
  462. ConsumableType: 1,
  463. WarehousingDetailId: warehouseInfo.ID,
  464. }
  465. stockFlow = append(stockFlow, flow)
  466. } else {
  467. warehouseInfo := &models.WarehousingInfo{
  468. ID: id,
  469. WarehousingOrder: warehouse.WarehousingOrder,
  470. WarehousingId: warehouse.ID,
  471. GoodId: good_id,
  472. Number: number,
  473. GoodTypeId: good_type_id,
  474. ProductDate: productDates,
  475. ExpiryDate: expiryDates,
  476. WarehousingCount: warehousing_count,
  477. Price: price,
  478. TotalPrice: total,
  479. Status: 1,
  480. Ctime: ctime,
  481. Remark: remark,
  482. OrgId: adminUserInfo.CurrentOrgId,
  483. Type: types,
  484. Manufacturer: manufacturer,
  485. Dealer: dealer,
  486. StockCount: warehousing_count,
  487. LicenseNumber: license_number,
  488. }
  489. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  490. flow := &models.VmStockFlow{
  491. WarehousingOrder: warehousing.WarehousingOrder,
  492. WarehousingId: warehousing.ID,
  493. GoodId: good_id,
  494. Number: number,
  495. ProductDate: productDates,
  496. ExpireDate: expiryDates,
  497. Count: warehousing_count,
  498. Price: price,
  499. Status: 1,
  500. Ctime: ctime,
  501. UserOrgId: adminUserInfo.CurrentOrgId,
  502. Manufacturer: manufacturer,
  503. Dealer: dealer,
  504. LicenseNumber: license_number,
  505. IsEdit: 2,
  506. Creator: adminUserInfo.AdminUser.Id,
  507. SystemTime: ctime,
  508. ConsumableType: 1,
  509. WarehousingDetailId: warehouseInfo.ID,
  510. }
  511. stockFlow = append(stockFlow, flow)
  512. }
  513. }
  514. }
  515. }
  516. var errs error
  517. if len(warehousingInfo) > 0 {
  518. errs = service.CreateWarehousingInfo(warehousingInfo)
  519. service.CreateStockFlow(stockFlow)
  520. }
  521. if len(upDateWarehousingInfo) > 0 {
  522. for _, item := range upDateWarehousingInfo {
  523. var total int64
  524. var all_total int64
  525. //获取该批次该型号的库存
  526. info, _ := service.GetLastWarehousingById(item.WarehousingId, item.GoodId)
  527. //判断 该批次的入库数量
  528. total = item.WarehousingCount - info.WarehousingCount
  529. all_total = info.StockCount + total
  530. item.StockCount = all_total
  531. errs = service.UpDateWarehousingInfo(item)
  532. service.CreateStockFlow(stockFlow)
  533. }
  534. }
  535. if errs != nil {
  536. utils.ErrorLog(errs.Error())
  537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  538. return
  539. }
  540. c.ServeSuccessJSON(map[string]interface{}{
  541. "msg": "编辑成功",
  542. })
  543. }
  544. func (c *StockManagerApiController) DeleteWarehouse() {
  545. ids := c.GetString("ids")
  546. if len(ids) == 0 {
  547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  548. return
  549. }
  550. idArray := strings.Split(ids, ",")
  551. err := service.DeleteWarehouse(idArray)
  552. if err != nil {
  553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  554. } else {
  555. c.ServeSuccessJSON(map[string]interface{}{
  556. "msg": "删除成功",
  557. })
  558. }
  559. }
  560. func (c *StockManagerApiController) DeleteWarehouseInfo() {
  561. id, _ := c.GetInt64("id", 0)
  562. if id == 0 {
  563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  564. return
  565. }
  566. err := service.UpDateWarehouseStatus(id)
  567. if err != nil {
  568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  569. } else {
  570. c.ServeSuccessJSON(map[string]interface{}{
  571. "msg": "删除成功",
  572. })
  573. }
  574. }
  575. func (c *StockManagerApiController) CreateSalesReturn() {
  576. dealer_id, _ := c.GetInt64("dealer_id", 0)
  577. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  578. sales_return_time := c.GetString("time")
  579. types, _ := c.GetInt64("type", 0)
  580. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  581. if parseDateErr != nil {
  582. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  584. return
  585. }
  586. adminUserInfo := c.GetAdminUserInfo()
  587. operation_time := time.Now().Unix()
  588. creater := adminUserInfo.AdminUser.Id
  589. ctime := time.Now().Unix()
  590. timeStr := time.Now().Format("2006-01-02")
  591. timeArr := strings.Split(timeStr, "-")
  592. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  593. total = total + 1
  594. orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  595. salesReturn := models.SalesReturn{
  596. OrderNumber: orderNumber,
  597. OperaTime: operation_time,
  598. OrgId: adminUserInfo.CurrentOrgId,
  599. Creater: creater,
  600. Ctime: ctime,
  601. Status: 1,
  602. ReturnTime: salesReturnDate.Unix(),
  603. Dealer: dealer_id,
  604. Manufacturer: manufacturer_id,
  605. Type: types,
  606. }
  607. service.AddSigleSalesReturn(&salesReturn)
  608. dataBody := make(map[string]interface{}, 0)
  609. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  610. if err != nil {
  611. utils.ErrorLog(err.Error())
  612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  613. return
  614. }
  615. var salesReturnInfos []*models.SalesReturnInfo
  616. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  617. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  618. if len(thisStockIn) > 0 {
  619. for _, item := range thisStockIn {
  620. items := item.(map[string]interface{})
  621. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  622. utils.ErrorLog("good_id")
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  624. return
  625. }
  626. good_id := int64(items["good_id"].(float64))
  627. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  628. utils.ErrorLog("good_type_id")
  629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  630. return
  631. }
  632. good_type_id := int64(items["good_type_id"].(float64))
  633. return_count, _ := items["return_count"].(string)
  634. if len(return_count) == 0 {
  635. utils.ErrorLog("len(return_count) == 0")
  636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  637. return
  638. }
  639. count, _ := strconv.ParseInt(return_count, 10, 64)
  640. price, _ := strconv.ParseFloat(items["price"].(string), 10)
  641. total := float64(count) * price
  642. salesReturnInfo := &models.SalesReturnInfo{
  643. OrderNumber: salesReturn.OrderNumber,
  644. SalesReturnId: salesReturn.ID,
  645. GoodId: good_id,
  646. GoodTypeId: good_type_id,
  647. Count: count,
  648. Price: price,
  649. Total: total,
  650. Status: 1,
  651. Ctime: ctime,
  652. OrgId: adminUserInfo.CurrentOrgId,
  653. Type: types,
  654. Manufacturer: manufacturer_id,
  655. Dealer: dealer_id,
  656. }
  657. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  658. }
  659. }
  660. }
  661. errs := service.CreateSalesReturnInfo(salesReturnInfos)
  662. if errs != nil {
  663. utils.ErrorLog(errs.Error())
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  665. return
  666. }
  667. c.ServeSuccessJSON(map[string]interface{}{
  668. "msg": "退货成功",
  669. })
  670. }
  671. func (c *StockManagerApiController) GetSalesReturnList() {
  672. page, _ := c.GetInt64("page", -1)
  673. limit, _ := c.GetInt64("limit", -1)
  674. start_time := c.GetString("start_time")
  675. end_time := c.GetString("end_time")
  676. types, _ := c.GetInt64("type", 0)
  677. keywords := c.GetString("keywords")
  678. timeLayout := "2006-01-02"
  679. loc, _ := time.LoadLocation("Local")
  680. var startTime int64
  681. if len(start_time) > 0 {
  682. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  683. if err != nil {
  684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  685. return
  686. }
  687. startTime = theTime.Unix()
  688. }
  689. var endTime int64
  690. if len(end_time) > 0 {
  691. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  692. if err != nil {
  693. utils.ErrorLog(err.Error())
  694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  695. return
  696. }
  697. endTime = theTime.Unix()
  698. }
  699. adminUserInfo := c.GetAdminUserInfo()
  700. returnList, total, err := service.FindAllReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  701. if err == nil {
  702. c.ServeSuccessJSON(map[string]interface{}{
  703. "list": returnList,
  704. "total": total,
  705. })
  706. } else {
  707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  708. }
  709. }
  710. func (this *StockManagerApiController) DeleteSalesReturn() {
  711. ids := this.GetString("ids")
  712. if len(ids) == 0 {
  713. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  714. return
  715. }
  716. idArray := strings.Split(ids, ",")
  717. err := service.DeleteSalesReturn(idArray)
  718. if err != nil {
  719. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  720. } else {
  721. this.ServeSuccessJSON(map[string]interface{}{
  722. "msg": "删除成功",
  723. })
  724. }
  725. }
  726. func (this *StockManagerApiController) DeleteSalesReturnInfo() {
  727. id, _ := this.GetInt64("id", 0)
  728. fmt.Println(id)
  729. if id == 0 {
  730. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  731. return
  732. }
  733. err := service.UpDateSaleReturnStatus(id)
  734. if err != nil {
  735. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  736. } else {
  737. this.ServeSuccessJSON(map[string]interface{}{
  738. "msg": "删除成功",
  739. })
  740. }
  741. }
  742. func (this *StockManagerApiController) GetSalesReturnInfoList() {
  743. id, _ := this.GetInt64("id", 0)
  744. list, _ := service.FindAllSalesReturnInfoById(id)
  745. salesReturn, _ := service.FindAllSalesReturnById(id)
  746. this.ServeSuccessJSON(map[string]interface{}{
  747. "list": list,
  748. "salesReturn": salesReturn,
  749. })
  750. }
  751. func (c *StockManagerApiController) EditReturnInfo() {
  752. return_time := c.GetString("return_time")
  753. id, _ := c.GetInt64("id", 0)
  754. types, _ := c.GetInt64("type", 0)
  755. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  756. dealer_id, _ := c.GetInt64("dealer_id", 0)
  757. if id == 0 {
  758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  759. return
  760. }
  761. ctime := time.Now().Unix()
  762. mtime := time.Now().Unix()
  763. adminUserInfo := c.GetAdminUserInfo()
  764. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  765. if parseDateErr != nil {
  766. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  768. return
  769. }
  770. salesReturns, _ := service.FindSalesReturnById(id)
  771. sales := models.SalesReturn{
  772. ID: salesReturns.ID,
  773. Mtime: mtime,
  774. ReturnTime: returnDate.Unix(),
  775. Manufacturer: manufacturer_id,
  776. Dealer: dealer_id,
  777. }
  778. service.EditSaleReturn(sales)
  779. dataBody := make(map[string]interface{}, 0)
  780. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  781. if err != nil {
  782. utils.ErrorLog(err.Error())
  783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  784. return
  785. }
  786. var returnInfos []*models.SalesReturnInfo
  787. var upDateReturnInfos []*models.SalesReturnInfo
  788. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  789. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  790. if len(thisStockIn) > 0 {
  791. for _, item := range thisStockIn {
  792. items := item.(map[string]interface{})
  793. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  794. utils.ErrorLog("good_id")
  795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  796. return
  797. }
  798. good_id := int64(items["good_id"].(float64))
  799. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  800. utils.ErrorLog("good_type_id")
  801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  802. return
  803. }
  804. good_type_id := int64(items["good_type_id"].(float64))
  805. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  806. utils.ErrorLog("count")
  807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  808. return
  809. }
  810. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  811. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  812. utils.ErrorLog("id")
  813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  814. return
  815. }
  816. id := int64(items["id"].(float64))
  817. if id == 0 {
  818. returnInfo := &models.SalesReturnInfo{
  819. GoodId: good_id,
  820. GoodTypeId: good_type_id,
  821. Count: count,
  822. Status: 1,
  823. Ctime: ctime,
  824. OrgId: adminUserInfo.CurrentOrgId,
  825. OrderNumber: sales.OrderNumber,
  826. SalesReturnId: sales.ID,
  827. Mtime: time.Now().Unix(),
  828. Type: types,
  829. Manufacturer: manufacturer_id,
  830. Dealer: dealer_id,
  831. }
  832. returnInfos = append(returnInfos, returnInfo)
  833. } else {
  834. returnInfo := &models.SalesReturnInfo{
  835. ID: id,
  836. GoodId: good_id,
  837. GoodTypeId: good_type_id,
  838. Count: count,
  839. Status: 1,
  840. Ctime: ctime,
  841. OrgId: adminUserInfo.CurrentOrgId,
  842. OrderNumber: sales.OrderNumber,
  843. SalesReturnId: sales.ID,
  844. Mtime: time.Now().Unix(),
  845. Type: types,
  846. Manufacturer: manufacturer_id,
  847. Dealer: dealer_id,
  848. }
  849. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  850. }
  851. }
  852. }
  853. }
  854. var errs error
  855. if len(returnInfos) > 0 {
  856. errs = service.CreateSalesReturnInfo(returnInfos)
  857. }
  858. if len(upDateReturnInfos) > 0 {
  859. for _, item := range upDateReturnInfos {
  860. errs = service.UpDateSalesReturnInfo(item)
  861. }
  862. }
  863. if errs != nil {
  864. utils.ErrorLog(errs.Error())
  865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  866. return
  867. }
  868. c.ServeSuccessJSON(map[string]interface{}{
  869. "msg": "编辑成功",
  870. })
  871. }
  872. func (c *StockManagerApiController) CreateWarehouseOut() {
  873. types, _ := c.GetInt64("type", 0)
  874. ctime := time.Now().Unix()
  875. adminUserInfo := c.GetAdminUserInfo()
  876. warehousing_out_time := c.GetString("warehousing_out_time")
  877. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  878. if parseDateErr != nil {
  879. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  881. return
  882. }
  883. timeStr := time.Now().Format("2006-01-02")
  884. timeArr := strings.Split(timeStr, "-")
  885. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  886. total = total + 1
  887. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  888. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  889. number = number + total
  890. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  891. operation_time := time.Now().Unix()
  892. creater := adminUserInfo.AdminUser.Id
  893. warehouseOut := models.WarehouseOut{
  894. WarehouseOutOrderNumber: warehousing_out_order,
  895. OperationTime: operation_time,
  896. OrgId: adminUserInfo.CurrentOrgId,
  897. Creater: creater,
  898. Ctime: ctime,
  899. Status: 1,
  900. WarehouseOutTime: warehousingOutDate.Unix(),
  901. Type: types,
  902. }
  903. dataBody := make(map[string]interface{}, 0)
  904. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  905. if err != nil {
  906. utils.ErrorLog(err.Error())
  907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  908. return
  909. }
  910. var warehousingOutInfo []*models.WarehouseOutInfo
  911. var beforePrepares []*models.DialysisBeforePrepareGoods
  912. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  913. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  914. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  915. if len(thisStockIn) > 0 {
  916. for _, item := range thisStockIn {
  917. items := item.(map[string]interface{})
  918. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  919. utils.ErrorLog("good_id")
  920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  921. return
  922. }
  923. good_id := int64(items["good_id"].(float64))
  924. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  925. utils.ErrorLog("good_type_id")
  926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  927. return
  928. }
  929. good_type_id := int64(items["good_type_id"].(float64))
  930. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  931. utils.ErrorLog("count")
  932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  933. return
  934. }
  935. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  936. utils.ErrorLog("price")
  937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  938. return
  939. }
  940. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  941. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  942. total := float64(count) * price
  943. remark := items["remark"].(string)
  944. manufacturer := int64(items["manufacturer"].(float64))
  945. dealer := int64(items["dealer"].(float64))
  946. number := items["number"].(string)
  947. expiry_date := items["expiry_date"].(string)
  948. timeLayout := "2006-01-02"
  949. loc, _ := time.LoadLocation("Local")
  950. var expiryDate int64
  951. if len(expiry_date) > 0 {
  952. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  953. if err != nil {
  954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  955. return
  956. }
  957. expiryDate = theTime.Unix()
  958. }
  959. product_date := items["product_date"].(string)
  960. var productDate int64
  961. if len(product_date) > 0 {
  962. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  963. if err != nil {
  964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  965. return
  966. }
  967. productDate = theTime.Unix()
  968. }
  969. license_number := items["license_number"].(string)
  970. warehouseOutInfo := &models.WarehouseOutInfo{
  971. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  972. WarehouseOutId: warehouseOut.ID,
  973. GoodId: good_id,
  974. GoodTypeId: good_type_id,
  975. Count: count,
  976. Price: price,
  977. TotalPrice: total,
  978. Status: 1,
  979. Ctime: ctime,
  980. Remark: remark,
  981. OrgId: adminUserInfo.CurrentOrgId,
  982. Type: types,
  983. Manufacturer: manufacturer,
  984. Number: number,
  985. ExpiryDate: expiryDate,
  986. ProductDate: productDate,
  987. Dealer: dealer,
  988. LicenseNumber: license_number,
  989. }
  990. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  991. prepareGoods := &models.DialysisBeforePrepareGoods{
  992. GoodTypeId: good_type_id,
  993. GoodId: good_id,
  994. Count: count,
  995. }
  996. beforePrepares = append(beforePrepares, prepareGoods)
  997. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  998. GoodTypeId: good_type_id,
  999. GoodId: good_id,
  1000. Count: count,
  1001. }
  1002. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  1003. }
  1004. }
  1005. }
  1006. //出库逻辑
  1007. for _, item := range warehousingOutInfo {
  1008. //查询库存
  1009. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
  1010. fmt.Println("库存数量组吗", warehouse.Count)
  1011. if item.Count > warehouse.Count {
  1012. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  1013. c.ServeSuccessJSON(map[string]interface{}{
  1014. "msg": "1",
  1015. "good_name": goodObj.GoodName,
  1016. "specification_name": goodObj.SpecificationName,
  1017. })
  1018. return
  1019. } else {
  1020. _, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
  1021. if errcodes == gorm.ErrRecordNotFound {
  1022. service.AddSigleWarehouseOut(&warehouseOut)
  1023. }
  1024. parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
  1025. if parseDateErr != nil {
  1026. utils.ErrorLog(parseDateErr.Error())
  1027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1028. return
  1029. }
  1030. c.ServeSuccessJSON(map[string]interface{}{
  1031. "msg": "2",
  1032. "good_name": "",
  1033. "specification_name": "",
  1034. })
  1035. }
  1036. }
  1037. //errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
  1038. //info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
  1039. }
  1040. func (c *StockManagerApiController) GetWarehouseOutList() {
  1041. page, _ := c.GetInt64("page", -1)
  1042. limit, _ := c.GetInt64("limit", -1)
  1043. start_time := c.GetString("start_time")
  1044. end_time := c.GetString("end_time")
  1045. types, _ := c.GetInt64("type", 0)
  1046. keywords := c.GetString("keywords")
  1047. timeLayout := "2006-01-02"
  1048. loc, _ := time.LoadLocation("Local")
  1049. var startTime int64
  1050. if len(start_time) > 0 {
  1051. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1052. if err != nil {
  1053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1054. return
  1055. }
  1056. startTime = theTime.Unix()
  1057. }
  1058. var endTime int64
  1059. if len(end_time) > 0 {
  1060. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1061. if err != nil {
  1062. utils.ErrorLog(err.Error())
  1063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1064. return
  1065. }
  1066. endTime = theTime.Unix()
  1067. }
  1068. adminUserInfo := c.GetAdminUserInfo()
  1069. var ids []int64
  1070. var goodids []int64
  1071. if len(keywords) > 0 {
  1072. //查询商品名称
  1073. list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
  1074. for _, item := range list {
  1075. goodids = append(goodids, item.ID)
  1076. }
  1077. if len(goodids) > 0 {
  1078. //出库详情但里面查询
  1079. info, _ := service.GetWarehoureOrderOutByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
  1080. for _, it := range info {
  1081. ids = append(ids, it.WarehouseOutId)
  1082. }
  1083. }
  1084. }
  1085. warehouseOutList, total, err := service.FindAllWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  1086. fmt.Println(err)
  1087. if err == nil {
  1088. c.ServeSuccessJSON(map[string]interface{}{
  1089. "list": warehouseOutList,
  1090. "total": total,
  1091. })
  1092. } else {
  1093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1094. }
  1095. }
  1096. func (c *StockManagerApiController) DeleteWarehouseOut() {
  1097. ids := c.GetString("ids")
  1098. if len(ids) == 0 {
  1099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1100. return
  1101. }
  1102. idArray := strings.Split(ids, ",")
  1103. err := service.DeleteWarehouseOut(idArray)
  1104. if err != nil {
  1105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1106. } else {
  1107. c.ServeSuccessJSON(map[string]interface{}{
  1108. "msg": "删除成功",
  1109. })
  1110. }
  1111. }
  1112. func (this *StockManagerApiController) DeleteWarehouseOutInfo() {
  1113. id, _ := this.GetInt64("id", 0)
  1114. fmt.Println(id)
  1115. if id == 0 {
  1116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1117. return
  1118. }
  1119. err := service.UpDateWarehouseOutStatus(id)
  1120. if err != nil {
  1121. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1122. } else {
  1123. this.ServeSuccessJSON(map[string]interface{}{
  1124. "msg": "删除成功",
  1125. })
  1126. }
  1127. }
  1128. func (c *StockManagerApiController) GetWarehouseOutInfoList() {
  1129. id, _ := c.GetInt64("id", 0)
  1130. warehouseOutInfo, _ := service.FindWarehouseOutInfoById(id)
  1131. warehouseOut, _ := service.FindWareHouseOutById(id)
  1132. adminUserInfo := c.GetAdminUserInfo()
  1133. orgId := adminUserInfo.CurrentOrgId
  1134. wareoutList, _ := service.GetWareOutInfoById(id, orgId)
  1135. c.ServeSuccessJSON(map[string]interface{}{
  1136. "list": warehouseOutInfo,
  1137. "info": warehouseOut,
  1138. "wareoutList": wareoutList,
  1139. })
  1140. }
  1141. func (c *StockManagerApiController) EditWarehouseOut() {
  1142. warehouse_out_time := c.GetString("warehouse_out_time")
  1143. id, _ := c.GetInt64("id", 0)
  1144. types, _ := c.GetInt64("type", 0)
  1145. if id == 0 {
  1146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1147. return
  1148. }
  1149. ctime := time.Now().Unix()
  1150. mtime := time.Now().Unix()
  1151. adminUserInfo := c.GetAdminUserInfo()
  1152. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1153. if parseDateErr != nil {
  1154. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1156. return
  1157. }
  1158. warehouseOut, _ := service.FindWareHouseOutById(id)
  1159. tempWarehouseOut := models.WarehouseOut{
  1160. ID: warehouseOut.ID,
  1161. Mtime: mtime,
  1162. WarehouseOutTime: warehouseOutDate.Unix(),
  1163. }
  1164. service.EditWarehouseOut(tempWarehouseOut)
  1165. dataBody := make(map[string]interface{}, 0)
  1166. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1167. if err != nil {
  1168. utils.ErrorLog(err.Error())
  1169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1170. return
  1171. }
  1172. var warehousingOutInfo []*models.WarehouseOutInfo
  1173. var upDateWarehouseOutInfos []*models.WarehouseOutInfo
  1174. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1175. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1176. if len(thisStockOut) > 0 {
  1177. for _, item := range thisStockOut {
  1178. items := item.(map[string]interface{})
  1179. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1180. utils.ErrorLog("good_id")
  1181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1182. return
  1183. }
  1184. good_id := int64(items["good_id"].(float64))
  1185. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1186. utils.ErrorLog("good_type_id")
  1187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1188. return
  1189. }
  1190. good_type_id := int64(items["good_type_id"].(float64))
  1191. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1192. utils.ErrorLog("count")
  1193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1194. return
  1195. }
  1196. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1197. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1198. utils.ErrorLog("price")
  1199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1200. return
  1201. }
  1202. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1203. total := float64(count) * price
  1204. remark := items["remark"].(string)
  1205. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1206. utils.ErrorLog("id")
  1207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1208. return
  1209. }
  1210. id := int64(items["id"].(float64))
  1211. manufacturer := int64(items["manufacturer"].(float64))
  1212. dealer := int64(items["dealer"].(float64))
  1213. number := items["number"].(string)
  1214. license_number := items["license_number"].(string)
  1215. timeLayout := "2006-01-02"
  1216. loc, _ := time.LoadLocation("Local")
  1217. expiry_date := items["expiry_date"].(string)
  1218. var expiryDate int64
  1219. if len(expiry_date) > 0 {
  1220. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1221. if err != nil {
  1222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1223. return
  1224. }
  1225. expiryDate = theTime.Unix()
  1226. }
  1227. product_date := items["product_date"].(string)
  1228. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1229. var productDate int64
  1230. if len(product_date) > 0 {
  1231. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
  1232. if err != nil {
  1233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1234. return
  1235. }
  1236. productDate = theTime.Unix()
  1237. }
  1238. if id == 0 {
  1239. warehouseOutInfo := &models.WarehouseOutInfo{
  1240. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1241. WarehouseOutId: warehouseOut.ID,
  1242. GoodId: good_id,
  1243. GoodTypeId: good_type_id,
  1244. Count: count,
  1245. Price: price,
  1246. TotalPrice: total,
  1247. Status: 1,
  1248. Ctime: ctime,
  1249. Remark: remark,
  1250. OrgId: adminUserInfo.CurrentOrgId,
  1251. Type: types,
  1252. IsSys: 0,
  1253. SysRecordTime: 0,
  1254. Number: number,
  1255. ExpiryDate: expiryDate,
  1256. ProductDate: productDate,
  1257. Dealer: dealer,
  1258. Manufacturer: manufacturer,
  1259. LicenseNumber: license_number,
  1260. ConsumableType: 1,
  1261. WarehouseInfotId: warehouse_info_id,
  1262. }
  1263. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1264. } else {
  1265. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1266. utils.ErrorLog("is_sys")
  1267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1268. return
  1269. }
  1270. is_sys := int64(items["is_sys"].(float64))
  1271. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1272. utils.ErrorLog("sys_record_time")
  1273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1274. return
  1275. }
  1276. sys_record_time := int64(items["sys_record_time"].(float64))
  1277. warehouseOutInfo := &models.WarehouseOutInfo{
  1278. ID: id,
  1279. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1280. WarehouseOutId: warehouseOut.ID,
  1281. GoodId: good_id,
  1282. GoodTypeId: good_type_id,
  1283. Count: count,
  1284. Price: price,
  1285. TotalPrice: total,
  1286. Status: 1,
  1287. Ctime: ctime,
  1288. Remark: remark,
  1289. OrgId: adminUserInfo.CurrentOrgId,
  1290. Mtime: time.Now().Unix(),
  1291. Type: types,
  1292. Manufacturer: manufacturer,
  1293. IsSys: is_sys,
  1294. SysRecordTime: sys_record_time,
  1295. Number: number,
  1296. ExpiryDate: expiryDate,
  1297. ProductDate: productDate,
  1298. Dealer: dealer,
  1299. LicenseNumber: license_number,
  1300. ConsumableType: 2,
  1301. WarehouseInfotId: warehouse_info_id,
  1302. }
  1303. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1304. }
  1305. }
  1306. }
  1307. }
  1308. var errs error
  1309. if len(warehousingOutInfo) > 0 {
  1310. errs = service.CreateWarehousingOutInfo(warehousingOutInfo)
  1311. }
  1312. if len(upDateWarehouseOutInfos) > 0 {
  1313. for _, item := range upDateWarehouseOutInfos {
  1314. //1.查询该耗材该批次的最后一次出库记录
  1315. lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId, adminUserInfo.CurrentOrgId)
  1316. fmt.Println("lastGood", lastGood.Count)
  1317. fmt.Println("item2323232", item.Count)
  1318. // 退库的库存和该耗材该批次最后一次出库数量进行比较
  1319. //如果退库数量大于 最后一次批次的数量(要么要进行出库)
  1320. if item.Count > lastGood.Count {
  1321. //查询该耗材是否还有库存
  1322. warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId)
  1323. fmt.Println("hhhhhh23h2323232", warehouseinfo.StockCount)
  1324. //无库存
  1325. if warehouseinfo.StockCount <= 0 {
  1326. c.ServeSuccessJSON(map[string]interface{}{
  1327. "msg": "5",
  1328. })
  1329. return
  1330. }
  1331. //有库存,进行出库,调用出库接口
  1332. if warehouseinfo.StockCount > 0 {
  1333. var total int64
  1334. var stock_cout int64
  1335. var total_count int64
  1336. //计算和最后一次出库数据的差
  1337. total = item.Count - lastGood.Count
  1338. fmt.Println("total22323232", total)
  1339. //获取该耗材该批次的剩余库存量
  1340. info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1341. fmt.Println("info2232323232323", info)
  1342. //判断该批次的剩余库存 和出库的库存进行比较
  1343. //如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
  1344. if item.Count > info.StockCount {
  1345. //计算出库和该批次相差的库存
  1346. total_count = item.Count - info.StockCount
  1347. //清空本批次次库存
  1348. service.DeleteWarehouseInfo(item.WarehouseInfotId)
  1349. //调用出库逻辑
  1350. service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
  1351. }
  1352. //如果出库的库存小于或等于于该批次的剩余库存,那么需要该批次出库
  1353. if item.Count <= info.StockCount {
  1354. stock_cout = lastGood.Count + total
  1355. fmt.Println("232323223232323232323232", stock_cout)
  1356. //扣减库存
  1357. warehouse := models.WarehousingInfo{
  1358. StockCount: info.StockCount - total,
  1359. }
  1360. errs := service.UpdateWarehousingInfo(warehouse, info.ID)
  1361. warehouseOutInfo := &models.WarehouseOutInfo{
  1362. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1363. WarehouseOutId: id,
  1364. WarehouseInfotId: item.WarehouseInfotId,
  1365. Status: 1,
  1366. Ctime: time.Now().Unix(),
  1367. Remark: item.Remark,
  1368. OrgId: item.OrgId,
  1369. Type: 1,
  1370. Manufacturer: item.Manufacturer,
  1371. Dealer: item.Dealer,
  1372. IsSys: 0,
  1373. SysRecordTime: item.SysRecordTime,
  1374. GoodTypeId: item.GoodTypeId,
  1375. GoodId: item.GoodId,
  1376. ExpiryDate: item.ExpiryDate,
  1377. ProductDate: item.ProductDate,
  1378. Number: item.Number,
  1379. Price: item.Price,
  1380. LicenseNumber: item.LicenseNumber,
  1381. Count: item.Count,
  1382. ConsumableType: 2,
  1383. }
  1384. //查询是否存在
  1385. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1386. if errcode == gorm.ErrRecordNotFound {
  1387. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1388. if errOne != nil {
  1389. utils.ErrorLog(errs.Error())
  1390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1391. return
  1392. }
  1393. c.ServeSuccessJSON(map[string]interface{}{
  1394. "msg": "1",
  1395. })
  1396. } else if errcode == nil {
  1397. service.UpDateWarehouseOutInfo(item)
  1398. }
  1399. }
  1400. }
  1401. }
  1402. var last_count int64
  1403. var all_total int64
  1404. var stock_total int64
  1405. //如果退库数量小于最后一次批次的数量(要么要进行退库)
  1406. if item.Count < lastGood.Count {
  1407. fmt.Println("hh232323h2h3hh23hh23hh2h3h23")
  1408. //退库数量和最后一次出库数据进行计算
  1409. last_count = lastGood.Count - item.Count
  1410. fmt.Println("last_count", last_count)
  1411. //获取该耗材该批次的剩余库存量
  1412. infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
  1413. //退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
  1414. all_total = last_count + infoInfo.StockCount
  1415. fmt.Println("all_total", all_total)
  1416. //如果库存大于总数量,则退回到这个批次
  1417. fmt.Println("inf232323", infoInfo.WarehousingCount)
  1418. if infoInfo.WarehousingCount > all_total {
  1419. stock_total = last_count + infoInfo.StockCount
  1420. fmt.Println("经历323232323232232", last_count, stock_total)
  1421. //退回该批次,计算数量
  1422. warehousingInfoOne := models.WarehousingInfo{
  1423. StockCount: stock_total,
  1424. ID: item.WarehouseInfotId,
  1425. OrgId: item.OrgId,
  1426. }
  1427. fmt.Println("********************", warehousingInfoOne, item.WarehouseInfotId)
  1428. parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
  1429. fmt.Println("parseDateErr2323232322323", parseDateErr)
  1430. //插入一条新纪录
  1431. warehouseOutInfoThree := &models.WarehouseOutInfo{
  1432. WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
  1433. WarehouseOutId: id,
  1434. WarehouseInfotId: item.WarehouseInfotId,
  1435. Status: 1,
  1436. Ctime: time.Now().Unix(),
  1437. Remark: item.Remark,
  1438. OrgId: item.OrgId,
  1439. Type: 1,
  1440. Manufacturer: item.Manufacturer,
  1441. Dealer: item.Dealer,
  1442. IsSys: 0,
  1443. GoodTypeId: item.GoodTypeId,
  1444. GoodId: item.GoodId,
  1445. ExpiryDate: item.ExpiryDate,
  1446. ProductDate: item.ProductDate,
  1447. Number: item.Number,
  1448. Price: item.Price,
  1449. LicenseNumber: item.LicenseNumber,
  1450. ConsumableType: 2,
  1451. Count: item.Count,
  1452. }
  1453. //查询是否存在
  1454. _, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
  1455. if errcode == gorm.ErrRecordNotFound {
  1456. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfoThree)
  1457. if errOne != nil {
  1458. utils.ErrorLog(errs.Error())
  1459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1460. return
  1461. }
  1462. c.ServeSuccessJSON(map[string]interface{}{
  1463. "msg": "1",
  1464. })
  1465. } else if errcode == nil {
  1466. service.UpDateWarehouseOutInfo(item)
  1467. }
  1468. }
  1469. //如果库存小于总数量,则报错提醒,该批次的退库数据大于入库数据了无法退库,则需要退库到另一个批次
  1470. if infoInfo.WarehousingCount < all_total {
  1471. c.ServeSuccessJSON(map[string]interface{}{
  1472. "msg": "6",
  1473. })
  1474. return
  1475. }
  1476. }
  1477. if item.Count == lastGood.Count {
  1478. errs = service.UpDateWarehouseOutInfo(item)
  1479. if errs != nil {
  1480. utils.ErrorLog(errs.Error())
  1481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1482. return
  1483. }
  1484. c.ServeSuccessJSON(map[string]interface{}{
  1485. "msg": "1",
  1486. })
  1487. }
  1488. }
  1489. }
  1490. if errs != nil {
  1491. utils.ErrorLog(errs.Error())
  1492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1493. return
  1494. }
  1495. c.ServeSuccessJSON(map[string]interface{}{
  1496. "msg": "1",
  1497. })
  1498. }
  1499. func (c *StockManagerApiController) CreateCancelStock() {
  1500. cancel_stock_time := c.GetString("time")
  1501. types, _ := c.GetInt64("type", 0)
  1502. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1503. if parseDateErr != nil {
  1504. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1506. return
  1507. }
  1508. adminUserInfo := c.GetAdminUserInfo()
  1509. operation_time := time.Now().Unix()
  1510. creater := adminUserInfo.AdminUser.Id
  1511. ctime := time.Now().Unix()
  1512. timeStr := time.Now().Format("2006-01-02")
  1513. timeArr := strings.Split(timeStr, "-")
  1514. total, _ := service.FindAllCancelStockTotal(adminUserInfo.CurrentOrgId)
  1515. total = total + 1
  1516. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1517. cancelStock := models.CancelStock{
  1518. OrderNumber: orderNumber,
  1519. OperaTime: operation_time,
  1520. OrgId: adminUserInfo.CurrentOrgId,
  1521. Creater: creater,
  1522. Ctime: ctime,
  1523. Status: 1,
  1524. ReturnTime: cancelStockDate.Unix(),
  1525. Type: types,
  1526. }
  1527. service.AddSigleCancelStock(&cancelStock)
  1528. dataBody := make(map[string]interface{}, 0)
  1529. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1530. if err != nil {
  1531. utils.ErrorLog(err.Error())
  1532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1533. return
  1534. }
  1535. var cancelStockInfos []*models.CancelStockInfo
  1536. var stockFLow []*models.VmStockFlow
  1537. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1538. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1539. if len(thisStockIn) > 0 {
  1540. for _, item := range thisStockIn {
  1541. items := item.(map[string]interface{})
  1542. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1543. utils.ErrorLog("good_id")
  1544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1545. return
  1546. }
  1547. good_id := int64(items["good_id"].(float64))
  1548. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1549. utils.ErrorLog("good_type_id")
  1550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1551. return
  1552. }
  1553. good_type_id := int64(items["good_type_id"].(float64))
  1554. return_count, _ := items["return_count"].(string)
  1555. if len(return_count) == 0 {
  1556. utils.ErrorLog("len(return_count) == 0")
  1557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1558. return
  1559. }
  1560. count, _ := strconv.ParseInt(return_count, 10, 64)
  1561. number := items["number"].(string)
  1562. register_account := items["register_account"].(string)
  1563. manufacturer, _ := items["manufacturer"].(string)
  1564. dealer, _ := items["dealer"].(string)
  1565. var expiryDates int64
  1566. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1567. expiryDates = 0
  1568. } else {
  1569. if len(items["expiry_date"].(string)) == 0 {
  1570. expiryDates = 0
  1571. } else {
  1572. expiryDate, _ := items["expiry_date"].(string)
  1573. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1574. expiryDates = expiry_date.Unix()
  1575. }
  1576. }
  1577. var productDates int64
  1578. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1579. productDates = 0
  1580. } else {
  1581. if len(items["product_date"].(string)) == 0 {
  1582. productDates = 0
  1583. } else {
  1584. productDate, _ := items["product_date"].(string)
  1585. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1586. productDates = product_date.Unix()
  1587. }
  1588. }
  1589. remark := items["remark"].(string)
  1590. retail_prices := items["price"].(string)
  1591. price, _ := strconv.ParseFloat(retail_prices, 64)
  1592. cancelStockInfo := &models.CancelStockInfo{
  1593. OrderNumber: cancelStock.OrderNumber,
  1594. CancelStockId: cancelStock.ID,
  1595. GoodId: good_id,
  1596. GoodTypeId: good_type_id,
  1597. Count: count,
  1598. Status: 1,
  1599. Ctime: ctime,
  1600. OrgId: adminUserInfo.CurrentOrgId,
  1601. Type: types,
  1602. Manufacturer: manufacturer,
  1603. Dealer: dealer,
  1604. Number: number,
  1605. ProductDate: productDates,
  1606. ExpiryDate: expiryDates,
  1607. RegisterAccount: register_account,
  1608. Remark: remark,
  1609. Price: price,
  1610. }
  1611. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1612. flow := &models.VmStockFlow{
  1613. WarehousingId: 0,
  1614. GoodId: good_id,
  1615. Number: number,
  1616. LicenseNumber: "",
  1617. Count: count,
  1618. UserOrgId: adminUserInfo.CurrentOrgId,
  1619. PatientId: 0,
  1620. SystemTime: time.Now().Unix(),
  1621. ConsumableType: 4,
  1622. IsSys: 0,
  1623. WarehousingOrder: "",
  1624. WarehouseOutId: 0,
  1625. WarehouseOutOrderNumber: "",
  1626. IsEdit: 0,
  1627. CancelStockId: cancelStock.ID,
  1628. CancelOrderNumber: cancelStock.OrderNumber,
  1629. Manufacturer: 0,
  1630. Dealer: 0,
  1631. Creator: adminUserInfo.AdminUser.Id,
  1632. UpdateCreator: 0,
  1633. Status: 1,
  1634. Ctime: time.Now().Unix(),
  1635. Mtime: 0,
  1636. Price: price,
  1637. WarehousingDetailId: 0,
  1638. WarehouseOutDetailId: 0,
  1639. CancelOutDetailId: 0,
  1640. ProductDate: productDates,
  1641. ExpireDate: expiryDates,
  1642. }
  1643. stockFLow = append(stockFLow, flow)
  1644. }
  1645. }
  1646. }
  1647. errs := service.CreateCancelStockInfo(cancelStockInfos)
  1648. if len(stockFLow) > 0 {
  1649. service.CreateStockFlow(stockFLow)
  1650. }
  1651. for _, item := range cancelStockInfos {
  1652. ////查找该耗材是否有出库记录
  1653. //_, errcode := service.GetWarehoureOutOrderInfo(item.GoodId, item.OrgId)
  1654. //if errcode == gorm.ErrRecordNotFound {
  1655. // c.ServeSuccessJSON(map[string]interface{}{
  1656. // "msg": "1",
  1657. // })
  1658. // return
  1659. //}
  1660. //统计该耗材的出库数量
  1661. info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId)
  1662. if item.Count > info.Count {
  1663. c.ServeSuccessJSON(map[string]interface{}{
  1664. "msg": "2",
  1665. })
  1666. return
  1667. }
  1668. }
  1669. // 改变入库单的值
  1670. for _, item := range cancelStockInfos {
  1671. //查询该耗材的入库记录
  1672. list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
  1673. //调用退库的方法
  1674. parseDateErr := service.UpdateCancelOut(list, item.Count)
  1675. fmt.Println("999999999999", parseDateErr)
  1676. if parseDateErr != nil {
  1677. utils.ErrorLog(parseDateErr.Error())
  1678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1679. return
  1680. }
  1681. }
  1682. if errs != nil {
  1683. utils.ErrorLog(errs.Error())
  1684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1685. return
  1686. }
  1687. c.ServeSuccessJSON(map[string]interface{}{
  1688. "msg": "3",
  1689. })
  1690. }
  1691. func (c *StockManagerApiController) GetCancelStockInfoList() {
  1692. id, _ := c.GetInt64("id", 0)
  1693. cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
  1694. info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1695. manufacturerList, _ := service.GetAllManufacturerList(c.GetAdminUserInfo().CurrentOrgId)
  1696. dealerList, _ := service.GetAllDealerList(c.GetAdminUserInfo().CurrentOrgId)
  1697. c.ServeSuccessJSON(map[string]interface{}{
  1698. "list": cancelStockInfoList,
  1699. "info": info,
  1700. "manufacturerList": manufacturerList,
  1701. "dealerList": dealerList,
  1702. })
  1703. }
  1704. func (c *StockManagerApiController) GetCancelStockList() {
  1705. page, _ := c.GetInt64("page", -1)
  1706. limit, _ := c.GetInt64("limit", -1)
  1707. start_time := c.GetString("start_time")
  1708. end_time := c.GetString("end_time")
  1709. types, _ := c.GetInt64("type", 0)
  1710. keywords := c.GetString("keywords")
  1711. timeLayout := "2006-01-02"
  1712. loc, _ := time.LoadLocation("Local")
  1713. var startTime int64
  1714. if len(start_time) > 0 {
  1715. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1716. if err != nil {
  1717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1718. return
  1719. }
  1720. startTime = theTime.Unix()
  1721. }
  1722. var endTime int64
  1723. if len(end_time) > 0 {
  1724. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1725. if err != nil {
  1726. utils.ErrorLog(err.Error())
  1727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1728. return
  1729. }
  1730. endTime = theTime.Unix()
  1731. }
  1732. adminUserInfo := c.GetAdminUserInfo()
  1733. returnList, total, err := service.FindAllCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1734. if err == nil {
  1735. c.ServeSuccessJSON(map[string]interface{}{
  1736. "list": returnList,
  1737. "total": total,
  1738. })
  1739. } else {
  1740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1741. }
  1742. }
  1743. func (this *StockManagerApiController) DeleteCancelStock() {
  1744. ids := this.GetString("ids")
  1745. if len(ids) == 0 {
  1746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1747. return
  1748. }
  1749. idArray := strings.Split(ids, ",")
  1750. err := service.DeleteCancelStock(idArray)
  1751. if err != nil {
  1752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1753. } else {
  1754. this.ServeSuccessJSON(map[string]interface{}{
  1755. "msg": "删除成功",
  1756. })
  1757. }
  1758. }
  1759. func (this *StockManagerApiController) DeleteCancelStockInfo() {
  1760. id, _ := this.GetInt64("id", 0)
  1761. fmt.Println(id)
  1762. if id == 0 {
  1763. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1764. return
  1765. }
  1766. err := service.UpDateCancleStockStatus(id)
  1767. if err != nil {
  1768. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1769. } else {
  1770. this.ServeSuccessJSON(map[string]interface{}{
  1771. "msg": "删除成功",
  1772. })
  1773. }
  1774. }
  1775. func (c *StockManagerApiController) EditCancelStock() {
  1776. cancel_time := c.GetString("cancel_time")
  1777. id, _ := c.GetInt64("id", 0)
  1778. if id == 0 {
  1779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1780. return
  1781. }
  1782. ctime := time.Now().Unix()
  1783. mtime := time.Now().Unix()
  1784. adminUserInfo := c.GetAdminUserInfo()
  1785. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  1786. if parseDateErr != nil {
  1787. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  1788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1789. return
  1790. }
  1791. cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
  1792. tempCancelStock := models.CancelStock{
  1793. ID: cancelStock.ID,
  1794. Mtime: mtime,
  1795. ReturnTime: cancelDate.Unix(),
  1796. }
  1797. service.EditCancelStock(tempCancelStock)
  1798. dataBody := make(map[string]interface{}, 0)
  1799. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1800. if err != nil {
  1801. utils.ErrorLog(err.Error())
  1802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1803. return
  1804. }
  1805. var cancelStockInfos []*models.CancelStockInfo
  1806. var upDateCancelStockInfos []*models.CancelStockInfo
  1807. var stockFlow []*models.VmStockFlow
  1808. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1809. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  1810. if len(thisCancelStock) > 0 {
  1811. for _, item := range thisCancelStock {
  1812. items := item.(map[string]interface{})
  1813. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  1814. utils.ErrorLog("good_id")
  1815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1816. return
  1817. }
  1818. good_id := int64(items["good_id"].(float64))
  1819. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  1820. utils.ErrorLog("good_type_id")
  1821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1822. return
  1823. }
  1824. good_type_id := int64(items["good_type_id"].(float64))
  1825. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1826. utils.ErrorLog("count")
  1827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1828. return
  1829. }
  1830. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1831. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1832. utils.ErrorLog("id")
  1833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1834. return
  1835. }
  1836. id := int64(items["id"].(float64))
  1837. number := items["number"].(string)
  1838. register_account := items["register_account"].(string)
  1839. manufacturer, _ := items["manufacturer"].(string)
  1840. dealer, _ := items["dealer"].(string)
  1841. remark := items["remark"].(string)
  1842. var productDates int64
  1843. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1844. productDates = 0
  1845. } else {
  1846. if len(items["product_date"].(string)) == 0 {
  1847. productDates = 0
  1848. } else {
  1849. productDate, _ := items["product_date"].(string)
  1850. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1851. productDates = product_date.Unix()
  1852. }
  1853. }
  1854. var expiryDates int64
  1855. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1856. expiryDates = 0
  1857. } else {
  1858. if len(items["expiry_date"].(string)) == 0 {
  1859. expiryDates = 0
  1860. } else {
  1861. expiryDate, _ := items["expiry_date"].(string)
  1862. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1863. expiryDates = expiry_date.Unix()
  1864. }
  1865. }
  1866. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1867. utils.ErrorLog("price")
  1868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1869. return
  1870. }
  1871. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1872. if id == 0 {
  1873. cancelStockInfo := &models.CancelStockInfo{
  1874. GoodId: good_id,
  1875. GoodTypeId: good_type_id,
  1876. Count: count,
  1877. Status: 1,
  1878. Ctime: ctime,
  1879. OrgId: adminUserInfo.CurrentOrgId,
  1880. OrderNumber: cancelStock.OrderNumber,
  1881. CancelStockId: cancelStock.ID,
  1882. Mtime: time.Now().Unix(),
  1883. Number: number,
  1884. RegisterAccount: register_account,
  1885. Manufacturer: manufacturer,
  1886. Dealer: dealer,
  1887. ProductDate: productDates,
  1888. ExpiryDate: expiryDates,
  1889. Remark: remark,
  1890. Price: price,
  1891. }
  1892. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1893. flow := &models.VmStockFlow{
  1894. WarehousingId: 0,
  1895. GoodId: good_id,
  1896. Number: number,
  1897. LicenseNumber: "",
  1898. Count: count,
  1899. UserOrgId: adminUserInfo.CurrentOrgId,
  1900. PatientId: 0,
  1901. SystemTime: time.Now().Unix(),
  1902. ConsumableType: 4,
  1903. IsSys: 0,
  1904. WarehousingOrder: "",
  1905. WarehouseOutId: 0,
  1906. WarehouseOutOrderNumber: "",
  1907. IsEdit: 2,
  1908. CancelStockId: cancelStock.ID,
  1909. CancelOrderNumber: cancelStock.OrderNumber,
  1910. Manufacturer: 0,
  1911. Dealer: 0,
  1912. Creator: adminUserInfo.AdminUser.Id,
  1913. UpdateCreator: 0,
  1914. Status: 1,
  1915. Ctime: time.Now().Unix(),
  1916. Mtime: 0,
  1917. Price: price,
  1918. WarehousingDetailId: 0,
  1919. WarehouseOutDetailId: 0,
  1920. CancelOutDetailId: 0,
  1921. ProductDate: productDates,
  1922. ExpireDate: expiryDates,
  1923. }
  1924. stockFlow = append(stockFlow, flow)
  1925. } else {
  1926. cancelStockInfo := &models.CancelStockInfo{
  1927. ID: id,
  1928. GoodId: good_id,
  1929. GoodTypeId: good_type_id,
  1930. Count: count,
  1931. Status: 1,
  1932. Ctime: ctime,
  1933. OrgId: adminUserInfo.CurrentOrgId,
  1934. OrderNumber: cancelStock.OrderNumber,
  1935. CancelStockId: cancelStock.ID,
  1936. Mtime: time.Now().Unix(),
  1937. Number: number,
  1938. RegisterAccount: register_account,
  1939. Manufacturer: manufacturer,
  1940. Dealer: dealer,
  1941. ProductDate: productDates,
  1942. ExpiryDate: expiryDates,
  1943. Remark: remark,
  1944. Price: price,
  1945. }
  1946. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  1947. flow := &models.VmStockFlow{
  1948. WarehousingId: 0,
  1949. GoodId: good_id,
  1950. Number: number,
  1951. LicenseNumber: "",
  1952. Count: count,
  1953. UserOrgId: adminUserInfo.CurrentOrgId,
  1954. PatientId: 0,
  1955. SystemTime: time.Now().Unix(),
  1956. ConsumableType: 4,
  1957. IsSys: 0,
  1958. WarehousingOrder: "",
  1959. WarehouseOutId: 0,
  1960. WarehouseOutOrderNumber: "",
  1961. IsEdit: 2,
  1962. CancelStockId: cancelStock.ID,
  1963. CancelOrderNumber: cancelStock.OrderNumber,
  1964. Manufacturer: 0,
  1965. Dealer: 0,
  1966. Creator: adminUserInfo.AdminUser.Id,
  1967. UpdateCreator: 0,
  1968. Status: 1,
  1969. Ctime: time.Now().Unix(),
  1970. Mtime: 0,
  1971. Price: price,
  1972. WarehousingDetailId: 0,
  1973. WarehouseOutDetailId: 0,
  1974. CancelOutDetailId: 0,
  1975. ProductDate: productDates,
  1976. ExpireDate: expiryDates,
  1977. }
  1978. stockFlow = append(stockFlow, flow)
  1979. }
  1980. }
  1981. }
  1982. }
  1983. var errs error
  1984. fmt.Println("出库22322333223", cancelStockInfos)
  1985. fmt.Println("更新23232323232323233", upDateCancelStockInfos)
  1986. if len(cancelStockInfos) > 0 {
  1987. errs = service.CreateCancelStockInfo(cancelStockInfos)
  1988. service.CreateStockFlow(stockFlow)
  1989. // 改变入库单的值
  1990. for _, item := range cancelStockInfos {
  1991. //查询该耗材的入库记录
  1992. list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
  1993. //调用退库的方法
  1994. parseDateErr := service.UpdateCancelOut(list, item.Count)
  1995. if parseDateErr != nil {
  1996. utils.ErrorLog(errs.Error())
  1997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1998. return
  1999. }
  2000. c.ServeSuccessJSON(map[string]interface{}{
  2001. "msg": "编辑成功",
  2002. })
  2003. }
  2004. }
  2005. if len(upDateCancelStockInfos) > 0 {
  2006. for _, item := range upDateCancelStockInfos {
  2007. service.CreateStockFlow(stockFlow)
  2008. errs = service.UpDateCancelStockInfo(item)
  2009. list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
  2010. //调用退库的方法
  2011. parseDateErr := service.UpdateCancelOut(list, item.Count)
  2012. fmt.Println("999999999999", parseDateErr)
  2013. break
  2014. }
  2015. if errs != nil {
  2016. utils.ErrorLog(errs.Error())
  2017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2018. return
  2019. }
  2020. c.ServeSuccessJSON(map[string]interface{}{
  2021. "msg": "编辑成功",
  2022. })
  2023. }
  2024. if errs != nil {
  2025. utils.ErrorLog(errs.Error())
  2026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  2027. return
  2028. }
  2029. c.ServeSuccessJSON(map[string]interface{}{
  2030. "msg": "编辑成功",
  2031. })
  2032. }
  2033. func (this *StockManagerApiController) GetCancelStockConfig() {
  2034. types, _ := this.GetInt64("type", 0)
  2035. adminUserInfo := this.GetAdminUserInfo()
  2036. warehouseOutInfoList, _ := service.FindAllWarehouseOutInfo(adminUserInfo.CurrentOrgId, types)
  2037. this.ServeSuccessJSON(map[string]interface{}{
  2038. "warehouseOutInfoList": warehouseOutInfoList,
  2039. })
  2040. }
  2041. func (c *StockManagerApiController) GetQueryInfo() {
  2042. page, _ := c.GetInt64("page", -1)
  2043. limit, _ := c.GetInt64("limit", -1)
  2044. keyword := c.GetString("keyword")
  2045. start_time := c.GetString("start_time")
  2046. end_time := c.GetString("end_time")
  2047. type_name, _ := c.GetInt64("type_name")
  2048. timeLayout := "2006-01-02"
  2049. loc, _ := time.LoadLocation("Local")
  2050. var startTime int64
  2051. if len(start_time) > 0 {
  2052. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2053. if err != nil {
  2054. fmt.Println(err)
  2055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2056. return
  2057. }
  2058. startTime = theTime.Unix()
  2059. }
  2060. var endTime int64
  2061. if len(end_time) > 0 {
  2062. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2063. if err != nil {
  2064. utils.ErrorLog(err.Error())
  2065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2066. return
  2067. }
  2068. endTime = theTime.Unix()
  2069. }
  2070. adminUserInfo := c.GetAdminUserInfo()
  2071. list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, startTime, endTime, type_name)
  2072. info, err := service.GetCoutWareseOutInfo(startTime, endTime, adminUserInfo.CurrentOrgId)
  2073. infomationList, err := service.GetGoodInfomationList(adminUserInfo.CurrentOrgId, "")
  2074. if err == nil {
  2075. c.ServeSuccessJSON(map[string]interface{}{
  2076. "list": list,
  2077. "total": total,
  2078. "info": info,
  2079. "infomationList": infomationList,
  2080. "orgid": adminUserInfo.CurrentOrgId,
  2081. })
  2082. } else {
  2083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2084. }
  2085. }
  2086. func (c *StockManagerApiController) SearchWarehouse() {
  2087. keywords := c.GetString("keywords")
  2088. adminUserInfo := c.GetAdminUserInfo()
  2089. warehouseList, total, err := service.FindAllWarehouseByKeyword(adminUserInfo.CurrentOrgId, 1, 10, keywords)
  2090. if err == nil {
  2091. c.ServeSuccessJSON(map[string]interface{}{
  2092. "list": warehouseList,
  2093. "total": total,
  2094. })
  2095. } else {
  2096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2097. }
  2098. }
  2099. func (c *StockManagerApiController) GetAllConfig() {
  2100. adminUserInfo := c.GetAdminUserInfo()
  2101. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  2102. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  2103. goodType, _ := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  2104. goodInfo, _ := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
  2105. c.ServeSuccessJSON(map[string]interface{}{
  2106. "manufacturer": manufacturer,
  2107. "dealer": dealer,
  2108. "goodType": goodType,
  2109. "goodInfo": goodInfo,
  2110. })
  2111. }
  2112. func (this *StockManagerApiController) GetAllSalesReturnConfig() {
  2113. types, _ := this.GetInt64("type", 0)
  2114. adminUserInfo := this.GetAdminUserInfo()
  2115. warehouseInfoList, _ := service.FindAllWarehouseInfo(adminUserInfo.CurrentOrgId, types)
  2116. this.ServeSuccessJSON(map[string]interface{}{
  2117. "warehouseInfoList": warehouseInfoList,
  2118. })
  2119. }
  2120. func (this *StockManagerApiController) GetDetailInfo() {
  2121. page, _ := this.GetInt64("page", 0)
  2122. limit, _ := this.GetInt64("limit", 0)
  2123. start_time := this.GetString("start_time")
  2124. end_time := this.GetString("end_time")
  2125. types, _ := this.GetInt64("type", 0)
  2126. keywords := this.GetString("keywords")
  2127. manufacturer, _ := this.GetInt64("manufacturer", 0)
  2128. order_type, _ := this.GetInt64("order_type", 0)
  2129. dealer, _ := this.GetInt64("dealer", 0)
  2130. timeLayout := "2006-01-02"
  2131. loc, _ := time.LoadLocation("Local")
  2132. var startTime int64
  2133. if len(start_time) > 0 {
  2134. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2135. if err != nil {
  2136. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2137. return
  2138. }
  2139. startTime = theTime.Unix()
  2140. }
  2141. var endTime int64
  2142. if len(end_time) > 0 {
  2143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2144. if err != nil {
  2145. utils.ErrorLog(err.Error())
  2146. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2147. return
  2148. }
  2149. endTime = theTime.Unix()
  2150. }
  2151. adminUserInfo := this.GetAdminUserInfo()
  2152. var list []*models.WarehousingInfo
  2153. var list1 []*models.WarehouseOutInfo
  2154. var list2 []*models.SalesReturnInfo
  2155. var list3 []*models.CancelStockInfo
  2156. var total int64
  2157. var err error
  2158. var total_price float64
  2159. if types == 1 {
  2160. list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2161. _, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2162. if err == nil {
  2163. this.ServeSuccessJSON(map[string]interface{}{
  2164. "list": list,
  2165. "total": total,
  2166. "total_price": total_price,
  2167. })
  2168. } else {
  2169. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2170. }
  2171. } else if types == 2 {
  2172. list1, total, err = service.FindStockOutDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2173. _, total_price = service.GetStockOutDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2174. if err == nil {
  2175. this.ServeSuccessJSON(map[string]interface{}{
  2176. "list": list1,
  2177. "total": total,
  2178. "total_price": total_price,
  2179. })
  2180. } else {
  2181. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2182. }
  2183. } else if types == 3 {
  2184. list2, total, err = service.FindSalesReturnDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2185. if err == nil {
  2186. this.ServeSuccessJSON(map[string]interface{}{
  2187. "list": list2,
  2188. "total": total,
  2189. })
  2190. } else {
  2191. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2192. }
  2193. } else if types == 4 {
  2194. list3, total, err = service.FindCancelDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
  2195. if err == nil {
  2196. this.ServeSuccessJSON(map[string]interface{}{
  2197. "list": list3,
  2198. "total": total,
  2199. })
  2200. } else {
  2201. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2202. }
  2203. }
  2204. }
  2205. func (this *StockManagerApiController) GetUserDetailInfo() {
  2206. order_id, _ := this.GetInt64("id")
  2207. if order_id <= 0 {
  2208. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2209. return
  2210. }
  2211. adminUserInfo := this.GetAdminUserInfo()
  2212. userDetails, err, total := service.FindUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  2213. if err == nil {
  2214. this.ServeSuccessJSON(map[string]interface{}{
  2215. "list": userDetails,
  2216. "total": total,
  2217. })
  2218. } else {
  2219. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2220. return
  2221. }
  2222. }
  2223. func (this *StockManagerApiController) PostSearchStock() {
  2224. keyword := this.GetString("keyword")
  2225. adminUserInfo := this.GetAdminUserInfo()
  2226. orgId := adminUserInfo.CurrentOrgId
  2227. stock, err := service.PostSearchStock(keyword, orgId)
  2228. if err != nil {
  2229. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2230. }
  2231. this.ServeSuccessJSON(map[string]interface{}{
  2232. "stock": stock,
  2233. })
  2234. }
  2235. func (this *StockManagerApiController) GetOutStockTotalCount() {
  2236. warehouseOutTime, _ := this.GetInt64("warehouse_out_time")
  2237. adminUserInfo := this.GetAdminUserInfo()
  2238. stockCount, err := service.GetOutStockTotalCount(warehouseOutTime, adminUserInfo.CurrentOrgId)
  2239. if err != nil {
  2240. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  2241. }
  2242. this.ServeSuccessJSON(map[string]interface{}{
  2243. "stockCount": stockCount,
  2244. })
  2245. }
  2246. func (this *StockManagerApiController) AddGoodInformation() {
  2247. adminUserInfo := this.GetAdminUserInfo()
  2248. orgId := adminUserInfo.CurrentOrgId
  2249. dataBody := make(map[string]interface{}, 0)
  2250. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2251. if err != nil {
  2252. utils.ErrorLog(err.Error())
  2253. return
  2254. }
  2255. utils.ErrorLog("%v", dataBody)
  2256. var goods []*models.GoodInfo
  2257. var total_goods []interface{}
  2258. tempGoods := dataBody["goods"].([]interface{})
  2259. total_goods = tempGoods
  2260. for index, goodMap := range tempGoods {
  2261. goodNameM := goodMap.(map[string]interface{})
  2262. var good models.GoodInfo
  2263. if goodNameM["good_name"] == nil || reflect.TypeOf(goodNameM["good_name"]).String() != "string" {
  2264. utils.ErrorLog("good_name")
  2265. return
  2266. }
  2267. good_name, _ := goodNameM["good_name"].(string)
  2268. if len(good_name) == 0 { //名字为空则生成一条导入错误日志
  2269. err_log := models.ExportErrLog{
  2270. LogType: 5,
  2271. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2272. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材名称不能为空",
  2273. Status: 1,
  2274. CreateTime: time.Now().Unix(),
  2275. UpdateTime: time.Now().Unix(),
  2276. ExportTime: time.Now().Unix(),
  2277. }
  2278. service.CreateExportErrLog(&err_log)
  2279. continue
  2280. }
  2281. good.GoodName = good_name
  2282. // 获取数据字典数据
  2283. var good_kind_id int64
  2284. var name = "耗材种类"
  2285. config, _ := service.GetDrugDataConfig(0, name)
  2286. good_kind := goodNameM["good_kind"].(string)
  2287. if len(good_kind) == 0 { //名字为空则生成一条导入错误日志
  2288. err_log := models.ExportErrLog{
  2289. LogType: 5,
  2290. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2291. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材种类不能为空",
  2292. Status: 1,
  2293. CreateTime: time.Now().Unix(),
  2294. UpdateTime: time.Now().Unix(),
  2295. ExportTime: time.Now().Unix(),
  2296. }
  2297. service.CreateExportErrLog(&err_log)
  2298. continue
  2299. }
  2300. if len(good_kind) != 0 {
  2301. _, errcodegoodkind := service.IsExistDicConfig(config.ID, good_kind, orgId)
  2302. lastConfig, _ := service.GetLastDicConfig(config.ID, orgId)
  2303. dataconfig := models.DictDataconfig{
  2304. ParentId: config.ID,
  2305. Module: "system",
  2306. OrgId: orgId,
  2307. Name: good_kind,
  2308. FieldName: "",
  2309. Value: lastConfig.Value + 1,
  2310. CreatedTime: "",
  2311. UpdatedTime: "",
  2312. CreateUserId: adminUserInfo.AdminUser.Id,
  2313. Status: 1,
  2314. Remark: "",
  2315. DeleteIdSystem: 0,
  2316. Title: "",
  2317. Content: "",
  2318. Order: 0,
  2319. Code: "",
  2320. }
  2321. if errcodegoodkind == gorm.ErrRecordNotFound {
  2322. service.CreatedDicConfig(&dataconfig)
  2323. }
  2324. }
  2325. dataConfig, _ := service.GetParentDataConfig(config.ID, orgId)
  2326. for _, it := range dataConfig {
  2327. if good_kind == it.Name {
  2328. fmt.Println(it.Name)
  2329. good_kind_id = int64(it.Value)
  2330. }
  2331. }
  2332. good.GoodKind = good_kind_id
  2333. good_type := goodNameM["type_name"].(string)
  2334. if len(good_type) == 0 {
  2335. err_log := models.ExportErrLog{
  2336. LogType: 5,
  2337. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2338. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的耗材类型不能为空",
  2339. Status: 1,
  2340. CreateTime: time.Now().Unix(),
  2341. UpdateTime: time.Now().Unix(),
  2342. ExportTime: time.Now().Unix(),
  2343. }
  2344. service.CreateExportErrLog(&err_log)
  2345. continue
  2346. }
  2347. if len(good_type) != 0 {
  2348. _, errcodegoodtype := service.GetGoodType(good_type, orgId)
  2349. if errcodegoodtype == gorm.ErrRecordNotFound {
  2350. goodsType := models.GoodsType{
  2351. TypeName: good_type,
  2352. Remark: "",
  2353. Ctime: time.Now().Unix(),
  2354. Mtime: 0,
  2355. Creater: adminUserInfo.AdminUser.Id,
  2356. Modifier: 0,
  2357. OrgId: adminUserInfo.CurrentOrgId,
  2358. Status: 1,
  2359. Type: 0,
  2360. Number: 0,
  2361. OutStock: 0,
  2362. StockAttribute: 1,
  2363. }
  2364. service.CreatedGoodType(&goodsType)
  2365. }
  2366. }
  2367. goodType, _ := service.GetAllGoodType(orgId)
  2368. var good_type_id int64
  2369. for _, it := range goodType {
  2370. if good_type == it.TypeName {
  2371. good_type_id = it.ID
  2372. }
  2373. }
  2374. good.GoodTypeId = good_type_id
  2375. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  2376. if len(medical_insurance_level) <= 0 { //名字为空则生成一条导入错误日志
  2377. err_log := models.ExportErrLog{
  2378. LogType: 5,
  2379. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2380. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  2381. Status: 1,
  2382. CreateTime: time.Now().Unix(),
  2383. UpdateTime: time.Now().Unix(),
  2384. ExportTime: time.Now().Unix(),
  2385. }
  2386. service.CreateExportErrLog(&err_log)
  2387. continue
  2388. }
  2389. var medical_insurance_id int64
  2390. var medicalInsurance = "医保等级"
  2391. medicalInsuranceDataConfig, _ := service.GetDrugDataConfig(0, medicalInsurance)
  2392. if len(medical_insurance_level) != 0 {
  2393. _, errcodemedicalInsurance := service.IsExistDicConfig(medicalInsuranceDataConfig.ID, medical_insurance_level, orgId)
  2394. if errcodemedicalInsurance == gorm.ErrRecordNotFound {
  2395. mediConfigOne, _ := service.GetLastDicConfig(medicalInsuranceDataConfig.ID, orgId)
  2396. dataconfig := models.DictDataconfig{
  2397. ParentId: medicalInsuranceDataConfig.ID,
  2398. Module: "system",
  2399. OrgId: orgId,
  2400. Name: medical_insurance_level,
  2401. FieldName: "",
  2402. Value: mediConfigOne.Value + 1,
  2403. CreatedTime: "",
  2404. UpdatedTime: "",
  2405. CreateUserId: adminUserInfo.AdminUser.Id,
  2406. Status: 1,
  2407. Remark: "",
  2408. DeleteIdSystem: 0,
  2409. Title: "",
  2410. Content: "",
  2411. Order: 0,
  2412. Code: "",
  2413. }
  2414. service.CreatedDicConfig(&dataconfig)
  2415. }
  2416. }
  2417. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceDataConfig.ID, orgId)
  2418. for _, it := range medicalInsuranceList {
  2419. if medical_insurance_level == it.Name {
  2420. medical_insurance_id = int64(it.Value)
  2421. }
  2422. }
  2423. good.MedicalInsuranceLevel = medical_insurance_id
  2424. if goodNameM["specification_name"] == nil || reflect.TypeOf(goodNameM["specification_name"]).String() != "string" {
  2425. utils.ErrorLog("specification_name")
  2426. return
  2427. }
  2428. specification_name := goodNameM["specification_name"].(string)
  2429. if len(specification_name) == 0 { //名字为空则生成一条导入错误日志
  2430. err_log := models.ExportErrLog{
  2431. LogType: 5,
  2432. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2433. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "规格型号不能为空",
  2434. Status: 1,
  2435. CreateTime: time.Now().Unix(),
  2436. UpdateTime: time.Now().Unix(),
  2437. ExportTime: time.Now().Unix(),
  2438. }
  2439. service.CreateExportErrLog(&err_log)
  2440. continue
  2441. }
  2442. good.SpecificationName = specification_name
  2443. var manufacturer_id int64
  2444. manufacturer := goodNameM["manufacturer"].(string)
  2445. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  2446. err_log := models.ExportErrLog{
  2447. LogType: 5,
  2448. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2449. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产厂商不能为空",
  2450. Status: 1,
  2451. CreateTime: time.Now().Unix(),
  2452. UpdateTime: time.Now().Unix(),
  2453. ExportTime: time.Now().Unix(),
  2454. }
  2455. service.CreateExportErrLog(&err_log)
  2456. continue
  2457. }
  2458. if len(manufacturer) != 0 {
  2459. _, errcodes := service.GetManufacturerName(orgId, manufacturer)
  2460. manu := models.Manufacturer{
  2461. ManufacturerName: manufacturer,
  2462. Status: 1,
  2463. OrgId: orgId,
  2464. Creater: adminUserInfo.AdminUser.Id,
  2465. }
  2466. if errcodes == gorm.ErrRecordNotFound {
  2467. service.CreateManufacturer(&manu)
  2468. }
  2469. }
  2470. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2471. for _, it := range manufacturerList {
  2472. if manufacturer == it.ManufacturerName {
  2473. manufacturer_id = it.ID
  2474. }
  2475. }
  2476. good.Manufacturer = manufacturer_id
  2477. if goodNameM["unit_id"] == nil || reflect.TypeOf(goodNameM["unit_id"]).String() != "float64" {
  2478. utils.ErrorLog("unit_id")
  2479. return
  2480. }
  2481. unit_id := int64(goodNameM["unit_id"].(float64))
  2482. if unit_id <= 0 { //名字为空则生成一条导入错误日志
  2483. err_log := models.ExportErrLog{
  2484. LogType: 5,
  2485. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2486. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位不能为空",
  2487. Status: 1,
  2488. CreateTime: time.Now().Unix(),
  2489. UpdateTime: time.Now().Unix(),
  2490. ExportTime: time.Now().Unix(),
  2491. }
  2492. service.CreateExportErrLog(&err_log)
  2493. continue
  2494. }
  2495. good.GoodUnit = unit_id
  2496. retail_prices := goodNameM["retail_price"].(string)
  2497. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  2498. if retail_price <= 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. good.RetailPrice = retail_price
  2512. if goodNameM["stock_warn_count"] == nil || reflect.TypeOf(goodNameM["stock_warn_count"]).String() != "float64" {
  2513. utils.ErrorLog("stock_warn_count")
  2514. return
  2515. }
  2516. stock_warn_count := int64(goodNameM["stock_warn_count"].(float64))
  2517. if stock_warn_count <= 0 { //名字为空则生成一条导入错误日志
  2518. err_log := models.ExportErrLog{
  2519. LogType: 5,
  2520. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2521. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空或内容与系统不匹配",
  2522. Status: 1,
  2523. CreateTime: time.Now().Unix(),
  2524. UpdateTime: time.Now().Unix(),
  2525. ExportTime: time.Now().Unix(),
  2526. }
  2527. service.CreateExportErrLog(&err_log)
  2528. continue
  2529. }
  2530. good.StockWarnCount = stock_warn_count
  2531. var dealer_id int64
  2532. dealerName := goodNameM["dealer"].(string)
  2533. fmt.Println("经销商", dealerName)
  2534. dealer := models.Dealer{
  2535. OrgId: orgId,
  2536. Status: 1,
  2537. DealerName: dealerName,
  2538. Creater: adminUserInfo.AdminUser.Id,
  2539. Ctime: time.Now().Unix(),
  2540. }
  2541. if len(dealerName) != 0 {
  2542. _, errcodedealer := service.GetDealerByName(orgId, dealerName)
  2543. if errcodedealer == gorm.ErrRecordNotFound {
  2544. service.CreateDealer(&dealer)
  2545. }
  2546. }
  2547. dealerList, _ := service.GetAllDealerList(orgId)
  2548. for _, it := range dealerList {
  2549. if dealerName == it.DealerName {
  2550. dealer_id = it.ID
  2551. }
  2552. }
  2553. good.Dealer = dealer_id
  2554. if goodNameM["pinyin"] == nil || reflect.TypeOf(goodNameM["pinyin"]).String() != "string" {
  2555. utils.ErrorLog("pinyin")
  2556. return
  2557. }
  2558. pinyin := goodNameM["pinyin"].(string)
  2559. good.Pinyin = pinyin
  2560. if goodNameM["wubi"] == nil || reflect.TypeOf(goodNameM["wubi"]).String() != "string" {
  2561. utils.ErrorLog("wubi")
  2562. return
  2563. }
  2564. wubi := goodNameM["wubi"].(string)
  2565. good.Wubi = wubi
  2566. buy_prices := goodNameM["buy_price"].(string)
  2567. buy_price, _ := strconv.ParseFloat(buy_prices, 64)
  2568. good.BuyPrice = buy_price
  2569. if goodNameM["social_security_directory_code"] == nil || reflect.TypeOf(goodNameM["social_security_directory_code"]).String() != "string" {
  2570. utils.ErrorLog("social_security_directory_code")
  2571. return
  2572. }
  2573. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  2574. good.SocialSecurityDirectoryCode = social_security_directory_code
  2575. if goodNameM["is_special_diseases"] == nil || reflect.TypeOf(goodNameM["is_special_diseases"]).String() != "float64" {
  2576. utils.ErrorLog("is_special_diseases")
  2577. return
  2578. }
  2579. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  2580. good.IsSpecialDiseases = is_special_diseases
  2581. if goodNameM["is_record"] == nil || reflect.TypeOf(goodNameM["is_record"]).String() != "float64" {
  2582. utils.ErrorLog("is_record")
  2583. return
  2584. }
  2585. is_record := int64(goodNameM["is_record"].(float64))
  2586. good.IsRecord = is_record
  2587. if goodNameM["good_status"] == nil || reflect.TypeOf(goodNameM["good_status"]).String() != "string" {
  2588. utils.ErrorLog("good_status")
  2589. return
  2590. }
  2591. good_status := goodNameM["good_status"].(string)
  2592. good.GoodStatus = good_status
  2593. if goodNameM["medical_insurance_number"] == nil || reflect.TypeOf(goodNameM["medical_insurance_number"]).String() != "string" {
  2594. utils.ErrorLog("medical_insurance_number")
  2595. return
  2596. }
  2597. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  2598. good.MedicalInsuranceNumber = medical_insurance_number
  2599. if goodNameM["production_type"] == nil || reflect.TypeOf(goodNameM["production_type"]).String() != "string" {
  2600. utils.ErrorLog("production_type")
  2601. return
  2602. }
  2603. production_type := goodNameM["production_type"].(string)
  2604. good.ProductionType = production_type
  2605. if goodNameM["remark"] == nil || reflect.TypeOf(goodNameM["remark"]).String() != "string" {
  2606. utils.ErrorLog("remark")
  2607. return
  2608. }
  2609. remark := goodNameM["remark"].(string)
  2610. good.Remark = remark
  2611. statistics_category := goodNameM["statistics_category"].(string)
  2612. var categoryName = "统计分类"
  2613. var statistic_id int64
  2614. drugDataConfig, _ := service.GetDrugDataConfig(0, categoryName)
  2615. if len(statistics_category) != 0 {
  2616. _, errcodecagegory := service.IsExistDicConfig(drugDataConfig.ID, statistics_category, orgId)
  2617. if errcodecagegory == gorm.ErrRecordNotFound {
  2618. dicConfigThree, _ := service.GetLastDicConfig(drugDataConfig.ID, orgId)
  2619. dataconfig := models.DictDataconfig{
  2620. ParentId: drugDataConfig.ID,
  2621. Module: "system",
  2622. OrgId: orgId,
  2623. Name: statistics_category,
  2624. FieldName: "",
  2625. Value: dicConfigThree.Value + 1,
  2626. CreatedTime: "",
  2627. UpdatedTime: "",
  2628. CreateUserId: adminUserInfo.AdminUser.Id,
  2629. Status: 1,
  2630. Remark: "",
  2631. DeleteIdSystem: 0,
  2632. Title: "",
  2633. Content: "",
  2634. Order: 0,
  2635. Code: "",
  2636. }
  2637. service.CreatedDicConfig(&dataconfig)
  2638. }
  2639. }
  2640. parentDataConfig, _ := service.GetParentDataConfig(drugDataConfig.ID, orgId)
  2641. for _, it := range parentDataConfig {
  2642. if statistics_category == it.Name {
  2643. statistic_id = int64(it.Value)
  2644. }
  2645. }
  2646. good.StatisticsCategory = statistic_id
  2647. special_medical := goodNameM["special_medical"].(string)
  2648. good.SpecialMedical = special_medical
  2649. goods = append(goods, &good)
  2650. }
  2651. export_time := time.Now().Unix()
  2652. errLogs, _ := service.FindPatientExportLogTwo(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2653. if len(goods) > 0 {
  2654. for _, item := range goods {
  2655. goodInfo := models.GoodInfo{
  2656. GoodName: item.GoodName,
  2657. SpecificationName: item.SpecificationName,
  2658. GoodKind: item.GoodKind,
  2659. GoodTypeId: item.GoodTypeId,
  2660. Dealer: item.Dealer,
  2661. GoodUnit: item.GoodUnit,
  2662. IsRecord: item.IsRecord,
  2663. IsSpecialDiseases: item.IsSpecialDiseases,
  2664. Manufacturer: item.Manufacturer,
  2665. Pinyin: item.Pinyin,
  2666. GoodStatus: item.GoodStatus,
  2667. ProductionType: item.ProductionType,
  2668. Remark: item.Remark,
  2669. RetailPrice: item.RetailPrice,
  2670. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  2671. SpecialMedical: item.SpecialMedical,
  2672. Wubi: item.Wubi,
  2673. StockWarnCount: item.StockWarnCount,
  2674. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  2675. OrgId: orgId,
  2676. Status: 1,
  2677. Ctime: time.Now().Unix(),
  2678. StatisticsCategory: item.StatisticsCategory,
  2679. GoodCode: item.GoodCode,
  2680. BuyPrice: item.BuyPrice,
  2681. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  2682. }
  2683. //查询同种耗材名称同种类型同种规格的耗材是否存在
  2684. _, errcodegood := service.GetGoodsInformaitonIsExist(item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2685. if errcodegood == gorm.ErrRecordNotFound {
  2686. service.CreateGoodsInfomation(&goodInfo)
  2687. } else if errcodegood == nil {
  2688. service.UpdateGoodsInformation(&goodInfo, item.GoodName, item.GoodTypeId, item.SpecificationName, orgId)
  2689. }
  2690. log := models.ExportLog{
  2691. LogType: 5,
  2692. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2693. TotalNum: int64(len(total_goods)),
  2694. FailNum: int64(len(errLogs)),
  2695. SuccessNum: int64(len(goods)),
  2696. CreateTime: time.Now().Unix(),
  2697. UpdateTime: time.Now().Unix(),
  2698. ExportTime: export_time,
  2699. Status: 1,
  2700. }
  2701. service.CreateExportLog(&log)
  2702. this.ServeSuccessJSON(map[string]interface{}{
  2703. "msg": "导入成功",
  2704. "total_num": len(total_goods),
  2705. "success_num": len(goods),
  2706. "fail_num": int64(len(errLogs)),
  2707. })
  2708. }
  2709. } else {
  2710. log := models.ExportLog{
  2711. LogType: 5,
  2712. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2713. TotalNum: int64(len(total_goods)),
  2714. FailNum: int64(len(errLogs)),
  2715. SuccessNum: int64(len(goods)),
  2716. CreateTime: time.Now().Unix(),
  2717. UpdateTime: time.Now().Unix(),
  2718. ExportTime: export_time,
  2719. Status: 1,
  2720. }
  2721. service.CreateExportLog(&log)
  2722. this.ServeSuccessJSON(map[string]interface{}{
  2723. "msg": "导入成功",
  2724. "total_num": len(total_goods),
  2725. "success_num": len(goods),
  2726. "fail_num": int64(len(errLogs)),
  2727. })
  2728. }
  2729. }
  2730. func (this *StockManagerApiController) AddDrugInformation() {
  2731. adminUser := this.GetAdminUserInfo()
  2732. orgId := adminUser.CurrentOrgId
  2733. dataBody := make(map[string]interface{}, 0)
  2734. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2735. if err != nil {
  2736. utils.ErrorLog(err.Error())
  2737. return
  2738. }
  2739. utils.ErrorLog("%v", dataBody)
  2740. var drugList []*models.BaseDrugLib
  2741. var total_goods []interface{}
  2742. tempDrugs := dataBody["drugs"].([]interface{})
  2743. total_goods = tempDrugs
  2744. for index, drugMap := range tempDrugs {
  2745. goodNameM := drugMap.(map[string]interface{})
  2746. var drug models.BaseDrugLib
  2747. if goodNameM["drug_name"] == nil || reflect.TypeOf(goodNameM["drug_name"]).String() != "string" {
  2748. utils.ErrorLog("drug_name")
  2749. return
  2750. }
  2751. drug_name, _ := goodNameM["drug_name"].(string)
  2752. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2753. err_log := models.ExportErrLog{
  2754. LogType: 4,
  2755. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2756. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品名称不能为空",
  2757. Status: 1,
  2758. CreateTime: time.Now().Unix(),
  2759. UpdateTime: time.Now().Unix(),
  2760. ExportTime: time.Now().Unix(),
  2761. }
  2762. service.CreateExportErrLog(&err_log)
  2763. continue
  2764. }
  2765. drug.DrugName = drug_name
  2766. if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
  2767. utils.ErrorLog("min_number")
  2768. return
  2769. }
  2770. min_number, _ := goodNameM["min_number"].(string)
  2771. minNumber, _ := strconv.ParseInt(min_number, 10, 64)
  2772. if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
  2773. err_log := models.ExportErrLog{
  2774. LogType: 4,
  2775. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2776. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零不能为空",
  2777. Status: 1,
  2778. CreateTime: time.Now().Unix(),
  2779. UpdateTime: time.Now().Unix(),
  2780. ExportTime: time.Now().Unix(),
  2781. }
  2782. service.CreateExportErrLog(&err_log)
  2783. continue
  2784. }
  2785. drug.MinNumber = minNumber
  2786. min_unit := goodNameM["min_unit"].(string)
  2787. if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
  2788. err_log := models.ExportErrLog{
  2789. LogType: 4,
  2790. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2791. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零单位不能为空",
  2792. Status: 1,
  2793. CreateTime: time.Now().Unix(),
  2794. UpdateTime: time.Now().Unix(),
  2795. ExportTime: time.Now().Unix(),
  2796. }
  2797. service.CreateExportErrLog(&err_log)
  2798. continue
  2799. }
  2800. drug.MinUnit = min_unit
  2801. dose := goodNameM["dose"].(float64)
  2802. if dose < 0 { //名字为空则生成一条导入错误日志
  2803. err_log := models.ExportErrLog{
  2804. LogType: 4,
  2805. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2806. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
  2807. Status: 1,
  2808. CreateTime: time.Now().Unix(),
  2809. UpdateTime: time.Now().Unix(),
  2810. ExportTime: time.Now().Unix(),
  2811. }
  2812. service.CreateExportErrLog(&err_log)
  2813. continue
  2814. }
  2815. drug.Dose = dose
  2816. max_unit_id := goodNameM["max_unit"].(string)
  2817. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  2818. err_log := models.ExportErrLog{
  2819. LogType: 4,
  2820. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2821. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
  2822. Status: 1,
  2823. CreateTime: time.Now().Unix(),
  2824. UpdateTime: time.Now().Unix(),
  2825. ExportTime: time.Now().Unix(),
  2826. }
  2827. service.CreateExportErrLog(&err_log)
  2828. continue
  2829. }
  2830. drug.MaxUnit = max_unit_id
  2831. max_unit := goodNameM["max_unit"].(string)
  2832. if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
  2833. err_log := models.ExportErrLog{
  2834. LogType: 4,
  2835. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2836. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
  2837. Status: 1,
  2838. CreateTime: time.Now().Unix(),
  2839. UpdateTime: time.Now().Unix(),
  2840. ExportTime: time.Now().Unix(),
  2841. }
  2842. service.CreateExportErrLog(&err_log)
  2843. continue
  2844. }
  2845. drug.MaxUnit = max_unit
  2846. delivery_way := goodNameM["delivery_way"].(string)
  2847. if len(delivery_way) == 0 { //名字为空则生成一条导入错误日志
  2848. err_log := models.ExportErrLog{
  2849. LogType: 4,
  2850. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2851. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认给药途径不能为空",
  2852. Status: 1,
  2853. CreateTime: time.Now().Unix(),
  2854. UpdateTime: time.Now().Unix(),
  2855. ExportTime: time.Now().Unix(),
  2856. }
  2857. service.CreateExportErrLog(&err_log)
  2858. continue
  2859. }
  2860. drug.DeliveryWay = delivery_way
  2861. execution_frequency := goodNameM["execution_frequency"].(string)
  2862. if len(execution_frequency) == 0 { //名字为空则生成一条导入错误日志
  2863. err_log := models.ExportErrLog{
  2864. LogType: 4,
  2865. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2866. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  2867. Status: 1,
  2868. CreateTime: time.Now().Unix(),
  2869. UpdateTime: time.Now().Unix(),
  2870. ExportTime: time.Now().Unix(),
  2871. }
  2872. service.CreateExportErrLog(&err_log)
  2873. continue
  2874. }
  2875. drug.ExecutionFrequency = execution_frequency
  2876. drug_day := goodNameM["drug_day"].(string)
  2877. if len(drug_day) == 0 { //名字为空则生成一条导入错误日志
  2878. err_log := models.ExportErrLog{
  2879. LogType: 4,
  2880. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2881. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认执行频率不能为空",
  2882. Status: 1,
  2883. CreateTime: time.Now().Unix(),
  2884. UpdateTime: time.Now().Unix(),
  2885. ExportTime: time.Now().Unix(),
  2886. }
  2887. service.CreateExportErrLog(&err_log)
  2888. continue
  2889. }
  2890. drug.DrugDay = drug_day
  2891. drug_type := goodNameM["drug_type"].(string)
  2892. if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
  2893. err_log := models.ExportErrLog{
  2894. LogType: 4,
  2895. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2896. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品类型不能为空",
  2897. Status: 1,
  2898. CreateTime: time.Now().Unix(),
  2899. UpdateTime: time.Now().Unix(),
  2900. ExportTime: time.Now().Unix(),
  2901. }
  2902. service.CreateExportErrLog(&err_log)
  2903. continue
  2904. }
  2905. var drug_type_id int64
  2906. var drugType = "药品类型"
  2907. drugconfig, _ := service.GetDrugDataConfig(0, drugType)
  2908. if len(drug_type) != 0 {
  2909. _, errcodes := service.IsExistDicConfig(drugconfig.ID, drug_type, orgId)
  2910. if errcodes == gorm.ErrRecordNotFound {
  2911. //获取该型号最后一条数据型号
  2912. config, _ := service.GetLastDicConfig(drugconfig.ID, orgId)
  2913. dataconfig := models.DictDataconfig{
  2914. ParentId: drugconfig.ID,
  2915. Module: "system",
  2916. OrgId: orgId,
  2917. Name: drug_type,
  2918. FieldName: "",
  2919. Value: config.Value + 1,
  2920. CreatedTime: "",
  2921. UpdatedTime: "",
  2922. CreateUserId: adminUser.AdminUser.Id,
  2923. Status: 1,
  2924. Remark: "",
  2925. DeleteIdSystem: 0,
  2926. Title: "",
  2927. Content: "",
  2928. Order: 0,
  2929. Code: "",
  2930. }
  2931. service.CreatedDicConfig(&dataconfig)
  2932. }
  2933. }
  2934. drugTypeList, _ := service.GetParentDataConfig(drugconfig.ID, orgId)
  2935. for _, it := range drugTypeList {
  2936. if drug_type == it.Name {
  2937. drug_type_id = int64(it.Value)
  2938. }
  2939. }
  2940. drug.DrugType = drug_type_id
  2941. drug_stock_limit, _ := goodNameM["drug_stock_limit"].(string)
  2942. if len(drug_stock_limit) == 0 { //名字为空则生成一条导入错误日志
  2943. err_log := models.ExportErrLog{
  2944. LogType: 4,
  2945. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2946. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的库存警戒不能为空",
  2947. Status: 1,
  2948. CreateTime: time.Now().Unix(),
  2949. UpdateTime: time.Now().Unix(),
  2950. ExportTime: time.Now().Unix(),
  2951. }
  2952. service.CreateExportErrLog(&err_log)
  2953. continue
  2954. }
  2955. drug.DrugStockLimit = drug_stock_limit
  2956. drug_origin_place, _ := goodNameM["drug_origin_place"].(string)
  2957. if len(drug_origin_place) == 0 { //名字为空则生成一条导入错误日志
  2958. err_log := models.ExportErrLog{
  2959. LogType: 4,
  2960. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2961. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的产地不能为空",
  2962. Status: 1,
  2963. CreateTime: time.Now().Unix(),
  2964. UpdateTime: time.Now().Unix(),
  2965. ExportTime: time.Now().Unix(),
  2966. }
  2967. service.CreateExportErrLog(&err_log)
  2968. continue
  2969. }
  2970. drug.DrugOriginPlace = drug_origin_place
  2971. drug_dosage_form := goodNameM["drug_dosage_form"].(string)
  2972. if len(drug_dosage_form) == 0 {
  2973. err_log := models.ExportErrLog{
  2974. LogType: 4,
  2975. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2976. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药品剂型不能为空",
  2977. Status: 1,
  2978. CreateTime: time.Now().Unix(),
  2979. UpdateTime: time.Now().Unix(),
  2980. ExportTime: time.Now().Unix(),
  2981. }
  2982. service.CreateExportErrLog(&err_log)
  2983. continue
  2984. }
  2985. var drug_dosage = "药品剂型"
  2986. var drug_dosage_form_id int64
  2987. drugDosageconfig, _ := service.GetDrugDataConfig(0, drug_dosage)
  2988. if len(drug_dosage_form) != 0 {
  2989. _, errcodess := service.IsExistDicConfig(drugDosageconfig.ID, drug_dosage_form, orgId)
  2990. if errcodess == gorm.ErrRecordNotFound {
  2991. configOne, _ := service.GetLastDicConfig(drugDosageconfig.ID, orgId)
  2992. dataconfig := models.DictDataconfig{
  2993. ParentId: drugDosageconfig.ID,
  2994. Module: "system",
  2995. OrgId: orgId,
  2996. Name: drug_dosage_form,
  2997. FieldName: "",
  2998. Value: configOne.Value + 1,
  2999. CreatedTime: "",
  3000. UpdatedTime: "",
  3001. CreateUserId: adminUser.AdminUser.Id,
  3002. Status: 1,
  3003. Remark: "",
  3004. DeleteIdSystem: 0,
  3005. Title: "",
  3006. Content: "",
  3007. Order: 0,
  3008. Code: "",
  3009. }
  3010. service.CreatedDicConfig(&dataconfig)
  3011. }
  3012. }
  3013. drugDosageList, _ := service.GetParentDataConfig(drugDosageconfig.ID, orgId)
  3014. for _, it := range drugDosageList {
  3015. if drug_dosage_form == it.Name {
  3016. drug_dosage_form_id = int64(it.Value)
  3017. }
  3018. }
  3019. drug.DrugDosageForm = drug_dosage_form_id
  3020. medical_insurance_level := goodNameM["medical_insurance_level"].(string)
  3021. var medical_insurance_level_id int64
  3022. if len(medical_insurance_level) == 0 { //名字为空则生成一条导入错误日志
  3023. err_log := models.ExportErrLog{
  3024. LogType: 4,
  3025. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3026. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的医保等级不能为空",
  3027. Status: 1,
  3028. CreateTime: time.Now().Unix(),
  3029. UpdateTime: time.Now().Unix(),
  3030. ExportTime: time.Now().Unix(),
  3031. }
  3032. service.CreateExportErrLog(&err_log)
  3033. continue
  3034. }
  3035. var medicalInsuranceName = "医保等级"
  3036. medicalInsuranceConfig, _ := service.GetDrugDataConfig(0, medicalInsuranceName)
  3037. if len(medical_insurance_level) != 0 {
  3038. _, errcodemedical := service.IsExistDicConfig(medicalInsuranceConfig.ID, medical_insurance_level, orgId)
  3039. if errcodemedical == gorm.ErrRecordNotFound {
  3040. medConfig, _ := service.GetLastDicConfig(medicalInsuranceConfig.ID, orgId)
  3041. dataconfig := models.DictDataconfig{
  3042. ParentId: medicalInsuranceConfig.ID,
  3043. Module: "system",
  3044. OrgId: orgId,
  3045. Name: medical_insurance_level,
  3046. FieldName: "",
  3047. Value: medConfig.Value + 1,
  3048. CreatedTime: "",
  3049. UpdatedTime: "",
  3050. CreateUserId: adminUser.AdminUser.Id,
  3051. Status: 1,
  3052. Remark: "",
  3053. DeleteIdSystem: 0,
  3054. Title: "",
  3055. Content: "",
  3056. Order: 0,
  3057. Code: "",
  3058. }
  3059. service.CreatedDicConfig(&dataconfig)
  3060. }
  3061. }
  3062. medicalInsuranceList, _ := service.GetParentDataConfig(medicalInsuranceConfig.ID, orgId)
  3063. for _, it := range medicalInsuranceList {
  3064. if medical_insurance_level == it.Name {
  3065. medical_insurance_level_id = int64(it.Value)
  3066. }
  3067. }
  3068. drug.MedicalInsuranceLevel = medical_insurance_level_id
  3069. unit_matrixing := goodNameM["unit_matrixing"].(string)
  3070. if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
  3071. err_log := models.ExportErrLog{
  3072. LogType: 4,
  3073. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3074. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的单位换算不能为空",
  3075. Status: 1,
  3076. CreateTime: time.Now().Unix(),
  3077. UpdateTime: time.Now().Unix(),
  3078. ExportTime: time.Now().Unix(),
  3079. }
  3080. service.CreateExportErrLog(&err_log)
  3081. continue
  3082. }
  3083. drug.UnitMatrixing = unit_matrixing
  3084. retail_prices := goodNameM["retail_price"].(string)
  3085. retail_price, _ := strconv.ParseFloat(retail_prices, 64)
  3086. if retail_price <= 0 { //名字为空则生成一条导入错误日志
  3087. err_log := models.ExportErrLog{
  3088. LogType: 4,
  3089. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3090. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的拆零售价不能为空",
  3091. Status: 1,
  3092. CreateTime: time.Now().Unix(),
  3093. UpdateTime: time.Now().Unix(),
  3094. ExportTime: time.Now().Unix(),
  3095. }
  3096. service.CreateExportErrLog(&err_log)
  3097. continue
  3098. }
  3099. drug.RetailPrice = retail_price
  3100. packing_prices := goodNameM["packing_price"].(string)
  3101. packing_price, _ := strconv.ParseFloat(packing_prices, 64)
  3102. if packing_price <= 0 { //名字为空则生成一条导入错误日志
  3103. err_log := models.ExportErrLog{
  3104. LogType: 4,
  3105. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3106. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的包装零售价不能为空",
  3107. Status: 1,
  3108. CreateTime: time.Now().Unix(),
  3109. UpdateTime: time.Now().Unix(),
  3110. ExportTime: time.Now().Unix(),
  3111. }
  3112. service.CreateExportErrLog(&err_log)
  3113. continue
  3114. }
  3115. drug.RetailPrice = retail_price
  3116. last_prices := goodNameM["last_price"].(string)
  3117. last_price, _ := strconv.ParseFloat(last_prices, 64)
  3118. if last_price <= 0 { //名字为空则生成一条导入错误日志
  3119. err_log := models.ExportErrLog{
  3120. LogType: 4,
  3121. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3122. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的进货价不能为空",
  3123. Status: 1,
  3124. CreateTime: time.Now().Unix(),
  3125. UpdateTime: time.Now().Unix(),
  3126. ExportTime: time.Now().Unix(),
  3127. }
  3128. service.CreateExportErrLog(&err_log)
  3129. continue
  3130. }
  3131. drug.LastPrice = last_price
  3132. drug_classify := goodNameM["drug_classify"].(string)
  3133. if len(drug_classify) == 0 { //名字为空则生成一条导入错误日志
  3134. err_log := models.ExportErrLog{
  3135. LogType: 4,
  3136. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3137. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的药物分类不能为空",
  3138. Status: 1,
  3139. CreateTime: time.Now().Unix(),
  3140. UpdateTime: time.Now().Unix(),
  3141. ExportTime: time.Now().Unix(),
  3142. }
  3143. service.CreateExportErrLog(&err_log)
  3144. continue
  3145. }
  3146. var drugClassify = "药物分类"
  3147. var drug_classify_id int64
  3148. drugClassifyConfig, _ := service.GetDrugDataConfig(0, drugClassify)
  3149. if len(drug_classify) != 0 {
  3150. _, errcodesClass := service.IsExistDicConfig(drugClassifyConfig.ID, drug_classify, orgId)
  3151. if errcodesClass == gorm.ErrRecordNotFound {
  3152. drugClassConfig, _ := service.GetLastDicConfig(drugClassifyConfig.ID, orgId)
  3153. dataconfig := models.DictDataconfig{
  3154. ParentId: drugClassifyConfig.ID,
  3155. Module: "system",
  3156. OrgId: orgId,
  3157. Name: drug_classify,
  3158. FieldName: "",
  3159. Value: drugClassConfig.Value + 1,
  3160. CreatedTime: "",
  3161. UpdatedTime: "",
  3162. CreateUserId: adminUser.AdminUser.Id,
  3163. Status: 1,
  3164. Remark: "",
  3165. DeleteIdSystem: 0,
  3166. Title: "",
  3167. Content: "",
  3168. Order: 0,
  3169. Code: "",
  3170. }
  3171. service.CreatedDicConfig(&dataconfig)
  3172. }
  3173. }
  3174. drugClassList, _ := service.GetParentDataConfig(drugClassifyConfig.ID, orgId)
  3175. for _, it := range drugClassList {
  3176. if drug_classify == it.Name {
  3177. drug_classify_id = int64(it.Value)
  3178. }
  3179. }
  3180. drug_dose := goodNameM["drug_dose"].(string)
  3181. if len(drug_dose) == 0 {
  3182. err_log := models.ExportErrLog{
  3183. LogType: 4,
  3184. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3185. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
  3186. Status: 1,
  3187. CreateTime: time.Now().Unix(),
  3188. UpdateTime: time.Now().Unix(),
  3189. ExportTime: time.Now().Unix(),
  3190. }
  3191. service.CreateExportErrLog(&err_log)
  3192. continue
  3193. }
  3194. drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
  3195. drug.DrugDose = drugDoses
  3196. var units = "单位"
  3197. var unit_id int64
  3198. drugDoseUnit := goodNameM["drug_dose_unit"].(string)
  3199. if len(drugDoseUnit) == 0 {
  3200. err_log := models.ExportErrLog{
  3201. LogType: 4,
  3202. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3203. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
  3204. Status: 1,
  3205. CreateTime: time.Now().Unix(),
  3206. UpdateTime: time.Now().Unix(),
  3207. ExportTime: time.Now().Unix(),
  3208. }
  3209. service.CreateExportErrLog(&err_log)
  3210. continue
  3211. }
  3212. dataConfig, _ := service.GetDataConfigIsExist(0, units)
  3213. if len(drugDoseUnit) != 0 {
  3214. _, errcodedataconfig := service.GetChildeConfigIsExist(dataConfig.ID, drugDoseUnit, orgId)
  3215. if errcodedataconfig == gorm.ErrRecordNotFound {
  3216. childConfig, _ := service.GetLastChildeConfig(dataConfig.ID, orgId)
  3217. dataconfig := models.Dataconfig{
  3218. ParentId: dataConfig.ID,
  3219. Module: "hemodialysis",
  3220. OrgId: orgId,
  3221. Name: drugDoseUnit,
  3222. FieldName: "",
  3223. Value: childConfig.Value + 1,
  3224. CreatedTime: "",
  3225. UpdatedTime: "",
  3226. CreateUserId: adminUser.AdminUser.Id,
  3227. Status: 1,
  3228. Remark: "",
  3229. DeleteIdSystem: 0,
  3230. Title: "",
  3231. Content: "",
  3232. Order: 0,
  3233. Code: "",
  3234. FieldType: 0,
  3235. }
  3236. service.CreateDataConfig(&dataconfig)
  3237. }
  3238. }
  3239. list, _ := service.FindAllDataConfigList(orgId, dataConfig.ID)
  3240. for _, it := range list {
  3241. if drugDoseUnit == it.Name {
  3242. unit_id = int64(it.Value)
  3243. }
  3244. }
  3245. drug.DrugDoseUnit = unit_id
  3246. drug.DrugClassify = strconv.FormatInt(drug_classify_id, 10)
  3247. manufacturer := goodNameM["manufacturer"].(string)
  3248. if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
  3249. err_log := models.ExportErrLog{
  3250. LogType: 4,
  3251. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3252. ErrMsg: "第" + strconv.Itoa(index+2) + "行" + "的生产商不能为空或内容与系统不匹配",
  3253. Status: 1,
  3254. CreateTime: time.Now().Unix(),
  3255. UpdateTime: time.Now().Unix(),
  3256. ExportTime: time.Now().Unix(),
  3257. }
  3258. service.CreateExportErrLog(&err_log)
  3259. continue
  3260. }
  3261. if len(manufacturer) != 0 {
  3262. _, errcodema := service.GetManufacturerName(orgId, manufacturer)
  3263. if errcodema == gorm.ErrRecordNotFound {
  3264. manufactur := models.Manufacturer{
  3265. OrgId: orgId,
  3266. Status: 1,
  3267. ManufacturerName: manufacturer,
  3268. Ctime: time.Now().Unix(),
  3269. Creater: adminUser.AdminUser.Id,
  3270. }
  3271. service.CreateManufacturer(&manufactur)
  3272. }
  3273. }
  3274. var manufacturer_id int64
  3275. manufacturList, _ := service.GetAllManufacturerList(orgId)
  3276. for _, it := range manufacturList {
  3277. if manufacturer == it.ManufacturerName {
  3278. manufacturer_id = it.ID
  3279. }
  3280. }
  3281. drug.Manufacturer = manufacturer_id
  3282. dealer := goodNameM["dealer"].(string)
  3283. if len(dealer) != 0 {
  3284. _, errcodesdealer := service.GetDealerByName(orgId, dealer)
  3285. if errcodesdealer == gorm.ErrRecordNotFound {
  3286. dealerconfig := models.Dealer{
  3287. DealerName: dealer,
  3288. Status: 1,
  3289. OrgId: orgId,
  3290. Ctime: time.Now().Unix(),
  3291. Creater: adminUser.AdminUser.Id,
  3292. }
  3293. service.CreateDealer(&dealerconfig)
  3294. }
  3295. }
  3296. var dealer_id int64
  3297. dealerList, _ := service.GetAllDealerList(orgId)
  3298. for _, it := range dealerList {
  3299. if dealer == it.DealerName {
  3300. dealer_id = it.ID
  3301. }
  3302. }
  3303. drug.Dealer = dealer_id
  3304. lmt_used_flags := int64(goodNameM["lmt_used_flag"].(float64))
  3305. drug.LmtUsedFlag = lmt_used_flags
  3306. if goodNameM["drug_alias"] == nil || reflect.TypeOf(goodNameM["drug_alias"]).String() != "string" {
  3307. utils.ErrorLog("drug_alias")
  3308. return
  3309. }
  3310. drug_alias, _ := goodNameM["drug_alias"].(string)
  3311. drug.DrugAlias = drug_alias
  3312. drug_category := goodNameM["drug_category"].(string)
  3313. var drugCategory = "药品类别"
  3314. var drug_category_id int64
  3315. drugCategoryConfig, _ := service.GetDrugDataConfig(0, drugCategory)
  3316. if len(drug_category) != 0 {
  3317. _, drugcategoryerrcodes := service.IsExistDicConfig(drugCategoryConfig.ID, drug_category, orgId)
  3318. if drugcategoryerrcodes == gorm.ErrRecordNotFound {
  3319. drugCategoryConfigSix, _ := service.GetLastDicConfig(drugCategoryConfig.ID, orgId)
  3320. dataconfig := models.DictDataconfig{
  3321. ParentId: drugCategoryConfig.ID,
  3322. Module: "system",
  3323. OrgId: orgId,
  3324. Name: drug_category,
  3325. FieldName: "",
  3326. Value: drugCategoryConfigSix.Value + 1,
  3327. CreatedTime: "",
  3328. UpdatedTime: "",
  3329. CreateUserId: adminUser.AdminUser.Id,
  3330. Status: 1,
  3331. Remark: "",
  3332. DeleteIdSystem: 0,
  3333. Title: "",
  3334. Content: "",
  3335. Order: 0,
  3336. Code: "",
  3337. }
  3338. service.CreatedDicConfig(&dataconfig)
  3339. }
  3340. }
  3341. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryConfig.ID, orgId)
  3342. fmt.Println("drugCategoryList", drugCategoryList)
  3343. for _, it := range drugCategoryList {
  3344. if drug_category == it.Name {
  3345. drug_category_id = int64(it.Value)
  3346. }
  3347. }
  3348. drug.DrugCategory = drug_category_id
  3349. statistics_category := goodNameM["statistics_category"].(string)
  3350. var statisticsCategory = "统计分类"
  3351. var statistics_category_id int64
  3352. statistcConfig, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3353. if len(statistics_category) != 0 {
  3354. _, errcodestatistc := service.IsExistDicConfig(statistcConfig.ID, statistics_category, orgId)
  3355. if errcodestatistc == gorm.ErrRecordNotFound {
  3356. staConfig, _ := service.GetLastDicConfig(statistcConfig.ID, orgId)
  3357. dataconfig := models.DictDataconfig{
  3358. ParentId: statistcConfig.ID,
  3359. Module: "system",
  3360. OrgId: orgId,
  3361. Name: statistics_category,
  3362. FieldName: "",
  3363. Value: staConfig.Value + 1,
  3364. CreatedTime: "",
  3365. UpdatedTime: "",
  3366. CreateUserId: adminUser.AdminUser.Id,
  3367. Status: 1,
  3368. Remark: "",
  3369. DeleteIdSystem: 0,
  3370. Title: "",
  3371. Content: "",
  3372. Order: 0,
  3373. Code: "",
  3374. }
  3375. service.CreatedDicConfig(&dataconfig)
  3376. }
  3377. }
  3378. statisticsCategoryList, _ := service.GetParentDataConfig(statistcConfig.ID, orgId)
  3379. for _, it := range statisticsCategoryList {
  3380. if statistics_category == it.Name {
  3381. statistics_category_id = int64(it.Value)
  3382. }
  3383. }
  3384. drug.StatisticsCategory = statistics_category_id
  3385. number := goodNameM["number"].(string)
  3386. drug.Number = number
  3387. hosp_appr_flag := int64(goodNameM["hosp_appr_flag"].(float64))
  3388. drug.HospApprFlag = hosp_appr_flag
  3389. medical_insurance_number := goodNameM["medical_insurance_number"].(string)
  3390. drug.MedicalInsuranceNumber = medical_insurance_number
  3391. pharmacology_category := goodNameM["pharmacology_category"].(string)
  3392. var pharmacology = "药理分类"
  3393. var pharmacology_category_id int64
  3394. pharmacologyConfig, _ := service.GetDrugDataConfig(0, pharmacology)
  3395. if len(pharmacology_category) != 0 {
  3396. _, errcodespharmacology := service.IsExistDicConfig(pharmacologyConfig.ID, pharmacology_category, orgId)
  3397. if errcodespharmacology == gorm.ErrRecordNotFound {
  3398. dicConfig, _ := service.GetLastDicConfig(pharmacologyConfig.ID, orgId)
  3399. dataconfig := models.DictDataconfig{
  3400. ParentId: pharmacologyConfig.ID,
  3401. Module: "system",
  3402. OrgId: orgId,
  3403. Name: pharmacology_category,
  3404. FieldName: "",
  3405. Value: dicConfig.Value + 1,
  3406. CreatedTime: "",
  3407. UpdatedTime: "",
  3408. CreateUserId: adminUser.AdminUser.Id,
  3409. Status: 1,
  3410. Remark: "",
  3411. DeleteIdSystem: 0,
  3412. Title: "",
  3413. Content: "",
  3414. Order: 0,
  3415. Code: "",
  3416. }
  3417. service.CreatedDicConfig(&dataconfig)
  3418. }
  3419. }
  3420. pharmacologyList, _ := service.GetParentDataConfig(pharmacologyConfig.ID, orgId)
  3421. for _, it := range pharmacologyList {
  3422. if pharmacology_category == it.Name {
  3423. pharmacology_category_id = int64(it.Value)
  3424. }
  3425. }
  3426. drug.PharmacologyCategory = pharmacology_category_id
  3427. code := goodNameM["code"].(string)
  3428. drug.Code = code
  3429. is_special_diseases := int64(goodNameM["is_special_diseases"].(float64))
  3430. drug.IsSpecialDiseases = is_special_diseases
  3431. is_record := int64(goodNameM["is_record"].(float64))
  3432. drug.IsRecord = is_record
  3433. prescription_mark := int64(goodNameM["prescription_mark"].(float64))
  3434. drug.PrescriptionMark = prescription_mark
  3435. social_security_directory_code := goodNameM["social_security_directory_code"].(string)
  3436. drug.SocialSecurityDirectoryCode = social_security_directory_code
  3437. record_date := goodNameM["record_date"].(string)
  3438. timeLayout := "2006-01-02"
  3439. loc, _ := time.LoadLocation("Local")
  3440. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3441. drug.RecordDate = theTime.Unix()
  3442. drug_remark := goodNameM["drug_remark"].(string)
  3443. drug.DrugRemark = drug_remark
  3444. drug_status := goodNameM["drug_status"].(string)
  3445. drug.DrugStatus = drug_status
  3446. limit_remark := goodNameM["limit_remark"].(string)
  3447. drug.LimitRemark = limit_remark
  3448. drug_control := goodNameM["drug_control"].(string)
  3449. var drugControl = "开药控制"
  3450. var drug_control_id int64
  3451. drugContorlConfig, _ := service.GetDrugDataConfig(0, drugControl)
  3452. if len(drug_control) != 0 {
  3453. _, errcodesdrugcontrol := service.IsExistDicConfig(drugContorlConfig.ID, drug_control, orgId)
  3454. if errcodesdrugcontrol == gorm.ErrRecordNotFound {
  3455. drugContorlConfigOne, _ := service.GetLastDicConfig(drugContorlConfig.ID, orgId)
  3456. dataconfig := models.DictDataconfig{
  3457. ParentId: drugContorlConfig.ID,
  3458. Module: "system",
  3459. OrgId: orgId,
  3460. Name: drug_control,
  3461. FieldName: "",
  3462. Value: drugContorlConfigOne.Value + 1,
  3463. CreatedTime: "",
  3464. UpdatedTime: "",
  3465. CreateUserId: adminUser.AdminUser.Id,
  3466. Status: 1,
  3467. Remark: "",
  3468. DeleteIdSystem: 0,
  3469. Title: "",
  3470. Content: "",
  3471. Order: 0,
  3472. Code: "",
  3473. }
  3474. service.CreatedDicConfig(&dataconfig)
  3475. }
  3476. }
  3477. drugContorlList, _ := service.GetParentDataConfig(drugContorlConfig.ID, orgId)
  3478. for _, it := range drugContorlList {
  3479. if drug_control == it.Name {
  3480. drug_control_id = int64(it.Value)
  3481. }
  3482. }
  3483. drug.DrugControl = drug_control_id
  3484. drugList = append(drugList, &drug)
  3485. }
  3486. export_time := time.Now().Unix()
  3487. errLogs, _ := service.FindPatientExportLogOne(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3488. if len(drugList) > 0 {
  3489. for _, item := range drugList {
  3490. goodInfo := models.BaseDrugLib{
  3491. DrugName: item.DrugName,
  3492. DrugAlias: item.DrugAlias,
  3493. DrugSpec: item.DrugSpec,
  3494. DrugType: item.DrugType,
  3495. DrugStockLimit: item.DrugStockLimit,
  3496. DrugOriginPlace: item.DrugOriginPlace,
  3497. DrugDosageForm: item.DrugDosageForm,
  3498. MedicalInsuranceLevel: item.MedicalInsuranceLevel,
  3499. MaxUnit: item.MaxUnit,
  3500. MinUnit: item.MinUnit,
  3501. UnitMatrixing: item.UnitMatrixing,
  3502. RetailPrice: item.RetailPrice,
  3503. LastPrice: item.LastPrice,
  3504. DrugClassify: item.DrugClassify,
  3505. Manufacturer: item.Manufacturer,
  3506. Dealer: item.Dealer,
  3507. OrgId: orgId,
  3508. Status: 1,
  3509. Ctime: time.Now().Unix(),
  3510. Pinyin: item.Pinyin,
  3511. Wubi: item.Wubi,
  3512. DrugAliasPinyin: item.DrugAliasPinyin,
  3513. DrugAliasWubi: item.DrugAliasWubi,
  3514. DrugControl: item.DrugControl,
  3515. Number: item.Number,
  3516. HospApprFlag: item.HospApprFlag,
  3517. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  3518. PharmacologyCategory: item.PharmacologyCategory,
  3519. StatisticsCategory: item.StatisticsCategory,
  3520. Code: item.Code,
  3521. IsSpecialDiseases: item.IsSpecialDiseases,
  3522. IsRecord: item.IsRecord,
  3523. PrescriptionMark: item.PrescriptionMark,
  3524. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3525. RecordDate: item.RecordDate,
  3526. DrugRemark: item.DrugRemark,
  3527. DrugStatus: item.DrugStatus,
  3528. LimitRemark: item.LimitRemark,
  3529. DrugCategory: item.DrugCategory,
  3530. DrugDose: item.DrugDose,
  3531. DrugDoseUnit: item.DrugDoseUnit,
  3532. LmtUsedFlag: item.LmtUsedFlag,
  3533. DrugDay: item.DrugDay,
  3534. DeliveryWay: item.DeliveryWay,
  3535. ExecutionFrequency: item.ExecutionFrequency,
  3536. DoseUnit: item.DoseUnit,
  3537. }
  3538. //查询同种药品同种规格是否存在
  3539. _, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.MaxUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
  3540. if drugerror == gorm.ErrRecordNotFound {
  3541. service.CreateDrugsInfomation(&goodInfo)
  3542. } else if drugerror == nil {
  3543. service.UpdateDrugsInformation(&goodInfo, item.DrugName, item.DrugSpec, orgId)
  3544. }
  3545. log := models.ExportLog{
  3546. LogType: 4,
  3547. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3548. TotalNum: int64(len(total_goods)),
  3549. FailNum: int64(len(errLogs)),
  3550. SuccessNum: int64(len(drugList)),
  3551. CreateTime: time.Now().Unix(),
  3552. UpdateTime: time.Now().Unix(),
  3553. ExportTime: export_time,
  3554. Status: 1,
  3555. }
  3556. service.CreateExportLog(&log)
  3557. this.ServeSuccessJSON(map[string]interface{}{
  3558. "msg": "导入成功",
  3559. "total_num": len(total_goods),
  3560. "success_num": len(drugList),
  3561. "fail_num": int64(len(errLogs)),
  3562. })
  3563. }
  3564. } else {
  3565. log := models.ExportLog{
  3566. LogType: 4,
  3567. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3568. TotalNum: int64(len(total_goods)),
  3569. FailNum: int64(len(errLogs)),
  3570. SuccessNum: int64(len(drugList)),
  3571. CreateTime: time.Now().Unix(),
  3572. UpdateTime: time.Now().Unix(),
  3573. ExportTime: export_time,
  3574. Status: 1,
  3575. }
  3576. service.CreateExportLog(&log)
  3577. this.ServeSuccessJSON(map[string]interface{}{
  3578. "msg": "导入成功",
  3579. "total_num": len(total_goods),
  3580. "success_num": len(drugList),
  3581. "fail_num": int64(len(errLogs)),
  3582. })
  3583. }
  3584. }
  3585. func (this *StockManagerApiController) GetInitializtion() {
  3586. orgId := this.GetAdminUserInfo().CurrentOrgId
  3587. var drugCategory = "药品类别"
  3588. var drugType = "药品类型"
  3589. var drugDosageForm = "药品剂型"
  3590. var medicalInsuranceLevel = "医保等级"
  3591. var drugControl = "开药控制"
  3592. var drugClassify = "药物分类"
  3593. var statisticsCategory = "统计分类"
  3594. var pharmacologyCategory = "药理分类"
  3595. var goodKind = "耗材种类"
  3596. var tubeColor = "试管颜色"
  3597. var costClassify = "费用类别"
  3598. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  3599. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  3600. drugCategoryParent, _ := service.GetDrugDataConfig(0, drugCategory)
  3601. drugCategoryList, _ := service.GetParentDataConfig(drugCategoryParent.ID, orgId)
  3602. drugDosageFormParent, _ := service.GetDrugDataConfig(0, drugDosageForm)
  3603. drugDosageFormList, _ := service.GetParentDataConfig(drugDosageFormParent.ID, orgId)
  3604. medicalInsuranceLevelParent, _ := service.GetDrugDataConfig(0, medicalInsuranceLevel)
  3605. medicalInsuranceLevelList, _ := service.GetParentDataConfig(medicalInsuranceLevelParent.ID, orgId)
  3606. drugControlParent, _ := service.GetDrugDataConfig(0, drugControl)
  3607. drugControlList, _ := service.GetParentDataConfig(drugControlParent.ID, orgId)
  3608. drugClassifyParent, _ := service.GetDrugDataConfig(0, drugClassify)
  3609. drugClassifyList, _ := service.GetParentDataConfig(drugClassifyParent.ID, orgId)
  3610. statisticsCategoryParent, _ := service.GetDrugDataConfig(0, statisticsCategory)
  3611. statisticsCategoryList, _ := service.GetParentDataConfig(statisticsCategoryParent.ID, orgId)
  3612. pharmacologyCategoryParent, _ := service.GetDrugDataConfig(0, pharmacologyCategory)
  3613. pharmacologyCategoryList, _ := service.GetParentDataConfig(pharmacologyCategoryParent.ID, orgId)
  3614. goodKindParent, _ := service.GetDrugDataConfig(0, goodKind)
  3615. goodKindList, _ := service.GetParentDataConfig(goodKindParent.ID, orgId)
  3616. tubeColorParent, _ := service.GetDrugDataConfig(0, tubeColor)
  3617. tubeColorList, _ := service.GetParentDataConfig(tubeColorParent.ID, orgId)
  3618. costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
  3619. costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, orgId)
  3620. this.ServeSuccessJSON(map[string]interface{}{
  3621. "drugCategoryList": drugCategoryList,
  3622. "drugTypeList": drugTypeList,
  3623. "drugDosageFormList": drugDosageFormList,
  3624. "medicalInsuranceLevelList": medicalInsuranceLevelList,
  3625. "drugControlList": drugControlList,
  3626. "drugClassifyList": drugClassifyList,
  3627. "statisticsCategoryList": statisticsCategoryList,
  3628. "pharmacologyCategoryList": pharmacologyCategoryList,
  3629. "goodKindList": goodKindList,
  3630. "tubeColorList": tubeColorList,
  3631. "costClassifyList": costClassifyList,
  3632. })
  3633. }
  3634. func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
  3635. adminUserInfo := this.GetAdminUserInfo()
  3636. orgId := adminUserInfo.CurrentOrgId
  3637. list, _ := service.GetWarehouseOrderInfoList(orgId)
  3638. this.ServeSuccessJSON(map[string]interface{}{
  3639. "list": list,
  3640. })
  3641. }
  3642. func (this *StockManagerApiController) PostSearchGoodList() {
  3643. keyword := this.GetString("keyword")
  3644. adminUserInfo := this.GetAdminUserInfo()
  3645. orgId := adminUserInfo.CurrentOrgId
  3646. list, _ := service.GetSearchGoodList(keyword, orgId)
  3647. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3648. dealerList, _ := service.GetAllDealerList(orgId)
  3649. this.ServeSuccessJSON(map[string]interface{}{
  3650. "list": list,
  3651. "manufacturerList": manufacturerList,
  3652. "dealerList": dealerList,
  3653. })
  3654. }
  3655. func (this *StockManagerApiController) GetAllStockList() {
  3656. page, _ := this.GetInt64("page", -1)
  3657. limit, _ := this.GetInt64("limit", -1)
  3658. start_time := this.GetString("start_time")
  3659. end_time := this.GetString("end_time")
  3660. types, _ := this.GetInt64("type", 0)
  3661. keywords := this.GetString("keywords")
  3662. timeLayout := "2006-01-02"
  3663. loc, _ := time.LoadLocation("Local")
  3664. var startTime int64
  3665. if len(start_time) > 0 {
  3666. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3667. if err != nil {
  3668. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3669. return
  3670. }
  3671. startTime = theTime.Unix()
  3672. }
  3673. var endTime int64
  3674. if len(end_time) > 0 {
  3675. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3676. if err != nil {
  3677. utils.ErrorLog(err.Error())
  3678. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3679. return
  3680. }
  3681. endTime = theTime.Unix()
  3682. }
  3683. adminUserInfo := this.GetAdminUserInfo()
  3684. orgId := adminUserInfo.CurrentOrgId
  3685. list, total, _ := service.GetAllStockList(page, limit, startTime, endTime, types, keywords, orgId)
  3686. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3687. this.ServeSuccessJSON(map[string]interface{}{
  3688. "list": list,
  3689. "total": total,
  3690. "manufacturerList": manufacturerList,
  3691. })
  3692. }
  3693. func (this *StockManagerApiController) GetStockListById() {
  3694. id, _ := this.GetInt64("id")
  3695. adminUserInfo := this.GetAdminUserInfo()
  3696. orgId := adminUserInfo.CurrentOrgId
  3697. limit, _ := this.GetInt64("limit")
  3698. page, _ := this.GetInt64("page")
  3699. timeLayout := "2006-01-02"
  3700. loc, _ := time.LoadLocation("Local")
  3701. start_time := this.GetString("start_time")
  3702. end_time := this.GetString("end_time")
  3703. var startTime int64
  3704. if len(start_time) > 0 {
  3705. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3706. if err != nil {
  3707. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3708. return
  3709. }
  3710. startTime = theTime.Unix()
  3711. }
  3712. var endTime int64
  3713. if len(end_time) > 0 {
  3714. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3715. if err != nil {
  3716. utils.ErrorLog(err.Error())
  3717. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3718. return
  3719. }
  3720. endTime = theTime.Unix()
  3721. }
  3722. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3723. list, total, _ := service.GetStockListById(id, orgId, limit, page, startTime, endTime)
  3724. this.ServeSuccessJSON(map[string]interface{}{
  3725. "list": list,
  3726. "total": total,
  3727. "manufacturerList": manufacturerList,
  3728. })
  3729. }
  3730. func (this *StockManagerApiController) GetStockOutList() {
  3731. id, _ := this.GetInt64("id")
  3732. adminUserInfo := this.GetAdminUserInfo()
  3733. orgId := adminUserInfo.CurrentOrgId
  3734. limit, _ := this.GetInt64("limit")
  3735. page, _ := this.GetInt64("page")
  3736. timeLayout := "2006-01-02"
  3737. loc, _ := time.LoadLocation("Local")
  3738. start_time := this.GetString("start_time")
  3739. end_time := this.GetString("end_time")
  3740. is_sys, _ := this.GetInt64("is_sys")
  3741. var startTime int64
  3742. if len(start_time) > 0 {
  3743. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3744. if err != nil {
  3745. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3746. return
  3747. }
  3748. startTime = theTime.Unix()
  3749. }
  3750. var endTime int64
  3751. if len(end_time) > 0 {
  3752. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3753. if err != nil {
  3754. utils.ErrorLog(err.Error())
  3755. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3756. return
  3757. }
  3758. endTime = theTime.Unix()
  3759. }
  3760. outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
  3761. this.ServeSuccessJSON(map[string]interface{}{
  3762. "outList": outList,
  3763. "total": total,
  3764. })
  3765. }
  3766. func (this *StockManagerApiController) GetStockDrugCount() {
  3767. adminUserInfo := this.GetAdminUserInfo()
  3768. orgId := adminUserInfo.CurrentOrgId
  3769. fmt.Println(orgId)
  3770. timeLayout := "2006-01-02"
  3771. loc, _ := time.LoadLocation("Local")
  3772. start_time := this.GetString("start_time")
  3773. end_time := this.GetString("end_time")
  3774. var startTime int64
  3775. if len(start_time) > 0 {
  3776. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3777. if err != nil {
  3778. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3779. return
  3780. }
  3781. startTime = theTime.Unix()
  3782. }
  3783. var endTime int64
  3784. if len(end_time) > 0 {
  3785. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3786. if err != nil {
  3787. utils.ErrorLog(err.Error())
  3788. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3789. return
  3790. }
  3791. endTime = theTime.Unix()
  3792. }
  3793. count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
  3794. outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
  3795. autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
  3796. totalCount, _ := service.GetCancelOutTotalCount(startTime, endTime, orgId)
  3797. this.ServeSuccessJSON(map[string]interface{}{
  3798. "count": count,
  3799. "outList": outList,
  3800. "autoCount": autoCount,
  3801. "totalCount": totalCount,
  3802. })
  3803. }
  3804. func (this *StockManagerApiController) GetOrderDetialByOrderId() {
  3805. ids := this.GetString("id")
  3806. idsArray := strings.Split(ids, ",")
  3807. orgId := this.GetAdminUserInfo().CurrentOrgId
  3808. order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
  3809. list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
  3810. //获取该耗材的最后一条数据
  3811. info, _ := service.GetLastWarehouseOutInfo(idsArray, orgId)
  3812. fmt.Println("info323e2342342342432342342432", info)
  3813. this.ServeSuccessJSON(map[string]interface{}{
  3814. "order": order,
  3815. "list": list,
  3816. "info": info,
  3817. })
  3818. }
  3819. func (this *StockManagerApiController) GetOrderDetailById() {
  3820. id, _ := this.GetInt64("id")
  3821. good_id, _ := this.GetInt64("good_id")
  3822. record_time, _ := this.GetInt64("record_time")
  3823. orgId := this.GetAdminUserInfo().CurrentOrgId
  3824. //自动出库
  3825. userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
  3826. //手动出库
  3827. info, _ := service.GetWarehouseOutInfoById(id, good_id)
  3828. stockFlowList, err := service.GetStockFlowBatchNumber(id, good_id)
  3829. if err == nil {
  3830. this.ServeSuccessJSON(map[string]interface{}{
  3831. "list": userDetails,
  3832. "total": total,
  3833. "info": info,
  3834. "stockFlowList": stockFlowList,
  3835. })
  3836. } else {
  3837. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3838. return
  3839. }
  3840. }
  3841. func (this *StockManagerApiController) GetSingleOutOrderDetail() {
  3842. id, _ := this.GetInt64("id", 0)
  3843. orgId := this.GetAdminUserInfo().CurrentOrgId
  3844. warehouseOutInfo, _ := service.GetOrderDetialByOrderId(id, orgId)
  3845. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3846. dealerList, _ := service.GetAllDealerList(orgId)
  3847. goodType, _ := service.GetAllGoodType(orgId)
  3848. this.ServeSuccessJSON(map[string]interface{}{
  3849. "list": warehouseOutInfo,
  3850. "dealerList": dealerList,
  3851. "manufacturerList": manufacturerList,
  3852. "goodType": goodType,
  3853. })
  3854. }
  3855. func (this *StockManagerApiController) GetExprotStockList() {
  3856. adminUserInfo := this.GetAdminUserInfo()
  3857. orgId := adminUserInfo.CurrentOrgId
  3858. timeLayout := "2006-01-02"
  3859. loc, _ := time.LoadLocation("Local")
  3860. start_time := this.GetString("start_time")
  3861. end_time := this.GetString("end_time")
  3862. idArray := this.GetString("id")
  3863. ids := strings.Split(idArray, ",")
  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. fmt.Println("ids2222222222222222", ids)
  3884. list, _ := service.GetExprotStockList(orgId, ids, startTime, endTime)
  3885. this.ServeSuccessJSON(map[string]interface{}{
  3886. "list": list,
  3887. })
  3888. }
  3889. func (this *StockManagerApiController) GetOutExprotList() {
  3890. adminUserInfo := this.GetAdminUserInfo()
  3891. orgId := adminUserInfo.CurrentOrgId
  3892. timeLayout := "2006-01-02"
  3893. loc, _ := time.LoadLocation("Local")
  3894. start_time := this.GetString("start_time")
  3895. end_time := this.GetString("end_time")
  3896. idArray := this.GetString("id")
  3897. ids := strings.Split(idArray, ",")
  3898. fmt.Println("ids2222222222", ids)
  3899. var startTime int64
  3900. if len(start_time) > 0 {
  3901. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3902. if err != nil {
  3903. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3904. return
  3905. }
  3906. startTime = theTime.Unix()
  3907. }
  3908. var endTime int64
  3909. if len(end_time) > 0 {
  3910. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3911. if err != nil {
  3912. utils.ErrorLog(err.Error())
  3913. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3914. return
  3915. }
  3916. endTime = theTime.Unix()
  3917. }
  3918. list, _ := service.GetOutExprotList(orgId, ids, startTime, endTime)
  3919. outCount, _ := service.GetOutStockTotalCountOne(startTime, endTime, orgId)
  3920. this.ServeSuccessJSON(map[string]interface{}{
  3921. "list": list,
  3922. "count": outCount,
  3923. })
  3924. }
  3925. func (this *StockManagerApiController) GetSingleCancelOrder() {
  3926. id, _ := this.GetInt64("id")
  3927. adminUserInfo := this.GetAdminUserInfo()
  3928. orgId := adminUserInfo.CurrentOrgId
  3929. order, _ := service.GetSingleCancelOrder(id, orgId)
  3930. this.ServeSuccessJSON(map[string]interface{}{
  3931. "list": order,
  3932. })
  3933. }
  3934. func (this *StockManagerApiController) GetCancelStockOrderPrint() {
  3935. id := this.GetString("id")
  3936. idStr := strings.Split(id, ",")
  3937. orgId := this.GetAdminUserInfo().CurrentOrgId
  3938. list, _ := service.GetCancelStockOrderPrintOne(idStr, orgId)
  3939. this.ServeSuccessJSON(map[string]interface{}{
  3940. "list": list,
  3941. })
  3942. }
  3943. func (this *StockManagerApiController) GetStockBatchNumber() {
  3944. id, _ := this.GetInt64("id")
  3945. orgId := this.GetAdminUserInfo().CurrentOrgId
  3946. list, _ := service.GetStockBatchNumber(id, orgId)
  3947. this.ServeSuccessJSON(map[string]interface{}{
  3948. "list": list,
  3949. })
  3950. }
  3951. func (this *StockManagerApiController) GetStockFlow() {
  3952. limit, _ := this.GetInt64("limit")
  3953. page, _ := this.GetInt64("page")
  3954. good_id, _ := this.GetInt64("good_id")
  3955. consumable_type, _ := this.GetInt64("is_sys")
  3956. adminUserInfo := this.GetAdminUserInfo()
  3957. orgId := adminUserInfo.CurrentOrgId
  3958. timeLayout := "2006-01-02"
  3959. loc, _ := time.LoadLocation("Local")
  3960. start_time := this.GetString("start_time")
  3961. end_time := this.GetString("end_time")
  3962. var startTime int64
  3963. if len(start_time) > 0 {
  3964. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3965. if err != nil {
  3966. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3967. return
  3968. }
  3969. startTime = theTime.Unix()
  3970. }
  3971. var endTime int64
  3972. if len(end_time) > 0 {
  3973. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3974. if err != nil {
  3975. utils.ErrorLog(err.Error())
  3976. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3977. return
  3978. }
  3979. endTime = theTime.Unix()
  3980. }
  3981. list, total, _ := service.GetStockFlowList(limit, page, consumable_type, orgId, startTime, endTime, good_id)
  3982. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  3983. this.ServeSuccessJSON(map[string]interface{}{
  3984. "list": list,
  3985. "total": total,
  3986. "manufacturerList": manufacturerList,
  3987. })
  3988. }
  3989. func (this *StockManagerApiController) GetCancelExportList() {
  3990. adminUserInfo := this.GetAdminUserInfo()
  3991. orgId := adminUserInfo.CurrentOrgId
  3992. timeLayout := "2006-01-02"
  3993. loc, _ := time.LoadLocation("Local")
  3994. start_time := this.GetString("start_time")
  3995. end_time := this.GetString("end_time")
  3996. idArray := this.GetString("order_id")
  3997. fmt.Println("232323232323232232", idArray)
  3998. ids := strings.Split(idArray, ",")
  3999. var startTime int64
  4000. if len(start_time) > 0 {
  4001. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4002. if err != nil {
  4003. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4004. return
  4005. }
  4006. startTime = theTime.Unix()
  4007. }
  4008. var endTime int64
  4009. if len(end_time) > 0 {
  4010. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4011. if err != nil {
  4012. utils.ErrorLog(err.Error())
  4013. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4014. return
  4015. }
  4016. endTime = theTime.Unix()
  4017. }
  4018. list, _ := service.GetCancelExportList(startTime, endTime, ids, orgId)
  4019. this.ServeSuccessJSON(map[string]interface{}{
  4020. "list": list,
  4021. })
  4022. }