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 getByReviewId($_id) { return $this->_reviewModel->getCollection()->findOne([$this->getPrimaryKey() => $_id]); }
@param $_id | String 后台编辑 通过评论id找到评论 注意:因为每个产品的评论可能加入了新的字段,因此不能使用ActiveRecord的方式取出来, 使用下面的方式可以把字段都取出来。
getByReviewId
php
fecshop/yii2_fecshop
services/product/review/ReviewMongodb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMongodb.php
BSD-3-Clause
public function getByPrimaryKey($primaryKey) { if ($primaryKey) { return $this->_reviewModel->findOne($primaryKey); } else { return new $this->_reviewModelName(); } }
@param $primaryKey | String 主键值 get artile model by primary key.
getByPrimaryKey
php
fecshop/yii2_fecshop
services/product/review/ReviewMongodb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMongodb.php
BSD-3-Clause
public function coll($filter = '') { return $this->lists($filter); }
@param $filter|array get artile collection by $filter example filter: [ 'numPerPage' => 20, 'pageNum' => 1, 'orderBy' => [$this->getPrimaryKey() => SORT_DESC, 'sku' => SORT_ASC ], 'where' => [ ['>','price',1], ['<=','price',10] ['sku' => 'uk10001'], ], 'asArray' => true, ]
coll
php
fecshop/yii2_fecshop
services/product/review/ReviewMongodb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMongodb.php
BSD-3-Clause
public function updateProductSpuReview($spu, $lang_code) { $reviewModel = $this->_reviewModel; $filter = [ 'numPerPage' => 10000, // mongodb 查询,numPerPage必须设置,如果不设置,默认为20 'pageNum' => 1, 'where' => [ ['product_spu' => $spu], ['status' => $reviewModel->getActiveStatus()], ], ]; $coll = $this->coll($filter); $count = $coll['count']; $data = $coll['coll']; $rate_total = 0; $rate_total_arr['star_0'] = 0; $rate_total_arr['star_1'] = 0; $rate_total_arr['star_2'] = 0; $rate_total_arr['star_3'] = 0; $rate_total_arr['star_4'] = 0; $rate_total_arr['star_5'] = 0; $rate_lang_total = 0; $rate_lang_total_arr['star_0'] = 0; $rate_lang_total_arr['star_1'] = 0; $rate_lang_total_arr['star_2'] = 0; $rate_lang_total_arr['star_3'] = 0; $rate_lang_total_arr['star_4'] = 0; $rate_lang_total_arr['star_5'] = 0; $lang_count = 0; if (!empty($data) && is_array($data)) { foreach ($data as $one) { $rate_total += $one['rate_star']; $rs = 'star_'.$one['rate_star']; $rate_total_arr[$rs] += 1; if ($lang_code == $one['lang_code']) { $rate_lang_total += $one['rate_star']; $lang_count++; $rate_lang_total_arr[$rs] += 1; } } } if ($count == 0) { $avag_rate = 0; } else { $avag_rate = ceil($rate_total / $count *10) / 10; } if ($lang_count == 0) { $avag_lang_rate = 0; } else { $avag_lang_rate = ceil($rate_lang_total / $lang_count *10) / 10; } Yii::$service->product->updateProductReviewInfo($spu, $avag_rate, $count, $lang_code, $avag_lang_rate, $lang_count, $rate_total_arr, $rate_lang_total_arr); return true; }
@param $spu | String 当评论保存,更新评论的总数,平均评分信息到产品表的所有spu
updateProductSpuReview
php
fecshop/yii2_fecshop
services/product/review/ReviewMongodb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMongodb.php
BSD-3-Clause
public function getReviewsByUserId($filter) { $query = $this->_reviewModel->find(); $query = Yii::$service->helper->ar->getCollByFilter($query, $filter); return [ 'coll' => $query->all(), 'count'=> $query->count(), ]; }
@param $filter|array get artile collection by $filter example filter: [ 'numPerPage' => 20, 'pageNum' => 1, 'orderBy' => [$this->getPrimaryKey() => SORT_DESC, 'sku' => SORT_ASC ], 'where' => [ ['>','price',1], ['<=','price',10] ['sku' => 'uk10001'], ], 'asArray' => true, ]
getReviewsByUserId
php
fecshop/yii2_fecshop
services/product/review/ReviewMongodb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMongodb.php
BSD-3-Clause
public function isReviewRole($product_id) { if (!$this->getReviewService()->reviewOnlyOrderedProduct) { return true; } $itmes = Yii::$service->order->item->getByProductIdAndCustomerId($product_id, $this->getReviewService()->reviewMonth); //var_dump($itmes);exit; if ($itmes) { return true; } else { return false; } }
@param $product_id | String, 产品id 是否有评论的权限,如果有,则返回true
isReviewRole
php
fecshop/yii2_fecshop
services/product/review/ReviewMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMysqldb.php
BSD-3-Clause
public function noActiveStatus() { $model = $this->_reviewModel; return $model::NOACTIVE_STATUS; }
得到review noactive status,默认状态
noActiveStatus
php
fecshop/yii2_fecshop
services/product/review/ReviewMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMysqldb.php
BSD-3-Clause
public function activeStatus() { $model = $this->_reviewModel; return $model::ACTIVE_STATUS; }
得到review active status 审核通过的状态
activeStatus
php
fecshop/yii2_fecshop
services/product/review/ReviewMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMysqldb.php
BSD-3-Clause
public function refuseStatus() { $model = $this->_reviewModel; return $model::REFUSE_STATUS; }
得到review refuse status 审核拒绝的状态
refuseStatus
php
fecshop/yii2_fecshop
services/product/review/ReviewMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMysqldb.php
BSD-3-Clause
public function getCountBySpu($spu) { $where = [ 'product_spu' => $spu, ]; if ($this->getReviewService()->filterByLang && ($currentLangCode = Yii::$service->store->currentLangCode)) { $where['lang_code'] = $currentLangCode; } $count = $this->_reviewModel->find()->asArray()->where($where)->count(); return $count ? $count : 0; }
@param $spu | String. 通过spu找到评论总数。
getCountBySpu
php
fecshop/yii2_fecshop
services/product/review/ReviewMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMysqldb.php
BSD-3-Clause
public function addReview($review_data) { //$this->initReviewAttr($review_data); $model = new $this->_reviewModelName(); if (isset($review_data[$this->getPrimaryKey()])) { unset($review_data[$this->getPrimaryKey()]); } $model = $this->_reviewModel; $review_data['status'] = $model::NOACTIVE_STATUS; $review_data['store'] = Yii::$service->store->currentStore; $review_data['lang_code'] = Yii::$service->store->currentLangCode; $review_data['review_date'] = time(); if (!Yii::$app->user->isGuest) { $identity = Yii::$app->user->identity; $user_id = $identity['id']; $review_data['user_id'] = $user_id; } $review_data['ip'] = \fec\helpers\CFunc::get_real_ip(); $saveStatus = Yii::$service->helper->ar->save($model, $review_data); return true; }
@param $review_data | Array 增加评论 前台增加评论调用的函数。
addReview
php
fecshop/yii2_fecshop
services/product/review/ReviewMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMysqldb.php
BSD-3-Clause
public function updateReview($review_data) { //$this->initReviewAttr($review_data); $model = $this->_reviewModel->findOne([$this->getPrimaryKey()=> $review_data[$this->getPrimaryKey()]]); unset($review_data[$this->getPrimaryKey()]); $saveStatus = Yii::$service->helper->ar->save($model, $review_data); return true; }
@param $review_data | Array 保存评论
updateReview
php
fecshop/yii2_fecshop
services/product/review/ReviewMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMysqldb.php
BSD-3-Clause
public function getByReviewId($_id) { return $this->_reviewModel->getCollection()->findOne([$this->getPrimaryKey() => $_id]); }
@param $_id | String 后台编辑 通过评论id找到评论 注意:因为每个产品的评论可能加入了新的字段,因此不能使用ActiveRecord的方式取出来, 使用下面的方式可以把字段都取出来。
getByReviewId
php
fecshop/yii2_fecshop
services/product/review/ReviewMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMysqldb.php
BSD-3-Clause
public function getByPrimaryKey($primaryKey) { if ($primaryKey) { return $this->_reviewModel->findOne($primaryKey); } else { return new $this->_reviewModelName(); } }
@param $primaryKey | String 主键值 get artile model by primary key.
getByPrimaryKey
php
fecshop/yii2_fecshop
services/product/review/ReviewMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMysqldb.php
BSD-3-Clause
public function coll($filter = '') { return $this->lists($filter); }
@param $filter|array get artile collection by $filter example filter: [ 'numPerPage' => 20, 'pageNum' => 1, 'orderBy' => [$this->getPrimaryKey() => SORT_DESC, 'sku' => SORT_ASC ], 'where' => [ ['>','price',1], ['<=','price',10] ['sku' => 'uk10001'], ], 'asArray' => true, ]
coll
php
fecshop/yii2_fecshop
services/product/review/ReviewMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMysqldb.php
BSD-3-Clause
public function save($one) { $currentDateTime = \fec\helpers\CDate::getCurrentDateTime(); $primaryVal = isset($one[$this->getPrimaryKey()]) ? $one[$this->getPrimaryKey()] : ''; $one['status'] = (int) $one['status']; $one['rate_star'] = (int) $one['rate_star']; if ($primaryVal) { $model = $this->_reviewModel->findOne($primaryVal); if (!$model) { Yii::$service->helper->errors->add('reviewModel {primaryKey} is not exist', ['primaryKey'=>$this->getPrimaryKey()]); return; } } else { $model = new $this->_reviewModelName(); $model->created_admin_user_id = \fec\helpers\CUser::getCurrentUserId(); } //$review_data['status'] = $this->_reviewModel->ACTIVE_STATUS; $model->review_date = time(); unset($one[$this->getPrimaryKey()]); $saveStatus = Yii::$service->helper->ar->save($model, $one); $model->save(); // 更新评论信息到产品表中。 $this->updateProductSpuReview($model['product_spu'], $model['lang_code']); return true; }
@param $one|array , save one data . @param $originUrlKey|string , article origin url key. 评论,后台审核评论的保存方法。 保存后,把评论信息更新到产品表中。
save
php
fecshop/yii2_fecshop
services/product/review/ReviewMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMysqldb.php
BSD-3-Clause
public function updateProductSpuReview($spu, $lang_code) { $reviewModel = $this->_reviewModel; $filter = [ 'numPerPage' => 10000, // mongodb 查询,numPerPage必须设置,如果不设置,默认为20 'pageNum' => 1, 'where' => [ ['product_spu' => $spu], ['status' => $reviewModel->getActiveStatus()], ], ]; $coll = $this->coll($filter); $count = $coll['count']; $data = $coll['coll']; $rate_total = 0; $rate_total_arr['star_0'] = 0; $rate_total_arr['star_1'] = 0; $rate_total_arr['star_2'] = 0; $rate_total_arr['star_3'] = 0; $rate_total_arr['star_4'] = 0; $rate_total_arr['star_5'] = 0; $rate_lang_total = 0; $rate_lang_total_arr['star_0'] = 0; $rate_lang_total_arr['star_1'] = 0; $rate_lang_total_arr['star_2'] = 0; $rate_lang_total_arr['star_3'] = 0; $rate_lang_total_arr['star_4'] = 0; $rate_lang_total_arr['star_5'] = 0; $lang_count = 0; if (!empty($data) && is_array($data)) { foreach ($data as $one) { $rate_total += $one['rate_star']; $rs = 'star_'.$one['rate_star']; $rate_total_arr[$rs] += 1; if ($lang_code == $one['lang_code']) { $rate_lang_total += $one['rate_star']; $lang_count++; $rate_lang_total_arr[$rs] += 1; } } } if ($count == 0) { $avag_rate = 0; } else { $avag_rate = ceil($rate_total / $count *10) / 10; } if ($lang_count == 0) { $avag_lang_rate = 0; } else { $avag_lang_rate = ceil($rate_lang_total / $lang_count *10) / 10; } Yii::$service->product->updateProductReviewInfo($spu, $avag_rate, $count, $lang_code, $avag_lang_rate, $lang_count, $rate_total_arr, $rate_lang_total_arr); return true; }
@param $spu | String 当评论保存,更新评论的总数,平均评分信息到产品表的所有spu
updateProductSpuReview
php
fecshop/yii2_fecshop
services/product/review/ReviewMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMysqldb.php
BSD-3-Clause
public function getReviewsByUserId($filter) { $query = $this->_reviewModel->find(); $query = Yii::$service->helper->ar->getCollByFilter($query, $filter); return [ 'coll' => $query->all(), 'count'=> $query->count(), ]; }
@param $filter|array get artile collection by $filter example filter: [ 'numPerPage' => 20, 'pageNum' => 1, 'orderBy' => [$this->getPrimaryKey() => SORT_DESC, 'sku' => SORT_ASC ], 'where' => [ ['>','price',1], ['<=','price',10] ['sku' => 'uk10001'], ], 'asArray' => true, ]
getReviewsByUserId
php
fecshop/yii2_fecshop
services/product/review/ReviewMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/review/ReviewMysqldb.php
BSD-3-Clause
public function getEnableStatus() { $model = $this->_attrGroupModel; return $model::STATUS_ENABLE; }
得到分类激活状态的值
getEnableStatus
php
fecshop/yii2_fecshop
services/product/attrgroup/AttrGroupMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/attrgroup/AttrGroupMysqldb.php
BSD-3-Clause
public function save($one) { $primaryVal = isset($one[$this->getPrimaryKey()]) ? $one[$this->getPrimaryKey()] : ''; $remoteId = isset($one['remote_id']) ? $one['remote_id'] : ''; $isUpdate = false; if ($primaryVal) { $model = $this->_attrGroupModel->findOne($primaryVal); if (!$model) { Yii::$service->helper->errors->add('Product attr group {primaryKey} is not exist', ['primaryKey' => $this->getPrimaryKey()]); return; } $isUpdate = true; } else if ($remoteId) { $model = $this->_attrGroupModel->findOne(['remote_id' => $remoteId]); if (!$model) { $model = new $this->_attrGroupModelName(); $model->created_at = time(); } else { $isUpdate = true; } } else { $model = new $this->_attrGroupModelName(); $model->created_at = time(); } // attr Group name唯一性判断 $groupName = $one['name']; if (!$groupName) { Yii::$service->helper->errors->add('name can not empty'); return false; } if ($isUpdate) { $groupId = $model['id']; if ($groupId) { $oneM = $this->_attrGroupModel->find()->asArray()->where([ 'and', ['<>', 'id', $groupId], ['name' => $groupName] ])->one(); if ($oneM['id']) { Yii::$service->helper->errors->add('name must unique'); return false; } } } else { $oneM = $this->_attrGroupModel->find()->asArray()->where(['name' => $groupName] )->one(); if ($oneM['id']) { Yii::$service->helper->errors->add('name must unique'); return false; } } $model->updated_at = time(); $primaryKey = $this->getPrimaryKey(); $model = Yii::$service->helper->ar->save($model, $one); $primaryVal = $model[$primaryKey]; return $model; }
@param $one|array save $data to cms model,then,add url rewrite info to system service urlrewrite.
save
php
fecshop/yii2_fecshop
services/product/attrgroup/AttrGroupMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/product/attrgroup/AttrGroupMysqldb.php
BSD-3-Clause
public function getViewFile($view, $throwError = true) { $view = trim($view); if (substr($view, 0, 1) == '@') { return Yii::getAlias($view); } $relativeFile = ''; $module = Yii::$app->controller->module; if ($module && $module->id) { $relativeFile = $module->id.'/'; } $routerPath = $relativeFile.Yii::$app->controller->id.'/'.$view; // 从配置中查看是否存在指定的view路径。 if (isset($this->viewFileConfig[$routerPath])) { $relativeFile = $this->viewFileConfig[$routerPath]; // 如果view是以@开头,则说明是绝对路径,直接返回 if (substr($relativeFile, 0, 1) == '@') { return Yii::getAlias($relativeFile); } } else { $relativeFile .= Yii::$app->controller->id.'/'.$view.'.php'; } $absoluteDir = Yii::$service->page->theme->getThemeDirArr(); foreach ($absoluteDir as $dir) { if ($dir) { $file = $dir.'/'.$relativeFile; if (file_exists($file)) { return $file; } } } // not find view file if ($throwError) { $notExistFile = []; foreach ($absoluteDir as $dir) { if ($dir) { $file = $dir.'/'.$relativeFile; $notExistFile[] = $file; } } throw new InvalidValueException('view file is not exist in'.implode(',', $notExistFile)); } else { return false; } }
@param $view | String ,view路径的字符串。 @param $throwError | boolean,view文件找不到的时候是否抛出异常。 根据模板路径的优先级,依次查找view文件,找到后,返回view文件的绝对路径。
getViewFile
php
fecshop/yii2_fecshop
services/page/Theme.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Theme.php
BSD-3-Clause
public function setLocalThemeDir($dir) { $this->localThemeDir = $dir; }
@param $dir | string 设置本地模板路径
setLocalThemeDir
php
fecshop/yii2_fecshop
services/page/Theme.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Theme.php
BSD-3-Clause
public function setThirdThemeDir($dir) { $this->thirdThemeDir = $dir; }
@param $dir | string 设置第三方模板路径
setThirdThemeDir
php
fecshop/yii2_fecshop
services/page/Theme.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Theme.php
BSD-3-Clause
public function getByKey($key, $lang = '') { if (!$lang) { $lang = Yii::$service->store->currentLanguage; } if (!$lang) { throw new InvalidValueException('language is empty'); } }
@param $key|array
getByKey
php
fecshop/yii2_fecshop
services/page/StaticBlock.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/StaticBlock.php
BSD-3-Clause
public function getById($_id) { }
@param $_id | Int get StaticBlock one data by $_id.
getById
php
fecshop/yii2_fecshop
services/page/StaticBlock.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/StaticBlock.php
BSD-3-Clause
public function getStaticBlockList($filter) { }
@param $filter | Array get StaticBlock collections by $filter .
getStaticBlockList
php
fecshop/yii2_fecshop
services/page/StaticBlock.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/StaticBlock.php
BSD-3-Clause
public function getCurrencys($currencyCode = '') { if (!$this->_currencys) { foreach ($this->currencys as $code => $info) { $this->_currencys[$code] = [ 'code' => $code, 'rate' => $info['rate'], 'symbol' => $info['symbol'], ]; } } if ($currencyCode) { if (isset($this->_currencys[$currencyCode])) { return $this->_currencys[$currencyCode]; } else { $currencyCode = $this->defaultCurrency; return $this->_currencys[$currencyCode]; } } return $this->_currencys; }
@param $currencyCode | string 货币简码,譬如USD,RMB等 @return array 如果不传递参数,得到所有的货币 如果传递参数,得到的是当前货币的信息。
getCurrencys
php
fecshop/yii2_fecshop
services/page/Currency.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Currency.php
BSD-3-Clause
public function getCurrentSymbol() { if (isset($this->currencys[$this->getCurrentCurrency()]['symbol'])) { return $this->currencys[$this->getCurrentCurrency()]['symbol']; } }
得到当前货币的符号,譬如¥ $ 等。 如果当前的货币在配置中找不到,则会强制改成默认货币
getCurrentSymbol
php
fecshop/yii2_fecshop
services/page/Currency.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Currency.php
BSD-3-Clause
public function getSymbol($currencyCode) { if (isset($this->currencys[$currencyCode]['symbol'])) { return $this->currencys[$currencyCode]['symbol']; } }
@param $currencyCode | 货币简码 得到货币的符号,譬如¥ $ 等。
getSymbol
php
fecshop/yii2_fecshop
services/page/Currency.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Currency.php
BSD-3-Clause
public function getBaseSymbol() { if (isset($this->currencys[$this->baseCurrecy]['symbol'])) { return $this->currencys[$this->baseCurrecy]['symbol']; } }
得到默认的货币符号,譬如: ¥, $
getBaseSymbol
php
fecshop/yii2_fecshop
services/page/Currency.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Currency.php
BSD-3-Clause
public function getBaseCurrecyCode() { return $this->baseCurrecy; }
得到默认的货币code,譬如: USD, CNY
getBaseCurrecyCode
php
fecshop/yii2_fecshop
services/page/Currency.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Currency.php
BSD-3-Clause
public function getCurrentCurrencyPrice($price) { $currencyCode = $this->getCurrentCurrency(); $currencyPrice = $this->getCurrencyPrice($price, $currencyCode); if ($currencyPrice !== null) { return $currencyPrice; } /* * 如果上面出现错误,当前的货币在货币配置中找不到,则会使用默认货币 * 这种情况可能出现在货币配置调整的过程中,找不到则会被强制改成默认货币。 */ $this->setCurrentCurrency($this->baseCurrecy); return $price; }
property $price|Float ,默认货币的价格 Get current currency price. price format is two decimal places, if current currency is not find in object variable $currencys(maybe change config in online shop,but current user session is effective), current currency will set defaultCurrency, origin price will be return. 通过传递默认货币的价格,得到当前货币的价格。
getCurrentCurrencyPrice
php
fecshop/yii2_fecshop
services/page/Currency.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Currency.php
BSD-3-Clause
public function getCurrencyPrice($price, $currencyCode) { if (isset($this->currencys[$currencyCode]['rate'])) { $rate = $this->currencys[$currencyCode]['rate']; if ($rate) { return bcmul($price, $rate, 2); } } return null; }
property $price|Float ,默认货币的价格 property $currencyCode|String,货币简码,譬如 USD 根据基础货币,得到相应货币的价格
getCurrencyPrice
php
fecshop/yii2_fecshop
services/page/Currency.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Currency.php
BSD-3-Clause
public function getBaseCurrencyPrice($current_price, $current_currency = '') { if (!$current_currency) { $current_currency = $this->getCurrentCurrency(); } if (isset($this->currencys[$current_currency]['rate'])) { $rate = $this->currencys[$current_currency]['rate']; if ($rate) { return bcdiv($current_price, $rate, 2); } } }
@param $current_price | Float 当前货币下的价格 @return 基础货币下的价格 通过当前的货币价格得到基础货币的价格,这是一个反推的过程, 需要特别注意的是:这种反推方法换算得到的基础货币的价格,和原来的基础货币价格, 可能有0.01的误差,因为默认货币换算成当前货币的算法为小数点后两位进一法得到的。
getBaseCurrencyPrice
php
fecshop/yii2_fecshop
services/page/Currency.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Currency.php
BSD-3-Clause
public function initCurrency($currencyCode = '') { if (!$this->defaultCurrency) { throw new InvalidConfigException('defautlt currency must config'); } if (!$this->baseCurrecy) { throw new InvalidConfigException('base currency must config'); } if (!$this->getCurrentCurrency()) { if (!$currencyCode) { $currencyCode = $this->defaultCurrency; } $this->setCurrentCurrency($currencyCode); } }
@param $currencyCode | 货币简码 初始化货币信息,在service Store bootstrap(Yii::$app->store->bootstrap()), 中会被调用 1. 如果 $this->defaultCurrency 和 $this->baseCurrecy 没有设置,将会报错。 2. 如果 传递参数$currencyCode为空,则会使用默认货币
initCurrency
php
fecshop/yii2_fecshop
services/page/Currency.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Currency.php
BSD-3-Clause
public function getCurrencyInfo($currencyCode = '') { if (!$currencyCode) { $currencyCode = $this->getCurrentCurrency(); } if (!$this->getCurrencys($currencyCode)) { $currencyCode = $this->defaultCurrency; $this->setCurrentCurrency($currencyCode); } return $this->getCurrencys($currencyCode); }
@param $currencyCode | String , 货币简码,如果参数$currencyCode为空,则取当前的货币简码 @return array 得到货币的详细信息,数据格式如下: [ 'code' => $code , 'rate' => $rate , 'symbol' => $symbol , ]
getCurrencyInfo
php
fecshop/yii2_fecshop
services/page/Currency.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Currency.php
BSD-3-Clause
public function getCurrentCurrency() { if (!$this->_currentCurrencyCode) { $this->_currentCurrencyCode = Yii::$service->session->get(self::CURRENCY_CURRENT); } return $this->_currentCurrencyCode; }
得到当前的货币。
getCurrentCurrency
php
fecshop/yii2_fecshop
services/page/Currency.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Currency.php
BSD-3-Clause
public function setCurrentCurrency($currencyCode) { if (!$this->isCorrectCurrency($currencyCode)) { $currencyCode = $this->defaultCurrency; } if ($currencyCode) { if (!Yii::$service->store->isAppserver()) { Yii::$service->session->set(self::CURRENCY_CURRENT, $currencyCode); } $this->_currentCurrencyCode = $currencyCode; return true; } }
@param $currencyCode | String, 当前的货币简码 设置当前的货币。
setCurrentCurrency
php
fecshop/yii2_fecshop
services/page/Currency.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Currency.php
BSD-3-Clause
public function appserverSetCurrentCurrency() { if ($this->_currentCurrencyCode) { return true; } $header = Yii::$app->request->getHeaders(); $currentCurrencyCode = $header[$this->appserverCurrencyHeaderName]; if (!$currentCurrencyCode) { $currentCurrencyCode = $this->defaultCurrency; } if (!$this->isCorrectCurrency($currentCurrencyCode)) { $currentCurrencyCode = $this->defaultCurrency; } $this->_currentCurrencyCode = $currentCurrencyCode; Yii::$app->response->getHeaders()->set($this->appserverCurrencyHeaderName, $this->_currentCurrencyCode); }
appserver端初始化currency 初始化货币services,直接从headers中取出来currency。进行set,这样currency就不会从session中读取 fecshop-2版本对于appserver已经抛弃session servcies
appserverSetCurrentCurrency
php
fecshop/yii2_fecshop
services/page/Currency.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Currency.php
BSD-3-Clause
protected function isCorrectCurrency($currencyCode) { if (isset($this->currencys[$currencyCode])) { return true; } else { return false; } }
@param $currency | String 货币简码 @return bool 检测当前传递的货币简码,是否在配置中存在,如果存在则返回true
isCorrectCurrency
php
fecshop/yii2_fecshop
services/page/Currency.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Currency.php
BSD-3-Clause
public function addItems($items) { if ($this->active) { $this->_items[] = $items; } }
property $items|Array. add $items to $this->_items. $items format example. 将各个部分的链接加入到面包屑导航中 $items = ['name'=>'fashion handbag','url'=>'http://www.xxx.com'];.
addItems
php
fecshop/yii2_fecshop
services/page/Breadcrumbs.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Breadcrumbs.php
BSD-3-Clause
public function getItems() { if ($this->active) { if (is_array($this->_items) && !empty($this->_items)) { return $this->_items; } else { return []; } } }
通过上面的方法addItems($items),把item加入进来后 然后,通过该函数取出来。
getItems
php
fecshop/yii2_fecshop
services/page/Breadcrumbs.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Breadcrumbs.php
BSD-3-Clause
public function getTextTerms() { Yii::$service->page->staticblock->get(self::TEXT_TERMS); }
得到页面底部的html部分
getTextTerms
php
fecshop/yii2_fecshop
services/page/Footer.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Footer.php
BSD-3-Clause
public function getCopyRight() { Yii::$service->page->staticblock->get(self::COPYRIGHT); }
得到页面底部的版权部分
getCopyRight
php
fecshop/yii2_fecshop
services/page/Footer.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Footer.php
BSD-3-Clause
public function followUs() { Yii::$service->page->staticblock->get(self::FOLLOW_USE); }
得到页面底部的follow us部分
followUs
php
fecshop/yii2_fecshop
services/page/Footer.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Footer.php
BSD-3-Clause
public function getPaymentImg() { Yii::$service->page->staticblock->get(self::PAYMENT_IMG); }
得到页面底部的支付图片部分
getPaymentImg
php
fecshop/yii2_fecshop
services/page/Footer.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Footer.php
BSD-3-Clause
public function getTraceCommonJsCode($view) { // 加入事件event $metaAfterEventName = 'event_after_trace_common_js_code'; Yii::$service->event->trigger($metaAfterEventName, [ 'view' => $view ]); if (!$this->traceJsEnable) { return ''; } $traceJs = "<script type=\"text/javascript\"> var _maq = _maq || []; _maq.push(['website_id', '" . $this->website_id . "']); _maq.push(['fec_store', '" . Yii::$service->store->currentStore . "']); _maq.push(['fec_lang', '" . Yii::$service->store->currentLangCode . "']); _maq.push(['fec_app', '" . Yii::$service->store->getCurrentAppName() . "']); _maq.push(['fec_currency', '" . Yii::$service->page->currency->getCurrentCurrency() . "']); (function() { var ma = document.createElement('script'); ma.type = 'text/javascript'; ma.async = true; ma.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + '".$this->trace_url."'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ma, s); })(); </script> "; return $traceJs . $this->thirdTraceJsStr; }
@return String, 通用的js部分,需要先设置 website_id 和 trace_url
getTraceCommonJsCode
php
fecshop/yii2_fecshop
services/page/Trace.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Trace.php
BSD-3-Clause
public function getTraceHomeJsCode($view, $homeData) { // 加入事件event $metaAfterEventName = 'event_after_trace_home_js_code'; Yii::$service->event->trigger($metaAfterEventName, [ 'view' => $view, 'homeData' => $homeData, ]); if ($this->traceJsEnable) { return "<script type=\"text/javascript\"> var _maq = _maq || []; </script>"; } else { return ''; } }
@param $view | Object ,\yii\web\View @param $homeData | array, 首页传递的数据,数组里面的值并不是固定的,根据需要灵活处理。 @return String, 注册页面的js Code
getTraceHomeJsCode
php
fecshop/yii2_fecshop
services/page/Trace.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Trace.php
BSD-3-Clause
public function getTraceSearchJsCode($view, $search, $products) { // 加入事件event $metaAfterEventName = 'event_after_trace_search_js_code'; Yii::$service->event->trigger($metaAfterEventName, [ 'view' => $view, 'searchText' => json_decode($search, true), 'products' => $products, ]); if ($this->traceJsEnable && $search) { return "<script type=\"text/javascript\"> var _maq = _maq || []; _maq.push(['search', ".$search." ]); </script>"; } else { return ''; } }
@param $view | Object ,\yii\web\View @param $search | string, 搜索数据信息,是一个json_encode的数组字符串 @param $products | array, 搜索页面的产品信息 搜索页面的trace信息。
getTraceSearchJsCode
php
fecshop/yii2_fecshop
services/page/Trace.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Trace.php
BSD-3-Clause
public function getTraceCategoryJsCode($view, $categoryM, $products) { // 加入事件event $metaAfterEventName = 'event_after_trace_category_js_code'; Yii::$service->event->trigger($metaAfterEventName, [ 'view' => $view, 'categoryM' => $categoryM, 'products' => $products, ]); $categoryName = Yii::$service->fecshoplang->getDefaultLangAttrVal($categoryM['name'], 'name'); if ($this->traceJsEnable && $categoryName) { return "<script type=\"text/javascript\"> var _maq = _maq || []; _maq.push(['category', '".$categoryName."']); </script>"; } else { return ''; } }
@param $view | Object ,\yii\web\View @param $categoryM | Object, 分类model @param $products | array, 分类页面的产品信息 分类页面的trace信息。
getTraceCategoryJsCode
php
fecshop/yii2_fecshop
services/page/Trace.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Trace.php
BSD-3-Clause
public function setLanguage($language) { Yii::$app->language = $language; }
Set current application's language. @param string $language the language to be set.
setLanguage
php
fecshop/yii2_fecshop
services/page/Translate.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Translate.php
BSD-3-Clause
public function register($view) { if ($this->basePath) { $view->assetManager->basePath = Yii::getAlias($this->basePath); } if ($this->baseUrl) { $view->assetManager->baseUrl = $this->baseUrl; } $view->assetManager->forceCopy = $this->forceCopy; $assetArr = []; // 模板路径优先级(由高到底) $themeDir = Yii::$service->page->theme->getThemeDirArr(); // 根据模板路径的优先级,初始化asset数组顺序,进而决定css的优先级 $assetThemeDirs = array_reverse($themeDir); // pushArr数组 $publishArr = []; foreach ($assetThemeDirs as $assetThemeDir) { $dir2 = $assetThemeDir.'/'.$this->defaultDir.'/'; $assetArr[$dir2] = []; if(is_dir($dir2)) { $publishDir = $view->assetManager->publish($dir2); $publishArr[$dir2] = $publishDir; } } $jsV = '?v='.$this->jsVersion; $cssV = '?v='.$this->cssVersion; // 根据模板的优先级,查找js和css文件 if (is_array($themeDir) && !empty($themeDir)) { if (is_array($this->jsOptions) && !empty($this->jsOptions)) { foreach ($this->jsOptions as $jsOption) { if (isset($jsOption['js']) && is_array($jsOption['js']) && !empty($jsOption['js'])) { foreach ($jsOption['js'] as $jsPath) { foreach ($themeDir as $dir) { $dir = $dir.'/'.$this->defaultDir.'/'; $jsAbsoluteDir = $dir.$jsPath; if (file_exists($jsAbsoluteDir)) { $publishDir = $publishArr[$dir]; $cOptions = isset($jsOption['options']) ? $this->initOptions($jsOption['options']) : null ; $view->registerJsFile($publishDir[1].'/'.$jsPath.$jsV, $cOptions); break; } } } } } } if (is_array($this->cssOptions) && !empty($this->cssOptions)) { foreach ($this->cssOptions as $cssOption) { if (isset($cssOption['css']) && is_array($cssOption['css']) && !empty($cssOption['css'])) { foreach ($cssOption['css'] as $cssPath) { foreach ($themeDir as $dir) { $dir = $dir.'/'.$this->defaultDir.'/'; $cssAbsoluteDir = $dir.$cssPath; if (file_exists($cssAbsoluteDir)) { $publishDir = $publishArr[$dir]; $cOptions = isset($cssOption['options']) ? $this->initOptions($cssOption['options']) : null; $view->registerCssFile($publishDir[1].'/'.$cssPath.$cssV, $cOptions); break; } } } } } } } /** * Registers a meta tag. 添加event,扩展可以通过event进行添加head meta信息等 * * For example, a description meta tag can be added like the following: * * ```php * $view->registerMetaTag([ * 'name' => 'description', * 'content' => 'This website is about funny raccoons.' * ]); * ``` * will result in the meta tag `<meta name="description" content="This website is about funny raccoons.">`. */ $metaAfterEventName = 'event_after_head_meta_config'; Yii::$service->event->trigger($metaAfterEventName, $view); /** * Registers a link tag. 添加event,扩展可以通过event进行添加head link信息等 * * For example, a link tag for a custom [favicon](http://www.w3.org/2005/10/howto-favicon) * can be added like the following: * * ```php * $view->registerLinkTag(['rel' => 'icon', 'type' => 'image/png', 'href' => '/myicon.png']); * ``` * * which will result in the following HTML: `<link rel="icon" type="image/png" href="/myicon.png">`. */ $linkAfterEventName = 'event_after_head_link_config'; Yii::$service->event->trigger($linkAfterEventName, $view); }
文件路径默认放到模板路径下面的assets里面.
register
php
fecshop/yii2_fecshop
services/page/Asset.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Asset.php
BSD-3-Clause
public function changeToMongoStorage() { $this->storage = 'ReviewMongodb'; $currentService = $this->getStorageService($this); $this->_newsletter = new $currentService(); }
动态更改为mongodb model
changeToMongoStorage
php
fecshop/yii2_fecshop
services/page/Newsletter.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Newsletter.php
BSD-3-Clause
public function changeToMysqlStorage() { $this->storage = 'ReviewMysqldb'; $currentService = $this->getStorageService($this); $this->_newsletter = new $currentService(); }
动态更改为mongodb model
changeToMysqlStorage
php
fecshop/yii2_fecshop
services/page/Newsletter.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Newsletter.php
BSD-3-Clause
public function getSubscriptionList($filter) { return $this->_newsletter->getSubscriptionList($filter); }
@param $filter|array get subscription email collection
getSubscriptionList
php
fecshop/yii2_fecshop
services/page/Newsletter.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Newsletter.php
BSD-3-Clause
public function addCorrect($message) { if (empty($message)) { return; } if (is_string($message)) { $message = [$message]; } $correct = $this->getCorrects(); if (is_array($correct) && is_array($message)) { $message = array_merge($correct, $message); } return Yii::$service->session->setFlash($this->_correctName, $message); }
@param $message | String 增加 correct message. 添加一些操作成功的提示信息,譬如产品加入购物车成功
addCorrect
php
fecshop/yii2_fecshop
services/page/Message.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Message.php
BSD-3-Clause
public function addError($message) { if (empty($message)) { return; } if (is_string($message)) { $message = [$message]; } $error = $this->getErrors(); if (is_array($error) && is_array($message)) { $message = array_merge($error, $message); } if (is_array($message)) { $message = implode(',', $message); } return Yii::$service->session->setFlash($this->_errorName, $message); }
@param $message | String 增加 error message.
addError
php
fecshop/yii2_fecshop
services/page/Message.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Message.php
BSD-3-Clause
public function getCorrects() { $corrects = Yii::$service->session->getFlash($this->_correctName); if ($corrects && !is_array($corrects)) { return [$corrects]; } else { return $corrects; } }
获取 correct message. @return array
getCorrects
php
fecshop/yii2_fecshop
services/page/Message.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Message.php
BSD-3-Clause
public function getErrors() { $errors = Yii::$service->session->getFlash($this->_errorName); if ($errors && !is_array($errors)) { return [$errors]; } else { return $errors; } }
获取 error message. @return array
getErrors
php
fecshop/yii2_fecshop
services/page/Message.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Message.php
BSD-3-Clause
public function getMenuData() { $this->_homeUrl = CUrl::getHomeUrl(); $arr = []; if ($displayHome = $this->displayHome) { $enable = isset($displayHome['enable']) ? $displayHome['enable'] : ''; $display = isset($displayHome['display']) ? $displayHome['display'] : ''; if ($enable && $display) { $arr[] = [ 'name' => Yii::$service->page->translate->__($display), 'url' => Yii::$service->url->homeUrl(), ]; } } $first_custom_menu = $this->customMenuInit($this->frontCustomMenu); if (is_array($first_custom_menu) && !empty($first_custom_menu)) { foreach ($first_custom_menu as $m) { $arr[] = $m; } } $categoryMenuArr = $this->getProductCategoryMenu(); //var_dump($categoryMenuArr); if (is_array($categoryMenuArr) && !empty($categoryMenuArr)) { foreach ($categoryMenuArr as $a) { $arr[] = $a; } } $behind_custom_menu = $this->customMenuInit($this->behindCustomMenu); if (is_array($behind_custom_menu) && !empty($behind_custom_menu)) { foreach ($behind_custom_menu as $m) { $arr[] = $m; } } return $arr; }
return menu array data, contains: home,frontCustomMenu,productCategory,behindCustomMenu. 得到网站的分类导航栏菜单。
getMenuData
php
fecshop/yii2_fecshop
services/page/Menu.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Menu.php
BSD-3-Clause
protected function getProductCategoryMenu() { return Yii::$service->category->menu->getCategoryMenuArr(); }
get product category array as menu.
getProductCategoryMenu
php
fecshop/yii2_fecshop
services/page/Menu.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Menu.php
BSD-3-Clause
public function render($configKey, $parentThis = '') { $config = ''; if (is_array($configKey)) { $config = $configKey; $configKey = ''; } else if ($configKey){ $configArr = explode('/', $configKey); if (count($configArr) < 2 ) { throw new InvalidValueException(" config key: '$configKey', format: `xxxx/xxxx`, you must config it with correct format"); } if (isset($this->widgetConfig[$configArr[0]][$configArr[1]])) { $config = $this->widgetConfig[$configArr[0]][$configArr[1]]; } else { throw new InvalidValueException(" config key: '$configKey', can not find in ".'Yii::$service->page->widget->widgetConfig'.', you must config it before use it.'); } } return $this->renderContent($configKey, $config, $parentThis); }
@param configKey String or Array 如果传递的是一个配置数组,内容格式如下: [ # class 选填 'class' => 'fec\block\TestMenu', # view 为 必填 , view可以用两种方式 # view 1 使用绝对地址的方式 'view' => '@fec/views/testmenu/index.php', OR # view 2 使用相对地址,通过当前模板进行查找 'view' => 'cms/home/index.php', # 下面为选填 'method'=> 'getLastData', 'terry1'=> 'My1', 'terry2'=> 'My2', ] 如果传递的是字符串,那么会去配置($widgetConfig)中查找,譬如 category/filter_price ,对应 $widgetConfig['category']['filter_price'] 的配置 最后找到后,通过renderContent函数,得到html 该功能大致为通过一个动态数据提供者block,和内容显示部分view,view里面需要使用的动态变量 由block提供,最终生成一个html区块,返回。 @param $parentThis 外部传递的数组变量,作为变量,可以在view中直接使用
render
php
fecshop/yii2_fecshop
services/page/Widget.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Widget.php
BSD-3-Clause
public function diRender($configKey, $diConfig = []) { if (!is_array($diConfig)) { throw new InvalidValueException(" configParent: '$diConfig' must be array"); } $config = ''; if (is_array($configKey)) { $config = $configKey; $configKey = ''; } else if ($configKey){ $configArr = explode('/', $configKey); if (count($configArr) < 2 ) { throw new InvalidValueException(" config key: '$configKey', format: `xxxx/xxxx`, you must config it with correct format"); } if (isset($this->widgetConfig[$configArr[0]][$configArr[1]])) { $config = $this->widgetConfig[$configArr[0]][$configArr[1]]; } else { throw new InvalidValueException(" config key: '$configKey', can not find in ".'Yii::$service->page->widget->widgetConfig'.', you must config it before use it.'); } } if (!isset($config['class']) || !$config['class']) { throw new InvalidConfigException('in widget ['.$configKey.'],you enable cache ,you must config widget class .'); } foreach ($diConfig as $k=>$v) { $config [$k] = $v; } return $this->renderContent($configKey, $config); }
@param configKey String or Array 如果传递的是一个配置数组,内容格式如下: [ # class 选填 'class' => 'fec\block\TestMenu', # view 为 必填 , view可以用两种方式 # view 1 使用绝对地址的方式 'view' => '@fec/views/testmenu/index.php', OR # view 2 使用相对地址,通过当前模板进行查找 'view' => 'cms/home/index.php', # 下面为选填 'method'=> 'getLastData', 'terry1'=> 'My1', 'terry2'=> 'My2', ] 如果传递的是字符串,那么会去配置($widgetConfig)中查找,譬如 category/filter_price ,对应 $widgetConfig['category']['filter_price'] 的配置 最后找到后,通过renderContent函数,得到html 该功能大致为通过一个动态数据提供者block,和内容显示部分view,view里面需要使用的动态变量 由block提供,最终生成一个html区块,返回。 @param $diConfig | array 数组变量,会注入$configKey中class对应的类变量
diRender
php
fecshop/yii2_fecshop
services/page/Widget.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Widget.php
BSD-3-Clause
public function renderContentHtml($configKey, $config, $parentThis = '') { if (!isset($config['view']) || empty($config['view']) ) { throw new InvalidConfigException('view and class must exist in array config!'); } $params = []; $view = $config['view']; unset($config['view']); $viewFile = $this->getViewFile($view); if (!isset($config['class']) || empty($config['class'])) { if ($parentThis) { $params['parentThis'] = $parentThis; } return Yii::$app->view->renderFile($viewFile, $params); } if (isset($config['method']) && !empty($config['method'])) { $method = $config['method']; unset($config['method']); } else { $method = $this->defaultObMethod; } $ob = Yii::createObject($config); $params = $ob->$method(); if ($parentThis) { $params['parentThis'] = $parentThis; } return Yii::$app->view->renderFile($viewFile, $params); }
@param $configKey | string ,使用配置中的widget,该参数对应相应的数组key @param $config,就是上面actionRender()方法中的参数,格式一样。 @param $parentThis | array or '' , 调用层传递的参数数组,可以在view中调用。
renderContentHtml
php
fecshop/yii2_fecshop
services/page/Widget.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Widget.php
BSD-3-Clause
public function renderContent($configKey, $config, $parentThis = '') { // 从配置中读取cache的enable状态 $cacheEnable = false; $cacheConfigKey = isset($this->_cache_arr[$configKey]) ? $this->_cache_arr[$configKey] : null; $appName = Yii::$service->helper->getAppName(); $cacheConfig = Yii::$app->store->get($appName.'_cache'); if ($cacheConfigKey && isset($cacheConfig[$cacheConfigKey]) && $cacheConfig[$cacheConfigKey] == Yii::$app->store->enable) { $cacheEnable = true; } if ($cacheEnable) { if (!isset($config['class']) || !$config['class']) { throw new InvalidConfigException('in widget ['.$configKey.'],you enable cache ,you must config widget class .'); } elseif ($ob = new $config['class']()) { if ($ob instanceof BlockCache) { $cacheKey = $ob->getCacheKey(); if (!($content = Yii::$app->cache->get($cacheKey))) { $cache = $config['cache']; $timeout = isset($cache['timeout']) ? $cache['timeout'] : 0; unset($config['cache']); $content = $this->renderContentHtml($configKey, $config, $parentThis); Yii::$app->cache->set($cacheKey, $content, $timeout); } return $content; } else { throw new InvalidConfigException($config['class'].' must implete fecshop\interfaces\block\BlockCache when you use block cache .'); } } } // 查看 $config['class'] 是否在YiiRewriteMap重写中存在配置,如果存在,则替换 !isset($config['class']) || $config['class'] = Yii::mapGetClassName($config['class']); $content = $this->renderContentHtml($configKey, $config, $parentThis); return $content; }
@param $configKey | string , 标记,以及报错排查时使用的key。 @param $config,就是上面actionRender()方法中的参数,格式一样。 @param $parentThis | array or '' , 调用层传递的参数数组,可以在view中调用。
renderContent
php
fecshop/yii2_fecshop
services/page/Widget.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Widget.php
BSD-3-Clause
protected function getViewFile($view, $throwError = true) { $view = trim($view); if (substr($view, 0, 1) == '@') { return Yii::getAlias($view); } $absoluteDir = Yii::$service->page->theme->getThemeDirArr(); foreach ($absoluteDir as $dir) { if ($dir) { $file = $dir.'/'.$view; if (file_exists($file)) { return $file; } } } // not find view file if ($throwError) { $notExistFile = []; foreach ($absoluteDir as $dir) { if ($dir) { $file = $dir.'/'.$view; $notExistFile[] = $file; } } throw new InvalidValueException('view file is not exist in'.implode(',', $notExistFile)); } else { return false; } }
find theme file by mutil theme ,if not find view file and $throwError=true, it will throw InvalidValueException.
getViewFile
php
fecshop/yii2_fecshop
services/page/Widget.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Widget.php
BSD-3-Clause
public function setDashboardBaseI() { $this->setBaseI(10000); }
用于登陆后台的dashboard页面的几个趋势图,的初始化。
setDashboardBaseI
php
fecshop/yii2_fecshop
services/helper/Echart.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Echart.php
BSD-3-Clause
public function getPie($data, $isShow=true, $width=1200, $height=600, $title='') { $this->i++; $div_id = "main_".$this->i; $legendArr = []; $showArr = []; $seriesArr = []; $legendStr = ''; $showStr = ''; $seriesStr = []; $isShow = $isShow ? 'true' : 'false'; if (is_array($data)) { foreach ($data as $one) { $name = $one['name']; $val = $one['value']; $legendArr[] = '\''.$name.'\''; $showArr[] = '\''.$name.'\':'.$isShow; $seriesArr[] = '{\'name\':\''.$name.'\',\'value\':\''.$val.'\'}'; } } $legendStr = implode(',', $legendArr); $showStr = implode(',', $showArr); $seriesStr = implode(',', $seriesArr); $str = " <div class='echart_line_containter' id='".$div_id."' style='width:".$width."px;height:".$height."px;'></div> <script type=\"text/javascript\"> $(document).ready(function(){ var myChart".$div_id." = echarts.init(document.getElementById('".$div_id."')); var option = { title: { text: '".$title."', subtext: '', left: 'center' }, tooltip: { trigger: 'item', formatter: '{a} <br/>{b} : {c} ({d}%)' }, legend: { type: 'scroll', orient: 'vertical', left: 10, top: 20, bottom: 20, data: [".$legendStr."], selected: {".$showStr."} }, series: [ { name: '姓名', type: 'pie', radius: '55%', center: ['50%', '50%'], data: [".$seriesStr."], emphasis: { itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' } } } ] }; myChart".$div_id.".setOption(option); }); </script> "; return $str; }
@param $data | array,example [ ['name'=> '张三', 'value'=>'12'], ['name'=> 'li三', 'value'=>'1'] ['name'=> 'wang五', 'value'=>'62'] ] @param $width | int, 饼图长度 @param $height | int, 饼图高度 @param $title | string, 标题 通过该数组,快速的返回echart的饼图,将函数返回的值,直接输出即可显示饼图
getPie
php
fecshop/yii2_fecshop
services/helper/Echart.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Echart.php
BSD-3-Clause
public function initParam($init_begin_before_days='', $date_interval='', $maxEndDateLimit='', $processTimeout='') { if ($init_begin_before_days) { $this->init_begin_before_days = $init_begin_before_days; } if ($date_interval) { $this->date_interval = $date_interval; } if ($maxEndDateLimit) { $this->maxEndDateLimit = $maxEndDateLimit; } if ($processTimeout) { $this->processTimeout = $processTimeout; } }
如果不使用默认值,可以通过该函数设置默认值 @param $init_begin_before_days | int, 第一次执行脚本,默认的数据开始时间 @param $date_interval | int, 如果没有传递参数,则使用默认的时间间隔,默认一个小时的间隔, beginAt和endAt @param $maxEndDateLimit , 脚本结束时间,最大不能离当前时间多少s, 也就是说 脚本的end_at <= time() - $this->maxEndDateLimit, 如果超过这个值,那么强制让 end_at = time() - $this->maxEndDateLimit @param $processTimeout, 脚本运行的超时时间,让超过3600,将会强制初始化数据,重新执行。
initParam
php
fecshop/yii2_fecshop
services/helper/ScriptDate.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ScriptDate.php
BSD-3-Clause
public function save($one) { $primaryVal = isset($one[$this->getPrimaryKey()]) ? $one[$this->getPrimaryKey()] : ''; if ($primaryVal) { $model = $this->_model->findOne($primaryVal); if (!$model) { Yii::$service->helper->errors->add('scriptDate {primaryKey} is not exist', ['primaryKey' => $this->getPrimaryKey()]); return; } } else { $model = new $this->_modelName(); $model->created_at = time(); } $model->updated_at = time(); $primaryKey = $this->getPrimaryKey(); $model = Yii::$service->helper->ar->save($model, $one); $primaryVal = $model[$primaryKey]; return true; }
@param $one|array save $data to cms model,then,add url rewrite info to system service urlrewrite.
save
php
fecshop/yii2_fecshop
services/helper/ScriptDate.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ScriptDate.php
BSD-3-Clause
public function updateScriptErrorInfo($scriptTypeName, $error_info) { if (!$error_info) { return true; } $model = $this->_model->findOne([ 'status' => $this->status_processing, 'type' => $scriptTypeName, ]); if (!$model['status']) { return false; } if (is_array($error_info)) { $error_info = implode(',', $error_info); } if ($model['error_info'] != '') { $error_info = $model['error_info'] . ' | ' . $error_info; } $model['error_info'] = $error_info; $model['script_updated_at'] = time(); $model->save(); return true; }
@param $scriptTypeName | string @param $error_info | string or array 更新脚本的错误信息
updateScriptErrorInfo
php
fecshop/yii2_fecshop
services/helper/ScriptDate.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ScriptDate.php
BSD-3-Clause
public function getProcessBeginAndEndAt($scriptTypeName) { $model = $this->_model->findOne([ 'status' => $this->status_processing, 'type' => $scriptTypeName, ]); if ($model['begin_at'] && $model['end_at']) { return [$model['begin_at'], $model['end_at']]; } return null; }
得到正在进行的脚本,开始执行时间和结束执行时间。 @param $scriptTypeName | sring, 您的脚本类型名称
getProcessBeginAndEndAt
php
fecshop/yii2_fecshop
services/helper/ScriptDate.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ScriptDate.php
BSD-3-Clause
public function processScript($scriptTypeName) { $updateComules = $this->_model->updateAll( [ 'status' => $this->status_processing, 'script_updated_at' => time(), ], [ 'type' => $scriptTypeName, 'status' => $this->status_init, ] ); if (empty($updateComules)) { Yii::$service->helper->errors->add('process script begin fail'); return false; } return true; }
2.开始执行脚本 @param $scriptTypeName | sring, 您的脚本类型名称
processScript
php
fecshop/yii2_fecshop
services/helper/ScriptDate.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ScriptDate.php
BSD-3-Clause
public function completeScript($scriptTypeName) { $updateComules = $this->_model->updateAll( [ 'status' => $this->status_complete, 'script_updated_at' => time(), ], [ 'type' => $scriptTypeName, 'status' => $this->status_processing, 'error_info' => null, // 如果分页执行过程中存在报错,则不能complete ] ); if (empty($updateComules)) { Yii::$service->helper->errors->add('complete script fail'); return false; } return true; }
3.完成脚本
completeScript
php
fecshop/yii2_fecshop
services/helper/ScriptDate.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ScriptDate.php
BSD-3-Clause
public function initScript($scriptTypeName) { $model = $this->_model->findOne(['type' => $scriptTypeName]); $beginAt = ''; if ($model) { // if ($model['status'] == $this->status_complete ) { // 判断当前的记录是否是完成状态?上个脚本是否已经完成 $beginAt = $model['end_at']; } else if ($model['script_updated_at'] - $model['script_created_at'] > $this->processTimeout ) { // 当脚本执行了xx时间,还是没有执行完成,则会强制init $model->script_created_at = time(); $model->script_updated_at = time(); $model->status = $this->status_init; $model->error_info = NULL; return $model->save(); } else { // 此种情况,代表脚本已经初始化,或者脚本正在进行中 // 更新 script_updated_at $model->script_updated_at = time(); $model->save(); return false; } } else { $model = new $this->_modelName(); $model->created_at = time(); } list($beginAt, $endAt) = $this->getBeginAndEndDateTime($beginAt); $model->script_created_at = time(); $model->script_updated_at = time(); $model->type = $scriptTypeName; $model->status = $this->status_init; $model->begin_at = $beginAt; $model->end_at = $endAt; $model->error_info = NULL; return $model->save(); }
1.初始化脚本信息 @param $scriptTypeName | sring, 您的脚本类型名称 获取脚本的开始和数据时间 本service的主要作用,是某些同步数据脚本,根据时间来进行同步数据,当脚本结束后,下一个脚本以上次脚本 的结束时间作为下次脚本执行的开始时间。
initScript
php
fecshop/yii2_fecshop
services/helper/ScriptDate.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ScriptDate.php
BSD-3-Clause
protected function getBeginAndEndDateTime($beginAt='') { if (!$beginAt) { $beginAt = strtotime(' -'.$this->init_begin_before_days.' days' ); } $beginAt = $this->correctDateTime($beginAt); $endAt = $beginAt + $this->date_interval; $endAt = $this->correctDateTime($endAt); return [$beginAt, $endAt]; }
@param $beginAt | int, 开始时间戳 得到脚本的开始和结束时间
getBeginAndEndDateTime
php
fecshop/yii2_fecshop
services/helper/ScriptDate.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ScriptDate.php
BSD-3-Clause
public function init() { parent::init(); $this->font = dirname(__FILE__).'/captcha/Elephant.ttf'; //注意字体路径要写对,否则显示不了图片 }
构造方法初始化
init
php
fecshop/yii2_fecshop
services/helper/Captcha.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Captcha.php
BSD-3-Clause
private function createCode() { $_len = strlen($this->charset) - 1; for ($i = 0; $i < $this->codelen; $i++) { $this->code .= $this->charset[mt_rand(0, $_len)]; } }
生成随机码
createCode
php
fecshop/yii2_fecshop
services/helper/Captcha.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Captcha.php
BSD-3-Clause
private function createBg() { $this->img = imagecreatetruecolor($this->width, $this->height); $color = imagecolorallocate($this->img, mt_rand(157, 255), mt_rand(157, 255), mt_rand(157, 255)); imagefilledrectangle($this->img, 0, $this->height, $this->width, 0, $color); }
生成背景
createBg
php
fecshop/yii2_fecshop
services/helper/Captcha.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Captcha.php
BSD-3-Clause
private function createFont() { $_x = $this->width / $this->codelen; for ($i = 0; $i < $this->codelen; $i++) { if (!$this->fontcolor) { $fontcolor = imagecolorallocate($this->img, mt_rand(0, 156), mt_rand(0, 156), mt_rand(0, 156)); } else { $fontcolor = $this->fontcolor; } imagettftext($this->img, $this->fontsize, mt_rand(-30, 30), $_x * $i + mt_rand(1, 5), $this->height / 1.4, $fontcolor, $this->font, $this->code[$i]); } }
生成文字
createFont
php
fecshop/yii2_fecshop
services/helper/Captcha.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Captcha.php
BSD-3-Clause
private function createLine() { //线条 for ($i = 0; $i < 6; $i++) { $color = imagecolorallocate($this->img, mt_rand(0, 156), mt_rand(0, 156), mt_rand(0, 156)); imageline($this->img, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $color); } //雪花 for ($i = 0; $i < 100; $i++) { $color = imagecolorallocate($this->img, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255)); imagestring($this->img, mt_rand(1, 5), mt_rand(0, $this->width), mt_rand(0, $this->height), '*', $color); } }
生成线条、雪花
createLine
php
fecshop/yii2_fecshop
services/helper/Captcha.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Captcha.php
BSD-3-Clause
private function outPut() { header('Content-type:image/jpg'); imagepng($this->img); imagedestroy($this->img); }
输出
outPut
php
fecshop/yii2_fecshop
services/helper/Captcha.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Captcha.php
BSD-3-Clause
public function doBase64img() { $this->createBg(); $this->createCode(); $this->createLine(); $this->createFont(); ob_start(); imagepng($this->img); imagedestroy($this->img); $fileContent = ob_get_contents(); ob_end_clean(); $this->setSessionCode(); return base64_encode($fileContent); }
对外生成
doBase64img
php
fecshop/yii2_fecshop
services/helper/Captcha.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Captcha.php
BSD-3-Clause
public function doimg() { $this->createBg(); $this->createCode(); $this->createLine(); $this->createFont(); $this->setSessionCode(); session_commit(); $this->outPut(); }
对外生成
doimg
php
fecshop/yii2_fecshop
services/helper/Captcha.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Captcha.php
BSD-3-Clause
public function getCode($code) { if (!$this->case_sensitive) { return strtolower($code); } else { return $this->code; } }
获取验证码
getCode
php
fecshop/yii2_fecshop
services/helper/Captcha.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Captcha.php
BSD-3-Clause
public function getResponseData($code, $data, $message = '') { if (!$message) { $message = $this->getMessageByCode($code); } if ($message) { return [ 'code' => $code, 'message' => $message, 'data' => $data, ]; } else { // 如果不存在,则说明系统内部调用不存在的code,报错。 $code = $this->status_invalid_code; $message = $this->getMessageByCode($code); return [ 'code' => $code, 'message' => $message, 'data' => '', ]; } }
@param $code | String 状态码 @param $data | 混合状态,可以是数字,数组等格式,用于做返回给前端的数组。 @param $message | String ,选填,如果不填写,则使用 函数 返回的内容作为message
getResponseData
php
fecshop/yii2_fecshop
services/helper/Appapi.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Appapi.php
BSD-3-Clause
public function getMessageByCode($code) { $messageArr = $this->getMessageArr(); return isset($messageArr[$code]['message']) ? $messageArr[$code]['message'] : ''; }
@param $code | String ,状态码 得到 code 对应 message的数组
getMessageByCode
php
fecshop/yii2_fecshop
services/helper/Appapi.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Appapi.php
BSD-3-Clause
public function getMessageArr() { $arr = [ /** * 公共状态码 */ $this->status_success => [ 'message' => 'process success', ], $this->status_unknown => [ 'message' => 'unknown errors', ], $this->status_mysql_disconnect => [ 'message' => 'mysql connect timeout', ], $this->status_mongodb_disconnect => [ 'message' => 'mongodb connect timeout', ], $this->status_redis_disconnect => [ 'message' => 'redis connect timeout', ], $this->status_invalid_token => [ 'message' => 'token is timeout or invalid', ], $this->status_invalid_request_url => [ 'message' => 'the request url is not exist', ], $this->status_invalid_email => [ 'message' => 'email format is not correct', ], $this->status_invalid_captcha => [ 'message' => 'captcha is not correct', ], $this->status_invalid_param => [ 'message' => 'incorrect request parameter', ], $this->status_invalid_code => [ 'message' => 'system error, invalid code', ], $this->status_miss_param => [ 'message' => 'required parameter does not exist', ], $this->status_limit_beyond => [ 'message' => 'beyond maximum limit', ], $this->status_data_repeat => [ 'message' => 'insert data is repeat', ], $this->status_attack => [ 'message' => 'access exception, the visit to determine the attack behavior', ], /** * 用户部分的状态码 */ $this->account_no_login_or_login_token_timeout => [ 'message' => 'account not login or token timeout', ], ]; return $arr; }
得到 code 对应 message的数组
getMessageArr
php
fecshop/yii2_fecshop
services/helper/Appapi.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Appapi.php
BSD-3-Clause
public function getCors(){ $cors_allow_headers = $this->getCorsAllowHeaders(); $cors = $this->appserver_cors; $corsFilterArr = []; if (is_array($cors) && !empty($cors)) { if (isset($cors['Origin']) && $cors['Origin']) { $corsFilterArr['Origin'] = $cors['Origin']; } if (isset($cors['Access-Control-Request-Method']) && $cors['Access-Control-Request-Method']) { $corsFilterArr['Access-Control-Request-Method'] = $cors['Access-Control-Request-Method']; } if (isset($cors['Access-Control-Max-Age']) && $cors['Access-Control-Max-Age']) { $corsFilterArr['Access-Control-Max-Age'] = $cors['Access-Control-Max-Age']; } if (isset($cors['Access-Control-Allow-Headers']) && is_array($cors['Access-Control-Allow-Headers'])) { $cors_allow_headers = array_merge($cors_allow_headers, $cors['Access-Control-Allow-Headers']); $corsFilterArr['Access-Control-Request-Headers'] = $cors_allow_headers; $corsFilterArr['Access-Control-Expose-Headers'] = $cors_allow_headers; } $corsFilterArr['Access-Control-Allow-Credentials'] = true; } return $corsFilterArr; }
用于vue端跨域访问的cors设置 @return array
getCors
php
fecshop/yii2_fecshop
services/helper/Appserver.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Appserver.php
BSD-3-Clause
public function getYiiAuthCors(){ $cors_allow_headers = $this->getCorsAllowHeaders(); $cors = $this->appserver_cors; $corsFilterArr = []; if (is_array($cors) && !empty($cors)) { if (isset($cors['Origin']) && $cors['Origin']) { $corsFilterArr[] = 'Access-Control-Allow-Origin: ' . implode(', ', $cors['Origin']); } if (isset($cors['Access-Control-Allow-Headers']) && is_array($cors['Access-Control-Allow-Headers'])) { $cors_allow_headers = array_merge($cors_allow_headers, $cors['Access-Control-Allow-Headers']); } $corsFilterArr[] = 'Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, ' . implode(', ', $cors_allow_headers); if (isset($cors['Access-Control-Allow-Methods']) && is_array($cors['Access-Control-Allow-Methods'])) { $corsFilterArr[] = 'Access-Control-Allow-Methods: ' . implode(', ',$cors['Access-Control-Allow-Methods']); } $corsFilterArr[] = 'Access-Control-Allow-Credentials: true'; } return $corsFilterArr; }
用于vue端跨域访问的 customer token auth 的 cors设置 @return array
getYiiAuthCors
php
fecshop/yii2_fecshop
services/helper/Appserver.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Appserver.php
BSD-3-Clause
public function getResponseData($code, $data, $message = '') { if (!$message) { $message = $this->getMessageByCode($code); } if ($message) { return [ 'code' => $code, 'message' => $message, 'data' => $data, ]; } else { // 如果不存在,则说明系统内部调用不存在的 code,报错。 $code = $this->status_invalid_code; $message = $this->getMessageByCode($code); return [ 'code' => $code, 'message' => $message, 'data' => '', ]; } }
@param int $code 状态码 @param mixed $data 可以是数字,数组等格式,用于做返回给前端的数组。 @param string $message 选填,如果不填写,则使用函数返回的内容作为 message @return array
getResponseData
php
fecshop/yii2_fecshop
services/helper/Appserver.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Appserver.php
BSD-3-Clause
public function getMessageByCode($code) { $messageArr = $this->getMessageArr(); return isset($messageArr[$code]['message']) ? $messageArr[$code]['message'] : ''; }
得到 code 对应 message @param int $code 状态码 @return string|array
getMessageByCode
php
fecshop/yii2_fecshop
services/helper/Appserver.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Appserver.php
BSD-3-Clause
public function getMessageArr() { $arr = [ /** * 公共状态码 */ $this->status_success => [ 'message' => 'process success', ], $this->status_unknown => [ 'message' => 'unknown errors', ], $this->status_mysql_disconnect => [ 'message' => 'mysql connect timeout', ], $this->status_mongodb_disconnect => [ 'message' => 'mongodb connect timeout', ], $this->status_redis_disconnect => [ 'message' => 'redis connect timeout', ], $this->status_invalid_token => [ 'message' => 'token is timeout or invalid', ], $this->status_invalid_request_url => [ 'message' => 'the request url is not exist', ], $this->status_invalid_email => [ 'message' => 'email format is not correct', ], $this->status_invalid_captcha => [ 'message' => 'captcha is not correct', ], $this->status_invalid_param => [ 'message' => 'incorrect request parameter', ], $this->status_invalid_code => [ 'message' => 'system error, invalid code', ], $this->status_miss_param => [ 'message' => 'required parameter does not exist', ], $this->status_limit_beyond => [ 'message' => 'beyond maximum limit', ], $this->status_data_repeat => [ 'message' => 'insert data is repeat', ], $this->status_attack => [ 'message' => 'access exception, the visit to determine the attack behavior', ], /** * 用户部分的状态码 */ $this->account_no_login_or_login_token_timeout => [ 'message' => 'account not login or token timeout', ], $this->account_register_email_exist => [ 'message' => 'account register email is exist', ], $this->account_register_invalid_data => [ 'message' => 'account register data is invalid', ], $this->account_login_invalid_email_or_password => [ 'message' => 'account login email or password is not correct', ], $this->account_edit_invalid_data => [ 'message' => 'account edit data is invalid', ], $this->account_contact_us_send_email_fail => [ 'message' => 'customer contact us send email fail', ], $this->account_is_logined => [ 'message' => 'account is logined', ], $this->account_register_fail => [ 'message' => 'account register fail', ], $this->account_email_not_exist => [ 'message' => 'account email not exist', ], $this->account_forget_password_token_timeout => [ 'message' => 'account forget password token timeout', ], $this->account_forget_password_reset_param_invalid => [ 'message' => 'account forget password reset param invalid', ], $this->account_forget_password_reset_fail => [ 'message' => 'account forget password reset fail', ], $this->account_address_is_not_exist => [ 'message' => 'account address id is not exist', ], $this->account_address_save_fail => [ 'message' => 'account address save fail', ], $this->account_register_disable => [ 'message' => 'account register is disable', ], $this->account_register_resend_email_success => [ 'message' => 'account register resend email success', ], $this->account_register_send_email_fail => [ 'message' => 'account_register_send_email_fail', ], $this->account_register_enable_token_invalid => [ 'message' => 'account_register_enable_token_invalid', ], $this->account_wx_get_user_info_fail => [ 'message' => 'use wxCode to get user info fail', ], $this->account_wx_user_login_fail => [ 'message' => 'wx user login account fail', ], $this->account_wx_get_customer_by_openid_fail => [ 'message' => 'you should bind wx openid with one account', ], $this->no_account_openid_and_session_key => [ 'message' => 'no_account_openid_and_session_key', ], $this->account_has_account_openid => [ 'message' => 'account_has_account_openid', ], $this->account_login_and_get_access_token_fail => [ 'message' => 'account_login_and_get_access_token_fail', ], $this->account_register_email_exit => [ 'message' => 'account_register_email_exit', ], $this->account_address_set_default_fail => [ 'message' => 'account_address_set_default_fail', ], $this->account_address_edit_param_invaild => [ 'message' => 'account address edit param is invalid', ], $this->account_reorder_order_id_invalid => [ 'message' => 'customer reorder order id is invalid', ], $this->account_favorite_id_not_exist => [ 'message' => 'customer favorite id is not exit', ], $this->account_facebook_login_error => [ 'message' => 'login F-E-C-shop with facebook account error', ], $this->account_google_login_error => [ 'message' => 'login F-e-c-shop with google account error', ], /** * category */ $this->category_not_exist => [ 'message' => 'category is not exist', ], /** * product */ $this->product_favorite_fail => [ 'message' => 'product favorite fail', ], $this->product_not_active => [ 'message' => 'product is not exist or off the shelf', ], $this->product_id_not_exist => [ 'message' => 'product id is not exist', ], $this->product_save_review_fail => [ 'message' => 'save product review fail', ], /** * Cart */ $this->cart_product_add_fail => [ 'message' => 'product add to cart fail', ], $this->cart_product_add_param_invaild => [ 'message' => 'product add to cart request param is invalid', ], $this->cart_product_update_qty_fail => [ 'message' => 'update cart product qty fail', ], $this->cart_coupon_invalid => [ 'message' => 'coupon code is invalid', ], $this->cart_product_select_fail => [ 'message' => 'cart product select fail', ], /** * Order */ $this->order_generate_product_stock_out => [ 'message' => 'before generate order,check product stock out ', ], $this->order_generate_fail => [ 'message' => 'generate order fail', ], $this->order_paypal_express_get_token_fail => [ 'message' => 'order pay by paypal express api, fetch token fail', ], $this->order_generate_request_post_param_invaild => [ 'message' => 'require order request param is invaild', ], $this->order_generate_create_account_fail => [ 'message' => 'order generate page, guest create account fail', ], $this->order_generate_save_address_fail => [ 'message' => 'order generate page, login account save address fail', ], $this->order_generate_cart_product_empty => [ 'message' => 'order generate page, cart product is empty', ], $this->order_shipping_country_empty => [ 'message' => 'order checkout one page, get shipping fail, country is empty', ], $this->order_paypal_standard_get_token_fail => [ 'message' => 'order pay by paypal standard api, fetch token fail', ], $this->order_paypal_standard_payment_fail => [ 'message' => 'order pay by paypal standard api, payment fail', ], $this->order_paypal_standard_updateorderinfoafterpayment_fail => [ 'message' => 'order pay by paypal standard api, update order fail after payment', ], $this->order_not_find_increment_id_from_dbsession => [ 'message' => 'can not find order increment id from db session storage', ], $this->order_paypal_express_payment_fail => [ 'message' => 'order pay by paypal express api, payment fail', ], $this->order_paypal_express_updateorderinfoafterpayment_fail => [ 'message' => 'order pay by paypal express api, update order info fail', ], $this->order_paypal_express_get_PayerID_fail => [ 'message' => 'order pay by paypal express api, fetch PayerID fail', ], $this->order_paypal_express_get_apiAddress_fail => [ 'message' => 'order pay by paypal express api, fetch address fail', ], $this->order_has_been_paid => [ 'message' => 'order has bean paid', ], $this->order_not_exist => [ 'message' => 'order is not exist', ], $this->order_alipay_payment_fail => [ 'message' => 'order pay by alipay payment fail', ], $this->order_wxpay_payment_fail => [ 'message' => 'order pay by wxpay payment fail', ], /** * cms */ $this->cms_article_not_exist => [ 'message' => 'article is not exist', ], ]; return $arr; }
得到 code 对应 message的数组
getMessageArr
php
fecshop/yii2_fecshop
services/helper/Appserver.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Appserver.php
BSD-3-Clause
public function __construct( array $headers = null, $userAgent = null ) { $this->setHttpHeaders($headers); $this->setUserAgent($userAgent); }
Construct an instance of this class. @param array $headers Specify the headers as injection. Should be PHP _SERVER flavored. If left empty, will use the global _SERVER['HTTP_*'] vars instead. @param string $userAgent Inject the User-Agent header. If null, will use HTTP_USER_AGENT from the $headers array instead.
__construct
php
fecshop/yii2_fecshop
services/helper/MobileDetect.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/MobileDetect.php
BSD-3-Clause
public static function getScriptVersion() { return self::VERSION; }
Get the current script version. This is useful for the demo.php file, so people can check on what version they are testing for mobile devices. @return string The version number in semantic version format.
getScriptVersion
php
fecshop/yii2_fecshop
services/helper/MobileDetect.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/MobileDetect.php
BSD-3-Clause
public function setHttpHeaders($httpHeaders = null) { // use global _SERVER if $httpHeaders aren't defined if (!is_array($httpHeaders) || !count($httpHeaders)) { $httpHeaders = $_SERVER; } // clear existing headers $this->httpHeaders = []; // Only save HTTP headers. In PHP land, that means only _SERVER vars that // start with HTTP_. foreach ($httpHeaders as $key => $value) { if (substr($key, 0, 5) === 'HTTP_') { $this->httpHeaders[$key] = $value; } } }
Set the HTTP Headers. Must be PHP-flavored. This method will reset existing headers. @param array $httpHeaders The headers to set. If null, then using PHP's _SERVER to extract the headers. The default null is left for backwards compatibilty.
setHttpHeaders
php
fecshop/yii2_fecshop
services/helper/MobileDetect.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/MobileDetect.php
BSD-3-Clause
public function getHttpHeaders() { return $this->httpHeaders; }
Retrieves the HTTP headers. @return array
getHttpHeaders
php
fecshop/yii2_fecshop
services/helper/MobileDetect.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/MobileDetect.php
BSD-3-Clause
public function getHttpHeader($header) { // are we using PHP-flavored headers? if (strpos($header, '_') === false) { $header = str_replace('-', '_', $header); $header = strtoupper($header); } // test the alternate, too $altHeader = 'HTTP_' . $header; //Test both the regular and the HTTP_ prefix if (isset($this->httpHeaders[$header])) { return $this->httpHeaders[$header]; } elseif (isset($this->httpHeaders[$altHeader])) { return $this->httpHeaders[$altHeader]; } return null; }
Retrieves a particular header. If it doesn't exist, no exception/error is caused. Simply null is returned. @param string $header The name of the header to retrieve. Can be HTTP compliant such as "User-Agent" or "X-Device-User-Agent" or can be php-esque with the all-caps, HTTP_ prefixed, underscore seperated awesomeness. @return string|null The value of the header.
getHttpHeader
php
fecshop/yii2_fecshop
services/helper/MobileDetect.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/MobileDetect.php
BSD-3-Clause
public function getUaHttpHeaders() { return self::$uaHttpHeaders; }
Get all possible HTTP headers that can contain the User-Agent string. @return array List of HTTP headers.
getUaHttpHeaders
php
fecshop/yii2_fecshop
services/helper/MobileDetect.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/MobileDetect.php
BSD-3-Clause
public function setUserAgent($userAgent = null) { // Invalidate cache due to #375 $this->cache = []; if (false === empty($userAgent)) { return $this->userAgent = $userAgent; } else { $this->userAgent = null; foreach ($this->getUaHttpHeaders() as $altHeader) { if (false === empty($this->httpHeaders[$altHeader])) { // @todo: should use getHttpHeader(), but it would be slow. (Serban) $this->userAgent .= $this->httpHeaders[$altHeader] . ' '; } } return $this->userAgent = (!empty($this->userAgent) ? trim($this->userAgent) : null); } }
Set the User-Agent to be used. @param string $userAgent The user agent string to set. @return string|null
setUserAgent
php
fecshop/yii2_fecshop
services/helper/MobileDetect.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/MobileDetect.php
BSD-3-Clause