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

529 lines
17 KiB

  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. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  9. "errors"
  10. "github.com/gin-gonic/gin"
  11. "time"
  12. )
  13. // GetPublicPlatoonBasic
  14. // @Summary 制度中心-公排管理-公排基础设置(获取)
  15. // @Tags 公排管理
  16. // @Description 公排基础设置(获取)
  17. // @Accept json
  18. // @Produce json
  19. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  20. // @Success 200 {object} md.GetPublicPlatoonBasicResp "具体数据"
  21. // @Failure 400 {object} md.Response "具体错误"
  22. // @Router /api/institutionalManagement/publicPlatoon/getBasic [get]
  23. func GetPublicPlatoonBasic(c *gin.Context) {
  24. publicPlatoonBasicDb := implement.NewPublicPlatoonBasicSettingDb(db.Db)
  25. publicPlatoonBasic, err := publicPlatoonBasicDb.PublicPlatoonBasicSettingGetOne()
  26. if err != nil {
  27. e.OutErr(c, e.ERR_DB_ORM, err)
  28. return
  29. }
  30. now := time.Now()
  31. if publicPlatoonBasic == nil {
  32. publicPlatoonBasic = &model.PublicPlatoonBasicSetting{
  33. IsOpen: 1,
  34. OriginatorUid: 0,
  35. SeveralTimes: 0,
  36. SeveralRows: 0,
  37. SystemPunishReplace: 0,
  38. SystemPunishReplaceValue: 0,
  39. IsSelfActiveGetTeamRevenue: 0,
  40. CreateAt: now.Format("2006-01-02 15:04:05"),
  41. UpdateAt: now.Format("2006-01-02 15:04:05"),
  42. }
  43. _, err1 := publicPlatoonBasicDb.PublicPlatoonBasicSettingInsert(publicPlatoonBasic)
  44. if err1 != nil {
  45. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  46. return
  47. }
  48. }
  49. var resp md.GetPublicPlatoonBasicResp
  50. resp = md.GetPublicPlatoonBasicResp{
  51. IsOpen: publicPlatoonBasic.IsOpen,
  52. OriginatorUid: publicPlatoonBasic.OriginatorUid,
  53. SeveralTimes: publicPlatoonBasic.SeveralTimes,
  54. SeveralRows: publicPlatoonBasic.SeveralRows,
  55. SystemPunishReplace: publicPlatoonBasic.SystemPunishReplace,
  56. SystemPunishReplaceValue: publicPlatoonBasic.SystemPunishReplaceValue,
  57. IsSelfActiveGetTeamRevenue: publicPlatoonBasic.IsSelfActiveGetTeamRevenue,
  58. }
  59. e.OutSuc(c, resp, nil)
  60. }
  61. // UpdatePublicPlatoonBasic
  62. // @Summary 制度中心-公排管理-公排基础设置(修改)
  63. // @Tags 公排管理
  64. // @Description 公排基础设置(修改)
  65. // @Accept json
  66. // @Produce json
  67. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  68. // @Param req body md.UpdatePublicPlatoonBasicReq true "公排设置表单内容"
  69. // @Success 200 {string} "success"
  70. // @Failure 400 {object} md.Response "具体错误"
  71. // @Router /api/institutionalManagement/publicPlatoon/updateBasic [put]
  72. func UpdatePublicPlatoonBasic(c *gin.Context) {
  73. var req *md.UpdatePublicPlatoonBasicReq
  74. if err := c.ShouldBindJSON(&req); err != nil {
  75. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  76. return
  77. }
  78. publicPlatoonBasicDb := implement.NewPublicPlatoonBasicSettingDb(db.Db)
  79. publicPlatoonBasic, err := publicPlatoonBasicDb.PublicPlatoonBasicSettingGetOne()
  80. if err != nil {
  81. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  82. return
  83. }
  84. setting := &model.PublicPlatoonBasicSetting{
  85. Id: publicPlatoonBasic.Id,
  86. IsOpen: req.IsOpen,
  87. OriginatorUid: req.OriginatorUid,
  88. SeveralTimes: req.SeveralTimes,
  89. SeveralRows: req.SeveralRows,
  90. SystemPunishReplace: req.SystemPunishReplace,
  91. SystemPunishReplaceValue: req.SystemPunishReplaceValue,
  92. IsSelfActiveGetTeamRevenue: req.IsSelfActiveGetTeamRevenue,
  93. CreateAt: "",
  94. UpdateAt: "",
  95. }
  96. updateAffected, err := publicPlatoonBasicDb.PublicPlatoonBasicSettingUpdate(publicPlatoonBasic.Id, setting, "")
  97. if err != nil {
  98. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  99. return
  100. }
  101. if updateAffected <= 0 {
  102. e.OutErr(c, e.ERR_DB_ORM, "更新数据表失败")
  103. return
  104. }
  105. e.OutSuc(c, "success", nil)
  106. }
  107. // GetRelationshipMap
  108. // @Summary 制度中心-公排管理-关系分布图(获取)
  109. // @Tags 公排管理
  110. // @Description 关系分布图(获取)
  111. // @Accept json
  112. // @Produce json
  113. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  114. // @param phone query string true "phone"
  115. // @param uid query string true "uid"
  116. // @Success 200 {object} md.TreeNode "具体数据"
  117. // @Failure 400 {object} md.Response "具体错误"
  118. // @Router /api/institutionalManagement/publicPlatoon/relationshipMap [get]
  119. func GetRelationshipMap(c *gin.Context) {
  120. phone := c.Query("phone")
  121. uid := c.Query("uid")
  122. userDb := implement.NewUserDb(db.Db)
  123. userRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  124. var relation *model.PublicPlatoonUserRelation
  125. var err error
  126. if phone != "" {
  127. user, err1 := userDb.UserGetOneByParams(map[string]interface{}{
  128. "key": "phone",
  129. "value": phone,
  130. })
  131. if err1 != nil {
  132. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  133. }
  134. relation, err = userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  135. "key": "uid",
  136. "value": user.Id,
  137. })
  138. } else if uid != "" {
  139. relation, err = userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  140. "key": "uid",
  141. "value": uid,
  142. })
  143. } else {
  144. relation, err = userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  145. "key": "level_total",
  146. "value": 1,
  147. })
  148. if err != nil {
  149. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  150. return
  151. }
  152. }
  153. var list *md.TreeNode
  154. list, err = svc.GetTrees(db.Db, relation, 3)
  155. if err != nil {
  156. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  157. return
  158. }
  159. e.OutSuc(c, list, nil)
  160. }
  161. // FindUserRelationshipMap
  162. // @Summary 制度中心-公排管理-关系分布图(获取指定用户下级)
  163. // @Tags 公排管理
  164. // @Description 关系分布图(获取指定用户下级)
  165. // @Accept json
  166. // @Produce json
  167. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  168. // @Param uid query string true "用户ID"
  169. // @Success 200 {object} md.TreeNode "具体数据"
  170. // @Failure 400 {object} md.Response "具体错误"
  171. // @Router /api/institutionalManagement/publicPlatoon/findUserRelationshipMap [get]
  172. func FindUserRelationshipMap(c *gin.Context) {
  173. uid := c.Query("uid")
  174. userRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  175. var err error
  176. var relation *model.PublicPlatoonUserRelation
  177. relation, err = userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  178. "key": "uid",
  179. "value": uid,
  180. })
  181. if err != nil {
  182. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  183. return
  184. }
  185. var list *md.TreeNode
  186. list, err = svc.GetTrees(db.Db, relation, 3)
  187. if err != nil {
  188. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  189. return
  190. }
  191. e.OutSuc(c, list, nil)
  192. }
  193. // FindSubUserRelationshipMap
  194. // @Summary 制度中心-公排管理-关系分布图(获取指定用户上级)
  195. // @Tags 公排管理
  196. // @Description 关系分布图(获取指定用户上级)
  197. // @Accept json
  198. // @Produce json
  199. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  200. // @Param uid query string true "用户ID"
  201. // @Success 200 {object} md.TreeNode "具体数据"
  202. // @Failure 400 {object} md.Response "具体错误"
  203. // @Router /api/institutionalManagement/publicPlatoon/findSubUserRelationshipMap [get]
  204. func FindSubUserRelationshipMap(c *gin.Context) {
  205. uid := c.Query("uid")
  206. RelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  207. sonRelation, err1 := RelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  208. "key": "uid",
  209. "value": uid,
  210. })
  211. if err1 != nil {
  212. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  213. return
  214. }
  215. parentRelation, err2 := RelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  216. "key": "uid",
  217. "value": sonRelation.FatherUid1,
  218. })
  219. if err2 != nil {
  220. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  221. return
  222. }
  223. userDb := implement.NewUserDb(db.Db)
  224. son, err3 := userDb.UserGetOneByParams(map[string]interface{}{
  225. "key": "id",
  226. "value": sonRelation.Uid,
  227. })
  228. if err3 != nil {
  229. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  230. return
  231. }
  232. parent, err4 := userDb.UserGetOneByParams(map[string]interface{}{
  233. "key": "id",
  234. "value": parentRelation.Uid,
  235. })
  236. if err4 != nil {
  237. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  238. return
  239. }
  240. var sonNode []*md.TreeNode
  241. sonNode = append(sonNode, &md.TreeNode{
  242. AvatarURL: son.Avatar,
  243. Phone: son.Phone,
  244. Nickname: son.Nickname,
  245. Uid: son.Id,
  246. PID: sonRelation.RecommendUid,
  247. Level: sonRelation.Level1,
  248. Position: sonRelation.Position1,
  249. SystemID: sonRelation.Id,
  250. Son: nil,
  251. })
  252. res := md.TreeNode{
  253. AvatarURL: parent.Avatar,
  254. Phone: parent.Phone,
  255. Nickname: parent.Nickname,
  256. Uid: parent.Id,
  257. PID: parentRelation.RecommendUid,
  258. Level: parentRelation.Level1,
  259. Position: parentRelation.Position1,
  260. SystemID: parentRelation.Id,
  261. Son: sonNode,
  262. }
  263. e.OutSuc(c, res, nil)
  264. }
  265. // ExchangeUserPosition
  266. // @Summary 制度中心-公排管理-关系分布图(位置转换)
  267. // @Tags 公排管理
  268. // @Description 关系分布图(位置转换)
  269. // @Accept json
  270. // @Produce json
  271. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  272. // @Param req body md.ExchangeUserPositionReq true "需要交换的两个位置"
  273. // @Success 200 {} "成功返回"
  274. // @Failure 400 {object} md.Response "具体错误"
  275. // @Router /api/institutionalManagement/publicPlatoon/exchangeUserPosition [post]
  276. func ExchangeUserPosition(c *gin.Context) {
  277. var req *md.ExchangeUserPositionReq
  278. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  279. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  280. return
  281. }
  282. userRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  283. relation1, err2 := userRelationDb.PublicPlatoonUserRelationGetOneByPosition(req.Position1)
  284. if err2 != nil {
  285. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  286. return
  287. }
  288. if relation1 == nil {
  289. e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("position_1 位置有误"))
  290. return
  291. }
  292. relation2, err3 := userRelationDb.PublicPlatoonUserRelationGetOneByPosition(req.Position1)
  293. if err3 != nil {
  294. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  295. return
  296. }
  297. if relation2 == nil {
  298. e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("position_2 位置有误"))
  299. return
  300. }
  301. if relation1.Uid == 1 || relation2.Uid == 1 {
  302. e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("创始人位置不能被修改"))
  303. }
  304. err4 := svc.ExchangeUserPosition(db.Db, relation1, relation2)
  305. if err4 != nil {
  306. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  307. return
  308. }
  309. e.OutSuc(c, nil, nil)
  310. }
  311. // GetFreePublishUser
  312. // @Summary 制度中心-公排管理-免罚用户(查询)
  313. // @Tags 公排管理
  314. // @Description 免罚用户(查询)
  315. // @Accept json
  316. // @Produce json
  317. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  318. // @Param req body md.GetFreePublishUserReq true "页数和行数必填,uid选填"
  319. // @Success 200 {object} md.GetFreePublishUserResp "成功返回"
  320. // @Failure 400 {object} md.Response "具体错误"
  321. // @Router /api/institutionalManagement/publicPlatoon/publicPlatoonUserFreePunish/index [post]
  322. func GetFreePublishUser(c *gin.Context) {
  323. var req *md.GetFreePublishUserReq
  324. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  325. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  326. return
  327. }
  328. freePunishWithUserDb := implement.NewPublicPlatoonFreePunishWithUserDb(db.Db)
  329. var m []model.PublicPlatoonFreePunishWithUser
  330. var err error
  331. var total int64
  332. if req.Uid != 0 {
  333. m, total, err = freePunishWithUserDb.PublicPlatoonFreePunishWithUserCountAndGetPageByParams(req.Page, req.Limit, map[string]interface{}{
  334. "key": "uid",
  335. "value": req.Uid,
  336. })
  337. } else {
  338. m, total, err = freePunishWithUserDb.PublicPlatoonFreePunishWithUserCountAndGetPageByParams(req.Page, req.Limit, nil)
  339. }
  340. if err != nil {
  341. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  342. return
  343. }
  344. userDb := implement.NewUserDb(db.Db)
  345. var ids []int64
  346. for _, item := range m {
  347. ids = append(ids, item.Uid)
  348. }
  349. users, err2 := userDb.UserFindByParams(map[string]interface{}{
  350. "key": "id",
  351. "value": ids,
  352. })
  353. if err2 != nil {
  354. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  355. }
  356. var nodes []md.FreePublishUserNode
  357. for _, user := range users {
  358. nodes = append(nodes, md.FreePublishUserNode{
  359. UID: user.Id,
  360. Phone: user.Phone,
  361. Nickname: user.Nickname,
  362. })
  363. }
  364. var paginate md.Paginate
  365. paginate = md.Paginate{
  366. Limit: req.Limit,
  367. Page: req.Page,
  368. Total: total,
  369. }
  370. var resp md.GetFreePublishUserResp
  371. resp = md.GetFreePublishUserResp{
  372. Paginate: paginate,
  373. List: nodes,
  374. }
  375. e.OutSuc(c, resp, nil)
  376. }
  377. // AddFreePublishUser
  378. // @Summary 制度中心-公排管理-免罚用户(新增)
  379. // @Tags 公排管理
  380. // @Description 免罚用户(新增)
  381. // @Accept json
  382. // @Produce json
  383. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  384. // @Param req body md.AddFreePublishUserReq true "页数和行数必填,uid选填"
  385. // @Success 200 {int} "插入数据 ID"
  386. // @Failure 400 {object} md.Response "具体错误"
  387. // @Router /api/institutionalManagement/publicPlatoon/publicPlatoonUserFreePunish/save [post]
  388. func AddFreePublishUser(c *gin.Context) {
  389. var req *md.AddFreePublishUserReq
  390. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  391. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  392. return
  393. }
  394. userDb := implement.NewUserDb(db.Db)
  395. user, err2 := userDb.UserGetOneByParams(map[string]interface{}{
  396. "key": "id",
  397. "value": req.Uid,
  398. })
  399. if err2 != nil {
  400. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  401. return
  402. }
  403. if user == nil {
  404. e.OutErr(c, e.ERR_DB_ORM, errors.New("该用户不存在"))
  405. }
  406. freePunishWithUserDb := implement.NewPublicPlatoonFreePunishWithUserDb(db.Db)
  407. var m model.PublicPlatoonFreePunishWithUser
  408. m = model.PublicPlatoonFreePunishWithUser{
  409. Uid: req.Uid,
  410. }
  411. id, err3 := freePunishWithUserDb.PublicPlatoonFreePunishWithUserInsert(&m)
  412. if err3 != nil {
  413. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  414. return
  415. }
  416. e.OutSuc(c, id, nil)
  417. }
  418. // AddCommunityDividends
  419. // @Summary 制度中心-公排管理-社区分红(新增)
  420. // @Tags 公排管理
  421. // @Description 社区分红(新增)
  422. // @Accept json
  423. // @Produce json
  424. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  425. // @Param req body md.AddCommunityDividendsReq true "分红名称、分红总量"
  426. // @Success 200 {int} "插入数据 ID"
  427. // @Failure 400 {object} md.Response "具体错误"
  428. // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsAdd [post]
  429. func AddCommunityDividends(c *gin.Context) {
  430. var req *md.AddCommunityDividendsReq
  431. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  432. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  433. return
  434. }
  435. // todo 判断分红数量是否大于社区分红钱包余额
  436. now := time.Now()
  437. var m model.EggEnergyCommunityDividends
  438. m = model.EggEnergyCommunityDividends{
  439. Name: req.Name,
  440. CoinId: 0,
  441. PersonsNum: 0,
  442. IsOver: 0,
  443. CreateAt: now.Format("2006-01-02 15:04:05"),
  444. UpdateAt: now.Format("2006-01-02 15:04:05"),
  445. }
  446. dividendsDb := implement.NewEggEnergyCommunityDividendsDb(db.Db)
  447. id, err := dividendsDb.EggEnergyCommunityDividendsInsert(&m)
  448. if err != nil {
  449. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  450. return
  451. }
  452. e.OutSuc(c, id, nil)
  453. }
  454. // AddCommunityDividendsWithUser
  455. // @Summary 制度中心-公排管理-社区长列表(新增)
  456. // @Tags 公排管理
  457. // @Description 社区长列表(新增)
  458. // @Accept json
  459. // @Produce json
  460. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  461. // @Param req body md.AddCommunityDividendsWithUserReq true "新增社区长 ID、备注"
  462. // @Success 200 {int} "插入数据 ID"
  463. // @Failure 400 {object} md.Response "具体错误"
  464. // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsWithUserAdd [post]
  465. func AddCommunityDividendsWithUser(c *gin.Context) {
  466. var req *md.AddCommunityDividendsWithUserReq
  467. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  468. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  469. return
  470. }
  471. now := time.Now()
  472. var m model.EggEnergyCommunityDividendsWithUser
  473. m = model.EggEnergyCommunityDividendsWithUser{
  474. Uid: req.Uid,
  475. Memo: req.Memo,
  476. CreateAt: now.Format("2006-01-02 15:04:05"),
  477. UpdateAt: now.Format("2006-01-02 15:04:05"),
  478. }
  479. communityDividendsWithUserDb := implement.NewEggEnergyCommunityDividendsWithUserDb(db.Db)
  480. id, err := communityDividendsWithUserDb.EggEnergyCommunityDividendsWithUserInsert(&m)
  481. if err != nil {
  482. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  483. return
  484. }
  485. e.OutSuc(c, id, nil)
  486. }