qc.ifish7.com/Application/Admin/Model/CraftModel.class.php

57 lines
1.8 KiB
PHP

<?php
namespace Admin\Model;
use Think\Model\RelationModel;
class CraftModel extends RelationModel{
protected $_link = array(
"craft_type"=>array(
'mapping_type' => self::BELONGS_TO,
'class_name' => 'craft_type',
'mapping_fields' => 'type_name',
'foreign_key' => 'type_id',
),
"who_add"=>array(
'mapping_type' => self::BELONGS_TO,
'class_name' => 'user',
'mapping_fields' => 'user_name',
'foreign_key' => 'craft_who_add',
),
"who_modify"=>array(
'mapping_type' => self::BELONGS_TO,
'class_name' => 'user',
'mapping_fields' => 'user_name',
'foreign_key' => 'craft_who_modify',
),
);
//验证
protected $_validate=array(
//array("字段","验证规则","错误提示",["验证条件","附加条件","验证时间"]),
array("craft_name","require","工艺名称不能为空"),
array("craft_code","require","工艺代码不能为空"),
array("type_id","require","工种不能为空"),
array("craft_name","","工艺名称已存在",0,"unique"),
array("craft_code","","工艺代码已存在",0,"unique"),
);
//保存信息
public function data_save(){
//创建数据
$data=$this->create();
$member_id = UID;
$data['craft_who_modify'] = $member_id;
$data['craft_time_modify'] = time();
$this->data($data)->save();
return $data['craft_id'];
}
//保存信息
public function data_add(){
//创建数据
$data=$this->create();
$member_id = UID;
$data['craft_who_add'] = $member_id;
$data['craft_time_add'] = time();
$id = $this->data($data)->add();
return $id;
}
}