stock_good_api_controller.go 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "fmt"
  7. "github.com/astaxie/beego"
  8. "strconv"
  9. "time"
  10. )
  11. type StockGoodApiController struct {
  12. BaseAuthAPIController
  13. }
  14. func StockGoodApiRegistRouters() {
  15. beego.Router("/api/stock/good/type/create", &StockGoodApiController{}, "post:CreateGoodType")
  16. beego.Router("/api/stock/good/type/modify", &StockGoodApiController{}, "post:ModifyGoodType")
  17. beego.Router("/api/stock/good/type/list", &StockGoodApiController{}, "get:GetGoodTypeList")
  18. beego.Router("/api/type/delete", &StockGoodApiController{}, "post:DeleteGoodType")
  19. beego.Router("/api/stock/good/type/get", &StockGoodApiController{}, "get:GetGoodType")
  20. //
  21. //beego.Router("/api/stock/good/info/create", &StockGoodApiController{}, "post:CreateGoodInfo")
  22. //beego.Router("/api/stock/good/info/modify", &StockGoodApiController{}, "post:ModifyGoodInfo")
  23. //beego.Router("/api/stock/good/info/list", &StockGoodApiController{}, "get:GetGoodInfoList")
  24. //beego.Router("/api/info/delete", &StockGoodApiController{}, "post:DeleteGoodInfo")
  25. //beego.Router("/api/stock/good/info/get", &StockGoodApiController{}, "get:GetGoodInfoByGoodId")
  26. //beego.Router("/api/stock/good/info", &StockGoodApiController{}, "get:GetGoodInfoById")
  27. beego.Router("/api/stock/good/type/all", &StockGoodApiController{}, "get:GetAllGoodType")
  28. beego.Router("/api/stock/good/info/all", &StockGoodApiController{}, "get:GetAllGoodInfo")
  29. beego.Router("/api/good/get", &StockGoodApiController{}, "get:GetAllGood")
  30. }
  31. func (c *StockGoodApiController) CreateGoodType() {
  32. type_name := c.GetString("type_name")
  33. remark := c.GetString("remark")
  34. out_stock := c.GetString("out_stock")
  35. outStockInt, _ := strconv.ParseInt(out_stock, 10, 64)
  36. stock_attribute := c.GetString("stock_attribute")
  37. stockAttribute, _ := strconv.ParseInt(stock_attribute, 10, 64)
  38. adminUserInfo := c.GetAdminUserInfo()
  39. totals := service.FindGoodTypeByName(type_name, adminUserInfo.CurrentOrgId)
  40. if totals > 0 {
  41. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGoodTypeNameExistError)
  42. return
  43. }
  44. total := service.FindAllGoodTypeTotal(adminUserInfo.CurrentOrgId)
  45. code := strconv.FormatInt(total+1, 10)
  46. code = "34000000" + code
  47. goodType := models.GoodsType{
  48. TypeCode: code,
  49. TypeName: type_name,
  50. Remark: remark,
  51. Ctime: time.Now().Unix(),
  52. Mtime: time.Now().Unix(),
  53. OrgId: adminUserInfo.CurrentOrgId,
  54. Creater: adminUserInfo.AdminUser.Id,
  55. Status: 1,
  56. OutStock: outStockInt,
  57. StockAttribute: stockAttribute,
  58. }
  59. err, types := service.AddSigleGoodType(&goodType)
  60. if err == nil {
  61. c.ServeSuccessJSON(map[string]interface{}{
  62. "goodTypes": types,
  63. })
  64. } else {
  65. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  66. }
  67. }
  68. func (c *StockGoodApiController) ModifyGoodType() {
  69. id, _ := c.GetInt64("id", 0)
  70. type_name := c.GetString("type_name")
  71. remark := c.GetString("remark")
  72. good_type_code := c.GetString("type_code")
  73. out_stock := c.GetString("out_stock")
  74. outStockInt, _ := strconv.ParseInt(out_stock, 10, 64)
  75. adminUserInfo := c.GetAdminUserInfo()
  76. stock_attribute := c.GetString("stock_attribute")
  77. stockAttribute, _ := strconv.ParseInt(stock_attribute, 10, 64)
  78. //totals := service.FindGoodTypeByName(type_name, adminUserInfo.CurrentOrgId)
  79. //if totals > 0 {
  80. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGoodTypeNameExistError)
  81. // return
  82. //}
  83. goodType := models.GoodsType{
  84. ID: id,
  85. TypeCode: good_type_code,
  86. TypeName: type_name,
  87. Remark: remark,
  88. Ctime: time.Now().Unix(),
  89. Mtime: time.Now().Unix(),
  90. OrgId: adminUserInfo.CurrentOrgId,
  91. Modifier: adminUserInfo.AdminUser.Id,
  92. Status: 1,
  93. OutStock: outStockInt,
  94. StockAttribute: stockAttribute,
  95. }
  96. err, types := service.ModifyGoodType(&goodType)
  97. if err == nil {
  98. c.ServeSuccessJSON(map[string]interface{}{
  99. "goodTypes": types,
  100. })
  101. } else {
  102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  103. }
  104. }
  105. func (c *StockGoodApiController) GetGoodTypeList() {
  106. page, _ := c.GetInt64("page", 1)
  107. limit, _ := c.GetInt64("limit", 7)
  108. keyword := c.GetString("keyword")
  109. adminUserInfo := c.GetAdminUserInfo()
  110. goodTypes, total, err := service.FindAllGoodTypeList(adminUserInfo.CurrentOrgId, page, limit, keyword)
  111. if err == nil {
  112. c.ServeSuccessJSON(map[string]interface{}{
  113. "list": goodTypes,
  114. "total": total,
  115. })
  116. } else {
  117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  118. }
  119. }
  120. func (c *StockGoodApiController) DeleteGoodType() {
  121. id, _ := c.GetInt64("id", 0)
  122. adminUserInfo := c.GetAdminUserInfo()
  123. goodInfo, _ := service.FindGoodInfoByGoodId(id)
  124. autoDetail, _ := service.FindStockOutDetailGoodInfoByGoodId(id)
  125. if len(goodInfo) > 0 {
  126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodTypeFail)
  127. return
  128. }
  129. if len(autoDetail) > 0 {
  130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodInfoFail)
  131. return
  132. }
  133. err := service.DeleteGoodTypeById(id, adminUserInfo.AdminUser.Id)
  134. if err == nil {
  135. c.ServeSuccessJSON(map[string]interface{}{
  136. "msg": "删除成功",
  137. })
  138. } else {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  140. }
  141. }
  142. func (c *StockGoodApiController) GetGoodType() {
  143. id, _ := c.GetInt64("id", 0)
  144. goodType, err := service.FindGoodTypeById(id)
  145. if err == nil {
  146. c.ServeSuccessJSON(map[string]interface{}{
  147. "goodType": goodType,
  148. })
  149. } else {
  150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  151. }
  152. }
  153. func (c *StockGoodApiController) GetAllGoodType() {
  154. adminUserInfo := c.GetAdminUserInfo()
  155. goodTypes, err := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  156. houseList, _ := service.GetAllStoreHouseListTwo(adminUserInfo.CurrentOrgId)
  157. storehouselist, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
  158. goodInfo, _ := service.FindAllGoodInfoTwo(adminUserInfo.CurrentOrgId)
  159. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  160. if err == nil {
  161. c.ServeSuccessJSON(map[string]interface{}{
  162. "goodType": goodTypes,
  163. "houseList": houseList,
  164. "goodInfo": goodInfo,
  165. "manufacturerList": manufacturerList,
  166. "storehouseList": storehouselist,
  167. })
  168. } else {
  169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  170. }
  171. }
  172. func (c *StockGoodApiController) GetAllGoodInfo() {
  173. adminUserInfo := c.GetAdminUserInfo()
  174. goodInfo, err := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
  175. if err == nil {
  176. c.ServeSuccessJSON(map[string]interface{}{
  177. "goodInfo": goodInfo,
  178. })
  179. } else {
  180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  181. }
  182. }
  183. func (c *StockGoodApiController) GetAllGood() {
  184. adminUserInfo := c.GetAdminUserInfo()
  185. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  186. dealer_id, _ := c.GetInt64("dealer_id", 0)
  187. fmt.Println(manufacturer_id)
  188. fmt.Println(dealer_id)
  189. goodInfo, err := service.FindAllGoodByManufactureId(manufacturer_id, dealer_id, adminUserInfo.CurrentOrgId)
  190. if err == nil {
  191. c.ServeSuccessJSON(map[string]interface{}{
  192. "goodInfo": goodInfo,
  193. })
  194. } else {
  195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  196. }
  197. }
  198. func (c *StockGoodApiController) GetWarehouseGoodInfo() {
  199. adminUserInfo := c.GetAdminUserInfo()
  200. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  201. dealer_id, _ := c.GetInt64("dealer_id", 0)
  202. goodInfo, err := service.FindAllGoodByManufactureId(manufacturer_id, dealer_id, adminUserInfo.CurrentOrgId)
  203. if err == nil {
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "goodInfo": goodInfo,
  206. })
  207. } else {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  209. }
  210. }