Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
072f42a4
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
17
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yii2_fecshop
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
072f42a4
编写于
7月 02, 2017
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fecshop service update: Helper ,Email , Image , Helper ,,etc
上级
2e32e9a7
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
87 addition
and
66 deletion
+87
-66
services/FecshopLang.php
services/FecshopLang.php
+7
-14
services/Image.php
services/Image.php
+28
-16
services/helper/AR.php
services/helper/AR.php
+12
-9
services/helper/Captcha.php
services/helper/Captcha.php
+7
-8
services/helper/Country.php
services/helper/Country.php
+15
-6
services/helper/Errors.php
services/helper/Errors.php
+15
-10
services/helper/Format.php
services/helper/Format.php
+2
-2
services/helper/MobileDetect.php
services/helper/MobileDetect.php
+1
-1
未找到文件。
services/FecshopLang.php
浏览文件 @
072f42a4
...
@@ -12,6 +12,7 @@ namespace fecshop\services;
...
@@ -12,6 +12,7 @@ namespace fecshop\services;
use
Yii
;
use
Yii
;
/**
/**
* language services 语言部分
* @author Terry Zhao <2358269014@qq.com>
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
* @since 1.0
*/
*/
...
@@ -37,26 +38,17 @@ class Fecshoplang extends Service
...
@@ -37,26 +38,17 @@ class Fecshoplang extends Service
{
{
return
$attrName
.
'_'
.
$langCode
;
return
$attrName
.
'_'
.
$langCode
;
}
}
/**
* @property $attrName | String 属性名称
* 得到默认语言的属性名称
*/
protected
function
actionGetDefaultLangAttrName
(
$attrName
)
protected
function
actionGetDefaultLangAttrName
(
$attrName
)
{
{
return
$attrName
.
'_'
.
$this
->
defaultLangCode
;
return
$attrName
.
'_'
.
$this
->
defaultLangCode
;
}
}
/**
/**
*
返回所有的,用于mongodb 生成fullSearch的语言名称。
*
得到所有的语言简码,譬如:en,es,fr,zh,de等
*/
*/
/*
protected function actionGetAllmongoSearchLangName(){
$arr = [];
foreach($this->allLangCode as $codeInfo){
$mongoSearchLangName = $codeInfo['mongoSearchLangName'];
$arr[] = $mongoSearchLangName;
}
return $arr;
}
*/
protected
function
actionGetAllLangCode
()
protected
function
actionGetAllLangCode
()
{
{
if
(
!
$this
->
_allLangCode
)
{
if
(
!
$this
->
_allLangCode
)
{
...
@@ -82,6 +74,7 @@ class Fecshoplang extends Service
...
@@ -82,6 +74,7 @@ class Fecshoplang extends Service
* @property $attrName|String, attribute name ,like: title ,description.
* @property $attrName|String, attribute name ,like: title ,description.
* get default language attr value.
* get default language attr value.
* example getDefaultLangAttrVal(['title_en'=>'xx','title_fr'=>'yy'],'title');
* example getDefaultLangAttrVal(['title_en'=>'xx','title_fr'=>'yy'],'title');
* 得到属性默认语言对应的值。上面是title属性默认语言的值。
*/
*/
protected
function
actionGetDefaultLangAttrVal
(
$attrVal
,
$attrName
)
protected
function
actionGetDefaultLangAttrVal
(
$attrVal
,
$attrName
)
{
{
...
...
services/Image.php
浏览文件 @
072f42a4
...
@@ -43,7 +43,9 @@ class Image extends Service
...
@@ -43,7 +43,9 @@ class Image extends Service
public
$appbase
;
public
$appbase
;
/**
/**
* 1.1 app front image Dir.
* @property $str | String 图片的相对路径
* @property $app | String @appimage下面的文件夹的名称。各个名称对应各个入口的名字,譬如common appfront appadmin等
* @return 返回图片的绝对路径。
*/
*/
protected
function
actionGetImgDir
(
$str
=
''
,
$app
=
'common'
)
protected
function
actionGetImgDir
(
$str
=
''
,
$app
=
'common'
)
{
{
...
@@ -58,10 +60,10 @@ class Image extends Service
...
@@ -58,10 +60,10 @@ class Image extends Service
}
}
}
}
/**
/**
*
1.2 app front image Url*
*
@property $str | String 图片的相对路径
*
example : <?= Yii::$service->image->getImgUrl('custom/logo.png','appfront'); ?>
*
@property $app | String @appimage下面的文件夹的名称。各个名称对应各个入口的名字,譬如common appfront appadmin等
*
it will find image in @appimage/$app.
*
@return 返回图片的完整URL
*/
*/
protected
function
actionGetImgUrl
(
$str
,
$app
=
'common'
)
protected
function
actionGetImgUrl
(
$str
,
$app
=
'common'
)
{
{
...
@@ -78,7 +80,8 @@ class Image extends Service
...
@@ -78,7 +80,8 @@ class Image extends Service
}
}
/**
/**
* 2.1 app front image base dir.
* @property $app | String @appimage下面的文件夹的名称。各个名称对应各个入口的名字,譬如common appfront appadmin等
* @return 返回图片存放目录的绝对路径。
*/
*/
protected
function
actionGetBaseImgDir
(
$app
=
'common'
)
protected
function
actionGetBaseImgDir
(
$app
=
'common'
)
{
{
...
@@ -86,7 +89,8 @@ class Image extends Service
...
@@ -86,7 +89,8 @@ class Image extends Service
}
}
/**
/**
* 2.2 app front image base Url.
* @property $app | String @appimage下面的文件夹的名称。各个名称对应各个入口的名字,譬如common appfront appadmin等
* @return 返回图片存放目录的URL
*/
*/
protected
function
actionGetBaseImgUrl
(
$app
=
'common'
)
protected
function
actionGetBaseImgUrl
(
$app
=
'common'
)
{
{
...
@@ -94,7 +98,8 @@ class Image extends Service
...
@@ -94,7 +98,8 @@ class Image extends Service
}
}
/**
/**
* 设置上传图片的最大的size.
* @property $uploadSize | Int , 多少MB
* 设置上传图片的最大的size. 参数单位为MB
*/
*/
protected
function
actionSetMaxUploadSize
(
$uploadSize
)
protected
function
actionSetMaxUploadSize
(
$uploadSize
)
{
{
...
@@ -116,7 +121,7 @@ class Image extends Service
...
@@ -116,7 +121,7 @@ class Image extends Service
}
}
/**
/**
* 得到保存图片所在相对根目录的url路径.
* 得到
(上传)
保存图片所在相对根目录的url路径.
*/
*/
protected
function
actionGetCurrentBaseImgUrl
()
protected
function
actionGetCurrentBaseImgUrl
()
{
{
...
@@ -124,7 +129,7 @@ class Image extends Service
...
@@ -124,7 +129,7 @@ class Image extends Service
}
}
/**
/**
* 得到保存图片所在相对根目录的文件夹路径.
* 得到
(上传)
保存图片所在相对根目录的文件夹路径.
*/
*/
protected
function
actionGetCurrentBaseImgDir
()
protected
function
actionGetCurrentBaseImgDir
()
{
{
...
@@ -132,6 +137,7 @@ class Image extends Service
...
@@ -132,6 +137,7 @@ class Image extends Service
}
}
/**
/**
* @property $str | String , 图片的相对路径字符串
* 通过图片的相对路径得到产品图片的url.
* 通过图片的相对路径得到产品图片的url.
*/
*/
protected
function
actionGetUrlByRelativePath
(
$str
)
protected
function
actionGetUrlByRelativePath
(
$str
)
...
@@ -140,13 +146,19 @@ class Image extends Service
...
@@ -140,13 +146,19 @@ class Image extends Service
}
}
/**
/**
* @property $str | String , 图片的相对路径字符串
* 通过图片的相对路径得到产品图片的绝对路径.
* 通过图片的相对路径得到产品图片的绝对路径.
*/
*/
protected
function
actionGetDirByRelativePath
()
protected
function
actionGetDirByRelativePath
(
$str
)
{
{
return
$this
->
GetImgDir
(
$this
->
imageFloder
.
$str
,
'common'
);
return
$this
->
GetImgDir
(
$this
->
imageFloder
.
$str
,
'common'
);
}
}
/**
* @property $name | String , 图片的原始名字,也就是图片上传的时候的名字。
* @property $length | String , 生成图片随机字符的长度。
* 随机生成图片的新名字,因为有的图片名字可能是中文或者其他语言,而fecshop在保存名字的时候会取名字的前2个字母生成2层文件夹
* 这样中文名字就会出现问题,因此需要使用随机生成的名字(生成2层文件夹,是为了让文件夹下面不至于太多的文件,linux文件夹下的文件超过几万个,查找文件就会有点慢,这样做是为了避免这个文件。)
*/
protected
function
generateImgName
(
$name
,
$length
=
15
)
{
protected
function
generateImgName
(
$name
,
$length
=
15
)
{
$arr
=
explode
(
'.'
,
$name
);
$arr
=
explode
(
'.'
,
$name
);
$fileType
=
'.'
.
$arr
[
count
(
$arr
)
-
1
];
$fileType
=
'.'
.
$arr
[
count
(
$arr
)
-
1
];
...
@@ -167,10 +179,9 @@ class Image extends Service
...
@@ -167,10 +179,9 @@ class Image extends Service
/**
/**
* @property $param_img_file | Array .
* @property $param_img_file | Array .
* upload image from web page , you can get image from $_FILE['XXX'] ,
* 上传产品图片,
* $param_img_file is get from $_FILE['XXX'].
* 如果成功,保存产品相对路径,譬如: '/b/i/big.jpg'
* return , if success ,return image saved relative file path , like '/b/i/big.jpg'
* 如果失败,reutrn false;
* if fail, reutrn false;
*/
*/
protected
function
actionSaveUploadImg
(
$FILE
)
protected
function
actionSaveUploadImg
(
$FILE
)
{
{
...
@@ -236,6 +247,7 @@ class Image extends Service
...
@@ -236,6 +247,7 @@ class Image extends Service
* @property $name|string , image file name ,not contain image suffix.
* @property $name|string , image file name ,not contain image suffix.
* @property $imageType|string , image file suffix. like '.gif','jpg'
* @property $imageType|string , image file suffix. like '.gif','jpg'
* return saved Image Name.
* return saved Image Name.
* 得到产品保存的唯一路径,因为可能存在名字重复的问题,因此使用该函数确保图片路径唯一。
*/
*/
protected
function
getUniqueImgNameInPath
(
$imgSaveFloder
,
$name
,
$imageType
,
$randStr
=
''
)
protected
function
getUniqueImgNameInPath
(
$imgSaveFloder
,
$name
,
$imageType
,
$randStr
=
''
)
{
{
...
...
services/helper/AR.php
浏览文件 @
072f42a4
...
@@ -13,7 +13,7 @@ use fecshop\services\Service;
...
@@ -13,7 +13,7 @@ use fecshop\services\Service;
use
Yii
;
use
Yii
;
/**
/**
* AR services.
* AR services.
(Active Record)
* @author Terry Zhao <2358269014@qq.com>
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
* @since 1.0
*/
*/
...
@@ -35,16 +35,16 @@ class AR extends Service
...
@@ -35,16 +35,16 @@ class AR extends Service
* ],
* ],
* 'asArray' => true,
* 'asArray' => true,
* ]
* ]
* 查询方面使用的函数,根据传递的参数,进行query
*/
*/
public
function
getCollByFilter
(
$query
,
$filter
)
public
function
getCollByFilter
(
$query
,
$filter
)
{
{
$select
=
isset
(
$filter
[
'select'
])
?
$filter
[
'select'
]
:
''
;
$select
=
isset
(
$filter
[
'select'
])
?
$filter
[
'select'
]
:
''
;
$asArray
=
isset
(
$filter
[
'asArray'
])
?
$filter
[
'asArray'
]
:
true
;
$asArray
=
isset
(
$filter
[
'asArray'
])
?
$filter
[
'asArray'
]
:
true
;
$numPerPage
=
isset
(
$filter
[
'numPerPage'
])
?
$filter
[
'numPerPage'
]
:
$this
->
numPerPage
;
$numPerPage
=
isset
(
$filter
[
'numPerPage'
])
?
$filter
[
'numPerPage'
]
:
$this
->
numPerPage
;
$pageNum
=
isset
(
$filter
[
'pageNum'
])
?
$filter
[
'pageNum'
]
:
$this
->
pageNum
;
$pageNum
=
isset
(
$filter
[
'pageNum'
])
?
$filter
[
'pageNum'
]
:
$this
->
pageNum
;
$orderBy
=
isset
(
$filter
[
'orderBy'
])
?
$filter
[
'orderBy'
]
:
''
;
$orderBy
=
isset
(
$filter
[
'orderBy'
])
?
$filter
[
'orderBy'
]
:
''
;
$where
=
isset
(
$filter
[
'where'
])
?
$filter
[
'where'
]
:
''
;
$where
=
isset
(
$filter
[
'where'
])
?
$filter
[
'where'
]
:
''
;
if
(
$asArray
)
{
if
(
$asArray
)
{
$query
->
asArray
();
$query
->
asArray
();
}
}
...
@@ -64,7 +64,6 @@ class AR extends Service
...
@@ -64,7 +64,6 @@ class AR extends Service
}
}
}
}
}
}
$offset
=
(
$pageNum
-
1
)
*
$numPerPage
;
$offset
=
(
$pageNum
-
1
)
*
$numPerPage
;
$query
->
limit
(
$numPerPage
)
->
offset
(
$offset
);
$query
->
limit
(
$numPerPage
)
->
offset
(
$offset
);
if
(
$orderBy
)
{
if
(
$orderBy
)
{
...
@@ -73,7 +72,11 @@ class AR extends Service
...
@@ -73,7 +72,11 @@ class AR extends Service
return
$query
;
return
$query
;
}
}
/**
* @property $model | Object , 数据库model
* @property $one | Array , 数据数组,对model进行赋值
* 通过循环的方式,对$model对象的属性进行赋值。
*/
public
function
save
(
$model
,
$one
,
$serialize
=
false
)
public
function
save
(
$model
,
$one
,
$serialize
=
false
)
{
{
if
(
!
$model
)
{
if
(
!
$model
)
{
...
...
services/helper/Captcha.php
浏览文件 @
072f42a4
...
@@ -12,17 +12,17 @@ namespace fecshop\services\helper;
...
@@ -12,17 +12,17 @@ namespace fecshop\services\helper;
use
fecshop\services\Service
;
use
fecshop\services\Service
;
/**
/**
* Helper Captcha services.
* Helper Captcha services.
验证码部分
* @author Terry Zhao <2358269014@qq.com>
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
* @since 1.0
*/
*/
class
Captcha
extends
Service
class
Captcha
extends
Service
{
{
public
$charset
=
'abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ0123456789'
;
//随机因子
public
$charset
=
'abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ0123456789'
;
//随机因子
public
$codelen
=
4
;
//验证码长度
public
$codelen
=
4
;
//验证码长度
public
$width
=
130
;
//宽度
public
$width
=
130
;
//宽度
public
$height
=
50
;
//高度
public
$height
=
50
;
//高度
public
$fontsize
=
20
;
//指定字体大小
public
$fontsize
=
20
;
//指定字体大小
public
$case_sensitive
=
false
;
public
$case_sensitive
=
false
;
private
$fontcolor
;
//指定字体颜色
private
$fontcolor
;
//指定字体颜色
private
$code
;
//验证码
private
$code
;
//验证码
...
@@ -37,7 +37,6 @@ class Captcha extends Service
...
@@ -37,7 +37,6 @@ class Captcha extends Service
public
function
__construct
()
public
function
__construct
()
{
{
$this
->
font
=
dirname
(
__FILE__
)
.
'/captcha/Elephant.ttf'
;
//注意字体路径要写对,否则显示不了图片
$this
->
font
=
dirname
(
__FILE__
)
.
'/captcha/Elephant.ttf'
;
//注意字体路径要写对,否则显示不了图片
//echo $this->font;exit;
}
}
//生成随机码
//生成随机码
...
@@ -52,8 +51,8 @@ class Captcha extends Service
...
@@ -52,8 +51,8 @@ class Captcha extends Service
//生成背景
//生成背景
private
function
createBg
()
private
function
createBg
()
{
{
$this
->
img
=
imagecreatetruecolor
(
$this
->
width
,
$this
->
height
);
$this
->
img
=
imagecreatetruecolor
(
$this
->
width
,
$this
->
height
);
$color
=
imagecolorallocate
(
$this
->
img
,
mt_rand
(
157
,
255
),
mt_rand
(
157
,
255
),
mt_rand
(
157
,
255
));
$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
);
imagefilledrectangle
(
$this
->
img
,
0
,
$this
->
height
,
$this
->
width
,
0
,
$color
);
}
}
...
...
services/helper/Country.php
浏览文件 @
072f42a4
...
@@ -19,7 +19,9 @@ use fecshop\services\Service;
...
@@ -19,7 +19,9 @@ use fecshop\services\Service;
class
Country
extends
Service
class
Country
extends
Service
{
{
public
$default_country
;
public
$default_country
;
/**
* 得到默认的国家
*/
public
function
getDefaultCountry
()
public
function
getDefaultCountry
()
{
{
if
(
!
$this
->
default_country
)
{
if
(
!
$this
->
default_country
)
{
...
@@ -28,7 +30,9 @@ class Country extends Service
...
@@ -28,7 +30,9 @@ class Country extends Service
return
$this
->
default_country
;
return
$this
->
default_country
;
}
}
/**
* 通过国家,得到省的option html的字符串
*/
public
function
getStateOptionsByContryCode
(
$CountryCode
,
$selected
=
''
)
public
function
getStateOptionsByContryCode
(
$CountryCode
,
$selected
=
''
)
{
{
if
(
!
$CountryCode
)
{
if
(
!
$CountryCode
)
{
...
@@ -54,8 +58,9 @@ class Country extends Service
...
@@ -54,8 +58,9 @@ class Country extends Service
return
$str
;
return
$str
;
}
}
/**
//得到所有国家的option
* 得到所有国家的option
*/
public
function
getAllCountryOptions
(
$name
=
'country'
,
$class
=
'country'
,
$current
=
''
,
$nullShow
=
''
)
public
function
getAllCountryOptions
(
$name
=
'country'
,
$class
=
'country'
,
$current
=
''
,
$nullShow
=
''
)
{
{
$all_country_array
=
$this
->
getAllCountryArray
();
$all_country_array
=
$this
->
getAllCountryArray
();
...
@@ -80,14 +85,18 @@ class Country extends Service
...
@@ -80,14 +85,18 @@ class Country extends Service
return
$str
;
return
$str
;
}
}
/**
* 通过国家简码得到国家的全称名字
*/
public
function
getCountryNameByKey
(
$key
)
public
function
getCountryNameByKey
(
$key
)
{
{
$all_country
=
$this
->
getAllCountryArray
();
$all_country
=
$this
->
getAllCountryArray
();
return
isset
(
$all_country
[
$key
])
?
$all_country
[
$key
]
:
$key
;
return
isset
(
$all_country
[
$key
])
?
$all_country
[
$key
]
:
$key
;
}
}
/**
* 国家option html
*/
public
static
function
getCountryOptionsHtml
(
$selectd
=
''
)
public
static
function
getCountryOptionsHtml
(
$selectd
=
''
)
{
{
if
(
!
$selectd
)
{
if
(
!
$selectd
)
{
...
...
services/helper/Errors.php
浏览文件 @
072f42a4
...
@@ -34,7 +34,11 @@ class Errors extends Service
...
@@ -34,7 +34,11 @@ class Errors extends Service
$this
->
_errors
[]
=
$errros
;
$this
->
_errors
[]
=
$errros
;
}
}
}
}
/**
* @property $model_errors | Array
* Yii2的model在使用rules验证数据格式的时候,报错保存在errors中
* 本函数将errors的内容添加到errors services中。
*/
public
function
addByModelErrors
(
$model_errors
)
public
function
addByModelErrors
(
$model_errors
)
{
{
$error_arr
=
[];
$error_arr
=
[];
...
@@ -60,17 +64,18 @@ class Errors extends Service
...
@@ -60,17 +64,18 @@ class Errors extends Service
*/
*/
public
function
get
(
$separator
=
false
)
public
function
get
(
$separator
=
false
)
{
{
if
(
$this
->
_errors
)
{
if
(
$errors
=
$this
->
_errors
;)
{
$errors
=
$this
->
_errors
;
$this
->
_errors
=
false
;
$this
->
_errors
=
false
;
if
(
!
$separator
)
{
if
(
is_array
(
$errors
)
&&
!
empty
(
$errors
)){
if
(
$separator
===
true
)
{
if
(
$separator
)
{
$separator
=
'|'
;
if
(
$separator
===
true
)
{
}
$separator
=
'|'
;
}
return
implode
(
$separator
,
$errors
);
return
implode
(
$separator
,
$errors
);
}
else
{
}
else
{
return
$errors
;
return
$errors
;
}
}
}
}
}
...
...
services/helper/Format.php
浏览文件 @
072f42a4
...
@@ -12,7 +12,7 @@ namespace fecshop\services\helper;
...
@@ -12,7 +12,7 @@ namespace fecshop\services\helper;
use
fecshop\services\Service
;
use
fecshop\services\Service
;
/**
/**
*
AR
services.
*
Format
services.
* @author Terry Zhao <2358269014@qq.com>
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
* @since 1.0
*/
*/
...
@@ -23,7 +23,7 @@ class Format extends Service
...
@@ -23,7 +23,7 @@ class Format extends Service
* @property $number | Float
* @property $number | Float
* @property $bits | Int
* @property $bits | Int
* @return $number | Float
* @return $number | Float
*
返回格式化形式的
*
返回格式化形式的float小数,譬如2 会变成2.00
*/
*/
public
function
number_format
(
$number
,
$bits
=
2
)
public
function
number_format
(
$number
,
$bits
=
2
)
{
{
...
...
services/helper/MobileDetect.php
浏览文件 @
072f42a4
...
@@ -31,7 +31,7 @@ class MobileDetect
...
@@ -31,7 +31,7 @@ class MobileDetect
{
{
/**
/**
* Mobile detection type.
* Mobile detection type.
*
*
这是第三方的文件,用来检测设备。是pc mobile等
* @deprecated since version 2.6.9
* @deprecated since version 2.6.9
*/
*/
const
DETECTION_TYPE_MOBILE
=
'mobile'
;
const
DETECTION_TYPE_MOBILE
=
'mobile'
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录