Beispiel #1
0
    def add_member_and_finish_request(self, activity, order, total_fee,
                                      member_state, payment_state, form,
                                      extra_fields):
        """
        Args:
            activity: 要参加的活动,
            order: 订单
            total_fee: 总金额,
            member_state: ActivityMember.state,
            payment_state: TeamOrder.state
            form:
            extra_fields: 参加活动的自定义字段
        """
        activity.add_member(
            user_id=self.current_user.id,
            users_count=form['users_count'],
            price=activity.price,
            free_times=0,
            total_fee=total_fee,
            order_id=order.id if order else 0,
            order_no=order.order_no if order else 0,
            payment_state=payment_state,
            state=member_state,
            **extra_fields,
        )

        self.sync_user_info(extra_fields)
        self.auto_join_team(activity.team)

        self.write_success(
            state=member_state,
            payment_state=TeamOrder.OrderState(payment_state).name,
            order_no=order.order_no if order else ""
        )
    def get(self, order_no):
        order = TeamOrder.get_or_404(order_no=order_no)

        self.write({
            "order_no": order.order_no,
            "team_id": order.team_id,
            "state": TeamOrder.OrderState(order.state).name
        })
Beispiel #3
0
    def get(self):
        parteam = Parteam(self.settings["parteam_api_url"])

        state = intval(self.get_argument("state", 100))
        start = self.get_argument("start", "")
        end = self.get_argument("end", "")

        orders = TeamOrder.select(
            TeamOrder,
            MatchMember
        ).join(
            MatchMember,
            on=(TeamOrder.id == MatchMember.order_id).alias("match_member")
        ).where(
            TeamOrder.team == self.current_team
        ).order_by(
            TeamOrder.id.desc()
        )

        if start:
            start = "%s 00:00:00" % start
            orders = orders.where(TeamOrder.created >= start)

        if end:
            end = "%s 23:59:59" % end
            orders = orders.where(TeamOrder.created <= end)

        if state != 100:
            orders = orders.where(TeamOrder.state ==
                                  TeamOrder.OrderState(state))

        query = self.paginate_query(orders)
        orders = []
        for item in query:
            orders.append(dict(item.info,
                               order_type_name=item.order_type_name,
                               state_name=item.state_name,
                               payment_method_name=item.payment_method_name,
                               match_member=item.match_member.info))

        user_ids = [order["match_member"]["user_id"] for order in orders
                    if order["match_member"]["user_id"]]

        if user_ids:
            user_infos = parteam.parteam_user(user_ids)
            for order in orders:
                order["user_info"] =\
                    user_infos.get(order["match_member"]["user_id"])

        self.render("orders/orders.html",
                    states=TeamOrder.ORDER_STATES,
                    orders=orders,
                    pagination=query.pagination
                    )
Beispiel #4
0
    def get(self):
        """订单列表"""

        state = intval(self.get_argument("state", 100))
        start = self.get_argument("start", "")
        end = self.get_argument("end", "")

        query = TeamOrder.select(
            TeamOrder,
            Team,
            Activity,
        ).join(
            Team, on=(Team.id == TeamOrder.team).alias("team")
        ).switch(
            TeamOrder
        ).join(
            Activity,
            join_type=JOIN.LEFT_OUTER,
            on=(Activity.id == TeamOrder.activity_id).alias("activity")
        )

        is_restrict_by_areas = self.current_user.is_restrict_by_areas()
        if is_restrict_by_areas:
            query = query.join(
                User,
                on=(User.id == Team.owner_id)
            ).where(
                User.province << self.current_user.valid_manage_provinces
            )

        kw = self.get_argument("kw", "")
        if kw:
            query = query.where(TeamOrder.title ** ("%%%s%%" % kw))

        if start:
            start = "%s 00:00:00" % start
            query = query.where(TeamOrder.created >= start)

        if end:
            end = "%s 23:59:59" % end
            query = query.where(TeamOrder.created <= end)

        if state != 100:
            query = query.where(TeamOrder.state == TeamOrder.OrderState(state))

        query = query.order_by(TeamOrder.id.desc())
        orders = self.paginate_query(query)

        self.render("order/orders.html",
                    states=TeamOrder.ORDER_STATES,
                    orders=orders,
                    )
Beispiel #5
0
    def refund(self, reason=""):
        """ 退款
        """
        # 未支付或已退款,无需退款
        if TeamOrder.OrderState(
                self.payment_state) != TeamOrder.OrderState.TRADE_BUYER_PAID:
            return True

        order = TeamOrder.get_or_none(id=self.order_id)
        if order is None:
            return True

        # 退款
        order.refund(reason=reason, free_times=self.free_times)

        return True