更新部分的内容,同步数据
This commit is contained in:
@@ -63,7 +63,8 @@ class PdmPartlist extends AdminController
|
||||
$limit = (int)input('limit', 10);
|
||||
$where = $this->buildSelectParams();
|
||||
$fieldList = $this->model->getFields();
|
||||
$order = !array_key_exists('sort', $fieldList) ? 'id' : 'sort';
|
||||
// $order = !array_key_exists('sort', $fieldList) ? 'id' : 'sort';
|
||||
$order = 'id' ;
|
||||
|
||||
$where[] = ['pid','in',$pid];
|
||||
if (!empty($post['keyword'])) {
|
||||
@@ -77,7 +78,13 @@ class PdmPartlist extends AdminController
|
||||
}
|
||||
// throw new \Exception(json_encode($where));
|
||||
$count = $this->model->where($where)->count();
|
||||
$subQuery = $this->model->field('id')->where($where)->order($order, 'desc')->limit($limit)->page($page)->buildSql();
|
||||
$export = input('export',0);
|
||||
if($export>0){
|
||||
$subQuery = $this->model->field('id')->where($where)->order($order, 'asc')->buildSql(); // asc or desc
|
||||
}else{
|
||||
$subQuery = $this->model->field('id')->where($where)->order($order, 'asc')->limit($limit)->page($page)->buildSql();
|
||||
}
|
||||
|
||||
$subQuery = '( SELECT object.id FROM ' . $subQuery . ' AS object )';
|
||||
$list = $this->model->with($this->relationModel)->where('id in' . $subQuery)->order($order, 'asc')->select() // 如果是'desc' list_to_tree 函数返回为空!
|
||||
// $list = $this->model->where($where)->limit((int)$limit)->page((int)$page)->select()
|
||||
@@ -99,4 +106,59 @@ class PdmPartlist extends AdminController
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新数据到CIS数据表
|
||||
* @return Response
|
||||
* @throws DbException
|
||||
*/
|
||||
public function sync(): Response
|
||||
{
|
||||
//$lists = json_decode( input('data'));
|
||||
$lists = input('data');
|
||||
$bomid = input('bomid') ;
|
||||
// throw new \Exception(json_encode($lists));
|
||||
|
||||
if(!empty($bomid)){
|
||||
$status = $this->model->destroy(['pid' => $bomid]);
|
||||
if($status){
|
||||
|
||||
} else{
|
||||
return $this->error('BOM ID:'.$bomid.',删除数据失败!');
|
||||
}
|
||||
}
|
||||
|
||||
foreach( $lists as &$item){
|
||||
// 添加或修改 'pid' 键
|
||||
$item['pid'] = $bomid;
|
||||
// 检查 '备注' 键是否存在
|
||||
// if (isset($item['备注'])) {
|
||||
// // 将 '备注' 的值赋给 'content'
|
||||
// $item['content'] = $item['备注'];
|
||||
// // 移除 '备注' 键
|
||||
// unset($item['备注']);
|
||||
// } else {
|
||||
// // 可选:如果 '备注' 键不存在,可以设置一个默认值或记录日志
|
||||
// $item['content'] = ''; // 或其他默认值
|
||||
// // error_log("缺少 '备注' 字段,键值: " . $key);
|
||||
// }
|
||||
// 可选:处理 'id' 键
|
||||
if (!empty($item['id'])) {
|
||||
unset($item['id']);
|
||||
}
|
||||
}
|
||||
// throw new \Exception(json_encode($lists));
|
||||
|
||||
$status = $this->model->saveAll($lists);
|
||||
if($status){
|
||||
return $this->success('BOM ID:'.$bomid.'更新数据成功。');
|
||||
// return $this->success();
|
||||
} else{
|
||||
return $this->error('BOM ID:'.$bomid.',更新数据失败!');
|
||||
}
|
||||
|
||||
return $this->error('更新失败,请检查您的参数!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user