65 lines
2.5 KiB
PHP
65 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\UpdateWinInfosRequest;
|
|
use App\Models\InstantWin;
|
|
use App\Models\Participation;
|
|
use App\Models\Settings;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class WinnersListController extends Controller
|
|
{
|
|
/**
|
|
* Show Instant win list
|
|
*
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
|
*/
|
|
public function index()
|
|
{
|
|
$participations = Participation::whereHas('instantWin')->with('code')
|
|
->with('instantWin.prize')->with('customer')->with('codeEan')->get();
|
|
$settings = Settings::select('use_ean_codes', 'winning_proof')->first();
|
|
// * Generate code to show up in front + format date + customer info
|
|
$participations = $participations->map(function (Participation $participation) {
|
|
$participation->created = $participation->created_at->format('d/m/Y à H:i');
|
|
$participation->code->code = $participation->code->code_unique;
|
|
$participation->code->code = $participation->code->code_unique;
|
|
$participation->customer->setRawAttributes(['data' => Cache::remember(
|
|
'winnerList' . $participation->customer->id,
|
|
90,
|
|
function () use ($participation) {
|
|
/** @var \LDC\LDCCRM\Models\Customer|null $crmCustomer */
|
|
$crmCustomer = $participation->customer->apiData;
|
|
$data = [];
|
|
if ($crmCustomer) {
|
|
$countryLabel = $crmCustomer->country->label;
|
|
$data = collect($crmCustomer)->all();
|
|
$data['country'] = $countryLabel;
|
|
}
|
|
return $data;
|
|
}
|
|
)]);
|
|
return $participation;
|
|
});
|
|
return view('bo.winners-list.index', compact('participations', 'settings'));
|
|
}
|
|
|
|
/**
|
|
* Update Instant win info
|
|
*
|
|
* @param UpdateWinInfosRequest $request
|
|
* @param InstantWin $instantWin
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function updateInstantWinInfos(UpdateWinInfosRequest $request, InstantWin $instantWin)
|
|
{
|
|
$instantWin->done = $request->done;
|
|
$instantWin->comment = $request->comment;
|
|
if ($instantWin->save()) {
|
|
return response()->json();
|
|
}
|
|
return response()->json([], 500);
|
|
}
|
|
}
|