AddStore.php 1.88 KB
<?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');
		}
	}
}