request->post(); if ($this->customer_id <= 0) { $param = []; if (isset($data['curr_url'])) { $param['url'] = $data['curr_url']; } return $this->json(-1000, '请先登录', $param); } if (empty($data) || !is_array($data)) { return $this->json(-1, '数据格式错误'); } $where = [ 'customer_id' => $this->customer_id, 'type' => $data['type'], 'coll_id' => $data['coll_id'], 'stat' => 0 ]; $is_collection = model('collection')->where($where)->find(); if (!empty($is_collection)) { return $this->json(200, '已经收藏过啦'); } $insert_data = [ 'customer_id' => $this->customer_id, 'type' => $data['type'], 'coll_id' => $data['coll_id'], 'create_time' => time(), 'stat' => 0 ]; $result = model('collection')->insert($insert_data); if (!$result) { return $this->json(-2, '收藏失败,请稍后再试'); } return $this->json(200, '收藏成功'); } public function cancel_collection() { $data = $this->request->post(); if ($this->customer_id <= 0) { $param = []; if (isset($data['curr_url'])) { $param['url'] = $data['curr_url']; } return $this->json(-1000, '请先登录', $param); } if (empty($data) || !is_array($data)) { return $this->json(-1, '数据格式错误'); } $where = [ 'customer_id' => $this->customer_id, 'type' => $data['type'], ]; if (!is_array($data['coll_id'])) { $where['coll_id'] = $data['coll_id']; } else { $where['coll_id'] = ['in', $data['coll_id']]; } $result = model('collection')->where($where)->update(['stat' => 1]); if (!$result) { return $this->json(-2, '取消失败,请稍后再试'); } return $this->json(200, '取消成功'); } }