stock_good_api_controller.go 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. adminUserInfo := c.GetAdminUserInfo()
  37. totals := service.FindGoodTypeByName(type_name, adminUserInfo.CurrentOrgId)
  38. if totals > 0 {
  39. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGoodTypeNameExistError)
  40. return
  41. }
  42. total := service.FindAllGoodTypeTotal(adminUserInfo.CurrentOrgId)
  43. code := strconv.FormatInt(total+1, 10)
  44. code = "34000000" + code
  45. goodType := models.GoodsType{
  46. TypeCode: code,
  47. TypeName: type_name,
  48. Remark: remark,
  49. Ctime: time.Now().Unix(),
  50. Mtime: time.Now().Unix(),
  51. OrgId: adminUserInfo.CurrentOrgId,
  52. Creater: adminUserInfo.AdminUser.Id,
  53. Status: 1,
  54. OutStock: outStockInt,
  55. }
  56. err, types := service.AddSigleGoodType(&goodType)
  57. if err == nil {
  58. c.ServeSuccessJSON(map[string]interface{}{
  59. "goodTypes": types,
  60. })
  61. } else {
  62. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  63. }
  64. }
  65. func (c *StockGoodApiController) ModifyGoodType() {
  66. id, _ := c.GetInt64("id", 0)
  67. type_name := c.GetString("type_name")
  68. remark := c.GetString("remark")
  69. good_type_code := c.GetString("type_code")
  70. out_stock := c.GetString("out_stock")
  71. outStockInt, _ := strconv.ParseInt(out_stock, 10, 64)
  72. adminUserInfo := c.GetAdminUserInfo()
  73. //totals := service.FindGoodTypeByName(type_name, adminUserInfo.CurrentOrgId)
  74. //if totals > 0 {
  75. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGoodTypeNameExistError)
  76. // return
  77. //}
  78. goodType := models.GoodsType{
  79. ID: id,
  80. TypeCode: good_type_code,
  81. TypeName: type_name,
  82. Remark: remark,
  83. Ctime: time.Now().Unix(),
  84. Mtime: time.Now().Unix(),
  85. OrgId: adminUserInfo.CurrentOrgId,
  86. Modifier: adminUserInfo.AdminUser.Id,
  87. Status: 1,
  88. OutStock: outStockInt,
  89. }
  90. err, types := service.ModifyGoodType(&goodType)
  91. if err == nil {
  92. c.ServeSuccessJSON(map[string]interface{}{
  93. "goodTypes": types,
  94. })
  95. } else {
  96. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  97. }
  98. }
  99. func (c *StockGoodApiController) GetGoodTypeList() {
  100. page, _ := c.GetInt64("page", 1)
  101. limit, _ := c.GetInt64("limit", 7)
  102. keyword := c.GetString("keyword")
  103. adminUserInfo := c.GetAdminUserInfo()
  104. goodTypes, total, err := service.FindAllGoodTypeList(adminUserInfo.CurrentOrgId, page, limit, keyword)
  105. if err == nil {
  106. c.ServeSuccessJSON(map[string]interface{}{
  107. "list": goodTypes,
  108. "total": total,
  109. })
  110. } else {
  111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  112. }
  113. }
  114. func (c *StockGoodApiController) DeleteGoodType() {
  115. id, _ := c.GetInt64("id", 0)
  116. adminUserInfo := c.GetAdminUserInfo()
  117. goodInfo, _ := service.FindGoodInfoByGoodId(id)
  118. autoDetail, _ := service.FindStockOutDetailGoodInfoByGoodId(id)
  119. if len(goodInfo) > 0 {
  120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodTypeFail)
  121. return
  122. }
  123. if len(autoDetail) > 0 {
  124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodInfoFail)
  125. return
  126. }
  127. err := service.DeleteGoodTypeById(id, adminUserInfo.AdminUser.Id)
  128. if err == nil {
  129. c.ServeSuccessJSON(map[string]interface{}{
  130. "msg": "删除成功",
  131. })
  132. } else {
  133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  134. }
  135. }
  136. func (c *StockGoodApiController) GetGoodType() {
  137. id, _ := c.GetInt64("id", 0)
  138. goodType, err := service.FindGoodTypeById(id)
  139. if err == nil {
  140. c.ServeSuccessJSON(map[string]interface{}{
  141. "goodType": goodType,
  142. })
  143. } else {
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  145. }
  146. }
  147. func (c *StockGoodApiController) GetAllGoodType() {
  148. adminUserInfo := c.GetAdminUserInfo()
  149. goodTypes, err := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  150. if err == nil {
  151. c.ServeSuccessJSON(map[string]interface{}{
  152. "goodType": goodTypes,
  153. })
  154. } else {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. }
  157. }
  158. func (c *StockGoodApiController) GetAllGoodInfo() {
  159. adminUserInfo := c.GetAdminUserInfo()
  160. goodInfo, err := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
  161. if err == nil {
  162. c.ServeSuccessJSON(map[string]interface{}{
  163. "goodInfo": goodInfo,
  164. })
  165. } else {
  166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  167. }
  168. }
  169. func (c *StockGoodApiController) GetAllGood() {
  170. adminUserInfo := c.GetAdminUserInfo()
  171. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  172. dealer_id, _ := c.GetInt64("dealer_id", 0)
  173. fmt.Println(manufacturer_id)
  174. fmt.Println(dealer_id)
  175. goodInfo, err := service.FindAllGoodByManufactureId(manufacturer_id, dealer_id, adminUserInfo.CurrentOrgId)
  176. if err == nil {
  177. c.ServeSuccessJSON(map[string]interface{}{
  178. "goodInfo": goodInfo,
  179. })
  180. } else {
  181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  182. }
  183. }
  184. func (c *StockGoodApiController) GetWarehouseGoodInfo() {
  185. adminUserInfo := c.GetAdminUserInfo()
  186. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  187. dealer_id, _ := c.GetInt64("dealer_id", 0)
  188. goodInfo, err := service.FindAllGoodByManufactureId(manufacturer_id, dealer_id, adminUserInfo.CurrentOrgId)
  189. if err == nil {
  190. c.ServeSuccessJSON(map[string]interface{}{
  191. "goodInfo": goodInfo,
  192. })
  193. } else {
  194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  195. }
  196. }