...
|
...
|
@@ -2,12 +2,24 @@ |
|
|
namespace backend\controllers;
|
|
|
|
|
|
use Yii;
|
|
|
use backend\components\Pagination;
|
|
|
use yii\helpers\ArrayHelper;
|
|
|
|
|
|
/**
|
|
|
* Live controller
|
|
|
*/
|
|
|
class ProductController extends BaseController
|
|
|
{
|
|
|
|
|
|
public function init()
|
|
|
{
|
|
|
parent::init();
|
|
|
|
|
|
$this->main_id = 'live';
|
|
|
$this->sub_id = 'room';
|
|
|
$this->sub_title = '商品管理';
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 房间商品列表
|
|
|
* @return type
|
...
|
...
|
@@ -18,7 +30,111 @@ class ProductController extends BaseController |
|
|
return $this->redirect($this->_refer);
|
|
|
}
|
|
|
|
|
|
return $this->render('list');
|
|
|
$model = \app\models\RoomProduct::find()->where(['room_id'=>$room_id]);
|
|
|
|
|
|
$count = clone $model;
|
|
|
$pagination = new Pagination(['totalCount' =>$count->count()]);
|
|
|
$list = $model
|
|
|
->offset($pagination->offset)->limit($pagination->limit)
|
|
|
->orderBy(['sort'=>SORT_ASC,'create_time'=>SORT_DESC])
|
|
|
->all();
|
|
|
|
|
|
return $this->render('list',[
|
|
|
'room'=> \app\models\Room::findOne(['room_id'=>$room_id]),
|
|
|
'pagination'=>$pagination,
|
|
|
'list'=>$list,
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 添加商品
|
|
|
* @return type
|
|
|
*/
|
|
|
public function actionAdd()
|
|
|
{
|
|
|
if (!$room_id = Yii::$app->getRequest()->getQueryParam('id')){
|
|
|
return $this->redirect($this->_refer);
|
|
|
}
|
|
|
|
|
|
$model = new \app\models\RoomProduct;
|
|
|
if (Yii::$app->getRequest()->isPost){
|
|
|
$post = Yii::$app->getRequest()->post();
|
|
|
$model->room_id = $room_id;
|
|
|
if ($model->load($post,'') && $model->save()){
|
|
|
Yii::$app->session->setFlash('success', '创建成功。');
|
|
|
return $this->redirect($this->_refer);
|
|
|
}else{
|
|
|
Yii::$app->session->setFlash('error', '创建失败。');
|
|
|
$model->setAttributes($post);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $this->render('edit',[
|
|
|
'model'=>$model,
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 编辑商品
|
|
|
* @return type
|
|
|
*/
|
|
|
public function actionEdit()
|
|
|
{
|
|
|
if (!$id = Yii::$app->getRequest()->getQueryParam('id')){
|
|
|
return $this->redirect($this->_refer);
|
|
|
}
|
|
|
|
|
|
if (!$model = \app\models\RoomProduct::findOne($id)){
|
|
|
Yii::$app->session->setFlash('error', '找不到该商品');
|
|
|
return $this->redirect($this->_refer);
|
|
|
}
|
|
|
|
|
|
if (Yii::$app->getRequest()->isPost){
|
|
|
$post = Yii::$app->getRequest()->post();
|
|
|
if ($model->load($post,'') && $model->save()){
|
|
|
Yii::$app->session->setFlash('success', '编辑成功。');
|
|
|
$model->refresh();
|
|
|
}else{
|
|
|
Yii::$app->session->setFlash('error', '编辑失败。');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $this->render('edit',[
|
|
|
'model'=>$model,
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 商品操作
|
|
|
* @return type
|
|
|
*/
|
|
|
public function actionOperate()
|
|
|
{
|
|
|
if (!$id = Yii::$app->getRequest()->getQueryParam('id')){
|
|
|
return $this->redirect($this->_refer);
|
|
|
}
|
|
|
if (!$type = Yii::$app->getRequest()->getQueryParam('type')){
|
|
|
return $this->redirect($this->_refer);
|
|
|
}
|
|
|
|
|
|
if (!$model = \app\models\RoomProduct::findOne($id)){
|
|
|
Yii::$app->session->setFlash('error', '找不到该商品');
|
|
|
return $this->redirect($this->_refer);
|
|
|
}
|
|
|
|
|
|
switch ($type){
|
|
|
case 'del'://删除
|
|
|
$r = $model->delete();
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
if (!empty($r)){
|
|
|
Yii::$app->session->setFlash('success', '操作成功');
|
|
|
}else{
|
|
|
Yii::$app->session->setFlash('error', '操作失败');
|
|
|
}
|
|
|
|
|
|
return $this->redirect($this->_refer);
|
|
|
}
|
|
|
} |
...
|
...
|
|