|
@@ -792,46 +792,24 @@ class StoreOrder extends BaseModel
|
|
|
$userModel = new \app\admin\model\user\User();
|
|
|
$leader = $userModel->getLeader($order['uid']);
|
|
|
$res = true;
|
|
|
- if ($leader) {
|
|
|
+ if($leader){
|
|
|
$price = $order['total_price'];
|
|
|
//TODO
|
|
|
- $ratio = sys_config('spread_ratio'); // 获取推广佣金比例
|
|
|
- $award = bcmul($price, $ratio, 2); // 计算推广佣金
|
|
|
+ $ratio = sys_config('spread_ratio');
|
|
|
+ $award = bcmul($price, $ratio, 2);
|
|
|
//TODO 上级推广员返佣之后的金额
|
|
|
- $spreadUserInfo = User::get($leader['spread_uid']);
|
|
|
- $virtualBrokeragePrice = self::getVirtualBrokeragePrice($award, $spreadUserInfo['grade']);
|
|
|
- $balance = bcadd($spreadUserInfo['brokerage_price'], $virtualBrokeragePrice, 2);
|
|
|
$userInfo = User::get($order['uid']);
|
|
|
- $mark = $userInfo['nickname'] . '成功消费[虚拟产品]' . floatval($order['pay_price']) . '元,奖励推广佣金' . floatval($virtualBrokeragePrice);
|
|
|
+ $mark = $userInfo['nickname'] . '成功消费[虚拟产品]' . floatval($order['pay_price']) . '元,奖励推广佣金' . floatval($award);
|
|
|
//TODO 添加推广记录
|
|
|
- $res1 = UserBill::income('获得推广佣金', $leader['spread_uid'], 'now_money', 'brokerage', $virtualBrokeragePrice, $order['id'], $balance, $mark); // 添加推广记录
|
|
|
+ $res1 = UserBill::income('获得推广佣金', $leader['spread_uid'], 'now_money', 'brokerage', $award, $order['id'], $leader['spreadUserInfo']['brokerage_price'] + $award, $mark);
|
|
|
//TODO 添加用户余额
|
|
|
- $res2 = User::bcInc($leader['spread_uid'], 'brokerage_price', $virtualBrokeragePrice, 'uid'); // 添加用户余额
|
|
|
+ $res2 = User::bcInc($leader['spread_uid'], 'brokerage_price', $award, 'uid');
|
|
|
//TODO END;
|
|
|
- $res = $res1 && $res2;
|
|
|
+ $res = $res1&&$res2;
|
|
|
}
|
|
|
return $res;
|
|
|
}
|
|
|
|
|
|
- public static function getVirtualBrokeragePrice($award, $grade)
|
|
|
- {
|
|
|
- $virtualBrokeragePrice = 0;
|
|
|
- $brokerageCount = count(sys_config('brokerage_count')); // 获取佣金层级数
|
|
|
- $brokeragePrices = [];
|
|
|
- for ($i = $brokerageCount - 1; $i >= 0; $i--) {
|
|
|
- $brokeragePrices[] = sys_config("brokerage_{$i}_price");
|
|
|
- }
|
|
|
- if ($grade < $brokerageCount) {
|
|
|
- $continue = true;
|
|
|
- for ($i = $grade - 1; $continue && $i >= 0; $i--) {
|
|
|
- $virtualBrokeragePrice = bcadd($virtualBrokeragePrice, bcmul($award, $brokeragePrices[$i], 2), 2);
|
|
|
- $continue = $brokeragePrices[$i] > 0;
|
|
|
- }
|
|
|
- } else {
|
|
|
- $virtualBrokeragePrice = bcadd($virtualBrokeragePrice, bcmul($award, $brokeragePrices[$brokerageCount - 1], 2), 2);
|
|
|
- }
|
|
|
- return $virtualBrokeragePrice;
|
|
|
- }
|
|
|
|
|
|
|
|
|
/*
|