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

858 lines
28 KiB

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