58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace admin\controllers\base;
|
|
|
|
use admin\components\BaseAdminController;
|
|
use common\helpers\ArrayHelper;
|
|
use common\models\oldDb\Region;
|
|
use yii\db\Exception;
|
|
|
|
class RegionController extends BaseAdminController
|
|
{
|
|
/**
|
|
* @doc-name 快递费--地区列表
|
|
*/
|
|
public function actionRegionList()
|
|
{
|
|
$get = \Yii::$app->request->get();
|
|
|
|
$query = Region::find()->where(['level'=>1]);
|
|
$this->field = [
|
|
Region::class => [
|
|
'id', 'name', 'pid', 'level', 'express_fee'
|
|
]
|
|
];
|
|
|
|
return $this->create($query, $get);
|
|
}
|
|
|
|
/**
|
|
* @doc-name 编辑快递费
|
|
* @doc-param int id id
|
|
* @doc-param float express_fee 快递费
|
|
*/
|
|
public function actionEditFee()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
$this->requestValidate($post, [
|
|
[['id', 'express_fee'], 'required'],
|
|
]);
|
|
|
|
$Region = Region::find()->where(['id' => $post['id']])->one();
|
|
if (!$Region) throw new Exception('地区不存在');
|
|
$Region->express_fee = $post['express_fee'];
|
|
if (!$Region->saveOrFail()) {
|
|
throw new Exception('修改失败');
|
|
};
|
|
return ['修改成功'];
|
|
}
|
|
/**
|
|
* @doc-name 地区列表
|
|
*/
|
|
public function actionAllRegionList()
|
|
{
|
|
$Region = Region::find()->asArray()->all();
|
|
return ArrayHelper::list_to_tree($Region, 'id', 'pid', 'children');
|
|
|
|
}
|
|
} |