在一个类中是否可以使用两个add方法添加到两张表中?应该如何处理同时添加两张表中。

浏览:1020 发布日期:2015/01/24 分类:求助交流 关键字: 一个类两个add方法 同时添加两张表
function add(){


if(isset($_POST['dosubmit'])){
/* dump($_POST);
exit;*/




//查询当前登录用户所属门店的信息
$store_mod = D('store');
$store_info = $store_mod->field('id,store_name,store_deposit')->where("user_id=".$_SESSION['admin_info']['id'])->find();
$store_depostit =$store_info['store_deposit'];
//判断当前用户是不是管理门店的用户

if(empty($store_info)){
$this->error('您没有管理的门店');

//判断门店金额是否足够
}elseif($store_depostit<$_POST['totalmoney']){
$this->error('门店金额不足,请充值!!!');
}
$purchase_order_mod = D('purchase_order');
$oderinfo_item_mod= D('oderinfo_item');
if($purchase_order_mod->create()){

$rel = $purchase_order_mod->add();


//返回$rel中id值
if ($rel){
$id = $rel;
$sn = date('YmdHis').str_pad($id,2,'0',STR_PAD_LEFT);
$result = $purchase_order_mod->where( "id='".$id."'")->setField('sn',$sn);
// 获取数据库写入数据的主键
}else{

exit($rel->getError());
}
//得到订单详细信息参数
$data['item_id'] = $_POST['item_id'];
$data['com_name'] = $_POST['com_name'];
$data ['com_id']=$_POST['com_id'];
$data['com_specific'] =$_POST['com_specific'];
$data['com_unit'] =$_POST['com_unit'];
$data['amount'] =$_POST['amount'];
$data['sell_price'] =$_POST['sell_price'];
$data['subtotal_price'] =$_POST['subtotal_price'];
dump($data);
exit;





//合并所有小数组到一个大数组
//$purchase_number = array_merge($item_id,$com_name,$com_id,$com_specific,$com_unit,$amount,$sell_price,$subtotal_price);
$rels = $oderinfo_item_mod->add($data);
dump($rels);
exit;

/*$len=count($purchase_number);
$rows=$len/7;
for($i=0;$i<$len;$i++){
$k=$purchase_number[$i];



}*/

/* $order = array();
for($j=0;$j<$rows;$j++){*/



/*foreach($rows as &$i){
$order[$i] = $i[0];
echo $order;
exit;
unset($i[3]);

}*/

/*$order = array();
foreach($rows as &$row){
$order[] = $row[需要取得索引];
unset($row[需要删除索引]);
}*/

if(false !== $rel){

$this->success(L('operation_success'), U('PurchaseOrder/index'));

}
else{
$this->error(L('operation_failure'));

}
}
else{
$this->error($purchase_order_mod->getError());
}


}else{



$inputtime = date("y-m-d H:i:s", time());
$this->assign('inputtime',$inputtime);
$this->display();

}

}
最佳答案
评论() 相关
后面还有条评论,点击查看>>