更新部分的内容,同步数据
This commit is contained in:
@@ -146,6 +146,73 @@ class PdmPartitemIndex extends AdminController
|
||||
}
|
||||
return [$count, $list];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取资源列表
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public static function dataListAll(array $params): array
|
||||
{
|
||||
$controller = new PdmPartitemIndex();
|
||||
|
||||
$where = $controller->buildSelectParams();
|
||||
$count = $controller->model->where($where)->count();
|
||||
$fieldList = $controller->model->getFields();
|
||||
$order = !array_key_exists('sort', $fieldList) ? 'id' : 'sort';
|
||||
$subQuery = $controller->model->field('id')->where($where)->order($order, 'desc')->buildSql();
|
||||
$subQuery = '( SELECT object.id FROM ' . $subQuery . ' AS object )';
|
||||
// $list = $this->model->with($this->relationModel)->where('id in' . $subQuery)->order($order, 'asc')->select()->toArray(); // 如果是'desc' list_to_tree 函数返回为空!
|
||||
$list = $controller->model->with($controller->relationModel)->where('id in' . $subQuery)->order($order, 'asc')->select(); // 如果是'desc' list_to_tree 函数返回为空!
|
||||
|
||||
foreach($list as $key => $value){
|
||||
// throw new \Exception(json_encode($value));
|
||||
// throw new \Exception(json_encode($list[$key]->admin['nickname']));
|
||||
$list[$key]['creator'] =__($list[$key]->admin == null?'': $list[$key]->admin['nickname']);
|
||||
$list[$key]['parttype'] =__($list[$key]->pdmParttype ==null?'': $list[$key]->pdmParttype['name']);
|
||||
$list[$key]['mfg_name'] =__($list[$key]->pdmMfgName == null ?'': $list[$key]->pdmMfgName['mfgname']);
|
||||
$list[$key]['mpn'] =__($list[$key]->pdmPurchasecode == null ?'': $list[$key]->pdmPurchasecode['mpn']);
|
||||
|
||||
// if($list[$key]->mfgname == null){
|
||||
// $list[$key]['mfg_name'] ='';
|
||||
// }else{
|
||||
// $list[$key]['mfg_name'] =$list[$key]->mfgname['mfgname'];
|
||||
// }
|
||||
}
|
||||
|
||||
$list = $list->toArray();
|
||||
if(!empty($list) && is_array($list)){
|
||||
$nodeid = array();
|
||||
foreach($list as $key => $value){
|
||||
if($value['pid'] == 0 ){
|
||||
$nodeid[] = $value['id'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach($list as $key => $value){
|
||||
if(!in_array($value['pid'],$nodeid) && $value['pid'] > 0){
|
||||
$nodeid[] = $value['pid'];
|
||||
$nodevalue = $controller->model->find($value['pid']);
|
||||
$nodevalue = $controller->model->find($value['pid'])->toArray();
|
||||
|
||||
if(!empty($nodevalue)){
|
||||
$list[] = &$nodevalue;
|
||||
}
|
||||
}
|
||||
}
|
||||
$list = list_sort_by($list,'id','asc');
|
||||
// usort($list, function($a, $b) {
|
||||
// return $a['id'] <=> $b['id']; // 对 'id' 进行升序排序
|
||||
// });
|
||||
// throw new \Exception(json_encode($list));
|
||||
}
|
||||
return [$count, $list];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -212,7 +212,7 @@ class PdmPartitemRelation extends AdminController
|
||||
$where = ['partnumber' => $partnumbertemp];
|
||||
// $partnumbertemp1 = PdmPartitemIndexModel::find($partnumbertemp)->toArray();
|
||||
$partnumbertemp1 = PdmPartitemIndexModel::where($where)->select()->toArray();
|
||||
list($countpartnumberIndex, $partitemIndex) = \app\admin\controller\PdmPartitemIndex::dataList($partnumbertemp1);
|
||||
list($countpartnumberIndex, $partitemIndex) = \app\admin\controller\PdmPartitemIndex::dataListAll($partnumbertemp1);
|
||||
|
||||
|
||||
if (request()->isPost()) {
|
||||
|
||||
@@ -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('更新失败,请检查您的参数!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -77,4 +77,33 @@ class PdmPurchasecode extends AdminController
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改资源状态 -EOL
|
||||
* @return Response|void
|
||||
*/
|
||||
public function statusEol()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
|
||||
$where[] = ['id', '=', input('id')];
|
||||
if (!$this->authService->SuperAdmin() && $this->dataLimit
|
||||
&& in_array($this->dataLimitField, $this->model->getFields())) {
|
||||
$where[] = [$this->dataLimitField, '=', get_admin_id()];
|
||||
}
|
||||
|
||||
try {
|
||||
$this->status = $this->model->where($where)->update(['eol' => input('eol')]);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->error($th->getMessage());
|
||||
}
|
||||
|
||||
if ($this->status) {
|
||||
return $this->success();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->error();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user