stock_good_api_controller.go 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. package controllers
  2. import (
  3. "Xcx_New/enums"
  4. "Xcx_New/models"
  5. "Xcx_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. if err == nil {
  157. c.ServeSuccessJSON(map[string]interface{}{
  158. "goodType": goodTypes,
  159. })
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. }
  163. }
  164. func (c *StockGoodApiController) GetAllGoodInfo() {
  165. adminUserInfo := c.GetAdminUserInfo()
  166. goodInfo, err := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
  167. if err == nil {
  168. c.ServeSuccessJSON(map[string]interface{}{
  169. "goodInfo": goodInfo,
  170. })
  171. } else {
  172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  173. }
  174. }
  175. func (c *StockGoodApiController) GetAllGood() {
  176. adminUserInfo := c.GetAdminUserInfo()
  177. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  178. dealer_id, _ := c.GetInt64("dealer_id", 0)
  179. fmt.Println(manufacturer_id)
  180. fmt.Println(dealer_id)
  181. goodInfo, err := service.FindAllGoodByManufactureId(manufacturer_id, dealer_id, adminUserInfo.CurrentOrgId)
  182. if err == nil {
  183. c.ServeSuccessJSON(map[string]interface{}{
  184. "goodInfo": goodInfo,
  185. })
  186. } else {
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  188. }
  189. }
  190. func (c *StockGoodApiController) GetWarehouseGoodInfo() {
  191. adminUserInfo := c.GetAdminUserInfo()
  192. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  193. dealer_id, _ := c.GetInt64("dealer_id", 0)
  194. goodInfo, err := service.FindAllGoodByManufactureId(manufacturer_id, dealer_id, adminUserInfo.CurrentOrgId)
  195. if err == nil {
  196. c.ServeSuccessJSON(map[string]interface{}{
  197. "goodInfo": goodInfo,
  198. })
  199. } else {
  200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  201. }
  202. }