zhaojs
2023-08-01 cc6247528b559cf6a9468591bb889bb58dc14199
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
<?php
 
namespace app\api\logic;
use app\common\logic\Basic as BasicLogic;
use app\common\model\user\Browse as ModelUserBrowse;
use app\api\logic\taoke\device\Jd as LogicJd;
use think\Db;
 
class UserBrowse extends BasicLogic
{
 
    protected $model;
 
    protected function initialize()
    {
        $this->model = new ModelUserBrowse();
    }
    
 
    /**
     * 获取浏览记录
     *
     * @param [type] $page
     * @param [type] $pageSize
     * @return void
     */
    public function getList($page,$pageSize)
    {
        $list = $this->model
        ->field('id,goodsId,goods_sign,sourceType,faction,title,mainPic,originalPrice,actualPrice,shopName,couponPrice,monthSales,browse_time')
        ->page($page,$pageSize)
        ->where(['user_id'=>USERID])
        ->order('browse_time desc')
        ->select();
        if (empty($list)) return [];
        $LogicJd = new LogicJd();
        foreach($list as &$item){
            $item['browse_time_str'] = formatTime($item['browse_time']);
            $item['browse_time'] = date("Y-m-d",$item['browse_time']);
            if($item['sourceType'] == 'jd'){
                $info = $LogicJd->searchGoods($item['goodsId'],'','','','',1,1);
                if(isset($info[0]))$item = $info[0];
            }
        }
        return $list;
    }
 
 
 
 
 
    /**
     * 删除记录
     *
     * * @param [type] $user_id
     * @param [type] $ids
     * @return void
     */
    public function deleteLog($user_id,$ids)
    {
        $model = $this->model->where(['user_id'=>$user_id]);
 
        if(!empty($ids)){
            $ids = strpos($ids, ',') == false  ? [$ids] : explode(',', $ids);
            $model->whereIn('id',$ids);
        }
 
        $res = $model->update(['delete_time'=>time()]);
 
        if(!$res) fault('删除失败');
 
        return true;
 
    }
 
    /**
     * 标记浏览0元购商品记录
     *
     * * @param [type] $user_id
     * @param [type] $ids
     * @return void
     */
    public function updatefirstfreelog($user_id,$ids,$new_goodsId,$plateform)
    {
        if(empty($ids)||empty($new_goodsId)){
            fault('宝贝ID不能为空');
            return true;
        }
        //查询是否已经标记过
        $res=Db::query('SELECT id FROM t_user_first_free_browse WHERE user_id=? AND goodsId=?',[$user_id,$ids]);
        if(!empty($res)){
             return true;
        }
        $res=Db::execute('INSERT INTO t_user_first_free_browse(user_id,goodsId,new_goodsId,plateform) VALUES (?,?,?,?)',[$user_id,$ids,$new_goodsId,$plateform]);
 
        return true;
 
    }
 
    /**
     * 查询是否首购
     *
     * * @param [type] $user_id
     * @param [type] $ids
     * @return void
     */
 
    public function checkisfirstfree($user_id)
    {
        //查询是否已经标记过
        $res=Db::query('SELECT id FROM t_user_first_free_browse WHERE user_id=? AND is_order=?',[$user_id,1]);
        return $res;
 
    }
 
 
   
 
}