蛋蛋星球 后台端
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.
 
 
 
 

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