public function getWriteOffCodeExchangeList($id_shop, $city, $type, $status, $tag, $page, $card_rank = '')
{
$filterMd5 = substr(md5($id_shop . $city . $type . $status . $tag . $card_rank), 0, 12);
$cache_key = getCacheKey(Point::MEMBER_ACTIVITY_CENTER_WRITE_OFF_CODE_EXCHANGE_LIST, $filterMd5, $page);
$data = cache($cache_key);
if (!empty($data)) {
if ($data == -1) {
return [];
}
}
// 从数据库获取
if (empty($data)) {
$condition = [
'type' => ModExchange::EXCHANGE_TYPE_WRITE_OFF_CODE,
'status' => ModExchange::EXCHANGE_STATUS_OK,
'activity_center_show' => 1,
'id_shop' => ['IN', [7,8,88]],
];
if (!empty($city)) {
$condition['activity_address'] = $city;
}
if (!empty($type)) {
$condition['activity_type'] = $type;
}
if (!empty($status)) {
if ($status == 1) {
$condition['activity_start'] = ['gt', time()];
} elseif ($status == 2) {
$condition['activity_start'] = ['lt', time()];
$condition['activity_end'] = ['gt', time()];
} elseif ($status == 3) {
$condition['activity_end'] = ['lt', time()];
}
}
$db = db($this->table_point_exchange, $this->connection)
->field('id_ep,id_shop,exchange_name,head_image,range_user,'
. 'activity_start,activity_end,activity_address,activity_type,'
. 'activity_tags,points,margin_nums')
->where($condition)
->page($page, 10);
$filterTags = explode(',', $tag);
if (!empty($tag)) {
foreach ($filterTags as $t) {
if (!empty($t)) {
$conditionOrTags[] = 'activity_tags =' . $t;
$conditionOrTags[] = 'activity_tags like \'' . $t . ',%\'';
$conditionOrTags[] = 'activity_tags like \'%,' . $t . ',%\'';
$conditionOrTags[] = 'activity_tags like \'%,' . $t . '\'';
}
}
if (!empty($conditionOrTags)) {
$db->where(function ($query) use ($conditionOrTags) {
foreach ($conditionOrTags as $k => $conditionOr) {
$query->whereOr($conditionOr);
}
});
}
}
if (ShopID::isFilaClub($id_shop)) {
$order_str = '(case when id_shop = ' . $id_shop . ' then 1 else 0 end) desc,';
if ($card_rank) {
$order_str .= '(case when FIND_IN_SET(' . $card_rank . ',range_user)>0 then 1 else 0 end) desc,';
}
$order_str .= 'id_ep desc';
$db = $db->orderRaw($order_str);
} else {
$order_str = '';
if ($card_rank) {
$order_str .= '(case when FIND_IN_SET(' . $card_rank . ',range_user)>0 then 1 else 0 end) desc,';
}
$order_str .= 'id_ep desc';
$db = $db->orderRaw($order_str);
}
// $data = $db->fetchSql()->select();
// var_dump($data);
// die;
$data = $db->select();
if (empty($data)) {
// 防止穿透
cache($cache_key, -1, 300);
return [];
}
cache($cache_key, $data, 600);
}
$ModWriteOffCodeTags = new ModWriteOffCodeTags();
$tagsList = $ModWriteOffCodeTags->getTagsList();
$tagsList = array_column($tagsList, 'val', 'k');
$ModShops = new ModShops();
$id_shops = [2,5,77];
$appidList = [];
foreach ($id_shops as $val) {
$shopInfo = $ModShops->getShopInfoOne($val);
$appidList[$val] = $shopInfo['wx_appid'];
}
foreach ($data as &$val) {
$val['status_msg'] = '';
if ($val['activity_start'] > time()) {
$val['status_msg'] = '未开始';
} elseif ($val['activity_end'] < time()) {
$val['status_msg'] = '已结束';
} else {
$val['status_msg'] = '进行中';
}
$activity_tags = explode(',', $val['activity_tags']);
unset($val['activity_tags']);
foreach ($activity_tags as $t) {
if (!empty($t) && isset($tagsList[$t])) {
$val['activity_tags'][] = $tagsList[$t];
}
}
$val['appid'] = $appidList[$val['id_shop']] ?? '';
$val['path'] = '/packages/pointsMall/details/index';
unset($val['activity_start'], $val['activity_end']);
}
return array_values($data);
}
发表回复