def patch(self, user_id): user = User.get_or_404(id=user_id) self.has_update_permission(user) form = self.validated_arguments if not form: raise ApiException(400, "填写需要修改的属性和值") User.update(**form).where(User.id == user_id).execute() self.set_status(204)
def get(self, user_id): """获取用户详情""" user = User.get_or_404(id=user_id) if self.current_user and self.current_user == user: serializer = UserInsecureSerializer else: serializer = UserSimpleSerializer data = serializer(instance=user).data self.write(data)
def post(self): action = self.get_argument("action") user_id = self.get_argument("user_id") if action == "change_group": group_name = self.get_argument("group_name") member = Team.get_member(self.current_team.id, user_id) TeamMember.update(group_name=group_name).where( TeamMember.team == self.current_team, TeamMember.user == user_id).execute() # 计算新分组成员数量 TeamMemberGroup.update_members_count(self.current_team.id, group_name) # 计算旧分组成员数量 TeamMemberGroup.update_members_count(self.current_team.id, member.group_name) elif action == "apply": user = User.get_or_404(id=user_id) self.current_team.apply(user) elif action == "remove_member": member = Team.get_member(self.current_team.id, user_id) if member: if not member.can_leave(): raise HttpForbiddenError("该会员有财务没有结清,不能踢出") user = User.get_or_404(id=user_id) self.current_team.leave(user) TeamMemberGroup.update_members_count(self.current_team.id, member.group_name) elif action == "recharge": amount = intval(self.get_argument("amount")) freetimes = intval(self.get_argument("freetimes")) remark = self.get_argument("remark") member = Team.get_member(self.current_team.id, user_id) if member: TeamMember.change_credit( self.current_team.id, user_id=user_id, change_type=1, # 充值类型为后台操作 change_amount=amount, free_times=freetimes, operator_id=self.current_user.id, note=remark) elif action == "deduction": amount = intval(self.get_argument("amount")) freetimes = intval(self.get_argument("freetimes")) remark = self.get_argument("remark") member = Team.get_member(self.current_team.id, user_id) if member: TeamMember.change_credit( self.current_team.id, user_id=user_id, change_type=1, # 充值类型为后台操作 change_amount=0 - amount, free_times=0 - freetimes, operator_id=self.current_user.id, note=remark) self.write_success()