diff --git a/app/Controller/v3/GoodsRecommendController.php b/app/Controller/v3/GoodsRecommendController.php index a4e8207..5981719 100644 --- a/app/Controller/v3/GoodsRecommendController.php +++ b/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')] ]); diff --git a/app/Controller/v3/HomeController.php b/app/Controller/v3/HomeController.php index f3d2e46..4d220f9 100644 --- a/app/Controller/v3/HomeController.php +++ b/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) { diff --git a/app/Model/v3/Category.php b/app/Model/v3/Category.php new file mode 100644 index 0000000..24311b0 --- /dev/null +++ b/app/Model/v3/Category.php @@ -0,0 +1,31 @@ +where(['status' => 1])->orderBy('sort', 'desc'); + }); + } + + public function getGoodsTypesAttribute() + { + return self::query()->where(['parent_id' => $this->attributes['id']])->orderBy('sort', 'desc')->get()->toArray(); + } +} \ No newline at end of file diff --git a/app/Model/v3/Goods.php b/app/Model/v3/Goods.php index 7bc8d43..4c71abc 100644 --- a/app/Model/v3/Goods.php +++ b/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'); diff --git a/app/Model/v3/GoodsActivity.php b/app/Model/v3/GoodsActivity.php index 455458c..4c18e27 100644 --- a/app/Model/v3/GoodsActivity.php +++ b/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'); diff --git a/app/Service/v3/Implementations/ActivityService.php b/app/Service/v3/Implementations/ActivityService.php index 58788f9..13282be 100644 --- a/app/Service/v3/Implementations/ActivityService.php +++ b/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(); } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/BannerService.php b/app/Service/v3/Implementations/BannerService.php index 5cd4541..dd46f35 100644 --- a/app/Service/v3/Implementations/BannerService.php +++ b/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(); } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/CategoryService.php b/app/Service/v3/Implementations/CategoryService.php index 4ecae9c..efbd046 100644 --- a/app/Service/v3/Implementations/CategoryService.php +++ b/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) diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index ebe30e5..3cceb2a 100644 --- a/config/autoload/dependencies.php +++ b/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, ];