You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123 lines
5.3 KiB
123 lines
5.3 KiB
<?php
|
|
|
|
namespace App\Service\v3\Implementations;
|
|
|
|
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
|
|
{
|
|
|
|
public function do()
|
|
{
|
|
// TODO: Implement do() method.
|
|
}
|
|
|
|
public function check()
|
|
{
|
|
// TODO: Implement check() method.
|
|
}
|
|
|
|
public function undo()
|
|
{
|
|
// TODO: Implement undo() method.
|
|
}
|
|
|
|
public function allForAppletIndex($type, $marketId)
|
|
{
|
|
|
|
$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());
|
|
|
|
return $builder->select(''.$goodsTable.'.*')->addSelect(''.$goodsTable.'.sales as total_sales')
|
|
->orderBy(''.$goodsTable.'.sort', 'DESC')
|
|
->orderBy(''.$goodsTable.'.expire_time', 'ASC')
|
|
->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'];
|
|
$settingsStr = $activitySettings[$activity['type']] ?? '';
|
|
$activity['settings'] = json_decode($settingsStr, true);
|
|
$activity['settings'] = !empty($activity['settings']) ? $activity['settings'] : (object)[];
|
|
$activity['goods'] = [];
|
|
|
|
if ($activity['settings']['show_type'] == 'list') {
|
|
$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 (is_array($activity['settings'])&&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;
|
|
}
|
|
}
|