Authored by wangqing

Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop

Too many changes to show.

To preserve performance only 11 of 11+ files are displayed.

<?php return function ($in, $debugopt = 1) {
$cx = array(
'flags' => array(
'jstrue' => false,
'jsobj' => false,
'spvar' => true,
'prop' => false,
'method' => false,
'mustlok' => true,
'echo' => false,
'debug' => $debugopt,
),
'constants' => array(),
'helpers' => array(),
'blockhelpers' => array(),
'hbhelpers' => array(),
'partials' => array(),
'scopes' => array(),
'sp_vars' => array('root' => $in),
'lcrun' => 'Plugin\LCRun3',
);
return '<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('staticTitle')), ENT_QUOTES, 'UTF-8').'</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<style>
*{margin: 0;padding: 0;}
#coupon-container {width: 100%;}
#coupon-container img {width: 100%; height: auto; display: block;overflow: hidden;}
.img-box {width: 100%;position: relative;}
.img-box .href {width: 50%; height: 100%;position: absolute;top: 0;}
.img-box .href-left {left: 0}
.img-box .href-right {right: 0}
.img-box .href-center {width: 90%;height: 100%;position: absolute;top: 0;left: 5%;}
.show-more {height: 100%;width: 25%;position: absolute;top: 0;right: 10%;}
.yoho-tip {position: fixed;display: none;text-align: center;width: 70%;padding: 34px 0;top: 50%;left: 50%;margin-left: -35%;margin-top: -45px;background-color: #000;opacity: 0.9;color: #fff;font-size: 18px;border: none;border-radius: 10px;}
</style>
<link rel="dns-prefetch" href="//cdn.yoho.cn">
<link rel="dns-prefetch" href="//static.yohobuy.com">
</head>
<body>
<div id="coupon-container" param="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('activityId')), ENT_QUOTES, 'UTF-8').'" isLogged="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('isLogged')), ENT_QUOTES, 'UTF-8').'">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/01.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/02.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/03-a.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/line-1.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/04-a.jpg">
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/05-a.jpg">
<a class="href href-right" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_yohope')), ENT_QUOTES, 'UTF-8').'"></a>
</div>
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/06.jpg">
<a class="href href-center" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_mycoupon')), ENT_QUOTES, 'UTF-8').'"></a>
</div>
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/line-2.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/07.jpg">
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/08.jpg">
<a class="href href-left" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_more')), ENT_QUOTES, 'UTF-8').'"></a>
<a class="href href-right" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_more')), ENT_QUOTES, 'UTF-8').'"></a>
</div>
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/09.jpg">
<span class="href href-left get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17443"></span>
<span class="href href-right get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17445"></span>
</div>
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/line-1.jpg">
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/10.jpg">
<a class="href href-left" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_more')), ENT_QUOTES, 'UTF-8').'"></a>
<a class="href href-right" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_1')), ENT_QUOTES, 'UTF-8').'"></a>
</div>
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/11.jpg">
<span class="href href-left get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17463"></span>
<span class="href href-right get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17451"></span>
</div>
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/line-1.jpg">
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/12.jpg">
<a class="href href-left" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_2')), ENT_QUOTES, 'UTF-8').'"></a>
<a class="href href-right" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_3')), ENT_QUOTES, 'UTF-8').'"></a>
</div>
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/13.jpg">
<span class="href href-left get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17461"></span>
<span class="href href-right get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17459"></span>
</div>
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/line-1.jpg">
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/14.jpg">
<a class="href href-left" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_4')), ENT_QUOTES, 'UTF-8').'"></a>
<a class="href href-right" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_5')), ENT_QUOTES, 'UTF-8').'"></a>
</div>
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/15.jpg">
<span class="href href-left get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17453"></span>
<span class="href href-right get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17455"></span>
</div>
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/line-1.jpg">
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/16.jpg">
<a class="href href-left" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_6')), ENT_QUOTES, 'UTF-8').'"></a>
</div>
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/17.jpg">
<span class="href href-left get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17449"></span>
</div>
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/line-1.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/24-1.jpg">
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/24-2.jpg">
<a class="show-more" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_help')), ENT_QUOTES, 'UTF-8').'"></a>
</div>
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/24-3.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/line-2.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/25-1-a.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/25-2-a.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/25-3-a.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/26-a.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/27-a.jpg">
</div>
<script type="text/javascript" src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/js/jquery.min.js"></script>
<script type="text/javascript" src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/js/newuser/coupon2.js"></script>
</body>
</html>';
}
?>
\ No newline at end of file
... ...
... ... @@ -23,18 +23,18 @@ class Yohobuy
const SERVICE_URL = 'http://service.api.yohobuy.com/';
const YOHOBUY_URL = 'http://www.yohobuy.com/';**/
// const API_URL = 'http://apih5.yoho.cn/';
// const API_URL2 = 'http://apih5.yoho.cn/';
// const SERVICE_URL = 'http://serviceh5.yoho.cn/';
// const YOHOBUY_URL = 'http://www.yohobuy.com/';
// const API_OLD = 'http://api2.open.yohobuy.com/';
const API_URL = 'http://apih5.yoho.cn/';
const API_URL2 = 'http://apih5.yoho.cn/';
const SERVICE_URL = 'http://serviceh5.yoho.cn/';
const YOHOBUY_URL = 'http://www.yohobuy.com/';
const API_OLD = 'http://api2.open.yohobuy.com/';
// /* 测试环境 */
// const API_URL = 'http://192.168.102.205:8080/gateway/'; // 先临时使用网关
const API_URL = 'http://testapi.yoho.cn:28078/';
/*const API_URL = 'http://testapi.yoho.cn:28078/';
const SERVICE_URL = 'http://testservice.yoho.cn:28077/';
const YOHOBUY_URL = 'http://www.yohobuy.com/';
const API_OLD = 'http://test2.open.yohobuy.com/';
const API_OLD = 'http://test2.open.yohobuy.com/';*/
/* 预览环境 */
// const API_URL = 'http://preapi.yoho.cn/';
... ...
... ... @@ -29,12 +29,13 @@ class SearchData
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer');
switch (APPLICATION_ENV) {
case 'release':
return 'http://100.98.132.63/yohosearch/search.json';
case 'test':
return 'http://101.201.178.220/yohosearch/search.json'; //return 'http://100.98.132.63/yohosearch/search.json';
case 'preview':
return 'http://101.200.31.165/yohosearch/search.json';
case 'test':
case 'developer':
default:
return 'http://101.200.31.165/yohosearch/search.json';//return 'http://192.168.10.64:8080/yohosearch/search.json';
return 'http://192.168.10.64:8080/yohosearch/search.json';
}
}
... ... @@ -154,10 +155,7 @@ class SearchData
if (!isset($condition['page'])) {
$param['page'] = 1;
}
if(isset($condition['viewNum'])) {
$param['viewNum'] = $condition['viewNum'];
} else if (!isset($condition['limit'])) {
if (!isset($condition['limit'])) {
$param['viewNum'] = 60;
} else {
$param['viewNum'] = $condition['limit'];
... ...
<?php
namespace LibModels\Web\Passport;
use Api\Sign;
use Api\Yohobuy;
class BackData extends \LibModels\Wap\Passport\BackData
{
/**
* 验证找回邮件code
*
* @param string $code
* @return array
*/
public static function checkEmailCode($code)
{
$param = Yohobuy::param();
$param['method'] = 'app.register.checkCodeValid';
$param['code'] = $code;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param, 3600); // 缓存1小时
}
/**
* 根据邮箱code修改密码
*
* @param string $code
* @param string $password
* @return array
*/
public static function modifyPasswordByEmailCode($code, $password)
{
$param = Yohobuy::param();
$param['method'] = 'app.register.resetPwdByCode';
$param['code'] = $code;
$param['newPwd'] = $password;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
\ No newline at end of file
... ...
... ... @@ -18,7 +18,7 @@ class BrandData
{
const URI_BRAND_TOPPOS = 'operations/api/v5/resource/get';
const URL_BRAND_LOGO = '/shops/service/v1/brand';
const URL_BRAND_LOGO = '/cmsproduct/service/v1/brands';
const URL_BRAND_FOLDER = '/cmsproduct/service/v1/brands';
const URL_BRAND_NODECONTENT = '/operations/service/v6/htmlcontent';
... ... @@ -76,9 +76,9 @@ class BrandData
* @param int $domain 品牌domain
* @return array
*/
public static function getBrandLogoByDomain($domain)
public static function getBrandLogoByDomain($domain, $fields = 'less')
{
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_BRAND_LOGO, 'getBrandByDomain', array($domain));
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_BRAND_LOGO, 'getBrandByDomain', array($domain, $fields));
}
/**
... ...
... ... @@ -9,7 +9,7 @@ use Api\Yohobuy;
*/
class HotrankData extends \LibModels\Wap\Product\SearchData
{
const URI_HOTRANK_TAG = 'http://test.service.api.yohobuy.com/operations/service/v1/hotranktag';
const URI_HOTRANK_TAG = 'operations/service/v1/hotranktag';
/**
* 获取标签
... ... @@ -19,7 +19,7 @@ class HotrankData extends \LibModels\Wap\Product\SearchData
public static function getHotranktag($client_type = 'web',$channel = 0,$is_concurrent = true)
{
$params = array('client_type'=>$client_type,'channel'=>$channel,'is_concurrent' => $is_concurrent);
return Yohobuy::yarClient(self::URI_HOTRANK_TAG, 'getTag',$params);
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_HOTRANK_TAG, 'getTag',$params);
}
/**
... ... @@ -29,6 +29,6 @@ class HotrankData extends \LibModels\Wap\Product\SearchData
public static function getTagById($id,$is_concurrent = true)
{
$params['id'] = $id;
return Yohobuy::yarClient(self::URI_HOTRANK_TAG, 'getOneTag',$params);
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_HOTRANK_TAG, 'getOneTag',$params);
}
}
\ No newline at end of file
... ...
<?php
namespace Plugin;
use Hood\Cache as HoodCache;
/**
* 数据缓存的操作类
*
* @name Cache
* @package Plugin
* @copyright yoho.inc
* @version 1.0 (2015-10-10 11:23:47)
* @author fei.hong <fei.hong@yoho.cn>
*/
class Cache
{
/**
* 设置缓存
*
* 备注:
* 采用主从分布式缓存
* master 代表主缓存服务器
* slave 代表从缓存服务器
*
* 作用:
* 在后端的服务异常挂掉了并且主服务器缓存(master)的数据时间到期后,
* 能获取从服务器缓存(slave)的数据,不影响前端页面的正常访问.
*
* @param string $key 键名
* @param mixed $value 需要缓存的数据
* @param int $expire 缓存有效期(单位秒, 0表示永久)
* @return void
*/
public static function set($key, $value, $expire = 3600)
{
if(USE_CACHE) {
try {
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
HoodCache::Memcache('master')->set(self::makeKey($key, 'master'), $value, $expire);
HoodCache::Memcache('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天
}
// LINUX
else {
HoodCache::Memcached('master')->set(self::makeKey($key, 'master'), $value, $expire);
HoodCache::Memcached('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天
}
} catch (Exception $e) {
// do nothing
}
}
}
/**
* 获取缓存
*
* @param string $key 键名
* @param string $node master代表主服务器, slave代表从服务器
* @return mixed
*/
public static function get($key, $node = 'master')
{
$result = array();
if(USE_CACHE) {
try {
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
$result = HoodCache::Memcache($node)->get(self::makeKey($key, $node));
}
// LINUX
else {
$result = HoodCache::Memcached($node)->get(self::makeKey($key, $node));
}
} catch (Exception $e) {
$result = array();
}
}
return $result;
}
/**
* 清除缓存
*
* @param string $key 键名
* @return void
*/
public static function delete($key)
{
if(USE_CACHE) {
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
HoodCache::Memcache('master')->delete(self::makeKey($key, 'master'));
HoodCache::Memcache('slave')->delete(self::makeKey($key, 'slave'));
}
// LINUX
else {
HoodCache::Memcached('master')->delete(self::makeKey($key, 'master'));
HoodCache::Memcached('slave')->delete(self::makeKey($key, 'slave'));
}
}
}
/**
* 生成键名
*
* @param string $key 键名
* @param string $prefix 前缀标识
* @return string
*/
public static function makeKey($key, $prefix)
{
return md5($prefix . '_' . $key);
}
/**
* 累加
*
* @param string $key
* @param int $offset
* @param int $initialValue
* @param int $expiry
* @return boolean
*/
public static function increment($key, $offset = 1, $initialValue = 0, $expiry = 0) {
return self::getMemcache('master')->increment(self::makeKey($key, 'master'), $offset, $initialValue, $expiry);
}
/**
* 递减
*
* @param string $key
* @param int $offset
* @return boolean
*/
public static function decrement($key, $offset = 1) {
return self::getMemcache('master')->decrement(self::makeKey($key, 'master'), $offset);
}
/**
* 获取memcache
*
* @param string $host
* @return object
*/
private static function getMemcache($host) {
$cache = new \stdClass();
if (DIRECTORY_SEPARATOR === '\\') {
$cache = HoodCache::Memcache($host);
}
else {
$cache = HoodCache::Memcached($host);
}
return $cache;
}
}
<?php
namespace Plugin;
use Hood\Cache as HoodCache;
/**
* 数据缓存的操作类
*
* @name Cache
* @package Plugin
* @copyright yoho.inc
* @version 1.0 (2015-10-10 11:23:47)
* @author fei.hong <fei.hong@yoho.cn>
*/
class Cache
{
/**
* 设置缓存
*
* 备注:
* 采用主从分布式缓存
* master 代表主缓存服务器
* slave 代表从缓存服务器
*
* 作用:
* 在后端的服务异常挂掉了并且主服务器缓存(master)的数据时间到期后,
* 能获取从服务器缓存(slave)的数据,不影响前端页面的正常访问.
*
* @param string $key 键名
* @param mixed $value 需要缓存的数据
* @param int $expire 缓存有效期(单位秒, 0表示永久)
* @return void
*/
public static function set($key, $value, $expire = 3600)
{
try {
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
HoodCache::Memcache('master')->set(self::makeKey($key, 'master'), $value, $expire);
HoodCache::Memcache('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天
}
// LINUX
else {
HoodCache::Memcached('master')->set(self::makeKey($key, 'master'), $value, $expire);
HoodCache::Memcached('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天
}
} catch (Exception $e) {
// do nothing
}
}
/**
* 获取缓存
*
* @param string $key 键名
* @param string $node master代表主服务器, slave代表从服务器
* @return mixed
*/
public static function get($key, $node = 'master')
{
$result = array();
try {
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
$result = HoodCache::Memcache($node)->get(self::makeKey($key, $node));
}
// LINUX
else {
$result = HoodCache::Memcached($node)->get(self::makeKey($key, $node));
}
} catch (Exception $e) {
$result = array();
}
return $result;
}
/**
* 清除缓存
*
* @param string $key 键名
* @return void
*/
public static function delete($key)
{
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
HoodCache::Memcache('master')->delete(self::makeKey($key, 'master'));
HoodCache::Memcache('slave')->delete(self::makeKey($key, 'slave'));
}
// LINUX
else {
HoodCache::Memcached('master')->delete(self::makeKey($key, 'master'));
HoodCache::Memcached('slave')->delete(self::makeKey($key, 'slave'));
}
}
/**
* 生成键名
*
* @param string $key 键名
* @param string $prefix 前缀标识
* @return string
*/
public static function makeKey($key, $prefix)
{
return md5($prefix . '_' . $key);
}
}
... ...
<?php
namespace Plugin\DataProcess;
use Plugin\Helpers;
/**
* 楼层数据处理类
*/
class FloorProcess
{
/**
* 频道参数
*
* @var array
*/
private static $channel = array(
'1' => '1,3',
'2' => '2,3'
);
/**
* 处理首页内容
* @param $data
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
*/
public static function getContent($data, $type = 1)
{
if (empty($data['list'])) {
return array();
}
$result = array();
$build = array();
foreach ($data['list'] as $v) {
if (empty($v)) {
continue;
}
$fun = $v['template_name'];
if (empty($v['data']) || !is_callable("self::$fun")) {
continue;
}
$build = self::$fun($v['data'], $type);
if (empty($build)) {
continue;
}
$result[] = $build;
}
$build = array();
return $result;
}
/**
* 焦点图数据处理方法
* @param array $data 焦点图数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的焦点图数据
*/
private static function focus($data, $type)
{
$result = array();
foreach ($data as $one) {
$result['bannerTop']['list'][] = Helpers::formatBanner($one, 640, 240);
}
return $result;
}
/**
* 图标
*/
private static function floor($data)
{
$result = array();
foreach ($data as &$one) {
$one['url'] = Helpers::getFilterUrl($one['url']);
$one['img'] = Helpers::getImageUrl($one['src'], 98, 98);
unset($one['src']);
}
$result['iconsEnter']['list'] = $data;
return $result;
}
/**
* 图标列表数据处理方法
*
* @param array $data 图标列表数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的图标列表数据
*/
private static function app_icon_list($data, $type)
{
$result = array();
foreach ($data as &$one) {
$one['url'] = Helpers::getFilterUrl($one['url']);
$one['img'] = Helpers::getImageUrl($one['src'], 98, 98);
unset($one['src']);
}
$result['iconsEnter']['list'] = $data;
return $result;
}
/**
* 单广告图片数据处理方法
*
* @param array $data 单图片数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的单图片数据
*/
private static function single_image($data, $type)
{
$result = array();
foreach ($data as &$one) {
$one['url'] = Helpers::getFilterUrl($one['url']);
$one['img'] = Helpers::getImageUrl($one['src'], 640, 200);
unset($one['src']);
}
$result['banner'] = $data;
return $result;
}
/**
* 女生品类
* 推荐(1T-12F)
*/
private static function recommend_content_three($data, $type)
{
$result = array();
$build = array();
if (!empty($data['big_image'][0])) {
$build['img'] = Helpers::getImageUrl($data['big_image'][0]['src'], 640, 200);
$build['url'] = Helpers::getFilterUrl($data['big_image'][0]['url']);
$result['hotCategory']['banner'] = $build;
}
$build = array();
foreach ($data['list'] as $one) {
$build['url'] = Helpers::getFilterUrl($one['url']);
$build['img'] = Helpers::getImageUrl($one['src'], 128, 140);
$build['textCn'] = $one['title'];
$result['hotCategory']['list'][] = $build;
}
if (isset($data['title']['more_url'])) {
$data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
}
return $result;
}
/**
* 带标题的12个小图推荐数据处理方法
*
* @param array $data 带标题的12个小图推荐数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的带标题的12个小图推荐数据
*/
private static function recommend_content_five($data, $type)
{
$result = array();
foreach ($data['list'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 140, 140);
$one['textCn'] = $one['title'];
unset($one['src']);
}
$data['is_show_name'] = $data['title']['is_show'];
$data['name'] = $data['title']['title'];
unset($data['title']);
if (isset($data['title']['more_url'])) {
$data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
}
$result['hotCategory'] = $data;
return $result;
}
/**
* 推荐品牌数据处理方法
* @param array $data 推荐品牌数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的推荐品牌数据
*/
private static function app_hot_brands($data, $type)
{
$result = array();
$data['is_show_name'] = (isset($data['is_show_name']) && $data['is_show_name'] === 'Y') ? 1 : 0;
$data['name'] = $data['title']['title'];
unset($data['title']);
foreach ($data['list'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
// isset(self::$channel[$type]) && $one['url'] .= '?gender=' . self::$channel[$type];
}
$one['img'] = Helpers::getImageUrl($one['src'], 158, 174);
unset($one['src']);
}
$data['more'] = '/brands?channel=' . $type;
$result['hotBrands'] = $data;
return $result;
}
/**
* 潮人·搭配数据处理方法
* @param array $data 潮人·搭配数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的潮人·搭配数据
*/
private static function trendsetter_collocation($data, $type)
{
$result = array();
foreach ($data as $key => &$value) {
if ($key == 'title') {
$value['more_url'] = Helpers::url('', array('id' => 3, 'gender' => self::$channel[$type]), 'guang');
}
if ($key == 'article') {
foreach ($value as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 400, 400);
unset($one['src']);
}
}
if ($key == 'recommend_collocation') {
foreach ($value as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 140, 140);
unset($one['src']);
}
}
}
$result['trendColloaction'] = $data;
return $result;
}
/**
* 潮品·话题数据处理方法
* @param array $data 潮品·话题数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的潮品·话题数据
*/
private static function trendgoods_topic($data, $type)
{
$result = array();
foreach ($data as $key => &$value) {
if ($key == 'title') {
$urlParam = array('id' => 4);
isset(self::$channel[$type]) && $urlParam['gender'] = self::$channel[$type];
$value['more_url'] = Helpers::url('', $urlParam, 'guang');
}
if ($key == 'list' && is_array($value)) {
foreach ($value as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 580, 360);
unset($one['src']);
}
}
}
$result['trendTopics'] = $data;
return $result;
}
/**
* 一张大图一个大的推荐和4个小图推荐数据处理方法
* @param array $data 一张大图一个大的推荐和4个小图推荐数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的一张大图一个大的推荐和4个小图推荐数据
*/
private static function recommend_content_one($data, $type)
{
$result = array();
foreach ($data['big_image'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 640, 403);
unset($one['src']);
}
// 区别多张图与一张图
if (count($data['big_image']) > 1) {
$result['big_image']['big_list'] = $data['big_image'];
unset($data['big_image']);
}
foreach ($data['list'] as $kk => &$one) {
if ($kk == 0) {
$one['img'] = Helpers::getImageUrl($one['src'], 253, 383);
} else {
$one['img'] = Helpers::getImageUrl($one['src'], 191, 191);
}
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['textCn'] = $one['title'];
unset($one['src']);
}
if (isset($data['title']['more_url'])) {
$data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
}
$result['goodsCategory'] = $data;
return $result;
}
/**
* 一张大图和6个小图推荐数据处理方法
* @param array $data 一张大图和6个小图推荐数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的一张大图和6个小图推荐数据
*/
private static function recommend_content_two($data, $type)
{
$result = array();
foreach ($data['big_image'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 640, 403);
unset($one['src']);
}
$data['banner'] = $data['big_image'];
unset($data['big_image']);
foreach ($data['list'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 191, 191);
unset($one['src']);
}
if (isset($data['title']['more_url'])) {
$data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
}
$result['creativeLife'] = $data;
return $result;
}
/**
* 小图片数据处理方法
* @param array $data 小图片数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的小图片数据
*/
private static function small_pic($data, $type)
{
$result = array();
foreach ($data as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 275, 160);
unset($one['src']);
}
if (!empty($data)) {
$result['smallPic']['list'] = $data;
}
return $result;
}
/**
* plus,star
* @param array $data 单名字图片数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的单名字图片数据
*/
private static function single_name_image($data, $type)
{
if (empty($data)) {
return array();
}
$data['name'] = $data['title'];
$data['img'] = Helpers::getImageUrl($data['src'], 640, 198);
if (isset($data['url'])) {
$data['url'] = Helpers::getFilterUrl($data['url']);
}
return array('plusStar' => $data);
}
/**
* 自定义品牌
*
* @param unknown $data
* @param mixed $type
* @return multitype:
*/
private static function custom_brands($data, $type)
{
// URL附加参数
$param = '';
/*if (isset(self::$channel[$type])) {
$param = '/?gender=' . self::$channel[$type];
}*/
$result = array();
$result['hotBrandsScroll']['name'] = $data['title']['title'];
foreach ($data['list'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 140, 140);
$one['textCn'] = $one['name'];
if (isset($one['url'])) {
$one['url'] .= $param;
}
}
if (!empty($data['is_show_name']) && $data['is_show_name'] == 'Y') {
$result['hotBrandsScroll']['is_show_name'] = true;
}
$result['hotBrandsScroll']['list'] = $data['list'];
return $result;
}
}
<?php
namespace Plugin\DataProcess;
use Plugin\Helpers;
/**
* 楼层数据处理类
*/
class FloorProcess
{
/**
* 频道参数
*
* @var array
*/
private static $channel = array(
'1' => '1,3',
'2' => '2,3'
);
/**
* 处理首页内容
* @param $data
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
*/
public static function getContent($data, $type = 1)
{
if (empty($data['list'])) {
return array();
}
$result = array();
$build = array();
foreach ($data['list'] as $v) {
if (empty($v)) {
continue;
}
$fun = $v['template_name'];
if (empty($v['data']) || !is_callable("self::$fun")) {
continue;
}
$build = self::$fun($v['data'], $type);
if (empty($build)) {
continue;
}
$result[] = $build;
}
$build = array();
return $result;
}
/**
* 焦点图数据处理方法
* @param array $data 焦点图数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的焦点图数据
*/
private static function focus($data, $type)
{
$result = array();
foreach ($data as $one) {
$result['bannerTop']['list'][] = Helpers::formatBanner($one, 640, 240);
}
return $result;
}
/**
* 图标
*/
private static function floor($data)
{
$result = array();
foreach ($data as &$one) {
$one['url'] = Helpers::getFilterUrl($one['url']);
$one['img'] = Helpers::getImageUrl($one['src'], 98, 98);
unset($one['src']);
}
$result['iconsEnter']['list'] = $data;
return $result;
}
/**
* 图标列表数据处理方法
*
* @param array $data 图标列表数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的图标列表数据
*/
private static function app_icon_list($data, $type)
{
$result = array();
foreach ($data as &$one) {
$one['url'] = Helpers::getFilterUrl($one['url']);
$one['img'] = Helpers::getImageUrl($one['src'], 98, 98);
unset($one['src']);
}
$result['iconsEnter']['list'] = $data;
return $result;
}
/**
* 单广告图片数据处理方法
*
* @param array $data 单图片数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的单图片数据
*/
private static function single_image($data, $type)
{
$result = array();
foreach ($data as &$one) {
$one['url'] = Helpers::getFilterUrl($one['url']);
$one['img'] = Helpers::getImageUrl($one['src'], 640, 200);
unset($one['src']);
}
$result['banner'] = $data;
return $result;
}
/**
* 女生品类
* 推荐(1T-12F)
*/
private static function recommend_content_three($data, $type)
{
$result = array();
$build = array();
if (!empty($data['big_image'][0])) {
$build['img'] = Helpers::getImageUrl($data['big_image'][0]['src'], 640, 200);
$build['url'] = Helpers::getFilterUrl($data['big_image'][0]['url']);
$result['hotCategory']['banner'] = $build;
}
$build = array();
foreach ($data['list'] as $one) {
$build['url'] = Helpers::getFilterUrl($one['url']);
$build['img'] = Helpers::getImageUrl($one['src'], 128, 140);
$build['textCn'] = $one['title'];
$result['hotCategory']['list'][] = $build;
}
if (isset($data['title']['more_url'])) {
$data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
}
return $result;
}
/**
* 带标题的12个小图推荐数据处理方法
*
* @param array $data 带标题的12个小图推荐数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的带标题的12个小图推荐数据
*/
private static function recommend_content_five($data, $type)
{
$result = array();
foreach ($data['list'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 140, 140);
$one['textCn'] = $one['title'];
unset($one['src']);
}
$data['is_show_name'] = $data['title']['is_show'];
$data['name'] = $data['title']['title'];
unset($data['title']);
if (isset($data['title']['more_url'])) {
$data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
}
$result['hotCategory'] = $data;
return $result;
}
/**
* 推荐品牌数据处理方法
* @param array $data 推荐品牌数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的推荐品牌数据
*/
private static function app_hot_brands($data, $type)
{
$result = array();
$data['is_show_name'] = (isset($data['is_show_name']) && $data['is_show_name'] === 'Y') ? 1 : 0;
$data['name'] = $data['title']['title'];
unset($data['title']);
foreach ($data['list'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
isset(self::$channel[$type]) && $one['url'] .= '?gender=' . self::$channel[$type];
}
$one['img'] = Helpers::getImageUrl($one['src'], 158, 174);
unset($one['src']);
}
$data['more'] = '/brands?channel=' . $type;
$result['hotBrands'] = $data;
return $result;
}
/**
* 潮人·搭配数据处理方法
* @param array $data 潮人·搭配数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的潮人·搭配数据
*/
private static function trendsetter_collocation($data, $type)
{
$result = array();
foreach ($data as $key => &$value) {
if ($key == 'title') {
$value['more_url'] = Helpers::url('', array('id' => 3, 'gender' => self::$channel[$type]), 'guang');
}
if ($key == 'article') {
foreach ($value as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 400, 400);
unset($one['src']);
}
}
if ($key == 'recommend_collocation') {
foreach ($value as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 140, 140);
unset($one['src']);
}
}
}
$result['trendColloaction'] = $data;
return $result;
}
/**
* 潮品·话题数据处理方法
* @param array $data 潮品·话题数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的潮品·话题数据
*/
private static function trendgoods_topic($data, $type)
{
$result = array();
foreach ($data as $key => &$value) {
if ($key == 'title') {
$urlParam = array('id' => 4);
isset(self::$channel[$type]) && $urlParam['gender'] = self::$channel[$type];
$value['more_url'] = Helpers::url('', $urlParam, 'guang');
}
if ($key == 'list') {
foreach ($value as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 580, 360);
unset($one['src']);
}
}
}
$result['trendTopics'] = $data;
return $result;
}
/**
* 一张大图一个大的推荐和4个小图推荐数据处理方法
* @param array $data 一张大图一个大的推荐和4个小图推荐数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的一张大图一个大的推荐和4个小图推荐数据
*/
private static function recommend_content_one($data, $type)
{
$result = array();
foreach ($data['big_image'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 640, 403);
unset($one['src']);
}
// 区别多张图与一张图
if (count($data['big_image']) > 1) {
$result['big_image']['big_list'] = $data['big_image'];
unset($data['big_image']);
}
foreach ($data['list'] as $kk => &$one) {
if ($kk == 0) {
$one['img'] = Helpers::getImageUrl($one['src'], 253, 383);
} else {
$one['img'] = Helpers::getImageUrl($one['src'], 191, 191);
}
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['textCn'] = $one['title'];
unset($one['src']);
}
if (isset($data['title']['more_url'])) {
$data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
}
$result['goodsCategory'] = $data;
return $result;
}
/**
* 一张大图和6个小图推荐数据处理方法
* @param array $data 一张大图和6个小图推荐数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的一张大图和6个小图推荐数据
*/
private static function recommend_content_two($data, $type)
{
$result = array();
foreach ($data['big_image'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 640, 403);
unset($one['src']);
}
$data['banner'] = $data['big_image'];
unset($data['big_image']);
foreach ($data['list'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 191, 191);
unset($one['src']);
}
if (isset($data['title']['more_url'])) {
$data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
}
$result['creativeLife'] = $data;
return $result;
}
/**
* 小图片数据处理方法
* @param array $data 小图片数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的小图片数据
*/
private static function small_pic($data, $type)
{
// 按照以前业务操作,不显示
return array();
$result = array();
foreach ($data as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 98, 98);
unset($one['src']);
}
$result['small_pic'] = $data;
return $result;
}
/**
* plus,star
* @param array $data 单名字图片数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的单名字图片数据
*/
private static function single_name_image($data, $type)
{
if (empty($data)) {
return array();
}
$data['name'] = $data['title'];
$data['img'] = Helpers::getImageUrl($data['src'], 640, 198);
if (isset($data['url'])) {
$data['url'] = Helpers::getFilterUrl($data['url']);
}
return array('plusStar' => $data);
}
/**
* 自定义品牌
*
* @param unknown $data
* @param mixed $type
* @return multitype:
*/
private static function custom_brands($data, $type)
{
// URL附加参数
$param = '';
if (isset(self::$channel[$type])) {
$param = '/?gender=' . self::$channel[$type];
}
$result = array();
$result['hotBrandsScroll']['name'] = $data['title']['title'];
foreach ($data['list'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 140, 140);
$one['textCn'] = $one['name'];
if (isset($one['url'])) {
$one['url'] .= $param;
}
}
if (!empty($data['is_show_name']) && $data['is_show_name'] == 'Y') {
$result['hotBrandsScroll']['is_show_name'] = true;
}
$result['hotBrandsScroll']['list'] = $data['list'];
return $result;
}
}
... ...
<?php
namespace Plugin\DataProcess;
use Plugin\Helpers;
/**
* 列表数据处理类
*/
class ListProcess
{
/**
* 返回商品和过滤数据
*
* @param $data
* @return array 处理之后的商品数据
*/
public static function getListData($data, $returnFilter = true)
{
$result = array();
if (isset($data['product_list'])) {
$result['new'] = self::getProductData($data['product_list']);
}
if ($returnFilter && isset($data['filter'])) {
$result['filter'] = self::getFilterData($data['filter']);
}
return $result;
}
/**
* 处理列表商品数据
*
* @param $data
* @return array 处理之后的商品数据
*/
public static function getProductData($data)
{
// 处理商品
$products = array();
foreach ($data as $value) {
$products[] = Helpers::formatProduct($value, true, true, true, 235, 314);
}
return $products;
}
/**
* 处理筛选数据
*
* @param $data
* @param string | integer $gender 默认选择的性别,默认1,2,3表示所有
* @param null|string $exclude 需要排除的字段
* @return array 处理之后的筛选数据
*/
public static function getFilterData($data, $gender = '1,2,3', $exclude = null)
{
// 过滤条件数据
$filters = array('classify' => array());
// 返回数据中有没有gender时要添加gender
$data['gender'] = array('2,3'=>'GIRLS','1,3'=>'BOYS');
$num = 1;
foreach ($data as $key => $val) {
if ($key === $exclude || empty($val) || !is_callable("self::$key")) {
continue;
}
$build = self::$key($val, $gender);
if ($num === 1) {
$build['active'] = true;
}
$num++;
$filters['classify'][] = $build;
}
// 按照指定字段进行排序筛选数据
self::sortArrByField($filters['classify'], 'sort_col');
return $filters;
}
private static function brand($data)
{
$result = array(
'title' => '品牌',
'name' => '所有品牌',
'sort_col' => 1,
'dataType' => 'brand',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有品牌'
)
)
);
// 对品牌数据按照品牌字母进行排序
self::sortArrByField($data, 'brand_alif');
foreach ($data as $one) {
$brand = array();
$brand['dataId'] = $one['id'];
$brand['name'] = $one['brand_name'];
$result['subs'][] = $brand;
}
return $result;
}
private static function color($data)
{
$result = array(
'title' => '颜色',
'name' => '所有颜色',
'sort_col' => 3,
'dataType' => 'color',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有颜色'
)
)
);
foreach ($data as $one) {
$color = array();
$color['dataId'] = $one['color_id'];
$color['name'] = $one['color_name'];
$result['subs'][] = $color;
}
return $result;
}
private static function discount($data)
{
$result = array(
'title' => '折扣',
'name' => '所有商品',
'sort_col' => 6,
'dataType' => 'discount',
'subs' => array(
array(
'chosed' => true,
'dataId' => '0.1,0.9',
'name' => '所有商品'
)
)
);
foreach ($data as $key => $one) {
$discount = array();
$discount['dataId'] = $key;
$discount['name'] = $one['name'] . '折商品';
$result['subs'][] = $discount;
}
return $result;
}
private static function gender($data, $gender)
{
$result = array(
'title' => '性别',
'name' => '所有性别',
'sort_col' => 0,
'dataType' => 'gender',
'subs' => array(
array(
'dataId' => '1,2,3',
'name' => '所有性别'
),
array(
'dataId' => '1,3',
'name' => 'BOYS'
),
array(
'dataId' => '2,3',
'name' => 'GIRLS'
),
)
);
// 处理选中状态
foreach ($result['subs'] as &$val) {
if ($val['dataId'] === $gender) {
$val['chosed'] = true;
$result['name'] = $val['name'];
}
}
return $result;
}
private static function group_sort($data)
{
$result = array(
'title' => '品类',
'name' => '所有品类',
'sort_col' => 2,
'dataType' => 'sort',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有品类'
)
)
);
$category = array();
foreach ($data as $one) {
$category['dataId'] = isset($one['relation_parameter']) ? $one['relation_parameter']['sort'] : 0;
$category['name'] = $one['category_name'];
/* // 子品类(目前h5不支持二级)
if(isset($one['sub']))
{
$category['subs'] = array();
foreach ($one['sub'] as $single) {
$subitem = array();
$subitem['dataId'] = $single['category_id'];
$subitem['name'] = $single['category_name'];
$category['subs'][] = $subitem;
}
} */
$result['subs'][] = $category;
}
return $result;
}
private static function priceRange($data)
{
// 首先对价格进行排序
ksort($data, SORT_NUMERIC);
$result = array(
'title' => '价格',
'name' => '所有价格',
'sort_col' => 5,
'dataType' => 'price',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有价格'
)
)
);
$price = array();
foreach ($data as $key => $one) {
$price['dataId'] = $key;
$price['name'] = $one;
$result['subs'][] = $price;
}
return $result;
}
private static function size($data)
{
$result = array(
'title' => '尺码',
'name' => '所有尺码',
'sort_col' => 4,
'dataType' => 'size',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有尺码'
)
)
);
$size = array();
foreach ($data as $one) {
$size['dataId'] = $one['size_id'];
$size['name'] = $one['size_name'];
$result['subs'][] = $size;
}
return $result;
}
/**
* 按照数组中指定字段排序二维数组
*
* @param array &$array 需要排序的数组
* @param string $field 字段名称
* @param boolean $desc 时候降序排列,默认为false
*/
private static function sortArrByField(&$array, $field, $desc = false)
{
$fieldArr = array();
foreach ($array as $k => $v) {
$fieldArr[$k] = isset($v[$field]) ? $v[$field] : '';
}
$sort = $desc == false ? SORT_ASC : SORT_DESC;
array_multisort($fieldArr, $sort, $array);
}
}
<?php
namespace Plugin\DataProcess;
use Plugin\Helpers;
/**
* 列表数据处理类
*/
class ListProcess
{
/**
* 返回商品和过滤数据
*
* @param $data
* @return array 处理之后的商品数据
*/
public static function getListData($data, $returnFilter = true)
{
$result = array();
if (isset($data['product_list'])) {
$result['new'] = self::getProductData($data['product_list']);
}
if ($returnFilter && isset($data['filter'])) {
$result['filter'] = self::getFilterData($data['filter']);
}
return $result;
}
/**
* 处理列表商品数据
*
* @param $data
* @return array 处理之后的商品数据
*/
public static function getProductData($data)
{
// 处理商品
$products = array();
foreach ($data as $value) {
$products[] = Helpers::formatProduct($value, true, true, true, 235, 314);
}
return $products;
}
/**
* 处理筛选数据
*
* @param $data
* @param string | integer $gender 默认选择的性别,默认1,2,3表示所有
* @param null|string $exclude 需要排除的字段
* @return array 处理之后的筛选数据
*/
public static function getFilterData($data, $gender = '1,2,3', $exclude = null)
{
// 过滤条件数据
$filters = array('classify' => array());
// 返回数据中有没有gender时要添加gender
$data['gender'] = array('2,3' => 'GIRLS', '1,3' => 'BOYS');
$num = 1;
foreach ($data as $key => $val) {
if ($key === $exclude || empty($val) || !is_callable("self::$key")) {
continue;
}
$build = self::$key($val, $gender);
if ($num === 1) {
$build['active'] = true;
}
$num++;
$filters['classify'][] = $build;
}
// 按照指定字段进行排序筛选数据
self::sortArrByField($filters['classify'], 'sort_col');
return $filters;
}
private static function brand($data)
{
$result = array(
'title' => '品牌',
'name' => '所有品牌',
'sort_col' => 1,
'dataType' => 'brand',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有品牌'
)
)
);
// 对品牌数据按照品牌字母进行排序
self::sortArrByField($data, 'brand_alif');
foreach ($data as $one) {
$brand = array();
$brand['dataId'] = $one['id'];
$brand['name'] = $one['brand_name'];
$result['subs'][] = $brand;
}
return $result;
}
private static function color($data)
{
$result = array(
'title' => '颜色',
'name' => '所有颜色',
'sort_col' => 3,
'dataType' => 'color',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有颜色'
)
)
);
foreach ($data as $one) {
$color = array();
$color['dataId'] = $one['color_id'];
$color['name'] = $one['color_name'];
$result['subs'][] = $color;
}
return $result;
}
private static function discount($data)
{
$result = array(
'title' => '折扣',
'name' => '所有商品',
'sort_col' => 6,
'dataType' => 'discount',
'subs' => array(
array(
'chosed' => true,
'dataId' => '0.1,0.9',
'name' => '所有商品'
)
)
);
foreach ($data as $key => $one) {
$discount = array();
$discount['dataId'] = $key;
$discount['name'] = $one['name'] . '折商品';
$result['subs'][] = $discount;
}
return $result;
}
private static function gender($data, $gender)
{
$result = array(
'title' => '性别',
'name' => '所有性别',
'sort_col' => 0,
'dataType' => 'gender',
'subs' => array(
array(
'dataId' => '1,2,3',
'name' => '所有性别'
),
array(
'dataId' => '1,3',
'name' => 'BOYS'
),
array(
'dataId' => '2,3',
'name' => 'GIRLS'
),
)
);
// 处理选中状态
foreach ($result['subs'] as &$val) {
if ($val['dataId'] === $gender) {
$val['chosed'] = true;
$result['name'] = $val['name'];
}
}
return $result;
}
private static function group_sort($data)
{
$result = array(
'title' => '品类',
'name' => '所有品类',
'sort_col' => 2,
'dataType' => 'sort',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有品类'
)
)
);
$category = array();
foreach ($data as $one) {
$category['dataId'] = isset($one['relation_parameter']) ? $one['relation_parameter']['sort'] : 0;
$category['name'] = $one['category_name'];
/* // 子品类(目前h5不支持二级)
if(isset($one['sub']))
{
$category['subs'] = array();
foreach ($one['sub'] as $single) {
$subitem = array();
$subitem['dataId'] = $single['category_id'];
$subitem['name'] = $single['category_name'];
$category['subs'][] = $subitem;
}
} */
$result['subs'][] = $category;
}
return $result;
}
private static function priceRange($data)
{
// 首先对价格进行排序
ksort($data, SORT_NUMERIC);
$result = array(
'title' => '价格',
'name' => '所有价格',
'sort_col' => 5,
'dataType' => 'price',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有价格'
)
)
);
$price = array();
foreach ($data as $key => $one) {
$price['dataId'] = $key;
$price['name'] = $one;
$result['subs'][] = $price;
}
return $result;
}
private static function size($data)
{
$result = array(
'title' => '尺码',
'name' => '所有尺码',
'sort_col' => 4,
'dataType' => 'size',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有尺码'
)
)
);
$size = array();
foreach ($data as $one) {
$size['dataId'] = $one['size_id'];
$size['name'] = $one['size_name'];
$result['subs'][] = $size;
}
return $result;
}
/**
* 按照数组中指定字段排序二维数组
*
* @param array &$array 需要排序的数组
* @param string $field 字段名称
* @param boolean $desc 时候降序排列,默认为false
*/
private static function sortArrByField(&$array, $field, $desc = false)
{
$fieldArr = array();
foreach ($array as $k => $v) {
$fieldArr[$k] = isset($v[$field]) ? $v[$field] : '';
}
$sort = $desc == false ? SORT_ASC : SORT_DESC;
array_multisort($fieldArr, $sort, $array);
}
}
... ...
<?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;
}
}
... ...
<?php
/**
* User: Zip
* Date: 15/10/28
* Time: 下午13:08
*/
namespace Plugin;
class Images
{
private static $domain = '.static.yhbimg.com';
private static $default_image = '/2015/08/25/02/01dd632a6e07bfef457ce4beda21dd6413.png';
private static $domainList = array(
'01' => array(
'img10.static.yhbimg.com',
'img11.static.yhbimg.com',
),
'02' => array(
'img12.static.yhbimg.com',
'img13.static.yhbimg.com'
),
'yhb-head' => 'head.static.yhbimg.com'
);
private static $qiniuDomain = 'yhfair.qiniudn.com';
/**
* 缩略图模板
* @param $fileName
* @param $bucket
* @param string $position ()
* @param string $background
* @return string
*/
static function template($fileName, $bucket = 'yhfair', $mode = 1)
{
return self::url($fileName, $bucket, $mode);
}
/**
*
* @param unknown $fileName
* @param string $bucket
* @return string
*/
public static function getSourceUrl($fileName, $bucket = 'yhfair')
{
if (stripos($fileName, 'http://') === 0) {
return $fileName;
}
$domain = self::getDomain($bucket, $fileName);
return 'http://' . $domain . '/' . $bucket . $fileName;
}
/**
* 根据尺寸获得图片url
* @param unknown $fileName
* @param unknown $width
* @param unknown $height
* @param number $mode
* @param string $bucket
* @return mixed
*/
public static function getImageUrl($fileName, $width, $height, $mode = 2, $bucket = 'goodsimg')
{
if (!is_string($fileName)) {
return self::template(self::$default_image, $bucket, $mode);
}
if (stripos($fileName, 'http://') !== 0) {
$fileName = self::template($fileName, $bucket, $mode);
}
return strtr($fileName, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode));
}
/**
* 获取图片URL模板
* @param $fileName
* @param int $mode
* @param string $bucket
* @return string
*/
public static function url($fileName, $bucket = 'yhfair', $mode = 1)
{
$domain = self::getDomain($bucket, $fileName);
return self::getImgTemplateUrl($bucket . $fileName, $mode, $domain);
}
public static function getDomain($bucket, $fileName)
{
$domain = '';
if (!empty(self::$domainList[$bucket])) {
$domain = self::$domainList[$bucket];
} else {
$node = mb_substr($fileName, 15, 2);
if (!empty(self::$domainList[$node])) {
$domainList = self::$domainList[$node];
$nodeNum = sprintf('%u', crc32($fileName)) % count($domainList);
$domain = $domainList[$nodeNum];
}
}
return $domain;
}
/**
* 图片上传
* @param string $name 文件表单name, 即用于$_FILES[$name]
*/
public static function saveImage($name)
{
if (empty($_FILES[$name]))
{
return array();
}
$files = $_FILES[$name];
$images = array();
if (is_array($files['tmp_name']))
{
foreach ($files['tmp_name'] as $k => $tmp_name)
{
if(!empty($tmp_name))
{
$images[$files['name'][$k]] = $tmp_name;
}
}
}
else
{
$images[$files['name']] = $files['tmp_name'];
}
return self::uploadStreamImage($images);
}
/**
* 上传图片[图片上传域名限制于http://test.service.api.yohobuy.com]
*
* @param string | array(filename => absolute file path) $file
* url:http://upload.static.yohobuy.com?project=sns&fileData=xxx
* @return mixed
*/
public static function uploadStreamImage($file)
{
$end ="\r\n";
$twoHyphens ="--";
$boundary = "*****";
$stream = '';
$files = is_array($file) ? $file : array($file);
foreach($files as $name => $filename)
{
if(!file_exists($filename))
{
continue;
}
$name = is_numeric($name) ? name.'.jpg' : $name;
$stream .= $twoHyphens.$boundary.$end;
$stream .="Content-Disposition: form-data; "."name=\"fileData\";filename=\"".$name ."\"".$end; // form file element name :fileData
$stream .= $end;
$stream .= file_get_contents($filename);
$stream .= $end;
}
if(empty($stream))
{
return false;
}
$stream .= $twoHyphens.$boundary.$end;
$stream .="Content-Disposition: form-data; "."name=\"project\"".$end;
$stream .= $end;
$stream .= "suggest";//project sns
$stream .= $end;
$stream .= $twoHyphens .$boundary .$twoHyphens .$end;
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'content-type:multipart/form-data;boundary='.$boundary,
'content' => $stream
)
);
$context = stream_context_create($opts);
$result = json_decode(file_get_contents('http://upload.static.yohobuy.com', false, $context), true);
if(!empty($result['data']['imagesList']))
{
$imgExtra = '?imageMogr2/thumbnail/130x130/extent/130x130/background/d2hpdGU=/position/center/quality/90';
$imgList = array('imgList'=>array());
if(count($file) == 1 || !is_array($file))
{
$imgRelUrl = current($result['data']['imagesList']);
$imgList['imgList'][] = array(
'imgUrl' => self::getSourceUrl($imgRelUrl, 'suggest') . $imgExtra,
'imgRelUrl' => $imgRelUrl
);
}
else
{
$img = array();
foreach ($result['data']['imagesList'] as $val) {
$img = array();
$img['imgUrl'] = self::getSourceUrl($val, 'suggest') . $imgExtra;
$img['imgRelUrl'] = $val;
$imgList['imgList'][] = $img;
}
}
return $imgList;
}
else
{
return false;
}
}
/**
* 获取模板的图片地址
* @param $fileName
* @param int $width
* @param int $height
* @param int $mode
* @param null $domain
* @return string
*/
private static function getImgTemplateUrl($fileName, $mode = 1, $domain = null)
{
if ($domain == null) {
$domain = self::$qiniuDomain;
}
$baseUrl = self::MakeBaseUrl($domain, $fileName);
return self::MakeTemplateRequest($baseUrl);
}
private static function MakeBaseUrl($domain, $key) // => $baseUrl
{
$keyEsc = str_replace("%2F", "/", rawurlencode($key));
return "http://$domain/$keyEsc";
}
private static function MakeTemplateRequest($url)
{
$ops = array();
$ops[] = '{mode}';
$ops[] = 'w/{width}';
$ops[] = 'h/{height}';
if (empty($ops)) {
return $url;
}
return $url . "?imageView/" . implode('/', $ops);
}
}
<?php
/**
* User: Zip
* Date: 15/10/28
* Time: 下午13:08
*/
namespace Plugin;
class Images
{
private static $domain = '.static.yhbimg.com';
private static $default_image = '/2015/08/25/02/01dd632a6e07bfef457ce4beda21dd6413.png';
private static $domainList = array(
'01' => array(
'img10.static.yhbimg.com',
'img11.static.yhbimg.com',
),
'02' => array(
'img12.static.yhbimg.com',
'img13.static.yhbimg.com'
),
'yhb-head' => 'head.static.yhbimg.com'
);
private static $qiniuDomain = 'yhfair.qiniudn.com';
/**
* 缩略图模板
* @param $fileName
* @param $bucket
* @param string $position ()
* @param string $background
* @return string
*/
static function template($fileName, $bucket = 'yhfair', $mode = 1)
{
return self::url($fileName, $bucket, $mode);
}
/**
*
* @param unknown $fileName
* @param string $bucket
* @return string
*/
public static function getSourceUrl($fileName, $bucket = 'yhfair')
{
if (stripos($fileName, 'http://') === 0) {
return $fileName;
}
$domain = self::getDomain($bucket, $fileName);
return 'http://' . $domain . '/' . $bucket . $fileName;
}
/**
* 根据尺寸获得图片url
* @param unknown $fileName
* @param unknown $width
* @param unknown $height
* @param number $mode
* @param string $bucket
* @return mixed
*/
public static function getImageUrl($fileName, $width, $height, $mode = 2, $bucket = 'goodsimg')
{
if (!is_string($fileName)) {
return self::template(self::$default_image, $bucket, $mode);
}
if (stripos($fileName, 'http://') !== 0) {
$fileName = self::template($fileName, $bucket, $mode);
}
return strtr($fileName, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode));
}
/**
* 获取图片URL模板
* @param $fileName
* @param int $mode
* @param string $bucket
* @return string
*/
public static function url($fileName, $bucket = 'yhfair', $mode = 1)
{
$domain = self::getDomain($bucket, $fileName);
return self::getImgTemplateUrl($bucket . $fileName, $mode, $domain);
}
public static function getDomain($bucket, $fileName)
{
$domain = '';
if (!empty(self::$domainList[$bucket])) {
$domain = self::$domainList[$bucket];
} else {
$node = mb_substr($fileName, 15, 2);
if (!empty(self::$domainList[$node])) {
$domainList = self::$domainList[$node];
$nodeNum = sprintf('%u', crc32($fileName)) % count($domainList);
$domain = $domainList[$nodeNum];
}
}
return $domain;
}
/**
* 图片上传
* @param string $name 文件表单name, 即用于$_FILES[$name]
*/
public static function saveImage($name)
{
if (empty($_FILES[$name])) {
return array();
}
$files = $_FILES[$name];
$images = array();
if (is_array($files['tmp_name'])) {
foreach ($files['tmp_name'] as $k => $tmp_name) {
if (!empty($tmp_name)) {
$images[$files['name'][$k]] = $tmp_name;
}
}
} else {
$images[$files['name']] = $files['tmp_name'];
}
return self::uploadStreamImage($images);
}
/**
* 上传图片[图片上传域名限制于http://test.service.api.yohobuy.com]
*
* @param string | array(filename => absolute file path) $file
* url:http://upload.static.yohobuy.com?project=sns&fileData=xxx
* @return mixed
*/
public static function uploadStreamImage($file)
{
$end = "\r\n";
$twoHyphens = "--";
$boundary = "*****";
$stream = '';
$files = is_array($file) ? $file : array($file);
foreach ($files as $name => $filename) {
if (!file_exists($filename)) {
continue;
}
$name = is_numeric($name) ? name . '.jpg' : $name;
$stream .= $twoHyphens . $boundary . $end;
$stream .="Content-Disposition: form-data; " . "name=\"fileData\";filename=\"" . $name . "\"" . $end; // form file element name :fileData
$stream .= $end;
$stream .= file_get_contents($filename);
$stream .= $end;
}
if (empty($stream)) {
return false;
}
$stream .= $twoHyphens . $boundary . $end;
$stream .="Content-Disposition: form-data; " . "name=\"project\"" . $end;
$stream .= $end;
$stream .= "suggest"; //project sns
$stream .= $end;
$stream .= $twoHyphens . $boundary . $twoHyphens . $end;
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'content-type:multipart/form-data;boundary=' . $boundary,
'content' => $stream
)
);
$context = stream_context_create($opts);
$result = json_decode(file_get_contents('http://upload.static.yohobuy.com', false, $context), true);
if (!empty($result['data']['imagesList'])) {
$imgExtra = '?imageMogr2/thumbnail/130x130/extent/130x130/background/d2hpdGU=/position/center/quality/90';
$imgList = array('imgList' => array());
if (count($file) == 1 || !is_array($file)) {
$imgRelUrl = current($result['data']['imagesList']);
$imgList['imgList'][] = array(
'imgUrl' => self::getSourceUrl($imgRelUrl, 'suggest') . $imgExtra,
'imgRelUrl' => $imgRelUrl
);
} else {
$img = array();
foreach ($result['data']['imagesList'] as $val) {
$img = array();
$img['imgUrl'] = self::getSourceUrl($val, 'suggest') . $imgExtra;
$img['imgRelUrl'] = $val;
$imgList['imgList'][] = $img;
}
}
return $imgList;
} else {
return false;
}
}
/**
* 获取模板的图片地址
* @param $fileName
* @param int $width
* @param int $height
* @param int $mode
* @param null $domain
* @return string
*/
private static function getImgTemplateUrl($fileName, $mode = 1, $domain = null)
{
if ($domain == null) {
$domain = self::$qiniuDomain;
}
$baseUrl = self::MakeBaseUrl($domain, $fileName);
return self::MakeTemplateRequest($baseUrl);
}
private static function MakeBaseUrl($domain, $key) // => $baseUrl
{
$keyEsc = str_replace("%2F", "/", rawurlencode($key));
return "http://$domain/$keyEsc";
}
private static function MakeTemplateRequest($url)
{
$ops = array();
$ops[] = '{mode}';
$ops[] = 'w/{width}';
$ops[] = 'h/{height}';
if (empty($ops)) {
return $url;
}
return $url . "?imageView/" . implode('/', $ops);
}
}
... ...