From a962bae6818f8f926ffcfa9ad92a0e4473302d67 Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 3 Sep 2020 20:36:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=8D=A2=E7=9C=9F=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/HomeController.php | 4 +- app/Model/v3/GoodsActivity.php | 31 +++++++ .../v3/Implementations/ActivityService.php | 88 ++----------------- config/autoload/dependencies.php | 1 + 4 files changed, 44 insertions(+), 80 deletions(-) diff --git a/app/Controller/v3/HomeController.php b/app/Controller/v3/HomeController.php index 2b4befc..1564ea4 100644 --- a/app/Controller/v3/HomeController.php +++ b/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) { diff --git a/app/Model/v3/GoodsActivity.php b/app/Model/v3/GoodsActivity.php index 5cf01f9..e46e520 100644 --- a/app/Model/v3/GoodsActivity.php +++ b/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'); diff --git a/app/Service/v3/Implementations/ActivityService.php b/app/Service/v3/Implementations/ActivityService.php index 58788f9..93432ea 100644 --- a/app/Service/v3/Implementations/ActivityService.php +++ b/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(); - - 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(); } } \ No newline at end of file diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index 2f102c7..ba79a7e 100644 --- a/config/autoload/dependencies.php +++ b/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, ];