|
|
@@ -297,7 +297,7 @@ class User extends BaseModel
|
|
|
if (!$userInfo || !$userInfo['spread_uid'] || $userInfo['spread_uid'] == $orderInfo['uid']) return true;
|
|
|
if (!User::be(['uid' => $userInfo['spread_uid'], 'is_promoter' => 1])) return self::backOrderBrokerageTwo($orderInfo, $open);
|
|
|
$cartId = is_string($orderInfo['cart_id']) ? json_decode($orderInfo['cart_id'], true) : $orderInfo['cart_id'];
|
|
|
- list($realBrokeragePrice, $virtualBrokeragePrice) = StoreProduct::getProductBrokerage($userInfo['uid'],$userInfo['spread_uid'],$cartId);
|
|
|
+ list($realBrokeragePrice, $virtualBrokeragePrice) = StoreProduct::getProductBrokerage($userInfo['uid'], $userInfo['spread_uid'], $cartId);
|
|
|
//TODO 返佣金额小于等于0 直接返回不返佣金
|
|
|
if ($realBrokeragePrice <= 0 && $virtualBrokeragePrice <= 0) return true;
|
|
|
//TODO 获取上级推广员信息
|
|
|
@@ -317,23 +317,23 @@ class User extends BaseModel
|
|
|
}
|
|
|
if ($realBrokeragePrice > 0) {
|
|
|
$spreadUserInfo = User::getUserInfo($userInfo['spread_uid']);
|
|
|
- $order_count = StoreOrder::where('uid', $userInfo['uid'])->where('paid' , 1)->count();
|
|
|
+ $order_count = StoreOrder::where('uid', $userInfo['uid'])->where('paid', 1)->count();
|
|
|
$cartInfo = StoreOrderCartInfo::whereIn('cart_id', $cartId)->column('cart_info');
|
|
|
$repurchase = 0;
|
|
|
foreach ($cartInfo as $value) {
|
|
|
$product = json_decode($value, true);
|
|
|
$product_fg = StoreProduct::where('id', $product['product_id'])->value('is_best');
|
|
|
- if ($product_fg > 0){
|
|
|
+ if ($product_fg > 0) {
|
|
|
$repurchase = 1;
|
|
|
}
|
|
|
}
|
|
|
//TODO 上级推广员返佣之后的金额
|
|
|
|
|
|
//TODO 添加推广记录
|
|
|
- if ($repurchase == 0){
|
|
|
+ if ($repurchase == 0) {
|
|
|
|
|
|
$brokerage_price = $realBrokeragePrice * 0.95;// 到账佣金
|
|
|
- $integral = $realBrokeragePrice * 0.05;// 到账积分
|
|
|
+ $integral = $realBrokeragePrice * 0.05;// 到账积分
|
|
|
|
|
|
$mark = $userInfo['nickname'] . '成功消费[实体产品]' . floatval($orderInfo['pay_price']) . '元,奖励推广佣金' . floatval($brokerage_price);
|
|
|
$mark1 = $userInfo['nickname'] . '成功消费[实体产品]' . floatval($orderInfo['pay_price']) . '元,奖励推广积分' . floatval($integral);
|
|
|
@@ -345,17 +345,17 @@ class User extends BaseModel
|
|
|
$res2 = self::bcInc($userInfo['spread_uid'], 'brokerage_price', $brokerage_price, 'uid');
|
|
|
$res2 = self::bcInc($userInfo['spread_uid'], 'integral', $integral, 'uid');
|
|
|
|
|
|
- if ($spreadUserInfo['identity'] == 1){
|
|
|
- $uid = getParent($userInfo['spread_uid'],User::select()); //找到最上级
|
|
|
- if (count($uid) > 0){
|
|
|
+ if ($spreadUserInfo['identity'] == 1) {
|
|
|
+ $uid = getParent($userInfo['spread_uid'], User::select()); //找到最上级
|
|
|
+ if (count($uid) > 0) {
|
|
|
$uid1 = array_pop($uid);
|
|
|
$user1 = User::where('uid', $uid1)->find();
|
|
|
- if ($user1['line'] >= 3){
|
|
|
+ if ($user1['line'] >= 3) {
|
|
|
$amministrazione = User::where('uid', $user1['spread_uid'])->find();// 发放管理奖
|
|
|
- if ($amministrazione){
|
|
|
- $realBrokeragePrice = $realBrokeragePrice * (sys_config('administration')/100);
|
|
|
+ if ($amministrazione) {
|
|
|
+ $realBrokeragePrice = $realBrokeragePrice * (sys_config('administration') / 100);
|
|
|
$brokerage_price = $realBrokeragePrice * 0.95;// 到账佣金
|
|
|
- $integral = $realBrokeragePrice * 0.05;// 到账积分
|
|
|
+ $integral = $realBrokeragePrice * 0.05;// 到账积分
|
|
|
|
|
|
UserBill::income('获得推广佣金', $amministrazione['uid'], 'now_money', 'brokerage', $brokerage_price, $orderInfo['id'], $amministrazione['brokerage_price'] + $brokerage_price, '管理佣金奖励');
|
|
|
UserBill::income('获得推广积分', $amministrazione['uid'], 'integral', 'Level', $integral, $orderInfo['id'], $amministrazione['integral'] + $integral, '管理积分奖励');
|
|
|
@@ -365,12 +365,12 @@ class User extends BaseModel
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }elseif ($spreadUserInfo['identity'] == 2){
|
|
|
+ } elseif ($spreadUserInfo['identity'] == 2) {
|
|
|
self::livello($spreadUserInfo['spread_uid'], $realBrokeragePrice);
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$brokerage_price = $realBrokeragePrice * 0.95;// 到账佣金
|
|
|
- $integral = $realBrokeragePrice * 0.05;// 到账积分
|
|
|
+ $integral = $realBrokeragePrice * 0.05;// 到账积分
|
|
|
|
|
|
$mark = $userInfo['nickname'] . '复购成功消费[实体产品]' . floatval($orderInfo['pay_price']) . '元,奖励推广佣金' . floatval($brokerage_price);
|
|
|
$mark1 = $userInfo['nickname'] . '复购成功消费[实体产品]' . floatval($orderInfo['pay_price']) . '元,奖励推广积分' . floatval($integral);
|
|
|
@@ -384,7 +384,6 @@ class User extends BaseModel
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|
|
|
// $res = $res && self::backOrderBrokerageTwo($orderInfo);
|
|
|
// $open && self::checkTrans($res);
|
|
|
@@ -400,15 +399,15 @@ class User extends BaseModel
|
|
|
*/
|
|
|
public static function livello($uid, $price)
|
|
|
{
|
|
|
- $uids = getParent_livello( $uid, User::select());
|
|
|
+ $uids = getParent_livello($uid, User::select());
|
|
|
|
|
|
- if (count($uids) > 0){
|
|
|
+ if (count($uids) > 0) {
|
|
|
// 第一级店长
|
|
|
- if (isset($uids[0])){
|
|
|
+ if (isset($uids[0])) {
|
|
|
$user = User::where('uid', $uids[0])->find();
|
|
|
$price1 = $price * 0.7;
|
|
|
$brokerage_price = $price1 * 0.95;// 到账佣金
|
|
|
- $integral = $price1 * 0.05;// 到账积分
|
|
|
+ $integral = $price1 * 0.05;// 到账积分
|
|
|
|
|
|
UserBill::income('获得推广佣金', $user['uid'], 'now_money', 'brokerage', $brokerage_price, '', $user['brokerage_price'] + $brokerage_price, '店长平级佣金奖励');
|
|
|
UserBill::income('获得推广积分', $user['uid'], 'integral', 'Level', $integral, '', $user['integral'] + $integral, '店长平级积分奖励');
|
|
|
@@ -416,17 +415,22 @@ class User extends BaseModel
|
|
|
self::bcInc($user['uid'], 'integral', $integral, 'uid'); //发放管理奖
|
|
|
}
|
|
|
|
|
|
- if (isset($uids[1])){
|
|
|
+ if (isset($uids[1])) {
|
|
|
// 第二级店长
|
|
|
$user = User::where('uid', $uids[1])->find();
|
|
|
$price2 = $price * 0.3;
|
|
|
$brokerage_price = $price2 * 0.95;// 到账佣金
|
|
|
- $integral = $price2 * 0.05;// 到账积分
|
|
|
-
|
|
|
- UserBill::income('获得推广佣金', $user['uid'], 'now_money', 'brokerage', $brokerage_price, '', $user['brokerage_price'] + $brokerage_price, '店长平级佣金奖励');
|
|
|
- UserBill::income('获得推广积分', $user['uid'], 'integral', 'Level', $integral, '', $user['integral'] + $integral, '店长平级积分奖励');
|
|
|
- self::bcInc($user['uid'], 'brokerage_price', $brokerage_price, 'uid'); //发放管理奖
|
|
|
- self::bcInc($user['uid'], 'integral', $integral, 'uid'); //发放管理奖
|
|
|
+ $integral = $price2 * 0.05;// 到账积分
|
|
|
+
|
|
|
+ if (UserLevel::getUserLevelInfo(UserLevel::getUserLevel($uids[1]), 'level_id') < 2) {
|
|
|
+ UserBill::income('获得推广佣金', $user['uid'], 'now_money', 'brokerage', $brokerage_price, '', $user['brokerage_price'] + $brokerage_price, '店长平级佣金奖励', 0, 1);
|
|
|
+ UserBill::income('获得推广积分', $user['uid'], 'integral', 'Level', $integral, '', $user['integral'] + $integral, '店长平级积分奖励', 0, 1);
|
|
|
+ } else {
|
|
|
+ UserBill::income('获得推广佣金', $user['uid'], 'now_money', 'brokerage', $brokerage_price, '', $user['brokerage_price'] + $brokerage_price, '店长平级佣金奖励');
|
|
|
+ UserBill::income('获得推广积分', $user['uid'], 'integral', 'Level', $integral, '', $user['integral'] + $integral, '店长平级积分奖励');
|
|
|
+ self::bcInc($user['uid'], 'brokerage_price', $brokerage_price, 'uid'); //发放管理奖
|
|
|
+ self::bcInc($user['uid'], 'integral', $integral, 'uid'); //发放管理奖
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -510,6 +514,41 @@ class User extends BaseModel
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 发放实际商品佣金
|
|
|
+ * @param $orderInfo
|
|
|
+ * @return bool
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws DbException
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ */
|
|
|
+ public static function sendLockBrokerage($uid)
|
|
|
+ {
|
|
|
+ $list = UserBill::where(['uid' => $uid, 'type' => 'brokerage', 'category' => 'now_money', 'pm' => 1, 'status' => 0, 'lock' => 1])->select();
|
|
|
+ $list2 = UserBill::where(['uid' => $uid, 'type' => 'Level', 'category' => 'integral', 'pm' => 1, 'status' => 0, 'lock' => 1])->select();
|
|
|
+ if ($list || $list2) {
|
|
|
+// self::beginTrans();
|
|
|
+ try {
|
|
|
+ foreach ($list as $v) {
|
|
|
+ self::bcInc($v['uid'], 'brokerage_price', $v['number'], 'uid');
|
|
|
+ $balance = self::getUserInfo($v['uid'])['brokerage_price'];
|
|
|
+ UserBill::where('id', $v['id'])->update(['add_time' => time(), 'status' => 1, 'balance' => $balance]);
|
|
|
+ }
|
|
|
+ foreach ($list2 as $v) {
|
|
|
+ $balance = self::getUserInfo($v['uid'])['integral'];
|
|
|
+ self::bcInc($v['uid'], 'integral', $v['number'], 'uid');
|
|
|
+ UserBill::where('id', $v['id'])->update(['add_time' => time(), 'status' => 1, 'balance' => $balance]);
|
|
|
+ }
|
|
|
+// self::commitTrans();
|
|
|
+ return true;
|
|
|
+ } catch (Exception $e) {
|
|
|
+// self::rollbackTrans();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 获取推荐人 暂无使用
|
|
|
@@ -854,29 +893,29 @@ class User extends BaseModel
|
|
|
public static function upgrade($uid)
|
|
|
{
|
|
|
$user = User::where('uid', $uid)->find();
|
|
|
- if ($user['identity'] == 0){
|
|
|
+ if ($user['identity'] == 0) {
|
|
|
$price = StoreOrder::where('uid', $uid)->where('paid', 1)->sum('pay_price');
|
|
|
- if ($price >= sys_config('cumulative')){
|
|
|
+ if ($price >= sys_config('cumulative')) {
|
|
|
$user['identity'] = 1;
|
|
|
- if ($user['spread_uid']){
|
|
|
+ if ($user['spread_uid']) {
|
|
|
$spd = User::where('uid', $user['spread_uid'])->find();
|
|
|
$user['line'] = $spd['lines'] + 1;
|
|
|
$spd['lines'] += 1;
|
|
|
$spd->save();
|
|
|
}
|
|
|
}
|
|
|
- }elseif ($user['identity'] == 1){
|
|
|
+ } elseif ($user['identity'] == 1) {
|
|
|
$count = User::where('spread_uid', $user['uid'])->where('identity', 1)->count();
|
|
|
- if ($count >= sys_config('push_clerk')){
|
|
|
+ if ($count >= sys_config('push_clerk')) {
|
|
|
$user['identity'] = 2;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
$res = $user->save();
|
|
|
- if ($user['spread_uid']){
|
|
|
+ if ($user['spread_uid']) {
|
|
|
$spd = User::where('uid', $user['spread_uid'])->find();
|
|
|
$count = User::where('spread_uid', $spd['uid'])->where('identity', 1)->count();
|
|
|
- if ($count >= sys_config('push_clerk')){
|
|
|
+ if ($count >= sys_config('push_clerk')) {
|
|
|
$spd['identity'] = 2;
|
|
|
}
|
|
|
$spd->save();
|
|
|
@@ -894,26 +933,25 @@ class User extends BaseModel
|
|
|
*/
|
|
|
public static function bonus()
|
|
|
{
|
|
|
- if (!cache('bonus')){
|
|
|
+ if (!cache('bonus')) {
|
|
|
$user = User::select();
|
|
|
- foreach ($user as $item)
|
|
|
- {
|
|
|
+ foreach ($user as $item) {
|
|
|
$start_time = date('Y-m-01 00:00:00', strtotime('-1 month'));
|
|
|
- $end_time = date('Y-m-d 23:59:59', strtotime(-date('d').'day'));
|
|
|
+ $end_time = date('Y-m-d 23:59:59', strtotime(-date('d') . 'day'));
|
|
|
$price = StoreOrder::whereBetweenTime('add_time', $start_time, $end_time)->where('paid', 1)->where('uid', $item['uid'])->sum('pay_price');// 月结
|
|
|
- if ($item['spread_uid'] > 0 and $price > 0){
|
|
|
+ if ($item['spread_uid'] > 0 and $price > 0) {
|
|
|
$spread = getParents($item['spread_uid'], $user->toArray());// 找到所有上级
|
|
|
$v1 = 0;
|
|
|
$v2 = 0;
|
|
|
$v3 = 0;
|
|
|
- $one = sys_config('area')/100; // 区代
|
|
|
- $tow = sys_config('city')/100; // 市代
|
|
|
- $three = sys_config('partner')/100;// 合伙人
|
|
|
+ $one = sys_config('area') / 100; // 区代
|
|
|
+ $tow = sys_config('city') / 100; // 市代
|
|
|
+ $three = sys_config('partner') / 100;// 合伙人
|
|
|
foreach ($spread as $value) {
|
|
|
$details = User::where('uid', $value)->find();
|
|
|
- if ($details['level'] > 0){
|
|
|
- if ($details['level'] == 1){
|
|
|
- if ($v2 == 0 and $v3 == 0){
|
|
|
+ if ($details['level'] > 0) {
|
|
|
+ if ($details['level'] == 1) {
|
|
|
+ if ($v2 == 0 and $v3 == 0) {
|
|
|
// 没有发放市代和合伙人的奖励
|
|
|
if ($v1 == 0) { // 没有发放v1的奖励
|
|
|
$jl = $price * $one;
|
|
|
@@ -921,7 +959,7 @@ class User extends BaseModel
|
|
|
$v1++;
|
|
|
}
|
|
|
}
|
|
|
- }elseif ($details['level'] == 2) {
|
|
|
+ } elseif ($details['level'] == 2) {
|
|
|
if ($v3 == 0) {
|
|
|
// 没有发放合伙人的奖励
|
|
|
if ($v1 == 0 and $v2 == 0) { // 没有发放区代和市代的奖励的奖励
|
|
|
@@ -950,25 +988,25 @@ class User extends BaseModel
|
|
|
// $v3++;
|
|
|
// }
|
|
|
// }
|
|
|
- if ($jl > 0){
|
|
|
+ if ($jl > 0) {
|
|
|
$brokerage_price = $jl * 0.95;// 到账佣金
|
|
|
$integral = $jl * 0.05;// 到账积分
|
|
|
User::where('uid', $value)->inc('brokerage_price', $brokerage_price)->update();
|
|
|
User::where('uid', $value)->inc('integral', $integral)->update();
|
|
|
if ($details['level'] == 3) {
|
|
|
- $bl = $three;
|
|
|
+ $bl = $three;
|
|
|
if ($v2 > 0 and $v1 > 0) $bl -= $tow;
|
|
|
if ($v2 > 0 and $v1 == 0) $bl -= $tow;
|
|
|
if ($v2 == 0 and $v1 > 0) $bl -= $one;
|
|
|
|
|
|
}
|
|
|
- if ($details['level'] == 2){
|
|
|
- $bl = $tow;
|
|
|
+ if ($details['level'] == 2) {
|
|
|
+ $bl = $tow;
|
|
|
if ($v1 > 0) $bl -= $one;
|
|
|
}
|
|
|
- if ($details['level'] == 1) $bl = $one;
|
|
|
- UserBill::income('获得推广佣金', $details['uid'], 'now_money', 'brokerage', $brokerage_price, $item['uid'],$details['brokerage_price'] + $brokerage_price, '用户'.$item['uid'].'月结'.$price.'团队奖励比例'.$bl.'的95%佣金');
|
|
|
- UserBill::income('获得推广积分', $details['uid'], 'integral', 'bonus', $integral, $item['uid'],$details['integral'] + $integral, '用户'.$item['uid'].'月结'.$price.'团队奖励比例'.$bl.'的5%积分');
|
|
|
+ if ($details['level'] == 1) $bl = $one;
|
|
|
+ UserBill::income('获得推广佣金', $details['uid'], 'now_money', 'brokerage', $brokerage_price, $item['uid'], $details['brokerage_price'] + $brokerage_price, '用户' . $item['uid'] . '月结' . $price . '团队奖励比例' . $bl . '的95%佣金');
|
|
|
+ UserBill::income('获得推广积分', $details['uid'], 'integral', 'bonus', $integral, $item['uid'], $details['integral'] + $integral, '用户' . $item['uid'] . '月结' . $price . '团队奖励比例' . $bl . '的5%积分');
|
|
|
}
|
|
|
$jl = 0;
|
|
|
}
|
|
|
@@ -989,7 +1027,7 @@ class User extends BaseModel
|
|
|
public static function getkeytoid($key)
|
|
|
{
|
|
|
$rs = self::order('uid DESC')->find();
|
|
|
- return $rs['uid']+1;
|
|
|
+ return $rs['uid'] + 1;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1002,19 +1040,18 @@ class User extends BaseModel
|
|
|
public static function creation()
|
|
|
{
|
|
|
$user = User::where('level', 4)->select();
|
|
|
- if (count($user) > 0){
|
|
|
+ if (count($user) > 0) {
|
|
|
$start_time = date('Y-m-01 00:00:00', strtotime('-1 month'));
|
|
|
- $end_time = date('Y-m-d 23:59:59', strtotime(-date('d').'day'));
|
|
|
- $price = StoreOrder::whereBetweenTime('add_time',$start_time, $end_time)->where('paid', 1)->sum('pay_price');// 月结
|
|
|
- if ($price > 0){
|
|
|
- foreach ($user as $item)
|
|
|
- {
|
|
|
- $brokerage_price = ($price * sys_config('link')/100) * 0.95;// 到账佣金
|
|
|
- $integral = ($price * sys_config('link')/100) * 0.05;// 到账积分
|
|
|
+ $end_time = date('Y-m-d 23:59:59', strtotime(-date('d') . 'day'));
|
|
|
+ $price = StoreOrder::whereBetweenTime('add_time', $start_time, $end_time)->where('paid', 1)->sum('pay_price');// 月结
|
|
|
+ if ($price > 0) {
|
|
|
+ foreach ($user as $item) {
|
|
|
+ $brokerage_price = ($price * sys_config('link') / 100) * 0.95;// 到账佣金
|
|
|
+ $integral = ($price * sys_config('link') / 100) * 0.05;// 到账积分
|
|
|
User::where('uid', $item['uid'])->inc('brokerage_price', $brokerage_price)->update();
|
|
|
User::where('uid', $item['uid'])->inc('integral', $integral)->update();
|
|
|
- UserBill::income('联创分红佣金', $item['uid'], 'now_money', 'brokerage', $brokerage_price, $item['uid'],$item['brokerage_price'] + $brokerage_price, '联创分红奖励比例'.(sys_config('link')/100).'的95%佣金');
|
|
|
- UserBill::income('联创分红积分', $item['uid'], 'integral', 'creation', $integral, $item['uid'],$item['integral'] + $integral, '联创分红奖励比例'.(sys_config('link')/100).'的5%积分');
|
|
|
+ UserBill::income('联创分红佣金', $item['uid'], 'now_money', 'brokerage', $brokerage_price, $item['uid'], $item['brokerage_price'] + $brokerage_price, '联创分红奖励比例' . (sys_config('link') / 100) . '的95%佣金');
|
|
|
+ UserBill::income('联创分红积分', $item['uid'], 'integral', 'creation', $integral, $item['uid'], $item['integral'] + $integral, '联创分红奖励比例' . (sys_config('link') / 100) . '的5%积分');
|
|
|
}
|
|
|
}
|
|
|
|