コード例 #1
0
ファイル: oem_service.py プロジェクト: FreeGodCode/easytask
def editmer():
    """
    商户信息修改接口
    :return: json
    """
    res = ResMsg()
    req = request.get_json(force=True)

    mer_id = req.get("mer_id")
    password = req.get("password")
    password_hash = hash_password(password)

    update_dict = {
        "password": password_hash,
    }
    update_dict_ready = helpers.rmnullkeys(update_dict)
    user = db.session.query(ETMerchants).filter(
        ETMerchants.id == mer_id).first()

    if user:
        db.session.query(ETMerchants).filter(
            ETMerchants.id == mer_id).update(update_dict_ready)
        try:
            db.session.commit()
            res.update(code=ResponseCode.Success, data={}, msg="修改成功")
            return res.data
        except Exception as why:
            res.update(code=ResponseCode.Success,
                       data={},
                       msg=f"修改失败,请稍后再试{why}")
            return res.data
    else:
        res.update(code=ResponseCode.Success, data={}, msg=f"修改失败,请稍后再试")
        return res.data
コード例 #2
0
ファイル: task_service.py プロジェクト: FreeGodCode/easytask
def handle_sorttask():
    """
    任务推荐排序
    :return: json
    """
    res = ResMsg()
    req = request.get_json(force=True)
    
    taskid= int(req.get("id", 1))
    recommend= int(req.get("recommend", 3))

    update_dict = {
        "recommend": recommend,
    }
    update_dict_ready = helpers.rmnullkeys( update_dict )
    db.session.query(EtTask).filter(EtTask.id == taskid).update(update_dict_ready)
    try:
        db.session.commit()
        res_data= dict()
        res.update(code=ResponseCode.Success, data=res_data, msg=f'任务排序成功')
        return res.data
    except Exception as why:

        res.update(code=ResponseCode.Success, data={},msg=f'排序失败,数据异常{why}')
        return res.data
コード例 #3
0
ファイル: task_service.py プロジェクト: FreeGodCode/easytask
def handle_verifytask():
    """
    新增任务审核
    :return: json
    """
    res = ResMsg()
    req = request.get_json(force=True)
    
    taskid= int(req.get("id", 1))
    status= int(req.get("status", 2))

    update_dict = {
        "status": status,
        "check_time": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    }
    update_dict_ready = helpers.rmnullkeys( update_dict )
    db.session.query(EtTask).filter(EtTask.id == taskid).update(update_dict_ready)
    try:
        db.session.commit()
        
        Redis.delete(task_info_key)
        Redis.delete(task_detail_key+str(taskid))

        res_data= dict()
        res.update(code=ResponseCode.Success, data=res_data, msg=f'任务状态变更成功')
        return res.data
    except Exception as why:

        res.update(code=ResponseCode.Success, data={},msg=f'修改失败,数据异常{why}')
        return res.data
コード例 #4
0
def handle_configs():
    """
    获取系统信息接口
    :return: json
    """
    res = ResMsg()
    id = request.args.get("id", 1)
    sysid = 1
    sys_configs = db.session.query(EtGlobalConfig).filter(
        EtGlobalConfig.id == sysid).first()
    res_data = dict()
    if sys_configs:
        res_data['data'] = helpers.model_to_dict(sys_configs)
        # logger.error(Redis.hgetall(redis_key_sys))
        if Redis.hgetall(redis_key_sys) == {}:
            del res_data['data']['update_time']
            cache_data = helpers.rmnullkeys(res_data['data'])
            logger.error(res_data['data'])
            ret = Redis.hmset(redis_key_sys, cache_data)
            logger.error(ret)

        res.update(code=ResponseCode.Success, data=res_data, msg='系统信息获取成功')
        return res.data
    else:

        res.update(code=ResponseCode.Success, data={}, msg='系统信息数据异常')
        return res.data
コード例 #5
0
ファイル: task_service.py プロジェクト: FreeGodCode/easytask
def handle_deltask():
    """
    任务软删除
    :return: json
    """
    res = ResMsg()
    req = request.get_json(force=True)
    
    taskid= int(req.get("id", 1))
    status= int(req.get("status", 3))

    update_dict = {
        "status": status,
    }
    update_dict_ready = helpers.rmnullkeys( update_dict )
    db.session.query(EtTask).filter(EtTask.id == taskid).update(update_dict_ready)
    try:
        db.session.commit()

        Redis.delete(task_info_key)
        Redis.delete(task_detail_key+str(taskid))

        res_data= dict()
        res.update(code=ResponseCode.Success, data=res_data, msg=f'任务删除成功')
        return res.data
    except Exception as why:

        res.update(code=ResponseCode.Success, data={},msg=f'修改失败,数据异常{why}')
        return res.data
コード例 #6
0
def handle_edit_appconfigs():
    """
    编辑当前平台绑定app信息
    :return: json
    """
    res = ResMsg()
    req = request.get_json(force=True)
    now_timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    cur_version = req.get("cur_version", 'tasktest1')
    update_status = int(req.get("update_status", 1))

    account_name = session.get("user_name")
    update_dict = {
        "cur_version": cur_version,
        "update_status": update_status,
        "update_time": now_timestr,
    }

    update_dict_ready = helpers.rmnullkeys(update_dict)
    db.session.query(EtAppConfig).filter().update(update_dict_ready)
    try:
        db.session.commit()
        res_data = dict()
        res.update(code=ResponseCode.Success, data=res_data, msg=f'绑定APP成功')
        return res.data
    except Exception as why:

        res.update(code=ResponseCode.Success,
                   data={},
                   msg=f'绑定app失败,数据异常{why}')
        return res.data
コード例 #7
0
def handle_banuser():
    """
    封禁用户
    :return: json 
    """
    res = ResMsg()
    req = request.get_json(force=True)

    memberid = req.get("id")
    status = req.get("status")

    update_dict = {
        "status": status,
    }
    update_dict_ready = helpers.rmnullkeys(update_dict)
    user = db.session.query(EtMember).filter(EtMember.id == memberid).first()

    if user:
        db.session.query(EtMember).filter(EtMember.id == memberid).update(update_dict_ready)
        try:
            db.session.commit()
            Redis.delete(user_center_key + str(user.id))
            Redis.delete(user_info_key + str(user.mobile))
            Redis.lpush(balck_list_key, user.mobile)
            res.update(code=ResponseCode.Success, data={}, msg='完成封禁用户')
            return res.data
        except Exception as why:
            res.update(code=ResponseCode.Success, data={}, msg=f'修改失败,请稍后再试{why}')
            return res.data
    else:
        res.update(code=ResponseCode.Success, data={}, msg='修改失败,请稍后再试')
        return res.data
コード例 #8
0
ファイル: oem_service.py プロジェクト: FreeGodCode/easytask
def ban_mer():
    """
    封禁商户
    :return json
    """
    res = ResMsg()
    req = request.get_json(force=True)

    mer_id = req.get("id")
    status = req.get("status")

    update_dict = {'status': status}
    update_dict_ready = helpers.rmnullkeys(update_dict)
    user = db.session.query(ETMerchants).filter(
        ETMerchants.id == mer_id).first()
    if user:
        db.session.query(ETMerchants).filter(
            ETMerchants.id == mer_id).update(update_dict_ready)
        try:
            db.session.commit()
            res.update(code=ResponseCode.Success, data={}, msg="完成封禁用户")
            return res.data
        except Exception as why:
            res.update(code=ResponseCode.Success,
                       data={},
                       msg=f"修改失败,请稍后再试{why}")
            return res.data
コード例 #9
0
def handle_drpconfig_edit():
    """
    分销设置修改接口
    :return: json 
    """
    res = ResMsg()
    req = request.get_json(force=True)
    now_timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    sysid = 1

    drp_layers = req.get("drp_layers", 1)
    profit_percentage = req.get("profit_percentage", '')
    need_setreal = req.get("need_setreal", 1)
    daily_max = int(req.get("daily_max", 1))
    handling_fee = req.get("handling_fee", 1)
    min_money = int(req.get("min_money", 1))
    withdrawal_condition = req.get("withdrawal_condition", '')
    daily_withdrawal = req.get("daily_withdrawal", 9)

    update_dict = {
        "drp_layers": drp_layers,
        "profit_percentage": profit_percentage,
        "need_setreal": need_setreal,
        "daily_max": daily_max,
        "handling_fee": handling_fee,
        "min_money": min_money,
        "withdrawal_condition": withdrawal_condition,
        "daily_withdrawal": daily_withdrawal,
        "update_time": now_timestr
    }
    update_dict_ready = helpers.rmnullkeys(update_dict)
    drpconfigs = db.session.query(EtDrpConfig).filter(
        EtDrpConfig.id == sysid).first()

    if drpconfigs:
        db.session.query(EtDrpConfig).filter(
            EtDrpConfig.id == sysid).update(update_dict_ready)
        try:
            db.session.commit()
            Redis.delete(redis_key_drp)

            r_data = helpers.model_to_dict(drpconfigs)
            del r_data['update_time']
            Redis.hmset(redis_key_drp, r_data)

            res.update(code=ResponseCode.Success, data={}, msg=f'分销设置配置成功')
            return res.data

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

        return res.data
コード例 #10
0
def handle_memdrplists():
    """
    用户分销总收益列表接口
    @todo 根据索引优化sql查询
    :return: json
    """
    res = ResMsg()
    now_timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    page_index = int(request.args.get("page", 1))
    page_size = int(request.args.get("limit", 10))
    start_time = request.args.get("tstart", '')
    end_time = request.args.get("end", '')

    query_dict = {}
    filters = helpers.rmnullkeys(query_dict)

    flatten_filters = 'and '.join("{!s}={!r}".format(key, val)
                                  for (key, val) in filters.items())

    if flatten_filters:
        where_cond = f"WHERE {flatten_filters} "

        if start_time and end_time:
            where_cond += f" AND add_time>'{start_time}' AND add_time<='{end_time}' "
    else:
        where_cond = "WHERE DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(add_time) "
        if start_time and end_time:
            where_cond = f" WHERE add_time>'{start_time}' or add_time<='{end_time}' "

    fetch_columns = "d.amounts,m.nickname,m.IIUV,m.m_class,m.alipay_id,m.mobile,m.realname,m.status as mstatus,m.reg_time"

    p_i, p_num = (page_index - 1) * page_size, page_size

    drp_sql = f"SELECT {fetch_columns} FROM (SELECT sum(amounts) as amounts,member_id FROM et_member_drps {where_cond} GROUP BY(member_id) ) AS d LEFT JOIN et_members AS m ON d.member_id =m.id LIMIT {p_i},{p_num};"

    count_drp_sql = f"SELECT {fetch_columns} FROM (SELECT sum(amounts) as amounts,member_id FROM et_member_drps {where_cond} GROUP BY(member_id) ) AS d LEFT JOIN et_members AS m ON d.member_id =m.id;"

    member_drplist = db.session.execute(drp_sql).fetchall()
    count_member_drplist = db.session.execute(count_drp_sql).fetchall()

    res_data = dict()

    counts = db.session.execute("SELECT count(*) FROM et_member_drps").first()
    if member_drplist:
        res_data['list'] = [{k: v
                             for (k, v) in row.items()}
                            for row in member_drplist]
        res_data['length'] = len(count_member_drplist)
        res.update(code=ResponseCode.Success,
                   data=res_data,
                   msg='用户分销收益列表数据获取成功')
        return res.data
    else:

        res.update(code=ResponseCode.Success, data={}, msg='用户收益数据异常')
        return res.data
コード例 #11
0
def handle_add_act():
    """
    新增活动接口
    :return: json
    """
    res = ResMsg()
    req = request.get_json(force=True)
    now_timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    act_name = req.get("act_name", 'tasktest1')
    act_type = int(req.get("act_type", 1))
    status = req.get("status", 1)
    create_time = req.get("create_time", now_timestr)

    round_num = req.get("round_num", '')
    limits = req.get("limits", 10)
    act_duration = req.get("act_duration", 2)
    rules = req.get("rules", '')

    update_dict = {
        "act_name": act_name,
        "act_type": act_type,
        "status": status,
        "create_time": create_time,
        "round_num": round_num,
        "act_duration": act_duration,
        "rules": rules,
    }
    update_dict_ready = helpers.rmnullkeys(update_dict)

    new_act = EtActivity(**update_dict_ready)
    db.session.add(new_act)
    try:
        db.session.commit()
        act_id = new_act.id
        config = {"page_show": limits}
        configs = json.dumps(config)
        insert_sql = f"INSERT INTO et_activity_configs (act_id, act_configs) VALUES ({act_id}, '{configs}')"
        db.session.execute(insert_sql)
        db.session.commit()
        res_data = dict()
        res.update(code=ResponseCode.Success, data=res_data, msg=f'新增活动成功')
        return res.data
    except Exception as why:

        res.update(code=ResponseCode.Success, data={}, msg=f'活动数据异常{why}')
        return res.data
コード例 #12
0
def handle_edit_act():
    """
    活动修改编辑接口
    :return: json
    """
    res = ResMsg()
    req = request.get_json(force=True)
    act_id = req.get("id", 1)
    now_timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    act_name = req.get("name", '')
    act_type = req.get("act_type", '')
    status = req.get("status", '')
    create_time = req.get("create_time", now_timestr)

    round_num = req.get("round_num", '')
    act_duration = req.get("act_duration", 2)
    rules = req.get("rules", '')

    update_dict = {
        "act_name": act_name,
        "act_type": act_type,
        "status": status,
        "create_time": create_time,
        "round_num": round_num,
        "act_duration": act_duration,
        "rules": rules,
    }

    update_dict_ready = helpers.rmnullkeys(update_dict)
    db.session.query(EtActivity).filter(
        EtActivity.id == act_id).update(update_dict_ready)
    try:
        db.session.commit()

        res_data = dict()
        res.update(code=ResponseCode.Success, data=res_data, msg=f'活动修改成功')
        return res.data
    except Exception as why:

        res.update(code=ResponseCode.Success, data={}, msg=f'活动修改失败,数据异常{why}')
        return res.data
コード例 #13
0
def handle_account_edit():
    """
    账户修改接口
    :return: json 
    """
    res = ResMsg()
    req = request.get_json(force=True)

    userid = req.get("userid")
    username = req.get("username")
    password = req.get("password")
    password_hash = hash_password(password)
    role_id = req.get("role")
    status = req.get("status")
    update_dict = {
        "name": username,
        "password": password_hash,
        "role_id": role_id,
        "status": status
    }
    update_dict_ready = helpers.rmnullkeys(update_dict)
    user = db.session.query(EtAccount).filter(EtAccount.id == userid).first()

    if user:
        db.session.query(EtAccount).filter(
            EtAccount.id == userid).update(update_dict_ready)
        try:
            db.session.commit()
            res.update(code=ResponseCode.Success, data={}, msg='修改成功')
            return res.data
        except Exception as why:
            res.update(code=ResponseCode.Success,
                       data={},
                       msg=f'修改失败,请稍后再试{why}')
            return res.data
    else:
        res.update(code=ResponseCode.Success, data={}, msg='修改失败,请稍后再试')

        return res.data
コード例 #14
0
def handle_addappubs():
    """
    新增发布APP信息
    :return: json
    """
    res = ResMsg()
    req = request.get_json(force=True)
    now_timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    version = req.get("version", '1.0')
    osversion = req.get("osversion", 'android')
    update_status = int(req.get("update_status", 1))
    down_url = req.get("down_url", 'XXXX')
    up_logs = req.get("up_logs", '')

    account_name = session.get("user_name")

    update_dict = {
        "version": version,
        "osversion": osversion,
        "update_status": update_status,
        "down_url": down_url,
        "up_logs": up_logs,
        "update_time": now_timestr,
    }
    update_dict_ready = helpers.rmnullkeys(update_dict)

    new_user = EtAppsPubHistory(**update_dict_ready)
    db.session.add(new_user)
    try:
        db.session.commit()
        res_data = dict()
        res.update(code=ResponseCode.Success, data=res_data, msg=f'新增APP成功')
        return res.data
    except Exception as why:

        res.update(code=ResponseCode.Success, data={}, msg=f'任务数据异常{why}')
        return res.data
コード例 #15
0
def handle_reward_setting():
    """
    发放排行榜活动奖励
    :return: json
    """
    res = ResMsg()
    req = request.get_json(force=True)

    rank_id = req.get("id", '')
    bonus = req.get("bonus", '')
    member_id = req.get("member_id", '')
    invite_count = req.get("invite_count", '')
    rank_num = req.get("rank_num", '')
    activity_id = req.get("activity_id", '')
    avatar = req.get("avatar", '')

    update_dict = {
        "invite_count": invite_count,
        "bonus": int(bonus),
        "rank_num": rank_num,
        "activity_id": activity_id,
        "avatar": avatar,
    }
    update_dict_ready = helpers.rmnullkeys(update_dict)

    db.session.query(ActivityRewards).filter(
        ActivityRewards.id == rank_id).update(update_dict_ready)

    try:
        db.session.commit()

        res_data = dict()
        res.update(code=ResponseCode.Success, data=res_data, msg=f'奖励更新成功')
        return res.data
    except Exception as why:

        res.update(code=ResponseCode.Success, data={}, msg=f'奖励修改失败,数据异常{why}')
        return res.data
コード例 #16
0
        def auto_handle_wd(app_context,
                           wd_id: int,
                           member_id: int,
                           status: int = 2):
            with app_context:
                res = {}

                verify_log = '系统自动发放'

                account_name = 'system'
                now_timestr = time.strftime("%Y-%m-%d %H:%M:%S",
                                            time.localtime())

                verify_orders = db.session.query(EtMemberWithdrawal).filter(
                    EtMemberWithdrawal.id == wd_id,
                    EtMemberWithdrawal.member_id == member_id).first()

                if not verify_orders:
                    res.update(code=ResponseCode.Success, data={}, msg=f'数据异常')
                    return res

                if verify_orders.pay_status == 3:
                    res.update(
                        dict(code=ResponseCode.Success,
                             data={},
                             msg=f'该单已发放无法再次提现'))
                    return res

                # if verify_orders.pay_status==2:
                #     res.update(dict(code=ResponseCode.Success, data={},
                #                 msg=f'正在支付走账'))
                #     return res

                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 == member_id).first()

                if not user:
                    res.update(
                        dict(code=ResponseCode.Success, data={},
                             msg=f'用户信息异常'))
                    return res

                user_info = (dict(zip(user.keys(), user)))

                pay_status = 2

                if user_info['status'] == 2:
                    verify_log = '账号违规,无法发放提现'
                    pay_status = 4
                    verify = 1
                    status = 1

                update_dict = {
                    "verify": status,
                    "verify_log": verify_log,
                    "account": account_name,
                    "check_time": now_timestr,
                    "pay_status": pay_status
                }
                update_dict_ready = helpers.rmnullkeys(update_dict)

                db.session.query(EtMemberWithdrawal).filter(
                    EtMemberWithdrawal.id == wd_id).update(update_dict_ready)

                res_data = dict()
                ret = ''

                try:
                    if user_info['status'] == 2:
                        # back balace to member
                        drp_config = Redis.hgetall(redis_key_drp)
                        handling_fee_s = drp_config[b'handling_fee']
                        handling_fee = float(
                            str(handling_fee_s, encoding="utf-8"))

                        add_balance = 0
                        if handling_fee == 0:
                            add_balance = verify_orders.amounts
                        else:
                            handling_fee = (1 - float(handling_fee) / 100)
                            add_balance = round(
                                verify_orders.amounts / handling_fee, 2)

                        if verify_orders.origin_amount:
                            add_balance = verify_orders.origin_amount

                        user_update_dict = {
                            "balance":
                            user_info['balance'] + add_balance * 100,
                            "balance_version": int(time.time())
                        }
                        db.session.query(EtMember).filter(
                            EtMember.id == mid, EtMember.balance_version ==
                            user_info['balance_version']).update(
                                user_update_dict)

                    db.session.commit()

                    # verify pass go alipay
                    ret = async_alipay_service.delay(
                        serial_number=wd_id,
                        alipay_account=user_info['alipayid'],
                        real_name=user_info['realname'],
                        pay_amount=verify_orders.amounts,
                        mid=member_id)

                    res.update(code=ResponseCode.Success,
                               data=res_data,
                               msg=f'提现审核成功,系统将发放收益到用户收款账户,请留意支付返回消息')
                    return res

                except Exception as why:

                    res.update(code=ResponseCode.Success,
                               data={},
                               msg=f'用户提现订单审核失败,数据异常{why}')
                    return res
コード例 #17
0
def handle_getuserlists():
    """
    获取用户列表
    :return: json
    """
    res = ResMsg()
    page_index = int(request.args.get("page",  1))
    page_size = int(request.args.get("limit", 10))

    start_time = request.args.get("tstart", '')
    end_time = request.args.get("end", '')

    nickname = request.args.get("nickname",'')
    realname = request.args.get("realname",'')
    mobile = request.args.get("mobile",'')
    id_numbers = request.args.get("id_numbers",'')
    status = request.args.get("status",'')
    IIUV = request.args.get("IIUV",'')
    setreal = request.args.get("setreal", '')
    alipay_id = request.args.get("alipay_id", '')
    m_class= request.args.get("m_class", '')

    query_dict = {
        "nickname": nickname,
        "realname": realname,
        "mobile": mobile,
        "status": status,
        "m_class": m_class,
        "IIUV": IIUV,
        'setreal': setreal,
        'alipay_id': alipay_id
    }
    filters = helpers.rmnullkeys( query_dict )
    p_i, p_num = (page_index-1) * page_size, page_size

    if start_time and end_time:
        if not IIUV:
            members = db.session.query(EtMember).filter(EtMember.reg_time >= start_time, EtMember.reg_time <= end_time).filter_by(**filters).order_by(EtMember.reg_time.desc()).limit(page_size).offset((page_index-1)*page_size).all()

            count_members = db.session.query(EtMember).filter(EtMember.reg_time >= start_time, EtMember.reg_time <= end_time).filter_by(**filters).all()
            mlists=  helpers.model_to_dict(members)
        else:
            del filters['IIUV']
            where_cond=''
            if filters:
                where_cond +='AND '
                where_cond += 'AND '.join("m.{!s}={!r}".format(key, val)
                                    for (key, val) in filters.items())

            where_cond +=f' AND m.reg_time>{start_time} AND m.reg_time<={end_time} '

            members = db.session.query(EtMember).filter(EtMember.IIUV == IIUV).first()
            mem_sql= f'SELECT * FROM `et_member_relations` as dr LEFT JOIN et_members as m on dr.member_id=m.id WHERE dr.parent_id={members.id} {where_cond} ORDER BY m.reg_time DESC  LIMIT {p_i},{p_num}'
            
            members_more = db.session.execute(mem_sql).fetchall()
            mlists=[{k: v for (k, v) in row.items()} for row in members_more]
            count_members=mlists

    else:
        if not IIUV:
            members = db.session.query(EtMember).filter_by(**filters).order_by(EtMember.reg_time.desc()).limit(page_size).offset((page_index-1)*page_size).all()
            
            count_members = db.session.query(EtMember).filter_by(**filters).all()
            mlists=  helpers.model_to_dict(members)
        else:
            del filters['IIUV']
            where_cond=''
            if filters:
                where_cond +='AND '
                where_cond += 'AND '.join("m.{!s}={!r}".format(key, val)
                                    for (key, val) in filters.items())

            members = db.session.query(EtMember).filter(EtMember.IIUV == IIUV).first()
            
            if not members:
                res.update(code=ResponseCode.Success, data={}, msg='数据获取异常')
                return res.data

            mem_sql= f'SELECT * FROM `et_member_relations` as dr LEFT JOIN et_members as m on dr.member_id=m.id WHERE dr.parent_id={members.id} {where_cond} ORDER BY m.reg_time DESC LIMIT {p_i},{p_num}'

            members_more = db.session.execute(mem_sql).fetchall()
            mlists=[{k: v for (k, v) in row.items()} for row in members_more]
            count_members=mlists


    res_data= dict()
    if members:
        res_data['list'] =  mlists
        res_data['length'] = len(count_members)
        res.update(code=ResponseCode.Success, data=res_data, msg=f'{len(count_members)}获取成功')
        
        return res.data
    else:
        res.update(code=ResponseCode.Success, data={}, msg='数据获取异常')

        return res.data
コード例 #18
0
def handle_withdrawals_list():
    """
    用户提现列表
    :return: json
    """
    res = ResMsg()

    page_index = int(request.args.get("page", 1))
    page_size = int(request.args.get("limit", 10))

    member_id = request.args.get("member_id", '')
    realname = request.args.get("realname", '')
    nickname = request.args.get("nickname", '')

    start_time = request.args.get("tstart", '')
    end_time = request.args.get("end", '')
    mobile = request.args.get("mobile", '')
    verify = request.args.get("verify", '')
    pay_status = request.args.get("pay_status", '')

    cond_by = ''
    if mobile:
        cond_by = f' WHERE m.mobile={mobile} '

    query_dict = {
        "member_id": member_id,
        "verify": verify,
        "pay_status": pay_status,
    }
    filters = helpers.rmnullkeys(query_dict)

    flatten_filters = 'and '.join("{!s}={!r}".format(key, val)
                                  for (key, val) in filters.items())

    where_cond = ''
    if flatten_filters:
        where_cond = f"WHERE {flatten_filters} "
        if start_time and end_time:
            where_cond += f" AND start_time>'{start_time}' AND start_time<='{end_time}' "
    else:
        if start_time and end_time:
            where_cond += f" WHERE start_time>'{start_time}' AND start_time<='{end_time}'"

    fetch_columns = "w.id as id,w.member_id as member_id,m.id as mid, w.verify,w.verify_log,w.amounts,w.start_time,w.pay_status,w.pay_log,w.check_time,w.account,w.end_time,m.m_class,m.alipayid,m.mobile,m.nickname,m.realname,m.status as mstatus,m.reg_time,m.IIUV"
    p_i, p_num = (page_index - 1) * page_size, page_size
    order_sql = f"SELECT {fetch_columns} FROM \
                    (SELECT * FROM et_member_withdrawal {where_cond}) AS w LEFT JOIN et_members AS m ON w.member_id = m.id {cond_by} ORDER BY w.start_time DESC LIMIT {p_i},{p_num} ;"

    count_order_sql = f"SELECT {fetch_columns} FROM \
                    (SELECT * FROM et_member_withdrawal {where_cond} ) AS w LEFT JOIN et_members AS m ON w.member_id = m.id {cond_by};"

    # logger.info(order_sql)
    wd_orders = db.session.execute(order_sql).fetchall()
    count_orders = db.session.execute(count_order_sql).fetchall()

    res_data = dict()

    if wd_orders:
        res_data['list'] = [{k: v
                             for (k, v) in row.items()} for row in wd_orders]
        res_data['length'] = len(count_orders)
        res.update(code=ResponseCode.Success,
                   data=res_data,
                   msg=f'{order_sql}用户提现列表数据获取成功')
        return res.data
    else:

        res.update(code=ResponseCode.Success, data={}, msg='提现列表数据为空or异常')
        return res.data
コード例 #19
0
ファイル: flows_service.py プロジェクト: FreeGodCode/easytask
def handle_drp_lists():
    """
    分销收益流水列表接口
    @todo 根据索引优化sql查询
    :return: json
    """
    res = ResMsg()

    page_index = int(request.args.get("page", 1))
    page_size = int(request.args.get("limit", 10))

    member_id = request.args.get("member_id", '')
    task_id = request.args.get("id", '')
    start_time = request.args.get("tstart", '')
    end_time = request.args.get("end", '')

    query_dict = {
        "member_id": int(member_id) if member_id else member_id,
        "task_id": int(task_id) if task_id else task_id,
    }
    filters = helpers.rmnullkeys(query_dict)

    flatten_filters = 'and '.join("{!s}={!r}".format(key, val)
                                  for (key, val) in filters.items())

    fetch_columns = "d.id, m1.nickname as username, m2.nickname as from_user, m1.IIUV,m2.IIUV as from_IIUV, t.name as taskname,t.task_class, d.amounts, d.add_time"
    p_i, p_num = (page_index - 1) * page_size, page_size

    where_cond = ''
    if flatten_filters:
        where_cond = f"WHERE {flatten_filters} "

        if start_time and end_time:
            where_cond += f" AND add_time>'{start_time}' AND add_time<='{end_time}' "
    else:
        if start_time and end_time:
            where_cond = f" WHERE add_time>'{start_time}' AND add_time<='{end_time}' "

    drp_sql = f"SELECT {fetch_columns} FROM \
                   (SELECT * FROM et_member_drps {where_cond} ORDER BY add_time DESC limit {p_i}, {p_num} ) AS d \
                    LEFT JOIN et_members AS m1 ON d.member_id = m1.id \
                     LEFT JOIN et_members AS m2 ON d.from_member_id = m2.id \
                      LEFT JOIN et_tasks AS t ON d.from_task_id = t.id ;"

    count_drp_sql = f"SELECT {fetch_columns} FROM \
                   (SELECT * FROM et_member_drps {where_cond} ) AS d \
                    LEFT JOIN et_members AS m1 ON d.member_id = m1.id \
                     LEFT JOIN et_members AS m2 ON d.from_member_id = m2.id \
                      LEFT JOIN et_tasks AS t ON d.from_task_id = t.id ;"

    drp_lists = db.session.execute(drp_sql).fetchall()
    count_drp_lists = db.session.execute(count_drp_sql).fetchall()

    res_data = dict()

    # counts = db.session.execute("SELECT count(*) FROM et_member_drps").first()
    if drp_lists:
        res_data['list'] = [{k: v
                             for (k, v) in row.items()} for row in drp_lists]
        res_data['length'] = len(count_drp_lists)
        res.update(code=ResponseCode.Success,
                   data=res_data,
                   msg=f'{len(count_drp_lists)}分销收益流水列表数据获取成功')
        return res.data
    else:

        res.update(code=ResponseCode.Success, data={}, msg='用户收益数据为空')
        return res.data
コード例 #20
0
ファイル: flows_service.py プロジェクト: FreeGodCode/easytask
def handle_orders_lists():
    """
    流水统计报表
    """
    res = ResMsg()
    now_timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    page_index = int(request.args.get("page", 1))
    page_size = int(request.args.get("limit", 10))
    date = int(request.args.get("date", 1))

    start_time = request.args.get("tstart", '')
    end_time = request.args.get("end", '')

    member_id = request.args.get("member_id", '')
    task_id = request.args.get("task_id", '')
    task_order_id = request.args.get("task_order_id", '')
    nickname = request.args.get("nickname", '')

    mobile = request.args.get("mobile", '')
    IIUV = request.args.get("IIUV", '')
    realname = request.args.get("realname", '')

    cond_by = ''
    if mobile:
        cond_by = f' WHERE m.mobile={mobile} '

    query_dict = {
        "member_id": int(member_id) if member_id else None,
        "task_id": int(task_id) if task_id else None,
        "task_order_id": int(task_order_id) if task_order_id else None,
    }
    filters = helpers.rmnullkeys(query_dict)
    flatten_filters = ' AND '.join("{!s}={!r}".format(key, val)
                                   for (key, val) in filters.items())
    p_i, p_num = (page_index - 1) * page_size, page_size

    where_cond = ''
    if flatten_filters:
        where_cond = f" AND {flatten_filters} "

        if start_time and end_time:
            where_cond += f" AND add_time>'{start_time}' AND add_time<='{end_time}' "
    else:
        if start_time and end_time:
            where_cond = f" AND add_time>'{start_time}' AND add_time<='{end_time}' "

    fetch_columns = "e.id,e.add_time,t.name AS task_name,t.task_reward,t.id as task_id,e.member_id,mr.parent_id as lv1_id,mr1.parent_id as lv2_id,mr2.parent_id as lv3_id"

    earning_sql = f"SELECT {fetch_columns} FROM ( SELECT id, amounts, member_id, task_order_id, task_id, amount_type, add_time FROM et_member_earnings WHERE task_order_id>0 {where_cond} ) AS e LEFT JOIN et_tasks AS t ON e.task_id = t.id \
    LEFT JOIN et_member_relations as mr ON mr.member_id=e.member_id \
    LEFT JOIN et_member_relations as mr1 ON mr.parent_id=mr1.member_id \
    LEFT JOIN et_member_relations as mr2 ON mr1.parent_id=mr2.member_id \
    WHERE  mr.top_parent_id IS NOT NULL LIMIT {p_i},{p_num}"

    count_earning_sql = f"SELECT {fetch_columns} FROM ( SELECT id, amounts, member_id, task_order_id, task_id, amount_type, add_time FROM et_member_earnings WHERE task_order_id>0 ) AS e LEFT JOIN et_tasks AS t ON e.task_id = t.id \
    LEFT JOIN et_member_relations as mr ON mr.member_id=e.member_id \
    LEFT JOIN et_member_relations as mr1 ON mr.parent_id=mr1.member_id \
    LEFT JOIN et_member_relations as mr2 ON mr1.parent_id=mr2.member_id \
    WHERE  mr.top_parent_id IS NOT NULL"

    earnings = db.session.execute(earning_sql).fetchall()

    counts = db.session.execute(count_earning_sql).fetchall()

    drp_config = Redis.hgetall(redis_key_drp)
    per_sets = json.loads(drp_config[b'profit_percentage'].decode('utf8'))

    logger.info(per_sets)

    profit_percentage_arr = []
    for i in range(len(per_sets)):
        profit_percentage_arr.append(per_sets[i]['per'])

    res_data = dict()

    if earnings:
        res_data['list'] = [{k: v
                             for (k, v) in row.items()} for row in earnings]
        res_data['length'] = len(counts)
        res_data['drpconfig'] = profit_percentage_arr

        res.update(code=ResponseCode.Success, data=res_data, msg='流水报表数据获取成功')
        return res.data
    else:

        res.update(code=ResponseCode.Success, data={}, msg='流水报表数据数据为空or异常')
        return res.data
コード例 #21
0
def handle_sysconfig_edit():
    """
    系统全局设置修改
    :return: json 
    """
    res = ResMsg()
    req = request.get_json(force=True)
    now_timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    sysid = 1
    notice = req.get("notice", '')
    domains = req.get("domains", '')
    share_domains = req.get("share_domains", '')
    task_limit = req.get("task_limit", 20)
    banners = req.get("banners", '')
    limit_withdrawal = req.get("limit_withdrawal", '')
    sys_status = int(req.get("status", 1))
    rules = req.get("rules", 1)
    helper = req.get("helpers", 1)
    start_page = req.get("start_page", 1)
    upgrade = int(req.get("upgrade", 10))

    update_dict = {
        "notice": notice,
        "domains": domains,
        "share_domains": share_domains,
        "task_limit": task_limit,
        "banners": banners,
        "limit_withdrawal": limit_withdrawal,
        "sys_status": sys_status,
        "rules": rules,
        "helpers": helper,
        "start_page": start_page,
        "upgrade": upgrade,
        "update_time": now_timestr
    }
    update_dict_ready = helpers.rmnullkeys(update_dict)
    sysdata = db.session.query(EtGlobalConfig).filter(
        EtGlobalConfig.id == sysid).first()

    if sysdata:
        db.session.query(EtGlobalConfig).filter(
            EtGlobalConfig.id == sysid).update(update_dict_ready)
        if notice:
            data = {'content': notice, 'time': now_timestr}
            json_data = json.dumps(data)
            redis_res = Redis.lpush(system_logging, json_data)
        try:
            db.session.commit()
            Redis.delete(redis_key_sys)
            res_data = helpers.queryToDict(sysdata)

            del res_data['update_time']

            Redis.hmset(redis_key_sys, res_data)
            res.update(code=ResponseCode.Success, data={}, msg='系统全局配置成功')
            return res.data

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

        return res.data
コード例 #22
0
def handle_withdrawals_verify():
    """
    用户提现审核接口
    @logic 审核完成 异步发送任务至redis队列执行支付宝付款任务
    :return: json
    """
    res = ResMsg()
    req = request.get_json(force=True)

    wd_id = int(req.get("id", 1))
    member_id = int(req.get("member_id", 1))
    status = int(req.get("status", 1))
    verify_log = str(req.get("verify_log", '数据真实有效,情节感人,通过'))

    account_name = session.get("user_name")
    now_timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    verify_orders = db.session.query(EtMemberWithdrawal).filter(
        EtMemberWithdrawal.id == wd_id,
        EtMemberWithdrawal.member_id == member_id).first()

    if not account_name or not verify_orders:
        res.update(code=ResponseCode.Success,
                   data={},
                   msg=f'账户{account_name}数据异常')
        return res.data

    if not status:
        res.update(code=ResponseCode.Success, data={}, msg='未提交审核数据,操作已经撤销')
        return res.data
    pay_status = 1
    if status == 2:
        pay_status = 2

    update_dict = {
        "verify": status,
        "verify_log": verify_log,
        "account": account_name,
        "check_time": now_timestr,
        "pay_status": pay_status
    }
    update_dict_ready = helpers.rmnullkeys(update_dict)

    db.session.query(EtMemberWithdrawal).filter(
        EtMemberWithdrawal.id == wd_id).update(update_dict_ready)
    res_data = dict()
    ret = ''
    try:
        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 == member_id).first()

        user_info = (dict(zip(user.keys(), user)))
        drp_config = Redis.hgetall(redis_key_drp)
        handling_fee_s = drp_config[b'handling_fee']
        handling_fee = float(str(handling_fee_s, encoding="utf-8"))
        logger.info("handling_fee:")
        logger.info(handling_fee)

        # verify reject
        if status == 1:

            if handling_fee == 0:
                add_balance = verify_orders.amounts
            else:
                handling_fee = (1 - float(handling_fee) / 100)
                add_balance = round(verify_orders.amounts / handling_fee, 2)

            if verify_orders.origin_amount:
                add_balance = verify_orders.origin_amount

            logger.info("add_balance:")
            logger.info(add_balance)

            update_dict = {
                "balance": user_info['balance'] + add_balance * 100,
                "balance_version": int(time.time())
            }
            logger.info(update_dict)

            db.session.query(EtMember).filter(
                EtMember.id == member_id, EtMember.balance_version ==
                user_info['balance_version']).update(update_dict)
            try:
                db.session.commit()

                Redis.delete(user_center_key + str(user_info['id']))
                Redis.delete(user_info_key + str(user_info['mobile']))

                res.update(code=ResponseCode.Success, data={}, msg='该单未通过审核')
                return res.data

            except Exception as why:

                res.update(code=ResponseCode.Success,
                           data={},
                           msg=f'审核拒绝操作数据异常{why}')
                return res.data

        db.session.commit()
        # verify pass go alipay
        if status == 2:
            if user:
                ret = async_alipay_service.delay(
                    serial_number=wd_id,
                    alipay_account=user_info['alipayid'],
                    real_name=user_info['realname'],
                    pay_amount=verify_orders.amounts,
                    mid=member_id)

        logger.info(ret)
        res.update(code=ResponseCode.Success,
                   data=res_data,
                   msg=f'提现审核成功,系统将发放收益到用户收款账户,请留意支付返回消息')
        return res.data

    except Exception as why:

        res.update(code=ResponseCode.Success,
                   data={},
                   msg=f'用户提现订单审核失败,数据异常{why}')
        return res.data
コード例 #23
0
def handle_earninglists():
    """
    用户收益流水列表接口
    @todo 根据索引优化sql查询
    :return: json
    """
    res = ResMsg()
    now_timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    page_index = int(request.args.get("page", 1))
    page_size = int(request.args.get("limit", 10))

    start_time = request.args.get("tstart", '')
    end_time = request.args.get("end", '')

    member_id = request.args.get("member_id", '')
    task_id = request.args.get("task_id", '')
    task_order_id = request.args.get("task_order_id", '')
    nickname = request.args.get("nickname", '')

    mobile = request.args.get("mobile", '')
    IIUV = request.args.get("IIUV", '')
    realname = request.args.get("realname", '')

    cond_by = ''
    if mobile:
        cond_by = f' WHERE m.mobile={mobile} '

    query_dict = {
        "member_id": int(member_id) if member_id else None,
        "task_id": int(task_id) if task_id else None,
        "task_order_id": int(task_order_id) if task_order_id else None,
    }
    filters = helpers.rmnullkeys(query_dict)

    flatten_filters = 'and '.join("{!s}={!r}".format(key, val)
                                  for (key, val) in filters.items())

    fetch_columns = "e.id, e.amount_type, e.amounts, e.task_order_id,e.amount_type, e.add_time, m.nickname,m.IIUV,t.name as taskname,t.task_class, m.m_class,m.alipayid,m.mobile,m.nickname,m.realname,m.status as mstatus,m.reg_time"

    p_i, p_num = (page_index - 1) * page_size, page_size

    where_cond = ''
    if flatten_filters:
        where_cond = f"WHERE {flatten_filters} "

        if start_time and end_time:
            where_cond += f" AND add_time>'{start_time}' AND add_time<='{end_time}' "
    else:
        if start_time and end_time:
            where_cond = f" WHERE add_time>'{start_time}' AND add_time<='{end_time}' "

    earning_sql = f"SELECT {fetch_columns} FROM(SELECT id,amounts,member_id,task_order_id,task_id,amount_type,add_time FROM et_member_earnings {where_cond} ORDER BY add_time DESC ) AS e LEFT JOIN et_members AS m ON e.member_id = m.id LEFT JOIN et_tasks AS t ON e.task_id = t.id {cond_by} LIMIT {p_i},{p_num};"

    count_earning_sql = f"SELECT {fetch_columns} FROM(SELECT id,amounts,member_id,task_order_id,task_id,amount_type,add_time FROM et_member_earnings {where_cond} ) AS e LEFT JOIN et_members AS m ON e.member_id = m.id LEFT JOIN et_tasks AS t ON e.task_id = t.id {cond_by};"

    earnings = db.session.execute(earning_sql).fetchall()

    counts = db.session.execute(count_earning_sql).fetchall()

    res_data = dict()
    if earnings:
        res_data['list'] = [{k: v
                             for (k, v) in row.items()} for row in earnings]
        res_data['length'] = len(counts)
        res.update(code=ResponseCode.Success,
                   data=res_data,
                   msg=f'用户收益列表数据获取成功')
        return res.data
    else:

        res.update(code=ResponseCode.Success, data={}, msg='用户收益数据异常')
        return res.data
コード例 #24
0
def async_alipay_service(serial_number: int, alipay_account: str,
                         real_name: str, pay_amount: int, mid: int):
    """
    @req: req_data
    req_data = {'alipay_account': alipay, 'alipay_name': real_name,
                        'amount': amount, 'serial_number': serial_number}
    @resp: result_status, error_code

    :return:
    """
    with current_app.app_context():
        res = {}
        now_timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        headers = {'content-type': 'application/json;charset=UTF-8'}
        req_data = {
            'alipay_account': alipay_account,
            'alipay_name': real_name,
            'amount': pay_amount,
            'serial_number': serial_number
        }

        req_data['secret_key'] = 'FA77E2804734C22F72B22D9B7EDB41A9'
        wd_record = db.session.query(EtMemberWithdrawal).filter(
            EtMemberWithdrawal.id == serial_number).first()

        if wd_record:
            if wd_record.pay_status == 3:
                res.update(
                    dict(code=ResponseCode.Success,
                         data={},
                         msg=f'该单已发放无法再次提现'))
                return res

        user = db.session.query(EtMember).filter(EtMember.id == mid).first()

        verify_orders = db.session.query(EtMemberWithdrawal).filter(
            EtMemberWithdrawal.id == serial_number,
            EtMemberWithdrawal.member_id == mid).first()

        if user.status == 2:

            drp_config = Redis.hgetall(redis_key_drp)
            handling_fee_s = drp_config[b'handling_fee']
            handling_fee = float(str(handling_fee_s, encoding="utf-8"))

            add_balance = 0
            if handling_fee == 0:
                add_balance = verify_orders.amounts
            else:
                handling_fee = (1 - float(handling_fee) / 100)
                add_balance = round(verify_orders.amounts / handling_fee, 2)

            if verify_orders.origin_amount:
                add_balance = verify_orders.origin_amount

            update_dict = {
                "balance": user.balance + add_balance * 100,
                "balance_version": int(time.time())
            }

            db.session.query(EtMember).filter(
                EtMember.id == mid, EtMember.balance_version ==
                user.balance_version).update(user_update_dict)
            update_dict = {
                "id": serial_number,
                "verify": 1,
                "pay_status": 4,
                "end_time": now_timestr,
                "verify_log": '账号已封禁,无法提现',
                "pay_log": '账号已封禁,无法提现',
            }
            update_dict_ready = helpers.rmnullkeys(update_dict)

            db.session.query(EtMemberWithdrawal).filter(
                EtMemberWithdrawal.id == serial_number).update(
                    update_dict_ready)
            try:
                db.session.commit()
                Redis.delete(user_center_key + str(user.id))
                Redis.delete(user_info_key + str(user.mobile))
                Redis.delete(user_withdraw_recode_key + str(user.id))

            except Exception as why:
                msg = f'支付失败,请稍后再试{why}'
                logging.info(str(why))
                return msg

            if user.status == 2:
                res.update(
                    dict(code=ResponseCode.Success,
                         data={},
                         msg=f'该用户已禁用,无法提现'))
                return res

            res.update(
                dict(code=ResponseCode.Success, data={}, msg=f'该用户余额已不足,无法提现'))
            return res

        try:

            resp = requests.post(
                'http://47.91.142.164/api/alipay/transfer',
                data=req_data,
            )

            resp_json = resp.json()

            if resp_json.get('code') == 0:
                resp_data = resp_json.get('data', {})
                result_status, error_code = resp_data.get(
                    'status'), resp_data.get('error_code')
            else:
                result_status, error_code = False, resp_json.get('msg', u'')

        except Exception as e:
            result_status, error_code = False, '网络错误' + str(e)
            logger.info(str(e))
            logger.info(result_status)

        if result_status:
            # update_db pay_status

            pay_status = 3
            update_dict = {
                "id": serial_number,
                "pay_status": pay_status,
                "end_time": now_timestr,
                "verify_log": '提现成功,已到账',
                "pay_log": '提现成功,已到账',
            }
            update_dict_ready = helpers.rmnullkeys(update_dict)

            db.session.query(EtMemberWithdrawal).filter(
                EtMemberWithdrawal.id == serial_number).update(
                    update_dict_ready)

            try:
                db.session.commit()
                # update user cache
                Redis.delete(user_center_key + str(user.id))
                Redis.delete(user_info_key + str(user.mobile))
                Redis.delete(user_withdraw_recode_key + str(user.id))
                # send balance 100 to a parent which is never get the balance from this member
                new_member_reward(from_user=user.id)
            except Exception as why:
                msg = f'修改失败,请稍后再试{why}'
                return msg

            # title = '提现成功'
            # content = '恭喜您提现审核通过成功提现 {0}元'.format('%.2f' % (pay_amount))
            # logger.info(result_status)

        else:
            remark = ''
            if error_code in [
                    '支付宝提现系统升级中!', 'INVALID_PARAMETER',
                    'PAYCARD_UNABLE_PAYMENT', 'PAYER_DATA_INCOMPLETE',
                    'PERMIT_CHECK_PERM_LIMITED', 'PAYER_STATUS_ERROR',
                    'PAYER_STATUS_ERROR', 'PAYER_DATA_INCOMPLETE',
                    'PAYMENT_INFO_INCONSISTENCY', 'CERT_MISS_TRANS_LIMIT',
                    'CERT_MISS_ACC_LIMIT', 'PAYEE_ACC_OCUPIED',
                    'MEMO_REQUIRED_IN_TRANSFER_ERROR',
                    'PERMIT_PAYER_LOWEST_FORBIDDEN', 'PERMIT_PAYER_FORBIDDEN',
                    'PERMIT_CHECK_PERM_IDENTITY_THEFT',
                    'REMARK_HAS_SENSITIVE_WORD', 'ACCOUNT_NOT_EXIST',
                    'PAYER_CERT_EXPIRED', 'SYNC_SECURITY_CHECK_FAILED',
                    'TRANSFER_ERROR'
            ]:
                remark = '支付宝提现系统升级中!请销后尝试'
            elif error_code in [
                    'PERM_AML_NOT_REALNAME_REV', 'PERM_AML_NOT_REALNAME_REV',
                    'PERMIT_NON_BANK_LIMIT_PAYEE'
            ]:
                remark = '请登录支付宝站内或手机客户端完善身份信息后,重试!'
            elif error_code in [
                    'PAYEE_NOT_EXIST', 'PERMIT_NON_BANK_LIMIT_PAYEE'
            ]:
                remark = '支付宝账号不存在!请检查之后重试'
            elif error_code == 'PAYEE_USER_INFO_ERROR':
                remark = '支付宝账号和姓名不匹配,请更换成实名信息支付宝账号!'
            elif error_code in [
                    '服务暂时不可用!', 'SYSTEM_ERROR', 'PAYER_BALANCE_NOT_ENOUGH'
            ]:
                remark = '服务暂时不可用'
            elif error_code == 'BLOCK_USER_FORBBIDEN_RECIEVE':
                remark = '账户异常被冻结,无法收款,请咨询支付宝客服95188'
            else:
                remark = '支付失败,请稍后再试' + str(error_code)

            now_timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

            pay_status = 4

            update_dict = {
                "id": serial_number,
                "verify": 1,
                "pay_status": pay_status,
                "verify_log": str(remark),
                "pay_log": str(remark) + ':' + str(error_code),
                # "end_time": now_timestr
            }
            update_dict_ready = helpers.rmnullkeys(update_dict)

            db.session.query(EtMemberWithdrawal).filter(
                EtMemberWithdrawal.id == serial_number).update(
                    update_dict_ready)

            drp_config = Redis.hgetall(redis_key_drp)
            handling_fee_s = drp_config[b'handling_fee']
            handling_fee = float(str(handling_fee_s, encoding="utf-8"))
            logging.info('+提现失败金额:')
            logging.info(str(verify_orders.amounts))
            add_balance = 0
            if handling_fee == 0:
                add_balance = verify_orders.amounts
            else:
                handling_fee = (1 - float(handling_fee) / 100)
                add_balance = round(verify_orders.amounts / handling_fee, 2)

            if verify_orders.origin_amount:
                add_balance = verify_orders.origin_amount

            user_update_dict = {
                "balance": user.balance + add_balance * 100,
                "balance_version": int(time.time())
            }

            db.session.query(EtMember).filter(
                EtMember.id == mid, EtMember.balance_version ==
                user.balance_version).update(user_update_dict)

            try:
                db.session.commit()
                Redis.delete(user_center_key + str(user.id))
                Redis.delete(user_info_key + str(user.mobile))
                Redis.delete(user_withdraw_recode_key + str(user.id))

            except Exception as why:
                msg = f'支付失败,请稍后再试{why}'
                logging.info(str(why))
                return msg

            logging.info(error_code + remark)
            return error_code + remark
コード例 #25
0
def handle_auto_withdrawals_verify():
    """
    APP端自动完成用户提现审核接口
    @logic 审核完成 异步发送任务至redis队列执行支付宝付款任务
    :return: json
    """
    res = ResMsg()
    req = request.get_json(force=True)

    wd_id = req.get("id", 1)
    member_id = req.get("member_id", 1)
    status = 2
    verify_log = '系统自动发放提现'

    now_timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    verify_orders = db.session.query(EtMemberWithdrawal).filter(
        EtMemberWithdrawal.id == wd_id,
        EtMemberWithdrawal.member_id == member_id).first()

    if not verify_orders:
        res.update(code=ResponseCode.Success, data={}, msg='审核数据异常')
        return res.data

    if not status:
        res.update(code=ResponseCode.Success, data={}, msg='未提交审核数据,操作已经撤销')
        return res.data

    update_dict = {
        "verify": status,
        "verify_log": verify_log,
        "account": 'system',
        "check_time": now_timestr,
        "pay_status": 1
    }
    update_dict_ready = helpers.rmnullkeys(update_dict)

    db.session.query(EtMemberWithdrawal).filter(
        EtMemberWithdrawal.id == wd_id).update(update_dict_ready)
    res_data = dict()
    ret = ''
    try:
        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 == member_id).first()
        user_info = (dict(zip(user.keys(), user)))

        db.session.commit()
        # verify pass go alipay
        if status == 2:
            if user:
                ret = async_alipay_service.delay(
                    serial_number=wd_id,
                    alipay_account=user_info['alipayid'],
                    real_name=user_info['realname'],
                    pay_amount=verify_orders.amounts,
                    mid=member_id)

        logger.info(ret)
        res.update(code=ResponseCode.Success,
                   data=res_data,
                   msg=f'提现审核成功,系统将发放收益到用户收款账户,请留意支付返回消息')
        return res.data

    except Exception as why:

        res.update(code=ResponseCode.Success,
                   data={},
                   msg=f'用户提现订单审核失败,数据异常{why}')
        return res.data
コード例 #26
0
ファイル: task_service.py プロジェクト: FreeGodCode/easytask
def handle_edittask():
    """
    任务修改编辑接口
    :return: json
    """
    res = ResMsg()
    req = request.get_json(force=True)
    now_timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    
    taskid= int(req.get("id", 1))
    taskname= req.get("name",'tasktest1-new')
    status= int(req.get("status", 1))
    task_class= int(req.get("task_class", 1))
    
    end_time= req.get("end_time", '')
    begin_task_time= req.get("begin_task_time",'')
    
    poster_img= req.get("poster_img", 'https://qiniu.staticfile.org/user_avatar.jpg')
    count_tasks= req.get("count_tasks",'')
    allow_nums= req.get("allow_nums", '')
    allow_member_nums= req.get("allow_member_nums", '')
    virtual_nums= req.get("virtual_nums", '')
    tasks_counts= req.get("tasks_counts", '')
    task_reward= req.get("task_reward", '')
    task_info= req.get("task_info", '请根据任务步骤完成任务')
    task_steps= req.get("task_steps", '')
    tags= req.get("tags", '')
    sys_tags = req.get("sys_tags", '')
    task_cats= req.get("task_cats", '')
    recommend= req.get("recommend", 1)
    deadline_time = req.get("deadline_time", '')
    check_router = req.get("check_router", '')

    end_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(end_time)/1000))
    begin_task_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(begin_task_time)/1000))

    account_name= session.get("user_name")

    update_dict = {
        "name": taskname,
        "status": status,
        "task_class": task_class,
        "end_time": end_time,
        "begin_task_time": begin_task_time,
        "count_tasks": count_tasks,
        "allow_nums": allow_nums,
        "allow_member_nums": allow_member_nums,
        "virtual_nums": virtual_nums,
        "tasks_counts": tasks_counts,
        "task_reward": task_reward,
        "task_info": task_info,
        "task_steps": task_steps,
        "tags": tags,
        "poster_img":poster_img,
        "sys_tags": sys_tags,
        "task_cats": task_cats,
        "recommend": recommend,
        "deadline_time": deadline_time,
        "check_router": check_router,
    }
    update_dict_ready = helpers.rmnullkeys( update_dict )
    db.session.query(EtTask).filter(EtTask.id == taskid).update(update_dict_ready)
    try:
        db.session.commit()
        
        Redis.delete(task_info_key)
        Redis.delete(task_detail_key+str(taskid))
        Redis.delete(tasks_high_info_key)

        res_data= dict()
        res.update(code=ResponseCode.Success, data=res_data, msg=f'任务修改成功')
        return res.data
    except Exception as why:

        res.update(code=ResponseCode.Success, data={},msg=f'修改失败,数据异常{why}')
        return res.data
コード例 #27
0
ファイル: task_service.py プロジェクト: FreeGodCode/easytask
def handle_list():
    """
    任务列表接口
    :return: json
    """
    res = ResMsg()

    page_index = int(request.args.get("page",  1))
    page_size = int(request.args.get("limit", 10))

    task_id = request.args.get("id",'')
    taskname = request.args.get("name",'')
    status = request.args.get("status",'')
    task_class = request.args.get("task_class", '')

    start_time = request.args.get("tstart", '')
    end_time = request.args.get("end", '')
    task_cats= request.args.get("task_cats", '')
    sys_tags= request.args.get("sys_tags", '')
    tags= request.args.get("tags", '')

    query_dict = {
        "id": task_id,
        "name": taskname,
        "status": status,
        "task_class": task_class,
        "task_cats": task_cats,
    }
    filters = helpers.rmnullkeys( query_dict )
    tasks_counts = None
    
    if start_time and end_time:
        
        tasks = db.session.query(EtTask).filter(EtTask.edit_time >= start_time, EtTask.edit_time <= end_time, EtTask.id>1, EtTask.mer_id==None).filter_by(**filters).order_by(EtTask.edit_time.desc()).limit(page_size).offset((page_index-1)*page_size).all()
        tasks_counts=db.session.query(EtTask).filter(EtTask.edit_time >= start_time, EtTask.edit_time <= end_time, EtTask.mer_id==None).filter_by(**filters).all()
    else:
        if not filters:
            tasks = db.session.query(EtTask).filter(EtTask.status<3, EtTask.id>1, EtTask.mer_id==None).filter_by(**filters).order_by(EtTask.edit_time.desc()).limit(page_size).offset((page_index-1)*page_size).all()

            tasks_counts= db.session.query(EtTask).filter(EtTask.status<3, EtTask.mer_id==None).filter_by(**filters).all()
        else:
            tasks = db.session.query(EtTask).filter(EtTask.id>1, EtTask.mer_id==None).filter_by(**filters).order_by(EtTask.edit_time.desc()).limit(page_size).offset((page_index-1)*page_size).all()

            tasks_counts= db.session.query(EtTask).filter(EtTask.status<3, EtTask.mer_id==None).filter_by(**filters).all()
    
    if tasks_counts:
        counts= (len(tasks_counts), 0)

    else:
        counts = db.session.execute("SELECT count(*) FROM et_tasks").first()


    res_data= dict()
    
    if tasks:
        res_data['list'] =  helpers.model_to_dict(tasks)
        res_data['length']= counts[0]
        res.update(code=ResponseCode.Success, data= res_data, msg=f'任务获取成功')
        return res.data
    else:

        res.update(code=ResponseCode.Success, data={}, msg=f'任务数据异常or空')
        return res.data
コード例 #28
0
ファイル: task_service.py プロジェクト: FreeGodCode/easytask
def handle_taskorderlist():
    """
    APP用户提交任务列表接口
    @todo 根据索引优化sql查询
    :return: json
    """
    res = ResMsg()
    page_index = int(request.args.get("page",  1))
    page_size = int(request.args.get("limit", 10))
    
    task_id = request.args.get("task_id", '')
    start_time = request.args.get("tstart", '')
    end_time = request.args.get("end", '')
    mobile = request.args.get("mobile", '')
    
    sys_tags= request.args.get("sys_tags", '')
    tags= request.args.get("tags", '')

    order_status = request.args.get("order_status", '')

    query_dict = {
        "task_id": int(task_id) if task_id else None,
    }
    

    filters = helpers.rmnullkeys(query_dict)

    flatten_filters = 'and '.join("{!s}={!r}".format(key, val)
                                for (key, val) in filters.items())
    cond_by= ''
    if mobile:
       cond_by= f' WHERE m.mobile={mobile} '
    # LIKE'%en%'
    cond_like= ''
    if sys_tags:
        if not mobile:
            cond_like=f"WHERE t.sys_tags LIKE'%{sys_tags}%' "
        else:
            cond_like=f" AND t.sys_tags LIKE'%{sys_tags}%' "

    if not order_status:
        where_cond = 'WHERE status> 0 '
    else:
        where_cond = f'WHERE status= {order_status} '
        
    if flatten_filters:
        where_cond += f" and {flatten_filters}"
        
        if start_time and end_time:
            where_cond +=f' and add_time>{start_time} or add_time<={end_time} '
    else:
        if start_time and end_time:
            where_cond +=f' and add_time>{start_time} or add_time<={end_time} '

    fetch_columns = "o.id,o.task_id,o.member_id,o.status as order_status,o.user_submit,o.add_time,o.submit_time,o.account_id,o.app_safe_info,o.safe_token,o.confidence, t.name as taskname,t.task_class, t.status as task_status, t.task_reward,t.deadline_time,m.nickname,m.realname,m.mobile,m.m_class,m.setreal,m.alipayid"
    
    p_i, p_num = (page_index-1) * page_size, page_size

    task_sql =f"SELECT {fetch_columns} FROM \
                    (SELECT * FROM et_task_orders {where_cond} ) AS o \
                    LEFT JOIN et_members AS m ON o.member_id =m.id \
                    LEFT JOIN et_tasks AS t ON o.task_id =t.id {cond_by} {cond_like} ORDER BY o.submit_time DESC LIMIT {p_i},{p_num} ;"
    
    task_counts_sql= f"SELECT {fetch_columns} FROM \
                    (SELECT * FROM et_task_orders {where_cond}) AS o \
                    LEFT JOIN et_members AS m ON o.member_id =m.id \
                    LEFT JOIN et_tasks AS t ON o.task_id =t.id {cond_by} {cond_like};"
    
    task_orders = db.session.execute(task_sql).fetchall()
    task_counts= db.session.execute(task_counts_sql).fetchall()

    res_data= dict()
    counts = db.session.execute(f"SELECT count(*) FROM et_task_orders {where_cond}").first()
    
    if task_orders:
        # result: RowProxy to dict 
        res_data['list'] =  [{key: value for (key, value) in row.items()} for row in task_orders]
        # logger.info(res_data['list'])      
        res_data['length'] = counts[0]

        res.update(code=ResponseCode.Success, data=res_data,
                   msg=f'{task_counts_sql}用户提交任务列表获取成功')
        return res.data
    else:

        res.update(code=ResponseCode.Success, data={}, msg=f'{task_sql}任务数据为空')
        return res.data
コード例 #29
0
ファイル: task_service.py プロジェクト: FreeGodCode/easytask
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