From 8120e6116baa67f0b49e8b4fa8d385964b0f9889 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Mon, 9 Dec 2019 20:07:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=94=AE=E5=90=8E=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=9A=84crud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/controllers/AfterSaleController.php | 149 +++++++++++++++ .../shop/models/searchs/AfterSaleSearch.php | 169 ++++++++++++++++++ .../modules/shop/views/after-sale/_form.php | 58 ++++++ .../modules/shop/views/after-sale/_search.php | 49 +++++ .../modules/shop/views/after-sale/create.php | 18 ++ .../modules/shop/views/after-sale/index.php | 28 +++ .../modules/shop/views/after-sale/update.php | 19 ++ .../modules/shop/views/after-sale/view.php | 45 +++++ 8 files changed, 535 insertions(+) create mode 100644 backend/modules/shop/controllers/AfterSaleController.php create mode 100644 backend/modules/shop/models/searchs/AfterSaleSearch.php create mode 100644 backend/modules/shop/views/after-sale/_form.php create mode 100644 backend/modules/shop/views/after-sale/_search.php create mode 100644 backend/modules/shop/views/after-sale/create.php create mode 100644 backend/modules/shop/views/after-sale/index.php create mode 100644 backend/modules/shop/views/after-sale/update.php create mode 100644 backend/modules/shop/views/after-sale/view.php diff --git a/backend/modules/shop/controllers/AfterSaleController.php b/backend/modules/shop/controllers/AfterSaleController.php new file mode 100644 index 0000000..1fa1c94 --- /dev/null +++ b/backend/modules/shop/controllers/AfterSaleController.php @@ -0,0 +1,149 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all AfterSale models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new AfterSaleSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'columns' => $searchModel->columns() + ]); + } + + /** + * Displays a single AfterSale 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 AfterSale model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new AfterSale(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing AfterSale 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 AfterSale 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 AfterSale model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return AfterSale the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = AfterSale::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } + /** + * @author iron + * 文件导出 + */ + public function actionExport() + { + $searchModel = new AfterSaleSearch(); + $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' =>'After Sales'. "-" .date('Y-m-d H/i/s', time()), + 'columns' => $searchModel->columns() + ]); + } +} diff --git a/backend/modules/shop/models/searchs/AfterSaleSearch.php b/backend/modules/shop/models/searchs/AfterSaleSearch.php new file mode 100644 index 0000000..c8b132c --- /dev/null +++ b/backend/modules/shop/models/searchs/AfterSaleSearch.php @@ -0,0 +1,169 @@ + 'blobt\grid\CheckboxColumn', + 'width' => '2%', + 'align' => 'center' + ], + 'id', + 'wx_refund_id', + 'after_sale_sn', + 'user_id', + 'order_goods_id', + //'amount', + //'count', + //'apply_at', + //'dealt_at', + //'finish_at', + //'operator_id', + //'refund_type', + //'description', + //'image', + //'status', + //'reason', + //'remarks', + //'take_shipping_sn', + //'refund_mode', + [ + 'class' => 'iron\grid\ActionColumn', + 'align' => 'center', + ], + ]; + } + /** + * @param $params + * @return ActiveDataProvider + * 不分页的所有数据 + */ + public function allData($params) + { + $query = AfterSale::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 = AfterSale::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, + 'user_id' => $this->user_id, + 'order_goods_id' => $this->order_goods_id, + 'amount' => $this->amount, + 'count' => $this->count, + 'apply_at' => $this->apply_at, + 'dealt_at' => $this->dealt_at, + 'finish_at' => $this->finish_at, + 'operator_id' => $this->operator_id, + 'refund_type' => $this->refund_type, + 'status' => $this->status, + 'reason' => $this->reason, + 'refund_mode' => $this->refund_mode, + ]); + + $query->andFilterWhere(['like', 'wx_refund_id', $this->wx_refund_id]) + ->andFilterWhere(['like', 'after_sale_sn', $this->after_sale_sn]) + ->andFilterWhere(['like', 'description', $this->description]) + ->andFilterWhere(['like', 'image', $this->image]) + ->andFilterWhere(['like', 'remarks', $this->remarks]) + ->andFilterWhere(['like', 'take_shipping_sn', $this->take_shipping_sn]); + 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/after-sale/_form.php b/backend/modules/shop/views/after-sale/_form.php new file mode 100644 index 0000000..b29c73a --- /dev/null +++ b/backend/modules/shop/views/after-sale/_form.php @@ -0,0 +1,58 @@ + + +
+ + + + field($model, 'wx_refund_id')->textInput(['maxlength' => true]) ?> + + field($model, 'after_sale_sn')->textInput(['maxlength' => true]) ?> + + field($model, 'user_id')->textInput() ?> + + field($model, 'order_goods_id')->textInput() ?> + + field($model, 'amount')->textInput() ?> + + field($model, 'count')->textInput() ?> + + field($model, 'apply_at')->textInput() ?> + + field($model, 'dealt_at')->textInput() ?> + + field($model, 'finish_at')->textInput() ?> + + field($model, 'operator_id')->textInput() ?> + + field($model, 'refund_type')->textInput() ?> + + field($model, 'description')->textarea(['rows' => 6]) ?> + + field($model, 'image')->textarea(['rows' => 6]) ?> + + field($model, 'status')->textInput() ?> + + field($model, 'reason')->textInput() ?> + + field($model, 'remarks')->textarea(['rows' => 6]) ?> + + field($model, 'take_shipping_sn')->textInput(['maxlength' => true]) ?> + + field($model, 'refund_mode')->textInput() ?> + +
+ 'btn btn-success']) ?> + 'btn btn-info']) ?> +
+ + + +
diff --git a/backend/modules/shop/views/after-sale/_search.php b/backend/modules/shop/views/after-sale/_search.php new file mode 100644 index 0000000..cd0a9d5 --- /dev/null +++ b/backend/modules/shop/views/after-sale/_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/after-sale/create.php b/backend/modules/shop/views/after-sale/create.php new file mode 100644 index 0000000..ddd13eb --- /dev/null +++ b/backend/modules/shop/views/after-sale/create.php @@ -0,0 +1,18 @@ +title = '创建 After Sale'; +$this->params['breadcrumbs'][] = ['label' => 'After Sales', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/shop/views/after-sale/index.php b/backend/modules/shop/views/after-sale/index.php new file mode 100644 index 0000000..4da215c --- /dev/null +++ b/backend/modules/shop/views/after-sale/index.php @@ -0,0 +1,28 @@ +title = '售后管理'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+
+ $dataProvider, + 'filter' => $this->render("_search", ['model' => $searchModel]), + 'batch' => [ + [ + "label" => "删除", + "url" => "after-sale/deletes" + ], + ], + 'columns' => $columns + ]); + ?> +
+
\ No newline at end of file diff --git a/backend/modules/shop/views/after-sale/update.php b/backend/modules/shop/views/after-sale/update.php new file mode 100644 index 0000000..a4268c5 --- /dev/null +++ b/backend/modules/shop/views/after-sale/update.php @@ -0,0 +1,19 @@ +title = '编辑 After Sale: ' . $model->id; +$this->params['breadcrumbs'][] = ['label' => 'After Sales', '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/after-sale/view.php b/backend/modules/shop/views/after-sale/view.php new file mode 100644 index 0000000..3035f24 --- /dev/null +++ b/backend/modules/shop/views/after-sale/view.php @@ -0,0 +1,45 @@ +title = $model->id; +$this->params['breadcrumbs'][] = ['label' => 'After Sales', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ +

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

+ + $model, + 'attributes' => [ + 'id', + 'wx_refund_id', + 'after_sale_sn', + 'user_id', + 'order_goods_id', + 'amount', + 'count', + 'apply_at', + 'dealt_at', + 'finish_at', + 'operator_id', + 'refund_type', + 'description:ntext', + 'image:ntext', + 'status', + 'reason', + 'remarks:ntext', + 'take_shipping_sn', + 'refund_mode', + ], + ]) ?> + +