Esempio n. 1
0
def handle_lists():
    """
    获取用户列表
    :return: json
    """
    res = ResMsg()
    page_index = int(request.args.get("page", 1))
    page_size = int(request.args.get("limit", 10))

    users = db.session.query(EtAccount).limit(page_size).offset(
        (page_index - 1) * page_size).all()
    counts = db.session.execute("SELECT count(*) FROM et_accounts").first()
    res_data = dict()
    if users:
        res_data['list'] = helpers.model_to_dict(users)
        res_data['length'] = counts[0]
        res.update(code=ResponseCode.Success,
                   data=res_data,
                   msg=f'{type(users)}获取成功')

        return res.data
    else:
        res.update(code=ResponseCode.Success, data={}, msg='数据获取异常')

        return res.data
Esempio n. 2
0
def test_tree():
    """
    测试无限层级目录树
    :return:
    """
    res = ResMsg()
    data = [
        {"id": 1, "father_id": None, "name": "01"},
        {"id": 2, "father_id": 1, "name": "0101"},
        {"id": 3, "father_id": 1, "name": "0102"},
        {"id": 4, "father_id": 1, "name": "0103"},
        {"id": 5, "father_id": 2, "name": "010101"},
        {"id": 6, "father_id": 2, "name": "010102"},
        {"id": 7, "father_id": 2, "name": "010103"},
        {"id": 8, "father_id": 3, "name": "010201"},
        {"id": 9, "father_id": 4, "name": "010301"},
        {"id": 10, "father_id": 9, "name": "01030101"},
        {"id": 11, "father_id": 9, "name": "01030102"},
    ]

    new_tree = Tree(data=data)

    data = new_tree.build_tree()

    res.update(data=data)
    return res.data
Esempio n. 3
0
def test_wx_login_or_register():
    """
    测试微信登陆注册
    :return:
    """
    res = ResMsg()
    code = request.args.get("code")
    flag = request.args.get("flag")
    # 参数错误
    if code is None or flag is None:
        res.update(code=ResponseCode.InvalidParameter)
        return res.data
    # 获取微信用户授权码
    access_code = get_access_code(code=code, flag=flag)
    if access_code is None:
        res.update(code=ResponseCode.WeChatAuthorizationFailure)
        return res.data
    # 获取微信用户信息
    wx_user_info = get_wx_user_info(access_data=access_code)
    if wx_user_info is None:
        res.update(code=ResponseCode.WeChatAuthorizationFailure)
        return res.data

    # 验证微信用户信息本平台是否有,
    data = wx_login_or_register(wx_user_info=wx_user_info)
    if data is None:
        res.update(code=ResponseCode.Fail)
        return res.data
    res.update(data=data)
    return res.data
Esempio n. 4
0
def course_list():
    """
    获取课程列表
    :return:
    """
    res = ResMsg()
    obj = request.args
    stu_cls = db.session.query(StuCls).filter(StuCls.student_id == obj['sid']).all()
    classid_arr = []
    for sc in stu_cls:
        classid_arr.append(sc.class_id)
    cls_wd = db.session.query(ClsWd).filter(ClsWd.class_id.in_(classid_arr)).all()
    n_class = db.session.query(Class).filter(Class.id.in_(classid_arr)).all()
    weekSet = set([])
    for sw in cls_wd:
        weekSet.add(sw.weekday)
    course_list = {}
    for wd in weekSet:
        week_cls = []
        # 获取每周几的班级id列表
        for clswd in cls_wd:
            if clswd.weekday == wd:
                week_cls.append(clswd.class_id)
        cls_arr = []
        for wc in week_cls:
            for nc in n_class:
                if wc == nc.id:
                    cls_arr.append(nc)
        course_list[wd] = cls_arr
    res.update(data = {
        'course_list': course_list
    })
    return res.data
Esempio n. 5
0
def changes_tasks():
    """
    商户任务状态修改接口
    """
    res = ResMsg()
    task_id = request.args.get('task_id', '')
    u_pass = request.args.get('u_pass', '')
    rejected = request.args.get('rejected', '')
    preview = request.args.get('preview', '')
    shelves = request.args.get('shelves', '')
    comment = request.args.get('comment', '')

    where_cond = ''
    if u_pass != '':
        where_cond = 2
    elif rejected != '':
        where_cond = 5
        l_sql = f"UPDATA et_tasks_verify set comment={comment} where task_id={task_id}"
        db.session.execute(l_sql)
        db.session.commit()
    elif shelves != '':
        where_cond = 1
    task_sql = f"UPDATE et_tasks set status={where_cond} WHERE id={task_id}"
    db.session.execute(task_sql)
    res = db.session.commit()
    if res == 1:
        res.update(code=ResponseCode.Success, data={}, msg="修改成功")
        return res.data
    else:
        res.updata(code=ResponseCode, data={}, msg="修改失败,请稍后再试")
        return res.data
Esempio n. 6
0
def handle_login():
    """
    登录接口
    :return: json
    """
    res = ResMsg()
    req = request.get_json(force=True)
    
    username = req.get("username")
    password = req.get("password")
    password_hash = hash_password(password)
    now_timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    user = db.session.query(EtAccount).filter(EtAccount.name == username, 
            EtAccount.password==password_hash).first() 

    res_data= dict()
    if user:
        user = db.session.query(EtAccount.name).first()
        res_data.update(dict(zip(user.keys(), user)))
        
        db.session.query(EtAccount).filter(EtAccount.name == username).update({"last_login": now_timestr})

        access_token, refresh_token = Auth.encode_auth_token(user_id=username)

        res_data.update({"access_token": access_token.decode("utf-8"),
                            "refresh_token": refresh_token.decode("utf-8")})
        
        res.update(code=ResponseCode.LoginSuccess, data=res_data, msg=ResponseMessage.LoginSuccess)
        
        return res.data
    else:
        res.update(code=ResponseCode.LoginFail, data={}, msg=ResponseMessage.LoginFail)

        return res.data
Esempio n. 7
0
def handle_info():
    """
    账号详情
    :return: json
    """
    res = ResMsg()
    
    token = request.args.get("token")
    payload = Auth.decode_auth_token(token)
    userid= payload['user_id']

    res_data= dict()
    
    user = db.session.query(EtAccount.id, EtAccount.name, EtAccount.role_id, EtAccount.status).filter(EtAccount.name == userid).first()
    if user:
        res_data.update(dict(zip(user.keys(), user)))
        if res_data['role_id']== 1:
            res_data['roles']= ['admin']
            res_data['avatar']= 'https://qiniu.staticfile.org/user_avatar.jpg'
            del res_data['role_id']
        res.update(code=ResponseCode.Success, data=res_data, msg='账号获取成功')
        return res.data
    else:

        res.update(code=ResponseCode.Success, data={},msg='账户异常')
        return res.data
Esempio n. 8
0
def handle_info():
    """
    查询任务详情
    :return: json
    """
    res = ResMsg()

    page_index = int(request.args.get("page", 1))
    page_size = int(request.args.get("limit", 10))
    act_id = int(request.args.get("id", 10))
    p_i, p_num = (page_index - 1) * page_size, page_size

    act_info = db.session.query(EtActivity).filter(
        EtActivity.id == act_id).first()

    res_data = dict()

    if feedlist:
        res_data['data'] = helpers.model_to_dict(act_info)
        res.update(code=ResponseCode.Success, data=res_data, msg='活动获取成功')
        return res.data
    else:

        res.update(code=ResponseCode.Success, data={}, msg='活动数据为空or异常')
        return res.data
Esempio n. 9
0
def handle_upstatus():
    """
    活动更新状态信息
    :return: json
    """
    res = ResMsg()
    req = request.get_json(force=True)

    act_id = req.get("id", '')
    status = req.get("status", '')

    update_dict = {
        "status": status,
    }
    db.session.query(EtActivity).filter(
        EtActivity.id == act_id).update(update_dict)
    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
Esempio n. 10
0
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
Esempio n. 11
0
def add_dataset():
    req_json = request.get_json(force=True)

    res = ResMsg()
    result = es.index(index='news', doc_type='politics', body=req_json)
    res.update(data=result)
    return res.data
Esempio n. 12
0
def mercharnt_list():
    """
    获取商户列表
    :return: json
    """
    res = ResMsg()

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

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

    k = 'id, nickname, user_type, industry, status, last_login, ip, password, username, mobile'
    oem_sql = f"SELECT {k} FROM et_merchants ORDER BY last_login DESC LIMIT {p_i}, {p_num}"

    oem = db.session.execute(oem_sql).fetchall()
    res_data = dict()

    if oem:
        olists = [{k: v for (k, v) in row.items()} for row in oem]
        count_oem = olists
        res_data['list'] = olists
        res_data['length'] = len(count_oem)
        res.update(code=ResponseCode.Success,
                   data=res_data,
                   msg=f"{len(count_oem)}商户列表获取成功")
        return res.data
    else:
        res.update(code=ResponseCode.Success, data={}, msg="数据获取异常")
        return res.data
Esempio n. 13
0
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
Esempio n. 14
0
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
Esempio n. 15
0
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
Esempio n. 16
0
def removeClusterResult():
    """
    根据网点文件id,失效网点文件、聚类问件,聚类结果和网点结果
    """
    res = ResMsg()
    try:
        logger.info("begin removeClusterResult!")
        aiBusModel = AiBusModel()
        userInfo = session.get("userInfo")
        data = request.get_json()
        fileId = data["fileId"]
        aiBusModel.updateSiteFile((0, 0, userInfo["userName"], fileId))
        aiBusModel.updateSiteStatusByfieldId(
            (0, userInfo["userName"], fileId, 1))
        aiBusModel.updateClusterResultByFileId(
            (0, userInfo["userName"], fileId), [1, 2])
        #失效fileId对应的聚类文件
        siteParams = aiBusModel.selectClusterParamsBySiteFileId(
            (fileId))  ##根据网点文件fileId的查询网点文件
        if siteParams:
            aiBusModel.updateClusterResultByFileId(
                (0, userInfo["userName"], siteParams["id"]), [1, 2])
            aiBusModel.updateSiteFile(
                (0, 0, userInfo["userName"], siteParams["id"]))
        res.update(code=ResponseCode.Success, msg="成功删除网点聚类结果!")
        return res.data
    except Exception as e:
        logger.error("removeClusterResult exception:{}".format(str(e)))
        res.update(code=ResponseCode.Fail, msg="删除网点聚类结果报错!")
        return res.data
Esempio n. 17
0
def log_list():
    """
    获取日志列表
    :return:
    """
    current_app.logger.debug('aodifoads')
    res = ResMsg()
    obj = request.args
    n_user = db.session.query(User).all()
    n_teacher = db.session.query(Teacher).all()
    n_student = db.session.query(Student).all()
    n_class = db.session.query(Class).all()
    n_log = db.session.query(Log).filter(Log.student_id == obj['sid']).all()
    dataList = []
    for log in n_log:
        logObj = log
        for user in n_user:
            if user.id == log.operator_id:
                logObj.operator_name = user.nick_name
        for teacher in n_teacher:
            if teacher.id == log.teacher_id:
                logObj.teacher_name = teacher.name
        for student in n_student:
            if student.id == log.student_id:
                logObj.student_name = student.name
        for cls in n_class:
            if cls.id == log.class_id:
                logObj.class_name = cls.class_name
        dataList.append(logObj)
    data = {dataList: dataList}
    res.update(data=data)
    return res.data
Esempio n. 18
0
def get_user_customers():
    res = ResMsg()

    user_name = session["user_name"]
    if not user_name:
        res.update(ResponseCode.InvalidParameter)
        return res.data

    user_obj = db.session.query(User).filter(
        User.username == user_name).first()
    customers_json = []
    if user_obj and user_obj.customers:
        for customer_obj in user_obj.customers:
            incomes_json = []
            if customer_obj.incomes:
                incomes_json = model_to_dict(customer_obj.incomes)
            customer_json = model_to_dict(customer_obj)
            customer_json["incomes"] = incomes_json
            customers_json.append(customer_json)

    user = model_to_dict(user_obj)
    user["customers"] = customers_json
    res.update(data=user)

    return res.data
Esempio n. 19
0
def send_email():
    """
    发送邮件
    :return:
    """
    res = ResMsg()

    user_name = session["user_name"]
    customer_id = request.form.get("customer_id")
    file = request.files['file']
    if not user_name or not customer_id or not file:
        res.update(code=ResponseCode.InvalidParameter)
        return res.data

    user = db.session.query(User).filter(User.username == user_name).first()
    customer = db.session.query(Customer).filter(
        Customer.id == customer_id).first()
    restult = EmailSender.send_email(customer.email, user.username, user.email,
                                     file.stream.read(), file.filename)

    if not restult:
        res.update(code=ResponseCode.SendEmailFailed)
        return res.data

    return res.data
Esempio n. 20
0
def banners_lists():
    """
    banners列表
    :return: json
    """

    res = ResMsg()

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

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

    data_sql = f"SELECT * FROM et_banner WHERE status != 1 ORDER BY show_time ASC LIMIT {p_i}, {p_num}"

    data_list = db.session.execute(data_sql)
    res_data = dict()

    if data_list:
        b_lists = [{k: v for (k, v) in row.items()} for row in data_list]
        count_b = b_lists
        res_data['list'] = b_lists
        res_data['length'] = len(count_b)
        res.update(code=ResponseCode.Success,
                   data=res_data,
                   msg=f"{len(count_b)}banner获取成功")
        return res.data
    else:
        res.update(code=ResponseCode.Success, data={}, msg="数据获取异常")
        return res.data
Esempio n. 21
0
def d_banner():
    """
    删除banner
    :return: json
    """

    res = ResMsg()
    req = request.get_json(force=True)

    banner_id = req.get('id')
    status = req.get('status')

    d_sql = f"UPDATE et_banner set status={status} WHERE id={int(banner_id)}"

    d_ex = db.session.execute(d_sql)

    try:
        db.session.commit()
        if status == 1:
            msg = "删除成功!"
        else:
            msg = "更改成功!"
        res.update(code=ResponseCode.Success, data={}, msg=msg)
        return res.data
    except Exception as why:
        res.update(code=ResponseCode.Success, data={}, msg=f"删除异常{why}")
        return res.data
Esempio n. 22
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
Esempio n. 23
0
def handle_stats_dashborad():
    """
    基本业务统计
    今日新用户 et_members
    今日任务提交 et_task_orders
    今日分销数 et_member_drps
    今日提现 et_member_withdrawal
    DAU -7days 
    :return: json
    """
    res = ResMsg()
    id = request.args.get("id", 1)

    member_sql = 'select count(id) as num from et_members  where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(reg_time);'
    task_orders_sql = 'select count(id) as num from et_task_orders where status>1 and DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(add_time);'
    member_drps_sql = 'select count(id) as num from et_member_drps where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(add_time);'
    member_wd_sql = 'select count(id) as num from et_member_withdrawal where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(start_time);'

    new_mems = db.session.execute(member_sql).first()
    new_task_orders = db.session.execute(task_orders_sql).first()
    member_drps = db.session.execute(member_drps_sql).first()
    member_wds = db.session.execute(member_wd_sql).first()

    res_data = dict()

    stats = {}
    stats['m'] = new_mems[0]
    stats['o'] = new_task_orders[0]
    stats['d'] = member_drps[0]
    stats['w'] = member_wds[0]
    res_data['infos'] = stats

    res.update(code=ResponseCode.Success, data=res_data, msg=f'获取成功')
    return res.data
Esempio n. 24
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
Esempio n. 25
0
def handle_feedlist():
    """
    获取app反馈信息列表
    :return: json
    """
    res = ResMsg()

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

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

    feedlist = db.session.execute(
        f"SELECT * FROM et_feedbacks ORDER BY add_time DESC LIMIT {p_i},{p_num}"
    ).fetchall()

    counts = db.session.execute("SELECT count(*) FROM et_feedbacks").first()
    res_data = dict()

    if feedlist:
        res_data['list'] = [{key: value
                             for (key, value) in row.items()}
                            for row in feedlist]
        res_data['length'] = counts[0]
        res.update(code=ResponseCode.Success,
                   data=res_data,
                   msg='app用户反馈列表获取成功')
        return res.data
    else:

        res.update(code=ResponseCode.Success, data={}, msg='app用户反馈信息数据为空or异常')
        return res.data
Esempio n. 26
0
def handle_applist():
    """
    获取app发布列表
    :return: json
    """
    res = ResMsg()

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

    applist = db.session.query(EtAppsPubHistory).limit(page_size).offset(
        (page_index - 1) * page_size).all()
    counts = db.session.execute(
        "SELECT count(*) FROM et_apps_pub_history").first()
    res_data = dict()

    if applist:
        res_data['list'] = helpers.model_to_dict(applist)
        res_data['length'] = counts[0]
        res.update(code=ResponseCode.Success, data=res_data, msg='app发布列表获取成功')
        return res.data
    else:

        res.update(code=ResponseCode.Success, data={}, msg='app发布列信息数据为空or异常')
        return res.data
Esempio n. 27
0
 def get(self, key=None):
     """
     获取列表或单条数据
     :param key:
     :return:
     """
     res = ResMsg()
     if key is not None:
         data = self.parse_data(self._get(key=key))
         if data:
             res.update(data=data)
         else:
             res.update(code=ResponseCode.NoResourceFound)
     else:
         query, by = self._parse_query_field()
         page, size = self._parse_page_size()
         cnt, data = self._find_by_page(page=page,
                                        size=size,
                                        query=query,
                                        by=by)
         data = self.parse_data(data)
         if data:
             res.update(data=data)
         else:
             res.update(code=ResponseCode.NoResourceFound)
         res.add_field(name='total', value=cnt)
         res.add_field(name='page', value=page + 1)
         res.add_field(name='size', value=size)
         res.update(data=data)
     return res.data
Esempio n. 28
0
def get_clients():
    res = ResMsg()

    name = session["user_name"]
    user_obj = User.query.filter(User.name == name).first()
    res.update(data=model_to_dict(user_obj.clients))

    return res.data
Esempio n. 29
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
Esempio n. 30
0
def test_unified_response():
    """
    测试统一返回消息
    :return:
    """
    res = ResMsg()
    test_dict = dict(name="zhang", age=18)
    res.update(code=ResponseCode.Success, data=test_dict)
    return jsonify(res.data)