From ee93723d623318d223c40a2cf306ed971ec39444 Mon Sep 17 00:00:00 2001 From: XingChao <1363688001@qq.com> Date: Thu, 1 Mar 2018 16:13:25 +0800 Subject: [PATCH] =?UTF-8?q?'=E8=AE=A2=E5=8D=95=E8=AF=BB=E5=8F=96'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/product/producttickets/add.html | 12 +- application/api/controller/Order.php | 103 +++++++++--------- application/api/model/Order.php | 67 ++++++++++++ 3 files changed, 127 insertions(+), 55 deletions(-) create mode 100644 application/api/model/Order.php diff --git a/application/admin/view/product/producttickets/add.html b/application/admin/view/product/producttickets/add.html index 88862024..86a8638a 100644 --- a/application/admin/view/product/producttickets/add.html +++ b/application/admin/view/product/producttickets/add.html @@ -116,12 +116,12 @@ -
- -
- -
-
+ + + + + +
diff --git a/application/api/controller/Order.php b/application/api/controller/Order.php index e9d5a747..fcbe1a2b 100644 --- a/application/api/controller/Order.php +++ b/application/api/controller/Order.php @@ -7,6 +7,7 @@ */ namespace app\api\controller; + use app\common\controller\Api; /** @@ -21,51 +22,62 @@ class Order extends Api parent::_initialize(); $this->model = model('Order'); } + /** * 插入订单 * @return mixed */ public function add() { - if (request()->isPost()) - { - //$params = $this->request->post("row/a"); - $params = input('post.'); - if ($params) - { - if ($this->dataLimit && $this->dataLimitFieldAutoFill) - { - $params[$this->dataLimitField] = $this->auth->id; - } - try - { - //是否采用模型验证 - if ($this->modelValidate) - { - $name = basename(str_replace('\\', '/', get_class($this->model))); - $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate; - $this->model->validate($validate); - } - $result = $this->model->allowField(true)->save($params); - if ($result !== false) - { - $this->success('','',json(),[]); - } - else - { - $this->error($this->getError()); - } - } - catch (\think\exception\PDOException $e) - { - $this->error($e->getMessage()); - } +// if (request()->isPost()) +// { + //$params = $this->request->post("row/a"); +// $params = input('post.'); + + $params = array( + 'order_num' => time(), + 'user_id' => '1', + 'travel_start_time' => '2018-01-04', + 'travel_end_time' => '2018-01-09', + 'product_name' => '产品名', + 'order_start_time' => 'order_start_time', + 'reconciliation_time' => '2018-01-09 12:33:44', + 'ota_name' => 'aasd', + ); + +// print_r($params); +// exit(); + if ($params) { + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { + $params[$this->dataLimitField] = $this->auth->id; + } + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = basename(str_replace('\\', '/', get_class($this->model))); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate; + $this->model->validate($validate); + } +// $result = $this->model->save($params); + $result = $this->model->allowField(true)->save($params); + if ($result !== false) { +// success里调用了strtolower +// $this->success('', '', json(), []); + return json('添加成功', 200, [], ''); + + } else { + $this->error($this->getError()); + } + } catch (\think\exception\PDOException $e) { + $this->error($e->getMessage()); } - $this->error(__('Parameter %s can not be empty', '')); } + $this->error(__('Parameter %s can not be empty', '')); +// } //return $this->view->fetch(); - return json('',200,[],''); +// return json('', 200, [], ''); } + public function index() { //设置过滤方法 @@ -73,8 +85,7 @@ class Order extends Api // if ($this->request->isAjax()) // { //如果发送的来源是Selectpage,则转发到Selectpage - if ($this->request->request('pkey_name')) - { + if ($this->request->request('pkey_name')) { return $this->selectpage(); } @@ -104,26 +115,20 @@ class Order extends Api */ public function del($ids = "") { - if ($ids) - { + if ($ids) { $pk = $this->model->getPk(); $adminIds = $this->getDataLimitAdminIds(); - if (is_array($adminIds)) - { + if (is_array($adminIds)) { $count = $this->model->where($this->dataLimitField, 'in', $adminIds); } $list = $this->model->where($pk, 'in', $ids)->select(); $count = 0; - foreach ($list as $k => $v) - { + foreach ($list as $k => $v) { $count += $v->delete(); } - if ($count) - { - $this->success('操作成功','',json(),[]); - } - else - { + if ($count) { + $this->success('操作成功', '', json(), []); + } else { $this->error(__('No rows were deleted')); } } diff --git a/application/api/model/Order.php b/application/api/model/Order.php new file mode 100644 index 00000000..243bb698 --- /dev/null +++ b/application/api/model/Order.php @@ -0,0 +1,67 @@ + __('Order_status 0'),'1' => __('Order_status 1')]; + } + + public function getCommentStatusList() + { + return ['0' => __('Comment_status 0'),'1' => __('Comment_status 1')]; + } + + + public function getOrderStatusTextAttr($value, $data) + { + $value = $value ? $value : $data['order_status']; + $list = $this->getOrderStatusList(); + return isset($list[$value]) ? $list[$value] : ''; + } + + + public function getCommentStatusTextAttr($value, $data) + { + $value = $value ? $value : $data['comment_status']; + $list = $this->getCommentStatusList(); + return isset($list[$value]) ? $list[$value] : ''; + } + + + public function getOrderStartTimeTextAttr($value, $data) + { + $value = $value ? $value : $data['order_start_time']; + return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; + } + + protected function setOrderStartTimeAttr($value) + { + return $value && !is_numeric($value) ? strtotime($value) : $value; + } + + +}