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

348 lines
11 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/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 interface{} true "公排设置表单内容"
  69. // @Success 200 {string} "success"
  70. // @Failure 400 {object} md.Response "具体错误"
  71. // @Router /api/publicPlatoon/getBasic [post]
  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)
  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)
  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/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 req query public_platoon.FindUserRelationshipMapReq true "用户ID"
  169. // @Success 200 {object} public_platoon.RelationshipMap "具体数据"
  170. // @Failure 400 {object} md.Response "具体错误"
  171. // @Router /api/publicPlatoon/findUserRelationshipMap [get]
  172. //func FindUserRelationshipMap(c *gin.Context) {
  173. // var req *public_platoon.FindUserRelationshipMapReq
  174. // if err := c.ShouldBindQuery(&req); err != nil {
  175. // e.OutErr(c, e.ERR_INVALID_ARGS, err)
  176. // return
  177. // }
  178. //
  179. // RelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  180. // relations, err1 := RelationDb.PublicPlatoonUserRelationFindByUid(req.Uid)
  181. // if err1 != nil {
  182. // e.OutErr(c, e.ERR_DB_ORM, err1)
  183. // return
  184. // }
  185. //
  186. // userDb := implement.NewUserDb(db.Db)
  187. // user, err3 := userDb.UserGetOneById(relations[0].Uid)
  188. // if err3 != nil {
  189. // e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  190. // return
  191. // }
  192. // var son []public_platoon.RelationshipMap
  193. // res := public_platoon.RelationshipMap{
  194. // AvatarUrl: user.Avatar,
  195. // Phone: user.Phone,
  196. // Nickname: user.Nickname,
  197. // Uid: user.Id,
  198. // Pid: relations[0].RecommendUid,
  199. // Level: relations[0].Level1,
  200. // Position: relations[0].Position1,
  201. // SystemID: relations[0].Id,
  202. // Son: son,
  203. // }
  204. // for i := 1; i < len(relations); i++ {
  205. // user, err4 := userDb.UserGetOneById(relations[i].Uid)
  206. // if err4 != nil {
  207. // e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  208. // return
  209. // }
  210. // node := public_platoon.RelationshipMap{
  211. // AvatarUrl: user.Avatar,
  212. // Phone: user.Phone,
  213. // Nickname: user.Nickname,
  214. // Uid: user.Id,
  215. // Pid: relations[i].RecommendUid,
  216. // Level: relations[i].Level1,
  217. // Position: relations[i].Position1,
  218. // SystemID: relations[i].Id,
  219. // Son: nil,
  220. // }
  221. // res.Son = append(res.Son, node)
  222. // }
  223. // e.OutSuc(c, res, nil)
  224. //}
  225. //
  226. //// FindSubUserRelationshipMap
  227. //// @Summary 制度中心-公排管理-关系分布图(获取指定用户上级)
  228. //// @Tags 公排管理
  229. //// @Description 关系分布图(获取指定用户上级)
  230. //// @Accept json
  231. //// @Produce json
  232. //// @param Authorization header string true "验证参数Bearer和token空格拼接"
  233. //// @Param req query public_platoon.FindSubUserRelationshipMapReq true "用户ID"
  234. //// @Success 200 {object} public_platoon.RelationshipMap "具体数据"
  235. //// @Failure 400 {object} md.Response "具体错误"
  236. //// @Router /api/publicPlatoon/findSubUserRelationshipMap [get]
  237. //func FindSubUserRelationshipMap(c *gin.Context) {
  238. // var req *public_platoon.FindSubUserRelationshipMapReq
  239. // if err := c.ShouldBindQuery(&req); err != nil {
  240. // e.OutErr(c, e.ERR_INVALID_ARGS, err)
  241. // return
  242. // }
  243. //
  244. // RelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  245. // sonRelation, err1 := RelationDb.PublicPlatoonUserRelationGetOneByUid(req.Uid)
  246. // if err1 != nil {
  247. // e.OutErr(c, e.ERR_DB_ORM, err1)
  248. // return
  249. // }
  250. // parentRelation, err2 := RelationDb.PublicPlatoonUserRelationGetOneByUid(sonRelation.FatherUid1)
  251. // if err2 != nil {
  252. // e.OutErr(c, e.ERR_DB_ORM, err2)
  253. // return
  254. // }
  255. //
  256. // userDb := implement.NewUserDb(db.Db)
  257. // son, err3 := userDb.UserGetOneById(sonRelation.Uid)
  258. // if err3 != nil {
  259. // e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  260. // return
  261. // }
  262. //
  263. // parent, err4 := userDb.UserGetOneById(parentRelation.Uid)
  264. // if err4 != nil {
  265. // e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  266. // return
  267. // }
  268. //
  269. // var sonNode []public_platoon.RelationshipMap
  270. // sonNode1 := public_platoon.RelationshipMap{
  271. // AvatarUrl: son.Avatar,
  272. // Phone: son.Phone,
  273. // Nickname: son.Nickname,
  274. // Uid: son.Id,
  275. // Pid: sonRelation.RecommendUid,
  276. // Level: sonRelation.Level1,
  277. // Position: sonRelation.Position1,
  278. // SystemID: sonRelation.Id,
  279. // Son: nil,
  280. // }
  281. // sonNode = append(sonNode, sonNode1)
  282. // res := public_platoon.RelationshipMap{
  283. // AvatarUrl: parent.Avatar,
  284. // Phone: parent.Phone,
  285. // Nickname: parent.Nickname,
  286. // Uid: parent.Id,
  287. // Pid: parentRelation.RecommendUid,
  288. // Level: parentRelation.Level1,
  289. // Position: parentRelation.Position1,
  290. // SystemID: parentRelation.Id,
  291. // Son: sonNode,
  292. // }
  293. // e.OutSuc(c, res, nil)
  294. //}
  295. func ExchangeUserPosition(c *gin.Context) {
  296. var req *md.ExchangeUserPositionReq
  297. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  298. e.OutErr(c, e.ERR_INVALID_ARGS, err1)
  299. return
  300. }
  301. relationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  302. relation1, err2 := relationDb.PublicPlatoonUserRelationGetOneByPosition(req.Position1)
  303. if err2 != nil {
  304. e.OutErr(c, e.ERR_DB_ORM, err2)
  305. return
  306. }
  307. if relation1 == nil {
  308. e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("position_1 位置有误"))
  309. return
  310. }
  311. relation2, err3 := relationDb.PublicPlatoonUserRelationGetOneByPosition(req.Position1)
  312. if err3 != nil {
  313. e.OutErr(c, e.ERR_DB_ORM, err3)
  314. return
  315. }
  316. if relation2 == nil {
  317. e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("position_2 位置有误"))
  318. return
  319. }
  320. if relation1.Uid == 1 || relation2.Uid == 1 {
  321. e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("创始人位置不能被修改"))
  322. }
  323. //uid1 := relation1.Uid
  324. //uid2 := relation2.Uid
  325. //recommendUid1 := relation1.RecommendUid
  326. //recommendUid2 := relation2.RecommendUid
  327. //relation1.Uid = ""
  328. }