面包店
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

277 wiersze
6.0 KiB

  1. package hdl
  2. import (
  3. "applet/app/admin/enum"
  4. "applet/app/admin/lib/validate"
  5. "applet/app/admin/md"
  6. "applet/app/admin/svc"
  7. svc2 "applet/app/admin/svc/category"
  8. "applet/app/admin/svc/goods"
  9. "applet/app/db"
  10. "applet/app/db/model"
  11. "applet/app/e"
  12. "applet/app/utils"
  13. "github.com/gin-gonic/gin"
  14. "time"
  15. )
  16. func SchemeList(c *gin.Context) {
  17. schemeDb := db.SchemeDb{}
  18. schemeDb.Set()
  19. schemeList, err := schemeDb.FindScheme()
  20. if err != nil {
  21. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  22. return
  23. }
  24. schemeEnterpriseDb := db.SchemeEnterpriseDb{}
  25. schemeEnterpriseDb.Set()
  26. enterpriseDb := db.EnterpriseDb{}
  27. enterpriseDb.Set()
  28. var result []*md.SchemeListResp
  29. for _, v := range *schemeList {
  30. var temp md.SchemeListResp
  31. temp.Data = v
  32. schemeWithEnterprises, err1 := schemeEnterpriseDb.FindSchemeEnterprise(v.Id)
  33. if err1 != nil {
  34. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  35. return
  36. }
  37. for _, schemeWithEnterprise := range *schemeWithEnterprises {
  38. enterprise, err2 := enterpriseDb.GetEnterprise(schemeWithEnterprise.EnterpriseId)
  39. if err2 != nil {
  40. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  41. return
  42. }
  43. temp.EnterpriseList = append(temp.EnterpriseList, struct {
  44. Id int `json:"id"`
  45. Name string `json:"name"`
  46. }{
  47. Id: enterprise.Id,
  48. Name: enterprise.Name,
  49. })
  50. }
  51. result = append(result, &temp)
  52. }
  53. e.OutSuc(c, map[string]interface{}{
  54. "list": result,
  55. "state": []map[string]interface{}{
  56. {
  57. "name": enum.SchemeState(enum.SchemeStateForNormal).String(),
  58. "value": enum.SchemeStateForNormal,
  59. },
  60. {
  61. "name": enum.SchemeState(enum.SchemeStateForFreeze).String(),
  62. "value": enum.SchemeStateForFreeze,
  63. },
  64. },
  65. }, nil)
  66. return
  67. }
  68. func AddScheme(c *gin.Context) {
  69. var req md.AddSchemeReq
  70. err := c.ShouldBindJSON(&req)
  71. if err != nil {
  72. err = validate.HandleValidateErr(err)
  73. err1 := err.(e.E)
  74. e.OutErr(c, err1.Code, err1.Error())
  75. return
  76. }
  77. schemeDb := db.SchemeDb{}
  78. schemeDb.Set()
  79. now := time.Now()
  80. _, err = schemeDb.SchemeInsert(&model.Scheme{
  81. Name: req.Name,
  82. State: enum.SchemeStateForNormal,
  83. Memo: req.Memo,
  84. CreateAt: now.Format("2006-01-02 15:04:05"),
  85. UpdateAt: now.Format("2006-01-02 15:04:05"),
  86. })
  87. if err != nil {
  88. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  89. return
  90. }
  91. e.OutSuc(c, "success", nil)
  92. return
  93. }
  94. func UpdateScheme(c *gin.Context) {
  95. var req md.UpdateSchemeReq
  96. err := c.ShouldBindJSON(&req)
  97. if err != nil {
  98. err = validate.HandleValidateErr(err)
  99. err1 := err.(e.E)
  100. e.OutErr(c, err1.Code, err1.Error())
  101. return
  102. }
  103. schemeDb := db.SchemeDb{}
  104. schemeDb.Set()
  105. scheme, err := schemeDb.GetScheme(req.Id)
  106. if err != nil {
  107. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  108. return
  109. }
  110. if scheme == nil {
  111. e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
  112. return
  113. }
  114. scheme.Name = req.Name
  115. scheme.Memo = req.Memo
  116. _, err = schemeDb.UpdateScheme(scheme, "name", "memo")
  117. if err != nil {
  118. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  119. return
  120. }
  121. e.OutSuc(c, "success", nil)
  122. return
  123. }
  124. func SchemeBindEnterprise(c *gin.Context) {
  125. var req md.SchemeBindEnterpriseReq
  126. err := c.ShouldBindJSON(&req)
  127. if err != nil {
  128. err = validate.HandleValidateErr(err)
  129. err1 := err.(e.E)
  130. e.OutErr(c, err1.Code, err1.Error())
  131. return
  132. }
  133. err = svc.SchemeBindEnterprise(req)
  134. if err != nil {
  135. e.OutErr(c, e.ERR, err.Error())
  136. return
  137. }
  138. e.OutSuc(c, "success", nil)
  139. return
  140. }
  141. func UpdateSchemeState(c *gin.Context) {
  142. var req md.UpdateSchemeStateReq
  143. err := c.ShouldBindJSON(&req)
  144. if err != nil {
  145. err = validate.HandleValidateErr(err)
  146. err1 := err.(e.E)
  147. e.OutErr(c, err1.Code, err1.Error())
  148. return
  149. }
  150. schemeDb := db.SchemeDb{}
  151. schemeDb.Set()
  152. scheme, err := schemeDb.GetScheme(req.Id)
  153. if err != nil {
  154. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  155. return
  156. }
  157. if scheme == nil {
  158. e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
  159. return
  160. }
  161. scheme.State = req.State
  162. _, err = schemeDb.UpdateScheme(scheme, "state")
  163. if err != nil {
  164. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  165. return
  166. }
  167. e.OutSuc(c, "success", nil)
  168. return
  169. }
  170. func DeleteScheme(c *gin.Context) {
  171. id := c.Param("id")
  172. schemeDb := db.SchemeDb{}
  173. schemeDb.Set()
  174. scheme, err := schemeDb.GetScheme(utils.StrToInt(id))
  175. if err != nil {
  176. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  177. return
  178. }
  179. if scheme == nil {
  180. e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
  181. return
  182. }
  183. err = svc.DeleteScheme(utils.StrToInt(id))
  184. if err != nil {
  185. e.OutErr(c, e.ERR, err.Error())
  186. return
  187. }
  188. e.OutSuc(c, "success", nil)
  189. return
  190. }
  191. func SchemeGoodsDetail(c *gin.Context) {
  192. goodsId := c.Query("goods_id")
  193. if goodsId == "" {
  194. goodsId = "0"
  195. }
  196. schemeId := c.Query("scheme_id")
  197. if schemeId == "" {
  198. schemeId = "0"
  199. }
  200. resp, err := svc.MallGoodsDetailByScheme(c, utils.StrToInt64(goodsId), utils.StrToInt(schemeId))
  201. if err != nil {
  202. e.OutErr(c, 400, err.Error())
  203. return
  204. }
  205. e.OutSuc(c, resp, nil)
  206. return
  207. }
  208. func SaveSchemeGoods(c *gin.Context) {
  209. var req md.SaveSchemeGoodsReq
  210. err := c.ShouldBindJSON(&req)
  211. if err != nil {
  212. err = validate.HandleValidateErr(err)
  213. err1 := err.(e.E)
  214. e.OutErr(c, err1.Code, err1.Error())
  215. return
  216. }
  217. err = svc.SaveSchemeGoods(req)
  218. if err != nil {
  219. e.OutErr(c, e.ERR, err.Error())
  220. return
  221. }
  222. e.OutSuc(c, "success", nil)
  223. return
  224. }
  225. func GoodsList(c *gin.Context) {
  226. var args md.MallGoodsListReq
  227. args.Title = c.Query("title")
  228. args.CategoryId = c.Query("category_id")
  229. args.SaleState = c.Query("sale_state")
  230. args.PageId = c.Query("page")
  231. args.PageSize = c.Query("limit")
  232. args.SkuCode = c.Query("sku_code")
  233. tree, err := svc2.GetAllCategory(c)
  234. data, total, err := goods.GetMallGoodsList(c, &args)
  235. if err != nil {
  236. e.OutErr(c, e.ERR_NO_DATA, err)
  237. return
  238. }
  239. var returnData = map[string]interface{}{
  240. "total": total,
  241. "cateList": tree,
  242. // "dataList": data,
  243. //-1审核拒绝 0审核中 1销售中 2已售罄 3放入仓库 4下架
  244. "stateList": []map[string]interface{}{
  245. {"name": "全部", "value": 99},
  246. {"name": "销售中", "value": 1},
  247. {"name": "已下架", "value": 2},
  248. },
  249. }
  250. if data == nil {
  251. returnData["dataList"] = []string{}
  252. } else {
  253. returnData["dataList"] = data
  254. }
  255. e.OutSuc(c, returnData, nil)
  256. return
  257. }