<?php
namespace Smi\Model;

use Think\Model;

header("Content-type:text/html;charset=utf-8");
class SetFundModel extends Model
{
    /**
     * [saveForm 保存表单数据]
     * @param  [array] $data [表单数据]
     * @return [mix]       [数据库操作结果]
     */
    public function saveForm($data)
    {
        if ($data['village_percent'] < 0) alertMsg("佣金比例不能为负数");
        if ($data['group_percent'] < 0) alertMsg("佣金比例不能为负数");
        if ($data['cook_percent'] < 0) alertMsg("佣金比例不能为负数");
        if ($data['village_percent'] > 100) alertMsg("佣金比例不能超过100%");
        if ($data['group_percent'] > 100) alertMsg("佣金比例不能超过100%");
        if ($data['cook_percent'] > 100) alertMsg("佣金比例不能超过100%");
        if ($data['unlock_time'] < 0) alertMsg("解冻时间不能为负数");
        if (!$data['id']) {
            // 数据表无记录
            return $insert_id = $this->add($data);
        } else {
            // 更新当前记录
            return $boolean = $this->where("`id` = {$data['id']}")->save($data);
        }
    }
}