面包店
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

hdl_scheme.go 6.1 KiB

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