array( 'mapping_type' => self::BELONGS_TO, 'class_name' => 'user', 'mapping_fields' => 'user_name', 'foreign_key' => 'task_who_add', ), "who_modify"=>array( 'mapping_type' => self::BELONGS_TO, 'class_name' => 'user', 'mapping_fields' => 'user_name', 'foreign_key' => 'task_who_modify', ), "product"=>array( 'mapping_type' => self::BELONGS_TO, 'class_name' => 'product', 'mapping_fields' => 'product_type', 'foreign_key' => 'product_id', ) ); //验证 protected $_validate=array( //array("字段","验证规则","错误提示",["验证条件","附加条件","验证时间"]), array("task_name","require","任务单号不能为空"), array("task_pici","require","任务进料批次不能为空"), array("task_inner_order","require","任务内部单号不能为空"), array("product_id","require","产品型号不能为空"), array("task_name","","任务单号已存在",0,"unique"), ); //保存信息 public function data_save(){ //创建数据 $data=$this->create(); $member_id = UID; $data['task_who_modify'] = $member_id; $data['task_time_modify'] = time(); $this->data($data)->save(); return $data['task_id']; } //保存信息 public function data_add(){ //创建数据 $data=$this->create(); $member_id = UID; $data['task_who_add'] = $member_id; $data['task_time_add'] = time(); $data['status'] = 0; $id = $this->data($data)->add(); $res = $this->find($id); $product = D('product')->find($res['product_id']); $flow_craft = D('flow_craft')->where(array('flow_id'=>$product['flow_id']))->relation(true)->order('order_id')->select(); foreach ($flow_craft as $k=>$v){ $thisData = array(); $thisData['product_desc'] = $product['product_desc']; $thisData['task_time'] = $res['task_time_add']; $thisData['task_name'] = $res['task_name']; $thisData['task_inner_order'] = $res['task_inner_order']; $thisData['task_pici'] = $res['task_pici']; $thisData['task_id'] = $id; $thisData['order_id'] = $k; $thisData['is_complete'] = 0; $thisData['is_final'] = 0; $thisData['status'] = 0; if($k == count($flow_craft)-1){ $thisData['is_final'] = 1; } $thisData['pre_num'] = 0; if($k == 0){ $thisData['pre_num'] = $res['task_product_num']; } $thisData['pass_num'] = 0; $thisData['product_id'] = $product['product_id']; $thisData['product_name'] = $product['product_name']; $thisData['flow_craft_id'] = $v['flow_craft_id']; $thisData['type_name'] = $v['craft']['craft_type']['type_name']; $thisData['type_id'] = $v['craft']['type_id']; $thisData['craft_name'] = $v['craft']['craft_name']; $thisData['craft_id'] = $v['craft']['craft_id']; D('task_flow')->add($thisData); } return $id; } }