Authored by 郭成尧

兼容旧数据

... ... @@ -8,8 +8,10 @@
namespace Plugin\DataProcess;
use WebPlugin\Cache;
use Plugin\Images;
use Plugin\Helpers;
use WebPlugin\HelperSearch;
class CouponFloorProcess
{
... ... @@ -174,6 +176,138 @@ class CouponFloorProcess
$result['list'] = $data;
return $result;
}
/**
* 这个是图片列表
* 重构
*
* @param $data
* @return mixed
*/
public static function image_list($data)
{
$result = array();
foreach ($data['list'] as &$image) {
$num = $data['title']['column_num'];
if ($num == 0) {
$image['src'] = str_replace('?imageView/{mode}/w/{width}/h/{height}', '', $image['src']);
} else {
if (640 % $num == 0) {
$width = (int)(640 / $num);
$width = empty($width) ? 640 : $width;
$image['src'] = str_replace('?imageView/{mode}/w/{width}/h/{height}', '?imageView2/2/w/' . $width, $image['src']);
$image['src'] = Images::getImageUrl($image['src'], $width, 0);
} else {
$image['src'] = str_replace('?imageView/{mode}/w/{width}/h/{height}', '', $image['src']);
}
}
$image['url'] = empty($image['url']) ? 'javascript:void(0);' : $image['url'];
}
$result['isImageList'] = true;
$result['imageList'] = array(
'col' => $data['title']['column_num'],
'title' => $data['title']['title'],
'list' => $data['list']
);
return $result;
}
/**
* 促銷
* 重构
*
* @param $data
* @return mixed
*/
public static function promotion($data)
{
$result = array();
$result['newArrival'] = array(
'goods' => self::getRecomProduct(1, 50, $data['promotionId'])
);
$result['isNewArrival'] = true;
return $result;
}
/**
* 推荐商品
* 重构
*
* @param int $page
* @param int $limit
* @param string $promotion
* @return array
*/
public static function getRecomProduct($page = 1, $limit = 50, $promotion = '')
{
$receiveData = filter_input_array(INPUT_GET, array(
'gender' => FILTER_DEFAULT,
'promotion' => FILTER_DEFAULT,
));
$gender = empty($receiveData['gender']) ? '1,2,3' : $receiveData['gender'];
$promotion = empty($receiveData['promotion']) ? $promotion : $receiveData['promotion'];
$genders = array('1,3', '2,3', '1,2,3');
if (!in_array($gender, $genders)) {
$gender = '1,2,3';
}
if (empty($promotion)) {
return array();
}
$params = array('status' => 1, 'order' => 's_t_desc', 'page' => $page, 'promotion' => $promotion, 'viewNum' => $limit, 'gender' => $gender, 'p_d' => '1,1', 'stocknumber' => 3);
$key = Cache::makeKey($params);
$data = Cache::get($key);
if (empty($data)) {
$productList = HelperSearch::getProductList($params, array('action' => 'new'));
$data = array();
foreach ($productList['data']['product_list'] as $product) {
$is_yohood = false;
$is_sale = false;
if (isset($product['is_yohood'])) {
$is_yohood == 'Y' ? true : false;
}
$goods_id = $product['goods_list'][0]['goods_id'];
$data[] = array('id' => $product['product_id'], 'isLike' => false, 'isFew' => false,//即将售罄
'src' => str_replace('?imageView/{mode}/w/{width}/h/{height}', '?imageView2/1/w/320/h/426', $product['default_images']),
'name' => $product['product_name'],
'price' => $product['market_price'] == $product['sales_price'] ? 0 : $product['market_price'],
'salePrice' => $product['sales_price'],
'tags' => array('isNew' => $product['is_new'] == 'Y' ? true : false,
'isLimit' => $product['is_limited'] == 'Y' ? true : false,
'isYohood' => $is_yohood,
'isSale' => $is_sale,//促销
),
'url' => Helpers::getUrlBySkc($product['product_id'], $goods_id, $product['cn_alphabet']),
);
}
Cache::set($key, $data, 600);
}
return $data;
}
/**
* 获取分享
*
* @param $code 资源码
* @param string $shareTitle 分享标题
* @param string $shareDesc 分享描述
* @param string $shareImg 分享图片
* @return array
* @internal param int $share_id
*/
public static function getShare($code, $shareTitle = '', $shareDesc = '', $shareImg = '')
{
return array(
'share' => array(
'shareLink' => Helpers::url('/coupon/floor', array('code' => $code), ''),
'shareTitle' => $shareTitle,
'shareDesc' => $shareDesc,
'shareImg' => $shareImg,
'hasWxShare' => true,
),
);
}
/**
*
... ...
... ... @@ -39,6 +39,9 @@ class CouponController extends AbstractAction
if (isset($resource['code']) && $resource['code'] == 200) {
$result = CouponFloorProcess::getContent($resource['data']);
}
// 分享
$shareData = CouponFloorProcess::getShare($receiveData['code'], '领券中心');
$result[count($result)] = $shareData;
$this->_view->display('index', array(
'content' => $result,
'floorPage' => true
... ...