common.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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. Enumdiccode string `form:"enumdiccode"`
  176. }
  177. // GetAllEnums 获取所有枚举信息
  178. // @Summary 获取所有枚举信息
  179. // @Description autoid传入后则返回这个ID之后的数据;如不传则返回所有
  180. // @Produce json
  181. // @Param autoid query int false "起始自增ID"
  182. // @Param enumdiccode query string false "枚举代码"
  183. // @Success 200 {object} models.Enumdicitem
  184. // @Failure 500 {object} app.Response
  185. // @Router /Common/GetAllEnums [get]
  186. // @Tags 通用服务
  187. func GetAllEnums(c *gin.Context) {
  188. appG := app.Gin{C: c}
  189. // 获取请求参数
  190. var req GetAllEnumsReq
  191. if err := appG.C.ShouldBindQuery(&req); err != nil {
  192. logger.GetLogger().Errorf("GetAllEnums failed: %s", err.Error())
  193. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  194. return
  195. }
  196. enums, err := models.GetEnums(req.Autoid, req.Enumdiccode)
  197. if err != nil {
  198. // 查询失败
  199. logger.GetLogger().Errorf("GetAllEnums failed: %s", err.Error())
  200. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  201. return
  202. }
  203. // 查询成功
  204. // logger.GetLogger().Debugln("GetAllEnums successed: %v", imageConfigs)
  205. appG.Response(http.StatusOK, e.SUCCESS, enums)
  206. }
  207. // GetServerTime 获取服务器时间
  208. // @Summary 获取服务器时间
  209. // @Produce json
  210. // @Success 200 {object} app.Response
  211. // @Failure 500 {object} app.Response
  212. // @Router /Common/GetServerTime [get]
  213. // @Tags 通用服务
  214. func GetServerTime(c *gin.Context) {
  215. appG := app.Gin{C: c}
  216. rst, err := models.GetServerTime()
  217. if err != nil {
  218. // 查询失败
  219. logger.GetLogger().Errorf("GetServerTime failed: %s", err.Error())
  220. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  221. return
  222. }
  223. // 查询成功
  224. logger.GetLogger().Debugln("GetServerTime successed: %v", rst)
  225. appG.Response(http.StatusOK, e.SUCCESS, rst)
  226. }
  227. // QueryMemberGoodsLimitConfig
  228. // @Summary 查询会员商品限制配置表
  229. // @Produce json
  230. // @Param userid query int true "用户ID"
  231. // @Param roletype query int true "会员角色 - 6:自营会员 7:经纪会员"
  232. // @Success 200 {array} models.Membergoodslimitconfig
  233. // @Failure 500 {object} app.Response
  234. // @Router /Common/QueryMemberGoodsLimitConfig [get]
  235. // @Tags 通用服务
  236. func QueryMemberGoodsLimitConfig(c *gin.Context) {
  237. a := app.GinUtils{Gin: app.Gin{C: c}}
  238. m := models.Membergoodslimitconfig{}
  239. a.DoBindReq(&m)
  240. a.DoGetDataEx(&m)
  241. }
  242. type GetWskhOpenAccountConfigsReq struct {
  243. Configs string `form:"configs" binding:"required"` // 配置ID列表,格式:1,2,3
  244. }
  245. // GetWskhOpenAccountConfigs 获取网上开户配置信息
  246. // @Summary 获取网上开户配置信息
  247. // @Produce json
  248. // @Security ApiKeyAuth
  249. // @Param configs query string true "配置ID列表,格式:1,2,3"
  250. // @Success 200 {array} models.Wskhopenaccountconfig
  251. // @Failure 500 {object} app.Response
  252. // @Router /Common/GetWskhOpenAccountConfigs [get]
  253. // @Tags 通用服务
  254. func GetWskhOpenAccountConfigs(c *gin.Context) {
  255. appG := app.Gin{C: c}
  256. // 获取请求参数
  257. var req GetWskhOpenAccountConfigsReq
  258. if err := appG.C.ShouldBindQuery(&req); err != nil {
  259. logger.GetLogger().Errorf("GetWskhOpenAccountConfigs failed: %s", err.Error())
  260. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  261. return
  262. }
  263. datas, err := models.GetWskhOpenAccountConfigs(req.Configs)
  264. if err != nil {
  265. // 查询失败
  266. logger.GetLogger().Errorf("GetWskhOpenAccountConfigs failed: %s", err.Error())
  267. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  268. return
  269. }
  270. // 查询成功
  271. appG.Response(http.StatusOK, e.SUCCESS, datas)
  272. }
  273. // GetI18nConfigs 获取枚举项字典扩展表信息
  274. // @Summary 获取枚举项字典扩展表信息
  275. // @Produce json
  276. // @Success 200 {array} models.I18nConfig
  277. // @Failure 500 {object} app.Response
  278. // @Router /Common/GetI18nConfigs [get]
  279. // @Tags 通用服务
  280. func GetI18nConfigs(c *gin.Context) {
  281. appG := app.Gin{C: c}
  282. datas, err := models.GetI18nConfigs()
  283. if err != nil {
  284. // 查询失败
  285. logger.GetLogger().Errorf("GetI18nConfigs failed: %s", err.Error())
  286. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  287. return
  288. }
  289. // 查询成功
  290. appG.Response(http.StatusOK, e.SUCCESS, datas)
  291. }
  292. type GetGetSystemParamsReq struct {
  293. Codes string `form:"codes"` // 参数代码,格式:1,2,3
  294. }
  295. // GetSystemParams 获取系统参数信息
  296. // @Summary 获取系统参数信息
  297. // @Produce json
  298. // @Param codes query string false "参数代码,格式:1,2,3"
  299. // @Success 200 {array} models.I18nConfig
  300. // @Failure 500 {object} app.Response
  301. // @Router /Common/GetSystemParams [get]
  302. // @Tags 通用服务
  303. func GetSystemParams(c *gin.Context) {
  304. appG := app.Gin{C: c}
  305. // 获取请求参数
  306. var req GetGetSystemParamsReq
  307. if err := appG.C.ShouldBindQuery(&req); err != nil {
  308. logger.GetLogger().Errorf("GetSystemParams failed: %s", err.Error())
  309. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  310. return
  311. }
  312. datas, err := models.GetSystemParamsByCodes(req.Codes)
  313. if err != nil {
  314. // 查询失败
  315. logger.GetLogger().Errorf("GetSystemParams failed: %s", err.Error())
  316. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  317. return
  318. }
  319. // 查询成功
  320. appG.Response(http.StatusOK, e.SUCCESS, datas)
  321. }
  322. // getClientDocumnetConfigs 获取终端文档配置信息
  323. // @Summary 获取终端文档配置信息
  324. // @Produce json
  325. // @Success 200 {array} models.ClientDocumentConfig
  326. // @Failure 500 {object} app.Response
  327. // @Router /Common/GetClientDocumnetConfigs [get]
  328. // @Tags 通用服务
  329. func GetClientDocumnetConfigs(c *gin.Context) {
  330. appG := app.Gin{C: c}
  331. datas, err := models.GetClientDocumnetConfigs()
  332. if err != nil {
  333. // 查询失败
  334. logger.GetLogger().Errorf("GetClientDocumnetConfigs failed: %s", err.Error())
  335. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  336. return
  337. }
  338. // 查询成功
  339. appG.Response(http.StatusOK, e.SUCCESS, datas)
  340. }
  341. // GetHotGoodses 查询热门商品(按上日成交额,持仓额倒序)
  342. // @Summary 查询热门商品(按上日成交额,持仓额倒序)
  343. // @Produce json
  344. // @Success 200 {array} models.ErmcpGoods
  345. // @Failure 500 {object} app.Response
  346. // @Router /Common/GetHotGoodses [get]
  347. // @Tags 通用服务
  348. func GetHotGoodses(c *gin.Context) {
  349. appG := app.Gin{C: c}
  350. datas, err := models.GetHotGoodses()
  351. if err != nil {
  352. // 查询失败
  353. logger.GetLogger().Errorf("GetHotGoodses failed: %s", err.Error())
  354. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  355. return
  356. }
  357. // 查询成功
  358. appG.Response(http.StatusOK, e.SUCCESS, datas)
  359. }