Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
68aebdaf
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 搜索 >>
提交
68aebdaf
编写于
9月 29, 2017
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
appserver product review list
上级
e7529b66
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
413 addition
and
0 deletion
+413
-0
app/appserver/modules/Catalog/block/reviewproduct/Add.php
app/appserver/modules/Catalog/block/reviewproduct/Add.php
+185
-0
app/appserver/modules/Catalog/block/reviewproduct/Lists.php
app/appserver/modules/Catalog/block/reviewproduct/Lists.php
+164
-0
app/appserver/modules/Catalog/controllers/ReviewproductController.php
...r/modules/Catalog/controllers/ReviewproductController.php
+64
-0
未找到文件。
app/appserver/modules/Catalog/block/reviewproduct/Add.php
0 → 100644
浏览文件 @
68aebdaf
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace
fecshop\app\apphtml5\modules\Catalog\block\reviewproduct
;
//use fecshop\app\apphtml5\modules\Catalog\helpers\Review as ReviewHelper;
use
Yii
;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
Add
{
protected
$_add_captcha
;
/**
* 为了可以使用rewriteMap,use 引入的文件统一采用下面的方式,通过Yii::mapGet()得到className和Object
*/
protected
$_reviewHelperName
=
'\fecshop\app\apphtml5\modules\Catalog\helpers\Review'
;
protected
$_reviewHelper
;
public
function
__construct
()
{
/**
* 通过Yii::mapGet() 得到重写后的class类名以及对象。Yii::mapGet是在文件@fecshop\yii\Yii.php中
*/
list
(
$this
->
_reviewHelperName
,
$this
->
_reviewHelper
)
=
Yii
::
mapGet
(
$this
->
_reviewHelperName
);
$reviewHelper
=
$this
->
_reviewHelper
;
$reviewHelper
::
initReviewConfig
();
}
/**
* @return boolean , review页面是否开启验证码验证。
*/
public
function
getAddCaptcha
()
{
if
(
!
$this
->
_add_captcha
)
{
$reviewParam
=
Yii
::
$app
->
getModule
(
'catalog'
)
->
params
[
'review'
];
$this
->
_add_captcha
=
isset
(
$reviewParam
[
'add_captcha'
])
?
$reviewParam
[
'add_captcha'
]
:
false
;
}
return
$this
->
_add_captcha
;
}
public
function
getLastData
(
$editForm
)
{
if
(
!
is_array
(
$editForm
))
{
$editForm
=
[];
}
$_id
=
Yii
::
$app
->
request
->
get
(
'_id'
);
if
(
!
$_id
)
{
Yii
::
$service
->
page
->
message
->
addError
(
'product _id is empty'
);
return
[];
}
$product
=
Yii
::
$service
->
product
->
getByPrimaryKey
(
$_id
);
if
(
!
$product
[
'spu'
])
{
Yii
::
$service
->
page
->
message
->
addError
(
'product _id:'
.
$_id
.
' is not exist in product collection'
);
return
[];
}
$price_info
=
$this
->
getProductPriceInfo
(
$product
);
$spu
=
$product
[
'spu'
];
$image
=
$product
[
'image'
];
$main_img
=
isset
(
$image
[
'main'
][
'image'
])
?
$image
[
'main'
][
'image'
]
:
''
;
$url_key
=
$product
[
'url_key'
];
$product_name
=
Yii
::
$service
->
store
->
getStoreAttrVal
(
$product
[
'name'
],
'name'
);
$customer_name
=
''
;
if
(
!
Yii
::
$app
->
user
->
isGuest
)
{
$identity
=
Yii
::
$app
->
user
->
identity
;
$customer_name
=
$identity
[
'firstname'
]
.
' '
.
$identity
[
'lastname'
];
}
return
[
'customer_name'
=>
$customer_name
,
'product_id'
=>
$_id
,
'product_name'
=>
$product_name
,
'spu'
=>
$spu
,
'price_info'
=>
$price_info
,
'main_img'
=>
$main_img
,
'editForm'
=>
$editForm
,
'add_captcha'
=>
$this
->
getAddCaptcha
(),
'url'
=>
Yii
::
$service
->
url
->
getUrl
(
$url_key
),
];
}
/**
* @property $editForm | Array
* @return boolean ,保存评论信息
*/
public
function
saveReview
(
$editForm
)
{
$add_captcha
=
$this
->
getAddCaptcha
();
$product_id
=
isset
(
$editForm
[
'product_id'
])
?
$editForm
[
'product_id'
]
:
''
;
if
(
!
$product_id
)
{
Yii
::
$service
->
page
->
message
->
addError
([
'Product id can not empty'
]);
return
false
;
}
$rate_star
=
isset
(
$editForm
[
'rate_star'
])
?
$editForm
[
'rate_star'
]
:
''
;
if
(
!
$rate_star
)
{
Yii
::
$service
->
page
->
message
->
addError
([
'Rate Star can not empty'
]);
return
false
;
}
$name
=
isset
(
$editForm
[
'name'
])
?
$editForm
[
'name'
]
:
''
;
if
(
!
$name
)
{
Yii
::
$service
->
page
->
message
->
addError
([
'Your Name can not empty'
]);
return
false
;
}
$summary
=
isset
(
$editForm
[
'summary'
])
?
$editForm
[
'summary'
]
:
''
;
if
(
!
$summary
)
{
Yii
::
$service
->
page
->
message
->
addError
([
'Summary can not empty'
]);
return
false
;
}
$review_content
=
isset
(
$editForm
[
'review_content'
])
?
$editForm
[
'review_content'
]
:
''
;
if
(
!
$review_content
)
{
Yii
::
$service
->
page
->
message
->
addError
([
'Review content can not empty'
]);
return
false
;
}
// captcha validate
$captcha
=
isset
(
$editForm
[
'captcha'
])
?
$editForm
[
'captcha'
]
:
''
;
if
(
$add_captcha
&&
!
$captcha
)
{
Yii
::
$service
->
page
->
message
->
addError
([
'Captcha can not empty'
]);
return
false
;
}
elseif
(
$captcha
&&
$add_captcha
&&
!
\
Yii
::
$service
->
helper
->
captcha
->
validateCaptcha
(
$captcha
))
{
Yii
::
$service
->
page
->
message
->
addError
([
'Captcha is not right'
]);
return
false
;
}
$product
=
Yii
::
$service
->
product
->
getByPrimaryKey
(
$product_id
);
if
(
!
$product
[
'spu'
])
{
Yii
::
$service
->
page
->
message
->
addError
(
'product _id:'
.
$product_id
.
' is not exist in product collection'
);
return
false
;
}
$editForm
[
'spu'
]
=
$product
[
'spu'
];
$editForm
[
'status'
]
=
$product
[
'spu'
];
Yii
::
$service
->
product
->
review
->
addReview
(
$editForm
);
Yii
::
$service
->
page
->
message
->
addCorrect
(
'Add product review success,Thank you! you can click product image to continue this product.'
);
return
true
;
}
/**
* @property $product | String Or Object
* 得到产品的价格信息
*/
protected
function
getProductPriceInfo
(
$product
)
{
$price
=
$product
[
'price'
];
$special_price
=
$product
[
'special_price'
];
$special_from
=
$product
[
'special_from'
];
$special_to
=
$product
[
'special_to'
];
return
Yii
::
$service
->
product
->
price
->
getCurrentCurrencyProductPriceInfo
(
$price
,
$special_price
,
$special_from
,
$special_to
);
}
// 废弃
protected
function
getSpuData
()
{
$spu
=
$this
->
_product
[
'spu'
];
$filter
=
[
'select'
=>
[
'size'
],
'where'
=>
[
[
'spu'
=>
$spu
],
],
'asArray'
=>
true
,
];
$coll
=
Yii
::
$service
->
product
->
coll
(
$filter
);
if
(
is_array
(
$coll
[
'coll'
])
&&
!
empty
(
$coll
[
'coll'
]))
{
foreach
(
$coll
[
'coll'
]
as
$one
)
{
$spu
=
$one
[
'spu'
];
}
}
}
}
app/appserver/modules/Catalog/block/reviewproduct/Lists.php
0 → 100644
浏览文件 @
68aebdaf
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace
fecshop\app\appserver\modules\Catalog\block\reviewproduct
;
//use fecshop\app\apphtml5\modules\Catalog\helpers\Review as ReviewHelper;
use
Yii
;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
Lists
{
public
$product_id
;
public
$spu
;
public
$filterBySpu
=
true
;
public
$filterOrderBy
=
'review_date'
;
public
$_page
=
'p'
;
public
$numPerPage
=
20
;
public
$pageNum
;
/**
* 为了可以使用rewriteMap,use 引入的文件统一采用下面的方式,通过Yii::mapGet()得到className和Object
*/
protected
$_reviewHelperName
=
'\fecshop\app\apphtml5\modules\Catalog\helpers\Review'
;
protected
$_reviewHelper
;
public
function
__construct
()
{
/**
* 通过Yii::mapGet() 得到重写后的class类名以及对象。Yii::mapGet是在文件@fecshop\yii\Yii.php中
*/
list
(
$this
->
_reviewHelperName
,
$this
->
_reviewHelper
)
=
Yii
::
mapGet
(
$this
->
_reviewHelperName
);
// 初始化服务
$reviewHelper
=
$this
->
_reviewHelper
;
$reviewHelper
::
initReviewConfig
();
}
/**
* @property $countTotal | Int
* 得到toolbar的分页部分
*/
protected
function
getProductPage
(
$countTotal
)
{
if
(
$countTotal
<=
$this
->
numPerPage
)
{
return
''
;
}
$config
=
[
'class'
=>
'fecshop\app\apphtml5\widgets\Page'
,
'view'
=>
'widgets/page.php'
,
'pageNum'
=>
$this
->
pageNum
,
'numPerPage'
=>
$this
->
numPerPage
,
'countTotal'
=>
$countTotal
,
'page'
=>
$this
->
_page
,
];
return
Yii
::
$service
->
page
->
widget
->
renderContent
(
'category_product_page'
,
$config
);
}
// 初始化参数
public
function
initParam
()
{
$this
->
pageNum
=
Yii
::
$app
->
request
->
get
(
$this
->
_page
);
$this
->
pageNum
=
$this
->
pageNum
?
$this
->
pageNum
:
1
;
//$this->spu = Yii::$app->request->get('spu');
$this
->
product_id
=
Yii
::
$app
->
request
->
get
(
'product_id'
);
$review
=
Yii
::
$app
->
getModule
(
'catalog'
)
->
params
[
'review'
];
$productPageReviewCount
=
isset
(
$review
[
'reviewPageReviewCount'
])
?
$review
[
'reviewPageReviewCount'
]
:
10
;
$this
->
numPerPage
=
$productPageReviewCount
?
$productPageReviewCount
:
$this
->
numPerPage
;
}
public
function
getLastData
()
{
$this
->
initParam
();
if
(
!
$this
->
product_id
)
{
return
[
'code'
=>
401
,
'content'
=>
'product id is not exist'
];
}
$product
=
Yii
::
$service
->
product
->
getByPrimaryKey
(
$this
->
product_id
);
if
(
!
$product
[
'spu'
])
{
return
[
'code'
=>
401
,
'content'
=>
'product is not exist'
];
}
$this
->
spu
=
$product
[
'spu'
];
$price_info
=
$this
->
getProductPriceInfo
(
$product
);
$spu
=
$product
[
'spu'
];
$image
=
$product
[
'image'
];
$main_img
=
isset
(
$image
[
'main'
][
'image'
])
?
$image
[
'main'
][
'image'
]
:
''
;
$imgUrl
=
Yii
::
$service
->
product
->
image
->
getResize
(
$main_img
,[
150
,
150
],
false
);
$name
=
Yii
::
$service
->
store
->
getStoreAttrVal
(
$product
[
'name'
],
'name'
);
if
(
$this
->
filterBySpu
)
{
$data
=
$this
->
getReviewsBySpu
(
$this
->
spu
);
$count
=
$data
[
'count'
];
$coll
=
$data
[
'coll'
];
$reviewHelper
=
$this
->
_reviewHelper
;
$ReviewAndStarCount
=
$reviewHelper
::
getReviewAndStarCount
(
$product
);
list
(
$review_count
,
$reviw_rate_star_average
)
=
$ReviewAndStarCount
;
$product
=
[
'product_id'
=>
$this
->
product_id
,
'spu'
=>
$this
->
spu
,
'price_info'
=>
$price_info
,
'imgUrl'
=>
$imgUrl
,
'name'
=>
$name
,
];
return
[
'code'
=>
200
,
'product'
=>
$product
,
'reviewList'
=>
$coll
,
'review_count'
=>
$review_count
,
'reviw_rate_star_average'
=>
$reviw_rate_star_average
,
];
}
}
/**
* @property $spu | String
* 通过spu得到产品评论
*/
public
function
getReviewsBySpu
(
$spu
)
{
$currentIp
=
\
fec\helpers\CFunc
::
get_real_ip
();
$filter
=
[
'numPerPage'
=>
$this
->
numPerPage
,
'pageNum'
=>
$this
->
pageNum
,
'orderBy'
=>
[
$this
->
filterOrderBy
=>
SORT_DESC
],
'where'
=>
[
[
'$or'
=>
[
[
'status'
=>
Yii
::
$service
->
product
->
review
->
activeStatus
(),
'product_spu'
=>
$spu
,
],
[
'status'
=>
Yii
::
$service
->
product
->
review
->
noActiveStatus
(),
'product_spu'
=>
$spu
,
'ip'
=>
$currentIp
,
],
],
],
],
];
return
Yii
::
$service
->
product
->
review
->
getListBySpu
(
$filter
);
}
// 产品价格信息
protected
function
getProductPriceInfo
(
$product
)
{
$price
=
$product
[
'price'
];
$special_price
=
$product
[
'special_price'
];
$special_from
=
$product
[
'special_from'
];
$special_to
=
$product
[
'special_to'
];
return
Yii
::
$service
->
product
->
price
->
getCurrentCurrencyProductPriceInfo
(
$price
,
$special_price
,
$special_from
,
$special_to
);
}
}
app/appserver/modules/Catalog/controllers/ReviewproductController.php
0 → 100644
浏览文件 @
68aebdaf
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace
fecshop\app\appserver\modules\Catalog\controllers
;
use
fecshop\app\appserver\modules\AppserverController
;
use
Yii
;
use
fecshop\app\appserver\modules\Catalog\helpers\Review
as
ReviewHelper
;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
ReviewproductController
extends
AppserverController
{
public
$enableCsrfValidation
=
false
;
// 增加评论
public
function
actionAdd
()
{
$reviewParam
=
Yii
::
$app
->
getModule
(
'catalog'
)
->
params
[
'review'
];
$addReviewOnlyLogin
=
isset
(
$reviewParam
[
'addReviewOnlyLogin'
])
?
$reviewParam
[
'addReviewOnlyLogin'
]
:
false
;
if
(
$addReviewOnlyLogin
&&
Yii
::
$app
->
user
->
isGuest
)
{
$currentUrl
=
Yii
::
$service
->
url
->
getCurrentUrl
();
Yii
::
$service
->
customer
->
setLoginSuccessRedirectUrl
(
$currentUrl
);
// 如果评论产品必须登录用户,则跳转到用户登录页面
return
Yii
::
$service
->
url
->
redirectByUrlKey
(
'customer/account/login'
);
}
$editForm
=
Yii
::
$app
->
request
->
post
(
'editForm'
);
$editForm
=
\
Yii
::
$service
->
helper
->
htmlEncode
(
$editForm
);
if
(
!
empty
(
$editForm
)
&&
is_array
(
$editForm
))
{
$saveStatus
=
$this
->
getBlock
()
->
saveReview
(
$editForm
);
if
(
$saveStatus
)
{
$spu
=
Yii
::
$app
->
request
->
get
(
'spu'
);
$_id
=
Yii
::
$app
->
request
->
get
(
'_id'
);
if
(
$spu
&&
$_id
)
{
$url
=
Yii
::
$service
->
url
->
getUrl
(
'catalog/reviewproduct/lists'
,
[
'spu'
=>
$spu
,
'_id'
=>
$_id
]);
$this
->
redirect
(
$url
);
}
}
}
//echo 1;exit;
$data
=
$this
->
getBlock
()
->
getLastData
(
$editForm
);
return
$this
->
render
(
$this
->
action
->
id
,
$data
);
}
public
function
actionLists
()
{
$data
=
$this
->
getBlock
()
->
getLastData
(
$editForm
);
return
$data
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录