Authored by whb

修改API

... ... @@ -57,26 +57,21 @@ class IndexData
* 邮箱订阅
*
* @param string $email
* @param string $uid
* @param int $uid
* @author sefon 2016-4-22 18:33:51
* @return array
*/
public static function emailSubscriber($email, $uid = 0)
{
//TODO 走老接口
// 构建必传参数
$param = Yohobuy::param();
$param['page'] = 1;
$param['open_key'] = '12345';
$param['method'] = 'open.subscriber.subscriber';
$param['email'] = $email;
$param['uid'] = $uid;
$param['client_type'] = 'web';
$param['private_key'] = Yohobuy::$privateKeyList['web'];
$param['client_secret'] = Sign::getSign($param);
unset($param['app_version']);
unset($param['client_type']);
unset($param['os_version']);
unset($param['screen_size']);
unset($param['v']);
return Yohobuy::post(Yohobuy::API_URL, $param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
... ... @@ -86,25 +81,21 @@ class IndexData
* @param int $question_id
* @param string $answer
* @param int $solution
* @author sefon 2016-4-22 18:34:02
* @return array
*/
public static function suggestFeedback($feedback_id, $question_id, $answer, $solution)
{
//TODO 走老接口
$param = Yohobuy::param();
$param['page'] = 1;
$param['open_key'] = '12345';
$param['method'] = 'open.feedback.submit';
$param['feedback_id'] = $feedback_id;
$param['question_id'] = $question_id;
$param['answer'] = $answer;
$param['solution'] = $solution;
unset($param['app_version']);
unset($param['client_type']);
unset($param['os_version']);
unset($param['screen_size']);
unset($param['v']);
return Yohobuy::post(Yohobuy::API_URL, $param);
$param['client_type'] = 'web';
$param['private_key'] = Yohobuy::$privateKeyList['web'];
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
... ...
... ... @@ -623,4 +623,13 @@ class UserData
return Yohobuy::get(Yohobuy::API_URL, $param);
}
public static function passportGet($uid)
{
$param = Yohobuy::param();
$param['method'] = 'open.passport.get';
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
... ...
<?php
namespace LibModels\Web\Product;
use Api\Yohobuy;
/**
* sale操作类
* @name SaleData
* @package
* @copyright yoho.inc
* @version 1.0 (2016-01-07)
* @author
*/
class SaleData
{
const URL_SALE_SPECIAL = '/operating/service/v1/special';
/**
* @param $specialsaleId 专区ID
* @return array
*/
public static function getSpecial($specialsaleId)
{
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_SALE_SPECIAL, 'getOneSpecial', array($specialsaleId), 600);
}
}
<?php
namespace LibModels\Web\Product;
use Api\Yohobuy;
use Api\Sign;
/**
* sale操作类
* @name SaleData
* @package
* @copyright yoho.inc
* @version 1.0 (2016-01-07)
* @author
*/
class SaleData
{
/**
* @param $specialsaleId 专区ID
* @return array
*/
public static function getSpecial($specialsaleId)
{
$param = Yohobuy::param();
$param['special_id'] = $specialsaleId;
$param['method'] = 'app.resources.getOneSpecial';
$param['client_secret'] = Sign::getSign($param);
//TODO等待接口发布到测试环境
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
... ...
... ... @@ -420,9 +420,22 @@ class SearchData
* 获取品牌店铺接口地址
* @return string
*/
public static function getBannerData($positionId,$msort,$misort,$gender)
public static function getBannerData($positionId, $msort, $misort, $gender)
{
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_INDEX_BANNER, 'get', array($positionId,$msort,$misort,$gender,0,0,0,0,0), 600, 1000); // 有缓存10分钟
// 构建必传参数
$param = Yohobuy::param();
$param['method'] = 'web.search.banner';
$param['position_id'] = $positionId;
$param['max_sort_id'] = $msort;
$param['middle_sort_id'] = $misort;
$param['gender'] = $gender;
$param['brand'] = '0';
$param['style'] = '0';
$param['color'] = '0';
$param['price'] = '0';
$param['size_id'] = '0';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param, 600, false, 5);
}
/**
... ...
... ... @@ -2,8 +2,12 @@
use Action\WebAction;
use Index\HomeModel;
use Product\SearchModel;
use Shopping\CartModel;
use Configs\WebCacheConfig;
use LibModels\Web\Home\IndexData;
use LibModels\Web\Home\UserData;
use LibModels\Web\Home\CartData;
use WebPlugin\Cache;
use WebPlugin\Images;
use WebPlugin\Helpers;
... ... @@ -142,13 +146,16 @@ class CommonController extends WebAction
$email = $this->get('email', '');
$uid = intval($this->get('uid', '0'));
$data = array();
//验证邮件
if (Helpers::verifyEmail($email)) {
do {
if (!Helpers::verifyEmail($email)) {
break;
}
$data = IndexData::emailSubscriber($email, $uid);
return $this->helpJsonCallbackResult($callback, $data['code'], $data['message'], $data['data']);
} else {
return $this->helpJsonCallbackResult($callback, 403, '订阅失败', '');
}
if (isset($data['code']) && $data['code'] === 200) {
return $this->helpJsonCallbackResult($callback, $data['code'], $data['message'], array('result' => 1));
}
} while(false);
return $this->helpJsonCallbackResult($callback, 403, '订阅失败', '');
}
/**
... ... @@ -167,7 +174,7 @@ class CommonController extends WebAction
$data = IndexData::suggestFeedback($feedback_id, $question_id, $answer, $solution);
return $this->helpJsonCallbackResult($callback, $data['code'], $data['message'], $data['data']);
} else {
return $this->helpJsonCallbackResult($callback, 403, '意见反馈失败', '');
return $this->helpJsonCallbackResult($callback, 403, '意见反馈失败');
}
}
... ... @@ -203,7 +210,7 @@ class CommonController extends WebAction
if ($isLogin) {
$tool['user'] = $username;
$tool['userCenter'] = Helpers::url('/home?t=' . $time);//用户中心链接
$tool['logout'] = Helpers::url('/logout.html?token=' . $this->_usession); //退出
$tool['logout'] = Helpers::url('/logout.html?t=' . $time); //退出
} else {
$tool['login'] = Helpers::url('/signin.html'); //登录链接,已登录不传
$tool['register'] = Helpers::url('/reg.html'); //注册链接,已登录不传
... ... @@ -227,4 +234,132 @@ class CommonController extends WebAction
$this->echoJson($result);
}
/**
* 头部调用登陆用户信息
*/
public function passportAction()
{
$callback = $this->get('callback');
$uid = $this->getUid();
$userInfo = UserData::passportGet($uid);
if (!empty($uid)) {
$total = 0;
//更新购物车cookie信息
$shoppingKey = Helpers::getShoppingKeyByCookie();
$result = CartModel::shoppingCart($uid, $shoppingKey);
if (isset($result['main_goods'])) {
foreach ($result['main_goods'] as $val) {
$total += $val['buy_number'];
}
// 老站购物车需要的COOKIE
$this->setCookie('_g', json_encode(array(
'_k' => $shoppingKey,
'_nac' => $total,
'_ac' => 0,
'_r' => 1
)));
}
}
if (isset($userInfo['data'])) {
if (isset($userInfo['data']['data']['vip']['curYearCost'])) {
$userInfo['data']['data']['vip']['curYearCost'] = intval($userInfo['data']['data']['vip']['curYearCost']);
}
if (isset($userInfo['data']['data']['vip']['nextVipInfo']['needCost'])) {
$userInfo['data']['data']['vip']['nextVipInfo']['needCost'] = intval($userInfo['data']['data']['vip']['nextVipInfo']['needCost']);
}
if (isset($userInfo['data']['data']['head_ico']) && !empty($userInfo['data']['data']['head_ico'])) {
$userInfo['data']['data']['head_ico'] = Images::getImageUrl($userInfo['data']['data']['head_ico'], 63, 63, 2, 'yhb-head');
}
if (isset($userInfo['data']['data']['vip']['curYearCostPer'])) {
$userInfo['data']['data']['vip']['curYearCostPer'] = intval($userInfo['data']['data']['vip']['curYearCostPer']);
}
$userInfo['data']['result'] = 1;
$this->helpJsonCallbackResult($callback, 200,'User info', $userInfo['data']);
}
}
/**
* 最近浏览记录
*/
public function recentReviewAction()
{
$result = array();
$callback = $this->get('callback');
$limit = $this->get('limit');
do {
$productInfo = explode(',', $this->getCookie('_browseskn'));
$skn = '';
if (empty($productInfo)) {
break;
}
foreach ($productInfo as $val) {
$sknArray = explode('-', $val);
$skn[]= $sknArray[0];
}
// rsort($skn);
$skn = array_slice($skn, 0 ,$limit);
$result = SearchModel::historyProduct($skn, $limit);
} while(false);
$this->helpJsonCallbackResult($callback, 200,'User info', $result);
}
/**
* 购物车
* @author sefon 2016-4-20 15:15:31
*/
public function shoppingCartAction()
{
$callback = $this->get('callback');
$uid = $this->getUid(true);
$shoppingKey = Helpers::getShoppingKeyByCookie();
$result = CartModel::shoppingCart($uid, $shoppingKey);
$this->helpJsonCallbackResult($callback, 200,'shoppingCart', $result);
}
/**
* 删除购物车商品
*/
public function delCartGoodsAction()
{
$productSku = $this->get('product_sku');
$buyNumber = $this->get('product_num');
$callback = $this->get('callback');
$uid = $this->getUid(true);
$shoppingKey = Helpers::getShoppingKeyByCookie();
$skuList[$productSku] = intval($buyNumber);
$result = CartModel::removeFromCart($uid, json_encode($skuList), $shoppingKey);
if (isset($result['code']) && $result['code'] == 200 && isset($result['total_goods_num'])) {
$this->helpJsonCallbackResult($callback, 200, $result['message'], array('total_goods_num' => $result['total_goods_num']));
} else {
$this->helpJsonCallbackResult($callback, $result['code'], $result['message'], '');
}
}
/**
* 选择支付时,时间间隔校验插入
*/
public function addPaymentIntervalAction()
{
$data = array('code'=>400,'message'=>'','data'=>'');
do {
if (!$this->isAjax()) {
break;
}
$uid = $this->getUid(TRUE);
$orderCode = $this->get('orderCode','');
$payment = $this->get('payment',0);
if (!$uid || !$orderCode || !$payment) {
break;
}
$res = CartData::savePrePayInfo($uid, $orderCode, $payment);
$data = array('code'=>$res['code'],'message'=>$res['message'],'data'=>$res['data']);
} while (false);
$this->echoJson($data);
}
}
... ...
... ... @@ -1223,5 +1223,64 @@ class CartModel
return $result;
}
/**
* 页面顶部购物车数据
* @param int $uid
* @param string $shoppingKey 客户端购物标识
* @author sefon 2016-4-20 15:22:28
* @return array
*/
public static function shoppingCart($uid, $shoppingKey)
{
$result = $goods = array();
$cartType = array('advance_cart_data', 'ordinary_cart_data');
$cartData = CartData::cartData($uid, $shoppingKey);
foreach ($cartType as $dataKey) {
if (!isset($cartData['data'][$dataKey]['goods_list']) || empty($cartData['data'][$dataKey]['goods_list'])) {
continue;
}
//购物车商品
foreach ($cartData['data'][$dataKey]['goods_list'] as $val) {
$goods['product_url'] = Helpers::getUrlBySkc($val['product_id'], $val['goods_id'], $val['cn_alphabet']);
$goods['is_advance'] = $val['is_advance'];
$goods['default_img'] = Helpers::getImageUrl($val['goods_images'], 46, 62);
$goods['product_name'] = $val['product_name'];
$goods['color_name'] = $val['color_name'];
$goods['size_name'] = $val['size_name'];
$goods['show_price'] = $val['real_price'];
$goods['buy_number'] = $val['buy_number'];
$goods['goods_incart_id'] = $val['shopping_cart_id'];
$goods['product_sku'] = $val['product_sku'];
$goods['promotion_id'] = $val['promotion_id'];
$result['main_goods'][] = $goods;
}
if (empty($cartData['data'][$dataKey]['promotion_info'])) {
continue;
}
//活动
foreach ($cartData['data'][$dataKey]['promotion_info'] as $key => $val) {
//包邮
if ($val['promotion_type'] == 'FreeShippingCost') {
preg_match('/\d+/', $val['promotion_title'], $arr);
$result['fit_free_shipping'] = $arr[0];
continue;
}
//打折
if (!isset($result['first_promotions'])) {
$result['has_promotion'] = true;
$result['has_first_promotion'] = true;
$result['first_promotions']['promotion_id'] = $val['promotion_id'];
$result['first_promotions']['promotion_title'] = $val['promotion_title'];
} else {
$result['has_other_promotion'] = true;
$result['other_promotions'][$key]['promotion_id'] = $val['promotion_id'];
$result['other_promotions'][$key]['promotion_title'] = $val['promotion_title'];
}
}
}
return $result;
}
}
... ...