فهرست منبع

add fcode expire warnging

stanley-king 7 سال پیش
والد
کامیت
2d19589a08
4فایلهای تغییر یافته به همراه81 افزوده شده و 10 حذف شده
  1. 5 3
      crontab/control/date.php
  2. 40 1
      helper/notify_helper.php
  3. 33 0
      helper/push_helper.php
  4. 3 6
      test/TestFcode.php

+ 5 - 3
crontab/control/date.php

@@ -104,11 +104,13 @@ class dateControl extends BaseCronControl
         $this->bonus_expire_notify();
         //商品到货通知提醒
         $this->_arrival_notice();
+        //F码过期提醒
+        $this->fcode_expire_notify();
     }
 
     public function testOp()
     {
-        $this->_stat_daily();
+        $this->fcode_expire_notify();
     }
 
     public function omsidOp()
@@ -1072,9 +1074,9 @@ class dateControl extends BaseCronControl
     {
         notify_helper::onBonusExpire(10,5);
     }
-
-    private function send_reward()
+    private function fcode_expire_notify()
     {
+        notify_helper::onFcodeWarning();
 
     }
     public function update_voteOp()

+ 40 - 1
helper/notify_helper.php

@@ -125,8 +125,47 @@ class notify_helper
         }
     }
 
-    static public function onFcodeExpire()
+    static public function onFcodeWarning()
     {
+        $pre_secs = 86400 * 5;
 
+        $mod_member = Model('member');
+        $i = 0;
+        while (true)
+        {
+            $start = $i * 1000;
+            $items = Model()->table('goods_fcode')
+                            ->field('fc_id,mobile,goods_commonid,usable_time')
+                            ->where(array('usable_time&usable_time' => ['_multi'=>true,['gt',time() - $pre_secs],['lt',time()]],'fc_state' => 0,'warning_time' => 0))
+                            ->order('fc_id desc')
+//                            ->limit("{$start},1000")->select();
+                            ->limit("{$start},1")->select();
+            if(empty($items)) {
+                return;
+            }
+            $i++;
+            foreach ($items as $item)
+            {
+                $fc_id = $item['fc_id'];
+                $cid   = $item['goods_commonid'];
+                $usable_time = $item['usable_time'];
+                $mobile = $item['mobile'];
+                $mid   = self::member_id($mod_member,$mobile);
+
+                if($mid!= false && $mid > 0) {
+                    push_helper::fcode_warning($cid,$mid,$usable_time);
+                }
+                Model()->table('goods_fcode')->where(['fc_id' => $fc_id])->update(['warning_time' => time()]);
+            }
+            return;
+        }
+    }
+    static private function member_id($mod_member,$mobile)
+    {
+        $items = $mod_member->where(['member_mobile' => $mobile])->select();
+        if(!empty($items)) {
+            return intval($items[0]['member_id']);
+        }
+        return false;
     }
 }

+ 33 - 0
helper/push_helper.php

@@ -207,6 +207,39 @@ class push_helper
 
         return $param;
     }
+
+    public static function fcode_warning($cid,$member_id,$usable_time)
+    {
+        $goods_name = self::goods_name($cid);
+        $remain_days = intval((time() - $usable_time) / 86400);
+        if(empty($goods_name))
+        {
+            $param = [];
+            $param['member_id'] = $member_id;
+            if($remain_days > 0) {
+                $text = "F码过期通知:您《{$goods_name}》的F码即将在{$remain_days}天内过期,请尽快使用";
+            } else {
+                $text = "F码过期通知:您《{$goods_name}》的F码即将在今天过期,请尽快使用";
+            }
+
+            $param['text'] = $text;
+            $param['go_type'] = 'fcode';
+            $param['url']      = 'xmmz://p.lrlz.com/mine/fcode';
+            Log::record("mid = {$member_id} msg={$text}",Log::DEBUG);
+
+            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'];
+        }
+    }
 }
 
 class push_message

+ 3 - 6
test/TestFcode.php

@@ -14,6 +14,7 @@ require_once(BASE_ROOT_PATH . '/helper/fcode/operator.php');
 require_once(BASE_ROOT_PATH . '/helper/fcode/mfcode.php');
 require_once(BASE_ROOT_PATH . '/helper/fcode/present_manager.php');
 require_once(BASE_ROOT_PATH . '/helper/fcode/send_manager.php');
+require_once(BASE_ROOT_PATH . '/helper/notify_helper.php');
 
 
 class TestFcode extends PHPUnit_Framework_TestCase
@@ -55,12 +56,8 @@ class TestFcode extends PHPUnit_Framework_TestCase
         $code = sprintf("%06s",'DLHS');
     }
 
-    public function testString()
+    public function testWarning()
     {
-        $num = "30";
-        for($i = 0; $i < $num; ++$i) {
-            $data = $i;
-        }
+        notify_helper::onFcodeWarning();
     }
-
 }