Authored by liangxs

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

<?php
/**
* Created by PhpStorm.
* User: Targaryen
* Date: 2016/4/15
* Time: 13:17
*/
namespace Plugin\DataProcess;
class CouponFloorProcess
{
/**
* 获取楼层数据
*
* @param $data
* @return array
*/
public static function getContent($data)
{
$result = array();
if (empty($data)) {
return array();
}
$build = array();
foreach ($data as $v) {
if (empty($v)) {
continue;
}
$fun = $v['template_name'];
if (empty($v['data']) || !is_callable("self::$fun")) {
continue;
}
$build = self::$fun($v['data']);
if (empty($build)) {
continue;
}
$result[] = $build;
}
$build = array();
return $result;
}
/**
* 焦点图处理
*
* @param $data
* @return mixed
*/
private static function carousel_banner($data)
{
if (empty($data)) {
return array();
}
$data['isCarouselBanner'] = true;
return $data;
}
/**
*
* 领券楼层数据处理
*
* @param $data
* @return array
* @internal param $type
*/
private static function getCoupon($data)
{
if (empty($data)) {
return array();
}
foreach ($data['list'] as &$item) {
switch ($item['status']) {
case 1:
$item['isGet'] = true;
break;
case 2:
$item['isZero'] = true;
break;
case 3:
$item['isGeted'] = true;
break;
default:
break;
}
}
$data['isCoupon'] = true;
return $data;
}
}
\ No newline at end of file
... ...
... ... @@ -269,8 +269,8 @@ class FloorProcess
foreach ($data as $key => &$value) {
if ($key == 'title') {
$urlParam = array('id' => 4);
//isset(self::$channel[$type]) && $urlParam['gender'] = self::$channel[$type];
$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)) {
... ...
... ... @@ -2,7 +2,7 @@
/**
* 模板视图
*
*
* @name TemplateLayout
* @package library/Plugin
* @copyright yoho.inc
... ... @@ -29,7 +29,7 @@ class TemplateLayout implements View_Interface
/**
* 传递给视图变量
*
*
* @param mixed $name
* @param mixed $value
* @return void
... ... @@ -41,7 +41,7 @@ class TemplateLayout implements View_Interface
/**
* 清除一个视图变量
*
*
* @param mixed $name
* @return void
*/
... ... @@ -59,10 +59,10 @@ class TemplateLayout implements View_Interface
/**
* 设置生成HTML及存放路径
*
*
* 如"xxx"则生成"xxx.html"文件, 如"path/xxx"则生成"path/xxx.html"
*
* @param string $htmlPath 生成的Html名字或路径
*
* @param string $htmlPath 生成的Html名字或路径
* @return void
*/
public function html($htmlPath)
... ... @@ -74,7 +74,7 @@ class TemplateLayout implements View_Interface
/**
* 渲染视图模板,并直接输出到客户端
*
*
* @param string $tpl
* @param array $tpl_vars
*/
... ... @@ -85,7 +85,7 @@ class TemplateLayout implements View_Interface
/**
* 渲染视图模板
*
*
* @param string $tpl
* @param array $tpl_vars
* @return string
... ... @@ -112,7 +112,7 @@ class TemplateLayout implements View_Interface
if (!file_exists($viewName)) {
return '';
}
// 合并通过assign传递的参数
if (is_array($this->_tpl_vars)) {
$tpl_vars = array_merge($this->_tpl_vars, $tpl_vars);
... ... @@ -194,7 +194,7 @@ class TemplateLayout implements View_Interface
/**
* 生成HTML
*
*
* @param string $assetsPath 存放静态页面的目录
* @param string $htmlPath 指定的html文件路径
* @param string $result 需要存的内容
... ... @@ -213,7 +213,7 @@ class TemplateLayout implements View_Interface
/**
* 获取HTML
*
*
* @param string $assetsPath 存放静态页面的目录
* @param string $htmlPath 指定的html文件路径
* @return string
... ... @@ -244,7 +244,7 @@ class TemplateLayout implements View_Interface
/**
* 设置视图模板目录
*
*
* @param string $path
* @return boolean
*/
... ... @@ -262,7 +262,7 @@ class TemplateLayout implements View_Interface
/**
* 获取视图模板目录
*
*
* @return string
*/
public function getScriptPath()
... ...
{{> layout/header}}
{{# floor}}
{{#if isCoupon}}
{{# list}}
{{#if isGet}}
<div>{{status}}</div>
{{/if}}
{{#if isZero}}
<div>{{status}}</div>
{{/if}}
{{#if isGeted}}
<div>{{status}}</div>
{{/if}}
{{/list}}
{{/if}}
{{#if isCarouselBanner}}
{{# list}}
<div>isCarouselBanner</div>
{{/list}}
{{/if}}
{{/ floor}}
<input type="hidden" id="couponId"/>
<button onclick="receiveCoupon()">领券</button>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="application/javascript">
function receiveCoupon() {
// 获取当前 URL
var referrer = window.location.pathname;
$.ajax({
method: 'GET',
url: 'http://m.dev.yohobuy.com/coupon/receiveCoupon',
data: {
couponID: 2516
},
dataType: 'json',
success: function (returnData) {
if (returnData['noLogin'] === true) {
window.location.href = returnData['url'];
} else {
alert(returnData);
}
},
error: function (e) {
alert(e);
}
});
}
</script>
{{> layout/footer}}
\ No newline at end of file
... ...
... ... @@ -8,65 +8,25 @@
*/
use Action\AbstractAction;
use Plugin\DataProcess\CouponFloorProcess;
use Plugin\Helpers;
class CouponController extends AbstractAction
{
/**
* 领券中心
*/
public function indexAction()
{
var_dump('123456');
}
/**
* 领券楼层
* 领券楼层数据列表
*
* @author Targaryen
*/
public function floorAction()
{
$result = [
'title' => '热门推荐',
'showTitle' => 1,
'coupons' => [
[
'id' => 1,
'picUrl' => 'http://img12.static.yhbimg.com/yhb-img01/2016/01/19/11/02039485d87cc1b100b883244cf386e62d.jpg?imageView/2/w/640/h/200',
'status' => true,
'num' => 123,
'go' => 'http://m.dev.yohobuy.com/boys',
'couponId' => 3587
], [
'id' => 1,
'picUrl' => 'http://img12.static.yhbimg.com/yhb-img01/2016/01/19/11/02039485d87cc1b100b883244cf386e62d.jpg?imageView/2/w/640/h/200',
'status' => false,
'num' => 122,
'go' => 'http://m.dev.yohobuy.com/boys',
'couponId' => 2564
], [
'id' => 1,
'picUrl' => 'http://img12.static.yhbimg.com/yhb-img01/2016/01/19/11/02039485d87cc1b100b883244cf386e62d.jpg?imageView/2/w/640/h/200',
'status' => false,
'is_zero' => true,
'num' => 0,
'go' => 'http://m.dev.yohobuy.com/boys',
'couponId' => 8024
], [
'id' => 1,
'picUrl' => 'http://img12.static.yhbimg.com/yhb-img01/2016/01/19/11/02039485d87cc1b100b883244cf386e62d.jpg?imageView/2/w/640/h/200',
'status' => true,
'num' => 123,
'go' => 'http://m.dev.yohobuy.com/boys',
'couponId' => 1234
]
]
];
/*// 优惠券列表接口调用
$param['method'] = 'app.promotion.queryCoupon';
$result = \Api\YohobuyH5::get(\Api\YohobuyH5::SERVICE_URL,$param);*/
$this->_view->display('index', array(
$result = array();
$resource = $this->getFloor();
if (isset($resource['code']) && $resource['code'] == 200) {
$result = CouponFloorProcess::getContent($resource['data']);
}
$this->_view->display('test', array(
'floor' => $result,
'floorPage' => true
));
}
... ... @@ -77,25 +37,40 @@ class CouponController extends AbstractAction
*/
public function receiveCouponAction()
{
$returnData = array();
// 获取优惠券 ID
$receiveData = filter_input_array(INPUT_GET, array(
'couponId' => FILTER_DEFAULT
'couponID' => FILTER_DEFAULT
));
$returnData = array();
// 调用领券接口
$result = $this->getCoupon($receiveData['couponId']);
switch ($result['code']) {
case 200:
$returnData = [
'msg' => '领券成功!',
'status' => true,
];
break;
default:
$returnData = [
'msg' => '领券失败!',
'status' => false,
];
break;
// 跳转 URl
$playUrl = 'coupon/floor';
// 判断用户是否登录
if (!$this->getUid() || !is_numeric($this->getUid())) {
// 用户未登录,跳转登录页面
$returnData['noLogin'] = true;
if (!$this->isApp()) {
$returnData['url'] = Helpers::url('/signin.html', array('refer' => $playUrl), 'default');
} else {
$playUrlEncode = strtr($playUrl, array('/' => '\\/'));
$returnData['url'] = $playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $playUrlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}';
}
} else {
// 登录后调用领券接口
$result = $this->getCouponHandler($receiveData['couponID']);
switch ($result['code']) {
case 200:
$returnData = [
'msg' => '领券成功!',
'status' => true,
];
break;
default:
$returnData = [
'msg' => '领券失败!',
'status' => false,
];
break;
}
}
echo json_encode($returnData);
}
... ... @@ -107,8 +82,9 @@ class CouponController extends AbstractAction
* @return array
* @internal param $couponId
*/
public function getCoupon($couponId)
public function getCouponHandler($couponId)
{
if ($couponId) {
$result['alg'] = 'SALT_MD5';
$result['code'] = 200;
... ... @@ -122,23 +98,12 @@ class CouponController extends AbstractAction
$result['md5'] = '50d19f5f5098c34607018f144baec14a';
$result['message'] = '操作失败';
}
/* // 组合接口参数
$params['method'] = 'app.promotion.getCoupon';
$params['couponId'] = $couponId;
$params['uid'] = $this->getUid();
/*// 判断用户是否登录
if (!$this->getUid() || !is_numeric($this->getUid())) {
// 用户未登录,跳转登录页面
if ($this->isApp()) {
$this->go(Helpers::url('/signin.html', array('refer' => Helpers::url($_SERVER["REQUEST_URI"])), 'default'));
} else {
$this->go($_SERVER["REQUEST_URI"] . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . strtr($_SERVER["REQUEST_URI"], array('/' => '\\/')) . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}');
}
}
// 组合接口参数
$params['method'] = 'app.promotion.getCoupon';
$params['couponId'] = $couponId;
$params['uid'] = $this->getUid();
$result = \Api\YohobuyH5::get(\Api\YohobuyH5::SERVICE_URL, $params);*/
$result = \Api\YohobuyH5::get(\Api\YohobuyH5::SERVICE_URL, $params);*/
return $result;
}
... ... @@ -152,4 +117,104 @@ class CouponController extends AbstractAction
{
return (null !== $this->get('app_version'));
}
/**
* 模拟后台接口数据
*
* @return array
*/
public function getFloor()
{
$result = array();
$result = [
'alg' => 'SALT_MD5',
'code' => 200,
'data' => [
0 => [
'data' => [
'list' => [
0 => [
'couponID' => 2516,
'status' => 1,
'goShopping' => 'http://item.m.yohobuy.com/product/pro_325933_419711/XiongJiaYouPin619081838990XiongJiaYouPinChuangYiLanRenTanZhuTuiKuan.html',
'image' => [
'src' => 'http://img12.static.yhbimg.com/yhb-img01/2016/01/19/01/02f639de49d79ece0cf86a2f214be781da.jpg?imageView/2/w/640/h/200',
'url' => 'http://2percent.yohobuy.com/?gender=2,3\n',
],
'isShow' => 'YES',
'title' => '标题内容',
],
],
],
'template_id' => 1111253,
'template_name' => 'getCoupon'
],
1 => [
'data' => [
'list' => [
0 => [
'couponID' => 200,
'status' => 3,
'goShopping' => 'http://item.m.yohobuy.com/product/pro_325933_419711/XiongJiaYouPin619081838990XiongJiaYouPinChuangYiLanRenTanZhuTuiKuan.html',
'image' => [
'src' => 'http://img12.static.yhbimg.com/yhb-img01/2016/01/19/01/02f639de49d79ece0cf86a2f214be781da.jpg?imageView/2/w/640/h/200',
'url' => 'http://2percent.yohobuy.com/?gender=2,3\n',
],
'isShow' => 'YES',
'title' => '标题内容',
],
],
],
'template_id' => 1111257,
'template_name' => 'getCoupon'
],
2 => [
'data' => [
'list' => [
0 => [
'couponID' => 1565,
'status' => 2,
'goShopping' => 'http://item.m.yohobuy.com/product/pro_325933_419711/XiongJiaYouPin619081838990XiongJiaYouPinChuangYiLanRenTanZhuTuiKuan.html',
'image' => [
'src' => 'http://img12.static.yhbimg.com/yhb-img01/2016/01/19/01/02f639de49d79ece0cf86a2f214be781da.jpg?imageView/2/w/640/h/200',
'url' => 'http://2percent.yohobuy.com/?gender=2,3\n',
],
'isShow' => 'YES',
'title' => '标题内容',
],
],
],
'template_id' => 1111255,
'template_name' => 'getCoupon'
],
3 => [
'data' => [
'list' => [
0 => [
'src' => 'http://img11.static.yhbimg.com/yhb-img01/2016/04/13/06/019bd2c1581f881c8ea22daf0e39a4a9ab.png?imageView/2/w/640/h/200',
'url' => []
],
1 => [
'src' => 'http://img12.static.yhbimg.com/yhb-img01/2016/04/13/06/02576fa876ccfbfe0648b4e2dabb989b6f.png?imageView/2/w/640/h/200',
'url' => []
],
2 => [
'src' => 'http://img11.static.yhbimg.com/yhb-img01/2016/04/13/06/01362e8c56fd6ac56ad3852b6a192e5336.png?imageView/2/w/640/h/200',
'url' => []
],
],
'speed' => '3'
],
'template_id' => 1111253,
'template_intro' => '轮播banner',
'template_name' => 'carousel_banner'
],
],
'md5' => '8febf00780011298f4a0530b6441827b',
'message' => '请求成功'
];
return $result;
}
}
\ No newline at end of file
... ...