Browse Source

创建售后管理的crud

antshop
linyaostalker 5 years ago
parent
commit
8120e6116b
  1. 149
      backend/modules/shop/controllers/AfterSaleController.php
  2. 169
      backend/modules/shop/models/searchs/AfterSaleSearch.php
  3. 58
      backend/modules/shop/views/after-sale/_form.php
  4. 49
      backend/modules/shop/views/after-sale/_search.php
  5. 18
      backend/modules/shop/views/after-sale/create.php
  6. 28
      backend/modules/shop/views/after-sale/index.php
  7. 19
      backend/modules/shop/views/after-sale/update.php
  8. 45
      backend/modules/shop/views/after-sale/view.php

149
backend/modules/shop/controllers/AfterSaleController.php

@ -0,0 +1,149 @@
<?php
namespace backend\modules\shop\controllers;
use Yii;
use backend\modules\shop\models\ars\AfterSale;
use backend\modules\shop\models\searchs\AfterSaleSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* AfterSaleController implements the CRUD actions for AfterSale model.
*/
class AfterSaleController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'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()
]);
}
}

169
backend/modules/shop/models/searchs/AfterSaleSearch.php

@ -0,0 +1,169 @@
<?php
namespace backend\modules\shop\models\searchs;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yii\helpers\ArrayHelper;
use backend\modules\shop\models\ars\AfterSale;
/**
* AfterSaleSearch represents the model behind the search form of `backend\modules\shop\models\ars\AfterSale`.
*/
class AfterSaleSearch extends AfterSale
{
/**
* @return array
* 增加创建时间查询字段
*/
public function attributes()
{
return ArrayHelper::merge(['created_at_range'], parent::attributes());
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'user_id', 'order_goods_id', 'amount', 'count', 'apply_at', 'dealt_at', 'finish_at', 'operator_id', 'refund_type', 'status', 'reason', 'refund_mode'], 'integer'],
[['wx_refund_id', 'after_sale_sn', 'description', 'image', 'remarks', 'take_shipping_sn'], 'safe'],
['created_at_range','safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* @return array
* 列格式
*/
public function columns()
{
return [
[
'class' => '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;
}
}

58
backend/modules/shop/views/after-sale/_form.php

@ -0,0 +1,58 @@
<?php
use yii\helpers\Html;
use yii\bootstrap4\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\shop\models\ars\AfterSale */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="after-sale-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'wx_refund_id')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'after_sale_sn')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'user_id')->textInput() ?>
<?= $form->field($model, 'order_goods_id')->textInput() ?>
<?= $form->field($model, 'amount')->textInput() ?>
<?= $form->field($model, 'count')->textInput() ?>
<?= $form->field($model, 'apply_at')->textInput() ?>
<?= $form->field($model, 'dealt_at')->textInput() ?>
<?= $form->field($model, 'finish_at')->textInput() ?>
<?= $form->field($model, 'operator_id')->textInput() ?>
<?= $form->field($model, 'refund_type')->textInput() ?>
<?= $form->field($model, 'description')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'image')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'status')->textInput() ?>
<?= $form->field($model, 'reason')->textInput() ?>
<?= $form->field($model, 'remarks')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'take_shipping_sn')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'refund_mode')->textInput() ?>
<div class="form-group">
<?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
<?= Html::a('返回', ['index'], ['class' => 'btn btn-info']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

49
backend/modules/shop/views/after-sale/_search.php

@ -0,0 +1,49 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use \blobt\widgets\DateRangePicker;
/* @var $this yii\web\View */
/* @var $model backend\modules\shop\models\searchs\AfterSaleSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
'validateOnType' => true,
]);
?>
<div class="row">
<div class="col">
<?= $form->field($model, 'id', [
"template" => "{input}{error}",
"inputOptions" => [
"placeholder" => "检索ID",
"class" => "form-control",
],
"errorOptions" => [
"class" => "error-tips"
]
])
?>
</div>
<div class="col">
<?= $form->field($model, "created_at_range", [
"template" => "{input}{error}",
"inputOptions" => [
"placeholder" => "创建时间",
],
"errorOptions" => [
"class" => "error-tips"
]
])->widget(DateRangePicker::className());
?>
</div>
<div class="form-group">
<?= Html::submitButton('<i class="fa fa-filter"></i>', ['class' => 'btn btn-default']) ?>
<?= Html::resetButton('<i class="fa fa-eraser"></i>', ['class' => 'btn btn-default']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>

18
backend/modules/shop/views/after-sale/create.php

@ -0,0 +1,18 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\modules\shop\models\ars\AfterSale */
$this->title = '创建 After Sale';
$this->params['breadcrumbs'][] = ['label' => 'After Sales', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="after-sale-create">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

28
backend/modules/shop/views/after-sale/index.php

@ -0,0 +1,28 @@
<?php
use yii\helpers\Html;
use iron\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\shop\models\searchs\AfterSaleSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = '售后管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="row">
<div class="col-12">
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filter' => $this->render("_search", ['model' => $searchModel]),
'batch' => [
[
"label" => "删除",
"url" => "after-sale/deletes"
],
],
'columns' => $columns
]);
?>
</div>
</div>

19
backend/modules/shop/views/after-sale/update.php

@ -0,0 +1,19 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\modules\shop\models\ars\AfterSale */
$this->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 ';
?>
<div class="after-sale-update">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

45
backend/modules/shop/views/after-sale/view.php

@ -0,0 +1,45 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model backend\modules\shop\models\ars\AfterSale */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => 'After Sales', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="after-sale-view">
<p>
<?= Html::a('返回列表', ['index'], ['class' => 'btn btn-success']) ?>
</p>
<?= DetailView::widget([
'model' => $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',
],
]) ?>
</div>
Loading…
Cancel
Save