|
@@ -7,6 +7,7 @@
|
|
|
* Time: 上午11:33
|
|
|
*/
|
|
|
require_once (BASE_ROOT_PATH . '/helper/account_helper.php');
|
|
|
+require_once (BASE_ROOT_PATH . '/helper/predeposit_helper.php');
|
|
|
|
|
|
class friend
|
|
|
{
|
|
@@ -46,7 +47,7 @@ class gain_policy
|
|
|
$this->total_amount = $amount;
|
|
|
}
|
|
|
|
|
|
- public function gain()
|
|
|
+ public function calculate()
|
|
|
{
|
|
|
$cur_value = intval($this->total_amount) >= self::max_amount ? self::max_amount : $this->total_amount;
|
|
|
return $this->scale() * $cur_value;
|
|
@@ -88,8 +89,8 @@ class gain_policy
|
|
|
|
|
|
class shaker_helper
|
|
|
{
|
|
|
- const max_gain_period = 12 * 3600;
|
|
|
- const max_lost_period = 1800;
|
|
|
+ const max_gain_period = 300;//12 * 3600;
|
|
|
+ const max_lost_period = 60;//1800;
|
|
|
|
|
|
const shake_expire = 5;
|
|
|
const direct_gain = 0;
|
|
@@ -103,17 +104,20 @@ class shaker_helper
|
|
|
{
|
|
|
$friends = $this->gain_friends();
|
|
|
$usable_amount = 0.0;
|
|
|
- $user_id = $this->find_friend($friends, $usable_amount);
|
|
|
+ $user_id = $this->find_gain_friend($friends, $usable_amount);
|
|
|
if ($user_id != false)
|
|
|
{
|
|
|
$policy = new gain_policy($this->strength, $usable_amount);
|
|
|
- $value = $policy->gain();
|
|
|
- bonus_helper::withold($user_id, $value);
|
|
|
+ $value = $policy->calculate();
|
|
|
+
|
|
|
$bonus = account_helper::gain_bonus($user_id, $_SESSION['member_id'], $value);
|
|
|
if($bonus != false) {
|
|
|
- $this->add_gained_friend(array($user_id));
|
|
|
-
|
|
|
$name = user_helper::nickname();
|
|
|
+
|
|
|
+ $predo = new predeposit_helper($_SESSION['member_id']);
|
|
|
+ $predo->hand_out_bonus($value,$bonus[0]['type_sn'],user_helper::nickname(),"被{$name}要走了{$value}元的红包.");
|
|
|
+
|
|
|
+ $this->add_gained_friend(array($user_id));
|
|
|
$push_param = array();
|
|
|
$push_param['member_id'] = $user_id;
|
|
|
$push_param['text'] = "您的好友{$name} 在熊猫美妆中偷走你{$value}元.";
|
|
@@ -127,14 +131,14 @@ class shaker_helper
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
-// if ($this->gained_system() == false) {
|
|
|
-// $result = array('code' => errcode::ErrShake, 'msg' => "系统红包一天只能抢一次~发红包邀请好友进来就可以抢他们的红包了.");
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-// else
|
|
|
+ if ($this->gained_system() == false) {
|
|
|
+ $result = array('code' => errcode::ErrShake, 'msg' => "系统红包一天只能抢一次~发红包邀请好友进来就可以抢他们的红包了.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
$policy = new gain_policy($this->strength, 50);
|
|
|
- $value = $policy->gain();
|
|
|
+ $value = $policy->calculate();
|
|
|
$bonus = account_helper::gain_sysBonus($_SESSION['member_id'], $value);
|
|
|
if($bonus != false) {
|
|
|
$this->save_gained_system();
|
|
@@ -146,43 +150,54 @@ class shaker_helper
|
|
|
|
|
|
private function lost(&$result)
|
|
|
{
|
|
|
+ $predo = new predeposit_helper($_SESSION['member_id']);
|
|
|
+ $total_amount = $predo->get_predeposit_total();
|
|
|
+
|
|
|
+ if(intval($total_amount * 100 + 0.5) <= 0) {
|
|
|
+ $result = array('code' => errcode::ErrShake,'msg' => '您余额不足~');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
$friends = $this->lost_friends();
|
|
|
- $mod_bonus = Model('user_bonus');
|
|
|
- $usable_amount = $mod_bonus->getUsableSum($_SESSION['member_id']);
|
|
|
- if(intval($usable_amount * 100 + 0.5) <= 0) {
|
|
|
- $result = array('code' => errcode::ErrShake,'msg' => '');
|
|
|
+ $user_id = $this->find_lost_friend($friends);
|
|
|
|
|
|
+ if($user_id == false) {
|
|
|
+ $result = array('code' => errcode::ErrShake, 'msg' => "么有摇到红包~");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- $friends = $this->gain_friends();
|
|
|
- $usable_amount = 0.0;
|
|
|
- $user_id = $this->find_friend($friends, $usable_amount);
|
|
|
- if ($user_id != false)
|
|
|
- {
|
|
|
- $policy = new gain_policy($this->strength, $usable_amount);
|
|
|
- $value = $policy->gain();
|
|
|
- $bonus = account_helper::gain_bonus($user_id, $_SESSION['member_id'], $value);
|
|
|
- if($bonus != false) {
|
|
|
- bonus_helper::withold($user_id, $value);
|
|
|
+ $policy = new gain_policy($this->strength, $total_amount);
|
|
|
+ $value = $policy->calculate();
|
|
|
+ $bonus = account_helper::lost_bonus($_SESSION['member_id'],$user_id, $value);
|
|
|
+ if($bonus != false) {
|
|
|
+ $predo->hand_out_bonus($value,$bonus[0]['type_sn'],user_helper::nickname(),"您摇丢了{$value}的红包.");
|
|
|
+ $this->add_lost_friend(array($user_id));
|
|
|
+ $name = user_helper::nickname();
|
|
|
+ $push_param = array();
|
|
|
+ $push_param['member_id'] = $user_id;
|
|
|
+ $push_param['text'] = "您的好友{$name}把{$value}元的红包,摇到你的账户.";
|
|
|
+ $push_param['go_type'] = 'bonus';
|
|
|
+ QueueClient::push('upushSendMsg', $push_param);
|
|
|
+ } else {
|
|
|
+ $result = array('code' => errcode::ErrShake, 'msg' => "没摇到任何红包~");
|
|
|
+ }
|
|
|
|
|
|
- $this->add_gained_friend(array($user_id));
|
|
|
+ return $bonus;
|
|
|
+ }
|
|
|
|
|
|
- $name = user_helper::nickname();
|
|
|
- $push_param = array();
|
|
|
- $push_param['member_id'] = $user_id;
|
|
|
- $push_param['text'] = "您的好友{$name} 在熊猫美妆中偷走你{$value}元.";
|
|
|
- $push_param['go_type'] = 'bonus';
|
|
|
- QueueClient::push('upushSendMsg', $push_param);
|
|
|
- } else {
|
|
|
- $result = array('code' => errcode::ErrShake, 'msg' => "么有抢到好友红包~");
|
|
|
- }
|
|
|
+ private function find_lost_friend($friends)
|
|
|
+ {
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ $count = count($friends);
|
|
|
+ if($count == 0) return false;
|
|
|
|
|
|
- return $bonus;
|
|
|
+ $pos = mt_rand(0,$count -1);
|
|
|
+ return $friends[$pos];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private function find_friend($friends,&$usable_amount)
|
|
|
+ private function find_gain_friend($friends, &$usable_amount)
|
|
|
{
|
|
|
while (true)
|
|
|
{
|
|
@@ -209,7 +224,7 @@ class shaker_helper
|
|
|
}
|
|
|
|
|
|
$this->strength = $strength;
|
|
|
- $direct = self::direct_gain;//$this->direction();
|
|
|
+ $direct = $this->direction();
|
|
|
if($direct == self::direct_gain) {
|
|
|
return $this->gain($result);
|
|
|
}
|
|
@@ -269,6 +284,27 @@ class shaker_helper
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private function add_lost_friend($user_ids)
|
|
|
+ {
|
|
|
+ if(!isset($_SESSION['game_shake']['losted_friends'])) {
|
|
|
+ $_SESSION['game_shake']['losted_friends'] = array();
|
|
|
+ }
|
|
|
+ $friends = &$_SESSION['game_shake']['losted_friends'];
|
|
|
+
|
|
|
+ foreach ($user_ids as $user_id)
|
|
|
+ {
|
|
|
+ if(isset($friends[$user_id])) {
|
|
|
+ $friends[$user_id]['user_id'] = $user_id;
|
|
|
+ $friends[$user_id]['last_time'] = time();
|
|
|
+ $friends[$user_id]['count'] = intval($friends[$user_id]['count']) + 1;
|
|
|
+ } else {
|
|
|
+ $friends[$user_id]['user_id'] = $user_id;
|
|
|
+ $friends[$user_id]['last_time'] = time();
|
|
|
+ $friends[$user_id]['count'] = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//可以偷的好友
|
|
|
private function gain_friends()
|
|
|
{
|
|
@@ -291,7 +327,7 @@ class shaker_helper
|
|
|
|
|
|
$all_friends = array_merge($subscriber,$follower);
|
|
|
sort($all_friends,SORT_NUMERIC);
|
|
|
- $all_friends = array_unique($all_friends,SORT_NUMERIC);
|
|
|
+ $all_friends = array_merge(array_unique($all_friends,SORT_NUMERIC),[]);
|
|
|
sort($all_friends);
|
|
|
foreach ($exids as $uid)
|
|
|
{
|
|
@@ -323,7 +359,10 @@ class shaker_helper
|
|
|
$follower = relation_helper::follower($_SESSION['member_id']);
|
|
|
|
|
|
$all_friends = array_merge($subscriber,$follower);
|
|
|
- sort($all_friends);
|
|
|
+ sort($all_friends,SORT_NUMERIC);
|
|
|
+ $all_friends = array_merge(array_unique($all_friends,SORT_NUMERIC),[]);
|
|
|
+ sort($all_friends,SORT_NUMERIC);
|
|
|
+
|
|
|
foreach ($exids as $uid)
|
|
|
{
|
|
|
$pos = algorithm_helper::bsearch($uid,$all_friends);
|
|
@@ -367,6 +406,7 @@ class shaker_helper
|
|
|
else
|
|
|
{
|
|
|
$rand = mt_rand(1,100);
|
|
|
+
|
|
|
$direct = ($rand % 2) == 0 ? self::direct_gain : self::direct_lost;
|
|
|
$_SESSION['game_shake']['direction'] = $direct;
|
|
|
}
|