stanley-king преди 8 години
родител
ревизия
aca6795eb3
променени са 6 файла, в които са добавени 90 реда и са изтрити 24 реда
  1. 20 10
      data/resource/mobile/bonus/js/tel.js
  2. 3 8
      helper/bonus/manager.php
  3. 1 1
      helper/bonus/shaker.php
  4. 7 3
      helper/bonus/user_bonus.php
  5. 51 0
      helper/bonus_helper.php
  6. 8 2
      mobile/control/bonusex.php

+ 20 - 10
data/resource/mobile/bonus/js/tel.js

@@ -314,6 +314,7 @@ $(function(){
         shake:function(){
             if (window.DeviceMotionEvent) {
                 window.addEventListener('devicemotion', deviceMotionHandler, false);
+                alert("shake");
             }
             else {
                 alert('您的设备不支持!');
@@ -329,6 +330,8 @@ $(function(){
              strong,
              mine_bonus_sn=$('#mine_bonus').val();
             function deviceMotionHandler(eventData) {
+
+                alert("shake event");
                 var acceleration = eventData.accelerationIncludingGravity;
                 var curTime = new Date().getTime();
                 var diffTime = curTime - last_update;
@@ -337,8 +340,12 @@ $(function(){
                     x = acceleration.x;
                     y = acceleration.y;
                     z = acceleration.z;
+                    alert("shake event x=" + x + " y=" + y);
                     var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;
 
+
+
+                    strong = 0;
                     if (speed>3000&&speed <= 4500) {
                         strong=1;
                     }
@@ -351,38 +358,41 @@ $(function(){
                     if(speed>7500&&speed <= 9000) {
                         strong=4;
                     }
-                    if(speed>9000&&speed <= 10500) {
+                    if(speed>9000) { //&&speed <= 10500
                         strong=5;
                     }
 
-                    last_x = x;
-                    last_y = y;
-                    last_z = z;
+                    if (strong == 0) return;
+
                     var speed_strongs={
                         strength:strong,
                         bonus_sn:mine_bonus_sn
                     };
                     $.ajax({
                         type:'get',
-                        url:"http://a.lrlz.com/mobile/index.php?op=shake&act=bonusex&client_type=ajax",
+                        url:"http://192.168.1.110/mobile/index.php?op=shake&act=bonusex&client_type=ajax",
                         data:speed_strongs,
                         dataType:"jsonp",
                         jsonp:'callback',
                         success:function(data){
                             if(data.code !=200) {
-                                    window.removeEventListener('devicemotion', deviceMotionHandler, false);
+                                    //window.removeEventListener('devicemotion', deviceMotionHandler, false);
                                     return;
                             }
                             else {
                                 var shake_New_price=data.datas.mine_bonus.bonus_value;
                                 $('.price span').text(shake_New_price);
-                                window.removeEventListener('devicemotion', deviceMotionHandler, false);
-                                setTimeout(function(){
-                                     window.addEventListener('devicemotion', deviceMotionHandler, false);
-                                },500)
+                                // window.removeEventListener('devicemotion', deviceMotionHandler, false);
+                                // setTimeout(function(){
+                                //      window.addEventListener('devicemotion', deviceMotionHandler, false);
+                                // },2000)
                             }
                         }
                     });
+
+                    last_x = x;
+                    last_y = y;
+                    last_z = z;
                 }
                 else {
                     return false;

+ 3 - 8
helper/bonus/manager.php

@@ -246,12 +246,7 @@ class manager
 
         return true;
     }
-
-    static private function can_shake($bonus_status)
-    {
-        return ($bonus_status == 1 || $bonus_status == 2);
-    }
-
+    
     public function shake($bonus_sn,$strength,$direction)
     {
         $bonus_info = self::read_session('',$bonus_sn);
@@ -272,12 +267,12 @@ class manager
             $bonus_status = $user_bonus->bonus_status();
         }
 
-        if(self::can_shake($bonus_status) == false) {
+        if($user_bonus->can_shake() == false) {
             return false;
         }
 
         $shaker = new \bonus\shaker();
-        $ret = $shaker->reassign($type_id,$bonus_id,$bonus_val,$bonus_status,$strength,$direction);
+        $ret = $shaker->reassign($type_id,$bonus_id,$bonus_status,$bonus_val,$strength,$direction);
         if($ret == true)
         {
             $bonus = $this->read_session('',$bonus_sn);

+ 1 - 1
helper/bonus/shaker.php

@@ -189,7 +189,7 @@ class shaker
             $total_tmp = $total_tmp - $delta;
         } else { //金额变小
             $delta = $this->delta_dec($bonus_val - self::min_amount, $strength);
-            $bonus_val -= $delta;
+            $bonus_val = $bonus_val - $delta + self::min_amount;
             $total_tmp = $total_tmp + $delta;
         }
         $total_amount = $total_tmp / 100;

+ 7 - 3
helper/bonus/user_bonus.php

@@ -55,16 +55,20 @@ class user_bonus
     }
     public function bonus_status()
     {
-        if(!isset($this->mParamer['bonus_value']) || empty($this->mParamer['bonus_value'])) {
+        if(!isset($this->mParamer['bonus_status']) || empty($this->mParamer['bonus_status'])) {
             return 0;
         } else {
-            return intval($this->mParamer['bonus_value']);
+            return intval($this->mParamer['bonus_status']);
         }
     }
     public function can_shake() {
-        $status = intval($this->mParamer['bonus_value']);
+        $status = intval($this->mParamer['bonus_status']);
         return ($status == self::GrabStatus || $status == self::BindStatus);
     }
+    public function remain_amount() {
+        $val = intval(floatval($this->mParamer['remain_amount']) * 100 + 0.5);
+        return floatval($val) / 100;
+    }
     public function type_sn() {
         return $this->mParamer['type_sn'];
     }

+ 51 - 0
helper/bonus_helper.php

@@ -26,6 +26,8 @@ class bonus_helper
     const def_bless = '恭喜发财大吉大利';
     const max_total_amount = 1000000;
     const max_total_num = 1000;
+    const shake_expire  = 10;
+    const shake_maxcount = 5;
 
     static public function filter_type($type_info) {
         $type = \bonus\type::crate_by_paramer($type_info);
@@ -260,4 +262,53 @@ class bonus_helper
     static public function direct_dec() {
         return \bonus\shaker::direct_dec;
     }
+
+    static public function get_direction($first)
+    {
+        if($first) {
+            return self::direct_asc();
+        }
+        else
+        {
+            $direct = mt_rand(1,100);
+
+            if($direct % 2 == 0) {
+                return self::direct_asc();
+            } else {
+                return self::direct_dec();
+            }
+        }
+    }
+
+    static public function check_shake($bonus_sn,&$first)
+    {
+        if(!isset($_SESSION['bonus_shake'])) {
+            $_SESSION['bonus_shake'] = array();
+        }
+
+        if(isset($_SESSION['bonus_shake'][$bonus_sn]))
+        {
+            $first = false;
+            $bonus_shake = &$_SESSION['bonus_shake'][$bonus_sn];
+
+            $tmout = time() - $bonus_shake['time'];
+            if($tmout <= self::shake_expire) {
+                return array('code' => errcode::ErrBonus, 'msg' => '请不要摇得太快~');
+            } elseif($bonus_shake['count'] > self::shake_maxcount) {
+                ++$bonus_shake['count'];
+                return array('code' => errcode::ErrBonus, 'msg' => '该红包只允许被摇' . self::shake_maxcount .'次~');
+            } else {
+                return true;
+            }
+        }
+        else {
+            $_SESSION['bonus_shake'][$bonus_sn] = array();
+            $bonus_shake = &$_SESSION['bonus_shake'][$bonus_sn];
+            $bonus_shake['count'] = 1;
+            $bonus_shake['time'] = time();
+            $first = true;
+
+            return true;
+        }
+    }
 }

+ 8 - 2
mobile/control/bonusex.php

@@ -303,9 +303,15 @@ class bonusexControl extends mobileControl
             }
             else
             {
-                $direction = bonus_helper::direct_dec();
+                $ret = bonus_helper::check_shake($bonus_sn,$first);
+                if($ret != true) {
+                    return self::outerr($ret['code'], $ret['msg']);
+                }
+
+                $direction = bonus_helper::get_direction($first);
                 $ret = bonus_helper::shake($bonus_obj->bonus_sn(),$strength,$direction);
-                if($ret == true) {
+                if($ret == true)
+                {
                     $bonus = bonus_helper::get_mine_by_bonussn($bonus_obj->bonus_sn());
                     $type_infos = bonus_helper::get_typeinfo($bonus_obj->type_sn());
                     $this->fileter_typeinfos($type_infos,$type_info,$binded_info);