From 9dbda08d88647a17fcf8e900da3b061f6025ff01 Mon Sep 17 00:00:00 2001 From: travis <310243791@qq.com> Date: Fri, 6 Dec 2019 08:57:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=91=E8=B4=A7=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/controllers/DeliveryController.php | 149 +++++++++++++++++ .../shop/models/searchs/DeliverySearch.php | 156 ++++++++++++++++++ backend/modules/shop/views/delivery/_form.php | 36 ++++ .../modules/shop/views/delivery/_search.php | 49 ++++++ .../modules/shop/views/delivery/create.php | 18 ++ backend/modules/shop/views/delivery/index.php | 28 ++++ .../modules/shop/views/delivery/update.php | 19 +++ backend/modules/shop/views/delivery/view.php | 36 ++++ 8 files changed, 491 insertions(+) create mode 100644 backend/modules/shop/controllers/DeliveryController.php create mode 100644 backend/modules/shop/models/searchs/DeliverySearch.php create mode 100644 backend/modules/shop/views/delivery/_form.php create mode 100644 backend/modules/shop/views/delivery/_search.php create mode 100644 backend/modules/shop/views/delivery/create.php create mode 100644 backend/modules/shop/views/delivery/index.php create mode 100644 backend/modules/shop/views/delivery/update.php create mode 100644 backend/modules/shop/views/delivery/view.php diff --git a/backend/modules/shop/controllers/DeliveryController.php b/backend/modules/shop/controllers/DeliveryController.php new file mode 100644 index 0000000..2569281 --- /dev/null +++ b/backend/modules/shop/controllers/DeliveryController.php @@ -0,0 +1,149 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Delivery models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new DeliverySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'columns' => $searchModel->columns() + ]); + } + + /** + * Displays a single Delivery model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Delivery model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Delivery(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing Delivery model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing Delivery model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Delivery model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Delivery the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Delivery::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } + /** + * @author iron + * 文件导出 + */ + public function actionExport() + { + $searchModel = new DeliverySearch(); + $params = Yii::$app->request->queryParams; + if ($params['page-type'] == 'all') { + $dataProvider = $searchModel->allData($params); + } else { + $dataProvider = $searchModel->search($params); + } + \iron\widget\Excel::export([ + 'models' => $dataProvider->getModels(), + 'format' => 'Xlsx', + 'asAttachment' => true, + 'fileName' =>'Deliveries'. "-" .date('Y-m-d H/i/s', time()), + 'columns' => $searchModel->columns() + ]); + } +} diff --git a/backend/modules/shop/models/searchs/DeliverySearch.php b/backend/modules/shop/models/searchs/DeliverySearch.php new file mode 100644 index 0000000..27c8c96 --- /dev/null +++ b/backend/modules/shop/models/searchs/DeliverySearch.php @@ -0,0 +1,156 @@ + 'blobt\grid\CheckboxColumn', + 'width' => '2%', + 'align' => 'center' + ], + 'id', + 'order_id', + 'shipping_name', + 'shipping_id', + 'type', + 'goods', + 'status', + 'decription', + //'updated_at', + [ + 'attribute' => 'created_at', + 'value' => function ($model) { + return date('Y-m-d H:i:s', $model->created_at); + } + ], + [ + 'class' => 'iron\grid\ActionColumn', + 'align' => 'center', + ], + ]; + } + /** + * @param $params + * @return ActiveDataProvider + * 不分页的所有数据 + */ + public function allData($params) + { + $query = Delivery::find(); + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => false, + 'sort' => false + ]); + $this->load($params); + return $this->filter($query, $dataProvider); + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + $query = Delivery::find(); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => [ + 'pageSizeLimit' => [1, 200] + ], + 'sort' => [ + 'defaultOrder' => [ + 'id' => SORT_DESC, + ] + ], + ]); + + $this->load($params); + return $this->filter($query, $dataProvider); + } + /** + * @param $query + * @param $dataProvider + * @return ActiveDataProvider + * 条件筛选 + */ + private function filter($query, $dataProvider){ + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'order_id' => $this->order_id, + 'type' => $this->type, + 'status' => $this->status, + 'updated_at' => $this->updated_at, + 'created_at' => $this->created_at, + ]); + + $query->andFilterWhere(['like', 'shipping_name', $this->shipping_name]) + ->andFilterWhere(['like', 'shipping_id', $this->shipping_id]) + ->andFilterWhere(['like', 'goods', $this->goods]) + ->andFilterWhere(['like', 'decription', $this->decription]); + if ($this->created_at_range) { + $arr = explode(' ~ ', $this->created_at_range); + $start = strtotime($arr[0]); + $end = strtotime($arr[1]) + 3600 * 24; + $query->andFilterWhere(['between', 'created_at', $start, $end]); + } + return $dataProvider; + } +} diff --git a/backend/modules/shop/views/delivery/_form.php b/backend/modules/shop/views/delivery/_form.php new file mode 100644 index 0000000..963acf9 --- /dev/null +++ b/backend/modules/shop/views/delivery/_form.php @@ -0,0 +1,36 @@ + + +
+ + + + field($model, 'order_id')->textInput() ?> + + field($model, 'shipping_name')->textInput(['maxlength' => true]) ?> + + field($model, 'shipping_id')->textInput(['maxlength' => true]) ?> + + field($model, 'type')->textInput() ?> + + field($model, 'goods')->textarea(['rows' => 6]) ?> + + field($model, 'status')->textInput() ?> + + field($model, 'decription')->textarea(['rows' => 6]) ?> + +
+ 'btn btn-success']) ?> + 'btn btn-info']) ?> +
+ + + +
diff --git a/backend/modules/shop/views/delivery/_search.php b/backend/modules/shop/views/delivery/_search.php new file mode 100644 index 0000000..3fc8317 --- /dev/null +++ b/backend/modules/shop/views/delivery/_search.php @@ -0,0 +1,49 @@ + + + ['index'], + 'method' => 'get', + 'validateOnType' => true, + ]); +?> +
+
+ field($model, 'id', [ + "template" => "{input}{error}", + "inputOptions" => [ + "placeholder" => "检索ID", + "class" => "form-control", + ], + "errorOptions" => [ + "class" => "error-tips" + ] + ]) + ?> +
+
+ field($model, "created_at_range", [ + "template" => "{input}{error}", + "inputOptions" => [ + "placeholder" => "创建时间", + ], + "errorOptions" => [ + "class" => "error-tips" + ] + ])->widget(DateRangePicker::className()); + ?> +
+
+ ', ['class' => 'btn btn-default']) ?> + ', ['class' => 'btn btn-default']) ?> +
+
+ \ No newline at end of file diff --git a/backend/modules/shop/views/delivery/create.php b/backend/modules/shop/views/delivery/create.php new file mode 100644 index 0000000..293904b --- /dev/null +++ b/backend/modules/shop/views/delivery/create.php @@ -0,0 +1,18 @@ +title = '创建 Delivery'; +$this->params['breadcrumbs'][] = ['label' => 'Deliveries', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/shop/views/delivery/index.php b/backend/modules/shop/views/delivery/index.php new file mode 100644 index 0000000..9cc14e1 --- /dev/null +++ b/backend/modules/shop/views/delivery/index.php @@ -0,0 +1,28 @@ +title = '发货列表'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+
+ $dataProvider, + 'filter' => $this->render("_search", ['model' => $searchModel]), + 'batch' => [ +// [ +// "label" => "删除", +// "url" => "delivery/deletes" +// ], + ], + 'columns' => $columns + ]); + ?> +
+
\ No newline at end of file diff --git a/backend/modules/shop/views/delivery/update.php b/backend/modules/shop/views/delivery/update.php new file mode 100644 index 0000000..9cc3935 --- /dev/null +++ b/backend/modules/shop/views/delivery/update.php @@ -0,0 +1,19 @@ +title = '编辑 Delivery: ' . $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Deliveries', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update '; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/shop/views/delivery/view.php b/backend/modules/shop/views/delivery/view.php new file mode 100644 index 0000000..9cca8c1 --- /dev/null +++ b/backend/modules/shop/views/delivery/view.php @@ -0,0 +1,36 @@ +title = $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Deliveries', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ +

+ 'btn btn-success']) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'order_id', + 'shipping_name', + 'shipping_id', + 'type', + 'goods:ntext', + 'status', + 'decription:ntext', + 'updated_at', + 'created_at', + ], + ]) ?> + +