Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
f2ff95e1
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
18
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,发现更多精彩内容 >>
提交
f2ff95e1
编写于
2月 24, 2017
作者:
R
root
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fecshop 收藏功能
上级
d995982f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
178 addition
and
2 deletion
+178
-2
services/payment/Paypal.php
services/payment/Paypal.php
+10
-2
services/product/Favorite.php
services/product/Favorite.php
+168
-0
未找到文件。
services/payment/Paypal.php
浏览文件 @
f2ff95e1
...
...
@@ -89,7 +89,7 @@ class Paypal extends Service
return
$verifyUrl
;
}
protected
function
curlGet
(
$url
){
protected
function
curlGet
(
$url
,
$i
=
0
){
$ch
=
curl_init
(
$url
);
curl_setopt
(
$ch
,
CURLOPT_HTTP_VERSION
,
CURL_HTTP_VERSION_1_1
);
curl_setopt
(
$ch
,
CURLOPT_POST
,
1
);
...
...
@@ -98,7 +98,7 @@ class Paypal extends Service
curl_setopt
(
$ch
,
CURLOPT_SSLVERSION
,
6
);
curl_setopt
(
$ch
,
CURLOPT_SSL_VERIFYPEER
,
1
);
curl_setopt
(
$ch
,
CURLOPT_SSL_VERIFYHOST
,
2
);
curl_setopt
(
$ch
,
CURLOPT_TIMEOUT
,
30
);
// This is often required if the server is missing a global cert bundle, or is using an outdated one.
if
(
$this
->
use_local_certs
)
{
curl_setopt
(
$ch
,
CURLOPT_CAINFO
,
__DIR__
.
"/cert/paypal.crt"
);
...
...
@@ -107,6 +107,14 @@ class Paypal extends Service
curl_setopt
(
$ch
,
CURLOPT_CONNECTTIMEOUT
,
30
);
curl_setopt
(
$ch
,
CURLOPT_HTTPHEADER
,
array
(
'Connection: Close'
));
$httpResponse
=
curl_exec
(
$ch
);
if
(
!
$httpResponse
){
$i
++
;
if
(
$i
<=
5
){
return
$this
->
curlGet
(
$url
,
$i
);
}
else
{
return
$httpResponse
;
}
}
return
$httpResponse
;
}
...
...
services/product/Favorite.php
0 → 100644
浏览文件 @
f2ff95e1
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace
fecshop\services\product
;
use
Yii
;
use
fec\helpers\CDir
;
use
yii\base\InvalidValueException
;
use
yii\base\InvalidConfigException
;
use
fecshop\services\Service
;
use
fecshop\models\mongodb\product\Favorite
as
FavoriteModel
;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
Favorite
extends
Service
{
protected
function
actionGetPrimaryKey
(){
return
'_id'
;
}
protected
function
actionGetByPrimaryKey
(
$val
){
$one
=
FavoriteModel
::
findOne
(
$val
);
if
(
$one
[
$this
->
getPrimaryKey
()]){
return
$one
;
}
else
{
return
new
FavoriteModel
;
}
}
protected
function
actionGetByProductIdAndUserId
(
$product_id
,
$user_id
=
''
){
if
(
!
$user_id
){
$identity
=
Yii
::
$app
->
user
->
identity
;
$user_id
=
$identity
[
'id'
];
}
if
(
$user_id
){
$one
=
FavoriteModel
::
findOne
([
'product_id'
=>
$product_id
,
'user_id'
=>
$user_id
,
]);
if
(
$one
[
$this
->
getPrimaryKey
()]){
return
$one
;
}
}
}
protected
function
actionAdd
(
$product_id
,
$user_id
){
$user_id
=
(
int
)
$user_id
;
$productPrimaryKey
=
Yii
::
$service
->
product
->
getPrimaryKey
();
$product
=
Yii
::
$service
->
product
->
getByPrimaryKey
(
$product_id
);
# 检查产品是否存在,如果不存在,输出报错信息。
if
(
!
isset
(
$product
[
$productPrimaryKey
])){
Yii
::
$service
->
helper
->
errors
->
add
(
'product is not exist!'
);
return
;
}
//echo $product_id;exit;
$favoritePrimaryKey
=
Yii
::
$service
->
product
->
favorite
->
getPrimaryKey
();
$one
=
FavoriteModel
::
findOne
([
'product_id'
=>
$product_id
,
'user_id'
=>
$user_id
,
]);
if
(
isset
(
$one
[
$favoritePrimaryKey
])){
$one
->
updated_at
=
time
();
$one
->
store
=
Yii
::
$service
->
store
->
currentStore
;
$one
->
save
();
return
true
;
}
$one
=
new
FavoriteModel
;
$one
->
product_id
=
$product_id
;
$one
->
user_id
=
$user_id
;
$one
->
created_at
=
time
();
$one
->
updated_at
=
time
();
$one
->
store
=
Yii
::
$service
->
store
->
currentStore
;
$one
->
save
();
# 更新该用户总的收藏产品个数到用户表
$this
->
updateUserFavoriteCount
(
$user_id
);
$this
->
updateProductFavoriteCount
(
$product_id
);
return
true
;
}
/**
* @property $product_id | String
* 更新该产品被收藏的总个数。
*/
protected
function
updateProductFavoriteCount
(
$product_id
){
if
(
$product_id
){
$count
=
FavoriteModel
::
find
()
->
where
([
'product_id'
=>
$product_id
])
->
count
();
$product
=
Yii
::
$service
->
product
->
getByPrimaryKey
(
$product_id
);
if
(
$product
[
'_id'
]){
$product
->
favorite_count
=
$count
;
$product
->
save
();
}
}
}
/**
* @property $user_id | Int
* 更新该用户总的收藏产品个数到用户表
*/
protected
function
updateUserFavoriteCount
(
$user_id
=
''
){
$identity
=
Yii
::
$app
->
user
->
identity
;
if
(
!
$user_id
){
$user_id
=
$identity
[
'id'
];
}
if
(
$user_id
){
$count
=
FavoriteModel
::
find
()
->
where
([
'user_id'
=>
$user_id
])
->
count
();
$identity
->
favorite_product_count
=
$count
;
$identity
->
save
();
}
}
/*
* example filter:
* [
* 'numPerPage' => 20,
* 'pageNum' => 1,
* 'orderBy' => [$this->getPrimaryKey() => SORT_DESC, 'sku' => SORT_ASC ],
* 'where' => [
['>','price',1],
['<=','price',10]
* ['sku' => 'uk10001'],
* ],
* 'asArray' => true,
* ]
*/
protected
function
actionList
(
$filter
){
$query
=
FavoriteModel
::
find
();
$query
=
Yii
::
$service
->
helper
->
ar
->
getCollByFilter
(
$query
,
$filter
);
return
[
'coll'
=>
$query
->
all
(),
'count'
=>
$query
->
count
(),
];
}
protected
function
actionColl
(
$filter
){
return
$this
->
list
(
$filter
);
}
/**
* @property $favorite_id|String
* 通过id删除favorite
*/
protected
function
actionCurrentUserRemove
(
$favorite_id
){
$identity
=
Yii
::
$app
->
user
->
identity
;
$user_id
=
$identity
[
'id'
];
$one
=
FavoriteModel
::
findOne
([
'_id'
=>
new
\
MongoId
(
$favorite_id
),
'user_id'
=>
$user_id
,
]);
if
(
$one
[
'_id'
]){
$one
->
delete
();
$this
->
updateUserFavoriteCount
(
$user_id
);
$this
->
updateProductFavoriteCount
(
$product_id
);
return
true
;
}
return
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录