<?php

namespace app\common\model;


use think\Model;

class Subcard extends Model
{

    protected $name = 'sub_card';

    /**
     * 返还卡券金额
     * @param $id
     * @param $balance
     */
    public function returnBalance($id, $balance)
    {
        $card = $this->where('id', $id)->find();
        if (empty($card)) {
            return ds_callback(false, '卡号错误');
        }
        if (($balance + $card['balance']) > $card['worth']) {
            return ds_callback(false, '退款金额不能超过使用金额');
        }

        $card->balance     += $balance;
        $card->freeze      -= $balance;
        $card->card_status = 2;
        $card->save();

        return ds_callback(true);
    }
}
