Initial commit
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace Admin\Model;
|
||||
use Think\Model\RelationModel;
|
||||
class FlowCraftModel extends RelationModel{
|
||||
//关联模型
|
||||
Protected $_link = array(
|
||||
//【对应副表】
|
||||
"craft"=>array(
|
||||
'mapping_type' => self::BELONGS_TO,
|
||||
'foreign_key' => 'craft_id',
|
||||
'relation_deep' => true
|
||||
),
|
||||
"flow"=>array(
|
||||
'mapping_type' => self::BELONGS_TO,
|
||||
'foreign_key' => 'flow_id',
|
||||
),
|
||||
"price"=>array(
|
||||
'mapping_type' => self::HAS_ONE,
|
||||
'class_name' => 'craft_price',
|
||||
'foreign_key' => 'flow_craft_id',
|
||||
),
|
||||
);
|
||||
|
||||
//验证
|
||||
protected $_validate=array(
|
||||
//array("字段","验证规则","错误提示",["验证条件","附加条件","验证时间"]),
|
||||
array("craft_id","require","工艺名称不能为空"),
|
||||
|
||||
);
|
||||
//保存信息
|
||||
public function data_save(){
|
||||
//创建数据
|
||||
$data=$this->create();
|
||||
$this->data($data)->save();
|
||||
return $data['flow_craft_id'];
|
||||
}
|
||||
//保存信息
|
||||
public function data_add(){
|
||||
//创建数据
|
||||
$data=$this->create();
|
||||
$craft_ids = I('craft_ids');
|
||||
$craft_arr = explode(',',$craft_ids );
|
||||
$res = array();
|
||||
foreach ($craft_arr as $k=>$v){
|
||||
$total=$this->where(array('flow_id'=>$data['flow_id']))->count();
|
||||
$data['order_id'] = ($total + 1)* 10;
|
||||
$data['craft_id'] = $v;
|
||||
$res[] = $this->add($data);
|
||||
}
|
||||
|
||||
return implode(',',$res);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user