|
|
<?php
|
|
|
|
|
|
namespace Plugin;
|
|
|
|
|
|
/**
|
|
|
* 辅助类
|
|
|
*/
|
|
|
class Helpers
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
* 构建网站的URL
|
|
|
*
|
|
|
* 备注:所有的URL构建都尽量使用该方法,便于以后维护.
|
|
|
*
|
|
|
* @param string $uri 如 "/passport/reg/index"
|
|
|
* @param array $param 参数项 array(key1 => value1, key2 => value2,),默认为array()
|
|
|
* @param string $module 模块名 如"index"表示默认, "guang"表示逛,"list"表示商品列表,"search"表示搜索
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function url($uri, $param = array(), $module = 'index')
|
|
|
{
|
|
|
$url = '';
|
|
|
|
|
|
switch ($module) {
|
|
|
case 'default':
|
|
|
$url = 'http://m.yohobuy.com';
|
|
|
break;
|
|
|
case 'guang': // 逛
|
|
|
$url = 'http://guang' . SUB_DOMAIN;
|
|
|
break;
|
|
|
case 'list': // 商品列表
|
|
|
$url = 'http://list' . SUB_DOMAIN;
|
|
|
break;
|
|
|
case 'search': // 搜索
|
|
|
$url = 'http://search' . SUB_DOMAIN;
|
|
|
break;
|
|
|
case 'index': // 默认
|
|
|
$url = SITE_MAIN;
|
|
|
break;
|
|
|
case '': // 相对地址
|
|
|
break;
|
|
|
default: // 其它子域名
|
|
|
$url = 'http://' . $module . SUB_DOMAIN;
|
|
|
}
|
|
|
$url .= $uri;
|
|
|
if (!empty($param)) {
|
|
|
$url .= '?' . http_build_query($param, null, '&');
|
|
|
}
|
|
|
|
|
|
return $url;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据尺寸获得图片url
|
|
|
*
|
|
|
* @param string $url 路径
|
|
|
* @param integer $width 图片宽度
|
|
|
* @param integer $height 图片高度
|
|
|
* @param integer $mode 模式
|
|
|
* @return string 图片地址
|
|
|
*/
|
|
|
public static function getImageUrl($url, $width, $height, $mode = 2)
|
|
|
{
|
|
|
return strtr($url, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取过滤APP里附加参数后的URL链接
|
|
|
*
|
|
|
* @param string $url 路径
|
|
|
* @return string 去除掉如&openby:yohobuy={"action":"go.brand"}这样的APP附加参数
|
|
|
*/
|
|
|
public static function getFilterUrl($url)
|
|
|
{
|
|
|
$url = strtr($url, array('.m.yohobuy.com' => SUB_DOMAIN, OLD_MAIN => SITE_MAIN, 'www.yohobuy.com' => SITE_MAIN));
|
|
|
$filter = strstr($url, 'openby:yohobuy=', true);
|
|
|
if ($filter) {
|
|
|
return rtrim(rtrim($filter, '?'), '&');
|
|
|
} else {
|
|
|
return $url;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据用户访问的COOKIE判断出性别
|
|
|
*
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function getGenderByCookie()
|
|
|
{
|
|
|
$cookie = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys';
|
|
|
switch (strval($cookie)) {
|
|
|
case 'boys': // 男
|
|
|
return '1,3';
|
|
|
case 'girls': // 女
|
|
|
return '2,3';
|
|
|
default: // 其它
|
|
|
return '1,2,3';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据用户访问的COOKIE判断出频道
|
|
|
*
|
|
|
* @return int
|
|
|
*/
|
|
|
public static function getChannelByCookie()
|
|
|
{
|
|
|
$cookie = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys';
|
|
|
switch (strval($cookie)) {
|
|
|
case 'boys': // 男
|
|
|
return 1;
|
|
|
case 'girls': // 女
|
|
|
return 2;
|
|
|
case 'kids': // 潮童
|
|
|
return 3;
|
|
|
case 'lifestyle': // 创意生活
|
|
|
return 4;
|
|
|
default: // 其它
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 从用户加入购物车的COOKIE取出购物车凭证
|
|
|
*
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function getShoppingKeyByCookie()
|
|
|
{
|
|
|
$cookie = isset($_COOKIE['_SPK']) ? $_COOKIE['_SPK'] : '';
|
|
|
return $cookie;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取商品的ICON
|
|
|
*
|
|
|
* @param int $type
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function getProductIcon($type)
|
|
|
{
|
|
|
static $icons = array(
|
|
|
1 => 'cloth',
|
|
|
3 => 'pants',
|
|
|
4 => 'dress',
|
|
|
6 => 'shoe',
|
|
|
7 => 'bag',
|
|
|
10 => 'lamp',
|
|
|
241 => 'headset',
|
|
|
8 => 'watch',
|
|
|
360 => 'swim-suit',
|
|
|
308 => 'under'
|
|
|
);
|
|
|
$type = intval($type);
|
|
|
|
|
|
return isset($icons[$type]) ? $icons[$type] : '';
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据排序类型和类型值获得正确的排序参数
|
|
|
* @param integer $order 类型值
|
|
|
* @param string $type 排序类型
|
|
|
* @return string 转换之后的排序参数
|
|
|
*/
|
|
|
public static function transOrder($order, $type)
|
|
|
{
|
|
|
switch ($type) {
|
|
|
case 'price':
|
|
|
$result = ($order == 0) ? 's_p_desc' : 's_p_asc';
|
|
|
break;
|
|
|
case 'discount':
|
|
|
$result = ($order == 0) ? 'p_d_desc' : 'p_d_asc';
|
|
|
break;
|
|
|
case 'newest':
|
|
|
default:
|
|
|
$result = ($order == 1) ? 's_t_desc' : 's_t_asc';
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 转换价格
|
|
|
*
|
|
|
* @param float|string $price 价格
|
|
|
* @return float|string 转换之后的价格
|
|
|
*/
|
|
|
public static function transPrice($price)
|
|
|
{
|
|
|
return !empty($price) ? number_format($price, 2, '.', '') : 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 格式化商品信息
|
|
|
*
|
|
|
* @param array $productData 需要格式化的商品数据
|
|
|
* @param bool $showTags 控制是否显示标签
|
|
|
* @param bool $showNew 控制是否显示NEW图标
|
|
|
* @param bool $showSale 控制是否显示SALE图标
|
|
|
* @param int $width 图片的宽度
|
|
|
* @param int $height 图片的高度
|
|
|
* @param bool $isApp 判断是不是APP访问
|
|
|
* @param bool $showPoint 商品价格是否显示小数位,默认显示
|
|
|
* @return array | false
|
|
|
*/
|
|
|
public static function formatProduct($productData, $showTags = true, $showNew = true, $showSale = true, $width = 290, $height = 388, $isApp = false, $showPoint = true)
|
|
|
{
|
|
|
// 商品信息有问题,则不显示
|
|
|
if (!isset($productData['product_skn']) || !isset($productData['goods_list'][0])) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 市场价和售价一样,则不显示市场价
|
|
|
if (intval($productData['market_price']) === intval($productData['sales_price'])) {
|
|
|
$productData['market_price'] = false;
|
|
|
}
|
|
|
|
|
|
$flag = false; // 判别默认的商品是否将默认的图片URL赋值到skn
|
|
|
$firstGood = array(); // 第一个skc产品
|
|
|
// 如果设置了默认图片,就取默认的图片
|
|
|
foreach ($productData['goods_list'] as $oneGoods) {
|
|
|
if (empty($firstGood)) {
|
|
|
$firstGood = $oneGoods;
|
|
|
}
|
|
|
|
|
|
// 此skc是默认的,则将图片赋值给skn
|
|
|
if ($oneGoods['is_default'] === 'Y') {
|
|
|
$productData['default_images'] = self::procProductImg($oneGoods);
|
|
|
$flag = true;
|
|
|
}
|
|
|
}
|
|
|
// 如果还未赋值,则取第一个skc产品的默认图片
|
|
|
if (!$flag && !empty($firstGood)) {
|
|
|
$productDatap['default_images'] = self::procProductImg($firstGood);
|
|
|
}
|
|
|
|
|
|
$result = array();
|
|
|
$result['id'] = $productData['product_skn'];
|
|
|
$result['product_id'] = $productData['product_id'];
|
|
|
$result['thumb'] = Images::getImageUrl($productData['default_images'], $width, $height);
|
|
|
$result['name'] = $productData['product_name'];
|
|
|
$result['price'] = empty($productData['market_price']) ? false : $productData['market_price'];
|
|
|
$result['salePrice'] = $productData['sales_price'];
|
|
|
if ($showPoint) {
|
|
|
$result['price'] && $result['price'] .= '.00';
|
|
|
$result['salePrice'] && $result['salePrice'] .= '.00';
|
|
|
}
|
|
|
$result['is_soon_sold_out'] = ($productData['is_soon_sold_out'] === 'Y');
|
|
|
$result['url'] = self::url('/product/pro_' . $productData['product_id'] . '_'
|
|
|
. $productData['goods_list'][0]['goods_id']
|
|
|
. '/' . $productData['cn_alphabet'] . '.html');
|
|
|
// APP访问需要加附加的参数
|
|
|
// 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
|
|
|
if ($isApp) {
|
|
|
$result['url'] .= '?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":' . $productData['product_skn'] . '}}';
|
|
|
}
|
|
|
|
|
|
if ($showTags) {
|
|
|
$result['tags'] = array();
|
|
|
$result['tags']['is_new'] = $showNew && isset($productData['is_new']) && $productData['is_new'] === 'Y'; // 新品
|
|
|
$result['tags']['is_discount'] = $showSale && isset($productData['is_discount']) && $productData['is_discount'] === 'Y'; // 在售
|
|
|
$result['tags']['is_limited'] = isset($productData['is_limited']) && $productData['is_limited'] === 'Y'; // 限量
|
|
|
$result['tags']['is_yohood'] = isset($productData['is_yohood']) && $productData['is_yohood'] === 'Y'; // YOHOOD
|
|
|
$result['tags']['midYear'] = isset($productData['mid-year']) && $productData['mid-year'] === 'Y'; // 年中
|
|
|
$result['tags']['yearEnd'] = isset($productData['year-end']) && $productData['year-end'] === 'Y'; // 年末
|
|
|
$result['tags']['is_advance'] = isset($productData['is_advance']) && $productData['is_advance'] === 'Y'; // 再到着
|
|
|
// 打折与即将售完组合显示打折
|
|
|
if ($result['is_soon_sold_out'] && $result['tags']['is_discount']) {
|
|
|
$result['tags']['is_new'] = false;
|
|
|
}
|
|
|
// 打折与其它组合则隐藏打折
|
|
|
elseif ($result['tags']['is_discount'] &&
|
|
|
($result['tags']['is_new'] || $result['tags']['is_limited'] || $result['tags']['is_yohood'] || $result['tags']['is_advance'])) {
|
|
|
$result['tags']['is_discount'] = false;
|
|
|
}
|
|
|
// YOHOOD和新品组合显示YOHOOD
|
|
|
elseif ($result['tags']['is_yohood'] && $result['tags']['is_new']) {
|
|
|
$result['tags']['is_new'] = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据性别来决定 默认图片获取字段 如果是 2、3 则优先从cover2 --》 cover1 -- 》 images_url
|
|
|
* 否则优先从cover1 --》 cover2 -- 》 images_url
|
|
|
* @param array $images
|
|
|
* @return string 商品图片
|
|
|
*/
|
|
|
private static function procProductImg($images)
|
|
|
{
|
|
|
$imgUrl = isset($images['images_url']) ? $images['images_url'] : '';
|
|
|
$cover1 = isset($images['cover_1']) ? $images['cover_1'] : '';
|
|
|
$cover2 = isset($images['cover_2']) ? $images['cover_2'] : '';
|
|
|
$gender = self::getGenderByCookie();
|
|
|
if ($gender === '2,3') {
|
|
|
return !empty($cover2) ? $cover2 : (!empty($cover1) ? $cover1 : $imgUrl);
|
|
|
} else {
|
|
|
return !empty($cover1) ? $cover1 : (!empty($cover2) ? $cover2 : $imgUrl);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 格式化资讯文章
|
|
|
*
|
|
|
* @param array $articleData 需要格式化的资讯数据
|
|
|
* @param bool $showTag 是否显示左上角标签
|
|
|
* @param mixed $isApp 是否显示分享,在APP客户端里嵌入需要传url链接
|
|
|
* @param bool $showAuthor 控制是否显示作者信息
|
|
|
* @param int $uid 当前登录的用户ID
|
|
|
* @return array | false
|
|
|
*/
|
|
|
public static function formatArticle($articleData, $showTag = true, $isApp = false, $showAuthor = true, $uid = null)
|
|
|
{
|
|
|
// 资讯ID不存在,则不显示
|
|
|
if (!isset($articleData['id'])) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
$result = array();
|
|
|
$result['id'] = $articleData['id'];
|
|
|
$result['showTags'] = $showTag;
|
|
|
$result['img'] = self::getImageUrl($articleData['src'], 640, 640);
|
|
|
$result['url'] = $isApp ? $articleData['url'] : self::url('/info/index', array('id' => $articleData['id']), 'guang');
|
|
|
$result['title'] = $articleData['title'];
|
|
|
$result['text'] = $articleData['intro'];
|
|
|
$result['publishTime'] = $articleData['publish_time'];
|
|
|
$result['pageView'] = $articleData['views_num'];
|
|
|
|
|
|
// 收藏
|
|
|
if ($isApp) {
|
|
|
$result['collect'] = array();
|
|
|
$result['collect']['isCollected'] = isset($articleData['isFavor']) && $articleData['isFavor'] === 'Y';
|
|
|
$result['collect']['url'] = !empty($uid) ? 'javascript:;' : strtr($articleData['url'], array('"islogin":"N"' => '"islogin":"Y"'));
|
|
|
}
|
|
|
// 点赞
|
|
|
else {
|
|
|
$result['like'] = array();
|
|
|
$result['like']['count'] = $articleData['praise_num'];
|
|
|
$result['like']['isLiked'] = isset($articleData['isPraise']) && $articleData['isPraise'] === 'Y';
|
|
|
}
|
|
|
|
|
|
// 分享链接
|
|
|
$result['share'] = $isApp && isset($articleData['share']['url']) ? $articleData['share']['url'] : false;
|
|
|
|
|
|
// 判断是否显示作者信息
|
|
|
if ($showAuthor && !empty($articleData['author'])) {
|
|
|
if (!$isApp) {
|
|
|
$articleData['author']['url'] = Helpers::getFilterUrl($articleData['author']['url']);
|
|
|
}
|
|
|
$result['author'] = $articleData['author'];
|
|
|
}
|
|
|
|
|
|
// 模板中需要的标签标识
|
|
|
if ($showTag && isset($articleData['category_id'])) {
|
|
|
switch (strval($articleData['category_id'])) {
|
|
|
case '1': // 话题
|
|
|
$result['isTopic'] = true;
|
|
|
break;
|
|
|
case '2': // 搭配
|
|
|
$result['isCollocation'] = true;
|
|
|
break;
|
|
|
case '3': // 潮人
|
|
|
$result['isFashionMan'] = true;
|
|
|
break;
|
|
|
case '4': // 潮品
|
|
|
$result['isFashionGood'] = true;
|
|
|
break;
|
|
|
case '5': // 小贴士
|
|
|
$result['isTip'] = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 格式化广告焦点图数据
|
|
|
*
|
|
|
* @param array $bannerData 需要格式化的广告图数据
|
|
|
* @param int $width 图片的宽度
|
|
|
* @param int $height 图片的高度
|
|
|
* @param int $mode 使用的七牛模式
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function formatBanner($bannerData, $width, $height, $mode = 2)
|
|
|
{
|
|
|
$result = array();
|
|
|
|
|
|
$result['img'] = self::getImageUrl($bannerData['src'], $width, $height, $mode);
|
|
|
if (isset($bannerData['url'])) {
|
|
|
$result['url'] = self::getFilterUrl($bannerData['url']);
|
|
|
}
|
|
|
$result['title'] = $bannerData['title'];
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 生成公开的TOKEN凭证
|
|
|
*
|
|
|
* @param string $string 字符串
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function makeToken($string)
|
|
|
{
|
|
|
return md5(md5($string . '#@!@#'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 验证TOKEN凭证
|
|
|
*
|
|
|
* @param string $string 字符串
|
|
|
* @param string $token 公开访问TOKEN
|
|
|
* @return bool
|
|
|
*/
|
|
|
public static function verifyToken($string, $token)
|
|
|
{
|
|
|
if ($token === self::makeToken($string)) {
|
|
|
return true;
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 验证手机是否合法
|
|
|
*
|
|
|
* @param int $mobile
|
|
|
* @return boolean
|
|
|
*/
|
|
|
public static function verifyMobile($mobile)
|
|
|
{
|
|
|
if (empty($mobile)) {
|
|
|
return false;
|
|
|
}
|
|
|
return (bool) preg_match('/^1[3|4|5|8|7][0-9]{9}$/', trim($mobile));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 验证密码是否合法
|
|
|
*
|
|
|
* @param int $password
|
|
|
* @return boolean
|
|
|
*/
|
|
|
public static function verifyPassword($password)
|
|
|
{
|
|
|
if (empty($password)) {
|
|
|
return false;
|
|
|
}
|
|
|
return (bool) preg_match('/^([a-zA-Z0-9\-\+_!@\#$%\^&\*\(\)\:\;\.=\[\]\\\',\?]){6,20}$/', trim($password));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 验证邮箱是否合法
|
|
|
*
|
|
|
* @param string $email
|
|
|
* @return boolean
|
|
|
*/
|
|
|
public static function verifyEmail($email)
|
|
|
{
|
|
|
if (empty($email)) {
|
|
|
return false;
|
|
|
}
|
|
|
return !!filter_var($email, FILTER_VALIDATE_EMAIL);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 验证国际手机号是否合法
|
|
|
*
|
|
|
* @param string $areaMobile
|
|
|
* @return boolean
|
|
|
*/
|
|
|
public static function verifyAreaMobile($areaMobile)
|
|
|
{
|
|
|
if (empty($areaMobile)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!strpos($areaMobile, '-')) {
|
|
|
return self::areaMobielVerify($areaMobile);
|
|
|
} else {
|
|
|
$mobileData = explode('-', $areaMobile);
|
|
|
if (count($mobileData) != 2) {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
return self::areaMobielVerify($mobileData[1], $mobileData[0]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据url获取拼接之后的地址,用于用户清理缓存
|
|
|
* @param string $url url地址
|
|
|
* @param string $channel 频道,默认为woman
|
|
|
*
|
|
|
* @return string 处理之后的地址
|
|
|
*/
|
|
|
public static function transUrl($url, $channel='woman') {
|
|
|
|
|
|
$extra = '';
|
|
|
if(!empty($url) && stripos($url, '?') === false) {
|
|
|
$extra = '?channel='.$channel;
|
|
|
}
|
|
|
if(!empty($url) && stripos($url, '?') !== false){
|
|
|
$extra = '&channel='.$channel;
|
|
|
}
|
|
|
return $url . $extra;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 各国手机号规则
|
|
|
*/
|
|
|
private static function areaMobielVerify($mobile, $area = 86)
|
|
|
{
|
|
|
$verify = array(
|
|
|
86 => array(
|
|
|
'name' => '中国',
|
|
|
'match' => (bool) preg_match('/^1[3|4|5|8|7][0-9]{9}$/', trim($mobile)),
|
|
|
),
|
|
|
852 => array(
|
|
|
'name' => '中国香港',
|
|
|
'match' => (bool) preg_match('/^[9|6|5][0-9]{7}$/', trim($mobile)),
|
|
|
),
|
|
|
853 => array(
|
|
|
'name' => '中国澳门',
|
|
|
'match' => (bool) preg_match('/^[0-9]{8}$/', trim($mobile)),
|
|
|
),
|
|
|
886 => array(
|
|
|
'name' => '中国台湾',
|
|
|
'match' => (bool) preg_match('/^[0-9]{10}$/', trim($mobile)),
|
|
|
),
|
|
|
65 => array(
|
|
|
'name' => '新加坡',
|
|
|
'match' => (bool) preg_match('/^[9|8][0-9]{7}$/', trim($mobile)),
|
|
|
),
|
|
|
60 => array(
|
|
|
'name' => '马来西亚',
|
|
|
'match' => (bool) preg_match('/^1[1|2|3|4|6|7|9][0-9]{8}$/', trim($mobile)),
|
|
|
),
|
|
|
1 => array(
|
|
|
'name' => '加拿大&美国',
|
|
|
'match' => (bool) preg_match('/^[0-9]{10}$/', trim($mobile)),
|
|
|
),
|
|
|
82 => array(
|
|
|
'name' => '韩国',
|
|
|
'match' => (bool) preg_match('/^01[0-9]{9}$/', trim($mobile)),
|
|
|
),
|
|
|
44 => array(
|
|
|
'name' => '英国',
|
|
|
'match' => (bool) preg_match('/^7[7|8|9][0-9]{8}$/', trim($mobile)),
|
|
|
),
|
|
|
81 => array(
|
|
|
'name' => '日本',
|
|
|
'match' => (bool) preg_match('/^0[9|8|7][0-9]{9}$/', trim($mobile)),
|
|
|
),
|
|
|
61 => array(
|
|
|
'name' => '澳大利亚',
|
|
|
'match' => (bool) preg_match('/^[0-9]{11}$/', trim($mobile)),
|
|
|
),
|
|
|
);
|
|
|
if (isset($verify[$area])) {
|
|
|
return $verify[$area]['match'];
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 格式化订单商品
|
|
|
*
|
|
|
* @param array $orderGoods 订单
|
|
|
* @param int $count 计订单件数
|
|
|
* @param bool $haveLink 控制是否需要商品链接
|
|
|
* @return array $arr 处理之后的订单商品数据
|
|
|
*/
|
|
|
public static function formatOrderGoods($orderGoods, &$count = 0, $haveLink = false)
|
|
|
{
|
|
|
$arr = array();
|
|
|
|
|
|
foreach ($orderGoods as $key => $vo) {
|
|
|
$arr[$key]['thumb'] = Helpers::getImageUrl($vo['goods_image'], 90, 120);
|
|
|
$arr[$key]['name'] = $vo['product_name'];
|
|
|
$arr[$key]['color'] = $vo['color_name'];
|
|
|
$arr[$key]['size'] = $vo['size_name'];
|
|
|
$arr[$key]['price'] = $vo['goods_price'];
|
|
|
$arr[$key]['count'] = $vo['buy_number'];
|
|
|
//gift=>是否赠品,advanceBuy=>是否加价购;
|
|
|
if ($vo['goods_type'] == 'gift') {
|
|
|
$arr[$key]['gift'] = true;
|
|
|
} elseif ($vo['goods_type'] == 'price_gift') {
|
|
|
$arr[$key]['advanceBuy'] = true;
|
|
|
}
|
|
|
// 上市期
|
|
|
if (!empty($vo['expect_arrival_time'])) {
|
|
|
$arr[$key]['appearDate'] = $vo['expect_arrival_time'];
|
|
|
}
|
|
|
// 商品链接
|
|
|
if ($haveLink && isset($vo['product_skn'])) {
|
|
|
$arr[$key]['link'] = self::url('/product/show_' . $vo['product_skn'] . '.html');
|
|
|
}
|
|
|
// 累计购买数
|
|
|
$count += intval($vo['buy_number']);
|
|
|
}
|
|
|
|
|
|
return $arr;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 格式化购物车商品
|
|
|
*
|
|
|
* @param array $cartGoods 购物车商品列表
|
|
|
* @param boolean $isValid 是否是可用商品(非失效商品),默认是
|
|
|
* @param bool $isAdvanceCart 是否是预售购物车(和上市期有关)
|
|
|
* @return array 处理之后的购物车商品数据
|
|
|
*/
|
|
|
public static function formatCartGoods($cartGoods, $isAdvanceCart, $isValid = true)
|
|
|
{
|
|
|
$arr = array();
|
|
|
|
|
|
$oneGoods = array();
|
|
|
foreach ($cartGoods as $key => $value) {
|
|
|
$oneGoods = array();
|
|
|
$oneGoods['id'] = $value['product_sku'];
|
|
|
$oneGoods['skn'] = $value['product_skn'];
|
|
|
$oneGoods['name'] = $value['product_name'];
|
|
|
$oneGoods['thumb'] = !empty($value['goods_images']) ? Images::getImageUrl($value['goods_images'], 120, 160) : '';
|
|
|
$oneGoods['color'] = $value['color_name'];
|
|
|
$oneGoods['size'] = $value['size_name'];
|
|
|
$oneGoods['checked'] = $value['selected'] === 'Y';
|
|
|
$oneGoods['price'] = self::transPrice($value['last_vip_price']);
|
|
|
$oneGoods['isVipPrice'] = $value['sales_price'] !== $value['last_vip_price'];
|
|
|
$oneGoods['count'] = $value['buy_number'];
|
|
|
|
|
|
if ($isValid) {
|
|
|
// 库存不足
|
|
|
$oneGoods['lowStocks'] = ($value['buy_number'] > $value['storage_number']);
|
|
|
} else { // 失效商品
|
|
|
$oneGoods['inValid'] = true;
|
|
|
}
|
|
|
|
|
|
//gift=>是否赠品,advanceBuy=>是否加价购,soldOut=>失效商品;
|
|
|
if (!isset($value['goods_type'])) {
|
|
|
$oneGoods['inValid'] = true;
|
|
|
} elseif ($value['goods_type'] == 'gift' && !isset($value['isAdvanceBuy'])) {
|
|
|
$oneGoods['isGift'] = true;
|
|
|
$oneGoods['salesPrice'] = self::transPrice($value['sales_price']);
|
|
|
$oneGoods['price'] = self::transPrice($value['last_price']);
|
|
|
} elseif ($value['goods_type'] == 'price_gift') {
|
|
|
$oneGoods['showCheckbox'] = true;
|
|
|
$oneGoods['isAdvanceBuy'] = true;
|
|
|
$oneGoods['salesPrice'] = self::transPrice($value['sales_price']);
|
|
|
$oneGoods['price'] = self::transPrice($value['last_price']);
|
|
|
} else {
|
|
|
$oneGoods['showCheckbox'] = true;
|
|
|
}
|
|
|
|
|
|
// 上市期
|
|
|
if ($isAdvanceCart && !empty($value['expect_arrival_time'])) {
|
|
|
$oneGoods['appearDate'] = $value['expect_arrival_time'];
|
|
|
}
|
|
|
// 商品链接
|
|
|
$oneGoods['link'] = self::url('/product/show_' . $value['product_skn'] . '.html');
|
|
|
|
|
|
$arr[$key] = $oneGoods;
|
|
|
}
|
|
|
|
|
|
return $arr;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 格式化加价购和赠品商品
|
|
|
*
|
|
|
* @param array $advanceGoods 加价购商品列表
|
|
|
* @param int $count 计商品件数
|
|
|
* @return array $arr 处理之后的加价购商品数据
|
|
|
*/
|
|
|
public static function formatAdvanceGoods($advanceGoods, &$count = 0)
|
|
|
{
|
|
|
$arr = array();
|
|
|
|
|
|
$gift = array();
|
|
|
$oneGoods = array();
|
|
|
$number = 0;
|
|
|
foreach ($advanceGoods as $value) {
|
|
|
$gift = array();
|
|
|
$gift['promotionId'] = $value['promotion_id'];
|
|
|
$gift['promotionTitle'] = $value['promotion_title'];
|
|
|
|
|
|
$number = 0;
|
|
|
foreach ($value['goods_list'] as $single) {
|
|
|
$oneGoods = array();
|
|
|
$oneGoods['id'] = $single['product_skn'];
|
|
|
$oneGoods['name'] = $single['product_name'];
|
|
|
$oneGoods['thumb'] = !empty($single['goods_images']) ? Images::getImageUrl($single['goods_images'], 120, 160) : '';
|
|
|
$oneGoods['price'] = self::transPrice($single['last_price']);
|
|
|
$oneGoods['marketPrice'] = self::transPrice($single['market_price']);
|
|
|
$oneGoods['count'] = $single['storage_number'];
|
|
|
|
|
|
$gift['goods'][] = $oneGoods;
|
|
|
$number ++;
|
|
|
}
|
|
|
|
|
|
$arr[] = $gift;
|
|
|
|
|
|
// 计算加价购商品数目
|
|
|
//$count += count($value['goods_list']);
|
|
|
$count += $number;
|
|
|
}
|
|
|
|
|
|
return $arr;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单状态,按订单支付类型和订单状态
|
|
|
* @var array
|
|
|
*/
|
|
|
public static function getOrderStatus()
|
|
|
{
|
|
|
return array(
|
|
|
'1' => array(//在线支付
|
|
|
0 => '待付款',
|
|
|
1 => '已付款',
|
|
|
2 => '已付款',
|
|
|
3 => '已付款',
|
|
|
4 => '已发货',
|
|
|
5 => '已发货',
|
|
|
6 => '交易成功'
|
|
|
),
|
|
|
'2' => array(//货到付款
|
|
|
0 => '备货中',
|
|
|
1 => '已付款',
|
|
|
2 => '已付款',
|
|
|
3 => '已付款',
|
|
|
4 => '已发货',
|
|
|
5 => '已发货',
|
|
|
6 => '交易成功'
|
|
|
),
|
|
|
'3' => array(//现金支付
|
|
|
0 => '待付款',
|
|
|
1 => '已付款',
|
|
|
2 => '已付款',
|
|
|
3 => '已付款',
|
|
|
4 => '已发货',
|
|
|
5 => '已发货',
|
|
|
6 => '交易成功'
|
|
|
),
|
|
|
'4' => array(//抵消支付
|
|
|
0 => '待付款',
|
|
|
1 => '已付款',
|
|
|
2 => '已付款',
|
|
|
3 => '已付款',
|
|
|
4 => '已发货',
|
|
|
5 => '已发货',
|
|
|
6 => '交易成功'
|
|
|
)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取会员的级别
|
|
|
*
|
|
|
* @param string $vipInfo
|
|
|
* @return int
|
|
|
*/
|
|
|
public static function getVipLevel($vipInfo)
|
|
|
{
|
|
|
$vipLevel = 0;
|
|
|
|
|
|
switch ($vipInfo) {
|
|
|
case '普通会员':
|
|
|
$vipLevel = 0;
|
|
|
break;
|
|
|
case '银卡会员':
|
|
|
$vipLevel = 1;
|
|
|
break;
|
|
|
case '金卡会员':
|
|
|
$vipLevel = 2;
|
|
|
break;
|
|
|
case '白金会员':
|
|
|
$vipLevel = 3;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return $vipLevel;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 同步用户的会话
|
|
|
*
|
|
|
* 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION
|
|
|
*
|
|
|
* @param int $uid 用户ID
|
|
|
* @param string $refer 访问来源
|
|
|
* @param string $callback 回调方法名
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function syncUserSession($uid, $refer = '', $callback = 'call')
|
|
|
{
|
|
|
return 'http://m1.yohobuy.com/Passport/session/index?callback=' . $callback
|
|
|
. '&sign=' . md5(md5($uid . 'Js8Yn0!EwPM45-ws')) . '&uid=' . $uid . '&go=' . $refer;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 退出清除用户的会话
|
|
|
*
|
|
|
* 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION
|
|
|
*
|
|
|
* @param int $uid 用户ID
|
|
|
* @param string $refer 访问来源
|
|
|
* @param string $callback 回调方法名
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function logoutSession($token, $refer = '', $callback = 'call')
|
|
|
{
|
|
|
return 'http://m1.yohobuy.com/Passport/session/logout?callback=' . $callback
|
|
|
. '&sign=' . md5(md5('Js8Yn0!EwPM45-ws')) . '&token=' . $token . '&go=' . $refer;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据skc获取商品链接
|
|
|
* @param unknown $productSkc
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function getUrlBySkc($product_id, $goods_id, $cn_alphabet='')
|
|
|
{
|
|
|
if (empty($cn_alphabet)) {
|
|
|
$cn_alphabet = 'goods.html';
|
|
|
}
|
|
|
return 'http://item.yohobuy.com/product/pro_' . $product_id . '_' . $goods_id . '/' . $cn_alphabet. '.html';
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取真实IP
|
|
|
*
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function getClientIp()
|
|
|
{
|
|
|
$ip = '0.0.0.0';
|
|
|
if (isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP'] != '')
|
|
|
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
|
|
elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != '')
|
|
|
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
|
|
elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] != '')
|
|
|
$ip = $_SERVER['REMOTE_ADDR'];
|
|
|
return $ip;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 组合国际手机号
|
|
|
* @param $area
|
|
|
* @param $mobile
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function makeMobile($area, $mobile){
|
|
|
if(empty($area) || $area == 86){
|
|
|
return $mobile;
|
|
|
}
|
|
|
return $area.'-'.$mobile;
|
|
|
}
|
|
|
} |
|
|
<?php
|
|
|
|
|
|
namespace Plugin;
|
|
|
|
|
|
/**
|
|
|
* 辅助类
|
|
|
*/
|
|
|
class Helpers
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
* 构建网站的URL
|
|
|
*
|
|
|
* 备注:所有的URL构建都尽量使用该方法,便于以后维护.
|
|
|
*
|
|
|
* @param string $uri 如 "/passport/reg/index"
|
|
|
* @param array $param 参数项 array(key1 => value1, key2 => value2,),默认为array()
|
|
|
* @param string $module 模块名 如"index"表示默认, "guang"表示逛,"list"表示商品列表,"search"表示搜索
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function url($uri, $param = array(), $module = 'index')
|
|
|
{
|
|
|
$url = '';
|
|
|
|
|
|
switch ($module) {
|
|
|
case 'default':
|
|
|
$url = 'http://m.yohobuy.com';
|
|
|
break;
|
|
|
case 'guang': // 逛
|
|
|
$url = 'http://guang' . SUB_DOMAIN;
|
|
|
break;
|
|
|
case 'list': // 商品列表
|
|
|
$url = 'http://list' . SUB_DOMAIN;
|
|
|
break;
|
|
|
case 'search': // 搜索
|
|
|
$url = 'http://search' . SUB_DOMAIN;
|
|
|
break;
|
|
|
case 'index': // 默认
|
|
|
$url = SITE_MAIN;
|
|
|
break;
|
|
|
case '': // 相对地址
|
|
|
break;
|
|
|
default: // 其它子域名
|
|
|
$url = 'http://' . $module . SUB_DOMAIN;
|
|
|
}
|
|
|
$url .= $uri;
|
|
|
if (!empty($param)) {
|
|
|
$url .= '?' . http_build_query($param, null, '&');
|
|
|
}
|
|
|
|
|
|
return $url;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据尺寸获得图片url
|
|
|
*
|
|
|
* @param string $url 路径
|
|
|
* @param integer $width 图片宽度
|
|
|
* @param integer $height 图片高度
|
|
|
* @param integer $mode 模式
|
|
|
* @return string 图片地址
|
|
|
*/
|
|
|
public static function getImageUrl($url, $width, $height, $mode = 2)
|
|
|
{
|
|
|
return strtr($url, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取过滤APP里附加参数后的URL链接
|
|
|
*
|
|
|
* @param string $url 路径
|
|
|
* @return string 去除掉如&openby:yohobuy={"action":"go.brand"}这样的APP附加参数
|
|
|
*/
|
|
|
public static function getFilterUrl($url)
|
|
|
{
|
|
|
$url = strtr($url, array('.m.yohobuy.com' => SUB_DOMAIN, OLD_MAIN => SITE_MAIN, 'www.yohobuy.com' => SITE_MAIN));
|
|
|
$filter = strstr($url, 'openby:yohobuy=', true);
|
|
|
if ($filter) {
|
|
|
return rtrim(rtrim($filter, '?'), '&');
|
|
|
} else {
|
|
|
return $url;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据用户访问的COOKIE判断出性别
|
|
|
*
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function getGenderByCookie()
|
|
|
{
|
|
|
$cookie = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys';
|
|
|
switch (strval($cookie)) {
|
|
|
case 'boys': // 男
|
|
|
return '1,3';
|
|
|
case 'girls': // 女
|
|
|
return '2,3';
|
|
|
default: // 其它
|
|
|
return '1,2,3';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据用户访问的COOKIE判断出频道
|
|
|
*
|
|
|
* @return int
|
|
|
*/
|
|
|
public static function getChannelByCookie()
|
|
|
{
|
|
|
$cookie = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys';
|
|
|
switch (strval($cookie)) {
|
|
|
case 'boys': // 男
|
|
|
return 1;
|
|
|
case 'girls': // 女
|
|
|
return 2;
|
|
|
case 'kids': // 潮童
|
|
|
return 3;
|
|
|
case 'lifestyle': // 创意生活
|
|
|
return 4;
|
|
|
default: // 其它
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 从用户加入购物车的COOKIE取出购物车凭证
|
|
|
*
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function getShoppingKeyByCookie()
|
|
|
{
|
|
|
$cookie = isset($_COOKIE['_SPK']) ? $_COOKIE['_SPK'] : '';
|
|
|
|
|
|
return $cookie;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取商品的ICON
|
|
|
*
|
|
|
* @param int $type
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function getProductIcon($type)
|
|
|
{
|
|
|
static $icons = array(
|
|
|
1 => 'cloth',
|
|
|
3 => 'pants',
|
|
|
4 => 'dress',
|
|
|
6 => 'shoe',
|
|
|
7 => 'bag',
|
|
|
10 => 'lamp',
|
|
|
241 => 'headset',
|
|
|
8 => 'watch',
|
|
|
360 => 'swim-suit',
|
|
|
308 => 'under'
|
|
|
);
|
|
|
$type = intval($type);
|
|
|
|
|
|
return isset($icons[$type]) ? $icons[$type] : '';
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据排序类型和类型值获得正确的排序参数
|
|
|
* @param integer $order 类型值
|
|
|
* @param string $type 排序类型
|
|
|
* @return string 转换之后的排序参数
|
|
|
*/
|
|
|
public static function transOrder($order, $type)
|
|
|
{
|
|
|
switch ($type) {
|
|
|
case 'price':
|
|
|
$result = ($order == 0) ? 's_p_desc' : 's_p_asc';
|
|
|
break;
|
|
|
case 'discount':
|
|
|
$result = ($order == 0) ? 'p_d_desc' : 'p_d_asc';
|
|
|
break;
|
|
|
case 'newest':
|
|
|
default:
|
|
|
$result = ($order == 1) ? 's_t_desc' : 's_t_asc';
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 转换价格
|
|
|
*
|
|
|
* @param float|string $price 价格
|
|
|
* @return float|string 转换之后的价格
|
|
|
*/
|
|
|
public static function transPrice($price)
|
|
|
{
|
|
|
return number_format($price, 2, '.', '');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 格式化商品信息
|
|
|
*
|
|
|
* @param array $productData 需要格式化的商品数据
|
|
|
* @param bool $showTags 控制是否显示标签
|
|
|
* @param bool $showNew 控制是否显示NEW图标
|
|
|
* @param bool $showSale 控制是否显示SALE图标
|
|
|
* @param int $width 图片的宽度
|
|
|
* @param int $height 图片的高度
|
|
|
* @param bool $isApp 判断是不是APP访问
|
|
|
* @param bool $showPoint 商品价格是否显示小数位,默认显示
|
|
|
* @return array | false
|
|
|
*/
|
|
|
public static function formatProduct($productData, $showTags = true, $showNew = true, $showSale = true, $width = 290, $height = 388, $isApp = false, $showPoint = true)
|
|
|
{
|
|
|
// 商品信息有问题,则不显示
|
|
|
if (!isset($productData['product_skn']) || !isset($productData['goods_list'][0])) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 市场价和售价一样,则不显示市场价
|
|
|
if (intval($productData['market_price']) === intval($productData['sales_price'])) {
|
|
|
$productData['market_price'] = false;
|
|
|
}
|
|
|
|
|
|
// 如果$productData['default_images']为空,就取$productData['goods_list']中第一个,为空就不处理
|
|
|
if (empty($productData['default_images'])) {
|
|
|
$productData['default_images'] = $productData['goods_list'][0]['images_url'];
|
|
|
}
|
|
|
|
|
|
$result = array();
|
|
|
$result['id'] = $productData['product_skn'];
|
|
|
$result['product_id'] = $productData['product_id'];
|
|
|
$result['thumb'] = Images::getImageUrl($productData['default_images'], $width, $height);
|
|
|
$result['name'] = $productData['product_name'];
|
|
|
$result['price'] = empty($productData['market_price']) ? false : $productData['market_price'];
|
|
|
$result['salePrice'] = $productData['sales_price'];
|
|
|
if ($showPoint) {
|
|
|
$result['price'] && $result['price'] .= '.00';
|
|
|
$result['salePrice'] && $result['salePrice'] .= '.00';
|
|
|
}
|
|
|
$result['is_soon_sold_out'] = ($productData['is_soon_sold_out'] === 'Y');
|
|
|
$result['url'] = self::url('/product/pro_' . $productData['product_id'] . '_'
|
|
|
. $productData['goods_list'][0]['goods_id']
|
|
|
. '/' . $productData['cn_alphabet'] . '.html');
|
|
|
// APP访问需要加附加的参数
|
|
|
// 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
|
|
|
if ($isApp) {
|
|
|
$result['url'] .= '?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":' . $productData['product_skn'] . '}}';
|
|
|
}
|
|
|
|
|
|
if ($showTags) {
|
|
|
$result['tags'] = array();
|
|
|
$result['tags']['is_new'] = $showNew && isset($productData['is_new']) && $productData['is_new'] === 'Y'; // 新品
|
|
|
$result['tags']['is_discount'] = $showSale && isset($productData['is_discount']) && $productData['is_discount'] === 'Y'; // 在售
|
|
|
$result['tags']['is_limited'] = isset($productData['is_limited']) && $productData['is_limited'] === 'Y'; // 限量
|
|
|
$result['tags']['is_yohood'] = isset($productData['is_yohood']) && $productData['is_yohood'] === 'Y'; // YOHOOD
|
|
|
$result['tags']['midYear'] = isset($productData['mid-year']) && $productData['mid-year'] === 'Y'; // 年中
|
|
|
$result['tags']['yearEnd'] = isset($productData['year-end']) && $productData['year-end'] === 'Y'; // 年末
|
|
|
$result['tags']['is_advance'] = isset($productData['is_advance']) && $productData['is_advance'] === 'Y'; // 再到着
|
|
|
// 打折与即将售完组合显示打折
|
|
|
if ($result['is_soon_sold_out'] && $result['tags']['is_discount']) {
|
|
|
$result['tags']['is_new'] = false;
|
|
|
}
|
|
|
// 打折与其它组合则隐藏打折
|
|
|
elseif ($result['tags']['is_discount'] &&
|
|
|
($result['tags']['is_new'] || $result['tags']['is_limited'] || $result['tags']['is_yohood'] || $result['tags']['is_advance'])) {
|
|
|
$result['tags']['is_discount'] = false;
|
|
|
}
|
|
|
// YOHOOD和新品组合显示YOHOOD
|
|
|
elseif ($result['tags']['is_yohood'] && $result['tags']['is_new']) {
|
|
|
$result['tags']['is_new'] = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 格式化资讯文章
|
|
|
*
|
|
|
* @param array $articleData 需要格式化的资讯数据
|
|
|
* @param bool $showTag 是否显示左上角标签
|
|
|
* @param mixed $isApp 是否显示分享,在APP客户端里嵌入需要传url链接
|
|
|
* @param bool $showAuthor 控制是否显示作者信息
|
|
|
* @param int $uid 当前登录的用户ID
|
|
|
* @return array | false
|
|
|
*/
|
|
|
public static function formatArticle($articleData, $showTag = true, $isApp = false, $showAuthor = true, $uid = null)
|
|
|
{
|
|
|
// 资讯ID不存在,则不显示
|
|
|
if (!isset($articleData['id'])) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
$result = array();
|
|
|
$result['id'] = $articleData['id'];
|
|
|
$result['showTags'] = $showTag;
|
|
|
$result['img'] = self::getImageUrl($articleData['src'], 640, 640);
|
|
|
$result['url'] = $isApp ? $articleData['url'] : self::url('/info/index', array('id' => $articleData['id']), 'guang');
|
|
|
$result['title'] = $articleData['title'];
|
|
|
$result['text'] = $articleData['intro'];
|
|
|
$result['publishTime'] = $articleData['publish_time'];
|
|
|
$result['pageView'] = $articleData['views_num'];
|
|
|
|
|
|
// 收藏
|
|
|
if ($isApp) {
|
|
|
$result['collect'] = array();
|
|
|
$result['collect']['isCollected'] = isset($articleData['isFavor']) && $articleData['isFavor'] === 'Y';
|
|
|
$result['collect']['url'] = !empty($uid) ? 'javascript:;' : strtr($articleData['url'], array('"islogin":"N"' => '"islogin":"Y"'));
|
|
|
}
|
|
|
// 点赞
|
|
|
else {
|
|
|
$result['like'] = array();
|
|
|
$result['like']['count'] = $articleData['praise_num'];
|
|
|
$result['like']['isLiked'] = isset($articleData['isPraise']) && $articleData['isPraise'] === 'Y';
|
|
|
}
|
|
|
|
|
|
// 分享链接
|
|
|
$result['share'] = $isApp && isset($articleData['share']['url']) ? $articleData['share']['url'] : false;
|
|
|
|
|
|
// 判断是否显示作者信息
|
|
|
if ($showAuthor && !empty($articleData['author'])) {
|
|
|
if (!$isApp) {
|
|
|
$articleData['author']['url'] = Helpers::getFilterUrl($articleData['author']['url']);
|
|
|
}
|
|
|
$result['author'] = $articleData['author'];
|
|
|
}
|
|
|
|
|
|
// 模板中需要的标签标识
|
|
|
if ($showTag && isset($articleData['category_id'])) {
|
|
|
switch (strval($articleData['category_id'])) {
|
|
|
case '1': // 话题
|
|
|
$result['isTopic'] = true;
|
|
|
break;
|
|
|
case '2': // 搭配
|
|
|
$result['isCollocation'] = true;
|
|
|
break;
|
|
|
case '3': // 潮人
|
|
|
$result['isFashionMan'] = true;
|
|
|
break;
|
|
|
case '4': // 潮品
|
|
|
$result['isFashionGood'] = true;
|
|
|
break;
|
|
|
case '5': // 小贴士
|
|
|
$result['isTip'] = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 格式化广告焦点图数据
|
|
|
*
|
|
|
* @param array $bannerData 需要格式化的广告图数据
|
|
|
* @param int $width 图片的宽度
|
|
|
* @param int $height 图片的高度
|
|
|
* @param int $mode 使用的七牛模式
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function formatBanner($bannerData, $width, $height, $mode = 2)
|
|
|
{
|
|
|
$result = array();
|
|
|
|
|
|
$result['img'] = self::getImageUrl($bannerData['src'], $width, $height, $mode);
|
|
|
if (isset($bannerData['url'])) {
|
|
|
$result['url'] = self::getFilterUrl($bannerData['url']);
|
|
|
}
|
|
|
$result['title'] = $bannerData['title'];
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 生成公开的TOKEN凭证
|
|
|
*
|
|
|
* @param string $string 字符串
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function makeToken($string)
|
|
|
{
|
|
|
return md5(md5($string . '#@!@#'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 验证TOKEN凭证
|
|
|
*
|
|
|
* @param string $string 字符串
|
|
|
* @param string $token 公开访问TOKEN
|
|
|
* @return bool
|
|
|
*/
|
|
|
public static function verifyToken($string, $token)
|
|
|
{
|
|
|
if ($token === self::makeToken($string)) {
|
|
|
return true;
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 验证手机是否合法
|
|
|
*
|
|
|
* @param int $mobile
|
|
|
* @return boolean
|
|
|
*/
|
|
|
public static function verifyMobile($mobile)
|
|
|
{
|
|
|
if (empty($mobile)) {
|
|
|
return false;
|
|
|
}
|
|
|
return (bool) preg_match('/^1[3|4|5|8|7][0-9]{9}$/', trim($mobile));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 验证密码是否合法
|
|
|
*
|
|
|
* @param int $password
|
|
|
* @return boolean
|
|
|
*/
|
|
|
public static function verifyPassword($password)
|
|
|
{
|
|
|
if (empty($password)) {
|
|
|
return false;
|
|
|
}
|
|
|
return (bool) preg_match('/^([a-zA-Z0-9\-\+_!@\#$%\^&\*\(\)\:\;\.=\[\]\\\',\?]){6,20}$/', trim($password));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 验证邮箱是否合法
|
|
|
*
|
|
|
* @param string $email
|
|
|
* @return boolean
|
|
|
*/
|
|
|
public static function verifyEmail($email)
|
|
|
{
|
|
|
if (empty($email)) {
|
|
|
return false;
|
|
|
}
|
|
|
return !!filter_var($email, FILTER_VALIDATE_EMAIL);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 验证国际手机号是否合法
|
|
|
*
|
|
|
* @param string $areaMobile
|
|
|
* @param int $area
|
|
|
* @return boolean
|
|
|
*/
|
|
|
public static function verifyAreaMobile($areaMobile, $area)
|
|
|
{
|
|
|
if (empty($areaMobile)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!strpos($areaMobile, '-')) {
|
|
|
return self::areaMobielVerify($areaMobile, $area);
|
|
|
} else {
|
|
|
$mobileData = explode('-', $areaMobile);
|
|
|
if (count($mobileData) != 2) {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
return self::areaMobielVerify($mobileData[1], $mobileData[0]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 各国手机号规则
|
|
|
*/
|
|
|
private static function areaMobielVerify($mobile, $area = 86)
|
|
|
{
|
|
|
$verify = array(
|
|
|
86 => array(
|
|
|
'name' => '中国',
|
|
|
'match' => (bool) preg_match('/^1[3|4|5|8|7][0-9]{9}$/', trim($mobile)),
|
|
|
),
|
|
|
852 => array(
|
|
|
'name' => '中国香港',
|
|
|
'match' => (bool) preg_match('/^[9|6|5][0-9]{7}$/', trim($mobile)),
|
|
|
),
|
|
|
853 => array(
|
|
|
'name' => '中国澳门',
|
|
|
'match' => (bool) preg_match('/^[0-9]{8}$/', trim($mobile)),
|
|
|
),
|
|
|
886 => array(
|
|
|
'name' => '中国台湾',
|
|
|
'match' => (bool) preg_match('/^[0-9]{10}$/', trim($mobile)),
|
|
|
),
|
|
|
65 => array(
|
|
|
'name' => '新加坡',
|
|
|
'match' => (bool) preg_match('/^[9|8][0-9]{7}$/', trim($mobile)),
|
|
|
),
|
|
|
60 => array(
|
|
|
'name' => '马来西亚',
|
|
|
'match' => (bool) preg_match('/^1[1|2|3|4|6|7|9][0-9]{8}$/', trim($mobile)),
|
|
|
),
|
|
|
1 => array(
|
|
|
'name' => '加拿大&美国',
|
|
|
'match' => (bool) preg_match('/^[0-9]{10}$/', trim($mobile)),
|
|
|
),
|
|
|
82 => array(
|
|
|
'name' => '韩国',
|
|
|
'match' => (bool) preg_match('/^01[0-9]{9}$/', trim($mobile)),
|
|
|
),
|
|
|
44 => array(
|
|
|
'name' => '英国',
|
|
|
'match' => (bool) preg_match('/^7[7|8|9][0-9]{8}$/', trim($mobile)),
|
|
|
),
|
|
|
81 => array(
|
|
|
'name' => '日本',
|
|
|
'match' => (bool) preg_match('/^0[9|8|7][0-9]{9}$/', trim($mobile)),
|
|
|
),
|
|
|
61 => array(
|
|
|
'name' => '澳大利亚',
|
|
|
'match' => (bool) preg_match('/^[0-9]{11}$/', trim($mobile)),
|
|
|
),
|
|
|
);
|
|
|
if (isset($verify[$area])) {
|
|
|
return $verify[$area]['match'];
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 格式化订单商品
|
|
|
*
|
|
|
* @param array $orderGoods 订单
|
|
|
* @param int $count 计订单件数
|
|
|
* @param bool $haveLink 控制是否需要商品链接
|
|
|
* @return array $arr 处理之后的订单商品数据
|
|
|
*/
|
|
|
public static function formatOrderGoods($orderGoods, &$count = 0, $haveLink = false)
|
|
|
{
|
|
|
$arr = array();
|
|
|
|
|
|
foreach ($orderGoods as $key => $vo) {
|
|
|
$arr[$key]['thumb'] = Helpers::getImageUrl($vo['goods_image'], 90, 120);
|
|
|
$arr[$key]['name'] = $vo['product_name'];
|
|
|
$arr[$key]['color'] = $vo['color_name'];
|
|
|
$arr[$key]['size'] = $vo['size_name'];
|
|
|
$arr[$key]['price'] = $vo['goods_price'];
|
|
|
$arr[$key]['count'] = $vo['buy_number'];
|
|
|
//gift=>是否赠品,advanceBuy=>是否加价购;
|
|
|
if ($vo['goods_type'] == 'gift') {
|
|
|
$arr[$key]['gift'] = true;
|
|
|
} elseif ($vo['goods_type'] == 'price_gift') {
|
|
|
$arr[$key]['advanceBuy'] = true;
|
|
|
}
|
|
|
// 上市期
|
|
|
if (!empty($vo['expect_arrival_time'])) {
|
|
|
$arr[$key]['appearDate'] = $vo['expect_arrival_time'];
|
|
|
}
|
|
|
// 商品链接
|
|
|
if ($haveLink && isset($vo['product_skn'])) {
|
|
|
$arr[$key]['link'] = self::url('/product/show_' . $vo['product_skn'] . '.html');
|
|
|
}
|
|
|
// 累计购买数
|
|
|
$count += intval($vo['buy_number']);
|
|
|
}
|
|
|
|
|
|
return $arr;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 格式化购物车商品
|
|
|
*
|
|
|
* @param array $cartGoods 购物车商品列表
|
|
|
* @param boolean $isValid 是否是可用商品(非失效商品),默认是
|
|
|
* @param bool $isAdvanceCart 是否是预售购物车(和上市期有关)
|
|
|
* @return array 处理之后的购物车商品数据
|
|
|
*/
|
|
|
public static function formatCartGoods($cartGoods, $isAdvanceCart, $isValid = true)
|
|
|
{
|
|
|
$arr = array();
|
|
|
|
|
|
$oneGoods = array();
|
|
|
foreach ($cartGoods as $key => $value) {
|
|
|
$oneGoods = array();
|
|
|
$oneGoods['id'] = $value['product_sku'];
|
|
|
$oneGoods['skn'] = $value['product_skn'];
|
|
|
$oneGoods['name'] = $value['product_name'];
|
|
|
$oneGoods['thumb'] = !empty($value['goods_images']) ? Images::getImageUrl($value['goods_images'], 120, 160) : '';
|
|
|
$oneGoods['color'] = $value['color_name'];
|
|
|
$oneGoods['size'] = $value['size_name'];
|
|
|
$oneGoods['checked'] = $value['selected'] === 'Y';
|
|
|
$oneGoods['price'] = self::transPrice($value['last_vip_price']);
|
|
|
$oneGoods['isVipPrice'] = $value['sales_price'] !== $value['last_vip_price'];
|
|
|
$oneGoods['count'] = $value['buy_number'];
|
|
|
|
|
|
if ($isValid) {
|
|
|
// 库存不足
|
|
|
$oneGoods['lowStocks'] = ($value['buy_number'] > $value['storage_number']);
|
|
|
} else { // 失效商品
|
|
|
$oneGoods['inValid'] = true;
|
|
|
}
|
|
|
|
|
|
//gift=>是否赠品,advanceBuy=>是否加价购,soldOut=>失效商品;
|
|
|
if (!isset($value['goods_type'])) {
|
|
|
$oneGoods['inValid'] = true;
|
|
|
} elseif ($value['goods_type'] == 'gift' && !isset($value['isAdvanceBuy'])) {
|
|
|
$oneGoods['isGift'] = true;
|
|
|
$oneGoods['salesPrice'] = self::transPrice($value['sales_price']);
|
|
|
$oneGoods['price'] = self::transPrice($value['last_price']);
|
|
|
} elseif ($value['goods_type'] == 'price_gift') {
|
|
|
$oneGoods['showCheckbox'] = true;
|
|
|
$oneGoods['isAdvanceBuy'] = true;
|
|
|
$oneGoods['salesPrice'] = self::transPrice($value['sales_price']);
|
|
|
$oneGoods['price'] = self::transPrice($value['last_price']);
|
|
|
} else {
|
|
|
$oneGoods['showCheckbox'] = true;
|
|
|
}
|
|
|
|
|
|
// 上市期
|
|
|
if ($isAdvanceCart && !empty($value['expect_arrival_time'])) {
|
|
|
$oneGoods['appearDate'] = $value['expect_arrival_time'];
|
|
|
}
|
|
|
// 商品链接
|
|
|
$oneGoods['link'] = self::url('/product/show_' . $value['product_skn'] . '.html');
|
|
|
|
|
|
$arr[$key] = $oneGoods;
|
|
|
}
|
|
|
|
|
|
return $arr;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 格式化加价购和赠品商品
|
|
|
*
|
|
|
* @param array $advanceGoods 加价购商品列表
|
|
|
* @param int $count 计商品件数
|
|
|
* @return array $arr 处理之后的加价购商品数据
|
|
|
*/
|
|
|
public static function formatAdvanceGoods($advanceGoods, &$count = 0)
|
|
|
{
|
|
|
$arr = array();
|
|
|
|
|
|
$gift = array();
|
|
|
$oneGoods = array();
|
|
|
$number = 0;
|
|
|
foreach ($advanceGoods as $value) {
|
|
|
$gift = array();
|
|
|
$gift['promotionId'] = $value['promotion_id'];
|
|
|
$gift['promotionTitle'] = $value['promotion_title'];
|
|
|
|
|
|
$number = 0;
|
|
|
foreach ($value['goods_list'] as $single) {
|
|
|
$oneGoods = array();
|
|
|
$oneGoods['id'] = $single['product_skn'];
|
|
|
$oneGoods['name'] = $single['product_name'];
|
|
|
$oneGoods['thumb'] = !empty($single['goods_images']) ? Images::getImageUrl($single['goods_images'], 120, 160) : '';
|
|
|
$oneGoods['price'] = self::transPrice($single['last_price']);
|
|
|
$oneGoods['marketPrice'] = self::transPrice($single['market_price']);
|
|
|
$oneGoods['count'] = $single['storage_number'];
|
|
|
|
|
|
$gift['goods'][] = $oneGoods;
|
|
|
$number ++;
|
|
|
}
|
|
|
|
|
|
$arr[] = $gift;
|
|
|
|
|
|
// 计算加价购商品数目
|
|
|
//$count += count($value['goods_list']);
|
|
|
$count += $number;
|
|
|
}
|
|
|
|
|
|
return $arr;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单状态,按订单支付类型和订单状态
|
|
|
* @var array
|
|
|
*/
|
|
|
public static function getOrderStatus()
|
|
|
{
|
|
|
return array(
|
|
|
'1' => array(//在线支付
|
|
|
0 => '待付款',
|
|
|
1 => '已付款',
|
|
|
2 => '已付款',
|
|
|
3 => '已付款',
|
|
|
4 => '已发货',
|
|
|
5 => '已发货',
|
|
|
6 => '交易成功'
|
|
|
),
|
|
|
'2' => array(//货到付款
|
|
|
0 => '备货中',
|
|
|
1 => '已付款',
|
|
|
2 => '已付款',
|
|
|
3 => '已付款',
|
|
|
4 => '已发货',
|
|
|
5 => '已发货',
|
|
|
6 => '交易成功'
|
|
|
),
|
|
|
'3' => array(//现金支付
|
|
|
0 => '待付款',
|
|
|
1 => '已付款',
|
|
|
2 => '已付款',
|
|
|
3 => '已付款',
|
|
|
4 => '已发货',
|
|
|
5 => '已发货',
|
|
|
6 => '交易成功'
|
|
|
),
|
|
|
'4' => array(//抵消支付
|
|
|
0 => '待付款',
|
|
|
1 => '已付款',
|
|
|
2 => '已付款',
|
|
|
3 => '已付款',
|
|
|
4 => '已发货',
|
|
|
5 => '已发货',
|
|
|
6 => '交易成功'
|
|
|
)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取会员的级别
|
|
|
*
|
|
|
* @param string $vipInfo
|
|
|
* @return int
|
|
|
*/
|
|
|
public static function getVipLevel($vipInfo)
|
|
|
{
|
|
|
$vipLevel = 0;
|
|
|
|
|
|
switch ($vipInfo) {
|
|
|
case '普通会员':
|
|
|
$vipLevel = 0;
|
|
|
break;
|
|
|
case '银卡会员':
|
|
|
$vipLevel = 1;
|
|
|
break;
|
|
|
case '金卡会员':
|
|
|
$vipLevel = 2;
|
|
|
break;
|
|
|
case '白金会员':
|
|
|
$vipLevel = 3;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return $vipLevel;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 同步用户的会话
|
|
|
*
|
|
|
* 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION
|
|
|
*
|
|
|
* @param int $uid 用户ID
|
|
|
* @param string $refer 访问来源
|
|
|
* @param string $callback 回调方法名
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function syncUserSession($uid, $refer = '', $callback = 'call')
|
|
|
{
|
|
|
return 'http://mapi.yohobuy.com/Passport/session/index?callback=' . $callback
|
|
|
. '&sign=' . md5(md5($uid . 'Js8Yn0!EwPM45-ws')) . '&uid=' . $uid . '&go=' . $refer;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 退出清除用户的会话
|
|
|
*
|
|
|
* 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION
|
|
|
*
|
|
|
* @param int $uid 用户ID
|
|
|
* @param string $refer 访问来源
|
|
|
* @param string $callback 回调方法名
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function logoutSession($token, $refer = '', $callback = 'call')
|
|
|
{
|
|
|
return 'http://mapi.yohobuy.com/Passport/session/logout?callback=' . $callback
|
|
|
. '&sign=' . md5(md5('Js8Yn0!EwPM45-ws')) . '&token=' . $token . '&go=' . $refer;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|