|
@@ -223,14 +223,17 @@ class predeposit_helper
|
|
|
private $mShareRates;
|
|
|
private $mBonusState;
|
|
|
private $mRateVersion; //用来记录,红包过期带来的红包变化
|
|
|
+ private $mFromSession;
|
|
|
|
|
|
- public function __construct($member_id)
|
|
|
+ public function __construct($member_id,$from_session = false)
|
|
|
{
|
|
|
$this->model_pd = Model('predeposit');
|
|
|
$this->member_id = $member_id;
|
|
|
+ $this->mFromSession = $from_session;
|
|
|
|
|
|
$pd_array = Model('member')->getMemberPdInfo($this->member_id);
|
|
|
$this->mRateVersion = intval($pd_array['rate_version']);
|
|
|
+
|
|
|
$this->init_rate();
|
|
|
}
|
|
|
public function member_id() {
|
|
@@ -239,27 +242,34 @@ class predeposit_helper
|
|
|
|
|
|
private function init_rate()
|
|
|
{
|
|
|
- $fUpdate = false;
|
|
|
- if(isset($_SESSION['bonus_rate_version']) == false) {
|
|
|
- $fUpdate = true;
|
|
|
- }
|
|
|
- else
|
|
|
+ if($this->mFromSession)
|
|
|
{
|
|
|
- $version = $_SESSION['bonus_rate_version'];
|
|
|
- if($version != $this->mRateVersion) {
|
|
|
+ $fUpdate = false;
|
|
|
+ if(isset($_SESSION['bonus_rate_version']) == false) {
|
|
|
$fUpdate = true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if(isset($_SESSION['bonus_rate']) && isset($_SESSION['bonus_state']) && isset($_SESSION['share_bonus_rate'])) {
|
|
|
- $this->mPayRates = new RateMoney($_SESSION['bonus_rate']);
|
|
|
- $this->mShareRates = new RateMoney($_SESSION['share_bonus_rate']);
|
|
|
- $this->mBonusState = $_SESSION['bonus_state'];
|
|
|
- } else {
|
|
|
+ $version = $_SESSION['bonus_rate_version'];
|
|
|
+ if($version != $this->mRateVersion) {
|
|
|
$fUpdate = true;
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(isset($_SESSION['bonus_rate']) && isset($_SESSION['bonus_state']) && isset($_SESSION['share_bonus_rate'])) {
|
|
|
+ $this->mPayRates = new RateMoney($_SESSION['bonus_rate']);
|
|
|
+ $this->mShareRates = new RateMoney($_SESSION['share_bonus_rate']);
|
|
|
+ $this->mBonusState = $_SESSION['bonus_state'];
|
|
|
+ } else {
|
|
|
+ $fUpdate = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $fUpdate = true;
|
|
|
+ }
|
|
|
|
|
|
if($fUpdate || $this->need_update())
|
|
|
{
|
|
@@ -274,10 +284,10 @@ class predeposit_helper
|
|
|
$this->mShareRates->add_bonuses($share_items);
|
|
|
$share_bonus_rate = $this->mShareRates->format();
|
|
|
|
|
|
-
|
|
|
$this->mBonusState = [];
|
|
|
$querys = array('usable','expiring','used','expired');
|
|
|
- foreach ($querys as $state) {
|
|
|
+ foreach ($querys as $state)
|
|
|
+ {
|
|
|
$cond = $this->query_cond($state);
|
|
|
if($state == 'used') {
|
|
|
$sum = $mod_bonus->getSum($cond,'bonus_value');
|
|
@@ -288,31 +298,44 @@ class predeposit_helper
|
|
|
}
|
|
|
|
|
|
$this->write_rates($this->mBonusState,$pay_bonus_rate,$share_bonus_rate);
|
|
|
+
|
|
|
$this->mPayRates->clean();
|
|
|
$this->mShareRates->clean();
|
|
|
- $_SESSION['bonus_update_time'] = time();
|
|
|
+
|
|
|
+ if($this->mFromSession) {
|
|
|
+ $_SESSION['bonus_update_time'] = time();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private function need_update()
|
|
|
{
|
|
|
- if(!isset($_SESSION['bonus_update_time'])) return true;
|
|
|
+ if($this->mFromSession)
|
|
|
+ {
|
|
|
+ if(!isset($_SESSION['bonus_update_time'])) return true;
|
|
|
|
|
|
- $time = intval($_SESSION['bonus_update_time']);
|
|
|
- if(time() - $time > 86400) {
|
|
|
+ $time = intval($_SESSION['bonus_update_time']);
|
|
|
+ if(time() - $time > 86400) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public function __destruct()
|
|
|
{
|
|
|
- if($this->mPayRates != null && $this->mPayRates->dirty()) {
|
|
|
- $this->del_rates();
|
|
|
- }
|
|
|
- if($this->mShareRates != null && $this->mShareRates->dirty()) {
|
|
|
- $this->del_rates();
|
|
|
+ if($this->mFromSession)
|
|
|
+ {
|
|
|
+ if($this->mPayRates != null && $this->mPayRates->dirty()) {
|
|
|
+ $this->del_rates();
|
|
|
+ }
|
|
|
+ if($this->mShareRates != null && $this->mShareRates->dirty()) {
|
|
|
+ $this->del_rates();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -329,59 +352,6 @@ class predeposit_helper
|
|
|
return $this->mShareRates->total();
|
|
|
}
|
|
|
|
|
|
- static public function order_cash($goods_amount, &$rates)
|
|
|
- {
|
|
|
- if(isset($_SESSION['bonus_rate']) == false) {
|
|
|
- $pred = new predeposit_helper($_SESSION['member_id']);
|
|
|
- $bonus_rate = $pred->pay_bonus_rates();
|
|
|
- } else {
|
|
|
- $bonus_rate = new RateMoney($_SESSION['bonus_rate']);
|
|
|
- }
|
|
|
-
|
|
|
- return $bonus_rate->calc_money($goods_amount,$rates);
|
|
|
- }
|
|
|
-
|
|
|
- static public function login_bonus_price($goods_price, &$rates)
|
|
|
- {
|
|
|
- if(session_helper::logined())
|
|
|
- {
|
|
|
- if(isset($_SESSION['bonus_rate']) == false) {
|
|
|
- $pred = new predeposit_helper($_SESSION['member_id']);
|
|
|
- $bonus_rate = $pred->pay_bonus_rates();
|
|
|
- } else {
|
|
|
- $bonus_rate = new RateMoney($_SESSION['bonus_rate']);
|
|
|
- }
|
|
|
-
|
|
|
- return $bonus_rate->calc_price($goods_price,$rates);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return ($goods_price);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- static public function unlogin_bonus_price($goods_price,$rate_moneys,&$rates)
|
|
|
- {
|
|
|
- if(!empty($rate_moneys)) {
|
|
|
- $bonus_rate = new RateMoney($rate_moneys);
|
|
|
- return $bonus_rate->calc_price($goods_price,$rates);
|
|
|
- } else {
|
|
|
- return $goods_price;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- static public function discount_gap($bonus_price,$goods_price)
|
|
|
- {
|
|
|
- $bonus_price = intval($bonus_price* 100 + 0.5);
|
|
|
- $discount = intval($goods_price * 70 + 0.5);
|
|
|
-
|
|
|
- if($bonus_price <= $discount) {
|
|
|
- return 0;
|
|
|
- } else {
|
|
|
- return ($bonus_price - $discount) / 100;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public function bonus_state() {
|
|
|
return $this->mBonusState;
|
|
|
}
|
|
@@ -391,7 +361,7 @@ class predeposit_helper
|
|
|
static $stQuerys = array('usable','expiring','used','expired');
|
|
|
static $day_secs = 24 * 3600;
|
|
|
|
|
|
- $cond = array('user_id' => $_SESSION['member_id'],'bonus_status' => 3);
|
|
|
+ $cond = array('user_id' => $this->member_id,'bonus_status' => 3);
|
|
|
|
|
|
if(!empty($query_state) && in_array($query_state,$stQuerys))
|
|
|
{
|
|
@@ -419,25 +389,31 @@ class predeposit_helper
|
|
|
|
|
|
private function write_rates($bonus_state, $pay_bonus_rate,$share_bonus_rate)
|
|
|
{
|
|
|
- $_SESSION['bonus_state'] = $bonus_state;
|
|
|
- $_SESSION['bonus_rate'] = $pay_bonus_rate;
|
|
|
- $_SESSION['share_bonus_rate'] = $share_bonus_rate;
|
|
|
- $_SESSION['bonus_rate_version'] = $this->mRateVersion;
|
|
|
+ if($this->mFromSession)
|
|
|
+ {
|
|
|
+ $_SESSION['bonus_state'] = $bonus_state;
|
|
|
+ $_SESSION['bonus_rate'] = $pay_bonus_rate;
|
|
|
+ $_SESSION['share_bonus_rate'] = $share_bonus_rate;
|
|
|
+ $_SESSION['bonus_rate_version'] = $this->mRateVersion;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private function del_rates()
|
|
|
{
|
|
|
- if(isset($_SESSION['bonus_state'])) {
|
|
|
- unset($_SESSION['bonus_state']);
|
|
|
- }
|
|
|
- if(isset($_SESSION['bonus_rate'])) {
|
|
|
- unset($_SESSION['bonus_rate']);
|
|
|
- }
|
|
|
- if(isset($_SESSION['share_bonus_rate'])) {
|
|
|
- unset($_SESSION['share_bonus_rate']);
|
|
|
- }
|
|
|
- if(isset($_SESSION['bonus_rate_version'])) {
|
|
|
- unset($_SESSION['bonus_rate_version']);
|
|
|
+ if($this->mFromSession)
|
|
|
+ {
|
|
|
+ if(isset($_SESSION['bonus_state'])) {
|
|
|
+ unset($_SESSION['bonus_state']);
|
|
|
+ }
|
|
|
+ if(isset($_SESSION['bonus_rate'])) {
|
|
|
+ unset($_SESSION['bonus_rate']);
|
|
|
+ }
|
|
|
+ if(isset($_SESSION['share_bonus_rate'])) {
|
|
|
+ unset($_SESSION['share_bonus_rate']);
|
|
|
+ }
|
|
|
+ if(isset($_SESSION['bonus_rate_version'])) {
|
|
|
+ unset($_SESSION['bonus_rate_version']);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -623,8 +599,7 @@ class predeposit_helper
|
|
|
public function bonus_refund($bonus_type)
|
|
|
{
|
|
|
$types = bonus\type::create_by_paramer($bonus_type);
|
|
|
- QueueClient::push('onPredeposit',
|
|
|
- array('change_type' => 'bonus_refund','buyer_id'=>$types->sender_id(),'order_sn'=>$types->getType_sn()));
|
|
|
+ QueueClient::push('onPredeposit',array('change_type' => 'bonus_refund','buyer_id'=>$types->sender_id(),'order_sn'=>$types->getType_sn()));
|
|
|
}
|
|
|
|
|
|
public function transform_money($member_id,$name,$amount)
|
|
@@ -941,4 +916,57 @@ class predeposit_helper
|
|
|
{
|
|
|
Model('member')->inc_rate_version($this->member_id);
|
|
|
}
|
|
|
+
|
|
|
+ static public function order_cash($goods_amount, &$rates)
|
|
|
+ {
|
|
|
+ if(isset($_SESSION['bonus_rate']) == false) {
|
|
|
+ $pred = new predeposit_helper($_SESSION['member_id'],true);
|
|
|
+ $bonus_rate = $pred->pay_bonus_rates();
|
|
|
+ } else {
|
|
|
+ $bonus_rate = new RateMoney($_SESSION['bonus_rate']);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $bonus_rate->calc_money($goods_amount,$rates);
|
|
|
+ }
|
|
|
+
|
|
|
+ static public function login_bonus_price($goods_price, &$rates)
|
|
|
+ {
|
|
|
+ if(session_helper::logined())
|
|
|
+ {
|
|
|
+ if(isset($_SESSION['bonus_rate']) == false) {
|
|
|
+ $pred = new predeposit_helper($_SESSION['member_id'],true);
|
|
|
+ $bonus_rate = $pred->pay_bonus_rates();
|
|
|
+ } else {
|
|
|
+ $bonus_rate = new RateMoney($_SESSION['bonus_rate']);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $bonus_rate->calc_price($goods_price,$rates);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return ($goods_price);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static public function unlogin_bonus_price($goods_price,$rate_moneys,&$rates)
|
|
|
+ {
|
|
|
+ if(!empty($rate_moneys)) {
|
|
|
+ $bonus_rate = new RateMoney($rate_moneys);
|
|
|
+ return $bonus_rate->calc_price($goods_price,$rates);
|
|
|
+ } else {
|
|
|
+ return $goods_price;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static public function discount_gap($bonus_price,$goods_price)
|
|
|
+ {
|
|
|
+ $bonus_price = intval($bonus_price* 100 + 0.5);
|
|
|
+ $discount = intval($goods_price * 70 + 0.5);
|
|
|
+
|
|
|
+ if($bonus_price <= $discount) {
|
|
|
+ return 0;
|
|
|
+ } else {
|
|
|
+ return ($bonus_price - $discount) / 100;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|