优化渠道核销统计

This commit is contained in:
2020-09-02 11:17:12 +08:00
parent 758146a02b
commit 5397d931f7
6 changed files with 234 additions and 220 deletions

View File

@@ -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();

View File

@@ -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();
}

View File

@@ -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)

View File

@@ -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;
}

View File

@@ -3,12 +3,12 @@
@section('title', '核销统计')
@section('css')
<link rel="stylesheet" href="{{ asset('assets/merchant/css/plugins/datapicker/datepicker3.css') }}" />
<link rel="stylesheet" href="{{ asset('assets/merchant/css/plugins/datapicker/datepicker3.css') }}"/>
@endsection
@push('script')
<script type="text/javascript" src="{{ asset('assets/merchant/js/plugins/datapicker/bootstrap-datepicker.js') }}"></script>
<script type="text/javascript">
<script type="text/javascript" src="{{ asset('assets/merchant/js/plugins/datapicker/bootstrap-datepicker.js') }}"></script>
<script type="text/javascript">
$("#time-interval .input-daterange").datepicker({
autoclose: true, //自动关闭
beforeShowDay: $.noop, //在显示日期之前调用的函数
@@ -18,35 +18,35 @@
language: 'cn', //语言
minViewMode: 1, // 最小精度选择
startView: 1, //开始显示
WeekHighlighted:true, // 本周高亮
endDate:new Date()
WeekHighlighted: true, // 本周高亮
endDate: new Date()
});
$("button").click(function(){
$("button").click(function () {
var $this = $(this);
var $form = $this.parents('form');
$("input[name='action']").val($this.data('action'));
$form.submit();
});
</script>
</script>
@endpush
@section('content')
<div class="ibox">
<div class="ibox">
<div class="row">
<div class="col-sm-12 m-b">
<form action="{{ route('merchant.census')}}" class="form-inline pull-right" method="get" accept-charset="utf-8">
<div class="form-group" id="time-interval">
<div class="input-daterange input-group">
<input type="text" class="input-sm form-control" placeholder="核销月份" readonly name="month" value="{{ Request::input('month')??now()->format('Y-m') }}" />
<input type="text" class="input-sm form-control" placeholder="核销月份" readonly name="month" value="{{ Request::input('month')??now()->format('Y-m') }}"/>
</div>
</div>
<div class="input-group">
<span class="input-group-btn">
<input type="hidden" name="action" value="search">
<button type="button" class="btn btn-sm btn-primary" data-action="search" ><i class="fa fa-check"></i>&nbsp;刷新</button>
<button type="button" class="btn btn-sm btn-primary" data-action="search"><i class="fa fa-check"></i>&nbsp;刷新</button>
<button type="button" class="btn btn-sm btn-warning confirm" tip='确认要导出当前条件内容?' data-action="excel"><i class="fa fa-paste"></i>&nbsp;导出</button>
</span>
</div>
@@ -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>
@@ -93,5 +90,5 @@
</div>
</div>
</div>
</div>
@endsection

View File

@@ -3,12 +3,12 @@
@section('title', '核销列表')
@section('css')
<link rel="stylesheet" href="{{ asset('assets/merchant/css/plugins/datapicker/datepicker3.css') }}" />
<link rel="stylesheet" href="{{ asset('assets/merchant/css/plugins/datapicker/datepicker3.css') }}"/>
@endsection
@push('script')
<script type="text/javascript" src="{{ asset('assets/merchant/js/plugins/datapicker/bootstrap-datepicker.js') }}"></script>
<script type="text/javascript">
<script type="text/javascript" src="{{ asset('assets/merchant/js/plugins/datapicker/bootstrap-datepicker.js') }}"></script>
<script type="text/javascript">
$("#time-interval .input-daterange").datepicker({
keyboardNavigation: !1,
forceParse: !1,
@@ -16,18 +16,18 @@
clearBtn: true,
});
$("button").click(function(){
$("button").click(function () {
var $this = $(this);
var $form = $this.parents('form');
$("input[name='action']").val($this.data('action'));
$form.submit();
});
</script>
</script>
@endpush
@section('content')
<div class="ibox">
<div class="ibox">
<div class="ibox-content">
<div class="row">
<div class="col-sm-12 m-b">
@@ -52,24 +52,25 @@
<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>
<div class="form-group" id="time-interval">
<div class="input-daterange input-group">
<input type="text" class="input-sm form-control" placeholder="核销时间" readonly name="start" value="{{ Request::input('start') }}" />
<input type="text" class="input-sm form-control" placeholder="核销时间" readonly name="start" value="{{ Request::input('start') }}"/>
<span class="input-group-addon">~</span>
<input type="text" class="input-sm form-control" placeholder="核销时间" readonly name="end" value="{{ Request::input('end') }}" />
<input type="text" class="input-sm form-control" placeholder="核销时间" readonly name="end" value="{{ Request::input('end') }}"/>
</div>
</div>
<span class="input-group-btn">
<input type="hidden" name="action" value="search">
<button type="button" class="btn btn-sm btn-primary" data-action="search" ><i class="fa fa-check"></i>&nbsp;搜索</button>
<button type="button" class="btn btn-sm btn-primary" data-action="search"><i class="fa fa-check"></i>&nbsp;搜索</button>
<button type="button" class="btn btn-sm btn-warning confirm" tip='确认要导出当前条件内容?' data-action="excel"><i class="fa fa-paste"></i>&nbsp;导出</button>
</span>
@@ -141,5 +142,5 @@
}}
</div>
</div>
</div>
</div>
@endsection