ref_date; # 新用户充值 $item->new_user_charge = Order::getChargeByDate($refDate, $refDate, $refDate) / 100; # 消耗 $item->paid_total = $item->paid_total / 100; # 新用户Roi $item->roi = $item->paid_total > 0 ? round(($item->new_user_charge / 100) / $item->paid_total, 5) * 100 . '%' : 0; # 获取需统计回收数据的月份和年份 # 获取本年度之前月份的用户回收数据 $paidAtSt = $refDate . ' 00:00:00'; $paidAtEt = $refDate . ' 23:59:59'; $recycleYear = Order::getRecycleOfYear($paidAtSt, $paidAtEt, $userCreatedAt); for($i=1; $i<=$currentMonth; $i++) { $key = 'recycle'.$i; $monthNumber = sprintf('%02d', $i); $item->$key = isset($recycleYear[$monthNumber]['recycle_total']) ? ($recycleYear[$monthNumber]['recycle_total'] / 100) : 0; $recycleTotal += $item->$key; } # 获取上一年度用户回收数据 $lastYearRecycle = Order::getRecycleLastYear($paidAtSt, $paidAtEt, $lastYearSt, $lastYearEt); $item->last_year_recycle = isset($lastYearRecycle->recycle_total) ? ($lastYearRecycle->recycle_total / 100) : 0; $recycleTotal += $item->last_year_recycle; $item->recycle_total = $recycleTotal; } if(!is_null($startDate) && !is_null($startDate)) { # 获取投放消耗汇总数据 $paidTotal = AdsReport::getPaidTotal($startDate, $endDate); # 获取新用户充值 $newUserCharge = Order::getNewUserChargeOfDate($startDate, $endDate); # roi $roi = $paidTotal > 0 ? round(($newUserCharge / 100) / $paidTotal, 5) * 100 . '%' : '-'; # 获取月用户回收 $recycleTotalData = Order::getRecycleOfYear($startDate . ' 00:00:00', $endDate . ' 23:59:59', $userCreatedAt); # 获取年度用户回收 $lastYearRecycleTotalData = Order::getRecycleLastYear($startDate . ' 00:00:00', $endDate . ' 23:59:59', $lastYearSt, $lastYearEt); $lastYearRecycleTotal = isset($lastYearRecycleTotalData->recycle_total) ? ($lastYearRecycleTotalData->recycle_total / 100) : 0; } else { $paidTotal = $newUserCharge = $roi = $lastYearRecycleTotal = 0; $recycleTotalData = array(); } $condition = [ 'paid_total' => $paidTotal / 100, 'new_user_charge_total' => $newUserCharge / 100, 'roi' => $roi, 'recycle_total_data' => $recycleTotalData, 'last_year_recycle_total' => $lastYearRecycleTotal ]; return [$list, $count, $currentMonth, $lastYear, $condition]; } }