蛋蛋星球 后台端
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

744 satır
24 KiB

  1. package public_platoon
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. md "applet/app/md/institutional_management/public_platoon"
  6. svc "applet/app/svc/public_platoon"
  7. "applet/app/utils"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  10. "errors"
  11. "github.com/gin-gonic/gin"
  12. "time"
  13. )
  14. // GetPublicPlatoonBasic
  15. // @Summary 制度中心-公排管理-公排基础设置(获取)
  16. // @Tags 公排管理
  17. // @Description 公排基础设置(获取)
  18. // @Accept json
  19. // @Produce json
  20. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  21. // @Success 200 {object} md.GetPublicPlatoonBasicResp "具体数据"
  22. // @Failure 400 {object} md.Response "具体错误"
  23. // @Router /api/institutionalManagement/publicPlatoon/getBasic [get]
  24. func GetPublicPlatoonBasic(c *gin.Context) {
  25. publicPlatoonBasicDb := implement.NewPublicPlatoonBasicSettingDb(db.Db)
  26. publicPlatoonBasic, err := publicPlatoonBasicDb.PublicPlatoonBasicSettingGetOne()
  27. if err != nil {
  28. e.OutErr(c, e.ERR_DB_ORM, err)
  29. return
  30. }
  31. now := time.Now()
  32. if publicPlatoonBasic == nil {
  33. publicPlatoonBasic = &model.PublicPlatoonBasicSetting{
  34. IsOpen: 1,
  35. OriginatorUid: 0,
  36. SeveralTimes: 0,
  37. SeveralRows: 0,
  38. SystemPunishReplace: 0,
  39. SystemPunishReplaceValue: 0,
  40. IsSelfActiveGetTeamRevenue: 0,
  41. CreateAt: now.Format("2006-01-02 15:04:05"),
  42. UpdateAt: now.Format("2006-01-02 15:04:05"),
  43. }
  44. _, err1 := publicPlatoonBasicDb.PublicPlatoonBasicSettingInsert(publicPlatoonBasic)
  45. if err1 != nil {
  46. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  47. return
  48. }
  49. }
  50. var resp md.GetPublicPlatoonBasicResp
  51. resp = md.GetPublicPlatoonBasicResp{
  52. IsOpen: publicPlatoonBasic.IsOpen,
  53. OriginatorUid: publicPlatoonBasic.OriginatorUid,
  54. SeveralTimes: publicPlatoonBasic.SeveralTimes,
  55. SeveralRows: publicPlatoonBasic.SeveralRows,
  56. SystemPunishReplace: publicPlatoonBasic.SystemPunishReplace,
  57. SystemPunishReplaceValue: publicPlatoonBasic.SystemPunishReplaceValue,
  58. IsSelfActiveGetTeamRevenue: publicPlatoonBasic.IsSelfActiveGetTeamRevenue,
  59. }
  60. e.OutSuc(c, resp, nil)
  61. }
  62. // UpdatePublicPlatoonBasic
  63. // @Summary 制度中心-公排管理-公排基础设置(修改)
  64. // @Tags 公排管理
  65. // @Description 公排基础设置(修改)
  66. // @Accept json
  67. // @Produce json
  68. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  69. // @Param req body md.UpdatePublicPlatoonBasicReq true "公排设置表单内容"
  70. // @Success 200 {string} "success"
  71. // @Failure 400 {object} md.Response "具体错误"
  72. // @Router /api/institutionalManagement/publicPlatoon/updateBasic [put]
  73. func UpdatePublicPlatoonBasic(c *gin.Context) {
  74. var req *md.UpdatePublicPlatoonBasicReq
  75. if err := c.ShouldBindJSON(&req); err != nil {
  76. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  77. return
  78. }
  79. publicPlatoonBasicDb := implement.NewPublicPlatoonBasicSettingDb(db.Db)
  80. publicPlatoonBasic, err := publicPlatoonBasicDb.PublicPlatoonBasicSettingGetOne()
  81. if err != nil {
  82. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  83. return
  84. }
  85. setting := &model.PublicPlatoonBasicSetting{
  86. Id: publicPlatoonBasic.Id,
  87. IsOpen: req.IsOpen,
  88. OriginatorUid: req.OriginatorUid,
  89. SeveralTimes: req.SeveralTimes,
  90. SeveralRows: req.SeveralRows,
  91. SystemPunishReplace: req.SystemPunishReplace,
  92. SystemPunishReplaceValue: req.SystemPunishReplaceValue,
  93. IsSelfActiveGetTeamRevenue: req.IsSelfActiveGetTeamRevenue,
  94. CreateAt: "",
  95. UpdateAt: "",
  96. }
  97. forceColumns := []string{"is_open", "system_punish_replace", "is_self_active_get_team_revenue"}
  98. updateAffected, err := publicPlatoonBasicDb.PublicPlatoonBasicSettingUpdate(publicPlatoonBasic.Id, setting, forceColumns...)
  99. if err != nil {
  100. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  101. return
  102. }
  103. if updateAffected <= 0 {
  104. e.OutErr(c, e.ERR_DB_ORM, "更新数据表失败")
  105. return
  106. }
  107. e.OutSuc(c, "success", nil)
  108. }
  109. // GetRelationshipMap
  110. // @Summary 制度中心-公排管理-关系分布图(获取)
  111. // @Tags 公排管理
  112. // @Description 关系分布图(获取)
  113. // @Accept json
  114. // @Produce json
  115. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  116. // @param phone query string true "phone"
  117. // @param uid query string true "uid"
  118. // @Success 200 {object} md.TreeNode "具体数据"
  119. // @Failure 400 {object} md.Response "具体错误"
  120. // @Router /api/institutionalManagement/publicPlatoon/relationshipMap [get]
  121. func GetRelationshipMap(c *gin.Context) {
  122. phone := c.Query("phone")
  123. uid := c.Query("uid")
  124. userDb := implement.NewUserDb(db.Db)
  125. userRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  126. var relation *model.PublicPlatoonUserRelation
  127. var err error
  128. if phone != "" {
  129. user, err1 := userDb.UserGetOneByParams(map[string]interface{}{
  130. "key": "phone",
  131. "value": phone,
  132. })
  133. if err1 != nil {
  134. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  135. return
  136. }
  137. if user == nil {
  138. e.OutErr(c, e.ERR_NO_DATA, errors.New("手机号不存在"))
  139. return
  140. }
  141. relation, err = userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  142. "key": "uid",
  143. "value": user.Id,
  144. })
  145. } else if uid != "" {
  146. relation, err = userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  147. "key": "uid",
  148. "value": uid,
  149. })
  150. } else {
  151. relation, err = userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  152. "key": "level_total",
  153. "value": 1,
  154. })
  155. if err != nil {
  156. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  157. return
  158. }
  159. }
  160. var list *md.TreeNode
  161. list, err = svc.GetTrees(db.Db, relation, 3)
  162. if err != nil {
  163. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  164. return
  165. }
  166. e.OutSuc(c, list, nil)
  167. }
  168. // FindUserRelationshipMap
  169. // @Summary 制度中心-公排管理-关系分布图(获取指定用户下级)
  170. // @Tags 公排管理
  171. // @Description 关系分布图(获取指定用户下级)
  172. // @Accept json
  173. // @Produce json
  174. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  175. // @Param uid query string true "用户ID"
  176. // @Success 200 {object} md.TreeNode "具体数据"
  177. // @Failure 400 {object} md.Response "具体错误"
  178. // @Router /api/institutionalManagement/publicPlatoon/findUserRelationshipMap [get]
  179. func FindUserRelationshipMap(c *gin.Context) {
  180. uid := c.Query("uid")
  181. userRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  182. var err error
  183. var relation *model.PublicPlatoonUserRelation
  184. relation, err = userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  185. "key": "uid",
  186. "value": uid,
  187. })
  188. if err != nil {
  189. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  190. return
  191. }
  192. var list *md.TreeNode
  193. list, err = svc.GetTrees(db.Db, relation, 1)
  194. if err != nil {
  195. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  196. return
  197. }
  198. e.OutSuc(c, list, nil)
  199. }
  200. // FindSubUserRelationshipMap
  201. // @Summary 制度中心-公排管理-关系分布图(获取指定用户上级)
  202. // @Tags 公排管理
  203. // @Description 关系分布图(获取指定用户上级)
  204. // @Accept json
  205. // @Produce json
  206. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  207. // @Param uid query string true "用户ID"
  208. // @Success 200 {object} md.FindSubUserRelationshipMapResp "具体数据"
  209. // @Failure 400 {object} md.Response "具体错误"
  210. // @Router /api/institutionalManagement/publicPlatoon/findSubUserRelationshipMap [get]
  211. func FindSubUserRelationshipMap(c *gin.Context) {
  212. uid := c.Query("uid")
  213. relateDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  214. userRelate, err := relateDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  215. "key": "uid",
  216. "value": uid,
  217. })
  218. if err != nil {
  219. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  220. return
  221. }
  222. if userRelate == nil {
  223. e.OutErr(c, e.ERR_NO_DATA, errors.New("用户不存在"))
  224. return
  225. }
  226. userDb := implement.NewUserDb(db.Db)
  227. parentUser, err4 := userDb.UserGetOneByParams(map[string]interface{}{
  228. "key": "id",
  229. "value": userRelate.FatherUid1,
  230. })
  231. if err4 != nil {
  232. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  233. return
  234. }
  235. platoonUserRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  236. parentRelation, err := platoonUserRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  237. "key": "uid",
  238. "value": parentUser.Id,
  239. })
  240. if err != nil {
  241. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  242. return
  243. }
  244. subUser := md.SubUser{
  245. AvatarURL: parentUser.Avatar,
  246. Phone: parentUser.Phone,
  247. Nickname: parentUser.Nickname,
  248. Uid: parentUser.Id,
  249. PID: parentRelation.RecommendUid,
  250. Level: parentRelation.LevelTotal,
  251. Position: parentRelation.Position1,
  252. }
  253. basicSettingDb := implement.NewPublicPlatoonBasicSettingDb(db.Db)
  254. basicSetting, err := basicSettingDb.PublicPlatoonBasicSettingGetOne()
  255. if err != nil {
  256. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  257. return
  258. }
  259. basicSettingResp := md.BasicSetting{
  260. Id: basicSetting.Id,
  261. IsOpen: basicSetting.IsOpen,
  262. SeveralTimes: basicSetting.SeveralTimes,
  263. SeveralRows: basicSetting.SeveralRows,
  264. OriginatorUid: basicSetting.OriginatorUid,
  265. SystemPunishReplace: basicSetting.SystemPunishReplace,
  266. SystemPunishReplaceValue: basicSetting.SystemPunishReplaceValue,
  267. IsSelfActiveGetTeamRevenue: basicSetting.IsSelfActiveGetTeamRevenue,
  268. }
  269. resp := md.FindSubUserRelationshipMapResp{
  270. SubUser: subUser,
  271. BasicSetting: basicSettingResp,
  272. SearchUid: uid,
  273. }
  274. e.OutSuc(c, resp, nil)
  275. }
  276. // ExchangeUserPosition
  277. // @Summary 制度中心-公排管理-关系分布图(位置转换)
  278. // @Tags 公排管理
  279. // @Description 关系分布图(位置转换)
  280. // @Accept json
  281. // @Produce json
  282. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  283. // @Param req body md.ExchangeUserPositionReq true "需要交换的两个位置"
  284. // @Success 200 {} "成功返回"
  285. // @Failure 400 {object} md.Response "具体错误"
  286. // @Router /api/institutionalManagement/publicPlatoon/exchangeUserPosition [post]
  287. func ExchangeUserPosition(c *gin.Context) {
  288. var req *md.ExchangeUserPositionReq
  289. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  290. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  291. return
  292. }
  293. userRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  294. relation1, err2 := userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  295. "key": "id",
  296. "value": req.Position1,
  297. })
  298. if err2 != nil {
  299. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  300. return
  301. }
  302. if relation1 == nil {
  303. e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("position_1 位置有误"))
  304. return
  305. }
  306. relation2, err3 := userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  307. "key": "id",
  308. "value": req.Position2,
  309. })
  310. if err3 != nil {
  311. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  312. return
  313. }
  314. if relation2 == nil {
  315. e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("position_2 位置有误"))
  316. return
  317. }
  318. if relation1.LevelTotal == 1 || relation2.LevelTotal == 1 {
  319. e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("创始人位置不能被修改"))
  320. }
  321. err4 := svc.ExchangeUserPosition(db.Db, relation1, relation2)
  322. if err4 != nil {
  323. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  324. return
  325. }
  326. e.OutSuc(c, nil, nil)
  327. }
  328. // GetFreePublishUser
  329. // @Summary 制度中心-公排管理-免罚用户(查询)
  330. // @Tags 公排管理
  331. // @Description 免罚用户(查询)
  332. // @Accept json
  333. // @Produce json
  334. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  335. // @Param req body md.GetFreePublishUserReq true "页数和行数必填,uid选填"
  336. // @Success 200 {object} md.GetFreePublishUserResp "成功返回"
  337. // @Failure 400 {object} md.Response "具体错误"
  338. // @Router /api/institutionalManagement/publicPlatoon/publicPlatoonUserFreePunish/index [post]
  339. func GetFreePublishUser(c *gin.Context) {
  340. var req *md.GetFreePublishUserReq
  341. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  342. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  343. return
  344. }
  345. freePunishWithUserDb := implement.NewPublicPlatoonFreePunishWithUserDb(db.Db)
  346. var m []model.PublicPlatoonFreePunishWithUser
  347. var err error
  348. var total int64
  349. if req.Uid != 0 {
  350. m, total, err = freePunishWithUserDb.PublicPlatoonFreePunishWithUserCountAndGetPageByParams(req.Page, req.Limit, map[string]interface{}{
  351. "key": "uid",
  352. "value": req.Uid,
  353. })
  354. } else {
  355. m, total, err = freePunishWithUserDb.PublicPlatoonFreePunishWithUserCountAndGetPageByParams(req.Page, req.Limit, nil)
  356. }
  357. if err != nil {
  358. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  359. return
  360. }
  361. userDb := implement.NewUserDb(db.Db)
  362. var ids []int64
  363. for _, item := range m {
  364. ids = append(ids, item.Uid)
  365. }
  366. users, err2 := userDb.UserFindByParams(map[string]interface{}{
  367. "key": "id",
  368. "value": ids,
  369. })
  370. if err2 != nil {
  371. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  372. }
  373. var nodes []md.FreePublishUserNode
  374. for _, user := range users {
  375. nodes = append(nodes, md.FreePublishUserNode{
  376. UID: user.Id,
  377. Phone: user.Phone,
  378. Nickname: user.Nickname,
  379. })
  380. }
  381. var paginate md.Paginate
  382. paginate = md.Paginate{
  383. Limit: req.Limit,
  384. Page: req.Page,
  385. Total: total,
  386. }
  387. var resp md.GetFreePublishUserResp
  388. resp = md.GetFreePublishUserResp{
  389. Paginate: paginate,
  390. List: nodes,
  391. }
  392. e.OutSuc(c, resp, nil)
  393. }
  394. // AddFreePublishUser
  395. // @Summary 制度中心-公排管理-免罚用户(新增)
  396. // @Tags 公排管理
  397. // @Description 免罚用户(新增)
  398. // @Accept json
  399. // @Produce json
  400. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  401. // @Param req body md.AddFreePublishUserReq true "页数和行数必填,uid选填"
  402. // @Success 200 {int} "插入数据 ID"
  403. // @Failure 400 {object} md.Response "具体错误"
  404. // @Router /api/institutionalManagement/publicPlatoon/publicPlatoonUserFreePunish/save [post]
  405. func AddFreePublishUser(c *gin.Context) {
  406. var req *md.AddFreePublishUserReq
  407. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  408. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  409. return
  410. }
  411. userDb := implement.NewUserDb(db.Db)
  412. user, err2 := userDb.UserGetOneByParams(map[string]interface{}{
  413. "key": "id",
  414. "value": req.Uid,
  415. })
  416. if err2 != nil {
  417. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  418. return
  419. }
  420. if user == nil {
  421. e.OutErr(c, e.ERR_DB_ORM, errors.New("该用户不存在"))
  422. }
  423. freePunishWithUserDb := implement.NewPublicPlatoonFreePunishWithUserDb(db.Db)
  424. var m model.PublicPlatoonFreePunishWithUser
  425. m = model.PublicPlatoonFreePunishWithUser{
  426. Uid: req.Uid,
  427. }
  428. id, err3 := freePunishWithUserDb.PublicPlatoonFreePunishWithUserInsert(&m)
  429. if err3 != nil {
  430. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  431. return
  432. }
  433. e.OutSuc(c, id, nil)
  434. }
  435. // ListCommunityDividends
  436. // @Summary 制度中心-公排管理-社区分红(查询)
  437. // @Tags 公排管理
  438. // @Description 社区分红(查询)
  439. // @Accept json
  440. // @Produce json
  441. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  442. // @Param req body md.ListCommunityDividendsReq true "页数、每页大小必填 起止时间、起止数量选填"
  443. // @Success 200 {object} md.ListCommunityDividendsResp "具体数据"
  444. // @Failure 400 {object} md.Response "具体错误"
  445. // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsList [post]
  446. func ListCommunityDividends(c *gin.Context) {
  447. var req *md.ListCommunityDividendsReq
  448. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  449. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  450. return
  451. }
  452. dividendsDb := implement.NewEggEnergyCommunityDividendsDb(db.Db)
  453. dividends, total, err2 := dividendsDb.EggEnergyCommunityDividendsFindAndCount(req.Page, req.Limit, req.StartAt, req.EndAt, req.StartNums, req.EndNums)
  454. if err2 != nil {
  455. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  456. return
  457. }
  458. list := make([]md.EggEnergyCommunityDividends, len(dividends))
  459. for i, dividend := range dividends {
  460. list[i] = md.EggEnergyCommunityDividends{
  461. Id: dividend.Id,
  462. Nums: dividend.Nums,
  463. Name: dividend.Name,
  464. CoinId: dividend.CoinId,
  465. PersonsNum: dividend.PersonsNum,
  466. IsOver: dividend.IsOver,
  467. CreateAt: dividend.CreateAt,
  468. UpdateAt: dividend.UpdateAt,
  469. }
  470. }
  471. resp := md.ListCommunityDividendsResp{
  472. List: list,
  473. Paginate: md.Paginate{
  474. Limit: req.Limit,
  475. Page: req.Page,
  476. Total: total,
  477. },
  478. }
  479. e.OutSuc(c, resp, nil)
  480. }
  481. // AddCommunityDividends
  482. // @Summary 制度中心-公排管理-社区分红(新增)
  483. // @Tags 公排管理
  484. // @Description 社区分红(新增)
  485. // @Accept json
  486. // @Produce json
  487. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  488. // @Param req body md.AddCommunityDividendsReq true "分红名称、分红总量"
  489. // @Success 200 {int} "插入数据 ID"
  490. // @Failure 400 {object} md.Response "具体错误"
  491. // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsAdd [post]
  492. func AddCommunityDividends(c *gin.Context) {
  493. var req *md.AddCommunityDividendsReq
  494. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  495. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  496. return
  497. }
  498. now := time.Now()
  499. var m model.EggEnergyCommunityDividends
  500. m = model.EggEnergyCommunityDividends{
  501. Nums: req.Nums,
  502. Name: req.Name,
  503. CoinId: 0,
  504. PersonsNum: 0,
  505. IsOver: 0,
  506. CreateAt: now.Format("2006-01-02 15:04:05"),
  507. UpdateAt: now.Format("2006-01-02 15:04:05"),
  508. }
  509. dividendsDb := implement.NewEggEnergyCommunityDividendsDb(db.Db)
  510. id, err := dividendsDb.EggEnergyCommunityDividendsInsert(&m)
  511. if err != nil {
  512. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  513. return
  514. }
  515. e.OutSuc(c, id, nil)
  516. }
  517. // ListCommunityDividendsWithUser
  518. // @Summary 制度中心-公排管理-社区长列表(查询)
  519. // @Tags 公排管理
  520. // @Description 社区长列表(查询)
  521. // @Accept json
  522. // @Produce json
  523. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  524. // @Param req body md.ListCommunityDividendsWithUserReq true "页数、每页大小必填 手机号、用户ID选填"
  525. // @Success 200 {object} md.ListCommunityDividendsWithUserResp "社区长列表"
  526. // @Failure 400 {object} md.Response "具体错误"
  527. // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsWithUserList [post]
  528. func ListCommunityDividendsWithUser(c *gin.Context) {
  529. var req *md.ListCommunityDividendsWithUserReq
  530. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  531. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  532. return
  533. }
  534. var uid int64
  535. if req.Phone != "" {
  536. userDb := implement.NewUserDb(db.Db)
  537. user, err := userDb.UserGetOneByParams(map[string]interface{}{
  538. "key": "phone",
  539. "value": req.Phone,
  540. })
  541. if err != nil {
  542. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  543. return
  544. }
  545. uid = user.Id
  546. }
  547. if req.Uid != 0 {
  548. uid = req.Uid
  549. }
  550. dividendsWithUserDb := implement.NewEggEnergyCommunityDividendsWithUserDb(db.Db)
  551. dividendsWithUserList, total, err := dividendsWithUserDb.EggEnergyCommunityDividendsWithUserFindAndCount(req.Page, req.Limit, uid)
  552. if err != nil {
  553. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  554. return
  555. }
  556. list := make([]md.EggEnergyCommunityDividendsWithUser, len(dividendsWithUserList))
  557. if len(dividendsWithUserList) > 0 {
  558. uids := make([]int64, len(dividendsWithUserList))
  559. for i, user := range dividendsWithUserList {
  560. uids[i] = user.Uid
  561. }
  562. userDb := implement.NewUserDb(db.Db)
  563. users, err := userDb.UserFindByParams(map[string]interface{}{
  564. "key": "id",
  565. "value": uids,
  566. })
  567. if err != nil {
  568. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  569. return
  570. }
  571. userMap := make(map[int64]model.User)
  572. for _, user := range users {
  573. userMap[user.Id] = user
  574. }
  575. for i, user := range dividendsWithUserList {
  576. list[i] = md.EggEnergyCommunityDividendsWithUser{
  577. Id: user.Id,
  578. Uid: user.Uid,
  579. Memo: user.Memo,
  580. Phone: userMap[user.Uid].Phone,
  581. Nickname: userMap[user.Uid].Nickname,
  582. }
  583. }
  584. }
  585. resp := md.ListCommunityDividendsWithUserResp{
  586. List: list,
  587. Paginate: md.Paginate{
  588. Limit: req.Limit,
  589. Page: req.Page,
  590. Total: total,
  591. },
  592. }
  593. e.OutSuc(c, resp, nil)
  594. }
  595. // AddCommunityDividendsWithUser
  596. // @Summary 制度中心-公排管理-社区长列表(新增)
  597. // @Tags 公排管理
  598. // @Description 社区长列表(新增)
  599. // @Accept json
  600. // @Produce json
  601. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  602. // @Param req body md.AddCommunityDividendsWithUserReq true "新增社区长 ID、备注"
  603. // @Success 200 {int} "插入数据 ID"
  604. // @Failure 400 {object} md.Response "具体错误"
  605. // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsWithUserAdd [post]
  606. func AddCommunityDividendsWithUser(c *gin.Context) {
  607. var req *md.AddCommunityDividendsWithUserReq
  608. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  609. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  610. return
  611. }
  612. communityDividendsWithUserDb := implement.NewEggEnergyCommunityDividendsWithUserDb(db.Db)
  613. exist, err := communityDividendsWithUserDb.EggEnergyCommunityDividendsWithUserExist(req.Uid)
  614. if err != nil {
  615. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  616. return
  617. }
  618. if exist {
  619. e.OutErr(c, e.ERR_BAD_REQUEST, "请勿重复添加")
  620. return
  621. }
  622. now := time.Now()
  623. var m model.EggEnergyCommunityDividendsWithUser
  624. m = model.EggEnergyCommunityDividendsWithUser{
  625. Uid: req.Uid,
  626. Memo: req.Memo,
  627. CreateAt: now.Format("2006-01-02 15:04:05"),
  628. UpdateAt: now.Format("2006-01-02 15:04:05"),
  629. }
  630. id, err := communityDividendsWithUserDb.EggEnergyCommunityDividendsWithUserInsert(&m)
  631. if err != nil {
  632. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  633. return
  634. }
  635. e.OutSuc(c, id, nil)
  636. }
  637. // UserDailyActivityAnalysis
  638. // @Summary 制度中心-公排管理-日活分析
  639. // @Tags 公排管理
  640. // @Description 日活分析
  641. // @Accept json
  642. // @Produce json
  643. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  644. // @Param req body md.UserDailyActivityAnalysisReq true "用户 ID、查询开始时间、结束时间(查询时间不超过30天)、页数、每页大小"
  645. // @Success 200 {object} md.UserDailyActivityAnalysisResp "具体数据"
  646. // @Failure 400 {object} md.Response "具体错误"
  647. // @Router /api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis/index [post]
  648. func UserDailyActivityAnalysis(c *gin.Context) {
  649. var req *md.UserDailyActivityAnalysisReq
  650. if err := c.ShouldBindJSON(&req); err != nil {
  651. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  652. return
  653. }
  654. total, sons, err := svc.GetSonUserDailyActivity(db.Db, req.Uid, req.StartDate, req.EndDate, req.Page, req.PageSize)
  655. if err != nil {
  656. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  657. return
  658. }
  659. sql1 := "SELECT COUNT(*) AS total, uid FROM `egg_energy_user_activity` WHERE uid IN (SELECT uid FROM `user_relate` WHERE parent_uid = ?) AND date > ? AND date < ? GROUP BY uid"
  660. results, err := db.Db.QueryString(sql1, req.Uid, req.StartDate, req.EndDate)
  661. if err != nil {
  662. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  663. return
  664. }
  665. var activityCount, activityUserCount int64
  666. for _, result := range results {
  667. tempCount := utils.StrToInt64(result["total"])
  668. activityCount += tempCount
  669. activityUserCount++
  670. }
  671. topData := md.DailyActivityAnalysisTopData{
  672. TeamUserCount: total,
  673. ActivityCount: activityCount,
  674. TeamActivityUserCount: activityUserCount,
  675. }
  676. if sons == nil {
  677. sons = make([]md.SonUserDailyActivityAnalysisNode, 0)
  678. }
  679. resp := md.UserDailyActivityAnalysisResp{
  680. TopData: topData,
  681. SonUserData: sons,
  682. }
  683. e.OutSuc(c, resp, nil)
  684. }