<?php

namespace App\Http\Controllers\Channel\User;

use App\Http\Controllers\Channel\User\Transformers\UserSubscribeStatsTransformer;
use App\Modules\User\Services\UserSubscribeBehaviorStatsService;
use Illuminate\Http\Request;
use App\Http\Controllers\Channel\BaseController;
use Log;

class UserSubscribeStatsController extends BaseController
{

    public function getServiceAccountUsersStats(Request $request) {
        $start_date = $request->input('start_date','');
        $end_date = $request->input('end_date','');

        $appid = $request->input('appid','');
        $param = [];
        if($start_date) {
            $param['start_date']=$start_date;
            $param['end_date']=$end_date;
            $param['appid'] = $appid;
        }
        $channel_id = $this->getChannelId();
        $res = UserSubscribeBehaviorStatsService::getChannelStats($channel_id,$param);
        foreach ($res as $item) {
            $item->actual_subscribe_arpu = $item->actual_subscribe_num?round($item->recharge_sum/$item->actual_subscribe_num,2):0;
            $item->new_subscribe_arpu = $item->new_subscribe_num?round($item->recharge_sum/$item->new_subscribe_num,2):0;
        }
        return response()->pagination(new UserSubscribeStatsTransformer(),$res);
    }

    public function getChannelServiceAccount(Request $request){
        $channel_id = $this->getChannelId();
        $res = UserSubscribeBehaviorStatsService::getChannelServiceAccount($channel_id);
        return response()->success($res);
    }
}
