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

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