蛋蛋星球-客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

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