Пример #1
0
 def find_by_date(botid, target_type, target_account, member_id, date_from,
                  date_to):
     target = get_target_composevalue(target_type, target_account)
     return Sign.query.filter(Sign.botid == botid, Sign.target == target,
                              Sign.member_id == member_id,
                              Sign.date >= date_from,
                              Sign.date <= date_to).all()
Пример #2
0
 def get_report_status(botid, target_type, target_account, reporter_id, ):
     target = get_target_composevalue(target_type, target_account)
     result = Point.get_report_count(botid, target, '0', reporter_id, output_datetime(get_now(), True, False))
     status = {}
     status['botid'] = botid
     status['target'] = target
     status['reporter_id'] = reporter_id
     status['reporter_confirmed_total'] = result.reporter_confirmed_total
     status['reporter_unconfirm_total'] = result.reporter_unconfirm_total
     return status
Пример #3
0
 def create(botid, target_type, target_account, point_id, member_id, confirm_code):
     PointConfirm.clear(botid, target_type, target_account)
     target = get_target_composevalue(target_type, target_account)
     record = PointConfirm(botid = botid,
                           target = target,
                           point_id = point_id,
                           member_id = member_id,
                           confirm_code = confirm_code)
     PointConfirm.query.session.add(record)
     PointConfirm.query.session.commit()
     return record
Пример #4
0
 def confirm(botid, target_type, target_account, member_id, confirm_code, is_newbie: bool = False):
     PointConfirm.clear(botid, target_type, target_account)
     target = get_target_composevalue(target_type, target_account)
     records = PointConfirm.query.filter(PointConfirm.botid == botid,
                                         PointConfirm.target == target,
                                         PointConfirm.member_id == member_id,
                                         PointConfirm.confirm_code == confirm_code).all()
     if len(records) > 0:
         # for record in records:
         record = records[0]
         point = Point.confirm(record.point_id, is_newbie)
         PointConfirm.query.session.delete(record)
         PointConfirm.query.session.commit()
         return point
     else:
         raise Exception('确认码[' + confirm_code + ']无效,请检查是否已经过期')
Пример #5
0
    def create(botid, target_type, target_account, member_id, reporter_id, point: int, message, is_newbie: bool = False,
               **kwargs):
        target = get_target_composevalue(target_type, target_account)

        Point.check_limit(botid, target, member_id, reporter_id, point, get_now().strftime('%Y-%m-%d'), is_newbie)

        record = Point(botid = botid,
                       target = target,
                       member_id = member_id,
                       member_name = '' if kwargs.get('member_name') is None else kwargs.get('member_name'),
                       reporter_id = reporter_id,
                       reporter_name = '' if kwargs.get('reporter_name') is None else kwargs.get('reporter_name'),
                       point = point,
                       is_newbie = 1 if is_newbie else 0,
                       message = message)
        record.query.session.add(record)
        record.query.session.commit()
        return PointConfirm.create(botid, target_type, target_account, record.id, record.member_id, record.confirm_code)
Пример #6
0
    def get_count(botid,
                  target_type,
                  target_account,
                  date_from,
                  date_to,
                  member=None):
        target = get_target_composevalue(target_type, target_account)

        if member is None:
            member_id = None
        elif not member.isdigit():
            record = Sign.find_first_by_member_name(member)
            member_id = record.member_id
        else:
            member_id = member

        return Sign.query.session.query(func.sum(1).label('cnt')).filter(
            Sign.botid == botid, Sign.target == target, Sign.date >= date_from,
            Sign.date <= date_to, Sign.member_id == member_id
            if member_id is not None else 1 == 1).first()
Пример #7
0
    def get_total(botid, target_type, target_account, date_from, date_to, member = None):
        target = get_target_composevalue(target_type, target_account)

        if member is None:
            member_id = None
        elif not member.isdigit():
            record = Point.find_first_by_member_name(member)
            member_id = record.member_id
        else:
            member_id = member

        return Point.query.session.query(
            func.sum(Point.point).label('total_full'),
            func.sum(case([(Point.has_confirmed == 1 , Point.point)], else_ = 0)).label('total_success'),
        ).filter(
            Point.botid == botid,
            Point.target == target,
            Point.date >= date_from,
            Point.date <= date_to,
            Point.member_id == member_id if member_id is not None else 1 == 1
        ).first()
Пример #8
0
    def create(botid, target_type, target_account, member_id, message,
               **kwargs):
        sign = Sign.find_by_date(
            botid,
            target_type,
            target_account,
            member_id,
            get_now().strftime('%Y-%m-%d'),
            get_now().strftime('%Y-%m-%d'),
        )
        if len(sign) > 0:
            raise Exception(member_id + ':' +
                            ('' if kwargs.get('member_name') is None else
                             kwargs.get('member_name')) + '今天已经签过到了')

        target = get_target_composevalue(target_type, target_account)
        record = Sign(
            botid=botid,
            target=target,
            member_id=member_id,
            member_name='' if kwargs.get('member_name') is None else
            kwargs.get('member_name'),
            # date = datetime.now(tz = timezone('Asia/Shanghai')).strftime('%Y-%m-%d') if kwargs.get(
            #     'date') is None else kwargs.get('date'),
            # time = datetime.now(tz = timezone('Asia/Shanghai')).strftime('%H:%M') if kwargs.get(
            #     'time') is None else kwargs.get('time'),
            # timemark = int(datetime.now(tz = utc).timestamp()) if kwargs.get(
            #     'timemark') is None else kwargs.get('timemark'),
            message=message)
        record.query.session.add(record)
        record.query.session.commit()
        sign_code = BotParam.find(botid, 'sign_code')
        if sign_code is not None:
            ScoreRecord.create_change(sign_code.value,
                                      member_id,
                                      member_name=kwargs.get('member_name'),
                                      botid=botid)

        return record
Пример #9
0
 def on_model_change(self, form, model, is_created):
     model.target = get_target_composevalue(form.target_type.data,
                                            form.target_account.data)
Пример #10
0
 def clear(botid, target_type, target_account):
     target = get_target_composevalue(target_type, target_account)
     PointConfirm.query.filter(PointConfirm.botid == botid,
                               PointConfirm.target == target,
                               PointConfirm.expire_at <= get_now()).delete()
     PointConfirm.query.session.commit()
Пример #11
0
 def find_by_target(botid, target_type, target_account):
     target = get_target_composevalue(target_type, target_account)
     return ScoreAccount.query.filter_by(botid=botid, target=target).all()