Browse Source

创建TakingSite表的curl

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
22fdde5a14
  1. 149
      backend/controllers/TakingSiteController.php
  2. 6
      backend/views/layouts/sidebar.php
  3. 34
      backend/views/taking-site/_form.php
  4. 49
      backend/views/taking-site/_search.php
  5. 18
      backend/views/taking-site/create.php
  6. 28
      backend/views/taking-site/index.php
  7. 19
      backend/views/taking-site/update.php
  8. 35
      backend/views/taking-site/view.php
  9. 149
      common/models/searchs/TakingSiteSearch.php

149
backend/controllers/TakingSiteController.php

@ -0,0 +1,149 @@
<?php
namespace backend\controllers;
use Yii;
use common\models\ars\TakingSite;
use common\models\searchs\TakingSiteSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* TakingSiteController implements the CRUD actions for TakingSite model.
*/
class TakingSiteController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all TakingSite models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new TakingSiteSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'columns' => $searchModel->columns()
]);
}
/**
* Displays a single TakingSite 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 TakingSite model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new TakingSite();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect('index');
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing TakingSite 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 TakingSite 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 TakingSite model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return TakingSite the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = TakingSite::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
/**
* @author iron
* 文件导出
*/
public function actionExport()
{
$searchModel = new TakingSiteSearch();
$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' =>'Taking Sites'. "-" .date('Y-m-d H/i/s', time()),
'columns' => $searchModel->columns()
]);
}
}

6
backend/views/layouts/sidebar.php

@ -20,7 +20,7 @@ use iron\widgets\Menu;
['label' => '基础配置', 'url' => ['config/index', 'tag' => 'new']], ['label' => '基础配置', 'url' => ['config/index', 'tag' => 'new']],
] ]
], ],
['label' => '商品管理', 'url' => '#', 'icon' => 'far fa-archive', 'items' => [
['label' => '商品管理', 'url' => '#', 'icon' => 'far fa-box', 'items' => [
['label' => '后台商品分类', 'url' => ['/antgoods/category/index']], ['label' => '后台商品分类', 'url' => ['/antgoods/category/index']],
['label' => '规格管理', 'url' => ['/antgoods/attribute/index']], ['label' => '规格管理', 'url' => ['/antgoods/attribute/index']],
['label' => '前端商品分类', 'url' => ['/antgoods/shop-category/index']], ['label' => '前端商品分类', 'url' => ['/antgoods/shop-category/index']],
@ -31,6 +31,10 @@ use iron\widgets\Menu;
], ],
['label' => '订单管理', 'url' => '#', 'icon' => 'far fa-list-alt', 'items' => [ ['label' => '订单管理', 'url' => '#', 'icon' => 'far fa-list-alt', 'items' => [
['label' => '订单列表', 'url' => ['/order/index', 'tag' => 'new']], ['label' => '订单列表', 'url' => ['/order/index', 'tag' => 'new']],
],
],
['label' => '配送服务', 'url' => '#', 'icon' => 'far fa-shipping-fast', 'items' => [
['label' => '上门自提', 'url' => ['/taking-site/index']],
] ]
], ],

34
backend/views/taking-site/_form.php

@ -0,0 +1,34 @@
<?php
use yii\helpers\Html;
use yii\bootstrap4\ActiveForm;
/* @var $this yii\web\View */
/* @var $model common\models\ars\TakingSite */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="taking-site-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'province')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'city')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'area')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'address')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'is_default')->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/views/taking-site/_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 common\models\searchs\TakingSiteSearch */
/* @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/views/taking-site/create.php

@ -0,0 +1,18 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\ars\TakingSite */
$this->title = '创建 Taking Site';
$this->params['breadcrumbs'][] = ['label' => 'Taking Sites', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="taking-site-create">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

28
backend/views/taking-site/index.php

@ -0,0 +1,28 @@
<?php
use yii\helpers\Html;
use iron\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel common\models\searchs\TakingSiteSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Taking Sites';
$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" => "taking-site/deletes"
],
],
'columns' => $columns
]);
?>
</div>
</div>

19
backend/views/taking-site/update.php

@ -0,0 +1,19 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\ars\TakingSite */
$this->title = '编辑 Taking Site: ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Taking Sites', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update ';
?>
<div class="taking-site-update">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

35
backend/views/taking-site/view.php

@ -0,0 +1,35 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model common\models\ars\TakingSite */
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Taking Sites', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="taking-site-view">
<p>
<?= Html::a('返回列表', ['index'], ['class' => 'btn btn-success']) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'name',
'province',
'city',
'area',
'address:ntext',
'is_default',
'updated_at',
'created_at',
],
]) ?>
</div>

149
common/models/searchs/TakingSiteSearch.php

@ -0,0 +1,149 @@
<?php
namespace common\models\searchs;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yii\helpers\ArrayHelper;
use common\models\ars\TakingSite;
/**
* TakingSiteSearch represents the model behind the search form of `common\models\ars\TakingSite`.
*/
class TakingSiteSearch extends TakingSite
{
/**
* @return array
* 增加创建时间查询字段
*/
public function attributes()
{
return ArrayHelper::merge(['created_at_range'], parent::attributes());
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'is_default', 'updated_at', 'created_at'], 'integer'],
[['name', 'province', 'city', 'area', 'address'], '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',
'name',
'province',
'city',
'area',
//'address',
//'is_default',
//'updated_at',
//'created_at',
[
'class' => 'iron\grid\ActionColumn',
'align' => 'center',
],
];
}
/**
* @param $params
* @return ActiveDataProvider
* 不分页的所有数据
*/
public function allData($params)
{
$query = TakingSite::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 = TakingSite::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,
'is_default' => $this->is_default,
'updated_at' => $this->updated_at,
'created_at' => $this->created_at,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'province', $this->province])
->andFilterWhere(['like', 'city', $this->city])
->andFilterWhere(['like', 'area', $this->area])
->andFilterWhere(['like', 'address', $this->address]);
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;
}
}
Loading…
Cancel
Save