feature: dump csv

This commit is contained in:
Tokumeikoi 2020-10-08 22:35:07 +08:00
parent 7a2967f41c
commit a00eca2fda
3 changed files with 17 additions and 2 deletions

View File

@ -107,7 +107,7 @@ class UserController extends Controller
]);
}
public function export(Request $request)
public function dumpCSV(Request $request)
{
$userModel = new User();
$this->filter($request, $userModel);
@ -120,6 +120,20 @@ class UserController extends Controller
}
}
}
$data = "邮箱,余额,推广佣金,总流量,剩余流量,套餐到期时间,订阅计划,订阅地址\r\n";
$baseUrl = config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL')));
foreach($res as $user) {
$expireDate = $user['expired_at'] === NULL ? '长期有效' : $user['expired_at'];
$balance = $user['balance'] / 100;
$commissionBalance = $user['commission_balance'] / 100;
$transferEnable = $user['transfer_enable'] ? $user['transfer_enable'] / 1073741824 : 0;
$notUseFlow = (($user['transfer_enable'] - ($user['u'] + $user['d'])) / 1073741824) ?? 0;
$planName = $user['plan_name'] ?? '无订阅';
$subscribeUrl = $baseUrl . '/api/v1/client/subscribe?token=' . $user['token'];
$data .= "{$user['email']},{$balance},{$commissionBalance},{$transferEnable},{$notUseFlow},{$expireDate},{$planName},{$subscribeUrl}\r\n";
}
echo $data;
}
public function generate(UserGenerate $request)

View File

@ -68,6 +68,7 @@ class AdminRoute
$router->post('/user/update', 'Admin\\UserController@update');
$router->get ('/user/getUserInfoById', 'Admin\\UserController@getUserInfoById');
$router->post('/user/generate', 'Admin\\UserController@generate');
$router->post('/user/dumpCSV', 'Admin\\UserController@dumpCSV');
// Stat
$router->get ('/stat/getOverride', 'Admin\\StatController@getOverride');
// Notice

File diff suppressed because one or more lines are too long