diff --git a/service/Application/Home/Controller/GoodsController.class.php b/service/Application/Home/Controller/GoodsController.class.php
index be88fae25..e0430f037 100755
--- a/service/Application/Home/Controller/GoodsController.class.php
+++ b/service/Application/Home/Controller/GoodsController.class.php
@@ -54,6 +54,9 @@ class GoodsController extends CommonController
$ret_favor = GoodsService::IsUserGoodsFavor(['goods_id'=>$id, 'user'=>$this->user]);
$goods[0]['is_favor'] = ($ret_favor['code'] == 0) ? $ret_favor['data'] : 0;
+ // 商品评价总数
+ $goods[0]['comments_count'] = GoodsService::GoodsCommentsTotal($id);
+
$this->assign('goods', $goods[0]);
$this->assign('home_seo_site_title', $goods[0]['title']);
diff --git a/service/Application/Home/Controller/OrderController.class.php b/service/Application/Home/Controller/OrderController.class.php
index ce8b0ac5d..9716c8a23 100755
--- a/service/Application/Home/Controller/OrderController.class.php
+++ b/service/Application/Home/Controller/OrderController.class.php
@@ -137,7 +137,7 @@ class OrderController extends CommonController
* @date 2018-10-08
* @desc description
*/
- public function CommentsInfo()
+ public function Comments()
{
// 参数
$params = array_merge($_POST, $_GET);
@@ -155,14 +155,37 @@ class OrderController extends CommonController
$data = OrderService::OrderList($data_params);
if(!empty($data['data'][0]))
{
+ $this->assign('referer_url', empty($_SERVER['HTTP_REFERER']) ? U('Home/Order/Index') : $_SERVER['HTTP_REFERER']);
$this->assign('data', $data['data'][0]);
- $this->display('CommentsInfo');
+ $this->display('Comments');
} else {
$this->assign('msg', L('common_not_data_tips'));
$this->display('/Public/TipsError');
}
}
+ /**
+ * 评价保存
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2018-10-09
+ * @desc description
+ */
+ public function CommentsSave()
+ {
+ if(IS_POST)
+ {
+ $params = $_POST;
+ $params['user'] = $this->user;
+ $ret = OrderService::Comments($params);
+ $this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
+ } else {
+ $this->assign('msg', L('common_unauthorized_access'));
+ $this->display('/Public/TipsError');
+ }
+ }
+
/**
* 订单支付
* @author Devil
diff --git a/service/Application/Home/View/Default/Goods/Index.html b/service/Application/Home/View/Default/Goods/Index.html
index d98e7677b..221d9ca6a 100755
--- a/service/Application/Home/View/Default/Goods/Index.html
+++ b/service/Application/Home/View/Default/Goods/Index.html
@@ -90,7 +90,7 @@
浏览次数{{$goods.access_count}}
- 累计评价640
+ 累计评价{{$goods.comments_count}}
diff --git a/service/Application/Home/View/Default/Order/Comments.html b/service/Application/Home/View/Default/Order/Comments.html
new file mode 100644
index 000000000..ad06e00bf
--- /dev/null
+++ b/service/Application/Home/View/Default/Order/Comments.html
@@ -0,0 +1,104 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/service/Application/Home/View/Default/Order/CommentsInfo.html b/service/Application/Home/View/Default/Order/CommentsInfo.html
deleted file mode 100644
index 396c5692a..000000000
--- a/service/Application/Home/View/Default/Order/CommentsInfo.html
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/service/Application/Home/View/Default/Order/Detail.html b/service/Application/Home/View/Default/Order/Detail.html
index 3d3f93ea7..6c2cb207d 100644
--- a/service/Application/Home/View/Default/Order/Detail.html
+++ b/service/Application/Home/View/Default/Order/Detail.html
@@ -170,7 +170,7 @@
- 评价
+ 评价
diff --git a/service/Application/Home/View/Default/Order/Index.html b/service/Application/Home/View/Default/Order/Index.html
index 141a02bfd..bbac502b1 100755
--- a/service/Application/Home/View/Default/Order/Index.html
+++ b/service/Application/Home/View/Default/Order/Index.html
@@ -186,7 +186,7 @@
- 评价
+ 评价
diff --git a/service/Application/Service/GoodsService.class.php b/service/Application/Service/GoodsService.class.php
index c12a41477..1f5c67a98 100755
--- a/service/Application/Service/GoodsService.class.php
+++ b/service/Application/Service/GoodsService.class.php
@@ -390,5 +390,19 @@ class GoodsService
$temp = $m->where($data)->find();
return DataReturn(L('common_operation_success'), 0, empty($temp) ? 0 : 1);
}
+
+ /**
+ * 商品评论总数
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2018-09-29
+ * @desc description
+ * @param [array] $where [条件]
+ */
+ public static function GoodsCommentsTotal($goods_id)
+ {
+ return (int) M('OrderComments')->where(['goods_id'=>intval($goods_id)])->count();
+ }
}
?>
\ No newline at end of file
diff --git a/service/Application/Service/OrderService.class.php b/service/Application/Service/OrderService.class.php
index eae685d4d..4107512fb 100755
--- a/service/Application/Service/OrderService.class.php
+++ b/service/Application/Service/OrderService.class.php
@@ -875,5 +875,116 @@ class OrderService
return DataReturn(L('common_operation_delete_error'), -1);
}
+ /**
+ * 订单评价
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2018-10-09
+ * @desc description
+ * @param [array] $params [输入参数]
+ */
+ public static function Comments($params = [])
+ {
+ // 请求参数
+ $p = [
+ [
+ 'checked_type' => 'empty',
+ 'key_name' => 'id',
+ 'error_msg' => '订单id有误',
+ ],
+ [
+ 'checked_type' => 'isset',
+ 'key_name' => 'goods_id',
+ 'error_msg' => '商品id有误',
+ ],
+ [
+ 'checked_type' => 'is_array',
+ 'key_name' => 'goods_id',
+ 'error_msg' => '商品数据格式有误',
+ ],
+ [
+ 'checked_type' => 'isset',
+ 'key_name' => 'rating',
+ 'error_msg' => '评级有误',
+ ],
+ [
+ 'checked_type' => 'is_array',
+ 'key_name' => 'rating',
+ 'error_msg' => '评级数据格式有误',
+ ],
+ [
+ 'checked_type' => 'isset',
+ 'key_name' => 'content',
+ 'error_msg' => '评价内容有误',
+ ],
+ [
+ 'checked_type' => 'is_array',
+ 'key_name' => 'content',
+ 'error_msg' => '评价内容数据格式有误',
+ ],
+ [
+ 'checked_type' => 'empty',
+ 'key_name' => 'user',
+ 'error_msg' => '用户信息有误',
+ ],
+ ];
+ $ret = params_checked($params, $p);
+ if($ret !== true)
+ {
+ return DataReturn($ret, -1);
+ }
+
+ // 获取订单信息
+ $order_id = intval($params['id']);
+ $order_m = M('Order');
+ $where = ['id'=>$order_id, 'user_id'=>$params['user']['id'], 'is_delete_time'=>0, 'user_is_delete_time'=>0];
+ $order = $order_m->where($where)->field('id,status,shop_id,user_is_comments')->find();
+ if(empty($order))
+ {
+ return DataReturn(L('common_data_no_exist_error'), -1);
+ }
+ if($order['status'] != 4)
+ {
+ $status_text = L('common_order_user_status')[$order['status']]['name'];
+ return DataReturn('状态不可操作['.$status_text.']', -1);
+ }
+ if($order['user_is_comments'] != 0)
+ {
+ return DataReturn('该订单你已进行过评价', -10);
+ }
+
+ // 处理数据
+ $comments_m = M('OrderComments');
+ $comments_m->startTrans();
+ foreach($params['goods_id'] as $k=>$goods_id)
+ {
+ $data = [
+ 'user_id' => $params['user']['id'],
+ 'shop_id' => $order['shop_id'],
+ 'order_id' => $order_id,
+ 'goods_id' => $goods_id,
+ 'content' => isset($params['content'][$k]) ? htmlspecialchars(trim($params['content'][$k])) : '',
+ 'rating' => isset($params['rating'][$k]) ? intval($params['rating'][$k]) : 0,
+ 'add_time' => time(),
+ ];
+ if($comments_m->add($data) <= 0)
+ {
+ $comments_m->rollback();
+ return DataReturn('评价内容添加失败', -100);
+ }
+ }
+
+ // 订单评价状态更新
+ if(!$order_m->where($where)->save(['user_is_comments'=>time(), 'upd_time'=>time()]))
+ {
+ $comments_m->rollback();
+ return DataReturn('订单更新失败', -101);
+ }
+
+ $comments_m->commit();
+ return DataReturn(L('common_operation_comments_success'), 0);
+ }
+
}
?>
\ No newline at end of file
diff --git a/service/Public/Home/Default/Css/Order.Comments.css b/service/Public/Home/Default/Css/Order.Comments.css
new file mode 100644
index 000000000..31c1baead
--- /dev/null
+++ b/service/Public/Home/Default/Css/Order.Comments.css
@@ -0,0 +1,43 @@
+ul.rating {
+ overflow: hidden;
+ margin-bottom: 2px;
+}
+ul.rating li {
+ float: left;
+ margin-right: 10px;
+}
+ul.rating li i.am-icon-star-o {
+ color: #888;
+}
+ul.rating li i.am-icon-star {
+ color: #d13b49;
+}
+
+
+/**
+ * 商品列表
+ */
+.order-goods { margin-top: 20px; }
+.goods-detail img { width: 80px; height: 80px; }
+.goods-detail { position: relative; }
+.goods-title { display: block; max-height: 36px; overflow: hidden; text-overflow: ellipsis; }
+.goods-title:hover { text-decoration: underline; }
+.goods-base { position: absolute; top: 0; left: 85px; }
+.goods-attr { margin-top: 5px; }
+.goods-attr li { color: #888; line-height: 16px; }
+.original-price, .line-price { font-family: Verdana,Tahoma,arial; }
+.original-price { color: #9c9c9c; text-decoration: line-through; }
+.line-price { color: #3c3c3c; }
+.line-price, strong.total-price-content { font-weight: 700; }
+strong.total-price-content { color: #d2364c; font-size: 16px; }
+.am-table { margin-bottom: 10px; }
+.am-table > tbody > tr > td { border-top: 1px solid #F5F5F5; }
+.am-table > thead > tr > th { border-bottom: 1px solid #f7f7f7; }
+
+@media only screen and (min-width:640px) {
+ .cart-content table tr .base { width: 40%; }
+ .cart-content table tr .price { width: 20%; }
+ .cart-content table tr .number { width: 20%; }
+ .cart-content table tr .total-price { width: 20%; }
+ .cart-content { margin-top: 20px; }
+}
\ No newline at end of file
diff --git a/service/Public/Home/Default/Js/Order.js b/service/Public/Home/Default/Js/Order.js
index 7dad4f38d..434e2a194 100644
--- a/service/Public/Home/Default/Js/Order.js
+++ b/service/Public/Home/Default/Js/Order.js
@@ -67,4 +67,19 @@ $(function()
}
});
+
+ /**
+ * 评价打分
+ */
+ $('ul.rating li').on('click', function()
+ {
+ $(this).parent().find('li i').removeClass('am-icon-star').addClass('am-icon-star-o');
+ var index = $(this).index();
+ for(var i=0; i<=index; i++)
+ {
+ $(this).parent().find('li').eq(i).find('i').removeClass('am-icon-star-o').addClass('am-icon-star');
+ }
+ $(this).parents('td').find('input.input-rating').val(index+1);
+ });
+
});
\ No newline at end of file