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

880 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. var list *md.TreeNode
  209. e.OutSuc(c, list, nil)
  210. return
  211. }
  212. relation, err = userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  213. "key": "uid",
  214. "value": user.Id,
  215. })
  216. } else if uid != "" {
  217. relation, err = userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  218. "key": "uid",
  219. "value": uid,
  220. })
  221. } else {
  222. relation, err = userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  223. "key": "level_total",
  224. "value": 1,
  225. })
  226. if err != nil {
  227. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  228. return
  229. }
  230. }
  231. var list *md.TreeNode
  232. list, err = svc.GetTrees(db.Db, relation, 3)
  233. if err != nil {
  234. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  235. return
  236. }
  237. e.OutSuc(c, list, nil)
  238. }
  239. // FindUserRelationshipMap
  240. // @Summary 制度中心-公排管理-关系分布图(获取指定用户下级)
  241. // @Tags 公排管理
  242. // @Description 关系分布图(获取指定用户下级)
  243. // @Accept json
  244. // @Produce json
  245. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  246. // @Param uid query string true "用户ID"
  247. // @Success 200 {object} md.TreeNode "具体数据"
  248. // @Failure 400 {object} md.Response "具体错误"
  249. // @Router /api/institutionalManagement/publicPlatoon/findUserRelationshipMap [get]
  250. func FindUserRelationshipMap(c *gin.Context) {
  251. uid := c.Query("uid")
  252. userRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  253. var err error
  254. var relation *model.PublicPlatoonUserRelation
  255. relation, err = userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  256. "key": "uid",
  257. "value": uid,
  258. })
  259. if err != nil {
  260. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  261. return
  262. }
  263. var list *md.TreeNode
  264. list, err = svc.GetTrees(db.Db, relation, 1)
  265. if err != nil {
  266. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  267. return
  268. }
  269. e.OutSuc(c, list, nil)
  270. }
  271. // FindSubUserRelationshipMap
  272. // @Summary 制度中心-公排管理-关系分布图(获取指定用户上级)
  273. // @Tags 公排管理
  274. // @Description 关系分布图(获取指定用户上级)
  275. // @Accept json
  276. // @Produce json
  277. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  278. // @Param uid query string true "用户ID"
  279. // @Success 200 {object} md.FindSubUserRelationshipMapResp "具体数据"
  280. // @Failure 400 {object} md.Response "具体错误"
  281. // @Router /api/institutionalManagement/publicPlatoon/findSubUserRelationshipMap [get]
  282. func FindSubUserRelationshipMap(c *gin.Context) {
  283. uid := c.Query("uid")
  284. relateDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  285. userRelate, err := relateDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  286. "key": "uid",
  287. "value": uid,
  288. })
  289. if err != nil {
  290. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  291. return
  292. }
  293. if userRelate == nil {
  294. e.OutErr(c, e.ERR_NO_DATA, errors.New("用户不存在"))
  295. return
  296. }
  297. userDb := implement.NewUserDb(db.Db)
  298. parentUser, err4 := userDb.UserGetOneByParams(map[string]interface{}{
  299. "key": "id",
  300. "value": userRelate.FatherUid1,
  301. })
  302. if err4 != nil {
  303. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  304. return
  305. }
  306. platoonUserRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  307. parentRelation, err := platoonUserRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  308. "key": "uid",
  309. "value": parentUser.Id,
  310. })
  311. if err != nil {
  312. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  313. return
  314. }
  315. subUser := md.SubUser{
  316. AvatarURL: parentUser.Avatar,
  317. Phone: parentUser.Phone,
  318. Nickname: parentUser.Nickname,
  319. Uid: parentUser.Id,
  320. PID: parentRelation.RecommendUid,
  321. Level: parentRelation.LevelTotal,
  322. Position: parentRelation.Position1,
  323. }
  324. basicSettingDb := implement.NewPublicPlatoonBasicSettingDb(db.Db)
  325. basicSetting, err := basicSettingDb.PublicPlatoonBasicSettingGetOne()
  326. if err != nil {
  327. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  328. return
  329. }
  330. basicSettingResp := md.BasicSetting{
  331. Id: basicSetting.Id,
  332. IsOpen: basicSetting.IsOpen,
  333. SeveralTimes: basicSetting.SeveralTimes,
  334. SeveralRows: basicSetting.SeveralRows,
  335. OriginatorUid: basicSetting.OriginatorUid,
  336. SystemPunishReplace: basicSetting.SystemPunishReplace,
  337. SystemPunishReplaceValue: basicSetting.SystemPunishReplaceValue,
  338. IsSelfActiveGetTeamRevenue: basicSetting.IsSelfActiveGetTeamRevenue,
  339. }
  340. resp := md.FindSubUserRelationshipMapResp{
  341. SubUser: subUser,
  342. BasicSetting: basicSettingResp,
  343. SearchUid: uid,
  344. }
  345. e.OutSuc(c, resp, nil)
  346. }
  347. // ExchangeUserPosition
  348. // @Summary 制度中心-公排管理-关系分布图(位置转换)
  349. // @Tags 公排管理
  350. // @Description 关系分布图(位置转换)
  351. // @Accept json
  352. // @Produce json
  353. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  354. // @Param req body md.ExchangeUserPositionReq true "需要交换的两个位置"
  355. // @Success 200 {} "成功返回"
  356. // @Failure 400 {object} md.Response "具体错误"
  357. // @Router /api/institutionalManagement/publicPlatoon/exchangeUserPosition [post]
  358. func ExchangeUserPosition(c *gin.Context) {
  359. var req *md.ExchangeUserPositionReq
  360. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  361. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  362. return
  363. }
  364. userRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  365. relation1, err2 := userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  366. "key": "id",
  367. "value": req.Position1,
  368. })
  369. if err2 != nil {
  370. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  371. return
  372. }
  373. if relation1 == nil {
  374. e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("position_1 位置有误"))
  375. return
  376. }
  377. relation2, err3 := userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  378. "key": "id",
  379. "value": req.Position2,
  380. })
  381. if err3 != nil {
  382. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  383. return
  384. }
  385. if relation2 == nil {
  386. e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("position_2 位置有误"))
  387. return
  388. }
  389. if relation1.LevelTotal == 1 || relation2.LevelTotal == 1 {
  390. e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("创始人位置不能被修改"))
  391. }
  392. err4 := svc.ExchangeUserPosition(db.Db, relation1, relation2)
  393. if err4 != nil {
  394. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  395. return
  396. }
  397. e.OutSuc(c, nil, nil)
  398. }
  399. // GetFreePublishUser
  400. // @Summary 制度中心-公排管理-免罚用户(查询)
  401. // @Tags 公排管理
  402. // @Description 免罚用户(查询)
  403. // @Accept json
  404. // @Produce json
  405. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  406. // @Param req body md.GetFreePublishUserReq true "页数和行数必填,uid选填"
  407. // @Success 200 {object} md.GetFreePublishUserResp "成功返回"
  408. // @Failure 400 {object} md.Response "具体错误"
  409. // @Router /api/institutionalManagement/publicPlatoon/publicPlatoonUserFreePunish/index [post]
  410. func GetFreePublishUser(c *gin.Context) {
  411. var req *md.GetFreePublishUserReq
  412. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  413. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  414. return
  415. }
  416. freePunishWithUserDb := implement.NewPublicPlatoonFreePunishWithUserDb(db.Db)
  417. var m []model.PublicPlatoonFreePunishWithUser
  418. var err error
  419. var total int64
  420. if req.Uid != 0 {
  421. m, total, err = freePunishWithUserDb.PublicPlatoonFreePunishWithUserCountAndGetPageByParams(req.Page, req.Limit, map[string]interface{}{
  422. "key": "uid",
  423. "value": req.Uid,
  424. })
  425. } else {
  426. m, total, err = freePunishWithUserDb.PublicPlatoonFreePunishWithUserCountAndGetPageByParams(req.Page, req.Limit, nil)
  427. }
  428. if err != nil {
  429. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  430. return
  431. }
  432. userDb := implement.NewUserDb(db.Db)
  433. var ids []int64
  434. for _, item := range m {
  435. ids = append(ids, item.Uid)
  436. }
  437. users, err2 := userDb.UserFindByParams(map[string]interface{}{
  438. "key": "id",
  439. "value": ids,
  440. })
  441. if err2 != nil {
  442. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  443. }
  444. var nodes []md.FreePublishUserNode
  445. for _, user := range users {
  446. nodes = append(nodes, md.FreePublishUserNode{
  447. UID: user.Id,
  448. Phone: user.Phone,
  449. Nickname: user.Nickname,
  450. })
  451. }
  452. var paginate md.Paginate
  453. paginate = md.Paginate{
  454. Limit: req.Limit,
  455. Page: req.Page,
  456. Total: total,
  457. }
  458. var resp md.GetFreePublishUserResp
  459. resp = md.GetFreePublishUserResp{
  460. Paginate: paginate,
  461. List: nodes,
  462. }
  463. e.OutSuc(c, resp, nil)
  464. }
  465. // AddFreePublishUser
  466. // @Summary 制度中心-公排管理-免罚用户(新增)
  467. // @Tags 公排管理
  468. // @Description 免罚用户(新增)
  469. // @Accept json
  470. // @Produce json
  471. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  472. // @Param req body md.AddFreePublishUserReq true "免罚用户ID"
  473. // @Success 200 {int} "插入数据 ID"
  474. // @Failure 400 {object} md.Response "具体错误"
  475. // @Router /api/institutionalManagement/publicPlatoon/publicPlatoonUserFreePunish/save [post]
  476. func AddFreePublishUser(c *gin.Context) {
  477. var req *md.AddFreePublishUserReq
  478. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  479. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  480. return
  481. }
  482. freePunishWithUserDb := implement.NewPublicPlatoonFreePunishWithUserDb(db.Db)
  483. userExist, err := freePunishWithUserDb.PublicPlatoonFreePunishWithUserGetOneByParams(map[string]interface{}{
  484. "key": "uid",
  485. "value": req.Uid,
  486. })
  487. if err != nil {
  488. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  489. return
  490. }
  491. if userExist != nil {
  492. e.OutErr(c, e.ERR_DB_ORM, "用户已在名单,无需重复添加")
  493. return
  494. }
  495. userDb := implement.NewUserDb(db.Db)
  496. user, err2 := userDb.UserGetOneByParams(map[string]interface{}{
  497. "key": "id",
  498. "value": req.Uid,
  499. })
  500. if err2 != nil {
  501. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  502. return
  503. }
  504. if user == nil {
  505. e.OutErr(c, e.ERR_DB_ORM, errors.New("该用户不存在"))
  506. }
  507. var m model.PublicPlatoonFreePunishWithUser
  508. m = model.PublicPlatoonFreePunishWithUser{
  509. Uid: req.Uid,
  510. }
  511. id, err3 := freePunishWithUserDb.PublicPlatoonFreePunishWithUserInsert(&m)
  512. if err3 != nil {
  513. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  514. return
  515. }
  516. e.OutSuc(c, id, nil)
  517. }
  518. // DeleteFreePublishUser
  519. // @Summary 制度中心-公排管理-免罚用户(删除)
  520. // @Tags 公排管理
  521. // @Description 免罚用户(删除)
  522. // @Accept json
  523. // @Produce json
  524. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  525. // @Param req body md.DeleteFreePublishUserReq true "免罚用户ID"
  526. // @Success 200 {int} "删除数据数量"
  527. // @Failure 400 {object} md.Response "具体错误"
  528. // @Router /api/institutionalManagement/publicPlatoon/publicPlatoonUserFreePunish/delete [delete]
  529. func DeleteFreePublishUser(c *gin.Context) {
  530. var req *md.DeleteFreePublishUserReq
  531. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  532. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  533. return
  534. }
  535. freePunishWithUserDb := implement.NewPublicPlatoonFreePunishWithUserDb(db.Db)
  536. affected, err := freePunishWithUserDb.PublicPlatoonFreePunishWithUserDeleteOneByUID(utils.StrToInt64(req.Uid))
  537. if err != nil {
  538. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  539. return
  540. }
  541. e.OutSuc(c, affected, nil)
  542. }
  543. // ListCommunityDividends
  544. // @Summary 制度中心-公排管理-社区分红(查询)
  545. // @Tags 公排管理
  546. // @Description 社区分红(查询)
  547. // @Accept json
  548. // @Produce json
  549. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  550. // @Param req body md.ListCommunityDividendsReq true "页数、每页大小必填 起止时间、起止数量选填"
  551. // @Success 200 {object} md.ListCommunityDividendsResp "具体数据"
  552. // @Failure 400 {object} md.Response "具体错误"
  553. // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsList [post]
  554. func ListCommunityDividends(c *gin.Context) {
  555. var req *md.ListCommunityDividendsReq
  556. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  557. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  558. return
  559. }
  560. dividendsDb := implement.NewEggEnergyCommunityDividendsDb(db.Db)
  561. dividends, total, err2 := dividendsDb.EggEnergyCommunityDividendsFindAndCount(req.Page, req.Limit, req.StartAt, req.EndAt, req.StartNums, req.EndNums)
  562. if err2 != nil {
  563. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  564. return
  565. }
  566. list := make([]md.EggEnergyCommunityDividends, len(dividends))
  567. for i, dividend := range dividends {
  568. list[i] = md.EggEnergyCommunityDividends{
  569. Id: dividend.Id,
  570. Amount: dividend.Amount,
  571. Name: dividend.Name,
  572. CoinId: dividend.CoinId,
  573. PersonsNum: dividend.PersonsNum,
  574. IsOver: dividend.IsOver,
  575. CreateAt: dividend.CreateAt,
  576. UpdateAt: dividend.UpdateAt,
  577. }
  578. }
  579. resp := md.ListCommunityDividendsResp{
  580. List: list,
  581. Paginate: md.Paginate{
  582. Limit: req.Limit,
  583. Page: req.Page,
  584. Total: total,
  585. },
  586. }
  587. e.OutSuc(c, resp, nil)
  588. }
  589. // AddCommunityDividends
  590. // @Summary 制度中心-公排管理-社区分红(新增)
  591. // @Tags 公排管理
  592. // @Description 社区分红(新增)
  593. // @Accept json
  594. // @Produce json
  595. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  596. // @Param req body md.AddCommunityDividendsReq true "分红名称、分红总量"
  597. // @Success 200 {success} "成功"
  598. // @Failure 400 {object} md.Response "具体错误"
  599. // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsAdd [post]
  600. func AddCommunityDividends(c *gin.Context) {
  601. var req *md.AddCommunityDividendsReq
  602. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  603. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  604. return
  605. }
  606. settingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  607. basic, err1 := settingDb.EggEnergyBasicSettingGetOne()
  608. if err1 != nil {
  609. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  610. return
  611. }
  612. rule.Init(cfg.RedisAddr)
  613. err2 := ruleSvc.AddCommunityDividends(db.Db, req.Amount, req.Name, *basic)
  614. if err2 != nil {
  615. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  616. return
  617. }
  618. e.OutSuc(c, "success", nil)
  619. }
  620. // ListCommunityDividendsWithUser
  621. // @Summary 制度中心-公排管理-社区长列表(查询)
  622. // @Tags 公排管理
  623. // @Description 社区长列表(查询)
  624. // @Accept json
  625. // @Produce json
  626. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  627. // @Param req body md.ListCommunityDividendsWithUserReq true "页数、每页大小必填 手机号、用户ID选填"
  628. // @Success 200 {object} md.ListCommunityDividendsWithUserResp "社区长列表"
  629. // @Failure 400 {object} md.Response "具体错误"
  630. // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsWithUserList [post]
  631. func ListCommunityDividendsWithUser(c *gin.Context) {
  632. var req *md.ListCommunityDividendsWithUserReq
  633. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  634. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  635. return
  636. }
  637. var uid int64
  638. if req.Phone != "" {
  639. userDb := implement.NewUserDb(db.Db)
  640. user, err := userDb.UserGetOneByParams(map[string]interface{}{
  641. "key": "phone",
  642. "value": req.Phone,
  643. })
  644. if err != nil {
  645. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  646. return
  647. }
  648. uid = user.Id
  649. }
  650. if req.Uid != 0 {
  651. uid = req.Uid
  652. }
  653. dividendsWithUserDb := implement.NewEggEnergyCommunityDividendsWithUserDb(db.Db)
  654. dividendsWithUserList, total, err := dividendsWithUserDb.EggEnergyCommunityDividendsWithUserFindAndCount(req.Page, req.Limit, uid)
  655. if err != nil {
  656. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  657. return
  658. }
  659. list := make([]md.EggEnergyCommunityDividendsWithUser, len(dividendsWithUserList))
  660. if len(dividendsWithUserList) > 0 {
  661. uids := make([]int64, len(dividendsWithUserList))
  662. for i, user := range dividendsWithUserList {
  663. uids[i] = user.Uid
  664. }
  665. userDb := implement.NewUserDb(db.Db)
  666. users, err := userDb.UserFindByParams(map[string]interface{}{
  667. "key": "id",
  668. "value": uids,
  669. })
  670. if err != nil {
  671. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  672. return
  673. }
  674. userMap := make(map[int64]model.User)
  675. for _, user := range users {
  676. userMap[user.Id] = user
  677. }
  678. for i, user := range dividendsWithUserList {
  679. list[i] = md.EggEnergyCommunityDividendsWithUser{
  680. Id: user.Id,
  681. Uid: user.Uid,
  682. Memo: user.Memo,
  683. Phone: userMap[user.Uid].Phone,
  684. Nickname: userMap[user.Uid].Nickname,
  685. }
  686. }
  687. }
  688. resp := md.ListCommunityDividendsWithUserResp{
  689. List: list,
  690. Paginate: md.Paginate{
  691. Limit: req.Limit,
  692. Page: req.Page,
  693. Total: total,
  694. },
  695. }
  696. e.OutSuc(c, resp, nil)
  697. }
  698. // AddCommunityDividendsWithUser
  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.AddCommunityDividendsWithUserReq true "新增社区长 ID、备注"
  706. // @Success 200 {int} "插入数据 ID"
  707. // @Failure 400 {object} md.Response "具体错误"
  708. // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsWithUserAdd [post]
  709. func AddCommunityDividendsWithUser(c *gin.Context) {
  710. var req *md.AddCommunityDividendsWithUserReq
  711. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  712. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  713. return
  714. }
  715. communityDividendsWithUserDb := implement.NewEggEnergyCommunityDividendsWithUserDb(db.Db)
  716. exist, err := communityDividendsWithUserDb.EggEnergyCommunityDividendsWithUserExist(req.Uid)
  717. if err != nil {
  718. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  719. return
  720. }
  721. if exist {
  722. e.OutErr(c, e.ERR_BAD_REQUEST, "请勿重复添加")
  723. return
  724. }
  725. now := time.Now()
  726. var m model.EggEnergyCommunityDividendsWithUser
  727. m = model.EggEnergyCommunityDividendsWithUser{
  728. Uid: req.Uid,
  729. Memo: req.Memo,
  730. CreateAt: now.Format("2006-01-02 15:04:05"),
  731. UpdateAt: now.Format("2006-01-02 15:04:05"),
  732. }
  733. id, err := communityDividendsWithUserDb.EggEnergyCommunityDividendsWithUserInsert(&m)
  734. if err != nil {
  735. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  736. return
  737. }
  738. e.OutSuc(c, id, nil)
  739. }
  740. // DelCommunityDividendsWithUser
  741. // @Summary 制度中心-公排管理-社区长列表(删除)
  742. // @Tags 公排管理
  743. // @Description 社区长列表(删除)
  744. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  745. // @Accept json
  746. // @Produce json
  747. // @Success 200 {int} "删除数据数量"
  748. // @Failure 400 {object} md.Response "具体错误"
  749. // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsWithUserDel/{$id} [DELETE]
  750. func DelCommunityDividendsWithUser(c *gin.Context) {
  751. id := c.Param("id")
  752. dividendsWithUserDb := implement.NewEggEnergyCommunityDividendsWithUserDb(db.Db)
  753. affected, err := dividendsWithUserDb.EggEnergyCommunityDividendsWithUserDel(id)
  754. if err != nil {
  755. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  756. return
  757. }
  758. e.OutSuc(c, affected, nil)
  759. }
  760. // UserDailyActivityAnalysis
  761. // @Summary 制度中心-公排管理-日活分析
  762. // @Tags 公排管理
  763. // @Description 日活分析
  764. // @Accept json
  765. // @Produce json
  766. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  767. // @Param req body md.UserDailyActivityAnalysisReq true "用户 ID、查询开始时间、结束时间(查询时间不超过30天)、页数、每页大小"
  768. // @Success 200 {object} md.UserDailyActivityAnalysisResp "具体数据"
  769. // @Failure 400 {object} md.Response "具体错误"
  770. // @Router /api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis/index [post]
  771. func UserDailyActivityAnalysis(c *gin.Context) {
  772. var req *md.UserDailyActivityAnalysisReq
  773. if err := c.ShouldBindJSON(&req); err != nil {
  774. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  775. return
  776. }
  777. total, sons, err := svc.GetSonUserDailyActivity(db.Db, req.Uid, req.StartDate, req.EndDate, req.Page, req.PageSize)
  778. if err != nil {
  779. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  780. return
  781. }
  782. 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"
  783. results, err := db.Db.QueryString(sql1, req.Uid, req.StartDate, req.EndDate)
  784. if err != nil {
  785. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  786. return
  787. }
  788. var activityCount, activityUserCount int64
  789. for _, result := range results {
  790. tempCount := utils.StrToInt64(result["total"])
  791. activityCount += tempCount
  792. activityUserCount++
  793. }
  794. topData := md.DailyActivityAnalysisTopData{
  795. TeamUserCount: total,
  796. ActivityCount: activityCount,
  797. TeamActivityUserCount: activityUserCount,
  798. }
  799. if sons == nil {
  800. sons = make([]md.SonUserDailyActivityAnalysisNode, 0)
  801. }
  802. resp := md.UserDailyActivityAnalysisResp{
  803. TopData: topData,
  804. SonUserData: sons,
  805. }
  806. e.OutSuc(c, resp, nil)
  807. }