stock_api_controller.go 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "github.com/astaxie/beego"
  8. "strconv"
  9. "time"
  10. )
  11. type StockApiController struct {
  12. BaseAuthAPIController
  13. }
  14. func StockApiRegistRouters() {
  15. beego.Router("/api/stock/dealer/create", &StockApiController{}, "post:CreateDealer")
  16. beego.Router("/api/stock/dealer/modify", &StockApiController{}, "post:ModifyDealer")
  17. beego.Router("/api/stock/dealer/list", &StockApiController{}, "get:GetDealersList")
  18. beego.Router("/api/stock/dealer/delete", &StockApiController{}, "post:DeleteDealer")
  19. beego.Router("/api/stock/dealer/get", &StockApiController{}, "get:GetDealer")
  20. beego.Router("/api/stock/manufacturer/create", &StockApiController{}, "post:CreateManufacturer")
  21. beego.Router("/api/stock/manufacturer/modify", &StockApiController{}, "post:ModifyManufacturer")
  22. beego.Router("/api/stock/manufacturer/list", &StockApiController{}, "get:GetManufacturerList")
  23. beego.Router("/api/stock/manufacturer/delete", &StockApiController{}, "post:DeleteManufacturer")
  24. beego.Router("/api/stock/manufacturer/get", &StockApiController{}, "get:GetManufacturer")
  25. beego.Router("/api/stock/dealer/all", &StockApiController{}, "get:GetAllDealer")
  26. beego.Router("/api/stock/manufacturer/all", &StockApiController{}, "get:GetAllManufacturer")
  27. }
  28. func (c *StockApiController) CreateDealer() {
  29. dealer_name := c.GetString("dealer_name")
  30. contact := c.GetString("contact")
  31. contact_phone := c.GetString("contact_phone")
  32. platform_number := c.GetString("platform_number")
  33. email := c.GetString("email")
  34. contact_address := c.GetString("contact_address")
  35. remark := c.GetString("remark")
  36. wubi := c.GetString("wubi")
  37. pinyin := c.GetString("pinyin")
  38. if len(dealer_name) <= 0 {
  39. utils.ErrorLog("len(dealer_name) == 0")
  40. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  41. return
  42. }
  43. adminUserInfo := c.GetAdminUserInfo()
  44. total := service.FindAllDealerTotal(adminUserInfo.CurrentOrgId)
  45. totalStr := strconv.FormatInt(total+1, 10)
  46. code := "1000" + totalStr
  47. dealer := models.Dealer{
  48. DealerName: dealer_name,
  49. Contact: contact,
  50. ContactPhone: contact_phone,
  51. ContactAddress: contact_address,
  52. DealerCode: code,
  53. Ctime: time.Now().Unix(),
  54. Mtime: time.Now().Unix(),
  55. Remark: remark,
  56. Creater: adminUserInfo.AdminUser.Id,
  57. Email: email,
  58. PlatformNumber: platform_number,
  59. OrgId: adminUserInfo.CurrentOrgId,
  60. Status: 1,
  61. WuBi: wubi,
  62. PinYin: pinyin,
  63. }
  64. err, dealers := service.AddSigleDealer(&dealer)
  65. if err == nil {
  66. c.ServeSuccessJSON(map[string]interface{}{
  67. "dealer": dealers,
  68. })
  69. } else {
  70. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  71. }
  72. }
  73. func (c *StockApiController) ModifyDealer() {
  74. id, _ := c.GetInt64("id", 0)
  75. dealer_name := c.GetString("dealer_name")
  76. contact := c.GetString("contact")
  77. contact_phone := c.GetString("contact_phone")
  78. platform_number := c.GetString("platform_number")
  79. dealer_code := c.GetString("dealer_code")
  80. email := c.GetString("email")
  81. contact_address := c.GetString("contact_address")
  82. remark := c.GetString("remark")
  83. wubi := c.GetString("wubi")
  84. pinyin := c.GetString("pinyin")
  85. if id <= 0 {
  86. utils.ErrorLog("id == 0")
  87. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  88. return
  89. }
  90. if len(dealer_name) <= 0 {
  91. utils.ErrorLog("len(dealer_name) == 0")
  92. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  93. return
  94. }
  95. adminUserInfo := c.GetAdminUserInfo()
  96. dealer := models.Dealer{
  97. ID: id,
  98. DealerName: dealer_name,
  99. Contact: contact,
  100. ContactPhone: contact_phone,
  101. ContactAddress: contact_address,
  102. Mtime: time.Now().Unix(),
  103. DealerCode: dealer_code,
  104. Remark: remark,
  105. Creater: adminUserInfo.AdminUser.Id,
  106. Email: email,
  107. PlatformNumber: platform_number,
  108. Modifier: adminUserInfo.AdminUser.Id,
  109. OrgId: adminUserInfo.CurrentOrgId,
  110. Status: 1,
  111. WuBi: wubi,
  112. PinYin: pinyin,
  113. }
  114. err := service.ModifyDealer(&dealer)
  115. if err == nil {
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "dealer": dealer,
  118. })
  119. } else {
  120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  121. }
  122. }
  123. func (c *StockApiController) GetDealersList() {
  124. page, _ := c.GetInt64("page", 1)
  125. limit, _ := c.GetInt64("limit", 7)
  126. adminUserInfo := c.GetAdminUserInfo()
  127. deales, total, err := service.FindAllDealerList(adminUserInfo.CurrentOrgId, page, limit)
  128. if err == nil {
  129. c.ServeSuccessJSON(map[string]interface{}{
  130. "dealer": deales,
  131. "total": total,
  132. })
  133. } else {
  134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  135. }
  136. }
  137. func (c *StockApiController) DeleteDealer() {
  138. id, _ := c.GetInt64("id", 0)
  139. total, _ := service.FindStockInByDealerId(id)
  140. if total > 0 {
  141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteDealerWrong)
  142. return
  143. }
  144. err := service.DeleteDealerById(id)
  145. if err == nil {
  146. c.ServeSuccessJSON(map[string]interface{}{
  147. "msg": "删除成功",
  148. })
  149. } else {
  150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  151. }
  152. }
  153. func (c *StockApiController) GetDealer() {
  154. id, _ := c.GetInt64("id", 0)
  155. dealer, err := service.FindDealerById(id)
  156. if err == nil {
  157. c.ServeSuccessJSON(map[string]interface{}{
  158. "dealer": dealer,
  159. })
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. }
  163. }
  164. func (c *StockApiController) CreateManufacturer() {
  165. manufacturer_name := c.GetString("manufacturer_name")
  166. contact := c.GetString("contact")
  167. contact_phone := c.GetString("contact_phone")
  168. platform_number := c.GetString("platform_number")
  169. email := c.GetString("email")
  170. contact_address := c.GetString("contact_address")
  171. remark := c.GetString("remark")
  172. wubi := c.GetString("wubi")
  173. pinyin := c.GetString("pinyin")
  174. if len(manufacturer_name) <= 0 {
  175. utils.ErrorLog("len(manufacturer_name) == 0")
  176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  177. return
  178. }
  179. adminUserInfo := c.GetAdminUserInfo()
  180. total := service.FindManufacturerTotal(adminUserInfo.CurrentOrgId)
  181. totalStr := strconv.FormatInt(total+1, 10)
  182. code := "2000" + totalStr
  183. manufacturer := models.Manufacturer{
  184. ManufacturerName: manufacturer_name,
  185. Contact: contact,
  186. ContactPhone: contact_phone,
  187. ContactAddress: contact_address,
  188. Ctime: time.Now().Unix(),
  189. Mtime: time.Now().Unix(),
  190. Remark: remark,
  191. Creater: adminUserInfo.AdminUser.Id,
  192. Email: email,
  193. PlatformNumber: platform_number,
  194. OrgId: adminUserInfo.CurrentOrgId,
  195. Status: 1,
  196. ManufacturerCode: code,
  197. WuBi: wubi,
  198. PinYin: pinyin,
  199. }
  200. err, manufacturers := service.AddSigleManufacturer(&manufacturer)
  201. if err == nil {
  202. c.ServeSuccessJSON(map[string]interface{}{
  203. "manufacturer": manufacturers,
  204. })
  205. } else {
  206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  207. }
  208. }
  209. func (c *StockApiController) ModifyManufacturer() {
  210. id, _ := c.GetInt64("id", 0)
  211. manufacturer_name := c.GetString("manufacturer_name")
  212. contact := c.GetString("contact")
  213. contact_phone := c.GetString("contact_phone")
  214. platform_number := c.GetString("platform_number")
  215. email := c.GetString("email")
  216. contact_address := c.GetString("contact_address")
  217. remark := c.GetString("remark")
  218. manufacturer_code := c.GetString("manufacturer_code")
  219. wubi := c.GetString("wubi")
  220. pinyin := c.GetString("pinyin")
  221. if id <= 0 {
  222. utils.ErrorLog("id == 0")
  223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  224. return
  225. }
  226. if len(manufacturer_name) <= 0 {
  227. utils.ErrorLog("len(manufacturer_name) == 0")
  228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  229. return
  230. }
  231. adminUserInfo := c.GetAdminUserInfo()
  232. manufacturer := models.Manufacturer{
  233. ID: id,
  234. ManufacturerName: manufacturer_name,
  235. Contact: contact,
  236. ContactPhone: contact_phone,
  237. ContactAddress: contact_address,
  238. Mtime: time.Now().Unix(),
  239. Remark: remark,
  240. Creater: adminUserInfo.AdminUser.Id,
  241. Email: email,
  242. PlatformNumber: platform_number,
  243. Modifier: adminUserInfo.AdminUser.Id,
  244. OrgId: adminUserInfo.CurrentOrgId,
  245. ManufacturerCode: manufacturer_code,
  246. Status: 1,
  247. WuBi: wubi,
  248. PinYin: pinyin,
  249. }
  250. err := service.ModifyManufacturer(&manufacturer)
  251. if err == nil {
  252. c.ServeSuccessJSON(map[string]interface{}{
  253. "manufacturer": manufacturer,
  254. })
  255. } else {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  257. }
  258. }
  259. func (c *StockApiController) GetManufacturerList() {
  260. page, _ := c.GetInt64("page", 1)
  261. limit, _ := c.GetInt64("limit", 10)
  262. adminUserInfo := c.GetAdminUserInfo()
  263. manufacturer, total, err := service.FindAllManufacturerList(adminUserInfo.CurrentOrgId, page, limit)
  264. if err == nil {
  265. c.ServeSuccessJSON(map[string]interface{}{
  266. "manufacturer": manufacturer,
  267. "total": total,
  268. })
  269. } else {
  270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  271. }
  272. }
  273. func (c *StockApiController) DeleteManufacturer() {
  274. id, _ := c.GetInt64("id", 0)
  275. total, _ := service.FindStockInByManufacturerId(id)
  276. if total > 0 {
  277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteManufacturerWrong)
  278. return
  279. }
  280. err := service.DeleteManufacturerById(id)
  281. if err == nil {
  282. c.ServeSuccessJSON(map[string]interface{}{
  283. "msg": "删除成功",
  284. })
  285. } else {
  286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  287. }
  288. }
  289. func (c *StockApiController) GetManufacturer() {
  290. id, _ := c.GetInt64("id", 0)
  291. manufacturer, err := service.FindManufacturerById(id)
  292. if err == nil {
  293. c.ServeSuccessJSON(map[string]interface{}{
  294. "manufacturer": manufacturer,
  295. })
  296. } else {
  297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  298. }
  299. }
  300. func (c *StockApiController) GetAllDealer() {
  301. adminUserInfo := c.GetAdminUserInfo()
  302. dealer, err := service.FindAllDealer(adminUserInfo.CurrentOrgId)
  303. if err == nil {
  304. c.ServeSuccessJSON(map[string]interface{}{
  305. "dealer": dealer,
  306. })
  307. } else {
  308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  309. }
  310. }
  311. func (c *StockApiController) GetAllManufacturer() {
  312. adminUserInfo := c.GetAdminUserInfo()
  313. manufacturer, err := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
  314. if err == nil {
  315. c.ServeSuccessJSON(map[string]interface{}{
  316. "manufacturer": manufacturer,
  317. })
  318. } else {
  319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  320. }
  321. }