/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $menuOption = "analitics"; $restaurant = Restaurant::where('user_id', Auth::user()->id)->first(); $dishes = Dish::where('restaurant_id', $restaurant->id)->get(); $categories = Category::where('restaurant_id', $restaurant->id)->get(); $dishesIds = Dish::where('restaurant_id', $restaurant->id)->lists('id'); $categoriesIds = Category::where('restaurant_id', $restaurant->id)->lists('id'); $dishesAnalytics = Analitic::where('related_table', 'dishes')->whereIn('related_id', $dishesIds)->get(); $firstDay = Analitic::where('related_table', 'dishes')->whereIn('related_id', $dishesIds)->min('date'); $categoriesAnalytics = Analitic::where('related_table', 'categories')->whereIn('related_id', $categoriesIds)->get(); return view('backend.pages.analitics')->with(compact('dishesAnalytics', 'menuOption')); }
public function actionAdddish() { //Yii::$app->session->destroy(); $id = Yii::$app->request->post('id'); $dInfo = Dish::findOne($id)->attributes; if (empty($dInfo) || count($dInfo) < 0) { exit('no dish'); } else { $dInfo["num"] = 1; if (isset($_SESSION["dishlist"][$id])) { $num = $_SESSION["dishlist"][$id]["num"]; $num++; $_SESSION["dishlist"][$id]["num"] = $num; } else { $_SESSION["dishlist"][$id] = $dInfo; } } return json_encode($_SESSION["dishlist"]); }
/** *修改 传入菜品id还有需要修改的信息 */ public function actionUpdate() { $id = Yii::$app->request->post('dish_id'); $res = Yii::$app->request; $dish = Dish::findOne($id); $dish->dish_name = $res->post('dish_name'); $dish->price = $res->post('price'); $dish->discount = $res->post('discount'); $dish->advice = $res->post('advice'); $dish->desc = $res->post('desc'); $dish->p_id = $res->post('p_id'); if ($dish === null) { throw new NotFoundHttpException(); } if ($dish->save()) { echo 'success'; // 获取用户输入的数据,验证并保存 } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $dish = Dish::find($id); $dish->categories()->detach(); $dish->delete(); return redirect('admin/dishes'); }