优化渠道核销统计
This commit is contained in:
@@ -49,7 +49,7 @@ class CensusController extends AdminController
|
||||
|
||||
$grid->model()->whereHas('identity', function ($q) {
|
||||
$q->where('identity_id', 1);
|
||||
})->where('type', 'pingan');
|
||||
});
|
||||
|
||||
$grid->disableCreateButton();
|
||||
$grid->disableBatchActions();
|
||||
|
||||
@@ -4,12 +4,14 @@ namespace App\Merchant\Controllers\Census;
|
||||
|
||||
use App\Merchant\Controllers\Controller;
|
||||
use App\Merchant\Exporters\CensusExport;
|
||||
use App\Models\ActivityRule;
|
||||
use App\Models\Coupon;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = Auth::guard('merchant')->user();
|
||||
@@ -23,28 +25,32 @@ class IndexController extends Controller
|
||||
->where('status', 2)
|
||||
->get(['id', 'thirdPartyGoodsId', 'created_at']);
|
||||
|
||||
$coupons = $coupons->groupBy('create_day')->map(function ($items, $key) {
|
||||
$rules = ActivityRule::get();
|
||||
|
||||
$coupons = $coupons->groupBy('create_day')->map(function ($items, $key) use ($rules) {
|
||||
$data = [
|
||||
'day' => $key,
|
||||
'ysd10' => $items->where('thirdPartyGoodsId', 'YSD-full100-10')->count(),
|
||||
'ysd25' => $items->where('thirdPartyGoodsId', 'YSD-full100-25')->count(),
|
||||
'ysd50' => $items->where('thirdPartyGoodsId', 'YSD-full100-50')->count(),
|
||||
'ysd100' => $items->where('thirdPartyGoodsId', 'YSD-full200-100')->count(),
|
||||
// 'ysd10' => $items->where('thirdPartyGoodsId', 'YSD-full100-10')->count(),
|
||||
// 'ysd25' => $items->where('thirdPartyGoodsId', 'YSD-full100-25')->count(),
|
||||
// 'ysd50' => $items->where('thirdPartyGoodsId', 'YSD-full100-50')->count(),
|
||||
// 'ysd100' => $items->where('thirdPartyGoodsId', 'YSD-full200-100')->count(),
|
||||
];
|
||||
foreach ($rules as $rule) {
|
||||
$data[$rule->code] = $items->where('thirdPartyGoodsId', $rule->code)->count();
|
||||
}
|
||||
|
||||
return collect($data);
|
||||
});
|
||||
|
||||
$all = [
|
||||
'ysd10' => $coupons->sum('ysd10'),
|
||||
'ysd25' => $coupons->sum('ysd25'),
|
||||
'ysd50' => $coupons->sum('ysd50'),
|
||||
'ysd100' => $coupons->sum('ysd100'),
|
||||
];
|
||||
$all = [];
|
||||
foreach ($rules as $rule) {
|
||||
$all[$rule->code] = $coupons->sum($rule->code);
|
||||
}
|
||||
|
||||
$coupons = $coupons->sortByDesc('day');
|
||||
|
||||
if ($action == 'search') {
|
||||
return view('Merchant::census.index', compact('coupons', 'all'));
|
||||
return view('Merchant::census.index', compact('coupons', 'all', 'rules'));
|
||||
} else {
|
||||
return (new CensusExport($month, $user))->download();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,14 @@ class IndexController extends Controller
|
||||
{
|
||||
$user = Auth::guard('merchant')->user();
|
||||
|
||||
if ($request->start) {
|
||||
$request->start = $request->start . ' 00:00:00';
|
||||
}
|
||||
|
||||
if ($request->end) {
|
||||
$request->end = $request->end . ' 23:59:59';
|
||||
}
|
||||
|
||||
$outlet = $request->outlet;
|
||||
$status = $request->status;
|
||||
$redemptionCode = $request->redemptionCode;
|
||||
@@ -24,14 +32,6 @@ class IndexController extends Controller
|
||||
$thirdPartyGoodsId = $request->thirdPartyGoodsId;
|
||||
$action = $request->action ?? 'search';
|
||||
|
||||
if ($start) {
|
||||
$start = $start . ' 00:00:00';
|
||||
}
|
||||
|
||||
if ($end) {
|
||||
$end = $end . ' 23:59:59';
|
||||
}
|
||||
|
||||
$coupons = Coupon::where('user_id', $user->id)
|
||||
->when($outlet, function ($q) use ($outlet) {
|
||||
$q->whereHas('outlet', function ($q) use ($outlet) {
|
||||
@@ -75,18 +75,14 @@ class IndexController extends Controller
|
||||
];
|
||||
|
||||
if ($action == 'search') {
|
||||
return view('Merchant::coupon.index', compact('coupons', 'data'));
|
||||
$rules = ActivityRule::get();
|
||||
|
||||
return view('Merchant::coupon.index', compact('coupons', 'data', 'rules'));
|
||||
|
||||
} else {
|
||||
$this->excel($request, $user);
|
||||
die();
|
||||
response()->stream($this->excel($request, $user), 200, [
|
||||
'Content-Encoding' => 'UTF-8',
|
||||
'Content-Type' => 'text/csv;charset=UTF-8',
|
||||
'Content-Disposition' => "attachment;filename=\"12346.csv\"",
|
||||
])->send();
|
||||
|
||||
return (new CouponExport($request->all(), $user))->download();
|
||||
// return (new CouponExport($request->all(), $user))->download();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,6 +138,7 @@ class IndexController extends Controller
|
||||
//获取分数据
|
||||
public function getData($request, $type, $user)
|
||||
{
|
||||
|
||||
switch ($type) {
|
||||
case 'all':
|
||||
return Coupon::where('user_id', $user->id)
|
||||
|
||||
@@ -2,32 +2,46 @@
|
||||
|
||||
namespace App\Merchant\Exporters;
|
||||
|
||||
use App\Models\ActivityRule;
|
||||
use App\Models\Coupon;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class CensusExport implements FromCollection, WithMapping, WithHeadings
|
||||
{
|
||||
|
||||
use Exportable;
|
||||
|
||||
public $year = '';
|
||||
|
||||
public $month = '';
|
||||
|
||||
public $user = '';
|
||||
|
||||
public $rules;
|
||||
|
||||
public function __construct($date, $user)
|
||||
{
|
||||
$this->year = $date[0];
|
||||
$this->month = $date[1];
|
||||
$this->user = $user;
|
||||
$this->fileName = '核销统计' . $this->year . '-' . $this->month . '.xlsx';
|
||||
$this->rules = ActivityRule::get();
|
||||
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return ['日期', '100元减10元优惠券', '100元减25元优惠券', '100元减50元优惠券', '200元减100元优惠券'];
|
||||
$titles = ['日期'];
|
||||
foreach ($this->rules as $rule) {
|
||||
$titles[] = $rule->title;
|
||||
}
|
||||
|
||||
return $titles;
|
||||
|
||||
}
|
||||
|
||||
public function collection()
|
||||
@@ -41,11 +55,12 @@ class CensusExport implements FromCollection, WithMapping, WithHeadings
|
||||
$coupons = $coupons->groupBy('create_day')->map(function ($items, $key) {
|
||||
$data = [
|
||||
'day' => $key,
|
||||
'ysd10' => $items->where('thirdPartyGoodsId', 'YSD-full100-10')->count() ?? 0,
|
||||
'ysd25' => $items->where('thirdPartyGoodsId', 'YSD-full100-25')->count() ?? 0,
|
||||
'ysd50' => $items->where('thirdPartyGoodsId', 'YSD-full100-50')->count() ?? 0,
|
||||
'ysd100' => $items->where('thirdPartyGoodsId', 'YSD-full200-100')->count() ?? 0,
|
||||
];
|
||||
|
||||
foreach ($this->rules as $rule) {
|
||||
$data[$rule->code] = $items->where('thirdPartyGoodsId', $rule->code)->count();
|
||||
}
|
||||
|
||||
return collect($data);
|
||||
});
|
||||
$coupons = $coupons->sortByDesc('day');
|
||||
@@ -56,13 +71,11 @@ class CensusExport implements FromCollection, WithMapping, WithHeadings
|
||||
|
||||
public function map($info): array
|
||||
{
|
||||
$data = [
|
||||
$info['day'],
|
||||
' ' . $info['ysd10'],
|
||||
' ' . $info['ysd25'],
|
||||
' ' . $info['ysd50'],
|
||||
' ' . $info['ysd100'],
|
||||
];
|
||||
$data = [];
|
||||
|
||||
foreach ($info as $value) {
|
||||
$data[] = '' . $value;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -59,10 +59,9 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>日期</th>
|
||||
<th>100元减10元优惠券</th>
|
||||
<th>100元减25元优惠券</th>
|
||||
<th>100元减50元优惠券</th>
|
||||
<th>200元减100元优惠券</th>
|
||||
@foreach ($rules as $rule)
|
||||
<th>{{ $rule->title }}</th>
|
||||
@endforeach
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -70,10 +69,9 @@
|
||||
@foreach ($coupons as $coupon)
|
||||
<tr>
|
||||
<td> {{ $coupon['day'] }} </td>
|
||||
<td> {{ $coupon['ysd10'] ??''}} </td>
|
||||
<td> {{ $coupon['ysd25'] ??''}} </td>
|
||||
<td> {{ $coupon['ysd50'] ??''}} </td>
|
||||
<td> {{ $coupon['ysd100']??'' }} </td>
|
||||
@foreach ($rules as $rule)
|
||||
<th>{{ $coupon[$rule->code] ??'' }}</th>
|
||||
@endforeach
|
||||
<td>
|
||||
<a href="{{ route('merchant.coupons',['start'=>$coupon['day'],'end'=>$coupon['day']]) }}">查看</a>
|
||||
</td>
|
||||
@@ -82,10 +80,9 @@
|
||||
@endforeach
|
||||
<tr style="color: #f8ac59">
|
||||
<td> 全部</td>
|
||||
<td> {{ $all['ysd10'] ??''}} </td>
|
||||
<td> {{ $all['ysd25'] ??''}} </td>
|
||||
<td> {{ $all['ysd50'] ??''}} </td>
|
||||
<td> {{ $all['ysd100']??'' }} </td>
|
||||
@foreach ($rules as $rule)
|
||||
<th>{{ $all[$rule->code] ??'' }}</th>
|
||||
@endforeach
|
||||
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@@ -52,10 +52,11 @@
|
||||
<div class="form-group">
|
||||
<select class="form-control m-b" name="thirdPartyGoodsId">
|
||||
<option value="">政策</option>
|
||||
<option value="YSD-full100-10" @if(request()->thirdPartyGoodsId=='YSD-full100-10') selected="" @endif >100减10元</option>
|
||||
<option value="YSD-full100-25" @if(request()->thirdPartyGoodsId=='YSD-full100-25') selected="" @endif >100减25元</option>
|
||||
<option value="YSD-full100-50" @if(request()->thirdPartyGoodsId=='YSD-full100-50') selected="" @endif >100减50元</option>
|
||||
<option value="YSD-full200-100" @if(request()->thirdPartyGoodsId=='YSD-full200-100') selected="" @endif >200减100元</option>
|
||||
@foreach ($rules as $rule)
|
||||
<option value="{{ $rule->code }}" @if(request()->thirdPartyGoodsId== $rule->code) selected="" @endif >
|
||||
{{ $rule->title }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user