stock_in_api_controller.go 110KB

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