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