2019-10-29 15:33:36 +08:00
|
|
|
<?php
|
|
|
|
|
2020-01-29 16:08:50 +08:00
|
|
|
namespace App\Http\Controllers\User;
|
2019-10-29 15:33:36 +08:00
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2022-02-07 14:37:04 +08:00
|
|
|
use App\Models\CommissionLog;
|
2020-01-29 16:08:50 +08:00
|
|
|
use Illuminate\Http\Request;
|
2019-10-29 15:33:36 +08:00
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\Order;
|
|
|
|
use App\Models\InviteCode;
|
|
|
|
use App\Utils\Helper;
|
|
|
|
|
|
|
|
class InviteController extends Controller
|
|
|
|
{
|
2020-01-11 13:36:52 +08:00
|
|
|
public function save(Request $request)
|
|
|
|
{
|
2022-07-11 14:48:35 +08:00
|
|
|
if (InviteCode::where('user_id', $request->user->id)->where('status', 0)->count() >= config('v2board.invite_gen_limit', 5)) {
|
2021-06-12 00:56:39 +08:00
|
|
|
abort(500, __('The maximum number of creations has been reached'));
|
2019-10-29 15:33:36 +08:00
|
|
|
}
|
|
|
|
$inviteCode = new InviteCode();
|
2022-07-11 14:48:35 +08:00
|
|
|
$inviteCode->user_id = $request->user->id;
|
2019-10-29 15:33:36 +08:00
|
|
|
$inviteCode->code = Helper::randomChar(8);
|
|
|
|
return response([
|
|
|
|
'data' => $inviteCode->save()
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-01-11 13:36:52 +08:00
|
|
|
public function details(Request $request)
|
|
|
|
{
|
2019-11-29 00:40:41 +08:00
|
|
|
return response([
|
2022-07-11 14:48:35 +08:00
|
|
|
'data' => CommissionLog::where('invite_user_id', $request->user->id)
|
2022-03-11 23:08:57 +08:00
|
|
|
->where('get_amount', '>', 0)
|
2019-11-29 00:40:41 +08:00
|
|
|
->select([
|
|
|
|
'id',
|
2022-02-07 14:37:04 +08:00
|
|
|
'trade_no',
|
|
|
|
'order_amount',
|
|
|
|
'get_amount',
|
|
|
|
'created_at'
|
2019-11-29 00:40:41 +08:00
|
|
|
])
|
|
|
|
->get()
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-01-11 13:36:52 +08:00
|
|
|
public function fetch(Request $request)
|
|
|
|
{
|
2022-07-11 14:48:35 +08:00
|
|
|
$codes = InviteCode::where('user_id', $request->user->id)
|
2019-10-29 15:33:36 +08:00
|
|
|
->where('status', 0)
|
|
|
|
->get();
|
2020-03-15 20:30:00 +08:00
|
|
|
$commission_rate = config('v2board.invite_commission', 10);
|
2022-07-11 14:48:35 +08:00
|
|
|
$user = User::find($request->user->id);
|
2019-11-29 00:24:35 +08:00
|
|
|
if ($user->commission_rate) {
|
|
|
|
$commission_rate = $user->commission_rate;
|
|
|
|
}
|
2019-10-29 15:33:36 +08:00
|
|
|
$stat = [
|
|
|
|
//已注册用户数
|
2022-07-11 14:48:35 +08:00
|
|
|
(int)User::where('invite_user_id', $request->user->id)->count(),
|
2019-10-29 15:33:36 +08:00
|
|
|
//有效的佣金
|
|
|
|
(int)Order::where('status', 3)
|
2020-01-30 19:57:18 +08:00
|
|
|
->where('commission_status', 2)
|
2022-07-11 14:48:35 +08:00
|
|
|
->where('invite_user_id', $request->user->id)
|
2019-10-29 15:33:36 +08:00
|
|
|
->sum('commission_balance'),
|
|
|
|
//确认中的佣金
|
|
|
|
(int)Order::where('status', 3)
|
|
|
|
->where('commission_status', 0)
|
2022-07-11 14:48:35 +08:00
|
|
|
->where('invite_user_id', $request->user->id)
|
2019-10-29 15:33:36 +08:00
|
|
|
->sum('commission_balance'),
|
2019-11-29 00:24:35 +08:00
|
|
|
//佣金比例
|
2020-01-30 16:59:52 +08:00
|
|
|
(int)$commission_rate,
|
|
|
|
//可用佣金
|
|
|
|
(int)$user->commission_balance
|
2019-10-29 15:33:36 +08:00
|
|
|
];
|
|
|
|
return response([
|
|
|
|
'data' => [
|
|
|
|
'codes' => $codes,
|
|
|
|
'stat' => $stat
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|