<?php
/**
 * Created by PhpStorm.
 * User: tandunzhao
 * Date: 2017/11/20
 * Time: 上午11:36
 */

namespace App\Http\Controllers\Manage\Finance;


use App\Http\Controllers\Manage\Finance\Transformers\CashAccountTransformer;
use App\Modules\Finance\Services\CashAccountService;
use Illuminate\Http\Request;

class CashAccountsController extends BaseController
{
    /**
     * @apiDefine Finance 结算提现模块
     */

    /**
     * @apiVersion 1.0.0
     * @apiDescription 更新银行账号可编辑
     * @api {GET} updateCashAccountEdit 更新银行账号可编辑
     * @apiGroup Finance
     * @apiName updateCashAccountEdit
     * @apiParam   {Number}  distribution_channel_id 渠道id.
     * @apiSuccess   {String}  account_name 姓名.
     * @apiSuccess   {String}  identity_card 身份证号码.
     * @apiSuccess   {String}  card_number 银行卡号码.
     * @apiSuccess   {String}  account_bank 开户支行.
     * @apiSuccess   {Number}  bank_id 银行ID.
     * @apiSuccess   {String}  bank 交易银行.
     * @apiSuccess   {String}  province 省份.
     * @apiSuccess   {Number}  status 省份.状态; -1:禁止编辑; 0:默认可编辑
     * @apiSuccess   {Number}  is_company 0:私人； 1:公司
     * @apiSuccessExample {json} Success-Response:
     *
     *     {
     *         "code": 0,
     *         "msg": "",
     *         "data":
     *              {
     *                   "account_bank": "钱江支行",
     *                   "account_name": "宋晓",
     *                   "bank_id": 1,
     *                   "bank": "杭州银行",
     *                   "card_number": "6222520177654916",
     *                   "identity_card": "33038119930901821X",
     *                   "province": "北京市",
     *                   "status": 0,
     *                   "is_company": 0,
     *                   "updated_time": "2017-11-20 14:54:50"
     *               }
     *     }
     */
    function update_cashAccountEdit(Request $request) {
        $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
        $cashAccount = CashAccountService::getCashAccountSingle($distribution_channel_id);

        if(empty($cashAccount)) {
            return response()->error("PARAM_ERROR");
        }
        $cashAccount = CashAccountService::updateCashAccountEdit($distribution_channel_id);
        return response()->item(new CashAccountTransformer(), $cashAccount);
    }
}