Пример #1
0
 def get(self):
     # 获取当前用户iiuv
     m = MysqlSearch().get_one(f"SELECT iiuv FROM {MEMBERS_TABLE} WHERE ID='{g.user_id}'")
     # 获取风险域名
     y = MysqlSearch().get_one(f"SELECT domains FROM {ET_GLOBAL_CONFIG}")
     if y['domains'] is not None:
         ym = y['domains'].split(',')[0]
         # 拼接url返回
         res = ym + "/" + m['iiuv']
         # 查询当前用户余额/点击更换链接的费用/乐观锁解决修改用户余额
         version_time = time.time()
         m = MysqlSearch().get_one(f"SELECT balance,balance_version FROM {MEMBERS_TABLE} WHERE id='{g.user_id}'")
         if m['balance'] < 10:
             return {'error': '无法切换,切换费用不足'}, HttpStatus.OK.value
         try:
             u = MysqlWrite().write(
                 f"UPDATE {MEMBERS_TABLE} SET balance=balance - 10,balance_version='{version_time}' WHERE balance_version='{m['balance_version']}' and id='{g.user_id}'")
         except Exception:
             return {'error': '请稍后重试'}, HttpStatus.OK.value
         if u == 1:
             # 更新出账表信息
             MysqlWrite().write(f"INSERT INTO {ET_MEMBER_EARNINGS} (out_amounts,member_id) VALUE ('{10}','{g.user_id}')")
             rc = current_app.redis_cli
             rc.delete('user_center:{}'.format(g.user_id))
             # 生成用户个人中心缓存信息
             UserCentreCache().get()
             return {'data': res}, HttpStatus.OK.value
         else:
             return {'error': '请稍后尝试'}, HttpStatus.OK.value
Пример #2
0
 def post(self):
     """单独邀请接口"""
     parser = reqparse.RequestParser()
     parser.add_argument('iiuv', type=str, required=True, location='json')
     args = parser.parse_args()
     iiuv = args.iiuv
     if iiuv:
         # 查询当前iiuv是否正确
         ii = MysqlSearch().get_one(
             f"SELECT ID FROM {MEMBERS_TABLE} WHERE IIUV='{args.iiuv}'")
         if ii is False:
             return {'error': '无此用户,请重新输入'}, HttpStatus.OK.value
         # todo 判断当前用户是否顶级用户
         res = intercept()
         if res and res >= 1:
             return {'error': '此用户已到达邀请限制,无法进行邀请绑定'}
         # 查询当前用户是否有父级或者子级
         u = MysqlSearch().get_one(
             f"SELECT top_parent_id,parent_id FROM {ET_MEMBER_RELATIONS} WHERE member_id={g.user_id}"
         )
         if u['parent_id'] != g.user_id:
             return {'error': '已绑定过邀请人,无法重复绑定'}, HttpStatus.OK.value
         # 否则正常绑定
         res = MemberRelationTreeCache().tree(g.mobile, iiuv)
         if res is True:
             # 删除缓存
             rc = current_app.redis_cli
             rc.delete(f'user_center:{g.user_id}')
             return {'data': '绑定成功'}, HttpStatus.OK.value
         else:
             return {'error': '绑定邀请网络繁忙,请稍后再试'}, HttpStatus.OK.value
Пример #3
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('amount', type=int, required=True, location='json')
     args = parser.parse_args()
     # 判断当前用户是否已经领取该奖金
     w = MysqlSearch().get_one(f"SELECT pay_status FROM {ACTIVITY_REWARDS} WHERE member_id='{g.user_id}'")
     if w is False or w['pay_status'] == 1:
         return {'error_code': 4003, 'msg': '改奖励已领取/没有奖金可领'}, HttpStatus.OK.value
     if not args.amount:
         return {'error_code': 4003, 'msg:': '参数异常'}, HttpStatus.OK.value
     # 乐观锁解决修改用户余额
     l = MysqlSearch().get_one(
         f"SELECT balance,balance_version FROM {MEMBERS_TABLE} WHERE id='{g.user_id}'")
     ye = int(args.amount * 100)
     # 生成20位随机字符串
     salt = ''.join(random.sample(string.ascii_letters + string.digits, 20))
     version_time = str(time.time()) + salt
     try:
         u = MysqlWrite().write(
             f"UPDATE {MEMBERS_TABLE} SET balance='{ye}',balance_version='{version_time}' WHERE balance_version='{l['balance_version']}' and id='{g.user_id}'")
         if u == 1:
             # 删除用户余额缓存
             rc = current_app.redis_cli
             rc.delete(f'user_center:{g.user_id}')
             # 修改当前用户是否已领取该奖金
             x = MysqlWrite().write(f"UPDATE {ACTIVITY_REWARDS} SET pay_status=1 WHERE member_id='{g.user_id}'")
             if x == 1:
                 return {'code': 2001, 'msg': '领取成功!'}, HttpStatus.OK.value
             else:
                 return {'error_code': 4001, 'msg': '服务器异常,请稍后再试'}, HttpStatus.OK.value
         else:
             return {'error_code': 4001, 'msg': '服务器异常,请稍后再试'}, HttpStatus.OK.value
     except Exception:
         return {'error_code': 4001, "msg": '请稍后重试'}, HttpStatus.OK.value
Пример #4
0
 def get(self):
     """
     获取用户状态
     :return:
     """
     rc = current_app.redis_cli
     try:
         user_info = current_app.redis_cli.hget(self.user_info_key,
                                                self.key)
     except RedisError as e:
         current_app.logger.error(e)
         user_info = None
     if user_info is not None:
         return json.loads(user_info.decode())
     else:
         try:
             sql = f"SELECT * FROM {MEMBERS_TABLE} WHERE mobile='{self.mobile}'"
             user_data = MysqlSearch().get_one(sql)
             user_info = dict()
             for k, v in user_data.items():
                 if k == "reg_time" or k == "logout_time":
                     continue
                 user_info[k] = v
         except Exception as e:
             current_app.logger.error(e)
         if user_info:
             self.save(user_info)
             return user_info
         else:
             return False
Пример #5
0
 def get(self):
     # 查询当前用户是否已领取开屏红包
     w = MysqlSearch().get_one(
         f"SELECT task_id FROM {ET_MEMBER_EARNINGS} WHERE task_id=1 and member_id={g.user_id}"
     )
     if w:
         return {'error_code': 4003, "msg": "当前用户已领取开屏红包"}, 200
     # 乐观锁解决修改用户余额
     l = MysqlSearch().get_one(
         f"SELECT balance,balance_version,mobile FROM {MEMBERS_TABLE} WHERE id='{g.user_id}'"
     )
     version_time = time.time()
     try:
         u = MysqlWrite().write(
             f"UPDATE {MEMBERS_TABLE} SET balance=balance+100,balance_version='{version_time}' WHERE balance_version='{l['balance_version']}' and id='{g.user_id}'"
         )
     except Exception:
         return {'error': '请稍后重试'}, HttpStatus.OK.value
     # 删除个人中心和用户信息缓存
     rc = current_app.redis_cli
     rc.delete(f"user_info_:{l['mobile']}")
     rc.delete(f"user_center:{g.user_id}")
     rc.delete(f"user_task_earnings_:{g.user_id}")
     UserCache(l["mobile"]).get()
     # 增加实名1元收益明细
     # 添加时间
     add_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
     smsy = MysqlWrite().write(
         f"INSERT INTO {ET_MEMBER_EARNINGS} (member_id,task_id,add_time,amounts) VALUE ('{g.user_id}',1,'{add_time}',1)"
     )
     return {"code": 2001}, 200
Пример #6
0
 def get(self):
     # 取出drp_config表里面的withdrawal_condition字段组装数据返回
     sql_charge = f"SELECT handling_fee,daily_withdrawal,min_money,withdrawal_condition FROM {ET_DRP_CONFIG}"
     res = MysqlSearch().get_more(sql_charge)
     # 查询当前用户余额
     y = MysqlSearch().get_one(
         f"SELECT balance FROM {MEMBERS_TABLE} WHERE ID='{g.user_id}'")
     user_carry_money = dict()
     if res:
         charge = res[-1]
         user_carry_money = json.loads(charge['withdrawal_condition'])
         user_carry_money['手续费'] = charge['handling_fee']
         user_carry_money['最小提现金额'] = charge['min_money']
         user_carry_money['可提现次数'] = charge['daily_withdrawal']
     if y['balance'] is None:
         user_carry_money['钱包余额'] = 0
     else:
         user_carry_money['钱包余额'] = y['balance'] / 100
     # 查询当前用户邀请的人数
     son_member = MysqlSearch().get_more(
         f"SELECT member_id FROM {ET_MEMBER_RELATIONS} WHERE parent_id='{g.user_id}'"
     )
     if son_member is not None:
         member_count = 80
         for son in son_member:
             if son['member_id'] != g.user_id:
                 member_count += 1
         user_carry_money['邀请人数'] = member_count
         return {'data': user_carry_money}, HttpStatus.OK.value
Пример #7
0
 def get(self):
     """获取用户个人中心信息缓存"""
     rc = current_app.redis_cli
     try:
         user_center = rc.hget(self.user_center_key, self.key)
     except RedisError as e:
         current_app.logger.error(e)
         user_center = None
     if user_center:
         return json.loads(user_center.decode())
     else:
         try:
             user_center = dict()
             # 查询当前app版本号
             config = MysqlSearch().get_more(
                 f"SELECT version,update_status,down_url FROM {ET_APPS_PUB_HISTORY}"
             )
             if config:
                 new_config = config[-1]
                 config_data = dict()
                 user_center['当前系统版本'] = new_config['version']
             # 用户uuid
             sql_user = f"SELECT nickname,avatar,IIUV,balance,mobile,setreal,alipayid FROM {MEMBERS_TABLE} WHERE ID='{g.user_id}'"
             user = MysqlSearch().get_one(sql_user)
             if user['alipayid'] is None:
                 user_center['支付宝状态'] = 0
             else:
                 user_center['支付宝状态'] = 1
             # 用户资金收益
             sql_earnings = f"SELECT sum(amounts) FROM {ET_MEMBER_EARNINGS} WHERE member_id='{g.user_id}'"
             # {'sum(amounts)': Decimal('300')}
             earnings = MysqlSearch().get_one(sql_earnings)
             # 查询我的邀请人
             m = MysqlSearch().get_one(
                 f"SELECT IIUV FROM {MEMBERS_TABLE} WHERE id in (SELECT parent_id FROM {ET_MEMBER_RELATIONS} WHERE member_id='{g.user_id}')"
             )
             if m is False or m['IIUV'] == user['IIUV']:
                 user_center['我的邀请人'] = ""
             else:
                 user_center['我的邀请人'] = m['IIUV']
             user_center['手机号码'] = int(user['mobile'])
             user_center['用户名称'] = user['nickname']
             user_center['头像'] = user['avatar']
             user_center['邀请码'] = user['IIUV']
             user_center['余额'] = user['balance'] / 100
             user_center['邀请链接'] = get_short_link(user['IIUV'])
             user_center['实名状态'] = user['setreal']
             if earnings['sum(amounts)'] is not None:
                 user_center['总收益'] = str((earnings['sum(amounts)']))
             else:
                 user_center['总收益'] = str(0)
             user_center['用户邀请权限'] = intercept()
         except Exception as e:
             current_app.logger.error(e)
         if user_center:
             self.save(user_center)
             return user_center
         else:
             return False
Пример #8
0
 def post(self):
     """用户提交任务"""
     parser = reqparse.RequestParser()
     parser.add_argument('task_id',
                         type=int,
                         required=True,
                         location='json')
     parser.add_argument('json_data',
                         type=dict,
                         required=True,
                         location='json')
     args = parser.parse_args()
     if args.json_data:
         if args.json_data['imgs'] == []:
             return {'code': 4002, 'msg': '请上传图片'}
     # todo 4月1号晚上修改格式
     # 要json数据入库,接收的类型必须是dict然后转str,不然会一直报错.可能需要flask的json,
     new_data = json.dumps(args.json_data).replace("'", '"')
     #     new_data = json.dumps(data)
     # 是否接过此任务
     t = MysqlSearch().get_more(
         f"SELECT task_id FROM {ET_TASK_ORDERS} WHERE member_id='{g.user_id}'"
     )
     if {'task_id': args.task_id} not in t:
         return {'error': '请先领取改任务'}, HttpStatus.OK.value
     # 查询当前接任务的时间
     r = MysqlSearch().get_one(
         f"SELECT add_time FROM {ET_TASK_ORDERS} WHERE task_id='{args.task_id}'"
     )
     # 获取任务最后结束时间, 查询当前任务deadline_time
     task_end_time = MysqlSearch().get_one(
         f"SELECT end_time,deadline_time FROM {TASKS_TABLE} WHERE id='{args.task_id}'"
     )
     end_time = task_end_time['end_time'].strftime("%Y-%m-%d-%H-%M-%S")
     now_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
     # 通过接任务的时间+任务deadline时间l
     # a = (r['add_time'] + datetime.timedelta(hours=int(task_end_time['deadline_time']))).strftime("%Y-%m-%d-%H-%S-%M")
     # todo >
     if now_time > (r['add_time'] + datetime.timedelta(
             hours=int(task_end_time['deadline_time']))
                    ).strftime("%Y-%m-%d-%H-%S-%M"):
         return {'error': '该任务已超过做单时间,无法提交'}, HttpStatus.OK.value
     # todo <
     if end_time < now_time:
         return {'error': '该任务已超过结束时间,无法提交'}, HttpStatus.OK.value
     else:
         # 更新order表数据
         sql = f"UPDATE {ET_TASK_ORDERS} SET status=2,user_submit='{new_data}',submit_time='{now_time}' WHERE member_id={g.user_id} AND task_id='{args.task_id}'"
         res = MysqlWrite().write(sql)
         if res == 1:
             # 更新任务数量
             # 删除用户任务详情缓存
             rc = current_app.redis_cli
             rc.delete('user_tasks_:{}'.format(g.user_id))
             return {'data': '提交成功'}, HttpStatus.OK.value
         else:
             return {"error": '提交失败,尝试再次提交'}, HttpStatus.OK.value
Пример #9
0
 def post(self):
     """用户接任务"""
     parser = reqparse.RequestParser()
     parser.add_argument('task_id', type=int, required=True, location='json')
     parser.add_argument('app_safe_info', type=dict, required=True, location='json')
     args = parser.parse_args()
     # 要json数据入库,接收的类型必须是dict然后转str,不然会一直报错.可能需要flask的json,
     new_data = json.dumps(args.app_safe_info).replace("'", '"')
     # 判断此任务是否还有剩余数量
     # 判断用户是否已经提现成功
     tx = MysqlSearch().get_one(f"SELECT verify FROM {ET_MEMBER_WITHDRAWAL} WHERE member_id='{g.user_id}' and verify=2")
     current_app.logger.error(tx)
     if tx is None:
         return {"error": "请进行新手提现成功再领取任务"}
     sy = MysqlSearch().get_one(f"SELECT tasks_counts,count_tasks,check_router FROM {TASKS_TABLE} WHERE id='{args.task_id}'")
     if sy['tasks_counts'] == sy['count_tasks']:
         return {'error_code': 4003, 'msg': '此任务无法领取.数量不足'}
     task_status = current_app.redis_cli.sismember('cancel_tasks_{}'.format(g.user_id), args.task_id)
     if task_status is True:
         return {'error': '此任务用户已取消过, 24小时内不能在领取'},HttpStatus.OK.value
     complete_task = current_app.redis_cli.sismember('complete_tasks_{}'.format(g.user_id), args.task_id)
     if complete_task is True:
         return {'error': '此任务用户已领取'}, HttpStatus.OK.value
     else:
         now_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
         # todo  'http://' + '47.113.91.65:5007' 添加到config配置项
         current_app.logger.error(sy['check_router'])
         safe_token = global_config.getRaw('Invite_link', 'EWM_LINK') + f'?td={args.task_id}&fromu={g.user_id}&ref={sy["check_router"]}'
         current_app.logger.error(safe_token)
         sql = f"INSERT INTO {ET_TASK_ORDERS} (task_id,member_id,status,add_time,app_safe_info,safe_token) VALUE ('{args.task_id}','{g.user_id}',1,'{now_time}','{new_data}','{safe_token}')"
         res = MysqlWrite().write(sql)
         if res == 1:
             # 更新任务剩余数量
             r = MysqlWrite().write(f"UPDATE {TASKS_TABLE} SET count_tasks=count_tasks + 1 WHERE ID='{args.task_id}'")
             # redis操作
             rc = current_app.redis_cli
             # 删除用户任务缓存
             rc.delete('user_tasks_:{}'.format(g.user_id))
             # 删除任务缓存
             rc.delete('tasks_info')
             # 删除用户任务的缓存
             rc.delete('user_tasks_:{}'.format(g.user_id))
             rc.sadd('complete_tasks_:{}'.format(args.task_id),g.user_id)
             # 向已领取任务redis中添加数据
             rc.sadd('fetch_tasks_:{}'.format(args.task_id), g.user_id)
             # 删除任务详情缓存
             rc.delete("tasks_detail_:{}".format(args.task_id))
             # 删除用户任务总列表数据
             rc.delete(f"tasks_info_{g.user_id}")
             return {'data': '添加任务完成'}, HttpStatus.OK.value
         else:
             return {'error': '任务获取失败,请重试'}, HttpStatus.OK.value
Пример #10
0
 def wrapper(*args, **kwargs):
     r = MysqlSearch().get_one(
         f"SELECT member_id FROM {ET_MEMBER_WITHDRAWAL} WHERE member_id='{g.user_id}'"
     )
     if not r:
         return {'error': '请完成新手提现任务'}, HttpStatus.OK.value
     return func(*args, **kwargs)
Пример #11
0
 def get(self):
     """返回当前app版本号"""
     parser = reqparse.RequestParser()
     parser.add_argument('app_version', type=str, location='args')
     args = parser.parse_args()
     if args.app_version:
         up = MysqlSearch().get_more(
             f"SELECT version,down_url,update_time,up_logs,update_status FROM {ET_APPS_PUB_HISTORY} WHERE osversion='{args.appversion}'"
         )
         app_version = dict()
         if up[-1]:
             for i in up:
                 app_version['app版本号'] = i['version'],
                 app_version['app下载url'] = i['down_url'],
                 app_version['更新日期'] = i['update_time'].strftime(
                     "%Y-%m-%d-%H-%M-%S")
                 app_version['更新日志'] = i['up_logs']
                 app_version['更新状态'] = i['update_status']
         return {'data': app_version}, HttpStatus.OK.value
     else:
         ios = MysqlSearch().get_more(
             f"SELECT version,down_url,update_time,up_logs,update_status FROM {ET_APPS_PUB_HISTORY} WHERE osversion='ios'"
         )
         android = MysqlSearch().get_more(
             f"SELECT version,down_url,update_time,up_logs,update_status FROM {ET_APPS_PUB_HISTORY} WHERE osversion='android'"
         )
         app_version_ios = dict()
         app_version = dict()
         app_version_list = list()
         for i in ios:
             app_version_ios['app版本号'] = i['version'],
             app_version_ios['app下载url'] = i['down_url'],
             app_version_ios['更新日期'] = i['update_time'].strftime(
                 "%Y-%m-%d-%H-%M-%S")
             app_version_ios['更新日志'] = i['up_logs']
             app_version_ios['更新状态'] = i['update_status']
         app_version_list.append(app_version_ios)
         for k in android:
             app_version['app版本号'] = k['version'],
             app_version['app下载url'] = k['down_url'],
             app_version['更新日期'] = k['update_time'].strftime(
                 "%Y-%m-%d-%H-%M-%S")
             app_version['更新日志'] = k['up_logs']
             app_version['更新状态'] = k['update_status']
         json_data = {'ios': app_version_ios, 'android': app_version}
         return {'data': json_data}, HttpStatus.OK.value
Пример #12
0
 def get(self):
     config = MysqlSearch().get_more(f"SELECT banners,rules,helpers FROM {ET_GLOBAL_CONFIG}")
     if config:
         new_config = config[-1]
         config_data = dict()
         config_data['广告'] = new_config['banners']
         config_data['提现规则'] = new_config['rules']
         config_data['帮助中心'] = new_config['helpers']
         return {'data': config_data}, HttpStatus.OK.value
Пример #13
0
 def get(self):
     """获取用户意见"""
     y = MysqlSearch().get_one(
         f"SELECT feedback,add_time FROM {ET_FEEDBACKS} WHERE member_id='{g.user_id}'"
     )
     data = dict()
     data["feedback"] = y['feedback']
     data["add_time"] = y['add_time']
     return {'data': data}, HttpStatus.OK.value
Пример #14
0
    def post(self):
        """获取任务列表"""
        parser = reqparse.RequestParser()
        parser.add_argument('kw', type=str, required=True, location='json')
        parser.add_argument('page_index',
                            type=int,
                            required=True,
                            location='json')
        parser.add_argument('page_size',
                            type=int,
                            required=True,
                            location='json')
        args = parser.parse_args()
        p_i, p_num = (args.page_index - 1), args.page_size
        tasks_data = TasksCache().get(p_i, p_num)

        if args.kw == 'high':
            # 检查当前用户是否高级用户
            user_info = 'user_info_:{}'.format(g.mobile)
            user_class_redis = current_app.redis_cli.hget(user_info, 0)
            if user_class_redis:
                user_class = json.loads(user_class_redis.decode())['m_class']
                if user_class != 2:
                    # TODO 查询当前用户任务数量 现在暂时查库,后期缓存
                    tasks = dict()
                    l = MysqlSearch().get_one(
                        f"SELECT task_limit FROM {ET_GLOBAL_CONFIG}")
                    u = MysqlSearch().get_one(
                        f"SELECT count(task_id) FROM {ET_TASK_ORDERS} WHERE member_id='{g.user_id}' AND status=4"
                    )
                    if u['count(task_id)']:
                        tasks['已做任务'] = int(u['count(task_id)'])
                    else:
                        tasks['已做任务'] = 0
                    tasks['升级需要'] = l['task_limit']
                    return {'error': tasks}, HttpStatus.OK.value
                else:
                    return {'data': tasks_data}, HttpStatus.OK.value
            else:
                return {'error': 'no authority'}, HttpStatus.OK.value
        elif args.kw == "general":
            return {'data': tasks_data}, HttpStatus.OK.value
        else:
            return {'error': 'bad parameter'}, HttpStatus.OK.value
Пример #15
0
 def get(self):
     """
     获取任务详情缓存
     :return:
     """
     rc = current_app.redis_cli
     try:
         tasks_detail = rc.hget(self.tasks_detail_key, self.key)
     except RedisError as e:
         current_app.logger.error(e)
         tasks_detail = None
     if tasks_detail is not None:
         return json.loads(tasks_detail.decode())
     else:
         current_app.logger.info(self.tasks_id)
         # 查询任务详情内容
         sql = f"SELECT task_class,recommend,tags,allow_nums,end_time,task_reward,name,poster_img,task_info,task_steps,virtual_nums,begin_task_time,deadline_time,count_tasks,tasks_counts,check_router FROM {TASKS_TABLE} WHERE ID={self.tasks_id}"
         res = MysqlSearch().get_one(sql)
         # 计算任务剩余数
         tasks_count = res['tasks_counts'] - res['count_tasks']
         # 计算审核时间
         times = str(res['end_time'] - res['begin_task_time']).split(':')
         if len((times[0] + '时' + times[1] + '分').split(',')) > 1:
             audit_time = (times[0] + '时' + times[1] + '分').split(',')[1]
         else:
             audit_time = (times[0] + '时' + times[1] + '分').split(',')[0]
         current_app.logger.info(audit_time)
         tasks_detail = dict()
         tasks_detail['审核时间'] = audit_time
         tasks_detail['任务数量'] = tasks_count
         tasks_detail['开始时间'] = res['begin_task_time'].strftime(
             "%Y-%m-%d-%H-%M-%S")
         tasks_detail['做单时间'] = res['deadline_time']
         tasks_detail['截止时间'] = res['end_time'].strftime(
             "%Y-%m-%d-%H-%M-%S")
         tasks_detail['任务奖励'] = res['task_reward']
         tasks_detail['任务名称'] = res['name']
         tasks_detail['任务头像'] = res['poster_img']
         tasks_detail['任务说明'] = res['task_info']
         tasks_detail['任务步骤'] = res['task_steps']
         tasks_detail['人气'] = res['virtual_nums']
         tasks_detail['标签'] = res['tags']
         tasks_detail['推荐'] = res['recommend']
         tasks_detail['任务类型'] = res['task_class']
         tasks_detail['任务完成数量'] = res['count_tasks'] + int(
             res['virtual_nums'])
         # 加密二维码链接
         ref_data = 'http://' + '47.113.91.65:5007' + '/share_jump' + f'?td={self.tasks_id}&ref={res["check_router"]}'
         base_url = base64.b64encode(ref_data.encode()).decode()
         tasks_detail['rwmlj'] = base_url
         if tasks_detail:
             self.save(tasks_detail)
             return tasks_detail
         else:
             return False
Пример #16
0
 def get(self):
     # 查询iiuv邀请码
     parser_data = reqparse.RequestParser()
     parser_data.add_argument('iiuv', type=str, required=True)
     args = parser_data.parse_args()
     # 查询风险域名
     fx = MysqlSearch().get_one(f"SELECT domains FROM {ET_GLOBAL_CONFIG}")
     ym = fx['domains'].split(',')[0]
     code = '?invite_code=+haozhuan+' + args.iiuv
     url = 'http://' + ym + code
     return redirect(url, 302)
Пример #17
0
    def get(self):
        """获取用户提现信息缓存"""
        rc = current_app.redis_cli
        try:
            user_recode = rc.lrange(self.user_withdraw_recode_key, 0, -1)
        except RedisError as e:
            current_app.logger.error(e)
            user_recode = None
        if user_recode:
            return json.loads(user_recode[0].decode())
        else:
            try:
                # 查询当前用户提现流水
                sql = f"SELECT withdrawal_type,start_time,amounts,verify FROM {ET_MEMBER_WITHDRAWAL} \
                            WHERE member_id='{g.user_id}' order by start_time desc"

                res_list = MysqlSearch().get_more(sql)
                # 查询提现手续费,计算出手续费金额返回
                s = MysqlSearch().get_more(
                    f"SELECT handling_fee FROM {ET_DRP_CONFIG}")[-1]
                user_recode = []
                for res in res_list:
                    user_recode.append({
                        '提现方式':
                        res['withdrawal_type'],
                        '提现时间':
                        res['start_time'].strftime("%Y-%m-%d %H:%M:%S"),
                        '提现金额':
                        res['amounts'],
                        '审核状态':
                        res['verify'],
                        '提现手续费':
                        s['handling_fee'],
                    })
            except Exception as e:
                current_app.logger.error(e)
            if user_recode:
                self.save(user_recode)
                return user_recode
            else:
                return False
Пример #18
0
 def get(self):
     """获取用户个人收益缓存"""
     rc = current_app.redis_cli
     try:
         user_earnings = rc.lrange(self.user_earnings_key, 0, -1)
     except RedisError as e:
         print('RedisError:{}'.format(e))
         user_earnings = None
     if user_earnings:
         return json.loads(user_earnings[0].decode())
     else:
         try:
             user_earnings = []
             # 任务id对应的名称
             sql_tasks_name = f"SELECT name FROM {TASKS_TABLE} WHERE id IN (SELECT task_id FROM {ET_MEMBER_EARNINGS} WHERE member_id='{g.user_id}')"
             tasks_name = MysqlSearch().get_more(sql_tasks_name)
             # 用户流水资料
             sql_info = f"SELECT task_order_id,add_time,amounts FROM {ET_MEMBER_EARNINGS} WHERE member_id='{g.user_id}' order by add_time asc;"
             info = MysqlSearch().get_more(sql_info)
             for k, v in zip(tasks_name, info):
                 user_earnings.append({
                     '流水号':
                     v['task_order_id'],
                     '任务名称':
                     k['name'],
                     '完成时间':
                     v['add_time'].strftime("%Y-%m-%d-%H-%M-%S"),
                     '奖励金额':
                     v['amounts'] / 100
                 })
         except Exception as e:
             current_app.logger.error(e)
         if user_earnings:
             user_list = user_earnings.sort(reverse=True)
             self.save(user_list)
             return user_list
         else:
             return False
Пример #19
0
    def get(self):
        """
        获取任务详情缓存
        :return:
        """
        rc = current_app.redis_cli
        try:
            tasks_detail = rc.hget(self.tasks_detail_key, self.key)
        except RedisError as e:
            current_app.logger.error(e)
            tasks_detail = None
        if tasks_detail is not None:
            return json.loads(tasks_detail.decode())
        else:
            current_app.logger.info(self.tasks_id)
            # 查询任务详情内容
            sql = f"SELECT task_class,recommend,tags,allow_nums,end_time,task_reward,name,poster_img,task_info,\
            task_steps,virtual_nums,begin_task_time,deadline_time,count_tasks,tasks_counts FROM {TASKS_TABLE} \
            WHERE ID={self.tasks_id}"

            res = MysqlSearch().get_one(sql)
            # 计算任务剩余数
            tasks_count = res['tasks_counts'] - res['count_tasks']
            # 计算审核时间
            times = str(res['end_time'] - res['begin_task_time']).split(':')
            audit_time = (times[0] + '时' + times[1] + '分').split(',')[1]
            tasks_detail = dict()
            tasks_detail['审核时间'] = audit_time
            tasks_detail['任务数量'] = tasks_count + int(res['virtual_nums'])
            tasks_detail['开始时间'] = res['begin_task_time'].strftime(
                "%Y-%m-%d-%H-%M-%S")
            tasks_detail['做单时间'] = res['deadline_time']
            tasks_detail['截止时间'] = res['end_time'].strftime(
                "%Y-%m-%d-%H-%M-%S")
            tasks_detail['任务奖励'] = res['task_reward']
            tasks_detail['任务名称'] = res['name']
            tasks_detail['任务头像'] = res['poster_img']
            tasks_detail['任务说明'] = res['task_info']
            tasks_detail['任务步骤'] = res['task_steps']
            tasks_detail['人气'] = res['virtual_nums']
            tasks_detail['标签'] = res['tags']
            tasks_detail['推荐'] = res['recommend']
            tasks_detail['任务类型'] = res['task_class']
            tasks_detail['任务完成数量'] = res['count_tasks'] + int(
                res['virtual_nums'])
            if tasks_detail:
                self.save(tasks_detail)
                return tasks_detail
            else:
                return False
Пример #20
0
 def get(self):
     """返回当前app版本号"""
     up = MysqlSearch().get_more(
         f"SELECT version,down_url,update_time,up_logs FROM {ET_APPS_PUB_HISTORY}"
     )
     if up[-1]:
         app_version = dict()
         for i in up:
             app_version['app版本号'] = i['version'],
             app_version['app下载url'] = i['down_url'],
             app_version['更新日期'] = i['update_time'].strftime(
                 "%Y-%m-%d-%H-%M-%S")
             app_version['更新日志'] = i['up_logs']
         if app_version:
             return {'data': app_version}, HttpStatus.OK.value
Пример #21
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('iiuv', type=str, required=True, location='json')
     parser.add_argument('open_id',
                         type=int,
                         required=True,
                         location='json')
     args = parser.parse_args()
     member_id = MysqlSearch().get_one(
         f"SELECT id,nickname FROM {MEMBERS_TABLE} WHERE IIUV='{args.iiuv}'"
     )
     res = MysqlWrite().write(
         f"UPDATE {MEMBERS_TABLE} SET open_id={args.open_id} WHERE ID={member_id['id']}"
     )
     if res == 1:
         return {'data': member_id['nickname']}, HttpStatus.OK.value
Пример #22
0
 def get(self):
     # 获取当前快报信息
     k = MysqlSearch().get_more(
         f"SELECT amounts,add_time,etm.nickname from {ET_MEMBER_EARNINGS} as ete \
                     LEFT JOIN et_tasks as ett on ett.id = ete.task_id \
                         LEFT JOIN {MEMBERS_TABLE} as etm on etm.id = ete.member_id \
                             ORDER BY add_time DESC LIMIT 0,30")
     json_list = list()
     for i in k:
         dic = {
             "bonus": i["amounts"],
             "time": i["add_time"].strftime("%m-%d"),
             "user_name": i["nickname"][0:5]
         }
         json_list.append(dic)
     return {'code': 2001, "data": json_list}, 200
Пример #23
0
    def get(self):
        """获取用户个人收益缓存"""
        rc = current_app.redis_cli
        try:
            user_earnings = rc.lrange(self.user_earnings_key, 0, -1)
        except RedisError as e:
            print('RedisError:{}'.format(e))
            user_earnings = None
        if user_earnings:
            return json.loads(user_earnings[0].decode())
        else:
            try:
                user_earnings = []
                # # 任务id对应的名称
                # sql_tasks_name = f"SELECT name FROM {TASKS_TABLE} WHERE id IN (SELECT task_id FROM {ET_MEMBER_EARNINGS} WHERE member_id='{g.user_id}')"
                # tasks_name = MysqlSearch().get_more(sql_tasks_name)
                # # 用户流水资料
                # sql_info = f"SELECT task_order_id,add_time,amounts FROM {ET_MEMBER_EARNINGS} WHERE member_id='{g.user_id}' order by add_time asc;"
                # info = MysqlSearch().get_more(sql_info)
                # for k, v in zip(tasks_name, info):
                #     user_earnings.append({
                #         '流水号':v['task_order_id'],
                #         '任务名称':k['name'],
                #         '完成时间':v['add_time'].strftime("%Y-%m-%d-%H-%M-%S"),
                #         '奖励金额':v['amounts'] / 100
                #     })

                # 查询用户任务流水
                sql_info = MysqlSearch().get_more(f"SELECT eme.task_order_id,eme.add_time,eme.amounts,\
                                            ett.`name` FROM et_member_earnings as eme \
                                                LEFT JOIN et_tasks as ett on ett.id=eme.task_id where eme.member_id='{g.user_id}' \
                                                    order by add_time DESC;")
                for i in sql_info:
                    user_earnings.append({
                        '流水号': i['task_order_id'],
                        '任务名称': i['name'],
                        '完成时间': i['add_time'].strftime("%Y-%m-%d-%H-%M-%S"),
                        '奖励金额': i['amounts']
                    })

            except Exception as e:
                current_app.logger.error(e)
            if user_earnings:
                self.save(user_earnings)
                return user_earnings
            else:
                return False
Пример #24
0
def mer_short_link():
    # 查询当前用户是否有旧的邀请链接
    old_sql = f"SELECT short_link,IIUV FROM {MEMBERS_TABLE} WHERE id = {g.user_id}"
    old_data = MysqlSearch().get_one(old_sql)
    old_short_link = old_data['short_link']
    if old_short_link != 'N':
        short_link = old_short_link
        return short_link
    elif old_short_link == 'N':
        # 生成短链接入库
        res_data = get_short_link(old_data['IIUV'])
        w_sql = f"UPDATE {MEMBERS_TABLE} SET short_link = '{res_data}' WHERE id = {g.user_id}"
        res = MysqlWrite().write(w_sql)
        if res == 1:
            return res_data
        else:
            return 'N'
Пример #25
0
    def get(self, p_i, p_num):
        """获取用户收徒明细信息缓存"""
        rc = current_app.redis_cli
        try:
            user_apprentice_detail = rc.lrange(self.user_appretice_detail, 0,
                                               -1)
        except RedisError as e:
            current_app.logger.error(e)
            user_apprentice_detail = None
        if user_apprentice_detail:
            return json.loads(user_apprentice_detail[0].decode())
        else:
            fetch_columns = "d.id,emr.levels, m1.nickname as username, \
                                m2.nickname as from_user, m1.IIUV, t.name\
                                    as taskname, d.amounts, d.add_time"

            drp_sql = f"SELECT {fetch_columns} FROM \
                   (SELECT * FROM et_member_drps WHERE member_id ={g.user_id} 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 \
								    LEFT JOIN et_member_relations as emr ON d.from_member_id = emr.member_id;"

            drp_list = MysqlSearch().get_more(drp_sql)
            user_apprentice_detail = []
            for res in drp_list:
                user_apprentice_detail.append({
                    '任务名称':
                    res['taskname'],
                    '徒弟名称':
                    res['from_user'],
                    '提交时间':
                    res['add_time'].strftime("%Y-%m-%d-%H-%M-%S"),
                    '金额':
                    res['amounts'],
                    '流水号':
                    hashids_iivu_encode(res['id']),
                    '等级':
                    res['levels'],
                })
            if user_apprentice_detail:
                self.save(user_apprentice_detail)
                return user_apprentice_detail
            else:
                return False
Пример #26
0
 def get(self):
     """获取用户个人收益缓存"""
     rc = current_app.redis_cli
     try:
         rc = current_app.redis_cli
         user_tasks = rc.lrange(self.user_task_earnings_key, 0, -1)
     except RedisError as e:
         current_app.logger.error(e)
         user_tasks = None
     if user_tasks:
         return json.loads(user_tasks[0].decode())
     else:
         try:
             user_task_earnings = []
             # 获取个人任务收益内容
             res_list = MysqlSearch().get_more(
                 f"SELECT et.task_order_id,et.task_id,et.amounts,et.add_time,t.name from \
                                     (SELECT * FROM {ET_MEMBER_EARNINGS} where member_id='{g.user_id}' ) as et \
                                     LEFT JOIN {TASKS_TABLE} as t on t.id=et.task_id;"
             )
             for res in res_list:
                 user_task_earnings.append({
                     '任务名称':
                     res['name'],
                     '流水号':
                     res['task_order_id'],
                     '收益':
                     res['amounts'],
                     '提交日期':
                     res['add_time'].strftime("%Y-%m-%d %H:%M:%S")
                 })
         except Exception as e:
             current_app.logger.error(e)
             return False
     if user_task_earnings:
         self.save(user_task_earnings)
         return user_task_earnings
     else:
         return False
Пример #27
0
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument('type', type=int, required=True, location='args')
        args = parser.parse_args()

        b_sql = f"SELECT banner_url, banner_name, banner_jumplink, show_time, sorting, end_time, banner_type FROM et_banner WHERE banner_type = {args.type} AND status = 2"
        b_ex = MysqlSearch().get_more(b_sql)
        b_list = list()

        if b_ex:
            for i in b_ex:
                b_list.append({
                    'name': i['banner_name'],
                    'url': i['banner_url'],
                    'j_link': i['banner_jumplink'],
                    's_time': i['show_time'],
                    'sort': i['sorting'],
                    'e_time': i['end_time'],
                    'b_type': i['banner_type']
                })
            return {'data': b_list}, HttpStatus.OK.value
        else:
            return {'error_code': 4007, 'msg': '暂无数据'}, HttpStatus.OK.value
Пример #28
0
 def get(self):
     """获取任务详情"""
     parser = reqparse.RequestParser()
     parser.add_argument('tasks_id',
                         type=int,
                         required=True,
                         location='args')
     args = parser.parse_args()
     tasks_id = args.tasks_id
     tasks_detail = TasksDetail(tasks_id).get()
     status = dict()
     # 审核状态标识
     s = MysqlSearch().get_one(
         f"SELECT status FROM {ET_TASK_ORDERS} WHERE task_id='{args.tasks_id}' and member_id='{g.user_id}'"
     )
     if s is not False and s['status']:
         status['状态'] = s['status']
         return {
             'data': tasks_detail,
             'status': status
         }, HttpStatus.OK.value
     status['状态'] = 0
     # todo 需要做一个用户单独任务状态缓存
     return {'data': tasks_detail, 'status': status}, HttpStatus.OK.value
Пример #29
0
    def post(self):
        """用户提交任务"""
        parser = reqparse.RequestParser()
        parser.add_argument('task_id',
                            type=int,
                            required=True,
                            location='json')
        parser.add_argument('json_data',
                            type=dict,
                            required=True,
                            location='json')
        parser.add_argument('safe_token',
                            type=str,
                            required=True,
                            location='json')
        # TODO res == app_safe_info == check_router
        parser.add_argument('res', type=dict, required=True, location='json')
        args = parser.parse_args()
        if args.json_data:
            if args.json_data['imgs'] == []:
                return {'code': 4002, 'msg': '请上传图片'}
        # todo 4月1号晚上修改格式
        # 要json数据入库,接收的类型必须是dict然后转str,不然会一直报错.可能需要flask的json,
        new_data = json.dumps(args.json_data).replace("'", '"')
        # 是否接过此任务
        t = MysqlSearch().get_more(
            f"SELECT task_id FROM {ET_TASK_ORDERS} WHERE member_id='{g.user_id}'"
        )
        if {'task_id': args.task_id} not in t:
            return {'error': '请先领取改任务'}, HttpStatus.OK.value
        # 查询用户当前接任务的时间
        r = MysqlSearch().get_one(
            f"SELECT add_time,safe_token,app_safe_info FROM {ET_TASK_ORDERS} WHERE task_id='{args.task_id}' AND member_id='{g.user_id}'"
        )
        #         # 获取任务最后结束时间, 查询当前任务deadline_time
        task_end_time = MysqlSearch().get_one(
            f"SELECT end_time,deadline_time,check_router FROM {TASKS_TABLE} WHERE id='{args.task_id}'"
        )
        end_time = task_end_time['end_time'].strftime("%Y-%m-%d-%H-%M-%S")
        now_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
        # todo 检验app_ip_mac地址是否一致
        json_app_info = json.loads(r['app_safe_info'])
        # 判断此ip是否存在集合
        rc = current_app.redis_cli
        res = rc.zscore(f'enterip_from_task_{args.task_id}',
                        json_app_info['ip'])
        if res is None:
            data = f"{json_app_info['ip']}"
            score = 1
            # 添加当前的member_id到redis集合中
            rc.zadd(f'enterip_from_task_{args.task_id}', {data: score})
        if args.res['mac'] != json_app_info['mac']:
            # 修改task_orders表confidence字段
            res = MysqlWrite().write(
                f"UPDATE {ET_TASK_ORDERS} SET confidence=2 WHERE member_id={g.user_id} AND task_id='{args.task_id}'"
            )
        # todo 检验safe_token是否一致,
        try:
            resp = urllib.urlopen(args.res['link'][0])
            # bytearray将数据转换成(返回)一个新的字节数组
            # asarray 复制数据,将结构化数据转换成ndarray
            image = np.asarray(bytearray(resp.read()), dtype="uint8")
            # cv2.imdecode()函数将数据解码成Opencv图像格式
            image = cv2.imdecode(image, cv2.IMREAD_COLOR)

            img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

            resImg2 = cv2.resize(img, (img.shape[1] * 10, img.shape[0] * 10),
                                 interpolation=cv2.INTER_CUBIC)

            barcodes = pyzbar.decode(resImg2)
            barcodeData = None
            for barcode in barcodes:
                barcodeData = barcode.data.decode("utf-8")
            safe_token = r['safe_token']
            current_app.logger.error(args.safe_token)
            # ref_data = 'http://' + '47.113.91.65:5007' + '/share_jump' + f'?td={args.task_id}&ref={task_end_time["check_router"]}'
            if safe_token != barcodeData:
                # 修改task_orders表confidence字段
                res = MysqlWrite().write(
                    f"UPDATE {ET_TASK_ORDERS} SET confidence=1 WHERE member_id={g.user_id} AND task_id='{args.task_id}'"
                )
        except Exception as e:
            current_app.logger.error(f'Exception : {e}')
        # 通过接任务的时间+任务deadline时间l
        # a = (r['add_time'] + datetime.timedelta(hours=int(task_end_time['deadline_time']))).strftime("%Y-%m-%d-%H-%S-%M")
        # todo >
        if now_time > (r['add_time'] + datetime.timedelta(
                hours=int(task_end_time['deadline_time']))
                       ).strftime("%Y-%m-%d-%H-%S-%M"):
            # 更新order表数据
            sql = f"UPDATE {ET_TASK_ORDERS} SET status=5,user_submit='{new_data}',submit_time='{now_time}' WHERE member_id={g.user_id} AND task_id='{args.task_id}'"
            res = MysqlWrite().write(sql)
            return {'error': '该任务已超过做单时间,无法提交'}, HttpStatus.OK.value
        # todo <
        if end_time < now_time:
            # 更新order表数据
            sql = f"UPDATE {ET_TASK_ORDERS} SET status=5,user_submit='{new_data}',submit_time='{now_time}' WHERE member_id={g.user_id} AND task_id='{args.task_id}'"
            res = MysqlWrite().write(sql)
            return {'error': '该任务已超过结束时间,无法提交'}, HttpStatus.OK.value
        else:
            # 更新order表数据
            sql = f"UPDATE {ET_TASK_ORDERS} SET status=2,user_submit='{new_data}',submit_time='{now_time}' WHERE member_id={g.user_id} AND task_id='{args.task_id}'"
            res = MysqlWrite().write(sql)
            if res == 1:
                # 更新任务数量
                # 删除用户任务详情缓存
                rc = current_app.redis_cli
                rc.delete('user_tasks_:{}'.format(g.user_id))
                return {'data': '提交成功'}, HttpStatus.OK.value
            else:
                return {"error": '提交失败,尝试再次提交'}, HttpStatus.OK.value
Пример #30
0
 def get(self, page_index, page_size):
     """
     获取任务缓存
     :return:
     """
     rc = current_app.redis_cli
     try:
         tasks_info = rc.hget(self.tasks_info_key, self.key)
     except RedisError as e:
         current_app.logger.error(e)
         tasks_info = None
     if tasks_info is not None:
         return json.loads(tasks_info.decode())
     else:
         try:
             # 判断用户登录状态
             # if g.user_id:
             #     # 查询用户任务列表
             #     tasks_info_list = MysqlSearch().get_more(f"SELECT t.task_reward,t.id,t.name,t.\
             #                                     tasks_counts,t.allow_nums,\
             #                                         t.poster_img,t.count_tasks, \
             #                                             t.tasks_fulfil,t.tags,t.recommend,t.virtual_nums,t.end_time, \
             #                                                 t.begin_task_time,t.task_class,t.check_time FROM {TASKS_TABLE} as t \
             #                                                     WHERE t.`status`=2 and t.id not IN \
             #                                                         (SELECT task_id FROM {ET_TASK_ORDERS} as et where member_id={g.user_id}) \
             #                                                             order by check_time desc LIMIT {page_index},{page_size} ")
             # else:
             tasks_info_list = MysqlSearch().get_more(
                 f"SELECT task_reward,id,name,tasks_counts,allow_nums,poster_img, count_tasks,tasks_fulfil,tags,\
                 recommend,virtual_nums,end_time,begin_task_time, task_class,check_time \
                 FROM {TASKS_TABLE} \
                 WHERE status=2 \
                 order by check_time desc \
                 LIMIT {page_index},{page_size} ")
             # 查询系统公告,并返回
             gg = MysqlSearch().get_one(
                 f"SELECT notice FROM {ET_GLOBAL_CONFIG}")
             tasks_info = []
             for res in tasks_info_list:
                 # 判断任务是否过期
                 end_time = res['end_time'].strftime("%Y-%m-%d-%H-%M-%S")
                 now_time = datetime.datetime.now().strftime(
                     "%Y-%m-%d-%H-%M-%S")
                 if end_time > now_time:
                     tasks_count = int(res['tasks_counts']) - int(
                         res['count_tasks'])
                     tasks_info.append({
                         '任务奖金':
                         res['task_reward'],
                         '任务id':
                         res['id'],
                         '任务名称':
                         res['name'],
                         '任务总参与次数':
                         res['allow_nums'],
                         '任务已赚':
                         res['count_tasks'] + int(res['virtual_nums']),
                         '任务头像':
                         res['poster_img'],
                         '任务数量':
                         int(tasks_count) + int(res['virtual_nums']),
                         '任务标签':
                         res['tags'],
                         '推荐':
                         res['recommend'],
                         '人气':
                         res['virtual_nums'],
                         '任务开始时间':
                         res['begin_task_time'].strftime(
                             "%Y-%m-%d-%H-%M-%s"),
                         '任务结束时间':
                         res['end_time'].strftime("%Y-%m-%d-%H-%M-%S"),
                         '任务类型':
                         res['task_class'],
                     })
             tasks_info.append({'系统公告': gg['notice']})
             tasks_info.append({'任务总条数': (len(tasks_info) - 1)})
         except Exception as e:
             current_app.logger.error(e)
         if tasks_info:
             self.save(tasks_info)
             return tasks_info
         else:
             return False