예제 #1
0
 def get_mnt_num(user):
     """根据权限码判断的托管数量"""
     mnt_num = 0
     if test_permission(AUTO_MNT_CODE, user):
         mnt_num = 2
     if test_permission(FULL_MNT_CODE, user):
         mnt_num = 8
     return mnt_num
예제 #2
0
파일: views.py 프로젝트: Florence3546/CRM
def auto_rob_rank(request, template='auto_rob_rank.html'):
    """自动抢排名"""
    version_limit = True
    if test_permission(AUTO_RANKING_CODE, request.user):
        version_limit = False
    custom_column = Account.get_custom_col(shop_id=request.user.shop_id)
    return render_to_response(template, {
        "custom_column": custom_column,
        "version_limit": version_limit
    },
                              context_instance=RequestContext(request))
예제 #3
0
 def is_runnable(self):
     if self.opt_type == 'auto':
         # 自动抢排名时才校验,手动抢排名时在前面已校验
         try:
             user = User.objects.get(shop_id=self.shop_id)
             if not test_permission(AUTO_RANKING_CODE, user):
                 self.unable_reason = '当前版本不支持自动抢排名'
                 return False
         except Exception, e:
             log.error('can not get user, shop_id=%s' % self.shop_id)
             self.unable_reason = '其他原因'
             return False
         if not Downloader.often_sync_struct(shop_id=self.shop_id):
             self.unable_reason = '同步数据失败'
             return False
예제 #4
0
파일: views.py 프로젝트: Florence3546/CRM
def shop_core(request, template="shop_core.html"):
    """店铺核心词"""
    custom_column = []
    refresh_time = None
    condition = "ok"
    version_limit = True
    if test_permission(ATTENTION_CODE, request.user):
        version_limit = False

        shop_id = int(request.user.shop_id)
        custom_column = Account.get_custom_col(shop_id=shop_id)
        ck, _ = CoreKeyword.objects.get_or_create(shop_id=shop_id,
                                                  defaults={
                                                      'kw_dict_list': [],
                                                      'update_time': None
                                                  })

        condition = "ok"
        if ck.status:
            condition = "doing"
        else:
            if time_is_someday(
                    ck.update_time):  # update_time为None的场景在时间判断里已经有了
                condition = "ok"
            elif time_is_recent(ck.update_time, days=7):
                if not time_is_someday(
                        ck.report_sync_time):  # 如果当天也已经同步过报表了,则不再去同步
                    Thread(target=ck.sync_current_report).start()
                    condition = "doing"
                else:
                    condition = "ok"
            else:
                Thread(target=ck.calc_top_keywords).start()
                condition = "doing"
        refresh_time = ck.update_time

    resp_data = {
        "custom_column": custom_column,
        "refresh_time": refresh_time,
        "condition": condition,
        "version_limit": version_limit
    }

    return render_to_response(template,
                              resp_data,
                              context_instance=RequestContext(request))
예제 #5
0
 def get_rjjh_info(shop_id):
     """获取人机结合旺旺信息"""
     is_upgrade, server = True, None
     try:
         if test_permission(CATEGORY_SERVER_CODE, request.user):
             ww = request.session.get('rjjh_ww', None)
             if ww is None:
                 #                     _, rjjh, _, _ = Customer.get_or_create_servers([shop_id], category = "rjjh").get(shop_id, [None, None, None, None]) # [consult, rjjh, tp, department]
                 rjjh = Customer.objects.select_related('operater').get(
                     shop_id=shop_id).operater
                 if rjjh:
                     ww = rjjh.ww
                     is_upgrade = False
                 else:
                     ww = ''
                 request.session['rjjh_ww'] = ww
             server = {'ww': ww}
     except Exception, e:
         log.error('get_mnt_info error,e=%s, shop_id=%s' % (e, shop_id))
예제 #6
0
    result_dict = {}
    shop_id = int(request.user.shop_id)
    result_dict.update({
        'JLB_COUNT':
        get_jlb_count(shop_id),
        'MNT_LIST':
        get_mnt_info(shop_id),
        'IS_VIP':
        get_isvip(shop_id),
        'CONSULT_WW':
        get_consult_ww(request, shop_id),
        'SERVER_MENU_LIST':
        get_server_menu(),
        'CAN_USE_ATTENTION':
        test_permission(ATTENTION_CODE, request.user),  # 临时处理千牛权限问题
    })
    is_upgrade, server = get_rjjh_info(shop_id)
    result_dict.update({'server': server, 'server_upgrade': is_upgrade})
    return result_dict


def rjjh_worktime(request):
    week_scope = [5, 6]
    time_scope = (datetime.time(9, 0, 0), datetime.time(18, 0, 0))

    today = datetime.datetime.now()
    week_day = today.weekday()
    today_time = today.time()
    if week_day not in week_scope and time_scope[0] <= today_time < time_scope[
            1]:
예제 #7
0
    def create_auto_robrank(cls, user, keyword_id, exp_rank_range, limit_price,
                            platform, start_time, end_time, nearly_success):
        error_msg = ''
        shop_id = user.shop_id
        next_run_time = datetime.datetime.now() + datetime.timedelta(
            minutes=5)  # 不立即优化的原因:1、防止用户短时间内多次修改,重复执行;2、避免立即改价后,页面未更新价格的问题
        try:
            if not test_permission(AUTO_RANKING_CODE, user):
                error_msg = "version_limit"
            else:
                # 删除抢排名表中已经删除的关键词
                kw_locker_id_list = [
                    keyword['_id']
                    for keyword in kw_locker_coll.find({'shop_id': shop_id})
                ]
                kw_id_list = [
                    keyword['_id'] for keyword in kw_coll.find(
                        {'_id': {
                            '$in': kw_locker_id_list
                        }})
                ]
                kw_locker_coll.remove(
                    {
                        '_id': {
                            '$in':
                            list(set(kw_locker_id_list) - set(kw_id_list))
                        }
                    },
                    multi=True)

                # 当是添加抢排名记录并且超过50个锁定排名的关键词时
                if kw_locker_coll.find({
                        '_id': keyword_id
                }).count() == 0 and len(kw_id_list) >= 50:
                    error_msg = "nums_limit"
                else:
                    kw = Keyword.objects.get(shop_id=shop_id,
                                             keyword_id=keyword_id)
                    result = kw_locker_coll.update(
                        {
                            'shop_id': shop_id,
                            'campaign_id': kw.campaign_id,
                            'adgroup_id': kw.adgroup_id,
                            '_id': kw.keyword_id
                        }, {
                            '$set': {
                                'exp_rank_range': exp_rank_range,
                                'word': kw.word,
                                'limit_price': limit_price,
                                'platform': platform,
                                'start_time': start_time,
                                'end_time': end_time,
                                'nearly_success': nearly_success,
                                'is_running': 0,
                                'is_stop': 0,
                                'next_run_time': next_run_time,
                                'is_auto_robrank': True
                            }
                        },
                        upsert=True)
                    if not result['updatedExisting']:
                        kw.is_locked = True
                        kw.save()
        except Exception, e:
            log.error('auto_rob_rank error shop_id=%s, e=%s' % (shop_id, e))
            error_msg = 'others'
예제 #8
0
    def process_request(self, request):
        # if not request.user.is_authenticated():
        #     log.info('SecurityMiddleware.process_request user: %s@%s:%s' % (request.session.get('psuser_name', 'Unknown'), request.META['REMOTE_ADDR'], request.path))

        # 根据请求类型,校验功能权限
        if request.is_ajax():
            try:
                path_list = request.META['HTTP_REFERER'].replace(
                    'http://', '').split('/')

                if 'crm' in path_list:
                    return None

                ajax_func = request.POST.get('function')

                perms_tuple = AJAX_PERMS_CONFIG.get(ajax_func,
                                                    ('undefined', '', 0, ()))
                if (perms_tuple[0] != 'undefined' and perms_tuple[2]):
                    if perms_tuple[0] and not test_permission(
                            perms_tuple[0], request.user):
                        if 'qnpc' in path_list:  # TODO 2015.11.3 临时处理,千牛改版时再重新设计该模块
                            from dajax.core import Dajax
                            dajax = Dajax()
                            dajax.script(
                                "PT.confirm('您当前的版本需要升级后才能使用该功能,要升级吗?', function(){window.open('https://fuwu.taobao.com/ser/detail.html?spm=a1z13.1113643.51940006.43.RmTuNs&service_code=FW_GOODS-1921400&tracelog=category&scm=1215.1.1.51940006', '_blank');},[],this,null,[],this, ['升级'])"
                            )
                            return dajax
                        result = perms_tuple[1](request=request,
                                                perms_code=perms_tuple[0])
                        return result
                    else:
                        for i in perms_tuple[3]:
                            if i == 'href':
                                ajax_func = path_list[2] + '_' + ajax_func
                                continue
                            ajax_func = ajax_func + '_' + request.POST.get(
                                i, '')

                if 'behavior_only' in ajax_func:
                    return perms_tuple[1]()
            except Exception:
                return None
            # TODO: wangqi 2013-12-29 ajax暂时不处理
            # ajax 请求权限验证
            # ajax_func = request.POST.get('function')暂时写死,全部以基础权限统一处理
#             try:
#                 ajax_path = request.path[1:-1].split('/')[-1]
#             except Exception:
#                 ajax_path = ''
#             perms_config = AJAX_PERMS_CONFIG.get(ajax_path, None)
#             if perms_config and not  test_permission(perms_config[0], request.user):
#                 return perms_config[1](request = request, perms_code = perms_config[0])
        else:
            # from 请求权限验证
            try:
                path_list = request.path[1:].split('/')
            except Exception:
                return None
            if path_list[0] in ['web', 'mnt']:
                perms_tuple = VIEW_PERMS_CONFIG.get(path_list[1], ('', '', 0))
                if perms_tuple[0] and not test_permission(
                        perms_tuple[0], request.user):
                    return perms_tuple[1](request=request,
                                          perms_code=perms_tuple[0])
            elif path_list[0] == 'kwlib':  # 建议将这几个功能也迁移到CRM中去
                from apps.common.utils.utils_render import render_to_limited
                if not request.user.is_superuser:
                    return render_to_limited(request, '亲,您没有权限使用该功能!')
            elif path_list[0] in ['crm', 'ncrm']:
                perms_tuple = CRM_PERMS_CONFIG.get(path_list[1], ('', ''))
                if perms_tuple[0] and not check_perms(perms_tuple[0], request):
                    return perms_tuple[1](request=request)

        return None