drug_stock_api_contorller.go 54KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727
  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:GetQueryInfo")
  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 := "RKD" + 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["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  119. utils.ErrorLog("price")
  120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  121. return
  122. }
  123. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  124. total := float64(warehousing_count) * price
  125. var productDates int64
  126. var expiryDates int64
  127. fmt.Println()
  128. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  129. expiryDates = 0
  130. } else {
  131. if len(items["expiry_date"].(string)) == 0 {
  132. expiryDates = 0
  133. } else {
  134. expiryDate, _ := items["expiry_date"].(string)
  135. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  136. expiryDates = expiry_date.Unix()
  137. }
  138. }
  139. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  140. productDates = 0
  141. } else {
  142. if len(items["product_date"].(string)) == 0 {
  143. productDates = 0
  144. } else {
  145. productDate, _ := items["product_date"].(string)
  146. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  147. productDates = product_date.Unix()
  148. }
  149. }
  150. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  151. utils.ErrorLog("number")
  152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  153. return
  154. }
  155. number, _ := items["number"].(string)
  156. var remark string
  157. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  158. remark = ""
  159. } else {
  160. remark = items["remark"].(string)
  161. }
  162. warehouseInfo := &models.DrugWarehouseInfo{
  163. WarehousingOrder: warehousing.WarehousingOrder,
  164. WarehousingId: warehousing.ID,
  165. DrugId: drug_id,
  166. Number: number,
  167. ProductDate: productDates,
  168. ExpiryDate: expiryDates,
  169. WarehousingCount: warehousing_count,
  170. Price: price,
  171. TotalPrice: total,
  172. Status: 1,
  173. Ctime: ctime,
  174. Remark: remark,
  175. OrgId: adminUserInfo.CurrentOrgId,
  176. Type: types,
  177. Manufacturer: manufacturer_id,
  178. Dealer: dealer_id,
  179. }
  180. warehousingInfo = append(warehousingInfo, warehouseInfo)
  181. }
  182. }
  183. }
  184. errs := service.CreateDrugWarehousingInfo(warehousingInfo)
  185. info, _ := service.FindLastDrugWarehousingInfo(warehousing.WarehousingOrder)
  186. if errs != nil {
  187. utils.ErrorLog(errs.Error())
  188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  189. return
  190. }
  191. c.ServeSuccessJSON(map[string]interface{}{
  192. "msg": "入库成功",
  193. "warehousing_order": warehousing_order,
  194. "info": info,
  195. })
  196. //}
  197. //else {
  198. // warehouse, err1 := service.FindWareHouseByOrderNumber(warehousing_order)
  199. // if (err1 != nil) {
  200. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  201. // return
  202. // }
  203. //
  204. // dataBody := make(map[string]interface{}, 0)
  205. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  206. // if err != nil {
  207. // utils.ErrorLog(err.Error())
  208. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. // return
  210. // }
  211. //
  212. // var warehousingInfo []*models.WarehousingInfo
  213. //
  214. // if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  215. // thisStockIn, _ := dataBody["stockIn"].([]interface{})
  216. // if len(thisStockIn) > 0 {
  217. // for _, item := range thisStockIn {
  218. // items := item.(map[string]interface{})
  219. //
  220. // if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  221. // utils.ErrorLog("good_id")
  222. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  223. // return
  224. // }
  225. // good_id := int64(items["good_id"].(float64))
  226. //
  227. // if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  228. // utils.ErrorLog("good_type_id")
  229. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  230. // return
  231. // }
  232. // good_type_id := int64(items["good_type_id"].(float64))
  233. //
  234. // if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  235. // utils.ErrorLog("warehousing_count")
  236. // c.ServeFailJSONWithSGJErrorCod Fe(enums.ErrorCodeParamWrong)
  237. // return
  238. // }
  239. //
  240. // warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  241. //
  242. // if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  243. // utils.ErrorLog("price")
  244. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  245. // return
  246. // }
  247. // price, _ := strconv.ParseFloat(items["price"].(string), 64)
  248. // total := float64(warehousing_count) * price
  249. //
  250. // if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  251. // utils.ErrorLog("expiry_date")
  252. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  253. // return
  254. // }
  255. //
  256. // expiryDate, _ := items["expiry_date"].(string)
  257. // if len(expiryDate) == 0 {
  258. // utils.ErrorLog("len(expiry_date) == 0")
  259. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  260. //
  261. // return
  262. // }
  263. //
  264. // expiry_date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  265. // if parseDateErr != nil {
  266. // c.ErrorLog("日期(%v)解析错误:%v", expiry_date, parseDateErr)
  267. // }
  268. //
  269. // var productDates int64
  270. //
  271. // if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  272. // productDates = 0;
  273. // } else {
  274. // productDate, _ := items["product_date"].(string)
  275. // product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  276. // productDates = product_date.Unix()
  277. //
  278. // }
  279. //
  280. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  281. // utils.ErrorLog("number")
  282. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  283. // return
  284. // }
  285. // number, _ := items["number"].(string)
  286. //
  287. // var remark string
  288. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  289. // remark = ""
  290. // } else {
  291. // remark = items["remark"].(string)
  292. // }
  293. //
  294. // warehouseInfo := &models.WarehousingInfo{
  295. // WarehousingOrder: warehousing_order,
  296. // WarehousingId: warehouse.ID,
  297. // GoodId: good_id,
  298. // Number: number,
  299. // GoodTypeId: good_type_id,
  300. // ProductDate: productDates,
  301. // ExpiryDate: expiry_date.Unix(),
  302. // WarehousingCount: warehousing_count,
  303. // Price: price,
  304. // TotalPrice: total,
  305. // Status: 1,
  306. // Ctime: ctime,
  307. // Remark: remark,
  308. // OrgId: adminUserInfo.CurrentOrgId,
  309. // }
  310. // warehousingInfo = append(warehousingInfo, warehouseInfo)
  311. //
  312. // }
  313. // }
  314. // }
  315. // errs := service.CreateWarehousingInfo(warehousingInfo)
  316. // info, _ := service.FindLastWarehousingInfo(warehousing_order)
  317. //
  318. // if (errs != nil) {
  319. // utils.ErrorLog(errs.Error())
  320. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  321. // return
  322. // }
  323. //
  324. // c.ServeSuccessJSON(map[string]interface{}{
  325. // "msg": "入库成功",
  326. // "info": info,
  327. // })
  328. //
  329. //}
  330. }
  331. func (c *StockDrugApiController) GetDrugWarehouseList() {
  332. page, _ := c.GetInt64("page", -1)
  333. limit, _ := c.GetInt64("limit", -1)
  334. start_time := c.GetString("start_time")
  335. end_time := c.GetString("end_time")
  336. types, _ := c.GetInt64("type", 0)
  337. keywords := c.GetString("keywords")
  338. fmt.Println(start_time)
  339. fmt.Println(end_time)
  340. timeLayout := "2006-01-02"
  341. loc, _ := time.LoadLocation("Local")
  342. var startTime int64
  343. if len(start_time) > 0 {
  344. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  345. if err != nil {
  346. fmt.Println(err)
  347. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  348. return
  349. }
  350. startTime = theTime.Unix()
  351. }
  352. var endTime int64
  353. if len(end_time) > 0 {
  354. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  355. if err != nil {
  356. utils.ErrorLog(err.Error())
  357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  358. return
  359. }
  360. endTime = theTime.Unix()
  361. }
  362. adminUserInfo := c.GetAdminUserInfo()
  363. warehouseList, total, err := service.FindAllDrugWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  364. if err == nil {
  365. c.ServeSuccessJSON(map[string]interface{}{
  366. "list": warehouseList,
  367. "total": total,
  368. })
  369. } else {
  370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  371. }
  372. }
  373. func (c *StockDrugApiController) GetDrugWarehouseInfoList() {
  374. id, _ := c.GetInt64("id", 0)
  375. if id <= 0 {
  376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  377. return
  378. }
  379. admin := c.GetAdminUserInfo()
  380. warehousing, err := service.FindDrugWarehousingById(id, admin.CurrentOrgId)
  381. if err != nil {
  382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  383. return
  384. }
  385. if warehousing.ID <= 0 {
  386. return
  387. }
  388. warehousingInfo, err := service.FindDrugWarehousingInfoById(id, admin.CurrentOrgId)
  389. if err == nil {
  390. c.ServeSuccessJSON(map[string]interface{}{
  391. "info": warehousingInfo,
  392. "warehousing": warehousing,
  393. })
  394. } else {
  395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  396. }
  397. }
  398. func (c *StockDrugApiController) EditDrugWarehouse() {
  399. warehousing_time := c.GetString("warehousing_time")
  400. id, _ := c.GetInt64("id", 0)
  401. types, _ := c.GetInt64("type", 0)
  402. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  403. dealer_id, _ := c.GetInt64("dealer_id", 0)
  404. if id == 0 {
  405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  406. return
  407. }
  408. ctime := time.Now().Unix()
  409. mtime := time.Now().Unix()
  410. adminUserInfo := c.GetAdminUserInfo()
  411. warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
  412. if parseDateErr != nil {
  413. c.ErrorLog("日期(%v)解析错误:%v", warehousingDate, parseDateErr)
  414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  415. return
  416. }
  417. warehouse, _ := service.FindDrugWarehousingById(id, adminUserInfo.CurrentOrgId)
  418. warehousing := models.DrugWarehouse{
  419. WarehousingOrder: warehouse.WarehousingOrder,
  420. OrgId: adminUserInfo.CurrentOrgId,
  421. Modifier: adminUserInfo.AdminUser.Id,
  422. Mtime: mtime,
  423. Status: 1,
  424. WarehousingTime: warehousingDate.Unix(),
  425. Type: warehouse.Type,
  426. Dealer: dealer_id,
  427. Manufacturer: manufacturer_id,
  428. }
  429. service.EditDrugWarehousing(warehousing)
  430. dataBody := make(map[string]interface{}, 0)
  431. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  432. if err != nil {
  433. utils.ErrorLog(err.Error())
  434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  435. return
  436. }
  437. var warehousingInfo []*models.DrugWarehouseInfo
  438. var upDateWarehousingInfo []*models.DrugWarehouseInfo
  439. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  440. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  441. if len(thisStockIn) > 0 {
  442. for _, item := range thisStockIn {
  443. items := item.(map[string]interface{})
  444. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  445. utils.ErrorLog("drug_id")
  446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  447. return
  448. }
  449. drug_id := int64(items["drug_id"].(float64))
  450. if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
  451. utils.ErrorLog("warehousing_count")
  452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  453. return
  454. }
  455. warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
  456. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  457. utils.ErrorLog("price")
  458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  459. return
  460. }
  461. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  462. total := float64(warehousing_count) * price
  463. var productDates int64
  464. var expiryDates int64
  465. fmt.Println()
  466. if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
  467. expiryDates = 0
  468. } else {
  469. if len(items["expiry_date"].(string)) == 0 {
  470. expiryDates = 0
  471. } else {
  472. expiryDate, _ := items["expiry_date"].(string)
  473. expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
  474. expiryDates = expiry_date.Unix()
  475. }
  476. }
  477. if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
  478. productDates = 0
  479. } else {
  480. if len(items["product_date"].(string)) == 0 {
  481. productDates = 0
  482. } else {
  483. productDate, _ := items["product_date"].(string)
  484. product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
  485. productDates = product_date.Unix()
  486. }
  487. }
  488. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  489. utils.ErrorLog("number")
  490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  491. return
  492. }
  493. number, _ := items["number"].(string)
  494. var remark string
  495. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  496. remark = ""
  497. } else {
  498. remark = items["remark"].(string)
  499. }
  500. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  501. utils.ErrorLog("id")
  502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  503. return
  504. }
  505. id := int64(items["id"].(float64))
  506. if id == 0 {
  507. warehouseInfo := &models.DrugWarehouseInfo{
  508. WarehousingOrder: warehouse.WarehousingOrder,
  509. WarehousingId: warehouse.ID,
  510. DrugId: drug_id,
  511. Number: number,
  512. ProductDate: productDates,
  513. ExpiryDate: expiryDates,
  514. WarehousingCount: warehousing_count,
  515. Price: price,
  516. TotalPrice: total,
  517. Status: 1,
  518. Ctime: ctime,
  519. Remark: remark,
  520. OrgId: adminUserInfo.CurrentOrgId,
  521. Type: types,
  522. Manufacturer: manufacturer_id,
  523. Dealer: dealer_id,
  524. }
  525. warehousingInfo = append(warehousingInfo, warehouseInfo)
  526. } else {
  527. warehouseInfo := &models.DrugWarehouseInfo{
  528. ID: id,
  529. WarehousingOrder: warehouse.WarehousingOrder,
  530. WarehousingId: warehouse.ID,
  531. DrugId: drug_id,
  532. Number: number,
  533. ProductDate: productDates,
  534. ExpiryDate: expiryDates,
  535. WarehousingCount: warehousing_count,
  536. Price: price,
  537. TotalPrice: total,
  538. Status: 1,
  539. Ctime: ctime,
  540. Remark: remark,
  541. OrgId: adminUserInfo.CurrentOrgId,
  542. Type: types,
  543. Manufacturer: manufacturer_id,
  544. Dealer: dealer_id,
  545. }
  546. upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
  547. }
  548. }
  549. }
  550. }
  551. var errs error
  552. if len(warehousingInfo) > 0 {
  553. errs = service.CreateDrugWarehousingInfo(warehousingInfo)
  554. }
  555. if len(upDateWarehousingInfo) > 0 {
  556. for _, item := range upDateWarehousingInfo {
  557. errs = service.UpDateDrugWarehousingInfo(item)
  558. }
  559. }
  560. if errs != nil {
  561. utils.ErrorLog(errs.Error())
  562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  563. return
  564. }
  565. c.ServeSuccessJSON(map[string]interface{}{
  566. "msg": "编辑成功",
  567. })
  568. }
  569. func (c *StockDrugApiController) DeleteDrugWarehouse() {
  570. ids := c.GetString("ids")
  571. if len(ids) == 0 {
  572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  573. return
  574. }
  575. idArray := strings.Split(ids, ",")
  576. err := service.DeleteDrugWarehouse(idArray)
  577. if err != nil {
  578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  579. } else {
  580. c.ServeSuccessJSON(map[string]interface{}{
  581. "msg": "删除成功",
  582. })
  583. }
  584. }
  585. func (c *StockDrugApiController) DeleteDrugWarehouseInfo() {
  586. id, _ := c.GetInt64("id", 0)
  587. if id == 0 {
  588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  589. return
  590. }
  591. err := service.UpDateDrugWarehouseStatus(id)
  592. if err != nil {
  593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  594. } else {
  595. c.ServeSuccessJSON(map[string]interface{}{
  596. "msg": "删除成功",
  597. })
  598. }
  599. }
  600. func (c *StockDrugApiController) CreateDrugSalesReturn() {
  601. dealer_id, _ := c.GetInt64("dealer_id", 0)
  602. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  603. sales_return_time := c.GetString("time")
  604. types, _ := c.GetInt64("type", 0)
  605. salesReturnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", sales_return_time)
  606. if parseDateErr != nil {
  607. c.ErrorLog("日期(%v)解析错误:%v", salesReturnDate, parseDateErr)
  608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  609. return
  610. }
  611. adminUserInfo := c.GetAdminUserInfo()
  612. operation_time := time.Now().Unix()
  613. creater := adminUserInfo.AdminUser.Id
  614. ctime := time.Now().Unix()
  615. timeStr := time.Now().Format("2006-01-02")
  616. timeArr := strings.Split(timeStr, "-")
  617. total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
  618. total = total + 1
  619. orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  620. salesReturn := models.DrugSalesReturn{
  621. OrderNumber: orderNumber,
  622. OperaTime: operation_time,
  623. OrgId: adminUserInfo.CurrentOrgId,
  624. Creater: creater,
  625. Ctime: ctime,
  626. Status: 1,
  627. ReturnTime: salesReturnDate.Unix(),
  628. Dealer: dealer_id,
  629. Manufacturer: manufacturer_id,
  630. Type: types,
  631. }
  632. service.AddSigleDrugSalesReturn(&salesReturn)
  633. dataBody := make(map[string]interface{}, 0)
  634. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  635. if err != nil {
  636. utils.ErrorLog(err.Error())
  637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  638. return
  639. }
  640. var salesReturnInfos []*models.DrugSalesReturnInfo
  641. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  642. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  643. if len(thisStockIn) > 0 {
  644. for _, item := range thisStockIn {
  645. items := item.(map[string]interface{})
  646. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  647. utils.ErrorLog("drug_id")
  648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  649. return
  650. }
  651. drug_id := int64(items["drug_id"].(float64))
  652. return_count, _ := items["return_count"].(string)
  653. if len(return_count) == 0 {
  654. utils.ErrorLog("len(return_count) == 0")
  655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  656. return
  657. }
  658. count, _ := strconv.ParseInt(return_count, 10, 64)
  659. price, _ := strconv.ParseFloat(items["price"].(string), 10)
  660. total := float64(count) * 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. }
  675. salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
  676. }
  677. }
  678. }
  679. errs := service.CreateDrugSalesReturnInfo(salesReturnInfos)
  680. if errs != nil {
  681. utils.ErrorLog(errs.Error())
  682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  683. return
  684. }
  685. c.ServeSuccessJSON(map[string]interface{}{
  686. "msg": "退货成功",
  687. })
  688. }
  689. func (c *StockDrugApiController) GetDrugSalesReturnList() {
  690. page, _ := c.GetInt64("page", -1)
  691. limit, _ := c.GetInt64("limit", -1)
  692. start_time := c.GetString("start_time")
  693. end_time := c.GetString("end_time")
  694. types, _ := c.GetInt64("type", 0)
  695. keywords := c.GetString("keywords")
  696. timeLayout := "2006-01-02"
  697. loc, _ := time.LoadLocation("Local")
  698. var startTime int64
  699. if len(start_time) > 0 {
  700. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  701. if err != nil {
  702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  703. return
  704. }
  705. startTime = theTime.Unix()
  706. }
  707. var endTime int64
  708. if len(end_time) > 0 {
  709. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  710. if err != nil {
  711. utils.ErrorLog(err.Error())
  712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  713. return
  714. }
  715. endTime = theTime.Unix()
  716. }
  717. adminUserInfo := c.GetAdminUserInfo()
  718. returnList, total, err := service.FindAllDrugReturnList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  719. if err == nil {
  720. c.ServeSuccessJSON(map[string]interface{}{
  721. "list": returnList,
  722. "total": total,
  723. })
  724. } else {
  725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  726. }
  727. }
  728. func (this *StockDrugApiController) DeleteDrugSalesReturn() {
  729. ids := this.GetString("ids")
  730. if len(ids) == 0 {
  731. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  732. return
  733. }
  734. idArray := strings.Split(ids, ",")
  735. err := service.DeleteDrugSalesReturn(idArray)
  736. if err != nil {
  737. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  738. } else {
  739. this.ServeSuccessJSON(map[string]interface{}{
  740. "msg": "删除成功",
  741. })
  742. }
  743. }
  744. func (this *StockDrugApiController) DeleteDrugSalesReturnInfo() {
  745. id, _ := this.GetInt64("id", 0)
  746. fmt.Println(id)
  747. if id == 0 {
  748. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  749. return
  750. }
  751. err := service.UpDateDrugSaleReturnStatus(id)
  752. if err != nil {
  753. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  754. } else {
  755. this.ServeSuccessJSON(map[string]interface{}{
  756. "msg": "删除成功",
  757. })
  758. }
  759. }
  760. func (this *StockDrugApiController) GetDrugSalesReturnInfoList() {
  761. id, _ := this.GetInt64("id", 0)
  762. list, _ := service.FindAllDrugSalesReturnInfoById(id)
  763. salesReturn, _ := service.FindAllDrugSalesReturnById(id)
  764. this.ServeSuccessJSON(map[string]interface{}{
  765. "list": list,
  766. "salesReturn": salesReturn,
  767. })
  768. }
  769. func (c *StockDrugApiController) EditDrugReturnInfo() {
  770. return_time := c.GetString("return_time")
  771. id, _ := c.GetInt64("id", 0)
  772. types, _ := c.GetInt64("type", 0)
  773. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  774. dealer_id, _ := c.GetInt64("dealer_id", 0)
  775. if id == 0 {
  776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  777. return
  778. }
  779. ctime := time.Now().Unix()
  780. mtime := time.Now().Unix()
  781. adminUserInfo := c.GetAdminUserInfo()
  782. returnDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", return_time)
  783. if parseDateErr != nil {
  784. c.ErrorLog("日期(%v)解析错误:%v", returnDate, parseDateErr)
  785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  786. return
  787. }
  788. salesReturns, _ := service.FindDrugSalesReturnById(id)
  789. sales := models.DrugSalesReturn{
  790. ID: salesReturns.ID,
  791. Mtime: mtime,
  792. ReturnTime: returnDate.Unix(),
  793. Manufacturer: manufacturer_id,
  794. Dealer: dealer_id,
  795. }
  796. service.EditDrugSaleReturn(sales)
  797. dataBody := make(map[string]interface{}, 0)
  798. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  799. if err != nil {
  800. utils.ErrorLog(err.Error())
  801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  802. return
  803. }
  804. var returnInfos []*models.DrugSalesReturnInfo
  805. var upDateReturnInfos []*models.DrugSalesReturnInfo
  806. if dataBody["salesReturn"] != nil && reflect.TypeOf(dataBody["salesReturn"]).String() == "[]interface {}" {
  807. thisStockIn, _ := dataBody["salesReturn"].([]interface{})
  808. if len(thisStockIn) > 0 {
  809. for _, item := range thisStockIn {
  810. items := item.(map[string]interface{})
  811. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  812. utils.ErrorLog("drug_id")
  813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  814. return
  815. }
  816. drug_id := int64(items["drug_id"].(float64))
  817. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  818. utils.ErrorLog("count")
  819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  820. return
  821. }
  822. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  823. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  824. utils.ErrorLog("id")
  825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  826. return
  827. }
  828. id := int64(items["id"].(float64))
  829. if id == 0 {
  830. returnInfo := &models.DrugSalesReturnInfo{
  831. DrugId: drug_id,
  832. Count: count,
  833. Status: 1,
  834. Ctime: ctime,
  835. OrgId: adminUserInfo.CurrentOrgId,
  836. OrderNumber: sales.OrderNumber,
  837. SalesReturnId: sales.ID,
  838. Mtime: time.Now().Unix(),
  839. Type: types,
  840. Manufacturer: manufacturer_id,
  841. Dealer: dealer_id,
  842. }
  843. returnInfos = append(returnInfos, returnInfo)
  844. } else {
  845. returnInfo := &models.DrugSalesReturnInfo{
  846. ID: id,
  847. DrugId: drug_id,
  848. Count: count,
  849. Status: 1,
  850. Ctime: ctime,
  851. OrgId: adminUserInfo.CurrentOrgId,
  852. OrderNumber: sales.OrderNumber,
  853. SalesReturnId: sales.ID,
  854. Mtime: time.Now().Unix(),
  855. Type: types,
  856. Manufacturer: manufacturer_id,
  857. Dealer: dealer_id,
  858. }
  859. upDateReturnInfos = append(upDateReturnInfos, returnInfo)
  860. }
  861. }
  862. }
  863. }
  864. var errs error
  865. if len(returnInfos) > 0 {
  866. errs = service.CreateDrugSalesReturnInfo(returnInfos)
  867. }
  868. if len(upDateReturnInfos) > 0 {
  869. for _, item := range upDateReturnInfos {
  870. errs = service.UpDateDrugSalesReturnInfo(item)
  871. }
  872. }
  873. if errs != nil {
  874. utils.ErrorLog(errs.Error())
  875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  876. return
  877. }
  878. c.ServeSuccessJSON(map[string]interface{}{
  879. "msg": "编辑成功",
  880. })
  881. }
  882. func (c *StockDrugApiController) CreateDrugWarehouseOut() {
  883. dealer_id, _ := c.GetInt64("dealer_id", 0)
  884. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  885. types, _ := c.GetInt64("type", 0)
  886. ctime := time.Now().Unix()
  887. adminUserInfo := c.GetAdminUserInfo()
  888. warehousing_out_time := c.GetString("warehousing_out_time")
  889. warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
  890. if parseDateErr != nil {
  891. c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
  892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  893. return
  894. }
  895. timeStr := time.Now().Format("2006-01-02")
  896. timeArr := strings.Split(timeStr, "-")
  897. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  898. total = total + 1
  899. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  900. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  901. number = number + total
  902. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  903. operation_time := time.Now().Unix()
  904. creater := adminUserInfo.AdminUser.Id
  905. warehouseOut := models.DrugWarehouseOut{
  906. WarehouseOutOrderNumber: warehousing_out_order,
  907. OperationTime: operation_time,
  908. OrgId: adminUserInfo.CurrentOrgId,
  909. Creater: creater,
  910. Ctime: ctime,
  911. Status: 1,
  912. WarehouseOutTime: warehousingOutDate.Unix(),
  913. Dealer: dealer_id,
  914. Manufacturer: manufacturer_id,
  915. Type: types,
  916. }
  917. service.AddSigleDrugWarehouseOut(&warehouseOut)
  918. dataBody := make(map[string]interface{}, 0)
  919. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  920. if err != nil {
  921. utils.ErrorLog(err.Error())
  922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  923. return
  924. }
  925. var warehousingOutInfo []*models.DrugWarehouseOutInfo
  926. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  927. thisStockIn, _ := dataBody["stockOut"].([]interface{})
  928. if len(thisStockIn) > 0 {
  929. for _, item := range thisStockIn {
  930. items := item.(map[string]interface{})
  931. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  932. utils.ErrorLog("drug_id")
  933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  934. return
  935. }
  936. drug_id := int64(items["drug_id"].(float64))
  937. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  938. utils.ErrorLog("count")
  939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  940. return
  941. }
  942. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  943. utils.ErrorLog("price")
  944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  945. return
  946. }
  947. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  948. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  949. total := float64(count) * price
  950. remark := items["remark"].(string)
  951. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  952. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  953. WarehouseOutId: warehouseOut.ID,
  954. DrugId: drug_id,
  955. Count: count,
  956. Price: price,
  957. TotalPrice: total,
  958. Status: 1,
  959. Ctime: ctime,
  960. Remark: remark,
  961. OrgId: adminUserInfo.CurrentOrgId,
  962. Type: types,
  963. Manufacturer: manufacturer_id,
  964. Dealer: dealer_id,
  965. }
  966. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  967. }
  968. }
  969. }
  970. errs := service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
  971. info, _ := service.FindLastDrugWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
  972. if errs != nil {
  973. utils.ErrorLog(errs.Error())
  974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  975. return
  976. }
  977. c.ServeSuccessJSON(map[string]interface{}{
  978. "msg": "出库成功",
  979. "info": info,
  980. "warehousing_out_order": warehousing_out_order,
  981. })
  982. }
  983. func (c *StockDrugApiController) GetDrugWarehouseOutList() {
  984. page, _ := c.GetInt64("page", -1)
  985. limit, _ := c.GetInt64("limit", -1)
  986. start_time := c.GetString("start_time")
  987. end_time := c.GetString("end_time")
  988. types, _ := c.GetInt64("type", 0)
  989. keywords := c.GetString("keywords")
  990. timeLayout := "2006-01-02"
  991. loc, _ := time.LoadLocation("Local")
  992. var startTime int64
  993. if len(start_time) > 0 {
  994. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  995. if err != nil {
  996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  997. return
  998. }
  999. startTime = theTime.Unix()
  1000. }
  1001. var endTime int64
  1002. if len(end_time) > 0 {
  1003. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1004. if err != nil {
  1005. utils.ErrorLog(err.Error())
  1006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1007. return
  1008. }
  1009. endTime = theTime.Unix()
  1010. }
  1011. adminUserInfo := c.GetAdminUserInfo()
  1012. warehouseOutList, total, err := service.FindAllDrugWarehouseOutList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1013. fmt.Println(err)
  1014. if err == nil {
  1015. c.ServeSuccessJSON(map[string]interface{}{
  1016. "list": warehouseOutList,
  1017. "total": total,
  1018. })
  1019. } else {
  1020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1021. }
  1022. }
  1023. func (c *StockDrugApiController) DeleteDrugWarehouseOut() {
  1024. ids := c.GetString("ids")
  1025. if len(ids) == 0 {
  1026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1027. return
  1028. }
  1029. idArray := strings.Split(ids, ",")
  1030. err := service.DeleteDrugWarehouseOut(idArray)
  1031. if err != nil {
  1032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1033. } else {
  1034. c.ServeSuccessJSON(map[string]interface{}{
  1035. "msg": "删除成功",
  1036. })
  1037. }
  1038. }
  1039. func (this *StockDrugApiController) DeleteDrugWarehouseOutInfo() {
  1040. id, _ := this.GetInt64("id", 0)
  1041. fmt.Println(id)
  1042. if id == 0 {
  1043. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1044. return
  1045. }
  1046. err := service.UpDateDrugWarehouseOutStatus(id)
  1047. if err != nil {
  1048. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1049. } else {
  1050. this.ServeSuccessJSON(map[string]interface{}{
  1051. "msg": "删除成功",
  1052. })
  1053. }
  1054. }
  1055. func (c *StockDrugApiController) GetDrugWarehouseOutInfoList() {
  1056. id, _ := c.GetInt64("id", 0)
  1057. warehouseOutInfo, _ := service.FindDrugWarehouseOutInfoById(id)
  1058. warehouseOut, _ := service.FindDrugWareHouseOutById(id)
  1059. c.ServeSuccessJSON(map[string]interface{}{
  1060. "list": warehouseOutInfo,
  1061. "info": warehouseOut,
  1062. })
  1063. }
  1064. func (c *StockDrugApiController) EditDrugWarehouseOut() {
  1065. warehouse_out_time := c.GetString("warehouse_out_time")
  1066. id, _ := c.GetInt64("id", 0)
  1067. types, _ := c.GetInt64("type", 0)
  1068. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1069. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1070. if id == 0 {
  1071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1072. return
  1073. }
  1074. ctime := time.Now().Unix()
  1075. mtime := time.Now().Unix()
  1076. adminUserInfo := c.GetAdminUserInfo()
  1077. warehouseOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
  1078. if parseDateErr != nil {
  1079. c.ErrorLog("日期(%v)解析错误:%v", warehouseOutDate, parseDateErr)
  1080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1081. return
  1082. }
  1083. warehouseOut, _ := service.FindDrugWareHouseOutById(id)
  1084. tempWarehouseOut := models.DrugWarehouseOut{
  1085. ID: warehouseOut.ID,
  1086. Mtime: mtime,
  1087. WarehouseOutTime: warehouseOutDate.Unix(),
  1088. Manufacturer: manufacturer_id,
  1089. Dealer: dealer_id,
  1090. }
  1091. service.EditDrugWarehouseOut(tempWarehouseOut)
  1092. dataBody := make(map[string]interface{}, 0)
  1093. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1094. if err != nil {
  1095. utils.ErrorLog(err.Error())
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. var warehousingOutInfo []*models.DrugWarehouseOutInfo
  1100. var upDateWarehouseOutInfos []*models.DrugWarehouseOutInfo
  1101. if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
  1102. thisStockOut, _ := dataBody["stockOut"].([]interface{})
  1103. if len(thisStockOut) > 0 {
  1104. for _, item := range thisStockOut {
  1105. items := item.(map[string]interface{})
  1106. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1107. utils.ErrorLog("drug_id")
  1108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1109. return
  1110. }
  1111. drug_id := int64(items["drug_id"].(float64))
  1112. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1113. utils.ErrorLog("count")
  1114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1115. return
  1116. }
  1117. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1118. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  1119. utils.ErrorLog("price")
  1120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1121. return
  1122. }
  1123. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1124. total := float64(count) * price
  1125. remark := items["remark"].(string)
  1126. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1127. utils.ErrorLog("id")
  1128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1129. return
  1130. }
  1131. id := int64(items["id"].(float64))
  1132. if id == 0 {
  1133. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1134. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1135. WarehouseOutId: warehouseOut.ID,
  1136. DrugId: drug_id,
  1137. Count: count,
  1138. Price: price,
  1139. TotalPrice: total,
  1140. Status: 1,
  1141. Ctime: ctime,
  1142. Remark: remark,
  1143. OrgId: adminUserInfo.CurrentOrgId,
  1144. Type: types,
  1145. Manufacturer: manufacturer_id,
  1146. Dealer: dealer_id,
  1147. IsSys: 0,
  1148. SysRecordTime: 0,
  1149. }
  1150. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1151. } else {
  1152. if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
  1153. utils.ErrorLog("is_sys")
  1154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1155. return
  1156. }
  1157. is_sys := int64(items["is_sys"].(float64))
  1158. if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
  1159. utils.ErrorLog("sys_record_time")
  1160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1161. return
  1162. }
  1163. sys_record_time := int64(items["sys_record_time"].(float64))
  1164. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  1165. ID: id,
  1166. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  1167. WarehouseOutId: warehouseOut.ID,
  1168. DrugId: drug_id,
  1169. Count: count,
  1170. Price: price,
  1171. TotalPrice: total,
  1172. Status: 1,
  1173. Ctime: ctime,
  1174. Remark: remark,
  1175. OrgId: adminUserInfo.CurrentOrgId,
  1176. Mtime: time.Now().Unix(),
  1177. Type: types,
  1178. Manufacturer: manufacturer_id,
  1179. Dealer: dealer_id,
  1180. IsSys: is_sys,
  1181. SysRecordTime: sys_record_time,
  1182. }
  1183. upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
  1184. }
  1185. }
  1186. }
  1187. }
  1188. var errs error
  1189. if len(warehousingOutInfo) > 0 {
  1190. errs = service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
  1191. }
  1192. if len(upDateWarehouseOutInfos) > 0 {
  1193. for _, item := range upDateWarehouseOutInfos {
  1194. errs = service.UpDateDrugWarehouseOutInfo(item)
  1195. }
  1196. }
  1197. if errs != nil {
  1198. utils.ErrorLog(errs.Error())
  1199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1200. return
  1201. }
  1202. c.ServeSuccessJSON(map[string]interface{}{
  1203. "msg": "编辑成功",
  1204. })
  1205. }
  1206. func (c *StockDrugApiController) CreateDrugCancelStock() {
  1207. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1208. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1209. cancel_stock_time := c.GetString("time")
  1210. types, _ := c.GetInt64("type", 0)
  1211. cancelStockDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_stock_time)
  1212. if parseDateErr != nil {
  1213. c.ErrorLog("日期(%v)解析错误:%v", cancelStockDate, parseDateErr)
  1214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1215. return
  1216. }
  1217. adminUserInfo := c.GetAdminUserInfo()
  1218. operation_time := time.Now().Unix()
  1219. creater := adminUserInfo.AdminUser.Id
  1220. ctime := time.Now().Unix()
  1221. timeStr := time.Now().Format("2006-01-02")
  1222. timeArr := strings.Split(timeStr, "-")
  1223. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1224. total = total + 1
  1225. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1226. cancelStock := models.DrugCancelStock{
  1227. OrderNumber: orderNumber,
  1228. OperaTime: operation_time,
  1229. OrgId: adminUserInfo.CurrentOrgId,
  1230. Creater: creater,
  1231. Ctime: ctime,
  1232. Status: 1,
  1233. ReturnTime: cancelStockDate.Unix(),
  1234. Dealer: dealer_id,
  1235. Manufacturer: manufacturer_id,
  1236. Type: types,
  1237. }
  1238. service.AddSigleDrugCancelStock(&cancelStock)
  1239. dataBody := make(map[string]interface{}, 0)
  1240. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1241. if err != nil {
  1242. utils.ErrorLog(err.Error())
  1243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1244. return
  1245. }
  1246. var cancelStockInfos []*models.DrugCancelStockInfo
  1247. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1248. thisStockIn, _ := dataBody["cancelStock"].([]interface{})
  1249. if len(thisStockIn) > 0 {
  1250. for _, item := range thisStockIn {
  1251. items := item.(map[string]interface{})
  1252. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1253. utils.ErrorLog("drug_id")
  1254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1255. return
  1256. }
  1257. drug_id := int64(items["drug_id"].(float64))
  1258. return_count, _ := items["return_count"].(string)
  1259. if len(return_count) == 0 {
  1260. utils.ErrorLog("len(return_count) == 0")
  1261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1262. return
  1263. }
  1264. count, _ := strconv.ParseInt(return_count, 10, 64)
  1265. cancelStockInfo := &models.DrugCancelStockInfo{
  1266. OrderNumber: cancelStock.OrderNumber,
  1267. CancelStockId: cancelStock.ID,
  1268. DrugId: drug_id,
  1269. Count: count,
  1270. Status: 1,
  1271. Ctime: ctime,
  1272. OrgId: adminUserInfo.CurrentOrgId,
  1273. Type: types,
  1274. Manufacturer: manufacturer_id,
  1275. Dealer: dealer_id,
  1276. }
  1277. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1278. }
  1279. }
  1280. }
  1281. errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
  1282. if errs != nil {
  1283. utils.ErrorLog(errs.Error())
  1284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
  1285. return
  1286. }
  1287. c.ServeSuccessJSON(map[string]interface{}{
  1288. "msg": "退库成功",
  1289. })
  1290. }
  1291. func (c *StockDrugApiController) GetDrugCancelStockInfoList() {
  1292. id, _ := c.GetInt64("id", 0)
  1293. cancelStockInfoList, _ := service.FindDrugCancelStockInfoById(id)
  1294. info, _ := service.FindCancelStockById(id)
  1295. c.ServeSuccessJSON(map[string]interface{}{
  1296. "list": cancelStockInfoList,
  1297. "info": info,
  1298. })
  1299. }
  1300. func (c *StockDrugApiController) GetDrugCancelStockList() {
  1301. page, _ := c.GetInt64("page", -1)
  1302. limit, _ := c.GetInt64("limit", -1)
  1303. start_time := c.GetString("start_time")
  1304. end_time := c.GetString("end_time")
  1305. types, _ := c.GetInt64("type", 0)
  1306. keywords := c.GetString("keywords")
  1307. timeLayout := "2006-01-02"
  1308. loc, _ := time.LoadLocation("Local")
  1309. var startTime int64
  1310. if len(start_time) > 0 {
  1311. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1312. if err != nil {
  1313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1314. return
  1315. }
  1316. startTime = theTime.Unix()
  1317. }
  1318. var endTime int64
  1319. if len(end_time) > 0 {
  1320. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1321. if err != nil {
  1322. utils.ErrorLog(err.Error())
  1323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1324. return
  1325. }
  1326. endTime = theTime.Unix()
  1327. }
  1328. adminUserInfo := c.GetAdminUserInfo()
  1329. returnList, total, err := service.FindAllDrugCancelList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
  1330. if err == nil {
  1331. c.ServeSuccessJSON(map[string]interface{}{
  1332. "list": returnList,
  1333. "total": total,
  1334. })
  1335. } else {
  1336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1337. }
  1338. }
  1339. func (this *StockDrugApiController) DeleteDrugCancelStock() {
  1340. ids := this.GetString("ids")
  1341. if len(ids) == 0 {
  1342. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1343. return
  1344. }
  1345. idArray := strings.Split(ids, ",")
  1346. err := service.DeleteDrugCancelStock(idArray)
  1347. if err != nil {
  1348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1349. } else {
  1350. this.ServeSuccessJSON(map[string]interface{}{
  1351. "msg": "删除成功",
  1352. })
  1353. }
  1354. }
  1355. func (this *StockDrugApiController) DeleteDrugCancelStockInfo() {
  1356. id, _ := this.GetInt64("id", 0)
  1357. fmt.Println(id)
  1358. if id == 0 {
  1359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1360. return
  1361. }
  1362. err := service.UpDateDrugCancleStockStatus(id)
  1363. if err != nil {
  1364. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
  1365. } else {
  1366. this.ServeSuccessJSON(map[string]interface{}{
  1367. "msg": "删除成功",
  1368. })
  1369. }
  1370. }
  1371. func (c *StockDrugApiController) EditDrugCancelStock() {
  1372. cancel_time := c.GetString("cancel_time")
  1373. id, _ := c.GetInt64("id", 0)
  1374. types, _ := c.GetInt64("type", 0)
  1375. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1376. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1377. if id == 0 {
  1378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1379. return
  1380. }
  1381. ctime := time.Now().Unix()
  1382. mtime := time.Now().Unix()
  1383. adminUserInfo := c.GetAdminUserInfo()
  1384. cancelDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", cancel_time)
  1385. if parseDateErr != nil {
  1386. c.ErrorLog("日期(%v)解析错误:%v", cancelDate, parseDateErr)
  1387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1388. return
  1389. }
  1390. cancelStock, _ := service.FindDrugCancelStockById(id)
  1391. tempCancelStock := models.DrugCancelStock{
  1392. ID: cancelStock.ID,
  1393. Mtime: mtime,
  1394. ReturnTime: cancelDate.Unix(),
  1395. Manufacturer: manufacturer_id,
  1396. Dealer: dealer_id,
  1397. }
  1398. service.EditDrugCancelStock(tempCancelStock)
  1399. dataBody := make(map[string]interface{}, 0)
  1400. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1401. if err != nil {
  1402. utils.ErrorLog(err.Error())
  1403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1404. return
  1405. }
  1406. var cancelStockInfos []*models.DrugCancelStockInfo
  1407. var upDateCancelStockInfos []*models.DrugCancelStockInfo
  1408. if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
  1409. thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
  1410. if len(thisCancelStock) > 0 {
  1411. for _, item := range thisCancelStock {
  1412. items := item.(map[string]interface{})
  1413. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1414. utils.ErrorLog("drug_id")
  1415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1416. return
  1417. }
  1418. drug_id := int64(items["drug_id"].(float64))
  1419. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  1420. utils.ErrorLog("count")
  1421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1422. return
  1423. }
  1424. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  1425. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1426. utils.ErrorLog("id")
  1427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1428. return
  1429. }
  1430. id := int64(items["id"].(float64))
  1431. if id == 0 {
  1432. cancelStockInfo := &models.DrugCancelStockInfo{
  1433. DrugId: drug_id,
  1434. Count: count,
  1435. Status: 1,
  1436. Ctime: ctime,
  1437. OrgId: adminUserInfo.CurrentOrgId,
  1438. OrderNumber: cancelStock.OrderNumber,
  1439. CancelStockId: cancelStock.ID,
  1440. Mtime: time.Now().Unix(),
  1441. Type: types,
  1442. Manufacturer: manufacturer_id,
  1443. Dealer: dealer_id,
  1444. }
  1445. cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
  1446. } else {
  1447. cancelStockInfo := &models.DrugCancelStockInfo{
  1448. ID: id,
  1449. DrugId: drug_id,
  1450. Count: count,
  1451. Status: 1,
  1452. Ctime: ctime,
  1453. OrgId: adminUserInfo.CurrentOrgId,
  1454. OrderNumber: cancelStock.OrderNumber,
  1455. CancelStockId: cancelStock.ID,
  1456. Mtime: time.Now().Unix(),
  1457. Type: types,
  1458. Manufacturer: manufacturer_id,
  1459. Dealer: dealer_id,
  1460. }
  1461. upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
  1462. }
  1463. }
  1464. }
  1465. }
  1466. var errs error
  1467. if len(cancelStockInfos) > 0 {
  1468. errs = service.CreateDrugCancelStockInfo(cancelStockInfos)
  1469. }
  1470. if len(upDateCancelStockInfos) > 0 {
  1471. for _, item := range upDateCancelStockInfos {
  1472. errs = service.UpDateDrugCancelStockInfo(item)
  1473. }
  1474. }
  1475. if errs != nil {
  1476. utils.ErrorLog(errs.Error())
  1477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  1478. return
  1479. }
  1480. c.ServeSuccessJSON(map[string]interface{}{
  1481. "msg": "编辑成功",
  1482. })
  1483. }
  1484. func (c *StockDrugApiController) GetAllConfig() {
  1485. adminUserInfo := c.GetAdminUserInfo()
  1486. manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  1487. dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  1488. drugs, _ := service.GetDrugs(adminUserInfo.CurrentOrgId)
  1489. c.ServeSuccessJSON(map[string]interface{}{
  1490. "manufacturer": manufacturer,
  1491. "dealer": dealer,
  1492. "drugs": drugs,
  1493. })
  1494. }
  1495. func (c *StockDrugApiController) GetAllDrugStock() {
  1496. adminUserInfo := c.GetAdminUserInfo()
  1497. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  1498. dealer_id, _ := c.GetInt64("dealer_id", 0)
  1499. drugs, err := service.FindAllDrugByManufactureId(manufacturer_id, dealer_id, adminUserInfo.CurrentOrgId)
  1500. if err == nil {
  1501. c.ServeSuccessJSON(map[string]interface{}{
  1502. "drugs": drugs,
  1503. })
  1504. } else {
  1505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1506. }
  1507. }