diff --git a/app-ht/config/main.php b/app-ht/config/main.php index f2b130a..9aa8109 100644 --- a/app-ht/config/main.php +++ b/app-ht/config/main.php @@ -46,8 +46,8 @@ $config = [ 'my'=>[ 'class' => 'app\ht\modules\my\Module', ], - 'automation' => [ - 'class' => 'app\ht\modules\automation\Module', + 'project' => [ + 'class' => 'app\ht\modules\project\Module', ], 'model' => [ 'class' => 'app\ht\modules\model\Module', diff --git a/app-ht/config/params.php b/app-ht/config/params.php index a1ef3a4..1ce1d57 100644 --- a/app-ht/config/params.php +++ b/app-ht/config/params.php @@ -3,5 +3,5 @@ return [ 'adminEmail' => 'tech@jiwork.com', 'DINGTALKL_URL' => 'https://tdd.jiwork.com/', //在钉钉端用系统扫码之后跳转到钉钉对应的界面,里面要指定钉钉的网址 'BAIDU_MAP_BROWSER_KEY' => 'UzLG5fpQtralY2hXO3wvVFzvlCmw6Rue', - 'VERSION' => 'v0.0.1 build 3', + 'VERSION' => 'v0.0.1 build 4', ]; \ No newline at end of file diff --git a/app-ht/modules/model/controllers/ModelController.php b/app-ht/modules/model/controllers/ModelController.php index 4dc8d33..ebe80cf 100644 --- a/app-ht/modules/model/controllers/ModelController.php +++ b/app-ht/modules/model/controllers/ModelController.php @@ -53,7 +53,7 @@ class ModelController extends BaseController $where[] = ['<=', 'm.created_at', $endTime]; } if ($name) { - $where[] = ['like', 'p.name', $name]; + $where[] = ['like', 'm.name', $name]; } if ($type == 0) { $pageList = ModelRepository::getPageList($where); diff --git a/app-ht/modules/project/Module.php b/app-ht/modules/project/Module.php new file mode 100644 index 0000000..bfd6ea6 --- /dev/null +++ b/app-ht/modules/project/Module.php @@ -0,0 +1,14 @@ +params['perm'] = require(__DIR__ . '/config/perm.php'); + } +} \ No newline at end of file diff --git a/app-ht/modules/project/config/perm.php b/app-ht/modules/project/config/perm.php new file mode 100644 index 0000000..5ddae80 --- /dev/null +++ b/app-ht/modules/project/config/perm.php @@ -0,0 +1,14 @@ + '项目', + 'items' => [ + 'shop_city' => [ + 'label' => '项目', + 'items' => [ + 4 => '项目管理', + ], + 'path' => 'project/project/*' + ], + ] +]; diff --git a/app-ht/modules/project/controllers/ProjectController.php b/app-ht/modules/project/controllers/ProjectController.php new file mode 100644 index 0000000..f583a91 --- /dev/null +++ b/app-ht/modules/project/controllers/ProjectController.php @@ -0,0 +1,186 @@ +dataList(1); + /** + * 渲染模板 + */ + return $this->render('index', $params); + } + + /** + * 查询数据列表 + */ + protected function dataList($type = '') + { + $request = Yii::$app->request; + $creatTime = $request->get('creatTime'); + $endTime = $request->get('endTime'); + $name = $request->get('name'); + + $gets = [ + 'creatTime' => $creatTime, + 'endTime' => $endTime, + 'name' => $name, + ]; + + $where = ['and']; + if ($creatTime) { + $creatTime = strtotime($creatTime); + $where[] = ['>=', 'p.created_at', $creatTime]; + } + if ($endTime) { + $endTime = strtotime($endTime) + 86400; + $where[] = ['<=', 'p.created_at', $endTime]; + } + if ($name) { + $where[] = ['like', 'p.name', $name]; + } + if ($type == 0) { + $pageList = ProjectRepository::getPageList($where); + $pages = null; + } else { + $pageSize = 20; + $pages = new Pagination(['totalCount' => ProjectRepository::getPageCount($where), 'pageSize' => $pageSize]); + $pageList = ProjectRepository::getPageList($where, $pages->offset, $pages->limit); + } + + /** + * 数据整理 + */ + return [ + 'listdata' => $pageList, + 'pages' => $pages, + 'gets' => $gets + ]; + } + + /** + * 创建项目 + * @return string + */ + public function actionCreate() + { + return $this->render('create'); + } + + /** + * 创建项目 + * @return string + */ + public function actionDoAdd() + { + $request = Yii::$app->request; + $name = $request->post("name"); // 项目 + if (empty($name)) { + Yii::$app->session->setFlash('error', '项目不能为空'); + return $this->render('create'); + } + $result = Project::create($request->post()); + if ($result === -1) { + Yii::$app->session->setFlash('error', '添加失败, 项目' . $name . '已存在'); + return $this->render('create'); + } + if ($result) { + Yii::$app->session->setFlash('success', '添加成功'); + } else { + Yii::$app->session->setFlash('error', '添加失败'); + } + + return $this->redirect('index'); + } + + /** + * 编辑项目 + * @return string + */ + public function actionEdit() + { + $ProjectId = $this->request->get("mid"); + $info = ProjectRepository::selectOne($ProjectId, true); + return $this->render('edit', ["info" => $info]); + } + + /** + * 编辑项目 + * @return string + */ + public function actionDoEdit() + { + $request = Yii::$app->request; + $name = $request->post("name"); + $mid = $request->post("mid"); + if (empty($mid)) { + Yii::$app->session->setFlash('error', '项目编号不能为空'); + $params = $this->dataList(1); + return $this->render('index', $params); + } + $Project =ProjectRepository::selectOne($mid,true); + if (empty($Project)) { + Yii::$app->session->setFlash('error', '项目记录不存在'); + $params = $this->dataList(1); + return $this->render('index', $params); + } + if (empty($name)) { + Yii::$app->session->setFlash('error', '项目不能为空'); + return $this->render('edit', ["info" => $Project]); + } + + $result = Project::update($mid, $request->post()); + + if ($result === -1) { + Yii::$app->session->setFlash('error', '修改的项目' . $name . '已存在'); + return $this->render('edit', ["info" => $Project]); + } + if ($result) { + Yii::$app->session->setFlash('success', '编辑成功'); + } else { + Yii::$app->session->setFlash('error', '编辑失败'); + } + $Project = ProjectRepository::selectOne($mid,true); + return $this->render('edit', ["info" => $Project]); + } + + /** + * 删除项目 + * @return string + * @throws \Exception + */ + public function actionDoDel() + { + $request = Yii::$app->request; + $itemId = $request->post("data_id"); + $msg = array(); + + // 删除对应的项目 + if (Project::delete($itemId)) { + $msg['status'] = 1; + $msg['msg'] = "操作成功"; + } else { + $msg['status'] = 0; + $msg['msg'] = "操作失败"; + } + + return $this->renderJson($msg); + } + +} \ No newline at end of file diff --git a/app-ht/modules/project/views/project/create.php b/app-ht/modules/project/views/project/create.php new file mode 100644 index 0000000..5d0821f --- /dev/null +++ b/app-ht/modules/project/views/project/create.php @@ -0,0 +1,60 @@ +title = '创建项目'; +$this->params['breadcrumbs'][] = ['label' => '项目管理', 'url' => ['/project/project/index']]; +$this->params['breadcrumbs'][] = $this->title; + +?> + +
+
+
+
+

创建项目

+
+
+ +
+ +
+
+
+ + +
+ +
+ + \ No newline at end of file diff --git a/app-ht/modules/project/views/project/edit.php b/app-ht/modules/project/views/project/edit.php new file mode 100644 index 0000000..6da1bfc --- /dev/null +++ b/app-ht/modules/project/views/project/edit.php @@ -0,0 +1,64 @@ +title = '编辑项目'; +$this->params['breadcrumbs'][] = ['label' => '项目管理', 'url' => ['/project/project/index']]; +$this->params['breadcrumbs'][] = $this->title; + +?> + +
+
+
+
+ " class="btn btn-success"> + 创建项目 +
+
+

编辑项目

+
+
+ +
+ " style="margin-top: -6px;" name="name" placeholder="请填写项目名称" class="form-control"> +
+
+
+ + +
+ +
+ + \ No newline at end of file diff --git a/app-ht/modules/project/views/project/index.php b/app-ht/modules/project/views/project/index.php new file mode 100644 index 0000000..73e7d85 --- /dev/null +++ b/app-ht/modules/project/views/project/index.php @@ -0,0 +1,121 @@ +title = '项目管理'; +$this->params['breadcrumbs'][] = $this->title; +?> + +
+
+
+ + + + + + + + + + + + +
项目名称 +
+ +
+
创建时间 +
+ - + +
+
+
+
+
+ +
+
+
+ " class="btn btn-success"> + 创建项目 +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
编号项目名称创建时间操作
+ +  |  + $item['id']])?>" aid="">编辑 +
+
暂无记录
+
+
+ + +
+ \ No newline at end of file diff --git a/app-ht/views/layouts/routes.php b/app-ht/views/layouts/routes.php index 8b7bffb..c92c81a 100644 --- a/app-ht/views/layouts/routes.php +++ b/app-ht/views/layouts/routes.php @@ -40,14 +40,14 @@ return [ ] ], [ - 'path' => '/projects', + 'path' => '/project', 'label' => '项目', 'routes' => [ [ - 'path' => '/projects', - 'redirect' => '/projects/projects/index' + 'path' => '/project', + 'redirect' => '/project/project/index' ], - ['label' => '项目管理', 'path'=> '/projects/projects/index'], + ['label' => '项目管理', 'path'=> '/project/project/index'], ] ], [ diff --git a/domain/model/Model.php b/domain/model/Model.php index 977f6db..4f28b64 100644 --- a/domain/model/Model.php +++ b/domain/model/Model.php @@ -8,8 +8,8 @@ use Exception; /** * 机器型号 - * Class Production - * @package domain\production + * Class Model + * @package domain\model */ class Model { diff --git a/domain/model/ModelRepository.php b/domain/model/ModelRepository.php index a68b529..19f6f7c 100644 --- a/domain/model/ModelRepository.php +++ b/domain/model/ModelRepository.php @@ -21,9 +21,9 @@ class ModelRepository */ static function getPageList($where, $offset, $limit) { - $modelFind = ModelModel::find()->alias("p") + $modelFind = ModelModel::find()->alias("m") ->select([ - "p.*" + "m.*" ]); if (!empty($where)) { @@ -36,7 +36,7 @@ class ModelRepository $modelFind->limit($limit); } - $modelFind->orderBy("p.id desc"); + $modelFind->orderBy("m.id desc"); $modelFind->asArray(); $dataList = $modelFind->all(); @@ -49,7 +49,7 @@ class ModelRepository */ static function getPageCount($map = '') { - $modelFind = ModelModel::find()->alias("p"); + $modelFind = ModelModel::find()->alias("m"); if (!empty($map)) { $modelFind->where($map); } diff --git a/domain/project/Project.php b/domain/project/Project.php new file mode 100644 index 0000000..c4ea910 --- /dev/null +++ b/domain/project/Project.php @@ -0,0 +1,99 @@ + $item["name"]]); + if (!empty($findProjectModel)) { + return -1; + } + $projectModel = Yii::createObject(ProjectModel::className()); + $projectModel->project_no = self::getProjectNo(); + $projectModel->name = $item["name"]; // 项目 + $saveResult = $projectModel->save(); + return $saveResult; + } catch (Exception $e) { + return false; + } + } + + /** + * 更新项目 + * @param $id + * @param $item + * @return null|static + */ + static function update($id, $item) + { + $projectModel = ProjectModel::findOne($id); + if (empty($projectModel)) { + return false; + } + if (isset($item['name']) && $projectModel->name != $item['name']) { + $findProjectModel = ProjectModel::findOne(['name' => $item["name"]]); + if (!empty($findProjectModel)) { + return -1; + } + } + if (isset($item['name']) && !empty($item['name'])) { + $projectModel->name = $item['name']; + } + + $resultSave = $projectModel->save(); + return $resultSave; + } + + /** + * 删除项目 + * @param $id + * @param $item + * @return null|static + */ + public static function delete($id) + { + $projectModel = ProjectModel::findOne($id); + if (empty($projectModel)) { + return false; + } + + return ProjectModel::deleteAll(["id" => $id]); + } + + /** + * 获取十六进制项目编号 + */ + private static function getProjectNo() + { + $findModel = ProjectModel::find()->orderBy("id desc")->asArray()->one(); + if (empty($findModel)) { + return "0001"; + } + $dataNo = hexdec($findModel['project_no']) + 1; + $dataNo = (string) dechex($dataNo); + if (strlen($dataNo) == 1) { + $dataNo = "000" . $dataNo; + } else if (strlen($dataNo) == 2) { + $dataNo = "00" . $dataNo; + } else if (strlen($dataNo) == 3) { + $dataNo = "0" . $dataNo; + } + return $dataNo; + } +} \ No newline at end of file diff --git a/domain/project/ProjectRepository.php b/domain/project/ProjectRepository.php new file mode 100644 index 0000000..d2993fb --- /dev/null +++ b/domain/project/ProjectRepository.php @@ -0,0 +1,85 @@ +alias("p") + ->select([ + "p.*" + ]); + + if (!empty($where)) { + $modelFind->where($where); + } + if ($offset) { + $modelFind->offset($offset); + } + if ($limit) { + $modelFind->limit($limit); + } + + $modelFind->orderBy("p.id desc"); + $modelFind->asArray(); + $dataList = $modelFind->all(); + + return $dataList; + } + + /** + * 列表页面分页器数量 + * @param string $map + */ + static function getPageCount($map = '') + { + $modelFind = ProjectModel::find()->alias("p"); + if (!empty($map)) { + $modelFind->where($map); + } + $pageCount = $modelFind->count(); + + return $pageCount; + } + + /** + * @param $id + * @param bool|false $asArr + * @return null|static + */ + static function selectOne($id, $asArr = false) + { + $model = ProjectModel::findOne($id); + if ($asArr && $model) { + $model = $model->toArray(); + } + return $model; + } + + /** + * @param $id + * @param bool|false $asArr + * @return null|static + */ + static function findOne($condition) + { + $model = ProjectModel::findOne($condition); + return $model; + } +} \ No newline at end of file diff --git a/domain/project/models/Project.php b/domain/project/models/Project.php new file mode 100644 index 0000000..d5e4223 --- /dev/null +++ b/domain/project/models/Project.php @@ -0,0 +1,36 @@ + [ + 'class' => TimestampBehavior::className(), + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + ] + ]; + } +} \ No newline at end of file -- libgit2 0.21.0