Exemple #1
0
 def delete(self):
     try:
         parser = reqparse.RequestParser()
         parser.add_argument('name', required=True, help='请求中必须包含name')
         args = parser.parse_args()
         result = BotParam.delete(ac.get_bot(), args['name'])
         if result:
             return ac.success(botid=ac.get_bot(), name=args['name'])
         else:
             return ac.fault(error=Exception('未知原因导致数据删除失败'))
     except Exception as e:
         return ac.fault(error=e)
Exemple #2
0
def delete_targetrule(type, target_type):
    try:
        parser = reqparse.RequestParser()
        parser.add_argument('account', required=True, help='请求中必须包含account')
        args = parser.parse_args()
        result = TargetRule.delete(ac.get_bot(), type,
                                   target_type + '#' + args['account'])
        if result:
            return ac.success(botid=ac.get_bot(),
                              type=type,
                              target=target_type + '#' + args['account'])
        else:
            return ac.fault(error=Exception('未知原因导致数据删除失败'))
    except Exception as e:
        return ac.fault(error=e)
Exemple #3
0
 def patch(self):
     try:
         parser = reqparse.RequestParser()
         parser.add_argument('target_type', required = True, help = '请求中必须包含target_type')
         parser.add_argument('target_account', required = True, help = '请求中必须包含target_account')
         parser.add_argument('member_id', required = True, help = '请求中必须包含member_id')
         parser.add_argument('confirm_code', required = True, help = '请求中必须包含confirm_code')
         parser.add_argument('is_newbie', type = bool)
         args = parser.parse_args()
         kwargs = {}
         if args['is_newbie'] is not None: kwargs['is_newbie'] = args['is_newbie']
         record = PointConfirm.confirm(ac.get_bot(),
                                       args['target_type'],
                                       args['target_account'],
                                       args['member_id'],
                                       args['confirm_code'],
                                       **kwargs)
         if record is not None:
             return ac.success(botid = record.botid,
                               target = record.target,
                               reporter_id = record.reporter_id,
                               reporter_name = record.reporter_name,
                               member_id = record.member_id,
                               member_name = record.member_name,
                               point = record.point,
                               has_confirmed = record.has_confirmed)
         else:
             return ac.fault(error = Exception('未知原因导致数据创建失败'))
     except Exception as e:
         return ac.fault(error = e)
Exemple #4
0
 def put(self):
     try:
         result = BotParam.init(ac.get_bot())
         if result:
             return ac.success(result='数据初始化成功')
         else:
             return ac.fault(error=Exception('未知原因导致数据初始化失败'))
     except Exception as e:
         return ac.fault(error=e)
Exemple #5
0
 def get(self):
     try:
         parser = reqparse.RequestParser()
         parser.add_argument('name', required=True, help='请求中必须包含name')
         args = parser.parse_args()
         param = BotParam.find(ac.get_bot(), args['name'])
         if param:
             return ac.success(
                 botid=param.botid,
                 name=param.name,
                 value=param.value,
                 create_at=param.create_at.strftime('%Y-%m-%d %H:%M'),
                 update_at=param.update_at.strftime('%Y-%m-%d %H:%M'),
                 remark=param.remark)
         else:
             return ac.fault(error=Exception(ac.get_bot() + '未找到名称为' +
                                             args['name'] + '的参数'))
     except Exception as e:
         return ac.fault(error=e)
Exemple #6
0
def get_targetrule(type, target_type):
    try:
        parser = reqparse.RequestParser()
        parser.add_argument('account', required=True, help='请求中必须包含account')
        args = parser.parse_args()
        rule = TargetRule.find(ac.get_bot(), type,
                               target_type + '#' + args['account'])
        if rule:
            return ac.success(
                botid=rule.botid,
                type=rule.type,
                target=rule.target,
                create_at=rule.create_at.strftime('%Y-%m-%d %H:%M'),
                update_at=rule.update_at.strftime('%Y-%m-%d %H:%M'),
                remark=rule.remark)
        else:
            return ac.fault(
                error=Exception(ac.get_bot() + '未找到目标为' + target_type + '#' +
                                args['account'] + '的' + type + '规则'))
    except Exception as e:
        return ac.fault(error=e)
Exemple #7
0
    def post(self):
        try:
            parser = reqparse.RequestParser()
            parser.add_argument('biz_type',
                                required=True,
                                help='请求中必须包含biz_type')
            parser.add_argument('outgo_member_id',
                                required=True,
                                help='请求中必须包含outgo_member_id')
            parser.add_argument('income_member_id',
                                required=True,
                                help='请求中必须包含income_member_id')
            parser.add_argument('amount',
                                type=int,
                                required=True,
                                help='请求中必须包含amount')
            parser.add_argument('account')
            parser.add_argument('outgo_member_name')
            parser.add_argument('income_member_name')
            parser.add_argument('remark')
            args = parser.parse_args()
            if args['amount'] <= 0:
                return ac.fault(error=Exception('amount必须大于0'))

            record = ScoreRecord.create_transfer(
                args['biz_type'],
                args['outgo_member_id'],
                args['income_member_id'],
                args['amount'],
                args['account'],
                outgo_member_name=args['outgo_member_name'],
                income_member_name=args['income_member_name'],
                remark=args['remark'],
                botid=ac.get_bot())
            if record is not None:
                return ac.success(
                    account=record.account,
                    biz_type=record.biz_type,
                    trans_type=record.trans_type,
                    outgo_member_id=args['outgo_member_id'],
                    outgo_member_name=args['outgo_member_name'],
                    income_member_id=args['income_member_id'],
                    income_member_name=args['income_member_name'],
                    amount=record.amount,
                    date=output_datetime(record.date),
                    time=output_datetime(record.time),
                    create_at=output_datetime(record.create_at),
                    remark=args['remark'])
            else:
                return ac.fault(error=Exception('未知原因导致数据创建失败'))
        except Exception as e:
            return ac.fault(error=e)
Exemple #8
0
    def get(self):
        try:
            parser = reqparse.RequestParser()
            parser.add_argument('target_type', required = True, help = '请求中必须包含target_type')
            parser.add_argument('target_account', required = True, help = '请求中必须包含target_account')
            parser.add_argument('reporter_id', required = True, help = '请求中必须包含reporter_id')
            args = parser.parse_args()

            record = Point.get_report_status(ac.get_bot(),
                                             args['target_type'],
                                             args['target_account'],
                                             args['reporter_id'])
            if record is not None:
                return ac.success(status = record)
            else:
                return ac.fault(error = Exception('未知原因导致数据创建失败'))
        except Exception as e:
            return ac.fault(error = e)
Exemple #9
0
def put_targetlist(type, target_type):
    try:
        parser = reqparse.RequestParser()
        parser.add_argument('account', required=True, help='请求中必须包含account')
        parser.add_argument('remark')
        args = parser.parse_args()
        rule = TargetRule.create(ac.get_bot(), type,
                                 target_type + '#' + args['account'],
                                 args['remark'])
        if rule:
            return ac.success(
                botid=rule.botid,
                type=rule.type,
                target=rule.target,
                create_at=rule.create_at.strftime('%Y-%m-%d %H:%M'),
                update_at=rule.update_at.strftime('%Y-%m-%d %H:%M'),
                remark=rule.remark)
        else:
            return ac.fault(error=Exception('未知原因导致数据创建失败'))
    except Exception as e:
        return ac.fault(error=e)
Exemple #10
0
def get_targetrules(type):
    try:
        rules = TargetRule.findall(ac.get_bot(), type)
        result = []
        for rule in rules:
            result.append({
                'botid':
                rule.botid,
                'type':
                rule.type,
                'target':
                rule.target,
                'create_at':
                rule.create_at.strftime('%Y-%m-%d %H:%M'),
                'update_at':
                rule.update_at.strftime('%Y-%m-%d %H:%M'),
                'remark':
                rule.remark
            })
        return ac.success(params=result)
    except Exception as e:
        return ac.fault(error=e)
Exemple #11
0
 def get(self):
     try:
         params = BotParam.findall(ac.get_bot())
         result = []
         for param in params:
             result.append({
                 'botid':
                 param.botid,
                 'name':
                 param.name,
                 'value':
                 param.value,
                 'create_at':
                 param.create_at.strftime('%Y-%m-%d %H:%M'),
                 'update_at':
                 param.update_at.strftime('%Y-%m-%d %H:%M'),
                 'remark':
                 param.remark
             })
         return ac.success(params=result)
     except Exception as e:
         return ac.fault(error=e)
Exemple #12
0
 def post(self):
     try:
         parser = reqparse.RequestParser()
         parser.add_argument('target_type', required = True, help = '请求中必须包含target_type')
         parser.add_argument('target_account', required = True, help = '请求中必须包含target_account')
         parser.add_argument('member_id', required = True, help = '请求中必须包含member_id')
         parser.add_argument('member_name')
         parser.add_argument('reporter_id', required = True, help = '请求中必须包含reporter_id')
         parser.add_argument('reporter_name')
         parser.add_argument('point', type = int, required = True, choices = (1, 2), help = '请求中必须包含point,且只能为1或2')
         parser.add_argument('message', required = True, help = '请求中必须包含message')
         parser.add_argument('is_newbie', type = bool)
         args = parser.parse_args()
         kwargs = {}
         kwargs['member_name'] = args['member_name']
         kwargs['reporter_name'] = args['reporter_name']
         if args['is_newbie'] is not None: kwargs['is_newbie'] = args['is_newbie']
         record = Point.create(ac.get_bot(),
                               args['target_type'],
                               args['target_account'],
                               args['member_id'],
                               args['reporter_id'],
                               args['point'],
                               args['message'],
                               **kwargs)
         if record is not None:
             return ac.success(botid = record.botid,
                               target = record.target,
                               reporter_id = args['reporter_id'],
                               reporter_name = args['reporter_name'],
                               member_id = args['member_id'],
                               member_name = args['member_name'],
                               point = args['point'],
                               confirm_code = record.confirm_code,
                               expire_at = output_datetime(record.expire_at))
         else:
             return ac.fault(error = Exception('未知原因导致数据创建失败'))
     except Exception as e:
         return ac.fault(error = e)
Exemple #13
0
    def post(self):
        try:
            parser = reqparse.RequestParser()
            parser.add_argument('biz_type',
                                required=True,
                                help='请求中必须包含biz_type')
            parser.add_argument('member_id',
                                required=True,
                                help='请求中必须包含member_id')
            parser.add_argument('amount', type=int)
            parser.add_argument('account')
            parser.add_argument('member_name')
            parser.add_argument('remark')
            args = parser.parse_args()

            record = ScoreRecord.create_change(args['biz_type'],
                                               args['member_id'],
                                               args['amount'],
                                               args['account'],
                                               member_name=args['member_name'],
                                               remark=args['remark'],
                                               botid=ac.get_bot())
            if record is not None:
                return ac.success(account=record.account,
                                  trans_type=record.trans_type,
                                  biz_type=record.biz_type,
                                  member_id=record.member_id,
                                  member_name=record.member_name,
                                  amount=record.amount,
                                  date=output_datetime(record.date),
                                  time=output_datetime(record.time),
                                  create_at=output_datetime(record.create_at),
                                  remark=record.remark)
            else:
                return ac.fault(error=Exception('未知原因导致数据创建失败'))
        except Exception as e:
            return ac.fault(error=e)
Exemple #14
0
 def post(self):
     try:
         parser = reqparse.RequestParser()
         parser.add_argument('target_type',
                             required=True,
                             help='请求中必须包含target_type')
         parser.add_argument('target_account',
                             required=True,
                             help='请求中必须包含target_account')
         parser.add_argument('member_id',
                             required=True,
                             help='请求中必须包含member_id')
         parser.add_argument('member_name')
         parser.add_argument('message',
                             required=True,
                             help='请求中必须包含message')
         args = parser.parse_args()
         record = Sign.create(ac.get_bot(),
                              args['target_type'],
                              args['target_account'],
                              args['member_id'],
                              args['message'],
                              member_name=args['member_name'])
         if record is not None:
             return ac.success(botid=record.botid,
                               target=record.target,
                               member_id=record.member_id,
                               member_name=record.member_name,
                               date=output_datetime(record.date),
                               time=output_datetime(record.time),
                               create_at=output_datetime(record.create_at),
                               message=record.message)
         else:
             return ac.fault(error=Exception('未知原因导致数据创建失败'))
     except Exception as e:
         return ac.fault(error=e)