diff --git a/app/Merchant/Controllers/Unionpay/CouponController.php b/app/Merchant/Controllers/Unionpay/CouponController.php new file mode 100644 index 0000000..f340464 --- /dev/null +++ b/app/Merchant/Controllers/Unionpay/CouponController.php @@ -0,0 +1,147 @@ +user(); + + if ($request->start) { + $request->start = $request->start . ' 00:00:00'; + } + + if ($request->end) { + $request->end = $request->end . ' 23:59:59'; + } + + $shop_no = $request->shop_no; + $shop_name = $request->shop_name; + $coupon_no = $request->coupon_no; + $start = $request->start; + $end = $request->end; + $action = $request->action ?? 'search'; + + $coupons = UnionpayCoupon::query() + ->whereHas('outlet', function ($q) use ($shop_name, $user) { + $q->where('parent_id', $user->id) + ->when($shop_name, function ($q) use ($shop_name) { + $q->whereHas('info', function ($q) use ($shop_name) { + $q->where('nickname', 'like', "%{$shop_name}%"); + }); + }); + }) + ->when($coupon_no, function ($q) use ($coupon_no) { + $q->where('coupon_no', $coupon_no); + }) + ->when($shop_no, function ($q) use ($shop_no) { + $q->where('shop_no', $shop_no); + }) + ->when($start && $end, function ($query) use ($start, $end) { + $query->whereBetween('created_at', [$start, $end]); + }) + ->when($start && !$end, function ($query) use ($start) { + $query->where('created_at', '>', $start); + }) + ->when(!$start && $end, function ($query) use ($end) { + $query->where('created_at', '<', $end); + }) + ->latest() + ->paginate(); + + if ($action == 'search') { + return view('Merchant::unionpay.coupon', compact('coupons',)); + } else { + $this->excel($request, $user); + } + } + + //导出数据 + public function excel($request, $user) + { + if (!$request->end) { + $request->end = now()->toDateTimeString(); + } + + set_time_limit(0); + ini_set('memory_limit', '1024M'); + $filename = '银联微信券记录' . date('YmdHis') . '.csv'; + $response = function () use ($user, $request) { + $handle = fopen('php://output', 'w'); + $titles = [ + 'ID', '手机号', '门店名称', '优惠券券编号', '原始金额', '优惠的金额', '支付金额', '券码生效时间', '券码过期时间', '门店号', '状态', '核销时间', + ]; + fputcsv($handle, $titles); + + $shop_no = $request->shop_no; + $shop_name = $request->shop_name; + $coupon_no = $request->coupon_no; + $start = $request->start; + $end = $request->end; + + UnionpayCoupon::query() + ->whereHas('outlet', function ($q) use ($shop_name, $user) { + $q->where('parent_id', $user->id) + ->when($shop_name, function ($q) use ($shop_name) { + $q->whereHas('info', function ($q) use ($shop_name) { + $q->where('nickname', 'like', "%{$shop_name}%"); + }); + }); + }) + ->when($coupon_no, function ($q) use ($coupon_no) { + $q->where('coupon_no', $coupon_no); + }) + ->when($shop_no, function ($q) use ($shop_no) { + $q->where('shop_no', $shop_no); + }) + ->when($start && $end, function ($query) use ($start, $end) { + $query->whereBetween('created_at', [$start, $end]); + }) + ->when($start && !$end, function ($query) use ($start) { + $query->where('created_at', '>', $start); + }) + ->when(!$start && $end, function ($query) use ($end) { + $query->where('created_at', '<', $end); + }) + ->latest() + ->chunk(5000, function ($coupons) use ($handle) { + foreach ($coupons as $index => $coupon) { + fputcsv($handle, [ + $coupon->id, + $coupon->mobile, + $coupon->outlet ? $coupon->outlet->nickname : 'Id:' . $coupon->outletId, + $coupon->coupon_no, + $coupon->orig_amt / 100, + $coupon->discount_amt / 100, + $coupon->pay_amt / 100, + $coupon->effective_date_time, + $coupon->expire_date_time, + $coupon->shop_no, + $coupon->status_text, + $coupon->updated_at, + ]); + } + }); + fclose($handle); + }; + + response() + ->stream($response, 200, [ + 'Content-Encoding' => 'UTF-8', + 'Content-Type' => 'text/csv;charset=UTF-8', + 'Content-Disposition' => "attachment;filename=\"{$filename}\"", + ])->send(); + + exit(); + } + +} diff --git a/app/Merchant/Resources/views/common/menu.blade.php b/app/Merchant/Resources/views/common/menu.blade.php index 52d4177..166665c 100644 --- a/app/Merchant/Resources/views/common/menu.blade.php +++ b/app/Merchant/Resources/views/common/menu.blade.php @@ -7,7 +7,8 @@ +
  • + + + 银联微信券管理 + + + +
  • + diff --git a/app/Merchant/Resources/views/unionpay/coupon.blade.php b/app/Merchant/Resources/views/unionpay/coupon.blade.php new file mode 100644 index 0000000..9188d0b --- /dev/null +++ b/app/Merchant/Resources/views/unionpay/coupon.blade.php @@ -0,0 +1,128 @@ +@extends('Merchant::layouts.app') + +@section('title', '银联微信券核销列表') + +@section('css') + +@endsection + +@push('script') + + +@endpush + +@section('content') +
    +
    +
    +
    +
    +
    +
    + +
    +
    + +
    + +
    + +
    + +
    +
    + + ~ + +
    +
    + + + + + + + + + +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + @foreach ($coupons as $coupon) + + + + + + + + + + + + + + + @endforeach + +
    ID手机号门店名称优惠券券编号原始金额优惠的金额支付金额券码生效时间券码过期时间门店号状态核销时间
    {{ $coupon->id }} {{ $coupon->mobile }} {{ $coupon->outlet ? $coupon->outlet->nickname : 'Id:' . $coupon->outletId }}{{ $coupon->coupon_no }}{{ $coupon->orig_amt/100 }}{{ $coupon->discount_amt/100 }}{{ $coupon->pay_amt/100 }}{{ $coupon->effective_date_time }}{{ $coupon->expire_date_time }}{{ $coupon->shop_no }}{{ $coupon->status_text }}{{ $coupon->updated_at }}
    +
    +
    + {{ + $coupons->appends([ + 'shop_no'=>Request::input('shop_no'), + 'shop_name'=>Request::input('shop_name'), + 'coupon_no'=>Request::input('coupon_no'), + 'start'=>Request::input('start'), + 'end'=>Request::input('end'), + ])->links('Merchant::common.pagination') + }} +
    +
    +
    +@endsection diff --git a/app/Merchant/routes.php b/app/Merchant/routes.php index bcdba95..9693074 100644 --- a/app/Merchant/routes.php +++ b/app/Merchant/routes.php @@ -16,4 +16,6 @@ Route::middleware(['merchant.auth'])->group(function ($route) { $route->get('census', 'Census\IndexController@index')->name('census'); + $route->get('unionpay/coupons', 'Unionpay\CouponController@index')->name('unionpay.coupons'); + }); diff --git a/composer.lock b/composer.lock index 09bf0d5..7f9dca7 100644 --- a/composer.lock +++ b/composer.lock @@ -5802,23 +5802,17 @@ }, { "name": "xuanchen/unionpay", - "version": "3.0.3", + "version": "3.3.6", "source": { "type": "git", "url": "https://github.com/xuanchen120/unionpay.git", - "reference": "c9894107cde8d524fcabeddbcbb3a287f091ab07" + "reference": "9728794099333ea9fac1a48f43c2b8eaa9cf3ecc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/xuanchen120/unionpay/zipball/c9894107cde8d524fcabeddbcbb3a287f091ab07", - "reference": "c9894107cde8d524fcabeddbcbb3a287f091ab07", - "shasum": "", - "mirrors": [ - { - "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", - "preferred": true - } - ] + "url": "https://api.github.com/repos/xuanchen120/unionpay/zipball/9728794099333ea9fac1a48f43c2b8eaa9cf3ecc", + "reference": "9728794099333ea9fac1a48f43c2b8eaa9cf3ecc", + "shasum": "" }, "require": { "laravel/framework": "*", @@ -5851,9 +5845,9 @@ "description": "第三方银联对接", "support": { "issues": "https://github.com/xuanchen120/unionpay/issues", - "source": "https://github.com/xuanchen120/unionpay/tree/3.0.3" + "source": "https://github.com/xuanchen120/unionpay/tree/3.3.6" }, - "time": "2021-03-08T07:09:17+00:00" + "time": "2021-07-28T08:42:00+00:00" } ], "packages-dev": [ @@ -8431,5 +8425,5 @@ "php": "^7.3|^8.0" }, "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.1.0" }