예제 #1
0
def test_get_verification_code():
    """
    获取手机验证码
    :return:
    """
    now = datetime.now()
    res = ResMsg()

    category = request.args.get("category", None)
    # category 参数如下:
    # authentication: 身份验证
    # login_confirmation: 登陆验证
    # login_exception: 登陆异常
    # user_registration: 用户注册
    # change_password: 修改密码
    # information_change: 信息修改

    phone = request.args.get('phone', None)

    # 验证手机号码正确性
    re_phone = PhoneTool.check_phone(phone)
    if phone is None or re_phone is None:
        res.update(code=ResponseCode.MobileNumberError)
        return res.data
    if category is None:
        res.update(code=ResponseCode.InvalidParameter)
        return res.data

    try:
        # 获取手机验证码设置时间
        flag = Redis.hget(re_phone, 'expire_time')
        if flag is not None:
            flag = datetime.strptime(flag, '%Y-%m-%d %H:%M:%S')
            # 判断是否重复操作
            if (flag - now).total_seconds() < 60:
                res.update(code=ResponseCode.FrequentOperation)
                return res.data

        # 获取随机验证码
        code = "".join([str(random.randint(0, 9)) for _ in range(6)])
        template_param = {"code": code}
        # 发送验证码
        sms = SendSms(phone=re_phone,
                      category=category,
                      template_param=template_param)
        sms.send_sms()
        # 将验证码存入redis,方便接下来的验证
        Redis.hset(re_phone, "code", code)
        # 设置重复操作屏障
        Redis.hset(re_phone, "expire_time",
                   (now + timedelta(minutes=1)).strftime('%Y-%m-%d %H:%M:%S'))
        # 设置验证码过去时间
        Redis.expire(re_phone, 60 * 3)
        return res.data
    except Exception as e:
        logger.exception(e)
        res.update(code=ResponseCode.Fail)
        return res.data
예제 #2
0
def handle_gen_blacklist():
    """
    设置黑名单用户 blacklists列表 到redis集合
    :@param: phone 如果设置phone,则在set中新增一个phone
    :return: json
    """
    res = ResMsg()
    phone = request.args.get("phone", '')

    if phone:
        p.sadd(blacklist_key, phone)

    blacklist = db.session.execute(
        "SELECT phone FROM et_blacklists").fetchall()

    counts = db.session.execute("SELECT count(*) FROM et_blacklists").first()
    res_data = dict()
    blacklists = [{key: value
                   for (key, value) in row.items()} for row in blacklist]

    # pipeline multi-set

    r = Redis._get_r()
    with r.pipeline(transaction=False) as p:
        for value in blacklists:
            p.sadd(blacklist_key, value['phone'])
        p.execute()

    Redis.expire(blacklist_key, 60 * 60 * 10 * 90)

    if blacklist:
        # res_data['list'] =  blacklists
        res_data['length'] = counts[0]
        res.update(code=ResponseCode.Success,
                   data=res_data,
                   msg='app用户blacklist列表获取成功')
        return res.data
    else:

        res.update(code=ResponseCode.Success,
                   data={},
                   msg='app用户blacklist数据为空or异常')
        return res.data
예제 #3
0
def handle_verifytaskorder():
    """
    用户提交任务审核接口(交单)
    @todo 审核流程优化
    :return: json
    """
    res = ResMsg()
    req = request.get_json(force=True)
    
    taskorder_id= int(req.get("id", 1))
    status= int(req.get("status", 1))
    verify_log = req.get("verify_log", '')

    account_name= session.get("user_name")

    if not account_name:
        res.update(code=ResponseCode.Success, data={},msg=f'账户{account_name}数据异常')
        return res.data
    
    user = db.session.query(EtAccount.id).filter(EtAccount.name == account_name).first()
    
    if not status:
        res.update(code=ResponseCode.Success, data={},msg='未提交审核数据,操作已经撤销')
        return res.data

    update_dict = {
        "status": status,
        "account_id": user.id,
        "verify_log":verify_log
    }
    task_order= db.session.query(EtTaskOrder.id,EtTaskOrder.task_id,EtTaskOrder.member_id).filter(EtTaskOrder.id == taskorder_id).first()
    
    user = db.session.query(EtMember.id, EtMember.nickname, EtMember.status, EtMember.m_class, EtMember.realname, EtMember.mobile, EtMember.IIUV,EtMember.balance,EtMember.balance_version, EtMember.setreal, EtMember.alipayid).filter(EtMember.id == EtTaskOrder.member_id).first()
    user_info = (dict(zip(user.keys(), user)))

    if task_order:

        db.session.query(EtTaskOrder).filter(EtTaskOrder.id == taskorder_id).update(update_dict)
        task_order_dict= dict(zip(task_order.keys(), task_order))
        
        if status == 4:

            up_sql= f"UPDATE et_tasks SET tasks_fulfil = tasks_fulfil+1 WHERE id ={task_order_dict['task_id']}"
            up_num= db.session.execute(up_sql)

        try:


            db.session.commit()
            res_data= dict()
            
            res_data.update(task_order_dict)
            
            u_task_key=f"user_tasks_:{task_order_dict['member_id']}"
            Redis.delete(u_task_key)

            if status == 5:
                Redis.sadd(f"{task_complete_key}{task_order.task_id}", task_order.member_id)
                
                Redis.sadd(f"{complete_tasks_uid_key}{task_order.member_id}", task_order.task_id)
                
                Redis.expire(f"{task_complete_key}{task_order.task_id}", 60 * 60 * 10)
                res.update(code=ResponseCode.Success, data={}, msg='该单未通过审核')
            
            if status == 4:
                task_limit=20
                counts = db.session.execute(f"SELECT count(id) FROM et_task_orders WHERE status=4 AND member_id={task_order_dict['member_id']}").first()
                
                # update member status 2
                if int(counts[0]) == task_limit:
                    update_dict = {
                        "m_class": 2,
                    }
                    update_dict_ready = helpers.rmnullkeys( update_dict )
                    db.session.query(EtMember).filter(EtMember.id == memberid).update(update_dict_ready)
                    try:
                        db.session.commit()
                        
                        Redis.delete(user_center_key + str(user_info['id']))
                        Redis.delete(user_info_key + str(user_info['mobile']))

                    except Exception as why:
                        res.update(code=ResponseCode.Success, data={}, msg=f'修改失败,请稍后再试{why}')
                        return res.data

                Redis.sadd(f"{task_verifyed_key}{task_order.task_id}", task_order.member_id)
                Redis.expire(f"{task_verifyed_key}{task_order.task_id}", 60 * 60 * 10)
                
                Redis.sadd(f"{task_complete_key}{task_order.task_id}", task_order.member_id)
                Redis.expire(f"{task_complete_key}{task_order.task_id}", 60 * 60 * 10)
                
                calculating_earnings(task_order_dict, task_order.task_id, type_set=1 )
                
                res.update(code=ResponseCode.Success, data=res_data, msg=f'任务订单审核成功,对该用户发放收益')
            
            update_dict_com = {
                "status": 4,
                "account_id": user.id,
                "verify_log":verify_log
            }

            db.session.query(EtTaskOrder).filter(EtTaskOrder.id == taskorder_id).update(update_dict_com)

            return res.data
        except Exception as why:

            res.update(code=ResponseCode.Success, data={},msg=f'任务订单审核失败,{why}')
            return res.data