code
stringlengths 15
9.96M
| docstring
stringlengths 1
10.1k
| func_name
stringlengths 1
124
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 6
186
| url
stringlengths 50
236
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public function actionIndex()
{
$data = $this->getBlock()->getLastData();
if(is_array($data)){
return $this->render($this->action->id, $data);
}
} | 产品详细页面 | actionIndex | php | fecshop/yii2_fecshop | app/appfront/modules/Catalog/controllers/ProductController.php | https://github.com/fecshop/yii2_fecshop/blob/master/app/appfront/modules/Catalog/controllers/ProductController.php | BSD-3-Clause |
public function behaviors()
{
if (Yii::$service->store->isAppServerMobile()) {
$primaryKey = Yii::$service->product->getPrimaryKey();
$primaryVal = Yii::$app->request->get($primaryKey);
$urlPath = 'catalog/product/'.$primaryVal;
Yii::$service->store->redirectAppServerMobile($urlPath);
}
$behaviors = parent::behaviors();
$primaryKey = Yii::$service->product->getPrimaryKey();
$product_id = Yii::$app->request->get($primaryKey);
$cacheName = 'product';
if (Yii::$service->cache->isEnable($cacheName)) {
$timeout = Yii::$service->cache->timeout($cacheName);
$disableUrlParam = Yii::$service->cache->disableUrlParam($cacheName);
$cacheUrlParam = Yii::$service->cache->cacheUrlParam($cacheName);
$get_str = '';
$get = Yii::$app->request->get();
// 存在无缓存参数,则关闭缓存
if (isset($get[$disableUrlParam])) {
$behaviors[] = [
'enabled' => false,
'class' => 'yii\filters\PageCache',
'only' => ['index'],
];
return $behaviors;
}
if (is_array($get) && !empty($get) && is_array($cacheUrlParam)) {
foreach ($get as $k=>$v) {
if (in_array($k, $cacheUrlParam)) {
if ($k != 'p' && $v != 1) {
$get_str .= $k.'_'.$v.'_';
}
}
}
}
$store = Yii::$service->store->currentStore;
$currency = Yii::$service->page->currency->getCurrentCurrency();
$behaviors[] = [
'enabled' => true,
'class' => 'yii\filters\PageCache',
'only' => ['index'],
'duration' => $timeout,
'variations' => [
$store, $currency, $get_str, $product_id,
],
//'dependency' => [
// 'class' => 'yii\caching\DbDependency',
// 'sql' => 'SELECT COUNT(*) FROM post',
//],
];
}
return $behaviors;
} | Yii2 behaviors 可以参看地址:http://www.yiichina.com/doc/guide/2.0/concept-behaviors
这里的行为的作用为添加page cache(整页缓存)。 | behaviors | php | fecshop/yii2_fecshop | app/appfront/modules/Catalog/controllers/ProductController.php | https://github.com/fecshop/yii2_fecshop/blob/master/app/appfront/modules/Catalog/controllers/ProductController.php | BSD-3-Clause |
public function actionGetcoprice()
{
$custom_option_sku = Yii::$app->request->get('custom_option_sku');
$product_id = Yii::$app->request->get('product_id');
$qty = Yii::$app->request->get('qty');
$cart_price = 0;
$custom_option_price = 0;
$product = Yii::$service->product->getByPrimaryKey($product_id);
$cart_price = Yii::$service->product->price->getCartPriceByProductId($product_id, $qty, $custom_option_sku);
if (!$cart_price) {
return;
}
$price_info = [
'price' => $cart_price,
];
$priceView = [
'view' => 'catalog/product/index/price.php',
];
$priceParam = [
'price_info' => $price_info,
];
echo json_encode([
'price' =>Yii::$service->page->widget->render($priceView, $priceParam),
]);
exit;
} | ajax 得到产品加入购物车的价格。 | actionGetcoprice | php | fecshop/yii2_fecshop | app/appfront/modules/Catalog/controllers/ProductController.php | https://github.com/fecshop/yii2_fecshop/blob/master/app/appfront/modules/Catalog/controllers/ProductController.php | BSD-3-Clause |
public function actionAdd()
{
return $this->getBlock()->getLastData();
//return $this->render($this->action->id,$data);
} | 增加收藏 | actionAdd | php | fecshop/yii2_fecshop | app/appfront/modules/Catalog/controllers/FavoriteproductController.php | https://github.com/fecshop/yii2_fecshop/blob/master/app/appfront/modules/Catalog/controllers/FavoriteproductController.php | BSD-3-Clause |
public function actionIndex()
{
$data = $this->getBlock()->getLastData();
if(is_array($data)){
return $this->render($this->action->id, $data);
}
} | 分类页面。 | actionIndex | php | fecshop/yii2_fecshop | app/appfront/modules/Catalog/controllers/CategoryController.php | https://github.com/fecshop/yii2_fecshop/blob/master/app/appfront/modules/Catalog/controllers/CategoryController.php | BSD-3-Clause |
public function behaviors()
{
// 检测手机设备,vue跳转
if (Yii::$service->store->isAppServerMobile()) {
$primaryKey = Yii::$service->category->getPrimaryKey();
$primaryVal = Yii::$app->request->get($primaryKey);
$urlPath = 'catalog/category/'.$primaryVal;
Yii::$service->store->redirectAppServerMobile($urlPath);
}
$behaviors = parent::behaviors();
$primaryKey = Yii::$service->category->getPrimaryKey();
$category_id = Yii::$app->request->get($primaryKey);
$cacheName = 'category';
if (Yii::$service->cache->isEnable($cacheName)) {
$timeout = Yii::$service->cache->timeout($cacheName);
$disableUrlParam = Yii::$service->cache->disableUrlParam($cacheName);
$cacheUrlParam = Yii::$service->cache->cacheUrlParam($cacheName);
$get_str = '';
$get = Yii::$app->request->get();
// 存在无缓存参数,则关闭缓存
if (isset($get[$disableUrlParam])) {
$behaviors[] = [
'enabled' => false,
'class' => 'yii\filters\PageCache',
'only' => ['index'],
];
return $behaviors;
}
if (is_array($get) && !empty($get) && is_array($cacheUrlParam)) {
foreach ($get as $k=>$v) {
if (in_array($k, $cacheUrlParam)) {
if ($k != 'p' || $v != 1) {
$get_str .= $k.'_'.$v.'_';
}
}
}
}
$store = Yii::$service->store->currentStore;
$currency = Yii::$service->page->currency->getCurrentCurrency();
$behaviors[] = [
'enabled' => true,
'class' => 'yii\filters\PageCache',
'only' => ['index'],
'duration' => $timeout,
'variations' => [
$store, $currency, $get_str, $category_id,
],
//'dependency' => [
// 'class' => 'yii\caching\DbDependency',
// 'sql' => 'SELECT COUNT(*) FROM post',
//],
];
}
return $behaviors;
} | Yii2 behaviors 可以参看地址:http://www.yiichina.com/doc/guide/2.0/concept-behaviors
这里的行为的作用为添加page cache(整页缓存)。 | behaviors | php | fecshop/yii2_fecshop | app/appfront/modules/Catalog/controllers/CategoryController.php | https://github.com/fecshop/yii2_fecshop/blob/master/app/appfront/modules/Catalog/controllers/CategoryController.php | BSD-3-Clause |
public static function initReviewConfig()
{
// 用当前的配置,覆盖service的公用配置。
// $reviewParam = Yii::$app->getModule('catalog')->params['review'];
//$appName = Yii::$service->helper->getAppName();
//$reviewFilterByLang = Yii::$app->store->get($appName.'_catalog','review_filterByLang');
//$reviewFilterByLang = ($reviewFilterByLang == Yii::$app->store->enable) ? true : false;
//
//if (isset($reviewParam['filterByLang'])) {
// Yii::$service->product->review->filterByLang = $reviewParam['filterByLang'];
//}
} | 初始化当前appfront的设置,覆盖service的初始设置。 | initReviewConfig | php | fecshop/yii2_fecshop | app/appfront/modules/Catalog/helpers/Review.php | https://github.com/fecshop/yii2_fecshop/blob/master/app/appfront/modules/Catalog/helpers/Review.php | BSD-3-Clause |
public static function getReviewAndStarCount($product)
{
// 这个是是否通过语言进行过滤评论,可以通过上面的函数 self::initReviewConfig进行初始化,
// 也就是通过当前模块的配置,来覆盖service的配置
$filterByLang = Yii::$service->product->review->filterByLang;
if ($filterByLang) {
$langCode = Yii::$service->store->currentLangCode;
if ($langCode) {
$a = Yii::$service->fecshoplang->getLangAttrName('review_count_lang', $langCode);
$b = Yii::$service->fecshoplang->getLangAttrName('reviw_rate_star_average_lang', $langCode);
$c = Yii::$service->fecshoplang->getLangAttrName('reviw_rate_star_info_lang', $langCode);
$review_count_lang = 0;
if (isset($product['review_count_lang'][$a])) {
$review_count_lang = $product['review_count_lang'][$a];
$review_count_lang = $review_count_lang ? $review_count_lang : 0;
}
$reviw_rate_star_average_lang = 0;
if (isset($product['reviw_rate_star_average_lang'][$b])) {
$reviw_rate_star_average_lang = $product['reviw_rate_star_average_lang'][$b];
$reviw_rate_star_average_lang = $reviw_rate_star_average_lang ? $reviw_rate_star_average_lang : 0;
}
$reviw_rate_star_info_lang = [];
if (isset($product['reviw_rate_star_info_lang'][$c])) {
$reviw_rate_star_info_lang = $product['reviw_rate_star_info_lang'][$c];
$reviw_rate_star_info_lang = $reviw_rate_star_info_lang ? $reviw_rate_star_info_lang : [];
}
$reviw_rate_star_info = self::getRateStarInfo($review_count_lang, $reviw_rate_star_info_lang);
return [$review_count_lang, $reviw_rate_star_average_lang, $reviw_rate_star_info];
}
} else {
$review_count = $product['review_count'] ? $product['review_count'] : 0;
$reviw_rate_star_average = $product['reviw_rate_star_average'] ? $product['reviw_rate_star_average'] : 0;
$reviw_rate_star_info = $product['reviw_rate_star_info'] ? $product['reviw_rate_star_info'] : [];
$reviw_rate_star_info = self::getRateStarInfo($review_count, $reviw_rate_star_info);
return [$review_count, $reviw_rate_star_average, $reviw_rate_star_info];
}
} | @param $product | Object
@return array
通过service的配置,是否通过语言进行过滤产品的总个数
如果不通过语言,则直接将产品的属性 review_count reviw_rate_star_average 返回
如果通过语言,那么通过属性 review_count_lang reviw_rate_star_average_lang ,在通过当前的语言获取相应的属性值。 | getReviewAndStarCount | php | fecshop/yii2_fecshop | app/appfront/modules/Catalog/helpers/Review.php | https://github.com/fecshop/yii2_fecshop/blob/master/app/appfront/modules/Catalog/helpers/Review.php | BSD-3-Clause |
public static function price($price, $bits = 2)
{
return number_format($price, $bits);
} | @param $price | Float ,价格
@param $bits | Int , 小数点后几位的格式,譬如4.00
@return float, 返回格式化后的数据
一般用于模板中,按照显示格式显示产品数据。 | price | php | fecshop/yii2_fecshop | app/appfront/helper/Format.php | https://github.com/fecshop/yii2_fecshop/blob/master/app/appfront/helper/Format.php | BSD-3-Clause |
public function renderException($exception)
{
//echo 1;exit;
// 获取异常数据 , 404页面不做收集
$code = $exception->statusCode ?: 500;
if ($code != 404) {
method_exists($exception,'getMessage') ? $message = $exception->getMessage() : $message = '';
method_exists($exception,'getName') ? $name = $exception->getName() : $name = '';
method_exists($exception,'getFile') ? $file = $exception->getFile() : $file = '';
method_exists($exception,'getLine') ? $line = $exception->getLine() : $line = '';
method_exists($exception,'getTraceAsString') ? $traceString = $exception->getTraceAsString() : $traceString = '';
$time = time();
$ip = Yii::$app->request->userIP;
$url = Yii::$service->url->getCurrentUrl();
$req_info = $this->getRequestInfo();
$response = Yii::$app->response;
Yii::$app->response->format = $response::FORMAT_JSON;
if (YII_ENV_PROD) {
$errorKey = $this->saveProdException($code, $message, $file, $line, $time, $ip, $name, $traceString, $url, $req_info);
Yii::$app->response->data = [
'code' => $code,
'error_no' => $errorKey,
];
Yii::$app->response->send();
Yii::$app->end();
} else {
$time = date('Y-m-d H:i:s', $time);
$exceptionInfo = [
'code' => $code,
'message' => $message,
'file' => $file,
'line' => $line,
'time' => $time,
'ip' => $ip,
'name' => $name,
'traceString' => $traceString,
];
Yii::$app->response->data = $exceptionInfo;
Yii::$app->response->send();
Yii::$app->end();
}
} else {
parent::renderException($exception);
}
} | [renderException description]
@param $exception | Object 异常数据对象 | renderException | php | fecshop/yii2_fecshop | components/AppfrontErrorHandler.php | https://github.com/fecshop/yii2_fecshop/blob/master/components/AppfrontErrorHandler.php | BSD-3-Clause |
public function getLogUid()
{
if (!$this->_serviceUid) {
$this->_serviceUid = $this->guid();
}
return $this->_serviceUid;
} | Log:get log uuid . | getLogUid | php | fecshop/yii2_fecshop | components/ServiceLog.php | https://github.com/fecshop/yii2_fecshop/blob/master/components/ServiceLog.php | BSD-3-Clause |
public function isServiceLogEnable()
{
if ($this->_isServiceLog === null) {
if (
isset($this->log_config['services']['enable'])
&& $this->log_config['services']['enable']
) {
$this->_isServiceLog = true;
} else {
$this->_isServiceLog = false;
}
}
return $this->_isServiceLog;
} | ServiceLog:是否开启service log. | isServiceLogEnable | php | fecshop/yii2_fecshop | components/ServiceLog.php | https://github.com/fecshop/yii2_fecshop/blob/master/components/ServiceLog.php | BSD-3-Clause |
public function printServiceLog($log_info)
{
if ($this->isServiceLogDbPrint()) {
$this->initServiceLogDbPrint();
$this->_logModel->getCollection()->save($log_info);
}
if ($this->isServiceLogHtmlPrint() || $this->isServiceLogDbPrintByParam()) {
$str = '<br>#################################<br><table>';
foreach ($log_info as $k=>$v) {
if (is_array($v)) {
$v = implode('<br>', $v);
$str .= "<tr>
<td>$k</td><td>$v</td>
</tr>";
} else {
$str .= "<tr>
<td>$k</td><td>$v</td>
</tr>";
}
}
$str .= '</table><br>#################################<br><br>';
$this->serviceLogHtmlPrintStr .= $str;
}
} | ServiceLog:保存serviceLog. | printServiceLog | php | fecshop/yii2_fecshop | components/ServiceLog.php | https://github.com/fecshop/yii2_fecshop/blob/master/components/ServiceLog.php | BSD-3-Clause |
public function getServiceLogHtmlPrintStr(){
if ($this->isServiceLogEnable()) {
return $this->serviceLogHtmlPrintStr;
} else {
return '';
}
} | 直接在前端打印service Log | getServiceLogHtmlPrintStr | php | fecshop/yii2_fecshop | components/ServiceLog.php | https://github.com/fecshop/yii2_fecshop/blob/master/components/ServiceLog.php | BSD-3-Clause |
protected function isServiceLogDbPrint()
{
if ($this->_isServiceLogDbPrint === null) {
if (
isset($this->log_config['services']['enable'])
&& $this->log_config['services']['enable']
&& isset($this->log_config['services']['dbprint'])
&& $this->log_config['services']['dbprint']
) {
$this->_isServiceLogDbPrint = true;
} else {
$this->_isServiceLogDbPrint = false;
}
}
return $this->_isServiceLogDbPrint;
} | ServiceLog:if service log db print is enable. | isServiceLogDbPrint | php | fecshop/yii2_fecshop | components/ServiceLog.php | https://github.com/fecshop/yii2_fecshop/blob/master/components/ServiceLog.php | BSD-3-Clause |
protected function isServiceLogHtmlPrint()
{
if ($this->_isServiceLogHtmlPrint === null) {
if (
isset($this->log_config['services']['enable'])
&& $this->log_config['services']['enable']
&& isset($this->log_config['services']['htmlprint'])
&& $this->log_config['services']['htmlprint']
) {
$this->_isServiceLogHtmlPrint = true;
} else {
$this->_isServiceLogHtmlPrint = false;
}
}
return $this->_isServiceLogHtmlPrint;
} | ServiceLog:在前台打印servicelog是否开启. | isServiceLogHtmlPrint | php | fecshop/yii2_fecshop | components/ServiceLog.php | https://github.com/fecshop/yii2_fecshop/blob/master/components/ServiceLog.php | BSD-3-Clause |
protected function isServiceLogDbPrintByParam()
{
if ($this->_isServiceLogDbPrintByParam === null) {
$this->_isServiceLogDbPrintByParam = false;
if (
isset($this->log_config['services']['enable'])
&& $this->log_config['services']['enable']
&& isset($this->log_config['services']['htmlprintbyparam']['enable'])
&& $this->log_config['services']['htmlprintbyparam']['enable']
&& isset($this->log_config['services']['htmlprintbyparam']['paramVal'])
&& ($paramVal = $this->log_config['services']['htmlprintbyparam']['paramVal'])
&& isset($this->log_config['services']['htmlprintbyparam']['paramKey'])
&& ($paramKey = $this->log_config['services']['htmlprintbyparam']['paramKey'])
) {
if (Yii::$app->request->get($paramKey) == $paramVal) {
$this->_isServiceLogDbPrintByParam = true;
}
}
}
return $this->_isServiceLogDbPrintByParam;
} | ServiceLog:通过参数,在前台打印servicelog是否开启. | isServiceLogDbPrintByParam | php | fecshop/yii2_fecshop | components/ServiceLog.php | https://github.com/fecshop/yii2_fecshop/blob/master/components/ServiceLog.php | BSD-3-Clause |
protected function guid()
{
if (function_exists('com_create_guid')) {
return com_create_guid();
} else {
mt_srand((float) microtime() * 10000); //optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45); // "-"
$uuid = //chr(123)// "{"
substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid, 12, 4).$hyphen
.substr($charid, 16, 4).$hyphen
.substr($charid, 20, 12)
//.chr(125)// "}"
;
return $uuid;
}
} | generate uuid . | guid | php | fecshop/yii2_fecshop | components/ServiceLog.php | https://github.com/fecshop/yii2_fecshop/blob/master/components/ServiceLog.php | BSD-3-Clause |
public function renderException($exception)
{
// 获取异常数据
$code = $exception->statusCode ?: 500;
method_exists($exception,'getMessage') ? $message = $exception->getMessage() : $message = '';
method_exists($exception,'getName') ? $name = $exception->getName() : $name = '';
method_exists($exception,'getFile') ? $file = $exception->getFile() : $file = '';
method_exists($exception,'getLine') ? $line = $exception->getLine() : $line = '';
method_exists($exception,'getTraceAsString') ? $traceString = $exception->getTraceAsString() : $traceString = '';
$time = time();
$ip = Yii::$app->request->userIP;
$url = Yii::$service->url->getCurrentUrl();
$req_info = $this->getRequestInfo();
$response = Yii::$app->response;
Yii::$app->response->format = $response::FORMAT_JSON;
if (YII_ENV_PROD) {
$errorKey = $this->saveProdException($code, $message, $file, $line, $time, $ip, $name, $traceString, $url, $req_info);
Yii::$app->response->data = [
'code' => $code,
'error_no' => $errorKey,
];
Yii::$app->response->send();
Yii::$app->end();
} else {
$time = date('Y-m-d H:i:s', $time);
$exceptionInfo = [
'code' => $code,
'message' => $message,
'file' => $file,
'line' => $line,
'time' => $time,
'ip' => $ip,
'name' => $name,
'traceString' => $traceString,
];
Yii::$app->response->data = $exceptionInfo;
Yii::$app->response->send();
Yii::$app->end();
}
} | [renderException description]
@param $exception | Object 异常数据对象 | renderException | php | fecshop/yii2_fecshop | components/AppserverErrorHandler.php | https://github.com/fecshop/yii2_fecshop/blob/master/components/AppserverErrorHandler.php | BSD-3-Clause |
public function bootstrap($app)
{
if ($this->appName == 'appadmin') {
Yii::$service->admin->bootstrap($app);
} else {
Yii::$service->store->bootstrap($app);
}
} | 初始化的bootstrap | bootstrap | php | fecshop/yii2_fecshop | components/Store.php | https://github.com/fecshop/yii2_fecshop/blob/master/components/Store.php | BSD-3-Clause |
public function get($key, $subKey = '')
{
$this->initBaseConfig();
if (!$subKey) {
return isset($this->_base_config[$key]) ? $this->_base_config[$key] : null;
}
return isset($this->_base_config[$key][$subKey]) ? $this->_base_config[$key][$subKey] : null;
} | @param $key | string, 配置的主Key
@param $subKey | string, 配置的子key | get | php | fecshop/yii2_fecshop | components/Store.php | https://github.com/fecshop/yii2_fecshop/blob/master/components/Store.php | BSD-3-Clause |
public function getLangAttrName($attrName, $langCode)
{
return $attrName.'_'.$langCode;
} | @param $attrName|string , attr name ,like : tilte , description ,name etc..
@param $langCode|string , language 2 code, like :en ,fr ,es,
get language child language attr, like: title_fr | getLangAttrName | php | fecshop/yii2_fecshop | services/FecshopLang.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/FecshopLang.php | BSD-3-Clause |
public function getDefaultLangAttrName($attrName)
{
return $attrName.'_'.$this->defaultLangCode;
} | @param $attrName | String 属性名称
得到默认语言的属性名称 | getDefaultLangAttrName | php | fecshop/yii2_fecshop | services/FecshopLang.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/FecshopLang.php | BSD-3-Clause |
public function getAllLanguages()
{
if (!$this->_allLanguages) {
if (empty($this->allLangCode) || !is_array($this->allLangCode)) {
$this->_allLanguages = [];
return $this->_allLanguages;
}
foreach ($this->allLangCode as $lang_name => $codeInfo) {
$isDefaulltLang = false;
$lang_code = $codeInfo['code'];
if ($this->defaultLangCode == $lang_code) {
$isDefaulltLang = true;
}
$this->_allLanguages[] = [
'name' => $lang_name,
'code' => $lang_code,
'is_default' => $isDefaulltLang,
];
}
}
return $this->_allLanguages;
} | @return array
得到所有的语言参数 | getAllLanguages | php | fecshop/yii2_fecshop | services/FecshopLang.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/FecshopLang.php | BSD-3-Clause |
public function getAllLangCode()
{
if (!$this->_allLangCode) {
if (empty($this->allLangCode) || !is_array($this->allLangCode)) {
return [];
}
if ($this->defaultLangCode) {
$this->_allLangCode[] = $this->defaultLangCode;
foreach ($this->allLangCode as $codeInfo) {
$code = $codeInfo['code'];
if ($this->defaultLangCode != $code) {
$this->_allLangCode[] = $code;
}
}
}
}
return $this->_allLangCode;
} | 得到所有的语言简码,譬如:en,es,fr,zh,de等 | getAllLangCode | php | fecshop/yii2_fecshop | services/FecshopLang.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/FecshopLang.php | BSD-3-Clause |
public function getCurrentLongLangCode()
{
return Yii::$service->store->currentLang;
} | 得到当前的语言长简码,譬如:en-US, zh-CN | getCurrentLongLangCode | php | fecshop/yii2_fecshop | services/FecshopLang.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/FecshopLang.php | BSD-3-Clause |
public function getCurrentShortLangCode()
{
return Yii::$service->store->currentLangCode;
} | 得到当前的语言缩写简码,譬如:en, zh | getCurrentShortLangCode | php | fecshop/yii2_fecshop | services/FecshopLang.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/FecshopLang.php | BSD-3-Clause |
public function getCurrentLangName()
{
return Yii::$service->store->currentLangName;
} | 得到当前的语言全称,譬如:English,中文 | getCurrentLangName | php | fecshop/yii2_fecshop | services/FecshopLang.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/FecshopLang.php | BSD-3-Clause |
public function getLangCodeByLanguage($language)
{
if (isset($this->allLangCode[$language])) {
return $this->allLangCode[$language]['code'];
} else {
return '';
}
} | @param $language|string like: en-US ,fr-FR,zh-CN
@return string , like en ,fr ,es , if $language is not exist in $this->allLangCode
empty will be return. | getLangCodeByLanguage | php | fecshop/yii2_fecshop | services/FecshopLang.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/FecshopLang.php | BSD-3-Clause |
public function getLangAndCodeArr(){
$arr = [];
if (is_array($this->allLangCode)) {
foreach ($this->allLangCode as $lang => $one) {
if (isset($one['code']) && $one['code'] && $lang) {
$arr[$one['code']] = $lang;
}
}
}
return $arr;
} | @return array , like
['en' => 'en_US' , 'zh' => 'zh_CN'] | getLangAndCodeArr | php | fecshop/yii2_fecshop | services/FecshopLang.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/FecshopLang.php | BSD-3-Clause |
public function getRecentStatisticsInfo()
{
// 1.1总量:产品Sku总数
$productFilter = [
'select' => ['sku'],
'asArray' => true,
'where' => [],
];
$productData = Yii::$service->product->coll($productFilter);
$productTotalCount = isset($productData['count']) ? $productData['count'] : 0;
// 1.2总量:用户总量
$filter = [
'select' => ['firstname'],
'where' => [],
'asArray' => true,
];
$customerData = Yii::$service->customer->coll($filter);
$customerTotalCount = 0;
if (isset($customerData['count']) && $customerData['count']) {
$customerTotalCount = $customerData['count'];
}
// 1.3总量:支付订单总数
$filter = [
'select' => ['increment_id'],
'where' => [
['in', 'order_status', Yii::$service->order->getOrderPaymentedStatusArr()]
],
'asArray' => true,
];
$orderData = Yii::$service->order->coll($filter);
$orderTotalCount = 0;
if (isset($orderData['count']) && $orderData['count']) {
$orderTotalCount = $orderData['count'];
}
// 1.4总量:评价
$filter = [
'select' => ['product_spu'],
'where' => [],
'asArray' => true,
];
$reviewData = Yii::$service->product->review->coll($filter);
$reviewTotalCount = 0;
if (isset($reviewData['count']) && $reviewData['count']) {
$reviewTotalCount = $reviewData['count'];
}
// 2.1昨日/今日 订单总销售额,总数,下单用户数
$yest0Time = strtotime(date("Y-m-d",strtotime("-1 day"))); // 昨日0点
$today0Time = strtotime(date("Y-m-d",time())); // 昨日0点
$filter = [
'select' => ['created_at', 'customer_id', 'order_status', 'base_grand_total' ],
'fetchAll' => true,
'where' => [
['>=', 'created_at', $yest0Time],
['in', 'order_status', Yii::$service->order->getOrderPaymentedStatusArr()]
],
'asArray' => true,
];
$orderData = Yii::$service->order->coll($filter);
$orderYestTotalCount= 0;
$orderYestTotalBaseSale = 0;
$orderTodayTotalCount= 0;
$orderTodayTotalBaseSale = 0;
$orderYestCustomer= [];
$orderTodayCustomer =[];
if (is_array($orderData['coll']) && !empty($orderData['coll'])) {
foreach ($orderData['coll'] as $one) {
$orderTime = $one['created_at'];
$baseGrandTotal = $one['base_grand_total'];
$customer_id = $one['customer_id'];
if ($orderTime >= $today0Time) {
$orderTodayTotalCount +=1;
$orderTodayTotalBaseSale += $baseGrandTotal;
$orderTodayCustomer[$customer_id] = $customer_id;
} else {
$orderYestTotalCount +=1;
$orderYestTotalBaseSale += $baseGrandTotal;
$orderYestCustomer[$customer_id] = $customer_id;
}
}
}
$orderYestCustomerCount= count($orderYestCustomer);
$orderTodayCustomerCount = count($orderTodayCustomer);
//2.2 新增用户数
// 1.2总量:用户总量
$filter = [
'select' => ['firstname'],
'where' => [
['>=', 'created_at', $yest0Time],
['<', 'created_at', $today0Time],
],
'asArray' => true,
];
$yestCustomerData = Yii::$service->customer->coll($filter);
$yestCustomerCount = isset($yestCustomerData['count']) ? $yestCustomerData['count'] : 0;
$filter = [
'select' => ['firstname'],
'where' => [
['>=', 'created_at', $today0Time],
],
'asArray' => true,
];
$todayCustomerData = Yii::$service->customer->coll($filter);
$todayCustomerCount = isset($todayCustomerData['count']) ? $todayCustomerData['count'] : 0;
return [
'all' => [
'product_count' => $productTotalCount,
'customer_count' => $customerTotalCount,
'order_count' => $orderTotalCount,
'review_count' => $reviewTotalCount,
],
'yestday' => [
'order_count' => $orderYestTotalCount,
'order_base_sale' => Yii::$service->helper->format->numberFormat($orderYestTotalBaseSale),
'order_customer_count' => $orderYestCustomerCount,
'register_customer_count' => $yestCustomerCount,
],
'today' => [
'order_count' => $orderTodayTotalCount,
'order_base_sale' => Yii::$service->helper->format->numberFormat($orderTodayTotalBaseSale),
'order_customer_count' => $orderTodayCustomerCount,
'register_customer_count' => $todayCustomerCount,
],
];
} | 后台用户登陆后,看到的的统计信息
1.总量:产品Sku总数,用户总量,订单总量,评价总量
2.昨日,今日:支付订单销售额,支付订单数,新增用户数,下单用户数 | getRecentStatisticsInfo | php | fecshop/yii2_fecshop | services/Systemhelper.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Systemhelper.php | BSD-3-Clause |
public function initRewriteMap(&$config)
{
/**
* yii class Map Custom
*/
$yiiClassMap = isset($config['yiiClassMap']) ? $config['yiiClassMap'] : '';
if(is_array($yiiClassMap) && !empty($yiiClassMap)){
foreach($yiiClassMap as $namespace => $filePath){
Yii::$classMap[$namespace] = $filePath;
}
}
unset($config['yiiClassMap']);
/**
* Yii 重写block controller model等
* 也就是说:除了compoent 和services,其他的用RewriteMap的方式来实现重写
* 重写的类可以集成被重写的类
*/
$fecRewriteMap = isset($config['fecRewriteMap']) ? $config['fecRewriteMap'] : '';
if(is_array($fecRewriteMap) && !empty($fecRewriteMap)){
Yii::$rewriteMap = $fecRewriteMap;
}
unset($config['fecRewriteMap']);
} | init yiiClassMap and fecRewriteMap | initRewriteMap | php | fecshop/yii2_fecshop | services/Application.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Application.php | BSD-3-Clause |
public function getChildService($childServiceName)
{
if (!isset($this->_childService[$childServiceName]) || !$this->_childService[$childServiceName]) {
$childService = $this->childService;
if (isset($childService[$childServiceName])) {
$service = $childService[$childServiceName];
if (!isset($service['enableService']) || $service['enableService']) {
$this->_childService[$childServiceName] = Yii::createObject($service);
} else {
throw new InvalidConfigException('Child Service ['.$childServiceName.'] is disabled in '.get_called_class().', you must enable it! ');
}
} else {
throw new InvalidConfigException('Child Service ['.$childServiceName.'] does not exist in '.get_called_class().', you must config it! ');
}
}
return isset($this->_childService[$childServiceName]) ? $this->_childService[$childServiceName] : null;
} | 根据服务名字获取服务实例
Get service instance by service name.
用类似于 Yii2 的 component 原理,采用单例模式实现的服务功能,
服务的配置文件位于 config/services 目录
@var string $childServiceName
@return \fecshop\services\Service
@throws \yii\base\InvalidConfigException if the service is not found or the service is disabled | getChildService | php | fecshop/yii2_fecshop | services/Application.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Application.php | BSD-3-Clause |
public function __get($serviceName)
{
return $this->getChildService($serviceName);
} | 魔术方法,当调用一个属性,对象不存在的时候就会执行该方法,然后
根据构造方法注入的配置,实例化service对象。
@var string $serviceName service name
@return \fecshop\services\Service
@throws \yii\base\InvalidConfigException if the service does not exist or the service is disabled | __get | php | fecshop/yii2_fecshop | services/Application.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Application.php | BSD-3-Clause |
public function init()
{
parent::init();
// 从数据库配置中得到值, 设置成当前service存储,是Mysqldb 还是 Mongodb
$config = Yii::$app->store->get('service_db', 'category_and_product');
$this->storage = 'CategoryMysqldb';
if ($config == Yii::$app->store->serviceMongodbName) {
$this->storage = 'CategoryMongodb';
}
$currentService = $this->getStorageService($this);
$this->_category = new $currentService();
} | init function , 初始化category,使用哪一个category service.
目前只支持mongodb,不支持mysql | init | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function changeToMongoStorage()
{
$this->storage = 'CategoryMongodb';
$currentService = $this->getStorageService($this);
$this->_category = new $currentService();
} | 动态更改为mongodb model | changeToMongoStorage | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function changeToMysqlStorage()
{
$this->storage = 'CategoryMysqldb';
$currentService = $this->getStorageService($this);
$this->_category = new $currentService();
} | 动态更改为mongodb model | changeToMysqlStorage | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function getPrimaryKey()
{
return $this->_category->getPrimaryKey();
} | 得到当前的category service 对应的主键名称,譬如如果是mongo,返回的是 _id. | getPrimaryKey | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function getModelName()
{
return get_class($this->_category->getByPrimaryKey());
} | 得到category model的全名. | getModelName | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function getByPrimaryKey($primaryKey)
{
return $this->_category->getByPrimaryKey($primaryKey);
} | @param $primaryKey | String or Int , 主键
通过主键,得到category info | getByPrimaryKey | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function getByUrlKey($urlKey)
{
return $this->_category->getByUrlKey($urlKey);
} | @param $urlKey | String or Int , Url Key
通过主键,得到category info | getByUrlKey | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function coll($filter = [])
{
return $this->_category->coll($filter);
} | Get category collection by $filter.
@param array $filter
example filter:
[
'numPerPage' => 20,
'pageNum' => 1,
'orderBy' => ['_id' => SORT_DESC, 'sku' => SORT_ASC ],
'where' => [
['>','price','1'],
['<','price','10'],
['sku' => 'uk10001'],
],
'asArray' => true,
] | coll | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function getTreeArr($rootCategoryId = 0, $lang = '', $appserver = false, $level = 1)
{
return $this->_category->getTreeArr($rootCategoryId, $lang, $appserver);
} | 得到分类的树数组。
数组中只有 id name(default language), child(子分类) 等数据。
目前此函数仅仅用于后台对分类的编辑使用。 appadmin. | getTreeArr | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function save($one, $originUrlKey = 'catalog/category/index')
{
return $this->_category->save($one, $originUrlKey);
} | @param $one|array , save one data . 分类数组
@param $originUrlKey|string , 分类的在修改之前的url key.(在数据库中保存的url_key字段,如果没有则为空)
保存分类,同时生成分类的伪静态url(自定义url),如果按照name生成的url或者自定义的urlkey存在,系统则会增加几个随机数字字符串,来增加唯一性。 | save | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function remove($id)
{
return $this->_category->remove($id);
} | @param $id | String 主键值
通过主键值找到分类,并且删除分类在url rewrite表中的记录
查看这个分类是否存在子分类,如果存在子分类,则删除所有的子分类,以及子分类在url rewrite表中对应的数据。 | remove | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function getAllParentInfo($parent_id)
{
return $this->_category->getAllParentInfo($parent_id);
} | @param $parent_id|string
通过当前分类的parent_id字段(当前分类的上级分类id),得到所有的上级分类数组。
里面包含的信息为:name,url_key。
譬如一个分类为三级分类,将他的parent_id传递给这个函数,那么,他返回的数组信息为[一级分类的信息(name,url_key),二级分类的信息(name,url_key)].
目前这个功能用于前端分类页面的面包屑导航。 | getAllParentInfo | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function getFilterCategory($category_id, $parent_id)
{
return $this->_category->getFilterCategory($category_id, $parent_id);
} | @param $category_id|string 当前的分类_id
@param $parent_id|string 当前的分类上级id parent_id
这个功能是点击分类后,在产品分类页面侧栏的子分类菜单导航,详细的逻辑如下:
1.如果level为一级,那么title部分为当前的分类,子分类为一级分类下的二级分类
2.如果level为二级,那么将所有的二级分类列出,当前的二级分类,会列出来当前二级分类对应的子分类
3.如果level为三级,那么将所有的二级分类列出。当前三级分类的所有姊妹分类(同一个父类)列出,当前三级分类如果有子分类,则列出
4.依次递归。
具体的显示效果,请查看appfront 对应的分类页面。 | getFilterCategory | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function getChildCategory($category_id)
{
return $this->_category->getChildCategory($category_id);
} | 得到category model的全名. | getChildCategory | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function getByRemoteId($remoteId)
{
return $this->_category->getByRemoteId($remoteId);
} | get model by remote primary key. | getByRemoteId | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function getFilterAttr($categoryM)
{
if (!$this->_filter_attr) {
$appName = Yii::$service->helper->getAppName();
$filter_default = Yii::$app->store->get($appName.'_catalog','category_filter_attr');
$filter_default = explode(',',$filter_default);
$current_fileter_select = $categoryM['filter_product_attr_selected'];
$current_fileter_unselect = $categoryM['filter_product_attr_unselected'];
$current_fileter_select_arr = $this->getFilterArr($current_fileter_select);
$current_fileter_unselect_arr = $this->getFilterArr($current_fileter_unselect);
$filter_attrs = array_merge($filter_default, $current_fileter_select_arr);
$filter_attrs = array_diff($filter_attrs, $current_fileter_unselect_arr);
$this->_filter_attr = $filter_attrs;
$this->_filter_attr[] = 'brand_id';
}
//var_dump($this->_filter_attr);
//echo 1;
return $this->_filter_attr;
} | 得到分类侧栏属性过滤的产品属性数组 | getFilterAttr | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function customCategoryFilterAttrInfo()
{
if (!$this->_customCategoryFilterAttrInfo) {
$customCategoryFilterAttr = $this->customCategoryFilterAttr;
// 加入品牌
$customCategoryFilterAttr['brand_id'] = [
'label' => 'Brand',
'items' => Yii::$service->product->brand->getAllBrandIdAndNames(),
];
$this->_customCategoryFilterAttrInfo = $customCategoryFilterAttr;
}
return $this->_customCategoryFilterAttrInfo;
} | 分类页面-属性过滤-自定义属性以及属性值。 | customCategoryFilterAttrInfo | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function getCustomCategoryFilterAttrItemLabel($attr, $attrVal)
{
$customAttrInfo = $this->customCategoryFilterAttrInfo();
if (isset($customAttrInfo[$attr]['items'][$attrVal]) && $customAttrInfo[$attr]['items'][$attrVal]) {
return $customAttrInfo[$attr]['items'][$attrVal];
}
return '';
} | @param $attr | string, 属性名称
@param $attrVal | string, 属性值
得到自定义的属性值。 | getCustomCategoryFilterAttrItemLabel | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function isEnableFilterPrice()
{
$appName = Yii::$service->helper->getAppName();
$category_filter_price = Yii::$app->store->get($appName.'_catalog','category_filter_price');
if ($category_filter_price == Yii::$app->store->enable) {
return true;
}
return false;
} | 是否在分类产品列表页面,进行价格过滤 | isEnableFilterPrice | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function isEnableFilterSubCategory()
{
$appName = Yii::$service->helper->getAppName();
$category_filter_category = Yii::$app->store->get($appName.'_catalog','category_filter_category');
if ($category_filter_category == Yii::$app->store->enable) {
return true;
}
return false;
} | 是否在分类产品列表页面,进行子分类显示 | isEnableFilterSubCategory | php | fecshop/yii2_fecshop | services/Category.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Category.php | BSD-3-Clause |
public function getXhEditorUploadImgUrl(){
return $this->xhEditorUploadImgUrl;
} | @return string 得到编辑器上传图片upload url | getXhEditorUploadImgUrl | php | fecshop/yii2_fecshop | services/Admin.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Admin.php | BSD-3-Clause |
public function getXhEditorUploadImgForamt(){
return $this->xhEditorUploadImgForamt;
} | @return string 得到编辑器上传图片允许的文件格式 | getXhEditorUploadImgForamt | php | fecshop/yii2_fecshop | services/Admin.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Admin.php | BSD-3-Clause |
public function getXhEditorUploadFlashUrl(){
return $this->xhEditorUploadFlashUrl;
} | @return string 得到编辑器上传Flash upload url | getXhEditorUploadFlashUrl | php | fecshop/yii2_fecshop | services/Admin.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Admin.php | BSD-3-Clause |
public function getXhEditorUploadFlashFormat(){
return $this->xhEditorUploadFlashFormat;
} | @return string 得到编辑器上传Flash允许的文件格式 | getXhEditorUploadFlashFormat | php | fecshop/yii2_fecshop | services/Admin.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Admin.php | BSD-3-Clause |
public function getXhEditorUploadLinkUrl(){
return $this->xhEditorUploadLinkUrl;
} | @return string 得到编辑器上传Link upload url | getXhEditorUploadLinkUrl | php | fecshop/yii2_fecshop | services/Admin.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Admin.php | BSD-3-Clause |
public function getXhEditorUploadLinkFormat(){
return $this->xhEditorUploadLinkFormat;
} | @return string 得到编辑器上传Link允许的文件格式 | getXhEditorUploadLinkFormat | php | fecshop/yii2_fecshop | services/Admin.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Admin.php | BSD-3-Clause |
public function getXhEditorUploadMediaUrl(){
return $this->xhEditorUploadMediaUrl;
} | @return string 得到编辑器上传Media upload url | getXhEditorUploadMediaUrl | php | fecshop/yii2_fecshop | services/Admin.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Admin.php | BSD-3-Clause |
public function getXhEditorUploadMediaFormat(){
return $this->xhEditorUploadMediaFormat;
} | @return string 得到编辑器上传Media允许的文件格式 | getXhEditorUploadMediaFormat | php | fecshop/yii2_fecshop | services/Admin.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Admin.php | BSD-3-Clause |
public function bootstrap($app){
$this->initLangCode();
} | @param $app
在Yii2框架的初始化过程过程过程中执行的函数,将被组件(Yii2 components)Yii::$app->store->bootstrap() 调用
Yii::$app->store 组件, 就是文件:fecshop\components\Store.php
@throws InvalidConfigException | bootstrap | php | fecshop/yii2_fecshop | services/Admin.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Admin.php | BSD-3-Clause |
protected function initLangCode(){
if (!$this->_currentLangCode) {
$currentLangCode = Yii::$service->session->get(self::ADMIN_CURRENT_LANG_CODE);
if (!$currentLangCode) {
$currentLangCode = Yii::$service->fecshoplang->defaultLangCode;
}
if (!$currentLangCode) {
throw new InvalidConfigException('default lang code must config');
}
if ($this->setTranslateLang($currentLangCode)) {
$this->_currentLangCode = $currentLangCode;
} else {
throw new InvalidConfigException('lang code: '.$currentLangCode.' can not find in fecshoplang service config, you should add this language config');
}
}
} | 初始化后台多语言
@throws InvalidConfigException | initLangCode | php | fecshop/yii2_fecshop | services/Admin.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Admin.php | BSD-3-Clause |
public function getSearchProductColl($select, $where, $pageNum, $numPerPage, $product_search_max_count, $filterAttr = [])
{
// 当前有效的搜索引擎
$searchEngineList = $this->getAllChildServiceName();
// 语言对应
$currentSearchEngine = $this->getCurrentSearchEngine();
if (in_array($currentSearchEngine, $searchEngineList)) {
$service = $this->{$currentSearchEngine};
return $service->getSearchProductColl($select, $where, $pageNum, $numPerPage, $product_search_max_count, $filterAttr);
}
} | @param $select | Array
@param $where | Array
@param $pageNum | Int
@param $numPerPage | Array
@param $product_search_max_count | Int , 搜索结果最大产品数。
对于上面的参数和以前的$filter类似,大致和下面的类似
[
'category_id' => 1,
'pageNum' => 2,
'numPerPage' => 50,
'orderBy' => 'name',
'where' => [
['>','price',11],
['<','price',22],
],
'select' => ['xx','yy'],
'group' => '$spu',
]
得到搜索的产品列表. | getSearchProductColl | php | fecshop/yii2_fecshop | services/Search.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Search.php | BSD-3-Clause |
public function getFrontSearchFilter($filter_attr, $where)
{
// 当前有效的搜索引擎
$searchEngineList = $this->getAllChildServiceName();
// 语言对应
$currentSearchEngine = $this->getCurrentSearchEngine();
if (in_array($currentSearchEngine, $searchEngineList)) {
$service = $this->{$currentSearchEngine};
return $service->getFrontSearchFilter($filter_attr, $where);
}
} | 得到搜索的sku列表侧栏的过滤.
@param $filter_attr | Array
@param $where | Array , like
[
['>','price',11],
['<','price',22],
], | getFrontSearchFilter | php | fecshop/yii2_fecshop | services/Search.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Search.php | BSD-3-Clause |
public function getCurrentSearchEngine()
{
if (!$this->_currentSearchEngine) {
$currentLangCode = Yii::$service->store->currentLangCode;
if (!$currentLangCode) {
return null;
}
$langArr = Yii::$app->store->get('mutil_lang');
$langCodeAndEngine = [];
foreach ($langArr as $one) {
$langCodeAndEngine[$one['lang_code']] = $one['search_engine'];
}
if (!isset($langCodeAndEngine[$currentLangCode])) {
return null;
}
$this->_currentSearchEngine = $langCodeAndEngine[$currentLangCode];
}
return $this->_currentSearchEngine;
} | 得到当前语言对应的搜索引擎 | getCurrentSearchEngine | php | fecshop/yii2_fecshop | services/Search.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Search.php | BSD-3-Clause |
public function getUUID()
{
if (!$this->_uuid) {
$header = Yii::$app->request->getHeaders();
$uuidName = $this->fecshop_uuid;
// 1.从requestheader里面获取uuid,
if (isset($header[$uuidName]) && !empty($header[$uuidName])) {
$this->_uuid = $header[$uuidName];
} else { // 2.如果获取不到uuid,就生成uuid
$uuid1 = Uuid::uuid1();
$this->_uuid = $uuid1->toString();
}
// 3.把 $this->_uuid 写入到 response 的header里面
Yii::$app->response->getHeaders()->set($uuidName, $this->_uuid);
}
return $this->_uuid;
} | 访问端:
api访问接口,返回数据的时候,需要从 response headers 中 读取 uuid
api 如果获取了uuid,那么下次访问的时候,需要在request header 中附带uuid信息。
接收端: 也就是下面的函数
先从 request headers 读取uuid
读取不到,自己生成uuid
最后将uuid写入response headers中 | getUUID | php | fecshop/yii2_fecshop | services/Session.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Session.php | BSD-3-Clause |
public function reflushUUID()
{
$uuid1 = Uuid::uuid1();
$this->_uuid = $uuid1->toString();
Yii::$app->response->getHeaders()->set($this->fecshop_uuid, $this->_uuid);
} | 刷新uuid(帐号退出后,需要刷新uuid) | reflushUUID | php | fecshop/yii2_fecshop | services/Session.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Session.php | BSD-3-Clause |
public function login($data)
{
return Yii::$service->adminUser->userLogin->login($data);
} | @param $data|array
数组格式:['username'=>'[email protected]','password'=>'xxxx'] | login | php | fecshop/yii2_fecshop | services/AdminUser.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/AdminUser.php | BSD-3-Clause |
public function getIdAndNameArrByIds($ids)
{
return Yii::$service->adminUser->adminUser->getIdAndNameArrByIds($ids);
} | @param $ids | Int Array
@return 得到相应用户的数组。 | getIdAndNameArrByIds | php | fecshop/yii2_fecshop | services/AdminUser.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/AdminUser.php | BSD-3-Clause |
public function loginAndGetAccessToken($username, $password)
{
return Yii::$service->adminUser->userLogin->loginAndGetAccessToken($username, $password);
} | Appapi 部分使用的函数
@param $username | String
@param $password | String
@return mix string|null
Appapi 和 第三方进行数据对接部分的用户登陆验证 | loginAndGetAccessToken | php | fecshop/yii2_fecshop | services/AdminUser.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/AdminUser.php | BSD-3-Clause |
public function loginByAccessToken($type = null)
{
return Yii::$service->adminUser->userLogin->loginByAccessToken($type);
} | AppServer 部分使用的函数
@param $type | null or Object
从request headers中获取access-token,然后执行登录
如果登录成功,然后验证时间是否过期
如果不过期,则返回identity
** 该方法为appserver用户通过access-token验证需要执行的函数。 | loginByAccessToken | php | fecshop/yii2_fecshop | services/AdminUser.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/AdminUser.php | BSD-3-Clause |
public function logoutByAccessToken()
{
return Yii::$service->adminUser->userLogin->logoutByAccessToken();
} | 通过accessToek的方式,进行登出从操作。 | logoutByAccessToken | php | fecshop/yii2_fecshop | services/AdminUser.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/AdminUser.php | BSD-3-Clause |
public function trigger($eventName, $data)
{
if (!is_array($data) && !is_object($data)) {
//Yii::$service->helper->errors->add('event data must array');
return;
}
if (isset($this->eventList[$eventName]) && !empty($this->eventList[$eventName]) && is_array($this->eventList[$eventName])) {
foreach ($this->eventList[$eventName] as $one) {
if (is_array($one) && !empty($one)) {
list($class, $method) = $one;
if ($class && $method) {
$class::$method($data);
}
}
}
}
} | @param $eventName | String , 时间的名字
@param $data | Array or object , 数据数组或者对象,将各个数据以数组的方式传递过来。
从配置中找到相应的event,然后执行event。
event 相当于插代码的感觉。 | trigger | php | fecshop/yii2_fecshop | services/Event.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Event.php | BSD-3-Clause |
public function addErr($errors)
{
$this->eventErr[] = $errors;
return true;
} | @param $errors | string
event 执行,增加错误信息 | addErr | php | fecshop/yii2_fecshop | services/Event.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Event.php | BSD-3-Clause |
public function getErrStr($split=',')
{
if (!is_array($this->eventErr) || empty($this->eventErr)) {
return '';
}
return implode($split, $this->eventErr);
} | @param $split | string, 字符串分隔符 | getErrStr | php | fecshop/yii2_fecshop | services/Event.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Event.php | BSD-3-Clause |
public function getErrArr($split=',')
{
if (!is_array($this->eventErr) || empty($this->eventErr)) {
return '';
}
return $this->eventErr;
} | @param $split | string, 字符串分隔符 | getErrArr | php | fecshop/yii2_fecshop | services/Event.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Event.php | BSD-3-Clause |
public function setPaymentMethod($payment_method)
{
$this->_currentPaymentMethod = $payment_method;
} | @param $payment_method | string
设置当前的支付方式 | setPaymentMethod | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getPaymentMethod()
{
return $this->_currentPaymentMethod;
} | @return $payment_method | string
得到当前的支付方式 | getPaymentMethod | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getPaymentLabels(){
$arr = [];
$paymentConfig = $this->paymentConfig;
if (is_array($paymentConfig['standard'])) {
foreach ($paymentConfig['standard'] as $payment_method => $one) {
if (isset($one['label']) && !empty($one['label']) && $payment_method) {
$arr[$payment_method] = $one['label'];
}
}
}
return $arr;
} | @return 得到支付方式,以及对应的label,譬如:
[
'check_money' => 'Check / Money Order',
'alipay_standard' => '支付宝支付',
] #从配置信息中获取 | getPaymentLabels | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getStandardStartUrl($payment_method = '', $type = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['standard'][$payment_method]['start_url'])) {
if (!empty($paymentConfig['standard'][$payment_method]['start_url'])) {
if ($type == 'appserver') {
return $this->getAppServerUrl($paymentConfig['standard'][$payment_method]['start_url']);
} else {
return $this->getUrl($paymentConfig['standard'][$payment_method]['start_url']);
}
}
}
}
} | @param $payment_method | String 支付方式。
@return 返回提交订单信息跳转到的第三方支付url,也就是第三方支付的url。
#从配置信息中获取 | getStandardStartUrl | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
protected function getUrl($url)
{
$homeUrl = Yii::$service->url->homeUrl();
$url = str_replace('@homeUrl', $homeUrl, $url);
return trim($url);
} | @param $url | String url的字符串
@return string 根据传递的字符串格式,得到相应的url | getUrl | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getStandardSuccessRedirectUrl($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['standard'][$payment_method]['success_redirect_url'])) {
if (!empty($paymentConfig['standard'][$payment_method]['success_redirect_url'])) {
return $this->getUrl($paymentConfig['standard'][$payment_method]['success_redirect_url']);
}
}
}
} | @param $payment_method | String 支付方式。
@return 第三方支付成功后,返回到网站的url
#从配置信息中获取 | getStandardSuccessRedirectUrl | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getStandardCancelUrl($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['standard'][$payment_method]['cancel_url'])) {
if (!empty($paymentConfig['standard'][$payment_method]['cancel_url'])) {
return $this->getUrl($paymentConfig['standard'][$payment_method]['cancel_url']);
}
}
}
} | @param $payment_method | String 支付方式。
@return string 支付取消的url。
#从配置信息中获取 | getStandardCancelUrl | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getStandardAccount($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['standard'][$payment_method]['account'])) {
if (!empty($paymentConfig['standard'][$payment_method]['account'])) {
return $paymentConfig['standard'][$payment_method]['account'];
}
}
}
} | @param $payment_method | String 支付方式。
@return string 用户名
#从配置信息中获取 | getStandardAccount | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getStandardPassword($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['standard'][$payment_method]['password'])) {
if (!empty($paymentConfig['standard'][$payment_method]['password'])) {
return $paymentConfig['standard'][$payment_method]['password'];
}
}
}
} | @param $payment_method | String 支付方式。
@return string Password
#从配置信息中获取 | getStandardPassword | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getStandardSignature($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['standard'][$payment_method]['signature'])) {
if (!empty($paymentConfig['standard'][$payment_method]['signature'])) {
return $paymentConfig['standard'][$payment_method]['signature'];
}
}
}
} | @param $payment_method | String 支付方式。
@return string Signature
#从配置信息中获取 | getStandardSignature | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getStandardWebscrUrl($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['standard'][$payment_method]['webscr_url'])) {
if (!empty($paymentConfig['standard'][$payment_method]['webscr_url'])) {
return $paymentConfig['standard'][$payment_method]['webscr_url'];
}
}
}
} | @param $payment_method | String 支付方式。
@return 返回进行数据交互的express的api地址。 | getStandardWebscrUrl | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function ifIsCorrectStandard($payment_method)
{
$paymentConfig = $this->paymentConfig;
$standard = isset($paymentConfig['standard']) ? $paymentConfig['standard'] : '';
if (isset($standard[$payment_method]) && !empty($standard[$payment_method])) {
return true;
} else {
return false;
}
} | @param $payment_method | String , 支付方式
@return bool 判断传递的支付方式,是否在配置中存在,如果存在返回true。 | ifIsCorrectStandard | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getPaymentLabelByMethod($payment_method = '')
{
$payment_method_label = $this->getStandardLabel($payment_method);
if (!$payment_method_label) {
$payment_method_label = $this->getExpressLabel($payment_method);
}
if ($payment_method_label) {
return $payment_method_label;
} else {
return $payment_method;
}
} | @param $payment_method | String 支付方式。
@return 返回支付方式的label | getPaymentLabelByMethod | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getStandardLabel($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['standard'][$payment_method]['label'])) {
if (!empty($paymentConfig['standard'][$payment_method]['label'])) {
return $paymentConfig['standard'][$payment_method]['label'];
}
}
}
} | @param $payment_method | String 支付方式。
@return 返回进行数据交互的express的label。 | getStandardLabel | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getStandardIpnUrl($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['standard'][$payment_method]['ipn_url'])) {
if (!empty($paymentConfig['standard'][$payment_method]['ipn_url'])) {
return $this->getUrl($paymentConfig['standard'][$payment_method]['ipn_url']);
}
}
}
} | @param $payment_method | String 支付方式。
@return 返回进行数据交互的express的signature。 | getStandardIpnUrl | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getStandardReturnUrl($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['standard'][$payment_method]['return_url'])) {
if (!empty($paymentConfig['standard'][$payment_method]['return_url'])) {
return $this->getUrl($paymentConfig['standard'][$payment_method]['return_url']);
}
}
}
} | @param $payment_method | String 支付方式。
@return 返回进行数据交互的express的signature。 | getStandardReturnUrl | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getExpressNvpUrl($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['express'][$payment_method]['nvp_url'])) {
if (!empty($paymentConfig['express'][$payment_method]['nvp_url'])) {
return $paymentConfig['express'][$payment_method]['nvp_url'];
}
}
}
} | @param $payment_method | String 支付方式。
@return 返回获取token的url地址。 | getExpressNvpUrl | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getExpressWebscrUrl($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['express'][$payment_method]['webscr_url'])) {
if (!empty($paymentConfig['express'][$payment_method]['webscr_url'])) {
return $paymentConfig['express'][$payment_method]['webscr_url'];
}
}
}
} | @param $payment_method | String 支付方式。
@return 返回进行数据交互的express的api地址。 | getExpressWebscrUrl | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getExpressAccount($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['express'][$payment_method]['account'])) {
if (!empty($paymentConfig['express'][$payment_method]['account'])) {
return $paymentConfig['express'][$payment_method]['account'];
}
}
}
} | @param $payment_method | String 支付方式。
@return 返回进行数据交互的express的account。 | getExpressAccount | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getExpressPassword($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['express'][$payment_method]['password'])) {
if (!empty($paymentConfig['express'][$payment_method]['password'])) {
return $paymentConfig['express'][$payment_method]['password'];
}
}
}
} | @param $payment_method | String 支付方式。
@return 返回进行数据交互的express的password。 | getExpressPassword | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getExpressSignature($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['express'][$payment_method]['signature'])) {
if (!empty($paymentConfig['express'][$payment_method]['signature'])) {
return $paymentConfig['express'][$payment_method]['signature'];
}
}
}
} | @param $payment_method | String 支付方式。
@return 返回进行数据交互的express的signature。 | getExpressSignature | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
public function getExpressLabel($payment_method = '')
{
if (!$payment_method) {
$payment_method = $this->getPaymentMethod();
}
if ($payment_method) {
$paymentConfig = $this->paymentConfig;
if (isset($paymentConfig['express'][$payment_method]['label'])) {
if (!empty($paymentConfig['express'][$payment_method]['label'])) {
return $paymentConfig['express'][$payment_method]['label'];
}
}
}
} | @param $payment_method | String 支付方式。
@return 返回进行数据交互的express的label。 | getExpressLabel | php | fecshop/yii2_fecshop | services/Payment.php | https://github.com/fecshop/yii2_fecshop/blob/master/services/Payment.php | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.