Esempio n. 1
0
def insert_error_log():
    """
    插入服务器错误请求日志
    :return:
    """
    req_number = 0
    while True:
        req_number += 1
        error_log_array = redis_req_log.brpop('error_log', timeout=2)
        if not error_log_array:
            if req_number < 60:
                req_number += 2
                time.sleep(1)
                continue
            else:
                break
        error_log_json = json.loads(error_log_array[1])
        # todo 做一些 数据统计
        error_log.insert_one(error_log_json)
Esempio n. 2
0
def initiate_withdrawal():
    """
    自动 提现 线程
    :return:
    """
    hour_str = datetime.now().strftime(format='%H')
    operation_obj = operation.find_one()
    automatic_withdraw_cash = operation_obj.get('automatic_withdraw_cash')

    while True:
        withdraw_task = withdraw_task_code.brpop('withdraw_notice', timeout=1)
        if not withdraw_task:
            new_hour_str = datetime.now().strftime(format='%H')
            if new_hour_str != hour_str:
                break
            continue
        try:
            withdraw_json = json.loads(withdraw_task[1])
            serial_number = withdraw_json.get('serial_number')
            withdraw_way(serial_number, automatic_withdraw_cash, is_back=False)
        except Exception as e:
            error_log.insert_one({
                'req_url':
                '',
                'req_data':
                '',
                'req_method':
                'initiate_withdrawal',
                '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
Esempio n. 3
0
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')
            })
Esempio n. 4
0
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')
            })
Esempio n. 5
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