|
@@ -296,7 +296,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($cartId);
|
|
|
+ list($realBrokeragePrice, $virtualBrokeragePrice) = StoreProduct::getProductBrokerage($userInfo['spread_uid'],$cartId);
|
|
|
//TODO 返佣金额小于等于0 直接返回不返佣金
|
|
|
if ($realBrokeragePrice <= 0 && $virtualBrokeragePrice <= 0) return true;
|
|
|
//TODO 获取上级推广员信息
|
|
@@ -316,12 +316,52 @@ class User extends BaseModel
|
|
|
}
|
|
|
if ($realBrokeragePrice > 0) {
|
|
|
$spreadUserInfo = User::getUserInfo($userInfo['spread_uid']);
|
|
|
+
|
|
|
//TODO 上级推广员返佣之后的金额
|
|
|
- $mark = $userInfo['nickname'] . '成功消费[实体产品]' . floatval($orderInfo['pay_price']) . '元,奖励推广佣金' . floatval($realBrokeragePrice);
|
|
|
+
|
|
|
//TODO 添加推广记录
|
|
|
- $res = UserBill::income('获得推广佣金', $userInfo['spread_uid'], 'now_money', 'brokerage', $realBrokeragePrice, $orderInfo['id'], $spreadUserInfo['brokerage_price'], $mark, 0);
|
|
|
+ $brokerage_price = $realBrokeragePrice * 0.95;// 到账佣金
|
|
|
+ $integral = $realBrokeragePrice * 0.05;// 到账积分
|
|
|
+
|
|
|
+ $mark = $userInfo['nickname'] . '成功消费[实体产品]' . floatval($orderInfo['pay_price']) . '元,奖励推广佣金' . floatval($brokerage_price);
|
|
|
+ $mark1 = $userInfo['nickname'] . '成功消费[实体产品]' . floatval($orderInfo['pay_price']) . '元,奖励推广积分' . floatval($integral);
|
|
|
+
|
|
|
+
|
|
|
+ $res = UserBill::income('获得推广佣金', $userInfo['spread_uid'], 'now_money', 'brokerage', $brokerage_price, $orderInfo['id'], $spreadUserInfo['brokerage_price'] + $brokerage_price, $mark, 0);
|
|
|
+ $res = UserBill::income('获得推广积分', $userInfo['spread_uid'], 'integral', 'push', $integral, $orderInfo['id'], $spreadUserInfo['integral'] + $integral, $mark1, 0);
|
|
|
+
|
|
|
+ $res2 = self::bcInc($userInfo['spread_uid'], 'brokerage_price', $brokerage_price, 'uid');
|
|
|
+ $res2 = self::bcInc($userInfo['spread_uid'], 'integral', $integral, 'uid');
|
|
|
+
|
|
|
+
|
|
|
+ $uid = getParent($userInfo['spread_uid'],User::select());
|
|
|
+ if (count($uid) >= 2){
|
|
|
+ $uid1 = array_pop($uid);
|
|
|
+ $uid2 = array_pop($uid);
|
|
|
+ $user1 = User::where('uid', $uid1)->find();
|
|
|
+ $user2 = User::where('uid', $uid2)->find();
|
|
|
+ if ($user1['identity'] == 2){
|
|
|
+ $brokerage_price = ($orderInfo['pay_price'] * sys_config('shopowner')/100 * 0.7) * 0.3 * 0.95;// 到账佣金
|
|
|
+ $integral = ($orderInfo['pay_price'] * sys_config('shopowner')/100 * 0.7) * 0.3 * 0.05;// 到账积分
|
|
|
+
|
|
|
+ UserBill::income('获得推广佣金', $uid1, 'now_money', 'brokerage', $brokerage_price, $orderInfo['id'], $user1['brokerage_price'] + $brokerage_price, '店长平级佣金奖励', 0);
|
|
|
+ UserBill::income('获得推广积分', $uid1, 'integral', 'Level', $integral, $orderInfo['id'], $user1['integral'] + $integral, '店长平级积分奖励', 0);
|
|
|
+ self::bcInc($uid1, 'brokerage_price', $brokerage_price, 'uid'); //那二代店长业绩的百分之30
|
|
|
+ self::bcInc($uid1, 'integral', $integral, 'uid'); //那二代店长业绩的百分之30
|
|
|
+ }
|
|
|
+ if ($user2['identity'] == 2){
|
|
|
+ $brokerage_price = ($orderInfo['pay_price'] * sys_config('shopowner')/100 * 0.7) * 0.95;// 到账佣金
|
|
|
+ $integral = ($orderInfo['pay_price'] * sys_config('shopowner')/100 * 0.7) * 0.05;// 到账积分
|
|
|
+
|
|
|
+
|
|
|
+ UserBill::income('获得推广佣金', $uid2, 'now_money', 'brokerage', $brokerage_price, $orderInfo['id'], $user2['brokerage_price'] + $brokerage_price, '店长平级佣金奖励', 0);
|
|
|
+ UserBill::income('获得推广积分', $uid2, 'integral', 'Level', $integral, $orderInfo['id'], $user2['brokerage_price'] + $integral, '店长平级积分奖励', 0);
|
|
|
+ self::bcInc($uid2, 'brokerage_price',$brokerage_price, 'uid'); //那二代店长业绩的百分之30
|
|
|
+ self::bcInc($uid2, 'brokerage_price', $integral, 'uid'); //那二代店长业绩的百分之30
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- $res = $res && self::backOrderBrokerageTwo($orderInfo);
|
|
|
+// $res = $res && self::backOrderBrokerageTwo($orderInfo);
|
|
|
// $open && self::checkTrans($res);
|
|
|
return $res;
|
|
|
}
|
|
@@ -346,9 +386,9 @@ class User extends BaseModel
|
|
|
if (!User::be(['uid' => $userInfoTwo['spread_uid'], 'is_promoter' => 1])) return true;
|
|
|
$cartId = is_string($orderInfo['cart_id']) ? json_decode($orderInfo['cart_id'], true) : $orderInfo['cart_id'];
|
|
|
list($realBrokeragePrice, $virtualBrokeragePrice) = StoreProduct::getProductBrokerage($cartId, false);
|
|
|
+
|
|
|
//TODO 返佣金额小于等于0 直接返回不返佣金
|
|
|
if ($realBrokeragePrice <= 0 && $virtualBrokeragePrice <= 0) return true;
|
|
|
-
|
|
|
// $open && self::beginTrans();
|
|
|
$res = true;
|
|
|
if ($virtualBrokeragePrice > 0) {
|
|
@@ -736,4 +776,168 @@ class User extends BaseModel
|
|
|
}
|
|
|
return $model->where('brokerage_price', '>', $brokerage_price)->count('uid');
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 升级店长店员
|
|
|
+ * @param $uid
|
|
|
+ * @return void
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws DbException
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ */
|
|
|
+ public static function upgrade($uid)
|
|
|
+ {
|
|
|
+ $user = User::where('uid', $uid)->find();
|
|
|
+ if ($user['identity'] == 0){
|
|
|
+ $price = StoreOrder::where('uid', $uid)->where('paid', 1)->sum('pay_price');
|
|
|
+ if ($price >= sys_config('cumulative')){
|
|
|
+ $user['identity'] = 1;
|
|
|
+ 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){
|
|
|
+ $count = User::where('spread_uid', $user['uid'])->where('identity', 1)->count();
|
|
|
+ if ($count >= sys_config('push_clerk')){
|
|
|
+ $user['identity'] = 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ $res = $user->save();
|
|
|
+ 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')){
|
|
|
+ $spd['identity'] = 2;
|
|
|
+ }
|
|
|
+ $spd->save();
|
|
|
+ }
|
|
|
+ if ($res) return true;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 团队奖励分红
|
|
|
+ * @return void
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws DbException
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ */
|
|
|
+ public static function bonus()
|
|
|
+ {
|
|
|
+
|
|
|
+ $user = User::select();
|
|
|
+ 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'));
|
|
|
+ $price = StoreOrder::whereBetweenTime('add_time', strtotime('yesterday'), strtotime('today'))->where('paid', 1)->where('uid', $item['uid'])->sum('pay_price');// 月结
|
|
|
+ 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;// 合伙人
|
|
|
+ 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 ($v1 == 0) { // 没有发放v1的奖励
|
|
|
+ $jl = $price * $one;
|
|
|
+ $details['dynamic_integral'] += $jl; // 区代团队奖励
|
|
|
+ $v1++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }elseif ($details['level'] == 2){
|
|
|
+ if ($v3 == 0){
|
|
|
+ // 没有发放合伙人的奖励
|
|
|
+ if ($v1 == 0 and $v2 == 0) { // 没有发放区代和市代的奖励的奖励
|
|
|
+ $jl = $price * $tow;// 市代团队奖励
|
|
|
+ $v2++;
|
|
|
+ }elseif ($v1 > 0 and $v2 == 0){// 发放区代奖励,没有发放市代的奖励
|
|
|
+ $jl = $price * ($tow - $one); // 市代团队奖励
|
|
|
+ $v2++;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }elseif ($details['level'] == 3){
|
|
|
+ if ($v1 == 0 and $v2 == 0 and $v3 == 0) { // 没有发放区代和市代,合伙人的奖励的奖励
|
|
|
+ $jl = $price * $three; // 合伙人团队奖励
|
|
|
+ $v3++;
|
|
|
+ }elseif ($v1 > 0 and $v2 == 0 and $v3 == 0){// 发放区代奖励,没有发放市代,合伙人的奖励
|
|
|
+ $jl = $price * ($three - $one); // 合伙人团队奖励
|
|
|
+ $v3++;
|
|
|
+ }elseif ($v1 == 0 and $v2 > 0 and $v3 == 0){// 没有发放区代奖励,发放市代的奖励,没有发放合伙人的奖励
|
|
|
+ $jl = ($price * ($three - $tow)); // 合伙人团队奖励
|
|
|
+ $v3++;
|
|
|
+ }elseif ($v1 > 0 and $v2 > 0 and $v3 == 0){// 发放区代奖励,发放市代的奖励,发放合伙人的奖励
|
|
|
+ $jl = ($price * ($three - $tow)); // 合伙人团队奖励
|
|
|
+ $v3++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ 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 ($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%积分');
|
|
|
+ }
|
|
|
+ $jl = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 联创分红
|
|
|
+ * @return void
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws DbException
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ */
|
|
|
+ public static function creation()
|
|
|
+ {
|
|
|
+ $user = User::where('level', 4)->select();
|
|
|
+ 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',strtotime('yesterday'), strtotime('today'))->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%积分');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|