From b87f3eae9418a10e997f0cce46128903806dcb92 Mon Sep 17 00:00:00 2001 From: panx <651666084@qq.com> Date: Sat, 3 May 2025 08:52:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=83=A8=E5=88=86=E7=9A=84?= =?UTF-8?q?=E5=86=85=E5=AE=B9=EF=BC=8C=E5=90=8C=E6=AD=A5=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/PdmPartitemIndex.php | 67 +++ app/admin/controller/PdmPartitemRelation.php | 2 +- app/admin/controller/PdmPartlist.php | 66 ++- app/admin/controller/PdmPurchasecode.php | 29 ++ app/admin/model/PdmPartlist.php | 2 +- app/admin/view/pdm_partitem_relation/add.html | 2 +- .../view/pdm_partitem_relation/index.html | 4 +- app/admin/view/pdm_partlist/index.html | 467 ++++++++++++++++-- app/admin/view/pdm_purchasecode/add.html | 6 +- app/admin/view/pdm_purchasecode/index.html | 49 +- 10 files changed, 652 insertions(+), 42 deletions(-) diff --git a/app/admin/controller/PdmPartitemIndex.php b/app/admin/controller/PdmPartitemIndex.php index 1df3b0f..6c6e4eb 100644 --- a/app/admin/controller/PdmPartitemIndex.php +++ b/app/admin/controller/PdmPartitemIndex.php @@ -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]; + } /** diff --git a/app/admin/controller/PdmPartitemRelation.php b/app/admin/controller/PdmPartitemRelation.php index 29870da..8b0991e 100644 --- a/app/admin/controller/PdmPartitemRelation.php +++ b/app/admin/controller/PdmPartitemRelation.php @@ -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()) { diff --git a/app/admin/controller/PdmPartlist.php b/app/admin/controller/PdmPartlist.php index 3343bda..f9b9e30 100644 --- a/app/admin/controller/PdmPartlist.php +++ b/app/admin/controller/PdmPartlist.php @@ -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('更新失败,请检查您的参数!'); + } + + + } diff --git a/app/admin/controller/PdmPurchasecode.php b/app/admin/controller/PdmPurchasecode.php index 36b369e..8ec9bce 100644 --- a/app/admin/controller/PdmPurchasecode.php +++ b/app/admin/controller/PdmPurchasecode.php @@ -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(); + } + + } diff --git a/app/admin/model/PdmPartlist.php b/app/admin/model/PdmPartlist.php index ee085a9..1a91220 100644 --- a/app/admin/model/PdmPartlist.php +++ b/app/admin/model/PdmPartlist.php @@ -40,7 +40,7 @@ class PdmPartlist extends Model */ public function partitemview() { - return $this->hasOne(\app\admin\model\PdmPartitemView::Class,'partnumber','partnumber')->bind(['purchasecode','parttype','value','description','mpn','mfgname','footprint','manufacture']); + return $this->hasOne(\app\admin\model\PdmPartitemView::Class,'partnumber','partnumber')->bind(['purchasecode','parttype','value','description','mpn','mfg','footprint','manufacture']); } // 字段修改器 diff --git a/app/admin/view/pdm_partitem_relation/add.html b/app/admin/view/pdm_partitem_relation/add.html index 07a74b9..9cca9a3 100644 --- a/app/admin/view/pdm_partitem_relation/add.html +++ b/app/admin/view/pdm_partitem_relation/add.html @@ -20,7 +20,7 @@ -->