From 711daaf39826f8d26c5c31170761f916ea3d396a Mon Sep 17 00:00:00 2001 From: weigang Date: Sat, 29 Aug 2020 21:33:36 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=95=B0=E6=8D=AE=E3=80=81?= =?UTF-8?q?=E9=A6=96=E9=A1=B5tab=E6=95=B0=E6=8D=AE=E3=80=81=E5=AE=9A?= =?UTF-8?q?=E4=BD=8D=E8=8E=B7=E5=8F=96=E6=9C=80=E8=BF=91=E5=B8=82=E5=9C=BA?= =?UTF-8?q?=E9=9C=80=E6=B1=82=E6=95=B4=E7=90=86=E5=92=8C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?mock=E3=80=81=E6=8E=A5=E5=8F=A3=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/v3/ActivityType.php | 28 ++++ app/Constants/v3/ErrorCode.php | 4 + app/Constants/v3/OrderState.php | 5 + app/Constants/v3/OrderType.php | 5 + app/Constants/v3/Payment.php | 5 + app/Constants/v3/Tabs.php | 31 ++++ .../v3/GoodsRecommendController.php | 122 ++++++++++++++ app/Controller/v3/HomeController.php | 157 ++++++++++++++++++ app/Controller/v3/LocationController.php | 39 +++++ app/Middleware/Auth/UserMiddleware.php | 42 +++++ config/config.php | 5 +- config/routes.php | 14 +- 12 files changed, 455 insertions(+), 2 deletions(-) create mode 100644 app/Constants/v3/ActivityType.php create mode 100644 app/Constants/v3/Tabs.php create mode 100644 app/Controller/v3/GoodsRecommendController.php create mode 100644 app/Controller/v3/HomeController.php create mode 100644 app/Controller/v3/LocationController.php create mode 100644 app/Middleware/Auth/UserMiddleware.php diff --git a/app/Constants/v3/ActivityType.php b/app/Constants/v3/ActivityType.php new file mode 100644 index 0000000..1ef89e7 --- /dev/null +++ b/app/Constants/v3/ActivityType.php @@ -0,0 +1,28 @@ + [ + [ + 'goods' => [ + 'id' => 1, + 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png', + 'name' => '【优质】大白菜11', + 'spec' => [ + ['key' => '净含量', 'value' => '500g'] + ], + 'tag' => ['限时', '折扣'], + 'original_price' => 50.5, + 'price' => 25.25, + 'inventory' => 10, + 'month_sales' => 20, + 'total_sales' => 20, + 'cart_num' => 0, + 'is_effective' => 2, + 'noneffective_note' => '已卖完', + ], + 'store' => ['id' => 111, 'logo' => '', 'name' => '我是一个商家'] + ], + + ], + Tabs::APPLET_INDEX_NEW => [ + [ + 'goods' => [ + 'id' => 2, + 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png', + 'name' => '【优质】大白菜11', + 'spec' => [ + ['key' => '净含量', 'value' => '500g'] + ], + 'tag' => ['限时', '折扣'], + 'original_price' => 50.5, + 'price' => 25.25, + 'inventory' => 10, + 'month_sales' => 20, + 'total_sales' => 20, + 'cart_num' => 0, + 'is_effective' => 2, + 'noneffective_note' => '已卖完', + ], + 'store' => ['id' => 222, 'logo' => '', 'name' => '我是一个商家222'] + ], + ], + Tabs::APPLET_INDEX_FRESH => [ + [ + 'goods' => [ + 'id' => 3, + 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png', + 'name' => '【优质】大白菜11', + 'spec' => [ + ['key' => '净含量', 'value' => '500g'] + ], + 'tag' => ['限时', '折扣'], + 'original_price' => 50.5, + 'price' => 25.25, + 'inventory' => 10, + 'month_sales' => 20, + 'total_sales' => 20, + 'cart_num' => 0, + 'is_effective' => 2, + 'noneffective_note' => '已卖完', + ], + 'store' => ['id' => 333, 'logo' => '', 'name' => '我是一个商家333'] + ], + ], + Tabs::APPLET_INDEX_OFFICE => [ + [ + 'goods' => [ + 'id' => 4, + 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png', + 'name' => '【优质】大白菜11', + 'spec' => [ + ['key' => '净含量', 'value' => '500g'] + ], + 'tag' => ['限时', '折扣'], + 'original_price' => 50.5, + 'price' => 25.25, + 'inventory' => 10, + 'month_sales' => 20, + 'total_sales' => 20, + 'cart_num' => 0, + 'is_effective' => 2, + 'noneffective_note' => '已卖完', + ], + 'store' => ['id' => 444, 'logo' => '', 'name' => '我是一个商家444'] + ], + ] + ]; + + return $this->success([ + 'tab_data' => $tabsData[$this->request->post('tab', 'applet_index_recommend')] + ]); + } +} \ No newline at end of file diff --git a/app/Controller/v3/HomeController.php b/app/Controller/v3/HomeController.php new file mode 100644 index 0000000..67df996 --- /dev/null +++ b/app/Controller/v3/HomeController.php @@ -0,0 +1,157 @@ +success([ + 'banners' => [ + [ + 'id' => 2, + 'img' => 'https://store.lanzu.vip/attachment/images/2/2020/06/nfXxIhEgH71hcSxSz2hHnaaEaF1g3A.jpg', + 'title' => '懒族生活', + 'subtitle' => '满足您的美味生活', + 'redirect_type' => '', + 'redirect_url' => '', + ], + [ + 'id' => 3, + 'img' => 'http://lanzutest.lanzulive.com/attachment/images/2/2020/08/PY55Y3Mz17yJo17rv1Z7vImX1V5159.jpg', + 'title' => '鲜菜有爱', + 'subtitle' => '很实在', + 'redirect_type' => 'page', + 'redirect_url' => '/pages/index', + ], + ], + 'categories' => [ + ['id' => 1, 'icon' => config('alioss.img_host').'/attachment/types/卤菜.png', 'name' => '卤菜'], + ['id' => 2, 'icon' => config('alioss.img_host').'/attachment/types/水果.png', 'name' => '水果'], + ['id' => 3, 'icon' => config('alioss.img_host').'/attachment/types/肉.png', 'name' => '肉'], + ['id' => 4, 'icon' => config('alioss.img_host').'/attachment/types/蔬菜.png', 'name' => '蔬菜'], + ['id' => 5, 'icon' => config('alioss.img_host').'/attachment/types/蔬菜.png', 'name' => '蔬菜'], + ['id' => 6, 'icon' => config('alioss.img_host').'/attachment/types/肉.png', 'name' => '肉'], + ['id' => 7, 'icon' => config('alioss.img_host').'/attachment/types/水果.png', 'name' => '水果'], + ['id' => 8, 'icon' => config('alioss.img_host').'/attachment/types/卤菜.png', 'name' => '卤菜'], + ], + 'activity' => [ + 'type' => ActivityType::FLASH_SALE, + 'goods' => [ + [ + 'id' => 1, + 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png', + 'name' => '【优质】大白菜', + 'spec' => [ + ['key' => '净含量', 'value' => '500g'] + ], + 'original_price' => 50.5, + 'price' => 25.25, + 'inventory' => 0, + 'month_sales' => 20, + 'total_sales' => 20, + 'cart_num' => 0, + 'is_effective' => 1, + 'noneffective_note' => '已抢光', + 'total_seconds' => $seconds, + 'days' => $days, + 'hours' => $hours, + 'minutes' => $minutes, + 'seconds' => $leftSeconds, + ],[ + 'id' => 1, + 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png', + 'name' => '【优质】大白菜', + 'spec' => [ + ['key' => '净含量', 'value' => '500g'] + ], + 'original_price' => 50.5, + 'price' => 25.25, + 'inventory' => 0, + 'month_sales' => 20, + 'total_sales' => 20, + 'cart_num' => 0, + 'is_effective' => 1, + 'noneffective_note' => '已抢光', + 'total_seconds' => $seconds, + 'days' => $days, + 'hours' => $hours, + 'minutes' => $minutes, + 'seconds' => $leftSeconds, + ],[ + 'id' => 1, + 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png', + 'name' => '【优质】大白菜', + 'spec' => [ + ['key' => '净含量', 'value' => '500g'] + ], + 'original_price' => 50.5, + 'price' => 25.25, + 'inventory' => 0, + 'month_sales' => 20, + 'total_sales' => 20, + 'cart_num' => 0, + 'is_effective' => 1, + 'noneffective_note' => '已抢光', + 'total_seconds' => $seconds, + 'days' => $days, + 'hours' => $hours, + 'minutes' => $minutes, + 'seconds' => $leftSeconds, + ],[ + 'id' => 1, + 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png', + 'name' => '【优质】大白菜', + 'spec' => [ + ['key' => '净含量', 'value' => '500g'] + ], + 'original_price' => 50.5, + 'price' => 25.25, + 'inventory' => 0, + 'month_sales' => 20, + 'total_sales' => 20, + 'cart_num' => 0, + 'is_effective' => 1, + 'noneffective_note' => '已抢光', + 'total_seconds' => $seconds, + 'days' => $days, + 'hours' => $hours, + 'minutes' => $minutes, + 'seconds' => $leftSeconds, + ], + ] + ], + 'tabs' => [ + ['tab' => Tabs::APPLET_INDEX_RECOMMEND, 'title' => '推荐', 'subtitle' => '猜你喜欢', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], + ['tab' => Tabs::APPLET_INDEX_NEW, 'title' => '懒族上新', 'subtitle' => '买点不一样', 'badge' => '限时', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], + ['tab' => Tabs::APPLET_INDEX_FRESH, 'title' => '实时鲜货', 'subtitle' => '今天辛苦了', 'badge' => '好新鲜', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], + ['tab' => Tabs::APPLET_INDEX_OFFICE, 'title' => '上班带餐', 'subtitle' => '轻奢快手菜', 'badge' => '不慌', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], + ] + ]); + + } +} \ No newline at end of file diff --git a/app/Controller/v3/LocationController.php b/app/Controller/v3/LocationController.php new file mode 100644 index 0000000..a70384f --- /dev/null +++ b/app/Controller/v3/LocationController.php @@ -0,0 +1,39 @@ +success([ + 'market' => [ + 'id' => 1, + 'name' => '海尔青啤', + 'province_id' => 1, + 'province_name' => '广西', + 'city_id' => 2, + 'city_name' => '南宁市', + 'area_id' => 3, + 'area_name' => '良庆区', + 'address' => '海尔青啤广场', + 'lng' => '108.383566', + 'lat' => '22.759946', + ] + ]); + } +} \ No newline at end of file diff --git a/app/Middleware/Auth/UserMiddleware.php b/app/Middleware/Auth/UserMiddleware.php new file mode 100644 index 0000000..d843008 --- /dev/null +++ b/app/Middleware/Auth/UserMiddleware.php @@ -0,0 +1,42 @@ +handle($request); + } + + // 校验 + if (!$this->checkLogin()) { + + $content = [ + "status" => 'ok', + "code" => 9002, + "result" => [], + "message" => '用户登录已失效' + ]; + + return $this->response->json($content); + } + + return $handler->handle($request); + } + + private function checkLogin() + { + return true; + } +} \ No newline at end of file diff --git a/config/config.php b/config/config.php index d416f7f..66529cf 100644 --- a/config/config.php +++ b/config/config.php @@ -47,5 +47,8 @@ return [ 'regionid' => env('ALI_SMS_REGION_ID', ''), 'product' => env('ALI_SMS_PRODUCT', ''), 'host' => env('ALI_SMS_HOST', ''), - ] + ], + 'alioss' => [ + 'img_host' => env('OSS_IMG_HOST', ''), + ], ]; diff --git a/config/routes.php b/config/routes.php index 659680f..d582d7e 100644 --- a/config/routes.php +++ b/config/routes.php @@ -73,4 +73,16 @@ Router::addGroup('/wechat/',function () { Router::post('notify/wxminionline', 'App\Controller\NotifyController@wxminiOnline'); Router::post('notify/wxminioffline', 'App\Controller\NotifyController@wxminiOffline'); Router::post('notify/wxpayrefund', 'App\Controller\NotifyPayRefundController@wxPayRefund'); -}); \ No newline at end of file +}); + +// 不需要登录的路由 +Router::addGroup('/v3/', function () { + Router::post('location/getNearestMarket', 'App\Controller\v3\LocationController@getNearestMarket'); + Router::post('home/appletIndex', 'App\Controller\v3\HomeController@appletIndex'); + Router::post('goodsRecommend/getByTabsForAppletIndex', 'App\Controller\v3\GoodsRecommendController@getByTabsForAppletIndex'); +},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]); + +// 需要登录的路由 +Router::addGroup('/v3/', function () { + +},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]); \ No newline at end of file