stock_in_api_controller.go 119KB

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