<?php
/**
 * Created by PhpStorm.
 * User: z-yang
 * Date: 2018/7/17
 * Time: 11:42
 */

namespace App\Modules\Welfare\Services;

use App\Modules\Welfare\Models\WelfareBook;

class WelfareBookService
{
    public static function create($data)
    {
        return WelfareBook::createWelfareBook($data);
    }

    public static function getWelfarePromotionBooks($params, $isAll = false)
    {
        return WelfareBook::getWelfarePromotionBooks($params, $isAll);
    }


    public static function getByImportantType(bool $important)
    {
        $where = [];
        if ($important) {
            $where[] = ['is_important', '=', 1];
        } else {
            $where[] = ['is_important', '=', 0];
        }
        $where[] = ['is_enable', '=', 1];
        return WelfareBook::where($where)->select('bid', 'book_name', 'charge_rate', 'data_img', 'force_subscribe_rate')->get();
    }

    public static function updateWelfarePromotionBook($id, $params)
    {
        return WelfareBook::updateWelfarePromotionBook($id, $params);
    }

}