drug_stock_api_contorller.go 62KB

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