116 lines
3.1 KiB
PHP
116 lines
3.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-5
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\admin\controllers;
|
|
use app\models\Detection;
|
|
use app\models\Store;
|
|
use app\modules\admin\behaviors\LoginBehavior;
|
|
use app\modules\admin\models\detection\DetectionActionForm;
|
|
use app\modules\admin\models\detection\DetectionEditForm;
|
|
use app\modules\admin\models\detection\DetectionListForm;
|
|
|
|
class DetectionController extends Controller
|
|
{
|
|
public function behaviors()
|
|
{
|
|
return array_merge(parent::behaviors(), [
|
|
'login' => [
|
|
'class' => LoginBehavior::className(),
|
|
],
|
|
]);
|
|
}
|
|
|
|
//列表
|
|
public function actionIndex()
|
|
{
|
|
if(\Yii::$app->request->isAjax){
|
|
$form = new DetectionListForm();
|
|
$form->attributes = \Yii::$app->request->get();
|
|
if(\Yii::$app->admin->identity->user->store){
|
|
$form->store_id = \Yii::$app->admin->identity->user->store->id;
|
|
}
|
|
$data = $form->search();
|
|
return $this->responseHandler($data);
|
|
|
|
}
|
|
$store = Store::find()->select('id,name')->where(['is_delete' => 0])->asArray()->all();
|
|
return $this->render('index',[
|
|
'store' => $store
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
//添加、编辑
|
|
public function actionEdit($id = 0)
|
|
{
|
|
$is_store = \Yii::$app->admin->identity->user->store;
|
|
$model = Detection::findOne([
|
|
'id' => $id,
|
|
'is_delete' => 0
|
|
]);
|
|
if($model == null)
|
|
$model = new Detection();
|
|
if(\Yii::$app->request->isPost){
|
|
$form = new DetectionEditForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
if($is_store){
|
|
$form->store_id = \Yii::$app->admin->identity->user->store->id;
|
|
}
|
|
$form->model = $model;
|
|
$data = $form->edit();
|
|
return $this->responseHandler($data);
|
|
|
|
}
|
|
$store = Store::find()->select('id,name')->where(['is_delete' => 0])->asArray()->all();
|
|
$return_url = \Yii::$app->request->referrer;
|
|
return $this->render('edit',[
|
|
'model' => $model,
|
|
'return_url' => $return_url,
|
|
'store' => $store,
|
|
]);
|
|
|
|
|
|
}
|
|
|
|
//删除
|
|
public function actionDelete()
|
|
{
|
|
if(!\Yii::$app->request->isPost){
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
$form = new DetectionActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->delete();
|
|
return $this->responseHandler($data);
|
|
|
|
|
|
}
|
|
|
|
//解绑
|
|
public function actionUntie()
|
|
{
|
|
if(!\Yii::$app->request->isPost){
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
$form = new DetectionActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->untie();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
|
|
} |