stock_in_api_controller.go 62KB

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