@param int $character_id
@param     $date
@param int $system_id
@param int $type_id

@return \Illuminate\Http\JsonResponse
@throws \Exception
977195
public function getDetailedLedger(int $character_id, $date, int $system_id, int $type_id): JsonResponse
    {
        if (! request()->has('all_linked_characters'))
            return abort(500);

        $character_ids = collect($character_id);

        $entries = $this->getCharacterLedger($character_ids)
            ->addSelect('time', 'quantity')
            ->where('character_minings.date', $date)
            ->where('solar_system_id', $system_id)
            ->where('character_minings.type_id', $type_id)
            ->get();

        return DataTables::of($entries)
            ->removeColumn('solar_system_id')
            ->removeColumn('date')
            ->removeColumn('type_id')
            ->removeColumn('average_price')
            ->removeColumn('type')
            ->editColumn('quantity', function ($row) {

                return view('web::partials.miningquantity', compact('row'));
            })
            ->editColumn('volume', function ($row) {

                return view('web::partials.miningvolume', compact('row'));
            })
            ->addColumn('value', function ($row) {

                $value = $row->average_price * $row->quantity;

                if(empty($value))
                    // If historical price has not been set, get historical price.
                    $value = $this->getHistoricalPrice($row->type_id, $row->date)->average_price;

                return view('web::partials.miningvalue', compact('value'));
            })
            ->rawColumns(['value', 'volume'])
            ->make(true);
    }
606384
public function getCardMemberCardDetail($begin_date, $end_date, $card_id)
    {
        $data = ['begin_date' => $begin_date, 'end_date' => $end_date, 'card_id' => $card_id];
        $url = "https://api.weixin.qq.com/datacube/getcardmembercarddetail?access_token=ACCESS_TOKEN";
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->httpPostForJson($url, $data);
    }
668541
public function pageShakeAroundStatistics($page_id, $begin_date, $end_date)
    {
        if (!$this->access_token && !$this->getAccessToken()) {
            return false;
        }
        $data = array('page_id' => $page_id, 'begin_date' => $begin_date, 'end_date' => $end_date);
        $result = Tools::httpPost(self::API_BASE_URL_PREFIX . self::SHAKEAROUND_STATISTICS_DEVICE . "access_token={$this->access_token}", Tools::json_encode($data));
        if ($result) {
            $json = json_decode($result, true);
            if (empty($json) || !empty($json['errcode'])) {
                $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
                $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容！';
                return $this->checkRetry(__FUNCTION__, func_get_args());
            }
            return $json;
        }
        return false;
    }
856668
public function getJournalGraphBalance(int $character_id)
    {

        $data = $this->getCharacterWalletJournal(collect($character_id))
            ->orderBy('date', 'desc')
            ->take(150)
            ->get();

        return response()->json([
            'labels'   => $data->map(function ($item) {

                return $item->date;
            })->toArray(),
            'datasets' => [
                [
                    'label'           => 'Balance',
                    'fill'            => false,
                    'lineTension'     => 0.1,
                    'backgroundColor' => 'rgba(60,141,188,0.9)',
                    'borderColor'     => 'rgba(60,141,188,0.8)',
                    'data'            => $data->map(function ($item) {

                        return $item->balance;
                    })->toArray(),
                ],
                [
                    'label'           => 'Amount',
                    'fill'            => false,
                    'lineTension'     => 0.1,
                    'backgroundColor' => 'rgba(210, 214, 222, 1)',
                    'borderColor'     => 'rgba(210, 214, 222, 1)',
                    'data'            => $data->map(function ($item) {

                        return $item->amount;
                    })->toArray(),
                ],
            ],
        ]);
    }
1242081
public function fileAction($id, $type)
    {
        $cm = new CronManager();
        $crons = $cm->get();
        $cron = $crons[$id];

        $data = array();
        $data['file'] =  ($type == 'log') ? $cron->getLogFile(): $cron->getErrorFile();
        $data['content'] = \file_get_contents($data['file']);

        $serializer = new Serializer(array(), array('json' => new JsonEncoder()));

        return new Response($serializer->serialize($data, 'json'));
    }
310028
function makeCalendar(char) {
    let calendar = function (id) {
        if (id === undefined) {
            return calendar.history();
        }
        else {
            return new EventImpl(char, id);
        }
    };
    calendar.history = function (fromId) {
        return char.agent.request('get_characters_character_id_calendar', {
            path: { character_id: char.id }, query: { from_event: fromId }
        }, char.ssoToken);
    };
    return calendar;
}
894754
public function getCharacterMailMessage(int $character_id, int $message_id): MailHeader
    {

        return MailHeader::where('character_id', $character_id)
            ->where('mail_id', $message_id)
            ->orderBy('timestamp', 'desc')
            ->first();
    }
583185
public function getTransactionsData(int $character_id)
    {

        if (! request()->has('all_linked_characters'))
            return abort(500);

        if (request('all_linked_characters') === 'false')
            $character_ids = collect($character_id);

        $user_group = User::find($character_id)->group->users
            ->filter(function ($user) {

                return $user->name !== 'admin' && $user->id !== 1;
            })
            ->pluck('id');

        if (request('all_linked_characters') === 'true')
            $character_ids = $user_group;

        $transactions = $this->getCharacterWalletTransactions($character_ids);

        return DataTables::of($transactions)
            ->editColumn('is_buy', function ($row) {

                return view('web::partials.transactionbuysell', compact('row'));
            })
            ->editColumn('unit_price', function ($row) {

                return number($row->unit_price);
            })
            ->addColumn('item_view', function ($row) {
                return view('web::partials.transactiontype', compact('row'));
            })
            ->addColumn('total', function ($row) {

                return number($row->unit_price * $row->quantity);
            })
            ->addColumn('client_view', function ($row) {

                $character_id = $row->character_id;

                $character = CharacterInfo::find($row->client_id) ?: $row->client_id;

                return view('web::partials.character', compact('character', 'character_id'));
            })
            ->rawColumns(['is_buy', 'client_view', 'item_view'])
            ->make(true);

    }
906318
function(oData) {
    var date = null;
    
    //Convert to date
    if(!(oData instanceof Date)) {
        date = new Date(oData);
    }
    else {
        return oData;
    }
    
    // Validate
    if(date instanceof Date) {
        return date;
    }
    else {
        YAHOO.log("Could not convert data " + lang.dump(oData) + " to type Date", "warn", this.toString());
        return null;
    }
}
1015100
public function getCompareStandingsWithProfileData(int $character_id, int $profile_id)
    {

        $journal = $this->getCharacterJournalStandingsWithProfile($character_id, $profile_id);

        return DataTables::of($journal)
            ->editColumn('characterName', function ($row) {

                return view('web::character.intel.partials.charactername', compact('row'))
                    ->render();
            })
            ->editColumn('corporationName', function ($row) {

                return view('web::character.intel.partials.corporationname', compact('row'))
                    ->render();
            })
            ->editColumn('allianceName', function ($row) {

                return view('web::character.intel.partials.alliancename', compact('row'))
                    ->render();
            })
            ->rawColumns(['characterName', 'corporationName', 'allianceName'])
            ->make(true);

    }
253903
public function getChangeCharacter(int $character_id)
    {

        $user_characters = $this->getUserGroupCharacters(
            auth()->user()->group)->pluck('id');

        // Prevent logins to arbitrary characters.
        if (! $user_characters->contains($character_id)) {

            // Log this attempt
            event('security.log', ['Character change denied ', 'authentication']);
            abort(404);
        }

        // Find the new user to login as.
        $user = User::findOrFail($character_id);

        // Log the character change login event.
        event('security.log', [
            'Character change to ' . $user->name . ' from ' . auth()->user()->name,
            'authentication',
        ]);

        auth()->login($user, true);

        return redirect()->back();
    }
1311371
public function findActionAfterDate(
        $action,
        $date,
        $doerId = null,
        $resourceId = null,
        $workspaceId = null,
        $receiverId = null,
        $roleId = null,
        $groupId = null,
        $toolName = null,
        $userType = null
    ) {
        $queryBuilder = $this
            ->createQueryBuilder('log')
            ->orderBy('log.dateLog', 'DESC')

            ->andWhere('log.action = :action')
            ->setParameter('action', $action)

            ->andWhere('log.dateLog >= :date')
            ->setParameter('date', $date);

        if (null !== $doerId) {
            $queryBuilder
                ->leftJoin('log.doer', 'doer')
                ->andWhere('doer.id = :doerId')
                ->setParameter('doerId', $doerId);
        }

        if (null !== $resourceId) {
            $queryBuilder
                ->leftJoin('log.resource', 'resource')
                ->andWhere('resource.id = :resourceId')
                ->setParameter('resourceId', $resourceId);
        }

        if (null !== $workspaceId) {
            $queryBuilder
                ->leftJoin('log.workspace', 'workspace')
                ->andWhere('workspace.id = :workspaceId')
                ->setParameter('workspaceId', $workspaceId);
        }

        if (null !== $receiverId) {
            $queryBuilder
                ->leftJoin('log.receiver', 'receiver')
                ->andWhere('receiver.id = :receiverId')
                ->setParameter('receiverId', $receiverId);
        }

        if (null !== $roleId) {
            $queryBuilder
                ->leftJoin('log.role', 'role')
                ->andWhere('role.id = :roleId')
                ->setParameter('roleId', $roleId);
        }

        if (null !== $groupId) {
            $queryBuilder
                ->leftJoin('log.receiverGroup', 'receiverGroup')
                ->andWhere('receiverGroup.id = :groupId')
                ->setParameter('groupId', $groupId);
        }

        if (null !== $toolName) {
            $queryBuilder
                ->andWhere('log.toolName = :toolName')
                ->setParameter('toolName', $toolName);
        }

        $q = $queryBuilder->getQuery();
        $logs = $q->getResult();

        return $logs;
    }
1229796
public function getIndustryData(int $character_id)
    {

        $jobs = $this->getCharacterIndustry($character_id, false);

        return DataTables::of($jobs)
            ->editColumn('installerName', function ($row) {

                return view('web::partials.industryinstaller', compact('row'))
                    ->render();
            })
            ->editColumn('facilityName', function ($row) {

                return view('web::partials.industrysystem', compact('row'))
                    ->render();
            })
            ->editColumn('blueprintTypeName', function ($row) {

                return view('web::partials.industryblueprint', compact('row'))
                    ->render();
            })
            ->editColumn('productTypeName', function ($row) {

                return view('web::partials.industryproduct', compact('row'))
                    ->render();
            })
            ->rawColumns(['installerName', 'facilityName', 'blueprintTypeName', 'productTypeName'])
            ->make(true);

    }
1076496
public function getCharacter($characterId, $fields = ['*'])
    {
        //dd(config('services.igdb.url'));
        $apiUrl = $this->getEndpoint('characters');
        $apiUrl .= $characterId;

        $params = array(
            'fields' => implode(',', $fields)
        );

        $apiData = $this->apiGet($apiUrl, $params);

        return $this->decodeSingle($apiData);
    }
1178589
protected function getMongoIdFromDate($date)
	{
		static $inc = 0;
		if ($date instanceof \DateTime) {
			$timestamp = $date->getTimestamp();
		} else if (is_int($date)) {
			$timestamp = $date;
		} else {
			$timestamp = strtotime($date);
		}
		if (empty($timestamp)) {
			return null;
		}
		$ts = pack('N', $timestamp);
		$m = substr(md5(gethostname()), 0, 3);
		$pid = pack('n', posix_getpid());
		$trail = substr(pack('N', $inc++), 1, 3);
		$bin = sprintf('%s%s%s%s', $ts, $m, $pid, $trail);
		$id = '';
		for ($i = 0; $i < 12; $i++ ) {
			$id .= sprintf('%02x', ord($bin[$i]));
		}
		return new \MongoId($id);
	}
979811
public function getCharacterContracts(Collection $character_ids) : Builder
    {

        return DB::table(DB::raw('contract_details as a'))
            ->select(DB::raw(
                '
                --
                -- All Columns
                --
                *,

                --
                -- Start Location Lookup
                --
                CASE
                when a.start_location_id BETWEEN 66015148 AND 66015151 then
                    (SELECT s.stationName FROM staStations AS s
                      WHERE s.stationID = a.start_location_id-6000000)
                when a.start_location_id BETWEEN 66000000 AND 66014933 then
                    (SELECT s.stationName FROM staStations AS s
                      WHERE s.stationID = a.start_location_id-6000001)
                when a.start_location_id BETWEEN 66014934 AND 67999999 then
                    (SELECT d.name FROM `sovereignty_structures` AS c
                      JOIN universe_stations d ON c.structure_id = d.station_id
                      WHERE c.structure_id = a.start_location_id-6000000)
                when a.start_location_id BETWEEN 60014861 AND 60014928 then
                    (SELECT d.name FROM `sovereignty_structures` AS c
                      JOIN universe_stations d ON c.structure_id = d.station_id
                      WHERE c.structure_id = a.start_location_id)
                when a.start_location_id BETWEEN 60000000 AND 61000000 then
                    (SELECT s.stationName FROM staStations AS s
                      WHERE s.stationID = a.start_location_id)
                when a.start_location_id >= 61000000 then
                    (SELECT d.name FROM `sovereignty_structures` AS c
                      JOIN universe_stations d ON c.structure_id = d.station_id
                      WHERE c.structure_id = a.start_location_id)
                else (SELECT m.itemName FROM mapDenormalize AS m
                    WHERE m.itemID = a.start_location_id) end
                AS startlocation,

                --
                -- End Location Lookup
                --
                CASE
                when a.end_location_id BETWEEN 66015148 AND 66015151 then
                    (SELECT s.stationName FROM staStations AS s
                      WHERE s.stationID = a.end_location_id-6000000)
                when a.end_location_id BETWEEN 66000000 AND 66014933 then
                    (SELECT s.stationName FROM staStations AS s
                      WHERE s.stationID = a.end_location_id-6000001)
                when a.end_location_id BETWEEN 66014934 AND 67999999 then
                    (SELECT d.name FROM `sovereignty_structures` AS c
                      JOIN universe_stations d ON c.structure_id = d.station_id
                      WHERE c.structure_id = a.end_location_id-6000000)
                when a.end_location_id BETWEEN 60014861 AND 60014928 then
                    (SELECT d.name FROM `sovereignty_structures` AS c
                      JOIN universe_stations d ON c.structure_id = d.station_id
                      WHERE c.structure_id = a.end_location_id)
                when a.end_location_id BETWEEN 60000000 AND 61000000 then
                    (SELECT s.stationName FROM staStations AS s
                      WHERE s.stationID = a.end_location_id)
                when a.end_location_id >= 61000000 then
                    (SELECT d.name FROM `sovereignty_structures` AS c
                      JOIN universe_stations d ON c.structure_id = d.station_id
                      WHERE c.structure_id = a.end_location_id)
                else (SELECT m.itemName FROM mapDenormalize AS m
                    WHERE m.itemID = a.end_location_id) end
                AS endlocation '))
            ->join('character_contracts', 'character_contracts.contract_id', '=', 'a.contract_id')
            ->whereIn('character_contracts.character_id', $character_ids->toArray());

    }
698140
public function getCharacterStandings(int $character_id): Collection
    {

        return CharacterStanding::where('character_id', $character_id)
            ->leftJoin('chrFactions', 'from_id', '=', 'factionID')
            ->orderBy('from_type')
            ->get();
    }