Browse Source

Merge branch 'phoenix' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into phoenix

# Conflicts:
#	config/routes.php
master
Lemon 6 years ago
parent
commit
381110b308
  1. 28
      app/Constants/v3/ActivityType.php
  2. 4
      app/Constants/v3/ErrorCode.php
  3. 5
      app/Constants/v3/OrderState.php
  4. 5
      app/Constants/v3/OrderType.php
  5. 5
      app/Constants/v3/Payment.php
  6. 31
      app/Constants/v3/Tabs.php
  7. 122
      app/Controller/v3/GoodsRecommendController.php
  8. 157
      app/Controller/v3/HomeController.php
  9. 39
      app/Controller/v3/LocationController.php
  10. 5
      config/config.php
  11. 1
      config/routes.php

28
app/Constants/v3/ActivityType.php

@ -0,0 +1,28 @@
<?php
namespace App\Constants\v3;
use Hyperf\Constants\AbstractConstants;
class ActivityType extends AbstractConstants
{
/**
* @Message("")
*/
const NONE = 'none';
/**
* @Message("限时抢购")
*/
const FLASH_SALE = 'flash_sale';
/**
* @Message("限时团购")
*/
const GROUP_BUY = 'group_buy';
/**
* @Message("新品推荐")
*/
const NEW_PRODUCT = 'new_product';
}

4
app/Constants/v3/ErrorCode.php

@ -27,4 +27,8 @@ class ErrorCode extends AbstractConstants
/************************************/
/* 用户相关 701-750 */
/************************************/
/************************************/
/* 定位相关 751-800 */
/************************************/
}

5
app/Constants/v3/OrderState.php

@ -4,6 +4,11 @@ namespace App\Constants\v3;
use Hyperf\Constants\AbstractConstants;
/**
* 订单状态
* Class OrderState
* @package App\Constants\v3
*/
class OrderState extends AbstractConstants
{
/**

5
app/Constants/v3/OrderType.php

@ -4,6 +4,11 @@ namespace App\Constants\v3;
use Hyperf\Constants\AbstractConstants;
/**
* 订单类型
* Class OrderType
* @package App\Constants\v3
*/
class OrderType extends AbstractConstants
{
/**

5
app/Constants/v3/Payment.php

@ -4,6 +4,11 @@ namespace App\Constants\v3;
use Hyperf\Constants\AbstractConstants;
/**
* 支付相关
* Class Payment
* @package App\Constants\v3
*/
class Payment extends AbstractConstants
{
/**

31
app/Constants/v3/Tabs.php

@ -0,0 +1,31 @@
<?php
namespace App\Constants\v3;
/**
* 选项卡标识
* Class Tabs
* @package App\Constants\v3
*/
class Tabs
{
/**
* @Message("小程序首页推荐")
*/
const APPLET_INDEX_RECOMMEND = 'applet_index_recommend';
/**
* @Message("小程序首页懒族上新")
*/
const APPLET_INDEX_NEW = 'applet_index_new';
/**
* @Message("小程序首页实时鲜货")
*/
const APPLET_INDEX_FRESH = 'applet_index_fresh';
/**
* @Message("小程序首页上班带餐")
*/
const APPLET_INDEX_OFFICE = 'applet_index_office';
}

122
app/Controller/v3/GoodsRecommendController.php

@ -0,0 +1,122 @@
<?php
namespace App\Controller\v3;
use App\Constants\v3\Tabs;
use App\Controller\BaseController;
/**
* 推荐商品相关
* Class GoodsRecommend
* @package App\Controller\v3
*/
class GoodsRecommendController extends BaseController
{
/**
* 获取首页tabs推荐商品列表
* 1、前端上传tab标识
* 2、根据tab标识从Elasticsearch中获取商品IDs
* 3、根据IDs获取商品数据
* 4、返回数据,id、封面图、名称、原价、现价、库存、月销、tag、规格、购物车相关、商户id、商户avatar、商户名
*/
public function getByTabsForAppletIndex()
{
$tabsData = [
Tabs::APPLET_INDEX_RECOMMEND => [
[
'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')]
]);
}
}

157
app/Controller/v3/HomeController.php

@ -0,0 +1,157 @@
<?php
namespace App\Controller\v3;
use App\Constants\v3\ActivityType;
use App\Constants\v3\Tabs;
use App\Controller\BaseController;
/**
* 首页相关
* Class HomeController
* @package App\Controller\v3
*/
class HomeController extends BaseController
{
/**
* 小程序首页,根据market_id
* 1.banner数据
* 2.一级分类
* 3.活动数据(秒杀、团购、新品、无)
* 4.tabs数据
*/
public function appletIndex()
{
$seconds = 25600;
$days = bcdiv($seconds, 86400);
$leftSeconds = bcsub($seconds, bcmul($days,86400));
$hours = bcdiv($leftSeconds,3600);
$leftSeconds = bcsub($leftSeconds, bcmul($hours,3600));
$minutes = bcdiv($leftSeconds,60);
$leftSeconds = bcsub($leftSeconds, bcmul($minutes,60));
return $this->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'],
]
]);
}
}

39
app/Controller/v3/LocationController.php

@ -0,0 +1,39 @@
<?php
namespace App\Controller\v3;
use App\Controller\BaseController;
/**
* 定位相关
* Class LocationController
* @package App\Controller\v3
*/
class LocationController extends BaseController
{
/**
* 获取当前用户定位最近的市场
* 1.用户上报经纬度数据
* 2.如果经纬度不存在或无法获取到最近市场信息,则返回空数据
* 3.根据经纬度查询获取市场数据,id、名称、省份、城市、行政区、地址、经纬度
*/
public function getNearestMarket()
{
return $this->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',
]
]);
}
}

5
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', ''),
],
];

1
config/routes.php

@ -80,6 +80,7 @@ Router::addGroup('/v3/', function () {
Router::post('location/getNearestMarket', 'App\Controller\v3\LocationController@getNearestMarket');
Router::post('home/appletIndex', 'App\Controller\v3\HomeController@appletIndex');
Router::post('Goods/detail', 'App\Controller\v3\GoodsController@detail');
Router::post('goodsRecommend/getByTabsForAppletIndex', 'App\Controller\v3\GoodsRecommendController@getByTabsForAppletIndex');
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]);
// 需要登录的路由

Loading…
Cancel
Save