瀏覽代碼

增加已领取红包过期逻辑

zhouzhijian 8 年之前
父節點
當前提交
0673103052
共有 5 個文件被更改,包括 50 次插入36 次删除
  1. 1 2
      crontab/control/date.php
  2. 3 8
      data/model/user_bonus.model.php
  3. 10 0
      helper/account_helper.php
  4. 36 2
      helper/notify_helper.php
  5. 0 24
      helper/user_helper.php

+ 1 - 2
crontab/control/date.php

@@ -935,7 +935,6 @@ class dateControl extends BaseCronControl {
 
     private function bonus_expired_notify()
     {
-        user_helper::notify_soon_expired_bonus(10,5);
-        user_helper::notify_already_expired_bonus();
+        
     }
 }

+ 3 - 8
data/model/user_bonus.model.php

@@ -238,16 +238,11 @@ class user_bonusModel extends Model
         }
     }
 
-    public function getexpired_bonus()
+    public function getExpired()
     {
-        $field = 'bonus_id,user_id,type_sn';
-        $condition = 'usable_time <= unix_timestamp(now())';
+        $field = 'bonus_id,user_id,type_sn,bonus_value';
+        $condition = 'expired=0 and usable_time <= unix_timestamp(now())';
         $ret = $this->field($field)->where($condition)->limit(false)->select();
         return $ret;
     }
-
-    public function expiredBonusRefund()
-    {
-
-    }
 }

+ 10 - 0
helper/account_helper.php

@@ -45,6 +45,11 @@ class account_helper
         {
             bonus_helper::send($ret['type_sn'],array($member_id));
             // todo 做push通知
+            $push_param = array();
+            $push_param['member_id'] = $member_id;
+            $push_param['text']      = "红包退款通知:金额{$amount}元.";
+            $push_param['go_type']   = 'bonus';
+            QueueClient::push('upushSendMsg',$push_param);
         } else {
             Log::record("给用户 {$member_id} 退款{$amount}失败.");
         }
@@ -62,6 +67,11 @@ class account_helper
         {
             bonus_helper::send($ret['type_sn'],array($member_id));
             // todo 做push通知
+            $push_param = array();
+            $push_param['member_id'] = $member_id;
+            $push_param['text']      = "红包退款通知:金额{$amount}元.";
+            $push_param['go_type']   = 'bonus';
+            QueueClient::push('upushSendMsg',$push_param);
         } else {
             Log::record("给用户 {$member_id} 退款{$amount}失败.");
         }

+ 36 - 2
helper/notify_helper.php

@@ -6,6 +6,8 @@
  * Date: 16/6/26
  * Time: 下午9:30
  */
+require_once (BASE_ROOT_PATH . '/helper/account_helper.php');
+
 class notify_helper
 {
     static public function bonus_expire($warn_remain_days, $warn_interval_days)
@@ -16,7 +18,7 @@ class notify_helper
         $bonus_ids = array();
         foreach ($expired_list as $key => $val) {
             $user_id = $val["user_id"];
-            $remain_days = intval($val["seconds"]) < 86400 ? 1 : (intval($val["seconds"]) / 86400) + 1;
+            $remain_days = intval($val["leftsecs"]) < 86400 ? 1 : (intval($val["leftsecs"]) / 86400) + 1;
 
             $param = array();
             $param['member_id'] = $user_id;
@@ -28,8 +30,40 @@ class notify_helper
 
         if (!empty($bonus_ids))
         {
-            $user_bonus_model->where(array('bonus_id' => array('in', $bonus_ids)))->update(array("notify_time" => 'unix_timestamp(now())'));
+            $mod_bonus->where(array('bonus_id' => array('in', $bonus_ids)))->update(array("notify_time" => 'unix_timestamp(now())'));
         }
     }
 
+    static public function bonus_expired()
+    {
+        $user_bonus_model = Model("user_bonus");
+        $expired_list = $user_bonus_model->getExpired();
+        $bonus_ids = array();
+        $user_infos = array();
+
+        foreach ($expired_list as $key => $val) {
+            $user_id = $val["user_id"];
+            $amount = $val["bonus_value"];
+
+            $param = array();
+            $param['member_id'] = $user_id;
+            $param['text'] = "红包过期通知:您领取的红包已经过期.";
+            $param['go_type'] = 'bonus';
+            QueueClient::push('upushSendMsg', $param);
+
+            $bonus_ids[] = $val["bonus_id"];
+            $user_infos[] = array("user_id"=>$user_id, "amount"=>$amount);
+        }
+
+        if (!empty($bonus_ids))
+        {
+            $user_bonus_model->where(array('bonus_id' => array('in', $bonus_ids)))->update(array("expired" => 1));
+            if ($user_bonus_model->affected_rows() > 0)
+            {
+                foreach($user_infos as $key => $val) {
+                    account_helper::onPredeposit('bonus_refund', $val["user_id"], $val["amount"]);
+                }
+            }
+        }
+    }
 }

+ 0 - 24
helper/user_helper.php

@@ -126,30 +126,6 @@ class user_helper
         return $member_info;
     }
 
-
-
-    static public function notify_already_expired_bonus()
-    {
-        $user_bonus_model = Model("user_bonus");
-        $expired_list = $user_bonus_model->getexpired_bonus();
-        $bonus_ids = array();
-
-        foreach ($expired_list as $key => $val) {
-            $user_id = $val["user_id"];
-            $param = array();
-            $param['member_id'] = $user_id;
-            $param['text'] = "红包过期通知:您领取的红包已经过期.";
-            $param['go_type'] = 'bonus';
-            QueueClient::push('upushSendMsg', $param);
-            $bonus_ids[] = $val["bonus_id"];
-        }
-
-        if (!empty($bonus_ids))
-        {
-            $user_bonus_model->where(array('bonus_id' => array('in', $bonus_ids)))->update(array("bonus_status" => 4));
-        }
-    }
-
     static public function filter_member_info($member_info,$openid)
     {
         field_helper::validate_null_string($member_info, 'member_mobile,member_wxopenid,member_name,' .