travis
5 years ago
8 changed files with 491 additions and 0 deletions
-
149backend/modules/shop/controllers/DeliveryController.php
-
156backend/modules/shop/models/searchs/DeliverySearch.php
-
36backend/modules/shop/views/delivery/_form.php
-
49backend/modules/shop/views/delivery/_search.php
-
18backend/modules/shop/views/delivery/create.php
-
28backend/modules/shop/views/delivery/index.php
-
19backend/modules/shop/views/delivery/update.php
-
36backend/modules/shop/views/delivery/view.php
@ -0,0 +1,149 @@ |
|||
<?php |
|||
|
|||
namespace backend\modules\shop\controllers; |
|||
|
|||
use Yii; |
|||
use backend\modules\shop\models\ars\Delivery; |
|||
use backend\modules\shop\models\searchs\DeliverySearch; |
|||
use yii\web\Controller; |
|||
use yii\web\NotFoundHttpException; |
|||
use yii\filters\VerbFilter; |
|||
|
|||
/** |
|||
* DeliveryController implements the CRUD actions for Delivery model. |
|||
*/ |
|||
class DeliveryController extends Controller |
|||
{ |
|||
/** |
|||
* {@inheritdoc} |
|||
*/ |
|||
public function behaviors() |
|||
{ |
|||
return [ |
|||
'verbs' => [ |
|||
'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() |
|||
]); |
|||
} |
|||
} |
@ -0,0 +1,156 @@ |
|||
<?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\Delivery; |
|||
|
|||
/** |
|||
* DeliverySearch represents the model behind the search form of `backend\modules\shop\models\ars\Delivery`. |
|||
*/ |
|||
class DeliverySearch extends Delivery |
|||
{ |
|||
/** |
|||
* @return array |
|||
* 增加创建时间查询字段 |
|||
*/ |
|||
public function attributes() |
|||
{ |
|||
return ArrayHelper::merge(['created_at_range'], parent::attributes()); |
|||
} |
|||
/** |
|||
* {@inheritdoc} |
|||
*/ |
|||
public function rules() |
|||
{ |
|||
return [ |
|||
[['id', 'order_id', 'type', 'status', 'updated_at', 'created_at'], 'integer'], |
|||
[['shipping_name', 'shipping_id', 'goods', 'decription'], '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', |
|||
'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; |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
<?php |
|||
|
|||
use yii\helpers\Html; |
|||
use yii\bootstrap4\ActiveForm; |
|||
|
|||
/* @var $this yii\web\View */ |
|||
/* @var $model backend\modules\shop\models\ars\Delivery */ |
|||
/* @var $form yii\widgets\ActiveForm */ |
|||
?>
|
|||
|
|||
<div class="delivery-form"> |
|||
|
|||
<?php $form = ActiveForm::begin(); ?>
|
|||
|
|||
<?= $form->field($model, 'order_id')->textInput() ?>
|
|||
|
|||
<?= $form->field($model, 'shipping_name')->textInput(['maxlength' => true]) ?>
|
|||
|
|||
<?= $form->field($model, 'shipping_id')->textInput(['maxlength' => true]) ?>
|
|||
|
|||
<?= $form->field($model, 'type')->textInput() ?>
|
|||
|
|||
<?= $form->field($model, 'goods')->textarea(['rows' => 6]) ?>
|
|||
|
|||
<?= $form->field($model, 'status')->textInput() ?>
|
|||
|
|||
<?= $form->field($model, 'decription')->textarea(['rows' => 6]) ?>
|
|||
|
|||
<div class="form-group"> |
|||
<?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
|
|||
<?= Html::a('返回', ['index'], ['class' => 'btn btn-info']) ?>
|
|||
</div> |
|||
|
|||
<?php ActiveForm::end(); ?>
|
|||
|
|||
</div> |
@ -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\DeliverySearch */ |
|||
/* @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(); ?>
|
@ -0,0 +1,18 @@ |
|||
<?php |
|||
|
|||
use yii\helpers\Html; |
|||
|
|||
/* @var $this yii\web\View */ |
|||
/* @var $model backend\modules\shop\models\ars\Delivery */ |
|||
|
|||
$this->title = '创建 Delivery'; |
|||
$this->params['breadcrumbs'][] = ['label' => 'Deliveries', 'url' => ['index']]; |
|||
$this->params['breadcrumbs'][] = $this->title; |
|||
?>
|
|||
<div class="delivery-create"> |
|||
|
|||
<?= $this->render('_form', [ |
|||
'model' => $model, |
|||
]) ?>
|
|||
|
|||
</div> |
@ -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\DeliverySearch */ |
|||
/* @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" => "delivery/deletes"
|
|||
// ],
|
|||
], |
|||
'columns' => $columns |
|||
]); |
|||
?>
|
|||
</div> |
|||
</div> |
@ -0,0 +1,19 @@ |
|||
<?php |
|||
|
|||
use yii\helpers\Html; |
|||
|
|||
/* @var $this yii\web\View */ |
|||
/* @var $model backend\modules\shop\models\ars\Delivery */ |
|||
|
|||
$this->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 '; |
|||
?>
|
|||
<div class="delivery-update"> |
|||
|
|||
<?= $this->render('_form', [ |
|||
'model' => $model, |
|||
]) ?>
|
|||
|
|||
</div> |
@ -0,0 +1,36 @@ |
|||
<?php |
|||
|
|||
use yii\helpers\Html; |
|||
use yii\widgets\DetailView; |
|||
|
|||
/* @var $this yii\web\View */ |
|||
/* @var $model backend\modules\shop\models\ars\Delivery */ |
|||
|
|||
$this->title = $model->id; |
|||
$this->params['breadcrumbs'][] = ['label' => 'Deliveries', 'url' => ['index']]; |
|||
$this->params['breadcrumbs'][] = $this->title; |
|||
\yii\web\YiiAsset::register($this); |
|||
?>
|
|||
<div class="delivery-view"> |
|||
|
|||
<p> |
|||
<?= Html::a('返回列表', ['index'], ['class' => 'btn btn-success']) ?>
|
|||
</p> |
|||
|
|||
<?= DetailView::widget([ |
|||
'model' => $model, |
|||
'attributes' => [ |
|||
'id', |
|||
'order_id', |
|||
'shipping_name', |
|||
'shipping_id', |
|||
'type', |
|||
'goods:ntext', |
|||
'status', |
|||
'decription:ntext', |
|||
'updated_at', |
|||
'created_at', |
|||
], |
|||
]) ?>
|
|||
|
|||
</div> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue