<?php
|
|
namespace app\controller;
|
|
|
|
use app\BaseController;
|
|
use app\model\Product;
|
|
|
|
class Menu extends BaseController
|
|
{
|
|
// GET api/menu/categories — 获取分类列表
|
|
public function categories()
|
|
{
|
|
$categories = Product::where('status', 1)
|
|
->field('category')
|
|
->group('category')
|
|
->order('sort_order', 'asc')
|
|
->column('category');
|
|
|
|
return json(['code' => 0, 'data' => $categories, 'msg' => 'ok']);
|
|
}
|
|
|
|
// GET api/menu/products?cate=经典鸡尾酒 — 按分类获取商品(不含recipe)
|
|
public function products()
|
|
{
|
|
$cate = $this->request->get('cate', '');
|
|
$query = Product::where('status', 1)->order('sort_order', 'asc');
|
|
|
|
if (!empty($cate) && $cate !== 'all') {
|
|
$query->where('category', $cate);
|
|
}
|
|
|
|
$products = $query->field('id,category,name,en,emoji,image_url,price,original_price,alc,desc')
|
|
->select()
|
|
->toArray();
|
|
|
|
return json(['code' => 0, 'data' => $products, 'msg' => 'ok']);
|
|
}
|
|
|
|
// GET api/menu/product?id=5 — 商品详情(不含recipe)
|
|
public function detail()
|
|
{
|
|
$id = $this->request->get('id', 0);
|
|
$product = Product::where('status', 1)
|
|
->field('id,category,name,en,emoji,image_url,price,original_price,alc,desc')
|
|
->find($id);
|
|
|
|
if (!$product) {
|
|
return json(['code' => -1, 'data' => null, 'msg' => '商品不存在']);
|
|
}
|
|
|
|
return json(['code' => 0, 'data' => $product->toArray(), 'msg' => 'ok']);
|
|
}
|
|
}
|