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
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\api\model\user;
 
use app\common\model\user\Favorite as FavoriteModel;
use app\common\model\supplier\Supplier as SupplierModel;
use app\common\model\product\Product as ProductModel;
/**
 * 收藏模型类
 */
class Favorite extends FavoriteModel
{
    public function getList($where,$param){
        if($where['type']==20){
            return parent::getList($where,$param); 
        }else{
            return parent::getMySupplier($where,$param);
        }
    }
 
    /**
     * 取消收藏
     */
    public function cancelFav(){
        $this->startTrans();
        try {
            // 取消店铺关注
            if($this['type'] == 10){
                (new SupplierModel())->where('shop_supplier_id', '=', $this['pid'])
                    ->dec('fav_count')->update();
            }
            $this->delete();
            // 事务提交
            $this->commit();
            return true;
        } catch (\Exception $e) {
            $this->error = $e->getMessage();
            $this->rollback();
            return false;
        }
    }
 
    public function fav($data){
        $data['app_id'] = self::$app_id;
        $this->startTrans();
        try {
            // 店铺收藏
            if($data['type'] == 10){
                $data['shop_supplier_id'] = $data['pid'];
                (new SupplierModel())->where('shop_supplier_id', '=', $data['pid'])
                    ->inc('fav_count')->update();
            }else{
                $product = ProductModel::detail($data['pid']);
                $data['shop_supplier_id'] = $product['shop_supplier_id'];
            }
            $this->save($data);
            // 事务提交
            $this->commit();
            return true;
        } catch (\Exception $e) {
            $this->error = $e->getMessage();
            $this->rollback();
            return false;
        }
    }
    public static function isFollow($pid,$user_id,$type){
        
        return (new static())->where('pid', '=', $pid)
                    ->where('user_id', '=', $user_id)
                    ->where('type', '=', $type)
                    ->count();
    }
}