Authored by Rock Zhang

添加发券相关的逻辑

Code Review By Rock Zhang
... ... @@ -2,6 +2,7 @@
namespace LibModels\Wap\Cuxiao;
use Api\Sign;
use Api\Yohobuy;
/**
... ... @@ -127,4 +128,22 @@ class ActivityData
));
}
/**
* 发放优惠券
*
* @param int $uid 用户ID
* @param string $token 发券标记
* @return mixed
*/
public static function couponSend($uid, $token)
{
$param = Yohobuy::param();
$param['method'] = 'app.coupons.couponSend';
$param['uid'] = $uid;
$param['coupon_send_token'] = $token;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
... ...
<?php
use Action\AbstractAction;
use Coupon\CouponModel;
/**
* 领券相关的控制器
*
* @name CouponController
* @package
* @copyright yoho.inc
* @version 1.0 (2016-04-19 16:30:44)
* @author Gtskk (2330416537@qq.com)
*/
class CouponController extends AbstractAction
{
/**
* 获取优惠券
*/
public function couponSendAction()
{
$callback = $this->get('callback');
$token = $this->get('token', '');
$uid = $this->getUid(true);
$appVersion = $this->get('app_version', '');
// APP时用参数中的ID
if (!empty($appVersion)) {
$uid = $this->get('uid', 0);
}
$result = CouponModel::couponSend($uid, $token);
$this->helpJsonCallbackResult($callback, $result['code'], $result['message'], $result['data']);
}
}
... ...
<?php
namespace Coupon;
use LibModels\Wap\Cuxiao\ActivityData;
use Plugin\Helpers;
/**
* 发券相关的数据处理模型
*
* @name CouponModel
* @package Models/Coupon
* @copyright yoho.inc
* @version 1.0 (2016-04-19 13:52:44)
* @author Gtskk<2330416537@qq.com>
*/
class CouponModel
{
/**
* 发放优惠券返回的接口数据处理
*
* @param int $uid 用户ID
* @param string $token 发券标记
* @return mixed
*/
public static function couponSend($uid, $token)
{
$result = array('code' => 403, 'message' => '参数错误', 'data' => '');
do {
// 用户ID或者发券标记为空时
if (empty($uid) || empty($token)) {
break;
}
$couponResult = ActivityData::couponSend($uid, $token);
// 接口返回错误时
if (empty($couponResult)) {
break;
}
$result = $couponResult;
} while (false);
return $result;
}
}
... ...
... ... @@ -311,4 +311,27 @@ class LoginController extends AbstractAction
}
}
/**
* jsonp获取用户uid
*/
public function userAction()
{
$result = array('code' => 403, 'message' => '未登录', 'data' => '');
do {
$callback = $this->get('callback');
$uid = $this->getUid(true);
if (!empty($uid)) {
$result = array(
'code' => 200,
'message' => '已登录',
'data' => $uid
);
}
} while (false);
$this->helpJsonCallbackResult($callback, $result['code'], $result['message'], $result['data']);
}
}
... ...