AddStore.php
1.88 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
<?php
/**
* 添加相应的店铺,用于注册后的操作
* @author tongdesheng
*
*/
class YHMAuth_Hook_AddStore extends YHMAuth_Hook_Abstract
{
/**
* 获取店铺类型
* @param integer $sso_uid
*/
static function getStoreType($sso_uid) {
if(empty($sso_uid)) {
return 1;
}
$url = 'http://www.yohoshow.com/api/yohobuy/getusertitle?sso_id=' . $sso_uid;
$httpClient = new Q_Utils_Http($url);
$httpClient->request('get');
if($httpClient->getStatus() == 200) {
$strRet = $httpClient->getBody();
$retData = json_decode($strRet, true); //{"status":true,"code":200,"data":{"title":"\u6f6e\u4eba"},"message":""}
if($retData['code'] == 200) {
if($retData['data']['title'] == '潮人') {
return 1;
} else if($retData['data']['title'] == '品牌' || $retData['data']['title'] == '红人') {
return 2;
} else if($retData['data']['title'] == '明星'){
return 3;
}
}
}
return 1;
}
static function run(array $package)
{
if (empty($package) || empty($package['uid'])) {
return;
}
$uid = $package['uid'];
$nick_name = empty($package['nick_name']) ? '' : $package['nick_name'];
$isExist = YHMStore_Models_Store_Client::getByUid($uid);
if(!empty($isExist)) {
return;
}
//添加一个店铺记录
$store_type = 1;
if(!empty($package['sso_uid'])) {
$store_type = self::getStoreType($package['sso_uid']);
}
$store_id = YHMStore_Models_Store_Client::addStore($uid, $store_type, 1); //默认给潮人,开启店铺
if (empty($store_id)) {
return self::result(503, '店铺添加失败');
}
//同步店铺记录
try {
$syncParams = array(
'store_id' => $store_id,
'nick_name' => $nick_name,
'store_type' => $store_type
);
$syncStore = new YHMSearch_Syncstore();
$syncStore->sync($syncParams);
} catch (Exception $e) {
error_log($e->getMessage(), 3, '/tmp/syncerror.log');
}
}
}