generated from liutk/owl-admin-base
门店地图分布
parent
64bfcf4bbb
commit
bb5afea754
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Filters\StoreFilter;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Employee;
|
||||
use App\Models\Keyword;
|
||||
|
|
@ -12,6 +13,7 @@ use App\Models\TaskPerformance;
|
|||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class CockpitController extends Controller
|
||||
|
|
@ -317,4 +319,63 @@ class CockpitController extends Controller
|
|||
'actual_performance' => trim_zeros($aggregates['actual_performance'] ?? 0),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 门店数量分布
|
||||
*/
|
||||
public function storeNumberDistribution(Request $request): array
|
||||
{
|
||||
/** @var array */
|
||||
$region = json_decode(Storage::disk('local')->get('region.json'), true);
|
||||
|
||||
/** @var \Illuminate\Support\Collection */
|
||||
$numbers = Store::select(['region'])
|
||||
->filter($request->input(), StoreFilter::class)
|
||||
->onlyOpen()
|
||||
->get()
|
||||
->groupBy(fn ($store) => $store->region['provinceCode'] ?? 'other')
|
||||
->map(fn ($stores) => $stores->count());
|
||||
|
||||
return collect($region['province'])->map(function ($province) use ($numbers) {
|
||||
return array_merge($province, [
|
||||
'stores_count' => $numbers->get($province['code'], 0),
|
||||
]);
|
||||
})->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* 门店分布
|
||||
*/
|
||||
public function storeDistribution(Request $request): array
|
||||
{
|
||||
$request->validate(
|
||||
rules: [
|
||||
'province_code' => ['required'],
|
||||
],
|
||||
);
|
||||
|
||||
$provinceCode = $request->input('province_code');
|
||||
|
||||
/** @var array */
|
||||
$region = json_decode(Storage::disk('local')->get('region.json'), true);
|
||||
|
||||
/** @var \Illuminate\Support\Collection */
|
||||
$stores = Store::filter($request->input(), StoreFilter::class)
|
||||
->onlyOpen()
|
||||
->get()
|
||||
->groupBy(fn ($store) => $store->region['cityCode'] ?? 'other');
|
||||
|
||||
return collect(data_get($region, "city.{$provinceCode}", []))->map(function ($city) use ($stores) {
|
||||
return array_merge($city, [
|
||||
'stores' => $stores->get($city['code'], collect())->map(function ($store) {
|
||||
return [
|
||||
'id' => $store->id,
|
||||
'title' => $store->title,
|
||||
'lon' => $store->lon,
|
||||
'lat' => $store->lat,
|
||||
];
|
||||
}),
|
||||
]);
|
||||
})->all();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -250,6 +250,10 @@ Route::group([
|
|||
$router->get('cockpit/lottery-sales-trend', [CockpitController::class, 'lotterySalesTrend']);
|
||||
// 门店销量排名
|
||||
$router->get('cockpit/store-sales-ranking', [CockpitController::class, 'storeSalesRanking']);
|
||||
// 门店数量分布(按省份)
|
||||
$router->get('cockpit/store-number-distribution', [CockpitController::class, 'storeNumberDistribution']);
|
||||
// 门店分布(按城市)
|
||||
$router->get('cockpit/store-distribution', [CockpitController::class, 'storeDistribution']);
|
||||
// 年度目标
|
||||
$router->get('cockpit/yearly-goals', [CockpitController::class, 'yearlyGoals']);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue