Browse Source

修改自提表省市区域和详细地址字段,改为必填

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
59d5cff63c
  1. 149
      backend/controllers/ExpressTemplateController.php
  2. 14
      common/models/ars/TakingSite.php
  3. 30
      console/migrations/m191203_030210_update_columns_province_city_area_in_table_ats_taking_site.php
  4. 22
      console/migrations/m191203_030911_update_column_address_in_table_ats_taking_site.php

149
backend/controllers/ExpressTemplateController.php

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

14
common/models/ars/TakingSite.php

@ -20,6 +20,14 @@ use yii\behaviors\TimestampBehavior;
*/ */
class TakingSite extends \yii\db\ActiveRecord class TakingSite extends \yii\db\ActiveRecord
{ {
//是否为默认
const IS_DEFAULT_NO = 0; //否
const IS_DEFAULT_YES = 1; //是
public static $isDefault = [
self::IS_DEFAULT_NO => '否',
self::IS_DEFAULT_YES => '是'
];
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -34,7 +42,7 @@ class TakingSite extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['name'], 'required'],
[['name', 'province', 'city', 'area', 'address'], 'required'],
[['address'], 'string'], [['address'], 'string'],
[['is_default'], 'integer'], [['is_default'], 'integer'],
[['name'], 'string', 'max' => 120], [['name'], 'string', 'max' => 120],
@ -53,8 +61,8 @@ class TakingSite extends \yii\db\ActiveRecord
'province' => '省份', 'province' => '省份',
'city' => '城市', 'city' => '城市',
'area' => '区域', 'area' => '区域',
'address' => '地址',
'is_default' => '是否为默认,1为默认',
'address' => '详细地址',
'is_default' => '是否为默认',
'updated_at' => '更新时间', 'updated_at' => '更新时间',
'created_at' => '创建时间', 'created_at' => '创建时间',
]; ];

30
console/migrations/m191203_030210_update_columns_province_city_area_in_table_ats_taking_site.php

@ -0,0 +1,30 @@
<?php
use yii\db\Migration;
/**
* Class m191203_030210_update_columns_province_city_area_in_table_ats_taking_site
*/
class m191203_030210_update_columns_province_city_area_in_table_ats_taking_site extends Migration
{
public function up()
{
$this->dropColumn('ats_taking_site', 'province');
$this->addColumn('ats_taking_site', 'province', $this->string(10)->notNull()->defaultValue(null)->comment('省份'));
$this->dropColumn('ats_taking_site', 'city');
$this->addColumn('ats_taking_site', 'city', $this->string(10)->notNull()->defaultValue(null)->comment('城市'));
$this->dropColumn('ats_taking_site', 'area');
$this->addColumn('ats_taking_site', 'area', $this->string(10)->notNull()->defaultValue(null)->comment('区域'));
}
public function down()
{
$this->dropColumn('ats_taking_site', 'province');
$this->addColumn('ats_taking_site', 'province', $this->string(10)->defaultValue(null)->comment('省份'));
$this->dropColumn('ats_taking_site', 'city');
$this->addColumn('ats_taking_site', 'city', $this->string(10)->defaultValue(null)->comment('城市'));
$this->dropColumn('ats_taking_site', 'area');
$this->addColumn('ats_taking_site', 'area', $this->string(10)->defaultValue(null)->comment('区域'));
return true;
}
}

22
console/migrations/m191203_030911_update_column_address_in_table_ats_taking_site.php

@ -0,0 +1,22 @@
<?php
use yii\db\Migration;
/**
* Class m191203_030911_update_column_address_in_table_ats_taking_site
*/
class m191203_030911_update_column_address_in_table_ats_taking_site extends Migration
{
public function up()
{
$this->dropColumn('ats_taking_site', 'address');
$this->addColumn('ats_taking_site', 'address', $this->text()->notNull()->comment('地址'));
}
public function down()
{
$this->dropColumn('ats_taking_site', 'address');
$this->addColumn('ats_taking_site', 'address', $this->text()->comment('地址'));
return true;
}
}
Loading…
Cancel
Save