<?php

namespace App\Transformer\Bank;

class BankTransformer
{
    /**
     * 银行卡账号列表
     *
     * @param $param
     * @return array
     */
    public function buildCashAccounts($param): array
    {
        if (empty($param)) {
            return [];
        }

        $result = [];
        foreach ($param as $value) {
            $result[] = $this->buildCashAccountItem($value);
        }

        return $result;
    }

    /**
     * @param $data
     * @return array
     */
    private function buildCashAccountItem($data): array
    {
        return [
            'card_id'              => getProp($data, 'id'),
            'account_name'         => getProp($data, 'account_name'),
            'identity_card'        => getProp($data, 'identity_card'),
            'card_number'          => getProp($data, 'card_number'),
            'account_bank'         => getProp($data, 'account_bank'),
            'bank_id'              => (float)getProp($data, 'bank_id', 0),
            'is_company'           => (float)getProp($data, 'is_company', 0),
            'bank'                 => getProp($data, 'bank'),
            'phone'                => getProp($data, 'phone'),
            'status'               => getProp($data, 'status', 0),
            'province'             => getProp($data, 'province'),
            'remain_enable_amount' => getProp($data, 'remain_enable_amount', 0),
            'updated_time'         => date('Y-m-d H:i:s', strtotime(getProp($data, 'updated_at')))
        ];
    }
}