Authored by uedxwg

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

... ... @@ -1243,6 +1243,6 @@
'cartInfo' : {
'numInCart' : 3,
'goodsInstore' : 0,
''
'isCollect':true
}
}
... ...
... ... @@ -32,4 +32,58 @@ class CartData
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 移出购物车
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @return array 接口返回的数据
*/
public static function removeFromCart($uid, $sku)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.remove';
$param['product_sku_list'] = $sku;
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 修改购物车商品数据
*
* @param int $uid 用户ID
* @param string $swapData 商品数据
* @return array 接口返回的数据
*/
public static function modifyCartProduct($uid, $swapData)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.swap';
$param['swap_data'] = $swapData;
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 移入收藏夹
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @return array 接口返回的数据
*/
public static function addToFav($uid, $sku)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.addfavorite';
$param['product_sku_list'] = $sku;
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
... ...
... ... @@ -22,15 +22,16 @@ class BrandData
*
* @param int $id 品牌ID
* @param int $uid 用户ID
* @param bool $isBrand 是品牌还是商品
* @return array
*/
public static function favorite($id, $uid)
public static function favorite($id, $uid, $isBrand = true)
{
$param = Yohobuy::param();
$param['method'] = 'app.favorite.add';
$param['id'] = $id;
$param['uid'] = $uid;
$param['type'] = 'brand';
$param['type'] = $isBrand ? 'brand' : 'product';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::post(Yohobuy::API_URL, $param);
... ... @@ -41,15 +42,16 @@ class BrandData
*
* @param int $id 品牌ID
* @param int $uid 用户ID
* @param bool $isBrand 是品牌还是商品
* @return array
*/
public static function favoriteCancel($id, $uid)
public static function favoriteCancel($id, $uid, $isBrand = true)
{
$param = Yohobuy::param();
$param['method'] = 'app.favorite.cancel';
$param['fav_id'] = $id;
$param['uid'] = $uid;
$param['type'] = 'brand';
$param['type'] = $isBrand ? 'brand' : 'product';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::post(Yohobuy::API_URL, $param);
... ...
... ... @@ -205,14 +205,14 @@ class Helpers
$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';
}
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'] = SITE_MAIN . '/product/pro_' . $productData['product_id'] . '_'
. $productData['goods_list'][0]['goods_id']
. '/' . $productData['cn_alphabet'] . '.html';
. $productData['goods_list'][0]['goods_id']
. '/' . $productData['cn_alphabet'] . '.html';
// APP访问需要加附加的参数
// 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
if ($isApp) {
... ...
... ... @@ -9,4 +9,5 @@ require('./order-detail');
require('./fav');
require('./index');
require('./coupons');
require('./online-service');
\ No newline at end of file
require('./online-service');
require('./address');
\ No newline at end of file
... ...
... ... @@ -4,7 +4,8 @@
* @date: 2015/11/12
*/
var $ = require('jquery');
var $userAvatar = $('.user-avatar');
var $userAvatar = $('.user-avatar'),
$listItem = $('.list-item');
var myImage = new Image();
require('../product/recommend-for-you.js');
... ... @@ -12,3 +13,10 @@ myImage.src = $userAvatar.attr('src');
myImage.onerror = function() {
$userAvatar.attr('src', 'http://static.dev.yohobuy.com/img/me/index/user-avatar.png');
};
$('.yoho-page').on('touchstart', '.list-item, .type-item', function() {
$listItem.removeClass('highlight');
$(this).addClass('highlight');
}).on('touchend touchcancel', '.list-item, .type-item', function() {
$(this).removeClass('highlight');
});
... ...
... ... @@ -5,9 +5,8 @@
*/
var $ = require('jquery'),
lazyLoad = require('yoho.lazyload'),
Swiper = require('yoho.iswiper');
var loading = require('../../plugin/loading'),
Swiper = require('yoho.iswiper'),
loading = require('../../plugin/loading'),
tip = require('../../plugin/tip');
var introUrl = $('#introUrl').val(),
... ...
... ... @@ -11,6 +11,7 @@ var goodsSwiper;
require('./desc');
require('./comments-consults');
require('./like');
require('../recommend-for-you.js');
lazyLoad($('img.lazy'));
... ... @@ -49,6 +50,4 @@ $('.goodsDiscount .dropdown').on('click', function() {
$('.goodsDiscount .first-item span').html('');
$('.goodsDiscount .discount-folder').slideUp();
}
});
});
\ No newline at end of file
... ...
/**
* 商品详情
* @author: Lynnic
* @date: 2015/11/24
*/
var $ = require('jquery'),
Hammer = require('yoho.hammer'),
tip = require('../../plugin/tip');
var likeHammer = new Hammer(document.getElementById('likeBtn'));
likeHammer.on('tap', function(e) {
var productId = $('#productId').val(),
opt;
var $this = $(this);
if ($this.hasClass('liked')) {
opt = 'cancel';
} else {
opt = 'ok';
}
$.ajax({
type: 'POST',
url: '/product/opt/favoriteProduct',
data: {
id: productId,
opt: opt
},
success: function(data) {
if (data.code === 200) {
$this.toggleClass('liked');
} else if (data.code === 400) {
location.href = data.data;//未登录跳转登录页
} else {
tip.show(data.message);
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
});
$('#likeBtn').on('click', function(e) {
return false;
});
\ No newline at end of file
... ...
... ... @@ -64,7 +64,7 @@ $('.cart-goods').on('touchstart', '.checkbox', function() {
id = $this.closest('.shopping-cart-good').data('id'),
url;
if ($this.closest('.put-in-favorite')) {
if ($this.closest('.put-in-favorite').length > 0) {
//移入收藏夹
url = '/shoppingCart/col';
... ...
... ... @@ -138,6 +138,10 @@
font-size: pxToRem(28px);
line-height: 1.5;
width: pxToRem(193px);
&.highlight {
background: #eee;
}
}
.iconfont {
... ... @@ -158,6 +162,11 @@
padding: 0 pxToRem(30px);
font-size: pxToRem(32px);
line-height: pxToRem(88px);
&.highlight {
background: #eee;
}
&:after {
content: '';
position: absolute;
... ...
... ... @@ -346,14 +346,14 @@ $basicBtnC:#eb0313;
font-size: pxToRem(47px);
color: #444;
}
&.unfavorite{
font-size: pxToRem(34px);
color:#ccc;
}
&.favorite {
font-size: pxToRem(34px);
color: $basicBtnC;
color: #ccc
}
&.favorite.liked{
color:$basicBtnC;;
}
&.addto-cart,
&.sold-out {
height: pxToRem(80px);
... ...
... ... @@ -2,7 +2,7 @@
<div class="good-detail-page yoho-page">
<div class="banner-container">
<div class="tag-container">
<p class="good-tag soonSoldOut-tag">即将售罄</p>
<!-- <p class="good-tag soonSoldOut-tag">即将售罄</p> -->
{{# tags}}
{{# is_new}}
<p class="good-tag new-tag">NEW</p>
... ... @@ -118,10 +118,10 @@
{{else}}
<a href="" class="sold-out">已售罄</a>
{{/if}}
{{#if favorite}}
<a href="" class="favorite iconfont ">&#xe605;</a>
{{#if isCollect}}
<a href="#" id="likeBtn" class="favorite iconfont liked">&#xe605;</a>
{{else}}
<a href="" class="unfavorite iconfont ">&#xe605;</a>
<a href="" id="likeBtn" class="favorite iconfont">&#xe605;</a>
{{/if}}
</div>
{{/cartInfo}}
... ... @@ -129,6 +129,10 @@
{{#if introUrl}}
<input id="introUrl" type="hidden" value={{introUrl}}>
{{/if}}
{{#if id}}
<input id="productId" type="hidden" value={{id}}>
{{/if}}
</div>
{{> layout/footer}}
\ No newline at end of file
... ...
... ... @@ -38,7 +38,7 @@
<div class="question">
<span class="iconfont">&#xe639;</span>
<p>
{{question}}
{{question}}<br>
<span class="time">{{time}}</span>
</p>
</div>
... ...
... ... @@ -14,7 +14,6 @@ use Index\UserModel as UserModel;
* @package
* @copyright yoho.inc
* @version 1.0 (2015-10-28 16:28:32)
* @author fei.hong <fei.hong@yoho.cn>
*/
class HomeController extends AbstractAction
{
... ... @@ -27,7 +26,12 @@ class HomeController extends AbstractAction
public function init()
{
// 检查用户是否登录, 未登录则跳转到登录页
$uid = 8826435; //$this->getUid(true);
// @todo 为了方便测试,支持传uid参数
$uid = $this->getUid();
if (!$uid) {
$uid = $this->_uid = $this->get('uid', 8826435); //$this->getUid(true);
}
$action = $this->getRequest()->getActionName();
if (!$uid && $action !== 'index') {
$this->go(Helpers::url('/signin.html'));
... ... @@ -678,4 +682,4 @@ class HomeController extends AbstractAction
);
$this->_view->display('i-help', $data);
}
}
\ No newline at end of file
}
... ...
<?php
use Action\AbstractAction;
use Index\CartModel;
use Plugin\Helpers;
/**
* 购物车
*/
class ShoppingCartController extends AbstractAction
{
protected $_uid;
/**
* 初始化
*/
public function init()
{
// 检查用户是否登录, 未登录则跳转到登录页
$this->_uid = $this->getUid();
if (!$this->_uid) {
$this->go(Helpers::url('/signin.html'));
}
parent::init();
}
/*
* 首页
*/
public function indexAction()
{
$this->setTitle('购物车');
$this->setNavHeader('购物车');
$uid = $this->getUid();
$data = array(
'shoppingCartPage' => true,
'shoppingCart' => \Index\CartModel::getCartData($uid)
'shoppingCart' => CartModel::getCartData($this->_uid)
);
// 渲染模板
$this->_view->display('index', $data);
}
/**
* 移出购物车
*/
public function delAction()
{
$result = array();
if ($this->isAjax()) {
$productId = $this->post('id', 0);
$result = CartModel::removeFromCart($this->_uid, $productId);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
}
/**
* 移入收藏夹
*/
public function colAction()
{
$result = array();
if ($this->isAjax()) {
$productId = $this->post('id', 0);
$result = CartModel::addToFav($this->_uid, $productId);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
}
/**
* 修改购物车商品数据
*/
public function modifyAction()
{
$result = array();
if ($this->isAjax()) {
$params = array();
$params['old_product_sku']= $this->post('old_product_sku', 0);
$params['new_product_sku']= $this->post('new_product_sku', 0);
$params['buy_number']= $this->post('buy_number', 0);
$params['selected']= $this->post('selected', null);
$result = CartModel::modifyCartProduct($this->_uid, $params);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
}
public function giftAdvanceAction()
{
$data = array(
... ...
... ... @@ -51,6 +51,75 @@ class CartModel
return $result;
}
/**
* 移出购物车
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @return array 接口返回的数据
*/
public static function removeFromCart($uid, $sku)
{
$result = array('code' => 400, 'message' => '出错啦~');
// 处理sku
$sku_list = json_encode(array($sku => 1));
$remove = CartData::removeFromCart($uid, $sku_list);
if ($remove && isset($remove['code'])) {
$result['code'] = $remove['code'];
$result['message'] = $remove['message'];
}
return $result;
}
/**
* 移入收藏夹
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @return array 接口返回的数据
*/
public static function addToFav($uid, $sku)
{
$result = array('code' => 400, 'message' => '出错啦~');
// 处理sku
$sku_list = json_encode(array($sku => 1));
$add = CartData::addToFav($uid, $sku_list);
if ($add && isset($add['code'])) {
$result['code'] = $add['code'];
$result['message'] = $add['message'];
}
return $result;
}
/**
* 修改购物车商品数据
*
* @param int $uid 用户ID
* @param string $param 要更改的数据
* @return array 接口返回的数据
*/
public static function modifyCartProduct($uid, $param)
{
$result = array('code' => 400, 'message' => '出错啦~');
// 处理要更改的数据
$swapData = json_encode(array($param));
$modify = CartData::addToFav($uid, $swapData);
if ($modify && isset($modify['code'])) {
$result['code'] = $modify['code'];
$result['message'] = $modify['message'];
}
return $result;
}
/**
* 处理不同类型的购物车数据
... ... @@ -65,7 +134,7 @@ class CartModel
$oneGoods = array();
// 购买的商品列表
foreach ($data['goods_list'] as $value) {
$oneGoods['id'] = $value['product_id'];
$oneGoods['id'] = $value['product_sku'];
$oneGoods['name'] = $value['product_name'];
$oneGoods['thumb'] = Images::getImageUrl($value['goods_images'], 120, 120);
$oneGoods['color'] = $value['color_name'];
... ...
... ... @@ -31,15 +31,44 @@ class DetailModel
if (is_numeric($productId) && is_numeric($goodsId)) {
// 调用服务
$baseInfo = DetailData::baseInfo($productId, $uid);
$baseInfo = DetailData::baseInfo($productId, $uid);
// 判断商品是否在架
if (empty($baseInfo['status'])) {
return $result;
}
// 商品名称
if (isset($baseInfo['productName'])) {
$result['goodsName'] = $baseInfo['productName'];
} else {
return $result;
}
}
// 商品标签
if (!empty($baseInfo['productTagBoList'])) {
foreach ($baseInfo['productTagBoList'] as $value) {
switch ($value['tagLabel']) {
case 'is_soon_sold_out': // 即将售磬
$result['tags']['is_soon_sold_out'] = true;
break;
case 'is_new': // 新品
$result['tags']['is_new'] = true;
break;
case 'is_discount': // 在售
$result['tags']['is_discount'] = true;
break;
case 'is_limited': // 限量
$result['tags']['is_limited'] = true;
break;
case 'is_yohood': // YOHOOD
$result['tags']['is_yohood'] = true;
break;
case 'is_advance': // 再到着
$result['tags']['is_advance'] = true;
break;
}
}
}
// 商品价格
if (isset($baseInfo['productPriceBo'])) {
$result['goodsPrice'] = array();
... ... @@ -174,8 +203,15 @@ class DetailModel
'goodsInstore' => $baseInfo['storage'],
);
// 是否收藏
$result['isCollect'] = false;
if (isset($baseInfo['isCollect']) && $baseInfo['isCollect'] === 'Y') {
$result['isCollect'] = true;
}
// 底部简介的URL链接
$result['introUrl'] = Helpers::url('/product/intro_' . $baseInfo['erpProductId'] . '/' . $baseInfo['cnAlphabet'] . '.html');
$result['id'] = $productId;
}
return $result;
... ...
... ... @@ -17,12 +17,10 @@ class DetailController extends AbstractAction
public function indexAction()
{
$productId = $this->param('productId');
$productId = 22399;
if (!is_numeric($productId)) {
$this->error();
}
$goodsId = $this->param('goodsId');
$goodsId = 32443;
if (!is_numeric($goodsId)) {
$this->error();
}
... ...
... ... @@ -60,7 +60,55 @@ class OptController extends AbstractAction
$result = array('code' => 401, 'message' => '参数不正确', 'data' => false);
break;
}
} while (false);
$this->echoJson($result);
}
/**
* 商品收藏/取消收藏
*
* @param int id 商品ID
* @param string opt 操作标识("ok":表示收藏,"cancel":表示取消收藏)
* @return json
*/
public function favoriteProductAction()
{
$result = array('code' => 401, 'message' => '参数不正确', 'data' => false);
do {
/* 判断是否是AJAX请求 */
if (!$this->isAjax()) {
break;
}
/* 判断品牌ID是否有效 */
$id = $this->post('id');
if (!is_numeric($id)) {
break;
}
/* 判断用户是否登录 */
$uid = $this->getUid();
if (!$uid) {
$referer = $this->server('HTTP_REFERER', SITE_MAIN);
$result = array('code' => 400, 'message' => '未登录', 'data' => Helpers::url('/signin.html', array('refer' => $referer)));
break;
}
/* 取消收藏 */
$opt = $this->post('opt', 'ok');
if ($opt !== 'ok') {
$result = BrandData::favoriteCancel($id, $uid, false);
break;
}
/* 收藏 */
$result = BrandData::favorite($id, $uid, false);
if (!isset($result['code'])) {
$result = array('code' => 401, 'message' => '参数不正确', 'data' => false);
break;
}
} while (false);
$this->echoJson($result);
... ...
... ... @@ -33,12 +33,12 @@ application.debug = False
application.servers.config = APPLICATION_PATH "/configs/core"
;出错的时候是否抛出异常
application.dispatcher.throwException = False
application.dispatcher.throwException = True
;是否使用默认的异常 捕获Controller, 如果开启, 在有未捕获的异常的时候,
;控制权会交给ErrorController的errorAction 方法,
;可以通过$request->getException()获得此异常对象
application.dispatcher.catchException = False
application.dispatcher.catchException = True
;模板预编译目录,该目录需要有读写权限
application.template.compile = ROOT_PATH "/compile/m.yohobuy.com"
... ...
... ... @@ -126,10 +126,10 @@ routes.product.route.action = Index
routes.product.map.1 = productId
routes.product.map.2 = goodsId
routes.buy.type = "regex"
routes.buy.match = "#/product/intro_([0-9]+)/(.*).html#"
routes.buy.route.module = Product
routes.buy.route.controller = Detail
routes.buy.route.action = Intro
routes.buy.map.1 = productSkn
routes.productintro.type = "regex"
routes.productintro.match = "#/product/intro_([0-9]+)/(.*).html#"
routes.productintro.route.module = Product
routes.productintro.route.controller = Detail
routes.productintro.route.action = Intro
routes.productintro.map.1 = productSkn
... ...
<?php
use Yaf\Application;
define('SITE_MAIN', 'http://m.yohobuy.com'); // 网站主域名
define('OLD_MAIN', 'http://m.yohobuy.com'); // 网站旧域名
define('COOKIE_DOMAIN', '.m.yohobuy.com'); // COOKIE作用域
define('SUB_DOMAIN', '.m.yohobuy.com'); // 子域名后缀
define('USE_CACHE', false); // 缓存的开关
define('APPLICATION_PATH', dirname(__DIR__)); // 应用目录
define('ROOT_PATH', dirname(dirname(APPLICATION_PATH))); // 根目录
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'preview');
$application = new Application(APPLICATION_PATH . '/configs/application.preview.ini');
$application->bootstrap()->run();
\ No newline at end of file
... ...