Browse Source

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

# Conflicts:
#	app/Model/v3/GoodsActivity.php
#	config/autoload/dependencies.php
master
Lemon 5 years ago
parent
commit
fd2e56ff50
  1. 6
      app/Controller/v3/GoodsRecommendController.php
  2. 4
      app/Controller/v3/HomeController.php
  3. 31
      app/Model/v3/Category.php
  4. 12
      app/Model/v3/Goods.php
  5. 25
      app/Model/v3/GoodsActivity.php
  6. 89
      app/Service/v3/Implementations/ActivityService.php
  7. 5
      app/Service/v3/Implementations/BannerService.php
  8. 8
      app/Service/v3/Implementations/CategoryService.php
  9. 1
      config/autoload/dependencies.php

6
app/Controller/v3/GoodsRecommendController.php

@ -207,6 +207,12 @@ class GoodsRecommendController extends BaseController
]
];
$goods = Goods::query()
->with(['store'])
->forPage($this->request->input('page', 1), $this->request->input('pagesize', 15))
->get()->toArray();
return $this->success(['tab_data' => $goods]);
return $this->success([
'tab_data' => $tabsData[$this->request->post('tab', 'applet_index_recommend')]
]);

4
app/Controller/v3/HomeController.php

@ -19,6 +19,7 @@ use App\Service\v3\Interfaces\UserInfoServiceInterface;
use App\TaskWorker\SSDBTask;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Utils\ApplicationContext;
use Psr\Http\Message\ResponseInterface;
/**
* 首页相关
@ -94,7 +95,7 @@ class HomeController extends BaseController
return $this->success([
'banners' => $banners,
'categories' => $categories,
'activity' => $activity,
'activity' => ['type' => ActivityType::FLASH_SALE, 'goods' => $activity],
'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'],
@ -112,6 +113,7 @@ class HomeController extends BaseController
* 3、badge角标,待付款、待收货、已完成、售后, SSDB维护
* 4、为你推荐的商品列表
* @param UserIndexRequest $request
* @return ResponseInterface
*/
public function userIndex(UserIndexRequest $request)
{

31
app/Model/v3/Category.php

@ -0,0 +1,31 @@
<?php
namespace App\Model\v3;
use App\Model\Model;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\SoftDeletes;
class Category extends Model
{
use SoftDeletes;
protected $table = 'lanzu_category';
protected $appends = [
'goods_types'
];
protected function boot(): void
{
parent::boot();
static::addGlobalScope('status', function (Builder $builder) {
$builder->where(['status' => 1])->orderBy('sort', 'desc');
});
}
public function getGoodsTypesAttribute()
{
return self::query()->where(['parent_id' => $this->attributes['id']])->orderBy('sort', 'desc')->get()->toArray();
}
}

12
app/Model/v3/Goods.php

@ -51,6 +51,8 @@ class Goods extends Model
protected $appends = [
'month_sales',
'cart_num',
'is_effective',
'noneffective_note',
];
protected function boot(): void
@ -87,6 +89,16 @@ class Goods extends Model
return (integer)$this->shopCartService->check($this->id);
}
public function getIsEffectiveAttribute()
{
return 1;
}
public function getNoneffectiveNoteAttribute()
{
return '';
}
public function store()
{
return $this->belongsTo(Store::class, 'store_id', 'id');

25
app/Model/v3/GoodsActivity.php

@ -6,12 +6,17 @@ use App\Constants\v3\Goods as GoodsConstants;
use App\Constants\v3\SsdbKeys;
use App\Model\Model;
use App\Service\v3\Interfaces\ShopCartServiceInterface;
use App\TaskWorker\SSDBTask;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\SoftDeletes;
use Hyperf\Utils\ApplicationContext;
use App\TaskWorker\SSDBTask;
use Hyperf\Di\Annotation\Inject;
class GoodsActivity extends Model
{
use SoftDeletes;
/**
* @Inject
* @var ShopCartServiceInterface
@ -29,6 +34,9 @@ class GoodsActivity extends Model
protected $appends = [
'month_sales',
'cart_num',
'is_effective',
'noneffective_note',
'total_seconds',
];
protected function boot(): void
@ -50,6 +58,21 @@ class GoodsActivity extends Model
return (integer)$this->shopCartService->check($this->id);
}
public function getIsEffectiveAttribute()
{
return 2;
}
public function getNoneffectiveNoteAttribute()
{
return '已抢光';
}
public function getTotalSecondsAttribute()
{
return $this->attributes['expire_time'] - time();
}
public function store()
{
return $this->belongsTo(Store::class, 'store_id', 'id');

89
app/Service/v3/Implementations/ActivityService.php

@ -26,85 +26,14 @@ class ActivityService implements ActivityServiceInterface
public function allForAppletIndex($type, $marketId)
{
return GoodsActivity::query()
->where(['type' => $type, 'market_id' => $marketId])
->addSelect('sales as total_sales')
->get()->toArray();
return [
'type' => ActivityType::FLASH_SALE,
'goods' => [
[
'id' => 1,
'store_id' => 111,
'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,
],[
'id' => 1,
'store_id' => 111,
'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,
],[
'id' => 1,
'store_id' => 111,
'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,
],[
'id' => 1,
'store_id' => 111,
'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,
],
]
];
$builder = GoodsActivity::query()
->select(['*'])
->where(['type' => $type])
->addSelect('sales as total_sales');
if ($marketId) {
$builder->where(['market_id' => $marketId]);
}
return $builder->get()->toArray();
}
}

5
app/Service/v3/Implementations/BannerService.php

@ -9,6 +9,9 @@ class BannerService implements BannerServiceInterface
{
public function all($type, $marketId)
{
return Banner::query()->where(['type' => $type, 'market_id' => $marketId])->get()->toArray();
return Banner::query()
->where(['type' => $type])
->whereIn('market_id', [0,$marketId])
->get()->toArray();
}
}

8
app/Service/v3/Implementations/CategoryService.php

@ -3,6 +3,7 @@
namespace App\Service\v3\Implementations;
use App\Constants\v3\SsdbKeys;
use App\Model\v3\Category;
use App\Model\v3\Goods;
use App\Model\v3\GoodsType;
use App\Model\v3\StoreType;
@ -30,12 +31,7 @@ class CategoryService implements CategoryServiceInterface
public function all()
{
return StoreType::query()
->with('goodsTypes')
->orderBy('sort', 'DESC')
->orderBy('id', 'DESC')
->get()
->toArray();
return Category::query()->where(['parent_id' => 0])->get()->toArray();
}
public function allForStore($storeId)

1
config/autoload/dependencies.php

@ -57,5 +57,6 @@ return [
\App\Service\v3\Interfaces\StoreLoginServiceInterface::class => \App\Service\v3\Implementations\StoreLoginService::class,
\App\Service\v3\Interfaces\StoreInfoServiceInterface::class => \App\Service\v3\Implementations\StoreInfoService::class,
\App\Service\v3\Interfaces\BannerServiceInterface::class => \App\Service\v3\Implementations\BannerService::class,
\App\Service\v3\Interfaces\ActivityServiceInterface::class => \App\Service\v3\Implementations\ActivityService::class,
\App\Service\v3\Interfaces\LocationServiceInterface::class => \App\Service\v3\Implementations\LocationService::class,
];
Loading…
Cancel
Save