蛋蛋星球 后台端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

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