stock_good_api_controller.go 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. autoDetail, _ := service.FindStockOutDetailGoodInfoByGoodId(id)
  112. if len(goodInfo) > 0 {
  113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodTypeFail)
  114. return
  115. }
  116. if len(autoDetail) > 0 {
  117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodInfoFail)
  118. return
  119. }
  120. err := service.DeleteGoodTypeById(id, adminUserInfo.AdminUser.Id)
  121. if err == nil {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "msg": "删除成功",
  124. })
  125. } else {
  126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  127. }
  128. }
  129. func (c *StockGoodApiController) GetGoodType() {
  130. id, _ := c.GetInt64("id", 0)
  131. goodType, err := service.FindGoodTypeById(id)
  132. if err == nil {
  133. c.ServeSuccessJSON(map[string]interface{}{
  134. "goodType": goodType,
  135. })
  136. } else {
  137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  138. }
  139. }
  140. func (c *StockGoodApiController) CreateGoodInfo() {
  141. good_id, _ := c.GetInt64("good_id", 0)
  142. specification_name := c.GetString("specification_name")
  143. good_unit, _ := c.GetInt64("good_unit", -1)
  144. buy_price, _ := c.GetFloat("buy_price", 0)
  145. sell_price, _ := c.GetFloat("sell_price", 0)
  146. remark := c.GetString("remark")
  147. manufacturer, _ := c.GetInt64("manufacturer", 0)
  148. dealer, _ := c.GetInt64("dealer", 0)
  149. expiry_date_warn_day_count, _ := c.GetInt64("expiry_date_warn_day_count", 0)
  150. stock_warn_count, _ := c.GetInt64("stock_warn_count", 0)
  151. is_reuse, _ := c.GetInt64("is_reuse", 0)
  152. adminUserInfo := c.GetAdminUserInfo()
  153. totals := service.FindGoodInfoByName(specification_name, adminUserInfo.CurrentOrgId)
  154. if totals > 0 {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGoodInfoNameExistError)
  156. return
  157. }
  158. total := service.FindAllGoodInfoTotal(adminUserInfo.CurrentOrgId)
  159. code := strconv.FormatInt(total+1, 10)
  160. code = "24000000" + code
  161. goodInfo := models.GoodInfo{
  162. GoodCode: code,
  163. SpecificationName: specification_name,
  164. GoodTypeId: good_id,
  165. GoodUnit: good_unit,
  166. BuyPrice: buy_price,
  167. SellPrice: sell_price,
  168. Remark: remark,
  169. Ctime: time.Now().Unix(),
  170. Manufacturer: manufacturer,
  171. Dealer: dealer,
  172. ExpiryDateWarnDayCount: expiry_date_warn_day_count,
  173. StockWarnCount: stock_warn_count,
  174. IsReuse: is_reuse,
  175. Status: 1,
  176. OrgId: adminUserInfo.CurrentOrgId,
  177. Creater: adminUserInfo.AdminUser.Id,
  178. }
  179. err, goodInfos := service.AddSigleGoodInfo(&goodInfo)
  180. if err == nil {
  181. c.ServeSuccessJSON(map[string]interface{}{
  182. "goodInfo": goodInfos,
  183. })
  184. } else {
  185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  186. }
  187. }
  188. func (c *StockGoodApiController) ModifyGoodInfo() {
  189. id, _ := c.GetInt64("id", 0)
  190. good_id, _ := c.GetInt64("good_id", 0)
  191. specification_name := c.GetString("specification_name")
  192. good_unit, _ := c.GetInt64("good_unit", -1)
  193. buy_price, _ := c.GetFloat("buy_price", 0)
  194. sell_price, _ := c.GetFloat("sell_price", 0)
  195. remark := c.GetString("remark")
  196. manufacturer, _ := c.GetInt64("manufacturer", 0)
  197. dealer, _ := c.GetInt64("dealer", 0)
  198. expiry_date_warn_day_count, _ := c.GetInt64("expiry_date_warn_day_count", 0)
  199. stock_warn_count, _ := c.GetInt64("stock_warn_count", 0)
  200. is_reuse, _ := c.GetInt64("is_reuse", 0)
  201. code := c.GetString("good_code")
  202. adminUserInfo := c.GetAdminUserInfo()
  203. //totals := service.FindGoodInfoByName(specification_name, adminUserInfo.CurrentOrgId)
  204. //if totals > 0 {
  205. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGoodInfoNameExistError)
  206. // return
  207. //}
  208. goodInfo := models.GoodInfo{
  209. ID: id,
  210. GoodCode: code,
  211. SpecificationName: specification_name,
  212. GoodTypeId: good_id,
  213. GoodUnit: good_unit,
  214. BuyPrice: buy_price,
  215. SellPrice: sell_price,
  216. Remark: remark,
  217. Mtime: time.Now().Unix(),
  218. Manufacturer: manufacturer,
  219. Dealer: dealer,
  220. ExpiryDateWarnDayCount: expiry_date_warn_day_count,
  221. StockWarnCount: stock_warn_count,
  222. IsReuse: is_reuse,
  223. Status: 1,
  224. OrgId: adminUserInfo.CurrentOrgId,
  225. Modifier: adminUserInfo.AdminUser.Id,
  226. }
  227. err, goodInfos := service.ModifyGoodInfo(&goodInfo)
  228. if err == nil {
  229. c.ServeSuccessJSON(map[string]interface{}{
  230. "goodInfo": goodInfos,
  231. })
  232. } else {
  233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  234. }
  235. }
  236. func (c *StockGoodApiController) GetGoodInfoList() {
  237. page, _ := c.GetInt64("page", 1)
  238. limit, _ := c.GetInt64("limit", 7)
  239. keyword := c.GetString("keyword")
  240. adminUserInfo := c.GetAdminUserInfo()
  241. goodInfos, total, err := service.FindGoodInfoList(adminUserInfo.CurrentOrgId, page, limit, keyword)
  242. if err == nil {
  243. c.ServeSuccessJSON(map[string]interface{}{
  244. "list": goodInfos,
  245. "total": total,
  246. })
  247. } else {
  248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  249. }
  250. }
  251. func (c *StockGoodApiController) DeleteGoodInfo() {
  252. id, _ := c.GetInt64("id", 0)
  253. adminUserInfo := c.GetAdminUserInfo()
  254. total, _ := service.FindWarehouseInfoTotalByGoodId(id)
  255. total2, _ := service.FindWarehouseOutInfoTotalByGoodId(id)
  256. if total > 0 {
  257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodInfoFail)
  258. return
  259. }
  260. if total2 > 0 {
  261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodInfoFail)
  262. return
  263. }
  264. err := service.DeleteGoodInfoById(id, adminUserInfo.AdminUser.Id)
  265. if err == nil {
  266. c.ServeSuccessJSON(map[string]interface{}{
  267. "msg": "删除成功",
  268. })
  269. } else {
  270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  271. }
  272. }
  273. func (c *StockGoodApiController) GetGoodInfoByGoodId() {
  274. id, _ := c.GetInt64("id", 0)
  275. goodInfo, err := service.FindGoodInfoByGoodId(id)
  276. if err == nil {
  277. c.ServeSuccessJSON(map[string]interface{}{
  278. "list": goodInfo,
  279. })
  280. } else {
  281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  282. }
  283. }
  284. func (c *StockGoodApiController) GetGoodInfoById() {
  285. id, _ := c.GetInt64("id", 0)
  286. goodInfo, err := service.FindGoodInfoById(id)
  287. if err == nil {
  288. c.ServeSuccessJSON(map[string]interface{}{
  289. "goodInfo": goodInfo,
  290. })
  291. } else {
  292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  293. }
  294. }
  295. func (c *StockGoodApiController) GetAllGoodType() {
  296. adminUserInfo := c.GetAdminUserInfo()
  297. goodTypes, err := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
  298. if err == nil {
  299. c.ServeSuccessJSON(map[string]interface{}{
  300. "goodType": goodTypes,
  301. })
  302. } else {
  303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  304. }
  305. }
  306. func (c *StockGoodApiController) GetAllGoodInfo() {
  307. adminUserInfo := c.GetAdminUserInfo()
  308. goodInfo, err := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
  309. if err == nil {
  310. c.ServeSuccessJSON(map[string]interface{}{
  311. "goodInfo": goodInfo,
  312. })
  313. } else {
  314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  315. }
  316. }
  317. func (c *StockGoodApiController) GetAllGood() {
  318. adminUserInfo := c.GetAdminUserInfo()
  319. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  320. dealer_id, _ := c.GetInt64("dealer_id", 0)
  321. fmt.Println(manufacturer_id)
  322. fmt.Println(dealer_id)
  323. goodInfo, err := service.FindAllGoodByManufactureId(manufacturer_id, dealer_id, adminUserInfo.CurrentOrgId)
  324. if err == nil {
  325. c.ServeSuccessJSON(map[string]interface{}{
  326. "goodInfo": goodInfo,
  327. })
  328. } else {
  329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  330. }
  331. }
  332. func (c *StockGoodApiController) GetWarehouseGoodInfo() {
  333. adminUserInfo := c.GetAdminUserInfo()
  334. manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
  335. dealer_id, _ := c.GetInt64("dealer_id", 0)
  336. goodInfo, err := service.FindAllGoodByManufactureId(manufacturer_id, dealer_id, adminUserInfo.CurrentOrgId)
  337. if err == nil {
  338. c.ServeSuccessJSON(map[string]interface{}{
  339. "goodInfo": goodInfo,
  340. })
  341. } else {
  342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  343. }
  344. }