zhaojs
2023-08-04 73e8924ae3a93d4b6a69579ccc464cc599af2bd6
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
 
namespace app\api\logic;
use app\common\logic\Basic as BasicLogic;
use app\common\model\user\Collect as ModelUserCollect;
use app\api\logic\taoke\Parser;
use app\api\logic\taoke\device\Jd as LogicJd;
 
class UserCollect extends BasicLogic
{
 
    protected $model;
 
    protected function initialize()
    {
        $this->model = new ModelUserCollect();
    }
    
 
    /**
     * 获取收藏记录
     *
     * @param [type] $page
     * @param [type] $pageSize
     * @return void
     */
    public function getList($page,$pageSize)
    {
        $list = $this->model
        ->field('id,goodsId,goods_sign,sourceType,faction,title as dtitle,mainPic,originalPrice,actualPrice,shopName,couponPrice,monthSales,create_time')
        ->where(['user_id'=>USERID])
        ->page($page,$pageSize)
        ->order('create_time desc')
        ->select();
        if (empty($list)) return [];
        $LogicJd = new LogicJd();
        foreach($list as &$item){
            $item['create_time_str'] = formatTime($item['create_time']);
            $item['create_time'] = date("Y-m-d",$item['create_time']);
            $item['labelImg'] = Parser::initSourse($item['sourceType']);
        }
        return $list;
    }
 
 
    /**
     * 判断商品是否收藏
     */
    public static function isCollect($goods)
    {
        if(USERID == "") return 0;
        $field = $goods['sourceType'] == 'pdd' ? 'goods_sign' : 'goodsId';
        $find = ModelUserCollect::field('id')->where(['user_id'=>USERID,$field=>$goods[$field]])->find();
        return empty($find) ? 0 : 1;
 
    }
 
 
    /**
     * 商品收藏
     *
     * @param [type] $user_id       用户id
     * @param [type] $goods         商品信息
     * @return void
     */
    public function addCollect($user_id,$goods)
    {
        $save_data = [
            'user_id' => $user_id,
            'goodsId' => $goods['goodsId'],
            'goods_sign' => isset($goods['goods_sign']) ? $goods['good_sign'] : '',
            'sourceType' => $goods['sourceType'],
            'faction' => $goods['faction'],
            'title' => $goods['title'],
            'mainPic' => $goods['mainPic'],
            'originalPrice' => $goods['originalPrice'],
            'actualPrice' => $goods['actualPrice'],
            'shopName' => $goods['shopName'],
            'couponPrice' => $goods['couponPrice'],
            'monthSales' => $goods['monthSales'],
            'create_time' => time()
        ];
 
        $res = $this->model->save($save_data);
        if(!$res) fault('收藏失败');
        return true;
    }
 
    
    /**
     * 商品收藏
     *
     * @param [type] $user_id       用户id
     * @return void
     */
    public function delCollect($user_id,$goodsId)
    {
        $goodsId = strpos($goodsId,',') ? explode(',',$goodsId) : [$goodsId];
        $res = $this->model->where(['user_id'=>$user_id])->whereIn('goodsId',$goodsId)->delete();
        if(!$res) fault('收藏失败');
        return true;
    }
 
 
    /**
     * 删除记录
     *
     * * @param [type] $user_id
     * @param [type] $ids
     * @return void
     */
    public function deleteLog($user_id,$ids)
    {
        $ids = strpos($ids, ',') == false  ? [$ids] : explode(',', $ids);
 
        $res = $this->model->where(['user_id'=>$user_id])->whereIn('id',$ids)->update(['delete_time'=>time()]);
 
        if(!$res) fault('删除失败');
 
        return true;
 
    }
 
 
   
 
}