stock_in_api_controller.go 121KB

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