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 getUserAgent() { return $this->userAgent; }
Retrieve the User-Agent. @return string|null The user agent if it's set.
getUserAgent
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 setDetectionType($type = null) { if ($type === null) { $type = self::DETECTION_TYPE_MOBILE; } if ($type !== self::DETECTION_TYPE_MOBILE && $type !== self::DETECTION_TYPE_EXTENDED) { return; } $this->detectionType = $type; }
Set the detection type. Must be one of self::DETECTION_TYPE_MOBILE or self::DETECTION_TYPE_EXTENDED. Otherwise, nothing is set. @deprecated since version 2.6.9 @param string $type The type. Must be a self::DETECTION_TYPE_* constant. The default parameter is null which will default to self::DETECTION_TYPE_MOBILE.
setDetectionType
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 getPhoneDevices() { return self::$phoneDevices; }
Retrieve the list of known phone devices. @return array List of phone devices.
getPhoneDevices
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 getTabletDevices() { return self::$tabletDevices; }
Retrieve the list of known tablet devices. @return array List of tablet devices.
getTabletDevices
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 getUserAgents() { return self::getBrowsers(); }
Alias for getBrowsers() method. @return array List of user agents.
getUserAgents
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 getBrowsers() { return self::$browsers; }
Retrieve the list of known browsers. Specifically, the user agents. @return array List of browsers / user agents.
getBrowsers
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 getUtilities() { return self::$utilities; }
Retrieve the list of known utilities. @return array List of utilities.
getUtilities
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 getMobileDetectionRules() { static $rules; if (!$rules) { $rules = array_merge( self::$phoneDevices, self::$tabletDevices, self::$operatingSystems, self::$browsers ); } return $rules; }
Method gets the mobile detection rules. This method is used for the magic methods $detect->is*(). @deprecated since version 2.6.9 @return array All the rules (but not extended).
getMobileDetectionRules
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 getMobileDetectionRulesExtended() { static $rules; if (!$rules) { // Merge all rules together. $rules = array_merge( self::$phoneDevices, self::$tabletDevices, self::$operatingSystems, self::$browsers, self::$utilities ); } return $rules; }
Method gets the mobile detection rules + utilities. The reason this is separate is because utilities rules don't necessary imply mobile. This method is used inside the new $detect->is('stuff') method. @deprecated since version 2.6.9 @return array All the rules + extended.
getMobileDetectionRulesExtended
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 getRules() { if ($this->detectionType == self::DETECTION_TYPE_EXTENDED) { return self::getMobileDetectionRulesExtended(); } else { return self::getMobileDetectionRules(); } }
Retrieve the current set of rules. @deprecated since version 2.6.9 @return array
getRules
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 getOperatingSystems() { return self::$operatingSystems; }
Retrieve the list of mobile operating systems. @return array The list of mobile operating systems.
getOperatingSystems
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 checkHttpHeadersForMobile() { foreach ($this->getMobileHeaders() as $mobileHeader => $matchType) { if (isset($this->httpHeaders[$mobileHeader])) { if (is_array($matchType['matches'])) { foreach ($matchType['matches'] as $_match) { if (strpos($this->httpHeaders[$mobileHeader], $_match) !== false) { return true; } } return false; } else { return true; } } } return false; }
Check the HTTP headers for signs of mobile. This is the fastest mobile check possible; it's used inside isMobile() method. @return bool
checkHttpHeadersForMobile
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 __call($name, $arguments) { // make sure the name starts with 'is', otherwise if (substr($name, 0, 2) !== 'is') { throw new BadMethodCallException("No such method exists: $name"); } $this->setDetectionType(self::DETECTION_TYPE_MOBILE); $key = substr($name, 2); return $this->matchUAAgainstKey($key); }
Magic overloading method. @method bool is[...]() @param string $name @param array $arguments @throws BadMethodCallException when the method doesn't exist and doesn't start with 'is' @return mixed
__call
php
fecshop/yii2_fecshop
services/helper/MobileDetect.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/MobileDetect.php
BSD-3-Clause
protected function matchDetectionRulesAgainstUA($userAgent = null) { // Begin general search. foreach ($this->getRules() as $_regex) { if (empty($_regex)) { continue; } if ($this->match($_regex, $userAgent)) { return true; } } return false; }
Find a detection rule that matches the current User-agent. @param null $userAgent deprecated @return bool
matchDetectionRulesAgainstUA
php
fecshop/yii2_fecshop
services/helper/MobileDetect.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/MobileDetect.php
BSD-3-Clause
protected function matchUAAgainstKey($key) { // Make the keys lowercase so we can match: isIphone(), isiPhone(), isiphone(), etc. $key = strtolower($key); if (false === isset($this->cache[$key])) { // change the keys to lower case $_rules = array_change_key_case($this->getRules()); if (false === empty($_rules[$key])) { $this->cache[$key] = $this->match($_rules[$key]); } if (false === isset($this->cache[$key])) { $this->cache[$key] = false; } } return $this->cache[$key]; }
Search for a certain key in the rules array. If the key is found the try to match the corresponding regex against the User-Agent. @param string $key @return bool
matchUAAgainstKey
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 isMobile($userAgent = null, $httpHeaders = null) { if ($this->_is_mobile || $this->_is_mobile === false) { return $this->_is_mobile; } if ($httpHeaders) { $this->setHttpHeaders($httpHeaders); } if ($userAgent) { $this->setUserAgent($userAgent); } $this->setDetectionType(self::DETECTION_TYPE_MOBILE); if ($this->checkHttpHeadersForMobile()) { $this->_is_mobile = true; } else { $this->_is_mobile = $this->matchDetectionRulesAgainstUA(); } return $this->_is_mobile; }
Check if the device is mobile. Returns true if any type of mobile device detected, including special ones. @param null $userAgent deprecated @param null $httpHeaders deprecated @return bool
isMobile
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 isTablet($userAgent = null, $httpHeaders = null) { if ($this->is_tablet || $this->is_tablet === false) { return $this->is_tablet; } $this->setDetectionType(self::DETECTION_TYPE_MOBILE); foreach (self::$tabletDevices as $_regex) { if ($this->match($_regex, $userAgent)) { $this->is_tablet = true; } } $this->is_tablet = false; return $this->is_tablet; }
Check if the device is a tablet. Return true if any type of tablet device is detected. @param string $userAgent deprecated @param array $httpHeaders deprecated @return bool
isTablet
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 is($key, $userAgent = null, $httpHeaders = null) { // Set the UA and HTTP headers only if needed (eg. batch mode). if ($httpHeaders) { $this->setHttpHeaders($httpHeaders); } if ($userAgent) { $this->setUserAgent($userAgent); } $this->setDetectionType(self::DETECTION_TYPE_EXTENDED); return $this->matchUAAgainstKey($key); }
This method checks for a certain property in the userAgent. @todo: The httpHeaders part is not yet used. @param string $key @param string $userAgent deprecated @param string $httpHeaders deprecated @return bool|int|null
is
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 match($regex, $userAgent = null) { $match = (bool) preg_match(sprintf('#%s#is', $regex), (false === empty($userAgent) ? $userAgent : $this->userAgent), $matches); // If positive match is found, store the results for debug. if ($match) { $this->matchingRegex = $regex; $this->matchesArray = $matches; } return $match; }
Some detection rules are relative (not standard), because of the diversity of devices, vendors and their conventions in representing the User-Agent or the HTTP headers. This method will be used to check custom regexes against the User-Agent string. @param $regex @param string $userAgent @return bool @todo: search in the HTTP headers too.
match
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 getProperties() { return self::$properties; }
Get the properties array. @return array
getProperties
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 mobileGrade() { $isMobile = $this->isMobile(); if ( // Apple iOS 4-7.0 – Tested on the original iPad (4.3 / 5.0), iPad 2 (4.3 / 5.1 / 6.1), iPad 3 (5.1 / 6.0), iPad Mini (6.1), iPad Retina (7.0), iPhone 3GS (4.3), iPhone 4 (4.3 / 5.1), iPhone 4S (5.1 / 6.0), iPhone 5 (6.0), and iPhone 5S (7.0) $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT) >= 4.3 || $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT) >= 4.3 || $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT) >= 4.3 || // Android 2.1-2.3 - Tested on the HTC Incredible (2.2), original Droid (2.2), HTC Aria (2.1), Google Nexus S (2.3). Functional on 1.5 & 1.6 but performance may be sluggish, tested on Google G1 (1.5) // Android 3.1 (Honeycomb) - Tested on the Samsung Galaxy Tab 10.1 and Motorola XOOM // Android 4.0 (ICS) - Tested on a Galaxy Nexus. Note: transition performance can be poor on upgraded devices // Android 4.1 (Jelly Bean) - Tested on a Galaxy Nexus and Galaxy 7 ($this->version('Android', self::VERSION_TYPE_FLOAT) > 2.1 && $this->is('Webkit')) || // Windows Phone 7.5-8 - Tested on the HTC Surround (7.5), HTC Trophy (7.5), LG-E900 (7.5), Nokia 800 (7.8), HTC Mazaa (7.8), Nokia Lumia 520 (8), Nokia Lumia 920 (8), HTC 8x (8) $this->version('Windows Phone OS', self::VERSION_TYPE_FLOAT) >= 7.5 || // Tested on the Torch 9800 (6) and Style 9670 (6), BlackBerry? Torch 9810 (7), BlackBerry Z10 (10) $this->is('BlackBerry') && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) >= 6.0 || // Blackberry Playbook (1.0-2.0) - Tested on PlayBook $this->match('Playbook.*Tablet') || // Palm WebOS (1.4-3.0) - Tested on the Palm Pixi (1.4), Pre (1.4), Pre 2 (2.0), HP TouchPad (3.0) ($this->version('webOS', self::VERSION_TYPE_FLOAT) >= 1.4 && $this->match('Palm|Pre|Pixi')) || // Palm WebOS 3.0 - Tested on HP TouchPad $this->match('hp.*TouchPad') || // Firefox Mobile 18 - Tested on Android 2.3 and 4.1 devices ($this->is('Firefox') && $this->version('Firefox', self::VERSION_TYPE_FLOAT) >= 18) || // Chrome for Android - Tested on Android 4.0, 4.1 device ($this->is('Chrome') && $this->is('AndroidOS') && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 4.0) || // Skyfire 4.1 - Tested on Android 2.3 device ($this->is('Skyfire') && $this->version('Skyfire', self::VERSION_TYPE_FLOAT) >= 4.1 && $this->is('AndroidOS') && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3) || // Opera Mobile 11.5-12: Tested on Android 2.3 ($this->is('Opera') && $this->version('Opera Mobi', self::VERSION_TYPE_FLOAT) >= 11.5 && $this->is('AndroidOS')) || // Meego 1.2 - Tested on Nokia 950 and N9 $this->is('MeeGoOS') || // Tizen (pre-release) - Tested on early hardware $this->is('Tizen') || // Samsung Bada 2.0 - Tested on a Samsung Wave 3, Dolphin browser // @todo: more tests here! $this->is('Dolfin') && $this->version('Bada', self::VERSION_TYPE_FLOAT) >= 2.0 || // UC Browser - Tested on Android 2.3 device (($this->is('UC Browser') || $this->is('Dolfin')) && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3) || // Kindle 3 and Fire - Tested on the built-in WebKit browser for each ($this->match('Kindle Fire') || $this->is('Kindle') && $this->version('Kindle', self::VERSION_TYPE_FLOAT) >= 3.0) || // Nook Color 1.4.1 - Tested on original Nook Color, not Nook Tablet $this->is('AndroidOS') && $this->is('NookTablet') || // Chrome Desktop 16-24 - Tested on OS X 10.7 and Windows 7 $this->version('Chrome', self::VERSION_TYPE_FLOAT) >= 16 && !$isMobile || // Safari Desktop 5-6 - Tested on OS X 10.7 and Windows 7 $this->version('Safari', self::VERSION_TYPE_FLOAT) >= 5.0 && !$isMobile || // Firefox Desktop 10-18 - Tested on OS X 10.7 and Windows 7 $this->version('Firefox', self::VERSION_TYPE_FLOAT) >= 10.0 && !$isMobile || // Internet Explorer 7-9 - Tested on Windows XP, Vista and 7 $this->version('IE', self::VERSION_TYPE_FLOAT) >= 7.0 && !$isMobile || // Opera Desktop 10-12 - Tested on OS X 10.7 and Windows 7 $this->version('Opera', self::VERSION_TYPE_FLOAT) >= 10 && !$isMobile ) { return self::MOBILE_GRADE_A; } if ( $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT) < 4.3 || $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT) < 4.3 || $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT) < 4.3 || // Blackberry 5.0: Tested on the Storm 2 9550, Bold 9770 $this->is('Blackberry') && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) >= 5 && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) < 6 || //Opera Mini (5.0-6.5) - Tested on iOS 3.2/4.3 and Android 2.3 ($this->version('Opera Mini', self::VERSION_TYPE_FLOAT) >= 5.0 && $this->version('Opera Mini', self::VERSION_TYPE_FLOAT) <= 7.0 && ($this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 || $this->is('iOS'))) || // Nokia Symbian^3 - Tested on Nokia N8 (Symbian^3), C7 (Symbian^3), also works on N97 (Symbian^1) $this->match('NokiaN8|NokiaC7|N97.*Series60|Symbian/3') || // @todo: report this (tested on Nokia N71) $this->version('Opera Mobi', self::VERSION_TYPE_FLOAT) >= 11 && $this->is('SymbianOS') ) { return self::MOBILE_GRADE_B; } if ( // Blackberry 4.x - Tested on the Curve 8330 $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) <= 5.0 || // Windows Mobile - Tested on the HTC Leo (WinMo 5.2) $this->match('MSIEMobile|Windows CE.*Mobile') || $this->version('Windows Mobile', self::VERSION_TYPE_FLOAT) <= 5.2 || // Tested on original iPhone (3.1), iPhone 3 (3.2) $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT) <= 3.2 || $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT) <= 3.2 || $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT) <= 3.2 || // Internet Explorer 7 and older - Tested on Windows XP $this->version('IE', self::VERSION_TYPE_FLOAT) <= 7.0 && !$isMobile ) { return self::MOBILE_GRADE_C; } // All older smartphone platforms and featurephones - Any device that doesn't support media queries // will receive the basic, C grade experience. return self::MOBILE_GRADE_C; }
Retrieve the mobile grading, using self::MOBILE_GRADE_* constants. @return string One of the self::MOBILE_GRADE_* constants.
mobileGrade
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 numberFormat($number, $bits = 2) { return number_format($number, $bits, '.', ''); }
@param $number | Float @param $bits | Int @return $number | Float 返回格式化形式的float小数,譬如2 会变成2.00
numberFormat
php
fecshop/yii2_fecshop
services/helper/Format.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Format.php
BSD-3-Clause
public function getPreDayDateArr($day) { $arr = []; for ($i=$day; $i>=0; $i--) { $str = date("Y-m-d", strtotime("-$i day")); $arr[$str] = 0; } return $arr; }
@param $day | Int 多少天之前 返回最近xx天的日期数组
getPreDayDateArr
php
fecshop/yii2_fecshop
services/helper/Format.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Format.php
BSD-3-Clause
public function getUserInfoByCode($code) { $urlKey = '/sns/jscode2session'; $apiId = $this->microProgramAppId; $secret = $this->microProgramSecret; $grant_type = 'authorization_code'; $url = $this->wxApiBaseUrl . $urlKey . "?appid=$apiId&secret=$secret&js_code=$code&grant_type=$grant_type"; $returnStr = \fec\helpers\CApi::getCurlData($url); $wxUserInfo = json_decode($returnStr, true); if (!isset($wxUserInfo['session_key']) || !isset($wxUserInfo['openid']) ) { return null; } return $wxUserInfo; }
@param $code | string, 微信登陆的code @return array , example: ['session_key' => '', 'openid' => '']
getUserInfoByCode
php
fecshop/yii2_fecshop
services/helper/Wx.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Wx.php
BSD-3-Clause
public function unzip($src_file, $dest_dir=false, $create_zip_name_dir=true, $overwrite=true) { if ($dest_dir) { $dest_dir .= '/'; } if ($zip = zip_open($src_file)) { if ($zip) { $splitter = ($create_zip_name_dir === true) ? "." : "/"; if ($dest_dir === false) { $dest_dir = substr($src_file, 0, strrpos($src_file, $splitter))."/"; } // 如果不存在 创建目标解压目录 $this->create_dirs($dest_dir); // 对每个文件进行解压 while ($zip_entry = zip_read($zip)) { // 文件不在根目录 $pos_last_slash = strrpos(zip_entry_name($zip_entry), "/"); if ($pos_last_slash !== false) { // 创建目录 在末尾带 $this->create_dirs($dest_dir.substr(zip_entry_name($zip_entry), 0, $pos_last_slash+1)); } // 打开包 if (zip_entry_open($zip,$zip_entry,"r")) { // 文件名保存在磁盘上 $file_name = $dest_dir.zip_entry_name($zip_entry); // 检查文件是否需要重写 if ($overwrite === true || $overwrite === false && !is_file($file_name)) { // 读取压缩文件的内容 $fstream = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); @file_put_contents($file_name, $fstream); // 设置权限 chmod($file_name, 0777); } // 关闭入口 zip_entry_close($zip_entry); } } // 关闭压缩包 zip_close($zip); } }else{ return false; } return true; }
@param $src_file | string, zip文件的完整路径 @param $dest_dir | bool or string,zip文件解压后的文件路径。 @param $create_zip_name_dir | bool or string,当$dest_dir为false的时候有效,解压到zip文件路径下。 @param $overwrite | bool,解压是否强制覆盖。 将zip文件进行解压。
unzip
php
fecshop/yii2_fecshop
services/helper/ZipFile.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ZipFile.php
BSD-3-Clause
protected function create_dirs($path) { if (!is_dir($path)) { $directory_path = ""; $directories = explode("/",$path); array_pop($directories); foreach ($directories as $directory) { $directory_path .= $directory."/"; if (!is_dir($directory_path)) { mkdir($directory_path); chmod($directory_path, 0777); } } } }
@param $path | string 创建目录
create_dirs
php
fecshop/yii2_fecshop
services/helper/ZipFile.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ZipFile.php
BSD-3-Clause
protected function generateZipName($name, $length = 20) { $arr = explode('.', $name); $fileType = '.'.$arr[count($arr)-1]; // 密码字符集,可任意添加你需要的字符 $chars = 'abcdefghijklmnopqrstuvwxyz0123456789'; $str =''; for ($i = 0; $i < $length; $i++) { // 这里提供两种字符获取方式 // 第一种是使用 substr 截取$chars中的任意一位字符; // 第二种是取字符数组 $chars 的任意元素 // $str .= substr($chars, mt_rand(0, strlen($chars) – 1), 1); $str .= $chars[ mt_rand(0, strlen($chars) - 1) ]; } $str .= time(); return $str.$fileType; }
@param $name | string, 生成zip 文件 @param $length | int,zip文件名称长度 生成随机的zip文件名称
generateZipName
php
fecshop/yii2_fecshop
services/helper/ZipFile.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ZipFile.php
BSD-3-Clause
protected function getZipMaxUploadSize() { if (!$this->_maxZipUploadSize) { if ($this->maxZipUploadMSize) { $this->_maxZipUploadSize = $this->maxZipUploadMSize * 1024 * 1024; } } return $this->_maxZipUploadSize; }
得到上传图片的最大的size.
getZipMaxUploadSize
php
fecshop/yii2_fecshop
services/helper/ZipFile.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ZipFile.php
BSD-3-Clause
public function getCurrentBaseZipDir() { return Yii::getAlias($this->baseZipDir); }
得到(上传)保存图片所在相对根目录的文件夹路径.
getCurrentBaseZipDir
php
fecshop/yii2_fecshop
services/helper/ZipFile.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ZipFile.php
BSD-3-Clause
public function getZipDir($relativeFilePath) { return Yii::getAlias($this->baseZipDir.$relativeFilePath); }
得到(上传)保存图片所在相对根目录的文件夹路径.
getZipDir
php
fecshop/yii2_fecshop
services/helper/ZipFile.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ZipFile.php
BSD-3-Clause
protected function getUniqueZipNameInPath($imgSaveFloder, $name, $imageType, $randStr = '') { $imagePath = $imgSaveFloder.'/'.$name.$randStr.'.'.$imageType; if (!file_exists($imagePath)) { return $name.$randStr.'.'.$imageType; } else { $randStr = time().rand(10000, 99999); return $this->getUniqueZipNameInPath($imgSaveFloder, $name, $imageType, $randStr); } }
@param $imgSaveFloder|string image save Floder absolute Path @param $name|string , image file name ,not contain image suffix. @param $imageType|string , image file suffix. like '.gif','jpg' return saved Image Name. 得到产品保存的唯一路径,因为可能存在名字重复的问题,因此使用该函数确保图片路径唯一。
getUniqueZipNameInPath
php
fecshop/yii2_fecshop
services/helper/ZipFile.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ZipFile.php
BSD-3-Clause
public function changeToMongoStorage() { $this->storage = 'ErrorHandlerMongodb'; $currentService = $this->getStorageService($this); $this->_errorHandler = new $currentService(); }
动态更改为mongodb model
changeToMongoStorage
php
fecshop/yii2_fecshop
services/helper/ErrorHandler.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ErrorHandler.php
BSD-3-Clause
public function changeToMysqlStorage() { $this->storage = 'ErrorHandlerMysqldb'; $currentService = $this->getStorageService($this); $this->_errorHandler = new $currentService(); }
动态更改为mongodb model
changeToMysqlStorage
php
fecshop/yii2_fecshop
services/helper/ErrorHandler.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ErrorHandler.php
BSD-3-Clause
public function saveByErrorHandler( $code, $message, $file, $line, $created_at, $ip, $name, $trace_string, $url, $req_info=[] ) { return $this->_errorHandler->saveByErrorHandler($code,$message,$file,$line,$created_at,$ip,$name,$trace_string,$url,$req_info); }
@param $code | Int, http 错误码 @param $message | String, 错误的具体信息 @param $file | string, 发生错误的文件 @param $line | Int, 发生错误所在文件的代码行 @param $created_at | Int, 发生错误的执行时间戳 @param $ip | string, 访问人的ip @param $name | string, 错误的名字 @param $trace_string | string, 错误的追踪信息 @return 返回错误存储到mongodb的id,作为前端显示的错误编码 该函数从errorHandler得到错误信息,然后保存到mongodb中。
saveByErrorHandler
php
fecshop/yii2_fecshop
services/helper/ErrorHandler.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ErrorHandler.php
BSD-3-Clause
public function getByPrimaryKey($primaryKey) { return $this->_errorHandler->getByPrimaryKey($primaryKey); }
通过主键,得到errorHandler对象。
getByPrimaryKey
php
fecshop/yii2_fecshop
services/helper/ErrorHandler.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/ErrorHandler.php
BSD-3-Clause
public function getCollByFilter($query, $filter) { $fetchAll = isset($filter['fetchAll']) ? $filter['fetchAll'] : false; $select = isset($filter['select']) ? $filter['select'] : ''; $asArray = isset($filter['asArray']) ? $filter['asArray'] : true; $numPerPage = isset($filter['numPerPage']) ? $filter['numPerPage'] : $this->numPerPage; $pageNum = isset($filter['pageNum']) ? $filter['pageNum'] : $this->pageNum; $orderBy = isset($filter['orderBy']) ? $filter['orderBy'] : ''; $where = isset($filter['where']) ? $filter['where'] : ''; if ($asArray) { $query->asArray(); } if (is_array($select) && !empty($select)) { $query->select($select); } if ($where) { if (is_array($where)) { $i = 0; foreach ($where as $w) { $i++; if ($i == 1) { $query->where($w); } else { $query->andWhere($w); } } } } if (!$fetchAll) { $offset = ($pageNum - 1) * $numPerPage; $query->limit($numPerPage)->offset($offset); } if ($orderBy) { $query->orderBy($orderBy); } return $query; }
example filter: [ 'numPerPage' => 20, 'pageNum' => 1, 'orderBy' => ['_id' => SORT_DESC, 'sku' => SORT_ASC ], 'where' => [ ['>','price',1], ['<=','price',10] ['sku' => 'uk10001'], ], 'asArray' => true, 'fetchAll' => false, // 是否获取所有数据,如果为true,则传递的numPerPage和pageNum将会无效。 ] 查询方面使用的函数,根据传递的参数,进行query @return ActiveQuery
getCollByFilter
php
fecshop/yii2_fecshop
services/helper/AR.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/AR.php
BSD-3-Clause
public function save($model, $one, $serialize = false) { if (!$model) { Yii::$service->helper->errors->add('ActiveRecord Save Error: $model is empty'); return false; } $attributes = $model->attributes(); if (is_array($attributes) && !empty($attributes)) { foreach ($attributes as $attr) { if (isset($one[$attr])) { if ($serialize && is_array($one[$attr])) { $model[$attr] = serialize($one[$attr]); } else { $model[$attr] = $one[$attr]; } } } if ($model->save()) { return $model; } else { Yii::$service->helper->errors->add('model save fail'); return false; } } else { Yii::$service->helper->errors->add('$attribute is empty or is not array'); return false; } }
@param $model | Object , 数据库model @param $one | Array , 数据数组,对model进行赋值 通过循环的方式,对$model对象的属性进行赋值。 并保存,保存成功后,返回保存后的model对象
save
php
fecshop/yii2_fecshop
services/helper/AR.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/AR.php
BSD-3-Clause
public function getDefaultCountry() { if (!$this->default_country) { $this->default_country = 'US'; } return $this->default_country; }
得到默认的国家
getDefaultCountry
php
fecshop/yii2_fecshop
services/helper/Country.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Country.php
BSD-3-Clause
public function getIOS3166InfoByCountryCode($countryCode) { return (new \League\ISO3166\ISO3166)->alpha2($countryCode); }
@param $countryCode | string, 二位国家简码 得到IOS3166的数组信息 例子: 参数 $countryCode = CN,返回结果如下 [ 'name' => 'China', 'alpha2' => 'CN', 'alpha3' => 'CHN', 'numeric' => '156', 'currency' => [ 'CNY', ], ],
getIOS3166InfoByCountryCode
php
fecshop/yii2_fecshop
services/helper/Country.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Country.php
BSD-3-Clause
public function getStateOptionsByContryCode($CountryCode, $selected = '') { if (!$CountryCode) { $CountryCode = $this->getDefaultCountry(); } $stateArr = $this->getStateByContryCode($CountryCode); $str = ''; if (is_array($stateArr) && !empty($stateArr)) { if ($selected) { foreach ($stateArr as $code=>$name) { if ($selected == $code || strtolower($selected) == strtolower($name)) { $str .= '<option selected="selected" value="'.$code.'" rel="'.$name.'">'.$name.'</option>'; } else { $str .= '<option value="'.$code.'" rel="'.$name.'" >'.$name.'</option>'; } } } else { foreach ($stateArr as $code=>$name) { $str .= '<option value="'.$code.'" rel="'.$name.'">'.$name.'</option>'; } } } return $str; }
通过国家,得到省的option html的字符串
getStateOptionsByContryCode
php
fecshop/yii2_fecshop
services/helper/Country.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Country.php
BSD-3-Clause
public function getAllCountryOptions($name = 'country', $class = 'country', $current = '', $nullShow = '') { $all_country_array = $this->getAllCountryArray(); if ($name && $class) { $str = '<select name="'.$name.'" class="'.$class.'">'; } $str .= '<option value="">'.$nullShow.'</option>'; foreach ($all_country_array as $k=>$v) { if ($current) { if ($k == $current) { $str .= '<option selected="selected" value="'.$k.'">'.$v.'</option>'; } else { $str .= '<option value="'.$k.'">'.$v.'</option>'; } } else { $str .= '<option value="'.$k.'">'.$v.'</option>'; } } if ($name && $class) { $str .= '</select>'; } return $str; }
得到所有国家的option
getAllCountryOptions
php
fecshop/yii2_fecshop
services/helper/Country.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Country.php
BSD-3-Clause
public function getCountryNameByKey($key) { $all_country = $this->getAllCountryArray(); return isset($all_country[$key]) ? $all_country[$key] : $key; }
通过国家简码得到国家的全称名字
getCountryNameByKey
php
fecshop/yii2_fecshop
services/helper/Country.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Country.php
BSD-3-Clause
public function getCountryOptionsHtml($selectd = '') { if (!$selectd) { $selectd = $this->getDefaultCountry(); } $all_country = $this->getAllCountryArray(); $str = ''; foreach ($all_country as $key=>$value) { if ($selectd && ($selectd == $key)) { $str .= '<option selected="selected" value="'.$key.'">'.$value.'</option>'; } else { $str .= '<option value="'.$key.'">'.$value.'</option>'; } } return $str; }
国家option html
getCountryOptionsHtml
php
fecshop/yii2_fecshop
services/helper/Country.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Country.php
BSD-3-Clause
public function getStateByContryCode($countryCode, $stateCode = '') { $countryStates = $this->getCountryStateArr(); $returnStateArr = []; $returnStateName = ''; if ($countryCode) { if ($stateCode) { if (isset($countryStates[$countryCode][$stateCode]) && !empty($countryStates[$countryCode][$stateCode])) { $returnStateName = $countryStates[$countryCode][$stateCode]; } return $returnStateName ? $returnStateName : $stateCode; } else { if (isset($countryStates[$countryCode]) && !empty($countryStates[$countryCode]) && is_array($countryStates[$countryCode])) { $returnStateArr = $countryStates[$countryCode]; } return $returnStateArr; } } }
@param $countryCode |String 国家简码 @param $stateCode | String 省市简码 @return string OR Array 如果不传递省市简码,那么返回的是该国家对应的省市数组 如果传递省市简码,传递的是省市的名称
getStateByContryCode
php
fecshop/yii2_fecshop
services/helper/Country.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Country.php
BSD-3-Clause
public function getAllCountryArray() { return [ 'AF'=>'Afghanistan', 'AX'=>'Åland Islands', 'AL'=>'Albania', 'DZ'=>'Algeria', 'AS'=>'American Samoa', 'AD'=>'Andorra', 'AO'=>'Angola', 'AI'=>'Anguilla', 'AQ'=>'Antarctica', 'AG'=>'Antigua and Barbuda', 'AR'=>'Argentina', 'AM'=>'Armenia', 'AW'=>'Aruba', 'AU'=>'Australia', 'AT'=>'Austria', 'AZ'=>'Azerbaijan', 'BS'=>'Bahamas', 'BH'=>'Bahrain', 'BD'=>'Bangladesh', 'BB'=>'Barbados', 'BY'=>'Belarus', 'BE'=>'Belgium', 'BZ'=>'Belize', 'BJ'=>'Benin', 'BM'=>'Bermuda', 'BT'=>'Bhutan', 'BO'=>'Bolivia', 'BA'=>'Bosnia and Herzegovina', 'BW'=>'Botswana', 'BV'=>'Bouvet Island', 'BR'=>'Brazil', 'IO'=>'British Indian Ocean Territory', 'VG'=>'British Virgin Islands', 'BN'=>'Brunei', 'BG'=>'Bulgaria', 'BF'=>'Burkina Faso', 'BI'=>'Burundi', 'KH'=>'Cambodia', 'CM'=>'Cameroon', 'CA'=>'Canada', 'CV'=>'Cape Verde', 'KY'=>'Cayman Islands', 'CF'=>'Central African Republic', 'TD'=>'Chad', 'CL'=>'Chile', 'CN'=>'China', 'CX'=>'Christmas Island', 'CC'=>'Cocos [Keeling] Islands', 'CO'=>'Colombia', 'KM'=>'Comoros', 'CG'=>'Congo - Brazzaville', 'CD'=>'Congo - Kinshasa', 'CK'=>'Cook Islands', 'CR'=>'Costa Rica', 'CI'=>'Côte d’Ivoire', 'HR'=>'Croatia', 'CU'=>'Cuba', 'CY'=>'Cyprus', 'CZ'=>'Czech Republic', 'DK'=>'Denmark', 'DJ'=>'Djibouti', 'DM'=>'Dominica', 'DO'=>'Dominican Republic', 'EC'=>'Ecuador', 'EG'=>'Egypt', 'SV'=>'El Salvador', 'GQ'=>'Equatorial Guinea', 'ER'=>'Eritrea', 'EE'=>'Estonia', 'ET'=>'Ethiopia', 'FK'=>'Falkland Islands', 'FO'=>'Faroe Islands', 'FJ'=>'Fiji', 'FI'=>'Finland', 'FR'=>'France', 'GF'=>'French Guiana', 'PF'=>'French Polynesia', 'TF'=>'French Southern Territories', 'GA'=>'Gabon', 'GM'=>'Gambia', 'GE'=>'Georgia', 'DE'=>'Germany', 'GH'=>'Ghana', 'GI'=>'Gibraltar', 'GR'=>'Greece', 'GL'=>'Greenland', 'GD'=>'Grenada', 'GP'=>'Guadeloupe', 'GU'=>'Guam', 'GT'=>'Guatemala', 'GG'=>'Guernsey', 'GN'=>'Guinea', 'GW'=>'Guinea-Bissau', 'GY'=>'Guyana', 'HT'=>'Haiti', 'HM'=>'Heard Island and McDonald Islands', 'HN'=>'Honduras', 'HK'=>'Hong Kong SAR China', 'HU'=>'Hungary', 'IS'=>'Iceland', 'IN'=>'India', 'ID'=>'Indonesia', 'IR'=>'Iran', 'IQ'=>'Iraq', 'IE'=>'Ireland', 'IM'=>'Isle of Man', 'IL'=>'Israel', 'IT'=>'Italy', 'JM'=>'Jamaica', 'JP'=>'Japan', 'JE'=>'Jersey', 'JO'=>'Jordan', 'KZ'=>'Kazakhstan', 'KE'=>'Kenya', 'KI'=>'Kiribati', 'KW'=>'Kuwait', 'KG'=>'Kyrgyzstan', 'LA'=>'Laos', 'LV'=>'Latvia', 'LB'=>'Lebanon', 'LS'=>'Lesotho', 'LR'=>'Liberia', 'LY'=>'Libya', 'LI'=>'Liechtenstein', 'LT'=>'Lithuania', 'LU'=>'Luxembourg', 'MO'=>'Macau SAR China', 'MK'=>'Macedonia', 'MG'=>'Madagascar', 'MW'=>'Malawi', 'MY'=>'Malaysia', 'MV'=>'Maldives', 'ML'=>'Mali', 'MT'=>'Malta', 'MH'=>'Marshall Islands', 'MQ'=>'Martinique', 'MR'=>'Mauritania', 'MU'=>'Mauritius', 'YT'=>'Mayotte', 'MX'=>'Mexico', 'FM'=>'Micronesia', 'MD'=>'Moldova', 'MC'=>'Monaco', 'MN'=>'Mongolia', 'ME'=>'Montenegro', 'MS'=>'Montserrat', 'MA'=>'Morocco', 'MZ'=>'Mozambique', 'MM'=>'Myanmar [Burma]', 'NA'=>'Namibia', 'NR'=>'Nauru', 'NP'=>'Nepal', 'NL'=>'Netherlands', 'AN'=>'Netherlands Antilles', 'NC'=>'New Caledonia', 'NZ'=>'New Zealand', 'NI'=>'Nicaragua', 'NE'=>'Niger', 'NG'=>'Nigeria', 'NU'=>'Niue', 'NF'=>'Norfolk Island', 'MP'=>'Northern Mariana Islands', 'KP'=>'North Korea', 'NO'=>'Norway', 'OM'=>'Oman', 'PK'=>'Pakistan', 'PW'=>'Palau', 'PS'=>'Palestinian Territories', 'PA'=>'Panama', 'PG'=>'Papua New Guinea', 'PY'=>'Paraguay', 'PE'=>'Peru', 'PH'=>'Philippines', 'PN'=>'Pitcairn Islands', 'PL'=>'Poland', 'PT'=>'Portugal', 'PR'=>'Puerto Rico', 'QA'=>'Qatar', 'RE'=>'R¨¦union', 'RO'=>'Romania', 'RU'=>'Russia', 'RW'=>'Rwanda', 'BL'=>'Saint Barth¨¦lemy', 'SH'=>'Saint Helena', 'KN'=>'Saint Kitts and Nevis', 'LC'=>'Saint Lucia', 'MF'=>'Saint Martin', 'PM'=>'Saint Pierre and Miquelon', 'VC'=>'Saint Vincent and the Grenadines', 'WS'=>'Samoa', 'SM'=>'San Marino', 'ST'=>'São Tomé and Príncipe', 'SA'=>'Saudi Arabia', 'SN'=>'Senegal', 'RS'=>'Serbia', 'SC'=>'Seychelles', 'SL'=>'Sierra Leone', 'SG'=>'Singapore', 'SK'=>'Slovakia', 'SI'=>'Slovenia', 'SB'=>'Solomon Islands', 'SO'=>'Somalia', 'ZA'=>'South Africa', 'GS'=>'South Georgia and the South Sandwich Islands', 'KR'=>'South Korea', 'ES'=>'Spain', 'LK'=>'Sri Lanka', 'SD'=>'Sudan', 'SR'=>'Suriname', 'SJ'=>'Svalbard and Jan Mayen', 'SZ'=>'Swaziland', 'SE'=>'Sweden', 'CH'=>'Switzerland', 'SY'=>'Syria', 'TW'=>'Taiwan', 'TJ'=>'Tajikistan', 'TZ'=>'Tanzania', 'TH'=>'Thailand', 'TL'=>'Timor-Leste', 'TG'=>'Togo', 'TK'=>'Tokelau', 'TO'=>'Tonga', 'TT'=>'Trinidad and Tobago', 'TN'=>'Tunisia', 'TR'=>'Turkey', 'TM'=>'Turkmenistan', 'TC'=>'Turks and Caicos Islands', 'TV'=>'Tuvalu', 'UG'=>'Uganda', 'UA'=>'Ukraine', 'AE'=>'United Arab Emirates', 'GB'=>'United Kingdom', 'US'=>'United States', 'UY'=>'Uruguay', 'UM'=>'U.S. Minor Outlying Islands', 'VI'=>'U.S. Virgin Islands', 'UZ'=>'Uzbekistan', 'VU'=>'Vanuatu', 'VA'=>'Vatican City', 'VE'=>'Venezuela', 'VN'=>'Vietnam', 'WF'=>'Wallis and Futuna', 'EH'=>'Western Sahara', 'YE'=>'Yemen', 'ZM'=>'Zambia', 'ZW'=>'Zimbabwe', ]; }
@return array ,得到所有国家的数组 格式:['国家简码' => '国家全称']
getAllCountryArray
php
fecshop/yii2_fecshop
services/helper/Country.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Country.php
BSD-3-Clause
public function getCountryStateArr() { $data = [ 'US' => [ 'AL' => 'Alabama', 'AK' => 'Alaska', 'AS' => 'American Samoa', 'AZ' => 'Arizona', 'AR' => 'Arkansas', 'AF' => 'Armed Forces Africa', 'AA' => 'Armed Forces Americas', 'AC' => 'Armed Forces Canada', 'AE' => 'Armed Forces Europe', 'AM' => 'Armed Forces Middle East', 'AP' => 'Armed Forces Pacific', 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', 'DC' => 'District of Columbia', 'FM' => 'Federated States Of Micronesia', 'FL' => 'Florida', 'GA' => 'Georgia', 'GU' => 'Guam', 'HI' => 'Hawaii', 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine', 'MH' => 'Marshall Islands', 'MD' => 'Maryland', 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'MP' => 'Northern Mariana Islands', 'OH' => 'Ohio', 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PW' => 'Palau', 'PA' => 'Pennsylvania', 'PR' => 'Puerto Rico', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', 'VT' => 'Vermont', 'VI' => 'Virgin Islands', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', 'WI' => 'Wisconsin', 'WY' => 'Wyoming', ], 'CA' => [ 'AB' => 'Alberta', 'BC' => 'British Columbia', 'MB' => 'Manitoba', 'NL' => 'Newfoundland and Labrador', 'NB' => 'New Brunswick', 'NS' => 'Nova Scotia', 'NT' => 'Northwest Territories', 'NU' => 'Nunavut', 'ON' => 'Ontario', 'PE' => 'Prince Edward Island', 'QC' => 'Quebec', 'SK' => 'Saskatchewan', 'YT' => 'Yukon Territory', ], 'DE' => [ 'NDS' => 'Niedersachsen', 'BAW' => 'Baden-Württemberg', 'BAY' => 'Bayern', 'BER' => 'Berlin', 'BRG' => 'Brandenburg', 'BRE' => 'Bremen', 'HAM' => 'Hamburg', 'HES' => 'Hessen', 'MEC' => 'Mecklenburg-Vorpommern', 'NRW' => 'Nordrhein-Westfalen', 'RHE' => 'Rheinland-Pfalz', 'SAR' => 'Saarland', 'SAS' => 'Sachsen', 'SAC' => 'Sachsen-Anhalt', 'SCN' => 'Schleswig-Holstein', 'THE' => 'Thüringen', ], 'AT' => [ 'WI' => 'Wien', 'NO' => 'Niederösterreich', 'OO' => 'Oberösterreich', 'SB' => 'Salzburg', 'KN' => 'Kärnten', 'ST' => 'Steiermark', 'TI' => 'Tirol', 'BL' => 'Burgenland', 'VB' => 'Voralberg', ], 'CH' => [ 'AG' => 'Aargau', 'AI' => 'Appenzell Innerrhoden', 'AR' => 'Appenzell Ausserrhoden', 'BE' => 'Bern', 'BL' => 'Basel-Landschaft', 'BS' => 'Basel-Stadt', 'FR' => 'Freiburg', 'GE' => 'Genf', 'GL' => 'Glarus', 'GR' => 'Graubünden', 'JU' => 'Jura', 'LU' => 'Luzern', 'NE' => 'Neuenburg', 'NW' => 'Nidwalden', 'OW' => 'Obwalden', 'SG' => 'St. Gallen', 'SH' => 'Schaffhausen', 'SO' => 'Solothurn', 'SZ' => 'Schwyz', 'TG' => 'Thurgau', 'TI' => 'Tessin', 'UR' => 'Uri', 'VD' => 'Waadt', 'VS' => 'Wallis', 'ZG' => 'Zug', 'ZH' => 'Zürich', ], 'ES' => [ 'A Coruсa' => 'A Coruña', 'Alava' => 'Alava', 'Albacete' => 'Albacete', 'Alicante' => 'Alicante', 'Almeria' => 'Almeria', 'Asturias' => 'Asturias', 'Avila' => 'Avila', 'Badajoz' => 'Badajoz', 'Baleares' => 'Baleares', 'Barcelona' => 'Barcelona', 'Burgos' => 'Burgos', 'Caceres' => 'Caceres', 'Cadiz' => 'Cadiz', 'Cantabria' => 'Cantabria', 'Castellon' => 'Castellon', 'Ceuta' => 'Ceuta', 'Ciudad Real' => 'Ciudad Real', 'Cordoba' => 'Cordoba', 'Cuenca' => 'Cuenca', 'Girona' => 'Girona', 'Granada' => 'Granada', 'Guadalajara' => 'Guadalajara', 'Guipuzcoa' => 'Guipuzcoa', 'Huelva' => 'Huelva', 'Huesca' => 'Huesca', 'Jaen' => 'Jaen', 'La Rioja' => 'La Rioja', 'Las Palmas' => 'Las Palmas', 'Leon' => 'Leon', 'Lleida' => 'Lleida', 'Lugo' => 'Lugo', 'Madrid' => 'Madrid', 'Malaga' => 'Malaga', 'Melilla' => 'Melilla', 'Murcia' => 'Murcia', 'Navarra' => 'Navarra', 'Ourense' => 'Ourense', 'Palencia' => 'Palencia', 'Pontevedra' => 'Pontevedra', 'Salamanca' => 'Salamanca', 'Santa Cruz de Tenerife' => 'Santa Cruz de Tenerife', 'Segovia' => 'Segovia', 'Sevilla' => 'Sevilla', 'Soria' => 'Soria', 'Tarragona' => 'Tarragona', 'Teruel' => 'Teruel', 'Toledo' => 'Toledo', 'Valencia' => 'Valencia', 'Valladolid' => 'Valladolid', 'Vizcaya' => 'Vizcaya', 'Zamora' => 'Zamora', 'Zaragoza' => 'Zaragoza', ], 'FR' => [ '1' => 'Ain', '2' => 'Aisne', '3' => 'Allier', '4' => 'Alpes-de-Haute-Provence', '5' => 'Hautes-Alpes', '6' => 'Alpes-Maritimes', '7' => 'Ardèche', '8' => 'Ardennes', '9' => 'Ariège', '10' => 'Aube', '11' => 'Aude', '12' => 'Aveyron', '13' => 'Bouches-du-Rhône', '14' => 'Calvados', '15' => 'Cantal', '16' => 'Charente', '17' => 'Charente-Maritime', '18' => 'Cher', '19' => 'Corrèze', '2A' => 'Corse-du-Sud', '2B' => 'Haute-Corse', '21' => 'Côte-d\'Or', '22' => 'Côtes-d\'Armor', '23' => 'Creuse', '24' => 'Dordogne', '25' => 'Doubs', '26' => 'Drôme', '27' => 'Eure', '28' => 'Eure-et-Loir', '29' => 'Finistère', '30' => 'Gard', '31' => 'Haute-Garonne', '32' => 'Gers', '33' => 'Gironde', '34' => 'Hérault', '35' => 'Ille-et-Vilaine', '36' => 'Indre', '37' => 'Indre-et-Loire', '38' => 'Isère', '39' => 'Jura', '40' => 'Landes', '41' => 'Loir-et-Cher', '42' => 'Loire', '43' => 'Haute-Loire', '44' => 'Loire-Atlantique', '45' => 'Loiret', '46' => 'Lot', '47' => 'Lot-et-Garonne', '48' => 'Lozère', '49' => 'Maine-et-Loire', '50' => 'Manche', '51' => 'Marne', '52' => 'Haute-Marne', '53' => 'Mayenne', '54' => 'Meurthe-et-Moselle', '55' => 'Meuse', '56' => 'Morbihan', '57' => 'Moselle', '58' => 'Nièvre', '59' => 'Nord', '60' => 'Oise', '61' => 'Orne', '62' => 'Pas-de-Calais', '63' => 'Puy-de-Dôme', '64' => 'Pyrénées-Atlantiques', '65' => 'Hautes-Pyrénées', '66' => 'Pyrénées-Orientales', '67' => 'Bas-Rhin', '68' => 'Haut-Rhin', '69' => 'Rhône', '70' => 'Haute-Saône', '71' => 'Saône-et-Loire', '72' => 'Sarthe', '73' => 'Savoie', '74' => 'Haute-Savoie', '75' => 'Paris', '76' => 'Seine-Maritime', '77' => 'Seine-et-Marne', '78' => 'Yvelines', '79' => 'Deux-Sèvres', '80' => 'Somme', '81' => 'Tarn', '82' => 'Tarn-et-Garonne', '83' => 'Var', '84' => 'Vaucluse', '85' => 'Vendée', '86' => 'Vienne', '87' => 'Haute-Vienne', '88' => 'Vosges', '89' => 'Yonne', '90' => 'Territoire-de-Belfort', '91' => 'Essonne', '92' => 'Hauts-de-Seine', '93' => 'Seine-Saint-Denis', '94' => 'Val-de-Marne', '95' => 'Val-d\'Oise', ], 'RO' => [ 'AB' => 'Alba', 'AR' => 'Arad', 'AG' => 'Argeş', 'BC' => 'Bacău', 'BH' => 'Bihor', 'BN' => 'Bistriţa-Năsăud', 'BT' => 'Botoşani', 'BV' => 'Braşov', 'BR' => 'Brăila', 'B' => 'Bucureşti', 'BZ' => 'Buzău', 'CS' => 'Caraş-Severin', 'CL' => 'Călăraşi', 'CJ' => 'Cluj', 'CT' => 'Constanţa', 'CV' => 'Covasna', 'DB' => 'Dâmboviţa', 'DJ' => 'Dolj', 'GL' => 'Galaţi', 'GR' => 'Giurgiu', 'GJ' => 'Gorj', 'HR' => 'Harghita', 'HD' => 'Hunedoara', 'IL' => 'Ialomiţa', 'IS' => 'Iaşi', 'IF' => 'Ilfov', 'MM' => 'Maramureş', 'MH' => 'Mehedinţi', 'MS' => 'Mureş', 'NT' => 'Neamţ', 'OT' => 'Olt', 'PH' => 'Prahova', 'SM' => 'Satu-Mare', 'SJ' => 'Sălaj', 'SB' => 'Sibiu', 'SV' => 'Suceava', 'TR' => 'Teleorman', 'TM' => 'Timiş', 'TL' => 'Tulcea', 'VS' => 'Vaslui', 'VL' => 'Vâlcea', 'VN' => 'Vrancea', ], 'FI' => [ 'Lappi' => 'Lappi', 'Pohjois-Pohjanmaa' => 'Pohjois-Pohjanmaa', 'Kainuu' => 'Kainuu', 'Pohjois-Karjala' => 'Pohjois-Karjala', 'Pohjois-Savo' => 'Pohjois-Savo', 'Etelä-Savo' => 'Etelä-Savo', 'Etelä-Pohjanmaa' => 'Etelä-Pohjanmaa', 'Pohjanmaa' => 'Pohjanmaa', 'Pirkanmaa' => 'Pirkanmaa', 'Satakunta' => 'Satakunta', 'Keski-Pohjanmaa' => 'Keski-Pohjanmaa', 'Keski-Suomi' => 'Keski-Suomi', 'Varsinais-Suomi' => 'Varsinais-Suomi', 'Etelä-Karjala' => 'Etelä-Karjala', 'Päijät-Häme' => 'Päijät-Häme', 'Kanta-Häme' => 'Kanta-Häme', 'Uusimaa' => 'Uusimaa', 'Itä-Uusimaa' => 'Itä-Uusimaa', 'Kymenlaakso' => 'Kymenlaakso', 'Ahvenanmaa' => 'Ahvenanmaa', ], 'EE' => [ 'EE-37' => 'Harjumaa', 'EE-39' => 'Hiiumaa', 'EE-44' => 'Ida-Virumaa', 'EE-49' => 'Jõgevamaa', 'EE-51' => 'Järvamaa', 'EE-57' => 'Läänemaa', 'EE-59' => 'Lääne-Virumaa', 'EE-65' => 'Põlvamaa', 'EE-67' => 'Pärnumaa', 'EE-70' => 'Raplamaa', 'EE-74' => 'Saaremaa', 'EE-78' => 'Tartumaa', 'EE-82' => 'Valgamaa', 'EE-84' => 'Viljandimaa', 'EE-86' => 'Võrumaa', ], 'LV' => [ 'LV-DGV' => 'Daugavpils', 'LV-JEL' => 'Jelgava', 'Jēkabpils' => 'Jēkabpils', 'LV-JUR' => 'Jūrmala', 'LV-LPX' => 'Liepāja', 'LV-LE' => 'Liepājas novads', 'LV-REZ' => 'Rēzekne', 'LV-RIX' => 'Rīga', 'LV-RI' => 'Rīgas novads', 'Valmiera' => 'Valmiera', 'LV-VEN' => 'Ventspils', 'Aglonas novads' => 'Aglonas novads', 'LV-AI' => 'Aizkraukles novads', 'Aizputes novads' => 'Aizputes novads', 'Aknīstes novads' => 'Aknīstes novads', 'Alojas novads' => 'Alojas novads', 'Alsungas novads' => 'Alsungas novads', 'LV-AL' => 'Alūksnes novads', 'Amatas novads' => 'Amatas novads', 'Apes novads' => 'Apes novads', 'Auces novads' => 'Auces novads', 'Babītes novads' => 'Babītes novads', 'Baldones novads' => 'Baldones novads', 'Baltinavas novads' => 'Baltinavas novads', 'LV-BL' => 'Balvu novads', 'LV-BU' => 'Bauskas novads', 'Beverīnas novads' => 'Beverīnas novads', 'Brocēnu novads' => 'Brocēnu novads', 'Burtnieku novads' => 'Burtnieku novads', 'Carnikavas novads' => 'Carnikavas novads', 'Cesvaines novads' => 'Cesvaines novads', 'Ciblas novads' => 'Ciblas novads', 'LV-CE' => 'Cēsu novads', 'Dagdas novads' => 'Dagdas novads', 'LV-DA' => 'Daugavpils novads', 'LV-DO' => 'Dobeles novads', 'Dundagas novads' => 'Dundagas novads', 'Durbes novads' => 'Durbes novads', 'Engures novads' => 'Engures novads', 'Garkalnes novads' => 'Garkalnes novads', 'Grobiņas novads' => 'Grobiņas novads', 'LV-GU' => 'Gulbenes novads', 'Iecavas novads' => 'Iecavas novads', 'Ikšķiles novads' => 'Ikšķiles novads', 'Ilūkstes novads' => 'Ilūkstes novads', 'Inčukalna novads' => 'Inčukalna novads', 'Jaunjelgavas novads' => 'Jaunjelgavas novads', 'Jaunpiebalgas novads' => 'Jaunpiebalgas novads', 'Jaunpils novads' => 'Jaunpils novads', 'LV-JL' => 'Jelgavas novads', 'LV-JK' => 'Jēkabpils novads', 'Kandavas novads' => 'Kandavas novads', 'Kokneses novads' => 'Kokneses novads', 'Krimuldas novads' => 'Krimuldas novads', 'Krustpils novads' => 'Krustpils novads', 'LV-KR' => 'Krāslavas novads', 'LV-KU' => 'Kuldīgas novads', 'Kārsavas novads' => 'Kārsavas novads', 'Lielvārdes novads' => 'Lielvārdes novads', 'LV-LM' => 'Limbažu novads', 'Lubānas novads' => 'Lubānas novads', 'LV-LU' => 'Ludzas novads', 'Līgatnes novads' => 'Līgatnes novads', 'Līvānu novads' => 'Līvānu novads', 'LV-MA' => 'Madonas novads', 'Mazsalacas novads' => 'Mazsalacas novads', 'Mālpils novads' => 'Mālpils novads', 'Mārupes novads' => 'Mārupes novads', 'Naukšēnu novads' => 'Naukšēnu novads', 'Neretas novads' => 'Neretas novads', 'Nīcas novads' => 'Nīcas novads', 'LV-OG' => 'Ogres novads', 'Olaines novads' => 'Olaines novads', 'Ozolnieku novads' => 'Ozolnieku novads', 'LV-PR' => 'Preiļu novads', 'Priekules novads' => 'Priekules novads', 'Priekuļu novads' => 'Priekuļu novads', 'Pārgaujas novads' => 'Pārgaujas novads', 'Pāvilostas novads' => 'Pāvilostas novads', 'Pļaviņu novads' => 'Pļaviņu novads', 'Raunas novads' => 'Raunas novads', 'Riebiņu novads' => 'Riebiņu novads', 'Rojas novads' => 'Rojas novads', 'Ropažu novads' => 'Ropažu novads', 'Rucavas novads' => 'Rucavas novads', 'Rugāju novads' => 'Rugāju novads', 'Rundāles novads' => 'Rundāles novads', 'LV-RE' => 'Rēzeknes novads', 'Rūjienas novads' => 'Rūjienas novads', 'Salacgrīvas novads' => 'Salacgrīvas novads', 'Salas novads' => 'Salas novads', 'Salaspils novads' => 'Salaspils novads', 'LV-SA' => 'Saldus novads', 'Saulkrastu novads' => 'Saulkrastu novads', 'Siguldas novads' => 'Siguldas novads', 'Skrundas novads' => 'Skrundas novads', 'Skrīveru novads' => 'Skrīveru novads', 'Smiltenes novads' => 'Smiltenes novads', 'Stopiņu novads' => 'Stopiņu novads', 'Strenču novads' => 'Strenču novads', 'Sējas novads' => 'Sējas novads', 'LV-TA' => 'Talsu novads', 'LV-TU' => 'Tukuma novads', 'Tērvetes novads' => 'Tērvetes novads', 'Vaiņodes novads' => 'Vaiņodes novads', 'LV-VK' => 'Valkas novads', 'LV-VM' => 'Valmieras novads', 'Varakļānu novads' => 'Varakļānu novads', 'Vecpiebalgas novads' => 'Vecpiebalgas novads', 'Vecumnieku novads' => 'Vecumnieku novads', 'LV-VE' => 'Ventspils novads', 'Viesītes novads' => 'Viesītes novads', 'Viļakas novads' => 'Viļakas novads', 'Viļānu novads' => 'Viļānu novads', 'Vārkavas novads' => 'Vārkavas novads', 'Zilupes novads' => 'Zilupes novads', 'Ādažu novads' => 'Ādažu novads', 'Ērgļu novads' => 'Ērgļu novads', 'Ķeguma novads' => 'Ķeguma novads', 'Ķekavas novads' => 'Ķekavas novads', ], 'LT' => [ 'LT-AL' => 'Alytaus Apskritis', 'LT-KU' => 'Kauno Apskritis', 'LT-KL' => 'Klaipėdos Apskritis', 'LT-MR' => 'Marijampolės Apskritis', 'LT-PN' => 'Panevėžio Apskritis', 'LT-SA' => 'Šiaulių Apskritis', 'LT-TA' => 'Tauragės Apskritis', 'LT-TE' => 'Telšių Apskritis', 'LT-UT' => 'Utenos Apskritis', 'LT-VL' => 'Vilniaus Apskritis', ], 'CN' => [ 'BJ' => '北京市', 'SH' => '上海市', 'TJ' => '天津市', 'CQ' => '重庆市', 'HEB' => '河北省', 'SAX' => '山西省', 'LN' => '辽宁省', 'JL' => '吉林省', 'HLJ' => '黑龙江省', 'JS' => '江苏省', 'ZJ' => '浙江省', 'AH' => '安徽省', 'FJ' => '福建省', 'JX' => '江西省', 'SD' => '山东省', 'HEN' => '河南省', 'HUB' => '湖北省', 'HUN' => '湖南省', 'GD' => '广东省', 'HN' => '海南省', 'SC' => '四川省', 'HZ' => '贵州省', 'YN' => '云南省', 'SNX' => '陕西省', 'GS' => '甘肃省', 'QH' => '青海省', 'TW' => '台湾省', 'GX' => '广西壮族自治区', 'NMG' => '内蒙古自治区', 'XZ' => '西藏自治区', 'NX' => '宁夏回族自治区', 'XJ' => '新疆维吾尔自治区', 'XG' => '香港特别行政区', ], 'ZA' => [ // 南非 'EC' => 'Eastern Cape', 'FS' => 'Free State', 'GT' => 'Gauteng', 'KZN' => 'KwaZulu-Natal', 'LP' => 'Limpopo', 'ML' => 'Mpumalange', 'NC' => 'Northern Cape', 'NW' => 'North West', 'WC' => 'Western Cape', ], ]; return $data; }
得到国家和省市数组 格式为: [ 国家简码 => [ 省/市简码 => 省/市名称, 省/市简码 => 省/市名称, 省/市简码 => 省/市名称, ] ] ] 在选择国家后,省市的信息会以ajax的形式带出,存在以下列表的国家,会以下拉选择条 的方式显示,如果不存在以下列表,则显示inputtext输入框,如果您想要某个国家的省市以 下拉条的方式选择,可以在下面的函数里面添加对应的国家和省市信息,添加后 选择国家后,省市会以下拉条的方式供用户选择,而不是inputtext填写省市信息。
getCountryStateArr
php
fecshop/yii2_fecshop
services/helper/Country.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Country.php
BSD-3-Clause
public function countryCallingCodes(){ return [ 'BD' => '+880', 'BE' => '+32', 'BF' => '+226', 'BG' => '+359', 'BA' => '+387', 'BB' => '+1246', 'WF' => '+681', 'BL' => '+590', 'BM' => '+1441', 'BN' => '+673', 'BO' => '+591', 'BH' => '+973', 'BI' => '+257', 'BJ' => '+229', 'BT' => '+975', 'JM' => '+1876', 'BV' => '', 'BW' => '+267', 'WS' => '+685', 'BQ' => '+599', 'BR' => '+55', 'BS' => '+1242', 'JE' => '+441534', 'BY' => '+375', 'BZ' => '+501', 'RU' => '+7', 'RW' => '+250', 'RS' => '+381', 'TL' => '+670', 'RE' => '+262', 'TM' => '+993', 'TJ' => '+992', 'RO' => '+40', 'TK' => '+690', 'GW' => '+245', 'GU' => '+1671', 'GT' => '+502', 'GS' => '', 'GR' => '+30', 'GQ' => '+240', 'GP' => '+590', 'JP' => '+81', 'GY' => '+592', 'GG' => '+441481', 'GF' => '+594', 'GE' => '+995', 'GD' => '+1473', 'GB' => '+44', 'GA' => '+241', 'SV' => '+503', 'GN' => '+224', 'GM' => '+220', 'GL' => '+299', 'GI' => '+350', 'GH' => '+233', 'OM' => '+968', 'TN' => '+216', 'JO' => '+962', 'HR' => '+385', 'HT' => '+509', 'HU' => '+36', 'HK' => '+852', 'HN' => '+504', 'HM' => '', 'VE' => '+58', 'PR' => array( '+1787', '+1939', ), 'PS' => '+970', 'PW' => '+680', 'PT' => '+351', 'SJ' => '+47', 'PY' => '+595', 'IQ' => '+964', 'PA' => '+507', 'PF' => '+689', 'PG' => '+675', 'PE' => '+51', 'PK' => '+92', 'PH' => '+63', 'PN' => '+870', 'PL' => '+48', 'PM' => '+508', 'ZM' => '+260', 'EH' => '+212', 'EE' => '+372', 'EG' => '+20', 'ZA' => '+27', 'EC' => '+593', 'IT' => '+39', 'VN' => '+84', 'SB' => '+677', 'ET' => '+251', 'SO' => '+252', 'ZW' => '+263', 'SA' => '+966', 'ES' => '+34', 'ER' => '+291', 'ME' => '+382', 'MD' => '+373', 'MG' => '+261', 'MF' => '+590', 'MA' => '+212', 'MC' => '+377', 'UZ' => '+998', 'MM' => '+95', 'ML' => '+223', 'MO' => '+853', 'MN' => '+976', 'MH' => '+692', 'MK' => '+389', 'MU' => '+230', 'MT' => '+356', 'MW' => '+265', 'MV' => '+960', 'MQ' => '+596', 'MP' => '+1670', 'MS' => '+1664', 'MR' => '+222', 'IM' => '+441624', 'UG' => '+256', 'TZ' => '+255', 'MY' => '+60', 'MX' => '+52', 'IL' => '+972', 'FR' => '+33', 'IO' => '+246', 'SH' => '+290', 'FI' => '+358', 'FJ' => '+679', 'FK' => '+500', 'FM' => '+691', 'FO' => '+298', 'NI' => '+505', 'NL' => '+31', 'NO' => '+47', 'NA' => '+264', 'VU' => '+678', 'NC' => '+687', 'NE' => '+227', 'NF' => '+672', 'NG' => '+234', 'NZ' => '+64', 'NP' => '+977', 'NR' => '+674', 'NU' => '+683', 'CK' => '+682', 'XK' => '', 'CI' => '+225', 'CH' => '+41', 'CO' => '+57', 'CN' => '+86', 'CM' => '+237', 'CL' => '+56', 'CC' => '+61', 'CA' => '+1', 'CG' => '+242', 'CF' => '+236', 'CD' => '+243', 'CZ' => '+420', 'CY' => '+357', 'CX' => '+61', 'CR' => '+506', 'CW' => '+599', 'CV' => '+238', 'CU' => '+53', 'SZ' => '+268', 'SY' => '+963', 'SX' => '+599', 'KG' => '+996', 'KE' => '+254', 'SS' => '+211', 'SR' => '+597', 'KI' => '+686', 'KH' => '+855', 'KN' => '+1869', 'KM' => '+269', 'ST' => '+239', 'SK' => '+421', 'KR' => '+82', 'SI' => '+386', 'KP' => '+850', 'KW' => '+965', 'SN' => '+221', 'SM' => '+378', 'SL' => '+232', 'SC' => '+248', 'KZ' => '+7', 'KY' => '+1345', 'SG' => '+65', 'SE' => '+46', 'SD' => '+249', 'DO' => array( '+1809', '+1829', '+1849', ), 'DM' => '+1767', 'DJ' => '+253', 'DK' => '+45', 'VG' => '+1284', 'DE' => '+49', 'YE' => '+967', 'DZ' => '+213', 'US' => '+1', 'UY' => '+598', 'YT' => '+262', 'UM' => '+1', 'LB' => '+961', 'LC' => '+1758', 'LA' => '+856', 'TV' => '+688', 'TW' => '+886', 'TT' => '+1868', 'TR' => '+90', 'LK' => '+94', 'LI' => '+423', 'LV' => '+371', 'TO' => '+676', 'LT' => '+370', 'LU' => '+352', 'LR' => '+231', 'LS' => '+266', 'TH' => '+66', 'TF' => '', 'TG' => '+228', 'TD' => '+235', 'TC' => '+1649', 'LY' => '+218', 'VA' => '+379', 'VC' => '+1784', 'AE' => '+971', 'AD' => '+376', 'AG' => '+1268', 'AF' => '+93', 'AI' => '+1264', 'VI' => '+1340', 'IS' => '+354', 'IR' => '+98', 'AM' => '+374', 'AL' => '+355', 'AO' => '+244', 'AQ' => '', 'AS' => '+1684', 'AR' => '+54', 'AU' => '+61', 'AT' => '+43', 'AW' => '+297', 'IN' => '+91', 'AX' => '+35818', 'AZ' => '+994', 'IE' => '+353', 'ID' => '+62', 'UA' => '+380', 'QA' => '+974', 'MZ' => '+258', ]; }
各个国家的手机号前缀
countryCallingCodes
php
fecshop/yii2_fecshop
services/helper/Country.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Country.php
BSD-3-Clause
public function add($errors, $arr = []) { if ($errors) { $errors = Yii::$service->page->translate->__($errors, $arr); $this->_errors[] = $errors; } }
添加一条错误信息 @param string $errors 错误信息,支持模板格式 @param array $arr 错误信息模板中变量替换对应的数组 Yii::$service->helper->errors->add('Hello, {username}!', ['username' => $username])
add
php
fecshop/yii2_fecshop
services/helper/Errors.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Errors.php
BSD-3-Clause
public function get($separator = false) { if ($errors = $this->_errors) { $this->_errors = false; if (is_array($errors) && !empty($errors)) { if ($separator) { if ($separator === true) { $separator = '|'; } return implode($separator, $errors); } else { return $errors; } } } return false; }
@param $separator 如果是false,则返回数组, 如果是true则返回用| 分隔的字符串 如果是传递的分隔符的值,譬如“,”,则返回用这个分隔符分隔的字符串
get
php
fecshop/yii2_fecshop
services/helper/Errors.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Errors.php
BSD-3-Clause
public function saveByErrorHandler( $code, $message, $file, $line, $created_at, $ip, $name, $trace_string, $url, $req_info=[] ) { $category = Yii::$service->helper->getAppName(); $model = new $this->_errorHandlerModelName(); $model->category = $category; $model->code = $code; $model->message = $message; $model->file = $file; $model->line = $line; $model->created_at = $created_at; $model->ip = $ip; $model->name = $name; $model->url = $url; $model->request_info = serialize($req_info); $model->trace_string = $trace_string; $model->save(); return (string)$model[$this->getPrimaryKey()]; }
@param $code | Int, http 错误码 @param $message | String, 错误的具体信息 @param $file | string, 发生错误的文件 @param $line | Int, 发生错误所在文件的代码行 @param $created_at | Int, 发生错误的执行时间戳 @param $ip | string, 访问人的ip @param $name | string, 错误的名字 @param $trace_string | string, 错误的追踪信息 @return 返回错误存储到mongodb的id,作为前端显示的错误编码 该函数从errorHandler得到错误信息,然后保存到mongodb中。
saveByErrorHandler
php
fecshop/yii2_fecshop
services/helper/errorhandler/ErrorHandlerMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/errorhandler/ErrorHandlerMysqldb.php
BSD-3-Clause
public function getByPrimaryKey($primaryKey) { if ($primaryKey) { return $this->_errorHandlerModel->findOne($primaryKey); } }
通过主键,得到errorHandler对象。
getByPrimaryKey
php
fecshop/yii2_fecshop
services/helper/errorhandler/ErrorHandlerMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/errorhandler/ErrorHandlerMysqldb.php
BSD-3-Clause
public function saveByErrorHandler( $code, $message, $file, $line, $created_at, $ip, $name, $trace_string, $url, $req_info=[] ) { $category = Yii::$service->helper->getAppName(); $model = new $this->_errorHandlerModelName(); $model->category = $category; $model->code = $code; $model->message = $message; $model->file = $file; $model->line = $line; $model->created_at = $created_at; $model->ip = $ip; $model->name = $name; $model->url = $url; $model->request_info = $req_info; $model->trace_string = $trace_string; $model->save(); return (string)$model[$this->getPrimaryKey()]; }
@param $code | Int, http 错误码 @param $message | String, 错误的具体信息 @param $file | string, 发生错误的文件 @param $line | Int, 发生错误所在文件的代码行 @param $created_at | Int, 发生错误的执行时间戳 @param $ip | string, 访问人的ip @param $name | string, 错误的名字 @param $trace_string | string, 错误的追踪信息 @return 返回错误存储到mongodb的id,作为前端显示的错误编码 该函数从errorHandler得到错误信息,然后保存到mongodb中。
saveByErrorHandler
php
fecshop/yii2_fecshop
services/helper/errorhandler/ErrorHandlerMongodb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/errorhandler/ErrorHandlerMongodb.php
BSD-3-Clause
public function getByPrimaryKey($primaryKey) { if ($primaryKey) { return $this->_errorHandlerModel->findOne($primaryKey); } }
通过主键,得到errorHandler对象。
getByPrimaryKey
php
fecshop/yii2_fecshop
services/helper/errorhandler/ErrorHandlerMongodb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/errorhandler/ErrorHandlerMongodb.php
BSD-3-Clause
public function getSearchProductColl($select, $where, $pageNum, $numPerPage, $product_search_max_count) { // 先进行sku搜索,如果有结果,说明是针对sku的搜索 $enableStatus = Yii::$service->product->getEnableStatus(); $searchText = $where['$text']['$search']; $productM = Yii::$service->product->getBySku($searchText); if ($productM && $enableStatus == $productM['status']) { $collection['coll'][] = $productM; $collection['count'] = 1; } else { $filter = [ 'pageNum' => $pageNum, 'numPerPage' => $numPerPage, 'where' => $where, 'product_search_max_count' => $product_search_max_count, 'select' => $select, ]; $collection = $this->fullTearchText($filter); } $collection['coll'] = Yii::$service->category->product->convertToCategoryInfo($collection['coll']); return $collection; }
@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/MongoSearch.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/search/MongoSearch.php
BSD-3-Clause
public function initFullSearchIndex() { return; }
创建索引. (mysql不需要)
initFullSearchIndex
php
fecshop/yii2_fecshop
services/search/MysqlSearch.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/search/MysqlSearch.php
BSD-3-Clause
protected function getActiveLangCode() { if (!$this->_searchLangCode) { $langArr = Yii::$app->store->get('mutil_lang'); foreach ($langArr as $one) { if ($one['search_engine'] == 'mysqlSearch') { $this->_searchLangCode[] = $one['lang_code']; } } } return $this->_searchLangCode; }
从配置中得到当前的搜索引擎对应的有效语言。
getActiveLangCode
php
fecshop/yii2_fecshop
services/search/MysqlSearch.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/search/MysqlSearch.php
BSD-3-Clause
public function getSearchProductColl($select, $where, $pageNum, $numPerPage, $product_search_max_count) { // 先进行sku搜索,如果有结果,说明是针对sku的搜索 $enableStatus = Yii::$service->product->getEnableStatus(); $searchText = $where['$text']['$search']; $productM = Yii::$service->product->getBySku($searchText); if ($productM && $enableStatus == $productM['status']) { $collection['coll'][] = $productM; $collection['count'] = 1; } else { $filter = [ 'pageNum' => $pageNum, 'numPerPage' => $numPerPage, 'where' => $where, 'product_search_max_count' => $product_search_max_count, 'select' => $select, ]; $collection = $this->fullTearchText($filter); } $collection['coll'] = Yii::$service->category->product->convertToCategoryInfo($collection['coll']); return $collection; }
@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/MysqlSearch.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/search/MysqlSearch.php
BSD-3-Clause
public function getFrontSearchFilter($filter_attr, $where) { return []; }
@param $filter_attr | String 需要进行统计的字段名称 @propertuy $where | Array 搜索条件。这个需要些mongodb的搜索条件。 得到的是个属性,以及对应的个数。 这个功能是用于前端分类侧栏进行属性过滤。 mysql 功能受限,这个废掉了。
getFrontSearchFilter
php
fecshop/yii2_fecshop
services/search/MysqlSearch.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/search/MysqlSearch.php
BSD-3-Clause
public function initFullSearchIndex() { }
初始化xunSearch索引.
initFullSearchIndex
php
fecshop/yii2_fecshop
services/search/XunSearch.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/search/XunSearch.php
BSD-3-Clause
public function getSearchProductColl($select, $where, $pageNum, $numPerPage, $product_search_max_count) { $collection = $this->fullTearchText($select, $where, $pageNum, $numPerPage, $product_search_max_count); $collection['coll'] = Yii::$service->category->product->convertToCategoryInfo($collection['coll']); return $collection; }
得到搜索的产品列表.
getSearchProductColl
php
fecshop/yii2_fecshop
services/search/XunSearch.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/search/XunSearch.php
BSD-3-Clause
public function getFrontSearchFilter($filter_attr, $where) { $dbName = $this->_searchModel->projectName(); $_search = Yii::$app->xunsearch->getDatabase($dbName)->getSearch(); $text = isset($where['$text']['$search']) ? $where['$text']['$search'] : ''; if (!$text) { return []; } $sh = ''; foreach ($where as $k => $v) { if ($k != '$text') { if (!$sh) { $sh = ' AND '.$k.':'.$v; } else { $sh .= ' AND '.$k.':'.$v; } } } $docs = $_search->setQuery($text.$sh) ->setFacets([$filter_attr]) ->setFuzzy($this->fuzzy) ->setAutoSynonyms($this->synonyms) ->search(); $filter_attr_counts = $_search->getFacets($filter_attr); $count_arr = []; if (is_array($filter_attr_counts) && !empty($filter_attr_counts)) { foreach ($filter_attr_counts as $k => $v) { $count_arr[] = [ '_id' => $k, 'count' => $v, ]; } } return $count_arr; }
得到搜索的sku列表侧栏的过滤.
getFrontSearchFilter
php
fecshop/yii2_fecshop
services/search/XunSearch.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/search/XunSearch.php
BSD-3-Clause
public function removeByProductId($product_id) { if (is_object($product_id)) { $product_id = (string) $product_id; $model = $this->_searchModel->findOne($product_id); if ($model) { $model->delete(); } } }
通过product_id删除搜索数据.
removeByProductId
php
fecshop/yii2_fecshop
services/search/XunSearch.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/search/XunSearch.php
BSD-3-Clause
public function getByPrimaryKey($primaryKey) { $one = $this->_addressModel->findOne($primaryKey); $primaryKey = $this->getPrimaryKey(); if ($one[$primaryKey]) { return $one; } else { return new $this->_addressModelName(); } }
@param $primaryKey | Int @return Object(MyCoupon) 通过id找到customer address的对象
getByPrimaryKey
php
fecshop/yii2_fecshop
services/customer/Address.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/customer/Address.php
BSD-3-Clause
public function getAddressByIdAndCustomerId($address_id, $customer_id) { $primaryKey = $this->getPrimaryKey(); $one = $this->_addressModel->findOne([ $primaryKey => $address_id, 'customer_id' => $customer_id, ]); if ($one[$primaryKey]) { return $one; } else { return false; } }
@param $address_id | Int , address表的id @param $customer_id | Int , 用户id 在这里在主键查询的同时,加入customer_id,这样查询的肯定是这个用户的, 这样就防止有的用户去查询其他用户的address信息。
getAddressByIdAndCustomerId
php
fecshop/yii2_fecshop
services/customer/Address.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/customer/Address.php
BSD-3-Clause
public function save($one) { if (!is_array($one) || empty($one)) { Yii::$service->helper->errors->add('address data is empty'); return false; } $primaryKey = $this->getPrimaryKey(); $primaryVal = isset($one[$primaryKey]) ? $one[$primaryKey] : ''; if ($primaryVal) { $model = $this->_addressModel->findOne($primaryVal); if (!$model) { Yii::$service->helper->errors->add('address {primaryKey} is not exist', ['primaryKey' => $this->getPrimaryKey()]); return false; } } else { $model = new $this->_addressModelName(); $model->created_at = time(); } $model->attributes = $one; // 规则验证 if ($model->validate()) { $model->updated_at = time(); // 保存地址。 $model = Yii::$service->helper->ar->save($model, $one); if (!$model) { return false; } } else { $errors = $model->errors; Yii::$service->helper->errors->addByModelErrors($errors); return false; } $primaryVal = $model[$primaryKey]; if ($one['is_default'] == 1) { $customer_id = $one['customer_id']; if ($customer_id && $primaryVal) { $this->_addressModel->updateAll( ['is_default'=>2], // $attributes 'customer_id = :customer_id and '.$primaryKey.' != :primaryVal ', // $condition [ 'customer_id' => $customer_id, 'primaryVal' => $primaryVal, ] ); } } return $primaryVal; }
@param $one|array , 保存的address数组 @return int 返回保存的 address_id 的值。
save
php
fecshop/yii2_fecshop
services/customer/Address.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/customer/Address.php
BSD-3-Clause
protected function removeCartAddress($customer_id, $address_id) { $cart = Yii::$service->cart->quote->getCartByCustomerId($customer_id); if (isset($cart['customer_address_id']) && !empty($cart['customer_address_id'])) { if ($cart['customer_address_id'] == $address_id) { $cart->customer_address_id = ''; $cart->save(); } } }
@param $customer_id | Int , @param $address_id | Int,address id 删除购物车中的address部分。
removeCartAddress
php
fecshop/yii2_fecshop
services/customer/Address.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/customer/Address.php
BSD-3-Clause
public function setDefault($customer_id, $address_id) { $primaryKey = $this->getPrimaryKey(); // 当前的设置成1 $address_one = $this->_addressModel->findOne([ 'customer_id' => $customer_id, $primaryKey => $address_id, ]); if (!$address_one[$primaryKey]) { Yii::$service->helper->errors->add('customer address is empty'); return false; } $address_one->is_default = 1; $address_one->updated_at = time(); $address_one->save(); // 将其他的设置成2 $this->_addressModel->updateAll( ['is_default'=>2], // $attributes 'customer_id = :customer_id and '.$primaryKey.' != :primaryVal ', // $condition [ 'customer_id' => $customer_id, 'primaryVal' => $address_id, ] ); return true; }
@param $customer_id | int 用户id @param $address_id | int 用户地址id @return boolean 将某个address_id对应的地址数据,设置成默认地址
setDefault
php
fecshop/yii2_fecshop
services/customer/Address.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/customer/Address.php
BSD-3-Clause
public function getDefaultAddress(){ if (Yii::$app->user->isGuest) { Yii::$service->helper->errors->add('customer is guest'); return null; } $identity = Yii::$app->user->identity; $customer_id = $identity->id; $one = $this->_addressModel->findOne([ 'customer_id' => $customer_id, 'is_default' => $this->is_default, ]); if ($one['customer_id']) { return $one; } return null; }
得到登陆用户的默认货运地址。
getDefaultAddress
php
fecshop/yii2_fecshop
services/customer/Address.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/customer/Address.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/customer/Newsletter.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/customer/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/customer/Newsletter.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/customer/Newsletter.php
BSD-3-Clause
public function emailIsExist($emailAddress) { return $this->_newsletter->emailIsExist($emailAddress); }
@param $emailAddress | String @return bool 检查邮件是否之前被订阅过
emailIsExist
php
fecshop/yii2_fecshop
services/customer/Newsletter.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/customer/Newsletter.php
BSD-3-Clause
public function subscribe($emailAddress, $isRegister = false) { return $this->_newsletter->subscribe($emailAddress, $isRegister); }
@param $emailAddress | String @return bool 订阅邮件
subscribe
php
fecshop/yii2_fecshop
services/customer/Newsletter.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/customer/Newsletter.php
BSD-3-Clause
public function getLoginUrl($url, $customDomain = false) { if (!$customDomain) { $redirectUrl = Yii::$service->url->getUrl($url); } else { $redirectUrl = $url; } $thirdLogin = Yii::$service->store->thirdLogin; $this->facebook_app_id = isset($thirdLogin['facebook']['facebook_app_id']) ? $thirdLogin['facebook']['facebook_app_id'] : ''; $this->facebook_app_secret = isset($thirdLogin['facebook']['facebook_app_secret']) ? $thirdLogin['facebook']['facebook_app_secret'] : ''; if (!$this->facebook_app_id || !$this->facebook_app_secret) { return ''; } $fb = new \Facebook\Facebook([ 'app_id' => $this->facebook_app_id, 'app_secret' => $this->facebook_app_secret, 'default_graph_version' => 'v2.10', ]); $helper = $fb->getRedirectLoginHelper(); $permissions = ['email']; // Optional permissions $loginUrl = $helper->getLoginUrl($redirectUrl, $permissions); return $loginUrl; }
@param $url | String , 用于得到返回url的字符串,$customDomain == false时,是urlKey,$customDomain == true时,是完整的url @param $customDomain | boolean, 是否是自定义url @return 得到跳转到facebook登录的url
getLoginUrl
php
fecshop/yii2_fecshop
services/customer/Facebook.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/customer/Facebook.php
BSD-3-Clause
public function getLoginUrl($url, $customDomain = false) { if (!$customDomain) { $redirectUrl = Yii::$service->url->getUrl($url); } else { $redirectUrl = $url; } global $googleapiinfo; $thirdLogin = Yii::$service->store->thirdLogin; $googleapiinfo['GOOGLE_CLIENT_ID'] = isset($thirdLogin['google']['CLIENT_ID']) ? $thirdLogin['google']['CLIENT_ID'] : ''; $googleapiinfo['GOOGLE_CLIENT_SECRET'] = isset($thirdLogin['google']['CLIENT_SECRET']) ? $thirdLogin['google']['CLIENT_SECRET'] : ''; //echo $lib_google_base.'/Social.php';exit; if (!$googleapiinfo['GOOGLE_CLIENT_ID'] || !$googleapiinfo['GOOGLE_CLIENT_SECRET'] ) { return ''; } $lib_google_base = Yii::getAlias('@fecshop/lib/google'); include $lib_google_base.'/Social.php'; $Social_obj = new \Social($redirectUrl, 1); $url = $Social_obj->google(); return $url; }
@param $url | String , 用于得到返回url的字符串,$customDomain == false时,是urlKey,$customDomain == true时,是完整的url @param $customDomain | boolean, 是否是自定义url @return 得到跳转到google登录的url
getLoginUrl
php
fecshop/yii2_fecshop
services/customer/Google.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/customer/Google.php
BSD-3-Clause
protected function emailIsExist($emailAddress) { $primaryKey = $this->getPrimaryKey(); $one = $this->_newsletterModel->findOne(['email' => $emailAddress]); if ($one[$primaryKey]) { return true; } return false; }
@param $emailAddress | String @return bool 检查邮件是否之前被订阅过
emailIsExist
php
fecshop/yii2_fecshop
services/customer/newsletter/NewsletterMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/customer/newsletter/NewsletterMysqldb.php
BSD-3-Clause
protected function emailIsExist($emailAddress) { $primaryKey = $this->_newsletterModel->primaryKey(); $one = $this->_newsletterModel->findOne(['email' => $emailAddress]); if ($one[$primaryKey]) { return true; } return false; }
@param $emailAddress | String @return bool 检查邮件是否之前被订阅过
emailIsExist
php
fecshop/yii2_fecshop
services/customer/newsletter/NewsletterMongodb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/customer/newsletter/NewsletterMongodb.php
BSD-3-Clause
protected function serializeSaveData($one) { if (!is_array($one) && !is_object($one)) { return $one; } foreach ($one as $k => $v) { if (in_array($k, $this->serializeAttrs)) { $one[$k] = serialize($v); } } return $one; }
保存的数据进行serialize序列化
serializeSaveData
php
fecshop/yii2_fecshop
services/category/CategoryMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMysqldb.php
BSD-3-Clause
protected function unserializeData($one) { if (!is_array($one) && !is_object($one)) { return $one; } foreach ($one as $k => $v) { if (in_array($k, $this->serializeAttrs)) { $one[$k] = unserialize($v); } } return $one; }
保存的数据进行serialize序列化
unserializeData
php
fecshop/yii2_fecshop
services/category/CategoryMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMysqldb.php
BSD-3-Clause
public function getByPrimaryKey($primaryKey) { if ($primaryKey) { $one = $this->_categoryModel->findOne($primaryKey); return $this->unserializeData($one) ; } else { return new $this->_categoryModelName; } }
通过主键,得到Category对象。
getByPrimaryKey
php
fecshop/yii2_fecshop
services/category/CategoryMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMysqldb.php
BSD-3-Clause
public function findOne($where) { $one = $this->_categoryModel->findOne($where); return $this->unserializeData($one) ; }
通过主键,得到Category对象。
findOne
php
fecshop/yii2_fecshop
services/category/CategoryMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMysqldb.php
BSD-3-Clause
public function getByUrlKey($urlKey) { if ($urlKey) { $urlKey = "/".trim($urlKey, "/"); $one = $this->_categoryModel->findOne(['url_key' => $urlKey]); return $this->unserializeData($one) ; } else { return new $this->_categoryModelName; } }
通过url_key,得到Category对象。
getByUrlKey
php
fecshop/yii2_fecshop
services/category/CategoryMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMysqldb.php
BSD-3-Clause
public function getPrimaryKey() { return 'id'; }
返回主键。
getPrimaryKey
php
fecshop/yii2_fecshop
services/category/CategoryMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMysqldb.php
BSD-3-Clause
public function getCategoryEnableStatus() { $model = $this->_categoryModel; return $model::STATUS_ENABLE; }
得到分类激活状态的值
getCategoryEnableStatus
php
fecshop/yii2_fecshop
services/category/CategoryMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMysqldb.php
BSD-3-Clause
public function getCategoryMenuShowStatus() { $model = $this->_categoryModel; return $model::MENU_SHOW; }
得到分类在menu中显示的状态值
getCategoryMenuShowStatus
php
fecshop/yii2_fecshop
services/category/CategoryMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMysqldb.php
BSD-3-Clause
public function apiColl($filter = '') { $query = $this->_categoryModel->find(); $query = Yii::$service->helper->ar->getCollByFilter($query, $filter); $coll = $query->all(); return [ 'coll' => $coll, 'count'=> $query->limit(null)->offset(null)->count(), ]; }
和coll函数类型,但是,对于查询出来的数据不做任何处理
apiColl
php
fecshop/yii2_fecshop
services/category/CategoryMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMysqldb.php
BSD-3-Clause
public function collCount($filter = '') { $query = $this->_categoryModel->find(); $query = Yii::$service->helper->ar->getCollByFilter($query, $filter); return $query->count(); }
得到总数.
collCount
php
fecshop/yii2_fecshop
services/category/CategoryMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMysqldb.php
BSD-3-Clause
public function upsert($one, $originUrlKey = 'catalog/category/index') { $primaryKey = $this->getPrimaryKey(); $primaryVal = isset($one['id']) ? $one['id'] : ''; unset($one['id']); if (!$primaryVal) { Yii::$service->helper->errors->add('id can not empty'); return; } $model = $this->_categoryModel->findOne($primaryVal); if (!$model) { $model = new $this->_categoryModelName; $model[$primaryKey] = $primaryVal; $model->created_at = time(); $model->created_user_id = \fec\helpers\CUser::getCurrentUserId(); } $model->updated_at = time(); $one['status'] = (int)$one['status']; $one['menu_show'] = (int)$one['menu_show']; $allowMenuShowArr = [ $model::MENU_SHOW, $model::MENU_NOT_SHOW]; if (!in_array($one['menu_show'], $allowMenuShowArr)) { $one['menu_show'] = $model::MENU_SHOW; } $allowStatusArr = [ $model::STATUS_ENABLE, $model::STATUS_DISABLE]; if (!in_array($one['status'], $allowStatusArr)) { $one['status'] = $model::STATUS_ENABLE; } $defaultLangName = Yii::$service->fecshoplang->getDefaultLangAttrVal($one['name'], 'name'); $one = $this->serializeSaveData($one); $saveStatus = Yii::$service->helper->ar->save($model, $one); $primaryVal = $model->id; $originUrl = $originUrlKey.'?'.$this->getPrimaryKey() .'='. $primaryVal; $originUrlKey = isset($one['url_key']) ? $one['url_key'] : ''; $defaultLangTitle = $defaultLangName; $urlKey = Yii::$service->url->saveRewriteUrlKeyByStr($defaultLangTitle, $originUrl, $originUrlKey); $model->url_key = $urlKey; $model->save(); return $model; }
@param $one|array , upsert one data . 分类数组 @param $originUrlKey|string , 分类的在修改之前的url key.(在数据库中保存的url_key字段,如果没有则为空) 保存分类,同时生成分类的伪静态url(自定义url),如果按照name生成的url或者自定义的urlkey存在,系统则会增加几个随机数字字符串,来增加唯一性。 upsert,就是update和insert的结合体,如果当前$one['id']对应的分类存在则更新,如果不存在则插入
upsert
php
fecshop/yii2_fecshop
services/category/CategoryMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMysqldb.php
BSD-3-Clause
public function sync($arr) { $originUrlKey = 'catalog/category/index'; $origin_mongo_parent_id = $arr['parent_id']; $origin_mongo_id = $arr['_id']; unset($arr['parent_id']); unset($arr['_id']); $model = $this->_categoryModel->findOne([ 'origin_mongo_id' => $origin_mongo_id ]); if (!$model['origin_mongo_id']) { $model = new $this->_categoryModelName; $model->created_at = time(); } $model->origin_mongo_id = $origin_mongo_id; $model->origin_mongo_parent_id = $origin_mongo_parent_id; $arr = $this->serializeSaveData($arr); $saveStatus = Yii::$service->helper->ar->save($model, $arr); $originUrl = $originUrlKey.'?'.$this->getPrimaryKey() .'='. $model->id; $originUrlKey = isset($model['url_key']) ? $model['url_key'] : ''; $defaultLangTitle = Yii::$service->fecshoplang->getDefaultLangAttrVal($arr['name'], 'name'); $urlKey = Yii::$service->url->saveRewriteUrlKeyByStr($defaultLangTitle, $originUrl, $originUrlKey); $model->url_key = $urlKey; return $model->save(); }
@param $arr | array 用于同步mongodb数据库到mysql数据库中
sync
php
fecshop/yii2_fecshop
services/category/CategoryMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMysqldb.php
BSD-3-Clause
public function getAllParentInfo($parent_id) { if ($parent_id) { $parentModel = $this->_categoryModel->findOne($parent_id); $parentModel =$this->unserializeData($parentModel) ; $parent_parent_id = $parentModel['parent_id']; $parent_category = []; if ($parent_parent_id !== 0) { $parent_category[] = [ 'name' => $parentModel['name'], 'url_key'=>$parentModel['url_key'], ]; $parent_category = array_merge($this->getAllParentInfo($parent_parent_id), $parent_category); } else { $parent_category[] = [ 'name' => $parentModel['name'], 'url_key'=>$parentModel['url_key'], ]; } return $parent_category; } }
@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/CategoryMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMysqldb.php
BSD-3-Clause
public function getFilterCategory($category_id, $parent_id) { $returnData = []; $primaryKey = $this->getPrimaryKey(); $currentCategory = $this->_categoryModel->findOne($category_id); $currentCategory =$this->unserializeData($currentCategory) ; $currentUrlKey = $currentCategory['url_key']; $currentName = $currentCategory['name']; $currentId = $currentCategory['id']; $returnData['current'] = [ '_id' => $currentId, 'name' => $currentName, 'url_key' => $currentUrlKey, 'parent_id' => $currentCategory['parent_id'], ]; if ($currentCategory['parent_id']) { $allParent = $this->getParentCategory($currentCategory['parent_id']); $allParent[] = $returnData['current']; $data = $this->getAllParentCate($allParent); } else { $data = $this->getOneLevelCateChild($returnData['current']); } return $data; }
@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/CategoryMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMysqldb.php
BSD-3-Clause
public function excelSave($one, $originUrlKey = 'catalog/category/index') { $parent_id = $one['parent_id']; $currentDateTime = \fec\helpers\CDate::getCurrentDateTime(); $primaryVal = isset($one[$this->getPrimaryKey()]) ? $one[$this->getPrimaryKey()] : ''; if (!$primaryVal) { Yii::$service->helper->errors->add('category id can not empty'); return false; } $model = $this->_categoryModel->findOne($primaryVal); if (!isset($model[$this->getPrimaryKey()]) || !$model[$this->getPrimaryKey()]) { $model = new $this->_categoryModelName; $model[$this->getPrimaryKey()] = $one[$this->getPrimaryKey()]; $model->created_at = time(); $model->created_user_id = \fec\helpers\CUser::getCurrentUserId(); } else { // 多语言属性,如果您有其他的多语言属性,可以自行二开添加。 $model = $this->unserializeData($model) ; $name =$model['name']; $title = $model['title']; $meta_keywords = $model['meta_keywords']; $meta_description = $model['meta_description']; $description = $model['description']; //var_dump($title);var_dump($one['title']); if (is_array($one['name']) && !empty($one['name'])) { $one['name'] = array_merge((is_array($name) ? $name : []), $one['name']); } if (is_array($one['title']) && !empty($one['title'])) { $one['title'] = array_merge((is_array($title) ? $title : []), $one['title']); } if (is_array($one['meta_keywords']) && !empty($one['meta_keywords'])) { $one['meta_keywords'] = array_merge((is_array($meta_keywords) ? $meta_keywords : []), $one['meta_keywords']); } if (is_array($one['meta_description']) && !empty($one['meta_description'])) { $one['meta_description'] = array_merge((is_array($meta_description) ? $meta_description : []), $one['meta_description']); } if (is_array($one['description']) && !empty($one['description'])) { $one['description'] = array_merge((is_array($description) ? $description : []), $one['description']); } } // 增加分类的级别字段level,从1级级别开始依次类推。 if ($parent_id == 0) { $model['level'] = 1; } else { $parent_model = $this->_categoryModel->findOne($parent_id); if ($parent_level = $parent_model['level']) { $model['level'] = $parent_level + 1; } } $model->updated_at = time(); unset($one[$this->getPrimaryKey()]); $one['status'] = (int)$one['status']; $one['menu_show'] = (int)$one['menu_show']; $allowMenuShowArr = [ $model::MENU_SHOW, $model::MENU_NOT_SHOW]; if (!in_array($one['menu_show'], $allowMenuShowArr)) { $one['menu_show'] = $model::MENU_SHOW; } $allowStatusArr = [ $model::STATUS_ENABLE, $model::STATUS_DISABLE]; if (!in_array($one['status'], $allowStatusArr)) { $one['status'] = $model::STATUS_ENABLE; } $one = $this->serializeSaveData($one); $saveStatus = Yii::$service->helper->ar->save($model, $one); $primaryVal = $model->id; $originUrl = $originUrlKey.'?'.$this->getPrimaryKey() .'='. $primaryVal; $originUrlKey = isset($one['url_key']) ? $one['url_key'] : ''; $defaultLangTitle = Yii::$service->fecshoplang->getDefaultLangAttrVal($one['name'], 'name'); $urlKey = Yii::$service->url->saveRewriteUrlKeyByStr($defaultLangTitle, $originUrl, $originUrlKey); $model->url_key = $urlKey; $model->save(); return $model; }
@param $one|array , save one data . 分类数组 @param $originUrlKey|string , 分类的在修改之前的url key.(在数据库中保存的url_key字段,如果没有则为空) 保存分类,同时生成分类的伪静态url(自定义url),如果按照name生成的url或者自定义的urlkey存在,系统则会增加几个随机数字字符串,来增加唯一性。 和save方法不同的是,如果category_id,查询不到,那么插入数据,将新插入数据的id = excel category id
excelSave
php
fecshop/yii2_fecshop
services/category/CategoryMysqldb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMysqldb.php
BSD-3-Clause
public function getFrontList($filter) { $filter['group'] = '$spu'; $filter['select'][] = 'brand_id'; $coll = Yii::$service->product->getFrontCategoryProducts($filter); $collection = $coll['coll']; $count = $coll['count']; $arr = $this->convertToCategoryInfo($collection); return [ 'coll' => $arr, 'count'=> $count, ]; }
@param $filter | Array 和上面的函数 coll($filter) 类似。
getFrontList
php
fecshop/yii2_fecshop
services/category/Product.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/Product.php
BSD-3-Clause
protected function getPrices($price, $special_price, $special_from, $special_to) { if (Yii::$service->product->price->specialPriceisActive($price, $special_price, $special_from, $special_to)) { return [$price, $special_price]; } return [$price, 0]; }
处理,得到产品价格信息.
getPrices
php
fecshop/yii2_fecshop
services/category/Product.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/Product.php
BSD-3-Clause
public function getByPrimaryKey($primaryKey) { if ($primaryKey) { return $this->_categoryModel->findOne($primaryKey); } else { return new $this->_categoryModelName; } }
通过主键,得到Category对象。
getByPrimaryKey
php
fecshop/yii2_fecshop
services/category/CategoryMongodb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMongodb.php
BSD-3-Clause
public function findOne($where) { $one = $this->_categoryModel->findOne($where); return $one; }
通过主键,得到Category对象。
findOne
php
fecshop/yii2_fecshop
services/category/CategoryMongodb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMongodb.php
BSD-3-Clause
public function getByUrlKey($urlKey) { if ($urlKey) { $urlKey = "/".trim($urlKey, "/"); return $this->_categoryModel->findOne(['url_key' => $urlKey]); } else { return new $this->_categoryModelName; } }
通过url_key,得到Category对象。
getByUrlKey
php
fecshop/yii2_fecshop
services/category/CategoryMongodb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMongodb.php
BSD-3-Clause
public function getPrimaryKey() { return '_id'; }
返回主键。
getPrimaryKey
php
fecshop/yii2_fecshop
services/category/CategoryMongodb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMongodb.php
BSD-3-Clause
public function getCategoryEnableStatus() { $model = $this->_categoryModel; return $model::STATUS_ENABLE; }
得到分类激活状态的值
getCategoryEnableStatus
php
fecshop/yii2_fecshop
services/category/CategoryMongodb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMongodb.php
BSD-3-Clause
public function getCategoryMenuShowStatus() { $model = $this->_categoryModel; return $model::MENU_SHOW; }
得到分类在menu中显示的状态值
getCategoryMenuShowStatus
php
fecshop/yii2_fecshop
services/category/CategoryMongodb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMongodb.php
BSD-3-Clause
public function collCount($filter = '') { $query = $this->_categoryModel->find(); $query = Yii::$service->helper->ar->getCollByFilter($query, $filter); return $query->count(); }
得到总数.
collCount
php
fecshop/yii2_fecshop
services/category/CategoryMongodb.php
https://github.com/fecshop/yii2_fecshop/blob/master/services/category/CategoryMongodb.php
BSD-3-Clause