stock_good_api_controller.go 6.4KB

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