瀏覽代碼

add poor user bonus

stanley-king 7 年之前
父節點
當前提交
d149806850

+ 1 - 1
core/framework/libraries/sms.php

@@ -23,7 +23,7 @@ class Sms
     const tpl_reg_user_bonus = '217654';        //亲爱的用户,您已获得{1}元新人首单红包,请登陆APP查收!退订回复N
     const tpl_reg_inviter = '217638';           //亲爱的会员,{1}成为您的{2}度粉丝,您获得{3}元全抵红包。退订回复N
     const tpl_reg_invitee = '217637';           //亲爱的会员,您的好友{1}成为{2}的{3}度粉丝,您获得{4}元雨露均沾红包。退订回复N
-    const tpl_order_complete_all = '217634';    //亲爱的会员,您的好友{1}下单成功,您获得{2}元全抵红包。登陆APP可查看红包余额!退订回复N
+    const tpl_order_complete_all = '218125';    //亲爱的会员,{1}下单成功,引发红包风暴,{2}元全抵红包砸中了你。快去查看红包余额!退订回复N
     const tpl_order_complete_inviter = '217647';//亲爱的会员,您的{1}度粉丝{2}下单成功,您获得{3}元全抵红包。登陆APP可查看红包余额!退订回复N
     const tpl_order_complete_invitee = '217630';//亲爱的会员,您的好友{1}成为{2}的{3}度粉丝,您获得{4}元雨露均沾红包。退订回复N    
 

+ 8 - 1
data/logic/queue.logic.php

@@ -638,11 +638,18 @@ class queueLogic
 
     public function onAsyncStatus($param)
     {
-        Log::record('queue::onAsyncStatus',Log::DEBUG);
+        Log::record(__METHOD__,Log::DEBUG);
         account_helper::onAsyncStatus($param['member_id']);
         return callback(true);
     }
 
+    public function onAsyncTopup($param)
+    {
+        Log::record(__METHOD__,Log::DEBUG);
+        account_helper::onAsyncTopup($param['member_id']);
+        return callback(true);
+    }
+
     public function onPredeposit($param)
     {
         Log::record('queue::onPredeposit',Log::DEBUG);

+ 10 - 0
helper/account_helper.php

@@ -340,6 +340,16 @@ class account_helper
             Log::record($ex->getMessage(),Log::ERR);
         }
     }
+    public static function onAsyncTopup($member_id)
+    {
+        try
+        {
+            $iPusher = new async\status($member_id);
+            $iPusher->topup();
+        } catch (Exception $ex) {
+            Log::record($ex->getMessage(),Log::ERR);
+        }
+    }
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     public static function onRegister($member_id,$relay_id)
     {

+ 26 - 6
helper/async/status.php

@@ -13,6 +13,8 @@ namespace async;
 use member_info;
 use fcode;
 use push_helper;
+use bonus;
+use bonus_helper;
 
 class status extends IAsync
 {
@@ -31,10 +33,33 @@ class status extends IAsync
     public function run()
     {
         if($this->check_present()) return;
-        if($this->check_bonus())   return;
         if($this->check_fcode())   return;
     }
 
+    public function topup()
+    {
+        $mod_bonus = Model('user_bonus');
+        $total = $mod_bonus->getUsableSum($this->member_id);
+        if($total > 50) return;
+
+        $params = bonus\parameters::poor_user();
+        foreach ($params as $param)
+        {
+            $type = bonus_helper::create_type_input($param);
+            $money = $type->getTotal_amount();
+            $rate  = $type->bonus_rate();
+            $ret = bonus_helper::make_bonus($param,$param['rate_money']);
+
+            if($ret != false) {
+                $type_sn = $ret['type_sn'];
+                bonus_helper::send($type_sn,[$this->member_id]);
+                push_helper::poor_user_bonus($this->member_id,$money,$rate,$type_sn);
+            } else {
+                return false;
+            }
+        }
+    }
+
     private function check_present()
     {
         if($this->mem_info->order_num() > 0) {
@@ -53,11 +78,6 @@ class status extends IAsync
         return true;
     }
 
-    private function check_bonus()
-    {
-        return false;
-    }
-
     private function check_fcode()
     {
         return false;

+ 19 - 0
helper/bonus/parameters.php

@@ -290,6 +290,25 @@ class parameters
 
         return $param;
     }
+
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    public static function poor_user()
+    {
+        $params = [];
+
+        $param['make_type'] = type::MakeAllowanceType;
+        $param['type_name'] = "津贴红包";
+        $param['type_bless'] = "您的红包余额不足,好心人紧急为您充值~";
+        $param['send_type']  = type::SendType_Fixed;
+        $param['grab_type']  = type::GrabType_All;
+        $param['sender_id']   = self::admin_member_id;
+        $param['sender_name'] = self::admin_name;
+        $param['usable_days'] = self::usable_days;
+        $param['rate_money'][] = ['amount' => 50,   'num' => 1, 'rate' => 40];
+        $params[] = $param;
+
+        return $params;
+    }
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     public static function admin_fixed($rate,$amount,$num,$type_name)
     {

+ 1 - 0
helper/bonus/type.php

@@ -31,6 +31,7 @@ class type
     const MakeVoteType = 11;
     const MakePayRewardInviterType = 12;
     const MakePayRewardInviteeType = 13;
+    const MakeAllowanceType = 14;
 
     const create_type = 0;
     const load_type = 1;

+ 1 - 0
helper/model/member_info.php

@@ -149,6 +149,7 @@ class member_info
         $client_type = intval($this->member_info['client_type']);
         return $client_type;
     }
+
     public function inviter_id() {
         return intval($this->member_info['inviter_id']);
     }

+ 24 - 0
helper/push_helper.php

@@ -543,6 +543,7 @@ class push_helper
         QueueClient::push('upushSendMsg',$push_param);
     }
 
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     public static function nofity_ugc_pub($follow,$author_id,$special_id,$title)
     {
         $author = new member_info($author_id);
@@ -814,6 +815,29 @@ class push_helper
     }
 
     //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)
     {

+ 15 - 1
mobile/control/member_bonus.php

@@ -649,6 +649,7 @@ class member_bonusControl extends mbMemberControl
     public function topupOp()
     {
         $items = $this->mPred->topup_bonus($_SESSION['member_mobile']);
+        $this->async_topup();
         if($items === false) {
             return self::outsuccess(array("count" => 0,'total_amount' => 0.00));
         }
@@ -724,9 +725,20 @@ class member_bonusControl extends mbMemberControl
         }
     }
 
+    private function async_topup()
+    {
+        $last_topup = intval($_SESSION['last_topup_time']);
+        if(time() - $last_topup > 7 * 86400) {
+            QueueClient::push('onAsyncTopup',['member_id' => session_helper::memberid()]);
+            $_SESSION['last_topup_time'] = time();
+        }
+    }
+
     public function topupexOp()
     {
         $items = $this->mPred->topup_bonus($_SESSION['member_mobile']);
+        $this->async_topup();
+
         if($items === false) {
             return self::outsuccess(array("count" => 0,'total_amount' => 0.00));
         }
@@ -736,7 +748,8 @@ class member_bonusControl extends mbMemberControl
             $max_rate = 0;
             $avatar = RESOURCE_SITE_URL . '/mobile/defimg/female.png';
             $type_sn = '';
-            foreach ($items as $item) {
+            foreach ($items as $item)
+            {
                 $bonus = \bonus\user_bonus::create_by_param($item);
                 $rate = $bonus->bonus_rate();
                 if ($max_rate < $rate) {
@@ -749,6 +762,7 @@ class member_bonusControl extends mbMemberControl
                 }
                 $total_amount += doubleval($item['bonus_value']);
             }
+
             $count = count($items);
             $title = "您新领了{$count}个, 总额价值{$total_amount}元的红包.";
             $detail_url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=detail&client_type=wap&type_sn={$type_sn}";