drug_stock_api_contorller.go 73KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329
  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. beego.Router("/api/drug/getcanceldrugorderprint", &StockDrugApiController{}, "get:GetCancelDrugOrderPrint")
  60. beego.Router("/api/drug/drugcancelexportlist", &StockDrugApiController{}, "get:GetDrugCancelExportList")
  61. }
  62. func (c *StockDrugApiController) CreateDrugWarehouse() {
  63. warehousing_time := c.GetString("warehousing_time")
  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.FindAllWarehouseTotalOne(adminUserInfo.CurrentOrgId)
  76. total = total + 1
  77. fmt.Println("total2323232323232", total)
  78. warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  79. fmt.Println("r入库单据好 2323232322223", warehousing_order)
  80. operation_time := time.Now().Unix()
  81. creater := adminUserInfo.AdminUser.Id
  82. warehousing := models.DrugWarehouse{
  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. 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. var drugFlow []*models.DrugFlow
  102. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  103. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  104. if len(thisStockIn) > 0 {
  105. for _, item := range thisStockIn {
  106. items := item.(map[string]interface{})
  107. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  108. utils.ErrorLog("drug_id")
  109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  110. return
  111. }
  112. drug_id := int64(items["drug_id"].(float64))
  113. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  114. utils.ErrorLog("warehousing_count")
  115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  116. return
  117. }
  118. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  119. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  120. utils.ErrorLog("last_price")
  121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  122. return
  123. }
  124. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  125. total := float64(warehousing_count) * last_price
  126. retail_price_total := float64(warehousing_count) * last_price
  127. var productDates int64
  128. var expiryDates int64
  129. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  130. expiryDates = 0
  131. } else {
  132. if len(items["expiry_date"].(string)) == 0 {
  133. expiryDates = 0
  134. } else {
  135. expiryDate, _ := items["expiry_date"].(string)
  136. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  137. expiryDates = expiry_date.Unix()
  138. }
  139. }
  140. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  141. productDates = 0
  142. } else {
  143. if len(items["product_date"].(string)) == 0 {
  144. productDates = 0
  145. } else {
  146. productDate, _ := items["product_date"].(string)
  147. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  148. productDates = product_date.Unix()
  149. }
  150. }
  151. number, _ := items["number"].(string)
  152. batch_number, _ := items["batch_number"].(string)
  153. if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
  154. utils.ErrorLog("max_unit")
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  156. return
  157. }
  158. max_unit, _ := items["max_unit"].(string)
  159. if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
  160. utils.ErrorLog("min_unit")
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  162. return
  163. }
  164. min_unit, _ := items["min_unit"].(string)
  165. var remark string
  166. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  167. remark = ""
  168. } else {
  169. remark = items["remark"].(string)
  170. }
  171. manufacturer := int64(items["manufacturer"].(float64))
  172. dealer := int64(items["dealer"].(float64))
  173. warehouseInfo := &models.DrugWarehouseInfo{
  174. WarehousingOrder: warehousing.WarehousingOrder,
  175. WarehousingId: warehousing.ID,
  176. DrugId: drug_id,
  177. Number: number,
  178. ProductDate: productDates,
  179. ExpiryDate: expiryDates,
  180. WarehousingCount: warehousing_count,
  181. Price: last_price,
  182. TotalPrice: total,
  183. Status: 1,
  184. Ctime: ctime,
  185. Remark: remark,
  186. OrgId: adminUserInfo.CurrentOrgId,
  187. Type: types,
  188. Manufacturer: manufacturer,
  189. Dealer: dealer,
  190. StockMaxNumber: warehousing_count,
  191. RetailTotalPrice: retail_price_total,
  192. BatchNumber: batch_number,
  193. MaxUnit: max_unit,
  194. MinUnit: min_unit,
  195. }
  196. warehousingInfo = append(warehousingInfo, warehouseInfo)
  197. drugflow := &models.DrugFlow{
  198. WarehousingOrder: warehousing.WarehousingOrder,
  199. WarehousingId: warehousing.ID,
  200. DrugId: drug_id,
  201. Number: number,
  202. ProductDate: productDates,
  203. ExpireDate: expiryDates,
  204. Count: warehousing_count,
  205. Price: last_price,
  206. Status: 1,
  207. Ctime: ctime,
  208. UserOrgId: adminUserInfo.CurrentOrgId,
  209. Manufacturer: manufacturer,
  210. Dealer: dealer,
  211. BatchNumber: batch_number,
  212. MaxUnit: max_unit,
  213. MinUnit: min_unit,
  214. ConsumableType: 1,
  215. IsEdit: 1,
  216. Creator: adminUserInfo.AdminUser.Id,
  217. IsSys: 0,
  218. }
  219. drugFlow = append(drugFlow, drugflow)
  220. }
  221. }
  222. }
  223. //创建入库单
  224. errs := service.CreateDrugWarehousingInfo(warehousingInfo)
  225. if errs == nil {
  226. //更改库存
  227. service.UpdateDrugInfo(warehousingInfo)
  228. }
  229. //创建流水单
  230. service.CreateDrugFlow(drugFlow)
  231. info, _ := service.FindLastDrugWarehousingInfo(warehousing.WarehousingOrder)
  232. if errs != nil {
  233. utils.ErrorLog(errs.Error())
  234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  235. return
  236. }
  237. c.ServeSuccessJSON(map[string]interface{}{
  238. "msg": "入库成功",
  239. "warehousing_order": warehousing_order,
  240. "info": info,
  241. })
  242. }
  243. func (c *StockDrugApiController) GetDrugWarehouseList() {
  244. page, _ := c.GetInt64("page", -1)
  245. limit, _ := c.GetInt64("limit", -1)
  246. start_time := c.GetString("start_time")
  247. end_time := c.GetString("end_time")
  248. types, _ := c.GetInt64("type", 0)
  249. keywords := c.GetString("keywords")
  250. timeLayout := "2006-01-02"
  251. loc, _ := time.LoadLocation("Local")
  252. var startTime int64
  253. if len(start_time) > 0 {
  254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  255. if err != nil {
  256. fmt.Println(err)
  257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  258. return
  259. }
  260. startTime = theTime.Unix()
  261. }
  262. var endTime int64
  263. if len(end_time) > 0 {
  264. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  265. if err != nil {
  266. utils.ErrorLog(err.Error())
  267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  268. return
  269. }
  270. endTime = theTime.Unix()
  271. }
  272. adminUserInfo := c.GetAdminUserInfo()
  273. fmt.Println("hhh2h3h23h2h32h3h2h32h32h3h2h3", keywords)
  274. //按药品名称搜索
  275. var ids []int64
  276. var idArray []int64
  277. list, _ := service.GetDrugNameByKeyword(keywords, adminUserInfo.CurrentOrgId)
  278. for _, item := range list {
  279. ids = append(ids, item.ID)
  280. }
  281. //查找入库单详情
  282. if len(ids) > 0 {
  283. info, _ := service.GetDrugWarehouseOrderDetailTwo(ids, adminUserInfo.CurrentOrgId, startTime, endTime)
  284. for _, it := range info {
  285. idArray = append(idArray, it.WarehousingId)
  286. }
  287. }
  288. warehouseList, total, err := service.FindAllDrugWarehousingListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, idArray)
  289. if err == nil {
  290. c.ServeSuccessJSON(map[string]interface{}{
  291. "list": warehouseList,
  292. "total": total,
  293. })
  294. } else {
  295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  296. }
  297. }
  298. func (c *StockDrugApiController) GetDrugWarehouseInfoList() {
  299. id, _ := c.GetInt64("id", 0)
  300. if id <= 0 {
  301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  302. return
  303. }
  304. admin := c.GetAdminUserInfo()
  305. warehousing, err := service.FindDrugWarehousingById(id, admin.CurrentOrgId)
  306. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  307. dealerList, _ := service.GetAllDealerList(admin.CurrentOrgId)
  308. if err != nil {
  309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  310. return
  311. }
  312. if warehousing.ID <= 0 {
  313. return
  314. }
  315. warehousingInfo, err := service.FindDrugWarehousingInfoById(id, admin.CurrentOrgId)
  316. fmt.Println("warehousinginfo000000000000000", warehousingInfo)
  317. if err == nil {
  318. c.ServeSuccessJSON(map[string]interface{}{
  319. "info": warehousingInfo,
  320. "warehousing": warehousing,
  321. "manufacturerList": manufacturerList,
  322. "dealerList": dealerList,
  323. })
  324. } else {
  325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  326. }
  327. }
  328. func (c *StockDrugApiController) EditDrugWarehouse() {
  329. warehousing_time := c.GetString("warehousing_time")
  330. id, _ := c.GetInt64("id", 0)
  331. types, _ := c.GetInt64("type", 0)
  332. if id == 0 {
  333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  334. return
  335. }
  336. ctime := time.Now().Unix()
  337. mtime := time.Now().Unix()
  338. adminUserInfo := c.GetAdminUserInfo()
  339. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  340. if parseDateErr != nil {
  341. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  343. return
  344. }
  345. warehouse, _ := service.FindDrugWarehousingById(id, adminUserInfo.CurrentOrgId)
  346. warehousing := models.DrugWarehouse{
  347. WarehousingOrder: warehouse.WarehousingOrder,
  348. OrgId: adminUserInfo.CurrentOrgId,
  349. Modifier: adminUserInfo.AdminUser.Id,
  350. Mtime: mtime,
  351. Status: 1,
  352. WarehousingTime: warehousingDate.Unix(),
  353. Type: warehouse.Type,
  354. }
  355. service.EditDrugWarehousingOne(warehousing, id)
  356. dataBody := make(map[string]interface{}, 0)
  357. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  358. if err != nil {
  359. utils.ErrorLog(err.Error())
  360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  361. return
  362. }
  363. var warehousingInfo []*models.DrugWarehouseInfo
  364. var upDateWarehousingInfo []*models.DrugWarehouseInfo
  365. var drugFlow []*models.DrugFlow
  366. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  367. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  368. if len(thisStockIn) > 0 {
  369. for _, item := range thisStockIn {
  370. items := item.(map[string]interface{})
  371. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  372. utils.ErrorLog("drug_id")
  373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  374. return
  375. }
  376. drug_id := int64(items["drug_id"].(float64))
  377. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  378. utils.ErrorLog("warehousing_count")
  379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  380. return
  381. }
  382. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  383. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  384. utils.ErrorLog("price")
  385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  386. return
  387. }
  388. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  389. total := float64(warehousing_count) * price
  390. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  391. utils.ErrorLog("last_price")
  392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  393. return
  394. }
  395. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  396. retail_price_total := float64(warehousing_count) * last_price
  397. var productDates int64
  398. var expiryDates int64
  399. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  400. expiryDates = 0
  401. } else {
  402. if len(items["expiry_date"].(string)) == 0 {
  403. expiryDates = 0
  404. } else {
  405. expiryDate, _ := items["expiry_date"].(string)
  406. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  407. expiryDates = expiry_date.Unix()
  408. }
  409. }
  410. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  411. productDates = 0
  412. } else {
  413. if len(items["product_date"].(string)) == 0 {
  414. productDates = 0
  415. } else {
  416. productDate, _ := items["product_date"].(string)
  417. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  418. productDates = product_date.Unix()
  419. }
  420. }
  421. number, _ := items["number"].(string)
  422. batch_number, _ := items["batch_number"].(string)
  423. max_unit, _ := items["max_unit"].(string)
  424. min_unit, _ := items["min_unit"].(string)
  425. var remark string
  426. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  427. remark = ""
  428. } else {
  429. remark = items["remark"].(string)
  430. }
  431. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  432. utils.ErrorLog("id")
  433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  434. return
  435. }
  436. id := int64(items["id"].(float64))
  437. manufacturer := int64(items["manufacturer"].(float64))
  438. dealer := int64(items["dealer"].(float64))
  439. if id == 0 {
  440. warehouseInfo := &models.DrugWarehouseInfo{
  441. WarehousingOrder: warehouse.WarehousingOrder,
  442. WarehousingId: warehouse.ID,
  443. DrugId: drug_id,
  444. Number: number,
  445. ProductDate: productDates,
  446. ExpiryDate: expiryDates,
  447. WarehousingCount: warehousing_count,
  448. Price: price,
  449. TotalPrice: total,
  450. Status: 1,
  451. Ctime: ctime,
  452. Remark: remark,
  453. OrgId: adminUserInfo.CurrentOrgId,
  454. Type: types,
  455. Manufacturer: manufacturer,
  456. Dealer: dealer,
  457. RetailPrice: last_price,
  458. RetailTotalPrice: retail_price_total,
  459. BatchNumber: batch_number,
  460. MaxUnit: max_unit,
  461. MinUnit: min_unit,
  462. }
  463. warehousingInfo = append(warehousingInfo, warehouseInfo)
  464. } else {
  465. warehouseInfo := &models.DrugWarehouseInfo{
  466. ID: id,
  467. WarehousingOrder: warehouse.WarehousingOrder,
  468. WarehousingId: warehouse.ID,
  469. DrugId: drug_id,
  470. Number: number,
  471. ProductDate: productDates,
  472. ExpiryDate: expiryDates,
  473. WarehousingCount: warehousing_count,
  474. Price: price,
  475. TotalPrice: total,
  476. Status: 1,
  477. Ctime: ctime,
  478. Remark: remark,
  479. OrgId: adminUserInfo.CurrentOrgId,
  480. Type: types,
  481. Manufacturer: manufacturer,
  482. Dealer: dealer,
  483. RetailPrice: last_price,
  484. RetailTotalPrice: retail_price_total,
  485. StockMaxNumber: warehousing_count,
  486. MaxUnit: max_unit,
  487. MinUnit: min_unit,
  488. BatchNumber: batch_number,
  489. }
  490. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  491. drugflow := &models.DrugFlow{
  492. WarehousingOrder: warehousing.WarehousingOrder,
  493. WarehousingId: warehousing.ID,
  494. DrugId: drug_id,
  495. Number: number,
  496. ProductDate: productDates,
  497. ExpireDate: expiryDates,
  498. Count: warehousing_count,
  499. Price: last_price,
  500. Status: 1,
  501. Ctime: ctime,
  502. UserOrgId: adminUserInfo.CurrentOrgId,
  503. Manufacturer: manufacturer,
  504. Dealer: dealer,
  505. BatchNumber: batch_number,
  506. MaxUnit: max_unit,
  507. MinUnit: min_unit,
  508. ConsumableType: 1,
  509. IsEdit: 1,
  510. Creator: adminUserInfo.AdminUser.Id,
  511. IsSys: 0,
  512. }
  513. drugFlow = append(drugFlow, drugflow)
  514. }
  515. }
  516. }
  517. }
  518. var errs error
  519. if len(warehousingInfo) > 0 {
  520. errs = service.CreateDrugWarehousingInfo(warehousingInfo)
  521. if errs == nil {
  522. service.CreateDrugFlow(drugFlow)
  523. //更改库存
  524. service.UpdateDrugInfo(warehousingInfo)
  525. }
  526. }
  527. if len(upDateWarehousingInfo) > 0 {
  528. var total int64
  529. var minNumber float64
  530. var allTotal int64
  531. for _, item := range upDateWarehousingInfo {
  532. //查询修改的记录
  533. orderInfo, _ := service.GetDrugWarehouseOrderOne(id, item.DrugId)
  534. info, _ := service.FindeDrugInfo(item.DrugId)
  535. total = orderInfo.StockMaxNumber * info.MinNumber
  536. allTotal = item.WarehousingCount*info.MinNumber - total
  537. str := strconv.FormatInt(allTotal, 10)
  538. minFloat, _ := strconv.ParseFloat(str, 64)
  539. minNumber = info.Total + minFloat
  540. lib := models.BaseDrugLib{
  541. Total: minNumber,
  542. }
  543. service.UpdateBaseDrug(&lib, item.DrugId)
  544. errs = service.UpDateDrugWarehousingInfo(item)
  545. service.CreateDrugFlow(drugFlow)
  546. }
  547. }
  548. if errs != nil {
  549. utils.ErrorLog(errs.Error())
  550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  551. return
  552. }
  553. c.ServeSuccessJSON(map[string]interface{}{
  554. "msg": "编辑成功",
  555. })
  556. }
  557. func (c *StockDrugApiController) DeleteDrugWarehouse() {
  558. ids := c.GetString("ids")
  559. if len(ids) == 0 {
  560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  561. return
  562. }
  563. idArray := strings.Split(ids, ",")
  564. err := service.DeleteDrugWarehouse(idArray)
  565. if err != nil {
  566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  567. } else {
  568. c.ServeSuccessJSON(map[string]interface{}{
  569. "msg": "删除成功",
  570. })
  571. }
  572. }
  573. func (c *StockDrugApiController) DeleteDrugWarehouseInfo() {
  574. id, _ := c.GetInt64("id", 0)
  575. if id == 0 {
  576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  577. return
  578. }
  579. err := service.UpDateDrugWarehouseStatus(id)
  580. if err != nil {
  581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  582. } else {
  583. c.ServeSuccessJSON(map[string]interface{}{
  584. "msg": "删除成功",
  585. })
  586. }
  587. }
  588. func (c *StockDrugApiController) CreateDrugSalesReturn() {
  589. dealer_id, _ := c.GetInt64("dealer_id", 0)
  590. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  591. sales_return_time := c.GetString("time")
  592. types, _ := c.GetInt64("type", 0)
  593. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  594. if parseDateErr != nil {
  595. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  597. return
  598. }
  599. adminUserInfo := c.GetAdminUserInfo()
  600. operation_time := time.Now().Unix()
  601. creater := adminUserInfo.AdminUser.Id
  602. ctime := time.Now().Unix()
  603. timeStr := time.Now().Format("2006-01-02")
  604. timeArr := strings.Split(timeStr, "-")
  605. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  606. total = total + 1
  607. orderNumber := "YPTHD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  608. salesReturn := models.DrugSalesReturn{
  609. OrderNumber: orderNumber,
  610. OperaTime: operation_time,
  611. OrgId: adminUserInfo.CurrentOrgId,
  612. Creater: creater,
  613. Ctime: ctime,
  614. Status: 1,
  615. ReturnTime: salesReturnDate.Unix(),
  616. Dealer: dealer_id,
  617. Manufacturer: manufacturer_id,
  618. Type: types,
  619. }
  620. service.AddSigleDrugSalesReturn(&salesReturn)
  621. dataBody := make(map[string]interface{}, 0)
  622. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  623. if err != nil {
  624. utils.ErrorLog(err.Error())
  625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  626. return
  627. }
  628. var salesReturnInfos []*models.DrugSalesReturnInfo
  629. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  630. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  631. if len(thisStockIn) > 0 {
  632. for _, item := range thisStockIn {
  633. items := item.(map[string]interface{})
  634. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  635. utils.ErrorLog("drug_id")
  636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  637. return
  638. }
  639. drug_id := int64(items["drug_id"].(float64))
  640. return_count, _ := items["return_count"].(string)
  641. if len(return_count) == 0 {
  642. utils.ErrorLog("len(return_count) == 0")
  643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  644. return
  645. }
  646. count, _ := strconv.ParseInt(return_count, 10, 64)
  647. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  648. utils.ErrorLog("price")
  649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  650. return
  651. }
  652. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  653. total := float64(count) * price
  654. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  655. utils.ErrorLog("retail_price")
  656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  657. return
  658. }
  659. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  660. retail_price_total := float64(count) * retail_price
  661. salesReturnInfo := &models.DrugSalesReturnInfo{
  662. OrderNumber: salesReturn.OrderNumber,
  663. SalesReturnId: salesReturn.ID,
  664. DrugId: drug_id,
  665. Count: count,
  666. Price: price,
  667. Total: total,
  668. Status: 1,
  669. Ctime: ctime,
  670. OrgId: adminUserInfo.CurrentOrgId,
  671. Type: types,
  672. Manufacturer: manufacturer_id,
  673. Dealer: dealer_id,
  674. RetailPrice: retail_price,
  675. RetailTotalPrice: retail_price_total,
  676. }
  677. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  678. }
  679. }
  680. }
  681. errs := service.CreateDrugSalesReturnInfo(salesReturnInfos)
  682. if errs != nil {
  683. utils.ErrorLog(errs.Error())
  684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateReturnFail)
  685. return
  686. }
  687. c.ServeSuccessJSON(map[string]interface{}{
  688. "msg": "退货成功",
  689. })
  690. }
  691. func (c *StockDrugApiController) GetDrugSalesReturnList() {
  692. page, _ := c.GetInt64("page", -1)
  693. limit, _ := c.GetInt64("limit", -1)
  694. start_time := c.GetString("start_time")
  695. end_time := c.GetString("end_time")
  696. types, _ := c.GetInt64("type", 0)
  697. keywords := c.GetString("keywords")
  698. timeLayout := "2006-01-02"
  699. loc, _ := time.LoadLocation("Local")
  700. var startTime int64
  701. if len(start_time) > 0 {
  702. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  703. if err != nil {
  704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  705. return
  706. }
  707. startTime = theTime.Unix()
  708. }
  709. var endTime int64
  710. if len(end_time) > 0 {
  711. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  712. if err != nil {
  713. utils.ErrorLog(err.Error())
  714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  715. return
  716. }
  717. endTime = theTime.Unix()
  718. }
  719. adminUserInfo := c.GetAdminUserInfo()
  720. returnList, total, err := service.FindAllDrugReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  721. if err == nil {
  722. c.ServeSuccessJSON(map[string]interface{}{
  723. "list": returnList,
  724. "total": total,
  725. })
  726. } else {
  727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  728. }
  729. }
  730. func (this *StockDrugApiController) DeleteDrugSalesReturn() {
  731. ids := this.GetString("ids")
  732. if len(ids) == 0 {
  733. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  734. return
  735. }
  736. idArray := strings.Split(ids, ",")
  737. err := service.DeleteDrugSalesReturn(idArray)
  738. if err != nil {
  739. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  740. } else {
  741. this.ServeSuccessJSON(map[string]interface{}{
  742. "msg": "删除成功",
  743. })
  744. }
  745. }
  746. func (this *StockDrugApiController) DeleteDrugSalesReturnInfo() {
  747. id, _ := this.GetInt64("id", 0)
  748. fmt.Println(id)
  749. if id == 0 {
  750. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  751. return
  752. }
  753. err := service.UpDateDrugSaleReturnStatus(id)
  754. if err != nil {
  755. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  756. } else {
  757. this.ServeSuccessJSON(map[string]interface{}{
  758. "msg": "删除成功",
  759. })
  760. }
  761. }
  762. func (this *StockDrugApiController) GetDrugSalesReturnInfoList() {
  763. id, _ := this.GetInt64("id", 0)
  764. adminUserInfo := this.GetAdminUserInfo()
  765. list, _ := service.FindAllDrugSalesReturnInfoById(id, adminUserInfo.CurrentOrgId)
  766. salesReturn, _ := service.FindAllDrugSalesReturnById(id, adminUserInfo.CurrentOrgId)
  767. this.ServeSuccessJSON(map[string]interface{}{
  768. "list": list,
  769. "salesReturn": salesReturn,
  770. })
  771. }
  772. func (c *StockDrugApiController) EditDrugReturnInfo() {
  773. return_time := c.GetString("return_time")
  774. id, _ := c.GetInt64("id", 0)
  775. types, _ := c.GetInt64("type", 0)
  776. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  777. dealer_id, _ := c.GetInt64("dealer_id", 0)
  778. if id == 0 {
  779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  780. return
  781. }
  782. ctime := time.Now().Unix()
  783. mtime := time.Now().Unix()
  784. adminUserInfo := c.GetAdminUserInfo()
  785. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  786. if parseDateErr != nil {
  787. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  789. return
  790. }
  791. salesReturns, _ := service.FindDrugSalesReturnById(id)
  792. sales := models.DrugSalesReturn{
  793. ID: salesReturns.ID,
  794. Mtime: mtime,
  795. ReturnTime: returnDate.Unix(),
  796. Manufacturer: manufacturer_id,
  797. Dealer: dealer_id,
  798. }
  799. service.EditDrugSaleReturn(sales)
  800. dataBody := make(map[string]interface{}, 0)
  801. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  802. if err != nil {
  803. utils.ErrorLog(err.Error())
  804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  805. return
  806. }
  807. var returnInfos []*models.DrugSalesReturnInfo
  808. var upDateReturnInfos []*models.DrugSalesReturnInfo
  809. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  810. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  811. if len(thisStockIn) > 0 {
  812. for _, item := range thisStockIn {
  813. items := item.(map[string]interface{})
  814. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  815. utils.ErrorLog("drug_id")
  816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  817. return
  818. }
  819. drug_id := int64(items["drug_id"].(float64))
  820. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  821. utils.ErrorLog("count")
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  826. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  827. utils.ErrorLog("id")
  828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  829. return
  830. }
  831. id := int64(items["id"].(float64))
  832. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  833. utils.ErrorLog("price")
  834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  835. return
  836. }
  837. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  838. total := float64(count) * price
  839. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  840. utils.ErrorLog("retail_price")
  841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  842. return
  843. }
  844. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  845. retail_price_total := float64(count) * retail_price
  846. if id == 0 {
  847. returnInfo := &models.DrugSalesReturnInfo{
  848. DrugId: drug_id,
  849. Count: count,
  850. Status: 1,
  851. Ctime: ctime,
  852. OrgId: adminUserInfo.CurrentOrgId,
  853. OrderNumber: sales.OrderNumber,
  854. SalesReturnId: sales.ID,
  855. Mtime: time.Now().Unix(),
  856. Type: types,
  857. Manufacturer: manufacturer_id,
  858. Dealer: dealer_id,
  859. RetailPrice: retail_price,
  860. RetailTotalPrice: retail_price_total,
  861. Total: total,
  862. Price: price,
  863. }
  864. returnInfos = append(returnInfos, returnInfo)
  865. } else {
  866. returnInfo := &models.DrugSalesReturnInfo{
  867. ID: id,
  868. DrugId: drug_id,
  869. Count: count,
  870. Status: 1,
  871. Ctime: ctime,
  872. OrgId: adminUserInfo.CurrentOrgId,
  873. OrderNumber: sales.OrderNumber,
  874. SalesReturnId: sales.ID,
  875. Mtime: time.Now().Unix(),
  876. Type: types,
  877. Manufacturer: manufacturer_id,
  878. Dealer: dealer_id,
  879. RetailPrice: retail_price,
  880. RetailTotalPrice: retail_price_total,
  881. Total: total,
  882. Price: price,
  883. }
  884. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  885. }
  886. }
  887. }
  888. }
  889. var errs error
  890. if len(returnInfos) > 0 {
  891. errs = service.CreateDrugSalesReturnInfo(returnInfos)
  892. }
  893. if len(upDateReturnInfos) > 0 {
  894. for _, item := range upDateReturnInfos {
  895. errs = service.UpDateDrugSalesReturnInfo(item)
  896. }
  897. }
  898. if errs != nil {
  899. utils.ErrorLog(errs.Error())
  900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateReturnFail)
  901. return
  902. }
  903. c.ServeSuccessJSON(map[string]interface{}{
  904. "msg": "编辑成功",
  905. })
  906. }
  907. func (c *StockDrugApiController) CreateDrugWarehouseOut() {
  908. types, _ := c.GetInt64("type", 0)
  909. ctime := time.Now().Unix()
  910. adminUserInfo := c.GetAdminUserInfo()
  911. warehousing_out_time := c.GetString("warehousing_out_time")
  912. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  913. if parseDateErr != nil {
  914. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  916. return
  917. }
  918. timeStr := time.Now().Format("2006-01-02")
  919. timeArr := strings.Split(timeStr, "-")
  920. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  921. total = total + 1
  922. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  923. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  924. number = number + total
  925. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  926. operation_time := time.Now().Unix()
  927. creater := adminUserInfo.AdminUser.Id
  928. warehouseOut := models.DrugWarehouseOut{
  929. WarehouseOutOrderNumber: warehousing_out_order,
  930. OperationTime: operation_time,
  931. OrgId: adminUserInfo.CurrentOrgId,
  932. Creater: creater,
  933. Ctime: ctime,
  934. Status: 1,
  935. WarehouseOutTime: warehousingOutDate.Unix(),
  936. Type: types,
  937. }
  938. dataBody := make(map[string]interface{}, 0)
  939. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  940. if err != nil {
  941. utils.ErrorLog(err.Error())
  942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  943. return
  944. }
  945. var warehousingOutInfo []*models.DrugWarehouseOutInfo
  946. var drugFlow []*models.DrugFlow
  947. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  948. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  949. if len(thisStockIn) > 0 {
  950. for _, item := range thisStockIn {
  951. items := item.(map[string]interface{})
  952. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  953. utils.ErrorLog("drug_id")
  954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  955. return
  956. }
  957. drug_id := int64(items["drug_id"].(float64))
  958. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  959. utils.ErrorLog("count")
  960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  961. return
  962. }
  963. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  964. utils.ErrorLog("price")
  965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  966. return
  967. }
  968. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  969. //if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  970. // utils.ErrorLog("last_price")
  971. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  972. // return
  973. //}
  974. //last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  975. //fmt.Println(last_price)
  976. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  977. total := float64(count) * price
  978. retail_price_total := float64(count) * price
  979. remark := items["remark"].(string)
  980. max_unit := items["max_unit"].(string)
  981. dealer := int64(items["dealer"].(float64))
  982. fmt.Println("dealer2222222222222222222", dealer)
  983. manufacturer := int64(items["manufacturer"].(float64))
  984. fmt.Println("manufacturer22222222222222", manufacturer)
  985. number := items["number"].(string)
  986. batch_number := items["batch_number"].(string)
  987. var productDates int64
  988. var expiryDates int64
  989. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  990. expiryDates = 0
  991. } else {
  992. if len(items["expiry_date"].(string)) == 0 {
  993. expiryDates = 0
  994. } else {
  995. expiryDate, _ := items["expiry_date"].(string)
  996. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  997. expiryDates = expiry_date.Unix()
  998. }
  999. }
  1000. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1001. productDates = 0
  1002. } else {
  1003. if len(items["product_date"].(string)) == 0 {
  1004. productDates = 0
  1005. } else {
  1006. productDate, _ := items["product_date"].(string)
  1007. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1008. productDates = product_date.Unix()
  1009. }
  1010. }
  1011. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1012. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1013. WarehouseOutId: warehouseOut.ID,
  1014. DrugId: drug_id,
  1015. Count: count,
  1016. Price: price,
  1017. TotalPrice: total,
  1018. Status: 1,
  1019. Ctime: ctime,
  1020. Remark: remark,
  1021. OrgId: adminUserInfo.CurrentOrgId,
  1022. Type: types,
  1023. Manufacturer: manufacturer,
  1024. Dealer: dealer,
  1025. RetailPrice: price,
  1026. RetailTotalPrice: retail_price_total,
  1027. CountUnit: max_unit,
  1028. ExpiryDate: expiryDates,
  1029. ProductDate: productDates,
  1030. Number: number,
  1031. BatchNumber: batch_number,
  1032. IsSys: 0,
  1033. }
  1034. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1035. drugflow := &models.DrugFlow{
  1036. WarehouseOutId: warehouseOut.ID,
  1037. WarehouseOutOrderNumber: warehousing_out_order,
  1038. DrugId: drug_id,
  1039. Number: number,
  1040. ProductDate: productDates,
  1041. ExpireDate: expiryDates,
  1042. Count: count,
  1043. Price: price,
  1044. Status: 1,
  1045. Ctime: ctime,
  1046. UserOrgId: adminUserInfo.CurrentOrgId,
  1047. Manufacturer: manufacturer,
  1048. Dealer: dealer,
  1049. BatchNumber: batch_number,
  1050. MaxUnit: max_unit,
  1051. ConsumableType: 2,
  1052. IsEdit: 1,
  1053. Creator: adminUserInfo.AdminUser.Id,
  1054. IsSys: 0,
  1055. }
  1056. drugFlow = append(drugFlow, drugflow)
  1057. }
  1058. }
  1059. }
  1060. //调用出库逻辑
  1061. for _, item := range warehousingOutInfo {
  1062. //获取药品库存
  1063. info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId)
  1064. if item.Count > info.Count {
  1065. goodObj, _ := service.GetDrugByGoodId(item.DrugId)
  1066. c.ServeSuccessJSON(map[string]interface{}{
  1067. "msg": "1",
  1068. "drug_name": goodObj.DrugName,
  1069. "dose": goodObj.Dose,
  1070. "dose_unit": goodObj.DoseUnit,
  1071. "min_number": goodObj.MinNumber,
  1072. "min_unit": goodObj.MinUnit,
  1073. "max_unit": goodObj.MaxUnit,
  1074. })
  1075. return
  1076. } else {
  1077. service.AddSigleDrugWarehouseOut(&warehouseOut)
  1078. service.CreateDrugFlow(drugFlow)
  1079. // 出库流程
  1080. // 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
  1081. drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
  1082. if drup.ID > 0 {
  1083. prescribingNumber := item.Count
  1084. service.AutoDrugDeliverInfo(item.OrgId, prescribingNumber, &warehouseOut, &drup, item)
  1085. }
  1086. }
  1087. }
  1088. //errs := service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
  1089. //info, _ := service.FindLastDrugWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
  1090. //if errs != nil {
  1091. // utils.ErrorLog(errs.Error())
  1092. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1093. // return
  1094. //}
  1095. c.ServeSuccessJSON(map[string]interface{}{
  1096. "msg": "2",
  1097. "drug_name": "",
  1098. "dose": "",
  1099. "dose_unit": "",
  1100. "min_number": "",
  1101. "min_unit": "",
  1102. "max_unit": "",
  1103. })
  1104. }
  1105. func (c *StockDrugApiController) GetDrugWarehouseOutList() {
  1106. page, _ := c.GetInt64("page", -1)
  1107. limit, _ := c.GetInt64("limit", -1)
  1108. start_time := c.GetString("start_time")
  1109. end_time := c.GetString("end_time")
  1110. types, _ := c.GetInt64("type", 0)
  1111. keywords := c.GetString("keywords")
  1112. timeLayout := "2006-01-02"
  1113. loc, _ := time.LoadLocation("Local")
  1114. var startTime int64
  1115. if len(start_time) > 0 {
  1116. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1117. if err != nil {
  1118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1119. return
  1120. }
  1121. startTime = theTime.Unix()
  1122. }
  1123. var endTime int64
  1124. if len(end_time) > 0 {
  1125. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1126. if err != nil {
  1127. utils.ErrorLog(err.Error())
  1128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1129. return
  1130. }
  1131. endTime = theTime.Unix()
  1132. }
  1133. adminUserInfo := c.GetAdminUserInfo()
  1134. var ids []int64
  1135. var goodids []int64
  1136. if len(keywords) > 0 {
  1137. //查询商品名称
  1138. list, _ := service.GetDrugNameByKeyword(keywords, adminUserInfo.CurrentOrgId)
  1139. for _, item := range list {
  1140. goodids = append(goodids, item.ID)
  1141. }
  1142. if len(goodids) > 0 {
  1143. //出库详情但里面查询
  1144. info, _ := service.GetDrugWarehouseOrderDetail(goodids, adminUserInfo.CurrentOrgId, startTime, endTime)
  1145. for _, it := range info {
  1146. ids = append(ids, it.WarehouseOutId)
  1147. }
  1148. }
  1149. }
  1150. warehouseOutList, total, err := service.FindAllDrugWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
  1151. fmt.Println(err)
  1152. if err == nil {
  1153. c.ServeSuccessJSON(map[string]interface{}{
  1154. "list": warehouseOutList,
  1155. "total": total,
  1156. })
  1157. } else {
  1158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1159. }
  1160. }
  1161. func (c *StockDrugApiController) DeleteDrugWarehouseOut() {
  1162. ids := c.GetString("ids")
  1163. if len(ids) == 0 {
  1164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1165. return
  1166. }
  1167. idArray := strings.Split(ids, ",")
  1168. err := service.DeleteDrugWarehouseOut(idArray)
  1169. if err != nil {
  1170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1171. } else {
  1172. c.ServeSuccessJSON(map[string]interface{}{
  1173. "msg": "删除成功",
  1174. })
  1175. }
  1176. }
  1177. func (this *StockDrugApiController) DeleteDrugWarehouseOutInfo() {
  1178. id, _ := this.GetInt64("id", 0)
  1179. fmt.Println(id)
  1180. if id == 0 {
  1181. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1182. return
  1183. }
  1184. err := service.UpDateDrugWarehouseOutStatus(id)
  1185. if err != nil {
  1186. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1187. } else {
  1188. this.ServeSuccessJSON(map[string]interface{}{
  1189. "msg": "删除成功",
  1190. })
  1191. }
  1192. }
  1193. func (c *StockDrugApiController) GetDrugWarehouseOutInfoList() {
  1194. id, _ := c.GetInt64("id", 0)
  1195. adminInfo := c.GetAdminUserInfo()
  1196. warehouseOutInfo, _ := service.FindDrugWarehouseOutInfoById(id, adminInfo.CurrentOrgId)
  1197. warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminInfo.CurrentOrgId)
  1198. manulist, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1199. dealerList, _ := service.GetAllDealerList(adminInfo.CurrentOrgId)
  1200. c.ServeSuccessJSON(map[string]interface{}{
  1201. "list": warehouseOutInfo,
  1202. "info": warehouseOut,
  1203. "manulist": manulist,
  1204. "dealerList": dealerList,
  1205. })
  1206. }
  1207. func (c *StockDrugApiController) EditDrugWarehouseOut() {
  1208. warehouse_out_time := c.GetString("warehouse_out_time")
  1209. id, _ := c.GetInt64("id", 0)
  1210. types, _ := c.GetInt64("type", 0)
  1211. if id == 0 {
  1212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1213. return
  1214. }
  1215. ctime := time.Now().Unix()
  1216. mtime := time.Now().Unix()
  1217. adminUserInfo := c.GetAdminUserInfo()
  1218. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1219. if parseDateErr != nil {
  1220. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1222. return
  1223. }
  1224. warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminUserInfo.CurrentOrgId)
  1225. tempWarehouseOut := models.DrugWarehouseOut{
  1226. ID: warehouseOut.ID,
  1227. Mtime: mtime,
  1228. WarehouseOutTime: warehouseOutDate.Unix(),
  1229. }
  1230. service.EditDrugWarehouseOut(tempWarehouseOut)
  1231. dataBody := make(map[string]interface{}, 0)
  1232. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1233. if err != nil {
  1234. utils.ErrorLog(err.Error())
  1235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1236. return
  1237. }
  1238. var warehousingOutInfo []*models.DrugWarehouseOutInfo
  1239. var upDateWarehouseOutInfos []*models.DrugWarehouseOutInfo
  1240. //var drugFlow []*models.DrugFlow
  1241. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1242. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1243. if len(thisStockOut) > 0 {
  1244. for _, item := range thisStockOut {
  1245. items := item.(map[string]interface{})
  1246. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1247. utils.ErrorLog("drug_id")
  1248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1249. return
  1250. }
  1251. drug_id := int64(items["drug_id"].(float64))
  1252. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1253. utils.ErrorLog("count")
  1254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1255. return
  1256. }
  1257. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1258. count_unit, _ := items["count_unit"].(string)
  1259. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1260. utils.ErrorLog("price")
  1261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1262. return
  1263. }
  1264. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1265. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1266. utils.ErrorLog("retail_price")
  1267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1268. return
  1269. }
  1270. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1271. total := float64(count) * price
  1272. retail_price_total := float64(count) * retail_price
  1273. remark := items["remark"].(string)
  1274. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1275. utils.ErrorLog("id")
  1276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1277. return
  1278. }
  1279. id := int64(items["id"].(float64))
  1280. dealer := int64(items["dealer"].(float64))
  1281. manufacturer := int64(items["manufacturer"].(float64))
  1282. batch_number := items["batch_number"].(string)
  1283. number := items["number"].(string)
  1284. var productDates int64
  1285. var expiryDates int64
  1286. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1287. expiryDates = 0
  1288. } else {
  1289. if len(items["expiry_date"].(string)) == 0 {
  1290. expiryDates = 0
  1291. } else {
  1292. expiryDate, _ := items["expiry_date"].(string)
  1293. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1294. expiryDates = expiry_date.Unix()
  1295. }
  1296. }
  1297. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1298. productDates = 0
  1299. } else {
  1300. if len(items["product_date"].(string)) == 0 {
  1301. productDates = 0
  1302. } else {
  1303. productDate, _ := items["product_date"].(string)
  1304. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1305. productDates = product_date.Unix()
  1306. }
  1307. }
  1308. if id == 0 {
  1309. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1310. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1311. WarehouseOutId: warehouseOut.ID,
  1312. DrugId: drug_id,
  1313. Count: count,
  1314. Price: price,
  1315. TotalPrice: total,
  1316. Status: 1,
  1317. Ctime: ctime,
  1318. Remark: remark,
  1319. OrgId: adminUserInfo.CurrentOrgId,
  1320. Type: types,
  1321. Manufacturer: manufacturer,
  1322. Dealer: dealer,
  1323. IsSys: 0,
  1324. SysRecordTime: 0,
  1325. RetailPrice: retail_price,
  1326. RetailTotalPrice: retail_price_total,
  1327. BatchNumber: batch_number,
  1328. Number: number,
  1329. ProductDate: productDates,
  1330. ExpiryDate: expiryDates,
  1331. CountUnit: count_unit,
  1332. }
  1333. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1334. //drugflow := &models.DrugFlow{
  1335. // WarehousingOrder: warehousing.WarehousingOrder,
  1336. // WarehousingId: warehousing.ID,
  1337. // DrugId: drug_id,
  1338. // Number: number,
  1339. // ProductDate: productDates,
  1340. // ExpireDate: expiryDates,
  1341. // Count: warehousing_count,
  1342. // Price: last_price,
  1343. // Status: 1,
  1344. // Ctime: ctime,
  1345. // UserOrgId: adminUserInfo.CurrentOrgId,
  1346. // Manufacturer: manufacturer,
  1347. // Dealer: dealer,
  1348. // BatchNumber: batch_number,
  1349. // MaxUnit: max_unit,
  1350. // MinUnit: min_unit,
  1351. // ConsumableType: 1,
  1352. // IsEdit: 1,
  1353. // Creator: adminUserInfo.AdminUser.Id,
  1354. // IsSys:0,
  1355. //}
  1356. //
  1357. //drugFlow = append(drugFlow,drugflow)
  1358. } else {
  1359. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1360. utils.ErrorLog("is_sys")
  1361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1362. return
  1363. }
  1364. is_sys := int64(items["is_sys"].(float64))
  1365. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1366. utils.ErrorLog("sys_record_time")
  1367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1368. return
  1369. }
  1370. sys_record_time := int64(items["sys_record_time"].(float64))
  1371. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1372. ID: id,
  1373. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1374. WarehouseOutId: warehouseOut.ID,
  1375. DrugId: drug_id,
  1376. Count: count,
  1377. Price: price,
  1378. TotalPrice: total,
  1379. Status: 1,
  1380. Ctime: ctime,
  1381. Remark: remark,
  1382. OrgId: adminUserInfo.CurrentOrgId,
  1383. Mtime: time.Now().Unix(),
  1384. Type: types,
  1385. Manufacturer: manufacturer,
  1386. Dealer: dealer,
  1387. IsSys: is_sys,
  1388. SysRecordTime: sys_record_time,
  1389. RetailPrice: retail_price,
  1390. RetailTotalPrice: retail_price_total,
  1391. BatchNumber: batch_number,
  1392. Number: number,
  1393. ProductDate: productDates,
  1394. ExpiryDate: expiryDates,
  1395. CountUnit: count_unit,
  1396. }
  1397. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1398. }
  1399. }
  1400. }
  1401. }
  1402. var errs error
  1403. if len(warehousingOutInfo) > 0 {
  1404. errs = service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
  1405. }
  1406. if len(upDateWarehouseOutInfos) > 0 {
  1407. for _, item := range upDateWarehouseOutInfos {
  1408. errs = service.UpDateDrugWarehouseOutInfo(item)
  1409. }
  1410. }
  1411. if errs != nil {
  1412. utils.ErrorLog(errs.Error())
  1413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
  1414. return
  1415. }
  1416. c.ServeSuccessJSON(map[string]interface{}{
  1417. "msg": "编辑成功",
  1418. })
  1419. }
  1420. func (c *StockDrugApiController) CreateDrugCancelStock() {
  1421. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1422. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1423. cancel_stock_time := c.GetString("time")
  1424. types, _ := c.GetInt64("type", 0)
  1425. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1426. if parseDateErr != nil {
  1427. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1429. return
  1430. }
  1431. adminUserInfo := c.GetAdminUserInfo()
  1432. operation_time := time.Now().Unix()
  1433. creater := adminUserInfo.AdminUser.Id
  1434. ctime := time.Now().Unix()
  1435. timeStr := time.Now().Format("2006-01-02")
  1436. timeArr := strings.Split(timeStr, "-")
  1437. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1438. total = total + 1
  1439. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1440. cancelStock := models.DrugCancelStock{
  1441. OrderNumber: orderNumber,
  1442. OperaTime: operation_time,
  1443. OrgId: adminUserInfo.CurrentOrgId,
  1444. Creater: creater,
  1445. Ctime: ctime,
  1446. Status: 1,
  1447. ReturnTime: cancelStockDate.Unix(),
  1448. Dealer: dealer_id,
  1449. Manufacturer: manufacturer_id,
  1450. Type: types,
  1451. }
  1452. service.AddSigleDrugCancelStock(&cancelStock)
  1453. dataBody := make(map[string]interface{}, 0)
  1454. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1455. if err != nil {
  1456. utils.ErrorLog(err.Error())
  1457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1458. return
  1459. }
  1460. var cancelStockInfos []*models.DrugCancelStockInfo
  1461. var drugFlow []*models.DrugFlow
  1462. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1463. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1464. if len(thisStockIn) > 0 {
  1465. for _, item := range thisStockIn {
  1466. items := item.(map[string]interface{})
  1467. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1468. utils.ErrorLog("drug_id")
  1469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1470. return
  1471. }
  1472. drug_id := int64(items["drug_id"].(float64))
  1473. return_count, _ := items["return_count"].(string)
  1474. if len(return_count) == 0 {
  1475. utils.ErrorLog("len(return_count) == 0")
  1476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1477. return
  1478. }
  1479. count, _ := strconv.ParseInt(return_count, 10, 64)
  1480. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1481. utils.ErrorLog("price")
  1482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1483. return
  1484. }
  1485. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1486. total := float64(count) * price
  1487. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1488. utils.ErrorLog("retail_price")
  1489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1490. return
  1491. }
  1492. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1493. retail_price_total := float64(count) * retail_price
  1494. register_account, _ := items["register_account"].(string)
  1495. remark, _ := items["remark"].(string)
  1496. var productDates int64
  1497. var expiryDates int64
  1498. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1499. expiryDates = 0
  1500. } else {
  1501. if len(items["expiry_date"].(string)) == 0 {
  1502. expiryDates = 0
  1503. } else {
  1504. expiryDate, _ := items["expiry_date"].(string)
  1505. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1506. expiryDates = expiry_date.Unix()
  1507. }
  1508. }
  1509. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1510. productDates = 0
  1511. } else {
  1512. if len(items["product_date"].(string)) == 0 {
  1513. productDates = 0
  1514. } else {
  1515. productDate, _ := items["product_date"].(string)
  1516. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1517. productDates = product_date.Unix()
  1518. }
  1519. }
  1520. manufacturer, _ := items["manufacturer"].(string)
  1521. dealer, _ := items["dealer"].(string)
  1522. batch_number := items["batch_number"].(string)
  1523. max_unit := items["max_unit"].(string)
  1524. batch_number_id := int64(items["batch_number_id"].(float64))
  1525. cancelStockInfo := &models.DrugCancelStockInfo{
  1526. OrderNumber: cancelStock.OrderNumber,
  1527. CancelStockId: cancelStock.ID,
  1528. DrugId: drug_id,
  1529. Count: count,
  1530. Status: 1,
  1531. Ctime: ctime,
  1532. OrgId: adminUserInfo.CurrentOrgId,
  1533. Type: types,
  1534. Manufacturer: manufacturer,
  1535. Dealer: dealer,
  1536. Total: total,
  1537. RetailPrice: retail_price,
  1538. RetailTotalPrice: retail_price_total,
  1539. Price: price,
  1540. RegisterAccount: register_account,
  1541. Remark: remark,
  1542. BatchNumber: batch_number,
  1543. MaxUnit: max_unit,
  1544. ProductDate: productDates,
  1545. ExpiryDate: expiryDates,
  1546. BatchNumberId: batch_number_id,
  1547. }
  1548. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1549. flow := &models.DrugFlow{
  1550. WarehousingId: 0,
  1551. DrugId: drug_id,
  1552. Number: "",
  1553. BatchNumber: batch_number,
  1554. Count: count,
  1555. UserOrgId: adminUserInfo.CurrentOrgId,
  1556. PatientId: 0,
  1557. SystemTime: ctime,
  1558. ConsumableType: 4,
  1559. IsSys: 0,
  1560. WarehousingOrder: "",
  1561. WarehouseOutId: 0,
  1562. WarehouseOutOrderNumber: "",
  1563. IsEdit: 0,
  1564. CancelStockId: cancelStock.ID,
  1565. CancelOrderNumber: cancelStock.OrderNumber,
  1566. Manufacturer: 0,
  1567. Dealer: 0,
  1568. Creator: adminUserInfo.AdminUser.Id,
  1569. UpdateCreator: 0,
  1570. Status: 1,
  1571. Ctime: time.Now().Unix(),
  1572. Mtime: 0,
  1573. Price: price,
  1574. WarehousingDetailId: 0,
  1575. WarehouseOutDetailId: 0,
  1576. CancelOutDetailId: 0,
  1577. ExpireDate: expiryDates,
  1578. ProductDate: productDates,
  1579. MaxUnit: max_unit,
  1580. MinUnit: "",
  1581. }
  1582. drugFlow = append(drugFlow, flow)
  1583. }
  1584. }
  1585. }
  1586. //扣减库存逻辑
  1587. for _, item := range cancelStockInfos {
  1588. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1589. //查询当前药品退库的批次号的总入库数
  1590. infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
  1591. fmt.Println("hhh2h3h2hh3233", item.MaxUnit, medical.MaxUnit)
  1592. var total_count int64
  1593. if item.MaxUnit == medical.MaxUnit {
  1594. total_count = infoWareInfo.WarehousingCount
  1595. fmt.Println("进来了吗发大发阿道夫阿方阿道夫撒发大发阿方阿方阿方阿道夫阿方暗示法", total_count)
  1596. }
  1597. //转化为最小库存
  1598. if item.MaxUnit == medical.MinUnit {
  1599. total_count = infoWareInfo.WarehousingCount * medical.MinNumber
  1600. }
  1601. fmt.Println("itme.count2323232323232323232332", item.Count)
  1602. fmt.Println("23232322322323232332", total_count)
  1603. //判断退库数量是否大于总入库数量
  1604. if item.Count > total_count {
  1605. c.ServeSuccessJSON(map[string]interface{}{
  1606. "msg": "2",
  1607. })
  1608. return
  1609. }
  1610. //正常退库
  1611. if item.Count <= infoWareInfo.WarehousingCount {
  1612. //创建退库详情
  1613. errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
  1614. //创建库存明细
  1615. service.CreateDrugFlow(drugFlow)
  1616. var total int64
  1617. //退库到当前批次,获取当前退库批次的库存
  1618. info, _ := service.GetDrugWarehouseInfoById(item.BatchNumberId)
  1619. if info.MaxUnit == item.MaxUnit {
  1620. total = item.Count + info.StockMaxNumber
  1621. warehouseInfo := models.XtDrugWarehouseInfo{
  1622. StockMaxNumber: total,
  1623. }
  1624. errs = service.UpdateDrugWarehouseInfo(&warehouseInfo, item.BatchNumberId)
  1625. if errs != nil {
  1626. utils.ErrorLog(errs.Error())
  1627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1628. return
  1629. }
  1630. c.ServeSuccessJSON(map[string]interface{}{
  1631. "msg": "1",
  1632. })
  1633. }
  1634. if medical.MinUnit == item.MaxUnit {
  1635. total = item.Count + info.StockMinNumber
  1636. warehouseInfo := models.XtDrugWarehouseInfo{
  1637. StockMinNumber: total,
  1638. }
  1639. errs = service.UpdateDrugWarehouseInfoOne(&warehouseInfo, item.BatchNumberId)
  1640. if errs != nil {
  1641. utils.ErrorLog(errs.Error())
  1642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1643. return
  1644. }
  1645. c.ServeSuccessJSON(map[string]interface{}{
  1646. "msg": "1",
  1647. })
  1648. }
  1649. }
  1650. }
  1651. }
  1652. func (c *StockDrugApiController) GetDrugCancelStockInfoList() {
  1653. id, _ := c.GetInt64("id", 0)
  1654. adminUserInfo := c.GetAdminUserInfo()
  1655. cancelStockInfoList, _ := service.FindDrugCancelStockInfoById(id, adminUserInfo.CurrentOrgId)
  1656. info, _ := service.FindCancelStockById(id, adminUserInfo.CurrentOrgId)
  1657. c.ServeSuccessJSON(map[string]interface{}{
  1658. "list": cancelStockInfoList,
  1659. "info": info,
  1660. })
  1661. }
  1662. func (c *StockDrugApiController) GetDrugCancelStockList() {
  1663. page, _ := c.GetInt64("page", -1)
  1664. limit, _ := c.GetInt64("limit", -1)
  1665. start_time := c.GetString("start_time")
  1666. end_time := c.GetString("end_time")
  1667. types, _ := c.GetInt64("type", 0)
  1668. keywords := c.GetString("keywords")
  1669. timeLayout := "2006-01-02"
  1670. loc, _ := time.LoadLocation("Local")
  1671. var startTime int64
  1672. if len(start_time) > 0 {
  1673. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1674. if err != nil {
  1675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1676. return
  1677. }
  1678. startTime = theTime.Unix()
  1679. }
  1680. var endTime int64
  1681. if len(end_time) > 0 {
  1682. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1683. if err != nil {
  1684. utils.ErrorLog(err.Error())
  1685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1686. return
  1687. }
  1688. endTime = theTime.Unix()
  1689. }
  1690. adminUserInfo := c.GetAdminUserInfo()
  1691. returnList, total, err := service.FindAllDrugCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1692. if err == nil {
  1693. c.ServeSuccessJSON(map[string]interface{}{
  1694. "list": returnList,
  1695. "total": total,
  1696. })
  1697. } else {
  1698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1699. }
  1700. }
  1701. func (this *StockDrugApiController) DeleteDrugCancelStock() {
  1702. ids := this.GetString("ids")
  1703. if len(ids) == 0 {
  1704. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1705. return
  1706. }
  1707. idArray := strings.Split(ids, ",")
  1708. err := service.DeleteDrugCancelStock(idArray)
  1709. if err != nil {
  1710. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1711. } else {
  1712. this.ServeSuccessJSON(map[string]interface{}{
  1713. "msg": "删除成功",
  1714. })
  1715. }
  1716. }
  1717. func (this *StockDrugApiController) DeleteDrugCancelStockInfo() {
  1718. id, _ := this.GetInt64("id", 0)
  1719. fmt.Println(id)
  1720. if id == 0 {
  1721. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1722. return
  1723. }
  1724. err := service.UpDateDrugCancleStockStatus(id)
  1725. if err != nil {
  1726. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1727. } else {
  1728. this.ServeSuccessJSON(map[string]interface{}{
  1729. "msg": "删除成功",
  1730. })
  1731. }
  1732. }
  1733. func (c *StockDrugApiController) EditDrugCancelStock() {
  1734. cancel_time := c.GetString("cancel_time")
  1735. id, _ := c.GetInt64("id", 0)
  1736. types, _ := c.GetInt64("type", 0)
  1737. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1738. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1739. if id == 0 {
  1740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1741. return
  1742. }
  1743. ctime := time.Now().Unix()
  1744. mtime := time.Now().Unix()
  1745. adminUserInfo := c.GetAdminUserInfo()
  1746. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  1747. if parseDateErr != nil {
  1748. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  1749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1750. return
  1751. }
  1752. cancelStock, _ := service.FindDrugCancelStockById(id)
  1753. tempCancelStock := models.DrugCancelStock{
  1754. ID: cancelStock.ID,
  1755. Mtime: mtime,
  1756. ReturnTime: cancelDate.Unix(),
  1757. Manufacturer: manufacturer_id,
  1758. Dealer: dealer_id,
  1759. }
  1760. service.EditDrugCancelStock(tempCancelStock)
  1761. dataBody := make(map[string]interface{}, 0)
  1762. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1763. if err != nil {
  1764. utils.ErrorLog(err.Error())
  1765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1766. return
  1767. }
  1768. var cancelStockInfos []*models.DrugCancelStockInfo
  1769. var upDateCancelStockInfos []*models.DrugCancelStockInfo
  1770. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1771. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  1772. if len(thisCancelStock) > 0 {
  1773. for _, item := range thisCancelStock {
  1774. items := item.(map[string]interface{})
  1775. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1776. utils.ErrorLog("drug_id")
  1777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1778. return
  1779. }
  1780. drug_id := int64(items["drug_id"].(float64))
  1781. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1782. utils.ErrorLog("count")
  1783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1784. return
  1785. }
  1786. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1787. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1788. utils.ErrorLog("price")
  1789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1790. return
  1791. }
  1792. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1793. total := float64(count) * price
  1794. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1795. utils.ErrorLog("retail_price")
  1796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1797. return
  1798. }
  1799. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1800. retail_price_total := float64(count) * retail_price
  1801. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1802. utils.ErrorLog("id")
  1803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1804. return
  1805. }
  1806. id := int64(items["id"].(float64))
  1807. max_unit := items["max_unit"].(string)
  1808. batch_number := items["batch_number"].(string)
  1809. register_account := items["register_account"].(string)
  1810. remark := items["remark"].(string)
  1811. manufacturer := items["manufacturer"].(string)
  1812. dealer := items["dealer"].(string)
  1813. var productDates int64
  1814. var expiryDates int64
  1815. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  1816. expiryDates = 0
  1817. } else {
  1818. if len(items["expiry_date"].(string)) == 0 {
  1819. expiryDates = 0
  1820. } else {
  1821. expiryDate, _ := items["expiry_date"].(string)
  1822. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  1823. expiryDates = expiry_date.Unix()
  1824. }
  1825. }
  1826. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  1827. productDates = 0
  1828. } else {
  1829. if len(items["product_date"].(string)) == 0 {
  1830. productDates = 0
  1831. } else {
  1832. productDate, _ := items["product_date"].(string)
  1833. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  1834. productDates = product_date.Unix()
  1835. }
  1836. }
  1837. if id == 0 {
  1838. cancelStockInfo := &models.DrugCancelStockInfo{
  1839. DrugId: drug_id,
  1840. Count: count,
  1841. Status: 1,
  1842. Ctime: ctime,
  1843. OrgId: adminUserInfo.CurrentOrgId,
  1844. OrderNumber: cancelStock.OrderNumber,
  1845. CancelStockId: cancelStock.ID,
  1846. Mtime: time.Now().Unix(),
  1847. Type: types,
  1848. RetailPrice: retail_price,
  1849. RetailTotalPrice: retail_price_total,
  1850. Price: price,
  1851. Total: total,
  1852. Manufacturer: manufacturer,
  1853. Dealer: dealer,
  1854. RegisterAccount: register_account,
  1855. MaxUnit: max_unit,
  1856. BatchNumber: batch_number,
  1857. Remark: remark,
  1858. ProductDate: productDates,
  1859. ExpiryDate: expiryDates,
  1860. }
  1861. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1862. } else {
  1863. cancelStockInfo := &models.DrugCancelStockInfo{
  1864. ID: id,
  1865. DrugId: drug_id,
  1866. Count: count,
  1867. Status: 1,
  1868. Ctime: ctime,
  1869. OrgId: adminUserInfo.CurrentOrgId,
  1870. OrderNumber: cancelStock.OrderNumber,
  1871. CancelStockId: cancelStock.ID,
  1872. Mtime: time.Now().Unix(),
  1873. Type: types,
  1874. RetailPrice: retail_price,
  1875. RetailTotalPrice: retail_price_total,
  1876. Price: price,
  1877. Total: total,
  1878. Manufacturer: manufacturer,
  1879. Dealer: dealer,
  1880. RegisterAccount: register_account,
  1881. MaxUnit: max_unit,
  1882. BatchNumber: batch_number,
  1883. Remark: remark,
  1884. ProductDate: productDates,
  1885. ExpiryDate: expiryDates,
  1886. }
  1887. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  1888. }
  1889. }
  1890. }
  1891. }
  1892. var errs error
  1893. if len(cancelStockInfos) > 0 {
  1894. errs = service.CreateDrugCancelStockInfo(cancelStockInfos)
  1895. }
  1896. if len(upDateCancelStockInfos) > 0 {
  1897. for _, item := range upDateCancelStockInfos {
  1898. errs = service.UpDateDrugCancelStockInfo(item)
  1899. }
  1900. }
  1901. if errs != nil {
  1902. utils.ErrorLog(errs.Error())
  1903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateCancelStockFail)
  1904. return
  1905. }
  1906. c.ServeSuccessJSON(map[string]interface{}{
  1907. "msg": "编辑成功",
  1908. })
  1909. }
  1910. func (c *StockDrugApiController) GetAllConfig() {
  1911. adminUserInfo := c.GetAdminUserInfo()
  1912. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  1913. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  1914. stockIns, _ := service.FindStockInNumber(adminUserInfo.CurrentOrgId)
  1915. drugs, _ := service.GetDrugs(adminUserInfo.CurrentOrgId)
  1916. c.ServeSuccessJSON(map[string]interface{}{
  1917. "manufacturer": manufacturer,
  1918. "dealer": dealer,
  1919. "drugs": drugs,
  1920. "numbers": stockIns,
  1921. })
  1922. }
  1923. func (c *StockDrugApiController) GetAllDrugStock() {
  1924. adminUserInfo := c.GetAdminUserInfo()
  1925. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1926. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1927. drugs, err := service.FindAllDrugByManufactureId(manufacturer_id, dealer_id, adminUserInfo.CurrentOrgId)
  1928. if err == nil {
  1929. c.ServeSuccessJSON(map[string]interface{}{
  1930. "drugs": drugs,
  1931. })
  1932. } else {
  1933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1934. }
  1935. }
  1936. func (c *StockDrugApiController) GetDrugQueryInfo() {
  1937. page, _ := c.GetInt64("page", -1)
  1938. limit, _ := c.GetInt64("limit", -1)
  1939. keyword := c.GetString("keyword")
  1940. drug_category, _ := c.GetInt64("drug_category")
  1941. start_time := c.GetString("start_time")
  1942. end_time := c.GetString("end_time")
  1943. timeLayout := "2006-01-02"
  1944. loc, _ := time.LoadLocation("Local")
  1945. var startTime int64
  1946. if len(start_time) > 0 {
  1947. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1948. if err != nil {
  1949. fmt.Println(err)
  1950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1951. return
  1952. }
  1953. startTime = theTime.Unix()
  1954. }
  1955. var endTime int64
  1956. if len(end_time) > 0 {
  1957. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1958. if err != nil {
  1959. utils.ErrorLog(err.Error())
  1960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1961. return
  1962. }
  1963. endTime = theTime.Unix()
  1964. }
  1965. adminUserInfo := c.GetAdminUserInfo()
  1966. list, total, err := service.FindAllDrugStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword, drug_category, startTime, endTime)
  1967. if err == nil {
  1968. c.ServeSuccessJSON(map[string]interface{}{
  1969. "list": list,
  1970. "total": total,
  1971. })
  1972. } else {
  1973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1974. }
  1975. }
  1976. func (this *StockDrugApiController) GetUserDetailInfo() {
  1977. order_id, _ := this.GetInt64("id")
  1978. if order_id <= 0 {
  1979. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1980. return
  1981. }
  1982. adminUserInfo := this.GetAdminUserInfo()
  1983. userDetails, err, total := service.FindDrugStockUserDetailById(adminUserInfo.CurrentOrgId, order_id)
  1984. if err == nil {
  1985. this.ServeSuccessJSON(map[string]interface{}{
  1986. "list": userDetails,
  1987. "total": total,
  1988. })
  1989. } else {
  1990. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1991. return
  1992. }
  1993. }
  1994. func (this *StockDrugApiController) GetCancelDrugOrderPrint() {
  1995. orderId := this.GetString("order_id")
  1996. ids := strings.Split(orderId, ",")
  1997. orgId := this.GetAdminUserInfo().CurrentOrgId
  1998. list, _ := service.GetCancelDrugOrderPrint(ids, orgId)
  1999. this.ServeSuccessJSON(map[string]interface{}{
  2000. "list": list,
  2001. })
  2002. }
  2003. func (this *StockDrugApiController) GetDrugCancelExportList() {
  2004. orderId := this.GetString("order_id")
  2005. fmt.Println("order_id2323232323223", orderId)
  2006. ids := strings.Split(orderId, ",")
  2007. orgId := this.GetAdminUserInfo().CurrentOrgId
  2008. list, _ := service.GetDrugCancelExportList(ids, orgId)
  2009. this.ServeSuccessJSON(map[string]interface{}{
  2010. "list": list,
  2011. })
  2012. }