コード例 #1
0
def compute_planet_calorific_total(planet_id):
    print(planet_id)
    if not planet_id:
        return False
    calorific_total_dict = user.aggregate([
        {
            '$match': {'$or': [{'planet_id': planet_id}, {'superior_planet_id': planet_id},
                               {'upperlevel_planet_id': planet_id}]}
        },
        {
            '$group': {'_id': '', 'calorific_total': {'$sum': '$calorific_total'}}
        },
        {'$limit': 1}
    ])
    try:
        if isinstance(calorific_total_dict, dict):

            _calorific_total_dict = calorific_total_dict.get('result')[0]
            planet_calorific_total = int(_calorific_total_dict.get('calorific_total'))
        else:
            _calorific_total_dict = calorific_total_dict.next()
            planet_calorific_total = int(_calorific_total_dict.get('calorific_total'))
    except:
        planet_calorific_total = 0
    if planet_id == '88888888':
        system.update_one({}, {'$set': {'planet_calorific_total': planet_calorific_total}})
    else:
        user.update_one({'_id': ObjectId(planet_id)}, {'$set': {'planet_calorific_total': planet_calorific_total}})
コード例 #2
0
ファイル: api.py プロジェクト: FreeGodCode/looting
def update():
    data = {key: dict(request.form)[key][0] for key in dict(request.form)}
    if not data:
        data = request.get_json()
    _id = data.get('_id')

    if not _id:
        return jsonify({'code': 201, 'msg': u'缺少参数'})
    _obj = user.find_one({'_id': ObjectId(_id)})
    if not _obj:
        return jsonify({'code': 202, 'msg': u'不存在'})
    invite_code = data.get('invite_code', '').lower()
    data.update({'invite_code': invite_code})
    access_status = judging_permissions('1_0_2')
    if access_status.get('code') != 200:
        return jsonify(access_status)
    _update = {}

    for key in default_values:
        if key in data:
            _values = data.get(key)
            if _values:
                # if isinstance(_values, str) or isinstance(_values, unicode):
                if isinstance(_values, str):
                    _values = _values.strip()
                if key in int_keys:
                    try:
                        _values = int(_values)
                    except:
                        return jsonify({'code': 201, 'msg': u'参数错误'})
                if _obj.get(key) != _values:
                    _update.update({key: _values})
    new_update = {}
    if 'status' in _update:
        new_update['status'] = _update.get('status')
    if 'verified_status' in _update:
        new_update['verified_status'] = _update.get('verified_status')
    if 'invite_code' in _update:
        invite_code = _update.get('invite_code')
        invite_code_obj = invite_code_data.find_one({'invite_code': invite_code})
        user_obj = user.find_one({'invite_code': invite_code})
        earth_code_obj = earth_code.find_one({'invite_code': invite_code})
        if invite_code_obj or user_obj or earth_code_obj:
            return jsonify({'code': 201, 'msg': u'邀请码已被使用'})
        invite_url_short = generate_dwz(
            '{0}/h5/reg?invite_code={1}&source=invite'.format(conf.api_url, invite_code))
        new_update['invite_code'] = invite_code
        new_update['invite_url_short'] = invite_url_short
    if new_update:
        try:

            user.update_one({'_id': ObjectId(_id)}, {'$set': new_update})
            return jsonify({'code': 200, 'msg': u'成功'})
        except:
            pass
    else:
        return jsonify({'code': 203, 'msg': u'无更新数据'})
    return jsonify({'code': 204, 'msg': u'失败'})
コード例 #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 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
コード例 #5
0
def calculate_planet(operation_obj, user_obj, real_value, is_commission=True):
    invite_id = user_obj.get('invite_id', '')
    superior_invite_id = user_obj.get('superior_invite_id', '')

    if is_commission:
        commission_percent_1 = operation_obj.get('commission_percent_1', 10)
        commission_percent_2 = operation_obj.get('commission_percent_2', 5)
        commission_1 = int(real_value * commission_percent_1 / 100)
        commission_2 = int(real_value * commission_percent_2 / 100)
        # 有邀请人一级分润
        if invite_id:
            # 有上级分润 且上级是真实用户邀请
            if commission_1 and ObjectId.is_valid(invite_id):
                planet_obj = user.find_one({'_id': ObjectId(invite_id)})
                if planet_obj:
                    planet_balance = planet_obj.get('balance', '')
                    user.update_one({'_id': planet_obj.get('_id')}, {
                        '$inc': {
                            'planet_commission_total': commission_1,
                            'balance': commission_1
                        }
                    })
                    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'系统热量分红获得{0}元'.format(
                            '%.2f' % (float(real_value) / float(100))),
                        'value':
                        int(commission_1),
                        'balance':
                        int(commission_1 + planet_balance),
                        'user_id':
                        invite_id,
                        'user_name':
                        user_obj.get('nickname'),
                        'contributor_id':
                        str(user_obj.get('_id')),
                        'is_arrival':
                        1,
                        'user_img':
                        user_obj.get('headimgurl'),
                        'grade':
                        2,
                        'type_num':
                        4,
                        'today':
                        datetime.now().strftime(format='%Y-%m-%d'),
                        'created_time':
                        datetime.now().strftime(format='%Y-%m-%d %H:%M:%S')
                    })
                    if commission_record.find({
                            'planet_id': invite_id,
                            'type_num': 0,
                            'grade': 2
                    }).count() == 1:
                        redis_invite_code.lpush(
                            'invite_json',
                            json.dumps({
                                'is_bind':
                                10,
                                'invite_id':
                                invite_id,
                                'grade':
                                2,
                                'value':
                                '%.2f' % (float(commission_1) / float(100)) +
                                u'元',
                                'nickname':
                                u'原住居民' + user_obj.get('nickname')
                            }))
        # 有上级邀请人二级分润
        if superior_invite_id:

            if commission_2 and ObjectId.is_valid(superior_invite_id):
                # 有上上级分润
                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'))

                planet_obj = user.find_one(
                    {'_id': ObjectId(superior_invite_id)})
                if planet_obj:
                    planet_balance = planet_obj.get('balance', '')
                    user.update_one({'_id': planet_obj.get('_id')}, {
                        '$inc': {
                            'planet_commission_total': commission_2,
                            'balance': commission_2
                        }
                    })

                    commission_record.insert_one({
                        'serial_number':
                        serial_number,
                        'planet_id':
                        superior_invite_id,
                        'origin':
                        u'系统热量分红获得{0}元'.format(
                            '%.2f' % (float(real_value) / float(100))),
                        'value':
                        int(commission_2),
                        'balance':
                        int(commission_2 + planet_balance),
                        'user_id':
                        superior_invite_id,
                        'user_name':
                        user_obj.get('nickname'),
                        'contributor_id':
                        str(user_obj.get('_id')),
                        'is_arrival':
                        1,
                        'user_img':
                        user_obj.get('headimgurl'),
                        'grade':
                        3,
                        'type_num':
                        4,
                        'today':
                        datetime.now().strftime(format='%Y-%m-%d'),
                        'created_time':
                        datetime.now().strftime(format='%Y-%m-%d %H:%M:%S')
                    })
                    if commission_record.find({
                            'planet_id': superior_invite_id,
                            'type_num': 0,
                            'grade': 3
                    }).count() == 1:
                        redis_invite_code.lpush(
                            'invite_json',
                            json.dumps({
                                'is_bind':
                                10,
                                'invite_id':
                                superior_invite_id,
                                'grade':
                                3,
                                'value':
                                '%.2f' % (float(commission_2) / float(100)) +
                                u'元',
                                'nickname':
                                u'附属居民' + user_obj.get('nickname')
                            }))

    return real_value
コード例 #6
0
def insert_req_log():
    """
    插入正常请求日志
    :return:
    """
    hour_str = datetime.now().strftime(format='%H')
    while True:
        try:
            req_log_array = redis_req_log.brpop('req_log', timeout=2)
            if not req_log_array:
                new_hour_str = datetime.now().strftime(format='%H')
                if new_hour_str != hour_str:
                    break
                continue
            req_log_json = json.loads(req_log_array[1])
            async_inser_req(req_log_json)
            # 统计此用户的在线时长
            user_id = req_log_json.get('user_id')
            today = req_log_json.get('today')
            if user_id:
                user_obj = user.find_one({'_id': ObjectId(user_id)})
                # 更新用户的最新版本
                req_data = req_log_json.get('req_data')
                system_type = req_data.get('system_type')
                version_num = req_data.get('version_num')
                app_version = user_obj.get('app_version')

                if version_num > app_version:
                    user.update_one({'_id': ObjectId(user_id)}, {
                        '$set': {
                            'app_version': version_num,
                            'mp_system_type': system_type
                        }
                    })

                req_time_stamp = req_log_json.get('time_stamp')
                s_user_online_t_obj = s_user_online_t.find_one({
                    'user_id':
                    user_id,
                    'today_str':
                    today
                })
                if s_user_online_t_obj:
                    last_visit_time = s_user_online_t_obj.get(
                        'last_visit_time')
                    if last_visit_time == 0:
                        first_visit_time_h = timestamp_to_strftime(
                            req_time_stamp, format='%H')
                        s_user_online_t.update_one(
                            {'_id': s_user_online_t_obj.get('_id')}, {
                                '$set': {
                                    'length_visit_time':
                                    0,
                                    'first_visit_time':
                                    req_time_stamp,
                                    'last_visit_time':
                                    req_time_stamp,
                                    'req_ip':
                                    req_log_json.get('req_ip', ''),
                                    'req_ip_area':
                                    req_log_json.get('req_ip_area', ''),
                                    'first_visit_time_h':
                                    int(first_visit_time_h)
                                }
                            })
                    else:
                        length_visit_time = s_user_online_t_obj.get(
                            'length_visit_time')
                        time_interval = req_time_stamp - last_visit_time
                        if time_interval < 10 * 60:
                            length_visit_time += time_interval
                        s_user_online_t.update_one(
                            {'_id': s_user_online_t_obj.get('_id')}, {
                                '$set': {
                                    'last_visit_time': req_time_stamp,
                                    'length_visit_time': length_visit_time
                                }
                            })
                else:
                    first_visit_time_h = timestamp_to_strftime(req_time_stamp,
                                                               format='%H')
                    try:
                        s_user_online_t.insert_one({
                            'user_id':
                            user_id,
                            'today_str':
                            today,
                            'length_visit_time':
                            0,
                            'first_visit_time':
                            req_time_stamp,
                            'last_visit_time':
                            req_time_stamp,
                            'req_ip':
                            req_log_json.get('req_ip', ''),
                            'req_ip_area':
                            req_log_json.get('req_ip_area', ''),
                            'first_visit_time_h':
                            int(first_visit_time_h),
                            'mp_system_type':
                            user_obj.get('mp_system_type')
                        })
                        async_ip_statistical(req_log_json)
                    except:
                        pass

                if user_obj:
                    today_str = datetime.now().strftime(format='%Y-%m-%d')
                    invite_active_status = user_obj.get('invite_active_status')
                    if invite_active_status == 1:
                        invite_active_time = user_obj.get('invite_active_time')
                        if invite_active_time != today_str:
                            user.update_one(
                                {'_id': ObjectId(user_id)},
                                {'$set': {
                                    'invite_active_status': 2
                                }})
                    elif invite_active_status == 3:
                        invite_active_time = user_obj.get('invite_active_time')
                        if invite_active_time != today_str:
                            user.update_one(
                                {'_id': ObjectId(user_id)},
                                {'$set': {
                                    'invite_active_status': 4
                                }})
            new_hour_str = datetime.now().strftime(format='%H')
            if new_hour_str != hour_str:
                break
        except:
            pass
コード例 #7
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')
            })
コード例 #8
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')
            })
コード例 #9
0
def update_guess_red_detail():
    """
    排队处理猜中红包的用户
    :return:
    """
    hour_str = datetime.now().strftime(format='%H')
    operation_obj = operation.find_one()
    while True:
        guess_red_task = redis_admin.brpop('guess_red_id_list', timeout=1)
        if not guess_red_task:
            new_hour_str = datetime.now().strftime(format='%H')
            if new_hour_str != hour_str:
                break
            continue
        try:
            guess_red_id = guess_red_task[1]
            guess_red_detail_obj = guess_red_detail.find_one({'_id': ObjectId(guess_red_id)})
            if not guess_red_detail_obj:
                continue
            number_of_periods = guess_red_detail_obj.get('number_of_periods')
            guess_red_obj = guess_red.find_one({'number_of_periods': number_of_periods})
            if not guess_red_obj:
                continue
            user_id = guess_red_obj.get('user_id', '')
            # 第一个猜中 领取红包
            if not user_id:
                user_id = guess_red_detail_obj.get('user_id')
                user_obj = user.find_one({'_id': ObjectId(user_id)})
                planet_id = user_obj.get('planet_id', '')
                superior_planet_id = user_obj.get('superior_planet_id', '')
                upperlevel_planet_id = user_obj.get('upperlevel_planet_id', '')

                guess_red_detail.update_one({'_id': guess_red_detail_obj.get('_id')}, {'$set': {'status': 1}})
                real_value = guess_red_obj.get('value')
                hour_int = guess_red_obj.get('hour_int')
                # 计算星球分润与星球总红包
                try:
                    calculate_planet(operation_obj, user_obj, real_value)
                except:
                    pass
                # 红包记录
                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'))
                if planet_id:
                    current_planet_id = planet_id
                elif superior_planet_id:
                    current_planet_id = superior_planet_id
                else:
                    current_planet_id = upperlevel_planet_id
                red_record_dict = {'serial_number': serial_number, 'origin': u'猜中红包', 'value': int(real_value),
                                   'balance': int(real_value + user_obj.get('balance')), 'user_id': user_id,
                                   'user_name': user_obj.get('nickname'), 'user_img': user_obj.get('headimgurl'),
                                   'today': guess_red_obj.get('today_str'), 'type_num': 2, 'hour_int': hour_int,
                                   'planet_id': planet_id, 'superior_planet_id': superior_planet_id, 'is_double': 0,
                                   'current_planet_id': current_planet_id, 'upperlevel_planet_id': upperlevel_planet_id,
                                   'red_returnp_calorific': 0,
                                   'created_time': datetime.now().strftime(format='%Y-%m-%d %H:%M:%S')}
                red_record.insert_one(red_record_dict)
                user.update_one({'_id': ObjectId(user_id)},
                                {'$inc': {'balance': int(real_value), 'red_total': int(real_value)}})
                guess_red.update_one({'number_of_periods': number_of_periods},
                                     {'$set': {'nickname': user_obj.get('nickname'), 'user_id': user_id,
                                               'headimgurl': user_obj.get('headimgurl', ''),
                                               'guess_time': guess_red_detail_obj.get('guess_time', ''),
                                               'millisecond': guess_red_detail_obj.get('millisecond', ''),
                                               'status': 1}})
            else:
                # 不是第一个猜中 返热量
                user_id = guess_red_detail_obj.get('user_id')
                consume_calorific = guess_red_detail_obj.get('consume_calorific')
                calorific_record.insert_one({'user_id': user_id, 'today': guess_red_obj.get('today_str'), 'symbol': 1,
                                             'type_num': 3, 'value': consume_calorific * 2,
                                             'des': u'猜中红包但晚了一步奖热量', 'red_id': number_of_periods,
                                             'created_time': datetime.now().strftime(format='%Y-%m-%d %H:%M:%S')})
                user.update_one({'_id': ObjectId(user_id)},
                                {'$inc': {'available_calorific': consume_calorific * 2,
                                          'calorific_total': consume_calorific * 2}})
                guess_red_detail.update_one({'_id': guess_red_detail_obj.get('_id')}, {'$set': {'status': 2}})
        except Exception as e:
            error_log.insert_one({'req_url': '', 'req_data': '', 'req_method': 'update_guess_red_detail',
                                  'error_str': str(e), 'today': datetime.now().strftime(format='%Y-%m-%d'),
                                  'time_stamp': int(time.time()),
                                  'req_time': datetime.now().strftime(format='%Y-%m-%d %H:%M:%S')})

        new_hour_str = datetime.now().strftime(format='%H')
        if new_hour_str != hour_str:
            break