Coupon.php
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace Coupon;
use Api\Sign;
use Api\Yohobuy;
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 发券标记
* @param array $app url中传递的app有关的参数
* @return mixed
*/
public static function couponSend($uid, $token, $app)
{
$result = array('code' => 403, 'message' => '参数错误', 'data' => '');
do {
// APP时用参数中的ID
if (self::checkApp($app)) {
$uid = isset($app['uid']) ? $app['uid'] : 0;
}
// 用户ID或者发券标记为空时
if (empty($uid) || empty($token)) {
break;
}
$couponResult = ActivityData::couponSend($uid, $token);
// 接口返回错误时
if (empty($couponResult)) {
$result['code'] = 404;
$result['message'] = '出错啦~';
break;
}
$result = $couponResult;
} while (false);
return $result;
}
/**
* 校验是否为app
*
* @param array $app url中传递的app有关的参数
* @return bool
*/
private static function checkApp($app)
{
$isApp = false;
// APP时用参数中的ID
if (!empty($app) && isset($app['client_secret'])) {
$params = $app;
unset($params['client_secret']);
$params['private_key'] = Yohobuy::$privateKeyList[$params['client_type']];
$isApp = ($app['client_secret'] === Sign::getSign($params));
}
return $isApp;
}
}