diff --git a/app/Admin/Controllers/Finance/CensusController.php b/app/Admin/Controllers/Finance/CensusController.php index a62e723..7445cac 100644 --- a/app/Admin/Controllers/Finance/CensusController.php +++ b/app/Admin/Controllers/Finance/CensusController.php @@ -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(); diff --git a/app/Merchant/Controllers/Census/IndexController.php b/app/Merchant/Controllers/Census/IndexController.php index b0039a4..3f980ec 100644 --- a/app/Merchant/Controllers/Census/IndexController.php +++ b/app/Merchant/Controllers/Census/IndexController.php @@ -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(); @@ -18,33 +20,37 @@ class IndexController extends Controller $month = explode('-', $month); $coupons = Coupon::where('user_id', $user->id) - ->whereYear('created_at', $month[0]) - ->whereMonth('created_at', $month[1]) - ->where('status', 2) - ->get(['id', 'thirdPartyGoodsId', 'created_at']); + ->whereYear('created_at', $month[0]) + ->whereMonth('created_at', $month[1]) + ->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(), + '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(), ]; + 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(); } diff --git a/app/Merchant/Controllers/Coupon/IndexController.php b/app/Merchant/Controllers/Coupon/IndexController.php index b49fbb6..38f15e5 100644 --- a/app/Merchant/Controllers/Coupon/IndexController.php +++ b/app/Merchant/Controllers/Coupon/IndexController.php @@ -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) diff --git a/app/Merchant/Exporters/CensusExport.php b/app/Merchant/Exporters/CensusExport.php index 625a920..0e76a0f 100644 --- a/app/Merchant/Exporters/CensusExport.php +++ b/app/Merchant/Exporters/CensusExport.php @@ -2,50 +2,65 @@ 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() { $coupons = Coupon::where('user_id', $this->user->id) - ->whereYear('created_at', $this->year) - ->whereMonth('created_at', $this->month) - ->where('status', 2) - ->get(['id', 'thirdPartyGoodsId', 'created_at']); + ->whereYear('created_at', $this->year) + ->whereMonth('created_at', $this->month) + ->where('status', 2) + ->get(['id', 'thirdPartyGoodsId', 'created_at']); $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, + 'day' => $key, ]; + + 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; } diff --git a/app/Merchant/Resources/views/census/index.blade.php b/app/Merchant/Resources/views/census/index.blade.php index 5f8091e..282a61a 100644 --- a/app/Merchant/Resources/views/census/index.blade.php +++ b/app/Merchant/Resources/views/census/index.blade.php @@ -3,95 +3,92 @@ @section('title', '核销统计') @section('css') - + @endsection @push('script') - - + + @endpush @section('content') -
| ID | 网点名称 | @@ -100,46 +101,46 @@核销时间 | {{--操作 | --}}||||||
|---|---|---|---|---|---|---|---|---|---|
| {{ $coupon->id }} | -{{ $coupon->outlet ? $coupon->outlet->nickname : 'Id:' . $coupon->outletId }} | - {{--{{ $coupon->partnerOrderId }} | --}} -{{ $coupon->redemptionCode }} | -{{ $coupon->couponName }} | -{{ $coupon->price }} | -{{ $coupon->status_text }} | -{{ $coupon->remark }} | -{{ $coupon->created_at }} | - {{--- 分润 - | --}} -
| {{ $coupon->id }} | +{{ $coupon->outlet ? $coupon->outlet->nickname : 'Id:' . $coupon->outletId }} | + {{--{{ $coupon->partnerOrderId }} | --}} +{{ $coupon->redemptionCode }} | +{{ $coupon->couponName }} | +{{ $coupon->price }} | +{{ $coupon->status_text }} | +{{ $coupon->remark }} | +{{ $coupon->created_at }} | + {{--+ 分润 + | --}} +