common.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. package common
  2. import (
  3. "mtp2_if/global/app"
  4. "mtp2_if/global/e"
  5. "mtp2_if/logger"
  6. "mtp2_if/models"
  7. "net/http"
  8. "strconv"
  9. "time"
  10. "github.com/gin-gonic/gin"
  11. )
  12. // QueryProvincesAndCitiesReq 查询省市信息请求参数
  13. type QueryProvincesAndCitiesReq struct {
  14. ProvinceID int `form:"provinceID"` // 省ID
  15. }
  16. // QueryProvincesAndCitiesRsp 查询省市信息返回模型
  17. type QueryProvincesAndCitiesRsp struct {
  18. Province models.Division // 省
  19. Cities []models.Division // 市
  20. }
  21. // QueryProvincesAndCities 查询省市信息(不包括区)
  22. // @Summary 查询省市信息(不包括区)
  23. // @Produce json
  24. // @Param provinceID query int false "省ID"
  25. // @Success 200 {object} QueryProvincesAndCitiesRsp
  26. // @Failure 500 {object} app.Response
  27. // @Router /Common/QueryProvincesAndCities [get]
  28. // @Tags 通用服务
  29. func QueryProvincesAndCities(c *gin.Context) {
  30. appG := app.Gin{C: c}
  31. // 获取请求参数
  32. var req QueryProvincesAndCitiesReq
  33. if err := appG.C.ShouldBindQuery(&req); err != nil {
  34. logger.GetLogger().Errorf("QueryProvincesAndCities failed: %s", err.Error())
  35. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  36. return
  37. }
  38. // 获取省市信息
  39. provinces, err := models.GetProvincesAndCities(req.ProvinceID)
  40. if err != nil {
  41. // 查询失败
  42. logger.GetLogger().Errorf("QueryProvincesAndCities failed: %s", err.Error())
  43. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  44. return
  45. }
  46. // 分解省市数据
  47. // Golang Map元素取址问题: cannot assign to struct field XXXX in map
  48. // https://blog.csdn.net/makenothing/article/details/105037977
  49. pMap := make(map[string]*QueryProvincesAndCitiesRsp)
  50. // 构建省节点
  51. for _, v := range provinces {
  52. if v.Divisionlevel == "province" {
  53. pMap[v.Divisioncode] = &QueryProvincesAndCitiesRsp{Province: v, Cities: make([]models.Division, 0)}
  54. }
  55. }
  56. // 为省节点增加市信息
  57. for _, v := range provinces {
  58. if v.Divisionlevel == "city" {
  59. pMap[v.Parentcode].Cities = append(pMap[v.Parentcode].Cities, v)
  60. }
  61. }
  62. // map to slice
  63. rst := make([]QueryProvincesAndCitiesRsp, 0)
  64. for _, v := range pMap {
  65. rst = append(rst, *v)
  66. }
  67. // 查询成功
  68. logger.GetLogger().Debugln("QueryProvincesAndCities successed: %v", rst)
  69. appG.Response(http.StatusOK, e.SUCCESS, rst)
  70. }
  71. // GetDivisions 查询区域信息
  72. // @Summary 查询区域信息
  73. // @Produce json
  74. // @Success 200 {object} models.Division
  75. // @Failure 500 {object} app.Response
  76. // @Router /Common/GetDivisions [get]
  77. // @Tags 通用服务
  78. func GetDivisions(c *gin.Context) {
  79. appG := app.Gin{C: c}
  80. divisions, err := models.GetDivisions()
  81. if err != nil {
  82. // 查询失败
  83. logger.GetLogger().Errorf("GetDivisions failed: %s", err.Error())
  84. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  85. return
  86. }
  87. // 查询成功
  88. logger.GetLogger().Debugln("GetDivisions successed: %v", divisions)
  89. appG.Response(http.StatusOK, e.SUCCESS, divisions)
  90. }
  91. // QueryImageConfigsReq 查询轮播图配置信息请求参数
  92. type QueryImageConfigsReq struct {
  93. ImageType int `form:"imageType"`
  94. UserId int64 `form:"userId"`
  95. }
  96. // QueryImageConfigsRsp 查询轮播图配置信息返回模型
  97. type QueryImageConfigsRsp struct {
  98. Configid int64 `json:"configid" xorm:"'CONFIGID'" binding:"required"` // 配置ID(SEQ_SZDZ2_IMAGECONFIG)
  99. Imagetype int32 `json:"imagetype" xorm:"'IMAGETYPE'"` // 类型 - 1:首页轮播(移动) 2:我的(移动)
  100. Title string `json:"title" xorm:"'TITLE'"` // 标题
  101. Imagepath string `json:"imagepath" xorm:"'IMAGEPATH'"` // 图片
  102. URL string `json:"url" xorm:"'URL'"` // 链接(地址或商品ID)
  103. Sort int64 `json:"sort" xorm:"'SORT'"` // 排序
  104. Isshow int32 `json:"isshow" xorm:"'ISSHOW'"` // 是否展示 - 0:不展示 1:展示
  105. Createdate time.Time `json:"-" xorm:"'CREATEDATE'"` // 创建时间
  106. Creatorid int64 `json:"-" xorm:"'CREATORID'"` // 创建人
  107. Updatedate time.Time `json:"-" xorm:"'UPDATEDATE'"` // 修改时间
  108. Modifierid int64 `json:"-" xorm:"'MODIFIERID'"` // 操作人
  109. Areauserid int64 `json:"-" xorm:"'AREAUSERID'"` // 所属机构ID
  110. Urltype int32 `json:"urltype" xorm:"'URLTYPE'"` // 链接类型 - 1:直接地址 2:商品ID
  111. IMAGEDETAILPATH string `json:"imagedetailpath" xorm:"'IMAGEDETAILPATH'"` // 详情图片 [UrlType = 3时 有且必填,其它类型不需要]
  112. MarketID int `json:"marketid"` // 市场ID
  113. TradeMode int `json:"trademode"` // 交易模式
  114. }
  115. // QueryImageConfigs 查询轮播图配置信息
  116. // @Summary 查询轮播图配置信息
  117. // @Produce json
  118. // @Param userId query int false "用户id"
  119. // @Param imageType query int false "类型 - 1:App首页轮播 2:我的 3:首页(PC) 4:首页推广(移动-新会)"
  120. // @Success 200 {object} QueryImageConfigsRsp
  121. // @Failure 500 {object} app.Response
  122. // @Router /Common/QueryImageConfigs [get]
  123. // @Tags 通用服务
  124. func QueryImageConfigs(c *gin.Context) {
  125. appG := app.Gin{C: c}
  126. // 获取请求参数
  127. var req QueryImageConfigsReq
  128. if err := appG.C.ShouldBindQuery(&req); err != nil {
  129. logger.GetLogger().Errorf("QueryImageConfigs failed: %s", err.Error())
  130. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  131. return
  132. }
  133. imageConfigs, err := models.GetImageConfigs(req.UserId, req.ImageType)
  134. if err != nil {
  135. // 查询失败
  136. logger.GetLogger().Errorf("QueryImageConfigs failed: %s", err.Error())
  137. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  138. return
  139. }
  140. rst := make([]QueryImageConfigsRsp, 0)
  141. for _, v := range imageConfigs {
  142. item := QueryImageConfigsRsp{
  143. Configid: v.Configid,
  144. Imagetype: v.Imagetype,
  145. Title: v.Title,
  146. Imagepath: v.Imagepath,
  147. URL: v.URL,
  148. Sort: v.Sort,
  149. Isshow: v.Isshow,
  150. Createdate: v.Createdate,
  151. Creatorid: v.Creatorid,
  152. Updatedate: v.Updatedate,
  153. Modifierid: v.Modifierid,
  154. Areauserid: v.Areauserid,
  155. Urltype: v.Urltype,
  156. IMAGEDETAILPATH: v.IMAGEDETAILPATH,
  157. }
  158. if item.Urltype == 2 {
  159. if i, err := strconv.Atoi(v.URL); err == nil {
  160. if market, _ := models.GetMarketByGoodsID(i); market != nil {
  161. item.MarketID = int(market.MARKETID)
  162. item.TradeMode = int(market.TRADEMODE)
  163. }
  164. }
  165. }
  166. rst = append(rst, item)
  167. }
  168. // 查询成功
  169. logger.GetLogger().Debugln("QueryImageConfigs successed: %v", rst)
  170. appG.Response(http.StatusOK, e.SUCCESS, rst)
  171. }
  172. // GetAllEnumsReq 获取所有枚举信息请求参数
  173. type GetAllEnumsReq struct {
  174. Autoid int `form:"autoid"`
  175. }
  176. // GetAllEnums 获取所有枚举信息
  177. // @Summary 获取所有枚举信息
  178. // @Description autoid传入后则返回这个ID之后的数据;如不传则返回所有
  179. // @Produce json
  180. // @Param autoid query int false "起始自增ID"
  181. // @Success 200 {object} models.Enumdicitem
  182. // @Failure 500 {object} app.Response
  183. // @Router /Common/GetAllEnums [get]
  184. // @Tags 通用服务
  185. func GetAllEnums(c *gin.Context) {
  186. appG := app.Gin{C: c}
  187. // 获取请求参数
  188. var req GetAllEnumsReq
  189. if err := appG.C.ShouldBindQuery(&req); err != nil {
  190. logger.GetLogger().Errorf("GetAllEnums failed: %s", err.Error())
  191. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  192. return
  193. }
  194. enums, err := models.GetEnums(req.Autoid)
  195. if err != nil {
  196. // 查询失败
  197. logger.GetLogger().Errorf("GetAllEnums failed: %s", err.Error())
  198. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  199. return
  200. }
  201. // 查询成功
  202. // logger.GetLogger().Debugln("GetAllEnums successed: %v", imageConfigs)
  203. appG.Response(http.StatusOK, e.SUCCESS, enums)
  204. }
  205. // GetServerTime 获取服务器时间
  206. // @Summary 获取服务器时间
  207. // @Produce json
  208. // @Success 200 {object} app.Response
  209. // @Failure 500 {object} app.Response
  210. // @Router /Common/GetServerTime [get]
  211. // @Tags 通用服务
  212. func GetServerTime(c *gin.Context) {
  213. appG := app.Gin{C: c}
  214. rst, err := models.GetServerTime()
  215. if err != nil {
  216. // 查询失败
  217. logger.GetLogger().Errorf("GetServerTime failed: %s", err.Error())
  218. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  219. return
  220. }
  221. // 查询成功
  222. logger.GetLogger().Debugln("GetServerTime successed: %v", rst)
  223. appG.Response(http.StatusOK, e.SUCCESS, rst)
  224. }
  225. // QueryMemberGoodsLimitConfig
  226. // @Summary 查询会员商品限制配置表
  227. // @Produce json
  228. // @Param userid query int true "用户ID"
  229. // @Param roletype query int true "会员角色 - 6:自营会员 7:经纪会员"
  230. // @Success 200 {array} models.Membergoodslimitconfig
  231. // @Failure 500 {object} app.Response
  232. // @Router /Common/QueryMemberGoodsLimitConfig [get]
  233. // @Tags 通用服务
  234. func QueryMemberGoodsLimitConfig(c *gin.Context) {
  235. a := app.GinUtils{Gin: app.Gin{C: c}}
  236. m := models.Membergoodslimitconfig{}
  237. a.DoBindReq(&m)
  238. a.DoGetDataEx(&m)
  239. }
  240. type GetWskhOpenAccountConfigsReq struct {
  241. Configs string `form:"configs" binding:"required"` // 配置ID列表,格式:1,2,3
  242. }
  243. // GetWskhOpenAccountConfigs 获取网上开户配置信息
  244. // @Summary 获取网上开户配置信息
  245. // @Produce json
  246. // @Security ApiKeyAuth
  247. // @Param configs query string true "配置ID列表,格式:1,2,3"
  248. // @Success 200 {array} models.Wskhopenaccountconfig
  249. // @Failure 500 {object} app.Response
  250. // @Router /Common/GetWskhOpenAccountConfigs [get]
  251. // @Tags 通用服务
  252. func GetWskhOpenAccountConfigs(c *gin.Context) {
  253. appG := app.Gin{C: c}
  254. // 获取请求参数
  255. var req GetWskhOpenAccountConfigsReq
  256. if err := appG.C.ShouldBindQuery(&req); err != nil {
  257. logger.GetLogger().Errorf("GetWskhOpenAccountConfigs failed: %s", err.Error())
  258. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  259. return
  260. }
  261. datas, err := models.GetWskhOpenAccountConfigs(req.Configs)
  262. if err != nil {
  263. // 查询失败
  264. logger.GetLogger().Errorf("GetWskhOpenAccountConfigs failed: %s", err.Error())
  265. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  266. return
  267. }
  268. // 查询成功
  269. appG.Response(http.StatusOK, e.SUCCESS, datas)
  270. }
  271. // GetI18nConfigs 获取枚举项字典扩展表信息
  272. // @Summary 获取枚举项字典扩展表信息
  273. // @Produce json
  274. // @Success 200 {array} models.I18nConfig
  275. // @Failure 500 {object} app.Response
  276. // @Router /Common/GetI18nConfigs [get]
  277. // @Tags 通用服务
  278. func GetI18nConfigs(c *gin.Context) {
  279. appG := app.Gin{C: c}
  280. datas, err := models.GetI18nConfigs()
  281. if err != nil {
  282. // 查询失败
  283. logger.GetLogger().Errorf("GetI18nConfigs failed: %s", err.Error())
  284. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  285. return
  286. }
  287. // 查询成功
  288. appG.Response(http.StatusOK, e.SUCCESS, datas)
  289. }
  290. type GetGetSystemParamsReq struct {
  291. Codes string `form:"codes"` // 参数代码,格式:1,2,3
  292. }
  293. // GetSystemParams 获取系统参数信息
  294. // @Summary 获取系统参数信息
  295. // @Produce json
  296. // @Param codes query string false "参数代码,格式:1,2,3"
  297. // @Success 200 {array} models.I18nConfig
  298. // @Failure 500 {object} app.Response
  299. // @Router /Common/GetSystemParams [get]
  300. // @Tags 通用服务
  301. func GetSystemParams(c *gin.Context) {
  302. appG := app.Gin{C: c}
  303. // 获取请求参数
  304. var req GetGetSystemParamsReq
  305. if err := appG.C.ShouldBindQuery(&req); err != nil {
  306. logger.GetLogger().Errorf("GetSystemParams failed: %s", err.Error())
  307. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  308. return
  309. }
  310. datas, err := models.GetSystemParamsByCodes(req.Codes)
  311. if err != nil {
  312. // 查询失败
  313. logger.GetLogger().Errorf("GetSystemParams failed: %s", err.Error())
  314. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  315. return
  316. }
  317. // 查询成功
  318. appG.Response(http.StatusOK, e.SUCCESS, datas)
  319. }
  320. // getClientDocumnetConfigs 获取终端文档配置信息
  321. // @Summary 获取终端文档配置信息
  322. // @Produce json
  323. // @Success 200 {array} models.ClientDocumentConfig
  324. // @Failure 500 {object} app.Response
  325. // @Router /Common/GetClientDocumnetConfigs [get]
  326. // @Tags 通用服务
  327. func GetClientDocumnetConfigs(c *gin.Context) {
  328. appG := app.Gin{C: c}
  329. datas, err := models.GetClientDocumnetConfigs()
  330. if err != nil {
  331. // 查询失败
  332. logger.GetLogger().Errorf("GetClientDocumnetConfigs failed: %s", err.Error())
  333. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  334. return
  335. }
  336. // 查询成功
  337. appG.Response(http.StatusOK, e.SUCCESS, datas)
  338. }