stock_in_api_controller.go 61KB

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