Authored by Rock Zhang

添加发券相关的逻辑

Code Review By Rock Zhang
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 namespace LibModels\Wap\Cuxiao; 3 namespace LibModels\Wap\Cuxiao;
4 4
  5 +use Api\Sign;
5 use Api\Yohobuy; 6 use Api\Yohobuy;
6 7
7 /** 8 /**
@@ -127,4 +128,22 @@ class ActivityData @@ -127,4 +128,22 @@ class ActivityData
127 )); 128 ));
128 } 129 }
129 130
  131 + /**
  132 + * 发放优惠券
  133 + *
  134 + * @param int $uid 用户ID
  135 + * @param string $token 发券标记
  136 + * @return mixed
  137 + */
  138 + public static function couponSend($uid, $token)
  139 + {
  140 + $param = Yohobuy::param();
  141 + $param['method'] = 'app.coupons.couponSend';
  142 + $param['uid'] = $uid;
  143 + $param['coupon_send_token'] = $token;
  144 + $param['client_secret'] = Sign::getSign($param);
  145 +
  146 + return Yohobuy::get(Yohobuy::API_URL, $param);
  147 + }
  148 +
130 } 149 }
  1 +<?php
  2 +
  3 +use Action\AbstractAction;
  4 +use Coupon\CouponModel;
  5 +
  6 +/**
  7 + * 领券相关的控制器
  8 + *
  9 + * @name CouponController
  10 + * @package
  11 + * @copyright yoho.inc
  12 + * @version 1.0 (2016-04-19 16:30:44)
  13 + * @author Gtskk (2330416537@qq.com)
  14 + */
  15 +class CouponController extends AbstractAction
  16 +{
  17 +
  18 + /**
  19 + * 获取优惠券
  20 + */
  21 + public function couponSendAction()
  22 + {
  23 + $callback = $this->get('callback');
  24 + $token = $this->get('token', '');
  25 + $uid = $this->getUid(true);
  26 + $appVersion = $this->get('app_version', '');
  27 +
  28 + // APP时用参数中的ID
  29 + if (!empty($appVersion)) {
  30 + $uid = $this->get('uid', 0);
  31 + }
  32 +
  33 + $result = CouponModel::couponSend($uid, $token);
  34 +
  35 + $this->helpJsonCallbackResult($callback, $result['code'], $result['message'], $result['data']);
  36 + }
  37 +
  38 +}
  1 +<?php
  2 +
  3 +namespace Coupon;
  4 +
  5 +use LibModels\Wap\Cuxiao\ActivityData;
  6 +use Plugin\Helpers;
  7 +
  8 +/**
  9 + * 发券相关的数据处理模型
  10 + *
  11 + * @name CouponModel
  12 + * @package Models/Coupon
  13 + * @copyright yoho.inc
  14 + * @version 1.0 (2016-04-19 13:52:44)
  15 + * @author Gtskk<2330416537@qq.com>
  16 + */
  17 +class CouponModel
  18 +{
  19 + /**
  20 + * 发放优惠券返回的接口数据处理
  21 + *
  22 + * @param int $uid 用户ID
  23 + * @param string $token 发券标记
  24 + * @return mixed
  25 + */
  26 + public static function couponSend($uid, $token)
  27 + {
  28 + $result = array('code' => 403, 'message' => '参数错误', 'data' => '');
  29 +
  30 + do {
  31 + // 用户ID或者发券标记为空时
  32 + if (empty($uid) || empty($token)) {
  33 + break;
  34 + }
  35 +
  36 + $couponResult = ActivityData::couponSend($uid, $token);
  37 + // 接口返回错误时
  38 + if (empty($couponResult)) {
  39 + break;
  40 + }
  41 +
  42 + $result = $couponResult;
  43 + } while (false);
  44 +
  45 + return $result;
  46 + }
  47 +
  48 +}
@@ -311,4 +311,27 @@ class LoginController extends AbstractAction @@ -311,4 +311,27 @@ class LoginController extends AbstractAction
311 } 311 }
312 } 312 }
313 313
  314 + /**
  315 + * jsonp获取用户uid
  316 + */
  317 + public function userAction()
  318 + {
  319 + $result = array('code' => 403, 'message' => '未登录', 'data' => '');
  320 +
  321 + do {
  322 + $callback = $this->get('callback');
  323 +
  324 + $uid = $this->getUid(true);
  325 + if (!empty($uid)) {
  326 + $result = array(
  327 + 'code' => 200,
  328 + 'message' => '已登录',
  329 + 'data' => $uid
  330 + );
  331 + }
  332 + } while (false);
  333 +
  334 + $this->helpJsonCallbackResult($callback, $result['code'], $result['message'], $result['data']);
  335 + }
  336 +
314 } 337 }