蛋蛋星球-客户端
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 24 KiB

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