コード例 #1
0
ファイル: api.py プロジェクト: FreeGodCode/looting
def my_list():
    criteria = {}
    criteria = format_request_params(get_request_params(),
                                     default_values,
                                     int_keys_processor(int_keys),
                                     mg_regex_processor)
    page_num, limit = get_request_page_params()
    _cur = user.find(criteria)
    page_obj = get_pageable(_cur, page_num, limit)
    return Resp.ok(page_obj)
コード例 #2
0
def send_compute_planet_calorific_task():
    """
    发送计算星球总热量的任务
    :return:
    """
    compute_planet_calorific_total('88888888')
    user_cur = user.find({'planet_id': {'$ne': ''}})
    for user_obj in user_cur:
        planet_id = user_obj.get('planet_id', '')
        if planet_id:
            redis_code.lpush('compute_planet_calorific', planet_id)
コード例 #3
0
def repair_data():
    user_cur = user.find({})
    for user_obj in user_cur:
        planet_id = str(user_obj.get('_id'))
        planet_commission_dict = commission_record.aggregate([{
            '$match': {
                'planet_id': planet_id,
                'is_arrival': 0
            }
        }, {
            '$group': {
                '_id': '',
                'planet_commission': {
                    '$sum': '$value'
                }
            }
        }, {
            '$limit': 1
        }])
        try:
            if isinstance(planet_commission_dict, dict):

                _planet_commission_dict = planet_commission_dict.get(
                    'result')[0]
                planet_commission = int(
                    _planet_commission_dict.get('planet_commission'))
            else:
                _planet_commission_dict = planet_commission_dict.next()
                planet_commission = int(
                    _planet_commission_dict.get('planet_commission'))
        except:
            planet_commission = 0
        if planet_commission:
            print(planet_commission)
            user.update_one({'_id': ObjectId(planet_id)}, {
                '$inc': {
                    'planet_commission_total': planet_commission,
                    'balance': planet_commission
                }
            })
            commission_record.update_many(
                {
                    'planet_id': planet_id,
                    'is_arrival': 0
                }, {'$set': {
                    'is_arrival': 1
                }})
コード例 #4
0
def check_registration_reward():
    """
    检查邀请用户首次注册是否奖励
    :return:
    """
    if int(timestamp_to_strftime(int(time.time()), format='%H')) == 0:
        return False
    last_hour_str = timestamp_to_strftime((int(time.time()) - 60 * 60), format='%Y-%m-%d %H')
    user_cur = user.find({'created_time': {'$regex': last_hour_str}})
    for user_obj in user_cur:
        invite_id = user_obj.get('invite_id', '')
        user_id = str(user_obj.get('_id'))
        if ObjectId.is_valid(invite_id):
            if not commission_record.find_one({'origin': u'邀请用户首次注册', 'user_id': invite_id,
                                               'contributor_id': user_id}):
                redis_invite_code.lpush('invite_json', json.dumps({'is_bind': 1, 'invite_id': invite_id,
                                                                   'user_id': user_id}))
コード例 #5
0
def system_dividend():
    """
    系统分红
    :return:
    """
    dividend_calorific_total = 0
    operation_obj = operation.find_one()
    dividend_of_calorific = int(
        operation_obj.get('dividend_of_calorific', 2000))
    dividend_deduct_calorific_per = int(
        operation_obj.get('dividend_deduct_calorific_per', 80))
    penny_calorific = operation_obj.get('penny_calorific', 5)

    dividend_config_obj = dividend_config.find({}).sort([('today_str', -1)])[0]
    # 将分红金额转换为分 同时扣除15的上级分润
    dividend_value = int(
        dividend_config_obj.get('dividend_value', 0) * 100 * 100 / 115)
    user_cur = user.find({
        'available_calorific': {
            '$gt': dividend_of_calorific
        },
        'status': 0
    })
    for user_obj in user_cur:
        user_id = str(user_obj.get('_id'))
        available_calorific = user_obj.get('available_calorific')
        if available_calorific > dividend_of_calorific:
            participate_dividend_calorific = int(
                available_calorific * dividend_deduct_calorific_per / 100)
            dividend_calorific_total += participate_dividend_calorific
            redis_admin.lpush(
                'system_dividend',
                json.dumps({
                    'participate_dividend_calorific':
                    participate_dividend_calorific,
                    'user_id': user_id
                }))

    while True:
        try:
            system_dividend_req = redis_admin.brpop('system_dividend',
                                                    timeout=2)
            if not system_dividend_req:
                break
            system_dividend_dict = json.loads(system_dividend_req[1])
            user_id = system_dividend_dict.get('user_id')
            participate_dividend_calorific = system_dividend_dict.get(
                'participate_dividend_calorific')

            try:
                user_obj = user.find_one({'_id': ObjectId(user_id)})
                if not user_obj:
                    continue
            except:
                continue

            value_total = int(participate_dividend_calorific / penny_calorific)
            user_dividend_value = int(value_total * 100 / 115)
            # user_dividend_value = int(dividend_value * participate_dividend_calorific / dividend_calorific_total)
            calorific_record.insert_one({
                'user_id':
                user_id,
                'today':
                datetime.now().strftime(format='%Y-%m-%d'),
                'symbol':
                -1,
                'type_num':
                11,
                'value':
                participate_dividend_calorific,
                'des':
                u'系统热量分红',
                'red_id':
                '',
                'created_time':
                datetime.now().strftime(format='%Y-%m-%d %H:%M:%S')
            })

            serial_number = '{0}{1}{2}{3}{4}{5}{6}'.format(
                datetime.now().strftime(format='%Y'), get_chars2(0, 1),
                datetime.now().strftime(format='%m'), get_chars2(0, 1),
                datetime.now().strftime(format='%d'), get_chars2(0, 1),
                datetime.now().strftime(format='%H%M%S'))

            commission_record.insert_one({
                'serial_number':
                serial_number,
                'planet_id':
                user_id,
                'origin':
                u'系统热量分红',
                'value':
                int(user_dividend_value),
                'consume_calorific':
                participate_dividend_calorific,
                'is_arrival':
                1,
                'balance':
                int(user_dividend_value + user_obj.get('balance')),
                'user_id':
                user_id,
                'user_name':
                user_obj.get('nickname'),
                'contributor_id':
                str(user_obj.get('_id')),
                'type_num':
                3,
                'user_img':
                user_obj.get('headimgurl'),
                'grade':
                1,
                'today':
                datetime.now().strftime(format='%Y-%m-%d'),
                'created_time':
                datetime.now().strftime(format='%Y-%m-%d %H:%M:%S')
            })
            user.update_one({'_id': user_obj.get('_id')}, {
                '$inc': {
                    'planet_commission_total': user_dividend_value,
                    'balance': user_dividend_value,
                    'available_calorific': -participate_dividend_calorific,
                    'consumption_calorific': participate_dividend_calorific
                }
            })
            calculate_planet(operation_obj, user_obj, user_dividend_value)
        except:
            pass
コード例 #6
0
ファイル: model.py プロジェクト: FreeGodCode/looting
            "mp_system_version": "12.4.1",
            "planet_name": "か的星球",
            "upperlevel_planet_id": "",
            "mp_version": "1.3.27",
            "refresh_token":
            "25_MjxP2dVPGMtkhvquR2QwVSYFgzXXZCrG_qA-M2FBV8mr-DLTPr8tIy6IR1ZgB6HemMe88VECt-opX4D_KROaEuZdWPTmOdse63o8hqzUrJ0",
            "al_uid": "",
            "reg_source": "",
            "unionid": "oLaQOwsqwrwR6lOwKh2xgsghmqbc",
            "invite_active_time": "2019-09-27"
        })

    print(
        u'用户手机&&昵称&&从注册到提现耗时&&从注册到抢红包耗时&&余额&&已提现金额&&冻结金额&&活跃天数&&邀请人数&&邀请人&&拆红包次数&&注册时间'
    )
    user_cur = user.find()
    for user_obj in user_cur:
        withdraw_time = 0
        created_time = user_obj.get('created_time')
        timeArray = time.strptime(created_time, "%Y-%m-%d %H:%M:%S")

        timeStamp = int(time.mktime(timeArray))
        withdraw_record_obj = withdraw_record.find_one(
            {'user_id': str(user_obj.get('_id'))})
        if withdraw_record_obj:
            created_time = withdraw_record_obj.get('created_time')
            timeArray = time.strptime(created_time, "%Y-%m-%d %H:%M:%S")
            timeStamp2 = int(time.mktime(timeArray))

            withdraw_time = int(timeStamp2 - timeStamp) / 60
            if not withdraw_time:
コード例 #7
0
def third_transfer_profit():
    """
    统计第三方文章的有效阅读数
    :return:
    """
    today_str = timestamp_to_strftime(int(time.time()), format='%Y-%m-%d')
    operation_obj = operation.find_one()
    wechat_transfer_cash = int(operation_obj.get('wechat_transfer_cash', 20))
    wechat_transfer_per_deduction = int(operation_obj.get('wechat_transfer_per_deduction', 70))
    user_cur = user.find({'status': 0})
    for user_obj in user_cur:
        user_id = str(user_obj.get('_id'))
        third_transfer_art_token = user_obj.get('third_transfer_art_token')
        if third_transfer_art_token:
            redis_admin.lpush('third_transfer_profit_h',
                              json.dumps({'third_transfer_art_token': third_transfer_art_token,
                                          'user_id': user_id}))
    while True:
        try:
            third_transfer_profit_req = redis_admin.brpop('third_transfer_profit_h', timeout=2)
            if not third_transfer_profit_req:
                break
            third_transfer_profit_dict = json.loads(third_transfer_profit_req[1])
            user_id = third_transfer_profit_dict.get('user_id')
            third_transfer_art_token = third_transfer_profit_dict.get('third_transfer_art_token')
            json_data = {}
            for i in range(3):
                try:
                    ts = int(time.time() * 1000)
                    uuid_m = hashlib.md5(str(uuid.uuid4()).replace('-', ''))
                    opt = {'day': today_str, 'token': third_transfer_art_token,
                           'uuid': uuid_m.hexdigest(), 'ts': ts}
                    result = ''
                    key_az = sorted(opt.keys())
                    for k in key_az:
                        v = str(opt.get(k, '')).strip()
                        if not v:
                            continue
                        try:
                            v = v.encode('utf8')
                        except:
                            v = v.decode("ascii").encode('utf8')
                        result += v
                    result = result + '1234567890VGY&XDR%'
                    m = hashlib.md5(result)
                    md5_text = m.hexdigest()
                    resp = requests.post('https://api.5qx8.cn/api/open-fetch-user-data',
                                         headers={'sign': md5_text,
                                                  'Content-Type': 'multipart/form-data'}, params=opt)
                    req_json = resp.json()
                    if req_json.get('code') == 0 and req_json.get('data', {}):
                        json_data = req_json.get('data', {})
                        break
                except Exception as e:
                    print(e)
                    continue
            if json_data:
                ips = json_data.get('ips', 0)
                if ips:
                    real_ips = ips - int(wechat_transfer_per_deduction * ips / 100)
                    real_value = wechat_transfer_cash * real_ips
                    s_user_online_t.update_one({'today_str': today_str, 'user_id': user_id},
                                               {'$set': {'show_wechat_transfer_ips': real_ips,
                                                         'show_cash': real_value}})
        except:
            pass
コード例 #8
0
def system_dividend():
    """
    系统分红
    :return:
    """
    dividend_calorific_total = 0
    operation_obj = operation.find_one()
    dividend_of_calorific = int(
        operation_obj.get('dividend_of_calorific', 2000))
    dividend_deduct_calorific_per = int(
        operation_obj.get('dividend_deduct_calorific_per', 80))
    penny_calorific = operation_obj.get('penny_calorific', 5)

    dividend_config_obj = dividend_config.find({}).sort([('today_str', -1)])[0]
    # 将分红金额转换为分 同时扣除15的上级分润
    dividend_value = int(
        dividend_config_obj.get('dividend_value', 0) * 100 * 100 / 115)
    user_cur = user.find({
        'available_calorific': {
            '$gt': dividend_of_calorific
        },
        'status': 0
    })
    for user_obj in user_cur:
        user_id = str(user_obj.get('_id'))
        available_calorific = user_obj.get('available_calorific')
        if available_calorific > dividend_of_calorific:
            participate_dividend_calorific = int(
                available_calorific * dividend_deduct_calorific_per / 100)
            dividend_calorific_total += participate_dividend_calorific
            redis_admin.lpush(
                'system_dividend',
                json.dumps({
                    'participate_dividend_calorific':
                    participate_dividend_calorific,
                    'user_id': user_id
                }))
    user_dividend_value_total = 0
    while True:
        try:
            system_dividend_req = redis_admin.brpop('system_dividend',
                                                    timeout=2)
            if not system_dividend_req:
                break
            system_dividend_dict = json.loads(system_dividend_req[1])
            user_id = system_dividend_dict.get('user_id')
            participate_dividend_calorific = system_dividend_dict.get(
                'participate_dividend_calorific')

            try:
                user_obj = user.find_one({'_id': ObjectId(user_id)})
                if not user_obj:
                    continue
            except:
                continue

            value_total = int(participate_dividend_calorific / penny_calorific)
            user_dividend_value = int(value_total * 100 / 115)
            user_dividend_value_total += user_dividend_value
            print(user_dividend_value, participate_dividend_calorific, user_id)
        except:
            pass
    print(user_dividend_value_total)
コード例 #9
0
def third_transfer_profit():
    """
    :param os: 1为安卓,2为ios
    :param uid: 用户唯 一id
    :return:
    """
    yesterday_str = timestamp_to_strftime((int(time.time())),
                                          format='%Y-%m-%d')

    user_cur = user.find({'status': 0})
    for user_obj in user_cur:
        user_id = str(user_obj.get('_id'))
        third_transfer_art_token = user_obj.get('third_transfer_art_token')
        if third_transfer_art_token:
            redis_admin.lpush(
                'third_transfer_profit',
                json.dumps({
                    'third_transfer_art_token': third_transfer_art_token,
                    'user_id': user_id
                }))
    while True:
        try:
            third_transfer_profit_req = redis_admin.brpop(
                'third_transfer_profit', timeout=2)
            if not third_transfer_profit_req:
                break
            third_transfer_profit_dict = json.loads(
                third_transfer_profit_req[1])
            user_id = third_transfer_profit_dict.get('user_id')
            third_transfer_art_token = third_transfer_profit_dict.get(
                'third_transfer_art_token')
            json_data = {}
            for i in range(3):
                try:
                    ts = int(time.time() * 1000)
                    uuid_m = hashlib.md5(str(uuid.uuid4()).replace('-', ''))
                    opt = {
                        'day': yesterday_str,
                        'token': third_transfer_art_token,
                        'uuid': uuid_m.hexdigest(),
                        'ts': ts
                    }
                    result = ''
                    key_az = sorted(opt.keys())
                    for k in key_az:
                        v = str(opt.get(k, '')).strip()
                        if not v:
                            continue
                        try:
                            v = v.encode('utf8')
                        except:
                            v = v.decode("ascii").encode('utf8')
                        result += v
                    result = result + '1234567890VGY&XDR%'
                    m = hashlib.md5(result)
                    md5_text = m.hexdigest()
                    resp = requests.post(
                        'https://api.5qx8.cn/api/open-fetch-user-data',
                        headers={
                            'sign': md5_text,
                            'Content-Type': 'multipart/form-data'
                        },
                        params=opt)
                    req_json = resp.json()
                    if req_json.get('code') == 0 and req_json.get('data', {}):
                        json_data = req_json.get('data', {})
                        break
                except Exception as e:
                    continue
            if json_data:
                ips = json_data.get('ips', 0)
                if ips:
                    print(user_id, ips)
        except:
            pass
コード例 #10
0
ファイル: minute.py プロジェクト: FreeGodCode/looting
def invite_activity_cash():
    """
    活动邀请奖现金奖
    :return:
    """

    req_number = 0
    while True:
        try:
            req_invite = redis_invite_code.brpop('invite_activity', timeout=2)
            if not req_invite:
                if req_number < 50:
                    req_number += 2
                    continue
                else:
                    break
            req_number += 1
            invite_json = json.loads(req_invite[1])

            invite_id = invite_json.get('invite_id', '')
            _type = invite_json.get('type', 1)
            user_id = invite_json.get('user_id', '')

            today_str = datetime.now().strftime(format='%Y-%m-%d')
            try:
                invite_user_obj = user.find_one({'_id': ObjectId(invite_id)})
                user_obj = user.find_one({'_id': ObjectId(user_id)})
            except:
                continue
            invite_active_status = user_obj.get('invite_active_status')

            user_input_time = user_obj.get('created_time').split(' ')[0]
            timeArray = time.strptime(user_input_time, "%Y-%m-%d")
            timeStamp = int(time.mktime(timeArray))
            effective_time = unix_time_to_string(unix_time=timeStamp +
                                                 6 * 24 * 60 * 60,
                                                 format='%Y-%m-%d')
            if effective_time < today_str:
                if invite_active_status in [-1, -2]:
                    continue
                user.update_one({'_id': user_obj.get('_id')},
                                {'$set': {
                                    'invite_active_status': -2
                                }})
            invite_active_time = user_obj.get('invite_active_time')
            if invite_active_time == today_str:
                continue
            if _type == 1:
                if invite_active_status != 0:
                    continue
                if withdraw_record.find({
                        'user_id': user_id,
                        'status': 1
                }).count() > 0:
                    invite_active_complete_num = user.find({
                        'invite_id':
                        invite_id,
                        'invite_active_status':
                        -1
                    }).count()
                    if invite_active_complete_num < 318:
                        serial_number = '{0}{1}{2}{3}{4}{5}{6}'.format(
                            datetime.now().strftime(format='%Y'),
                            get_chars2(0, 1),
                            datetime.now().strftime(format='%m'),
                            get_chars2(0, 1),
                            datetime.now().strftime(format='%d'),
                            get_chars2(0, 1),
                            datetime.now().strftime(format='%H%M%S'))
                        commission_record.insert_one({
                            'serial_number':
                            serial_number,
                            'planet_id':
                            invite_id,
                            'origin':
                            u'活动邀请用户提现',
                            'is_arrival':
                            1,
                            'value':
                            20,
                            'balance':
                            int(20 + invite_user_obj.get('balance')),
                            'user_id':
                            invite_id,
                            'user_name':
                            user_obj.get('nickname'),
                            'contributor_id':
                            str(user_obj.get('_id')),
                            'type_num':
                            2,
                            'user_img':
                            user_obj.get('headimgurl'),
                            'grade':
                            2,
                            'today':
                            today_str,
                            'created_time':
                            datetime.now().strftime(format='%Y-%m-%d %H:%M:%S')
                        })
                        user.update_one({'_id': invite_user_obj.get('_id')}, {
                            '$inc': {
                                'planet_commission_total': 20,
                                'balance': 20
                            }
                        })
                        user.update_one({'_id': user_obj.get('_id')}, {
                            '$set': {
                                'invite_active_status': 1,
                                'invite_active_time': today_str
                            },
                            '$inc': {
                                'invite_active_cash': 20
                            }
                        })
                    else:
                        user.update_one({'_id': user_obj.get('_id')}, {
                            '$set': {
                                'invite_active_status': -2,
                                'invite_active_time': today_str
                            }
                        })
            else:
                if invite_active_status in [1, 2]:
                    invite_active_complete_num = user.find({
                        'invite_id':
                        invite_id,
                        'invite_active_status':
                        -1
                    }).count()
                    if invite_active_complete_num < 318:
                        serial_number = '{0}{1}{2}{3}{4}{5}{6}'.format(
                            datetime.now().strftime(format='%Y'),
                            get_chars2(0, 1),
                            datetime.now().strftime(format='%m'),
                            get_chars2(0, 1),
                            datetime.now().strftime(format='%d'),
                            get_chars2(0, 1),
                            datetime.now().strftime(format='%H%M%S'))
                        commission_record.insert_one({
                            'serial_number':
                            serial_number,
                            'planet_id':
                            invite_id,
                            'origin':
                            u'活动邀请用户完成第二天抢红包',
                            'is_arrival':
                            1,
                            'value':
                            30,
                            'balance':
                            int(30 + invite_user_obj.get('balance')),
                            'user_id':
                            invite_id,
                            'user_name':
                            user_obj.get('nickname'),
                            'contributor_id':
                            str(user_obj.get('_id')),
                            'type_num':
                            2,
                            'user_img':
                            user_obj.get('headimgurl'),
                            'grade':
                            2,
                            'today':
                            today_str,
                            'created_time':
                            datetime.now().strftime(format='%Y-%m-%d %H:%M:%S')
                        })
                        user.update_one({'_id': invite_user_obj.get('_id')}, {
                            '$inc': {
                                'planet_commission_total': 30,
                                'balance': 30
                            }
                        })
                        user.update_one({'_id': user_obj.get('_id')}, {
                            '$set': {
                                'invite_active_status': 3,
                                'invite_active_time': today_str
                            },
                            '$inc': {
                                'invite_active_cash': 30
                            }
                        })
                    else:
                        user.update_one({'_id': user_obj.get('_id')}, {
                            '$set': {
                                'invite_active_status': -2,
                                'invite_active_time': today_str
                            }
                        })
                elif invite_active_status in [3, 4]:
                    invite_active_complete_num = user.find({
                        'invite_id':
                        invite_id,
                        'invite_active_status':
                        -1
                    }).count()
                    if invite_active_complete_num < 318:
                        integer_red_detail_count = integer_red_detail.find({
                            'today_str':
                            today_str,
                            'user_id':
                            user_id
                        }).count()
                        guess_red_detail_count = guess_red_detail.find({
                            'guess_time': {
                                '$regex': today_str
                            },
                            'user_id':
                            user_id
                        }).count()
                        if (integer_red_detail_count +
                                guess_red_detail_count) < 2:
                            continue
                        if invite_active_complete_num >= 200:
                            cash_value = 200
                        elif invite_active_complete_num >= 100:
                            cash_value = 150
                        elif invite_active_complete_num >= 20:
                            cash_value = 130
                        elif invite_active_complete_num >= 3:
                            cash_value = 100
                        else:
                            cash_value = 50

                        serial_number = '{0}{1}{2}{3}{4}{5}{6}'.format(
                            datetime.now().strftime(format='%Y'),
                            get_chars2(0, 1),
                            datetime.now().strftime(format='%m'),
                            get_chars2(0, 1),
                            datetime.now().strftime(format='%d'),
                            get_chars2(0, 1),
                            datetime.now().strftime(format='%H%M%S'))
                        commission_record.insert_one({
                            'serial_number':
                            serial_number,
                            'planet_id':
                            invite_id,
                            'origin':
                            u'活动邀请用户完成第三天抢两红包',
                            'is_arrival':
                            1,
                            'value':
                            cash_value,
                            'balance':
                            int(cash_value + invite_user_obj.get('balance')),
                            'user_id':
                            invite_id,
                            'user_name':
                            user_obj.get('nickname'),
                            'contributor_id':
                            str(user_obj.get('_id')),
                            'type_num':
                            2,
                            'user_img':
                            user_obj.get('headimgurl'),
                            'grade':
                            2,
                            'today':
                            today_str,
                            'created_time':
                            datetime.now().strftime(format='%Y-%m-%d %H:%M:%S')
                        })
                        user.update_one({'_id': invite_user_obj.get('_id')}, {
                            '$inc': {
                                'planet_commission_total': cash_value,
                                'balance': cash_value
                            }
                        })
                        user.update_one({'_id': user_obj.get('_id')}, {
                            '$set': {
                                'invite_active_status': -1,
                                'invite_active_time': today_str
                            },
                            '$inc': {
                                'invite_active_cash': cash_value
                            }
                        })
                    else:
                        user.update_one({'_id': user_obj.get('_id')}, {
                            '$set': {
                                'invite_active_status': -2,
                                'invite_active_time': today_str
                            }
                        })
                else:
                    continue
        except Exception as e:
            error_log.insert_one({
                'fn_name':
                'invite_return_calorific_1',
                'invite_activity':
                invite_json,
                'error_str':
                str(e),
                'today':
                datetime.now().strftime(format='%Y-%m-%d')
            })
コード例 #11
0
ファイル: minute.py プロジェクト: FreeGodCode/looting
def invite_return_calorific():
    """
    正常邀请奖现金奖热量
    :return:
    """
    req_number = 0
    while True:
        try:
            req_invite = redis_invite_code.brpop('invite_json', timeout=2)
            if not req_invite:
                if req_number < 50:
                    req_number += 2
                    continue
                else:
                    break
            req_number += 1
            invite_json = json.loads(req_invite[1])
            invite_id = invite_json.get('invite_id', '')
            is_bind = invite_json.get('is_bind', 0)
            user_id = invite_json.get('user_id', '')
            operation_obj = operation.find_one()
            effective_invitation_num = operation_obj.get(
                'effective_invitation_num')
            calorific_number_people = operation_obj.get(
                'calorific_number_people')
            effective_invitation_calorific = operation_obj.get(
                'effective_invitation_calorific')
            effective_invitation_cash1 = operation_obj.get(
                'effective_invitation_cash1')
            effective_invitation_cash2 = operation_obj.get(
                'effective_invitation_cash2')
            # today_str = datetime.now().strftime(format='%Y-%m-%d')
            today_str = datetime.now().strftime('%Y-%m-%d')
            try:
                invite_user_obj = user.find_one({'_id': ObjectId(invite_id)})
            except:
                if is_bind == 1:
                    system.update_one({}, {
                        '$inc': {
                            'planet_commission_total':
                            effective_invitation_cash1
                        }
                    })
                if is_bind == 2:
                    system.update_one({}, {
                        '$inc': {
                            'planet_commission_total':
                            effective_invitation_cash2
                        }
                    })
                continue
            if is_bind == 10:
                # 第一笔分润通知
                grade = invite_json.get('grade')
                if commission_record.find({
                        'planet_id': invite_id,
                        'type_num': 0,
                        'grade': grade
                }).count() == 1:
                    openid = invite_user_obj.get('wx_uid')
                    if conf_ver == 'conf.ProductionConfig':
                        template_id = 'kLvKUoi6_y_rB4CN1MBt3956Gh54_AkfxzItmH6yQtA'
                    else:
                        template_id = 'CuRkLGY-RCH-CZfxHnuQXEmAqm7Q1tvcDXJSwWUV0NY'

                    if openid:
                        try:
                            push_template(
                                openid, template_id, '',
                                invite_json.get('value', ''),
                                u'您的{0}为您贡献了一笔分润,请进入热量星球APP查看我的收益。'.format(
                                    invite_json.get('nickname')),
                                datetime.now().strftime('%Y-%m-%d %H:%M'))
                        except:
                            pass
                continue

            try:
                user_obj = user.find_one({'_id': ObjectId(user_id)})
            except:
                user_obj = dict()

            # 当用户初次绑定邀请码 给邀请人奖励0.3元
            commission_record_num = commission_record.find({
                'user_id':
                invite_id,
                'today':
                today_str,
                'type_num':
                1,
                'origin':
                u'邀请用户首次注册'
            }).count()
            if is_bind == 1 and commission_record_num < int(
                    calorific_number_people):
                serial_number = '{0}{1}{2}{3}{4}{5}{6}'.format(
                    datetime.now().strftime(format='%Y'), get_chars2(0, 1),
                    datetime.now().strftime(format='%m'), get_chars2(0, 1),
                    datetime.now().strftime(format='%d'), get_chars2(0, 1),
                    datetime.now().strftime(format='%H%M%S'))
                commission_record.insert_one({
                    'serial_number':
                    serial_number,
                    'planet_id':
                    invite_id,
                    'origin':
                    u'邀请用户首次注册',
                    'is_arrival':
                    1,
                    'value':
                    int(effective_invitation_cash1),
                    'balance':
                    int(effective_invitation_cash1 +
                        invite_user_obj.get('balance')),
                    'user_id':
                    invite_id,
                    'user_name':
                    user_obj.get('nickname'),
                    'contributor_id':
                    str(user_obj.get('_id')),
                    'type_num':
                    1,
                    'user_img':
                    user_obj.get('headimgurl'),
                    'grade':
                    2,
                    'today':
                    today_str,
                    'created_time':
                    datetime.now().strftime(format='%Y-%m-%d %H:%M:%S')
                })
                user.update_one({'_id': invite_user_obj.get('_id')}, {
                    '$inc': {
                        'planet_commission_total': effective_invitation_cash1,
                        'balance': effective_invitation_cash1
                    }
                })

            # 当用户首次提现  给邀请人返热量
            commission_record_num = commission_record.find({
                'user_id':
                invite_id,
                'today':
                today_str,
                'type_num':
                1,
                'origin':
                u'邀请用户首次提现'
            }).count()
            if is_bind == 2 and commission_record_num < int(
                    calorific_number_people):
                serial_number = '{0}{1}{2}{3}{4}{5}{6}'.format(
                    datetime.now().strftime(format='%Y'), get_chars2(0, 1),
                    datetime.now().strftime(format='%m'), get_chars2(0, 1),
                    datetime.now().strftime(format='%d'), get_chars2(0, 1),
                    datetime.now().strftime(format='%H%M%S'))
                commission_record.insert_one({
                    'serial_number':
                    serial_number,
                    'planet_id':
                    invite_id,
                    'origin':
                    u'邀请用户首次提现',
                    'is_arrival':
                    1,
                    'value':
                    int(effective_invitation_cash2),
                    'balance':
                    int(effective_invitation_cash2 +
                        invite_user_obj.get('balance')),
                    'user_id':
                    invite_id,
                    'user_name':
                    user_obj.get('nickname'),
                    'contributor_id':
                    str(user_obj.get('_id')),
                    'type_num':
                    1,
                    'user_img':
                    user_obj.get('headimgurl'),
                    'grade':
                    2,
                    'today':
                    today_str,
                    'created_time':
                    datetime.now().strftime(format='%Y-%m-%d %H:%M:%S')
                })

                calorific_record_dict = {
                    'user_id':
                    invite_id,
                    'today':
                    today_str,
                    'symbol':
                    1,
                    'type_num':
                    7,
                    'value':
                    effective_invitation_calorific,
                    'des':
                    u'邀请用户首次提现',
                    'created_time':
                    datetime.now().strftime(format='%Y-%m-%d %H:%M:%S')
                }
                calorific_record.insert_one(calorific_record_dict)
                user.update_one({'_id': invite_user_obj.get('_id')}, {
                    '$inc': {
                        'planet_commission_total': effective_invitation_cash2,
                        'balance': effective_invitation_cash2,
                        'calorific_total': effective_invitation_calorific,
                        'available_calorific': effective_invitation_calorific
                    }
                })

            # 判断此邀请人数 看是否升级成了球主
            invite_user_obj = user.find_one({'_id': ObjectId(invite_id)})
            planet_id = invite_user_obj.get('planet_id', '')
            invite_user_num = user.find({
                'invite_id': invite_id,
                'new_value': -1
            }).count()
            if invite_user_num >= effective_invitation_num and not planet_id:
                user.update_one({'_id': ObjectId(invite_id)},
                                {'$set': {
                                    'planet_id': invite_id
                                }})
                # title = u'成为星主'
                # content = u'恭喜您达到系统要求的邀请人数,我们已经为您创建属于您自己的星球'
                # alert = {
                #     'title': title,
                #     'body': content
                # }
                # try:
                #     jp_notification(alert, title, 'id', '', type_num=1, jg_ids=[invite_user_obj.get('jg_id')])
                # except:
                #     pass
                # if conf_ver == 'conf.ProductionConfig':
                #     template_id = 'BicMMuwBiTojbCEGRocNevHJfYhibNYBHP_ieScf7KI'
                # else:
                #     template_id = '18IjSoLlT_ejZBhnpZrFq5tZeDMInBFCpG09qzw56Pc'
                # openid = invite_user_obj.get('wx_uid')
                # if openid:
                #     try:
                #         push_template(openid, template_id, '', invite_user_obj.get('name', ''),
                #                       invite_user_obj.get('phone', ''), '')
                #     except:
                #         pass
                # params_163 = '{}'
                # send_sms_163(invite_user_obj.get('phone'), params_163, '10858')

            # 如果邀请人成为球主 则同步其所有邀请人的球主信息
            invite_user_obj = user.find_one({'_id': ObjectId(invite_id)})
            planet_id = invite_user_obj.get('planet_id', '')
            if planet_id and invite_user_num < 30:
                # planet_commission_dict = commission_record.aggregate([
                #     {
                #         '$match': {'planet_id': planet_id, 'is_arrival': 0}
                #     },
                #     {
                #         '$group': {'_id': '', 'planet_commission': {'$sum': '$value'}}
                #     },
                #     {'$limit': 1}
                # ])
                # try:
                #     if isinstance(planet_commission_dict, dict):
                #
                #         _planet_commission_dict = planet_commission_dict.get('result')[0]
                #         planet_commission = int(_planet_commission_dict.get('planet_commission'))
                #     else:
                #         _planet_commission_dict = planet_commission_dict.next()
                #         planet_commission = int(_planet_commission_dict.get('planet_commission'))
                # except:
                #     planet_commission = 0
                # if planet_commission:
                #     user.update_one({'_id': ObjectId(planet_id)},
                #                     {'$inc': {'planet_commission_total': planet_commission,
                #                               'balance': planet_commission}})
                #     commission_record.update_many({'planet_id': planet_id, 'is_arrival': 0},
                #                                   {'$set': {'is_arrival': 1}})

                user.update_many({'invite_id': invite_id},
                                 {'$set': {
                                     'superior_planet_id': planet_id
                                 }})
                user.update_many({'superior_invite_id': invite_id},
                                 {'$set': {
                                     'upperlevel_planet_id': planet_id
                                 }})
        except Exception as e:
            error_log.insert_one({
                'fn_name':
                'invite_return_calorific_1',
                'invite_json':
                invite_json,
                'error_str':
                str(e),
                'today':
                datetime.now().strftime(format='%Y-%m-%d')
            })
コード例 #12
0
def get_user_day():
    access_status = judging_permissions('3_1_3')
    if access_status.get('code') != 200:
        return jsonify(access_status)
    yesterday_str = timestamp_to_strftime(int(time.time()), format='%Y-%m-%d')

    earth_code_list = earth_code.find({}).distinct('invite_code')
    earth_code_list.append('')
    user_num_invite = user.find({
        'created_time': {
            '$regex': yesterday_str
        },
        'invite_id': {
            '$nin': earth_code_list
        },
    }).count()
    user_red_record = len(
        red_record.find({
            'today': yesterday_str
        }).distinct('user_id'))

    statistical_day_obj = {
        'today_str':
        yesterday_str,
        'user_num_total':
        user.find({}).count(),
        'user_num':
        user.find({
            'created_time': {
                '$regex': yesterday_str
            }
        }).count(),
        'user_num_novice_task':
        user.find({
            'created_time': {
                '$regex': yesterday_str
            },
            'new_value': -1
        }).count(),
        'user_num_invite':
        user_num_invite,
        'user_num_invite_bind':
        reg_user.find({
            'today': yesterday_str,
            'is_bind': 1
        }).count(),
        'user_num_active':
        s_user_online_t.find({
            'today_str': yesterday_str
        }).count(),
        'user_red_record':
        user_red_record,
    }
    date_list = []

    user_num_total_list = []
    user_num_list = []
    user_num_novice_task_list = []
    user_num_invite_list = []
    user_num_invite_bind_list = []
    user_num_active_list = []
    user_red_record_list = []

    date_list.insert(0, statistical_day_obj.get('today_str'))

    user_num_total_list.insert(0, statistical_day_obj.get('user_num_total'))
    user_num_list.insert(0, statistical_day_obj.get('user_num'))
    user_num_novice_task_list.insert(
        0, statistical_day_obj.get('user_num_novice_task'))
    user_num_invite_list.insert(0, statistical_day_obj.get('user_num_invite'))
    user_num_invite_bind_list.insert(
        0, statistical_day_obj.get('user_num_invite_bind'))
    user_num_active_list.insert(0, statistical_day_obj.get('user_num_active'))
    user_red_record_list.insert(0, statistical_day_obj.get('user_red_record'))

    statistical_day_cur = statistical_day.find().sort([('today_str', -1)
                                                       ]).limit(29)

    for statistical_day_obj in statistical_day_cur:
        date_list.insert(0, statistical_day_obj.get('today_str'))
        user_num_total_list.insert(0,
                                   statistical_day_obj.get('user_num_total'))
        user_num_list.insert(0, statistical_day_obj.get('user_num'))
        user_num_novice_task_list.insert(
            0, statistical_day_obj.get('user_num_novice_task'))
        user_num_invite_list.insert(0,
                                    statistical_day_obj.get('user_num_invite'))
        user_num_invite_bind_list.insert(
            0, statistical_day_obj.get('user_num_invite_bind'))
        user_num_active_list.insert(0,
                                    statistical_day_obj.get('user_num_active'))
        user_red_record_list.insert(0,
                                    statistical_day_obj.get('user_red_record'))

    return jsonify({
        'code': 200,
        'data': {
            'date_list': date_list,
            'user_num_total_list': user_num_total_list,
            'user_num_list': user_num_list,
            'user_num_novice_task_list': user_num_novice_task_list,
            'user_num_invite_list': user_num_invite_list,
            'user_num_invite_bind_list': user_num_invite_bind_list,
            'user_num_active_list': user_num_active_list,
            'user_red_record_list': user_red_record_list
        }
    })
コード例 #13
0
def my_list():
    criteria = {}
    # 支持表格字段里的任何搜索
    access_status = judging_permissions('3_4_3')
    if access_status.get('code') != 200:
        return jsonify(access_status)

    try:
        page_num = int(request.args.get('page_num', 1)) - 1
        limit = int(request.args.get('limit', 20))
    except:
        return jsonify({'code': 201, 'msg': u'参数错误'})

    _cur = statistical_day.find(criteria)
    _count = _cur.count()
    if _count % limit:
        num = _count / limit + 1
    else:
        num = _count / limit
    if _count > (page_num * limit):
        _list = []
        if page_num == 0:
            today_str = timestamp_to_strftime(int(time.time()),
                                              format='%Y-%m-%d')
            user_num_total = user.find({}).count()

            user_num = user.find({
                'created_time': {
                    '$regex': today_str
                }
            }).count()
            user_num_active = s_user_online_t.find({
                'today_str': today_str
            }).count()
            integer_red_user_id_list = integer_red_detail.find({
                'today_str':
                today_str
            }).distinct('user_id')
            integer_red_user_num = len(integer_red_user_id_list)
            guess_red_user_id_list = guess_red_detail.find({
                'guess_time': {
                    '$regex': today_str
                }
            }).distinct('user_id')
            guess_red_user_num = len(guess_red_user_id_list)

            dict_obj = dict()

            real_user_num_active = user_num_active - user_num
            real_user_num_total = user_num_total - user_num
            dict_obj['today_str'] = today_str
            dict_obj['user_num_total'] = user_num_total
            dict_obj['user_num'] = user_num
            dict_obj['user_num_active'] = user_num_active
            dict_obj['real_user_num_active'] = real_user_num_active
            dict_obj['real_user_num_total'] = real_user_num_total
            dict_obj['user_num_active_per'] = '%.2f' % (float(
                real_user_num_active * 100) / float(real_user_num_total)) + '%'

            dict_obj['integer_red_user_num'] = integer_red_user_num
            dict_obj['guess_red_user_num'] = guess_red_user_num
            dict_obj['integer_red_user_per'] = '%.2f' % (float(
                integer_red_user_num * 100) / float(user_num_active)) + '%'
            dict_obj['guess_red_user_per'] = '%.2f' % (
                float(guess_red_user_num * 100) / float(user_num_active)) + '%'
            _list.append(dict_obj)
            cur_list = _cur.sort([('today_str', -1)
                                  ]).skip(page_num * limit).limit(limit)
        else:
            cur_list = _cur.sort([('today_str', -1)
                                  ]).skip(page_num * limit).limit(limit)
        for _obj in cur_list:
            try:
                _obj['_id'] = str(_obj['_id'])
                user_num_total = _obj.get('user_num_total')
                user_num = _obj.get('user_num')
                user_num_active = _obj.get('user_num_active')
                real_user_num_active = user_num_active - user_num
                real_user_num_total = user_num_total - user_num
                _obj['real_user_num_active'] = real_user_num_active
                _obj['real_user_num_total'] = real_user_num_total
                _obj['user_num_active_per'] = '%.2f' % (
                    float(real_user_num_active * 100) /
                    float(real_user_num_total)) + '%'
                _obj['integer_red_user_per'] = '%.2f' % (
                    float(_obj.get('integer_red_user_num', 0) * 100) /
                    float(user_num_active)) + '%'
                _obj['guess_red_user_per'] = '%.2f' % (
                    float(_obj.get('guess_red_user_num', 0) * 100) /
                    float(user_num_active)) + '%'
                _list.append(_obj)
            except Exception as e:
                print(e)
        return jsonify({
            'code': 200,
            'data': {
                'num': num,
                'count': _count,
                'page': page_num + 1,
                'list': _list
            }
        })
    else:
        return jsonify({
            'code': 200,
            'data': {
                'num': num,
                'count': _count,
                'page': page_num + 1,
                'list': []
            }
        })
コード例 #14
0
def get_planet_day():
    access_status = judging_permissions('3_0_3')
    if access_status.get('code') != 200:
        return jsonify(access_status)
    yesterday_str = timestamp_to_strftime(int(time.time()), format='%Y-%m-%d')

    planet_commission_dict = commission_record.aggregate([{
        '$match': {
            'today': yesterday_str
        }
    }, {
        '$group': {
            '_id': '',
            'planet_commission': {
                '$sum': '$value'
            }
        }
    }, {
        '$limit': 1
    }])
    try:
        if isinstance(planet_commission_dict, dict):

            _planet_commission_dict = planet_commission_dict.get('result')[0]
            planet_commission = int(
                _planet_commission_dict.get('planet_commission'))
        else:
            _planet_commission_dict = planet_commission_dict.next()
            planet_commission = int(
                _planet_commission_dict.get('planet_commission'))
    except:
        planet_commission = 0
    planet_commission_total = system.find_one().get('planet_commission_total',
                                                    0)
    planet_commission_total_dict = user.aggregate([{
        '$match': {
            'grade': 1
        }
    }, {
        '$group': {
            '_id': '',
            'planet_commission_total': {
                '$sum': '$planet_commission_total'
            }
        }
    }, {
        '$limit': 1
    }])
    try:
        if isinstance(planet_commission_total_dict, dict):

            _planet_commission_total_dict = planet_commission_total_dict.get(
                'result')[0]
            planet_commission_total += int(
                _planet_commission_total_dict.get('planet_commission_total'))
        else:
            _planet_commission_total_dict = planet_commission_total_dict.next()
            planet_commission_total += int(
                _planet_commission_total_dict.get('planet_commission_total'))
    except:
        pass
    statistical_day_obj = {
        'today_str': yesterday_str,
        'planet_num': user.find({
            'planet_id': {
                '$ne': ''
            }
        }).count(),
        'planet_commission': int(planet_commission / 100),
        'planet_commission_total': int(planet_commission_total / 100)
    }
    date_list = []
    planet_num_list = []
    planet_commission_list = []
    planet_commission_total_list = []
    date_list.insert(0, statistical_day_obj.get('today_str'))
    planet_num_list.insert(0, statistical_day_obj.get('planet_num'))
    planet_commission_list.insert(0,
                                  statistical_day_obj.get('planet_commission'))
    planet_commission_total_list.insert(0, int(planet_commission_total / 100))

    statistical_day_cur = statistical_day.find().sort([('today_str', -1)
                                                       ]).limit(29)

    for statistical_day_obj in statistical_day_cur:
        date_list.insert(0, statistical_day_obj.get('today_str'))
        planet_num_list.insert(0, statistical_day_obj.get('planet_num'))
        planet_commission_list.insert(
            0, int(statistical_day_obj.get('planet_commission') / 100))
        planet_commission_total_list.insert(
            0,
            int(statistical_day_obj.get('planet_commission_total', 0) / 100))
    return jsonify({
        'code': 200,
        'data': {
            'date_list': date_list,
            'planet_num_list': planet_num_list,
            'planet_commission_list': planet_commission_list,
            'planet_commission_total_list': planet_commission_total_list
        }
    })