stock_good_api_controller.go 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. beego.Router("/api/stock/good/info/create", &StockGoodApiController{}, "post:CreateGoodInfo")
  21. beego.Router("/api/stock/good/info/modify", &StockGoodApiController{}, "post:ModifyGoodInfo")
  22. beego.Router("/api/stock/good/info/list", &StockGoodApiController{}, "get:GetGoodInfoList")
  23. beego.Router("/api/info/delete", &StockGoodApiController{}, "post:DeleteGoodInfo")
  24. beego.Router("/api/stock/good/info/get", &StockGoodApiController{}, "get:GetGoodInfoByGoodId")
  25. beego.Router("/api/stock/good/info", &StockGoodApiController{}, "get:GetGoodInfoById")
  26. beego.Router("/api/stock/good/type/all", &StockGoodApiController{}, "get:GetAllGoodType")
  27. beego.Router("/api/stock/good/info/all", &StockGoodApiController{}, "get:GetAllGoodInfo")
  28. beego.Router("/api/good/get", &StockGoodApiController{}, "get:GetAllGood")
  29. }
  30. func (c *StockGoodApiController) CreateGoodType() {
  31. type_name := c.GetString("type_name")
  32. remark := c.GetString("remark")
  33. adminUserInfo := c.GetAdminUserInfo()
  34. totals := service.FindGoodTypeByName(type_name, adminUserInfo.CurrentOrgId)
  35. if totals > 0 {
  36. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGoodTypeNameExistError)
  37. return
  38. }
  39. total := service.FindAllGoodTypeTotal(adminUserInfo.CurrentOrgId)
  40. code := strconv.FormatInt(total+1, 10)
  41. code = "34000000" + code
  42. goodType := models.GoodsType{
  43. TypeCode: code,
  44. TypeName: type_name,
  45. Remark: remark,
  46. Ctime: time.Now().Unix(),
  47. Mtime: time.Now().Unix(),
  48. OrgId: adminUserInfo.CurrentOrgId,
  49. Creater: adminUserInfo.AdminUser.Id,
  50. Status: 1,
  51. }
  52. err, types := service.AddSigleGoodType(&goodType)
  53. if err == nil {
  54. c.ServeSuccessJSON(map[string]interface{}{
  55. "goodTypes": types,
  56. })
  57. } else {
  58. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  59. }
  60. }
  61. func (c *StockGoodApiController) ModifyGoodType() {
  62. id, _ := c.GetInt64("id", 0)
  63. type_name := c.GetString("type_name")
  64. remark := c.GetString("remark")
  65. good_type_code := c.GetString("type_code")
  66. adminUserInfo := c.GetAdminUserInfo()
  67. //totals := service.FindGoodTypeByName(type_name, adminUserInfo.CurrentOrgId)
  68. //if totals > 0 {
  69. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGoodTypeNameExistError)
  70. // return
  71. //}
  72. goodType := models.GoodsType{
  73. ID: id,
  74. TypeCode: good_type_code,
  75. TypeName: type_name,
  76. Remark: remark,
  77. Ctime: time.Now().Unix(),
  78. Mtime: time.Now().Unix(),
  79. OrgId: adminUserInfo.CurrentOrgId,
  80. Modifier: adminUserInfo.AdminUser.Id,
  81. Status: 1,
  82. }
  83. err, types := service.ModifyGoodType(&goodType)
  84. if err == nil {
  85. c.ServeSuccessJSON(map[string]interface{}{
  86. "goodTypes": types,
  87. })
  88. } else {
  89. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  90. }
  91. }
  92. func (c *StockGoodApiController) GetGoodTypeList() {
  93. page, _ := c.GetInt64("page", 1)
  94. limit, _ := c.GetInt64("limit", 7)
  95. keyword := c.GetString("keyword")
  96. adminUserInfo := c.GetAdminUserInfo()
  97. goodTypes, total, err := service.FindAllGoodTypeList(adminUserInfo.CurrentOrgId, page, limit, keyword)
  98. if err == nil {
  99. c.ServeSuccessJSON(map[string]interface{}{
  100. "list": goodTypes,
  101. "total": total,
  102. })
  103. } else {
  104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  105. }
  106. }
  107. func (c *StockGoodApiController) DeleteGoodType() {
  108. id, _ := c.GetInt64("id", 0)
  109. adminUserInfo := c.GetAdminUserInfo()
  110. goodInfo, _ := service.FindGoodInfoByGoodId(id)
  111. if len(goodInfo) > 0 {
  112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodTypeFail)
  113. return
  114. }
  115. err := service.DeleteGoodTypeById(id, adminUserInfo.AdminUser.Id)
  116. if err == nil {
  117. c.ServeSuccessJSON(map[string]interface{}{
  118. "msg": "删除成功",
  119. })
  120. } else {
  121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  122. }
  123. }
  124. func (c *StockGoodApiController) GetGoodType() {
  125. id, _ := c.GetInt64("id", 0)
  126. goodType, err := service.FindGoodTypeById(id)
  127. if err == nil {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "goodType": goodType,
  130. })
  131. } else {
  132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  133. }
  134. }
  135. func (c *StockGoodApiController) CreateGoodInfo() {
  136. good_id, _ := c.GetInt64("good_id", 0)
  137. specification_name := c.GetString("specification_name")
  138. good_unit, _ := c.GetInt64("good_unit", -1)
  139. buy_price, _ := c.GetFloat("buy_price", 0)
  140. sell_price, _ := c.GetFloat("sell_price", 0)
  141. remark := c.GetString("remark")
  142. manufacturer, _ := c.GetInt64("manufacturer", 0)
  143. dealer, _ := c.GetInt64("dealer", 0)
  144. expiry_date_warn_day_count, _ := c.GetInt64("expiry_date_warn_day_count", 0)
  145. stock_warn_count, _ := c.GetInt64("stock_warn_count", 0)
  146. is_reuse, _ := c.GetInt64("is_reuse", 0)
  147. adminUserInfo := c.GetAdminUserInfo()
  148. totals := service.FindGoodInfoByName(specification_name, adminUserInfo.CurrentOrgId)
  149. if totals > 0 {
  150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGoodInfoNameExistError)
  151. return
  152. }
  153. total := service.FindAllGoodInfoTotal(adminUserInfo.CurrentOrgId)
  154. code := strconv.FormatInt(total+1, 10)
  155. code = "24000000" + code
  156. goodInfo := models.GoodInfo{
  157. GoodCode: code,
  158. SpecificationName: specification_name,
  159. GoodTypeId: good_id,
  160. GoodUnit: good_unit,
  161. BuyPrice: buy_price,
  162. SellPrice: sell_price,
  163. Remark: remark,
  164. Ctime: time.Now().Unix(),
  165. Manufacturer: manufacturer,
  166. Dealer: dealer,
  167. ExpiryDateWarnDayCount: expiry_date_warn_day_count,
  168. StockWarnCount: stock_warn_count,
  169. IsReuse: is_reuse,
  170. Status: 1,
  171. OrgId: adminUserInfo.CurrentOrgId,
  172. Creater: adminUserInfo.AdminUser.Id,
  173. }
  174. err, goodInfos := service.AddSigleGoodInfo(&goodInfo)
  175. if err == nil {
  176. c.ServeSuccessJSON(map[string]interface{}{
  177. "goodInfo": goodInfos,
  178. })
  179. } else {
  180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  181. }
  182. }
  183. func (c *StockGoodApiController) ModifyGoodInfo() {
  184. id, _ := c.GetInt64("id", 0)
  185. good_id, _ := c.GetInt64("good_id", 0)
  186. specification_name := c.GetString("specification_name")
  187. good_unit, _ := c.GetInt64("good_unit", -1)
  188. buy_price, _ := c.GetFloat("buy_price", 0)
  189. sell_price, _ := c.GetFloat("sell_price", 0)
  190. remark := c.GetString("remark")
  191. manufacturer, _ := c.GetInt64("manufacturer", 0)
  192. dealer, _ := c.GetInt64("dealer", 0)
  193. expiry_date_warn_day_count, _ := c.GetInt64("expiry_date_warn_day_count", 0)
  194. stock_warn_count, _ := c.GetInt64("stock_warn_count", 0)
  195. is_reuse, _ := c.GetInt64("is_reuse", 0)
  196. code := c.GetString("good_code")
  197. adminUserInfo := c.GetAdminUserInfo()
  198. //totals := service.FindGoodInfoByName(specification_name, adminUserInfo.CurrentOrgId)
  199. //if totals > 0 {
  200. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGoodInfoNameExistError)
  201. // return
  202. //}
  203. goodInfo := models.GoodInfo{
  204. ID: id,
  205. GoodCode: code,
  206. SpecificationName: specification_name,
  207. GoodTypeId: good_id,
  208. GoodUnit: good_unit,
  209. BuyPrice: buy_price,
  210. SellPrice: sell_price,
  211. Remark: remark,
  212. Mtime: time.Now().Unix(),
  213. Manufacturer: manufacturer,
  214. Dealer: dealer,
  215. ExpiryDateWarnDayCount: expiry_date_warn_day_count,
  216. StockWarnCount: stock_warn_count,
  217. IsReuse: is_reuse,
  218. Status: 1,
  219. OrgId: adminUserInfo.CurrentOrgId,
  220. Modifier: adminUserInfo.AdminUser.Id,
  221. }
  222. err, goodInfos := service.ModifyGoodInfo(&goodInfo)
  223. if err == nil {
  224. c.ServeSuccessJSON(map[string]interface{}{
  225. "goodInfo": goodInfos,
  226. })
  227. } else {
  228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  229. }
  230. }
  231. func (c *StockGoodApiController) GetGoodInfoList() {
  232. page, _ := c.GetInt64("page", 1)
  233. limit, _ := c.GetInt64("limit", 7)
  234. keyword := c.GetString("keyword")
  235. adminUserInfo := c.GetAdminUserInfo()
  236. goodInfos, total, err := service.FindGoodInfoList(adminUserInfo.CurrentOrgId, page, limit, keyword)
  237. if err == nil {
  238. c.ServeSuccessJSON(map[string]interface{}{
  239. "list": goodInfos,
  240. "total": total,
  241. })
  242. } else {
  243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  244. }
  245. }
  246. func (c *StockGoodApiController) DeleteGoodInfo() {
  247. id, _ := c.GetInt64("id", 0)
  248. adminUserInfo := c.GetAdminUserInfo()
  249. total, _ := service.FindWarehouseInfoTotalByGoodId(id)
  250. if total > 0 {
  251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodInfoFail)
  252. return
  253. }
  254. err := service.DeleteGoodInfoById(id, adminUserInfo.AdminUser.Id)
  255. if err == nil {
  256. c.ServeSuccessJSON(map[string]interface{}{
  257. "msg": "删除成功",
  258. })
  259. } else {
  260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  261. }
  262. }
  263. func (c *StockGoodApiController) GetGoodInfoByGoodId() {
  264. id, _ := c.GetInt64("id", 0)
  265. goodInfo, err := service.FindGoodInfoByGoodId(id)
  266. if err == nil {
  267. c.ServeSuccessJSON(map[string]interface{}{
  268. "list": goodInfo,
  269. })
  270. } else {
  271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  272. }
  273. }
  274. func (c *StockGoodApiController) GetGoodInfoById() {
  275. id, _ := c.GetInt64("id", 0)
  276. goodInfo, err := service.FindGoodInfoById(id)
  277. if err == nil {
  278. c.ServeSuccessJSON(map[string]interface{}{
  279. "goodInfo": goodInfo,
  280. })
  281. } else {
  282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  283. }
  284. }
  285. func (c *StockGoodApiController) GetAllGoodType() {
  286. adminUserInfo := c.GetAdminUserInfo()
  287. goodTypes, err := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  288. if err == nil {
  289. c.ServeSuccessJSON(map[string]interface{}{
  290. "goodType": goodTypes,
  291. })
  292. } else {
  293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  294. }
  295. }
  296. func (c *StockGoodApiController) GetAllGoodInfo() {
  297. adminUserInfo := c.GetAdminUserInfo()
  298. goodInfo, err := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
  299. if err == nil {
  300. c.ServeSuccessJSON(map[string]interface{}{
  301. "goodInfo": goodInfo,
  302. })
  303. } else {
  304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  305. }
  306. }
  307. func (c *StockGoodApiController) GetAllGood() {
  308. adminUserInfo := c.GetAdminUserInfo()
  309. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  310. dealer_id, _ := c.GetInt64("dealer_id", 0)
  311. fmt.Println(manufacturer_id)
  312. fmt.Println(dealer_id)
  313. goodInfo, err := service.FindAllGoodByManufactureId(manufacturer_id, dealer_id, adminUserInfo.CurrentOrgId)
  314. if err == nil {
  315. c.ServeSuccessJSON(map[string]interface{}{
  316. "goodInfo": goodInfo,
  317. })
  318. } else {
  319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  320. }
  321. }
  322. func (c *StockGoodApiController) GetWarehouseGoodInfo() {
  323. adminUserInfo := c.GetAdminUserInfo()
  324. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  325. dealer_id, _ := c.GetInt64("dealer_id", 0)
  326. goodInfo, err := service.FindAllGoodByManufactureId(manufacturer_id, dealer_id, adminUserInfo.CurrentOrgId)
  327. if err == nil {
  328. c.ServeSuccessJSON(map[string]interface{}{
  329. "goodInfo": goodInfo,
  330. })
  331. } else {
  332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  333. }
  334. }