133 lines
4.7 KiB
PHP
133 lines
4.7 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: chatfeed
|
|
* Date: 2022/5/21
|
|
* Time: 11:50 AM
|
|
*/
|
|
|
|
namespace admin\controllers\system;
|
|
|
|
use admin\components\BaseAdminController;
|
|
use admin\components\UI\Form;
|
|
use admin\components\UI\Table;
|
|
use admin\exceptions\ApiException;
|
|
use admin\models\search\CommonSearch;
|
|
use app\forms\common\CommonPostageRules;
|
|
use common\models\oldDb\DistrictArr;
|
|
use common\models\oldDb\RefundAddress;
|
|
use yii\db\ActiveQuery;
|
|
use yii\web\NotFoundHttpException;
|
|
|
|
class RefundAddressController extends BaseAdminController
|
|
{
|
|
public function actionIndex(){
|
|
$table = new Table(new RefundAddress());
|
|
//$table->model();
|
|
$table->title('退货地址');
|
|
$table->key('id');
|
|
$table->eventName(md5(get_called_class()));//设置事件名,后面更改数据对应
|
|
$table->url(\Yii::$app->urlManager->createUrl("system/refund-address/list"));
|
|
$table->filter('关键字', 'keyword',false)->text('请输入收件人姓名或联系方式')->quick();
|
|
$table->action()->button('添加', $this->createUrl('system/refund-address/edit'))->type('dialog');
|
|
$table->column('ID','id');
|
|
$table->column('收件人姓名','name');
|
|
$table->column('详细地址','full_address');
|
|
$table->column('备注','remark');
|
|
$column = $table->column('操作')->width(200);
|
|
$column->link('编辑', $this->createUrl('system/refund-address/edit'), ['id' => 'id'])->type('dialog');
|
|
$column->link('删除', $this->createUrl('system/refund-address/del'), ['id' => 'id'])->type('ajax', ['method' => 'post']);
|
|
return $table->renderArray();
|
|
}
|
|
public function actionEdit(){
|
|
$id = (int)$this->get('id');
|
|
$config = $this->findModel($id);
|
|
$form = new Form($config->getAttributes(['id','name','mobile','address_id','address_detail','remark']),false);
|
|
$form->title('配置信息');
|
|
$form->action($this->createUrl('system/refund-address/edit-save'));
|
|
$arr = DistrictArr::getArr();
|
|
unset($arr['1']);
|
|
$form->card(function (/** @var Form $form */$form) use($arr) {
|
|
$form->text("收件人姓名",'name');
|
|
$form->text("联系方式",'mobile');
|
|
$form->cascader('省市区','address_id',$arr);
|
|
$form->textarea('详细地址','address_detail');
|
|
$form->textarea('备注','remark');
|
|
});
|
|
return $form->renderArray();
|
|
}
|
|
|
|
public function actionDistrict()
|
|
{
|
|
$district_arr = DistrictArr::getArr();
|
|
$arr = DistrictArr::getList($district_arr);
|
|
$str = str_replace('list','children',json_encode($arr));
|
|
$arr = json_decode($str,true);
|
|
return $arr;
|
|
}
|
|
|
|
|
|
public function actionEditSave(){
|
|
$id = $this->get('id');
|
|
$model = RefundAddress::findOne([
|
|
'is_delete' => 0,
|
|
'mall_id' => \Yii::$app->mallId,
|
|
'id' => $id
|
|
]);
|
|
|
|
if (!$model) {
|
|
$model = new RefundAddress();
|
|
$model->mall_id = \Yii::$app->mallId;
|
|
}
|
|
$model->load($this->post(),'');
|
|
if($model->save()){
|
|
$this->callbackEvent([],'id','refresh');
|
|
return [];
|
|
}else{
|
|
return ['error'=>$model->getErrors()];
|
|
}
|
|
}
|
|
|
|
public function actionDel(){
|
|
$id = $this->get('id');
|
|
if(RefundAddress::updateAll(['is_delete'=>1],['id'=>$id,'mall_id'=>\Yii::$app->mallId])){
|
|
$this->callbackEvent([],'id','refresh');
|
|
return [];
|
|
}else{
|
|
throw new ApiException("删除失败");
|
|
}
|
|
}
|
|
|
|
public function actionList()
|
|
{
|
|
$commonSearch = new CommonSearch(['keyword']);
|
|
$commonSearch->setQuery(RefundAddress::find()
|
|
->select(['id', 'name','address','address_detail','remark'])
|
|
->where(['mall_id'=>\Yii::$app->mallId])->andWhere(['is_delete'=>0]));
|
|
$commonSearch->additionRules = [
|
|
['keyword', 'string']
|
|
];
|
|
$commonSearch->bindFilter(function(/** @var ActiveQuery $q */ $q) {
|
|
$q->andFilterWhere(['like','name',$this->keyword]);
|
|
});
|
|
$this->field = [
|
|
RefundAddress::class =>[
|
|
'id','name','full_address','remark'
|
|
]
|
|
];
|
|
return $commonSearch->search($this->get());
|
|
|
|
}
|
|
protected function findModel($id)
|
|
{
|
|
if ($id == 0) {
|
|
return new RefundAddress();
|
|
}
|
|
if (($model = RefundAddress::findOne($id)) !== null) {
|
|
return $model;
|
|
} else {
|
|
throw new NotFoundHttpException('The requested page does not exist.');
|
|
}
|
|
}
|
|
}
|