Browse Source

新活动商品

master
weigang 5 years ago
parent
commit
4c087aeba6
  1. 15
      app/Controller/v3/HomeController.php
  2. 54
      app/Service/v3/Implementations/ActivityService.php
  3. 15
      app/Service/v3/Implementations/ShareInfoService.php
  4. 1
      app/Service/v3/Interfaces/ActivityServiceInterface.php
  5. 8
      app/Service/v3/Interfaces/ShareInfoServiceInterface.php
  6. 1
      config/autoload/dependencies.php

15
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,
]);
}

54
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;
}
}

15
app/Service/v3/Implementations/ShareInfoService.php

@ -0,0 +1,15 @@
<?php
namespace App\Service\v3\Implementations;
use App\TaskWorker\SSDBTask;
use Hyperf\Utils\ApplicationContext;
class ShareInfoService implements \App\Service\v3\Interfaces\ShareInfoServiceInterface
{
public function getForApplet()
{
return [];
}
}

1
app/Service/v3/Interfaces/ActivityServiceInterface.php

@ -8,4 +8,5 @@ interface ActivityServiceInterface
public function check();
public function undo();
public function allForAppletIndex($type, $marketId);
public function allSpecialForAppletIndex($marketId);
}

8
app/Service/v3/Interfaces/ShareInfoServiceInterface.php

@ -0,0 +1,8 @@
<?php
namespace App\Service\v3\Interfaces;
interface ShareInfoServiceInterface
{
public function getForApplet();
}

1
config/autoload/dependencies.php

@ -92,4 +92,5 @@ return [
\App\Service\v3\Interfaces\ParamsTokenServiceInterface::class => \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,
];
Loading…
Cancel
Save