73 lines
2.5 KiB
PHP
73 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Models\Coupon;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class TestController
|
|
{
|
|
|
|
public function index(Request $request)
|
|
{
|
|
$date = $request->date ?? date('Y-m-d');
|
|
$time = Carbon::parse($date);
|
|
|
|
$all = Coupon::where('status', 2)
|
|
->whereBetween('created_at', [
|
|
$time->startOfDay()->toDateTimeString(),
|
|
$time->endOfDay()->toDateTimeString(),
|
|
])
|
|
->count();
|
|
$self = Coupon::where('status', 2)
|
|
->where('type', Coupon::TYPE_YSD)
|
|
->whereBetween('created_at', [
|
|
$time->startOfDay()->toDateTimeString(),
|
|
$time->endOfDay()->toDateTimeString(),
|
|
])
|
|
->count();
|
|
$pingan = Coupon::where('status', 2)
|
|
->where('type', Coupon::TYPE_PINGAN)
|
|
->whereBetween('created_at', [
|
|
$time->startOfDay()->toDateTimeString(),
|
|
$time->endOfDay()->toDateTimeString(),
|
|
])
|
|
->count();
|
|
|
|
$error = Coupon::where('status', 3)
|
|
->whereBetween('created_at', [
|
|
$time->startOfDay()->toDateTimeString(),
|
|
$time->endOfDay()->toDateTimeString(),
|
|
])
|
|
->count();
|
|
|
|
$lists = DB::table('coupons')
|
|
->where('status', 2)
|
|
->whereBetween('created_at', [
|
|
$time->startOfDay()->toDateTimeString(),
|
|
$time->endOfDay()->toDateTimeString(),
|
|
])
|
|
->select('redemptionCode', DB::raw('COUNT(*) as code_count'))
|
|
->groupBy('redemptionCode')
|
|
->having('code_count', '>', 1)
|
|
->get();
|
|
|
|
$data = [
|
|
' 日期为:' . $time->format('Y-m-d'),
|
|
' 核销总数为:' . $all,
|
|
' 自有卡券总数为:' . $self,
|
|
' 平安卡券总数为:' . $pingan,
|
|
' 核销错误总数为:' . $error,
|
|
' 核销重复数据数为:' . $lists->count(),
|
|
];
|
|
|
|
foreach ($data as $info) {
|
|
dump($info);
|
|
}
|
|
|
|
}
|
|
|
|
}
|