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

hdl_basic.go 28 KiB

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