def patch(self, team_id): """ 修改俱乐部信息; 俱乐部徽标额外接口修改 """ team = Team.get_or_404(id=team_id) self.has_update_permission(team) form = self.validated_arguments Team.update(**form).where(Team.id == team.id).execute() self.set_status(204)
def post(self): action = self.get_argument("action") team_id = self.get_argument("team_id") if action == "pass": Team.update( state=1, updated=datetime.now() ).where( Team.id == team_id ).execute() self.write_success()
def post(self): form = ApplyCashFrom(self.arguments) settings = TeamSettings.get_or_none(team=self.current_team.id) if form.validate() and self.validate_amount(form) and \ settings and settings.cash_ready(): with(self.db.transaction()): team = Team.select().where( Team.id == self.current_team.id ).for_update().get() cash_amount = decimalval(self.get_argument("amount")) TeamCashLog.create( team_id=team.id, amount=cash_amount, cash_account_type=settings.cash_type, cash_account=settings.cash_account, cash_name=settings.cash_username, order_no=TeamCashLog.get_new_order_no() ) # 将收入打到俱乐部账上 Team.update( credit=Team.credit - cash_amount, cashed_amount=Team.cashed_amount + cash_amount, updated=datetime.now() ).where( Team.id == team.id ).execute() self.redirect(self.reverse_url("club_cash_logs")) return self.render("orders/apply_cash.html", form=form, settings=settings )
def get(self): if self.get_argument("auth_code", None): auth_info = self.get_query_auth(self.get_argument("auth_code")) team_weixin = TeamWeixin.get_or_none( appid=auth_info['authorizer_appid']) if team_weixin and team_weixin.team_id != self.current_team.id: self.flash("绑定失败:此微信公众号已绑定到其他俱乐部", category='danger') self.redirect(self.reverse_url("club_settings_weixin")) return if self.current_team.wx_appid and \ auth_info['authorizer_appid'] != self.current_team.wx_appid: self.flash("重新授权失败:新授权公众号与已绑定公众号不符", category='danger') self.redirect(self.reverse_url("club_settings_weixin_info")) return wx_info = self.get_authorizer_info(auth_info['authorizer_appid']) TeamWeixin.insert( team_id=self.current_team.id, access_token=auth_info['authorizer_access_token'], refresh_token=auth_info['authorizer_refresh_token'], expires_in=time.time() + auth_info['expires_in'] - 600, head_img=wx_info['authorizer_info'].get("head_img", ""), qrcode_url=wx_info['authorizer_info']["qrcode_url"], appid=wx_info['authorization_info']["authorizer_appid"], service_type=wx_info['authorizer_info'][ "service_type_info"]["id"], verify_type=wx_info['authorizer_info'][ "verify_type_info"]["id"], alias=wx_info['authorizer_info']["alias"], user_name=wx_info['authorizer_info'].get("user_name", ""), nick_name=wx_info['authorizer_info'].get("nick_name", ""), open_store=wx_info['authorizer_info'][ "business_info"]['open_store'], open_scan=wx_info['authorizer_info'][ "business_info"]['open_scan'], open_pay=wx_info['authorizer_info'][ "business_info"]['open_pay'], open_card=wx_info['authorizer_info'][ "business_info"]['open_card'], open_shake=wx_info['authorizer_info'][ "business_info"]['open_shake'], permissions=[str(i['funcscope_category']['id']) for i in wx_info['authorization_info']['func_info']] ).upsert().execute() Team.update( wx_appid=auth_info['authorizer_appid'], ).where( Team.id == self.current_team.id ).execute() self.flash("绑定微信公众号成功!", category='success') self.redirect(self.reverse_url("club_settings_weixin")) return redirect_uri = urljoin(self.request.full_url(), self.reverse_url("club_wxmp_bind") ) self.authorize_redirect(redirect_uri)
def approve_team(team_id): Team.update(state=1).where((Team.id == team_id) & (Team.state == 0)).execute()
def finish_activity(activity_id): """结算活动场次 1. 将用户在线支付费用转到俱乐部账户 2. 标记场次和订单状态为完成 3. 记录俱乐部账户变化 """ activity = Activity.get_or_404(id=activity_id) if activity.end_time > datetime.now(): raise Exception("活动场次未结束") if activity.state == Activity.ActivityState.cancelled: raise Exception("活动场次已取消") if activity.state == Activity.ActivityState.finished: raise Exception("活动场次已结算") # 计算在线支付完成交易的总额 online_paid_amount = TeamOrder.select(fn.SUM(TeamOrder.payment_fee)).where( TeamOrder.activity_id == activity_id, TeamOrder.state >= TeamOrder.OrderState.TRADE_BUYER_PAID.value, TeamOrder.refund_state == TeamOrder.OrderRefundState.NO_REFUND, TeamOrder.payment_method << TeamOrder.ONLINE_PAYMENT_METHODS).scalar() or 0 # 计算余额支付完成交易的总额 credit_paid_amount = TeamOrder.select(fn.SUM(TeamOrder.credit_fee)).where( TeamOrder.activity_id == activity_id, TeamOrder.state >= TeamOrder.OrderState.TRADE_BUYER_PAID.value).scalar() or 0 # 使用次数 free_times_amount = ActivityMember.select(fn.SUM( ActivityMember.free_times)).where( ActivityMember.state == ActivityMember.ActivityMemberState.confirmed).scalar() or 0 # online_paid_amount= DecimalField(default=Decimal(0), verbose_name="在线支付收入") # credit_paid_amount= DecimalField(default=Decimal(0), verbose_name="余额支付收入") # cash_paid_amount= DecimalField(default=Decimal(0), verbose_name="现金支付收入") # free_times_amount = IntegerField(default=0, verbose_name="次卡支付数量") with app.db.transaction() as txn: team = Team.select().where( Team.id == activity.team.id).for_update().get() # 将收入打到俱乐部账上 Team.update( credit=Team.credit + online_paid_amount, total_receipts=Team.total_receipts + online_paid_amount, updated=datetime.now()).where(Team.id == team.id).execute() # 将订单修改状态为已完成 TeamOrder.update( state=TeamOrder.OrderState.TRADE_FINISHED.value, finished=datetime.now()).where( TeamOrder.activity_id == activity_id, TeamOrder.state == TeamOrder.OrderState.TRADE_BUYER_PAID.value, TeamOrder.refund_state == TeamOrder.OrderRefundState.NO_REFUND.value).execute() # 修改场次状态为已结算 Activity.update(state=Activity.ActivityState.finished, finished=datetime.now(), online_paid_amount=online_paid_amount, credit_paid_amount=credit_paid_amount, free_times_amount=free_times_amount).where( Activity.id == activity_id).execute() # 记录俱乐部账户变更 TeamAccountLog.create(team_id=team.id, credit_change=online_paid_amount, change_type=0, credit_before=team.credit, credit_after=team.credit + online_paid_amount, note="活动结算:%s(%s)" % (activity.title, activity.start_time), activity_id=activity_id, operator_id=0) # 生成下期活动 gen_next_activity(activity_id)