|
@@ -26,6 +26,7 @@ class CalcPrice implements ICalc
|
|
private $mUserCards = null;
|
|
private $mUserCards = null;
|
|
private $mMemberInfo = null;
|
|
private $mMemberInfo = null;
|
|
private $mInvitees = 0;
|
|
private $mInvitees = 0;
|
|
|
|
+ private $mOrderCount = 0;
|
|
|
|
|
|
private $mUsedInvitees = false;
|
|
private $mUsedInvitees = false;
|
|
private $mUsedInviteesNum = 0;
|
|
private $mUsedInviteesNum = 0;
|
|
@@ -37,6 +38,7 @@ class CalcPrice implements ICalc
|
|
$this->mUserCards = new user_mcards($userid);
|
|
$this->mUserCards = new user_mcards($userid);
|
|
$this->mMemberInfo = new member_info($userid);
|
|
$this->mMemberInfo = new member_info($userid);
|
|
$this->mInvitees = $this->invitees();
|
|
$this->mInvitees = $this->invitees();
|
|
|
|
+ $this->mOrderCount = $this->order_num() + $this->vrorder_num();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -49,17 +51,40 @@ class CalcPrice implements ICalc
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- private function isFirstorOrder()
|
|
|
|
|
|
+ private function order_num()
|
|
{
|
|
{
|
|
- if($this->mUserId > 0 && $this->mMemberInfo != null) {
|
|
|
|
- return $this->mMemberInfo->order_num() == 0;
|
|
|
|
|
|
+ if($this->mUserId <= 0) return 0;
|
|
|
|
+ $mod_member = Model('order');
|
|
|
|
+ $items = $mod_member->field('COUNT(*) AS order_num')
|
|
|
|
+ ->where(['member_id' => $this->mUserId,'order_state' => ['in',[ORDER_STATE_NEW,ORDER_STATE_PAY,ORDER_STATE_SEND,ORDER_STATE_SUCCESS]]])
|
|
|
|
+ ->select();
|
|
|
|
+
|
|
|
|
+ if(empty($items)) {
|
|
|
|
+ return 0;
|
|
|
|
+ } else {
|
|
|
|
+ return intval($items[0]['order_num']);
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- return true;
|
|
|
|
|
|
+ }
|
|
|
|
+ private function vrorder_num()
|
|
|
|
+ {
|
|
|
|
+ if($this->mUserId <= 0) return 0;
|
|
|
|
+ $mod_member = Model('vr_order');
|
|
|
|
+ $items = $mod_member->field('COUNT(*) AS order_num')
|
|
|
|
+ ->where(['member_id' => $this->mUserId,'order_state' => ['in',[ORDER_STATE_NEW,ORDER_STATE_PAY,ORDER_STATE_SEND,ORDER_STATE_SUCCESS]]])
|
|
|
|
+ ->select();
|
|
|
|
+
|
|
|
|
+ if(empty($items)) {
|
|
|
|
+ return 0;
|
|
|
|
+ } else {
|
|
|
|
+ return intval($items[0]['order_num']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private function isFirstorOrder()
|
|
|
|
+ {
|
|
|
|
+ return ($this->mOrderCount == 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
private function select_invitees()
|
|
private function select_invitees()
|
|
{
|
|
{
|
|
if($this->mUserId <= 0 || $this->mMemberInfo == null) {
|
|
if($this->mUserId <= 0 || $this->mMemberInfo == null) {
|
|
@@ -80,8 +105,10 @@ class CalcPrice implements ICalc
|
|
|
|
|
|
private function invitees()
|
|
private function invitees()
|
|
{
|
|
{
|
|
- $model = model('member');
|
|
|
|
- $ret = $model->field('count(*) inviter_count' )->where(['inviter_id' => $this->mUserId])->select();
|
|
|
|
|
|
+ $mod_member = Model('member');
|
|
|
|
+ $ret = $mod_member->field('COUNT(*) AS inviter_count')
|
|
|
|
+ ->where(['inviter_id' => $this->mUserId])
|
|
|
|
+ ->select();
|
|
if(empty($ret)) {
|
|
if(empty($ret)) {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -105,7 +132,7 @@ class CalcPrice implements ICalc
|
|
public function deduct_invitees()
|
|
public function deduct_invitees()
|
|
{
|
|
{
|
|
if($this->mUsedInvitees) {
|
|
if($this->mUsedInvitees) {
|
|
- $model = model('member');
|
|
|
|
|
|
+ $model = Model('member');
|
|
$num = $this->mUsedInviteesNum;
|
|
$num = $this->mUsedInviteesNum;
|
|
$model->editMember(['member_id' => $this->mUserId], ['used_invitees'=> ['exp', "used_invitees+{$num}"]]);
|
|
$model->editMember(['member_id' => $this->mUserId], ['used_invitees'=> ['exp', "used_invitees+{$num}"]]);
|
|
}
|
|
}
|
|
@@ -122,13 +149,13 @@ class CalcPrice implements ICalc
|
|
$fVip = $this->isVip();
|
|
$fVip = $this->isVip();
|
|
if($fVip)
|
|
if($fVip)
|
|
{
|
|
{
|
|
- if(session_helper::first_order()) {
|
|
|
|
|
|
+ if($this->isFirstorOrder()) {
|
|
$tips = $config['tips']['vip_first_order'];
|
|
$tips = $config['tips']['vip_first_order'];
|
|
} else {
|
|
} else {
|
|
$tips = $config['tips']['vip_user'];
|
|
$tips = $config['tips']['vip_user'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- elseif(session_helper::first_order()) {
|
|
|
|
|
|
+ elseif($this->isFirstorOrder()) {
|
|
$tips = $config['tips']['first_order'];
|
|
$tips = $config['tips']['first_order'];
|
|
} else {
|
|
} else {
|
|
$tips = $config['tips']['none_vip'];
|
|
$tips = $config['tips']['none_vip'];
|
|
@@ -178,7 +205,6 @@ class CalcPrice implements ICalc
|
|
return ['price_des' => '首单价', 'accu_price' => round($goods_price * self::FIRST_ORDER_PRICE,2)];
|
|
return ['price_des' => '首单价', 'accu_price' => round($goods_price * self::FIRST_ORDER_PRICE,2)];
|
|
}
|
|
}
|
|
elseif(!empty($num_dis = $this->select_invitees())) {
|
|
elseif(!empty($num_dis = $this->select_invitees())) {
|
|
- $num = $num_dis['num'];
|
|
|
|
$this->mUsedInvitees = true;
|
|
$this->mUsedInvitees = true;
|
|
$discount = $num_dis['discount'];
|
|
$discount = $num_dis['discount'];
|
|
return ['price_des' => '邀请价', 'accu_price' => round($goods_price * $discount,2)];
|
|
return ['price_des' => '邀请价', 'accu_price' => round($goods_price * $discount,2)];
|
|
@@ -204,10 +230,9 @@ class CalcPrice implements ICalc
|
|
return round($goods_price * self::FIRST_ORDER_PRICE * $num,2);
|
|
return round($goods_price * self::FIRST_ORDER_PRICE * $num,2);
|
|
}
|
|
}
|
|
elseif(!empty($num_dis = $this->select_invitees())) {
|
|
elseif(!empty($num_dis = $this->select_invitees())) {
|
|
- $num = $num_dis['num'];
|
|
|
|
$this->mUsedInvitees = true;
|
|
$this->mUsedInvitees = true;
|
|
$discount = $num_dis['discount'];
|
|
$discount = $num_dis['discount'];
|
|
- return round($goods_price * $discount * $num);
|
|
|
|
|
|
+ return round($goods_price * $discount * $num,2);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
return round($goods_price * $num * self::DEFAULT_ORDER_PRICE,2);
|
|
return round($goods_price * $num * self::DEFAULT_ORDER_PRICE,2);
|