drug_stock_api_contorller.go 64KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999
  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. "reflect"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. type StockDrugApiController struct {
  16. BaseAuthAPIController
  17. }
  18. func DrugStockManagerApiRegistRouters() {
  19. //入库管理和其他入库管理相关接口
  20. beego.Router("/api/drugwarehouse/create", &StockDrugApiController{}, "post:CreateDrugWarehouse")
  21. beego.Router("/api/drugwarehouse/list", &StockDrugApiController{}, "get:GetDrugWarehouseList")
  22. beego.Router("/api/drugwarehouse/delete", &StockDrugApiController{}, "post:DeleteDrugWarehouse")
  23. beego.Router("/api/drugwarehouseinfo/delete", &StockDrugApiController{}, "post:DeleteDrugWarehouseInfo")
  24. beego.Router("/api/drugwarehouseinfo/list", &StockDrugApiController{}, "get:GetDrugWarehouseInfoList")
  25. beego.Router("/api/drugwarehouse/edit", &StockDrugApiController{}, "post:EditDrugWarehouse")
  26. //退货管理和其他退货管理相关接口
  27. beego.Router("/api/drugsalesreturn/create", &StockDrugApiController{}, "post:CreateDrugSalesReturn")
  28. beego.Router("/api/drugsalesreturn/delete", &StockDrugApiController{}, "post:DeleteDrugSalesReturn")
  29. beego.Router("/api/drugsalesreturninfo/delete", &StockDrugApiController{}, "post:DeleteDrugSalesReturnInfo")
  30. beego.Router("/api/drugsalesreturninfo/list", &StockDrugApiController{}, "get:GetDrugSalesReturnInfoList")
  31. beego.Router("/api/drugsalesreturn/list", &StockDrugApiController{}, "get:GetDrugSalesReturnList")
  32. beego.Router("/api/drugsalesreturn/edit", &StockDrugApiController{}, "post:EditDrugReturnInfo")
  33. //出库管理和其他出库管理相关接口
  34. beego.Router("/api/drugwarehouseout/create", &StockDrugApiController{}, "post:CreateDrugWarehouseOut")
  35. beego.Router("/api/drugwarehouseout/delete", &StockDrugApiController{}, "post:DeleteDrugWarehouseOut")
  36. beego.Router("/api/drugwarehouseoutinfo/delete", &StockDrugApiController{}, "post:DeleteDrugWarehouseOutInfo")
  37. beego.Router("/api/drugwarehouseout/list", &StockDrugApiController{}, "get:GetDrugWarehouseOutList")
  38. beego.Router("/api/drugwarehouseout/edit", &StockDrugApiController{}, "post:EditDrugWarehouseOut")
  39. beego.Router("/api/drugwarehouseout/info", &StockDrugApiController{}, "get:GetDrugWarehouseOutInfoList")
  40. //出库退库管理和其他出库退库管理相关接口
  41. beego.Router("/api/drugcancelstock/create", &StockDrugApiController{}, "post:CreateDrugCancelStock")
  42. beego.Router("/api/drugcancelstock/list", &StockDrugApiController{}, "get:GetDrugCancelStockList")
  43. beego.Router("/api/drugcancelstock/info", &StockDrugApiController{}, "get:GetDrugCancelStockInfoList")
  44. beego.Router("/api/drugcancelstock/delete", &StockDrugApiController{}, "post:DeleteDrugCancelStock")
  45. beego.Router("/api/drugcancelstockinfo/delete", &StockDrugApiController{}, "post:DeleteDrugCancelStockInfo")
  46. beego.Router("/api/drugcancelstockinfo/edit", &StockDrugApiController{}, "post:EditDrugCancelStock")
  47. //beego.Router("/api/drugcancelstockinfo/config", &StockDrugApiController{}, "get:GetDrugCancelStockConfig")
  48. ////库存相关全局配置
  49. beego.Router("/api/drugstock/config", &StockDrugApiController{}, "get:GetAllConfig")
  50. //beego.Router("/api/drugreturn/config", &StockDrugApiController{}, "get:GetAllSalesReturnConfig")
  51. //
  52. ////库存查询
  53. beego.Router("/api/drugstock/query", &StockDrugApiController{}, "get:GetDrugQueryInfo")
  54. //
  55. //beego.Router("/api/drugstock/detail", &StockDrugApiController{}, "get:GetDetailInfo")
  56. //
  57. beego.Router("/api/drugwarehouseout/user", &StockDrugApiController{}, "get:GetUserDetailInfo")
  58. beego.Router("/api/drugstock/get", &StockDrugApiController{}, "get:GetAllDrugStock")
  59. }
  60. func (c *StockDrugApiController) CreateDrugWarehouse() {
  61. warehousing_time := c.GetString("warehousing_time")
  62. dealer_id, _ := c.GetInt64("dealer_id", 0)
  63. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  64. types, _ := c.GetInt64("type", 0)
  65. ctime := time.Now().Unix()
  66. adminUserInfo := c.GetAdminUserInfo()
  67. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  68. if parseDateErr != nil {
  69. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  70. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  71. return
  72. }
  73. timeStr := time.Now().Format("2006-01-02")
  74. timeArr := strings.Split(timeStr, "-")
  75. total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
  76. total = total + 1
  77. warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  78. operation_time := time.Now().Unix()
  79. creater := adminUserInfo.AdminUser.Id
  80. warehousing := models.DrugWarehouse{
  81. WarehousingOrder: warehousing_order,
  82. OperationTime: operation_time,
  83. OrgId: adminUserInfo.CurrentOrgId,
  84. Creater: creater,
  85. Ctime: ctime,
  86. Status: 1,
  87. WarehousingTime: warehousingDate.Unix(),
  88. Dealer: dealer_id,
  89. Manufacturer: manufacturer_id,
  90. Type: types,
  91. }
  92. service.AddSigleDrugWarehouse(&warehousing)
  93. dataBody := make(map[string]interface{}, 0)
  94. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  95. if err != nil {
  96. utils.ErrorLog(err.Error())
  97. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  98. return
  99. }
  100. var warehousingInfo []*models.DrugWarehouseInfo
  101. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  102. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  103. if len(thisStockIn) > 0 {
  104. for _, item := range thisStockIn {
  105. items := item.(map[string]interface{})
  106. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  107. utils.ErrorLog("drug_id")
  108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  109. return
  110. }
  111. drug_id := int64(items["drug_id"].(float64))
  112. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  113. utils.ErrorLog("warehousing_count")
  114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  115. return
  116. }
  117. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  118. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  119. utils.ErrorLog("last_price")
  120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  121. return
  122. }
  123. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  124. total := float64(warehousing_count) * last_price
  125. //if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  126. // utils.ErrorLog("retail_price")
  127. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  128. // return
  129. //}
  130. //retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  131. retail_price_total := float64(warehousing_count) * last_price
  132. var productDates int64
  133. var expiryDates int64
  134. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  135. expiryDates = 0
  136. } else {
  137. if len(items["expiry_date"].(string)) == 0 {
  138. expiryDates = 0
  139. } else {
  140. expiryDate, _ := items["expiry_date"].(string)
  141. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  142. expiryDates = expiry_date.Unix()
  143. }
  144. }
  145. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  146. productDates = 0
  147. } else {
  148. if len(items["product_date"].(string)) == 0 {
  149. productDates = 0
  150. } else {
  151. productDate, _ := items["product_date"].(string)
  152. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  153. productDates = product_date.Unix()
  154. }
  155. }
  156. lot_number, _ := items["lot_number"].(string)
  157. batch_number, _ := items["batch_number"].(string)
  158. if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
  159. utils.ErrorLog("max_unit")
  160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  161. return
  162. }
  163. max_unit, _ := items["max_unit"].(string)
  164. fmt.Println("最大单位00000000000000000000000000000000", max_unit)
  165. if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
  166. utils.ErrorLog("min_unit")
  167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. return
  169. }
  170. min_unit, _ := items["min_unit"].(string)
  171. fmt.Println("最下单位0090000000000000000000", min_unit)
  172. var remark string
  173. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  174. remark = ""
  175. } else {
  176. remark = items["remark"].(string)
  177. }
  178. warehouseInfo := &models.DrugWarehouseInfo{
  179. WarehousingOrder: warehousing.WarehousingOrder,
  180. WarehousingId: warehousing.ID,
  181. DrugId: drug_id,
  182. Number: lot_number,
  183. ProductDate: productDates,
  184. ExpiryDate: expiryDates,
  185. WarehousingCount: warehousing_count,
  186. Price: last_price,
  187. TotalPrice: total,
  188. Status: 1,
  189. Ctime: ctime,
  190. Remark: remark,
  191. OrgId: adminUserInfo.CurrentOrgId,
  192. Type: types,
  193. Manufacturer: manufacturer_id,
  194. Dealer: dealer_id,
  195. //RetailPrice: retail_price,
  196. StockMaxNumber: warehousing_count,
  197. RetailTotalPrice: retail_price_total,
  198. BatchNumber: batch_number,
  199. MaxUnit: max_unit,
  200. MinUnit: min_unit,
  201. }
  202. warehousingInfo = append(warehousingInfo, warehouseInfo)
  203. }
  204. }
  205. }
  206. errs := service.CreateDrugWarehousingInfo(warehousingInfo)
  207. info, _ := service.FindLastDrugWarehousingInfo(warehousing.WarehousingOrder)
  208. if errs != nil {
  209. utils.ErrorLog(errs.Error())
  210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  211. return
  212. }
  213. c.ServeSuccessJSON(map[string]interface{}{
  214. "msg": "入库成功",
  215. "warehousing_order": warehousing_order,
  216. "info": info,
  217. })
  218. //}
  219. //else {
  220. // warehouse, err1 := service.FindWareHouseByOrderNumber(warehousing_order)
  221. // if (err1 != nil) {
  222. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  223. // return
  224. // }
  225. //
  226. // dataBody := make(map[string]interface{}, 0)
  227. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  228. // if err != nil {
  229. // utils.ErrorLog(err.Error())
  230. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. // return
  232. // }
  233. //
  234. // var warehousingInfo []*models.WarehousingInfo
  235. //
  236. // if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  237. // thisStockIn, _ := dataBody["stockIn"].([]interface{})
  238. // if len(thisStockIn) > 0 {
  239. // for _, item := range thisStockIn {
  240. // items := item.(map[string]interface{})
  241. //
  242. // if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  243. // utils.ErrorLog("good_id")
  244. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  245. // return
  246. // }
  247. // good_id := int64(items["good_id"].(float64))
  248. //
  249. // if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  250. // utils.ErrorLog("good_type_id")
  251. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  252. // return
  253. // }
  254. // good_type_id := int64(items["good_type_id"].(float64))
  255. //
  256. // if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  257. // utils.ErrorLog("warehousing_count")
  258. // c.ServeFailJSONWithSGJErrorCod Fe(enums.ErrorCodeParamWrong)
  259. // return
  260. // }
  261. //
  262. // warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  263. //
  264. // if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  265. // utils.ErrorLog("price")
  266. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  267. // return
  268. // }
  269. // price, _ := strconv.ParseFloat(items["price"].(string), 64)
  270. // total := float64(warehousing_count) * price
  271. //
  272. // if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  273. // utils.ErrorLog("expiry_date")
  274. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  275. // return
  276. // }
  277. //
  278. // expiryDate, _ := items["expiry_date"].(string)
  279. // if len(expiryDate) == 0 {
  280. // utils.ErrorLog("len(expiry_date) == 0")
  281. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  282. //
  283. // return
  284. // }
  285. //
  286. // expiry_date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  287. // if parseDateErr != nil {
  288. // c.ErrorLog("日期(%v)解析错误:%v", expiry_date, parseDateErr)
  289. // }
  290. //
  291. // var productDates int64
  292. //
  293. // if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  294. // productDates = 0;
  295. // } else {
  296. // productDate, _ := items["product_date"].(string)
  297. // product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  298. // productDates = product_date.Unix()
  299. //
  300. // }
  301. //
  302. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  303. // utils.ErrorLog("number")
  304. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  305. // return
  306. // }
  307. // number, _ := items["number"].(string)
  308. //
  309. // var remark string
  310. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  311. // remark = ""
  312. // } else {
  313. // remark = items["remark"].(string)
  314. // }
  315. //
  316. // warehouseInfo := &models.WarehousingInfo{
  317. // WarehousingOrder: warehousing_order,
  318. // WarehousingId: warehouse.ID,
  319. // GoodId: good_id,
  320. // Number: number,
  321. // GoodTypeId: good_type_id,
  322. // ProductDate: productDates,
  323. // ExpiryDate: expiry_date.Unix(),
  324. // WarehousingCount: warehousing_count,
  325. // Price: price,
  326. // TotalPrice: total,
  327. // Status: 1,
  328. // Ctime: ctime,
  329. // Remark: remark,
  330. // OrgId: adminUserInfo.CurrentOrgId,
  331. // }
  332. // warehousingInfo = append(warehousingInfo, warehouseInfo)
  333. //
  334. // }
  335. // }
  336. // }
  337. // errs := service.CreateWarehousingInfo(warehousingInfo)
  338. // info, _ := service.FindLastWarehousingInfo(warehousing_order)
  339. //
  340. // if (errs != nil) {
  341. // utils.ErrorLog(errs.Error())
  342. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  343. // return
  344. // }
  345. //
  346. // c.ServeSuccessJSON(map[string]interface{}{
  347. // "msg": "入库成功",
  348. // "info": info,
  349. // })
  350. //
  351. //}
  352. }
  353. func (c *StockDrugApiController) GetDrugWarehouseList() {
  354. page, _ := c.GetInt64("page", -1)
  355. limit, _ := c.GetInt64("limit", -1)
  356. start_time := c.GetString("start_time")
  357. end_time := c.GetString("end_time")
  358. types, _ := c.GetInt64("type", 0)
  359. keywords := c.GetString("keywords")
  360. fmt.Println(start_time)
  361. fmt.Println(end_time)
  362. timeLayout := "2006-01-02"
  363. loc, _ := time.LoadLocation("Local")
  364. var startTime int64
  365. if len(start_time) > 0 {
  366. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  367. if err != nil {
  368. fmt.Println(err)
  369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  370. return
  371. }
  372. startTime = theTime.Unix()
  373. }
  374. var endTime int64
  375. if len(end_time) > 0 {
  376. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  377. if err != nil {
  378. utils.ErrorLog(err.Error())
  379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  380. return
  381. }
  382. endTime = theTime.Unix()
  383. }
  384. adminUserInfo := c.GetAdminUserInfo()
  385. warehouseList, total, err := service.FindAllDrugWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  386. if err == nil {
  387. c.ServeSuccessJSON(map[string]interface{}{
  388. "list": warehouseList,
  389. "total": total,
  390. })
  391. } else {
  392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  393. }
  394. }
  395. func (c *StockDrugApiController) GetDrugWarehouseInfoList() {
  396. id, _ := c.GetInt64("id", 0)
  397. if id <= 0 {
  398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  399. return
  400. }
  401. admin := c.GetAdminUserInfo()
  402. warehousing, err := service.FindDrugWarehousingById(id, admin.CurrentOrgId)
  403. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  404. if err != nil {
  405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  406. return
  407. }
  408. if warehousing.ID <= 0 {
  409. return
  410. }
  411. warehousingInfo, err := service.FindDrugWarehousingInfoById(id, admin.CurrentOrgId)
  412. fmt.Println("warehousinginfo000000000000000", warehousingInfo)
  413. if err == nil {
  414. c.ServeSuccessJSON(map[string]interface{}{
  415. "info": warehousingInfo,
  416. "warehousing": warehousing,
  417. "manufacturerList": manufacturerList,
  418. })
  419. } else {
  420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  421. }
  422. }
  423. func (c *StockDrugApiController) EditDrugWarehouse() {
  424. warehousing_time := c.GetString("warehousing_time")
  425. id, _ := c.GetInt64("id", 0)
  426. types, _ := c.GetInt64("type", 0)
  427. //manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  428. //dealer_id, _ := c.GetInt64("dealer_id", 0)
  429. if id == 0 {
  430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  431. return
  432. }
  433. ctime := time.Now().Unix()
  434. mtime := time.Now().Unix()
  435. adminUserInfo := c.GetAdminUserInfo()
  436. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  437. if parseDateErr != nil {
  438. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  440. return
  441. }
  442. warehouse, _ := service.FindDrugWarehousingById(id, adminUserInfo.CurrentOrgId)
  443. warehousing := models.DrugWarehouse{
  444. WarehousingOrder: warehouse.WarehousingOrder,
  445. OrgId: adminUserInfo.CurrentOrgId,
  446. Modifier: adminUserInfo.AdminUser.Id,
  447. Mtime: mtime,
  448. Status: 1,
  449. WarehousingTime: warehousingDate.Unix(),
  450. Type: warehouse.Type,
  451. //Dealer: dealer_id,
  452. //Manufacturer: manufacturer_id,
  453. }
  454. service.EditDrugWarehousingOne(warehousing, id)
  455. dataBody := make(map[string]interface{}, 0)
  456. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  457. if err != nil {
  458. utils.ErrorLog(err.Error())
  459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  460. return
  461. }
  462. var warehousingInfo []*models.DrugWarehouseInfo
  463. var upDateWarehousingInfo []*models.DrugWarehouseInfo
  464. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  465. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  466. if len(thisStockIn) > 0 {
  467. for _, item := range thisStockIn {
  468. items := item.(map[string]interface{})
  469. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  470. utils.ErrorLog("drug_id")
  471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  472. return
  473. }
  474. drug_id := int64(items["drug_id"].(float64))
  475. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  476. utils.ErrorLog("warehousing_count")
  477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  478. return
  479. }
  480. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  481. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  482. utils.ErrorLog("price")
  483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  484. return
  485. }
  486. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  487. total := float64(warehousing_count) * price
  488. //if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  489. // utils.ErrorLog("retail_price")
  490. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  491. // return
  492. //}
  493. //retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  494. //retail_price_total := float64(warehousing_count) * last_price
  495. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  496. utils.ErrorLog("last_price")
  497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  498. return
  499. }
  500. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  501. retail_price_total := float64(warehousing_count) * last_price
  502. var productDates int64
  503. var expiryDates int64
  504. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  505. expiryDates = 0
  506. } else {
  507. if len(items["expiry_date"].(string)) == 0 {
  508. expiryDates = 0
  509. } else {
  510. expiryDate, _ := items["expiry_date"].(string)
  511. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  512. expiryDates = expiry_date.Unix()
  513. }
  514. }
  515. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  516. productDates = 0
  517. } else {
  518. if len(items["product_date"].(string)) == 0 {
  519. productDates = 0
  520. } else {
  521. productDate, _ := items["product_date"].(string)
  522. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  523. productDates = product_date.Unix()
  524. }
  525. }
  526. if items["lot_number"] == nil || reflect.TypeOf(items["lot_number"]).String() != "string" {
  527. utils.ErrorLog("lot_number")
  528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  529. return
  530. }
  531. number, _ := items["lot_number"].(string)
  532. batch_number, _ := items["batch_number"].(string)
  533. max_unit, _ := items["max_unit"].(string)
  534. min_unit, _ := items["min_unit"].(string)
  535. var remark string
  536. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  537. remark = ""
  538. } else {
  539. remark = items["remark"].(string)
  540. }
  541. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  542. utils.ErrorLog("id")
  543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  544. return
  545. }
  546. id := int64(items["id"].(float64))
  547. //if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "float64" {
  548. // utils.ErrorLog("dealer")
  549. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  550. // return
  551. //}
  552. //dealer := int64(items["dealer"].(float64))
  553. //
  554. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "float64" {
  555. utils.ErrorLog("manufacturer")
  556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  557. return
  558. }
  559. manufacturer := int64(items["manufacturer"].(float64))
  560. if id == 0 {
  561. warehouseInfo := &models.DrugWarehouseInfo{
  562. WarehousingOrder: warehouse.WarehousingOrder,
  563. WarehousingId: warehouse.ID,
  564. DrugId: drug_id,
  565. Number: number,
  566. ProductDate: productDates,
  567. ExpiryDate: expiryDates,
  568. WarehousingCount: warehousing_count,
  569. Price: price,
  570. TotalPrice: total,
  571. Status: 1,
  572. Ctime: ctime,
  573. Remark: remark,
  574. OrgId: adminUserInfo.CurrentOrgId,
  575. Type: types,
  576. Manufacturer: manufacturer,
  577. //Dealer: dealer,
  578. RetailPrice: last_price,
  579. RetailTotalPrice: retail_price_total,
  580. BatchNumber: batch_number,
  581. MaxUnit: max_unit,
  582. MinUnit: min_unit,
  583. }
  584. warehousingInfo = append(warehousingInfo, warehouseInfo)
  585. } else {
  586. warehouseInfo := &models.DrugWarehouseInfo{
  587. ID: id,
  588. WarehousingOrder: warehouse.WarehousingOrder,
  589. WarehousingId: warehouse.ID,
  590. DrugId: drug_id,
  591. Number: number,
  592. ProductDate: productDates,
  593. ExpiryDate: expiryDates,
  594. WarehousingCount: warehousing_count,
  595. Price: price,
  596. TotalPrice: total,
  597. Status: 1,
  598. Ctime: ctime,
  599. Remark: remark,
  600. OrgId: adminUserInfo.CurrentOrgId,
  601. Type: types,
  602. Manufacturer: manufacturer,
  603. //Dealer: dealer,
  604. RetailPrice: last_price,
  605. RetailTotalPrice: retail_price_total,
  606. StockMaxNumber: warehousing_count,
  607. MaxUnit: max_unit,
  608. MinUnit: min_unit,
  609. }
  610. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  611. }
  612. }
  613. }
  614. }
  615. var errs error
  616. if len(warehousingInfo) > 0 {
  617. errs = service.CreateDrugWarehousingInfo(warehousingInfo)
  618. }
  619. if len(upDateWarehousingInfo) > 0 {
  620. for _, item := range upDateWarehousingInfo {
  621. errs = service.UpDateDrugWarehousingInfo(item)
  622. }
  623. }
  624. if errs != nil {
  625. utils.ErrorLog(errs.Error())
  626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  627. return
  628. }
  629. c.ServeSuccessJSON(map[string]interface{}{
  630. "msg": "编辑成功",
  631. })
  632. }
  633. func (c *StockDrugApiController) DeleteDrugWarehouse() {
  634. ids := c.GetString("ids")
  635. if len(ids) == 0 {
  636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  637. return
  638. }
  639. idArray := strings.Split(ids, ",")
  640. err := service.DeleteDrugWarehouse(idArray)
  641. if err != nil {
  642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  643. } else {
  644. c.ServeSuccessJSON(map[string]interface{}{
  645. "msg": "删除成功",
  646. })
  647. }
  648. }
  649. func (c *StockDrugApiController) DeleteDrugWarehouseInfo() {
  650. id, _ := c.GetInt64("id", 0)
  651. if id == 0 {
  652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  653. return
  654. }
  655. err := service.UpDateDrugWarehouseStatus(id)
  656. if err != nil {
  657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  658. } else {
  659. c.ServeSuccessJSON(map[string]interface{}{
  660. "msg": "删除成功",
  661. })
  662. }
  663. }
  664. func (c *StockDrugApiController) CreateDrugSalesReturn() {
  665. dealer_id, _ := c.GetInt64("dealer_id", 0)
  666. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  667. sales_return_time := c.GetString("time")
  668. types, _ := c.GetInt64("type", 0)
  669. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  670. if parseDateErr != nil {
  671. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  673. return
  674. }
  675. adminUserInfo := c.GetAdminUserInfo()
  676. operation_time := time.Now().Unix()
  677. creater := adminUserInfo.AdminUser.Id
  678. ctime := time.Now().Unix()
  679. timeStr := time.Now().Format("2006-01-02")
  680. timeArr := strings.Split(timeStr, "-")
  681. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  682. total = total + 1
  683. orderNumber := "YPTHD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  684. salesReturn := models.DrugSalesReturn{
  685. OrderNumber: orderNumber,
  686. OperaTime: operation_time,
  687. OrgId: adminUserInfo.CurrentOrgId,
  688. Creater: creater,
  689. Ctime: ctime,
  690. Status: 1,
  691. ReturnTime: salesReturnDate.Unix(),
  692. Dealer: dealer_id,
  693. Manufacturer: manufacturer_id,
  694. Type: types,
  695. }
  696. service.AddSigleDrugSalesReturn(&salesReturn)
  697. dataBody := make(map[string]interface{}, 0)
  698. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  699. if err != nil {
  700. utils.ErrorLog(err.Error())
  701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  702. return
  703. }
  704. var salesReturnInfos []*models.DrugSalesReturnInfo
  705. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  706. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  707. if len(thisStockIn) > 0 {
  708. for _, item := range thisStockIn {
  709. items := item.(map[string]interface{})
  710. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  711. utils.ErrorLog("drug_id")
  712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  713. return
  714. }
  715. drug_id := int64(items["drug_id"].(float64))
  716. return_count, _ := items["return_count"].(string)
  717. if len(return_count) == 0 {
  718. utils.ErrorLog("len(return_count) == 0")
  719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  720. return
  721. }
  722. count, _ := strconv.ParseInt(return_count, 10, 64)
  723. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  724. utils.ErrorLog("price")
  725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  726. return
  727. }
  728. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  729. total := float64(count) * price
  730. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  731. utils.ErrorLog("retail_price")
  732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  733. return
  734. }
  735. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  736. retail_price_total := float64(count) * retail_price
  737. salesReturnInfo := &models.DrugSalesReturnInfo{
  738. OrderNumber: salesReturn.OrderNumber,
  739. SalesReturnId: salesReturn.ID,
  740. DrugId: drug_id,
  741. Count: count,
  742. Price: price,
  743. Total: total,
  744. Status: 1,
  745. Ctime: ctime,
  746. OrgId: adminUserInfo.CurrentOrgId,
  747. Type: types,
  748. Manufacturer: manufacturer_id,
  749. Dealer: dealer_id,
  750. RetailPrice: retail_price,
  751. RetailTotalPrice: retail_price_total,
  752. }
  753. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  754. }
  755. }
  756. }
  757. errs := service.CreateDrugSalesReturnInfo(salesReturnInfos)
  758. if errs != nil {
  759. utils.ErrorLog(errs.Error())
  760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateReturnFail)
  761. return
  762. }
  763. c.ServeSuccessJSON(map[string]interface{}{
  764. "msg": "退货成功",
  765. })
  766. }
  767. func (c *StockDrugApiController) GetDrugSalesReturnList() {
  768. page, _ := c.GetInt64("page", -1)
  769. limit, _ := c.GetInt64("limit", -1)
  770. start_time := c.GetString("start_time")
  771. end_time := c.GetString("end_time")
  772. types, _ := c.GetInt64("type", 0)
  773. keywords := c.GetString("keywords")
  774. timeLayout := "2006-01-02"
  775. loc, _ := time.LoadLocation("Local")
  776. var startTime int64
  777. if len(start_time) > 0 {
  778. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  779. if err != nil {
  780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  781. return
  782. }
  783. startTime = theTime.Unix()
  784. }
  785. var endTime int64
  786. if len(end_time) > 0 {
  787. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  788. if err != nil {
  789. utils.ErrorLog(err.Error())
  790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  791. return
  792. }
  793. endTime = theTime.Unix()
  794. }
  795. adminUserInfo := c.GetAdminUserInfo()
  796. returnList, total, err := service.FindAllDrugReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  797. if err == nil {
  798. c.ServeSuccessJSON(map[string]interface{}{
  799. "list": returnList,
  800. "total": total,
  801. })
  802. } else {
  803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  804. }
  805. }
  806. func (this *StockDrugApiController) DeleteDrugSalesReturn() {
  807. ids := this.GetString("ids")
  808. if len(ids) == 0 {
  809. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  810. return
  811. }
  812. idArray := strings.Split(ids, ",")
  813. err := service.DeleteDrugSalesReturn(idArray)
  814. if err != nil {
  815. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  816. } else {
  817. this.ServeSuccessJSON(map[string]interface{}{
  818. "msg": "删除成功",
  819. })
  820. }
  821. }
  822. func (this *StockDrugApiController) DeleteDrugSalesReturnInfo() {
  823. id, _ := this.GetInt64("id", 0)
  824. fmt.Println(id)
  825. if id == 0 {
  826. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  827. return
  828. }
  829. err := service.UpDateDrugSaleReturnStatus(id)
  830. if err != nil {
  831. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  832. } else {
  833. this.ServeSuccessJSON(map[string]interface{}{
  834. "msg": "删除成功",
  835. })
  836. }
  837. }
  838. func (this *StockDrugApiController) GetDrugSalesReturnInfoList() {
  839. id, _ := this.GetInt64("id", 0)
  840. adminUserInfo := this.GetAdminUserInfo()
  841. list, _ := service.FindAllDrugSalesReturnInfoById(id, adminUserInfo.CurrentOrgId)
  842. salesReturn, _ := service.FindAllDrugSalesReturnById(id, adminUserInfo.CurrentOrgId)
  843. this.ServeSuccessJSON(map[string]interface{}{
  844. "list": list,
  845. "salesReturn": salesReturn,
  846. })
  847. }
  848. func (c *StockDrugApiController) EditDrugReturnInfo() {
  849. return_time := c.GetString("return_time")
  850. id, _ := c.GetInt64("id", 0)
  851. types, _ := c.GetInt64("type", 0)
  852. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  853. dealer_id, _ := c.GetInt64("dealer_id", 0)
  854. if id == 0 {
  855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  856. return
  857. }
  858. ctime := time.Now().Unix()
  859. mtime := time.Now().Unix()
  860. adminUserInfo := c.GetAdminUserInfo()
  861. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  862. if parseDateErr != nil {
  863. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  865. return
  866. }
  867. salesReturns, _ := service.FindDrugSalesReturnById(id)
  868. sales := models.DrugSalesReturn{
  869. ID: salesReturns.ID,
  870. Mtime: mtime,
  871. ReturnTime: returnDate.Unix(),
  872. Manufacturer: manufacturer_id,
  873. Dealer: dealer_id,
  874. }
  875. service.EditDrugSaleReturn(sales)
  876. dataBody := make(map[string]interface{}, 0)
  877. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  878. if err != nil {
  879. utils.ErrorLog(err.Error())
  880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  881. return
  882. }
  883. var returnInfos []*models.DrugSalesReturnInfo
  884. var upDateReturnInfos []*models.DrugSalesReturnInfo
  885. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  886. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  887. if len(thisStockIn) > 0 {
  888. for _, item := range thisStockIn {
  889. items := item.(map[string]interface{})
  890. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  891. utils.ErrorLog("drug_id")
  892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  893. return
  894. }
  895. drug_id := int64(items["drug_id"].(float64))
  896. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  897. utils.ErrorLog("count")
  898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  899. return
  900. }
  901. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  902. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  903. utils.ErrorLog("id")
  904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  905. return
  906. }
  907. id := int64(items["id"].(float64))
  908. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  909. utils.ErrorLog("price")
  910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  911. return
  912. }
  913. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  914. total := float64(count) * price
  915. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  916. utils.ErrorLog("retail_price")
  917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  918. return
  919. }
  920. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  921. retail_price_total := float64(count) * retail_price
  922. if id == 0 {
  923. returnInfo := &models.DrugSalesReturnInfo{
  924. DrugId: drug_id,
  925. Count: count,
  926. Status: 1,
  927. Ctime: ctime,
  928. OrgId: adminUserInfo.CurrentOrgId,
  929. OrderNumber: sales.OrderNumber,
  930. SalesReturnId: sales.ID,
  931. Mtime: time.Now().Unix(),
  932. Type: types,
  933. Manufacturer: manufacturer_id,
  934. Dealer: dealer_id,
  935. RetailPrice: retail_price,
  936. RetailTotalPrice: retail_price_total,
  937. Total: total,
  938. Price: price,
  939. }
  940. returnInfos = append(returnInfos, returnInfo)
  941. } else {
  942. returnInfo := &models.DrugSalesReturnInfo{
  943. ID: id,
  944. DrugId: drug_id,
  945. Count: count,
  946. Status: 1,
  947. Ctime: ctime,
  948. OrgId: adminUserInfo.CurrentOrgId,
  949. OrderNumber: sales.OrderNumber,
  950. SalesReturnId: sales.ID,
  951. Mtime: time.Now().Unix(),
  952. Type: types,
  953. Manufacturer: manufacturer_id,
  954. Dealer: dealer_id,
  955. RetailPrice: retail_price,
  956. RetailTotalPrice: retail_price_total,
  957. Total: total,
  958. Price: price,
  959. }
  960. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  961. }
  962. }
  963. }
  964. }
  965. var errs error
  966. if len(returnInfos) > 0 {
  967. errs = service.CreateDrugSalesReturnInfo(returnInfos)
  968. }
  969. if len(upDateReturnInfos) > 0 {
  970. for _, item := range upDateReturnInfos {
  971. errs = service.UpDateDrugSalesReturnInfo(item)
  972. }
  973. }
  974. if errs != nil {
  975. utils.ErrorLog(errs.Error())
  976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateReturnFail)
  977. return
  978. }
  979. c.ServeSuccessJSON(map[string]interface{}{
  980. "msg": "编辑成功",
  981. })
  982. }
  983. func (c *StockDrugApiController) CreateDrugWarehouseOut() {
  984. dealer_id, _ := c.GetInt64("dealer_id", 0)
  985. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  986. types, _ := c.GetInt64("type", 0)
  987. ctime := time.Now().Unix()
  988. adminUserInfo := c.GetAdminUserInfo()
  989. warehousing_out_time := c.GetString("warehousing_out_time")
  990. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  991. if parseDateErr != nil {
  992. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  994. return
  995. }
  996. timeStr := time.Now().Format("2006-01-02")
  997. timeArr := strings.Split(timeStr, "-")
  998. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  999. total = total + 1
  1000. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1001. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1002. number = number + total
  1003. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1004. operation_time := time.Now().Unix()
  1005. creater := adminUserInfo.AdminUser.Id
  1006. warehouseOut := models.DrugWarehouseOut{
  1007. WarehouseOutOrderNumber: warehousing_out_order,
  1008. OperationTime: operation_time,
  1009. OrgId: adminUserInfo.CurrentOrgId,
  1010. Creater: creater,
  1011. Ctime: ctime,
  1012. Status: 1,
  1013. WarehouseOutTime: warehousingOutDate.Unix(),
  1014. Dealer: dealer_id,
  1015. Manufacturer: manufacturer_id,
  1016. Type: types,
  1017. }
  1018. service.AddSigleDrugWarehouseOut(&warehouseOut)
  1019. dataBody := make(map[string]interface{}, 0)
  1020. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1021. if err != nil {
  1022. utils.ErrorLog(err.Error())
  1023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1024. return
  1025. }
  1026. var warehousingOutInfo []*models.DrugWarehouseOutInfo
  1027. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1028. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  1029. if len(thisStockIn) > 0 {
  1030. for _, item := range thisStockIn {
  1031. items := item.(map[string]interface{})
  1032. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1033. utils.ErrorLog("drug_id")
  1034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1035. return
  1036. }
  1037. drug_id := int64(items["drug_id"].(float64))
  1038. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1039. utils.ErrorLog("count")
  1040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1041. return
  1042. }
  1043. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1044. utils.ErrorLog("price")
  1045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1046. return
  1047. }
  1048. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1049. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1050. utils.ErrorLog("last_price")
  1051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1052. return
  1053. }
  1054. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1055. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1056. total := float64(count) * price
  1057. retail_price_total := float64(count) * last_price
  1058. remark := items["remark"].(string)
  1059. max_unit := items["max_unit"].(string)
  1060. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1061. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1062. WarehouseOutId: warehouseOut.ID,
  1063. DrugId: drug_id,
  1064. Count: count,
  1065. Price: price,
  1066. TotalPrice: total,
  1067. Status: 1,
  1068. Ctime: ctime,
  1069. Remark: remark,
  1070. OrgId: adminUserInfo.CurrentOrgId,
  1071. Type: types,
  1072. Manufacturer: manufacturer_id,
  1073. Dealer: dealer_id,
  1074. RetailPrice: last_price,
  1075. RetailTotalPrice: retail_price_total,
  1076. CountUnit: max_unit,
  1077. }
  1078. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1079. }
  1080. }
  1081. }
  1082. //调用出库逻辑
  1083. //for _, item := range warehousingOutInfo {
  1084. //
  1085. // // 出库流程
  1086. // // 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
  1087. // drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
  1088. // if drup.ID > 0 {
  1089. // prescribingNumber := item.Count
  1090. //
  1091. // service.AutoDrugDeliverInfo(item.OrgId, prescribingNumber, &warehouseOut, &drup, item)
  1092. //
  1093. // }
  1094. //
  1095. //}
  1096. errs := service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
  1097. info, _ := service.FindLastDrugWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
  1098. if errs != nil {
  1099. utils.ErrorLog(errs.Error())
  1100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1101. return
  1102. }
  1103. c.ServeSuccessJSON(map[string]interface{}{
  1104. "info": info,
  1105. "msg": "出库成功",
  1106. "warehousing_out_order": warehousing_out_order,
  1107. })
  1108. }
  1109. func (c *StockDrugApiController) GetDrugWarehouseOutList() {
  1110. page, _ := c.GetInt64("page", -1)
  1111. limit, _ := c.GetInt64("limit", -1)
  1112. start_time := c.GetString("start_time")
  1113. end_time := c.GetString("end_time")
  1114. types, _ := c.GetInt64("type", 0)
  1115. keywords := c.GetString("keywords")
  1116. timeLayout := "2006-01-02"
  1117. loc, _ := time.LoadLocation("Local")
  1118. var startTime int64
  1119. if len(start_time) > 0 {
  1120. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1121. if err != nil {
  1122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1123. return
  1124. }
  1125. startTime = theTime.Unix()
  1126. }
  1127. var endTime int64
  1128. if len(end_time) > 0 {
  1129. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1130. if err != nil {
  1131. utils.ErrorLog(err.Error())
  1132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1133. return
  1134. }
  1135. endTime = theTime.Unix()
  1136. }
  1137. adminUserInfo := c.GetAdminUserInfo()
  1138. warehouseOutList, total, err := service.FindAllDrugWarehouseOutList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1139. fmt.Println(err)
  1140. if err == nil {
  1141. c.ServeSuccessJSON(map[string]interface{}{
  1142. "list": warehouseOutList,
  1143. "total": total,
  1144. })
  1145. } else {
  1146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1147. }
  1148. }
  1149. func (c *StockDrugApiController) DeleteDrugWarehouseOut() {
  1150. ids := c.GetString("ids")
  1151. if len(ids) == 0 {
  1152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1153. return
  1154. }
  1155. idArray := strings.Split(ids, ",")
  1156. err := service.DeleteDrugWarehouseOut(idArray)
  1157. if err != nil {
  1158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1159. } else {
  1160. c.ServeSuccessJSON(map[string]interface{}{
  1161. "msg": "删除成功",
  1162. })
  1163. }
  1164. }
  1165. func (this *StockDrugApiController) DeleteDrugWarehouseOutInfo() {
  1166. id, _ := this.GetInt64("id", 0)
  1167. fmt.Println(id)
  1168. if id == 0 {
  1169. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1170. return
  1171. }
  1172. err := service.UpDateDrugWarehouseOutStatus(id)
  1173. if err != nil {
  1174. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1175. } else {
  1176. this.ServeSuccessJSON(map[string]interface{}{
  1177. "msg": "删除成功",
  1178. })
  1179. }
  1180. }
  1181. func (c *StockDrugApiController) GetDrugWarehouseOutInfoList() {
  1182. id, _ := c.GetInt64("id", 0)
  1183. adminInfo := c.GetAdminUserInfo()
  1184. warehouseOutInfo, _ := service.FindDrugWarehouseOutInfoById(id, adminInfo.CurrentOrgId)
  1185. warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminInfo.CurrentOrgId)
  1186. manulist, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1187. c.ServeSuccessJSON(map[string]interface{}{
  1188. "list": warehouseOutInfo,
  1189. "info": warehouseOut,
  1190. "manulist": manulist,
  1191. })
  1192. }
  1193. func (c *StockDrugApiController) EditDrugWarehouseOut() {
  1194. warehouse_out_time := c.GetString("warehouse_out_time")
  1195. id, _ := c.GetInt64("id", 0)
  1196. types, _ := c.GetInt64("type", 0)
  1197. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1198. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1199. if id == 0 {
  1200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1201. return
  1202. }
  1203. ctime := time.Now().Unix()
  1204. mtime := time.Now().Unix()
  1205. adminUserInfo := c.GetAdminUserInfo()
  1206. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1207. if parseDateErr != nil {
  1208. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1210. return
  1211. }
  1212. warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminUserInfo.CurrentOrgId)
  1213. tempWarehouseOut := models.DrugWarehouseOut{
  1214. ID: warehouseOut.ID,
  1215. Mtime: mtime,
  1216. WarehouseOutTime: warehouseOutDate.Unix(),
  1217. Manufacturer: manufacturer_id,
  1218. Dealer: dealer_id,
  1219. }
  1220. service.EditDrugWarehouseOut(tempWarehouseOut)
  1221. dataBody := make(map[string]interface{}, 0)
  1222. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1223. if err != nil {
  1224. utils.ErrorLog(err.Error())
  1225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1226. return
  1227. }
  1228. var warehousingOutInfo []*models.DrugWarehouseOutInfo
  1229. var upDateWarehouseOutInfos []*models.DrugWarehouseOutInfo
  1230. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1231. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1232. if len(thisStockOut) > 0 {
  1233. for _, item := range thisStockOut {
  1234. items := item.(map[string]interface{})
  1235. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1236. utils.ErrorLog("drug_id")
  1237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1238. return
  1239. }
  1240. drug_id := int64(items["drug_id"].(float64))
  1241. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1242. utils.ErrorLog("count")
  1243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1244. return
  1245. }
  1246. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1247. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1248. utils.ErrorLog("price")
  1249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1250. return
  1251. }
  1252. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1253. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1254. utils.ErrorLog("retail_price")
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1256. return
  1257. }
  1258. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1259. total := float64(count) * price
  1260. retail_price_total := float64(count) * retail_price
  1261. remark := items["remark"].(string)
  1262. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1263. utils.ErrorLog("id")
  1264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1265. return
  1266. }
  1267. id := int64(items["id"].(float64))
  1268. if id == 0 {
  1269. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1270. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1271. WarehouseOutId: warehouseOut.ID,
  1272. DrugId: drug_id,
  1273. Count: count,
  1274. Price: price,
  1275. TotalPrice: total,
  1276. Status: 1,
  1277. Ctime: ctime,
  1278. Remark: remark,
  1279. OrgId: adminUserInfo.CurrentOrgId,
  1280. Type: types,
  1281. Manufacturer: manufacturer_id,
  1282. Dealer: dealer_id,
  1283. IsSys: 0,
  1284. SysRecordTime: 0,
  1285. RetailPrice: retail_price,
  1286. RetailTotalPrice: retail_price_total,
  1287. }
  1288. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1289. } else {
  1290. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1291. utils.ErrorLog("is_sys")
  1292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1293. return
  1294. }
  1295. is_sys := int64(items["is_sys"].(float64))
  1296. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1297. utils.ErrorLog("sys_record_time")
  1298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1299. return
  1300. }
  1301. sys_record_time := int64(items["sys_record_time"].(float64))
  1302. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1303. ID: id,
  1304. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1305. WarehouseOutId: warehouseOut.ID,
  1306. DrugId: drug_id,
  1307. Count: count,
  1308. Price: price,
  1309. TotalPrice: total,
  1310. Status: 1,
  1311. Ctime: ctime,
  1312. Remark: remark,
  1313. OrgId: adminUserInfo.CurrentOrgId,
  1314. Mtime: time.Now().Unix(),
  1315. Type: types,
  1316. Manufacturer: manufacturer_id,
  1317. Dealer: dealer_id,
  1318. IsSys: is_sys,
  1319. SysRecordTime: sys_record_time,
  1320. RetailPrice: retail_price,
  1321. RetailTotalPrice: retail_price_total,
  1322. }
  1323. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1324. }
  1325. }
  1326. }
  1327. }
  1328. var errs error
  1329. if len(warehousingOutInfo) > 0 {
  1330. errs = service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
  1331. }
  1332. if len(upDateWarehouseOutInfos) > 0 {
  1333. for _, item := range upDateWarehouseOutInfos {
  1334. errs = service.UpDateDrugWarehouseOutInfo(item)
  1335. }
  1336. }
  1337. if errs != nil {
  1338. utils.ErrorLog(errs.Error())
  1339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1340. return
  1341. }
  1342. c.ServeSuccessJSON(map[string]interface{}{
  1343. "msg": "编辑成功",
  1344. })
  1345. }
  1346. func (c *StockDrugApiController) CreateDrugCancelStock() {
  1347. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1348. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1349. cancel_stock_time := c.GetString("time")
  1350. types, _ := c.GetInt64("type", 0)
  1351. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1352. if parseDateErr != nil {
  1353. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1355. return
  1356. }
  1357. adminUserInfo := c.GetAdminUserInfo()
  1358. operation_time := time.Now().Unix()
  1359. creater := adminUserInfo.AdminUser.Id
  1360. ctime := time.Now().Unix()
  1361. timeStr := time.Now().Format("2006-01-02")
  1362. timeArr := strings.Split(timeStr, "-")
  1363. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1364. total = total + 1
  1365. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1366. cancelStock := models.DrugCancelStock{
  1367. OrderNumber: orderNumber,
  1368. OperaTime: operation_time,
  1369. OrgId: adminUserInfo.CurrentOrgId,
  1370. Creater: creater,
  1371. Ctime: ctime,
  1372. Status: 1,
  1373. ReturnTime: cancelStockDate.Unix(),
  1374. Dealer: dealer_id,
  1375. Manufacturer: manufacturer_id,
  1376. Type: types,
  1377. }
  1378. service.AddSigleDrugCancelStock(&cancelStock)
  1379. dataBody := make(map[string]interface{}, 0)
  1380. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1381. if err != nil {
  1382. utils.ErrorLog(err.Error())
  1383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1384. return
  1385. }
  1386. var cancelStockInfos []*models.DrugCancelStockInfo
  1387. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1388. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1389. if len(thisStockIn) > 0 {
  1390. for _, item := range thisStockIn {
  1391. items := item.(map[string]interface{})
  1392. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1393. utils.ErrorLog("drug_id")
  1394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1395. return
  1396. }
  1397. drug_id := int64(items["drug_id"].(float64))
  1398. return_count, _ := items["return_count"].(string)
  1399. if len(return_count) == 0 {
  1400. utils.ErrorLog("len(return_count) == 0")
  1401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1402. return
  1403. }
  1404. count, _ := strconv.ParseInt(return_count, 10, 64)
  1405. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1406. utils.ErrorLog("price")
  1407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1408. return
  1409. }
  1410. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1411. total := float64(count) * price
  1412. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1413. utils.ErrorLog("retail_price")
  1414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1415. return
  1416. }
  1417. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1418. retail_price_total := float64(count) * retail_price
  1419. cancelStockInfo := &models.DrugCancelStockInfo{
  1420. OrderNumber: cancelStock.OrderNumber,
  1421. CancelStockId: cancelStock.ID,
  1422. DrugId: drug_id,
  1423. Count: count,
  1424. Status: 1,
  1425. Ctime: ctime,
  1426. OrgId: adminUserInfo.CurrentOrgId,
  1427. Type: types,
  1428. Manufacturer: manufacturer_id,
  1429. Dealer: dealer_id,
  1430. Total: total,
  1431. RetailPrice: retail_price,
  1432. RetailTotalPrice: retail_price_total,
  1433. Price: price,
  1434. }
  1435. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1436. }
  1437. }
  1438. }
  1439. errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
  1440. if errs != nil {
  1441. utils.ErrorLog(errs.Error())
  1442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1443. return
  1444. }
  1445. c.ServeSuccessJSON(map[string]interface{}{
  1446. "msg": "退库成功",
  1447. })
  1448. }
  1449. func (c *StockDrugApiController) GetDrugCancelStockInfoList() {
  1450. id, _ := c.GetInt64("id", 0)
  1451. adminUserInfo := c.GetAdminUserInfo()
  1452. cancelStockInfoList, _ := service.FindDrugCancelStockInfoById(id, adminUserInfo.CurrentOrgId)
  1453. info, _ := service.FindCancelStockById(id, adminUserInfo.CurrentOrgId)
  1454. c.ServeSuccessJSON(map[string]interface{}{
  1455. "list": cancelStockInfoList,
  1456. "info": info,
  1457. })
  1458. }
  1459. func (c *StockDrugApiController) GetDrugCancelStockList() {
  1460. page, _ := c.GetInt64("page", -1)
  1461. limit, _ := c.GetInt64("limit", -1)
  1462. start_time := c.GetString("start_time")
  1463. end_time := c.GetString("end_time")
  1464. types, _ := c.GetInt64("type", 0)
  1465. keywords := c.GetString("keywords")
  1466. timeLayout := "2006-01-02"
  1467. loc, _ := time.LoadLocation("Local")
  1468. var startTime int64
  1469. if len(start_time) > 0 {
  1470. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1471. if err != nil {
  1472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1473. return
  1474. }
  1475. startTime = theTime.Unix()
  1476. }
  1477. var endTime int64
  1478. if len(end_time) > 0 {
  1479. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1480. if err != nil {
  1481. utils.ErrorLog(err.Error())
  1482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1483. return
  1484. }
  1485. endTime = theTime.Unix()
  1486. }
  1487. adminUserInfo := c.GetAdminUserInfo()
  1488. returnList, total, err := service.FindAllDrugCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1489. if err == nil {
  1490. c.ServeSuccessJSON(map[string]interface{}{
  1491. "list": returnList,
  1492. "total": total,
  1493. })
  1494. } else {
  1495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1496. }
  1497. }
  1498. func (this *StockDrugApiController) DeleteDrugCancelStock() {
  1499. ids := this.GetString("ids")
  1500. if len(ids) == 0 {
  1501. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1502. return
  1503. }
  1504. idArray := strings.Split(ids, ",")
  1505. err := service.DeleteDrugCancelStock(idArray)
  1506. if err != nil {
  1507. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1508. } else {
  1509. this.ServeSuccessJSON(map[string]interface{}{
  1510. "msg": "删除成功",
  1511. })
  1512. }
  1513. }
  1514. func (this *StockDrugApiController) DeleteDrugCancelStockInfo() {
  1515. id, _ := this.GetInt64("id", 0)
  1516. fmt.Println(id)
  1517. if id == 0 {
  1518. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1519. return
  1520. }
  1521. err := service.UpDateDrugCancleStockStatus(id)
  1522. if err != nil {
  1523. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1524. } else {
  1525. this.ServeSuccessJSON(map[string]interface{}{
  1526. "msg": "删除成功",
  1527. })
  1528. }
  1529. }
  1530. func (c *StockDrugApiController) EditDrugCancelStock() {
  1531. cancel_time := c.GetString("cancel_time")
  1532. id, _ := c.GetInt64("id", 0)
  1533. types, _ := c.GetInt64("type", 0)
  1534. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1535. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1536. if id == 0 {
  1537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1538. return
  1539. }
  1540. ctime := time.Now().Unix()
  1541. mtime := time.Now().Unix()
  1542. adminUserInfo := c.GetAdminUserInfo()
  1543. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  1544. if parseDateErr != nil {
  1545. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  1546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1547. return
  1548. }
  1549. cancelStock, _ := service.FindDrugCancelStockById(id)
  1550. tempCancelStock := models.DrugCancelStock{
  1551. ID: cancelStock.ID,
  1552. Mtime: mtime,
  1553. ReturnTime: cancelDate.Unix(),
  1554. Manufacturer: manufacturer_id,
  1555. Dealer: dealer_id,
  1556. }
  1557. service.EditDrugCancelStock(tempCancelStock)
  1558. dataBody := make(map[string]interface{}, 0)
  1559. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1560. if err != nil {
  1561. utils.ErrorLog(err.Error())
  1562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1563. return
  1564. }
  1565. var cancelStockInfos []*models.DrugCancelStockInfo
  1566. var upDateCancelStockInfos []*models.DrugCancelStockInfo
  1567. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1568. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  1569. if len(thisCancelStock) > 0 {
  1570. for _, item := range thisCancelStock {
  1571. items := item.(map[string]interface{})
  1572. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1573. utils.ErrorLog("drug_id")
  1574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1575. return
  1576. }
  1577. drug_id := int64(items["drug_id"].(float64))
  1578. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1579. utils.ErrorLog("count")
  1580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1581. return
  1582. }
  1583. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1584. //count, _ := strconv.ParseInt(return_count, 10, 64)
  1585. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1586. utils.ErrorLog("price")
  1587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1588. return
  1589. }
  1590. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1591. total := float64(count) * price
  1592. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1593. utils.ErrorLog("retail_price")
  1594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1595. return
  1596. }
  1597. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1598. retail_price_total := float64(count) * retail_price
  1599. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1600. utils.ErrorLog("id")
  1601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1602. return
  1603. }
  1604. id := int64(items["id"].(float64))
  1605. if id == 0 {
  1606. cancelStockInfo := &models.DrugCancelStockInfo{
  1607. DrugId: drug_id,
  1608. Count: count,
  1609. Status: 1,
  1610. Ctime: ctime,
  1611. OrgId: adminUserInfo.CurrentOrgId,
  1612. OrderNumber: cancelStock.OrderNumber,
  1613. CancelStockId: cancelStock.ID,
  1614. Mtime: time.Now().Unix(),
  1615. Type: types,
  1616. Manufacturer: manufacturer_id,
  1617. Dealer: dealer_id,
  1618. RetailPrice: retail_price,
  1619. RetailTotalPrice: retail_price_total,
  1620. Price: price,
  1621. Total: total,
  1622. }
  1623. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1624. } else {
  1625. cancelStockInfo := &models.DrugCancelStockInfo{
  1626. ID: id,
  1627. DrugId: drug_id,
  1628. Count: count,
  1629. Status: 1,
  1630. Ctime: ctime,
  1631. OrgId: adminUserInfo.CurrentOrgId,
  1632. OrderNumber: cancelStock.OrderNumber,
  1633. CancelStockId: cancelStock.ID,
  1634. Mtime: time.Now().Unix(),
  1635. Type: types,
  1636. Manufacturer: manufacturer_id,
  1637. Dealer: dealer_id,
  1638. RetailPrice: retail_price,
  1639. RetailTotalPrice: retail_price_total,
  1640. Price: price,
  1641. Total: total,
  1642. }
  1643. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  1644. }
  1645. }
  1646. }
  1647. }
  1648. var errs error
  1649. if len(cancelStockInfos) > 0 {
  1650. errs = service.CreateDrugCancelStockInfo(cancelStockInfos)
  1651. }
  1652. if len(upDateCancelStockInfos) > 0 {
  1653. for _, item := range upDateCancelStockInfos {
  1654. errs = service.UpDateDrugCancelStockInfo(item)
  1655. }
  1656. }
  1657. if errs != nil {
  1658. utils.ErrorLog(errs.Error())
  1659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateCancelStockFail)
  1660. return
  1661. }
  1662. c.ServeSuccessJSON(map[string]interface{}{
  1663. "msg": "编辑成功",
  1664. })
  1665. }
  1666. func (c *StockDrugApiController) GetAllConfig() {
  1667. adminUserInfo := c.GetAdminUserInfo()
  1668. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  1669. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  1670. stockIns, _ := service.FindStockInNumber(adminUserInfo.CurrentOrgId)
  1671. drugs, _ := service.GetDrugs(adminUserInfo.CurrentOrgId)
  1672. c.ServeSuccessJSON(map[string]interface{}{
  1673. "manufacturer": manufacturer,
  1674. "dealer": dealer,
  1675. "drugs": drugs,
  1676. "numbers": stockIns,
  1677. })
  1678. }
  1679. func (c *StockDrugApiController) GetAllDrugStock() {
  1680. adminUserInfo := c.GetAdminUserInfo()
  1681. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1682. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1683. drugs, err := service.FindAllDrugByManufactureId(manufacturer_id, dealer_id, adminUserInfo.CurrentOrgId)
  1684. if err == nil {
  1685. c.ServeSuccessJSON(map[string]interface{}{
  1686. "drugs": drugs,
  1687. })
  1688. } else {
  1689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1690. }
  1691. }
  1692. func (c *StockDrugApiController) GetDrugQueryInfo() {
  1693. page, _ := c.GetInt64("page", -1)
  1694. limit, _ := c.GetInt64("limit", -1)
  1695. keyword := c.GetString("keyword")
  1696. drug_category, _ := c.GetInt64("drug_category")
  1697. start_time := c.GetString("start_time")
  1698. end_time := c.GetString("end_time")
  1699. timeLayout := "2006-01-02"
  1700. loc, _ := time.LoadLocation("Local")
  1701. var startTime int64
  1702. if len(start_time) > 0 {
  1703. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1704. if err != nil {
  1705. fmt.Println(err)
  1706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1707. return
  1708. }
  1709. startTime = theTime.Unix()
  1710. }
  1711. var endTime int64
  1712. if len(end_time) > 0 {
  1713. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1714. if err != nil {
  1715. utils.ErrorLog(err.Error())
  1716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1717. return
  1718. }
  1719. endTime = theTime.Unix()
  1720. }
  1721. adminUserInfo := c.GetAdminUserInfo()
  1722. list, total, err := service.FindAllDrugStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, drug_category, startTime, endTime)
  1723. if err == nil {
  1724. c.ServeSuccessJSON(map[string]interface{}{
  1725. "list": list,
  1726. "total": total,
  1727. })
  1728. } else {
  1729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1730. }
  1731. }
  1732. func (this *StockDrugApiController) GetUserDetailInfo() {
  1733. order_id, _ := this.GetInt64("id")
  1734. if order_id <= 0 {
  1735. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1736. return
  1737. }
  1738. adminUserInfo := this.GetAdminUserInfo()
  1739. userDetails, err, total := service.FindDrugStockUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  1740. if err == nil {
  1741. this.ServeSuccessJSON(map[string]interface{}{
  1742. "list": userDetails,
  1743. "total": total,
  1744. })
  1745. } else {
  1746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1747. return
  1748. }
  1749. }