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

937 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. if parentUser == nil {
  309. e.OutErr(c, e.ERR_NO_DATA, errors.New("该用户不存在上级用户"))
  310. return
  311. }
  312. platoonUserRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  313. parentRelation, err := platoonUserRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  314. "key": "uid",
  315. "value": parentUser.Id,
  316. })
  317. if err != nil {
  318. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  319. return
  320. }
  321. subUser := md.SubUser{
  322. AvatarURL: parentUser.Avatar,
  323. Phone: parentUser.Phone,
  324. Nickname: parentUser.Nickname,
  325. Uid: parentUser.Id,
  326. PID: parentRelation.RecommendUid,
  327. Level: parentRelation.LevelTotal,
  328. Position: parentRelation.Position1,
  329. }
  330. basicSettingDb := implement.NewPublicPlatoonBasicSettingDb(db.Db)
  331. basicSetting, err := basicSettingDb.PublicPlatoonBasicSettingGetOne()
  332. if err != nil {
  333. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  334. return
  335. }
  336. basicSettingResp := md.BasicSetting{
  337. Id: basicSetting.Id,
  338. IsOpen: basicSetting.IsOpen,
  339. SeveralTimes: basicSetting.SeveralTimes,
  340. SeveralRows: basicSetting.SeveralRows,
  341. OriginatorUid: basicSetting.OriginatorUid,
  342. SystemPunishReplace: basicSetting.SystemPunishReplace,
  343. SystemPunishReplaceValue: basicSetting.SystemPunishReplaceValue,
  344. IsSelfActiveGetTeamRevenue: basicSetting.IsSelfActiveGetTeamRevenue,
  345. }
  346. resp := md.FindSubUserRelationshipMapResp{
  347. SubUser: subUser,
  348. BasicSetting: basicSettingResp,
  349. SearchUid: uid,
  350. }
  351. e.OutSuc(c, resp, nil)
  352. }
  353. // ExchangeUserPosition
  354. // @Summary 制度中心-公排管理-关系分布图(位置转换)
  355. // @Tags 公排管理
  356. // @Description 关系分布图(位置转换)
  357. // @Accept json
  358. // @Produce json
  359. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  360. // @Param req body md.ExchangeUserPositionReq true "需要交换的两个位置"
  361. // @Success 200 {} "成功返回"
  362. // @Failure 400 {object} md.Response "具体错误"
  363. // @Router /api/institutionalManagement/publicPlatoon/exchangeUserPosition [post]
  364. func ExchangeUserPosition(c *gin.Context) {
  365. var req *md.ExchangeUserPositionReq
  366. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  367. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  368. return
  369. }
  370. userRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  371. relation1, err2 := userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  372. "key": "id",
  373. "value": req.Position1,
  374. })
  375. if err2 != nil {
  376. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  377. return
  378. }
  379. if relation1 == nil {
  380. e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("position_1 位置有误"))
  381. return
  382. }
  383. relation2, err3 := userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  384. "key": "id",
  385. "value": req.Position2,
  386. })
  387. if err3 != nil {
  388. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  389. return
  390. }
  391. if relation2 == nil {
  392. e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("position_2 位置有误"))
  393. return
  394. }
  395. if relation1.LevelTotal == 1 || relation2.LevelTotal == 1 {
  396. e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("创始人位置不能被修改"))
  397. }
  398. err4 := svc.ExchangeUserPosition(db.Db, relation1, relation2)
  399. if err4 != nil {
  400. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  401. return
  402. }
  403. e.OutSuc(c, nil, nil)
  404. }
  405. // NineDimensionalSpace
  406. // @Summary 制度中心-公排管理-关系分布图(公排详情)
  407. // @Tags 公排管理
  408. // @Description 关系分布图(公排详情)
  409. // @Accept json
  410. // @Produce json
  411. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  412. // @Param uid query string false "用户id"
  413. // @Success 200 {} "成功返回"
  414. // @Failure 400 {object} md.Response "具体错误"
  415. // @Router /api/institutionalManagement/publicPlatoon/nineDimensionalSpace [GET]
  416. func NineDimensionalSpace(c *gin.Context) {
  417. uid := c.Query("uid")
  418. // 1. 查询公排基础设置
  419. settingDb := implement.NewPublicPlatoonBasicSettingDb(db.Db)
  420. setting, err := settingDb.PublicPlatoonBasicSettingGetOneByParams(map[string]interface{}{
  421. "key": "is_open",
  422. "value": 1,
  423. })
  424. if err != nil {
  425. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  426. return
  427. }
  428. if setting == nil {
  429. e.OutErr(c, e.ERR_NO_DATA, nil)
  430. return
  431. }
  432. var spaceTotalNums float64
  433. var list []md.SpaceListNode
  434. for i := 1; i <= setting.SeveralRows; i++ {
  435. var tmpSql = fmt.Sprintf("SELECT COUNT(*)AS total FROM `public_platoon_user_relation` WHERE father_uid%d = %s", i, uid)
  436. tmpNativeString, _ := db.QueryNativeString(db.Db, tmpSql)
  437. nowUserCount := utils.StrToInt64(tmpNativeString[0]["total"])
  438. maxCount := math.Pow(float64(setting.SeveralTimes), float64(i))
  439. if nowUserCount > int64(maxCount) {
  440. nowUserCount = int64(maxCount)
  441. }
  442. list = append(list, md.SpaceListNode{
  443. Name: utils.IntToStr(i) + "维",
  444. MaxCount: int(maxCount),
  445. NowCount: int(nowUserCount),
  446. })
  447. spaceTotalNums += maxCount
  448. }
  449. resp := md.NineDimensionalSpaceResp{SpaceList: list}
  450. e.OutSuc(c, resp, nil)
  451. }
  452. // GetFreePublishUser
  453. // @Summary 制度中心-公排管理-免罚用户(查询)
  454. // @Tags 公排管理
  455. // @Description 免罚用户(查询)
  456. // @Accept json
  457. // @Produce json
  458. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  459. // @Param req body md.GetFreePublishUserReq true "页数和行数必填,uid选填"
  460. // @Success 200 {object} md.GetFreePublishUserResp "成功返回"
  461. // @Failure 400 {object} md.Response "具体错误"
  462. // @Router /api/institutionalManagement/publicPlatoon/publicPlatoonUserFreePunish/index [post]
  463. func GetFreePublishUser(c *gin.Context) {
  464. var req *md.GetFreePublishUserReq
  465. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  466. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  467. return
  468. }
  469. freePunishWithUserDb := implement.NewPublicPlatoonFreePunishWithUserDb(db.Db)
  470. var m []model.PublicPlatoonFreePunishWithUser
  471. var err error
  472. var total int64
  473. if req.Uid != 0 {
  474. m, total, err = freePunishWithUserDb.PublicPlatoonFreePunishWithUserCountAndGetPageByParams(req.Page, req.Limit, map[string]interface{}{
  475. "key": "uid",
  476. "value": req.Uid,
  477. })
  478. } else {
  479. m, total, err = freePunishWithUserDb.PublicPlatoonFreePunishWithUserCountAndGetPageByParams(req.Page, req.Limit, nil)
  480. }
  481. if err != nil {
  482. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  483. return
  484. }
  485. userDb := implement.NewUserDb(db.Db)
  486. var ids []int64
  487. for _, item := range m {
  488. ids = append(ids, item.Uid)
  489. }
  490. users, err2 := userDb.UserFindByParams(map[string]interface{}{
  491. "key": "id",
  492. "value": ids,
  493. })
  494. if err2 != nil {
  495. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  496. }
  497. var nodes []md.FreePublishUserNode
  498. for _, user := range users {
  499. nodes = append(nodes, md.FreePublishUserNode{
  500. UID: user.Id,
  501. Phone: user.Phone,
  502. Nickname: user.Nickname,
  503. })
  504. }
  505. var paginate md.Paginate
  506. paginate = md.Paginate{
  507. Limit: req.Limit,
  508. Page: req.Page,
  509. Total: total,
  510. }
  511. var resp md.GetFreePublishUserResp
  512. resp = md.GetFreePublishUserResp{
  513. Paginate: paginate,
  514. List: nodes,
  515. }
  516. e.OutSuc(c, resp, nil)
  517. }
  518. // AddFreePublishUser
  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.AddFreePublishUserReq true "免罚用户ID"
  526. // @Success 200 {int} "插入数据 ID"
  527. // @Failure 400 {object} md.Response "具体错误"
  528. // @Router /api/institutionalManagement/publicPlatoon/publicPlatoonUserFreePunish/save [post]
  529. func AddFreePublishUser(c *gin.Context) {
  530. var req *md.AddFreePublishUserReq
  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. userExist, err := freePunishWithUserDb.PublicPlatoonFreePunishWithUserGetOneByParams(map[string]interface{}{
  537. "key": "uid",
  538. "value": req.Uid,
  539. })
  540. if err != nil {
  541. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  542. return
  543. }
  544. if userExist != nil {
  545. e.OutErr(c, e.ERR_DB_ORM, "用户已在名单,无需重复添加")
  546. return
  547. }
  548. userDb := implement.NewUserDb(db.Db)
  549. user, err2 := userDb.UserGetOneByParams(map[string]interface{}{
  550. "key": "id",
  551. "value": req.Uid,
  552. })
  553. if err2 != nil {
  554. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  555. return
  556. }
  557. if user == nil {
  558. e.OutErr(c, e.ERR_DB_ORM, errors.New("该用户不存在"))
  559. }
  560. var m model.PublicPlatoonFreePunishWithUser
  561. m = model.PublicPlatoonFreePunishWithUser{
  562. Uid: req.Uid,
  563. }
  564. id, err3 := freePunishWithUserDb.PublicPlatoonFreePunishWithUserInsert(&m)
  565. if err3 != nil {
  566. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  567. return
  568. }
  569. e.OutSuc(c, id, nil)
  570. }
  571. // DeleteFreePublishUser
  572. // @Summary 制度中心-公排管理-免罚用户(删除)
  573. // @Tags 公排管理
  574. // @Description 免罚用户(删除)
  575. // @Accept json
  576. // @Produce json
  577. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  578. // @Param req body md.DeleteFreePublishUserReq true "免罚用户ID"
  579. // @Success 200 {int} "删除数据数量"
  580. // @Failure 400 {object} md.Response "具体错误"
  581. // @Router /api/institutionalManagement/publicPlatoon/publicPlatoonUserFreePunish/delete [delete]
  582. func DeleteFreePublishUser(c *gin.Context) {
  583. var req *md.DeleteFreePublishUserReq
  584. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  585. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  586. return
  587. }
  588. freePunishWithUserDb := implement.NewPublicPlatoonFreePunishWithUserDb(db.Db)
  589. affected, err := freePunishWithUserDb.PublicPlatoonFreePunishWithUserDeleteOneByUID(utils.StrToInt64(req.Uid))
  590. if err != nil {
  591. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  592. return
  593. }
  594. e.OutSuc(c, affected, nil)
  595. }
  596. // ListCommunityDividends
  597. // @Summary 制度中心-公排管理-社区分红(查询)
  598. // @Tags 公排管理
  599. // @Description 社区分红(查询)
  600. // @Accept json
  601. // @Produce json
  602. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  603. // @Param req body md.ListCommunityDividendsReq true "页数、每页大小必填 起止时间、起止数量选填"
  604. // @Success 200 {object} md.ListCommunityDividendsResp "具体数据"
  605. // @Failure 400 {object} md.Response "具体错误"
  606. // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsList [post]
  607. func ListCommunityDividends(c *gin.Context) {
  608. var req *md.ListCommunityDividendsReq
  609. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  610. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  611. return
  612. }
  613. dividendsDb := implement.NewEggEnergyCommunityDividendsDb(db.Db)
  614. dividends, total, err2 := dividendsDb.EggEnergyCommunityDividendsFindAndCount(req.Page, req.Limit, req.StartAt, req.EndAt, req.StartNums, req.EndNums)
  615. if err2 != nil {
  616. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  617. return
  618. }
  619. list := make([]md.EggEnergyCommunityDividends, len(dividends))
  620. for i, dividend := range dividends {
  621. list[i] = md.EggEnergyCommunityDividends{
  622. Id: dividend.Id,
  623. Amount: dividend.Amount,
  624. Name: dividend.Name,
  625. CoinId: dividend.CoinId,
  626. PersonsNum: dividend.PersonsNum,
  627. IsOver: dividend.IsOver,
  628. CreateAt: dividend.CreateAt,
  629. UpdateAt: dividend.UpdateAt,
  630. }
  631. }
  632. resp := md.ListCommunityDividendsResp{
  633. List: list,
  634. Paginate: md.Paginate{
  635. Limit: req.Limit,
  636. Page: req.Page,
  637. Total: total,
  638. },
  639. }
  640. e.OutSuc(c, resp, nil)
  641. }
  642. // AddCommunityDividends
  643. // @Summary 制度中心-公排管理-社区分红(新增)
  644. // @Tags 公排管理
  645. // @Description 社区分红(新增)
  646. // @Accept json
  647. // @Produce json
  648. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  649. // @Param req body md.AddCommunityDividendsReq true "分红名称、分红总量"
  650. // @Success 200 {success} "成功"
  651. // @Failure 400 {object} md.Response "具体错误"
  652. // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsAdd [post]
  653. func AddCommunityDividends(c *gin.Context) {
  654. var req *md.AddCommunityDividendsReq
  655. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  656. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  657. return
  658. }
  659. settingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  660. basic, err1 := settingDb.EggEnergyBasicSettingGetOne()
  661. if err1 != nil {
  662. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  663. return
  664. }
  665. rule.Init(cfg.RedisAddr)
  666. err2 := ruleSvc.AddCommunityDividends(db.Db, req.Amount, req.Name, *basic)
  667. if err2 != nil {
  668. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  669. return
  670. }
  671. e.OutSuc(c, "success", nil)
  672. }
  673. // ListCommunityDividendsWithUser
  674. // @Summary 制度中心-公排管理-社区长列表(查询)
  675. // @Tags 公排管理
  676. // @Description 社区长列表(查询)
  677. // @Accept json
  678. // @Produce json
  679. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  680. // @Param req body md.ListCommunityDividendsWithUserReq true "页数、每页大小必填 手机号、用户ID选填"
  681. // @Success 200 {object} md.ListCommunityDividendsWithUserResp "社区长列表"
  682. // @Failure 400 {object} md.Response "具体错误"
  683. // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsWithUserList [post]
  684. func ListCommunityDividendsWithUser(c *gin.Context) {
  685. var req *md.ListCommunityDividendsWithUserReq
  686. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  687. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  688. return
  689. }
  690. var uid int64
  691. if req.Phone != "" {
  692. userDb := implement.NewUserDb(db.Db)
  693. user, err := userDb.UserGetOneByParams(map[string]interface{}{
  694. "key": "phone",
  695. "value": req.Phone,
  696. })
  697. if err != nil {
  698. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  699. return
  700. }
  701. uid = user.Id
  702. }
  703. if req.Uid != 0 {
  704. uid = req.Uid
  705. }
  706. dividendsWithUserDb := implement.NewEggEnergyCommunityDividendsWithUserDb(db.Db)
  707. dividendsWithUserList, total, err := dividendsWithUserDb.EggEnergyCommunityDividendsWithUserFindAndCount(req.Page, req.Limit, uid)
  708. if err != nil {
  709. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  710. return
  711. }
  712. list := make([]md.EggEnergyCommunityDividendsWithUser, len(dividendsWithUserList))
  713. if len(dividendsWithUserList) > 0 {
  714. uids := make([]int64, len(dividendsWithUserList))
  715. for i, user := range dividendsWithUserList {
  716. uids[i] = user.Uid
  717. }
  718. userDb := implement.NewUserDb(db.Db)
  719. users, err := userDb.UserFindByParams(map[string]interface{}{
  720. "key": "id",
  721. "value": uids,
  722. })
  723. if err != nil {
  724. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  725. return
  726. }
  727. userMap := make(map[int64]model.User)
  728. for _, user := range users {
  729. userMap[user.Id] = user
  730. }
  731. for i, user := range dividendsWithUserList {
  732. list[i] = md.EggEnergyCommunityDividendsWithUser{
  733. Id: user.Id,
  734. Uid: user.Uid,
  735. Memo: user.Memo,
  736. Phone: userMap[user.Uid].Phone,
  737. Nickname: userMap[user.Uid].Nickname,
  738. }
  739. }
  740. }
  741. resp := md.ListCommunityDividendsWithUserResp{
  742. List: list,
  743. Paginate: md.Paginate{
  744. Limit: req.Limit,
  745. Page: req.Page,
  746. Total: total,
  747. },
  748. }
  749. e.OutSuc(c, resp, nil)
  750. }
  751. // AddCommunityDividendsWithUser
  752. // @Summary 制度中心-公排管理-社区长列表(新增)
  753. // @Tags 公排管理
  754. // @Description 社区长列表(新增)
  755. // @Accept json
  756. // @Produce json
  757. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  758. // @Param req body md.AddCommunityDividendsWithUserReq true "新增社区长 ID、备注"
  759. // @Success 200 {int} "插入数据 ID"
  760. // @Failure 400 {object} md.Response "具体错误"
  761. // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsWithUserAdd [post]
  762. func AddCommunityDividendsWithUser(c *gin.Context) {
  763. var req *md.AddCommunityDividendsWithUserReq
  764. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  765. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  766. return
  767. }
  768. communityDividendsWithUserDb := implement.NewEggEnergyCommunityDividendsWithUserDb(db.Db)
  769. exist, err := communityDividendsWithUserDb.EggEnergyCommunityDividendsWithUserExist(req.Uid)
  770. if err != nil {
  771. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  772. return
  773. }
  774. if exist {
  775. e.OutErr(c, e.ERR_BAD_REQUEST, "请勿重复添加")
  776. return
  777. }
  778. now := time.Now()
  779. var m model.EggEnergyCommunityDividendsWithUser
  780. m = model.EggEnergyCommunityDividendsWithUser{
  781. Uid: req.Uid,
  782. Memo: req.Memo,
  783. CreateAt: now.Format("2006-01-02 15:04:05"),
  784. UpdateAt: now.Format("2006-01-02 15:04:05"),
  785. }
  786. id, err := communityDividendsWithUserDb.EggEnergyCommunityDividendsWithUserInsert(&m)
  787. if err != nil {
  788. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  789. return
  790. }
  791. e.OutSuc(c, id, nil)
  792. }
  793. // DelCommunityDividendsWithUser
  794. // @Summary 制度中心-公排管理-社区长列表(删除)
  795. // @Tags 公排管理
  796. // @Description 社区长列表(删除)
  797. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  798. // @Accept json
  799. // @Produce json
  800. // @Success 200 {int} "删除数据数量"
  801. // @Failure 400 {object} md.Response "具体错误"
  802. // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsWithUserDel/{$id} [DELETE]
  803. func DelCommunityDividendsWithUser(c *gin.Context) {
  804. id := c.Param("id")
  805. dividendsWithUserDb := implement.NewEggEnergyCommunityDividendsWithUserDb(db.Db)
  806. affected, err := dividendsWithUserDb.EggEnergyCommunityDividendsWithUserDel(id)
  807. if err != nil {
  808. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  809. return
  810. }
  811. e.OutSuc(c, affected, nil)
  812. }
  813. // UserDailyActivityAnalysis
  814. // @Summary 制度中心-公排管理-日活分析
  815. // @Tags 公排管理
  816. // @Description 日活分析
  817. // @Accept json
  818. // @Produce json
  819. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  820. // @Param req body md.UserDailyActivityAnalysisReq true "用户 ID、查询开始时间、结束时间(查询时间不超过30天)、页数、每页大小"
  821. // @Success 200 {object} md.UserDailyActivityAnalysisResp "具体数据"
  822. // @Failure 400 {object} md.Response "具体错误"
  823. // @Router /api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis/index [post]
  824. func UserDailyActivityAnalysis(c *gin.Context) {
  825. var req *md.UserDailyActivityAnalysisReq
  826. if err := c.ShouldBindJSON(&req); err != nil {
  827. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  828. return
  829. }
  830. total, sons, err := svc.GetSonUserDailyActivity(db.Db, req.Uid, req.StartDate, req.EndDate, req.Page, req.PageSize)
  831. if err != nil {
  832. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  833. return
  834. }
  835. 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"
  836. results, err := db.Db.QueryString(sql1, req.Uid, req.StartDate, req.EndDate)
  837. if err != nil {
  838. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  839. return
  840. }
  841. var activityCount, activityUserCount int64
  842. for _, result := range results {
  843. tempCount := utils.StrToInt64(result["total"])
  844. activityCount += tempCount
  845. activityUserCount++
  846. }
  847. topData := md.DailyActivityAnalysisTopData{
  848. TeamUserCount: total,
  849. ActivityCount: activityCount,
  850. TeamActivityUserCount: activityUserCount,
  851. }
  852. if sons == nil {
  853. sons = make([]md.SonUserDailyActivityAnalysisNode, 0)
  854. }
  855. resp := md.UserDailyActivityAnalysisResp{
  856. TopData: topData,
  857. SonUserData: sons,
  858. }
  859. e.OutSuc(c, resp, nil)
  860. }