supply_order_api_contorller.go 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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 SupplyOrderApiController struct {
  16. BaseAuthAPIController
  17. }
  18. func SupplyOrderApiRegistRouters() {
  19. beego.Router("/api/supply/getinitorder", &SupplyOrderApiController{}, "get:GetInitOrder")
  20. beego.Router("/api/supply/savepurchaseorder", &SupplyOrderApiController{}, "post:SavePurchaseOrder")
  21. beego.Router("/api/supply/getallsupply", &SupplyOrderApiController{}, "get:GetAllSupply")
  22. beego.Router("/api/supply/getallpurchaseorderlist", &SupplyOrderApiController{}, "get:GetAllPurchaseOrderList")
  23. beego.Router("/api/supply/updatepurchaseorder", &SupplyOrderApiController{}, "Post:UpdatePurchaseOrder")
  24. beego.Router("/api/supply/checkpurchaseorder", &SupplyOrderApiController{}, "get:UpdateSupplyWaresing")
  25. beego.Router("/api/supply/getpurchaseorderdetail", &SupplyOrderApiController{}, "get:GetPurchaseOrderDetail")
  26. beego.Router("/api/supply/addgoodorder", &SupplyOrderApiController{}, "post:AddGoodOrder")
  27. }
  28. func (this *SupplyOrderApiController) GetInitOrder() {
  29. orgId := this.GetAdminUserInfo().CurrentOrgId
  30. //获取药品库数据
  31. baseList, _ := service.GetSupplyDrugList(orgId)
  32. goodList, _ := service.GetSupplyGoodList(orgId)
  33. manufactuerList, _ := service.GetAllManufacturerList(orgId)
  34. goodTypeList, _ := service.GetAllGoodType(orgId)
  35. supplyList, _ := service.GetSupplierList(orgId)
  36. var drugType = "药品类型"
  37. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  38. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  39. this.ServeSuccessJSON(map[string]interface{}{
  40. "drugList": baseList,
  41. "goodList": goodList,
  42. "manufactuerList": manufactuerList,
  43. "goodTypeList": goodTypeList,
  44. "drugTypeList": drugTypeList,
  45. "supplyList": supplyList,
  46. })
  47. return
  48. }
  49. func (this *SupplyOrderApiController) SavePurchaseOrder() {
  50. supplier_id, _ := this.GetInt64("supplier_name")
  51. start_time := this.GetString("start_time")
  52. end_time := this.GetString("end_time")
  53. timeLayout := "2006-01-02"
  54. loc, _ := time.LoadLocation("Local")
  55. var startTime int64
  56. if len(start_time) > 0 {
  57. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  58. if err != nil {
  59. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  60. return
  61. }
  62. startTime = theTime.Unix()
  63. }
  64. var endTime int64
  65. if len(end_time) > 0 {
  66. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  67. if err != nil {
  68. utils.ErrorLog(err.Error())
  69. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  70. return
  71. }
  72. endTime = theTime.Unix()
  73. }
  74. rate_of_concession := this.GetString("rate_of_concession")
  75. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  76. discount_amount := this.GetString("discount_amount")
  77. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  78. fmt.Println("supplier_id23323232323232", supplier_id, startTime, endTime, rate_of_concession, rate_of_concession_float, discount_amount, discount_amount_float)
  79. dataBody := make(map[string]interface{}, 0)
  80. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  81. if err != nil {
  82. utils.ErrorLog(err.Error())
  83. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  84. return
  85. }
  86. //生成订货单
  87. timeStr := time.Now().Format("2006-01-02")
  88. timeArr := strings.Split(timeStr, "-")
  89. orgId := this.GetAdminUserInfo().CurrentOrgId
  90. total, _ := service.FindAllSupplyOrder(orgId)
  91. total = total + 1
  92. warehousing_order := "CGDD" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  93. recordDateStr := time.Now().Format("2006-01-02")
  94. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  95. fmt.Scan("parseDateErr", parseDateErr)
  96. record_date := recordDate.Unix()
  97. info := models.SupplierWarehouseInfo{
  98. Number: warehousing_order,
  99. UserOrgId: orgId,
  100. Creater: this.GetAdminUserInfo().AdminUser.Id,
  101. Ctime: time.Now().Unix(),
  102. Mtime: 0,
  103. Status: 1,
  104. RecordDate: record_date,
  105. IsCheck: 2,
  106. RateOfConcession: rate_of_concession_float,
  107. DiscountAmount: discount_amount_float,
  108. DocumentDate: startTime,
  109. DeliveryDate: endTime,
  110. SupplierId: supplier_id,
  111. }
  112. err = service.CreateSupplyWarehouse(info)
  113. warehouseInfo, _ := service.FindLastSupplyWarehouseInfo(orgId)
  114. var warehousingInfo []*models.SupplierWarehousingInfoOrder
  115. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  116. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  117. if len(thisStockIn) > 0 {
  118. for _, item := range thisStockIn {
  119. items := item.(map[string]interface{})
  120. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  121. utils.ErrorLog("project_id")
  122. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  123. return
  124. }
  125. project_id := int64(items["project_id"].(float64))
  126. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  127. utils.ErrorLog("supply_count")
  128. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  129. return
  130. }
  131. supply_count := int64(items["supply_count"].(float64))
  132. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  133. utils.ErrorLog("supply_license_number")
  134. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  135. return
  136. }
  137. supply_license_number := items["supply_license_number"].(string)
  138. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  139. utils.ErrorLog("supply_price")
  140. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  141. return
  142. }
  143. supply_price := items["supply_price"].(string)
  144. supply_price_float, _ := strconv.ParseFloat(supply_price, 64)
  145. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  146. utils.ErrorLog("supply_remake")
  147. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  148. return
  149. }
  150. supply_remake := items["supply_remake"].(string)
  151. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  152. utils.ErrorLog("supply_total_price")
  153. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  154. return
  155. }
  156. supply_total_price := items["supply_total_price"].(string)
  157. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  158. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  159. utils.ErrorLog("type")
  160. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  161. return
  162. }
  163. is_source := int64(items["type"].(float64))
  164. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  165. utils.ErrorLog("supply_type")
  166. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. return
  168. }
  169. supply_type := items["supply_type"].(string)
  170. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  171. utils.ErrorLog("supply_specification_name")
  172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  173. return
  174. }
  175. supply_specification_name := items["supply_specification_name"].(string)
  176. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  177. utils.ErrorLog("supply_total")
  178. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  179. return
  180. }
  181. supply_total := items["supply_total"].(string)
  182. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  183. utils.ErrorLog("supply_manufacturer")
  184. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  185. return
  186. }
  187. supply_manufacturer := items["supply_manufacturer"].(string)
  188. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  189. utils.ErrorLog("name")
  190. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  191. return
  192. }
  193. name := items["name"].(string)
  194. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  195. utils.ErrorLog("supply_unit")
  196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  197. return
  198. }
  199. supply_unit := items["supply_unit"].(string)
  200. order := models.SupplierWarehousingInfoOrder{
  201. OrderNumber: warehousing_order,
  202. IsSource: is_source,
  203. Count: supply_count,
  204. Price: supply_price_float,
  205. Amount: supply_total_price_float,
  206. Remark: supply_remake,
  207. UserOrgId: orgId,
  208. Ctime: time.Now().Unix(),
  209. Status: 1,
  210. Mtime: 0,
  211. WarehousingId: warehouseInfo.ID,
  212. ProjectId: project_id,
  213. SupplyLicenseNumber: supply_license_number,
  214. SupplyType: supply_type,
  215. SupplySpecificationName: supply_specification_name,
  216. SupplyTotal: supply_total,
  217. SupplyManufacturer: supply_manufacturer,
  218. Name: name,
  219. SupplyUnit: supply_unit,
  220. }
  221. warehousingInfo = append(warehousingInfo, &order)
  222. }
  223. }
  224. }
  225. for _, item := range warehousingInfo {
  226. err = service.CreateSupplyWarehousingOrder(item)
  227. }
  228. //查询
  229. orderInfo, err := service.GetSupplyWarehousingOrderInfo(warehouseInfo.ID)
  230. if err == nil {
  231. this.ServeSuccessJSON(map[string]interface{}{
  232. "order": warehousingInfo,
  233. "warehouseInfo": warehouseInfo,
  234. "orderInfo": orderInfo,
  235. })
  236. } else {
  237. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  238. }
  239. }
  240. func (this *SupplyOrderApiController) GetAllSupply() {
  241. orgId := this.GetAdminUserInfo().CurrentOrgId
  242. appId := this.GetAdminUserInfo().CurrentAppId
  243. supplyList, err := service.GetSupplierList(orgId)
  244. doctorList, err := service.GetAllDoctor(orgId, appId)
  245. if err == nil {
  246. this.ServeSuccessJSON(map[string]interface{}{
  247. "supplyList": supplyList,
  248. "doctorList": doctorList,
  249. })
  250. } else {
  251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  252. }
  253. }
  254. func (this *SupplyOrderApiController) GetAllPurchaseOrderList() {
  255. check_id, _ := this.GetInt64("check_id")
  256. start_time := this.GetString("start_time")
  257. end_time := this.GetString("end_time")
  258. timeLayout := "2006-01-02"
  259. loc, _ := time.LoadLocation("Local")
  260. var startTime int64
  261. if len(start_time) > 0 {
  262. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  263. if err != nil {
  264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  265. return
  266. }
  267. startTime = theTime.Unix()
  268. }
  269. var endTime int64
  270. if len(end_time) > 0 {
  271. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  272. if err != nil {
  273. utils.ErrorLog(err.Error())
  274. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  275. return
  276. }
  277. endTime = theTime.Unix()
  278. }
  279. keyword := this.GetString("keyword")
  280. page, _ := this.GetInt64("page")
  281. limit, _ := this.GetInt64("limit")
  282. orgId := this.GetAdminUserInfo().CurrentOrgId
  283. list, total, err := service.GetAllPurchaseOrderList(check_id, startTime, endTime, keyword, page, limit, orgId)
  284. if err == nil {
  285. this.ServeSuccessJSON(map[string]interface{}{
  286. "list": list,
  287. "total": total,
  288. })
  289. } else {
  290. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  291. }
  292. }
  293. func (this *SupplyOrderApiController) UpdatePurchaseOrder() {
  294. supplier_id, _ := this.GetInt64("supplier_name")
  295. start_time := this.GetString("start_time")
  296. end_time := this.GetString("end_time")
  297. timeLayout := "2006-01-02"
  298. loc, _ := time.LoadLocation("Local")
  299. var startTime int64
  300. if len(start_time) > 0 {
  301. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  302. if err != nil {
  303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  304. return
  305. }
  306. startTime = theTime.Unix()
  307. }
  308. var endTime int64
  309. if len(end_time) > 0 {
  310. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  311. if err != nil {
  312. utils.ErrorLog(err.Error())
  313. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  314. return
  315. }
  316. endTime = theTime.Unix()
  317. }
  318. rate_of_concession := this.GetString("rate_of_concession")
  319. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  320. discount_amount := this.GetString("discount_amount")
  321. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  322. warehousing_id, _ := this.GetInt64("id")
  323. number := this.GetString("number")
  324. //fmt.Println("supplier_id23323232323232", supplier_id, startTime, endTime, rate_of_concession, rate_of_concession_float, discount_amount, discount_amount_float)
  325. orgId := this.GetAdminUserInfo().CurrentOrgId
  326. info := models.SupplierWarehouseInfo{
  327. RateOfConcession: rate_of_concession_float,
  328. DiscountAmount: discount_amount_float,
  329. DocumentDate: startTime,
  330. DeliveryDate: endTime,
  331. SupplierId: supplier_id,
  332. Mtime: time.Now().Unix(),
  333. }
  334. service.ModefySupplyWarehouseInfo(warehousing_id, info)
  335. dataBody := make(map[string]interface{}, 0)
  336. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  337. if err != nil {
  338. utils.ErrorLog(err.Error())
  339. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  340. return
  341. }
  342. var warehousingInfo []*models.SupplierWarehousingInfoOrder
  343. var updateWarehousingInfo []*models.SupplierWarehousingInfoOrder
  344. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  345. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  346. if len(thisStockIn) > 0 {
  347. for _, item := range thisStockIn {
  348. items := item.(map[string]interface{})
  349. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  350. utils.ErrorLog("id")
  351. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  352. return
  353. }
  354. id := int64(items["id"].(float64))
  355. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  356. utils.ErrorLog("project_id")
  357. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  358. return
  359. }
  360. project_id := int64(items["project_id"].(float64))
  361. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  362. utils.ErrorLog("supply_count")
  363. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  364. return
  365. }
  366. supply_count := int64(items["supply_count"].(float64))
  367. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  368. utils.ErrorLog("supply_license_number")
  369. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  370. return
  371. }
  372. supply_license_number := items["supply_license_number"].(string)
  373. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  374. utils.ErrorLog("supply_price")
  375. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  376. return
  377. }
  378. supply_price := items["supply_price"].(string)
  379. supply_price_float, _ := strconv.ParseFloat(supply_price, 64)
  380. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  381. utils.ErrorLog("supply_remake")
  382. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  383. return
  384. }
  385. supply_remake := items["supply_remake"].(string)
  386. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  387. utils.ErrorLog("supply_total_price")
  388. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  389. return
  390. }
  391. supply_total_price := items["supply_total_price"].(string)
  392. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  393. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  394. utils.ErrorLog("type")
  395. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  396. return
  397. }
  398. is_source := int64(items["type"].(float64))
  399. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  400. utils.ErrorLog("supply_type")
  401. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  402. return
  403. }
  404. supply_type := items["supply_type"].(string)
  405. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  406. utils.ErrorLog("supply_specification_name")
  407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  408. return
  409. }
  410. supply_specification_name := items["supply_specification_name"].(string)
  411. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  412. utils.ErrorLog("supply_total")
  413. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  414. return
  415. }
  416. supply_total := items["supply_total"].(string)
  417. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  418. utils.ErrorLog("supply_manufacturer")
  419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  420. return
  421. }
  422. supply_manufacturer := items["supply_manufacturer"].(string)
  423. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  424. utils.ErrorLog("name")
  425. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  426. return
  427. }
  428. name := items["name"].(string)
  429. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  430. utils.ErrorLog("supply_unit")
  431. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  432. return
  433. }
  434. supply_unit := items["supply_unit"].(string)
  435. if id > 0 {
  436. order := models.SupplierWarehousingInfoOrder{
  437. ID: id,
  438. IsSource: is_source,
  439. Count: supply_count,
  440. Price: supply_price_float,
  441. Amount: supply_total_price_float,
  442. Remark: supply_remake,
  443. Ctime: time.Now().Unix(),
  444. Status: 1,
  445. Mtime: 0,
  446. ProjectId: project_id,
  447. SupplyLicenseNumber: supply_license_number,
  448. SupplyType: supply_type,
  449. SupplySpecificationName: supply_specification_name,
  450. SupplyTotal: supply_total,
  451. SupplyManufacturer: supply_manufacturer,
  452. Name: name,
  453. SupplyUnit: supply_unit,
  454. }
  455. updateWarehousingInfo = append(updateWarehousingInfo, &order)
  456. }
  457. if id == 0 {
  458. order := models.SupplierWarehousingInfoOrder{
  459. OrderNumber: number,
  460. IsSource: is_source,
  461. Count: supply_count,
  462. Price: supply_price_float,
  463. Amount: supply_total_price_float,
  464. Remark: supply_remake,
  465. UserOrgId: orgId,
  466. Ctime: time.Now().Unix(),
  467. Status: 1,
  468. Mtime: 0,
  469. WarehousingId: warehousing_id,
  470. ProjectId: project_id,
  471. SupplyLicenseNumber: supply_license_number,
  472. SupplyType: supply_type,
  473. SupplySpecificationName: supply_specification_name,
  474. SupplyTotal: supply_total,
  475. SupplyManufacturer: supply_manufacturer,
  476. Name: name,
  477. SupplyUnit: supply_unit,
  478. }
  479. warehousingInfo = append(warehousingInfo, &order)
  480. }
  481. }
  482. }
  483. if len(warehousingInfo) > 0 {
  484. for _, item := range warehousingInfo {
  485. service.CreateSupplyWarehousingOrder(item)
  486. }
  487. }
  488. if len(updateWarehousingInfo) > 0 {
  489. for _, item := range updateWarehousingInfo {
  490. service.ModifySupplyWarehouseOrder(item)
  491. }
  492. }
  493. this.ServeSuccessJSON(map[string]interface{}{
  494. "warehousingInfo": warehousingInfo,
  495. })
  496. }
  497. }
  498. func (this *SupplyOrderApiController) UpdateSupplyWaresing() {
  499. id, _ := this.GetInt64("id")
  500. recordDateStr := time.Now().Format("2006-01-02")
  501. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  502. record_date := recordDate.Unix()
  503. checker := this.GetAdminUserInfo().AdminUser.Id
  504. info := models.SupplierWarehouseInfo{
  505. Mtime: time.Now().Unix(),
  506. Status: 1,
  507. IsCheck: 1,
  508. Checker: checker,
  509. CheckTime: record_date,
  510. }
  511. parseDateErr := service.UpdateSupplyWaresing(id, info)
  512. if parseDateErr == nil {
  513. this.ServeSuccessJSON(map[string]interface{}{
  514. "info": info,
  515. })
  516. } else {
  517. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  518. }
  519. }
  520. func (this *SupplyOrderApiController) GetPurchaseOrderDetail() {
  521. id, _ := this.GetInt64("id")
  522. info, _ := service.GetPurchaseOrderDetail(id)
  523. //查询
  524. orderInfo, err := service.GetSupplyWarehousingOrderInfo(id)
  525. orgId := this.GetAdminUserInfo().CurrentOrgId
  526. supplyList, _ := service.GetSupplierList(orgId)
  527. //获取药品库数据
  528. baseList, _ := service.GetSupplyDrugList(orgId)
  529. goodList, _ := service.GetSupplyGoodList(orgId)
  530. if err == nil {
  531. this.ServeSuccessJSON(map[string]interface{}{
  532. "info": info,
  533. "orderInfo": orderInfo,
  534. "supplyList": supplyList,
  535. "baseList": baseList,
  536. "goodList": goodList,
  537. })
  538. } else {
  539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  540. }
  541. }
  542. func (this *SupplyOrderApiController) AddGoodOrder() {
  543. supplier_id, _ := this.GetInt64("supplier_id")
  544. start_time := this.GetString("start")
  545. timeLayout := "2006-01-02"
  546. loc, _ := time.LoadLocation("Local")
  547. var startTime int64
  548. if len(start_time) > 0 {
  549. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  550. if err != nil {
  551. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  552. return
  553. }
  554. startTime = theTime.Unix()
  555. }
  556. good_number := this.GetString("good_number")
  557. arrerage, _ := this.GetInt64("arrerage")
  558. payment, _ := this.GetInt64("payment")
  559. warehousing_id, _ := this.GetInt64("warehousing_id")
  560. number := this.GetString("number")
  561. rate_of_concession, _ := this.GetInt64("rate_of_concession")
  562. discount_amount, _ := this.GetInt64("discount_amount")
  563. fmt.Println(supplier_id, startTime, good_number, arrerage, payment, warehousing_id, number, rate_of_concession, discount_amount)
  564. }