|
@@ -91,6 +91,10 @@ class User extends ModelBasic
|
|
|
return $uid;
|
|
return $uid;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** //TODO 一级返佣
|
|
|
|
|
+ * @param $orderInfo
|
|
|
|
|
+ * @return bool
|
|
|
|
|
+ */
|
|
|
public static function backOrderBrokerage($orderInfo)
|
|
public static function backOrderBrokerage($orderInfo)
|
|
|
{
|
|
{
|
|
|
$userInfo = User::getUserInfo($orderInfo['uid']);
|
|
$userInfo = User::getUserInfo($orderInfo['uid']);
|
|
@@ -102,6 +106,7 @@ class User extends ModelBasic
|
|
|
$brokerageRatio = (SystemConfigService::get('store_brokerage_ratio') ?: 0)/100;
|
|
$brokerageRatio = (SystemConfigService::get('store_brokerage_ratio') ?: 0)/100;
|
|
|
if($brokerageRatio <= 0) return true;
|
|
if($brokerageRatio <= 0) return true;
|
|
|
$cost = isset($orderInfo['cost']) ? $orderInfo['cost'] : 0;//成本价
|
|
$cost = isset($orderInfo['cost']) ? $orderInfo['cost'] : 0;//成本价
|
|
|
|
|
+ if($cost > $orderInfo['pay_price']) return true;//成本价大于支付价格时直接返回
|
|
|
$brokeragePrice = bcmul(bcsub($orderInfo['pay_price'],$cost,2),$brokerageRatio,2);
|
|
$brokeragePrice = bcmul(bcsub($orderInfo['pay_price'],$cost,2),$brokerageRatio,2);
|
|
|
if($brokeragePrice <= 0) return true;
|
|
if($brokeragePrice <= 0) return true;
|
|
|
$mark = $userInfo['nickname'].'成功消费'.floatval($orderInfo['pay_price']).'元,奖励推广佣金'.floatval($brokeragePrice);
|
|
$mark = $userInfo['nickname'].'成功消费'.floatval($orderInfo['pay_price']).'元,奖励推广佣金'.floatval($brokeragePrice);
|
|
@@ -110,6 +115,35 @@ class User extends ModelBasic
|
|
|
$res2 = self::bcInc($userInfo['spread_uid'],'now_money',$brokeragePrice,'uid');
|
|
$res2 = self::bcInc($userInfo['spread_uid'],'now_money',$brokeragePrice,'uid');
|
|
|
$res = $res1 && $res2;
|
|
$res = $res1 && $res2;
|
|
|
self::checkTrans($res);
|
|
self::checkTrans($res);
|
|
|
|
|
+ if($res) self::backOrderBrokerageTwo($orderInfo);
|
|
|
|
|
+ return $res;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * //TODO 二级推广
|
|
|
|
|
+ * @param $orderInfo
|
|
|
|
|
+ * @return bool
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function backOrderBrokerageTwo($orderInfo){
|
|
|
|
|
+ $userInfo = User::getUserInfo($orderInfo['uid']);
|
|
|
|
|
+ $userInfoTwo = User::getUserInfo($userInfo['spread_uid']);
|
|
|
|
|
+ if(!$userInfoTwo || !$userInfoTwo['spread_uid']) return true;
|
|
|
|
|
+ $storeBrokerageStatu = SystemConfigService::get('store_brokerage_statu') ? : 1;//获取后台分销类型
|
|
|
|
|
+ if($storeBrokerageStatu == 1){
|
|
|
|
|
+ if(!User::be(['uid'=>$userInfoTwo['spread_uid'],'is_promoter'=>1])) return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ $brokerageRatio = (SystemConfigService::get('store_brokerage_two') ?: 0)/100;
|
|
|
|
|
+ if($brokerageRatio <= 0) return true;
|
|
|
|
|
+ $cost = isset($orderInfo['cost']) ? $orderInfo['cost'] : 0;//成本价
|
|
|
|
|
+ if($cost > $orderInfo['pay_price']) return true;//成本价大于支付价格时直接返回
|
|
|
|
|
+ $brokeragePrice = bcmul(bcsub($orderInfo['pay_price'],$cost,2),$brokerageRatio,2);
|
|
|
|
|
+ if($brokeragePrice <= 0) return true;
|
|
|
|
|
+ $mark = '二级推广人'.$userInfo['nickname'].'成功消费'.floatval($orderInfo['pay_price']).'元,奖励推广佣金'.floatval($brokeragePrice);
|
|
|
|
|
+ self::beginTrans();
|
|
|
|
|
+ $res1 = UserBill::income('获得推广佣金',$userInfoTwo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],0,$mark);
|
|
|
|
|
+ $res2 = self::bcInc($userInfoTwo['spread_uid'],'now_money',$brokeragePrice,'uid');
|
|
|
|
|
+ $res = $res1 && $res2;
|
|
|
|
|
+ self::checkTrans($res);
|
|
|
return $res;
|
|
return $res;
|
|
|
}
|
|
}
|
|
|
|
|
|