morphTo('target', [ 1 => 'app\common\model\Goods', //商品 ]); } //获取列表 public function getList($userId, $target_type = 1, $exclude_target_id = []) { if (!empty($exclude_target_id)) { $this->where('target_id', 'not in', $exclude_target_id); } $list = $this->where('user_id', '=', $userId) ->where('target_type', '=', $target_type)->order(['id' => 'desc']) ->paginate(); return $list; } public function getOne($user_id, $target_type, $target_id) { return $this->where('user_id', '=', $user_id) ->where('target_type', $target_type) ->where('target_id', $target_id) ->find(); } public function addOne($user_id, $target_type, $target_id) { $data['user_id'] = $user_id; $data['target_type'] = $target_type; $data['target_id'] = $target_id; $this->save($data); } public function deleteOne($user_id, $target_type, $target_id) { $data['user_id'] = $user_id; $data['target_type'] = $target_type; $data['target_id'] = $target_id; $this->where($data)->delete(); } public function getGoodCollect($user_id, $target_id, $target_type = 1) { if (empty($user_id)) { return false; } $one = $this->getOne($user_id, $target_type, $target_id); if (empty($one)) { return false; } return true; } }