'火锅', 'B0001' => '中式正餐', 'B0002' => '西式正餐', 'B0003' => '日韩/东南亚菜', 'B0004' => '中式快餐', 'B0005' => '西式快餐', 'B0006' => '小吃/熟食', 'B0007' => '校园团餐', 'B0008' => '综合团餐', 'B0009' => '饮品/甜品', 'B0010' => '烘焙糕点', 'B0011' => '酒吧/清吧', 'B0012' => '咖啡馆/茶馆', 'B0200' => '宴会提供商' ]; public $store_id; public function getInfo() { // 商户信息 $store_id = get_store_id(); $store_info = Store::findOne(['id' => $store_id, 'is_delete' => 0]); if (!$store_info) { return [ 'code' => 1, 'msg' => '该店铺不存在' ]; } $food_config = Option::getFoodBookConfig(); $data = [ 'store' => [ 'name' => $food_config['name'], 'address' => $food_config['address'], 'phone' => $food_config['phone'], 'logo' => $store_info['logo'], 'open_time' => $food_config['open_time'], 'latitude' => explode(',', $store_info['coordinate'])[0] ?: '', 'longitude' => explode(',', $store_info['coordinate'])[1] ?: '' ], 'banner' => [], 'recommend_list' => [] ]; // 轮播图 $banners = Banner::find()->where(['store_id' => $this->store_id, 'type' => Banner::TYPE_FOOD, 'is_delete' => 0])->orderBy('sort desc')->asArray()->all(); if (!empty($banners)) { $temp = []; foreach ($banners as $value) { $temp[] = [ 'image' => $value['pic_url'], 'link' => $value['page_url'], 'title' => $value['title'] ]; } $data['banner'] = $temp; } // 推荐商品 $goods = FoodGoods::find()->where(['store_id' => $this->store_id, 'is_delete' => 0, 'status' => 1, 'is_recommend' => 1])->orderBy('sort desc')->asArray()->all(); if (!empty($goods)) { $temp = []; foreach ($goods as $value) { $temp[] = [ 'goods_pic' => Json::decode($value['cover_pic'])[0]['url'], 'desc' => $value['subtitle'], 'name' => $value['name'], 'price' => $value['price'], 'original_price' => $value['original_price'], 'id' => $value['id'], 'sales' => $value['virtual_sales'] ]; } $data['recommend_list'] = $temp; } return [ 'code' => 0, 'msg' => 'success', 'data' => $data ]; } public function getGoodsList() { // 分类 $cats = FoodCat::find()->where(['store_id' => $this->store_id, 'is_delete' => 0, 'is_show' => 1])->orderBy('sort desc')->select('id, name as title, desc as subtitle, pic_url as icon')->asArray()->all(); if (empty($cats)) { return [ 'code' => 1, 'msg' => '分类未找到' ]; } foreach ($cats as $key => &$cat) { $goods_list = FoodGoods::find()->where(['store_id' => $this->store_id, 'cat_id' => $cat['id'], 'is_delete' => 0, 'status' => 1]) ->select('id, name, cover_pic as goods_pic, subtitle as desc, price, original_price, attr, virtual_sales as sales')->orderBy('sort desc')->asArray()->all(); if (empty($goods_list)) { // 如果当前分类下无商品,不作展示 unset($cats[$key]); continue; } foreach ($goods_list as $key => $goods) { $goods_list[$key]['goods_pic'] = Json::decode($goods['goods_pic'])[0]['url']; $goods_list[$key]['attr'] = Json::decode($goods['attr']); } $cat['list'] = $goods_list; } sort($cats); return [ 'code' => 0, 'msg' => 'success', 'data' => $cats ]; } }