liyaozhi
2025-10-28 1320688354fd168c51cf2e05f29a2253f4ed9c00
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
<?php
 
namespace app\api\controller\user;
 
use app\api\controller\Controller;
use app\api\model\user\Favorite as FavoriteModel;
/**
 * 我的收藏商品和关注店铺
 */
class Favorite extends Controller
{
    protected $user;
     /**
     * 构造方法
     */
    public function initialize()
    {   
        parent::initialize();
        $this->user = $this->getUser();
    }
    /*
    *收藏
    */
    public function add()
    {
        $data = $this->request->param();
        $model = FavoriteModel::detail($data['pid'], $data['type'], $this->user['user_id']);
        if($model && $model->cancelFav()){
            return $this->renderSuccess('操作成功'); 
        }else{
            $data['user_id'] = $this->user['user_id'];
            $model = new FavoriteModel();
            if($model->fav($data)){
                return $this->renderSuccess('操作成功');
            }
        }
 
        return $this->renderSuccess($model->getError()?:'操作失败');
    }
    //我的收藏/关注
    public function list()
    {
        $Favorite = new FavoriteModel;
        $where['user_id'] = $this->user['user_id'];
        $where['type'] = $this->request->param('type');
        $list = $Favorite->getList($where,$this->postData());
        return $this->renderSuccess('',compact('list'));
    }
}