Exemple #1
0
def task_push_new_mama_task(xlmm, current_task, params=None):
    """
    通知完成某新手任务,同时提醒下一个任务
    """
    return  # 暂时关闭新手任务推送

    from shopapp.weixin.apis import WeixinPush
    from flashsale.xiaolumm.models.new_mama_task import NewMamaTask

    next_task = xlmm.get_next_new_mama_task()

    header = NewMamaTask.get_push_msg(current_task, params=params)[0]

    if next_task:
        footer = NewMamaTask.get_push_msg(next_task, params=params)[1]
        to_url = NewMamaTask.get_push_msg(next_task, params=params)[2]
    else:
        footer = u'\n恭喜你,完成所有新手任务。'
        to_url = ''

    if not params:
        params = {'task_name': NewMamaTask.get_task_desc(current_task)}
    else:
        params['task_name'] = NewMamaTask.get_task_desc(current_task)

    wxpush = WeixinPush()
    wxpush.push_new_mama_task(xlmm.id,
                              header=header,
                              footer=footer,
                              to_url=to_url,
                              params=params)
Exemple #2
0
def task_push_mission_state_msg_to_weixin_user(mission_record_id, state):
    """state: staging,任务未完成状态通知; finished,任务完成奖励通知; confirm,任务奖励确认通知; cancel,任务奖励取消通知;"""
    try:
        from shopapp.weixin.apis import WeixinPush
        mama_mission = MamaMissionRecord.objects.filter(
            id=mission_record_id).first()
        if not settings.MAMA_MISSION_PUSH_SWITCH and mama_mission.mama_id > 135:
            return

        base_mission = mama_mission.mission
        if not base_mission.is_push_msg:
            return

        mama_grade = MamaSaleGrade.objects.filter(
            mama_id=mama_mission.mama_id).first()
        wxpush = WeixinPush()
        if state == MamaMissionRecord.STAGING:
            week_end_time = datetime.datetime.strptime(
                '%s-0' % mama_mission.year_week, '%Y-%W-%w')
            mission_kpi_unit = base_mission.kpi_type == MamaMission.KPI_COUNT and u'个' or u'元'

            head_title = u'女王,您本周还有一个任务未完成,点击查看奖励规则!'
            if mama_grade and base_mission.cat_type == MamaMission.CAT_SALE_MAMA:
                mama_grade_params = {
                    'grade': mama_grade.get_grade_display(),
                    'combo': mama_grade.combo_count
                }
                head_title = u'女王,您本周销售任务奖励等级为{grade}级,连续达标{combo}次,点击查看奖励规则!'.format(
                    **mama_grade_params)

            params = {
                'header':
                head_title,
                'footer':
                u'小鹿妈妈在截止日期前完成任务可获取额外奖励 (本周业绩越好,下周可获取额外奖励越高,点击查看奖励规则).',
                'task_name':
                mama_mission.get_mission_name(),
                'award_amount':
                u'¥%.2f' % mama_mission.get_award_amount(),
                'deadline':
                u'%s' % week_end_time.strftime('%Y-%m-%d'),
                'target_state':
                u'已完成 %s %s/(目标数 %s %s)' %
                (mama_mission.get_finish_value(), mission_kpi_unit,
                 mama_mission.get_target_value(), mission_kpi_unit),
                'description':
                base_mission.desc,
            }

            wxpush.push_mission_state_task(
                mama_mission.mama_id,
                header=params.get('header'),
                footer=params.get('footer'),
                to_url=constants.WEEKLY_AWARD_RULES_URL,
                params=params)

        elif state == MamaMissionRecord.FINISHED:
            params = {
                'header':
                u'女王,本周有一任务已完成,奖励已生成,请到小鹿美美app任务列表查看吧!',
                'footer':
                u'小鹿妈妈在截止日期前完成任务可获取额外奖励 (妈妈销售奖励预计收益,需7天后变成确认收益,退款会影响收益到账哦).',
                'task_name':
                u'%s, 赏¥%.2f元' % (mama_mission.get_mission_name(),
                                  mama_mission.get_award_amount()),
                'task_type':
                base_mission.get_cat_type_display(),
                'finish_time':
                mama_mission.finish_time
            }
            wxpush.push_new_mama_task(mama_mission.mama_id,
                                      header=params.get('header'),
                                      footer=params.get('footer'),
                                      to_url=constants.WEEKLY_AWARD_RULES_URL,
                                      params=params)

        elif state == MamaMissionRecord.CONFIRM:
            params = {
                'header':
                u'女王,(%s)周任务奖励已到账,请到小鹿美美app任务列表查看吧!' % mama_mission.year_week,
                'footer':
                u'小鹿妈妈在截止日期前完成任务可获取额外奖励 (本周业绩越好,下周可获取额外奖励越高,点击查看奖励规则).',
                'task_name':
                u'%s, 赏¥%.2f元' % (mama_mission.get_mission_name(),
                                  mama_mission.get_award_amount()),
                'task_type':
                base_mission.get_cat_type_display(),
                'finish_time':
                mama_mission.finish_time
            }
            wxpush.push_new_mama_task(mama_mission.mama_id,
                                      header=params.get('header'),
                                      footer=params.get('footer'),
                                      to_url=constants.WEEKLY_AWARD_RULES_URL,
                                      params=params)

        elif state == MamaMissionRecord.CANCEL:
            week_end_time = datetime.datetime.strptime(
                '%s-0' % mama_mission.year_week, '%Y-%W-%w')
            mission_kpi_unit = base_mission.kpi_type == MamaMission.KPI_COUNT and u'个' or u'元'
            params = {
                'header':
                u'女王,您有笔交易退款,导致(%s)周销售任务未达预期奖励取消,请到小鹿美美app任务列表查看吧!' %
                mama_mission.year_week,
                'footer':
                u'妈妈销售奖励预计收益,需7天后变成确认收益,退款会影响收益到账哦( 如有疑问请咨询客服热线: 400-823-5355,点击查看奖励规则)',
                'task_name':
                mama_mission.get_mission_name(),
                'award_amount':
                u'¥%.2f' % mama_mission.get_award_amount(),
                'deadline':
                u'%s' % week_end_time.strftime('%Y-%m-%d'),
                'target_state':
                u'已完成 %s %s/(目标数 %s %s)' %
                (mama_mission.get_finish_value(), mission_kpi_unit,
                 mama_mission.get_target_value(), mission_kpi_unit),
                'description':
                base_mission.desc,
            }
            wxpush.push_mission_state_task(
                mama_mission.mama_id,
                header=params.get('header'),
                footer=params.get('footer'),
                to_url=constants.WEEKLY_AWARD_RULES_URL,
                params=params)

    except Exception, exc:
        raise task_push_mission_state_msg_to_weixin_user.retry(exc=exc)