diff --git a/app/admin/controller/PdmFootprint.php b/app/admin/controller/PdmFootprint.php index b9ca5ea..f021422 100644 --- a/app/admin/controller/PdmFootprint.php +++ b/app/admin/controller/PdmFootprint.php @@ -58,7 +58,7 @@ class PdmFootprint extends AdminController * @throws DbException * @throws ModelNotFoundException */ - public function dataList(array $params): array + public static function dataList(array $params): array { // $where = array(); // if (!empty($params['footprint'])) { @@ -80,14 +80,16 @@ class PdmFootprint extends AdminController // return [$count, $list->toArray()]; - $where = $this->buildSelectParams(); - $count = $this->model->where($where)->count(); - $fieldList = $this->model->getFields(); + $controller = new PdmFootprint(); + + $where = $controller->buildSelectParams(); + $count = $controller->model->where($where)->count(); + $fieldList = $controller->model->getFields(); $order = !array_key_exists('sort', $fieldList) ? 'id' : 'sort'; - $subQuery = $this->model->field('id')->where($where)->order($order, 'asc')->buildSql(); + $subQuery = $controller->model->field('id')->where($where)->order($order, 'asc')->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 = $this->model->with($this->relationModel)->where('id in' . $subQuery)->order($order, 'asc')->select(); // 如果是'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)); @@ -107,8 +109,8 @@ class PdmFootprint extends AdminController foreach($list as $key => $value){ if(!in_array($value['pid'],$nodeid) && $value['pid'] > 0){ $nodeid[] = $value['pid']; - $nodevalue = $this->model->find($value['pid']); - $nodevalue = $this->model->find($value['pid'])->toArray(); + $nodevalue = $controller->model->find($value['pid']); + $nodevalue = $controller->model->find($value['pid'])->toArray(); if(!empty($nodevalue)){ $list[] = &$nodevalue; diff --git a/app/admin/controller/PdmPartitemRelation.php b/app/admin/controller/PdmPartitemRelation.php index 21340f9..70740e2 100644 --- a/app/admin/controller/PdmPartitemRelation.php +++ b/app/admin/controller/PdmPartitemRelation.php @@ -5,6 +5,8 @@ namespace app\admin\controller; use app\AdminController; use Webman\Http\Request; use app\admin\model\PdmPartitemRelation as PdmPartitemRelationModel; +use app\admin\model\PdmSymbol as PdmSymbolModel; +use app\admin\model\PdmFootprint as PdmFootprintModel; use support\Response; /** @@ -93,7 +95,7 @@ class PdmPartitemRelation extends AdminController $subQuery = $this->model->field('id')->where($where)->order($order, 'desc')->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()->toArray(); // 如果是'desc' list_to_tree 函数返回为空! - $list = $this->model->with($this->relationModel)->where('id in' . $subQuery)->order($order, 'asc')->select(); // 如果是'desc' list_to_tree 函数返回为空! + $list = $this->model->with($this->relationModel)->where('id in' . $subQuery)->order($order, 'desc')->select(); // 如果是'desc' list_to_tree 函数返回为空! foreach($list as $key => $value){ // throw new \Exception(json_encode($value)); @@ -134,7 +136,7 @@ class PdmPartitemRelation extends AdminController } } } - $list = list_sort_by($list,'id','asc'); + // $list = list_sort_by($list,'id','asc'); // usort($list, function($a, $b) { // return $a['id'] <=> $b['id']; // 对 'id' 进行升序排序 // }); @@ -144,5 +146,264 @@ class PdmPartitemRelation extends AdminController } + /** + * 添加节点数据 + * @return Response + */ + public function add(): Response + { + $symbol = PdmSymbolModel::select()->toArray(); + $footprint = PdmFootprintModel::select()->toArray(); + + if (request()->isPost()) { + $post = \request()->post(); + // validate(\app\common\validate\system\AdminRules::class . '.add')->check($post); + $userid = get_admin_id(); + $admin_info = get_admin_info(); + // throw new \Exception(json_encode($admin_info)); + $post['creatorid'] = $userid ; + $post['departmentid'] = $admin_info['department_id'] ; + + if ($this->model->create($post)) { + return $this->success('添加数据关系成功!'); + } + } + + $data = $this->getTableFields(); + $data['pid'] = input('pid', 0); + // $data['auth'] = 1; + // $data['type'] = 1; + + list($count, $list) = PdmPartitemRelation::dataList(request()->all()); + return view('/pdm_partitem_relation/add', [ + 'data' => $data, + 'symbol' => json_encode( list_to_tree($symbol), JSON_UNESCAPED_UNICODE), + 'footprint' => json_encode( list_to_tree($footprint), JSON_UNESCAPED_UNICODE), + // 'parttype' => $this->parttype, + 'list' => json_encode( list_to_tree($list), JSON_UNESCAPED_UNICODE), + ]); + } + + /** + * 编辑节点数据 + * @return Response + * @throws DbException + * @throws DataNotFoundException + * @throws ModelNotFoundException + */ + public function edit(): Response + { + $id = input('id', 0); + $data = $this->model->find($id); + // $parttypeid = $data['parttypeid']; + + $symbolid = $data['symbolid']; + $footprintid = $data['footprintid']; + + // $parems['id'] = input('parttypeid', 0); + $symbol = PdmSymbolModel::find($symbolid)->toArray(); + list($countsymbol, $symbol) = \app\admin\controller\PdmSymbol::dataList($symbol); + $footprint = PdmFootprintModel::find($footprintid)->toArray(); + list($countfootprint, $footprint) = \app\admin\controller\PdmFootprint::dataList($footprint); + + if (request()->isPost()) { + $post = \request()->post(); + // validate(\app\common\validate\system\AdminRules::class . '.edit')->check($post); + if ($this->model->update($post)) { + return $this->success('更新数据关系成功!'); + } + } + + list($count, $list) = PdmPartitemRelation::dataList(request()->all()); + // throw new \Exception(json_encode($parttype)); + // throw new \Exception( json_encode(list_to_tree($parttype))); + return view('/pdm_partitem_relation/add', [ + 'data' => $data, + 'symbol' => json_encode( list_to_tree($symbol), JSON_UNESCAPED_UNICODE), + 'footprint' => json_encode( list_to_tree($footprint), JSON_UNESCAPED_UNICODE), + // 'parttype' => json_encode( $parttype, JSON_UNESCAPED_UNICODE), + 'list' => json_encode( list_to_tree($list), JSON_UNESCAPED_UNICODE), + ]); + } + + + /** + * 更新数据到CIS数据表 + * @return Response + * @throws DbException + */ + public function updata(): Response + { + $id = input('id'); + if (!empty($id)) { + + $data = $this->model->find($id); + $department = $data->department; + $pdmPartitemIndex = $data->pdmPartitemIndex; + // $departmentid = $department['id']; + $partnumber = $pdmPartitemIndex['partnumber']; + $partnumber = $pdmPartitemIndex['partnumber']; + // $parttypeid = $pdmPartitemIndex['parttypeid']; + + $tablesuffix1= $department['suffix']; + + // return $this->success($tablesuffix1."_"); + + $pdmParttype = $pdmPartitemIndex->pdmParttype; + if($pdmParttype['pid']!=0){ + $pdmParttype1 = \app\admin\model\PdmParttype::find($pdmParttype['pid']); + $tablesuffix2= $pdmParttype1['suffix']; + }else{ + $tablesuffix2= $pdmParttype['suffix']; + } + + // $table = "pdm_partitem"; + $suffix = '_'.$tablesuffix1."_".$tablesuffix2; + + $partitem = \app\admin\model\PdmPartitem::suffix($suffix)->where(['partnumber' => $partnumber])->select()->toArray(); + $partitem_view = \app\admin\model\PdmPartitemView::where(['partnumber' => $partnumber])->select()->toArray(); + // throw new \Exception(json_encode(count($partitem))); + if(count($partitem_view)==1){ + if(count($partitem)<1){ + unset($partitem_view[0]['id']); + }else if(count($partitem)==1){ + $partitem_view[0]['id'] = $partitem[0]['id']; + }else { + + $status = \app\admin\model\PdmPartitem::suffix($suffix)->where(['partnumber' => $partnumber])->delete(); + if($status){ + // throw new \Exception(json_encode(count($partitem))."删除数据成功。"); + }else{ + // throw new \Exception(json_encode(count($partitem))."删除数据失败!"); + return $this->error('有'.count($partitem).'个数据:'.$partnumber.',删除数据失败!'); + } + unset($partitem_view[0]['id']); + } + $status = \app\admin\model\PdmPartitem::suffix($suffix)->saveAll($partitem_view); + } + + + // if(!empty($partitem)){ + + // $status = \app\admin\model\PdmPartitem::suffix($suffix)->update($partitem_view[0]); + // }else{ + // $status = \app\admin\model\PdmPartitem::suffix($suffix)->create($partitem_view[0]); + // } + + if($status){ + return $this->success('更新数据成功。'. \app\admin\model\PdmPartitem::suffix($suffix)->getTable()); + }else { + return $this->error('更新数据失败!'); + } + // // 查询子节点 + // if ($this->model->where('pid',$id)->count()) { + // return $this->error('当前分类存在子项!'); + // } + + // // 删除单个 + // if ($this->model::destroy($id)) { + // return $this->success('删除FootPrint成功!'); + // } + } + + return $this->error('更新失败,请检查您的参数!'); + } + + + /** + * 更新数据到CIS数据表 + * @return Response + * @throws DbException + */ + public function updataAll(): Response + { + + // $where = $this->buildSelectParams(); + $where = []; + $lists = \app\admin\model\PdmPartitemRelation::where($where)->select(); + foreach( $lists as $key => $value){ + $id = $value['id'] ; + if (!empty($id)) { + + $data = $this->model->find($id); + $department = $data->department; + $pdmPartitemIndex = $data->pdmPartitemIndex; + // $departmentid = $department['id']; + $partnumber = $pdmPartitemIndex['partnumber']; + $partnumber = $pdmPartitemIndex['partnumber']; + // $parttypeid = $pdmPartitemIndex['parttypeid']; + + $tablesuffix1= $department['suffix']; + + // return $this->success($tablesuffix1."_"); + + $pdmParttype = $pdmPartitemIndex->pdmParttype; + if($pdmParttype['pid']!=0){ + $pdmParttype1 = \app\admin\model\PdmParttype::find($pdmParttype['pid']); + $tablesuffix2= $pdmParttype1['suffix']; + }else{ + $tablesuffix2= $pdmParttype['suffix']; + } + + // $table = "pdm_partitem"; + $suffix = '_'.$tablesuffix1."_".$tablesuffix2; + + $partitem = \app\admin\model\PdmPartitem::suffix($suffix)->where(['partnumber' => $partnumber])->select()->toArray(); + $partitem_view = \app\admin\model\PdmPartitemView::where(['partnumber' => $partnumber])->select()->toArray(); + // throw new \Exception(json_encode(count($partitem))); + if(count($partitem_view)==1){ + if(count($partitem)<1){ + unset($partitem_view[0]['id']); + }else if(count($partitem)==1){ + $partitem_view[0]['id'] = $partitem[0]['id']; + }else { + + $status = \app\admin\model\PdmPartitem::suffix($suffix)->where(['partnumber' => $partnumber])->delete(); + if($status){ + // throw new \Exception(json_encode(count($partitem))."删除数据成功。"); + }else{ + // throw new \Exception(json_encode(count($partitem))."删除数据失败!"); + return $this->error('有'.count($partitem).'个数据:'.$partnumber.',删除数据失败!'); + } + unset($partitem_view[0]['id']); + } + $status = \app\admin\model\PdmPartitem::suffix($suffix)->saveAll($partitem_view); + } + + + // if(!empty($partitem)){ + + // $status = \app\admin\model\PdmPartitem::suffix($suffix)->update($partitem_view[0]); + // }else{ + // $status = \app\admin\model\PdmPartitem::suffix($suffix)->create($partitem_view[0]); + // } + + if($status){ + // return $this->success('更新数据成功。'. \app\admin\model\PdmPartitem::suffix($suffix)->getTable()); + }else { + return $this->error('更新数据失败!'); + } + } + + + // // 查询子节点 + // if ($this->model->where('pid',$id)->count()) { + // return $this->error('当前分类存在子项!'); + // } + + // // 删除单个 + // if ($this->model::destroy($id)) { + // return $this->success('删除FootPrint成功!'); + // } + } + if($status){ + return $this->success('更新数据成功。'. \app\admin\model\PdmPartitem::suffix($suffix)->getTable()); + }else { + return $this->error('更新数据失败!'); + } + + return $this->error('更新失败,请检查您的参数!'); + } + } diff --git a/app/admin/controller/PdmPartitemView.php b/app/admin/controller/PdmPartitemView.php index 0d53215..f4711f8 100644 --- a/app/admin/controller/PdmPartitemView.php +++ b/app/admin/controller/PdmPartitemView.php @@ -67,7 +67,7 @@ class PdmPartitemView extends AdminController $subQuery = '( SELECT object.id FROM ' . $subQuery . ' AS object )'; // $list = $this->model->where($where)->limit((int)$limit)->page((int)$page)->select(); - $list = $this->model->with($this->relationModel)->where('id in' . $subQuery)->order($order, 'asc')->select() ; + $list = $this->model->with($this->relationModel)->where('id in' . $subQuery)->order($order, 'desc')->select() ; // $list = $this->model->where($where)->limit((int)$limit)->page((int)$page)->select(); return $this->success('查询成功', null, $list, $count); diff --git a/app/admin/controller/PdmPurchasecode.php b/app/admin/controller/PdmPurchasecode.php index e4a2827..36b369e 100644 --- a/app/admin/controller/PdmPurchasecode.php +++ b/app/admin/controller/PdmPurchasecode.php @@ -66,7 +66,7 @@ class PdmPurchasecode extends AdminController $subQuery = '( SELECT object.id FROM ' . $subQuery . ' AS object )'; // $list = $this->model->where($where)->limit((int)$limit)->page((int)$page)->select(); - $list = $this->model->with($this->relationModel)->where('id in' . $subQuery)->order($order, 'asc')->select() ; + $list = $this->model->with($this->relationModel)->where('id in' . $subQuery)->order($order, 'desc')->select() ; // $list = $this->model->where($where)->limit((int)$limit)->page((int)$page)->select(); return $this->success('查询成功', null, $list, $count); diff --git a/app/admin/controller/PdmSymbol.php b/app/admin/controller/PdmSymbol.php index c6c338c..10f315d 100644 --- a/app/admin/controller/PdmSymbol.php +++ b/app/admin/controller/PdmSymbol.php @@ -58,7 +58,7 @@ class PdmSymbol extends AdminController * @throws DbException * @throws ModelNotFoundException */ - public function dataList(array $params): array // static 限定后, $this-> 不可用。 + public static function dataList(array $params): array // static 限定后, $this-> 不可用。 { // $where = array(); // if (!empty($params['status'])) { @@ -71,14 +71,16 @@ class PdmSymbol extends AdminController // $count = $this->model->where($where)->count(); // $list = $this->model->where($where)->order('sort asc')->select()->toArray(); - $where = $this->buildSelectParams(); - $count = $this->model->where($where)->count(); - $fieldList = $this->model->getFields(); + $controller = new PdmSymbol(); + + $where = $controller->buildSelectParams(); + $count = $controller->model->where($where)->count(); + $fieldList = $controller->model->getFields(); $order = !array_key_exists('sort', $fieldList) ? 'id' : 'sort'; - $subQuery = $this->model->field('id')->where($where)->order($order, 'asc')->buildSql(); + $subQuery = $controller->model->field('id')->where($where)->order($order, 'asc')->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 = $this->model->with($this->relationModel)->where('id in' . $subQuery)->order($order, 'asc')->select(); // 如果是'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)); @@ -98,9 +100,9 @@ class PdmSymbol extends AdminController foreach($list as $key => $value){ if(!in_array($value['pid'],$nodeid) && $value['pid'] > 0){ $nodeid[] = $value['pid']; - $nodevalue = $this->model->find($value['pid']); + $nodevalue = $controller->model->find($value['pid']); // throw new \Exception(json_encode($nodevalue)); - $nodevalue = $this->model->find($value['pid'])->toArray(); + $nodevalue = $controller->model->find($value['pid'])->toArray(); // throw new \Exception(json_encode($nodevalue)); // throw new \Exception(json_encode($list)); if(!empty($nodevalue)){ diff --git a/app/admin/model/PdmPartitem.php b/app/admin/model/PdmPartitem.php new file mode 100644 index 0000000..55cf483 --- /dev/null +++ b/app/admin/model/PdmPartitem.php @@ -0,0 +1,90 @@ + + * Partnumber管理 + * Class PdmPartitemIndex + * @package app\admin\model + */ +class PdmPartitem extends Model +{ + + // use SoftDelete; + + // 定义时间戳字段名 + protected $createTime = 'create_time'; + protected $updateTime = 'update_time'; + protected $deleteTime = 'delete_time'; + + + // /** + // * 定义 sa_admin 关联模型 + // * @localKey creatorid + // * @bind nickname,name + // */ + // public function admin() + // { + // return $this->hasOne(\app\common\model\system\Admin::Class,'id','creatorid')->bind(['nickname','name']); + // } + + + // /** + // * 定义 sa_admin 关联模型 + // * @localKey parttypeid + // * @bind name + // */ + // public function pdmParttype() + // { + // return $this->hasOne(\app\admin\model\PdmParttype::Class,'id','parttypeid')->bind(['name']); + // } + + // /** + // * 定义 sa_admin 关联模型 + // * @localKey parttypeid + // * @bind name + // */ + // public function pdmMfgName() + // { + // return $this->hasOne(\app\admin\model\PdmMfgName::Class,'id','mfg_id')->bind(['mfgname']); + // } + + // /** + // * 定义 sa_admin 关联模型 + // * @localKey parttypeid + // * @bind name + // */ + // public function pdmPurchasecode() + // { + // return $this->hasOne(\app\admin\model\PdmPurchasecode::Class,'purchasecode','purchasecode')->bind(['mpn']); + // } + + // public function setPartattributeAttr($value) + // { + // if (!empty($value) && is_array($value)) { + // $arr = []; + // foreach ($value['key'] as $key => $elem) { + // $arr[$elem] = $value['value'][$key]; + // } + + // $value = json_encode($arr,JSON_UNESCAPED_UNICODE); + // } + + // return $value ?: json_encode([]); + // } + + // public function getPartattributeAttr($value) + // { + // if (!empty($value) && is_string($value)) { + // $value = json_decode($value, true); + // } + + // return $value; + // } + +} \ No newline at end of file diff --git a/app/admin/model/PdmPartitemRelation.php b/app/admin/model/PdmPartitemRelation.php index 3acd035..757d703 100644 --- a/app/admin/model/PdmPartitemRelation.php +++ b/app/admin/model/PdmPartitemRelation.php @@ -1,27 +1,27 @@ - - * PN关系维护 - * Class PdmPartitemRelation - * @package app\admin\model - */ -class PdmPartitemRelation extends Model -{ - - use SoftDelete; - - // 定义时间戳字段名 - protected $createTime = 'create_time'; - protected $updateTime = 'update_time'; - protected $deleteTime = 'delete_time'; - + + * PN关系维护 + * Class PdmPartitemRelation + * @package app\admin\model + */ +class PdmPartitemRelation extends Model +{ + + use SoftDelete; + + // 定义时间戳字段名 + protected $createTime = 'create_time'; + protected $updateTime = 'update_time'; + protected $deleteTime = 'delete_time'; + /** * 定义 sa_admin 关联模型 @@ -39,7 +39,7 @@ class PdmPartitemRelation extends Model */ public function pdmPartitemIndex() { - return $this->hasOne(\app\admin\model\PdmPartitemIndex::Class,'partnumber','partnumber')->bind(['description','value','purchasecode']); + return $this->hasOne(\app\admin\model\PdmPartitemIndex::Class,'partnumber','partnumber')->bind(['description','value','purchasecode','datasheet']); } /** * 定义 sa_pdm_symbol 关联模型 @@ -48,7 +48,7 @@ class PdmPartitemRelation extends Model */ public function pdmSymbol() { - return $this->hasOne(\app\admin\model\PdmSymbol::Class,'id','symbolid')->bind(['symbolname','view','attachment']); + return $this->hasOne(\app\admin\model\PdmSymbol::Class,'id','symbolid')->bind(['symbolname']); } /** * 定义 sa_pdm_footprint 关联模型 @@ -57,7 +57,7 @@ class PdmPartitemRelation extends Model */ public function pdmFootprint() { - return $this->hasOne(\app\admin\model\PdmFootprint::Class,'id','footprintid')->bind(['footprint','manufacture','view','attachment']); + return $this->hasOne(\app\admin\model\PdmFootprint::Class,'id','footprintid')->bind(['footprint','manufacture']); } /** * 定义 sa_department 关联模型 @@ -68,7 +68,7 @@ class PdmPartitemRelation extends Model { return $this->hasOne(\app\common\model\system\Department::Class,'id','departmentid')->bind(['title']); } - - - + + + } \ No newline at end of file diff --git a/app/admin/view/pdm_footprint/add.html b/app/admin/view/pdm_footprint/add.html index 0a9aabc..69ef3ea 100644 --- a/app/admin/view/pdm_footprint/add.html +++ b/app/admin/view/pdm_footprint/add.html @@ -8,8 +8,10 @@