Authored by hf

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

framework @ e9d066dd
Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2
Subproject commit e9d066dd88a8e7e37103021c427a205a5cfcdcec
... ...
... ... @@ -23,12 +23,13 @@ class CartData
* @param int $productSku 商品SKU
* @param int $buyNumber 购买数量
* @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品
* @param int int $isEdit 是否是编辑商品SKU,0表示不是编辑
* @param int $isEdit 是否是编辑商品SKU,0表示不是编辑
* @param null|int $promotionId 促销id,默认null(加价购有关)
* @param null|int $uid 用户UID,可以不传
* @param string $shoppingKey 未登录用户唯一识别码,可以不传
* @return array 加入购物车接口返回的数据
*/
public static function addToCart($productSku, $buyNumber, $goodsType, $isEdit = 0, $promotionId = null, $uid = null)
public static function addToCart($productSku, $buyNumber, $goodsType, $isEdit = 0, $promotionId = null, $uid = null, $shoppingKey = null)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.add';
... ... @@ -42,6 +43,9 @@ class CartData
if ($uid !== null) {
$param['uid'] = $uid;
}
if ($shoppingKey !== null) {
$param['shoppingKey'] = $shoppingKey;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
... ...
... ... @@ -42,7 +42,7 @@ class BindData
* @param string $mobile 手机号
*
*/
public static function sendBindMsg($area,$mobile)
public static function sendBindMsg($area, $mobile)
{
$param = Yohobuy::param();
... ... @@ -58,7 +58,7 @@ class BindData
* 验证验证码是否正确
*
*/
public static function checkBindCode($area,$mobile, $code)
public static function checkBindCode($area, $mobile, $code)
{
$param = Yohobuy::param();
... ... @@ -100,4 +100,47 @@ class BindData
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 换绑手机检验
* @param string $mobile 手机号
* @param string $area 国别码
*/
public static function changeCheck($mobile, $area)
{
$param = Yohobuy::param();
$param['method'] = 'app.passport.changeCheck';
$param['mobile'] = $mobile;
$param['area'] = $area;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 换绑手机
* @param string $uid 用户Id
* @param string $code 验证码
* @param string $mobile 手机号
* @param string $area 国别码
*/
public static function changeMobile($uid, $mobile, $area, $code)
{
$param = Yohobuy::param();
$param['method'] = 'app.passport.changeMobile';
$param['mobile'] = $mobile;
$param['uid'] = $uid;
$param['code'] = $code;
$param['area'] = $area;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
... ...
... ... @@ -90,21 +90,17 @@ function orderCompute() {
if (!res) {
tip.show('网络出错');
} else {
if (res.order_amount) {
/*if (res.order_amount) {
res.order_amount = (+res.order_amount).toFixed(2);
}
if (res.discount_amount) {
res.discount_amount = (+res.discount_amount).toFixed(2);
}
}*/
if (res.last_order_amount) {
res.last_order_amount = (+res.last_order_amount).toFixed(2);
}
priceHtml = priceTmpl({
sumPrice: res.order_amount,
salePrice: res.discount_amount,
freight: res.promotion_formula_list[1].promotion_amount,
couponPrice: res.coupon_amount,
yohoCoin: res.use_yoho_coin,
cartPayData: res.promotion_formula_list,
price: res.last_order_amount
});
... ...
... ... @@ -98,28 +98,12 @@
<section class="price-cal block">
<ul class="total">
{{#cartPayData}}
<li>
<span>总价</span>
&nbsp;&nbsp;¥{{sumPrice}}
</li>
<li>
<span>活动价</span>
- ¥{{salePrice}}
</li>
<li>
<span>运费</span>
+ {{freight}}
</li>
{{#couponPrice}}
<li>
<span>优惠券</span>
- ¥{{.}}
</li>
{{/couponPrice}}
<li>
<span>YOHO币</span>
- ¥{{yohoCoin}}
<span>{{promotion}}</span>
&nbsp;&nbsp;{{promotion_amount}}
</li>
{{/cartPayData}}
<li class="cost">
应付金额: <em>¥{{price}}</em>
</li>
... ... @@ -144,28 +128,12 @@
</div>
<script id="tmpl-price" type="text/tmpl">
<ul class="total">
\{{#cartPayData}}
<li>
<span>总价</span>
&nbsp;&nbsp;¥\{{sumPrice}}
</li>
<li>
<span>活动价</span>
- ¥\{{salePrice}}
</li>
<li>
<span>运费</span>
+ \{{freight}}
</li>
\{{#couponPrice}}
<li>
<span>优惠券</span>
- ¥\{{.}}
</li>
\{{/couponPrice}}
<li>
<span>YOHO币</span>
- ¥\{{yohoCoin}}
<span>\{{promotion}}</span>
&nbsp;&nbsp;\{{promotion_amount}}
</li>
\{{/cartPayData}}
<li class="cost">
应付金额: <em>¥\{{price}}</em>
</li>
... ...
... ... @@ -33,14 +33,16 @@
{{/if}}
</ul>
{{/if}}
{{# promotionInfo}}
<div class="activity">
<h1>参与活动</h1>
<h1>参与活动</h1>
<ul>
{{# promotionInfo}}
<li>{{name}}</li>
{{/ promotionInfo}}
</ul>
</div>
{{/ promotionInfo}}
<div class="price-compute">
<p>
<span>总价(¥{{price}})<i>-</i></span>
... ...
<div class="header">
{{#backUrl}}
<a class="go-back" href="javascript:history.go(-1);"></a>
{{/backUrl}}
<a class="go-back" href="{{#if backUrl}}{{backUrl}}{{^}}javascript:history.go(-1);{{/if}}"></a>
{{#showHeaderImg}}
<div class="img-header"></div>
{{/showHeaderImg}}
... ...
... ... @@ -26,13 +26,14 @@ class CartModel
* @param int $isEdit 是否是编辑商品SKU,0表示不是编辑
* @param null|int $promotionId 促销id,默认null(加价购有关)
* @param null|int $uid 用户UID,可以不传
* @param string $shoppingKey 未登录用户唯一识别码,可以不传
* @return array 加入购物车接口返回的数据
*/
public static function addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid)
public static function addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid, $shoppingKey)
{
$result = array('code' => 400, 'message' => '出错啦~~');
$addCart = CartData::addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid);
$addCart = CartData::addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid, $shoppingKey);
if ($addCart && isset($addCart['code'])) {
$result = $addCart;
}
... ... @@ -449,7 +450,11 @@ class CartModel
// 订单数据
if (isset($payReturn['shopping_cart_data']) && !empty($payReturn['shopping_cart_data'])) {
$sumPrice = isset($orderCompute['order_amount']) ? $orderCompute['order_amount'] : $payReturn['shopping_cart_data']['order_amount'];
$result['cartPayData'] = isset($orderCompute['promotion_formula_list']) ? $orderCompute['promotion_formula_list'] : $payReturn['shopping_cart_data']['promotion_formula_list'];
$price = isset($orderCompute['last_order_amount']) ? $orderCompute['last_order_amount'] : $payReturn['shopping_cart_data']['last_order_amount'];
$result['price'] = Helpers::transPrice($price);
/*$sumPrice = isset($orderCompute['order_amount']) ? $orderCompute['order_amount'] : $payReturn['shopping_cart_data']['order_amount'];
$freight = '¥0';
if (isset($orderCompute['promotion_formula_list'][1]['promotion_amount'])) {
... ... @@ -465,7 +470,7 @@ class CartModel
$result['salePrice'] = Helpers::transPrice($salePrice);
$result['price'] = Helpers::transPrice($price);
$result['freight'] = $freight;
$result['couponPrice'] = $couponPrice;
$result['couponPrice'] = $couponPrice;*/
}
// 发票有关数据
... ... @@ -566,17 +571,21 @@ class CartModel
$coupons = CartData::getCouponList($uid);
do {
if ($onlyTotal) {
$result['count'] = count($coupons['data']['couponList']);
break;
}
if (isset($coupons['data']['couponList'])) {
foreach ($coupons['data']['couponList'] as &$val) {
$val['notAvailable'] = $val['isValidity'] === 'N';
foreach ($coupons['data']['couponList'] as $val) {
$notAvailableRes = self::searchCoupon($uid, $val['couponCode']);
// 处理可用的优惠券
if ($val['isValidity'] === 'N' || (isset($notAvailableRes['code']) && $notAvailableRes['code'] !== 200)) {
// $val['notAvailable'] = true;
continue;
}
$result[] = $val;
}
}
$result = $coupons['data']['couponList'];
if ($onlyTotal) {
$count = count($result);
$result = array('count' => $count);
}
}while(0);
... ... @@ -655,6 +664,7 @@ class CartModel
$oneColor = array();
$sizes = array();
$oneSize = array();
$sizeList = array();
$thumbImageList = array();
$colorNum = 0;
$totalStorageNum = 0; // 总库存数
... ... @@ -676,14 +686,16 @@ class CartModel
$colorNum += $one['storage_number'];
$sizeStorageStr .= $one['storage_number'] . '/';
$sizes[] = $oneSize;
$sizeList[$val['color_id']][] = $oneSize;
$colorStorageGroup[$one['size_name']][$val['color_name']] = $one['storage_number'];
}
// 统计尺码对应的各个颜色的库存量
foreach ($sizes as &$sizeArr) {
$sizeArr['colorNumStr'] = implode('/', array_values($colorStorageGroup[ $sizeArr['name'] ]) );
foreach ($sizes as $colorId => $sizeArr) {
foreach ($sizeArr as $key => $value) {
$sizeList[$colorId][$key]['colorNumStr'] = implode('/', array_values($colorStorageGroup[ $sizeArr['name'] ]) );
}
}
// 颜色
... ... @@ -707,6 +719,11 @@ class CartModel
$totalStorageNum += $colorNum;
}
// 格式化尺码对应的各个颜色分组
foreach ($colors as $color) {
$sizes[]['size'] = $sizeList[$color['id']];
}
$data['thumbs'] = $thumbImageList;
$data['colors'] = $colors;
$data['sizes'] = $sizes;
... ... @@ -780,8 +797,6 @@ class CartModel
$result['promotionInfo'][] = $info;
}
$result['promotionFormula'] = $data['shopping_cart_data']['promotion_formula'];
}
// 结算数据
... ...
... ... @@ -446,7 +446,7 @@ class IndexController extends AbstractAction
$result = CartModel::addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid, $shoppingKey);
// 设置加入购物车凭证到客户端浏览器
if (isset($result['data']['shopping_key'])) {
if (!$shoppingKey && isset($result['data']['shopping_key'])) {
$this->setCookie('_spk', $result['data']['shopping_key']);
}
}
... ...
... ... @@ -17,7 +17,8 @@ class BindController extends AbstractAction
public function indexAction()
{
$refer = $this->get('refer');
if (!empty($refer)) {
if (!empty($refer))
{
$this->setCookie('refer', $refer);
}
... ... @@ -105,9 +106,11 @@ class BindController extends AbstractAction
{
$data = array('code' => 400, 'message' => '', 'data' => '');
do {
do
{
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
if (!$this->isAjax())
{
break;
}
... ... @@ -118,21 +121,27 @@ class BindController extends AbstractAction
$nickname = $this->post('nickname');
if (!is_numeric($phoneNum) || !$openId || !$areaCode || !$sourceType) {
if (!is_numeric($phoneNum) || !$openId || !$areaCode || !$sourceType)
{
break;
}
$res = BindData::bindCheck($phoneNum, $openId, $sourceType);
if (!isset($res['code'])) {
if (!isset($res['code']))
{
break;
}
if ($res['code'] == 200) {
if ($res['code'] == 200)
{
$next = Helpers::url('/passport/bind/code', array('isReg' => $res['data']['is_register'], 'openId' => $openId, 'sourceType' => $sourceType, 'nickname' => $nickname, 'areaCode' => $areaCode, 'phoneNum' => $phoneNum));
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('isReg' => $res['data']['is_register'], 'next' => $next));
} else {
}
else
{
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => isset($res['data']) ? $res['data'] : '');
}
} while (false);
}
while (false);
$this->echoJson($data);
}
... ... @@ -142,24 +151,29 @@ class BindController extends AbstractAction
{
$data = array('code' => 400, 'message' => '', 'data' => '');
do {
do
{
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
if (!$this->isAjax())
{
break;
}
$phoneNum = $this->post('phoneNum');
$areaCode = $this->post('areaCode');
if (!is_numeric($phoneNum)) {
if (!is_numeric($phoneNum) || !$areaCode)
{
break;
}
$data = BindData::sendBindMsg($areaCode, $phoneNum);
if (!isset($data['code'])) {
if (!isset($data['code']))
{
break;
}
} while (false);
}
while (false);
$this->echoJson($data);
}
... ... @@ -169,9 +183,11 @@ class BindController extends AbstractAction
{
$data = array('code' => 400, 'message' => '', 'data' => '');
do {
do
{
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
if (!$this->isAjax())
{
break;
}
... ... @@ -179,15 +195,18 @@ class BindController extends AbstractAction
$code = $this->post('code');
$areaCode = $this->post('areaCode');
if (!is_numeric($phoneNum) || !$code) {
if (!is_numeric($phoneNum) || !$code || !$areaCode)
{
break;
}
$data = BindData::checkBindCode($areaCode, $phoneNum, $code);
if (!isset($data['code'])) {
if (!isset($data['code']))
{
break;
}
} while (false);
}
while (false);
$this->echoJson($data);
}
... ... @@ -197,9 +216,11 @@ class BindController extends AbstractAction
{
$data = array('code' => 400, 'message' => '', 'data' => '');
do {
do
{
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
if (!$this->isAjax())
{
break;
}
... ... @@ -210,33 +231,107 @@ class BindController extends AbstractAction
$nickname = $this->post('nickname');
$password = $this->post('password');
if (!is_numeric($phoneNum) || !$openId || !$sourceType || !$areaCode) {
if (!is_numeric($phoneNum) || !$openId || !$sourceType || !$areaCode)
{
break;
}
$res = BindData::bindMobile($openId, $nickname, $sourceType, $phoneNum, $areaCode, $password);
if (!isset($res['code'])) {
if (!isset($res['code']))
{
break;
}
//绑定成功,跳转页面
$refer = $this->getCookie('refer');
if (empty($refer)) {
if (empty($refer))
{
$refer = SITE_MAIN . '/?go=1';
} else {
}
else
{
$refer = rawurldecode($refer);
}
if (isset($res['code']) && $res['code'] == 200 && !empty($res['data']['uid'])) {
if (isset($res['code']) && $res['code'] == 200 && !empty($res['data']['uid']))
{
$token = Helpers::makeToken($res['data']['uid']);
$this->setCookie('_TOKEN', $token);
$this->setSession('_TOKEN', $token);
$refer = Helpers::syncUserSession($res['data']['uid'], $refer);
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer));
} else {
}
else
{
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer));
}
} while (false);
}
while (false);
$this->echoJson($data);
}
//换绑check
public function changeCheckAction()
{
$data = array('code' => 400, 'message' => '', 'data' => '');
do
{
/* 判断是不是AJAX请求 */
if (!$this->isAjax())
{
break;
}
$phoneNum = $this->post('phoneNum');
$areaCode = $this->post('areaCode');
if (!is_numeric($phoneNum) || !$areaCode)
{
break;
}
$data = BindData::changeCheck($phoneNum, $areaCode);
if (!isset($data['code']))
{
break;
}
}
while (false);
$this->echoJson($data);
}
//换绑mobile
public function changeMobileAction()
{
$data = array('code' => 400, 'message' => '', 'data' => '');
do
{
/* 判断是不是AJAX请求 */
if (!$this->isAjax())
{
break;
}
$uid = $this->getUid(true);
$phoneNum = $this->post('phoneNum');
$areaCode = $this->post('areaCode');
$code = $this->post('code');
if (!is_numeric($phoneNum) || !$areaCode || !$code || !$uid)
{
break;
}
$data = BindData::changeMobile($uid, $phoneNum, $areaCode, $code);
if (!isset($data['code']))
{
break;
}
}
while (false);
$this->echoJson($data);
}
... ...