diff --git a/app/Controller/v3/HomeController.php b/app/Controller/v3/HomeController.php index 03281c6..1ee1695 100644 --- a/app/Controller/v3/HomeController.php +++ b/app/Controller/v3/HomeController.php @@ -25,6 +25,7 @@ use App\Service\v3\Interfaces\FinancialRecordServiceInterface; use App\Service\v3\Interfaces\OrderOnlineServiceInterface; use App\Service\v3\Interfaces\OrderStatisticsServiceInterface; use App\Service\v3\Interfaces\RevenueListServiceInterface; +use App\Service\v3\Interfaces\ShareInfoServiceInterface; use App\Service\v3\Interfaces\StoreServiceInterface; use App\Service\v3\Interfaces\TabsServiceInterface; use App\Service\v3\Interfaces\UserCenterBlockServiceInterface; @@ -121,6 +122,12 @@ class HomeController extends BaseController */ protected $financialRecordService; + /** + * @Inject + * @var ShareInfoServiceInterface + */ + protected $shareInfoService; + /** * 小程序首页,根据market_id * 1.banner数据 @@ -134,14 +141,18 @@ class HomeController extends BaseController $version = $this->request->input('version', -1); $banners = $this->bannerService->all(Banner::TYPE_APPLET_INDEX, $marketId); $categories = $this->categoryService->allForAppletIndex(); - $activity = $this->activityService->allForAppletIndex(env('APPLET_INDEX_ACTIVITY_TYPE'), $marketId); + // $activity = $this->activityService->allForAppletIndex(env('APPLET_INDEX_ACTIVITY_TYPE'), $marketId); + $activity = $this->activityService->allSpecialForAppletIndex($marketId); $tabs = $this->tabsService->allForAppletIndex($version); + $shareInfo = $this->shareInfoService->getForApplet(); return $this->success([ 'banners' => $banners, 'categories' => $categories, - 'activity' => ['type' => ActivityType::FLASH_SALE, 'goods' => $activity], + // 'activity' => ['type' => ActivityType::FLASH_SALE, 'goods' => $activity], + 'activity' => $activity, 'tabs' => $tabs, + 'share_info' => $shareInfo, ]); } diff --git a/app/Service/v3/Implementations/ActivityService.php b/app/Service/v3/Implementations/ActivityService.php index 8ee2e02..dcd1043 100644 --- a/app/Service/v3/Implementations/ActivityService.php +++ b/app/Service/v3/Implementations/ActivityService.php @@ -6,6 +6,7 @@ use App\Constants\v3\Goods as GoodsConstants; use App\Model\v3\GoodsActivity; use App\Model\v3\Store; use App\Service\v3\Interfaces\ActivityServiceInterface; +use Hyperf\Redis\Redis; use Hyperf\Utils\ApplicationContext; class ActivityService implements ActivityServiceInterface @@ -61,4 +62,57 @@ class ActivityService implements ActivityServiceInterface ->orderBy(''.$goodsTable.'.created_at', 'DESC') ->get()->toArray(); } + + public function allSpecialForAppletIndex($marketId) + { + $activity = [ + 'type' => '', + 'settings' => '', + 'goods' => [] + ]; + + $redis = ApplicationContext::getContainer()->get(Redis::class); + $activitySettings = $redis->hGetAll('activity_type_setting'); + $activity['type'] = $type = $activitySettings['index_activity_type']; + $activity['settings'] = json_decode($activitySettings[$activitySettings['index_activity_type']], true); + + $storeTable = ApplicationContext::getContainer()->get(Store::class)->getTable(); + $goodsTable = ApplicationContext::getContainer()->get(GoodsActivity::class)->getTable(); + + $builder = GoodsActivity::query() + ->join($storeTable, ''.$storeTable.'.id', '=', ''.$goodsTable.'.store_id') + ->with(['store']) + ->where([''.$goodsTable.'.type' => $type]) + ->where(function ($query) use ($marketId, $goodsTable) { + $query->whereJsonContains(''.$goodsTable.'.market_ids', [(string)$marketId]) + ->orWhereJsonLength(''.$goodsTable.'.market_ids', '=', 0); + }) + ->where([''.$goodsTable.'.on_sale' => GoodsConstants::ON_SALE_YES]) + // ->where(function ($query) use ($goodsTable) { + // $query->where(''.$goodsTable.'.inventory', '>', 0)->orWhere(''.$goodsTable.'.is_infinite', '=', 1); + // }) + ->whereRaw(''.$goodsTable.'.deleted_at IS NULL') + ->where([''.$storeTable.'.market_id' => $marketId]) + ->where([''.$storeTable.'.is_open' => \App\Constants\v3\Store::IS_OPEN_YES]) + ->where([''.$storeTable.'.is_rest' => \App\Constants\v3\Store::IS_REST_NO]) + ->where('time1', '<=', date('H:i')) + ->where(function ($query) { + $query->where('time2', '>=', date('H:i')) + ->orWhere('time4', '>=', date('H:i')); + }) + ->where(''.$goodsTable.'.expire_time', '>', time()); + + $builder = $builder->select(''.$goodsTable.'.*')->addSelect(''.$goodsTable.'.sales as total_sales') + ->orderBy(''.$goodsTable.'.sort', 'DESC') + ->orderBy(''.$goodsTable.'.expire_time', 'ASC') + ->orderBy(''.$goodsTable.'.created_at', 'DESC'); + + if (isset($activity['settings']['index_num_limit'])&&!empty($activity['settings']['index_num_limit'])) { + $builder = $builder->limit($activity['settings']['index_num_limit']); + } + + $activity['goods'] = $builder->get()->toArray(); + + return $activity; + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/ShareInfoService.php b/app/Service/v3/Implementations/ShareInfoService.php new file mode 100644 index 0000000..0bb4d89 --- /dev/null +++ b/app/Service/v3/Implementations/ShareInfoService.php @@ -0,0 +1,15 @@ + \App\Service\v3\Implementations\ParamsTokenSsdbService::class, \App\Service\v3\Interfaces\GoodsInventoryServiceInterface::class => \App\Service\v3\Implementations\GoodsInventoryService::class, \App\Service\v3\Interfaces\HorsemanServiceInterface::class => \App\Service\v3\Implementations\HorsemanService::class, + \App\Service\v3\Interfaces\ShareInfoServiceInterface::class => \App\Service\v3\Implementations\ShareInfoService::class, ];