Example #1
0
    def push_mama_invite_award(self,
                               mama,
                               buy_customer,
                               amount,
                               level_1_customer=None):
        """
        购买小鹿全球精品会员注册礼包,给推荐人发推送

        {{first.DATA}}
        任务名称:{{keyword1.DATA}}
        奖励金额:{{keyword2.DATA}}
        时间:{{keyword3.DATA}}
        {{remark.DATA}}
        """
        customer = utils.get_mama_customer(mama.id)
        now = datetime.datetime.now()

        if level_1_customer:
            first = u'恭喜你团队{}增加一名新成员{}!'.format(level_1_customer.nick,
                                                buy_customer.nick)
        else:
            first = u'恭喜你团队增加一名成员{}, 请邀请你朋友加入到团队群!'.format(buy_customer.nick)

        if type(amount) == str or type(amount) == unicode:
            amount = u'%s' % amount
        else:
            amount = u'¥%.2f' % amount,

        template_ids = {
            'meimei': 'K2RVQnhIh6psYkGrkjLclLWmNXQ-hqoc-yumdsLuqC4',
            'temai': 'ATPs2YP1ynKfgtXRl1fhhZ2Kne3AmDmU8Rghax31edg'
        }
        template_data = {
            'first': {
                'value': first,
                'color': '#F87217',
            },
            'keyword1': {
                'value': u'推荐新人',
                'color': '#000000',
            },
            'keyword2': {
                'value': amount,
                'color': '#ff0000',
            },
            'keyword3': {
                'value': u'%s' % now.strftime('%Y-%m-%d %H:%M:%S'),
                'color': '#000000',
            },
            'remark': {
                'value': u'',
                'color': '#F87217',
            },
        }
        to_url = 'https://m.xiaolumeimei.com'

        return self.push(customer, template_ids, template_data, to_url)
Example #2
0
    def push_mission_state_task(self,
                                mama_id,
                                header='',
                                footer='',
                                to_url='',
                                params=None):
        """
        新任务提醒

        {{first.DATA}}
        任务名称:{{keyword1.DATA}}
        奖励金额:{{keyword2.DATA}}
        截止时间:{{keyword3.DATA}}
        需求数量:{{keyword4.DATA}}
        任务简介:{{keyword5.DATA}}
        {{remark.DATA}}
        """
        customer = utils.get_mama_customer(mama_id)
        if not params:
            params = {}

        template_ids = {
            'meimei': '5dmrReey6YXG-eRuNWsfpK0xFL35xzk0UoJ43DJHwJ4',
            'temai': '98pFo0KBn5WFLecvFnC2Ve_atd9wNYXdBc5zO4jJO9g'
        }
        template_data = {
            'first': {
                'value': header,
                'color': '#4CC417',
            },
            'keyword1': {
                'value': params.get('task_name', ''),
                'color': '#4CC417',
            },
            'keyword2': {
                'value': params.get('award_amount', u'不限额'),
                'color': '#4CC417',
            },
            'keyword3': {
                'value': params.get('deadline', ''),
                'color': '#4CC417',
            },
            'keyword4': {
                'value': params.get('target_state', ''),
                'color': '#4CC417',
            },
            'keyword5': {
                'value': params.get('description', ''),
                'color': '#4CC417',
            },
            'remark': {
                'value': footer,
                'color': '#4CC417',
            },
        }
        return self.push(customer, template_ids, template_data, to_url)
Example #3
0
    def push_mama_update_app(self,
                             mama_id,
                             user_version,
                             latest_version,
                             to_url,
                             device=''):
        """
        {{first.DATA}}
        系统名称:{{keyword1.DATA}}
        运维状态:{{keyword2.DATA}}
        {{remark.DATA}}
        """
        customer = utils.get_mama_customer(mama_id)

        if self.need_sms_push(customer):
            sms = SMSPush()
            sms.push_mama_update_app(customer)
            return

        template_ids = {
            'meimei': 'l9QBpAojbpQmFIRmhSN4M-eQDzkw76yBpfrYcBoakK0',
            'temai': 'x_nPMjWKodG0V4w334I_u5LAFpoTH1fSqjAv5jPmA7Y'
        }
        template = WeixinTplMsg.objects.filter(
            wx_template_id__in=template_ids.values(), status=True).first()

        if not template:
            return

        template_data = {
            'first': {
                'value': template.header.decode('string_escape'),
                'color': '#4CC417',
            },
            'keyword1': {
                'value': u'您的当前%s版本:%s' % (device, user_version),
                'color': '#4CC417',
            },
            'keyword2': {
                'value': u'最新发布%s版本:%s' % (device, latest_version),
                'color': '#ff0000',
            },
            'remark': {
                'value': template.footer.decode('string_escape'),
                'color': '#4CC417',
            },
        }

        return self.push(customer, template_ids, template_data, to_url)
Example #4
0
    def push_mama_ordercarry(cls, ordercarry):
        """
        有新的订单收益推送给小鹿妈妈
        """
        customer = get_mama_customer(ordercarry.mama_id)
        target_url = get_target_url(protocal_constants.TARGET_TYPE_VIP_HOME)
        msgtpl = PushMsgTpl.objects.filter(id=5, is_valid=True).first()
        msg    = ''
        if msgtpl:
            money = '%.2f' % ordercarry.carry_num_display()
            nick = ordercarry.contributor_nick
            msg = msgtpl.get_emoji_content().format(money, nick)

        if msg:
            cls.push(customer.id, target_url, msg)
Example #5
0
    def push_new_mama_task(self,
                           mama_id,
                           header='',
                           footer='',
                           to_url='',
                           params=None):
        """
        任务完成通知

        {{first.DATA}}
        任务名称:{{keyword1.DATA}}
        任务类型:{{keyword2.DATA}}
        完成时间:{{keyword3.DATA}}
        {{remark.DATA}}
        """
        customer = utils.get_mama_customer(mama_id)
        if not params:
            params = {}

        template_ids = {
            'meimei': 'Lvw0t5ttadeEzRV2tczPclzpPnLXGEQZZJVdWxHyS4g',
            'temai': 'frGeesnAWDCmn5CinuzVGb1VbS5610J8xjM-tgPV7XQ'
        }
        template_data = {
            'first': {
                'value': header,
                'color': '#4CC417',
            },
            'keyword1': {
                'value': params.get('task_name', ''),
                'color': '#4CC417',
            },
            'keyword2': {
                'value': params.get('task_type', u'新手任务'),
                'color': '#4CC417',
            },
            'keyword3': {
                'value': (params.get('finish_time')
                          or datetime.datetime.now()).strftime('%Y-%m-%d'),
                'color':
                '#4CC417',
            },
            'remark': {
                'value': footer,
                'color': '#4CC417',
            },
        }
        return self.push(customer, template_ids, template_data, to_url)
Example #6
0
    def push_mama_award(self, awardcarry, courage_remarks, to_url):
        """
        {{first.DATA}}
        任务名称:{{keyword1.DATA}}
        奖励金额:{{keyword2.DATA}}
        时间:{{keyword3.DATA}}
        {{remark.DATA}}
        """

        customer = utils.get_mama_customer(awardcarry.mama_id)

        if self.need_sms_push(customer):
            sms = SMSPush()
            money = u'¥%.2f' % awardcarry.carry_num_display()
            sms.push_mama_ordercarry(customer, money=money)
            return

        template_ids = {
            'meimei': 'K2RVQnhIh6psYkGrkjLclLWmNXQ-hqoc-yumdsLuqC4',
            'temai': 'ATPs2YP1ynKfgtXRl1fhhZ2Kne3AmDmU8Rghax31edg'
        }
        template_data = {
            'first': {
                'value': u'报!公主殿下, 您的小鹿美美App奖金又来啦!',
                'color': '#F87217',
            },
            'keyword1': {
                'value': u'%s' % awardcarry.carry_type_name(),
                'color': '#000000',
            },
            'keyword2': {
                'value': u'¥%.2f' % awardcarry.carry_num_display(),
                'color': '#ff0000',
            },
            'keyword3': {
                'value':
                u'%s' % awardcarry.created.strftime('%Y-%m-%d %H:%M:%S'),
                'color': '#000000',
            },
            'remark': {
                'value': courage_remarks,
                'color': '#F87217',
            },
        }

        return self.push(customer, template_ids, template_data, to_url)
Example #7
0
    def push_mama_ordercarry_to_all(cls, ordercarry):
        """
        有新的订单收益推送给所有小鹿妈妈,使用透传消息
        """
        topic = APPFullPushMessge.TOPIC_XLMM
        msgtpl = PushMsgTpl.objects.filter(id=12, is_valid=True).first()
        customer = get_mama_customer(ordercarry.mama_id)

        if not msgtpl:
            return

        money = '%.2f' % ordercarry.carry_num_display()
        nick = customer.nick
        content = msgtpl.get_emoji_content().format(nick=nick[:10], money=money)

        msg = {
            'content': content,
            'avatar': customer.thumbnail,
            'type': 'mama_ordercarry_broadcast'
        }
        msg = json.dumps(msg)
        target_url = ''
        cls.push_to_topic(topic, target_url, msg, pass_through=1)
Example #8
0
    def push_mama_invite_trial(self, referal_mama_id, potential_mama_id,
                               diff_num, award_num, invite_num, award_sum,
                               trial_num, carry_num):
        """
        {{first.DATA}}
        姓名:{{keyword1.DATA}}
        手机:{{keyword2.DATA}}
        会员等级:{{keyword3.DATA}}
        {{remark.DATA}}
        """

        referal_customer = utils.get_mama_customer(referal_mama_id)

        if not referal_customer:
            return

        potential_customer = utils.get_mama_customer(potential_mama_id)
        mobile_string = ''
        if potential_customer.mobile:
            mobile = potential_customer.mobile
            mobile_string = '%s****%s' % (mobile[0:3], mobile[7:])

        template_ids = {
            'meimei': 'tvns3YwYkRkkd2mycvxKsbRtuQl1spBHxtm9PLFIlFI',
            'temai': 'O6SYsBHUpYpk9UTUzmUrhybU7arHuFsz2shox0JOg1s'
        }
        template = WeixinTplMsg.objects.filter(
            wx_template_id__in=template_ids.values(), status=True).first()

        if not template:
            return

        template_data = {
            'first': {
                'value':
                template.header.format(
                    diff_num=diff_num,
                    award_num=award_num).decode('string_escape'),
                'color':
                '#F87217',
            },
            'keyword1': {
                'value':
                u'%s (ID:%s)' % (potential_customer.nick, potential_mama_id),
                'color':
                '#4CC417',
            },
            'keyword2': {
                'value': mobile_string,
                'color': '#4CC417',
            },
            'keyword3': {
                'value': u'15天体验试用',
                'color': '#4CC417',
            },
            'remark': {
                'value':
                template.footer.format(invite_num=invite_num,
                                       award_sum=award_sum,
                                       trial_num=trial_num,
                                       award_total=trial_num *
                                       carry_num).decode('string_escape'),
                'color':
                '#F87217',
            },
        }
        to_url = 'http://m.xiaolumeimei.com'
        return self.push(referal_customer, template_ids, template_data, to_url)
Example #9
0
    def push_mama_coupon_audit(self, coupon_record):
        """
        审核申请提醒

        {{first.DATA}}
        审核内容:{{keyword1.DATA}}
        客户名称:{{keyword2.DATA}}
        商品名称:{{keyword3.DATA}}
        申请金额:{{keyword4.DATA}}
        {{remark.DATA}}
        """
        from flashsale.coupon.models import CouponTemplate

        if coupon_record.transfer_type in [CouponTransferRecord.OUT_TRANSFER]:
            mama_id = coupon_record.coupon_from_mama_id
        elif coupon_record.transfer_type in [
                CouponTransferRecord.OUT_CASHOUT,
                CouponTransferRecord.IN_RETURN_COUPON
        ]:
            mama_id = coupon_record.coupon_to_mama_id
        else:
            return

        customer = utils.get_mama_customer(mama_id)
        if not customer:
            return

        event_type = WeixinPushEvent.COUPON_TRANSFER_AUDIT
        template_id = 'GQqbrGtAmmKdUnknaaIEmW7DakgvQK6apfROTxzYkUs'
        template = WeixinTplMsg.objects.filter(wx_template_id=template_id,
                                               status=True).first()

        if not template:
            return

        today = datetime.datetime.now().date()
        uni_key = '{mama_id}-{date}-coupon_audit-{coupon_record_id}'.format(
            **{
                'mama_id': mama_id,
                'date': today.strftime('%Y%m%d'),
                'coupon_record_id': coupon_record.id
            })

        coupon_template = CouponTemplate.objects.filter(
            id=coupon_record.template_id).first()

        header = template.header.format().decode('string_escape')
        footer = template.footer.format().decode('string_escape')
        to_url = 'https://m.xiaolumeimei.com/rest/v1/users/weixin_login/?next=https://m.xiaolumeimei.com/tran_coupon/html/trancoupon.html'
        footer_color = '#F87217'

        template_data = {
            'first': {
                'value': header,
                'color': '#F87217',
            },
            'keyword1': {
                'value': u'精品券申请',
                'color': '#000000',
            },
            'keyword2': {
                'value': u'%s' % coupon_record.to_mama_nick,
                'color': '#000000',
            },
            'keyword3': {
                'value': u'%s' % coupon_template.title,
                'color': '#000000',
            },
            'keyword4': {
                'value':
                u'%.2f元 x %s个' %
                (coupon_record.coupon_value, coupon_record.coupon_num),
                'color':
                '#000000',
            },
            'remark': {
                'value': footer,
                'color': footer_color,
            },
        }

        event = WeixinPushEvent(customer_id=customer.id,
                                mama_id=mama_id,
                                uni_key=uni_key,
                                tid=template.id,
                                event_type=event_type,
                                params=template_data,
                                to_url=to_url)
        event.save()
Example #10
0
    def push_mama_clickcarry(self, clickcarry, fake=False, advertising=False):
        """
        推送点击收益

        ---
        收益通知

        {{first.DATA}}
        收益类型:{{keyword1.DATA}}
        收益金额:{{keyword2.DATA}}
        收益时间:{{keyword3.DATA}}
        剩余金额:{{keyword4.DATA}}
        {{remark.DATA}}


        """
        mama_id = clickcarry.mama_id
        customer = utils.get_mama_customer(mama_id)
        try:
            userbudget = customer.userbudget
        except Exception:
            return

        if fake:
            event_type = WeixinPushEvent.FAKE_CLICK_CARRY
        else:
            event_type = WeixinPushEvent.CLICK_CARRY

        template_id = 'n9kUgavs_10Dz8RbIgY2F9r6rNdlNw3I6D1KLft0_2I'
        template = WeixinTplMsg.objects.filter(wx_template_id=template_id,
                                               status=True).first()

        if not template:
            return

        today = datetime.datetime.now().date()
        last_event = WeixinPushEvent.objects.filter(
            mama_id=mama_id, date_field=today,
            event_type=event_type).order_by('-created').first()

        if last_event:
            if last_event.uni_key.startswith('fake'):
                _, _, _, _, last_click_num, last_total_value = last_event.uni_key.split(
                    '-')
            else:
                _, _, _, last_click_num, last_total_value = last_event.uni_key.split(
                    '-')
            carry_count = clickcarry.click_num - int(last_click_num)
            carry_money = clickcarry.total_value - int(last_total_value)

            # 一段时间内不许重复推送
            delta = datetime.datetime.now() - last_event.created
            if delta.seconds < 60 * 60 * 3 and clickcarry.click_num < clickcarry.init_click_limit:
                return
            if carry_count < 0 or carry_money < 0:
                return
        else:
            carry_count = clickcarry.click_num
            carry_money = clickcarry.total_value

        uni_key = '{mama_id}-{date}-clickcarry-{click_num}-{total_value}'.format(
            **{
                'mama_id': mama_id,
                'date': clickcarry.date_field.strftime('%Y%m%d'),
                'click_num': clickcarry.click_num,
                'total_value': clickcarry.total_value
            })
        if fake:
            uni_key = 'fake-' + uni_key

        header = template.header.format(carry_count).decode('string_escape')
        footer = template.footer.format(
            '%.2f' % (clickcarry.total_value * 0.01)).decode('string_escape')
        to_url = 'http://m.xiaolumeimei.com/rest/v2/mama/redirect_stats_link?link_id=4'
        footer_color = '#F87217'

        # 模板消息底部替换为小广告
        if fake or advertising:
            from flashsale.pay.models.admanager import ADManager
            ads = ADManager.objects.filter(status=True)
            if ads.count() > 0:
                ad = random.choice(ads)
                footer = u'\n%s' % ad.title
                footer_color = '#ff0000'
                to_url = ad.url

        template_data = {
            'first': {
                'value': header,
                'color': '#F87217',
            },
            'keyword1': {
                'value': u'点击收益',
                'color': '#000000',
            },
            'keyword2': {
                'value': u'%.2f元' % (carry_money * 0.01),
                'color': '#ff0000',
            },
            'keyword3': {
                'value':
                u'%s' % clickcarry.modified.strftime('%Y-%m-%d %H:%M:%S'),
                'color': '#000000',
            },
            'keyword4': {
                'value': u'%.2f元(可提现)' % (userbudget.amount * 0.01),
                'color': '#000000',
            },
            'remark': {
                'value': footer,
                'color': footer_color,
            },
        }

        event = WeixinPushEvent(customer_id=customer.id,
                                mama_id=mama_id,
                                uni_key=uni_key,
                                tid=template.id,
                                event_type=event_type,
                                params=template_data,
                                to_url=to_url)
        event.save()
Example #11
0
    def push_mama_ordercarry(self, ordercarry, to_url):
        """
        {{first.DATA}}

        提交时间:{{tradeDateTime.DATA}}
        订单类型:{{orderType.DATA}}
        客户信息:{{customerInfo.DATA}}
        {{orderItemName.DATA}}:{{orderItemData.DATA}}
        {{remark.DATA}}
        """
        # CARRY_TYPES = ((1, u'微商城订单'), (2, u'App订单额外+10%'), (3, u'下属订单+20%'),)
        order_type = ""
        if ordercarry.carry_type == 1:
            order_type = u'微商城订单'
        if ordercarry.carry_type == 2:
            order_type = u'App订单(佣金更高哦!)'
        if ordercarry.carry_type == 3:
            order_type = u'下属订单'

        customer = utils.get_mama_customer(ordercarry.mama_id)

        if self.need_sms_push(customer):
            sms = SMSPush()
            money = u'¥%.2f' % ordercarry.carry_num_display()
            sms.push_mama_ordercarry(customer, money=money)
            return

        template_ids = {
            'meimei': 'eBAuTQQxeGw9NFmheYd8Fc5X7CQbMKpfUSmqxnJOyEc',
            'temai': 'IDXvfqC9j_Y1NhVmtRdBcc6W7MNTNCiLdGTrikgdHoJ3E'
        }
        template = WeixinTplMsg.objects.filter(
            wx_template_id__in=template_ids.values(), status=True).first()

        if not template:
            return

        template_data = {
            'first': {
                'value': template.header.decode('string_escape'),
                'color': '#F87217',
            },
            'tradeDateTime': {
                'value': ordercarry.created.strftime('%Y-%m-%d %H:%M:%S'),
                'color': '#000000',
            },
            'orderType': {
                'value': order_type,
                'color': '#000000',
            },
            'customerInfo': {
                'value': ordercarry.contributor_nick,
                'color': '#000000',
            },
            'orderItemName': {
                'value': u'订单佣金',
                'color': '#ff0000',
            },
            'orderItemData': {
                'value': '¥%.2f' % ordercarry.carry_num_display(),
                'color': '#ff0000',
            },
            'remark': {
                'value': template.footer.decode('string_escape'),
                'color': '#F87217',
            },
        }

        return self.push(customer, template_ids, template_data, to_url)