Thinkphp更改子集

时间:2023-03-09 00:30:40
Thinkphp更改子集
//规格编辑
public function standard(){
//$id = $_GET['id'];//dump($id);die;
$id = 388;
//根据$id 到re_goodsstandard表 查询该商家的写下的规格
$name = M('re_goodsstandard')->where(array('id'=>"{$id}", 'isValid'=>'1'))->field('id,name,adminUserId')->find();
$children = M('re_goodsstandard')->where(array('parentStandardId'=>"{$id}", 'isValid'=>'1'))->field('id,name,adminUserId')->select();
// $this->ajaxReturn($name['adminuserid']);
// $this->ajaxReturn($_POST);
if(IS_POST){
$admin_id = $_POST['admin_id'];
$sta_name = $_POST['sta_name'];
if($name['name'] !== $sta_name){
$pname['name'] = $sta_name;
$pname['createTime'] = date("Y-m-d H:i:s");
$datas = M('re_goodsstandard')->where(array('id'=>"{$admin_id}"))->save($pname);
}

$count = M('re_goodsstandard')->where(array('parentStandardId'=>"{$id}", 'isValid'=>'1','parentStandardId'=>"{$admin_id}"))->count();
$names = $_POST['name'];
$c_id = $_POST['id'];
foreach($c_id as $k=>$v){
if($v != 0){
$cname = M('re_goodsstandard')->where(array('id'=>"{$v}"))->setField('name',$names[$k]);
}else{

//新增
$data['isValid'] = '1';
$data['createTime'] = date("Y-m-d H:i:s");
$data['name'] = $names[$k];
$data['parentStandardId'] = $name['id'];
$data['adminUserId'] = $name['adminuserid'];

//$sta = M('re_goodsstandard')->add($data);
$sta = M('re_goodsstandard')->data($data)->add();
//$cname = M('re_goodsstandard')->where(array('id'=>"{$sta}"))->setField('name',$names[$k]);
}

}
$this->ajaxReturn($sta);

}

$this->assign('name', $name);
$this->assign('child', $children);
$this->assign('id', $id);
$this->display();
}