6
0
Fork 0

代理统计

release
李静 2021-12-30 19:53:10 +08:00
parent 391cf9caee
commit 9a55583cfb
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,41 @@
<?php
namespace App\Endpoint\Api\Http\Controllers\Merchant;
use App\Endpoint\Api\Http\Controllers\Controller;
use App\Models\UserInfo;
use Illuminate\Http\Request;
class AgentStatisticController extends Controller
{
/**
* 代理统计
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function __invoke(Request $request)
{
$user = $request->user();
$statistics = UserInfo::selectRaw('count(1) as aggregate, agent_level')
->where('agent_level', '>=', 0)
->where('path', 'like', "{$user->userInfo->full_path}%")
->groupBy('agent_level')
->pluck('aggregate', 'agent_level');
$data = [];
foreach ([
UserInfo::AGENT_LEVEL_VIP => 'vip',
UserInfo::AGENT_LEVEL_COMMUNITY => 'community',
UserInfo::AGENT_LEVEL_DISTRICT => 'district',
UserInfo::AGENT_LEVEL_CITY => 'city',
UserInfo::AGENT_LEVEL_PROVINCE => 'province',
UserInfo::AGENT_LEVEL_BRANCH => 'branch',
] as $k => $v) {
$data[$v] = $statistics[$k] ?? 0;
}
return response()->json($data);
}
}

View File

@ -196,5 +196,7 @@ Route::group([
Route::get('sales-value-logs', [Merchant\SalesValueLogController::class, 'index']);
// 团队销售值日志
Route::get('team-sales-value-logs', [Merchant\TeamSalesValueLogController::class, 'index']);
// 代理统计
Route::get('agent-statistics', Merchant\AgentStatisticController::class);
});
});