|
@@ -736,4 +736,116 @@ class User extends BaseModel
|
|
|
}
|
|
|
return $model->where('brokerage_price', '>', $brokerage_price)->count('uid');
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 团队奖励分红
|
|
|
+ * @return void
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws DbException
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ */
|
|
|
+ public static function bonus()
|
|
|
+ {
|
|
|
+ if (!Push::where('add_time', strtotime('today'))->find()) {
|
|
|
+ $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;
|
|
|
+ $v4 = 0;
|
|
|
+ $v5 = 0;
|
|
|
+ $one = sys_config('team1') / 100; // 等级1
|
|
|
+ $tow = sys_config('team2') / 100; // 等级2
|
|
|
+ $three = sys_config('team3') / 100;// 等级3
|
|
|
+ $four = sys_config('team4') / 100;// 等级4
|
|
|
+ $five = sys_config('team5') / 100;// 等级5
|
|
|
+ foreach ($spread as $value) {
|
|
|
+ $details = User::where('uid', $value)->find();
|
|
|
+ if ($details['level'] > 0) {
|
|
|
+ if ($details['level'] == 1) {
|
|
|
+ if ($v1 == 0 and $v2 == 0 and $v3 == 0 and $v4 == 0 and $v5 == 0) {
|
|
|
+ $jl = $price * $one;
|
|
|
+ $v1++;
|
|
|
+ }
|
|
|
+ } elseif ($details['level'] == 2) {
|
|
|
+ if ($v2 == 0 and $v3 == 0 and $v4 == 0 and $v5 == 0){
|
|
|
+ if ($v1 == 0) {
|
|
|
+ $jl = $price * $tow;
|
|
|
+ $v2++;
|
|
|
+ } elseif ($v1 > 0) {
|
|
|
+ $jl = $price * ($tow - $one);
|
|
|
+ $v2++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } elseif ($details['level'] == 3) {
|
|
|
+ if ($v3 == 0 and $v4 == 0 and $v5 == 0){
|
|
|
+ if ($v1 == 0 and $v2 == 0) {
|
|
|
+ $jl = $price * $three;
|
|
|
+ $v3++;
|
|
|
+ } elseif ($v1 > 0 and $v2 == 0) {
|
|
|
+ $jl = $price * ($three - $one);
|
|
|
+ $v3++;
|
|
|
+ } elseif ($v2 > 0) {
|
|
|
+ $jl = ($price * ($three - $tow));
|
|
|
+ $v3++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }elseif ($details['level'] == 4) {
|
|
|
+ if ($v4 == 0 and $v5 == 0){
|
|
|
+ if ($v1 == 0 and $v2 == 0 and $v3 == 0) {
|
|
|
+ $jl = $price * $four;
|
|
|
+ $v4++;
|
|
|
+ } elseif ($v1 > 0 and $v2 == 0 and $v3 == 0) {
|
|
|
+ $jl = $price * ($four - $one);
|
|
|
+ $v4++;
|
|
|
+ } elseif ($v2 > 0 and $v3 == 0) {
|
|
|
+ $jl = ($price * ($four - $tow));
|
|
|
+ $v4++;
|
|
|
+ }elseif ($v3 > 0){
|
|
|
+ $jl = ($price * ($four - $three));
|
|
|
+ $v4++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }elseif ($details['level'] == 5) {
|
|
|
+ if ($v5 == 0){
|
|
|
+ if ($v1 == 0 and $v2 == 0 and $v3 == 0 and $v4 == 0) {
|
|
|
+ $jl = $price * $five;
|
|
|
+ $v5++;
|
|
|
+ } elseif ($v1 > 0 and $v2 == 0 and $v3 == 0 and $v4 == 0) {
|
|
|
+ $jl = $price * ($five - $one);
|
|
|
+ $v5++;
|
|
|
+ } elseif ($v2 > 0 and $v3 == 0 and $v4 == 0) {
|
|
|
+ $jl = ($price * ($five - $tow));
|
|
|
+ $v5++;
|
|
|
+ }elseif ($v3 > 0 and $v4 == 0){
|
|
|
+ $jl = ($price * ($five - $three));
|
|
|
+ $v5++;
|
|
|
+ }elseif ($v4 > 0){
|
|
|
+ $jl = ($price * ($five - $four));
|
|
|
+ $v5++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($jl > 0) {
|
|
|
+ $brokerage_price = $jl;// 到账佣金
|
|
|
+ User::where('uid', $value)->inc('brokerage_price', $brokerage_price)->update();
|
|
|
+ UserBill::income('佣金', $details['uid'], 'now_money', 'brokerage', $brokerage_price, $item['uid'], $details['brokerage_price'] + $brokerage_price, '用户' . $item['uid'] . '消费' . $price . '团队奖励佣金');
|
|
|
+ }
|
|
|
+ $jl = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Push::create(['add_time' => strtotime('today')]); //存入数据库信息
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|