quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
 
namespace app\shop\controller\product;
 
use app\shop\controller\Controller;
use app\shop\model\product\Comment as CommentModel;
use app\shop\model\supplier\Supplier as SupplierModel;
 
/**
 * 商品评价控制器
 */
class Comment extends Controller
{
    /**
     * 评价列表
     */
    public function index()
    {
        //获取该角色管理的区域 by yj 2023.12.20
        $shop_supplier_ids = SupplierModel::getSupplierIdsByUser($this->store['user']);
        $model = new CommentModel;
        $postData = $this->postData();
 
        $where[] = ['status', '=', 0];
        if(!empty($shop_supplier_ids)){
            $postData["shop_supplier_ids"] = $shop_supplier_ids;
            $where[] = ['shop_supplier_id', 'in', $shop_supplier_ids];
        }
 
        //列表
        $list = $model->getList($postData);
        //重要数据
        $num = $model->getStatusNum($where);
        return $this->renderSuccess('', compact('list','num'));
    }
 
    /**
     * 评价详情
     */
    public function detail($comment_id)
    {
        // 评价详情
        $data = CommentModel::detail($comment_id);
        return $this->renderSuccess('', compact('data'));
    }
 
    /**
     * 更新商品评论
     */
    public function edit($comment_id)
    {
        $model = CommentModel::detail($comment_id);
        // 更新记录
        if ($model->edit($this->postData())) {
            (new CommentModel)->updateScore($model['shop_supplier_id']);
            return $this->renderSuccess('修改成功');
        }
        return $this->renderError('修改失败');
    }
 
    /**
     * 删除评价
     */
    public function delete($comment_id)
    {
        $model = new CommentModel();
        if (!$model->setDelete($comment_id)) {
            return $this->renderError('删除失败');
        }
        return $this->renderSuccess('删除成功');
    }
 
}