Пример #1
0
    def download_rpt(self, klass, last_time, is_force=False):
        attr_name = '%s%s_status' % (get_klass_name(klass), 'rpt')
        setattr(
            self, attr_name,
            '%s_%s_DOING' % (datetime_2string(last_time), datetime_2string()))
        self.save()

        # 报表的特殊时间处理:1,上次同步时间太久置为15天前;2,上次同步时间不能超过今天;3,当前时间小于6点,因淘宝数据尚未准备好只下载前天数据
        # 强制上次同步时间不超过前天,原因:1,淘宝报表效果数据经常延时,这样第2天会自动修复报表;2,历史数据为3天转化数据,比1天转化数据更可靠。
        last_date = last_time.date()

        init_start_date = datetime.date.today() - datetime.timedelta(
            days=klass.Report.INIT_DAYS)
        valid_rpt_days = datetime.datetime.now().hour < 6 and 2 or 1
        default_end_date = datetime.date.today() - datetime.timedelta(
            days=valid_rpt_days)
        default_start_date = default_end_date - datetime.timedelta(days=2)
        if last_date < init_start_date:
            last_date = init_start_date
        elif last_date > default_start_date:
            last_date = default_start_date

        time_scope = last_date, default_end_date
        if is_force and get_klass_name(klass) in ['keyword', 'creative']:
            result = klass.force_download_rpt(shop_id=self.shop_id,
                                              tapi=self.tapi,
                                              token=self.token,
                                              time_scope=time_scope)
        else:
            result = klass.report_download(shop_id=self.shop_id,
                                           tapi=self.tapi,
                                           token=self.token,
                                           time_scope=time_scope)
        # TODO: wangqi 2014-4-14 同样,由于上面同步时间的不同,这里也要在此基础上作改动,后续考虑再优化
        record_datetime = valid_rpt_days == 1 and datetime.datetime.now(
        ) or datetime.datetime.now() - datetime.timedelta(days=1)
        status_str = '%s_%s' % (result in ['OK', 'EMPTY']
                                and datetime_2string(record_datetime)
                                or datetime_2string(last_time), result)
        setattr(self, attr_name, status_str)
        self.save()
        return result
Пример #2
0
    def sync_all_rpt(self,
                     detail_flag=False,
                     is_force=False,
                     rpt_days=None,
                     quick_flag=False):
        if self.tapi:
            acct_rpt_status = self.sync_rpt(klass=Account,
                                            is_force=is_force,
                                            rpt_days=rpt_days)
            if acct_rpt_status == 'EMPTY':
                if datetime.datetime.now(
                ).hour < 9:  # TODO: wangqi 20140725 该特性很久没有用上了,是否考虑去掉。如果淘宝返回空并且时间是9点以前,将状态设置为FAILED
                    status_str = '%s_%s' % (datetime_2string(), 'FAILED')
                    self.accountrpt_status = status_str
                    self.save()
                    return False
                else:
                    return True
            else:
                self.sync_rpt(klass=Campaign,
                              is_force=is_force,
                              rpt_days=rpt_days)
                if quick_flag:
                    return True
                self.sync_rpt(klass=Adgroup,
                              is_force=is_force,
                              rpt_days=rpt_days)
                if detail_flag:
                    self.sync_rpt(klass=Creative,
                                  is_force=is_force,
                                  rpt_days=rpt_days)
                    self.sync_rpt(klass=Keyword,
                                  is_force=is_force,
                                  rpt_days=rpt_days)

            return self.check_rpt_isok(need_detail=detail_flag)
        else:
            return False
Пример #3
0
# coding=UTF-8

import init_environ
from apps.common.utils.utils_datetime import datetime_2string, datetime
from apps.subway.download import dler_coll
from apps.web.api import reset_shop_task

reset_str = '%s_OK' % datetime_2string(datetime.datetime.now() - datetime.timedelta(days = 3))
dler_coll.update({}, {'$set':{'acctrpt_status':reset_str, 'camprpt_status':reset_str, 'adgrpt_status':reset_str}}, multi = True)

reset_shop_task()
Пример #4
0
            CacheAdpter.set(
                CacheKey.LOGIN_USERS %
                (customer.consult_id, datetime.date.today()), login_cache,
                'crm', 24 * 60 * 60)

    # 登陆时删除左侧菜单缓存
    CacheAdpter.delete(CacheKey.WEB_MNT_MENU % user.shop_id, 'web')
    CacheAdpter.delete(CacheKey.WEB_ISNEED_PHONE % user.shop_id, 'web')

    # 将剩余天数,订购版本等标记记录到session中
    left_days = user.get_left_days()
    if left_days < 0:
        left_days = 0
    request.session['left_days'] = left_days
    request.session['deadline'] = datetime_2string(
        datetime.datetime.now() + datetime.timedelta(days=left_days),
        '%Y-%m-%d')
    request.session[
        'highest_version'] = ArticleUserSubscribe.get_highest_version(
            nick=user.nick)
    request.session['item_code'] = ArticleUserSubscribe.get_hightest_item_code(
        nick=user.nick)
    request.session['visitor_from'] = visitor_from

    # 无线推广活动临时代码记录到session中
    # if user.f5 and user.f5.isdigit() and int(user.f5) == 1:
    #     request.session['apply_passed'] = 1

    # 启动新线程下载数据和跳转
    smt, _ = ShopMngTask.objects.get_or_create(shop_id=user.shop_id)
    if smt.is_runnable(is_login=True):
Пример #5
0
def image_optimize(request, adgroup_id):
    shop_id = request.user.shop_id
    adgroup_id = int(adgroup_id)
    yesterday = datetime_2string(dt=datetime.datetime.today() -
                                 datetime.timedelta(days=1),
                                 fmt='%Y-%m-%d')
    seven_day = datetime_2string(dt=datetime.datetime.today() -
                                 datetime.timedelta(days=7),
                                 fmt='%Y-%m-%d')
    start_date = str(request.GET.get('s', seven_day))
    end_date = str(request.GET.get('e', yesterday))
    date_text = '%s&emsp;至&emsp;%s' % (start_date[5:], end_date[5:])
    if start_date == end_date:
        date_text = start_date[5:]

    try:
        adgroup = Adgroup.objects.get(shop_id=shop_id, adgroup_id=adgroup_id)
        adgroup.get_creative_rpt()
        adgroup.rpt_list = adgroup.Report.get_snap_list(
            {
                'shop_id': shop_id,
                'adgroup_id': adgroup_id
            },
            start_date=start_date,
            end_date=end_date)
    except DoesNotExist:
        return render_to_error(request, '该宝贝已经被删除,请返回页面重新操作')

    creative_list = list(
        Creative.objects.filter(shop_id=shop_id,
                                adgroup_id=adgroup_id).order_by('create_time'))

    custom_creative_list = list(
        CustomCreative.objects.filter(
            shop_id=shop_id, adgroup_id=adgroup_id).order_by('create-time'))
    crt_rpt_dict = Creative.Report.get_summed_rpt(
        {
            'shop_id': shop_id,
            'adgroup_id': adgroup_id
        },
        start_date=start_date,
        end_date=end_date)

    # 获取类目点击率
    if adgroup.category_ids:
        g_cat_ctr = int(
            CatStatic.get_market_data_8id(
                cat_id=adgroup.category_ids.split(' ')[0]).get('ctr', '0'))

    cmp_ctr = g_cat_ctr * 0.8

    empty_rpt = Creative.Report()
    for creative in creative_list:
        creative.qr = crt_rpt_dict.get(creative.creative_id, empty_rpt)
        creative.show_ww_class = (
            int(creative.qr.ctr) == 0 or
            (cmp_ctr and creative.qr.ctr < cmp_ctr)) and 'dib' or 'hide'

    waiting_creative_list, complete_creative_list = [], []
    for custom_creative in custom_creative_list:
        if custom_creative.status == 0:
            waiting_creative_list.append(custom_creative)
        else:
            custom_creative.qr = crt_rpt_dict.get(custom_creative.creative_id,
                                                  empty_rpt)
            custom_creative.show_ww_class = (
                int(custom_creative.qr.ctr) == 0 or
                (cmp_ctr
                 and custom_creative.qr.ctr < cmp_ctr)) and 'dib' or 'hide'
            complete_creative_list.append(custom_creative)

    # 获取商品主图
    tapi = get_tapi(shop_id=shop_id)
    item_img_list = CustomCreative.get_item_img_list(
        tapi=tapi, shop_id=shop_id, item_id_list=[adgroup.item_id])
    img_list = item_img_list and item_img_list[adgroup.item_id] or None

    return render_to_response('image_optimize.html', {
        'adg': adgroup,
        'creatives': creative_list,
        'waiting_creatives': waiting_creative_list,
        'complete_creatives': complete_creative_list,
        'img_list': img_list,
        'start_date': start_date,
        'end_date': end_date,
        'date_text': date_text
    },
                              context_instance=RequestContext(request))
Пример #6
0
def export_workbench_data(customer_list, export_type):
    """个人工作台数据导出"""
    title = "客户列表"
    export_list = []
    for data in customer_list:
        temp_data = {
            'shop_id': data.shop_id,
            'nick': data.nick,
            'phone': data.phone,
            'qq': data.qq,
            'category': data.category,
            'department': '',
            'name_cn': ''
        }
        if hasattr(data, 'consult'):
            if hasattr(data.consult, 'department'):
                temp_data.update({
                    'department':
                    dict(PSUser.DEPARTMENT_CHOICES)[data.consult.department]
                })
            if hasattr(data.consult, 'name_cn'):
                temp_data.update({'name_cn': data.consult.name_cn})
        elif hasattr(data, 'operater'):
            if hasattr(data.operater, 'department'):
                temp_data.update({
                    'department':
                    dict(PSUser.DEPARTMENT_CHOICES)[data.operater.department]
                })
            if hasattr(data.operater, 'name_cn'):
                temp_data.update({'name_cn': data.operater.name_cn})

        if hasattr(data, 'order_info'):
            order_info = data.order_info
            if order_info:
                temp_data.update({
                    'create_time':
                    datetime_2string(order_info.create_time, '%Y-%m-%d'),
                    'end_date':
                    datetime_2string(order_info.end_date, '%Y-%m-%d'),
                    'biz_type':
                    order_info.display_biz_type(),
                    'cycle':
                    order_info.cycle,
                    'pay':
                    '%.2f' % (order_info.pay / 100.0),
                    'item_code':
                    order_info.item_code
                })
        if hasattr(data, 'rpt'):
            rpt = data.rpt if data.rpt else {
                'click': 0,
                'cost': '0.00',
                'paycount': 0,
                'pay': '0.00',
                'cpc': '0.00',
                'ctr': '0.00',
                'roi': '0.00'
            }
            temp_data.update(rpt)
        export_list.append(temp_data)

    column_dict = [{
        'key': 'shop_id',
        'name': '店铺ID'
    }, {
        'key': 'nick',
        'name': '店铺名称',
        'width': 2
    }, {
        'key': 'phone',
        'name': '电话',
        'width': 2
    }, {
        'key': 'qq',
        'name': 'QQ'
    }, {
        'key': 'category',
        'name': '店铺类别',
        'width': 2
    }, {
        'key': 'name_cn',
        'name': '所属顾问'
    }, {
        'key': 'department',
        'name': '所属部门'
    }]

    if export_type == '1':
        column_dict += [{
            'key': 'create_time',
            'name': '订购时间'
        }, {
            'key': 'end_date',
            'name': '到期时间'
        }, {
            'key': 'biz_type',
            'name': '订单类型'
        }, {
            'key': 'cycle',
            'name': '订购周期'
        }, {
            'key': 'pay',
            'name': '实付金额'
        }, {
            'key': 'item_code',
            'name': '版本Code',
            'width': 2
        }]
    elif export_type == '2':
        column_dict += [{
            'key': 'click',
            'name': '7天点击量'
        }, {
            'key': 'cost',
            'name': '7天总花费'
        }, {
            'key': 'paycount',
            'name': '7天成交量'
        }, {
            'key': 'pay',
            'name': '7天成交金额'
        }, {
            'key': 'cpc',
            'name': 'PPC'
        }, {
            'key': 'ctr',
            'name': 'CTR'
        }, {
            'key': 'roi',
            'name': 'ROI'
        }]
    elif export_type == '3':
        column_dict += [{
            'key': 'create_time',
            'name': '订购时间'
        }, {
            'key': 'end_date',
            'name': '到期时间'
        }, {
            'key': 'biz_type',
            'name': '订单类型'
        }, {
            'key': 'cycle',
            'name': '订购周期'
        }, {
            'key': 'pay',
            'name': '实付金额'
        }, {
            'key': 'item_code',
            'name': '版本Code',
            'width': 2
        }, {
            'key': 'click',
            'name': '7天点击量'
        }, {
            'key': 'cost',
            'name': '7天总花费'
        }, {
            'key': 'paycount',
            'name': '7天成交量'
        }, {
            'key': 'pay',
            'name': '7天成交金额'
        }, {
            'key': 'cpc',
            'name': 'PPC'
        }, {
            'key': 'ctr',
            'name': 'CTR'
        }, {
            'key': 'roi',
            'name': 'ROI'
        }]
    response = export_excel(title, column_dict, export_list)
    return response
Пример #7
0
def get_trend_chart_data(data_type, rpt_list):
    '''
    /封装趋势图数据
    data_type=((1,customer),(2,campaign),(3,adgroup),(4,keyword),(5,qnyd_acount),(6,ncrm_account))
    '''

    def format_digit(i):
        return round_digit(i, 2)

    def div100(i):
        return round_digit(float(i) / 100, 2)

    def mul100(i):
        return round_digit(float(i) / 0.01, 2)

    series_cfg_dict = {
        'impr':{'name':'展现量', 'color':'#426ab3', 'func':None, 'unit':'次', 'field_name':'impressions', 'value_list':[], 'visible':False, 'opposite':False, 'is_axis':0, 'yaxis':0},
        'click':{'name':'点击量', 'color':'#87CEFA', 'func':None, 'unit':'次', 'field_name':'click', 'value_list':[], 'visible':False, 'opposite':False, 'is_axis':1, 'yaxis':0},
        'cpc':{'name':'PPC', 'color':'#06B9D1', 'func':div100, 'unit':'元', 'field_name':'cpc', 'value_list':[], 'visible':False, 'opposite':False, 'is_axis':1, 'yaxis':1},
        'ctr':{'name':'点击率', 'color':'#005687', 'func':format_digit, 'unit':'%', 'field_name':'ctr', 'value_list':[], 'visible':False, 'opposite':False, 'is_axis':1, 'yaxis':2},
        'cost':{'name':'总花费', 'color':'#1E90FF', 'func':div100, 'unit':'元', 'field_name':'cost', 'value_list':[], 'visible':True, 'opposite':True, 'is_axis':1, 'yaxis':3},
        'pay':{'name':'成交额', 'color':'#FD5B78', 'func':div100, 'unit':'元', 'field_name':'pay', 'value_list':[], 'visible':True, 'opposite':True, 'is_axis':0, 'yaxis':3}, # 与花费共y坐标
        'paycount':{'name':'成交量', 'color':'#FF84BA', 'func':None, 'unit':'笔', 'field_name':'paycount', 'value_list':[], 'visible':False, 'opposite':True, 'is_axis':1, 'yaxis':4},
        'favcount':{'name':'收藏量', 'color':'#f3715c', 'func':None, 'unit':'次', 'field_name':'favcount', 'value_list':[], 'visible':False, 'opposite':True, 'is_axis':0, 'yaxis':4},
        'roi':{'name':'ROI', 'color':'#FF0090', 'func':format_digit, 'unit':'', 'field_name':'roi', 'value_list':[], 'visible':False, 'opposite':True, 'is_axis':1, 'yaxis':5},
        'conv':{'name':'转化率', 'color':'#BF0A10', 'func':format_digit, 'unit':'%', 'field_name':'conv', 'value_list':[], 'visible':False, 'opposite':False, 'is_axis':0, 'yaxis':2},
        'shop_pv':{'name':'店铺总流量', 'color':'#5c7a29', 'func':None, 'unit':'次', 'field_name':'shop_pv', 'value_list':[], 'visible':False, 'opposite':False, 'is_axis':0, 'yaxis':0},
        'shop_uv':{'name':'店铺访客数', 'color':'#7fb80e', 'func':None, 'unit':'次', 'field_name':'shop_uv', 'value_list':[], 'visible':False, 'opposite':False, 'is_axis':0, 'yaxis':0},
        'shop_conv':{'name':'店铺转化率', 'color':'#00FF7F', 'func':mul100, 'unit':'%', 'field_name':'shop_conv', 'value_list':[], 'visible':False, 'opposite':False, 'is_axis':0, 'yaxis':2},
        'item_pv':{'name':'宝贝自然流量', 'color':'#5c7a29', 'func':None, 'unit':'次', 'field_name':'item_pv', 'value_list':[], 'visible':False, 'opposite':False, 'is_axis':0, 'yaxis':0},
        'item_uv':{'name':'宝贝访客数', 'color':'#7fb80e', 'func':None, 'unit':'次', 'field_name':'item_uv', 'value_list':[], 'visible':False, 'opposite':False, 'is_axis':0, 'yaxis':0},
        'item_conv':{'name':'宝贝转化率', 'color':'#00FF7F', 'func':None, 'unit':'%', 'field_name':'item_conv', 'value_list':[], 'visible':False, 'opposite':False, 'is_axis':0, 'yaxis':2}, # 与点击率共y坐标
        'avgpos':{'name':'昨日平均排名', 'color':'#614B36', 'func':None, 'unit':'', 'field_name':'avgpos', 'value_list':[], 'visible':False, 'opposite':False, 'is_axis':0, 'yaxis':0},
        'carttotal':{'name':'购物车总数', 'color':'#663399', 'func':None, 'unit':'', 'field_name':'carttotal', 'value_list':[], 'visible':False, 'opposite':False, 'is_axis':0, 'yaxis':4},
        }

    if data_type == 1:
        key_list = ['impr', 'click', 'cpc', 'ctr', 'cost', 'pay', 'paycount', 'favcount', 'roi', 'conv', 'carttotal']
    elif data_type == 2:
        key_list = ['impr', 'click', 'cpc', 'ctr', 'cost', 'pay', 'paycount', 'favcount', 'roi', 'conv']
    elif data_type == 3:
        key_list = ['impr', 'click', 'cpc', 'ctr', 'cost', 'pay', 'paycount', 'favcount', 'roi', 'conv']
    elif data_type == 4:
        key_list = ['impr', 'click', 'cpc', 'ctr', 'cost', 'pay', 'paycount', 'favcount', 'roi', 'avgpos']
    elif data_type == 5:
        key_list = ['cost', 'pay', 'click', 'roi']
    elif data_type == 6:
        key_list = ['impr', 'click', 'cpc', 'ctr', 'cost', 'pay', 'paycount', 'roi', 'conv']
    else:
        key_list = []

    category_list = []
    series_cfg_list = [series_cfg_dict[k] for k in key_list]
    now = datetime_2string(fmt = '%m-%d')
    for rpt in rpt_list:
        item_date = datetime_2string(rpt.date, "%m-%d")
        if item_date == now:
            category_list.append('实时数据')
        else:
            category_list.append(item_date)
        for series_cfg in series_cfg_list:
            value = getattr(rpt, series_cfg['field_name'])
            value = value and series_cfg['func'] and series_cfg['func'](value) or value
            series_cfg['value_list'].append(value)

    for series_cfg in series_cfg_list:
        del series_cfg['func']
    return category_list, series_cfg_list
Пример #8
0
def campaign_list(request):
    """获取计划数据"""
    shop_id = int(request.user.shop_id)
    campaign_list = Campaign.objects.filter(
        shop_id=shop_id).order_by('campaign_id')
    start_date = request.POST.get('start_date')
    end_date = request.POST.get('end_date')
    camp_rpt_dict = {}
    mnt_list = MntCampaign.objects.only('campaign_id', 'mnt_index', 'mnt_type',
                                        'start_time').filter(shop_id=shop_id)
    mnt_dict = {
        mnt.campaign_id:
        (mnt.mnt_index, mnt.mnt_type, mnt.get_mnt_type_display(),
         days_diff_interval(mnt.start_time.date()))
        for mnt in mnt_list
    }
    adg_num_dict = Adgroup.get_adgroup_count(shop_id=shop_id)
    json_campaign_list = []
    init_mnt_list = (0, 0, '', 0)
    is_rt_camp = 0

    if start_date == end_date == datetime.date.today().strftime('%Y-%m-%d'):
        camp_rpt_dict = RealtimeReport.get_summed_rtrpt(rpt_type='campaign',
                                                        args_list=[shop_id])
        if camp_rpt_dict:
            is_rt_camp = 1
    else:
        camp_rpt_dict = Campaign.Report.get_summed_rpt(
            query_dict={'shop_id': shop_id},
            start_date=start_date,
            end_date=end_date)

    for camp in campaign_list:
        tmp_rpt = camp_rpt_dict.get(camp.campaign_id, Campaign.Report())
        tmp_rpt_dict = tmp_rpt.to_dict()
        mnt_info = mnt_dict.get(camp.campaign_id, init_mnt_list)
        mnt_index, mnt_type, mnt_name, mnt_days = mnt_info
        temp_adg_num_tuple = adg_num_dict.get(camp.campaign_id, (0, 0, 0))

        yd_search = 0  # 是否在移动端推广
        if camp.platform['yd_outsite'] or camp.platform['yd_insite']:
            yd_search = 1

        schedule = 0
        now_date = time.mktime(datetime.datetime.now().timetuple())
        now_date_str = datetime_2string(None, '%Y-%m-%d')

        try:
            for _schedule in camp.schedule.split(';')[
                    datetime.datetime.now().weekday()].split(','):
                start_time = string_2datetime(
                    now_date_str + ' ' + _schedule[0:5], '%Y-%m-%d %H:%M')
                end_time = string_2datetime(
                    now_date_str + ' ' + ('23:59' if _schedule[6:11] == '24:00'
                                          else _schedule[6:11]),
                    '%Y-%m-%d %H:%M')
                if time.mktime(
                        start_time.timetuple()) <= now_date and time.mktime(
                            end_time.timetuple()) >= now_date:
                    schedule = _schedule[12:len(_schedule)]
                    break
        except:
            pass

        temp_camp = {
            'campaign_id': camp.campaign_id,
            'title': camp.title,
            'budget': '%.0f' % (camp.budget / 100.0),
            'online_status': camp.online_status,
            'comment_count': camp.comment_count,
            'error_descr': camp.error_descr,
            'is_smooth': camp.is_smooth and 1 or 0,
            'adg_num': temp_adg_num_tuple[0],
            'mnt_index': mnt_index,
            'mnt_name': mnt_name,
            'mnt_type': mnt_type,
            'schedule': schedule,
            'yd_search': yd_search,
            'mnt_days': mnt_days
        }
        temp_camp.update(tmp_rpt_dict)
        json_campaign_list.append(temp_camp)

    return {
        'errMsg': '',
        'json_campaign_list': json_campaign_list,
        'is_rt_camp': is_rt_camp
    }
Пример #9
0
def mnt_campaign(request, campaign_id, template='mnt_campaign.html'):
    shop_id = int(request.user.shop_id)
    campaign_id = int(campaign_id)
    mnt_list = []
    mnt_campaign_dict = dict(
        MntCampaign.objects.filter(shop_id=shop_id).values_list(
            'campaign_id', 'mnt_type'))
    campaign_list = list(Campaign.objects.filter(shop_id=shop_id))
    mnt_desc_dict = dict(MNT_TYPE_CHOICES)
    campaign = None
    for camp in campaign_list:
        camp.mnt_type = mnt_campaign_dict.get(camp.campaign_id, 0)
        camp.mnt_name = mnt_desc_dict.get(camp.mnt_type, '').replace(
            '托管', '') if camp.mnt_type else '手动'
        mnt_list.append({
            'campaign_id': camp.id,
            'name': camp.title,
            'mnt_type_name': camp.mnt_name
        })
        if camp.id == campaign_id:
            campaign = camp
    if campaign is None:
        return render_to_error(request, "该计划不存在,请返回页面重新操作")

    snap_list = campaign.get_snap_list(rpt_days=7)
    start_time = None
    mnt_days = 0
    try:
        mnt_camp = MntCampaign.objects.get(shop_id=shop_id,
                                           campaign_id=campaign_id)
        campaign.optimize_time = mnt_camp.optimize_time and time_humanize(
            mnt_camp.optimize_time) or "0"
        campaign.mnt_type = mnt_camp.mnt_type
        campaign.max_num = mnt_camp.max_num
        campaign.max_price = '%.2f' % (mnt_camp.max_price / 100.0)
        campaign.mobile_max_price = '%.2f' % (mnt_camp.real_mobile_max_price /
                                              100.0)
        campaign.mnt_desc = mnt_camp.get_mnt_type_display()
        campaign.is_active = mnt_camp.is_active
        campaign.quick_optime = mnt_camp.quick_optime
        campaign.mnt_bid_factor = mnt_camp.mnt_bid_factor
        campaign.mnt_rt = mnt_camp.mnt_rt
        start_time = datetime_2string(mnt_camp.start_time, '%Y年%m月%d日')
        mnt_days = days_diff_interval(mnt_camp.start_time.date())
    except DoesNotExist:
        campaign.mnt_type = 0
        campaign.max_num = 0
        campaign.max_price = 0.00
        campaign.mobile_max_price = 0.00
        campaign.mnt_desc = "未托管计划"
        campaign.is_active = False
        campaign.quick_optime = datetime.datetime.now()
        campaign.mnt_bid_factor = 50
        campaign.mnt_rt = 0

    is_smooth = campaign.is_smooth and 1 or 0
    budget = '%.0f' % (campaign.budget / 100.0)

    from apps.web.utils import get_trend_chart_data
    category_list, series_cfg_list = get_trend_chart_data(data_type=2,
                                                          rpt_list=snap_list)
    snap_list.reverse()
    camp_dict = dict(
        Campaign.objects.filter(shop_id=shop_id).values_list(
            'campaign_id', 'title'))
    mnt_opter, _ = analysis_web_opter(request)
    return render_to_response(template, {
        'camp': campaign,
        'mnt_list': mnt_list,
        'snap_list': snap_list,
        'is_smooth': is_smooth,
        'budget': budget,
        'category_list': category_list,
        'series_cfg_list': json.dumps(series_cfg_list),
        'camp_dict': camp_dict,
        'mnt_opter': mnt_opter,
        'add_adgroup': campaign.mnt_type,
        'start_time': start_time,
        'mnt_days': mnt_days
    },
                              context_instance=RequestContext(request))