Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/trieyouth/basic into dcc
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.lock
座位的添加
  • Loading branch information
cxqz520 committed Dec 23, 2015
1 parent 346c8ee commit b0f7037
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
3 changes: 1 addition & 2 deletions controllers/DishController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function actionAdd(){

$dish = new Dish();
$res = Yii::$app->request;
$dish->s_id = '1@qq.com';
$dish->s_id = Yii::$app->user->id;
$dish->dish_name = $res->post('dish_name');
$dish->price = $res->post('price');
$dish->discount = $res->post('discount');
Expand Down Expand Up @@ -55,7 +55,6 @@ public function actionUpdate(){

$id = Yii::$app->request->post('dish_id');
$res = Yii::$app->request;
$dish = new Dish();
$dish = Dish::findOne($id);
$dish->dish_name = $res->post('dish_name');
$dish->price = $res->post('price');
Expand Down
35 changes: 34 additions & 1 deletion controllers/SeatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,50 @@ class SeatController extends Controller{
*
*/
public function actionAdd(){

$seat = new Seat();
$res = Yii::$app->request;
//$seat->s_id = Yii::$app->user->id;
$seat->s_id = '1@qq.com';
$seat->id = $res->post('id');
$seat->count = $res->post('count');
$seat->statue = 0;
if($seat->validate()&&$seat->save()){
return 'success';
}else{
return 'fales';
}
}

/**
*
*/
public function actionDel(){

$id = Yii::$app->request->post('id');
$s_id = Yii::$app->user->id;
Seat::find()->where(['s_id'=>$s_id,'id'=>$id])->one()->delete();
}

/**
*
*/
public function actionUpdate(){

$id = Yii::$app->request->post('id');
$s_id = Yii::$app->user->id;
$res = Yii::$app->request;
$seat = Seat::find()->where(['s_id'=>$s_id,'id'=>$id])->one();
$seat->id = $res->post('id');
$seat->count = $res->post('count');
$seat->desc = $res->post('desc');
if ($seat === null) {
echo 'no data';
throw new NotFoundHttpException;
}
if ($seat->save()) {
echo 'success';
// 获取用户输入的数据,验证并保存
}
}


Expand All @@ -42,5 +71,9 @@ public function actionUpdate(){
*/
public function actionDisplay(){

$s_id = Yii::$app->user->id;
$dishes = Seat::find()->where(['s_id'=>$s_id])->all();
return json_encode($dishes);
}

}
23 changes: 19 additions & 4 deletions models/Seat.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,28 @@

class Seat extends ActiveRecord{

public function tableName(){
return 'seat';
}

public function rule(){
return [
[],
[['id','s_id','status','count'],'required'],
['s_id','email'],
['status','integer'],
['count','integer'],
['desc','string','max'=>200],
];
}

/**
*检验是否有重复的位置
*/
public function validateId(){
if(!$this->hasErrors()){
if(isset($this->id)){
$seat = $this->find()->where(['s_id'=>$this->s_id,'id'=>$this->id])->one();
if(isset($seat)){
$this->addError('座位已存在');
}
}
}
}
}

0 comments on commit b0f7037

Please sign in to comment.