Browse Source

首页换真的数据了

master
weigang 5 years ago
parent
commit
a962bae681
  1. 4
      app/Controller/v3/HomeController.php
  2. 31
      app/Model/v3/GoodsActivity.php
  3. 86
      app/Service/v3/Implementations/ActivityService.php
  4. 1
      config/autoload/dependencies.php

4
app/Controller/v3/HomeController.php

@ -18,6 +18,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;
/**
* 首页相关
@ -86,7 +87,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'],
@ -104,6 +105,7 @@ class HomeController extends BaseController
* 3、badge角标,待付款、待收货、已完成、售后, SSDB维护
* 4、为你推荐的商品列表
* @param UserIndexRequest $request
* @return ResponseInterface
*/
public function userIndex(UserIndexRequest $request)
{

31
app/Model/v3/GoodsActivity.php

@ -5,11 +5,24 @@ namespace App\Model\v3;
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 Hyperf\Di\Annotation\Inject;
class GoodsActivity extends Model
{
use SoftDeletes;
/**
* @Inject
* @var ShopCartServiceInterface
*/
protected $shopCartService;
protected $table = 'lanzu_goods_activity';
protected $casts = [
@ -21,6 +34,9 @@ class GoodsActivity extends Model
protected $appends = [
'month_sales',
'cart_num',
'is_effective',
'noneffective_note',
'total_seconds',
];
protected function boot(): void
@ -42,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', 'goods_id');

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

@ -27,84 +27,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();
$builder = GoodsActivity::query()
->select(['*'])
->where(['type' => $type])
->addSelect('sales as total_sales');
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,
],
]
];
if ($marketId) {
$builder->where(['market_id' => $marketId]);
}
return $builder->get()->toArray();
}
}

1
config/autoload/dependencies.php

@ -55,4 +55,5 @@ return [
\App\Service\v3\Interfaces\OrderListServiceInterface::class => \App\Service\v3\Implementations\OrderListService::class,
\App\Service\v3\Interfaces\UserCenterBlockServiceInterface::class => \App\Service\v3\Implementations\UserCenterBlockService::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,
];
Loading…
Cancel
Save