From d2b43d2a2f4fa0dc6801a0fb716721ecf7db3088 Mon Sep 17 00:00:00 2001 From: zhujinyong Date: Fri, 10 Sep 2021 08:35:03 +0800 Subject: [PATCH] * Fix bugs of product api. --- api/v1/entries/products.php | 11 ++++++----- api/v1/entries/programs.php | 2 +- api/v1/entries/user.php | 8 +++++--- config/routes.php | 5 +++-- framework/api/entry.class.php | 3 +++ module/program/control.php | 10 +++++++++- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/api/v1/entries/products.php b/api/v1/entries/products.php index 9c88576cd8..11698865cf 100644 --- a/api/v1/entries/products.php +++ b/api/v1/entries/products.php @@ -18,9 +18,10 @@ class productsEntry extends entry * @access public * @return void */ - public function get() + public function get($programID = 0) { - $programID = $this->param('program', 0); + if(!$programID) $programID = $this->param('program', 0); + if($programID) { $control = $this->loadController('program', 'product'); @@ -67,16 +68,16 @@ class productsEntry extends entry */ public function post() { - $fields = 'program,line,name,PO,QD,RD,type,desc,whitelist'; + $fields = 'program,code,line,name,PO,QD,RD,type,desc,whitelist'; $this->batchSetPost($fields); $this->setPost('acl', $this->request('acl', 'private')); $this->setPost('whitelist', $this->request('whitelist', array())); $control = $this->loadController('product', 'create'); - $this->requireFields('name,program'); + $this->requireFields('name,code'); - $control->create($this->request('program')); + $control->create($this->request('program', 0)); $data = $this->getData(); if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); diff --git a/api/v1/entries/programs.php b/api/v1/entries/programs.php index 265aaa6178..1b36ddafea 100644 --- a/api/v1/entries/programs.php +++ b/api/v1/entries/programs.php @@ -29,7 +29,7 @@ class ProgramsEntry extends Entry $result = array(); foreach($programs as $program) { - $result[] = $this->format($program, 'openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time'); + $result[] = $this->format($program, 'begin:date,end:date,realBegan:date,realEnd:date,openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time,deleted:bool'); } return $this->send(200, array('programs' => $result)); } diff --git a/api/v1/entries/user.php b/api/v1/entries/user.php index b5c773ea6d..d4f666abf5 100644 --- a/api/v1/entries/user.php +++ b/api/v1/entries/user.php @@ -31,7 +31,7 @@ class userEntry extends Entry $user = $data->data->user; unset($user->password); - $this->send(200, $this->format($user, 'last:time,locked:time')); + $this->send(200, $user); } /** @@ -46,8 +46,10 @@ class userEntry extends Entry { $info = new stdclass(); - $info->profile = $this->loadModel('user')->getById($this->app->user->account); - unset($info->profile->password); + $profile = $this->loadModel('user')->getById($this->app->user->account); + unset($profile->password); + + $info->profile = $this->format($profile, 'last:time,locked:time,birthday:date,join:date'); if(!$fields) return $this->send(200, $info); diff --git a/config/routes.php b/config/routes.php index c5cace7a5b..1bf82ac744 100644 --- a/config/routes.php +++ b/config/routes.php @@ -9,8 +9,9 @@ $routes['/tokens'] = 'tokens'; $routes['/configurations'] = 'configs'; $routes['/configurations/:name'] = 'config'; -$routes['/products'] = 'products'; -$routes['/products/:id'] = 'product'; +$routes['/programs/:id/products'] = 'products'; +$routes['/products'] = 'products'; +$routes['/products/:id'] = 'product'; $routes['/productlines'] = 'productLines'; $routes['/productlines/:id'] = 'productLine'; diff --git a/framework/api/entry.class.php b/framework/api/entry.class.php index 8f8496fed1..0cdcbe9622 100644 --- a/framework/api/entry.class.php +++ b/framework/api/entry.class.php @@ -529,6 +529,9 @@ class baseEntry return gmdate("Y-m-d\TH:i:s\Z", strtotime($value)); } return $value; + case 'date': + if(!$value or $value == '0000-00-00') return null; + return $value; case 'bool': return boolval($value) ? true : false; default: diff --git a/module/program/control.php b/module/program/control.php index 261669925d..989fd40291 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -97,7 +97,15 @@ class program extends control */ public function product($programID = 0, $browseType = 'noclosed', $orderBy = 'order_desc', $recTotal = 0, $recPerPage = 15, $pageID = 1) { - $programID = $this->program->saveState($programID, $this->program->getPairs()); + $programPairs = $this->program->getPairs(); + + if(defined('RUN_MODE') && RUN_MODE == 'api' && !isset($programPairs[$programID])) + { + return $this->send(array('status' => 'fail', 'code' => 404, 'message' => '404 Not found')); + } + + $programID = $this->program->saveState($programID, $programPairs); + setCookie("lastProgram", $programID, $this->config->cookieLife, $this->config->webRoot, '', false, true); $this->program->setMenu($programID);