Commit 2b0bb349 authored by suntengda's avatar suntengda

update app-团餐活动列表已结束列表增加缓存

parent 65a4dfd7
<?php <?php
use Api\PhpUtils\Log\FileLog;
use App\Base\Base; use App\Base\Base;
use App\Services\marketing\MarketingService; use App\Services\marketing\MarketingService;
use App\Exception\custom\MarketingException; use App\Exception\custom\MarketingException;
...@@ -9,6 +10,7 @@ use \Validate\MarketingOnlineStatusValidate; ...@@ -9,6 +10,7 @@ use \Validate\MarketingOnlineStatusValidate;
use \Validate\MarketingInfoValidate; use \Validate\MarketingInfoValidate;
use App\Models\marketing\mysql\Marketing; use App\Models\marketing\mysql\Marketing;
use App\Models\marketing\mysql\MarketingPindan; use App\Models\marketing\mysql\MarketingPindan;
use Api\PhpUtils\Redis\RedisUtil;
class MarketingController extends Base class MarketingController extends Base
{ {
...@@ -157,27 +159,6 @@ class MarketingController extends Base ...@@ -157,27 +159,6 @@ class MarketingController extends Base
$this->success(); $this->success();
} }
/**
* 切换活动状态
* @throws \App\Exception\custom\ParamException
*/
public function toogle_yingxiao_online_statusAction()
{
(new MarketingOnlineStatusValidate())->scene('yingxiao')->validate();
$res = MarketingService::toogleOnlineStatus($this->params['marketing_id'],$this->params['online_status']);
$this->success(['result' => $res]);
}
/**
* 营销中心-活动列表
* @throws Exception
*/
public function yingxiao_listAction()
{
$lists = MarketingService::yingxiaoList($this->params);
$this->success(['result' => $lists]);
}
/** /**
* app内团餐活动列表 * app内团餐活动列表
* @throws \App\Exception\custom\InterfaceException * @throws \App\Exception\custom\InterfaceException
...@@ -207,18 +188,56 @@ class MarketingController extends Base ...@@ -207,18 +188,56 @@ class MarketingController extends Base
$marketingIdsPrepare = array_keys($list['prepare']); $marketingIdsPrepare = array_keys($list['prepare']);
//已结束的 按结束时间倒序 //已结束的 按结束时间倒序
$this->params['page'] = 1; $list['end'] = $this->getTuanCanEndList();
$this->params['page_size'] = 10;
$this->params['sort_field'] = 'end_time'; $marketingIds = array_merge($marketingIdsDoing, $marketingIdsPrepare);
$this->params['sort_type'] = 'desc';
$this->params['need_buy_num'] = false; $list = $this->_fillSkuAndOrderInfo($marketingIds,$list);
$this->params['online_status'] = [Marketing::ONLINE_STATUS_QIDONG, Marketing::ONLINE_STATUS_GUANBI, Marketing::ONLINE_STATUS_DAOQI];//状态 , 1启用,2关闭,3 到期
$this->params['activity_status'] = MarketingPindan::ACTIVITY_STATUS_FINISHED;//1 未开始,2进行中,3已结束, 4当日上新(即将开始) $list['life_account_id'] = MarketingService::getPublicLifeAccountId();
$list['end'] = MarketingService::marketingList($this->params)['result'];
$list['end'] = $list['end'] ? array_column($list['end'], null, 'marketing_id') : []; $this->success(['result' => $list]);
$marketingIdsEnd = array_keys($list['end']); }
private function getTuanCanEndList(){
try{
$redis = RedisUtil::getInstance('cache',['serializer'=>'php']);
$key = "tuancan_end_list_".date('Ymd');
$list['end'] = $redis->get($key);
if(empty($list['end'])) {
$this->params['page'] = 1;
$this->params['page_size'] = 10;
$this->params['sort_field'] = 'end_time';
$this->params['sort_type'] = 'desc';
$this->params['need_buy_num'] = false;
$this->params['online_status'] = [Marketing::ONLINE_STATUS_QIDONG, Marketing::ONLINE_STATUS_GUANBI, Marketing::ONLINE_STATUS_DAOQI];//状态 , 1启用,2关闭,3 到期
$this->params['activity_status'] = MarketingPindan::ACTIVITY_STATUS_FINISHED;//1 未开始,2进行中,3已结束, 4当日上新(即将开始)
$list['end'] = MarketingService::marketingList($this->params)['result'];
$list['end'] = $list['end'] ? array_column($list['end'], null, 'marketing_id') : [];
$marketingIdsEnd = array_keys($list['end']);
$list = $this->_fillSkuAndOrderInfo($marketingIdsEnd,$list);
$redis->set($key,json_encode($list['end']),['ex'=>86400]);//已结束列表 缓存一天
}else {
$list['end'] = json_decode($list['end'], true);
}
}catch (Exception $e) {
FileLog::error("获取团餐已结束列表异常", $e->getMessage(), '', 'suntengda@yidian-inc.com');
}
$marketingIds = array_merge($marketingIdsDoing, $marketingIdsPrepare, $marketingIdsEnd); return $list['end'] ?? [];
}
/**
* 给列表填充sku和订单相关信息
* @param $marketingIds
* @param $list
* @return mixed
* @throws \App\Exception\custom\InterfaceException
*/
private function _fillSkuAndOrderInfo($marketingIds,$list) {
//获取活动的sku列表 //获取活动的sku列表
$skuList = MarketingService::getGoodsSkuListByMarketingIds($marketingIds); $skuList = MarketingService::getGoodsSkuListByMarketingIds($marketingIds);
//获取活动支付用户列表 //获取活动支付用户列表
...@@ -237,8 +256,33 @@ class MarketingController extends Base ...@@ -237,8 +256,33 @@ class MarketingController extends Base
$listPart = array_values($listPart); $listPart = array_values($listPart);
} }
unset($listPart); unset($listPart);
$list['life_account_id'] = MarketingService::getPublicLifeAccountId();
$this->success(['result' => $list]); return $list;
}
/**
* 切换活动状态
* @throws \App\Exception\custom\ParamException
*/
public function toogle_yingxiao_online_statusAction()
{
(new MarketingOnlineStatusValidate())->scene('yingxiao')->validate();
$res = MarketingService::toogleOnlineStatus($this->params['marketing_id'],$this->params['online_status']);
$this->success(['result' => $res]);
}
/**
* 营销中心-活动列表
* @throws Exception
*/
public function yingxiao_listAction()
{
$lists = MarketingService::yingxiaoList($this->params);
$this->success(['result' => $lists]);
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment