stanley-king 8 سال پیش
والد
کامیت
2df4b8070c
2فایلهای تغییر یافته به همراه11 افزوده شده و 3 حذف شده
  1. 10 3
      helper/bonus_share.php
  2. 1 0
      test/account_helperTest.php

+ 10 - 3
helper/bonus_share.php

@@ -53,11 +53,18 @@ class bonus_share
     }
     public function get($share_id = 0)
     {
-        if($share_id == 0) {
+        $share_id = intval($share_id);
+        if($share_id <= 0) {
             $count = count($this->mShareIds);
-            $share_id = mt_rand(1,$count);
+            $pos = mt_rand(0,$count - 1);
+            $share_id = $this->mShareIds[$pos];
         }
 
-        return $this->mDatas[$share_id];
+        if(array_key_exists($share_id,$this->mDatas)) {
+            return $this->mDatas[$share_id];
+        }
+        else {
+            return $this->mDatas[self::default_id];
+        }
     }
 }

+ 1 - 0
test/account_helperTest.php

@@ -80,6 +80,7 @@ class account_helperTest extends PHPUnit_Framework_TestCase
 
     public function testBrands()
     {
+        $x = mt_rand(1,1);
         $brands = brand_helper::brandex();
     }