<?php
/**
 * Created by PhpStorm.
 * User: stanley-king
 * Date: 2016/11/15
 * Time: 下午12:26
 */

require_once (BASE_ROOT_PATH . '/helper/sms_helper.php');
require_once (BASE_ROOT_PATH . '/helper/push_sender.php');


class push_helper
{
    static $admin_info = null;

    private static function admin_alias() {
        return bonus\parameters::admin_member_id;
    }
    private static function admin_avatar()
    {
        if(self::$admin_info == null) {
            self::$admin_info = new member_info(self::admin_alias());
        }
        return self::$admin_info->avatar();
    }

    public static function stolen_bonus(member_info $from_info,member_info $to_info,$amount)
    {
        $thief = $to_info->nickname();
        $text = "{$thief}偷走了您{$amount}元的红包.";

        $push_param['alias'] = $from_info->member_id();
        $push_param['title'] = "摇红包";
        $push_param['text'] = $text;

        $push_param['extra']['go_type']   = 'bonus';
        $push_param['extra']['title']     = "红包被偷";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['url']       = 'xmmz://p.lrlz.com/main/index?index=2';
        $push_param['extra']['image']     = $to_info->avatar();

        QueueClient::push('upushSendMsg',$push_param);
    }

    public static function fly_bonus(member_info $from_info,member_info $to_info,$amount)
    {
        $name = $from_info->nickname();
        $text = "{$name}的{$amount}元的红包,在向您飞来~.";

        $push_param['alias'] = $to_info->member_id();
        $push_param['title'] = "摇红包";
        $push_param['text']  = $text;

        $push_param['extra']['go_type'] = 'bonus';
        $push_param['extra']['title']     = "摇红包";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['url']     = 'xmmz://p.lrlz.com/main/index?index=2';
        $push_param['extra']['image']     = $from_info->avatar();

        QueueClient::push('upushSendMsg',$push_param);
    }

    public static function order_refund_bonus($member_id,$amount)
    {
        $minfo = new member_info($member_id);
        $text = "退款通知:金额{$amount}元红包已退还到您的账户.";

        $push_param['alias'] = $member_id;
        $push_param['title'] = "退款";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']   = 'bonus';
        $push_param['extra']['title']     = "退款";
        $push_param['extra']['text']      = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['url']      = 'xmmz://p.lrlz.com/main/index?index=2';
        $push_param['extra']['image']     = $minfo->avatar();

        QueueClient::push('upushSendMsg',$push_param);
    }

    public static function send_bonus($member_id,$to_ids)
    {
        $sender = new member_info($member_id);
        $name = $sender->nickname();
        foreach ($to_ids as $member_id)
        {
            $push_param = [];
            $text = "新的红包:您的好友{$name}给您发了一个红包，请查收.";

            $push_param['alias'] = $member_id;
            $push_param['title'] = "新到红包";
            $push_param['text']  = $text;

            $push_param['extra']['go_type']   = 'bonus';
            $push_param['extra']['title']     = "新到红包";
            $push_param['extra']['text']      = $text;
            $push_param['extra']['show_type'] = 'pop';
            $push_param['extra']['url']       = 'xmmz://p.lrlz.com/main/index?index=2';
            $push_param['extra']['image']     = $sender->avatar();

            QueueClient::push('upushSendMsg',$push_param);
        }
    }
    public static function bonus_refund($member_id,$amount)
    {
        $sender = new member_info($member_id);
        $text = "红包退还通知:您发送的红包已超过24小时,退还未被领取的金额{$amount}元，您可以重新发送并通知小伙伴及时领取.";

        $push_param['alias'] = $member_id;
        $push_param['title'] = "过期未领红包退还";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']   = 'bonus';
        $push_param['extra']['title']     = "过期未领红包退还";
        $push_param['extra']['text']      = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['url']      = 'xmmz://p.lrlz.com/main/index?index=2';
        $push_param['extra']['image']     = $sender->avatar();

        QueueClient::push('upushSendMsg',$push_param);
    }

    public static function invite_bonus($member_id,$money)
    {
        $minfo = new member_info($member_id);
        $text = "好东西就要与好盆友一起分享，感谢您的热情推荐，特奖励您{$money}元的友情红包，请查收~.";

        $push_param['alias'] = $member_id;
        $push_param['title'] = "邀请奖励";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']   = 'bonus';
        $push_param['extra']['title']    = "邀请奖励";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['url']      = 'xmmz://p.lrlz.com/main/index?index=2';
        $push_param['extra']['image']    = $minfo->avatar();

        QueueClient::push('upushSendMsg',$push_param);
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public static function register_bonus($user, $money,$type_sn,$fQueue=false)
    {
        $text = "您获得{$money}元的新人首单红包，请查收~";

        $push_param['alias'] = $user;
        $push_param['title'] = "收到新人首单红包";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']   = 'bonus';
        $push_param['extra']['title']    = "收到新人首单红包";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['url']      = schema_helper::bonus_detail($type_sn);
        $push_param['extra']['image']    = self::admin_avatar();

        self::push($user,$push_param,Sms::tpl_reg_user_bonus,['amount' => $money],$fQueue);
    }

    public static function money_rate_desc($money,$rate)
    {
        $discount = 100 - $rate;
        if($discount == 0) {
            $desc = "全抵";
        } else {
            $tmp = $discount / 10;
            $desc = "{$tmp}折";
        }
        $amount = intval($money * 100 + 0.5) / 100;
        return "{$amount}元{$desc}";
    }

    private static function push($alias, $push_param, $sms_type='',$sms_param=[], $fQueue=false)
    {
        $alias_info = new member_info($alias);
        $mobile = $alias_info->mobile();
        $client_type = $alias_info->client_type();

        if($fQueue)
        {
            if($client_type > 0) {
                QueueClient::push('upushSendMsg',$push_param);
            }
            else
            {
                if(!empty($sms_type) && $alias_info->can_sms()) {
                    $sms_param['mobile'] = $mobile;
                    $sms_param['type'] = $sms_type;
                    QueueClient::push('sendOperSMS',$s普shms_param);
                }
                else {
                    QueueClient::push('upushSendMsg',$push_param);
                }
            }
        }
        else
        {
            if($client_type > 0) {
                $push = new push_sender();
                $status = $push->send($push_param,$client_type);
            }
            else
            {
                if(!empty($sms_type) && $alias_info->can_sms()) {
                    $sms = new Sms();
                    $status = $sms->send_oper($mobile,$sms_type,$sms_param);
                }
                else {
                    $push = new push_sender();
                    $status = $push->send($push_param,$client_type);
                }
            }
        }
    }

    private static function inviter_text(member_info $invitee, $level, $money, $rate)
    {
        $nickname = $invitee->nickname();
        $text = self::money_rate_desc($money, $rate);
        return "{$nickname} 成为您的{$level}度粉丝,您获得{$text}红包奖励.";
    }

    public static function inviter_bonus($inviter, $user, $level, $money, $rate, $type_sn,$fQueue=false)
    {
        $user_info = new member_info($user);
        $text = self::inviter_text($user_info,$level,$money,$rate);

        $push_param['alias'] = $inviter;
        $push_param['title'] = "收到邀请奖励红包";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']  = 'bonus';
        $push_param['extra']['title']    = "收到邀请奖励红包";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type']= 'pop';

        $push_param['extra']['url']      = schema_helper::bonus_detail($type_sn);
        $push_param['extra']['image']    = $user_info->avatar();

        self::push($inviter,$push_param,Sms::tpl_reg_inviter,['user_name' => $user_info->nickname(),'level' => $level,'amount' => $money],$fQueue);
    }

    private static function invitee_text(member_info $inviter, member_info $user, $level, $money, $rate)
    {
        $desc = self::money_rate_desc($money, $rate);
        $text = "{$user->nickname()}成为{$inviter->nickname()}的{$level}度粉丝,您获得{$desc}红包奖励.";
        return $text;
    }

    public static function invitee_bonus($inviter, $invitee,member_info $user,$level, $money, $rate, $type_sn,$fQueue=false)
    {
        $inviter_info = new member_info($inviter);

        $text = self::invitee_text($inviter_info,$user,$level,$money,$rate);

        $push_param['alias'] = $invitee;
        $push_param['title'] = "收到雨露均沾红包";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']  = 'bonus';
        $push_param['extra']['title']    = "收到雨露均沾红包";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type']= 'pop';

        $push_param['extra']['url']      = schema_helper::bonus_detail($type_sn);
        $push_param['extra']['image']    = $inviter_info->avatar();

        self::push($invitee,$push_param,Sms::tpl_reg_invitee,['user_name' => $user->nickname(),'inviter_name' => $inviter_info->nickname(),'level' => $level,'amount' => $money],$fQueue);
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    private static function buygoods_inviter_text(member_info $user, $level, $goods_name)
    {
        $text = "您的{$level}度粉丝 {$user->nickname()},刚刚购买了《{$goods_name}》.";
        return $text;
    }
    public static function inviter_order_paied($inviter, $user, $level, $goods_info,$fQueue=false)
    {
        $user_info = new member_info($user);
        $text = self::buygoods_inviter_text($user_info,$level,$goods_info['goods_name']);

        $push_param['alias'] = $inviter;
        $push_param['title'] = "粉丝正在买";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']  = 'bonus';
        $push_param['extra']['title']    = "粉丝正在买";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type']= 'pop';

        $push_param['extra']['url']      = schema_helper::goods($goods_info['goods_id']);
        $push_param['extra']['image']    = $goods_info['goods_image'];
        QueueClient::push('upushSendMsg',$push_param);
        //self::push($inviter,$push_param);
    }

    private static function buygoods_invitee_text(member_info $user, $goods_name)
    {
        $text = "您的好友 {$user->nickname()},刚刚购买了《{$goods_name}》.";
        return $text;
    }

    public static function invitee_order_paied($invitee, $user, $goods_info)
    {
        $user_info = new member_info($user);
        $text = self::buygoods_invitee_text($user_info,$goods_info['goods_name']);

        $push_param['alias'] = $invitee;
        $push_param['title'] = "好友正在买";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']  = 'bonus';
        $push_param['extra']['title']    = "好友正在买";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type']= 'pop';

        $push_param['extra']['url']      = schema_helper::goods($goods_info['goods_id']);
        $push_param['extra']['image']    = $goods_info['goods_image'];

        QueueClient::push('upushSendMsg',$push_param);
    }

    public static function user_order_paied($user, $paysn)
    {
        $text = "请留意发货短信，确认收货后会有红包奖励～";

        $push_param['alias'] = $user;
        $push_param['title'] = "支付成功";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']   = '';
        $push_param['extra']['title']     = "支付成功";
        $push_param['extra']['text']      = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['url']       = schema_helper::order_info($paysn);
        $push_param['extra']['image']     = self::admin_avatar();

        QueueClient::push('upushSendMsg',$push_param);
        //self::push($user,$push_param);
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public static function user_order_complete_fixed($user, $money, $rate, $type_sn)
    {
        $desc = self::money_rate_desc($money,$rate);
        $text = "您的宝贝已被安全签收，小熊猫送您{$desc}红包，请查收~";

        $push_param['alias'] = $user;
        $push_param['title'] = "收货红包";
        $push_param['text']  = $text;
        $push_param['img']   = self::admin_avatar();

        $push_param['extra']['go_type']  = 'bonus';
        $push_param['extra']['title']    = "收货红包";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type']= 'pop';
        $push_param['extra']['url']      = schema_helper::bonus_detail($type_sn);
        $push_param['extra']['image']    = self::admin_avatar();
        QueueClient::push('upushSendMsg',$push_param);
        //self::push($user,$push_param);
    }

    public static function user_order_complete_random($user,$num,$type_sn)
    {
        $text = "您的宝贝已被安全签收，小熊猫送您{$num}个可分享红包，分享给小伙伴吧~";

        $push_param['alias'] = $user;
        $push_param['title'] = "收货可分享红包";
        $push_param['text']  = $text;
        $push_param['img']   = self::admin_avatar();

        $push_param['extra']['go_type']  = 'bonus';
        $push_param['extra']['title']    = "收货可分享红包";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type']= 'pop';
        $push_param['extra']['url']      = schema_helper::bonus_detail($type_sn);
        $push_param['extra']['image']    = self::admin_avatar();

        QueueClient::push('upushSendMsg',$push_param);
        //self::push($user,$push_param);
    }

    private static function inviter_order_complete_text(member_info $invitee, $level, $money, $rate)
    {
        $nickname = $invitee->nickname();
        $text = self::money_rate_desc($money, $rate);
        return "您的{$level}度粉丝 {$nickname} 下单成功,您获得{$text}红包奖励.";
    }

    public static function inviter_order_complete_bonus($inviter, $user, $level, $money, $rate, $type_sn,$fQueue=false)
    {
        $user_info = new member_info($user);
        $text = self::inviter_order_complete_text($user_info,$level,$money,$rate);

        $push_param['alias'] = $inviter;
        $push_param['title'] = "收到粉丝下单红包";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']  = 'bonus';
        $push_param['extra']['title']    = "收到粉丝下单红包";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type']= 'pop';

        $push_param['extra']['url']      = schema_helper::bonus_detail($type_sn);
        $push_param['extra']['image']    = $user_info->avatar();

        self::push($inviter,$push_param,Sms::tpl_order_complete_inviter,['level' => $level,'name' => $user_info->nickname(),'amount' => $money],$fQueue);
    }

    private static function invitee_order_complete_text(member_info $user, $money, $rate)
    {
        $nickname = $user->nickname();
        $text = self::money_rate_desc($money, $rate);
        return "好友{$nickname}下单成功,您获得{$text}红包奖励.";
    }
    public static function invitee_order_complete_bonus($invitee,member_info $user, $money, $rate, $type_sn,$fQueue=false)
    {
        $text = self::invitee_order_complete_text($user,$money,$rate);

        $push_param['alias'] = $invitee;
        $push_param['title'] = "收到好友下单红包";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']  = 'bonus';
        $push_param['extra']['title']    = "收到好友下单红包";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type']= 'pop';

        $push_param['extra']['url']      = schema_helper::bonus_detail($type_sn);
        $push_param['extra']['image']    = $user->avatar();

        self::push($invitee,$push_param,Sms::tpl_order_complete_invitee,['name' => $user->nickname(),'amount' => $money],$fQueue);
    }

    private static function all_order_complete_text(member_info $user, $money, $rate)
    {
        $nickname = $user->nickname();
        $text = self::money_rate_desc($money, $rate);
        return "{$nickname}下单成功,引发红包风暴,您获得{$text}红包奖励.";
    }
    public static function all_order_complete_bonus($user, member_info $buyer, $money, $rate, $type_sn, $fQueue=false)
    {
        $text = self::all_order_complete_text($buyer,$money,$rate);

        $push_param['alias'] = $user;
        $push_param['title'] = "收到下单红包雨";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']  = 'bonus';
        $push_param['extra']['title']    = "收到下单红包雨";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type']= 'pop';

        $push_param['extra']['url']      = schema_helper::bonus_detail($type_sn);
        $push_param['extra']['image']    = self::admin_avatar();

        self::push($user,$push_param,Sms::tpl_order_complete_all,['name' => $buyer->nickname(),'amount' => $money],$fQueue);
    }

    public static function order_cancel_bonus($member_id,$amount,$rate,$order_sn,$type_sn)
    {
        $desc = self::money_rate_desc($amount,$rate);
        $text = "订单{$order_sn}取消成功，退还{$desc}红包.";

        $push_param['alias'] = $member_id;
        $push_param['title'] = "收到取消订单红包";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']   = 'bonus';
        $push_param['extra']['title']     = "收到取消订单红包";
        $push_param['extra']['text']      = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['url']       = schema_helper::bonus_detail($type_sn);
        $push_param['extra']['image']     = self::admin_avatar();

        QueueClient::push('upushSendMsg',$push_param);
    }

    public static function order_evaluate_bonus($user, $money,$rate,$type_sn)
    {
        $desc = self::money_rate_desc($money, $rate);
        $text = "感谢您的每一个评价，小熊猫送您{$desc}红包，请查收~.";

        $push_param['alias'] = $user;
        $push_param['title'] = "收到评价红包";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']   = 'bonus';
        $push_param['extra']['title']     = "收到评价红包";
        $push_param['extra']['text']      = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['url']       = schema_helper::bonus_detail($type_sn);
        $push_param['extra']['image']     = self::admin_avatar();

        QueueClient::push('upushSendMsg',$push_param);
    }

    private static function inviter_evaluated_text(member_info $user, $level, $goods_name)
    {
        $text = "您的{$level}度粉丝 {$user->nickname()},刚刚评论了《{$goods_name}》.";
        return $text;
    }
    public static function inviter_order_evaluated($inviter, $user, $level, $goods_info)
    {
        $user_info = new member_info($user);
        $text = self::inviter_evaluated_text($user_info,$level,$goods_info['goods_name']);

        $push_param['alias'] = $inviter;
        $push_param['title'] = "粉丝正在评论";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']  = 'bonus';
        $push_param['extra']['title']    = "粉丝正在评论";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type']= 'pop';

        $push_param['extra']['url']      = schema_helper::goods($goods_info['goods_id']);
        $push_param['extra']['image']    = $goods_info['goods_image'];

        QueueClient::push('upushSendMsg',$push_param);
    }

    private static function invitee_evaluated_text(member_info $user, $goods_name)
    {
        $text = "您的好友 {$user->nickname()},刚刚评论了《{$goods_name}》.";
        return $text;
    }
    public static function invitee_order_evaluated($invitee, $user, $goods_info)
    {
        $user_info = new member_info($user);
        $text = self::invitee_evaluated_text($user_info,$goods_info['goods_name']);

        $push_param['alias'] = $invitee;
        $push_param['title'] = "好友正在评论";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']  = 'bonus';
        $push_param['extra']['title']    = "好友正在评论";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type']= 'pop';

        $push_param['extra']['url']      = schema_helper::goods($goods_info['goods_id']);
        $push_param['extra']['image']    = $goods_info['goods_image'];

        QueueClient::push('upushSendMsg',$push_param);
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public static function nofity_ugc_pub($follow,$author_id,$special_id,$title)
    {
        $author = new member_info($author_id);
        $text = "好友{$author->nickname()} 发表文章《{$title}》";

        $push_param['alias'] = $follow;
        $push_param['title'] = "好友发表文章";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']  = 'bonus';
        $push_param['extra']['title']    = "好友发表文章";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type']= 'pop';

        $push_param['extra']['url']      = schema_helper::ugc($title,$special_id);
        $push_param['extra']['image']    = $author->avatar();

        QueueClient::push('upushSendMsg',$push_param);
    }

    public static function nofity_ugc_submit($author,$reader,$special_id,$title)
    {
        $user = new member_info($reader);
        $text = "好友{$user->nickname()} 阅读了您的文章《{$title}》";

        $push_param['alias'] = $author;
        $push_param['title'] = "好友阅读文章";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']  = 'bonus';
        $push_param['extra']['title']    = "好友阅读文章";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type']= 'pop';

        $push_param['extra']['url']      = schema_helper::ugc($title,$special_id);
        $push_param['extra']['image']    = $user->avatar();

        QueueClient::push('upushSendMsg',$push_param);
    }

    public static function nofity_ugc_comment($author,$commender,$fcomment,$special_id,$content,$article_title)
    {
        $commender = new member_info($commender);
        if($fcomment) {
            $title = '收到留言回复';
            $text = "好友{$commender->nickname()} 回复您的评论:{$content}";
        } else {
            $title = '收到文章评论';
            $text = "文章《{$article_title}》收到一个新评论";
        }

        $push_param['alias'] = $author;
        $push_param['title'] = $title;
        $push_param['text']  = $text;

        $push_param['extra']['go_type'] = '';
        $push_param['extra']['title']= $title;
        $push_param['extra']['text'] = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['url']      = schema_helper::ugc($article_title,$special_id);
        $push_param['extra']['image'] = $commender->avatar();

        QueueClient::push('upushSendMsg',$push_param);
    }

    public static function nofity_ugc_support($author,$commender,$fcomment,$special_id,$content,$article_title)
    {
        if($commender > 0)
        {
            $commender = new member_info($commender);

            if($fcomment) {
                $text = "{$commender->nickname()} 点赞您的评论:{$content}";
            } else {
                $text = "{$commender->nickname()} 点赞您的文章《{$article_title}》";
            }
            $push_param['extra']['image'] = $commender->avatar();
        }
        else
        {
            if($fcomment) {
                $text = "刚刚有人点赞您的评论:{$content}";
            } else {
                $text = "刚刚有人点赞您的文章《{$article_title}》";
            }
            $push_param['extra']['image'] = "";
        }

        $push_param['alias'] = $author;
        $push_param['title'] = '收到点赞';
        $push_param['text']  = $text;

        $push_param['extra']['go_type'] = '';
        $push_param['extra']['title']= '收到点赞';
        $push_param['extra']['text'] = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['url']      = schema_helper::ugc($article_title,$special_id);

        QueueClient::push('upushSendMsg',$push_param);
    }

    public static function nofity_ugc_appreciate($author,$user,$special_id,$article,$rate,$amount)
    {
        $user_info = new member_info($user);

        $name = $user_info->nickname();
        $desc = self::money_rate_desc($amount,$rate);
        $text = "{$name}打赏您的文章《{$article}》{$desc}红包，快去查看吧.";

        $push_param['alias'] = $author;
        $push_param['title'] = "文章打赏";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']   = 'bonus';
        $push_param['extra']['title']     = "文章打赏";
        $push_param['extra']['text']      = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['url']       = schema_helper::ugc($article,$special_id);
        $push_param['extra']['image']     = $user_info->avatar();

        QueueClient::push('upushSendMsg',$push_param);
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public static function fcode_unlock($member_id,$num)
    {
        $text = "F码解锁通知:您有{$num}个F码已成功解锁，请注意过期时间～.";

        $push_param['alias'] = $member_id;
        $push_param['title'] = "F码";
        $push_param['text']  = $text;

        $push_param['extra']['go_type'] = 'fcode';
        $push_param['extra']['title']    = "F码";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['url']      =  schema_helper::mine_fcode();
        $push_param['extra']['image']    = self::admin_avatar();

        QueueClient::push('upushSendMsg', $push_param);
    }

    public static function notice_expring($member_id,$amount,$remain_days)
    {
        $minfo = new member_info($member_id);
        $text = "红包过期提醒:您价值{$amount}元的红包即将在{$remain_days}天内过期,尽快使用或者慷慨地分享给好友吧~";

        $push_param['alias'] = $member_id;
        $push_param['title'] = "红包过期提醒";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']   = 'fcode';
        $push_param['extra']['title']= "红包过期提醒";
        $push_param['extra']['text'] = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['url']       = 'xmmz://p.lrlz.com/mine/fcode';
        $push_param['extra']['image']    = $minfo->avatar();

        QueueClient::push('upushSendMsg', $push_param);
    }

    public static function notice_expired($member_id,$amount)
    {
        $minfo = new member_info($member_id);
        $text = "红包过期通知:您价值{$amount}元的红包已过期,别伤心，每天十点试试手气，可以继续赚红包哦~";

        $push_param['alias'] = $member_id;
        $push_param['title'] = "红包过期通知";
        $push_param['text'] = $text;

        $push_param['extra']['go_type'] = 'bonus';
        $push_param['extra']['title']= "红包过期提醒";
        $push_param['extra']['text'] = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['url']       = 'xmmz://p.lrlz.com/mine/fcode';
        $push_param['extra']['image']    = $minfo->avatar();

        QueueClient::push('upushSendMsg', $push_param);
    }

    public static function notice_subscribe($member_id,member_info $user)
    {
        $name = $user->nickname();
        $text = "手机{$name}用户,关注了你~";

        $push_param['alias'] = $member_id;
        $push_param['title'] = "好友关系";
        $push_param['text'] = $text;

        $push_param['extra']['go_type']   = 'bonus';
        $push_param['extra']['title']= "好友关系";
        $push_param['extra']['text'] = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['image'] = $user->avatar();

        QueueClient::push('upushSendMsg',$push_param);
    }

    public static function oper_push($member_id,$content)
    {
        $minfo = new member_info($member_id);

        $push_param['alias'] = $member_id;
        $push_param['title'] = "日常活动";
        $push_param['text']  = $content;

        $push_param['extra']['go_type']   = '';
        $push_param['extra']['title']= "日常活动";
        $push_param['extra']['text'] = $content;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['image'] = $minfo->avatar();

        QueueClient::push('upushSendMsg',$push_param);
    }
    public static function format_msg($member_id,$content)
    {
        $param['alias'] = $member_id;
        $param['text']  = $content;

        $param['extra']['go_type']   = '';
        $param['extra']['show_type'] = 'pop';

        return $param;
    }

    public static function fcode_warning($cid,$member_id,$usable_time)
    {
        $minfo = new member_info($member_id);

        $goods_name = self::goods_name($cid);
        $remain_days = intval((time() - $usable_time) / 86400);
        if(!empty($goods_name))
        {
            $param = [];
            $param['alias'] = $member_id;
            $param['title'] = "F码过期提醒";
            if($remain_days > 0) {
                $text = "F码过期提醒:您《{$goods_name}》的F码即将在{$remain_days}天内过期,请尽快使用";
            } else {
                $text = "F码过期提醒:您《{$goods_name}》的F码即将在今天过期,请尽快使用";
            }
            $param['text'] = $text;

            $param['extra']['go_type']   = 'fcode';
            $param['extra']['title']= "用户评价";
            $param['extra']['text'] = $text;
            $param['extra']['show_type'] = 'pop';
            $param['extra']['url']       = 'xmmz://p.lrlz.com/mine/fcode';
            $param['extra']['image'] = $minfo->avatar();

            QueueClient::push('upushSendMsg', $param);
        }
    }
    private static function goods_name($cid)
    {
        $items = Model()->table('goods_common')->field('goods_name')->where(['goods_commonid' => $cid])->select();
        if(empty($items)) {
            return false;
        }
        else {
            return $items[0]['goods_name'];
        }
    }
    private static function pushurl()
    {
        $url = BASE_SITE_URL . "/mobile/index.php?act=webpush";
        return $url;
    }

    //DialogMessage

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public static function poor_user_bonus($user, $money, $rate, $type_sn, $fQueue=false)
    {
//        $url = self::pushurl() . "&op=bonus&type_sn={$type_sn}";
        $desc = self::money_rate_desc($money,$rate);
        $text = "您的红包余额不足，好心人紧急为您充值{$desc}红包～";

        $push_param['alias'] = $user;
        $push_param['title'] = "收到津贴红包";
        $push_param['text']  = $text;

        $push_param['extra']['go_type']  = 'bonus';
        $push_param['extra']['title']    = "收到津贴红包";
        $push_param['extra']['text']     = $text;
        $push_param['extra']['show_type']= 'pop';

        $push_param['extra']['url']      = url_helper::bonus_open_url($type_sn);
        $push_param['extra']['image']    = self::admin_avatar();

        self::push($user,$push_param);
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public static function first_present($member_id,$fcode)
    {
        $fc_id = intval($fcode['fc_id']);
        $url = self::pushurl() . "&op=fcode&fc_id={$fc_id}";
        $minfo = new member_info($member_id);

        $push_param['alias'] = $member_id;
        $push_param['title'] = "收到下单首单礼";
        $text = "恭喜您获得首单礼，现在就去下单";
        $push_param['text']      = $text;

        $push_param['extra']['go_type'] = '';
        $push_param['extra']['title']= "下单首单礼";
        $push_param['extra']['text'] = $text;
        $push_param['extra']['show_type'] = 'dialog';
        $push_param['extra']['image'] = $minfo->avatar();
        $push_param['extra']['url'] = $url;

        QueueClient::push('upushSendMsg',$push_param);
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public static function call_friends($caller,$callee)
    {
        $minfo = new member_info($caller);

        $push_param['alias'] = $callee;
        $push_param['title'] = "{$minfo->nickname()} 的召唤";
        $text = "我正在赚红包，你也有得赚，赶快登陆App查看你的红包余额，赢免费大牌美妆~";
        $push_param['text']      = $text;

        $push_param['extra']['go_type'] = '';
        $push_param['extra']['title']= "{$minfo->nickname()} 的召唤";
        $push_param['extra']['text'] = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['image'] = $minfo->avatar();
        $push_param['extra']['url'] = schema_helper::invite_page();
        self::push($callee,$push_param,Sms::tpl_call_user_back,['name' => $minfo->nickname()],true);
    }
    public static function pop_message($user, $title, $text,$url)
    {
        $push_param['alias'] = $user;
        $push_param['title'] = $title;
        $push_param['text']      = $text;

        $push_param['extra']['go_type'] = '';
        $push_param['extra']['title']= $title;
        $push_param['extra']['text'] = $text;
        $push_param['extra']['show_type'] = 'pop';
        $push_param['extra']['image'] = self::admin_avatar();
        $push_param['extra']['url'] = $url;

        return $push_param;
    }
}

class push_event
{
    static public function publish_special($member_ids,$ispub,$count)
    {
        if($ispub) {
            $visible_type = 'pub_visible';
        } else {
            $visible_type = 'pri_visible';
        }
        foreach ($member_ids as $member_id)
        {
            $info['alias'] = $member_id;
            $info['custom'] = ['type' => 'add_special','visible_type' => $visible_type,'count' => $count];

            QueueClient::push('sendPushMessage',$info);
        }
    }
}