Beispiel #1
0
def match_start(self, match_id: int):
    """
    赛事开始前, 调用派队消息推送接口
    :param self: celery task Context
    :param match_id:
    :return:
    """
    match = Match.get(id=match_id)  # type: Match
    team = Team.get(id=match.team_id)  # type: Team
    members = MatchService.members(match,
                                   state=MatchMember.MatchMemberState.normal)
    infos = []
    for member in members:
        infos.append({"userId": member.user_id, "mobile": member.mobile})

    message = MatchStartMessage(
        user_infos=infos,
        match_id=match_id,
        match_name=match.title,
        sponsor_name=team.name,
        sponsor_pic_url=team.get_cover_url(size="medium"))

    pt = Parteam(app.settings["parteam_api_url"])
    if not pt.push_message(message=message):
        self.retry(exc=ParteamRequestError("调用派队推送接口失败"))
Beispiel #2
0
def new_match_status(self, match_id: int):
    """
    主办方发布新战报时向赛事成员推送信息
    :param self:
    :param match_id:
    :return:
    """
    match = Match.get(id=match_id)  # type: Match
    team = Team.get(id=match.team_id)  # type: Team
    members = MatchService.members(match,
                                   state=MatchMember.MatchMemberState.normal)

    infos = []
    for member in members:
        infos.append({"mobile": member.mobile, "userId": member.user_id})

    message = NewMatchScheduleMessage(
        user_infos=infos,
        match_id=match_id,
        match_name=match.title,
        sponsor_name=team.name,
        sponsor_pic_url=team.get_cover_url(size="medium"))

    pt = Parteam(app.settings["parteam_api_url"])
    if not pt.push_message(message):
        self.retry(ParteamRequestError("调用派队推送接口失败"))
Beispiel #3
0
    def post(self):
        form = self.validated_arguments
        team = Team.get(id=form.pop("team_id"))
        self.has_create_permission(team)

        fields = copy.copy(form)

        # 如果有地址信息, 获取 GPS 信息
        if "city" in form and "address" in form:
            logging.debug("有 `city` 和 `address` 开始调用远程接口获取 GPS 信息")
            geocode = yield self.get_geocode(city=form["city"],
                                             address=form["address"])
            logging.debug("获取到 geocode: {0}".format(geocode))
            if geocode.get("geocodes", []):
                location = geocode['geocodes'][0]['location'].split(",")
                fields["lat"] = location[1]
                fields["lng"] = location[0]
                fields["geohash "] = geohash.encode(float(location[1]),
                                                    float(location[0]))

        # TODO: 处理循环类型
        if "repeat_type" in form:
            if form["repeat_type"] == "week":
                fields["week_day"] = form["start_time"].weekday() + 1

            elif form["repeat_type"] == "month":
                fields["month_day"] = form["start_time"].day

        activity = Activity.create(team=team, creator=self.current_user,
                                   leader=self.current_user,
                                   **fields)
        self.set_status(201)
        self.write(ActivitySerializer(instance=activity).data)
Beispiel #4
0
    def test_patch_team(self):
        url = self.OBJECT_PATH.format(team_id=self.team.id)
        body = {
            "name": "new test create team",
            "description": "new description",
            "notice": "new notice",
            "province": "四川省",
            "city": "成都市",
            "address": "天府四街",
            "contact_person": "new contact person",
            "contact_phone": "new contact phone",
            "lat": 123.0,
            "lng": 123.0,
            "open_type": 1,
            "state": 2,
        }

        self.auth_user = self.team_owner
        response = self.fetch(url, method="PATCH", body=json.dumps(body))
        self.assertEqual(204, response.code, response.body.decode())
        updated = Team.get(id=self.team.id)

        self.assertEqual(0, updated.state, "状态被修改了")
        body.pop("state")
        for k, v in body.items():
            self.assertEqual(v, getattr(updated, k), k)
Beispiel #5
0
    def test_patch_team_permission_deny(self):
        url = self.OBJECT_PATH.format(team_id=self.team.id)
        body = {"name": "new name"}
        self.auth_user = User.create(name="permission deny for patch team")
        response = self.fetch(url, method="PATCH", body=json.dumps(body))
        self.assertEqual(403, response.code, response.body.decode)

        updated = Team.get(id=self.team.id)
        self.assertNotEqual("new name", updated.name, "权限错误, 但是跟新成功了")
    def test_finish_activity(self):
        finish_activity(self.activity.id)

        try:
            finish_activity(self.activity.id)
        except Exception as e:
            pass

        finished_activity = Activity.get(id=self.activity.id)
        rich_team = Team.get(id=self.team.id)

        new_activity = Activity.get(parent_id=self.activity.id)

        self.assertEqual(self.online_paid_amount,
                         finished_activity.online_paid_amount)
        self.assertEqual(finished_activity.state,
                         Activity.ActivityState.finished)
        self.assertEqual(rich_team.credit, self.online_paid_amount)
        self.assertIsInstance(new_activity, Activity)
    def put(self, team_id):
        team = Team.get_or_404(id=team_id)
        self.has_update_permission(team)

        if "icon" not in self.request.files:
            raise ApiException(400, "请选择文件")

        to_bucket = self.settings['qiniu_avatar_bucket']
        to_key = "team:%s%s" % (self.current_user.id, time.time())
        to_key = hashlib.md5(to_key.encode()).hexdigest()

        icon_key = self.upload_file(
            "icon",
            to_bucket=to_bucket,
            to_key=to_key,
        )
        team.icon_key = icon_key
        team.save()

        updated = Team.get(id=team.id)
        self.write(updated.icon)
Beispiel #8
0
def match_refund(self, match_id: int, order_no: str, user_info: dict):
    """
    主办方退款推送
    :param self:
    :param match_id:
    :param order_no: 派队支付订单
    :param user_info:
    :return:
    """
    match = Match.get(id=match_id)  # type: Match
    team = Team.get(id=match.team_id)
    message = RefundMessage(user_infos=[
        user_info,
    ],
                            order_no=order_no,
                            match_id=match_id,
                            match_name=match.title,
                            sponsor_name=team.name,
                            sponsor_pic_url=team.get_cover_url(size="medium"))
    pt = Parteam(app.settings["parteam_api_url"])
    if not pt.push_message(message):
        self.retry(exc=ParteamRequestError("调用派队推送接口失败"))
Beispiel #9
0
def join_match_done(self, match_id: int, member_id: int):
    """
    参加赛事完成, 调用派队消息推送接口
    :param: self: celery.task.Context
    :param match_id: int,  Match.id
    :param member_id: int, MatchMember.id
    """

    pt = Parteam(app.settings["parteam_api_url"])
    match = Match.get(id=match_id)  # type: Team
    team = Team.get(id=match.team_id)
    member = MatchMember.get(match_id=match_id,
                             id=member_id)  # type: MatchMember
    user_info = {"mobile": member.mobile, "userId": member.user_id}
    message = JoinMatchDone(user_infos=[user_info],
                            match_fee=int(member.total_fee * 100),
                            match_id=match_id,
                            match_name=match.title,
                            sponsor_name=team.name,
                            sponsor_pic_url=team.get_cover_url(size="medium"))

    if not pt.push_message(message=message):
        raise self.retry(exc=ParteamRequestError("调用派队推送接口失败"))